Search in sources :

Example 1 with PreferencesHelper

use of org.firstinspires.ftc.robotcore.internal.system.PreferencesHelper in project Relic_Main by TeamOverdrive.

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)

Example 2 with PreferencesHelper

use of org.firstinspires.ftc.robotcore.internal.system.PreferencesHelper in project robotcode by OutoftheBoxFTC.

the class ThemedActivity method appAppThemeToActivity.

public static void appAppThemeToActivity(String tag, Activity activity) {
    // Find / initialize the app theme
    PreferencesHelper preferencesHelper = new PreferencesHelper(tag, activity);
    String pref_app_theme = activity.getString(R.string.pref_app_theme);
    String tokenCur = preferencesHelper.readString(pref_app_theme, activity.getString(R.string.tokenThemeRed));
    preferencesHelper.writePrefIfDifferent(pref_app_theme, tokenCur);
    String[] tokens = activity.getResources().getStringArray(R.array.app_theme_tokens);
    TypedArray ar = activity.getResources().obtainTypedArray(R.array.app_theme_ids);
    boolean found = false;
    for (int i = 0; i < tokens.length; i++) {
        if (tokens[i].equals(tokenCur)) {
            int themeId = ar.getResourceId(i, 0);
            activity.setTheme(themeId);
            found = true;
            break;
        }
    }
    if (!found) {
        activity.setTheme(ar.getResourceId(0, 0));
    }
    ar.recycle();
}
Also used : TypedArray(android.content.res.TypedArray) PreferencesHelper(org.firstinspires.ftc.robotcore.internal.system.PreferencesHelper)

Example 3 with PreferencesHelper

use of org.firstinspires.ftc.robotcore.internal.system.PreferencesHelper in project robotcode by OutoftheBoxFTC.

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()");
    /* // Modified for OpenRC
     * Check to see if the DS app is also installed.
     * If it is, then show the user a dialog explaining
     * the situation and offer them the option to uninstall
     * either the DS app or the RC app
     */
    if (BuildConfig.IS_OPENRC && Utils.isFtcDriverStationInstalled(getPackageManager())) {
        UiUtils.showDsAppInstalledDialog(this);
    }
    if (BuildConfig.IS_OPENRC && !Utils.hasAcknowledgedLegalityStatus()) {
        UiUtils.showLegalityAcknowlegementDialog(this);
    }
    // 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);
        }
    });
    if (isFullVersion) {
        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);
    if (BuildConfig.IS_OPENRC) {
        textOpenRCVersion = (TextView) findViewById(R.id.openrc_version);
        textOpenRCVersion.setText(org.openftc.rc.BuildConfig.VERSION_COMPLETE);
    }
    immersion = new ImmersiveMode(getWindow().getDecorView());
    dimmer = new Dimmer(this);
    dimmer.longBright();
    if (isFullVersion) {
        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)

Example 4 with PreferencesHelper

use of org.firstinspires.ftc.robotcore.internal.system.PreferencesHelper in project robotcode by OutoftheBoxFTC.

the class RunOnBoot method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    this.context = context;
    if (preferencesHelper == null) {
        preferencesHelper = new PreferencesHelper(TAG, context);
    }
    String action = intent.getAction();
    RobotLog.vv(TAG, "onReceive() action=%s", action);
    if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
        if (AppUtil.getInstance().isRobotController()) {
            onRobotControllerBoot();
        } else if (AppUtil.getInstance().isDriverStation()) {
            onDriverStationBoot();
        }
    } else {
        if (AppUtil.getInstance().isRobotController()) {
            onRobotControllerPostBoot();
        } else if (AppUtil.getInstance().isDriverStation()) {
            onDriverStationPostBoot();
        }
    }
}
Also used : PreferencesHelper(org.firstinspires.ftc.robotcore.internal.system.PreferencesHelper)

Example 5 with PreferencesHelper

use of org.firstinspires.ftc.robotcore.internal.system.PreferencesHelper in project robotcode by OutoftheBoxFTC.

the class FtcAdvancedRCSettingsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_generic_settings);
    // Always make sure we have a real device name before we launch
    DeviceNameManager.getInstance().initializeDeviceNameIfNecessary();
    // Display the fragment as the main content.
    SettingsFragment settingsFragment = new SettingsFragment();
    Bundle arguments = new Bundle();
    arguments.putBoolean(CLIENT_CONNECTED, new PreferencesHelper(TAG, this).readBoolean(getString(R.string.pref_rc_connected), false));
    settingsFragment.setArguments(arguments);
    getFragmentManager().beginTransaction().replace(android.R.id.content, settingsFragment).commit();
}
Also used : Bundle(android.os.Bundle) PreferencesHelper(org.firstinspires.ftc.robotcore.internal.system.PreferencesHelper)

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