Esempio n. 1
1
    @Override
    public boolean onContextItemSelected(MenuItem item) {

      int posn = (int) ((AdapterContextMenuInfo) item.getMenuInfo()).position;
      Codec c = codecs.elementAt(posn);
      if (item.getItemId() == MENU_UP) {
        if (posn == 0) return super.onContextItemSelected(item);
        Codec tmp = codecs.elementAt(posn - 1);
        codecs.set(posn - 1, c);
        codecs.set(posn, tmp);
      } else if (item.getItemId() == MENU_DOWN) {
        if (posn == codecs.size() - 1) return super.onContextItemSelected(item);
        Codec tmp = codecs.elementAt(posn + 1);
        codecs.set(posn + 1, c);
        codecs.set(posn, tmp);
      }
      PreferenceScreen ps = getPreferenceScreen();
      SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext);
      String v = "";
      SharedPreferences.Editor e = sp.edit();

      for (Codec d : codecs) v = v + d.number() + " ";
      e.putString(Settings.PREF_CODECS, v);
      e.commit();
      ps.removeAll();
      addPreferences(ps);
      return super.onContextItemSelected(item);
    }
  private PreferenceScreen createPreferenceHierarchy() {
    PreferenceScreen root = getPreferenceScreen();
    if (root != null) {
      root.removeAll();
    }
    // Location Settings
    addPreferencesFromResource(R.xml.location_settings);

    addPreferencesFromResource(R.xml.security_settings);
    root = getPreferenceScreen();

    // Location Settings
    mNetwork = (CheckBoxPreference) root.findPreference(KEY_LOCATION_NETWORK);
    mGps = (CheckBoxPreference) root.findPreference(KEY_LOCATION_GPS);
    mAssistedGps = (CheckBoxPreference) root.findPreference(KEY_ASSISTED_GPS);
    if (GoogleLocationSettingHelper.isAvailable(getActivity())) {
      // GSF present, Add setting for 'Use My Location'
      CheckBoxPreference useLocation = new CheckBoxPreference(getActivity());
      useLocation.setKey(KEY_USE_LOCATION);
      useLocation.setTitle(R.string.use_location_title);
      useLocation.setSummary(R.string.use_location_summary);
      useLocation.setChecked(
          GoogleLocationSettingHelper.getUseLocationForServices(getActivity())
              == GoogleLocationSettingHelper.USE_LOCATION_FOR_SERVICES_ON);
      useLocation.setPersistent(false);
      useLocation.setOnPreferenceChangeListener(this);
      getPreferenceScreen().addPreference(useLocation);
      mUseLocation = useLocation;
    }

    // Change the summary for wifi-only devices
    if (Utils.isWifiOnly(getActivity())) {
      mNetwork.setSummaryOn(R.string.location_neighborhood_level_wifi);
    }

    // Security Settings
    // Add options for lock/unlock screen
    int resid = 0;
    if (!mLockPatternUtils.isSecure()) {
      if (mLockPatternUtils.isLockScreenDisabled()) {
        resid = R.xml.security_settings_lockscreen;
      } else {
        resid = R.xml.security_settings_chooser;
      }
    } else if (mLockPatternUtils.usingBiometricWeak()
        && mLockPatternUtils.isBiometricWeakInstalled()) {
      resid = R.xml.security_settings_biometric_weak;
    } else {
      switch (mLockPatternUtils.getKeyguardStoredPasswordQuality()) {
        case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
          resid = R.xml.security_settings_pattern;
          break;
        case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
          resid = R.xml.security_settings_pin;
          break;
        case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
        case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
        case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
          resid = R.xml.security_settings_password;
          break;
      }
    }
    addPreferencesFromResource(resid);

    boolean isSystemEmmcDetect = false;
    try {
      Class c = Class.forName(SYSTEM_DETECT_HANDLER);
      ISystemInfoDetectHandler handler = (ISystemInfoDetectHandler) c.newInstance();
      isSystemEmmcDetect = handler.isFileSystemAutoDetect();
      Log.i("SecuritySettings", "isSystemEmmcDetect = " + isSystemEmmcDetect);
    } catch (Exception e) {
      Log.i("SecuritySettings", "exception " + e);
      isSystemEmmcDetect = false;
    }
    if ((DefaultQuery.SYSTEM_INFO_DETECT_ENABLED == 1)
        || ((DefaultQuery.SYSTEM_INFO_DETECT_ENABLED == 2) && isSystemEmmcDetect)) {
      // Add options for device encryption
      DevicePolicyManager dpm =
          (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);

      switch (dpm.getStorageEncryptionStatus()) {
        case DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE:
          // The device is currently encrypted.
          addPreferencesFromResource(R.xml.security_settings_encrypted);
          break;
        case DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE:
          // This device supports encryption but isn't encrypted.
          addPreferencesFromResource(R.xml.security_settings_unencrypted);
          break;
      }
    }

    // lock after preference
    mLockAfter = (ListPreference) root.findPreference(KEY_LOCK_AFTER_TIMEOUT);
    if (mLockAfter != null) {
      setupLockAfterPreference();
      updateLockAfterPreferenceSummary();
    }

    // visible pattern
    mVisiblePattern = (CheckBoxPreference) root.findPreference(KEY_VISIBLE_PATTERN);

    // lock instantly on power key press
    mPowerButtonInstantlyLocks =
        (CheckBoxPreference) root.findPreference(KEY_POWER_INSTANTLY_LOCKS);

    // don't display visible pattern if biometric and backup is not
    // pattern
    if (resid == R.xml.security_settings_biometric_weak
        && mLockPatternUtils.getKeyguardStoredPasswordQuality()
            != DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) {
      PreferenceGroup securityCategory =
          (PreferenceGroup) root.findPreference(KEY_SECURITY_CATEGORY);
      if (securityCategory != null && mVisiblePattern != null) {
        securityCategory.removePreference(root.findPreference(KEY_VISIBLE_PATTERN));
      }
    }

    // tactile feedback. Should be common to all unlock preference
    // screens.
    mTactileFeedback = (CheckBoxPreference) root.findPreference(KEY_TACTILE_FEEDBACK_ENABLED);
    if (!((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).hasVibrator()) {
      PreferenceGroup securityCategory =
          (PreferenceGroup) root.findPreference(KEY_SECURITY_CATEGORY);
      if (securityCategory != null && mTactileFeedback != null) {
        securityCategory.removePreference(mTactileFeedback);
      }
    }

    // Append the rest of the settings
    addPreferencesFromResource(R.xml.security_settings_misc);

    MSimTelephonyManager tm = MSimTelephonyManager.getDefault();
    int numPhones = TelephonyManager.getDefault().getPhoneCount();
    boolean disableLock = false;
    for (int i = 0; i < numPhones; i++) {
      // Disable SIM lock if sim card is missing or unknown
      // notice:cdma can also set sim lock
      if ((tm.getSimState(i) == TelephonyManager.SIM_STATE_ABSENT)
          || (tm.getSimState(i) == TelephonyManager.SIM_STATE_UNKNOWN)) {
        disableLock = true;
      } else {
        disableLock = false;
        break;
      }
    }
    if (disableLock) {
      root.findPreference(KEY_SIM_LOCK).setEnabled(false);
    }

    // Show password
    mShowPassword = (CheckBoxPreference) root.findPreference(KEY_SHOW_PASSWORD);

    // SIM/RUIM lock
    Preference iccLock = (Preference) root.findPreference(KEY_SIM_LOCK_SETTINGS);

    Intent intent = new Intent();
    if (tm.isMultiSimEnabled()) {
      intent.setClassName(
          "com.android.settings", "com.android.settings.multisimsettings.MultiSimSettingTab");
      intent.putExtra(SelectSubscription.PACKAGE, "com.android.settings");
      intent.putExtra(SelectSubscription.TARGET_CLASS, "com.android.settings.IccLockSettings");
    } else {
      intent.setClassName("com.android.settings", "com.android.settings.IccLockSettings");
    }
    iccLock.setIntent(intent);

    // Credential storage
    mResetCredentials = root.findPreference(KEY_RESET_CREDENTIALS);

    mToggleAppInstallation = (CheckBoxPreference) findPreference(KEY_TOGGLE_INSTALL_APPLICATIONS);
    mToggleAppInstallation.setChecked(isNonMarketAppsAllowed());

    return root;
  }
  protected void hardRefresh() {
    // This is the only way to guarantee that the EditText dialogs created by
    // EditTextPreferences are re-created. This works around the issue described
    // at http://androiddev.orkitra.com/?p=112079.
    final PreferenceScreen statusScreen = (PreferenceScreen) ensureFindPreference("status_screen");
    statusScreen.removeAll();
    addPreferences();

    refresh();
  }
Esempio n. 4
0
 private void updatePreferencesOrFinish() {
   Intent intent = getActivity().getIntent();
   int quality = intent.getIntExtra(LockPatternUtils.PASSWORD_TYPE_KEY, -1);
   if (quality == -1) {
     // If caller didn't specify password quality, show UI and allow the user to choose.
     quality = intent.getIntExtra(MINIMUM_QUALITY_KEY, -1);
     quality = upgradeQuality(quality);
     final PreferenceScreen prefScreen = getPreferenceScreen();
     if (prefScreen != null) {
       prefScreen.removeAll();
     }
     addPreferencesFromResource(R.xml.security_settings_picker);
     disableUnusablePreferences(quality);
   } else {
     updateUnlockMethodAndFinish(quality, false);
   }
 }
  private PreferenceScreen createPreferenceHierarchy() {
    PreferenceScreen root = getPreferenceScreen();
    if (root != null) {
      root.removeAll();
    }
    addPreferencesFromResource(R.xml.location_settings);
    root = getPreferenceScreen();

    mLocationAccess = (SwitchPreference) root.findPreference(KEY_LOCATION_TOGGLE);
    mNetwork = (CheckBoxPreference) root.findPreference(KEY_LOCATION_NETWORK);
    mGps = (CheckBoxPreference) root.findPreference(KEY_LOCATION_GPS);
    mAssistedGps = (CheckBoxPreference) root.findPreference(KEY_ASSISTED_GPS);
    mGpsDownloadDataWifiOnly =
        (CheckBoxPreference) root.findPreference(KEY_GPS_DOWNLOAD_DATA_WIFI_ONLY);

    // Only enable these controls if this user is allowed to change location
    // sharing settings.
    final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
    boolean isToggleAllowed = !um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION);
    if (mLocationAccess != null) mLocationAccess.setEnabled(isToggleAllowed);
    if (mNetwork != null) mNetwork.setEnabled(isToggleAllowed);
    if (mGps != null) mGps.setEnabled(isToggleAllowed);
    if (mAssistedGps != null) mAssistedGps.setEnabled(isToggleAllowed);
    if (mGpsDownloadDataWifiOnly != null) mGpsDownloadDataWifiOnly.setEnabled(isToggleAllowed);

    if (!LongTermOrbits.isSupported()) {
      root.removePreference(mGpsDownloadDataWifiOnly);
      mGpsDownloadDataWifiOnly = null;
    } else {
      if (saveDownloadDataWifiOnlyPref(getActivity())) {
        root.removePreference(mGpsDownloadDataWifiOnly);
        mGpsDownloadDataWifiOnly = null;
      }
    }

    mLocationAccess.setOnPreferenceChangeListener(this);
    return root;
  }
  private PreferenceScreen createCustomView() {
    mCheckPreferences = false;
    PreferenceScreen prefSet = getPreferenceScreen();
    if (prefSet != null) {
      prefSet.removeAll();
    }

    addPreferencesFromResource(R.xml.status_bar_clock_style);
    prefSet = getPreferenceScreen();

    PackageManager pm = getPackageManager();
    Resources systemUiResources;
    try {
      systemUiResources = pm.getResourcesForApplication("com.android.systemui");
    } catch (Exception e) {
      Log.e(TAG, "can't access systemui resources", e);
      return null;
    }

    mClockStyle = (ListPreference) findPreference(PREF_ENABLE);
    mClockStyle.setOnPreferenceChangeListener(this);
    mClockStyle.setValue(
        Integer.toString(
            Settings.System.getInt(
                getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_STYLE, 0)));
    mClockStyle.setSummary(mClockStyle.getEntry());

    mClockAmPmStyle = (ListPreference) prefSet.findPreference(PREF_AM_PM_STYLE);
    mClockAmPmStyle.setOnPreferenceChangeListener(this);
    mClockAmPmStyle.setValue(
        Integer.toString(
            Settings.System.getInt(
                getActivity().getContentResolver(),
                Settings.System.STATUSBAR_CLOCK_AM_PM_STYLE,
                0)));
    boolean is24hour = DateFormat.is24HourFormat(getActivity());
    if (is24hour) {
      mClockAmPmStyle.setSummary(R.string.status_bar_am_pm_info);
    } else {
      mClockAmPmStyle.setSummary(mClockAmPmStyle.getEntry());
    }
    mClockAmPmStyle.setEnabled(!is24hour);

    mColorPicker = (ColorPickerPreference) findPreference(PREF_COLOR_PICKER);
    mColorPicker.setOnPreferenceChangeListener(this);
    int intColor =
        Settings.System.getInt(
            getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_COLOR, -2);
    if (intColor == -2) {
      intColor =
          systemUiResources.getColor(
              systemUiResources.getIdentifier(
                  "com.android.systemui:color/status_bar_clock_color", null, null));
      mColorPicker.setSummary(getResources().getString(R.string.default_string));
    } else {
      String hexColor = String.format("#%08x", (0xffffffff & intColor));
      mColorPicker.setSummary(hexColor);
    }
    mColorPicker.setNewPreviewColor(intColor);

    mClockDateDisplay = (ListPreference) findPreference(PREF_CLOCK_DATE_DISPLAY);
    mClockDateDisplay.setOnPreferenceChangeListener(this);
    mClockDateDisplay.setValue(
        Integer.toString(
            Settings.System.getInt(
                getActivity().getContentResolver(),
                Settings.System.STATUSBAR_CLOCK_DATE_DISPLAY,
                0)));
    mClockDateDisplay.setSummary(mClockDateDisplay.getEntry());

    mClockDateStyle = (ListPreference) findPreference(PREF_CLOCK_DATE_STYLE);
    mClockDateStyle.setOnPreferenceChangeListener(this);
    mClockDateStyle.setValue(
        Integer.toString(
            Settings.System.getInt(
                getActivity().getContentResolver(),
                Settings.System.STATUSBAR_CLOCK_DATE_STYLE,
                2)));
    mClockDateStyle.setSummary(mClockDateStyle.getEntry());

    mClockDateFormat = (ListPreference) findPreference(PREF_CLOCK_DATE_FORMAT);
    mClockDateFormat.setOnPreferenceChangeListener(this);
    if (mClockDateFormat.getValue() == null) {
      mClockDateFormat.setValue("EEE");
    }

    parseClockDateFormats();

    mStatusBarClock = (CheckBoxPreference) prefSet.findPreference(STATUS_BAR_CLOCK);
    mStatusBarClock.setChecked(
        (Settings.System.getInt(
                getActivity().getApplicationContext().getContentResolver(),
                Settings.System.STATUS_BAR_CLOCK,
                1)
            == 1));
    mStatusBarClock.setOnPreferenceChangeListener(this);

    boolean mClockDateToggle =
        Settings.System.getInt(
                getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_DISPLAY, 0)
            != 0;
    if (!mClockDateToggle) {
      mClockDateStyle.setEnabled(false);
      mClockDateFormat.setEnabled(false);
    }

    setHasOptionsMenu(true);
    mCheckPreferences = true;
    return prefSet;
  }
Esempio n. 7
0
  private static void setupPreferences(PreferenceActivity context) {
    // create Categories
    PreferenceScreen prefScreen = context.getPreferenceManager().createPreferenceScreen(context);
    prefScreen.removeAll();

    // selected location category
    PreferenceCategory selectedCat = new PreferenceCategory(context);
    selectedCat.setTitle(R.string.selected_location_str);
    // location list category
    PreferenceCategory locationListCat = new PreferenceCategory(context);
    locationListCat.setTitle(R.string.location_list_str);
    // general category
    PreferenceCategory generalCat = new PreferenceCategory(context);
    generalCat.setTitle(R.string.general_preferences_str);
    //		//gesture category
    //		PreferenceCategory gestureCat = new PreferenceCategory(context);
    //		gestureCat.setTitle(R.string.gesture_settings_str);

    // add categories to preference screen
    prefScreen.addPreference(selectedCat);
    prefScreen.addPreference(locationListCat);
    //		prefScreen.addPreference(gestureCat);
    prefScreen.addPreference(generalCat);

    // Create add and delete location preferences and add to location list
    locationListCat.addPreference(
        createAddLocationPreference(
            context,
            context.getString(R.string.add_location_str),
            context.getString(R.string.add_location_description_str)));
    locationListCat.addPreference(
        createDeleteLocationPreference(
            context,
            context.getString(R.string.delete_location_str),
            context.getString(R.string.delete_location_description_str)));

    // create apptheme action preference
    generalCat.addPreference(
        createIntListPreference(
            context,
            PREF_APP_THEME,
            R.string.pref_app_theme,
            R.string.pref_app_theme_description,
            R.array.app_theme_strings,
            R.array.app_theme_values,
            "0"));

    // create mythfrontend update status interval preference
    generalCat.addPreference(
        createIntListPreference(
            context,
            PREF_STATUS_UPDATE_INTERVAL,
            R.string.status_update_interval_str,
            R.string.status_update_interval_description_str,
            R.array.status_Update_Interval_strings,
            R.array.status_Update_Interval_values,
            "0"));

    // create haptic feedback shared preference
    generalCat.addPreference(
        createCheckBox(
            context,
            PREF_HAPTIC_FEEDBACK_ENABLED,
            R.string.haptic_feedback_enabled_str,
            R.string.haptic_feedback_enabled_description_str,
            false));

    // create longpress action preference
    generalCat.addPreference(
        createIntListPreference(
            context,
            PREF_LONGPRESS_ACTION,
            R.string.longpress_action_str,
            R.string.longpress_action_description_str,
            R.array.longpress_action_strings,
            R.array.longpress_action_values,
            "0"));

    // create key repeat interval preference
    generalCat.addPreference(
        createIntListPreference(
            context,
            PREF_KEY_REPEAT_INTERVAL,
            R.string.key_repeat_interval_str,
            R.string.key_repeat_interval_description_str,
            R.array.key_repeat_interval_strings,
            R.array.key_repeat_interval_values,
            "100"));

    // create connection timeout interval preference
    generalCat.addPreference(
        createIntListPreference(
            context,
            PREF_CONNECTION_TIMEOUT_INTERVAL,
            R.string.conection_timeout_interval_str,
            R.string.conection_timeout_interval_description_str,
            R.array.connection_timeout_interval_strings,
            R.array.connection_timeout_interval_values,
            "5000"));

    // create donate button visible checkbox
    generalCat.addPreference(
        createCheckBox(
            context,
            PREF_SHOW_DONATE_MENU_ITEM,
            R.string.show_donate_menu_item_str,
            R.string.show_donate_menu_item_str,
            true));

    //		//create gestures enabled
    //		gestureCat.addPreference(createCheckBox(context,
    //				PREF_GESTURES_ENABLED,
    //				R.string.gestures_enabled_str,
    //				R.string.gestures_enabled_str, false));
    //
    //		//gesture list preference
    //		Preference gestureList = createGestureListPreference(context);
    //		gestureCat.addPreference(gestureList);

    // open DB
    MythMoteDbManager _dbAdapter = new MythMoteDbManager(context);
    _dbAdapter.open();

    // get list of locations
    Cursor cursor = _dbAdapter.fetchAllFrontendLocations();

    // get column indexes
    sIdIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_ROWID);
    sAddressIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_ADDRESS);
    sNameIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_NAME);
    sPortIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_PORT);
    sMacIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_MAC);
    sWifiOnlyIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_WIFIONLY);

    // determine if we have locations saved
    int count = cursor.getCount();
    if (count > 0 && cursor.moveToFirst()) {
      // get selected frontend id
      int selected =
          context
              .getSharedPreferences(MYTHMOTE_SHARED_PREFERENCES_ID, MODE_PRIVATE)
              .getInt(MythMotePreferences.PREF_SELECTED_LOCATION, -1);

      // if selected failed
      if (selected == -1) {
        // set to first in list
        selected = cursor.getInt(sIdIndex);
        // save (defaulted) selected location
        SaveSelectedLocationId(context, selected);
      }

      // put each location in the preference list
      for (int i = 0; i < count; i++) {
        locationListCat.addPreference(
            MythMotePreferences.createLocationPreference(
                context,
                cursor.getString(sIdIndex),
                cursor.getString(sNameIndex),
                cursor.getString(sAddressIndex)));

        if (cursor.getInt(sIdIndex) == selected) {
          // create preference for selected location
          selectedCat.addPreference(
              MythMotePreferences.createSelectedLocationPreference(
                  context,
                  context.getString(R.string.selected_location_str),
                  cursor.getString(sNameIndex)));
        }

        cursor.moveToNext();
      }

      // the saved selected location was not found just pick the first one
      if (selectedCat.getPreferenceCount() <= 0) {
        cursor.moveToFirst();
        selectedCat.addPreference(
            MythMotePreferences.createSelectedLocationPreference(
                context,
                context.getString(R.string.selected_location_str),
                cursor.getString(sNameIndex)));

        // save location ID so that it is for real
        SaveSelectedLocationId(context, cursor.getInt(sIdIndex));
      }
    } else {
      selectedCat.addPreference(
          MythMotePreferences.createSelectedLocationPreference(
              context,
              context.getString(R.string.selected_location_str),
              context.getString(R.string.no_frontend_locations_defined_str)));
    }

    cursor.close();
    _dbAdapter.close();

    // set preference screen
    context.setPreferenceScreen(prefScreen);

    // Assign dependences
    //		gestureList.setDependency(PREF_GESTURES_ENABLED);
  }