Exemple #1
0
  /** Called to initialize the action bar. */
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.desktop_actionbar, menu);

    mActivityLifecycleListener.onActivityCreatedOptionsMenu(this, menu);

    boolean enableCardboard = false;
    try {
      ApplicationInfo ai =
          getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
      Bundle bundle = ai.metaData;
      enableCardboard = bundle.getInt("enable_cardboard") == 1;
    } catch (NameNotFoundException e) {
      // Does nothing since by default Cardboard activity is turned off.
    }

    MenuItem item = menu.findItem(R.id.actionbar_cardboard);
    item.setVisible(enableCardboard);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      // We don't need to show a hide ActionBar button if immersive fullscreen is supported.
      menu.findItem(R.id.actionbar_hide).setVisible(false);
    }

    ChromotingUtil.tintMenuIcons(this, menu);

    return super.onCreateOptionsMenu(menu);
  }
Exemple #2
0
 @Override
 public void onResume() {
   super.onResume();
   mActivityLifecycleListener.onActivityResumed(this);
   JniInterface.enableVideoChannel(true);
   startActionBarAutoHideTimer();
 }
Exemple #3
0
 @Override
 protected void onStart() {
   super.onStart();
   mActivityLifecycleListener.onActivityStarted(this);
   JniInterface.enableVideoChannel(true);
   mRemoteHostDesktop.attachRedrawCallback();
 }
Exemple #4
0
 @Override
 protected void onPause() {
   if (isFinishing()) mActivityLifecycleListener.onActivityPaused(this);
   super.onPause();
   if (!mSwitchToCardboardDesktopActivity) {
     JniInterface.enableVideoChannel(false);
   }
   stopActionBarAutoHideTimer();
 }
Exemple #5
0
 @Override
 protected void onStop() {
   mActivityLifecycleListener.onActivityStopped(this);
   super.onStop();
   if (mSwitchToCardboardDesktopActivity) {
     mSwitchToCardboardDesktopActivity = false;
   } else {
     JniInterface.enableVideoChannel(false);
   }
 }
Exemple #6
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.desktop);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mRemoteHostDesktop = (DesktopView) findViewById(R.id.desktop_view);
    mRemoteHostDesktop.setDesktop(this);
    mSwitchToCardboardDesktopActivity = false;

    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // For this Activity, the home button in the action bar acts as a Disconnect button, so
    // set the description for accessibility/screen readers.
    getSupportActionBar().setHomeActionContentDescription(R.string.disconnect_myself_button);

    // The action bar is already shown when the activity is started however calling the
    // function below will set our preferred system UI flags which will adjust the layout
    // size of the canvas and we can avoid an initial resize event.
    showActionBar();

    View decorView = getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(this);

    mActivityLifecycleListener =
        CapabilityManager.getInstance()
            .onActivityAcceptingListener(this, Capabilities.CAST_CAPABILITY);
    mActivityLifecycleListener.onActivityCreated(this, savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      attachKeyboardVisibilityListener();

      // Only create an Autohide task if the system supports immersive fullscreen mode.  Older
      // versions of the OS benefit less from this functionality and we don't want to change
      // the experience for them.
      mActionBarAutoHideTask =
          new Runnable() {
            public void run() {
              hideActionBar();
            }
          };
    } else {
      mRemoteHostDesktop.setFitsSystemWindows(true);
    }
  }
Exemple #7
0
  /** Called whenever an action bar button is pressed. */
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    mActivityLifecycleListener.onActivityOptionsItemSelected(this, item);

    // Whenever a user selects an option from the ActionBar, reset the auto-hide timer.
    startActionBarAutoHideTimer();

    if (id == R.id.actionbar_cardboard) {
      onCardboardItemSelected();
      return true;
    }
    if (id == R.id.actionbar_keyboard) {
      ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).toggleSoftInput(0, 0);
      return true;
    }
    if (id == R.id.actionbar_hide) {
      hideActionBar();
      return true;
    }
    if (id == R.id.actionbar_disconnect || id == android.R.id.home) {
      JniInterface.disconnectFromHost();
      return true;
    }
    if (id == R.id.actionbar_send_ctrl_alt_del) {
      int[] keys = {
        KeyEvent.KEYCODE_CTRL_LEFT, KeyEvent.KEYCODE_ALT_LEFT, KeyEvent.KEYCODE_FORWARD_DEL,
      };
      for (int key : keys) {
        JniInterface.sendKeyEvent(0, key, true);
      }
      for (int key : keys) {
        JniInterface.sendKeyEvent(0, key, false);
      }
      return true;
    }
    if (id == R.id.actionbar_help) {
      HelpActivity.launch(this, HELP_URL);
      return true;
    }
    return super.onOptionsItemSelected(item);
  }