The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.internal.app; |
| 18 | |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 20 | import android.os.AsyncTask; |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 21 | import android.util.ArrayMap; |
| 22 | import android.widget.AbsListView; |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 23 | import android.widget.GridView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import com.android.internal.R; |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 25 | import com.android.internal.content.PackageMonitor; |
| 26 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 27 | import android.app.ActivityManager; |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 28 | import android.app.ActivityManagerNative; |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 29 | import android.app.AppGlobals; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.content.ComponentName; |
| 31 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.content.Intent; |
| 33 | import android.content.IntentFilter; |
| 34 | import android.content.pm.ActivityInfo; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 35 | import android.content.pm.LabeledIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageManager; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.content.pm.ResolveInfo; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 39 | import android.content.res.Resources; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 40 | import android.graphics.drawable.Drawable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.net.Uri; |
| 42 | import android.os.Bundle; |
| 43 | import android.os.PatternMatcher; |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 44 | import android.os.RemoteException; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 45 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.util.Log; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 47 | import android.view.LayoutInflater; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import android.view.View; |
| 49 | import android.view.ViewGroup; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 50 | import android.widget.AdapterView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.widget.BaseAdapter; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 52 | import android.widget.Button; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.widget.ImageView; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 54 | import android.widget.ListView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.widget.TextView; |
Adam Powell | 4f6c205 | 2014-07-07 18:49:10 -0700 | [diff] [blame] | 56 | import com.android.internal.widget.ResolverDrawerLayout; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 57 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import java.util.ArrayList; |
| 59 | import java.util.Collections; |
| 60 | import java.util.HashSet; |
| 61 | import java.util.Iterator; |
| 62 | import java.util.List; |
| 63 | import java.util.Set; |
| 64 | |
| 65 | /** |
| 66 | * This activity is displayed when the system attempts to start an Intent for |
| 67 | * which there is more than one matching activity, allowing the user to decide |
| 68 | * which to go to. It is not normally used directly by application developers. |
| 69 | */ |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 70 | public class ResolverActivity extends Activity implements AdapterView.OnItemClickListener { |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 71 | private static final String TAG = "ResolverActivity"; |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 72 | private static final boolean DEBUG = true; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 73 | |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 74 | private int mLaunchedFromUid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | private ResolveListAdapter mAdapter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | private PackageManager mPm; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 77 | private boolean mAlwaysUseOption; |
| 78 | private boolean mShowExtended; |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 79 | private GridView mGridView; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 80 | private Button mAlwaysButton; |
| 81 | private Button mOnceButton; |
| 82 | private int mIconDpi; |
| 83 | private int mIconSize; |
Adam Powell | 589e6f9 | 2012-05-06 20:52:38 -0700 | [diff] [blame] | 84 | private int mMaxColumns; |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 85 | private int mLastSelected = ListView.INVALID_POSITION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 87 | private boolean mRegistered; |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 88 | private final PackageMonitor mPackageMonitor = new PackageMonitor() { |
| 89 | @Override public void onSomePackagesChanged() { |
| 90 | mAdapter.handlePackagesChanged(); |
| 91 | } |
| 92 | }; |
| 93 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 94 | private enum ActionTitle { |
| 95 | VIEW(Intent.ACTION_VIEW, |
| 96 | com.android.internal.R.string.whichViewApplication, |
| 97 | com.android.internal.R.string.whichViewApplicationNamed), |
| 98 | EDIT(Intent.ACTION_EDIT, |
| 99 | com.android.internal.R.string.whichEditApplication, |
| 100 | com.android.internal.R.string.whichEditApplicationNamed), |
| 101 | SEND(Intent.ACTION_SEND, |
| 102 | com.android.internal.R.string.whichSendApplication, |
| 103 | com.android.internal.R.string.whichSendApplicationNamed), |
| 104 | SENDTO(Intent.ACTION_SENDTO, |
| 105 | com.android.internal.R.string.whichSendApplication, |
| 106 | com.android.internal.R.string.whichSendApplicationNamed), |
| 107 | SEND_MULTIPLE(Intent.ACTION_SEND_MULTIPLE, |
| 108 | com.android.internal.R.string.whichSendApplication, |
| 109 | com.android.internal.R.string.whichSendApplicationNamed), |
| 110 | DEFAULT(null, |
| 111 | com.android.internal.R.string.whichApplication, |
| 112 | com.android.internal.R.string.whichApplicationNamed); |
| 113 | |
| 114 | public final String action; |
| 115 | public final int titleRes; |
| 116 | public final int namedTitleRes; |
| 117 | |
| 118 | ActionTitle(String action, int titleRes, int namedTitleRes) { |
| 119 | this.action = action; |
| 120 | this.titleRes = titleRes; |
| 121 | this.namedTitleRes = namedTitleRes; |
| 122 | } |
| 123 | |
| 124 | public static ActionTitle forAction(String action) { |
| 125 | for (ActionTitle title : values()) { |
| 126 | if (action != null && action.equals(title.action)) { |
| 127 | return title; |
| 128 | } |
| 129 | } |
| 130 | return DEFAULT; |
| 131 | } |
| 132 | } |
| 133 | |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 134 | private Intent makeMyIntent() { |
| 135 | Intent intent = new Intent(getIntent()); |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 136 | intent.setComponent(null); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 137 | // The resolver activity is set to be hidden from recent tasks. |
| 138 | // we don't want this attribute to be propagated to the next activity |
| 139 | // being launched. Note that if the original Intent also had this |
| 140 | // flag set, we are now losing it. That should be a very rare case |
| 141 | // and we can live with this. |
| 142 | intent.setFlags(intent.getFlags()&~Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 143 | return intent; |
| 144 | } |
| 145 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | @Override |
| 147 | protected void onCreate(Bundle savedInstanceState) { |
Christopher Tate | b72b363 | 2013-09-30 17:50:32 -0700 | [diff] [blame] | 148 | // Use a specialized prompt when we're handling the 'Home' app startActivity() |
| 149 | final int titleResource; |
| 150 | final Intent intent = makeMyIntent(); |
| 151 | final Set<String> categories = intent.getCategories(); |
| 152 | if (Intent.ACTION_MAIN.equals(intent.getAction()) |
| 153 | && categories != null |
| 154 | && categories.size() == 1 |
| 155 | && categories.contains(Intent.CATEGORY_HOME)) { |
| 156 | titleResource = com.android.internal.R.string.whichHomeApplication; |
| 157 | } else { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 158 | titleResource = 0; |
Christopher Tate | b72b363 | 2013-09-30 17:50:32 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 161 | onCreate(savedInstanceState, intent, |
| 162 | titleResource != 0 ? getResources().getText(titleResource) : null, titleResource, |
Jeff Hamilton | d88e9aa | 2011-01-24 14:53:00 -0600 | [diff] [blame] | 163 | null, null, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | } |
| 165 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 166 | /** |
| 167 | * Compatibility version for other bundled services that use this ocerload without |
| 168 | * a default title resource |
| 169 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | protected void onCreate(Bundle savedInstanceState, Intent intent, |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 171 | CharSequence title, Intent[] initialIntents, |
| 172 | List<ResolveInfo> rList, boolean alwaysUseOption) { |
| 173 | onCreate(savedInstanceState, intent, title, initialIntents, rList, alwaysUseOption); |
| 174 | } |
| 175 | |
| 176 | protected void onCreate(Bundle savedInstanceState, Intent intent, |
| 177 | CharSequence title, int defaultTitleRes, Intent[] initialIntents, |
| 178 | List<ResolveInfo> rList, boolean alwaysUseOption) { |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 179 | setTheme(R.style.Theme_DeviceDefault_Resolver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | super.onCreate(savedInstanceState); |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 181 | try { |
| 182 | mLaunchedFromUid = ActivityManagerNative.getDefault().getLaunchedFromUid( |
| 183 | getActivityToken()); |
| 184 | } catch (RemoteException e) { |
| 185 | mLaunchedFromUid = -1; |
| 186 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | mPm = getPackageManager(); |
Adam Powell | 589e6f9 | 2012-05-06 20:52:38 -0700 | [diff] [blame] | 188 | mMaxColumns = getResources().getInteger(R.integer.config_maxResolverActivityColumns); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 190 | mPackageMonitor.register(this, getMainLooper(), false); |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 191 | mRegistered = true; |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 192 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 193 | final ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); |
| 194 | mIconDpi = am.getLauncherLargeIconDensity(); |
| 195 | mIconSize = am.getLauncherLargeIconSize(); |
| 196 | |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 197 | mAdapter = new ResolveListAdapter(this, intent, initialIntents, rList, |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 198 | mLaunchedFromUid, alwaysUseOption); |
| 199 | |
| 200 | final int layoutId; |
| 201 | if (mAdapter.hasFilteredItem()) { |
| 202 | layoutId = R.layout.resolver_list_with_default; |
| 203 | alwaysUseOption = false; |
| 204 | } else { |
| 205 | layoutId = R.layout.resolver_list; |
| 206 | } |
| 207 | mAlwaysUseOption = alwaysUseOption; |
| 208 | |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 209 | int count = mAdapter.getCount(); |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 210 | if (mLaunchedFromUid < 0 || UserHandle.isIsolated(mLaunchedFromUid)) { |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 211 | // Gulp! |
| 212 | finish(); |
| 213 | return; |
| 214 | } else if (count > 1) { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 215 | setContentView(layoutId); |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 216 | mGridView = (GridView) findViewById(R.id.resolver_list); |
| 217 | mGridView.setAdapter(mAdapter); |
| 218 | mGridView.setOnItemClickListener(this); |
| 219 | mGridView.setOnItemLongClickListener(new ItemLongClickListener()); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 220 | |
| 221 | if (alwaysUseOption) { |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 222 | mGridView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 223 | } |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 224 | |
| 225 | resizeGrid(); |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 226 | } else if (count == 1) { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 227 | startActivity(mAdapter.intentForPosition(0, false)); |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 228 | mPackageMonitor.unregister(); |
| 229 | mRegistered = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | finish(); |
| 231 | return; |
| 232 | } else { |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 233 | setContentView(R.layout.resolver_list); |
| 234 | |
| 235 | final TextView empty = (TextView) findViewById(R.id.empty); |
| 236 | empty.setVisibility(View.VISIBLE); |
| 237 | |
| 238 | mGridView = (GridView) findViewById(R.id.resolver_list); |
| 239 | mGridView.setVisibility(View.GONE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | } |
| 241 | |
Adam Powell | 4f6c205 | 2014-07-07 18:49:10 -0700 | [diff] [blame] | 242 | final ResolverDrawerLayout rdl = (ResolverDrawerLayout) findViewById(R.id.contentPanel); |
| 243 | if (rdl != null) { |
| 244 | rdl.setOnClickOutsideListener(new View.OnClickListener() { |
| 245 | @Override |
| 246 | public void onClick(View v) { |
| 247 | finish(); |
| 248 | } |
| 249 | }); |
| 250 | } |
| 251 | |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 252 | final TextView titleView = (TextView) findViewById(R.id.title); |
| 253 | if (titleView != null) { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 254 | if (title == null) { |
| 255 | title = getTitleForAction(intent.getAction(), defaultTitleRes); |
| 256 | } |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 257 | titleView.setText(title); |
| 258 | } |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 259 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 260 | final ImageView iconView = (ImageView) findViewById(R.id.icon); |
| 261 | final DisplayResolveInfo iconInfo = mAdapter.getFilteredItem(); |
| 262 | if (iconView != null && iconInfo != null) { |
| 263 | new LoadIconIntoViewTask(iconView).execute(iconInfo); |
| 264 | } |
| 265 | |
| 266 | if (alwaysUseOption || mAdapter.hasFilteredItem()) { |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 267 | final ViewGroup buttonLayout = (ViewGroup) findViewById(R.id.button_bar); |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 268 | if (buttonLayout != null) { |
| 269 | buttonLayout.setVisibility(View.VISIBLE); |
| 270 | mAlwaysButton = (Button) buttonLayout.findViewById(R.id.button_always); |
| 271 | mOnceButton = (Button) buttonLayout.findViewById(R.id.button_once); |
| 272 | } else { |
| 273 | mAlwaysUseOption = false; |
| 274 | } |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 275 | } |
| 276 | |
| 277 | if (mAdapter.hasFilteredItem()) { |
| 278 | setAlwaysButtonEnabled(true, mAdapter.getFilteredPosition(), false); |
| 279 | mOnceButton.setEnabled(true); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | protected CharSequence getTitleForAction(String action, int defaultTitleRes) { |
| 284 | final ActionTitle title = ActionTitle.forAction(action); |
| 285 | final boolean named = mAdapter.hasFilteredItem(); |
| 286 | if (title == ActionTitle.DEFAULT && defaultTitleRes != 0) { |
| 287 | return getString(defaultTitleRes); |
| 288 | } else { |
| 289 | return named ? getString(title.namedTitleRes, mAdapter.getFilteredItem().displayLabel) : |
| 290 | getString(title.titleRes); |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 291 | } |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 294 | void resizeGrid() { |
| 295 | final int itemCount = mAdapter.getCount(); |
| 296 | mGridView.setNumColumns(Math.min(itemCount, mMaxColumns)); |
| 297 | } |
| 298 | |
| 299 | void dismiss() { |
| 300 | if (!isFinishing()) { |
| 301 | finish(); |
| 302 | } |
| 303 | } |
| 304 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 305 | Drawable getIcon(Resources res, int resId) { |
| 306 | Drawable result; |
| 307 | try { |
| 308 | result = res.getDrawableForDensity(resId, mIconDpi); |
| 309 | } catch (Resources.NotFoundException e) { |
| 310 | result = null; |
| 311 | } |
| 312 | |
| 313 | return result; |
| 314 | } |
| 315 | |
| 316 | Drawable loadIconForResolveInfo(ResolveInfo ri) { |
| 317 | Drawable dr; |
| 318 | try { |
| 319 | if (ri.resolvePackageName != null && ri.icon != 0) { |
| 320 | dr = getIcon(mPm.getResourcesForApplication(ri.resolvePackageName), ri.icon); |
| 321 | if (dr != null) { |
| 322 | return dr; |
| 323 | } |
| 324 | } |
| 325 | final int iconRes = ri.getIconResource(); |
| 326 | if (iconRes != 0) { |
| 327 | dr = getIcon(mPm.getResourcesForApplication(ri.activityInfo.packageName), iconRes); |
| 328 | if (dr != null) { |
| 329 | return dr; |
| 330 | } |
| 331 | } |
| 332 | } catch (NameNotFoundException e) { |
| 333 | Log.e(TAG, "Couldn't find resources for package", e); |
| 334 | } |
| 335 | return ri.loadIcon(mPm); |
| 336 | } |
| 337 | |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 338 | @Override |
| 339 | protected void onRestart() { |
| 340 | super.onRestart(); |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 341 | if (!mRegistered) { |
| 342 | mPackageMonitor.register(this, getMainLooper(), false); |
| 343 | mRegistered = true; |
| 344 | } |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 345 | mAdapter.handlePackagesChanged(); |
| 346 | } |
| 347 | |
| 348 | @Override |
| 349 | protected void onStop() { |
| 350 | super.onStop(); |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 351 | if (mRegistered) { |
| 352 | mPackageMonitor.unregister(); |
| 353 | mRegistered = false; |
| 354 | } |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 355 | if ((getIntent().getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0) { |
| 356 | // This resolver is in the unusual situation where it has been |
| 357 | // launched at the top of a new task. We don't let it be added |
| 358 | // to the recent tasks shown to the user, and we need to make sure |
| 359 | // that each time we are launched we get the correct launching |
| 360 | // uid (not re-using the same resolver from an old launching uid), |
| 361 | // so we will now finish ourself since being no longer visible, |
| 362 | // the user probably can't get back to us. |
| 363 | if (!isChangingConfigurations()) { |
| 364 | finish(); |
| 365 | } |
| 366 | } |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 367 | } |
| 368 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 369 | @Override |
Adam Powell | 9bee466 | 2012-05-08 11:07:23 -0700 | [diff] [blame] | 370 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 371 | super.onRestoreInstanceState(savedInstanceState); |
| 372 | if (mAlwaysUseOption) { |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 373 | final int checkedPos = mGridView.getCheckedItemPosition(); |
Nicolas Prevot | 5044988 | 2014-06-23 12:42:37 +0100 | [diff] [blame] | 374 | final boolean hasValidSelection = checkedPos != ListView.INVALID_POSITION; |
Adam Powell | d81cc4a | 2012-07-19 13:51:39 -0700 | [diff] [blame] | 375 | mLastSelected = checkedPos; |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 376 | setAlwaysButtonEnabled(hasValidSelection, checkedPos, true); |
Nicolas Prevot | 5044988 | 2014-06-23 12:42:37 +0100 | [diff] [blame] | 377 | mOnceButton.setEnabled(hasValidSelection); |
| 378 | if (hasValidSelection) { |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 379 | mGridView.setSelection(checkedPos); |
Adam Powell | 9bee466 | 2012-05-08 11:07:23 -0700 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | @Override |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 385 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 386 | final int checkedPos = mGridView.getCheckedItemPosition(); |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 387 | final boolean hasValidSelection = checkedPos != ListView.INVALID_POSITION; |
Adam Powell | bdda4e7 | 2012-07-20 11:22:03 -0700 | [diff] [blame] | 388 | if (mAlwaysUseOption && (!hasValidSelection || mLastSelected != checkedPos)) { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 389 | setAlwaysButtonEnabled(hasValidSelection, checkedPos, true); |
Adam Powell | d81cc4a | 2012-07-19 13:51:39 -0700 | [diff] [blame] | 390 | mOnceButton.setEnabled(hasValidSelection); |
| 391 | if (hasValidSelection) { |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 392 | mGridView.smoothScrollToPosition(checkedPos); |
Adam Powell | 9bee466 | 2012-05-08 11:07:23 -0700 | [diff] [blame] | 393 | } |
Adam Powell | d81cc4a | 2012-07-19 13:51:39 -0700 | [diff] [blame] | 394 | mLastSelected = checkedPos; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 395 | } else { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 396 | startSelected(position, false, true); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 400 | private void setAlwaysButtonEnabled(boolean hasValidSelection, int checkedPos, |
| 401 | boolean filtered) { |
Nicolas Prevot | 5044988 | 2014-06-23 12:42:37 +0100 | [diff] [blame] | 402 | boolean enabled = false; |
| 403 | if (hasValidSelection) { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 404 | ResolveInfo ri = mAdapter.resolveInfoForPosition(checkedPos, filtered); |
Nicolas Prevot | 5044988 | 2014-06-23 12:42:37 +0100 | [diff] [blame] | 405 | if (ri.targetUserId == UserHandle.USER_CURRENT) { |
| 406 | enabled = true; |
| 407 | } |
| 408 | } |
| 409 | mAlwaysButton.setEnabled(enabled); |
| 410 | } |
| 411 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 412 | public void onButtonClick(View v) { |
| 413 | final int id = v.getId(); |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 414 | startSelected(mAlwaysUseOption ? |
| 415 | mGridView.getCheckedItemPosition() : mAdapter.getFilteredPosition(), |
| 416 | id == R.id.button_always, |
| 417 | mAlwaysUseOption); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 418 | dismiss(); |
| 419 | } |
| 420 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 421 | void startSelected(int which, boolean always, boolean filtered) { |
Amith Yamasani | 07cd351 | 2013-09-18 13:16:00 -0700 | [diff] [blame] | 422 | if (isFinishing()) { |
| 423 | return; |
| 424 | } |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 425 | ResolveInfo ri = mAdapter.resolveInfoForPosition(which, filtered); |
| 426 | Intent intent = mAdapter.intentForPosition(which, filtered); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 427 | onIntentSelected(ri, intent, always); |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 428 | finish(); |
| 429 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 431 | protected void onIntentSelected(ResolveInfo ri, Intent intent, boolean alwaysCheck) { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 432 | if ((mAlwaysUseOption || mAdapter.hasFilteredItem()) && mAdapter.mOrigResolveList != null) { |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 433 | // Build a reasonable intent filter, based on what matched. |
| 434 | IntentFilter filter = new IntentFilter(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 436 | if (intent.getAction() != null) { |
| 437 | filter.addAction(intent.getAction()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | } |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 439 | Set<String> categories = intent.getCategories(); |
| 440 | if (categories != null) { |
| 441 | for (String cat : categories) { |
| 442 | filter.addCategory(cat); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | } |
| 444 | } |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 445 | filter.addCategory(Intent.CATEGORY_DEFAULT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 446 | |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 447 | int cat = ri.match&IntentFilter.MATCH_CATEGORY_MASK; |
| 448 | Uri data = intent.getData(); |
| 449 | if (cat == IntentFilter.MATCH_CATEGORY_TYPE) { |
| 450 | String mimeType = intent.resolveType(this); |
| 451 | if (mimeType != null) { |
| 452 | try { |
| 453 | filter.addDataType(mimeType); |
| 454 | } catch (IntentFilter.MalformedMimeTypeException e) { |
| 455 | Log.w("ResolverActivity", e); |
| 456 | filter = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | } |
| 458 | } |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 459 | } |
| 460 | if (data != null && data.getScheme() != null) { |
| 461 | // We need the data specification if there was no type, |
| 462 | // OR if the scheme is not one of our magical "file:" |
| 463 | // or "content:" schemes (see IntentFilter for the reason). |
| 464 | if (cat != IntentFilter.MATCH_CATEGORY_TYPE |
| 465 | || (!"file".equals(data.getScheme()) |
| 466 | && !"content".equals(data.getScheme()))) { |
| 467 | filter.addDataScheme(data.getScheme()); |
| 468 | |
| 469 | // Look through the resolved filter to determine which part |
| 470 | // of it matched the original Intent. |
| 471 | Iterator<PatternMatcher> pIt = ri.filter.schemeSpecificPartsIterator(); |
| 472 | if (pIt != null) { |
| 473 | String ssp = data.getSchemeSpecificPart(); |
| 474 | while (ssp != null && pIt.hasNext()) { |
| 475 | PatternMatcher p = pIt.next(); |
| 476 | if (p.match(ssp)) { |
| 477 | filter.addDataSchemeSpecificPart(p.getPath(), p.getType()); |
| 478 | break; |
| 479 | } |
Dianne Hackborn | df1c0bf | 2013-06-12 16:21:38 -0700 | [diff] [blame] | 480 | } |
| 481 | } |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 482 | Iterator<IntentFilter.AuthorityEntry> aIt = ri.filter.authoritiesIterator(); |
| 483 | if (aIt != null) { |
| 484 | while (aIt.hasNext()) { |
| 485 | IntentFilter.AuthorityEntry a = aIt.next(); |
| 486 | if (a.match(data) >= 0) { |
| 487 | int port = a.getPort(); |
| 488 | filter.addDataAuthority(a.getHost(), |
| 489 | port >= 0 ? Integer.toString(port) : null); |
| 490 | break; |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | pIt = ri.filter.pathsIterator(); |
| 495 | if (pIt != null) { |
| 496 | String path = data.getPath(); |
| 497 | while (path != null && pIt.hasNext()) { |
| 498 | PatternMatcher p = pIt.next(); |
| 499 | if (p.match(path)) { |
| 500 | filter.addDataPath(p.getPath(), p.getType()); |
| 501 | break; |
| 502 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | } |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 508 | if (filter != null) { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 509 | final int N = mAdapter.mOrigResolveList.size(); |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 510 | ComponentName[] set = new ComponentName[N]; |
| 511 | int bestMatch = 0; |
| 512 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 513 | ResolveInfo r = mAdapter.mOrigResolveList.get(i); |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 514 | set[i] = new ComponentName(r.activityInfo.packageName, |
| 515 | r.activityInfo.name); |
| 516 | if (r.match > bestMatch) bestMatch = r.match; |
| 517 | } |
| 518 | if (alwaysCheck) { |
| 519 | getPackageManager().addPreferredActivity(filter, bestMatch, set, |
| 520 | intent.getComponent()); |
| 521 | } else { |
| 522 | try { |
| 523 | AppGlobals.getPackageManager().setLastChosenActivity(intent, |
| 524 | intent.resolveTypeIfNeeded(getContentResolver()), |
| 525 | PackageManager.MATCH_DEFAULT_ONLY, |
| 526 | filter, bestMatch, intent.getComponent()); |
| 527 | } catch (RemoteException re) { |
| 528 | Log.d(TAG, "Error calling setLastChosenActivity\n" + re); |
| 529 | } |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 530 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | |
| 534 | if (intent != null) { |
Amith Yamasani | 203a2f4 | 2012-10-03 20:16:40 -0700 | [diff] [blame] | 535 | startActivity(intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 536 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | } |
| 538 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 539 | void showAppDetails(ResolveInfo ri) { |
| 540 | Intent in = new Intent().setAction("android.settings.APPLICATION_DETAILS_SETTINGS") |
Adam Powell | 0fc5b2b | 2012-07-18 18:20:29 -0700 | [diff] [blame] | 541 | .setData(Uri.fromParts("package", ri.activityInfo.packageName, null)) |
| 542 | .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
Amith Yamasani | 203a2f4 | 2012-10-03 20:16:40 -0700 | [diff] [blame] | 543 | startActivity(in); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 544 | } |
| 545 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | private final class DisplayResolveInfo { |
| 547 | ResolveInfo ri; |
| 548 | CharSequence displayLabel; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 549 | Drawable displayIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | CharSequence extendedInfo; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 551 | Intent origIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 553 | DisplayResolveInfo(ResolveInfo pri, CharSequence pLabel, |
| 554 | CharSequence pInfo, Intent pOrigIntent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 555 | ri = pri; |
| 556 | displayLabel = pLabel; |
| 557 | extendedInfo = pInfo; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 558 | origIntent = pOrigIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 559 | } |
| 560 | } |
| 561 | |
| 562 | private final class ResolveListAdapter extends BaseAdapter { |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 563 | private final Intent[] mInitialIntents; |
| 564 | private final List<ResolveInfo> mBaseResolveList; |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 565 | private ResolveInfo mLastChosen; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 566 | private final Intent mIntent; |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 567 | private final int mLaunchedFromUid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 568 | private final LayoutInflater mInflater; |
| 569 | |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 570 | List<DisplayResolveInfo> mList; |
| 571 | List<ResolveInfo> mOrigResolveList; |
| 572 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 573 | private int mLastChosenPosition = -1; |
| 574 | private boolean mFilterLastUsed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 575 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 576 | public ResolveListAdapter(Context context, Intent intent, |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 577 | Intent[] initialIntents, List<ResolveInfo> rList, int launchedFromUid, |
| 578 | boolean filterLastUsed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | mIntent = new Intent(intent); |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 580 | mInitialIntents = initialIntents; |
| 581 | mBaseResolveList = rList; |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 582 | mLaunchedFromUid = launchedFromUid; |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 583 | mInflater = LayoutInflater.from(context); |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 584 | mList = new ArrayList<DisplayResolveInfo>(); |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 585 | mFilterLastUsed = filterLastUsed; |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 586 | rebuildList(); |
| 587 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 588 | |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 589 | public void handlePackagesChanged() { |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 590 | final int oldItemCount = getCount(); |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 591 | rebuildList(); |
| 592 | notifyDataSetChanged(); |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 593 | final int newItemCount = getCount(); |
| 594 | if (newItemCount == 0) { |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 595 | // We no longer have any items... just finish the activity. |
| 596 | finish(); |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 597 | } else if (newItemCount != oldItemCount) { |
| 598 | resizeGrid(); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 599 | } |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 600 | } |
| 601 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 602 | public DisplayResolveInfo getFilteredItem() { |
| 603 | if (mFilterLastUsed && mLastChosenPosition >= 0) { |
| 604 | // Not using getItem since it offsets to dodge this position for the list |
| 605 | return mList.get(mLastChosenPosition); |
| 606 | } |
| 607 | return null; |
| 608 | } |
| 609 | |
| 610 | public int getFilteredPosition() { |
| 611 | if (mFilterLastUsed && mLastChosenPosition >= 0) { |
| 612 | return mLastChosenPosition; |
| 613 | } |
| 614 | return AbsListView.INVALID_POSITION; |
| 615 | } |
| 616 | |
| 617 | public boolean hasFilteredItem() { |
| 618 | return mFilterLastUsed && mLastChosenPosition >= 0; |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 621 | private void rebuildList() { |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 622 | List<ResolveInfo> currentResolveList; |
| 623 | |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 624 | try { |
| 625 | mLastChosen = AppGlobals.getPackageManager().getLastChosenActivity( |
| 626 | mIntent, mIntent.resolveTypeIfNeeded(getContentResolver()), |
| 627 | PackageManager.MATCH_DEFAULT_ONLY); |
| 628 | } catch (RemoteException re) { |
| 629 | Log.d(TAG, "Error calling setLastChosenActivity\n" + re); |
| 630 | } |
| 631 | |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 632 | mList.clear(); |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 633 | if (mBaseResolveList != null) { |
Xiong Li | e88b042 | 2014-04-10 15:25:45 +0800 | [diff] [blame] | 634 | currentResolveList = mOrigResolveList = mBaseResolveList; |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 635 | } else { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 636 | currentResolveList = mOrigResolveList = mPm.queryIntentActivities( |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 637 | mIntent, PackageManager.MATCH_DEFAULT_ONLY |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 638 | | (mFilterLastUsed ? PackageManager.GET_RESOLVED_FILTER : 0)); |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 639 | // Filter out any activities that the launched uid does not |
| 640 | // have permission for. We don't do this when we have an explicit |
| 641 | // list of resolved activities, because that only happens when |
| 642 | // we are being subclassed, so we can safely launch whatever |
| 643 | // they gave us. |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 644 | if (currentResolveList != null) { |
| 645 | for (int i=currentResolveList.size()-1; i >= 0; i--) { |
| 646 | ActivityInfo ai = currentResolveList.get(i).activityInfo; |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 647 | int granted = ActivityManager.checkComponentPermission( |
| 648 | ai.permission, mLaunchedFromUid, |
| 649 | ai.applicationInfo.uid, ai.exported); |
| 650 | if (granted != PackageManager.PERMISSION_GRANTED) { |
| 651 | // Access not allowed! |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 652 | if (mOrigResolveList == currentResolveList) { |
| 653 | mOrigResolveList = new ArrayList<ResolveInfo>(mOrigResolveList); |
| 654 | } |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 655 | currentResolveList.remove(i); |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | } |
Jeff Hamilton | d88e9aa | 2011-01-24 14:53:00 -0600 | [diff] [blame] | 659 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 660 | int N; |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 661 | if ((currentResolveList != null) && ((N = currentResolveList.size()) > 0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 662 | // Only display the first matches that are either of equal |
| 663 | // priority or have asked to be default options. |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 664 | ResolveInfo r0 = currentResolveList.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 665 | for (int i=1; i<N; i++) { |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 666 | ResolveInfo ri = currentResolveList.get(i); |
| 667 | if (DEBUG) Log.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | "ResolveListActivity", |
| 669 | r0.activityInfo.name + "=" + |
| 670 | r0.priority + "/" + r0.isDefault + " vs " + |
| 671 | ri.activityInfo.name + "=" + |
| 672 | ri.priority + "/" + ri.isDefault); |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 673 | if (r0.priority != ri.priority || |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | r0.isDefault != ri.isDefault) { |
| 675 | while (i < N) { |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 676 | if (mOrigResolveList == currentResolveList) { |
| 677 | mOrigResolveList = new ArrayList<ResolveInfo>(mOrigResolveList); |
| 678 | } |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 679 | currentResolveList.remove(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 680 | N--; |
| 681 | } |
| 682 | } |
| 683 | } |
| 684 | if (N > 1) { |
| 685 | ResolveInfo.DisplayNameComparator rComparator = |
| 686 | new ResolveInfo.DisplayNameComparator(mPm); |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 687 | Collections.sort(currentResolveList, rComparator); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 688 | } |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 689 | // First put the initial items at the top. |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 690 | if (mInitialIntents != null) { |
| 691 | for (int i=0; i<mInitialIntents.length; i++) { |
| 692 | Intent ii = mInitialIntents[i]; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 693 | if (ii == null) { |
| 694 | continue; |
| 695 | } |
| 696 | ActivityInfo ai = ii.resolveActivityInfo( |
| 697 | getPackageManager(), 0); |
| 698 | if (ai == null) { |
| 699 | Log.w("ResolverActivity", "No activity found for " |
| 700 | + ii); |
| 701 | continue; |
| 702 | } |
| 703 | ResolveInfo ri = new ResolveInfo(); |
| 704 | ri.activityInfo = ai; |
| 705 | if (ii instanceof LabeledIntent) { |
| 706 | LabeledIntent li = (LabeledIntent)ii; |
| 707 | ri.resolvePackageName = li.getSourcePackage(); |
| 708 | ri.labelRes = li.getLabelResource(); |
| 709 | ri.nonLocalizedLabel = li.getNonLocalizedLabel(); |
| 710 | ri.icon = li.getIconResource(); |
| 711 | } |
| 712 | mList.add(new DisplayResolveInfo(ri, |
| 713 | ri.loadLabel(getPackageManager()), null, ii)); |
| 714 | } |
| 715 | } |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 716 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 717 | // Check for applications with same name and use application name or |
| 718 | // package name if necessary |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 719 | r0 = currentResolveList.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 720 | int start = 0; |
| 721 | CharSequence r0Label = r0.loadLabel(mPm); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 722 | mShowExtended = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 723 | for (int i = 1; i < N; i++) { |
| 724 | if (r0Label == null) { |
| 725 | r0Label = r0.activityInfo.packageName; |
| 726 | } |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 727 | ResolveInfo ri = currentResolveList.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | CharSequence riLabel = ri.loadLabel(mPm); |
| 729 | if (riLabel == null) { |
| 730 | riLabel = ri.activityInfo.packageName; |
| 731 | } |
| 732 | if (riLabel.equals(r0Label)) { |
| 733 | continue; |
| 734 | } |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 735 | processGroup(currentResolveList, start, (i-1), r0, r0Label); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 736 | r0 = ri; |
| 737 | r0Label = riLabel; |
| 738 | start = i; |
| 739 | } |
| 740 | // Process last group |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 741 | processGroup(currentResolveList, start, (N-1), r0, r0Label); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 742 | } |
| 743 | } |
| 744 | |
| 745 | private void processGroup(List<ResolveInfo> rList, int start, int end, ResolveInfo ro, |
| 746 | CharSequence roLabel) { |
| 747 | // Process labels from start to i |
| 748 | int num = end - start+1; |
| 749 | if (num == 1) { |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 750 | if (mLastChosen != null |
| 751 | && mLastChosen.activityInfo.packageName.equals( |
| 752 | ro.activityInfo.packageName) |
| 753 | && mLastChosen.activityInfo.name.equals(ro.activityInfo.name)) { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 754 | mLastChosenPosition = mList.size(); |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 755 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 756 | // No duplicate labels. Use label for entry at start |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 757 | mList.add(new DisplayResolveInfo(ro, roLabel, null, null)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 758 | } else { |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 759 | mShowExtended = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 760 | boolean usePkg = false; |
| 761 | CharSequence startApp = ro.activityInfo.applicationInfo.loadLabel(mPm); |
| 762 | if (startApp == null) { |
| 763 | usePkg = true; |
| 764 | } |
| 765 | if (!usePkg) { |
| 766 | // Use HashSet to track duplicates |
| 767 | HashSet<CharSequence> duplicates = |
| 768 | new HashSet<CharSequence>(); |
| 769 | duplicates.add(startApp); |
| 770 | for (int j = start+1; j <= end ; j++) { |
| 771 | ResolveInfo jRi = rList.get(j); |
| 772 | CharSequence jApp = jRi.activityInfo.applicationInfo.loadLabel(mPm); |
| 773 | if ( (jApp == null) || (duplicates.contains(jApp))) { |
| 774 | usePkg = true; |
| 775 | break; |
| 776 | } else { |
| 777 | duplicates.add(jApp); |
| 778 | } |
| 779 | } |
| 780 | // Clear HashSet for later use |
| 781 | duplicates.clear(); |
| 782 | } |
| 783 | for (int k = start; k <= end; k++) { |
| 784 | ResolveInfo add = rList.get(k); |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 785 | if (mLastChosen != null |
| 786 | && mLastChosen.activityInfo.packageName.equals( |
| 787 | add.activityInfo.packageName) |
| 788 | && mLastChosen.activityInfo.name.equals(add.activityInfo.name)) { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 789 | mLastChosenPosition = mList.size(); |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 790 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 791 | if (usePkg) { |
| 792 | // Use application name for all entries from start to end-1 |
| 793 | mList.add(new DisplayResolveInfo(add, roLabel, |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 794 | add.activityInfo.packageName, null)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 795 | } else { |
| 796 | // Use package name for all entries from start to end-1 |
| 797 | mList.add(new DisplayResolveInfo(add, roLabel, |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 798 | add.activityInfo.applicationInfo.loadLabel(mPm), null)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | } |
| 800 | } |
| 801 | } |
| 802 | } |
| 803 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 804 | public ResolveInfo resolveInfoForPosition(int position, boolean filtered) { |
| 805 | return (filtered ? getItem(position) : mList.get(position)).ri; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | } |
| 807 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 808 | public Intent intentForPosition(int position, boolean filtered) { |
| 809 | DisplayResolveInfo dri = filtered ? getItem(position) : mList.get(position); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 810 | |
| 811 | Intent intent = new Intent(dri.origIntent != null |
| 812 | ? dri.origIntent : mIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 813 | intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT |
| 814 | |Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 815 | ActivityInfo ai = dri.ri.activityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 816 | intent.setComponent(new ComponentName( |
| 817 | ai.applicationInfo.packageName, ai.name)); |
| 818 | return intent; |
| 819 | } |
| 820 | |
| 821 | public int getCount() { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 822 | int result = mList.size(); |
| 823 | if (mFilterLastUsed && mLastChosenPosition >= 0) { |
| 824 | result--; |
| 825 | } |
| 826 | return result; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 827 | } |
| 828 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 829 | public DisplayResolveInfo getItem(int position) { |
| 830 | if (mFilterLastUsed && mLastChosenPosition >= 0 && position >= mLastChosenPosition) { |
| 831 | position++; |
| 832 | } |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 833 | return mList.get(position); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | public long getItemId(int position) { |
| 837 | return position; |
| 838 | } |
| 839 | |
| 840 | public View getView(int position, View convertView, ViewGroup parent) { |
| 841 | View view; |
| 842 | if (convertView == null) { |
| 843 | view = mInflater.inflate( |
| 844 | com.android.internal.R.layout.resolve_list_item, parent, false); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 845 | |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 846 | final ViewHolder holder = new ViewHolder(view); |
| 847 | view.setTag(holder); |
| 848 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 849 | // Fix the icon size even if we have different sized resources |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 850 | ViewGroup.LayoutParams lp = holder.icon.getLayoutParams(); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 851 | lp.width = lp.height = mIconSize; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | } else { |
| 853 | view = convertView; |
| 854 | } |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 855 | bindView(view, getItem(position)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 856 | return view; |
| 857 | } |
| 858 | |
| 859 | private final void bindView(View view, DisplayResolveInfo info) { |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 860 | final ViewHolder holder = (ViewHolder) view.getTag(); |
| 861 | holder.text.setText(info.displayLabel); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 862 | if (mShowExtended) { |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 863 | holder.text2.setVisibility(View.VISIBLE); |
| 864 | holder.text2.setText(info.extendedInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 865 | } else { |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 866 | holder.text2.setVisibility(View.GONE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 867 | } |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 868 | if (info.displayIcon == null) { |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 869 | new LoadIconTask().execute(info); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 870 | } |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 871 | holder.icon.setImageDrawable(info.displayIcon); |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | static class ViewHolder { |
| 876 | public TextView text; |
| 877 | public TextView text2; |
| 878 | public ImageView icon; |
| 879 | |
| 880 | public ViewHolder(View view) { |
| 881 | text = (TextView) view.findViewById(com.android.internal.R.id.text1); |
| 882 | text2 = (TextView) view.findViewById(com.android.internal.R.id.text2); |
| 883 | icon = (ImageView) view.findViewById(R.id.icon); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 884 | } |
| 885 | } |
| 886 | |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 887 | class ItemLongClickListener implements AdapterView.OnItemLongClickListener { |
| 888 | |
| 889 | @Override |
| 890 | public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 891 | ResolveInfo ri = mAdapter.resolveInfoForPosition(position, true); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 892 | showAppDetails(ri); |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 893 | return true; |
| 894 | } |
| 895 | |
| 896 | } |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 897 | |
| 898 | class LoadIconTask extends AsyncTask<DisplayResolveInfo, Void, DisplayResolveInfo> { |
| 899 | @Override |
| 900 | protected DisplayResolveInfo doInBackground(DisplayResolveInfo... params) { |
| 901 | final DisplayResolveInfo info = params[0]; |
| 902 | if (info.displayIcon == null) { |
| 903 | info.displayIcon = loadIconForResolveInfo(info.ri); |
| 904 | } |
| 905 | return info; |
| 906 | } |
| 907 | |
| 908 | @Override |
| 909 | protected void onPostExecute(DisplayResolveInfo info) { |
| 910 | mAdapter.notifyDataSetChanged(); |
| 911 | } |
| 912 | } |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame^] | 913 | |
| 914 | class LoadIconIntoViewTask extends AsyncTask<DisplayResolveInfo, Void, DisplayResolveInfo> { |
| 915 | final ImageView mTargetView; |
| 916 | |
| 917 | public LoadIconIntoViewTask(ImageView target) { |
| 918 | mTargetView = target; |
| 919 | } |
| 920 | |
| 921 | @Override |
| 922 | protected DisplayResolveInfo doInBackground(DisplayResolveInfo... params) { |
| 923 | final DisplayResolveInfo info = params[0]; |
| 924 | if (info.displayIcon == null) { |
| 925 | info.displayIcon = loadIconForResolveInfo(info.ri); |
| 926 | } |
| 927 | return info; |
| 928 | } |
| 929 | |
| 930 | @Override |
| 931 | protected void onPostExecute(DisplayResolveInfo info) { |
| 932 | mTargetView.setImageDrawable(info.displayIcon); |
| 933 | } |
| 934 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 935 | } |
| 936 | |