diff options
author | Fabrice Di Meglio <fdimeglio@google.com> | 2015-01-23 19:03:22 -0800 |
---|---|---|
committer | Fabrice Di Meglio <fdimeglio@google.com> | 2015-04-03 14:10:01 -0700 |
commit | 8b2ea39cbc5b0923646b5ad4d5f66ff3c66a9f7f (patch) | |
tree | 3bbb8007c3af047f17c22d4e8c5384fe43a55688 /src/com/android/settings/applications/AppLaunchSettings.java | |
parent | 43a0cbad1bc630aca89ff59208f8f5f6260f3efd (diff) | |
download | packages_apps_Settings-8b2ea39cbc5b0923646b5ad4d5f66ff3c66a9f7f.zip packages_apps_Settings-8b2ea39cbc5b0923646b5ad4d5f66ff3c66a9f7f.tar.gz packages_apps_Settings-8b2ea39cbc5b0923646b5ad4d5f66ff3c66a9f7f.tar.bz2 |
Settings - add support for Launch by Default
- implement UX spec
Change-Id: I7ee8962f83983273d809e0ef6fc81b0eb2df15dd
Diffstat (limited to 'src/com/android/settings/applications/AppLaunchSettings.java')
-rw-r--r-- | src/com/android/settings/applications/AppLaunchSettings.java | 185 |
1 files changed, 57 insertions, 128 deletions
diff --git a/src/com/android/settings/applications/AppLaunchSettings.java b/src/com/android/settings/applications/AppLaunchSettings.java index ffb84ef..c0a662a 100644 --- a/src/com/android/settings/applications/AppLaunchSettings.java +++ b/src/com/android/settings/applications/AppLaunchSettings.java @@ -17,117 +17,78 @@ package com.android.settings.applications; import android.app.AlertDialog; -import android.appwidget.AppWidgetManager; -import android.content.ComponentName; -import android.content.Context; -import android.content.IntentFilter; +import android.content.pm.IntentFilterVerificationInfo; import android.content.pm.PackageManager; -import android.hardware.usb.IUsbManager; import android.os.Bundle; -import android.os.RemoteException; import android.os.UserHandle; -import android.text.SpannableString; -import android.text.TextUtils; -import android.text.style.BulletSpan; -import android.util.Log; -import android.view.LayoutInflater; +import android.preference.Preference; +import android.preference.SwitchPreference; +import android.util.ArraySet; import android.view.View; import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.TextView; import com.android.internal.logging.MetricsLogger; import com.android.settings.R; -import com.android.settings.Utils; -import com.android.settings.applications.ApplicationsState.AppEntry; -import java.util.ArrayList; import java.util.List; -public class AppLaunchSettings extends AppInfoWithHeader implements OnClickListener { +public class AppLaunchSettings extends AppInfoWithHeader implements OnClickListener, + Preference.OnPreferenceChangeListener { - private Button mActivitiesButton; - private AppWidgetManager mAppWidgetManager; + private static final String KEY_OPEN_DOMAIN_URLS = "app_launch_open_domain_urls"; + private static final String KEY_SUPPORTED_DOMAIN_URLS = "app_launch_supported_domain_urls"; + private static final String KEY_CLEAR_DEFAULTS = "app_launch_clear_defaults"; - private View mRootView; + private PackageManager mPm; + + private SwitchPreference mOpenDomainUrls; + private AppDomainsPreference mAppDomainUrls; + private ClearDefaultsPreference mClearDefaultsPreference; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mAppWidgetManager = AppWidgetManager.getInstance(getActivity()); - } - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - final View view = inflater.inflate(R.layout.app_preferred_settings, container, false); + addPreferencesFromResource(R.xml.installed_app_launch_settings); + + mPm = getActivity().getPackageManager(); + final int myUserId = UserHandle.myUserId(); - final ViewGroup allDetails = (ViewGroup) view.findViewById(R.id.all_details); - Utils.forceCustomPadding(allDetails, true /* additive padding */); + mOpenDomainUrls = (SwitchPreference) findPreference(KEY_OPEN_DOMAIN_URLS); + mOpenDomainUrls.setOnPreferenceChangeListener(this); - mActivitiesButton = (Button) view.findViewById(R.id.clear_activities_button); - mRootView = view; + final int status = mPm.getIntentVerificationStatus(mPackageName, myUserId); + boolean checked = status == PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS; + mOpenDomainUrls.setChecked(checked); - return view; + mAppDomainUrls = (AppDomainsPreference) findPreference(KEY_SUPPORTED_DOMAIN_URLS); + CharSequence[] entries = getEntries(mPackageName); + mAppDomainUrls.setTitles(entries); + mAppDomainUrls.setValues(new int[entries.length]); + + mClearDefaultsPreference = (ClearDefaultsPreference) findPreference(KEY_CLEAR_DEFAULTS); } - @Override - protected boolean refreshUi() { - retrieveAppEntry(); - boolean hasBindAppWidgetPermission = - mAppWidgetManager.hasBindAppWidgetPermission(mAppEntry.info.packageName); - - TextView autoLaunchTitleView = (TextView) mRootView.findViewById(R.id.auto_launch_title); - TextView autoLaunchView = (TextView) mRootView.findViewById(R.id.auto_launch); - boolean autoLaunchEnabled = hasPreferredActivities(mPm, mPackageName) - || hasUsbDefaults(mUsbManager, mPackageName); - if (!autoLaunchEnabled && !hasBindAppWidgetPermission) { - resetLaunchDefaultsUi(autoLaunchTitleView, autoLaunchView); - } else { - boolean useBullets = hasBindAppWidgetPermission && autoLaunchEnabled; - - if (hasBindAppWidgetPermission) { - autoLaunchTitleView.setText(R.string.auto_launch_label_generic); - } else { - autoLaunchTitleView.setText(R.string.auto_launch_label); - } + private CharSequence[] getEntries(String packageName) { + ArraySet<String> result = new ArraySet<>(); - CharSequence text = null; - int bulletIndent = getResources() - .getDimensionPixelSize(R.dimen.installed_app_details_bullet_offset); - if (autoLaunchEnabled) { - CharSequence autoLaunchEnableText = getText(R.string.auto_launch_enable_text); - SpannableString s = new SpannableString(autoLaunchEnableText); - if (useBullets) { - s.setSpan(new BulletSpan(bulletIndent), 0, autoLaunchEnableText.length(), 0); - } - text = (text == null) ? - TextUtils.concat(s, "\n") : TextUtils.concat(text, "\n", s, "\n"); - } - if (hasBindAppWidgetPermission) { - CharSequence alwaysAllowBindAppWidgetsText = - getText(R.string.always_allow_bind_appwidgets_text); - SpannableString s = new SpannableString(alwaysAllowBindAppWidgetsText); - if (useBullets) { - s.setSpan(new BulletSpan(bulletIndent), - 0, alwaysAllowBindAppWidgetsText.length(), 0); - } - text = (text == null) ? - TextUtils.concat(s, "\n") : TextUtils.concat(text, "\n", s, "\n"); + List<IntentFilterVerificationInfo> list = + mPm.getIntentFilterVerifications(packageName); + for (IntentFilterVerificationInfo ivi : list) { + for (String host : ivi.getDomains()) { + result.add(host); } - autoLaunchView.setText(text); - mActivitiesButton.setEnabled(true); - mActivitiesButton.setOnClickListener(this); } - return true; + + return result.toArray(new CharSequence[0]); } - private void resetLaunchDefaultsUi(TextView title, TextView autoLaunchView) { - title.setText(R.string.auto_launch_label); - autoLaunchView.setText(R.string.auto_launch_disable_text); - // Disable clear activities button - mActivitiesButton.setEnabled(false); + @Override + protected boolean refreshUi() { + mClearDefaultsPreference.setPackageName(mPackageName); + mClearDefaultsPreference.setAppEntry(mAppEntry); + + return true; } @Override @@ -136,56 +97,24 @@ public class AppLaunchSettings extends AppInfoWithHeader implements OnClickListe return null; } + @Override public void onClick(View v) { - if (v == mActivitiesButton) { - if (mUsbManager != null) { - mPm.clearPackagePreferredActivities(mPackageName); - try { - mUsbManager.clearDefaults(mPackageName, UserHandle.myUserId()); - } catch (RemoteException e) { - Log.e(TAG, "mUsbManager.clearDefaults", e); - } - mAppWidgetManager.setBindAppWidgetPermission(mPackageName, false); - TextView autoLaunchTitleView = - (TextView) mRootView.findViewById(R.id.auto_launch_title); - TextView autoLaunchView = (TextView) mRootView.findViewById(R.id.auto_launch); - resetLaunchDefaultsUi(autoLaunchTitleView, autoLaunchView); - } - } - } - - private static boolean hasUsbDefaults(IUsbManager usbManager, String packageName) { - try { - if (usbManager != null) { - return usbManager.hasDefaults(packageName, UserHandle.myUserId()); - } - } catch (RemoteException e) { - Log.e(TAG, "mUsbManager.hasDefaults", e); - } - return false; + // Nothing to do } - private static boolean hasPreferredActivities(PackageManager pm, String packageName) { - // Get list of preferred activities - List<ComponentName> prefActList = new ArrayList<>(); - // Intent list cannot be null. so pass empty list - List<IntentFilter> intentList = new ArrayList<>(); - pm.getPreferredActivities(intentList, prefActList, packageName); - if (localLOGV) { - Log.i(TAG, "Have " + prefActList.size() + " number of activities in preferred list"); + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + boolean ret = false; + final String key = preference.getKey(); + if (KEY_OPEN_DOMAIN_URLS.equals(key)) { + SwitchPreference pref = (SwitchPreference) preference; + int status = !pref.isChecked() ? + PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS : + PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER; + ret = mPm.updateIntentVerificationStatus(mPackageName, status, UserHandle.myUserId()); } - return prefActList.size() > 0; - } - - public static CharSequence getSummary(AppEntry appEntry, IUsbManager usbManager, - PackageManager pm, Context context) { - String packageName = appEntry.info.packageName; - boolean hasPreferred = hasPreferredActivities(pm, packageName) - || hasUsbDefaults(usbManager, packageName); - return context.getString(hasPreferred - ? R.string.launch_defaults_some - : R.string.launch_defaults_none); + return ret; } @Override |