Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 89ae9e36 authored by Jorge Ruesga's avatar Jorge Ruesga
Browse files

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: default avatarJorge Ruesga <jorge@ruesga.com>
parent c7aa3f31
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
+12 −6
Original line number Diff line number Diff line
@@ -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);

    }

+31 −5
Original line number Diff line number Diff line
@@ -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.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.