@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_ftc_controller);

    utility = new Utility(this);
    context = this;
    exposedContext = context;
    entireScreenLayout = (LinearLayout) findViewById(R.id.entire_screen);
    buttonMenu = (ImageButton) findViewById(R.id.menu_buttons);
    buttonMenu.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            openOptionsMenu();
          }
        });

    textDeviceName = (TextView) findViewById(R.id.textDeviceName);
    textWifiDirectStatus = (TextView) findViewById(R.id.textWifiDirectStatus);
    textRobotStatus = (TextView) findViewById(R.id.textRobotStatus);
    textOpMode = (TextView) findViewById(R.id.textOpMode);
    textErrorMessage = (TextView) findViewById(R.id.textErrorMessage);
    textGamepad[0] = (TextView) findViewById(R.id.textGamepad1);
    textGamepad[1] = (TextView) findViewById(R.id.textGamepad2);
    immersion = new ImmersiveMode(getWindow().getDecorView());
    dimmer = new Dimmer(this);
    dimmer.longBright();
    Restarter restarter = new RobotRestarter();

    updateUI = new UpdateUI(this, dimmer);
    updateUI.setRestarter(restarter);
    updateUI.setTextViews(
        textWifiDirectStatus,
        textRobotStatus,
        textGamepad,
        textOpMode,
        textErrorMessage,
        textDeviceName);
    callback = updateUI.new Callback();

    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    preferences = PreferenceManager.getDefaultSharedPreferences(this);

    hittingMenuButtonBrightensScreen();

    if (USE_DEVICE_EMULATION) {
      HardwareFactory.enableDeviceEmulation();
    }
  }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.action_restart_robot:
       dimmer.handleDimTimer();
       Toast.makeText(context, "Restarting Robot", Toast.LENGTH_SHORT).show();
       requestRobotRestart();
       return true;
     case R.id.action_settings:
       // The string to launch this activity must match what's in AndroidManifest of FtcCommon for
       // this activity.
       Intent settingsIntent =
           new Intent(
               "com.qualcomm.ftccommon.FtcRobotControllerSettingsActivity.intent.action.Launch");
       startActivityForResult(
           settingsIntent,
           LaunchActivityConstantsList.FTC_ROBOT_CONTROLLER_ACTIVITY_CONFIGURE_ROBOT);
       return true;
     case R.id.action_about:
       // The string to launch this activity must match what's in AndroidManifest of FtcCommon for
       // this activity.
       Intent intent =
           new Intent("com.qualcomm.ftccommon.configuration.AboutActivity.intent.action.Launch");
       startActivity(intent);
       return true;
     case R.id.action_exit_app:
       finish();
       return true;
     case R.id.action_view_logs:
       // The string to launch this activity must match what's in AndroidManifest of FtcCommon for
       // this activity.
       Intent viewLogsIntent =
           new Intent("com.qualcomm.ftccommon.ViewLogsActivity.intent.action.Launch");
       viewLogsIntent.putExtra(
           LaunchActivityConstantsList.VIEW_LOGS_ACTIVITY_FILENAME, RobotLog.getLogFilename(this));
       startActivity(viewLogsIntent);
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!OpenCVLoader.initDebug()) {
      Log.e(this.getClass().getSimpleName(), "  OpenCVLoader.initDebug(), not working.");
    } else {
      Log.d(this.getClass().getSimpleName(), "  OpenCVLoader.initDebug(), working.");
    }

    receivedUsbAttachmentNotifications = new ConcurrentLinkedQueue<UsbDevice>();
    eventLoop = null;

    setContentView(R.layout.activity_ftc_controller);

    utility = new Utility(this);
    context = this;
    entireScreenLayout = (LinearLayout) findViewById(R.id.entire_screen);
    buttonMenu = (ImageButton) findViewById(R.id.menu_buttons);
    buttonMenu.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            openOptionsMenu();
          }
        });

    textDeviceName = (TextView) findViewById(R.id.textDeviceName);
    textWifiDirectStatus = (TextView) findViewById(R.id.textWifiDirectStatus);
    textRobotStatus = (TextView) findViewById(R.id.textRobotStatus);
    textOpMode = (TextView) findViewById(R.id.textOpMode);
    textErrorMessage = (TextView) findViewById(R.id.textErrorMessage);
    textGamepad[0] = (TextView) findViewById(R.id.textGamepad1);
    textGamepad[1] = (TextView) findViewById(R.id.textGamepad2);
    mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.camerapreview);
    immersion = new ImmersiveMode(getWindow().getDecorView());
    dimmer = new Dimmer(this);
    dimmer.longBright();
    Restarter restarter = new RobotRestarter();

    updateUI = new UpdateUI(this, dimmer);
    updateUI.setRestarter(restarter);
    updateUI.setTextViews(
        textWifiDirectStatus,
        textRobotStatus,
        textGamepad,
        textOpMode,
        textErrorMessage,
        textDeviceName);
    callback = updateUI.new Callback();

    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    preferences = PreferenceManager.getDefaultSharedPreferences(this);

    WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "");

    hittingMenuButtonBrightensScreen();

    if (USE_DEVICE_EMULATION) {
      HardwareFactory.enableDeviceEmulation();
    }
  }