Ejemplo n.º 1
0
  private void enableAll() {
    hostText.setEnabled(true);

    if (!isPACCheck.isChecked()) {
      portText.setEnabled(true);
      proxyTypeList.setEnabled(true);
    }

    bypassAddrs.setEnabled(true);

    if (isAuthCheck.isChecked()) {
      userText.setEnabled(true);
      passwordText.setEnabled(true);
      isNTLMCheck.setEnabled(true);
      if (isNTLMCheck.isChecked()) domainText.setEnabled(true);
    }
    if ("https".equals(proxyTypeList.getValue())) {
      certificateText.setEnabled(true);
    }
    if (!isAutoSetProxyCheck.isChecked()) {
      proxyedApps.setEnabled(true);
      isBypassAppsCheck.setEnabled(true);
    }
    if (isAutoConnectCheck.isChecked()) ssidList.setEnabled(true);

    isDNSProxyCheck.setEnabled(true);
    profileList.setEnabled(true);
    isAutoSetProxyCheck.setEnabled(true);
    isAuthCheck.setEnabled(true);
    isAutoConnectCheck.setEnabled(true);
    isPACCheck.setEnabled(true);
  }
  @TargetApi(Build.VERSION_CODES.GINGERBREAD)
  @SuppressWarnings("deprecation")
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Ensure we have a camera!
    PackageManager pm = this.getPackageManager();
    if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
      finish();
      return;
    }

    addPreferencesFromResource(R.xml.preferences);
    cameraIndexPreference = (ListPreference) findPreference("pref_cameraIndex");
    cameraResolutionPreference = (ListPreference) findPreference("pref_cameraResolution");

    // One time only, we need to build a list of cameras. If more than
    // one camera, enable the cameraIndexPreference. Otherwise, disable it.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
      cameraCount = Camera.getNumberOfCameras();
      Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
      int cameraCountFront = 0;
      int cameraCountRear = 0;
      CharSequence[] entries = new CharSequence[cameraCount];
      CharSequence[] entryValues = new CharSequence[cameraCount];
      for (int camIndex = 0; camIndex < cameraCount; camIndex++) {
        Camera.getCameraInfo(camIndex, cameraInfo);
        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
          cameraCountFront++;
          entries[camIndex] = "Front camera";
          if (cameraCountFront > 1) entries[camIndex] = entries[camIndex] + " " + cameraCountFront;
        } else {
          cameraCountRear++;
          entries[camIndex] = "Rear camera";
          if (cameraCountRear > 1) entries[camIndex] = entries[camIndex] + " " + cameraCountRear;
        }
        entryValues[camIndex] = Integer.toString(camIndex);
      }
      cameraIndexPreference.setEnabled(true);
      cameraIndexPreference.setEntries(entries);
      cameraIndexPreference.setEntryValues(entryValues);
    } else {
      cameraCount = 1;
      cameraIndexPreference.setEnabled(false);
    }

    buildResolutionListForCameraIndex();
  }
 private void updateNetworkTrafficState(int mIndex) {
   if (mIndex <= 0) {
     mNetTrafficUnit.setEnabled(false);
     mNetTrafficColor.setEnabled(false);
     mNetTrafficPeriod.setEnabled(false);
     mNetTrafficAutohide.setEnabled(false);
     mNetTrafficAutohideThreshold.setEnabled(false);
   } else {
     mNetTrafficUnit.setEnabled(true);
     mNetTrafficColor.setEnabled(true);
     mNetTrafficPeriod.setEnabled(true);
     mNetTrafficAutohide.setEnabled(true);
     mNetTrafficAutohideThreshold.setEnabled(true);
   }
 }
 private void disableUnusableTimeouts(long maxTimeout) {
   final CharSequence[] entries = mLockAfter.getEntries();
   final CharSequence[] values = mLockAfter.getEntryValues();
   ArrayList<CharSequence> revisedEntries = new ArrayList<CharSequence>();
   ArrayList<CharSequence> revisedValues = new ArrayList<CharSequence>();
   for (int i = 0; i < values.length; i++) {
     long timeout = Long.valueOf(values[i].toString());
     if (timeout <= maxTimeout) {
       revisedEntries.add(entries[i]);
       revisedValues.add(values[i]);
     }
   }
   if (revisedEntries.size() != entries.length || revisedValues.size() != values.length) {
     mLockAfter.setEntries(revisedEntries.toArray(new CharSequence[revisedEntries.size()]));
     mLockAfter.setEntryValues(revisedValues.toArray(new CharSequence[revisedValues.size()]));
     final int userPreference = Integer.valueOf(mLockAfter.getValue());
     if (userPreference <= maxTimeout) {
       mLockAfter.setValue(String.valueOf(userPreference));
     } else {
       // There will be no highlighted selection since nothing in the list matches
       // maxTimeout. The user can still select anything less than maxTimeout.
       // TODO: maybe append maxTimeout to the list and mark selected.
     }
   }
   mLockAfter.setEnabled(revisedEntries.size() > 0);
 }
 private void disableUnusableTimeouts(ListPreference screenTimeoutPreference) {
   final DevicePolicyManager dpm =
       (DevicePolicyManager) getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
   final long maxTimeout = dpm != null ? dpm.getMaximumTimeToLock(null) : 0;
   if (maxTimeout == 0) {
     return; // policy not enforced
   }
   final CharSequence[] entries = screenTimeoutPreference.getEntries();
   final CharSequence[] values = screenTimeoutPreference.getEntryValues();
   ArrayList<CharSequence> revisedEntries = new ArrayList<CharSequence>();
   ArrayList<CharSequence> revisedValues = new ArrayList<CharSequence>();
   for (int i = 0; i < values.length; i++) {
     long timeout = Long.parseLong(values[i].toString());
     if (timeout <= maxTimeout) {
       revisedEntries.add(entries[i]);
       revisedValues.add(values[i]);
     }
   }
   if (revisedEntries.size() != entries.length || revisedValues.size() != values.length) {
     screenTimeoutPreference.setEntries(
         revisedEntries.toArray(new CharSequence[revisedEntries.size()]));
     screenTimeoutPreference.setEntryValues(
         revisedValues.toArray(new CharSequence[revisedValues.size()]));
     final int userPreference = Integer.parseInt(screenTimeoutPreference.getValue());
     if (userPreference <= maxTimeout) {
       screenTimeoutPreference.setValue(String.valueOf(userPreference));
     } else {
       // There will be no highlighted selection since nothing in the list matches
       // maxTimeout. The user can still select anything less than maxTimeout.
       // TODO: maybe append maxTimeout to the list and mark selected.
     }
   }
   screenTimeoutPreference.setEnabled(revisedEntries.size() > 0);
 }
 public void refreshSettings() {
   refreshButtons();
   if (!isTablet(mContext)) {
     mDragHandleOpacity.setEnabled(mNavBarHideEnable.isChecked());
     mDragHandleWidth.setEnabled(mNavBarHideEnable.isChecked());
     mNavBarHideTimeout.setEnabled(mNavBarHideEnable.isChecked());
   }
 }
Ejemplo n.º 7
0
 @Override
 public boolean onPreferenceChange(Preference preference, Object newValue) {
   if (preference == mCheckBoxPreference) {
     Utilities.writeAutoCheck(mContext, (Boolean) newValue);
     if ((Boolean) newValue) {
       mListPreference.setEnabled(true);
     } else {
       mListPreference.setEnabled(false);
     }
   } else if (preference == mListPreference) {
     mListPreference.setSummary(
         getResources().getString(R.string.checkfrequency_summary)
             + (String) newValue
             + getResources().getString(R.string.day));
     Utilities.writeCheckFrequency(mContext, Integer.valueOf((String) newValue).intValue());
   }
   return true;
 }
Ejemplo n.º 8
0
  private void update() {
    enableListeners(false);

    List<LanguageData> languages = TtsPlayer.INSTANCE.refreshLanguages();
    mLanguages.clear();
    mCurrentLanguage = null;

    if (languages.isEmpty()) {
      mPrefEnabled.setChecked(false);
      mPrefEnabled.setEnabled(false);
      mPrefEnabled.setSummary(R.string.pref_tts_unavailable);
      mPrefLanguages.setEnabled(false);
      mPrefLanguages.setSummary(null);

      enableListeners(true);
      return;
    }

    mPrefEnabled.setChecked(TtsPlayer.INSTANCE.isEnabled());
    mPrefEnabled.setSummary(null);

    final CharSequence[] entries = new CharSequence[languages.size()];
    final CharSequence[] values = new CharSequence[languages.size()];
    for (int i = 0; i < languages.size(); i++) {
      LanguageData lang = languages.get(i);
      entries[i] = lang.name;
      values[i] = lang.internalCode;

      mLanguages.put(lang.internalCode, lang);
    }

    mPrefLanguages.setEntries(entries);
    mPrefLanguages.setEntryValues(values);

    mCurrentLanguage = TtsPlayer.getSelectedLanguage(languages);
    boolean available = (mCurrentLanguage != null && mCurrentLanguage.downloaded);
    mPrefLanguages.setEnabled(available && TtsPlayer.INSTANCE.isEnabled());
    mPrefLanguages.setSummary(available ? mCurrentLanguage.name : null);
    mPrefLanguages.setValue(available ? mCurrentLanguage.internalCode : null);
    mPrefEnabled.setChecked(available && TtsPlayer.INSTANCE.isEnabled());

    enableListeners(true);
  }
Ejemplo n.º 9
0
  private void disableAll() {
    hostText.setEnabled(false);
    portText.setEnabled(false);
    userText.setEnabled(false);
    passwordText.setEnabled(false);
    domainText.setEnabled(false);
    ssidList.setEnabled(false);
    proxyTypeList.setEnabled(false);
    proxyedApps.setEnabled(false);
    profileList.setEnabled(false);
    bypassAddrs.setEnabled(false);

    isAuthCheck.setEnabled(false);
    isNTLMCheck.setEnabled(false);
    isDNSProxyCheck.setEnabled(false);
    isAutoSetProxyCheck.setEnabled(false);
    isAutoConnectCheck.setEnabled(false);
    isPACCheck.setEnabled(false);
    isBypassAppsCheck.setEnabled(false);
  }
Ejemplo n.º 10
0
 /*
  * M: update ipv4&ipv6 setting preference
  */
 private void updateIpv6Preference() {
   if (mTetherIpv6 != null) {
     mTetherIpv6.setEnabled(
         !mUsbTether.isChecked() && !mBluetoothTether.isChecked() && !mWifiTether.isChecked());
     ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
     if (cm != null) {
       int ipv6Value = cm.getTetheringIpv6Enable() ? 1 : 0;
       mTetherIpv6.setValueIndex(ipv6Value);
       mTetherIpv6.setSummary(
           getResources().getStringArray(R.array.tethered_ipv6_entries)[ipv6Value]);
     }
   }
 }
Ejemplo n.º 11
0
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
          Statistics.INSTANCE.trackEvent(
              Statistics.EventName.Settings.VOICE_ENABLED,
              Statistics.params().add(Statistics.EventParam.ENABLED, newValue.toString()));
          boolean set = (Boolean) newValue;
          if (!set) {
            TtsPlayer.setEnabled(false);
            mPrefLanguages.setEnabled(false);
            return true;
          }

          if (mCurrentLanguage != null && mCurrentLanguage.downloaded) {
            setLanguage(mCurrentLanguage);
            return true;
          }

          mPrefLanguages.setEnabled(true);
          getPreferenceScreen().onItemClick(null, null, mPrefLanguages.getOrder(), 0);
          mPrefLanguages.setEnabled(false);
          return false;
        }
Ejemplo n.º 12
0
 @Override
 public boolean onPreferenceTreeClick(PreferenceScreen ps, Preference p) {
   ListPreference l = (ListPreference) p;
   for (Codec c : codecs)
     if (c.key().equals(l.getKey())) {
       c.init();
       if (!c.isLoaded()) {
         l.setValue("never");
         c.fail();
         l.setEnabled(false);
         l.setSummary(l.getEntry());
         if (l.getDialog() != null) l.getDialog().dismiss();
       }
     }
   return super.onPreferenceTreeClick(ps, p);
 }
Ejemplo n.º 13
0
  public void onAlbumsLoaded(Account account, List<Album> albums) {
    String[] entries = new String[albums.size()];
    String[] entryValues = new String[albums.size()];

    for (int i = 0, z = albums.size(); i < z; i++) {
      final Album album = albums.get(i);
      entries[i] = album.getName();
      entryValues[i] = album.getId();
    }

    ListPreference albumsPref =
        (ListPreference) findPreference(PreferenceConstants.PREF_INSTANT_UPLOAD_ALBUM_ID);

    albumsPref.setEntries(entries);
    albumsPref.setEntryValues(entryValues);
    albumsPref.setEnabled(true);
  }
Ejemplo n.º 14
0
  private static void addPreferences(PreferenceScreen ps) {
    Context cx = ps.getContext();
    Resources r = cx.getResources();
    ps.setOrderingAsAdded(true);

    for (Codec c : codecs) {
      ListPreference l = new ListPreference(cx);
      l.setEntries(r.getStringArray(R.array.compression_display_values));
      l.setEntryValues(r.getStringArray(R.array.compression_values));
      l.setKey(c.key());
      l.setPersistent(true);
      l.setEnabled(!c.isFailed());
      c.setListPreference(l);
      l.setSummary(l.getEntry());
      l.setTitle(c.getTitle());
      ps.addPreference(l);
    }
  }
Ejemplo n.º 15
0
  public void findView() {
    mCheckBoxPreference = (CheckBoxPreference) findPreference("setcheckbox");
    mCheckBoxPreference.setOnPreferenceChangeListener(this);

    mListPreference = (ListPreference) findPreference("setfrequency");
    mListPreference.setOnPreferenceChangeListener(this);

    String summary =
        PreferenceManager.getDefaultSharedPreferences(this)
            .getString(mListPreference.getKey(), Utilities.readCheckFrequency(mContext) + "");
    mListPreference.setSummary(
        getResources().getString(R.string.checkfrequency_summary)
            + summary
            + getResources().getString(R.string.day));

    if (Utilities.readAutoCheck(mContext)) {
      mCheckBoxPreference.setChecked(Utilities.readAutoCheck(mContext));
    } else {
      mListPreference.setEnabled(false);
    }
  }
Ejemplo n.º 16
0
    private void refresh() {
      final ListPreference autoSilencePref = (ListPreference) findPreference(KEY_AUTO_SILENCE);
      String delay = autoSilencePref.getValue();
      updateAutoSnoozeSummary(autoSilencePref, delay);
      autoSilencePref.setOnPreferenceChangeListener(this);

      final ListPreference clockStylePref = (ListPreference) findPreference(KEY_CLOCK_STYLE);
      clockStylePref.setSummary(clockStylePref.getEntry());
      clockStylePref.setOnPreferenceChangeListener(this);

      final Preference autoHomeClockPref = findPreference(KEY_AUTO_HOME_CLOCK);
      final boolean autoHomeClockEnabled = ((CheckBoxPreference) autoHomeClockPref).isChecked();
      autoHomeClockPref.setOnPreferenceChangeListener(this);

      final ListPreference homeTimezonePref = (ListPreference) findPreference(KEY_HOME_TZ);
      homeTimezonePref.setEnabled(autoHomeClockEnabled);
      homeTimezonePref.setSummary(homeTimezonePref.getEntry());
      homeTimezonePref.setOnPreferenceChangeListener(this);

      final ListPreference volumeButtonsPref = (ListPreference) findPreference(KEY_VOLUME_BUTTONS);
      volumeButtonsPref.setSummary(volumeButtonsPref.getEntry());
      volumeButtonsPref.setOnPreferenceChangeListener(this);

      final Preference volumePref = findPreference(KEY_ALARM_VOLUME);
      volumePref.setOnPreferenceClickListener(this);

      final SnoozeLengthDialog snoozePref = (SnoozeLengthDialog) findPreference(KEY_ALARM_SNOOZE);
      snoozePref.setSummary();

      final ListPreference weekStartPref = (ListPreference) findPreference(KEY_WEEK_START);
      // Set the default value programmatically
      final String value = weekStartPref.getValue();
      final int idx =
          weekStartPref.findIndexOfValue(
              value == null ? String.valueOf(Utils.DEFAULT_WEEK_START) : value);
      weekStartPref.setValueIndex(idx);
      weekStartPref.setSummary(weekStartPref.getEntries()[idx]);
      weekStartPref.setOnPreferenceChangeListener(this);
    }
Ejemplo n.º 17
0
  private void enableDisableAllCbConfigButtons(boolean enable) {
    mButtonEmergencyBroadcast.setEnabled(enable);
    mListLanguage.setEnabled(enable);
    mButtonAdministrative.setEnabled(enable);
    mButtonMaintenance.setEnabled(enable);
    mButtonLocalWeather.setEnabled(enable);
    mButtonAtr.setEnabled(enable);
    mButtonLafs.setEnabled(enable);
    mButtonRestaurants.setEnabled(enable);
    mButtonLodgings.setEnabled(enable);
    mButtonRetailDirectory.setEnabled(enable);
    mButtonAdvertisements.setEnabled(enable);
    mButtonStockQuotes.setEnabled(enable);
    mButtonEo.setEnabled(enable);
    mButtonMhh.setEnabled(enable);
    mButtonTechnologyNews.setEnabled(enable);
    mButtonMultiCategory.setEnabled(enable);

    mButtonLocal1.setEnabled(enable);
    mButtonRegional1.setEnabled(enable);
    mButtonNational1.setEnabled(enable);
    mButtonInternational1.setEnabled(enable);

    mButtonLocal2.setEnabled(enable);
    mButtonRegional2.setEnabled(enable);
    mButtonNational2.setEnabled(enable);
    mButtonInternational2.setEnabled(enable);

    mButtonLocal3.setEnabled(enable);
    mButtonRegional3.setEnabled(enable);
    mButtonNational3.setEnabled(enable);
    mButtonInternational3.setEnabled(enable);

    mButtonLocal4.setEnabled(enable);
    mButtonRegional4.setEnabled(enable);
    mButtonNational4.setEnabled(enable);
    mButtonInternational4.setEnabled(enable);
  }
Ejemplo n.º 18
0
 public static ListPreference List(
     Context paramContext,
     PreferenceCategory paramPreferenceCategory,
     String paramString1,
     String paramString2,
     String paramString3,
     String paramString4,
     Object paramObject,
     CharSequence[] paramArrayOfCharSequence1,
     CharSequence[] paramArrayOfCharSequence2,
     boolean paramBoolean) {
   ListPreference localListPreference = new ListPreference(paramContext);
   localListPreference.setTitle(paramString1);
   localListPreference.setSummary(paramString2);
   localListPreference.setEnabled(paramBoolean);
   localListPreference.setKey(paramString4);
   localListPreference.setDefaultValue(paramObject);
   localListPreference.setDialogTitle(paramString3);
   localListPreference.setEntries(paramArrayOfCharSequence1);
   localListPreference.setEntryValues(paramArrayOfCharSequence2);
   paramPreferenceCategory.addPreference(localListPreference);
   return localListPreference;
 }
Ejemplo n.º 19
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    listPreference = (ListPreference) findPreference(PREF_KEY_NOTIFICATION_FREQUENCY_TOGGLE);
    prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
    boolean isDaily = prefs.getBoolean(AlarmsUtility.PREF_ALARM_DAILY, false);

    // Set the default or previously selected value
    listPreference.setSummary(
        getString(R.string.text_configured)
            + (isDaily ? getString(R.string.text_daily) : getString(R.string.text_weekly)));
    listPreference.setValueIndex(isDaily ? 1 : 0);

    listPreference.setEnabled(
        ((CheckBoxPreference) findPreference(PREF_KEY_NOTIFICATION_TOGGLE)).isChecked());

    getPreferenceManager().setSharedPreferencesMode(Context.MODE_MULTI_PROCESS);
    getPreferenceScreen()
        .getSharedPreferences()
        .registerOnSharedPreferenceChangeListener(mSharePrefListener);
  }
Ejemplo n.º 20
0
  private void updateUsbState(String[] available, String[] tethered, String[] errored) {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    boolean usbAvailable = mUsbConnected && !mMassStorageActive;
    int usbError = ConnectivityManager.TETHER_ERROR_NO_ERROR;
    /// M: @{
    int usbErrorIpv4;
    int usbErrorIpv6;
    if (FeatureOption.MTK_TETHERINGIPV6_SUPPORT) {
      usbErrorIpv4 = ConnectivityManager.TETHER_ERROR_NO_ERROR;
      usbErrorIpv6 = ConnectivityManager.TETHER_ERROR_IPV6_NO_ERROR;
    }
    /// @}
    for (String s : available) {
      for (String regex : mUsbRegexs) {
        if (s.matches(regex) && cm != null) {
          if (FeatureOption.MTK_TETHERINGIPV6_SUPPORT) {
            /// M: @{
            if (usbErrorIpv4 == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
              usbErrorIpv4 = (cm.getLastTetherError(s) & 0x0f);
            }
            if (usbErrorIpv6 == ConnectivityManager.TETHER_ERROR_IPV6_NO_ERROR) {
              usbErrorIpv6 = (cm.getLastTetherError(s) & 0xf0);
            }
            /// @}
          } else {
            if (usbError == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
              usbError = cm.getLastTetherError(s);
            }
          }
        }
      }
    }
    boolean usbTethered = false;
    for (String s : tethered) {
      for (String regex : mUsbRegexs) {
        if (s.matches(regex)) {
          usbTethered = true;
          /// M: @{
          if (FeatureOption.MTK_TETHERINGIPV6_SUPPORT && cm != null) {
            if (usbErrorIpv6 == ConnectivityManager.TETHER_ERROR_IPV6_NO_ERROR) {
              usbErrorIpv6 = (cm.getLastTetherError(s) & 0xf0);
            }
          }
          /// @}
        }
      }
    }

    boolean usbErrored = false;
    for (String s : errored) {
      for (String regex : mUsbRegexs) {
        if (s.matches(regex)) {
          usbErrored = true;
        }
      }
    }

    Xlog.d(
        TAG,
        "updateUsbState - usbTethered : "
            + usbTethered
            + " usbErrored: "
            + usbErrored
            + " usbAvailable: "
            + usbAvailable);

    if (usbTethered) {
      Xlog.d(TAG, "updateUsbState: usbTethered ! mUsbTether checkbox setEnabled & checked ");
      mUsbTether.setEnabled(true);
      mUsbTether.setChecked(true);
      /// M: set usb tethering to false @{
      final String summary = getString(R.string.usb_tethering_active_subtext);
      if (FeatureOption.MTK_TETHERINGIPV6_SUPPORT) {
        mUsbTether.setSummary(summary + getIPV6String(usbErrorIpv4, usbErrorIpv6));
      } else {
        mUsbTether.setSummary(summary);
      }
      mUsbTethering = false;
      mUsbTetherType.setEnabled(false);
      Xlog.d(TAG, "updateUsbState - usbTethered - mUsbTetherCheckEnable: " + mUsbTetherCheckEnable);
      /// @}
    } else if (usbAvailable) {
      /// M: update summary @{
      if (FeatureOption.MTK_TETHERINGIPV6_SUPPORT) {
        if (usbErrorIpv4 == ConnectivityManager.TETHER_ERROR_NO_ERROR
            || usbErrorIpv4 == ConnectivityManager.TETHER_ERROR_IPV6_NO_ERROR) {
          mUsbTether.setSummary(R.string.usb_tethering_available_subtext);
        } else {
          mUsbTether.setSummary(R.string.usb_tethering_errored_subtext);
        }
      } else {
        ///  @}
        if (usbError == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
          mUsbTether.setSummary(R.string.usb_tethering_available_subtext);
        } else {
          mUsbTether.setSummary(R.string.usb_tethering_errored_subtext);
        }
      }
      if (mUsbTetherCheckEnable) {
        Xlog.d(
            TAG,
            "updateUsbState - mUsbTetherCheckEnable, "
                + "mUsbTether checkbox setEnabled, and set unchecked ");
        mUsbTether.setEnabled(true);
        mUsbTether.setChecked(false);
        /// M:
        mUsbTethering = false;
        mUsbTetherType.setEnabled(true);
      }
      Xlog.d(
          TAG,
          "updateUsbState - usbAvailable - mUsbConfigured:  "
              + mUsbConfigured
              + " mUsbTethering: "
              + mUsbTethering
              + " mUsbTetherCheckEnable: "
              + mUsbTetherCheckEnable);
    } else if (usbErrored) {
      mUsbTether.setSummary(R.string.usb_tethering_errored_subtext);
      mUsbTether.setEnabled(false);
      mUsbTether.setChecked(false);
      /// M: set usb tethering to false
      mUsbTethering = false;
    } else if (mMassStorageActive) {
      mUsbTether.setSummary(R.string.usb_tethering_storage_active_subtext);
      mUsbTether.setEnabled(false);
      mUsbTether.setChecked(false);
      /// M: set usb tethering to false
      mUsbTethering = false;
    } else {
      if (mUsbHwDisconnected || (!mUsbHwDisconnected && !mUsbConnected && !mUsbConfigured)) {
        mUsbTether.setSummary(R.string.usb_tethering_unavailable_subtext);
        mUsbTether.setEnabled(false);
        mUsbTether.setChecked(false);
        mUsbTethering = false;
      } else {
        /// M: update usb state @{
        Xlog.d(
            TAG, "updateUsbState - else, " + "mUsbTether checkbox setEnabled, and set unchecked ");
        mUsbTether.setSummary(R.string.usb_tethering_available_subtext);
        mUsbTether.setEnabled(true);
        mUsbTether.setChecked(false);
        mUsbTethering = false;
        mUsbTetherType.setEnabled(true);
        /// @}
      }
      Xlog.d(TAG, "updateUsbState- usbAvailable- mUsbHwDisconnected:" + mUsbHwDisconnected);
    }
  }
  @Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {

    if (preference == menuDisplayLocation) {
      int val = Integer.parseInt((String) newValue);
      Settings.System.putInt(mContentRes, Settings.System.MENU_LOCATION, val);
      refreshSettings();
      mNavBarMenuDisplay.setEnabled(val < 4 ? true : false);
      return true;
    } else if (preference == mNavBarMenuDisplay) {
      Settings.System.putInt(
          mContentRes, Settings.System.MENU_VISIBILITY, Integer.parseInt((String) newValue));
      return true;
    } else if (preference == mNavigationBarWidth) {
      String newVal = (String) newValue;
      int dp = Integer.parseInt(newVal);
      int width = mapChosenDpToPixels(dp);
      Settings.System.putInt(mContentRes, Settings.System.NAVIGATION_BAR_WIDTH, width);
      return true;
    } else if (preference == mNavigationBarHeight) {
      String newVal = (String) newValue;
      int dp = Integer.parseInt(newVal);
      int height = mapChosenDpToPixels(dp);
      Settings.System.putInt(mContentRes, Settings.System.NAVIGATION_BAR_HEIGHT, height);
      return true;
    } else if (preference == mNavBarHideTimeout) {
      int val = Integer.parseInt((String) newValue);
      Settings.System.putInt(mContentRes, Settings.System.NAV_HIDE_TIMEOUT, val);
      return true;
    } else if (preference == mNavigationBarHeightLandscape) {
      String newVal = (String) newValue;
      int dp = Integer.parseInt(newVal);
      int height = mapChosenDpToPixels(dp);
      Settings.System.putInt(mContentRes, Settings.System.NAVIGATION_BAR_HEIGHT_LANDSCAPE, height);
      return true;
    } else if (preference == mNavigationColor) {
      String hex = ColorPickerPreference.convertToARGB(Integer.valueOf(String.valueOf(newValue)));
      preference.setSummary(hex);
      int intHex = ColorPickerPreference.convertToColorInt(hex) & 0x00FFFFFF;
      Settings.System.putInt(mContentRes, Settings.System.NAVIGATION_BAR_COLOR, intHex);
      refreshSettings();
      return true;
    } else if (preference == mNavigationBarColor) {
      String hex = ColorPickerPreference.convertToARGB(Integer.valueOf(String.valueOf(newValue)));
      preference.setSummary(hex);
      int intHex = ColorPickerPreference.convertToColorInt(hex);
      Settings.System.putInt(mContentRes, Settings.System.NAVIGATION_BAR_TINT, intHex);
      refreshSettings();
      return true;
    } else if (preference == mNavigationBarGlowColor) {
      String hex = ColorPickerPreference.convertToARGB(Integer.valueOf(String.valueOf(newValue)));
      preference.setSummary(hex);
      int intHex = ColorPickerPreference.convertToColorInt(hex);
      Settings.System.putInt(mContentRes, Settings.System.NAVIGATION_BAR_GLOW_TINT, intHex);
      refreshSettings();
      return true;
    } else if (preference == mGlowTimes) {
      // format is (on|off) both in MS
      String value = (String) newValue;
      String[] breakIndex = value.split("\\|");
      int onTime = Integer.valueOf(breakIndex[0]);
      int offTime = Integer.valueOf(breakIndex[1]);

      Settings.System.putInt(mContentRes, Settings.System.NAVIGATION_BAR_GLOW_DURATION[0], offTime);
      Settings.System.putInt(mContentRes, Settings.System.NAVIGATION_BAR_GLOW_DURATION[1], onTime);
      updateGlowTimesSummary();
      return true;
    } else if (preference == mButtonAlpha) {
      float val = Float.parseFloat((String) newValue);
      Settings.System.putFloat(
          mContentRes, Settings.System.NAVIGATION_BAR_BUTTON_ALPHA, val * 0.01f);
      refreshSettings();
      return true;
    } else if (preference == mDragHandleOpacity) {
      String newVal = (String) newValue;
      int op = Integer.parseInt(newVal);
      Settings.System.putInt(mContentRes, Settings.System.DRAG_HANDLE_OPACITY, op);
      return true;
    } else if (preference == mDragHandleWidth) {
      String newVal = (String) newValue;
      int dp = Integer.parseInt(newVal);
      // int height = mapChosenDpToPixels(dp);
      Settings.System.putInt(mContentRes, Settings.System.DRAG_HANDLE_WEIGHT, dp);
      return true;
    } else if (preference == mWidthPort) {
      float val = Float.parseFloat((String) newValue);
      Settings.System.putFloat(mContentRes, Settings.System.NAVIGATION_BAR_WIDTH_PORT, val * 0.4f);
      return true;
    } else if (preference == mWidthLand) {
      float val = Float.parseFloat((String) newValue);
      Settings.System.putFloat(mContentRes, Settings.System.NAVIGATION_BAR_WIDTH_LAND, val * 0.4f);
      return true;
    }
    return false;
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(R.string.title_navbar);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.navbar_settings);

    PreferenceScreen prefs = getPreferenceScreen();

    mPicker = new ShortcutPickerHelper(this, this);
    mPackMan = getPackageManager();
    mResources = mContext.getResources();

    // Get NavBar Actions
    mActionCodes = NavBarHelpers.getNavBarActions();
    mActions = new String[mActionCodes.length];
    int actionqty = mActions.length;
    for (int i = 0; i < actionqty; i++) {
      mActions[i] = AwesomeConstants.getProperName(mContext, mActionCodes[i]);
    }

    menuDisplayLocation = (ListPreference) findPreference(PREF_MENU_UNLOCK);
    menuDisplayLocation.setOnPreferenceChangeListener(this);
    menuDisplayLocation.setValue(
        Settings.System.getInt(mContentRes, Settings.System.MENU_LOCATION, 0) + "");

    mNavBarMenuDisplay = (ListPreference) findPreference(PREF_NAVBAR_MENU_DISPLAY);
    mNavBarMenuDisplay.setOnPreferenceChangeListener(this);
    mNavBarMenuDisplay.setValue(
        Settings.System.getInt(mContentRes, Settings.System.MENU_VISIBILITY, 0) + "");

    mNavBarHideEnable = (CheckBoxPreference) findPreference(NAVBAR_HIDE_ENABLE);
    mNavBarHideEnable.setChecked(
        Settings.System.getBoolean(mContentRes, Settings.System.NAV_HIDE_ENABLE, false));

    final int defaultDragOpacity =
        Settings.System.getInt(mContentRes, Settings.System.DRAG_HANDLE_OPACITY, 50);
    mDragHandleOpacity = (SeekBarPreference) findPreference(DRAG_HANDLE_OPACITY);
    mDragHandleOpacity.setInitValue((int) (defaultDragOpacity));
    mDragHandleOpacity.setOnPreferenceChangeListener(this);

    final int defaultDragWidth =
        Settings.System.getInt(mContentRes, Settings.System.DRAG_HANDLE_WEIGHT, 5);
    mDragHandleWidth = (SeekBarPreference) findPreference(DRAG_HANDLE_WIDTH);
    mDragHandleWidth.setInitValue((int) (defaultDragWidth));
    mDragHandleWidth.setOnPreferenceChangeListener(this);

    mNavBarHideTimeout = (ListPreference) findPreference(NAVBAR_HIDE_TIMEOUT);
    mNavBarHideTimeout.setOnPreferenceChangeListener(this);
    mNavBarHideTimeout.setValue(
        Settings.System.getInt(mContentRes, Settings.System.NAV_HIDE_TIMEOUT, 3000) + "");

    boolean hasNavBarByDefault =
        mContext.getResources().getBoolean(com.android.internal.R.bool.config_showNavigationBar);
    mEnableNavigationBar = (CheckBoxPreference) findPreference(ENABLE_NAVIGATION_BAR);
    mEnableNavigationBar.setChecked(
        Settings.System.getBoolean(
            mContentRes, Settings.System.NAVIGATION_BAR_SHOW, hasNavBarByDefault));

    mNavigationColor = (ColorPickerPreference) findPreference(NAVIGATION_BAR_COLOR);
    mNavigationColor.setOnPreferenceChangeListener(this);

    mNavigationBarColor = (ColorPickerPreference) findPreference(PREF_NAV_COLOR);
    mNavigationBarColor.setOnPreferenceChangeListener(this);

    mColorizeAllIcons = (CheckBoxPreference) findPreference("navigation_bar_allcolor");
    mColorizeAllIcons.setChecked(
        Settings.System.getBoolean(mContentRes, Settings.System.NAVIGATION_BAR_ALLCOLOR, false));

    mNavigationBarGlowColor = (ColorPickerPreference) findPreference(PREF_NAV_GLOW_COLOR);
    mNavigationBarGlowColor.setOnPreferenceChangeListener(this);

    mGlowTimes = (ListPreference) findPreference(PREF_GLOW_TIMES);
    mGlowTimes.setOnPreferenceChangeListener(this);

    final float defaultButtonAlpha =
        Settings.System.getFloat(mContentRes, Settings.System.NAVIGATION_BAR_BUTTON_ALPHA, 0.6f);
    mButtonAlpha = (SeekBarPreference) findPreference("button_transparency");
    mButtonAlpha.setInitValue((int) (defaultButtonAlpha * 100));
    mButtonAlpha.setOnPreferenceChangeListener(this);

    mWidthHelp = (Preference) findPreference("width_help");

    float defaultPort =
        Settings.System.getFloat(mContentRes, Settings.System.NAVIGATION_BAR_WIDTH_PORT, 0f);
    mWidthPort = (SeekBarPreference) findPreference("width_port");
    mWidthPort.setInitValue((int) (defaultPort * 2.5f));
    mWidthPort.setOnPreferenceChangeListener(this);

    float defaultLand =
        Settings.System.getFloat(mContentRes, Settings.System.NAVIGATION_BAR_WIDTH_LAND, 0f);
    mWidthLand = (SeekBarPreference) findPreference("width_land");
    mWidthLand.setInitValue((int) (defaultLand * 2.5f));
    mWidthLand.setOnPreferenceChangeListener(this);

    mNavigationBarHeight = (ListPreference) findPreference("navigation_bar_height");
    mNavigationBarHeight.setOnPreferenceChangeListener(this);

    mNavigationBarHeightLandscape =
        (ListPreference) findPreference("navigation_bar_height_landscape");
    mNavigationBarHeightLandscape.setOnPreferenceChangeListener(this);

    mNavigationBarWidth = (ListPreference) findPreference("navigation_bar_width");
    mNavigationBarWidth.setOnPreferenceChangeListener(this);
    mConfigureWidgets = findPreference(NAVIGATION_BAR_WIDGETS);

    mMenuArrowKeysCheckBox = (CheckBoxPreference) findPreference(PREF_MENU_ARROWS);
    mMenuArrowKeysCheckBox.setChecked(
        Settings.System.getBoolean(
            mContentRes, Settings.System.NAVIGATION_BAR_MENU_ARROW_KEYS, true));

    // don't allow devices that must use a navigation bar to disable it
    if (hasNavBarByDefault) {
      prefs.removePreference(mEnableNavigationBar);
    }
    PreferenceGroup pg = (PreferenceGroup) prefs.findPreference("advanced_cat");
    if (isTablet(mContext)) {
      mNavigationBarHeight.setTitle(R.string.system_bar_height_title);
      mNavigationBarHeight.setSummary(R.string.system_bar_height_summary);
      mNavigationBarHeightLandscape.setTitle(R.string.system_bar_height_landscape_title);
      mNavigationBarHeightLandscape.setSummary(R.string.system_bar_height_landscape_summary);
      pg.removePreference(mNavigationBarWidth);
      mNavBarHideEnable.setEnabled(false);
      mDragHandleOpacity.setEnabled(false);
      mDragHandleWidth.setEnabled(false);
      mNavBarHideTimeout.setEnabled(false);
    } else { // Phones&Phablets don't have SystemBar
      pg.removePreference(mWidthPort);
      pg.removePreference(mWidthLand);
      pg.removePreference(mWidthHelp);
    }

    if (Integer.parseInt(menuDisplayLocation.getValue()) == 4) {
      mNavBarMenuDisplay.setEnabled(false);
    }

    // Only show the hardware keys config on a device that does not have a navbar
    IWindowManager windowManager =
        IWindowManager.Stub.asInterface(ServiceManager.getService(Context.WINDOW_SERVICE));

    if (hasNavBarByDefault) {
      // Let's assume they don't have hardware keys
      getPreferenceScreen().removePreference(findPreference(KEY_HARDWARE_KEYS));
    }
    refreshSettings();
    setHasOptionsMenu(true);
    updateGlowTimesSummary();
  }
Ejemplo n.º 23
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.preferences);

    PackageManager pm = getActivity().getPackageManager();
    Intent mediaIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);

    List<ResolveInfo> mAppsInfo = pm.queryBroadcastReceivers(mediaIntent, 0);
    ListPreference simpleAppListPref = (ListPreference) findPreference("selectapp");
    ListPreference advancedAppListPref = (ListPreference) findPreference("selectadvancedapp");

    ListPreference baudRatePref = (ListPreference) findPreference("baud_rate");

    simpleAppListPref.setOnPreferenceChangeListener(this);
    advancedAppListPref.setOnPreferenceChangeListener(this);

    baudRatePref.setOnPreferenceChangeListener(this);
    baudRatePref.setTitle(baudRatePref.getEntry());

    CharSequence[] mEntries;
    CharSequence[] mEntryValues;

    CharSequence[] mAdvEntries;
    CharSequence[] mAdvEntryValues;

    if (mAppsInfo.size() > 0) {

      mEntries = new CharSequence[mAppsInfo.size()];
      mEntryValues = new CharSequence[mAppsInfo.size()];

      mAdvEntries = new CharSequence[mAppsInfo.size() + 1];
      mAdvEntryValues = new CharSequence[mAppsInfo.size() + 1];

      mAdvEntries[0] = "PodMode";
      mAdvEntryValues[0] = "me.spadival.podmode";

      int i = 0;
      for (ResolveInfo info : mAppsInfo) {
        mEntries[i] = info.activityInfo.applicationInfo.loadLabel(pm);
        mEntryValues[i] = (String) info.activityInfo.packageName;
        mAdvEntries[i + 1] = mEntries[i];
        mAdvEntryValues[i + 1] = mEntryValues[i];
        i++;
      }

      simpleAppListPref.setSelectable(true);
      simpleAppListPref.setEntries(mEntries);
      simpleAppListPref.setEntryValues(mEntryValues);

      advancedAppListPref.setSelectable(true);
      advancedAppListPref.setEntries(mAdvEntries);
      advancedAppListPref.setEntryValues(mAdvEntryValues);

      boolean simpleAppEntryFound = false;

      String simpleAppName = (String) simpleAppListPref.getEntry();

      if (simpleAppName != null) {
        for (i = 0; i < mEntries.length; i++) {
          if (simpleAppName.equals(mEntries[i])) {
            simpleAppEntryFound = true;
          }
        }
      }

      if (!simpleAppEntryFound) simpleAppListPref.setValue((String) mEntryValues[0]);

      simpleAppListPref.setTitle(simpleAppListPref.getEntry());
      try {
        simpleAppListPref.setIcon(pm.getApplicationIcon(simpleAppListPref.getValue()));
      } catch (NameNotFoundException e) {
        e.printStackTrace();
      }

      boolean advancedAppEntryFound = false;
      String advancedAppName = (String) advancedAppListPref.getEntry();

      if (advancedAppName != null) {
        for (i = 0; i < mAdvEntries.length; i++) {
          if (advancedAppName.equals(mAdvEntries[i])) {
            advancedAppEntryFound = true;
          }
        }
      }

      if (!advancedAppEntryFound) advancedAppListPref.setValue((String) mAdvEntryValues[0]);

      advancedAppListPref.setTitle(advancedAppListPref.getEntry());
      try {
        advancedAppListPref.setIcon(pm.getApplicationIcon(advancedAppListPref.getValue()));
      } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

    } else {
      simpleAppListPref.setTitle(R.string.no_media_player);
      simpleAppListPref.setEntries(null);
      simpleAppListPref.setEntryValues(null);
      simpleAppListPref.setEnabled(false);

      mAdvEntries = new CharSequence[1];
      mAdvEntryValues = new CharSequence[1];

      mAdvEntries[0] = "PodMode";
      mAdvEntryValues[0] = "me.spadival.podmode";

      advancedAppListPref.setTitle(mAdvEntries[0]);
      advancedAppListPref.setEntries(mAdvEntries);
      advancedAppListPref.setEntryValues(mAdvEntryValues);
      advancedAppListPref.setEnabled(false);
    }
  }
Ejemplo n.º 24
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // Workaround for bug 4611: http://code.google.com/p/android/issues/detail?id=4611
    if (AnkiDroidApp.SDK_VERSION >= 7 && AnkiDroidApp.SDK_VERSION <= 10) {
      Themes.applyTheme(this, Themes.THEME_ANDROID_DARK);
    }
    super.onCreate(savedInstanceState);

    mCol = AnkiDroidApp.getCol();
    mPrefMan = getPreferenceManager();
    mPrefMan.setSharedPreferencesName(AnkiDroidApp.SHARED_PREFS_NAME);

    addPreferencesFromResource(R.xml.preferences);

    swipeCheckboxPreference = (CheckBoxPreference) getPreferenceScreen().findPreference("swipe");
    zoomCheckboxPreference = (CheckBoxPreference) getPreferenceScreen().findPreference("zoom");
    keepScreenOnCheckBoxPreference =
        (CheckBoxPreference) getPreferenceScreen().findPreference("keepScreenOn");
    showAnswerCheckBoxPreference =
        (CheckBoxPreference) getPreferenceScreen().findPreference("timeoutAnswer");
    animationsCheckboxPreference =
        (CheckBoxPreference) getPreferenceScreen().findPreference("themeAnimations");
    useBackupPreference = (CheckBoxPreference) getPreferenceScreen().findPreference("useBackup");
    asyncModePreference = (CheckBoxPreference) getPreferenceScreen().findPreference("asyncMode");
    eInkDisplayPreference =
        (CheckBoxPreference) getPreferenceScreen().findPreference("eInkDisplay");
    fadeScrollbars = (CheckBoxPreference) getPreferenceScreen().findPreference("fadeScrollbars");
    //        ListPreference listpref = (ListPreference)
    // getPreferenceScreen().findPreference("theme");
    convertFenText = (CheckBoxPreference) getPreferenceScreen().findPreference("convertFenText");
    fixHebrewText = (CheckBoxPreference) getPreferenceScreen().findPreference("fixHebrewText");
    syncAccount = (Preference) getPreferenceScreen().findPreference("syncAccount");
    showEstimates = (CheckBoxPreference) getPreferenceScreen().findPreference("showEstimates");
    showProgress = (CheckBoxPreference) getPreferenceScreen().findPreference("showProgress");
    learnCutoff = (NumberRangePreference) getPreferenceScreen().findPreference("learnCutoff");
    timeLimit = (NumberRangePreference) getPreferenceScreen().findPreference("timeLimit");
    useCurrent = (ListPreference) getPreferenceScreen().findPreference("useCurrent");
    newSpread = (ListPreference) getPreferenceScreen().findPreference("newSpread");
    dayOffset = (SeekBarPreference) getPreferenceScreen().findPreference("dayOffset");
    //        String theme = listpref.getValue();
    //        animationsCheckboxPreference.setEnabled(theme.equals("2") || theme.equals("3"));
    zoomCheckboxPreference.setEnabled(!swipeCheckboxPreference.isChecked());

    initializeLanguageDialog();
    initializeCustomFontsDialog();

    if (mCol != null) {
      // For collection preferences, we need to fetch the correct values from the collection
      mStartDate = GregorianCalendar.getInstance();
      Timestamp timestamp = new Timestamp(mCol.getCrt() * 1000);
      mStartDate.setTimeInMillis(timestamp.getTime());
      dayOffset.setValue(mStartDate.get(Calendar.HOUR_OF_DAY));
      try {
        JSONObject conf = mCol.getConf();
        learnCutoff.setValue(conf.getInt("collapseTime") / 60);
        timeLimit.setValue(conf.getInt("timeLim") / 60);
        showEstimates.setChecked(conf.getBoolean("estTimes"));
        showProgress.setChecked(conf.getBoolean("dueCounts"));
        newSpread.setValueIndex(conf.getInt("newSpread"));
        useCurrent.setValueIndex(conf.getBoolean("addToCur") ? 0 : 1);
      } catch (JSONException e) {
        throw new RuntimeException();
      } catch (NumberFormatException e) {
        throw new RuntimeException();
      }
    } else {
      // It's possible to open the preferences from the loading screen if no SD card is found.
      // In that case, there will be no collection loaded, so we need to disable the settings
      // that read from and write to the collection.
      dayOffset.setEnabled(false);
      learnCutoff.setEnabled(false);
      timeLimit.setEnabled(false);
      showEstimates.setEnabled(false);
      showProgress.setEnabled(false);
      newSpread.setEnabled(false);
      useCurrent.setEnabled(false);
    }

    for (String key : mShowValueInSummList) {
      updateListPreference(key);
    }
    for (String key : mShowValueInSummSeek) {
      updateSeekBarPreference(key);
    }
    for (String key : mShowValueInSummEditText) {
      updateEditTextPreference(key);
    }
    for (String key : mShowValueInSummNumRange) {
      updateNumberRangePreference(key);
    }

    if (AnkiDroidApp.SDK_VERSION <= 4) {
      fadeScrollbars.setChecked(false);
      fadeScrollbars.setEnabled(false);
    }
  }
Ejemplo n.º 25
0
 public boolean onPreferenceChange(Preference preference, Object newValue) {
   ContentResolver resolver = mContext.getContentResolver();
   if (preference == mQuietHoursTimeRange) {
     Settings.System.putInt(
         resolver, Settings.System.QUIET_HOURS_START, mQuietHoursTimeRange.getStartTime());
     Settings.System.putInt(
         resolver, Settings.System.QUIET_HOURS_END, mQuietHoursTimeRange.getEndTime());
     SmsCallHelper.scheduleService(mContext);
     return true;
   } else if (preference == mQuietHoursEnabled) {
     Settings.System.putInt(
         resolver, Settings.System.QUIET_HOURS_ENABLED, (Boolean) newValue ? 1 : 0);
     SmsCallHelper.scheduleService(mContext);
     return true;
   } else if (preference == mQuietHoursMute) {
     Settings.System.putInt(
         resolver, Settings.System.QUIET_HOURS_MUTE, (Boolean) newValue ? 1 : 0);
     return true;
   } else if (preference == mQuietHoursStill) {
     Settings.System.putInt(
         resolver, Settings.System.QUIET_HOURS_STILL, (Boolean) newValue ? 1 : 0);
     return true;
   } else if (preference == mQuietHoursDim) {
     Settings.System.putInt(resolver, Settings.System.QUIET_HOURS_DIM, (Boolean) newValue ? 1 : 0);
     return true;
   } else if (preference == mQuietHoursHaptic) {
     Settings.System.putInt(
         resolver, Settings.System.QUIET_HOURS_HAPTIC, (Boolean) newValue ? 1 : 0);
     return true;
   } else if (preference == mRingtoneLoop) {
     mRingtoneLoop.setSummary(
         (Boolean) newValue
             ? R.string.quiet_hours_bypass_ringtone_loop_summary_on
             : R.string.quiet_hours_bypass_ringtone_loop_summary_off);
     return true;
   } else if (preference == mAutoSms) {
     mSmsPref = Integer.parseInt((String) newValue);
     mAutoSms.setSummary(mAutoSms.getEntries()[mSmsPref]);
     shouldDisplayTextPref();
     return true;
   } else if (preference == mAutoSmsCall) {
     mCallPref = Integer.parseInt((String) newValue);
     mAutoSmsCall.setSummary(mAutoSmsCall.getEntries()[mCallPref]);
     shouldDisplayTextPref();
     return true;
   } else if (preference == mSmsBypass) {
     mSmsBypassPref = Integer.parseInt((String) newValue);
     mSmsBypass.setSummary(mSmsBypass.getEntries()[mSmsBypassPref]);
     mSmsBypassCode.setEnabled(mSmsBypassPref != 0);
     shouldDisplayRingerPrefs();
     return true;
   } else if (preference == mCallBypass) {
     mCallBypassPref = Integer.parseInt((String) newValue);
     mCallBypass.setSummary(mCallBypass.getEntries()[mCallBypassPref]);
     mCallBypassNumber.setEnabled(mCallBypassPref != 0);
     shouldDisplayRingerPrefs();
     return true;
   } else if (preference == mCallBypassNumber) {
     int val = Integer.parseInt((String) newValue);
     mCallBypassNumber.setSummary(
         mCallBypassNumber.getEntries()[val - 2]
             + getResources().getString(R.string.quiet_hours_calls_required_summary));
     return true;
   } else if (preference == mBypassRingtone) {
     Uri val = Uri.parse((String) newValue);
     SharedPreferences.Editor editor = mPrefs.edit();
     Ringtone ringtone = RingtoneManager.getRingtone(mContext, val);
     if (ringtone != null) {
       editor.putString(KEY_BYPASS_RINGTONE, val.toString()).apply();
       mBypassRingtone.setSummary(ringtone.getTitle(mContext));
     } else {
       // No silent option, won't reach here
       editor.putString(KEY_BYPASS_RINGTONE, null).apply();
     }
     return true;
   }
   return false;
 }
Ejemplo n.º 26
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getPreferenceManager() != null) {
      addPreferencesFromResource(R.xml.quiet_hours_settings);

      mContext = getActivity().getApplicationContext();

      ContentResolver resolver = mContext.getContentResolver();

      PreferenceScreen prefSet = getPreferenceScreen();

      mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);

      // Load the preferences
      mQuietHoursNote = prefSet.findPreference(KEY_QUIET_HOURS_NOTE);
      mQuietHoursEnabled = (CheckBoxPreference) prefSet.findPreference(KEY_QUIET_HOURS_ENABLED);
      mQuietHoursTimeRange =
          (TimeRangePreference) prefSet.findPreference(KEY_QUIET_HOURS_TIMERANGE);
      mQuietHoursMute = (CheckBoxPreference) prefSet.findPreference(KEY_QUIET_HOURS_MUTE);
      mQuietHoursStill = (CheckBoxPreference) prefSet.findPreference(KEY_QUIET_HOURS_STILL);
      mQuietHoursHaptic = (CheckBoxPreference) prefSet.findPreference(KEY_QUIET_HOURS_HAPTIC);
      mQuietHoursDim = (CheckBoxPreference) findPreference(KEY_QUIET_HOURS_DIM);
      mRingtoneLoop = (CheckBoxPreference) findPreference(KEY_LOOP_BYPASS_RINGTONE);
      mAutoSms = (ListPreference) findPreference(KEY_AUTO_SMS);
      mAutoSmsCall = (ListPreference) findPreference(KEY_AUTO_SMS_CALL);
      mAutoSmsMessage = (Preference) findPreference(KEY_AUTO_SMS_MESSAGE);
      mSmsBypass = (ListPreference) findPreference(KEY_SMS_BYPASS);
      mCallBypass = (ListPreference) findPreference(KEY_CALL_BYPASS);
      mCallBypassNumber = (ListPreference) findPreference(KEY_REQUIRED_CALLS);
      mSmsBypassCode = (Preference) findPreference(KEY_SMS_BYPASS_CODE);
      mBypassRingtone = (RingtonePreference) findPreference(KEY_BYPASS_RINGTONE);

      // Remove the "Incoming calls behaviour" note if the device does not support phone calls
      if (mQuietHoursNote != null
          && getResources().getBoolean(com.android.internal.R.bool.config_voice_capable) == false) {
        getPreferenceScreen().removePreference(mQuietHoursNote);
      }

      // Set the preference state and listeners where applicable
      mQuietHoursEnabled.setChecked(
          Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_ENABLED, 0) == 1);
      mQuietHoursEnabled.setOnPreferenceChangeListener(this);
      mQuietHoursTimeRange.setTimeRange(
          Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_START, 0),
          Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_END, 0));
      mQuietHoursTimeRange.setOnPreferenceChangeListener(this);
      mQuietHoursMute.setChecked(
          Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_MUTE, 0) == 1);
      mQuietHoursMute.setOnPreferenceChangeListener(this);
      mQuietHoursStill.setChecked(
          Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_STILL, 0) == 1);
      mQuietHoursStill.setOnPreferenceChangeListener(this);
      mQuietHoursHaptic.setChecked(
          Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_HAPTIC, 0) == 1);
      mQuietHoursHaptic.setOnPreferenceChangeListener(this);
      mRingtoneLoop.setOnPreferenceChangeListener(this);
      mAutoSms.setValue(mPrefs.getString(KEY_AUTO_SMS, "0"));
      mAutoSms.setOnPreferenceChangeListener(this);
      mAutoSmsCall.setValue(mPrefs.getString(KEY_AUTO_SMS_CALL, "0"));
      mAutoSmsCall.setOnPreferenceChangeListener(this);
      mSmsBypass.setValue(mPrefs.getString(KEY_SMS_BYPASS, "0"));
      mSmsBypass.setOnPreferenceChangeListener(this);
      mCallBypass.setValue(mPrefs.getString(KEY_CALL_BYPASS, "0"));
      mCallBypass.setOnPreferenceChangeListener(this);
      mCallBypassNumber.setValue(mPrefs.getString(KEY_REQUIRED_CALLS, "2"));
      mCallBypassNumber.setOnPreferenceChangeListener(this);
      mBypassRingtone.setOnPreferenceChangeListener(this);

      TelephonyManager telephonyManager =
          (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
      if (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
        prefSet.removePreference((PreferenceGroup) findPreference("sms_respond"));
        prefSet.removePreference((PreferenceGroup) findPreference("quiethours_bypass"));
      } else {
        int callBypassNumber = Integer.parseInt(mPrefs.getString(KEY_REQUIRED_CALLS, "2"));
        boolean loopRingtone = mPrefs.getBoolean(KEY_LOOP_BYPASS_RINGTONE, true);
        mSmsBypassPref = Integer.parseInt(mPrefs.getString(KEY_SMS_BYPASS, "0"));
        mSmsPref = Integer.parseInt(mPrefs.getString(KEY_AUTO_SMS, "0"));
        mCallPref = Integer.parseInt(mPrefs.getString(KEY_AUTO_SMS_CALL, "0"));
        mCallBypassPref = Integer.parseInt(mPrefs.getString(KEY_CALL_BYPASS, "0"));
        Uri alertSoundUri = SmsCallHelper.returnUserRingtone(mContext);
        Ringtone ringtoneAlarm = RingtoneManager.getRingtone(mContext, alertSoundUri);
        mBypassRingtone.setSummary(ringtoneAlarm.getTitle(mContext));
        mRingtoneLoop.setChecked(loopRingtone);
        mRingtoneLoop.setSummary(
            loopRingtone
                ? R.string.quiet_hours_bypass_ringtone_loop_summary_on
                : R.string.quiet_hours_bypass_ringtone_loop_summary_off);
        mSmsBypass.setSummary(mSmsBypass.getEntries()[mSmsBypassPref]);
        mCallBypass.setSummary(mCallBypass.getEntries()[mCallBypassPref]);
        mCallBypassNumber.setSummary(
            mCallBypassNumber.getEntries()[callBypassNumber - 2]
                + getResources().getString(R.string.quiet_hours_calls_required_summary));
        mAutoSms.setSummary(mAutoSms.getEntries()[mSmsPref]);
        mAutoSmsCall.setSummary(mAutoSmsCall.getEntries()[mCallPref]);
        mCallBypassNumber.setEnabled(mCallBypassPref != 0);
        mSmsBypassCode.setEnabled(mSmsBypassPref != 0);
        shouldDisplayRingerPrefs();
        shouldDisplayTextPref();
        setSmsBypassCodeSummary();
      }

      // Remove the notification light setting if the device does not support it
      if (mQuietHoursDim != null
          && getResources().getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed)
              == false) {
        getPreferenceScreen().removePreference(mQuietHoursDim);
      } else {
        mQuietHoursDim.setChecked(
            Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_DIM, 0) == 1);
        mQuietHoursDim.setOnPreferenceChangeListener(this);
      }

      mPreferencesChangeListener =
          new OnSharedPreferenceChangeListener() {
            public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
              if (key.equals(KEY_AUTO_SMS_CALL)
                  || key.equals(KEY_AUTO_SMS)
                  || key.equals(KEY_CALL_BYPASS)
                  || key.equals(KEY_SMS_BYPASS)) {
                SmsCallHelper.scheduleService(mContext);
              }
              if (key.equals(KEY_SMS_BYPASS_CODE)) {
                setSmsBypassCodeSummary();
              }
            }
          };
    }
  }
  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;
  }
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    if (!mCheckPreferences) {
      return false;
    }
    AlertDialog dialog;

    if (preference == mClockAmPmStyle) {
      int val = Integer.parseInt((String) newValue);
      int index = mClockAmPmStyle.findIndexOfValue((String) newValue);
      Settings.System.putInt(
          getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_AM_PM_STYLE, val);
      mClockAmPmStyle.setSummary(mClockAmPmStyle.getEntries()[index]);
      return true;
    } else if (preference == mClockStyle) {
      int val = Integer.parseInt((String) newValue);
      int index = mClockStyle.findIndexOfValue((String) newValue);
      Settings.System.putInt(
          getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_STYLE, val);
      mClockStyle.setSummary(mClockStyle.getEntries()[index]);
      return true;
    } else if (preference == mColorPicker) {
      String hex = ColorPickerPreference.convertToARGB(Integer.valueOf(String.valueOf(newValue)));
      preference.setSummary(hex);
      int intHex = ColorPickerPreference.convertToColorInt(hex);
      Settings.System.putInt(
          getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_COLOR, intHex);
      return true;
    } else if (preference == mClockDateDisplay) {
      int val = Integer.parseInt((String) newValue);
      int index = mClockDateDisplay.findIndexOfValue((String) newValue);
      Settings.System.putInt(
          getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_DISPLAY, val);
      mClockDateDisplay.setSummary(mClockDateDisplay.getEntries()[index]);
      if (val == 0) {
        mClockDateStyle.setEnabled(false);
        mClockDateFormat.setEnabled(false);
      } else {
        mClockDateStyle.setEnabled(true);
        mClockDateFormat.setEnabled(true);
      }
      return true;
    } else if (preference == mClockDateStyle) {
      int val = Integer.parseInt((String) newValue);
      int index = mClockDateStyle.findIndexOfValue((String) newValue);
      Settings.System.putInt(
          getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_STYLE, val);
      mClockDateStyle.setSummary(mClockDateStyle.getEntries()[index]);
      parseClockDateFormats();
      return true;
    } else if (preference == mStatusBarClock) {
      Settings.System.putInt(
          getActivity().getApplicationContext().getContentResolver(),
          Settings.System.STATUS_BAR_CLOCK,
          (Boolean) newValue ? 1 : 0);
      return true;
    } else if (preference == mClockDateFormat) {
      int index = mClockDateFormat.findIndexOfValue((String) newValue);

      if (index == CUSTOM_CLOCK_DATE_FORMAT_INDEX) {
        AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
        alert.setTitle(R.string.clock_date_string_edittext_title);
        alert.setMessage(R.string.clock_date_string_edittext_summary);

        final EditText input = new EditText(getActivity());
        String oldText =
            Settings.System.getString(
                getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_FORMAT);
        if (oldText != null) {
          input.setText(oldText);
        }
        alert.setView(input);

        alert.setPositiveButton(
            R.string.menu_save,
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialogInterface, int whichButton) {
                String value = input.getText().toString();
                if (value.equals("")) {
                  return;
                }
                Settings.System.putString(
                    getActivity().getContentResolver(),
                    Settings.System.STATUSBAR_CLOCK_DATE_FORMAT,
                    value);

                return;
              }
            });

        alert.setNegativeButton(
            R.string.menu_cancel,
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialogInterface, int which) {
                return;
              }
            });
        dialog = alert.create();
        dialog.show();
      } else {
        if ((String) newValue != null) {
          Settings.System.putString(
              getActivity().getContentResolver(),
              Settings.System.STATUSBAR_CLOCK_DATE_FORMAT,
              (String) newValue);
        }
      }
      return true;
    }
    return false;
  }
Ejemplo n.º 29
0
  @Override
  public void onSharedPreferenceChanged(SharedPreferences settings, String key) {
    // Let's do something a preference value changes

    if (key.equals("profile")) {
      String profileString = settings.getString("profile", "");
      if (profileString.equals("0")) {
        String[] profileEntries = settings.getString("profileEntries", "").split("\\|");
        String[] profileValues = settings.getString("profileValues", "").split("\\|");
        int newProfileValue = Integer.valueOf(profileValues[profileValues.length - 2]) + 1;

        StringBuilder profileEntriesBuffer = new StringBuilder();
        StringBuilder profileValuesBuffer = new StringBuilder();

        for (int i = 0; i < profileValues.length - 1; i++) {
          profileEntriesBuffer.append(profileEntries[i]).append("|");
          profileValuesBuffer.append(profileValues[i]).append("|");
        }
        profileEntriesBuffer.append(getProfileName(Integer.toString(newProfileValue))).append("|");
        profileValuesBuffer.append(newProfileValue).append("|");
        profileEntriesBuffer.append(getString(R.string.profile_new));
        profileValuesBuffer.append("0");

        Editor ed = settings.edit();
        ed.putString("profileEntries", profileEntriesBuffer.toString());
        ed.putString("profileValues", profileValuesBuffer.toString());
        ed.putString("profile", Integer.toString(newProfileValue));
        ed.commit();

        loadProfileList();
      } else {
        String oldProfile = profile;
        profile = profileString;
        profileList.setValue(profile);
        onProfileChange(oldProfile);
        profileList.setSummary(getProfileName(profileString));
      }
    }

    if (key.equals("isConnecting")) {
      if (settings.getBoolean("isConnecting", false)) {
        Log.d(TAG, "Connecting start");
        isRunningCheck.setEnabled(false);
        pd = ProgressDialog.show(this, "", getString(R.string.connecting), true, true);
      } else {
        Log.d(TAG, "Connecting finish");
        if (pd != null) {
          pd.dismiss();
          pd = null;
        }
        isRunningCheck.setEnabled(true);
      }
    }

    if (key.equals("isPAC")) {
      if (settings.getBoolean("isPAC", false)) {
        portText.setEnabled(false);
        proxyTypeList.setEnabled(false);
        hostText.setTitle(R.string.host_pac);
      } else {
        portText.setEnabled(true);
        proxyTypeList.setEnabled(true);
        hostText.setTitle(R.string.host);
      }
      if (settings.getString("host", "").equals("")) {
        hostText.setSummary(
            settings.getBoolean("isPAC", false)
                ? R.string.host_pac_summary
                : R.string.host_summary);
      } else {
        hostText.setSummary(settings.getString("host", ""));
      }
    }

    if (key.equals("isAuth")) {
      if (!settings.getBoolean("isAuth", false)) {
        userText.setEnabled(false);
        passwordText.setEnabled(false);
        isNTLMCheck.setEnabled(false);
        domainText.setEnabled(false);
      } else {
        userText.setEnabled(true);
        passwordText.setEnabled(true);
        isNTLMCheck.setEnabled(true);
        if (isNTLMCheck.isChecked()) {
          domainText.setEnabled(true);
        } else {
          domainText.setEnabled(false);
        }
      }
    }

    if (key.equals("isNTLM")) {
      if (!settings.getBoolean("isAuth", false) || !settings.getBoolean("isNTLM", false)) {
        domainText.setEnabled(false);
      } else {
        domainText.setEnabled(true);
      }
    }

    if (key.equals("proxyType")) {
      if (!"https".equals(settings.getString("proxyType", ""))) {
        certificateText.setEnabled(false);
      } else {
        certificateText.setEnabled(true);
      }
    }

    if (key.equals("isAutoConnect")) {
      if (settings.getBoolean("isAutoConnect", false)) {
        loadNetworkList();
        ssidList.setEnabled(true);
      } else {
        ssidList.setEnabled(false);
      }
    }

    if (key.equals("isAutoSetProxy")) {
      if (settings.getBoolean("isAutoSetProxy", false)) {
        proxyedApps.setEnabled(false);
        isBypassAppsCheck.setEnabled(false);
      } else {
        proxyedApps.setEnabled(true);
        isBypassAppsCheck.setEnabled(true);
      }
    }

    if (key.equals("isRunning")) {
      if (settings.getBoolean("isRunning", false)) {
        disableAll();
        if (Build.VERSION.SDK_INT >= 14) {
          ((SwitchPreference) isRunningCheck).setChecked(true);
        } else {
          ((CheckBoxPreference) isRunningCheck).setChecked(true);
        }
        if (!Utils.isConnecting()) serviceStart();
      } else {
        enableAll();
        if (Build.VERSION.SDK_INT >= 14) {
          ((SwitchPreference) isRunningCheck).setChecked(false);
        } else {
          ((CheckBoxPreference) isRunningCheck).setChecked(false);
        }
        if (!Utils.isConnecting()) serviceStop();
      }
    }

    if (key.equals("ssid")) {
      if (settings.getString("ssid", "").equals("")) {
        ssidList.setSummary(getString(R.string.ssid_summary));
      } else {
        ssidList.setSummary(settings.getString("ssid", ""));
      }
    } else if (key.equals("user")) {
      if (settings.getString("user", "").equals("")) {
        userText.setSummary(getString(R.string.user_summary));
      } else {
        userText.setSummary(settings.getString("user", ""));
      }
    } else if (key.equals("domain")) {
      if (settings.getString("domain", "").equals("")) {
        domainText.setSummary(getString(R.string.domain_summary));
      } else {
        domainText.setSummary(settings.getString("domain", ""));
      }
    } else if (key.equals("proxyType")) {
      if (settings.getString("proxyType", "").equals("")) {
        certificateText.setSummary(getString(R.string.certificate_summary));
      } else {
        certificateText.setSummary(settings.getString("certificate", ""));
      }
    } else if (key.equals("bypassAddrs")) {
      if (settings.getString("bypassAddrs", "").equals("")) {
        bypassAddrs.setSummary(getString(R.string.set_bypass_summary));
      } else {
        bypassAddrs.setSummary(settings.getString("bypassAddrs", "").replace("|", ", "));
      }
    } else if (key.equals("port")) {
      if (settings.getString("port", "-1").equals("-1")
          || settings.getString("port", "-1").equals("")) {
        portText.setSummary(getString(R.string.port_summary));
      } else {
        portText.setSummary(settings.getString("port", ""));
      }
    } else if (key.equals("host")) {
      if (settings.getString("host", "").equals("")) {
        hostText.setSummary(
            settings.getBoolean("isPAC", false)
                ? R.string.host_pac_summary
                : R.string.host_summary);
      } else {
        hostText.setSummary(settings.getString("host", ""));
      }
    } else if (key.equals("proxyType")) {
      if (settings.getString("proxyType", "").equals("")) {
        proxyTypeList.setSummary(getString(R.string.proxy_type_summary));
      } else {
        proxyTypeList.setSummary(settings.getString("proxyType", "").toUpperCase());
      }
    } else if (key.equals("password")) {
      if (!settings.getString("password", "").equals("")) {
        passwordText.setSummary("*********");
      } else {
        passwordText.setSummary(getString(R.string.password_summary));
      }
    }
  }
Ejemplo n.º 30
0
  @Override
  public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    if (preference == mUsbTether) {
      if (!mUsbTethering) {
        boolean newState = mUsbTether.isChecked();

        /// M: update usb tethering @{
        mUsbTether.setEnabled(false);
        mUsbTetherType.setEnabled(false);
        mUsbTethering = true;
        mUsbTetherCheckEnable = false;
        if (newState) {
          mUsbTetherDone = false;
        } else {
          mUsbUnTetherDone = false;
        }
        mUsbTetherFail = false;

        Xlog.d(
            TAG,
            "onPreferenceTreeClick - setusbTethering("
                + newState
                + ") mUsbTethering:  "
                + mUsbTethering);
        /// @}

        if (newState) {
          startProvisioningIfNecessary(USB_TETHERING);
        } else {
          setUsbTethering(newState);
        }
      } else {
        return true;
      }
    } else if (preference == mBluetoothTether) {
      boolean bluetoothTetherState = mBluetoothTether.isChecked();

      if (bluetoothTetherState) {
        startProvisioningIfNecessary(BLUETOOTH_TETHERING);
      } else {
        boolean errored = false;

        String[] tethered = cm.getTetheredIfaces();
        String bluetoothIface = findIface(tethered, mBluetoothRegexs);
        if (bluetoothIface != null
            && cm.untether(bluetoothIface) != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
          errored = true;
        }

        BluetoothPan bluetoothPan = mBluetoothPan.get();
        if (bluetoothPan != null) {
          bluetoothPan.setBluetoothTethering(false);
        }
        /// M: set bluetooth tethering to false @{
        BluetoothDun bluetoothDun = BluetoothDunGetProxy();
        if (bluetoothDun != null) {
          bluetoothDun.setBluetoothTethering(false);
        }
        /// @}
        if (errored) {
          mBluetoothTether.setSummary(R.string.bluetooth_tethering_errored_subtext);
        } else {
          mBluetoothTether.setSummary(R.string.bluetooth_tethering_off_subtext);
        }
      }
      /// M: @{
      if (FeatureOption.MTK_TETHERINGIPV6_SUPPORT) {
        updateIpv6Preference();
      }
      /// @}
    }

    return super.onPreferenceTreeClick(screen, preference);
  }