summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRoman Birg <roman@cyngn.com>2015-03-12 16:42:51 -0700
committerMichael Bestas <mikeioannina@gmail.com>2015-12-27 21:40:33 +0200
commita48f1658f3e155a32286059a7d314ebc638ad859 (patch)
tree4f2352b635d41143fdfb3526563a963daa02726b /src
parent80b4c3500b66b88729fc5f792b7d7719975396b4 (diff)
downloadpackages_apps_Settings-a48f1658f3e155a32286059a7d314ebc638ad859.zip
packages_apps_Settings-a48f1658f3e155a32286059a7d314ebc638ad859.tar.gz
packages_apps_Settings-a48f1658f3e155a32286059a7d314ebc638ad859.tar.bz2
Settings: merge ProfilesList into ProfilesSettings
ProfilesSettings previously had a viewpager with the profiles list, and an app group list. Then we removed app groups, but the viewpager was left over. The main reason for getting rid of it now is to make sure that refreshList() always works. Previously there was a small chance that because it was in a viewpager, the preference may not have been attached (at the time of the resetAll() dialog being shown and user pressing yes), which caused the refresh method call to fail, since it needs access to the preference screen, which is null at that time. Change-Id: Ib9c3a27e3062660bd8a91998c20c15b4ffb4390b Signed-off-by: Roman Birg <roman@cyngn.com>
Diffstat (limited to 'src')
-rw-r--r--src/com/android/settings/profiles/ProfilesList.java129
-rw-r--r--src/com/android/settings/profiles/ProfilesSettings.java127
2 files changed, 89 insertions, 167 deletions
diff --git a/src/com/android/settings/profiles/ProfilesList.java b/src/com/android/settings/profiles/ProfilesList.java
deleted file mode 100644
index 4a384dc..0000000
--- a/src/com/android/settings/profiles/ProfilesList.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (C) 2012 The CyanogenMod Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.profiles;
-
-import java.util.UUID;
-
-import com.android.internal.logging.MetricsLogger;
-import cyanogenmod.app.Profile;
-import cyanogenmod.app.ProfileManager;
-import android.content.Context;
-import android.os.Bundle;
-import android.preference.Preference;
-import android.preference.PreferenceScreen;
-import android.text.TextUtils;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.widget.ListView;
-
-import com.android.settings.R;
-import com.android.settings.SettingsPreferenceFragment;
-
-import org.cyanogenmod.internal.util.ScreenType;
-
-public class ProfilesList extends SettingsPreferenceFragment implements
- Preference.OnPreferenceChangeListener {
- static final String TAG = "ProfilesSettings";
-
- private ProfileManager mProfileManager;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- addPreferencesFromResource(R.xml.profiles_settings);
- mProfileManager = ProfileManager.getInstance(getActivity());
- }
-
- @Override
- protected int getMetricsCategory() {
- return MetricsLogger.DONT_TRACK_ME_BRO;
- }
-
- @Override
- public void onResume() {
- super.onResume();
- refreshList();
-
- // On tablet devices remove the padding
- if (ScreenType.isTablet(getActivity())) {
- getListView().setPadding(0, 0, 0, 0);
- }
- }
-
- @Override
- public void onViewCreated(View view, Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
- // Add a footer to avoid a situation where the FAB would cover the last
- // item's options in a non-scrollable listview.
- ListView listView = getListView();
- View footer = LayoutInflater.from(getActivity())
- .inflate(R.layout.empty_list_entry_footer, listView, false);
- listView.addFooterView(footer);
- listView.setFooterDividersEnabled(false);
- footer.setOnClickListener(null);
- }
-
- public void refreshList() {
- PreferenceScreen plist = getPreferenceScreen();
- plist.removeAll();
-
- // Get active profile, if null
- Profile prof = mProfileManager.getActiveProfile();
- String selectedKey = prof != null ? prof.getUuid().toString() : null;
-
- for (Profile profile : mProfileManager.getProfiles()) {
- Bundle args = new Bundle();
- args.putParcelable(ProfilesSettings.EXTRA_PROFILE, profile);
- args.putBoolean(ProfilesSettings.EXTRA_NEW_PROFILE, false);
-
- ProfilesPreference ppref = new ProfilesPreference(this, args);
- ppref.setKey(profile.getUuid().toString());
- ppref.setTitle(profile.getName());
- ppref.setPersistent(false);
- ppref.setOnPreferenceChangeListener(this);
- ppref.setSelectable(true);
- ppref.setEnabled(true);
-
- if (TextUtils.equals(selectedKey, ppref.getKey())) {
- ppref.setChecked(true);
- }
-
- plist.addPreference(ppref);
- }
- }
-
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- if (newValue instanceof String) {
- setSelectedProfile((String) newValue);
- refreshList();
- }
- return true;
- }
-
- private void setSelectedProfile(String key) {
- try {
- UUID selectedUuid = UUID.fromString(key);
- mProfileManager.setActiveProfile(selectedUuid);
- } catch (IllegalArgumentException ex) {
- ex.printStackTrace();
- }
- }
-}
diff --git a/src/com/android/settings/profiles/ProfilesSettings.java b/src/com/android/settings/profiles/ProfilesSettings.java
index 2de2d95..16c9018 100644
--- a/src/com/android/settings/profiles/ProfilesSettings.java
+++ b/src/com/android/settings/profiles/ProfilesSettings.java
@@ -16,6 +16,7 @@
package com.android.settings.profiles;
+import android.annotation.Nullable;
import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
@@ -28,16 +29,21 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.UserHandle;
+import android.preference.Preference;
+import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.support.v4.view.ViewPager;
import android.support.v13.app.FragmentStatePagerAdapter;
+import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.FrameLayout;
import android.widget.ImageView;
+import android.widget.ListView;
import android.widget.Switch;
import android.widget.TextView;
@@ -58,7 +64,8 @@ import org.cyanogenmod.internal.util.ScreenType;
import java.util.UUID;
public class ProfilesSettings extends SettingsPreferenceFragment
- implements CMBaseSystemSettingSwitchBar.SwitchBarChangeCallback {
+ implements CMBaseSystemSettingSwitchBar.SwitchBarChangeCallback,
+ Preference.OnPreferenceChangeListener {
private static final String TAG = "ProfilesSettings";
public static final String EXTRA_PROFILE = "Profile";
@@ -73,9 +80,6 @@ public class ProfilesSettings extends SettingsPreferenceFragment
private ProfileManager mProfileManager;
private CMBaseSystemSettingSwitchBar mProfileEnabler;
- private ViewPager mViewPager;
- private TextView mEmptyText;
- private ProfilesPagerAdapter mAdapter;
private View mAddProfileFab;
private boolean mEnabled;
@@ -101,14 +105,42 @@ public class ProfilesSettings extends SettingsPreferenceFragment
}
@Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ addPreferencesFromResource(R.xml.profiles_settings);
+ }
+
+ @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- mContainer = container;
+ Bundle savedInstanceState) {
+ View view = super.onCreateView(inflater, container, savedInstanceState);
+ FrameLayout frameLayout = new FrameLayout(getActivity());
+ mContainer = frameLayout;
+ frameLayout.addView(view);
+ return frameLayout;
+ }
- View view = inflater.inflate(R.layout.profile_tabs, container, false);
- mViewPager = (ViewPager) view.findViewById(R.id.pager);
- mEmptyText = (TextView) view.findViewById(R.id.empty);
- mAddProfileFab = view.findViewById(R.id.floating_action_button);
+ @Override
+ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ // Add a footer to avoid a situation where the FAB would cover the last
+ // item's options in a non-scrollable listview.
+ ListView listView = getListView();
+ View footer = LayoutInflater.from(getActivity())
+ .inflate(R.layout.empty_list_entry_footer, listView, false);
+ listView.addFooterView(footer);
+ listView.setFooterDividersEnabled(false);
+ footer.setOnClickListener(null);
+
+ View v = LayoutInflater.from(getActivity())
+ .inflate(R.layout.empty_textview, (ViewGroup) view, true);
+
+ TextView emptyTextView = (TextView) v.findViewById(R.id.empty);
+ listView.setEmptyView(emptyTextView);
+
+ View fab = LayoutInflater.from(getActivity())
+ .inflate(R.layout.fab, mContainer, true);
+ mAddProfileFab = fab.findViewById(R.id.floating_action_button);
mAddProfileFab.setOnClickListener(
new View.OnClickListener() {
@Override
@@ -116,11 +148,6 @@ public class ProfilesSettings extends SettingsPreferenceFragment
addProfile();
}
});
-
- mAdapter = new ProfilesPagerAdapter(getChildFragmentManager());
- mViewPager.setAdapter(mAdapter);
-
- return view;
}
@Override
@@ -223,6 +250,9 @@ public class ProfilesSettings extends SettingsPreferenceFragment
mProfileManager.resetAll();
mProfileManager.setActiveProfile(
mProfileManager.getActiveProfile().getUuid());
+ dialog.dismiss();
+ refreshList();
+
}
})
.setNegativeButton(R.string.cancel, null)
@@ -237,8 +267,11 @@ public class ProfilesSettings extends SettingsPreferenceFragment
activity.invalidateOptionsMenu();
mAddProfileFab.setVisibility(mEnabled ? View.VISIBLE : View.GONE);
- mViewPager.setVisibility(mEnabled ? View.VISIBLE : View.GONE);
- mEmptyText.setVisibility(mEnabled ? View.GONE : View.VISIBLE);
+ if (!mEnabled) {
+ getPreferenceScreen().removeAll(); // empty it
+ } else {
+ refreshList();
+ }
}
@Override
@@ -251,32 +284,50 @@ public class ProfilesSettings extends SettingsPreferenceFragment
getActivity().sendBroadcast(intent);
}
- class ProfilesPagerAdapter extends FragmentStatePagerAdapter {
- Fragment[] frags = { new ProfilesList() };
- String[] titles = { getString(R.string.profile_profiles_manage) };
-
- ProfilesPagerAdapter(FragmentManager fm) {
- super(fm);
- }
-
- @Override
- public Fragment getItem(int position) {
- return frags[position];
- }
+ public void refreshList() {
+ PreferenceScreen plist = getPreferenceScreen();
+ plist.removeAll();
+
+ // Get active profile, if null
+ Profile prof = mProfileManager.getActiveProfile();
+ String selectedKey = prof != null ? prof.getUuid().toString() : null;
+
+ for (Profile profile : mProfileManager.getProfiles()) {
+ Bundle args = new Bundle();
+ args.putParcelable(ProfilesSettings.EXTRA_PROFILE, profile);
+ args.putBoolean(ProfilesSettings.EXTRA_NEW_PROFILE, false);
+
+ ProfilesPreference ppref = new ProfilesPreference(this, args);
+ ppref.setKey(profile.getUuid().toString());
+ ppref.setTitle(profile.getName());
+ ppref.setPersistent(false);
+ ppref.setOnPreferenceChangeListener(this);
+ ppref.setSelectable(true);
+ ppref.setEnabled(true);
+
+ if (TextUtils.equals(selectedKey, ppref.getKey())) {
+ ppref.setChecked(true);
+ }
- @Override
- public int getCount() {
- return frags.length;
+ plist.addPreference(ppref);
}
+ }
- @Override
- public CharSequence getPageTitle(int position) {
- return titles[position];
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (newValue instanceof String) {
+ setSelectedProfile((String) newValue);
+ refreshList();
}
+ return true;
+ }
- public void refreshProfiles() {
- ((ProfilesList) frags[0]).refreshList();
+ private void setSelectedProfile(String key) {
+ try {
+ UUID selectedUuid = UUID.fromString(key);
+ mProfileManager.setActiveProfile(selectedUuid);
+ } catch (IllegalArgumentException ex) {
+ ex.printStackTrace();
}
-
}
+
}