Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Monday, August 15, 2016

Fullscreen activity wizard activity. How do I stop actionbar from showing when I interact with device?

Fullscreen activity wizard activity. How do I stop actionbar from showing when I interact with device?


When I create an activity using the fullscreen activity wizard it creatre a fullscreen activity but whenever I click anywhere on the screen the actionbar shows for a few seconds. How can I stop it from doing so?

Full code of FullScreenActivity.java

/**   * An example full-screen activity that shows and hides the system UI (i.e.   * status bar and navigation/system bar) with user interaction.   *    * @see SystemUiHider   */  public class FullscreenActivity extends Activity {      /**       * Whether or not the system UI should be auto-hidden after       * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.       */      private static final boolean AUTO_HIDE = true;        /**       * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after       * user interaction before hiding the system UI.       */      private static final int AUTO_HIDE_DELAY_MILLIS = 3000;        /**       * If set, will toggle the system UI visibility upon interaction. Otherwise,       * will show the system UI visibility upon interaction.       */      private static final boolean TOGGLE_ON_CLICK = true;        /**       * The flags to pass to {@link SystemUiHider#getInstance}.       */      private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;        /**       * The instance of the {@link SystemUiHider} for this activity.       */      private SystemUiHider mSystemUiHider;        @Override      protected void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);            setContentView(R.layout.activity_fullscreen);            final View controlsView = findViewById(R.id.fullscreen_content_controls);          final View contentView = findViewById(R.id.fullscreen_content);            // Set up an instance of SystemUiHider to control the system UI for          // this activity.          mSystemUiHider = SystemUiHider.getInstance(this, contentView,                  HIDER_FLAGS);          mSystemUiHider.setup();          mSystemUiHider                  .setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {                      // Cached values.                      int mControlsHeight;                      int mShortAnimTime;                        @Override                      @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)                      public void onVisibilityChange(boolean visible) {                          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {                              // If the ViewPropertyAnimator API is available                              // (Honeycomb MR2 and later), use it to animate the                              // in-layout UI controls at the bottom of the                              // screen.                              if (mControlsHeight == 0) {                                  mControlsHeight = controlsView.getHeight();                              }                              if (mShortAnimTime == 0) {                                  mShortAnimTime = getResources().getInteger(                                          android.R.integer.config_shortAnimTime);                              }                              controlsView                                      .animate()                                      .translationY(visible ? 0 : mControlsHeight)                                      .setDuration(mShortAnimTime);                          } else {                              // If the ViewPropertyAnimator APIs aren't                              // available, simply show or hide the in-layout UI                              // controls.                              controlsView.setVisibility(visible ? View.VISIBLE                                      : View.GONE);                          }                            if (visible && AUTO_HIDE) {                              // Schedule a hide().                              delayedHide(AUTO_HIDE_DELAY_MILLIS);                          }                      }                  });            // Set up the user interaction to manually show or hide the system UI.          contentView.setOnClickListener(new View.OnClickListener() {              @Override              public void onClick(View view) {                  if (TOGGLE_ON_CLICK) {                      mSystemUiHider.toggle();                  } else {                      mSystemUiHider.show();                  }              }          });            // Upon interacting with UI controls, delay any scheduled hide()          // operations to prevent the jarring behavior of controls going away          // while interacting with the UI.          findViewById(R.id.dummy_button).setOnTouchListener(                  mDelayHideTouchListener);      }        @Override      protected void onPostCreate(Bundle savedInstanceState) {          super.onPostCreate(savedInstanceState);            // Trigger the initial hide() shortly after the activity has been          // created, to briefly hint to the user that UI controls          // are available.          delayedHide(100);      }        /**       * Touch listener to use for in-layout UI controls to delay hiding the       * system UI. This is to prevent the jarring behavior of controls going away       * while interacting with activity UI.       */      View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {          @Override          public boolean onTouch(View view, MotionEvent motionEvent) {              if (AUTO_HIDE) {                  delayedHide(AUTO_HIDE_DELAY_MILLIS);              }              return false;          }      };        Handler mHideHandler = new Handler();      Runnable mHideRunnable = new Runnable() {          @Override          public void run() {              mSystemUiHider.hide();          }      };        /**       * Schedules a call to hide() in [delay] milliseconds, canceling any       * previously scheduled calls.       */      private void delayedHide(int delayMillis) {          mHideHandler.removeCallbacks(mHideRunnable);          mHideHandler.postDelayed(mHideRunnable, delayMillis);      }  }  

Answer by Matthias Robbers for Fullscreen activity wizard activity. How do I stop actionbar from showing when I interact with device?


I took a deep look into the code and started the activity on an Android 4.2 device without physical navigation buttons. The default configuration is as fullscreen as possible. It hides status bar, action bar and navigation bar. So how would the user be supposed to get out of your activity if not with a click anywhere on the screen? Anything else would be very restricting and bad usability. I think this is the reason why this behavior can not be manipulated.

What you can do instead, is change the SystemUiHider so that it hides the status bar and the action bar, but not the navigation bar. It instead dimmes the navigation bar to three pale dots, see the screenshot below.

dimmed navigation bar

There must be a better way to achieve this, but the following works. Comment these lines in the end of the SystemUiHiderHoneycomb() constructor:

if ((mFlags & FLAG_HIDE_NAVIGATION) != 0) {      // If the client requested hiding navigation, add relevant flags.      mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;      mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION              | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;      mTestFlags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;  }  

The activity then stays fullscreen on user interaction and you can toggle() it at a particular event. Of course, you would still have to do the change from my original answer to disable the click behavior.


Original answer:

I guess you have to comment this part:

// Set up the user interaction to manually show or hide the system UI.  contentView.setOnClickListener(new View.OnClickListener() {      @Override      public void onClick(View view) {          if (TOGGLE_ON_CLICK) {              mSystemUiHider.toggle();          } else {              mSystemUiHider.show();          }      }  });  

Answer by Pulkit Sethi for Fullscreen activity wizard activity. How do I stop actionbar from showing when I interact with device?


Change the theme of your activity to not have action bar. Best is to inherit from action bar Sherlock activity and remove the action bar

Answer by shaish for Fullscreen activity wizard activity. How do I stop actionbar from showing when I interact with device?


if i understand correctly, you just want to hide the action bar?

if yes, Change this line (changing the flag_hide_navigation to 0).

private static final int HIDER_FLAGS = 0;// SystemUiHider.FLAG_HIDE_NAVIGATION;  

and add this to the onCreate call:

protected void onCreate(Bundle savedInstanceState) {      super.onCreate(savedInstanceState);        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);   //new      getActionBar().hide();                                   //new      getWindow().setFlags(           WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);        setContentView(R.layout.activity_fullscreen);  

afterwards, if you want to show the action bar, just call from anywhere in the activity :

getActionBar().show();  

Answer by Vikram Dhingra for Fullscreen activity wizard activity. How do I stop actionbar from showing when I interact with device?


I Tried The Same By Putting 0 in place of 3000

private static final int AUTO_HIDE_DELAY_MILLIS = 3000;  

But its becoming too laggy... So,The trick u to make changes in androidmanifest.xml add

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"  

to AndroidManifest.xml underApplication

Answer by JJ_Coder4Hire for Fullscreen activity wizard activity. How do I stop actionbar from showing when I interact with device?


This worked for me. Although the navigator isn't removed completely it doesn't allow much time for the user to interact, plus the button icons are small dots. Also this cuts down on the amount of code needed all over the place to make a screen fullscreen.

SystemUiHider hider = null;    @Override  protected void onCreate(Bundle savedInstanceState) {      super.onCreate(savedInstanceState);        //go full screen with no title      this.requestWindowFeature(Window.FEATURE_PROGRESS); //show progress on loadup      this.requestWindowFeature(Window.FEATURE_NO_TITLE); //hide the title bar      this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //go fullscreen        setContentView(R.layout.activity_main);        //hide the navigation controls      final RelativeLayout mainLayout = (RelativeLayout)this.findViewById(R.id.mainLayout);      hider = SystemUiHider.getInstance(this, mainLayout, SystemUiHider.FLAG_HIDE_NAVIGATION);      hider.setup();      hider.setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {          @Override          @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)          public void onVisibilityChange(boolean visible) {              if (visible) {                  //will make navigator into small dots                  hider.hide();                     //must use delayed to force navigator to disappear completely                  final Handler mHideHandler = new Handler();                  final Runnable mHideRunnable = new Runnable() {                      @Override                      public void run() {                          hider.hide();                      }                  };                  mHideHandler.removeCallbacks(mHideRunnable);                  mHideHandler.postDelayed(mHideRunnable, 1000); //min 1 sec to work              }          }      });      hider.hide();        //do the rest of your onCreate stuff here  }  

Answer by shabbir mohammed for Fullscreen activity wizard activity. How do I stop actionbar from showing when I interact with device?


In api19 we can use:

getWindow().getDecorView()      .setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY                             | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);   

to hide navigation bar along with status bar

Answer by Ashutosh for Fullscreen activity wizard activity. How do I stop actionbar from showing when I interact with device?


Though its too late to post an answer, but as far as I can understand the question and since I am working using the Full Screen Activity template provided in Android Studio, I think the answer to this question is to disable action bar which becomes visible when the user interacts with the UI, which can be achieved just by disabling the OnClickListener on contentView i.e.

contentView.setOnClickListener(new View.OnClickListener() {      @Override      public void onClick(View view) {          if (TOGGLE_ON_CLICK) {              mSystemUiHider.toggle();          } else {              mSystemUiHider.show();          }      }  });  

i.e. comment out the onClick method implementation.

Answer by Madhur Chadha for Fullscreen activity wizard activity. How do I stop actionbar from showing when I interact with device?


Just comment out

if (TOGGLE_ON_CLICK) {                      mSystemUiHider.toggle();                  } else {                      mSystemUiHider.show();                  }  

By default the state is Off. Toggle happens because there is a onclick listener also added which toggles the screen. You could simply not add it and delete the code snippet.

The newest code is // Set up the user interaction to manually show or hide the system UI.

mContentView.setOnClickListener(new View.OnClickListener() {          @Override          public void onClick(View view) {             // toggle();          }  

I simply commented out toggle() and voila


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.