SHARE
TWEET

Untitled

a guest Jun 19th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <item android:title="Screen Sensor">
  2.     <menu>
  3.         <group android:checkableBehavior="single">
  4.             <item
  5.                 android:id="@+id/screen_sensor_enable"
  6.                 android:title="Enable"
  7.                 android:checked="true" // When this is clicked this needs to be false.
  8.                 app:showAsAction="never"/>
  9.  
  10.             <item
  11.                 android:id="@+id/screen_sensor_disable"
  12.                 android:title="Disable"
  13.                 android:checked="false" // When this is clicked this needs to be true.
  14.                 app:showAsAction="never"/>
  15.         </group>
  16.     </menu>
  17. </item>
  18.      
  19. @Override
  20. public boolean onCreateOptionsMenu(Menu menu) {
  21.     getScreenSensorSetting();
  22.     menu.clear();
  23.     getMenuInflater().inflate(R.menu.my_menu, menu);
  24.     if (sensor.equals("Enable")) {
  25.         menu.findItem(R.id.screen_sensor_enable).isChecked();
  26.     }else if (sensor.equals("Disable")) {
  27.         menu.findItem(R.id.screen_sensor_disable).isChecked();
  28.     }
  29.  
  30.     this.myMenu = menu;
  31.  
  32.     return true;
  33. }
  34.  
  35.  
  36. menuOptionsButton.setOnClickListener(new View.OnClickListener() {
  37. @Override
  38. public void onClick(final View v) {
  39.     PopupMenu popupMenu = new PopupMenu(getApplicationContext(), menuOptionsButton);
  40.     popupMenu.getMenuInflater().inflate(R.menu.my_menu, popupMenu.getMenu());
  41.  
  42.     popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
  43.         @Override
  44.         public boolean onMenuItemClick(MenuItem item) {
  45.             int id = item.getItemId();
  46.  
  47.                 if (id == R.id.screen_sensor_enable) {
  48.                 screenSensor = true;
  49.                 MainActivity.screenSensor = true;
  50.                 sensor = "Enable";
  51.                 myTB.setVisibility(View.GONE);
  52.                 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
  53.                 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  54.                 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
  55.  
  56.                 mPlayerView.getLayoutParams().width = 10000;
  57.                 mPlayerView.getLayoutParams().height = 10000;
  58.                 mPlayerView.requestLayout();
  59.                 myCustomToast(getApplicationContext(), "Screen Sensor is ON! - The Playing Video Will Full Screen In Landscape Position.");
  60.             }else if (id == R.id.screen_sensor_disable) {
  61.                 screenSensor = false;
  62.                 MainActivity.screenSensor = false;
  63.                 sensor = "Disable";
  64.                 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  65.                 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
  66.                 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
  67.                 myCustomToast(getApplicationContext(), "Screen Sensor is OFF! - The Playing Video Will Not Full Screen In Landscape Position.");
  68.             }
  69.             return true;
  70.         }
  71.     });
  72.  
  73.     popupMenu.show();
  74.  
  75. }
  76. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top