Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <item android:title="Screen Sensor">
- <menu>
- <group android:checkableBehavior="single">
- <item
- android:id="@+id/screen_sensor_enable"
- android:title="Enable"
- android:checked="true" // When this is clicked this needs to be false.
- app:showAsAction="never"/>
- <item
- android:id="@+id/screen_sensor_disable"
- android:title="Disable"
- android:checked="false" // When this is clicked this needs to be true.
- app:showAsAction="never"/>
- </group>
- </menu>
- </item>
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getScreenSensorSetting();
- menu.clear();
- getMenuInflater().inflate(R.menu.my_menu, menu);
- if (sensor.equals("Enable")) {
- menu.findItem(R.id.screen_sensor_enable).isChecked();
- }else if (sensor.equals("Disable")) {
- menu.findItem(R.id.screen_sensor_disable).isChecked();
- }
- this.myMenu = menu;
- return true;
- }
- menuOptionsButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(final View v) {
- PopupMenu popupMenu = new PopupMenu(getApplicationContext(), menuOptionsButton);
- popupMenu.getMenuInflater().inflate(R.menu.my_menu, popupMenu.getMenu());
- popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
- @Override
- public boolean onMenuItemClick(MenuItem item) {
- int id = item.getItemId();
- if (id == R.id.screen_sensor_enable) {
- screenSensor = true;
- MainActivity.screenSensor = true;
- sensor = "Enable";
- myTB.setVisibility(View.GONE);
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
- getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
- mPlayerView.getLayoutParams().width = 10000;
- mPlayerView.getLayoutParams().height = 10000;
- mPlayerView.requestLayout();
- myCustomToast(getApplicationContext(), "Screen Sensor is ON! - The Playing Video Will Full Screen In Landscape Position.");
- }else if (id == R.id.screen_sensor_disable) {
- screenSensor = false;
- MainActivity.screenSensor = false;
- sensor = "Disable";
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
- getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
- myCustomToast(getApplicationContext(), "Screen Sensor is OFF! - The Playing Video Will Not Full Screen In Landscape Position.");
- }
- return true;
- }
- });
- popupMenu.show();
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement