private void initSmsApplicationSetting() { log("initSmsApplicationSetting:"); Collection<SmsApplicationData> smsApplications = SmsApplication.getApplicationCollection(getActivity()); // If the list is empty the dialog will be empty, but we will not crash. int count = smsApplications.size(); CharSequence[] entries = new CharSequence[count]; CharSequence[] entryValues = new CharSequence[count]; Drawable[] entryImages = new Drawable[count]; PackageManager packageManager = getPackageManager(); int i = 0; for (SmsApplicationData smsApplicationData : smsApplications) { entries[i] = smsApplicationData.mApplicationName; entryValues[i] = smsApplicationData.mPackageName; try { entryImages[i] = packageManager.getApplicationIcon(smsApplicationData.mPackageName); } catch (NameNotFoundException e) { entryImages[i] = packageManager.getDefaultActivityIcon(); } i++; } mSmsApplicationPreference.setEntries(entries); mSmsApplicationPreference.setEntryValues(entryValues); mSmsApplicationPreference.setEntryDrawables(entryImages); updateSmsApplicationSetting(); }
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference == mSmsApplicationPreference && newValue != null) { SmsApplication.setDefaultApplication(newValue.toString(), getActivity()); updateSmsApplicationSetting(); return true; } return false; }
private void updateSmsApplicationSetting() { log("updateSmsApplicationSetting:"); ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true); if (appName != null) { String packageName = appName.getPackageName(); CharSequence[] values = mSmsApplicationPreference.getEntryValues(); for (int i = 0; i < values.length; i++) { if (packageName.contentEquals(values[i])) { mSmsApplicationPreference.setValueIndex(i); mSmsApplicationPreference.setSummary(mSmsApplicationPreference.getEntries()[i]); break; } } } }