diff options
author | Jorge Ruesga <jorge@ruesga.com> | 2013-02-22 23:03:52 +0100 |
---|---|---|
committer | Jorge Ruesga <jorge@ruesga.com> | 2013-02-24 05:00:37 +0100 |
commit | 89ae9e36dcf4c89ebf2e8a16982aff001176195c (patch) | |
tree | 9766134df518ec2a760a1993ba6c37d3034be352 | |
parent | c7aa3f31ad4ce5f54a6c1a1fc3a9ab8bb1cac867 (diff) | |
download | packages_apps_Settings-89ae9e36dcf4c89ebf2e8a16982aff001176195c.tar.gz packages_apps_Settings-89ae9e36dcf4c89ebf2e8a16982aff001176195c.tar.bz2 packages_apps_Settings-89ae9e36dcf4c89ebf2e8a16982aff001176195c.zip |
Settings: fix profiles TabManager
Whenever an user enters in the profiles settings a new TabHost, but the TabManager is neither created
or updated with this new tabhost. On tablets when the user returns to profiles from a fragment
activity, the tabhost is not displayed.
TabManager need to be created along with the tabhost.
Patchset 2: Fixed ProfileEnabler on tablets. The instance of ProfileEnabler of Settings that
is the one used on tablets doesn't have a reference of ProfileSettings, so this class
never will be updated. With this pathset the profiles enabler follows the rules of
wifi and bluetooth enablers: broadcast intent. Now, settings listen for
PROFILES_STATE_CHANGED_ACTION events, and refresh its own ui.
Requires: http://review.cyanogenmod.org/#/c/32460/1
Change-Id: I5eae79cd20cee3c14f7d2c30a2238425ccd15e09
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
-rw-r--r-- | src/com/android/settings/Settings.java | 2 | ||||
-rw-r--r-- | src/com/android/settings/profiles/ProfileEnabler.java | 18 | ||||
-rw-r--r-- | src/com/android/settings/profiles/ProfilesSettings.java | 36 |
3 files changed, 44 insertions, 12 deletions
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index 935097d30..07b04b978 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -672,7 +672,7 @@ public class Settings extends PreferenceActivity // Switches inflated from their layouts. Must be done before adapter is set in super mWifiEnabler = new WifiEnabler(context, new Switch(context)); mBluetoothEnabler = new BluetoothEnabler(context, new Switch(context)); - mProfileEnabler = new ProfileEnabler(context, null, new Switch(context)); + mProfileEnabler = new ProfileEnabler(context, new Switch(context)); } @Override diff --git a/src/com/android/settings/profiles/ProfileEnabler.java b/src/com/android/settings/profiles/ProfileEnabler.java index e5bbc49cf..0540dbe84 100644 --- a/src/com/android/settings/profiles/ProfileEnabler.java +++ b/src/com/android/settings/profiles/ProfileEnabler.java @@ -16,7 +16,9 @@ package com.android.settings.profiles; +import android.app.ProfileManager; import android.content.Context; +import android.content.Intent; import android.provider.Settings; import android.widget.CompoundButton; import android.widget.Switch; @@ -25,12 +27,10 @@ public class ProfileEnabler implements CompoundButton.OnCheckedChangeListener { private final Context mContext; private Switch mSwitch; private boolean mStateMachineEvent; - private ProfilesSettings mParent; - public ProfileEnabler(Context context, ProfilesSettings parent, Switch switch_) { + public ProfileEnabler(Context context, Switch switch_) { mContext = context; mSwitch = switch_; - mParent = parent; } public void resume() { @@ -66,9 +66,15 @@ public class ProfileEnabler implements CompoundButton.OnCheckedChangeListener { Settings.System.putInt(mContext.getContentResolver(), Settings.System.SYSTEM_PROFILES_ENABLED, isChecked ? 1 : 0); - if (mParent != null) { - mParent.refreshActiveTab(); - } + // Send a broadcast intent to the world + // TODO Enabling or disabling profiles should be at ProfileManager, not here + Intent intent=new Intent(ProfileManager.PROFILES_STATE_CHANGED_ACTION); + intent.putExtra( + ProfileManager.EXTRA_PROFILES_STATE, + isChecked ? + ProfileManager.PROFILES_STATE_ENABLED : + ProfileManager.PROFILES_STATE_DISABLED); + mContext.sendBroadcast(intent); } diff --git a/src/com/android/settings/profiles/ProfilesSettings.java b/src/com/android/settings/profiles/ProfilesSettings.java index b98724eda..4127d7979 100644 --- a/src/com/android/settings/profiles/ProfilesSettings.java +++ b/src/com/android/settings/profiles/ProfilesSettings.java @@ -24,8 +24,11 @@ import android.app.FragmentTransaction; import android.app.NotificationGroup; import android.app.Profile; import android.app.ProfileManager; +import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; +import android.content.IntentFilter; import android.os.Bundle; import android.preference.PreferenceActivity; import android.provider.Settings; @@ -59,6 +62,9 @@ public class ProfilesSettings extends SettingsPreferenceFragment { private static final int MENU_ADD_PROFILE = Menu.FIRST + 1; private static final int MENU_ADD_APPGROUP = Menu.FIRST + 2; + private final IntentFilter mFilter; + private final BroadcastReceiver mReceiver; + private static Menu mOptionsMenu; private ProfileManager mProfileManager; @@ -75,6 +81,18 @@ public class ProfilesSettings extends SettingsPreferenceFragment { private static Activity mActivity; + public ProfilesSettings() { + mFilter = new IntentFilter(); + mFilter.addAction(ProfileManager.PROFILES_STATE_CHANGED_ACTION); + + mReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + handleEvent(context, intent); + } + }; + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -101,7 +119,7 @@ public class ProfilesSettings extends SettingsPreferenceFragment { @Override public void onActivityCreated(Bundle savedInstanceState) { // We don't call super.onActivityCreated() here, since it assumes we already set up - // Preference (probably in onCreate()), while WifiSettings exceptionally set it up in + // Preference (probably in onCreate()), while ProfilesSettings exceptionally set it up in // this method. // On/off switch Activity activity = getActivity(); @@ -123,7 +141,7 @@ public class ProfilesSettings extends SettingsPreferenceFragment { } } - mProfileEnabler = new ProfileEnabler(activity, this, mActionBarSwitch); + mProfileEnabler = new ProfileEnabler(activity, mActionBarSwitch); // After confirming PreferenceScreen is available, we call super. super.onActivityCreated(savedInstanceState); @@ -135,6 +153,7 @@ public class ProfilesSettings extends SettingsPreferenceFragment { if (mProfileEnabler != null) { mProfileEnabler.resume(); } + getActivity().registerReceiver(mReceiver, mFilter); // If running on a phone, remove padding around tabs if (!Utils.isTablet(getActivity())) { @@ -149,6 +168,7 @@ public class ProfilesSettings extends SettingsPreferenceFragment { if (mProfileEnabler != null) { mProfileEnabler.pause(); } + getActivity().unregisterReceiver(mReceiver); // store the current tab so we can get back to it later if (mSavedState == null) { @@ -243,9 +263,7 @@ public class ProfilesSettings extends SettingsPreferenceFragment { mTabHost.setup(); mTabHost.clearAllTabs(); - if (mTabManager == null) { - mTabManager = new TabManager(getActivity(), mTabHost, android.R.id.tabcontent); - } + mTabManager = new TabManager(getActivity(), mTabHost, android.R.id.tabcontent); mTabManager.addTab(mTabHost.newTabSpec(TAB_PROFILES).setIndicator(getString(R.string.profile_profiles_manage)), ProfilesList.class, null); mTabManager.addTab(mTabHost.newTabSpec(TAB_APPGROUPS).setIndicator(getString(R.string.profile_appgroups_manage)), @@ -344,6 +362,14 @@ public class ProfilesSettings extends SettingsPreferenceFragment { } } + private void handleEvent(Context context, Intent intent) { + String action = intent.getAction(); + if (ProfileManager.PROFILES_STATE_CHANGED_ACTION.equals(action)) { + // we don't need to check the new state, refresh will do it + refreshActiveTab(); + } + } + /** * This is a helper class that implements a generic mechanism for * associating fragments with the tabs in a tab host. |