Permalink
Browse files

Profiles: Switch to Tabbed layout for the Profiles Settings screen

Patch set 9 - fixes padding for tablet devices

Change-Id: I2a118a5f1734c74cdbfbaa32d699ae4a377ba0cf
  • Loading branch information...
DvTonder committed Mar 17, 2012
1 parent 68d7a22 commit 272077d339e93cb06afeae34f9349e834b851959
View
@@ -15,5 +15,5 @@ LOCAL_PROGUARD_FLAG_FILES := proguard.flags
include $(BUILD_PACKAGE)
-# Use the folloing include to make our test apk.
+# Use the following include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))
@@ -28,7 +28,7 @@
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
-
+
<include layout="@layout/tab_widget" />
<FrameLayout
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<TabHost
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@android:id/tabhost"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <include layout="@layout/tab_widget" />
+
+ <ListView
+ android:id="@android:id/list"
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ android:layout_weight="0"/>
+
+ <FrameLayout
+ android:id="@+android:id/tabcontent"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"/>
+
+ </LinearLayout>
+</TabHost>
View
@@ -907,7 +907,7 @@
<string name="profile_profiles_manage">Profiles</string>
<string name="profile_profile_manage">Manage profile</string>
<string name="profile_applist_manage">Application list</string>
- <string name="profile_appgroups_manage">Manage application groups</string>
+ <string name="profile_appgroups_manage">Application groups</string>
<string name="profile_appgroup_manage">Profile</string>
<!-- Profile settings screen, section header for settings related to notification profiles -->
@@ -16,18 +16,5 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
-
- <PreferenceCategory
- android:title="@string/profile_appgroups_title">
- <PreferenceScreen
- android:key="app_groups"
- android:title="@string/profile_appgroups_manage"
- android:fragment="com.android.settings.profiles.AppGroupList" />
- </PreferenceCategory>
-
- <PreferenceCategory
- android:key="profiles_list"
- android:title="@string/profile_profiles_manage" />
-
-</PreferenceScreen>
+ xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
+ android:key="profiles_list" />
@@ -18,31 +18,23 @@
import java.util.UUID;
-import android.app.AlertDialog;
import android.app.NotificationGroup;
import android.app.ProfileManager;
-import android.content.Context;
-import android.content.DialogInterface;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.widget.EditText;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.Utils;
public class AppGroupList extends SettingsPreferenceFragment {
private static final String TAG = "AppGroupSettings";
public static final String PROFILE_SERVICE = "profile";
- private static final int MENU_ADD = Menu.FIRST;
-
private ProfileManager mProfileManager;
// constant value that can be used to check return code from sub activity.
@@ -56,64 +48,20 @@ public void onCreate(Bundle savedInstanceState) {
addPreferencesFromResource(R.xml.appgroup_list);
mProfileManager = (ProfileManager) getActivity().getSystemService(PROFILE_SERVICE);
}
-
- setHasOptionsMenu(true);
- }
-
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- MenuItem addAppGroup = menu.add(0, MENU_ADD, 0, R.string.profiles_add)
- .setIcon(R.drawable.ic_menu_add)
- .setAlphabeticShortcut('a');
- addAppGroup.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
- MenuItem.SHOW_AS_ACTION_WITH_TEXT);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case MENU_ADD:
- addAppGroup();
- return true;
- default:
- return false;
- }
}
@Override
public void onResume() {
super.onResume();
- fillList();
- }
+ refreshList();
- private void addAppGroup() {
- Context context = getActivity();
- if (context != null) {
- AlertDialog.Builder dialog = new AlertDialog.Builder(context);
- final EditText entry = new EditText(context);
- entry.setPadding(10, 10, 10, 10);
- dialog.setMessage(R.string.profile_appgroup_name_prompt);
- dialog.setView(entry);
- dialog.setPositiveButton(android.R.string.ok,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- NotificationGroup newGroup = new NotificationGroup(entry.getText().toString());
- mProfileManager.addNotificationGroup(newGroup);
- fillList();
- }
- });
- dialog.setNegativeButton(android.R.string.cancel,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- }
- });
- dialog.create().show();
+ // On tablet devices remove the padding
+ if (Utils.isScreenLarge()) {
+ getListView().setPadding(0, 0, 0, 0);
}
- }
+}
- private void fillList() {
+ public void refreshList() {
PreferenceScreen appgroupList = getPreferenceScreen();
appgroupList.removeAll();
@@ -0,0 +1,118 @@
+/*
+ * 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 android.app.Profile;
+import android.app.ProfileManager;
+import android.os.Bundle;
+import android.preference.Preference;
+import android.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.Utils;
+
+public class ProfilesList extends SettingsPreferenceFragment implements
+ Preference.OnPreferenceChangeListener {
+ static final String TAG = "ProfilesSettings";
+
+ public static final String EXTRA_POSITION = "position";
+
+ public static final String PROFILE_SERVICE = "profile";
+
+ public static final String RESTORE_CARRIERS_URI = "content://telephony/carriers/restore";
+
+ public static final String PREFERRED_APN_URI = "content://telephony/carriers/preferapn";
+
+ private String mSelectedKey;
+
+ private ProfileManager mProfileManager;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ if (getPreferenceManager() != null) {
+ addPreferencesFromResource(R.xml.profiles_settings);
+ mProfileManager = (ProfileManager) getActivity().getSystemService(PROFILE_SERVICE);
+
+ }
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ refreshList();
+
+ // On tablet devices remove the padding
+ if (Utils.isScreenLarge()) {
+ getListView().setPadding(0, 0, 0, 0);
+ }
+ }
+
+ public void refreshList() {
+ PreferenceScreen plist = getPreferenceScreen();
+ if (plist != null) {
+ plist.removeAll();
+
+ if (mProfileManager != null) {
+ mSelectedKey = mProfileManager.getActiveProfile().getUuid().toString();
+ for(Profile profile : mProfileManager.getProfiles()) {
+ Bundle args = new Bundle();
+ args.putParcelable("Profile", profile);
+
+ ProfilesPreference ppref = new ProfilesPreference(this, args);
+ ppref.setKey(profile.getUuid().toString());
+ ppref.setTitle(profile.getName());
+ ppref.setPersistent(false);
+ ppref.setOnPreferenceChangeListener(this);
+ ppref.setSelectable(true);
+
+ if ((mSelectedKey != null) && mSelectedKey.equals(ppref.getKey())) {
+ ppref.setChecked(true);
+ }
+
+ plist.addPreference(ppref);
+ }
+ }
+ }
+ }
+
+ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+ return super.onPreferenceTreeClick(preferenceScreen, preference);
+ }
+
+ 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);
+ mSelectedKey = key;
+ } catch (IllegalArgumentException ex) {
+ ex.printStackTrace();
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 272077d

Please sign in to comment.