Search in sources :

Example 6 with PreferencesHelper

use of org.firstinspires.ftc.robotcore.internal.system.PreferencesHelper in project FTC-2017 by FIRST-4030.

the class FtcRobotControllerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // robustify against onCreate() following onDestroy() but using the same app instance, which apparently does happen
    RobotLog.onApplicationStart();
    RobotLog.vv(TAG, "onCreate()");
    // do this way instead of inherit to help AppInventor
    ThemedActivity.appAppThemeToActivity(getTag(), this);
    Assert.assertTrue(FtcRobotControllerWatchdogService.isFtcRobotControllerActivity(AppUtil.getInstance().getRootActivity()));
    Assert.assertTrue(AppUtil.getInstance().isRobotController());
    // a stand-alone USB-connected module?
    if (LynxConstants.isRevControlHub()) {
        if (LynxConstants.disableDragonboard()) {
            // Double-sure check that the Lynx Module can operate over USB, etc, then get out of Dodge
            RobotLog.vv(TAG, "disabling Dragonboard and exiting robot controller");
            DragonboardLynxDragonboardIsPresentPin.getInstance().setState(false);
            AppUtil.getInstance().finishRootActivityAndExitApp();
        } else {
            // Double-sure check that we can talk to the DB over the serial TTY
            DragonboardLynxDragonboardIsPresentPin.getInstance().setState(true);
        }
    }
    context = this;
    utility = new Utility(this);
    DeviceNameManager.getInstance().start(deviceNameManagerStartResult);
    PreferenceRemoterRC.getInstance().start(prefRemoterStartResult);
    receivedUsbAttachmentNotifications = new ConcurrentLinkedQueue<UsbDevice>();
    eventLoop = null;
    setContentView(R.layout.activity_ftc_controller);
    preferencesHelper = new PreferencesHelper(TAG, context);
    preferencesHelper.writeBooleanPrefIfDifferent(context.getString(R.string.pref_rc_connected), true);
    preferencesHelper.getSharedPreferences().registerOnSharedPreferenceChangeListener(sharedPreferencesListener);
    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) {
            AppUtil.getInstance().openOptionsMenuFor(FtcRobotControllerActivity.this);
        }
    });
    BlocksOpMode.setActivityAndWebView(this, (WebView) findViewById(R.id.webViewBlocksRuntime));
    ClassManagerFactory.registerFilters();
    ClassManagerFactory.processAllClasses();
    cfgFileMgr = new RobotConfigFileManager(this);
    // Clean up 'dirty' status after a possible crash
    RobotConfigFile configFile = cfgFileMgr.getActiveConfig();
    if (configFile.isDirty()) {
        configFile.markClean();
        cfgFileMgr.setActiveConfig(false, configFile);
    }
    textDeviceName = (TextView) findViewById(R.id.textDeviceName);
    textNetworkConnectionStatus = (TextView) findViewById(R.id.textNetworkConnectionStatus);
    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();
    programmingWebHandlers = new ProgrammingWebHandlers();
    programmingModeController = new ProgrammingModeControllerImpl(this, (TextView) findViewById(R.id.textRemoteProgrammingMode), programmingWebHandlers);
    updateUI = createUpdateUI();
    callback = createUICallback(updateUI);
    PreferenceManager.setDefaultValues(this, R.xml.app_settings, false);
    WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "");
    hittingMenuButtonBrightensScreen();
    wifiLock.acquire();
    callback.networkConnectionUpdate(WifiDirectAssistant.Event.DISCONNECTED);
    readNetworkType();
    ServiceController.startService(FtcRobotControllerWatchdogService.class);
    bindToService();
    logPackageVersions();
}
Also used : WifiManager(android.net.wifi.WifiManager) ImmersiveMode(com.qualcomm.robotcore.util.ImmersiveMode) UsbDevice(android.hardware.usb.UsbDevice) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) RobotConfigFileManager(com.qualcomm.ftccommon.configuration.RobotConfigFileManager) PreferencesHelper(org.firstinspires.ftc.robotcore.internal.system.PreferencesHelper) ProgrammingModeControllerImpl(com.google.blocks.ftcrobotcontroller.ProgrammingModeControllerImpl) Utility(com.qualcomm.robotcore.hardware.configuration.Utility) RobotConfigFile(com.qualcomm.ftccommon.configuration.RobotConfigFile) Dimmer(com.qualcomm.robotcore.util.Dimmer) TextView(android.widget.TextView) ProgrammingWebHandlers(com.google.blocks.ftcrobotcontroller.ProgrammingWebHandlers)

Aggregations

PreferencesHelper (org.firstinspires.ftc.robotcore.internal.system.PreferencesHelper)6 UsbDevice (android.hardware.usb.UsbDevice)3 WifiManager (android.net.wifi.WifiManager)3 View (android.view.View)3 WebView (android.webkit.WebView)3 TextView (android.widget.TextView)3 ProgrammingModeControllerImpl (com.google.blocks.ftcrobotcontroller.ProgrammingModeControllerImpl)3 ProgrammingWebHandlers (com.google.blocks.ftcrobotcontroller.ProgrammingWebHandlers)3 RobotConfigFile (com.qualcomm.ftccommon.configuration.RobotConfigFile)3 RobotConfigFileManager (com.qualcomm.ftccommon.configuration.RobotConfigFileManager)3 Utility (com.qualcomm.robotcore.hardware.configuration.Utility)3 Dimmer (com.qualcomm.robotcore.util.Dimmer)3 ImmersiveMode (com.qualcomm.robotcore.util.ImmersiveMode)3 TypedArray (android.content.res.TypedArray)1 Bundle (android.os.Bundle)1