summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2012-05-10 15:53:47 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-05-10 15:53:47 -0700
commitee10ceccde8155016af557e96c9ac6a6e2bb477d (patch)
treed8bd4dc8e954e542cb2015d1c1318931ca9465cd
parent2f3b5314333b36e1fbc058a70a7ec89cec7f96d4 (diff)
parent7a3221bb95efd2e38e2aea243bcb13577bb276b3 (diff)
downloadpackages_apps_settings-ee10ceccde8155016af557e96c9ac6a6e2bb477d.zip
packages_apps_settings-ee10ceccde8155016af557e96c9ac6a6e2bb477d.tar.gz
packages_apps_settings-ee10ceccde8155016af557e96c9ac6a6e2bb477d.tar.bz2
Merge "Use Spinner instead of Tabs, so that a 4th entry doesn't disappear off the screen." into jb-dev
-rw-r--r--res/layout/apps_spinner_dropdown_item.xml (renamed from res/layout/manage_apps_tab_content.xml)31
-rw-r--r--res/layout/apps_spinner_item.xml27
-rw-r--r--res/layout/manage_apps_spinner_content.xml51
-rw-r--r--src/com/android/settings/applications/ManageApplications.java167
4 files changed, 180 insertions, 96 deletions
diff --git a/res/layout/manage_apps_tab_content.xml b/res/layout/apps_spinner_dropdown_item.xml
index b36501b..6f641e7 100644
--- a/res/layout/manage_apps_tab_content.xml
+++ b/res/layout/apps_spinner_dropdown_item.xml
@@ -2,7 +2,7 @@
<!--
/*
**
-** Copyright 2011, The Android Open Source Project
+** Copyright 2012, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
@@ -17,26 +17,11 @@
** limitations under the License.
*/
-->
-
-<TabHost
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@android:id/tabhost"
+<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@android:id/text1"
+ style="?android:attr/spinnerDropDownItemStyle"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:singleLine="true"
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"/>
-
- <FrameLayout
- android:id="@android:id/tabcontent"
- android:layout_width="match_parent"
- android:layout_height="0dip"
- android:layout_weight="1" />
-
- </LinearLayout>
-</TabHost>
+ android:layout_height="?android:attr/listPreferredItemHeightSmall"
+ android:ellipsize="marquee" />
diff --git a/res/layout/apps_spinner_item.xml b/res/layout/apps_spinner_item.xml
new file mode 100644
index 0000000..1ca6ffc
--- /dev/null
+++ b/res/layout/apps_spinner_item.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, The Android Open Source 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.
+*/
+-->
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@android:id/text1"
+ style="?android:attr/spinnerItemStyle"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:singleLine="true"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:ellipsize="marquee" />
diff --git a/res/layout/manage_apps_spinner_content.xml b/res/layout/manage_apps_spinner_content.xml
new file mode 100644
index 0000000..cbf0a40
--- /dev/null
+++ b/res/layout/manage_apps_spinner_content.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, The Android Open Source 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.
+*/
+-->
+
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <Spinner
+ android:id="@+id/spinner"
+ android:layout_width="wrap_content"
+ android:layout_height="48sp"
+ android:minWidth="180dp"
+ android:layout_marginLeft="@*android:dimen/preference_fragment_padding_side"
+ android:layout_marginRight="@*android:dimen/preference_fragment_padding_side"
+ />
+
+ <ImageView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@*android:dimen/preference_fragment_padding_side"
+ android:layout_marginRight="@*android:dimen/preference_fragment_padding_side"
+ android:scaleType="fitXY"
+ android:src="?android:attr/listDivider" />
+
+ <FrameLayout
+ android:id="@+id/spinner_content"
+ android:layout_width="match_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1" />
+
+</LinearLayout>
diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java
index eee9c43..fdbb289 100644
--- a/src/com/android/settings/applications/ManageApplications.java
+++ b/src/com/android/settings/applications/ManageApplications.java
@@ -36,6 +36,7 @@ import android.preference.PreferenceActivity;
import android.provider.Settings;
import android.text.format.Formatter;
import android.util.Log;
+import android.util.SparseIntArray;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -47,11 +48,13 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
+import android.widget.FrameLayout;
import android.widget.ListView;
-import android.widget.TabHost;
+import android.widget.Spinner;
import android.widget.TextView;
import com.android.internal.app.IMediaContainerService;
@@ -113,8 +116,7 @@ final class CanBeOnSdCardChecker {
* intent.
*/
public class ManageApplications extends Fragment implements
- OnItemClickListener,
- TabHost.TabContentFactory, TabHost.OnTabChangeListener {
+ OnItemClickListener {
static final String TAG = "ManageApplications";
static final boolean DEBUG = false;
@@ -122,7 +124,7 @@ public class ManageApplications extends Fragment implements
private static final String EXTRA_FILTER_APPS = "filterApps";
private static final String EXTRA_SORT_ORDER = "sortOrder";
private static final String EXTRA_SHOW_BACKGROUND = "showBackground";
- private static final String EXTRA_DEFAULT_TAB_TAG = "defaultTabTag";
+ private static final String EXTRA_DEFAULT_LIST_TYPE = "defaultListType";
// attributes used as keys when passing values to InstalledAppDetails activity
public static final String APP_CHG = "chg";
@@ -178,8 +180,8 @@ public class ManageApplications extends Fragment implements
TextView mFreeStorageText;
private Menu mOptionsMenu;
-
- // These are for keeping track of activity and tab switch state.
+
+ // These are for keeping track of activity and spinner switch state.
private int mCurView;
private boolean mCreatedRunning;
@@ -189,20 +191,19 @@ public class ManageApplications extends Fragment implements
private boolean mLastShowedInternalStorage = true;
private long mLastUsedStorage, mLastAppStorage, mLastFreeStorage;
- static final String TAB_DOWNLOADED = "Downloaded";
- static final String TAB_RUNNING = "Running";
- static final String TAB_ALL = "All";
- static final String TAB_SDCARD = "OnSdCard";
+ static final int LIST_TYPE_DOWNLOADED = 0;
+ static final int LIST_TYPE_RUNNING = 1;
+ static final int LIST_TYPE_SDCARD = 2;
+ static final int LIST_TYPE_ALL = 3;
private View mRootView;
private boolean mShowBackground = false;
- // -------------- Copied from TabActivity --------------
-
- private TabHost mTabHost;
- private String mDefaultTab = null;
+ private int mDefaultListType = -1;
+ private SparseIntArray mIndexToType = new SparseIntArray(4);
- // -------------- Copied from TabActivity --------------
+ private Spinner mSpinner;
+ private FrameLayout mSpinnerContent;
final Runnable mRunningProcessesAvail = new Runnable() {
public void run() {
@@ -210,6 +211,14 @@ public class ManageApplications extends Fragment implements
}
};
+ static class AppFilterAdapter extends ArrayAdapter<String> {
+
+ public AppFilterAdapter(Context context) {
+ super(context, R.layout.apps_spinner_item);
+ setDropDownViewResource(R.layout.apps_spinner_dropdown_item);
+ }
+ }
+
/*
* Custom adapter implementation for the ListView
* This adapter maintains a map for each displayed application and its properties
@@ -509,7 +518,7 @@ public class ManageApplications extends Fragment implements
mApplicationsAdapter = new ApplicationsAdapter(mApplicationsState);
Intent intent = getActivity().getIntent();
String action = intent.getAction();
- String defaultTabTag = TAB_DOWNLOADED;
+ int defaultListType = LIST_TYPE_DOWNLOADED;
String className = getArguments() != null
? getArguments().getString("classname") : null;
if (className == null) {
@@ -517,27 +526,27 @@ public class ManageApplications extends Fragment implements
}
if (className.equals(RunningServicesActivity.class.getName())
|| className.endsWith(".RunningServices")) {
- defaultTabTag = TAB_RUNNING;
+ defaultListType = LIST_TYPE_RUNNING;
} else if (className.equals(StorageUseActivity.class.getName())
|| Intent.ACTION_MANAGE_PACKAGE_STORAGE.equals(action)
|| className.endsWith(".StorageUse")) {
mSortOrder = SORT_ORDER_SIZE;
mFilterApps = FILTER_APPS_ALL;
- defaultTabTag = TAB_ALL;
+ defaultListType = LIST_TYPE_ALL;
} else if (Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS.equals(action)) {
- // Select the all-apps tab, with the default sorting
- defaultTabTag = TAB_ALL;
+ // Select the all-apps list, with the default sorting
+ defaultListType = LIST_TYPE_ALL;
}
-
+
if (savedInstanceState != null) {
mSortOrder = savedInstanceState.getInt(EXTRA_SORT_ORDER, mSortOrder);
mFilterApps = savedInstanceState.getInt(EXTRA_FILTER_APPS, mFilterApps);
- String tmp = savedInstanceState.getString(EXTRA_DEFAULT_TAB_TAG);
- if (tmp != null) defaultTabTag = tmp;
+ int tmp = savedInstanceState.getInt(EXTRA_DEFAULT_LIST_TYPE, -1);
+ if (tmp != -1) defaultListType = tmp;
mShowBackground = savedInstanceState.getBoolean(EXTRA_SHOW_BACKGROUND, false);
}
-
- mDefaultTab = defaultTabTag;
+
+ mDefaultListType = defaultListType;
final Intent containerIntent = new Intent().setComponent(
StorageMeasurement.DEFAULT_CONTAINER_COMPONENT);
@@ -579,34 +588,44 @@ public class ManageApplications extends Fragment implements
mCreatedRunning = mResumedRunning = false;
mCurView = VIEW_NOTHING;
- mTabHost = (TabHost) mInflater.inflate(R.layout.manage_apps_tab_content, container, false);
- mTabHost.setup();
- final TabHost tabHost = mTabHost;
- tabHost.addTab(tabHost.newTabSpec(TAB_DOWNLOADED)
- .setIndicator(getActivity().getString(R.string.filter_apps_third_party),
- getActivity().getResources().getDrawable(R.drawable.ic_tab_download))
- .setContent(this));
+ View spinnerHost = mInflater.inflate(R.layout.manage_apps_spinner_content,
+ container, false);
+
+ mSpinner = (Spinner) spinnerHost.findViewById(R.id.spinner);
+ mSpinnerContent = (FrameLayout) spinnerHost.findViewById(R.id.spinner_content);
+ mSpinnerContent.addView(mRootView);
+
+ AppFilterAdapter sa = new AppFilterAdapter(getActivity());
+ mIndexToType.append(sa.getCount(), LIST_TYPE_DOWNLOADED);
+ sa.add(getActivity().getString(R.string.filter_apps_third_party));
if (!Environment.isExternalStorageEmulated()) {
- tabHost.addTab(tabHost.newTabSpec(TAB_SDCARD)
- .setIndicator(getActivity().getString(R.string.filter_apps_onsdcard),
- getActivity().getResources().getDrawable(R.drawable.ic_tab_sdcard))
- .setContent(this));
- }
- tabHost.addTab(tabHost.newTabSpec(TAB_RUNNING)
- .setIndicator(getActivity().getString(R.string.filter_apps_running),
- getActivity().getResources().getDrawable(R.drawable.ic_tab_running))
- .setContent(this));
- tabHost.addTab(tabHost.newTabSpec(TAB_ALL)
- .setIndicator(getActivity().getString(R.string.filter_apps_all),
- getActivity().getResources().getDrawable(R.drawable.ic_tab_all))
- .setContent(this));
- tabHost.setCurrentTabByTag(mDefaultTab);
- tabHost.setOnTabChangedListener(this);
-
- // adjust padding around tabwidget as needed
- prepareCustomPreferencesList(container, mTabHost, mListView, false);
-
- return mTabHost;
+ mIndexToType.append(sa.getCount(), LIST_TYPE_SDCARD);
+ sa.add(getActivity().getString(R.string.filter_apps_onsdcard));
+ }
+ mIndexToType.append(sa.getCount(), LIST_TYPE_RUNNING);
+ sa.add(getActivity().getString(R.string.filter_apps_running));
+ mIndexToType.append(sa.getCount(), LIST_TYPE_ALL);
+ sa.add(getActivity().getString(R.string.filter_apps_all));
+
+ mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> parent,
+ View view, int position, long id) {
+ showCurrentList();
+ }
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ // Nothing
+ }
+
+ });
+
+ mSpinner.setSelection(getIndex(mDefaultListType));
+ mSpinner.setAdapter(sa);
+
+ prepareCustomPreferencesList(container, spinnerHost, mListView, false);
+
+ return spinnerHost;
}
@Override
@@ -618,9 +637,10 @@ public class ManageApplications extends Fragment implements
public void onResume() {
super.onResume();
mActivityResumed = true;
- showCurrentTab();
+ showCurrentList();
updateOptionsMenu();
- mTabHost.getTabWidget().setEnabled(true);
+ mSpinner.setEnabled(true);
+ mSpinnerContent.setEnabled(true);
}
@Override
@@ -628,8 +648,8 @@ public class ManageApplications extends Fragment implements
super.onSaveInstanceState(outState);
outState.putInt(EXTRA_SORT_ORDER, mSortOrder);
outState.putInt(EXTRA_FILTER_APPS, mFilterApps);
- if (mDefaultTab != null) {
- outState.putString(EXTRA_DEFAULT_TAB_TAG, mDefaultTab);
+ if (mDefaultListType != -1) {
+ outState.putInt(EXTRA_DEFAULT_LIST_TYPE, mDefaultListType);
}
outState.putBoolean(EXTRA_SHOW_BACKGROUND, mShowBackground);
}
@@ -643,7 +663,8 @@ public class ManageApplications extends Fragment implements
mRunningProcessesView.doPause();
mResumedRunning = false;
}
- mTabHost.getTabWidget().setEnabled(false);
+ mSpinner.setEnabled(false);
+ mSpinnerContent.setEnabled(false);
}
@Override
@@ -652,7 +673,14 @@ public class ManageApplications extends Fragment implements
mApplicationsState.requestSize(mCurrentPkgName);
}
}
-
+
+ private int getIndex(int listType) {
+ for (int i = 0; i < mIndexToType.size(); i++) {
+ if (listType == mIndexToType.get(i)) return i;
+ }
+ return 0;
+ }
+
// utility method used to start sub activity
private void startApplicationDetailsActivity() {
// start new fragment to display extended information
@@ -751,10 +779,6 @@ public class ManageApplications extends Fragment implements
mCurrentPkgName = entry.info.packageName;
startApplicationDetailsActivity();
}
-
- public View createTabContent(String tag) {
- return mRootView;
- }
static final int VIEW_NOTHING = 0;
static final int VIEW_LIST = 1;
@@ -910,16 +934,17 @@ public class ManageApplications extends Fragment implements
}
}
- public void showCurrentTab() {
- String tabId = mDefaultTab = mTabHost.getCurrentTabTag();
+ public void showCurrentList() {
+ int listType = mIndexToType.get(mSpinner.getSelectedItemPosition());
+
int newOption;
- if (TAB_DOWNLOADED.equalsIgnoreCase(tabId)) {
+ if (LIST_TYPE_DOWNLOADED == listType) {
newOption = FILTER_APPS_THIRD_PARTY;
- } else if (TAB_ALL.equalsIgnoreCase(tabId)) {
+ } else if (LIST_TYPE_ALL == listType) {
newOption = FILTER_APPS_ALL;
- } else if (TAB_SDCARD.equalsIgnoreCase(tabId)) {
+ } else if (LIST_TYPE_SDCARD == listType) {
newOption = FILTER_APPS_SDCARD;
- } else if (TAB_RUNNING.equalsIgnoreCase(tabId)) {
+ } else if (LIST_TYPE_RUNNING == listType) {
((InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(
getActivity().getWindow().getDecorView().getWindowToken(), 0);
@@ -929,17 +954,13 @@ public class ManageApplications extends Fragment implements
// Invalid option. Do nothing
return;
}
-
+
mFilterApps = newOption;
selectView(VIEW_LIST);
updateStorageUsage();
updateOptionsMenu();
}
- public void onTabChanged(String tabId) {
- showCurrentTab();
- }
-
private volatile IMediaContainerService mContainerService;
private final ServiceConnection mContainerConnection = new ServiceConnection() {