From f4eb85bc3c57ca70b577cea1524431fead4a4ccc Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Fri, 29 Oct 2010 16:53:04 -0700 Subject: [PATCH] Start fragmentizing Manage Applications. Change-Id: I0c3d6a358d0236893aba7257537ec32bfad4170d --- AndroidManifest.xml | 43 ++- proguard.flags | 2 +- res/xml/application_settings.xml | 8 +- src/com/android/settings/Settings.java | 15 +- .../settings/applications/InstalledAppDetails.java | 301 ++++++++++++--------- .../applications/InstalledAppDetailsTop.java | 13 + .../settings/applications/ManageApplications.java | 172 ++++++------ .../applications/RunningProcessesView.java | 6 +- 8 files changed, 333 insertions(+), 227 deletions(-) create mode 100644 src/com/android/settings/applications/InstalledAppDetailsTop.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 5b9af25dd6..5b30ba5d30 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -382,6 +382,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -412,6 +452,7 @@ + --> - + android:fragment="com.android.settings.applications.ManageApplications" + android:title="@string/manageapplications_settings_title" + android:summary="@string/manageapplications_settings_summary"> intentList = new ArrayList(); mPm.getPreferredActivities(intentList, prefActList, packageName); if(localLOGV) Log.i(TAG, "Have "+prefActList.size()+" number of activities in prefered list"); - TextView autoLaunchView = (TextView)findViewById(R.id.auto_launch); + TextView autoLaunchView = (TextView)mRootView.findViewById(R.id.auto_launch); if (prefActList.size() <= 0) { // Disable clear activities button autoLaunchView.setText(R.string.auto_launch_disable_text); @@ -433,8 +446,8 @@ public class InstalledAppDetails extends Activity } // Security permissions section - LinearLayout permsView = (LinearLayout) findViewById(R.id.permissions_section); - AppSecurityPermissions asp = new AppSecurityPermissions(this, packageName); + LinearLayout permsView = (LinearLayout) mRootView.findViewById(R.id.permissions_section); + AppSecurityPermissions asp = new AppSecurityPermissions(getActivity(), packageName); if (asp.getPermissionCount() > 0) { permsView.setVisibility(View.VISIBLE); // Make the security sections header visible @@ -457,9 +470,12 @@ public class InstalledAppDetails extends Activity if(localLOGV) Log.i(TAG, "appChanged="+appChanged); Intent intent = new Intent(); intent.putExtra(ManageApplications.APP_CHG, appChanged); - setResult(ManageApplications.RESULT_OK, intent); - if(finish) { - finish(); + Fragment target = getTargetFragment(); + if (target != null) { + target.onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, intent); + } + if (finish) { + getActivity().onBackPressed(); } } @@ -549,8 +565,7 @@ public class InstalledAppDetails extends Activity // Refresh size information again. mState.requestSize(mAppEntry.info.packageName); } else { - mMoveErrorCode = result; - showDialogInner(DLG_MOVE_FAILED); + showDialogInner(DLG_MOVE_FAILED, result); } refreshUi(); } @@ -567,105 +582,125 @@ public class InstalledAppDetails extends Activity if (mClearDataObserver == null) { mClearDataObserver = new ClearUserDataObserver(); } - ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); + ActivityManager am = (ActivityManager) + getActivity().getSystemService(Context.ACTIVITY_SERVICE); boolean res = am.clearApplicationUserData(packageName, mClearDataObserver); if (!res) { // Clearing data failed for some obscure reason. Just log error for now Log.i(TAG, "Couldnt clear application user data for package:"+packageName); - showDialogInner(DLG_CANNOT_CLEAR_DATA); + showDialogInner(DLG_CANNOT_CLEAR_DATA, 0); } else { mClearDataButton.setText(R.string.recompute_size); } } - private void showDialogInner(int id) { - //removeDialog(id); - showDialog(id); + private void showDialogInner(int id, int moveErrorCode) { + DialogFragment newFragment = MyAlertDialogFragment.newInstance(id, moveErrorCode); + newFragment.setTargetFragment(this, 0); + newFragment.show(getFragmentManager(), "dialog " + id); } - @Override - public Dialog onCreateDialog(int id, Bundle args) { - switch (id) { - case DLG_CLEAR_DATA: - return new AlertDialog.Builder(this) - .setTitle(getString(R.string.clear_data_dlg_title)) - .setIcon(android.R.drawable.ic_dialog_alert) - .setMessage(getString(R.string.clear_data_dlg_text)) - .setPositiveButton(R.string.dlg_ok, - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - // Clear user data here - initiateClearUserData(); - } - }) - .setNegativeButton(R.string.dlg_cancel, null) - .create(); - case DLG_FACTORY_RESET: - return new AlertDialog.Builder(this) - .setTitle(getString(R.string.app_factory_reset_dlg_title)) - .setIcon(android.R.drawable.ic_dialog_alert) - .setMessage(getString(R.string.app_factory_reset_dlg_text)) - .setPositiveButton(R.string.dlg_ok, - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - // Clear user data here - uninstallPkg(mAppEntry.info.packageName); - } - }) - .setNegativeButton(R.string.dlg_cancel, null) - .create(); - case DLG_APP_NOT_FOUND: - return new AlertDialog.Builder(this) - .setTitle(getString(R.string.app_not_found_dlg_title)) - .setIcon(android.R.drawable.ic_dialog_alert) - .setMessage(getString(R.string.app_not_found_dlg_title)) - .setNeutralButton(getString(R.string.dlg_ok), - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - //force to recompute changed value - setIntentAndFinish(true, true); - } - }) - .create(); - case DLG_CANNOT_CLEAR_DATA: - return new AlertDialog.Builder(this) - .setTitle(getString(R.string.clear_failed_dlg_title)) - .setIcon(android.R.drawable.ic_dialog_alert) - .setMessage(getString(R.string.clear_failed_dlg_text)) - .setNeutralButton(R.string.dlg_ok, - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - mClearDataButton.setEnabled(false); - //force to recompute changed value - setIntentAndFinish(false, false); - } - }) - .create(); - case DLG_FORCE_STOP: - return new AlertDialog.Builder(this) - .setTitle(getString(R.string.force_stop_dlg_title)) - .setIcon(android.R.drawable.ic_dialog_alert) - .setMessage(getString(R.string.force_stop_dlg_text)) - .setPositiveButton(R.string.dlg_ok, - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - // Force stop - forceStopPackage(mAppEntry.info.packageName); - } - }) - .setNegativeButton(R.string.dlg_cancel, null) - .create(); - case DLG_MOVE_FAILED: - CharSequence msg = getString(R.string.move_app_failed_dlg_text, - getMoveErrMsg(mMoveErrorCode)); - return new AlertDialog.Builder(this) - .setTitle(getString(R.string.move_app_failed_dlg_title)) - .setIcon(android.R.drawable.ic_dialog_alert) - .setMessage(msg) - .setNeutralButton(R.string.dlg_ok, null) - .create(); - } - return null; + public static class MyAlertDialogFragment extends DialogFragment { + + public static MyAlertDialogFragment newInstance(int id, int moveErrorCode) { + MyAlertDialogFragment frag = new MyAlertDialogFragment(); + Bundle args = new Bundle(); + args.putInt("id", id); + args.putInt("moveError", moveErrorCode); + frag.setArguments(args); + return frag; + } + + InstalledAppDetails getOwner() { + return (InstalledAppDetails)getTargetFragment(); + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + int id = getArguments().getInt("id"); + int moveErrorCode = getArguments().getInt("moveError"); + switch (id) { + case DLG_CLEAR_DATA: + return new AlertDialog.Builder(getActivity()) + .setTitle(getActivity().getText(R.string.clear_data_dlg_title)) + .setIcon(android.R.drawable.ic_dialog_alert) + .setMessage(getActivity().getText(R.string.clear_data_dlg_text)) + .setPositiveButton(R.string.dlg_ok, + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + // Clear user data here + getOwner().initiateClearUserData(); + } + }) + .setNegativeButton(R.string.dlg_cancel, null) + .create(); + case DLG_FACTORY_RESET: + return new AlertDialog.Builder(getActivity()) + .setTitle(getActivity().getText(R.string.app_factory_reset_dlg_title)) + .setIcon(android.R.drawable.ic_dialog_alert) + .setMessage(getActivity().getText(R.string.app_factory_reset_dlg_text)) + .setPositiveButton(R.string.dlg_ok, + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + // Clear user data here + getOwner().uninstallPkg(getOwner().mAppEntry.info.packageName); + } + }) + .setNegativeButton(R.string.dlg_cancel, null) + .create(); + case DLG_APP_NOT_FOUND: + return new AlertDialog.Builder(getActivity()) + .setTitle(getActivity().getText(R.string.app_not_found_dlg_title)) + .setIcon(android.R.drawable.ic_dialog_alert) + .setMessage(getActivity().getText(R.string.app_not_found_dlg_title)) + .setNeutralButton(getActivity().getText(R.string.dlg_ok), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + //force to recompute changed value + getOwner().setIntentAndFinish(true, true); + } + }) + .create(); + case DLG_CANNOT_CLEAR_DATA: + return new AlertDialog.Builder(getActivity()) + .setTitle(getActivity().getText(R.string.clear_failed_dlg_title)) + .setIcon(android.R.drawable.ic_dialog_alert) + .setMessage(getActivity().getText(R.string.clear_failed_dlg_text)) + .setNeutralButton(R.string.dlg_ok, + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + getOwner().mClearDataButton.setEnabled(false); + //force to recompute changed value + getOwner().setIntentAndFinish(false, false); + } + }) + .create(); + case DLG_FORCE_STOP: + return new AlertDialog.Builder(getActivity()) + .setTitle(getActivity().getText(R.string.force_stop_dlg_title)) + .setIcon(android.R.drawable.ic_dialog_alert) + .setMessage(getActivity().getText(R.string.force_stop_dlg_text)) + .setPositiveButton(R.string.dlg_ok, + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + // Force stop + getOwner().forceStopPackage(getOwner().mAppEntry.info.packageName); + } + }) + .setNegativeButton(R.string.dlg_cancel, null) + .create(); + case DLG_MOVE_FAILED: + CharSequence msg = getActivity().getString(R.string.move_app_failed_dlg_text, + getOwner().getMoveErrMsg(moveErrorCode)); + return new AlertDialog.Builder(getActivity()) + .setTitle(getActivity().getText(R.string.move_app_failed_dlg_title)) + .setIcon(android.R.drawable.ic_dialog_alert) + .setMessage(msg) + .setNeutralButton(R.string.dlg_ok, null) + .create(); + } + throw new IllegalArgumentException("unknown id " + id); + } } private void uninstallPkg(String packageName) { @@ -677,7 +712,7 @@ public class InstalledAppDetails extends Activity } private void forceStopPackage(String pkgName) { - ActivityManager am = (ActivityManager)getSystemService( + ActivityManager am = (ActivityManager)getActivity().getSystemService( Context.ACTIVITY_SERVICE); am.forceStopPackage(pkgName); checkForceStop(); @@ -686,7 +721,7 @@ public class InstalledAppDetails extends Activity private final BroadcastReceiver mCheckKillProcessesReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - mForceStopButton.setEnabled(getResultCode() != RESULT_CANCELED); + mForceStopButton.setEnabled(getResultCode() != Activity.RESULT_CANCELED); mForceStopButton.setOnClickListener(InstalledAppDetails.this); } }; @@ -696,7 +731,7 @@ public class InstalledAppDetails extends Activity Uri.fromParts("package", mAppEntry.info.packageName, null)); intent.putExtra(Intent.EXTRA_PACKAGES, new String[] { mAppEntry.info.packageName }); intent.putExtra(Intent.EXTRA_UID, mAppEntry.info.uid); - sendOrderedBroadcast(intent, null, mCheckKillProcessesReceiver, null, + getActivity().sendOrderedBroadcast(intent, null, mCheckKillProcessesReceiver, null, Activity.RESULT_CANCELED, null, null); } @@ -728,7 +763,7 @@ public class InstalledAppDetails extends Activity String packageName = mAppEntry.info.packageName; if(v == mUninstallButton) { if (mUpdatedSysApp) { - showDialogInner(DLG_FACTORY_RESET); + showDialogInner(DLG_FACTORY_RESET, 0); } else { if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { new DisableChanger(this, mAppEntry.info, mAppEntry.info.enabled ? @@ -748,7 +783,7 @@ public class InstalledAppDetails extends Activity mAppEntry.info.manageSpaceActivityName); startActivityForResult(intent, -1); } else { - showDialogInner(DLG_CLEAR_DATA); + showDialogInner(DLG_CLEAR_DATA, 0); } } else if (v == mClearCacheButton) { // Lazy initialization of observer @@ -757,7 +792,7 @@ public class InstalledAppDetails extends Activity } mPm.deleteApplicationCacheFiles(packageName, mClearCacheObserver); } else if (v == mForceStopButton) { - showDialogInner(DLG_FORCE_STOP); + showDialogInner(DLG_FORCE_STOP, 0); //forceStopPackage(mAppInfo.packageName); } else if (v == mMoveAppButton) { if (mPackageMoveObserver == null) { diff --git a/src/com/android/settings/applications/InstalledAppDetailsTop.java b/src/com/android/settings/applications/InstalledAppDetailsTop.java new file mode 100644 index 0000000000..5ad21820d1 --- /dev/null +++ b/src/com/android/settings/applications/InstalledAppDetailsTop.java @@ -0,0 +1,13 @@ +package com.android.settings.applications; + +import android.content.Intent; +import android.preference.PreferenceActivity; + +public class InstalledAppDetailsTop extends PreferenceActivity { + @Override + public Intent getIntent() { + Intent modIntent = new Intent(super.getIntent()); + modIntent.putExtra(EXTRA_SHOW_FRAGMENT, InstalledAppDetails.class.getName()); + return modIntent; + } +} diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java index 9ec65c13cf..217e333486 100644 --- a/src/com/android/settings/applications/ManageApplications.java +++ b/src/com/android/settings/applications/ManageApplications.java @@ -20,6 +20,7 @@ import com.android.internal.content.PackageHelper; import com.android.settings.R; import com.android.settings.applications.ApplicationsState.AppEntry; +import android.app.Fragment; import android.app.TabActivity; import android.content.Context; import android.content.DialogInterface; @@ -33,12 +34,14 @@ import android.os.Environment; import android.os.RemoteException; import android.os.ServiceManager; import android.os.StatFs; +import android.preference.PreferenceActivity; import android.provider.Settings; import android.text.format.Formatter; import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -54,6 +57,7 @@ import android.widget.Filterable; import android.widget.ImageView; import android.widget.ListView; import android.widget.TabHost; +import android.widget.TabWidget; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; @@ -108,8 +112,8 @@ final class CanBeOnSdCardChecker { * can be launched through Settings or via the ACTION_MANAGE_PACKAGE_STORAGE * intent. */ -public class ManageApplications extends TabActivity implements - OnItemClickListener, DialogInterface.OnCancelListener, +public class ManageApplications extends Fragment implements + OnItemClickListener, TabHost.TabContentFactory, TabHost.OnTabChangeListener { static final String TAG = "ManageApplications"; static final boolean DEBUG = false; @@ -169,13 +173,25 @@ public class ManageApplications extends TabActivity implements private boolean mResumedRunning; private boolean mActivityResumed; - private Object mNonConfigInstance; private StatFs mDataFileStats; private StatFs mSDCardFileStats; 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"; + private View mRootView; + + // -------------- Copied from TabActivity -------------- + + private TabHost mTabHost; + private String mDefaultTab = null; + + // -------------- Copied from TabActivity -------------- + final Runnable mRunningProcessesAvail = new Runnable() { public void run() { handleRunningProcessesAvail(); @@ -345,16 +361,16 @@ public class ManageApplications extends TabActivity implements @Override public void onRunningStateChanged(boolean running) { - setProgressBarIndeterminateVisibility(running); + getActivity().setProgressBarIndeterminateVisibility(running); } @Override public void onRebuildComplete(ArrayList apps) { if (mLoadingContainer.getVisibility() == View.VISIBLE) { mLoadingContainer.startAnimation(AnimationUtils.loadAnimation( - ManageApplications.this, android.R.anim.fade_out)); + getActivity(), android.R.anim.fade_out)); mListContainer.startAnimation(AnimationUtils.loadAnimation( - ManageApplications.this, android.R.anim.fade_in)); + getActivity(), android.R.anim.fade_in)); } mListContainer.setVisibility(View.VISIBLE); mLoadingContainer.setVisibility(View.GONE); @@ -453,7 +469,7 @@ public class ManageApplications extends TabActivity implements holder.entry = entry; if (entry.label != null) { holder.appName.setText(entry.label); - holder.appName.setTextColor(getResources().getColorStateList( + holder.appName.setTextColor(getActivity().getResources().getColorStateList( entry.info.enabled ? android.R.color.primary_text_dark : android.R.color.secondary_text_dark)); } @@ -491,18 +507,15 @@ public class ManageApplications extends TabActivity implements } } - static final String TAB_DOWNLOADED = "Downloaded"; - static final String TAB_RUNNING = "Running"; - static final String TAB_ALL = "All"; - static final String TAB_SDCARD = "OnSdCard"; - private View mRootView; - @Override - protected void onCreate(Bundle savedInstanceState) { + public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mApplicationsState = ApplicationsState.getInstance(getApplication()); + + setHasOptionsMenu(true); + + mApplicationsState = ApplicationsState.getInstance(getActivity().getApplication()); mApplicationsAdapter = new ApplicationsAdapter(mApplicationsState); - Intent intent = getIntent(); + Intent intent = getActivity().getIntent(); String action = intent.getAction(); String defaultTabTag = TAB_DOWNLOADED; if (intent.getComponent().getClassName().equals( @@ -526,19 +539,21 @@ public class ManageApplications extends TabActivity implements if (tmp != null) defaultTabTag = tmp; } - mNonConfigInstance = getLastNonConfigurationInstance(); + mDefaultTab = defaultTabTag; mDataFileStats = new StatFs("/data"); mSDCardFileStats = new StatFs(Environment.getExternalStorageDirectory().toString()); - // initialize some window features - requestWindowFeature(Window.FEATURE_RIGHT_ICON); - requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); - mInvalidSizeStr = getText(R.string.invalid_size_value); - mComputingSizeStr = getText(R.string.computing_size); + mInvalidSizeStr = getActivity().getText(R.string.invalid_size_value); + mComputingSizeStr = getActivity().getText(R.string.computing_size); + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // initialize the inflater - mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); - mRootView = mInflater.inflate(R.layout.manage_applications, null); + mInflater = inflater; + mRootView = inflater.inflate(R.layout.manage_applications, null); mLoadingContainer = mRootView.findViewById(R.id.loading_container); mListContainer = mRootView.findViewById(R.id.list_container); // Create adapter and list view here @@ -562,54 +577,56 @@ public class ManageApplications extends TabActivity implements mRunningProcessesView = (RunningProcessesView)mRootView.findViewById( R.id.running_processes); - final TabHost tabHost = getTabHost(); + View tabRoot = mInflater.inflate(com.android.internal.R.layout.tab_content, null); + mTabHost = (TabHost)tabRoot.findViewById(com.android.internal.R.id.tabhost); + mTabHost.setup(); + final TabHost tabHost = mTabHost; tabHost.addTab(tabHost.newTabSpec(TAB_DOWNLOADED) - .setIndicator(getString(R.string.filter_apps_third_party), - getResources().getDrawable(R.drawable.ic_tab_download)) + .setIndicator(getActivity().getString(R.string.filter_apps_third_party), + getActivity().getResources().getDrawable(R.drawable.ic_tab_download)) .setContent(this)); tabHost.addTab(tabHost.newTabSpec(TAB_ALL) - .setIndicator(getString(R.string.filter_apps_all), - getResources().getDrawable(R.drawable.ic_tab_all)) + .setIndicator(getActivity().getString(R.string.filter_apps_all), + getActivity().getResources().getDrawable(R.drawable.ic_tab_all)) .setContent(this)); tabHost.addTab(tabHost.newTabSpec(TAB_SDCARD) - .setIndicator(getString(R.string.filter_apps_onsdcard), - getResources().getDrawable(R.drawable.ic_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(getString(R.string.filter_apps_running), - getResources().getDrawable(R.drawable.ic_tab_running)) + .setIndicator(getActivity().getString(R.string.filter_apps_running), + getActivity().getResources().getDrawable(R.drawable.ic_tab_running)) .setContent(this)); - tabHost.setCurrentTabByTag(defaultTabTag); + tabHost.setCurrentTabByTag(mDefaultTab); tabHost.setOnTabChangedListener(this); + + return tabRoot; } - + @Override public void onStart() { super.onStart(); } @Override - protected void onResume() { + public void onResume() { super.onResume(); mActivityResumed = true; showCurrentTab(); } @Override - protected void onSaveInstanceState(Bundle outState) { + public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt("sortOrder", mSortOrder); outState.putInt("filterApps", mFilterApps); - outState.putString("defautTabTag", getTabHost().getCurrentTabTag()); + if (mTabHost != null) { + outState.putString("defautTabTag", mTabHost.getCurrentTabTag()); + } } @Override - public Object onRetainNonConfigurationInstance() { - return mRunningProcessesView.doRetainNonConfigurationInstance(); - } - - @Override - protected void onPause() { + public void onPause() { super.onPause(); mActivityResumed = false; mApplicationsAdapter.pause(); @@ -620,8 +637,7 @@ public class ManageApplications extends TabActivity implements } @Override - protected void onActivityResult(int requestCode, int resultCode, - Intent data) { + public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == INSTALLED_APP_DETAILS && mCurrentPkgName != null) { mApplicationsState.requestSize(mCurrentPkgName); } @@ -632,23 +648,34 @@ public class ManageApplications extends TabActivity implements // Create intent to start new activity Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", mCurrentPkgName, null)); - // start new activity to display extended information - startActivityForResult(intent, INSTALLED_APP_DETAILS); + // start new fragment to display extended information + Bundle args = new Bundle(); + args.putString(InstalledAppDetails.ARG_PACKAGE_NAME, mCurrentPkgName); + + PreferenceActivity pa = (PreferenceActivity)getActivity(); + if (pa.isMultiPane()) { + Fragment frag = new InstalledAppDetails(); + frag.setTargetFragment(this, INSTALLED_APP_DETAILS); + frag.setArguments(args); + frag.setTargetFragment(this, INSTALLED_APP_DETAILS); + pa.startPreferenceFragment(frag, true); + } else { + pa.startWithFragment(InstalledAppDetails.class.getName(), args); + } } @Override - public boolean onCreateOptionsMenu(Menu menu) { + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.add(0, SORT_ORDER_ALPHA, 1, R.string.sort_order_alpha) .setIcon(android.R.drawable.ic_menu_sort_alphabetically); menu.add(0, SORT_ORDER_SIZE, 2, R.string.sort_order_size) .setIcon(android.R.drawable.ic_menu_sort_by_size); menu.add(0, SHOW_RUNNING_SERVICES, 3, R.string.show_running_services); menu.add(0, SHOW_BACKGROUND_PROCESSES, 3, R.string.show_background_processes); - return true; } @Override - public boolean onPrepareOptionsMenu(Menu menu) { + public void onPrepareOptionsMenu(Menu menu) { /* * The running processes screen doesn't use the mApplicationsAdapter * so bringing up this menu in that case doesn't make any sense. @@ -665,7 +692,6 @@ public class ManageApplications extends TabActivity implements menu.findItem(SHOW_RUNNING_SERVICES).setVisible(false); menu.findItem(SHOW_BACKGROUND_PROCESSES).setVisible(false); } - return true; } @Override @@ -684,18 +710,6 @@ public class ManageApplications extends TabActivity implements return true; } - @Override - public boolean onKeyUp(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_SEARCH && event.isTracking()) { - if (mCurView != VIEW_RUNNING) { - ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)) - .showSoftInputUnchecked(0, null); - } - return true; - } - return super.onKeyUp(keyCode, event); - } - public void onItemClick(AdapterView parent, View view, int position, long id) { ApplicationsState.AppEntry entry = mApplicationsAdapter.getAppEntry(position); @@ -703,11 +717,6 @@ public class ManageApplications extends TabActivity implements startApplicationDetailsActivity(); } - // Finish the activity if the user presses the back button to cancel the activity - public void onCancel(DialogInterface dialog) { - finish(); - } - public View createTabContent(String tag) { return mRootView; } @@ -730,7 +739,7 @@ public class ManageApplications extends TabActivity implements if (mLastShowedInternalStorage) { mLastShowedInternalStorage = false; } - newLabel = this.getText(R.string.sd_card_storage); + newLabel = getActivity().getText(R.string.sd_card_storage); mSDCardFileStats.restat(Environment.getExternalStorageDirectory().toString()); try { totalStorage = (long)mSDCardFileStats.getBlockCount() * @@ -744,7 +753,7 @@ public class ManageApplications extends TabActivity implements if (!mLastShowedInternalStorage) { mLastShowedInternalStorage = true; } - newLabel = this.getText(R.string.internal_storage); + newLabel = getActivity().getText(R.string.internal_storage); mDataFileStats.restat("/data"); try { totalStorage = (long)mDataFileStats.getBlockCount() * @@ -769,14 +778,14 @@ public class ManageApplications extends TabActivity implements long usedStorage = totalStorage - freeStorage; if (mLastUsedStorage != usedStorage) { mLastUsedStorage = usedStorage; - String sizeStr = Formatter.formatShortFileSize(this, usedStorage); - mUsedStorageText.setText(getResources().getString( + String sizeStr = Formatter.formatShortFileSize(getActivity(), usedStorage); + mUsedStorageText.setText(getActivity().getResources().getString( R.string.service_foreground_processes, sizeStr)); } if (mLastFreeStorage != freeStorage) { mLastFreeStorage = freeStorage; - String sizeStr = Formatter.formatShortFileSize(this, freeStorage); - mFreeStorageText.setText(getResources().getString( + String sizeStr = Formatter.formatShortFileSize(getActivity(), freeStorage); + mFreeStorageText.setText(getActivity().getResources().getString( R.string.service_background_processes, sizeStr)); } } else { @@ -808,7 +817,7 @@ public class ManageApplications extends TabActivity implements } } else if (which == VIEW_RUNNING) { if (!mCreatedRunning) { - mRunningProcessesView.doCreate(null, mNonConfigInstance); + mRunningProcessesView.doCreate(null); mCreatedRunning = true; } boolean haveData = true; @@ -832,16 +841,16 @@ public class ManageApplications extends TabActivity implements void handleRunningProcessesAvail() { if (mCurView == VIEW_RUNNING) { mLoadingContainer.startAnimation(AnimationUtils.loadAnimation( - this, android.R.anim.fade_out)); + getActivity(), android.R.anim.fade_out)); mRunningProcessesView.startAnimation(AnimationUtils.loadAnimation( - this, android.R.anim.fade_in)); + getActivity(), android.R.anim.fade_in)); mRunningProcessesView.setVisibility(View.VISIBLE); mLoadingContainer.setVisibility(View.GONE); } } public void showCurrentTab() { - String tabId = getTabHost().getCurrentTabTag(); + String tabId = mTabHost.getCurrentTabTag(); int newOption; if (TAB_DOWNLOADED.equalsIgnoreCase(tabId)) { newOption = FILTER_APPS_THIRD_PARTY; @@ -850,8 +859,9 @@ public class ManageApplications extends TabActivity implements } else if (TAB_SDCARD.equalsIgnoreCase(tabId)) { newOption = FILTER_APPS_SDCARD; } else if (TAB_RUNNING.equalsIgnoreCase(tabId)) { - ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)) - .hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0); + ((InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) + .hideSoftInputFromWindow( + getActivity().getWindow().getDecorView().getWindowToken(), 0); selectView(VIEW_RUNNING); return; } else { diff --git a/src/com/android/settings/applications/RunningProcessesView.java b/src/com/android/settings/applications/RunningProcessesView.java index 86457bf8b7..779436560c 100644 --- a/src/com/android/settings/applications/RunningProcessesView.java +++ b/src/com/android/settings/applications/RunningProcessesView.java @@ -433,7 +433,7 @@ public class RunningProcessesView extends FrameLayout super(context, attrs); } - public void doCreate(Bundle savedInstanceState, Object nonConfigurationInstace) { + public void doCreate(Bundle savedInstanceState) { mAm = (ActivityManager)getContext().getSystemService(Context.ACTIVITY_SERVICE); mState = RunningState.getInstance(getContext()); LayoutInflater inflater = (LayoutInflater)getContext().getSystemService( @@ -486,10 +486,6 @@ public class RunningProcessesView extends FrameLayout return false; } - public Object doRetainNonConfigurationInstance() { - return null; - } - void updateTimes() { Iterator it = mActiveItems.values().iterator(); while (it.hasNext()) { -- 2.11.0