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 | |
| 19 | import com.android.internal.R; |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 20 | import com.android.internal.content.PackageMonitor; |
| 21 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 22 | import android.app.ActivityManager; |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 23 | import android.app.ActivityManagerNative; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.ComponentName; |
| 25 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.content.Intent; |
| 27 | import android.content.IntentFilter; |
| 28 | import android.content.pm.ActivityInfo; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 29 | import android.content.pm.LabeledIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.content.pm.PackageManager; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 31 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.content.pm.ResolveInfo; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 33 | import android.content.res.Resources; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 34 | import android.graphics.drawable.Drawable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.net.Uri; |
| 36 | import android.os.Bundle; |
| 37 | import android.os.PatternMatcher; |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 38 | import android.os.RemoteException; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 39 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.util.Log; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 41 | import android.view.LayoutInflater; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import android.view.View; |
| 43 | import android.view.ViewGroup; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 44 | import android.widget.AdapterView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.widget.BaseAdapter; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 46 | import android.widget.Button; |
| 47 | import android.widget.GridView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import android.widget.ImageView; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 49 | import android.widget.ListView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import android.widget.TextView; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 51 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import java.util.ArrayList; |
| 53 | import java.util.Collections; |
| 54 | import java.util.HashSet; |
| 55 | import java.util.Iterator; |
| 56 | import java.util.List; |
| 57 | import java.util.Set; |
| 58 | |
| 59 | /** |
| 60 | * This activity is displayed when the system attempts to start an Intent for |
| 61 | * which there is more than one matching activity, allowing the user to decide |
| 62 | * which to go to. It is not normally used directly by application developers. |
| 63 | */ |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 64 | public class ResolverActivity extends AlertActivity implements AdapterView.OnItemClickListener { |
| 65 | private static final String TAG = "ResolverActivity"; |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 66 | private static final boolean DEBUG = false; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 67 | |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 68 | private int mLaunchedFromUid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | private ResolveListAdapter mAdapter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | private PackageManager mPm; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 71 | private boolean mAlwaysUseOption; |
| 72 | private boolean mShowExtended; |
| 73 | private GridView mGrid; |
| 74 | private Button mAlwaysButton; |
| 75 | private Button mOnceButton; |
| 76 | private int mIconDpi; |
| 77 | private int mIconSize; |
Adam Powell | 589e6f9 | 2012-05-06 20:52:38 -0700 | [diff] [blame] | 78 | private int mMaxColumns; |
Adam Powell | d81cc4a | 2012-07-19 13:51:39 -0700 | [diff] [blame] | 79 | private int mLastSelected = GridView.INVALID_POSITION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 81 | private boolean mRegistered; |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 82 | private final PackageMonitor mPackageMonitor = new PackageMonitor() { |
| 83 | @Override public void onSomePackagesChanged() { |
| 84 | mAdapter.handlePackagesChanged(); |
| 85 | } |
| 86 | }; |
| 87 | |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 88 | private Intent makeMyIntent() { |
| 89 | Intent intent = new Intent(getIntent()); |
| 90 | // The resolver activity is set to be hidden from recent tasks. |
| 91 | // we don't want this attribute to be propagated to the next activity |
| 92 | // being launched. Note that if the original Intent also had this |
| 93 | // flag set, we are now losing it. That should be a very rare case |
| 94 | // and we can live with this. |
| 95 | intent.setFlags(intent.getFlags()&~Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 96 | return intent; |
| 97 | } |
| 98 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | @Override |
| 100 | protected void onCreate(Bundle savedInstanceState) { |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 101 | onCreate(savedInstanceState, makeMyIntent(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | getResources().getText(com.android.internal.R.string.whichApplication), |
Jeff Hamilton | d88e9aa | 2011-01-24 14:53:00 -0600 | [diff] [blame] | 103 | null, null, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | protected void onCreate(Bundle savedInstanceState, Intent intent, |
Jeff Hamilton | d88e9aa | 2011-01-24 14:53:00 -0600 | [diff] [blame] | 107 | CharSequence title, Intent[] initialIntents, List<ResolveInfo> rList, |
Mike Lockwood | bce6f8f | 2011-03-13 17:26:52 -0400 | [diff] [blame] | 108 | boolean alwaysUseOption) { |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 109 | setTheme(R.style.Theme_DeviceDefault_Light_Dialog_Alert); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | super.onCreate(savedInstanceState); |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 111 | try { |
| 112 | mLaunchedFromUid = ActivityManagerNative.getDefault().getLaunchedFromUid( |
| 113 | getActivityToken()); |
| 114 | } catch (RemoteException e) { |
| 115 | mLaunchedFromUid = -1; |
| 116 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | mPm = getPackageManager(); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 118 | mAlwaysUseOption = alwaysUseOption; |
Adam Powell | 589e6f9 | 2012-05-06 20:52:38 -0700 | [diff] [blame] | 119 | mMaxColumns = getResources().getInteger(R.integer.config_maxResolverActivityColumns); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | intent.setComponent(null); |
| 121 | |
| 122 | AlertController.AlertParams ap = mAlertParams; |
| 123 | |
| 124 | ap.mTitle = title; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 126 | mPackageMonitor.register(this, getMainLooper(), false); |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 127 | mRegistered = true; |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 128 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 129 | final ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); |
| 130 | mIconDpi = am.getLauncherLargeIconDensity(); |
| 131 | mIconSize = am.getLauncherLargeIconSize(); |
| 132 | |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 133 | mAdapter = new ResolveListAdapter(this, intent, initialIntents, rList, |
| 134 | mLaunchedFromUid); |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 135 | int count = mAdapter.getCount(); |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 136 | if (mLaunchedFromUid < 0 || UserHandle.isIsolated(mLaunchedFromUid)) { |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 137 | // Gulp! |
| 138 | finish(); |
| 139 | return; |
| 140 | } else if (count > 1) { |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 141 | ap.mView = getLayoutInflater().inflate(R.layout.resolver_grid, null); |
| 142 | mGrid = (GridView) ap.mView.findViewById(R.id.resolver_grid); |
| 143 | mGrid.setAdapter(mAdapter); |
| 144 | mGrid.setOnItemClickListener(this); |
| 145 | mGrid.setOnItemLongClickListener(new ItemLongClickListener()); |
| 146 | |
| 147 | if (alwaysUseOption) { |
| 148 | mGrid.setChoiceMode(ListView.CHOICE_MODE_SINGLE); |
| 149 | } |
| 150 | |
| 151 | resizeGrid(); |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 152 | } else if (count == 1) { |
Amith Yamasani | 203a2f4 | 2012-10-03 20:16:40 -0700 | [diff] [blame] | 153 | startActivity(mAdapter.intentForPosition(0)); |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 154 | mPackageMonitor.unregister(); |
| 155 | mRegistered = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | finish(); |
| 157 | return; |
| 158 | } else { |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 159 | ap.mMessage = getResources().getText(R.string.noApplications); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | setupAlert(); |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 163 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 164 | if (alwaysUseOption) { |
| 165 | final ViewGroup buttonLayout = (ViewGroup) findViewById(R.id.button_bar); |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 166 | if (buttonLayout != null) { |
| 167 | buttonLayout.setVisibility(View.VISIBLE); |
| 168 | mAlwaysButton = (Button) buttonLayout.findViewById(R.id.button_always); |
| 169 | mOnceButton = (Button) buttonLayout.findViewById(R.id.button_once); |
| 170 | } else { |
| 171 | mAlwaysUseOption = false; |
| 172 | } |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 173 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | } |
| 175 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 176 | void resizeGrid() { |
| 177 | final int itemCount = mAdapter.getCount(); |
Adam Powell | 589e6f9 | 2012-05-06 20:52:38 -0700 | [diff] [blame] | 178 | mGrid.setNumColumns(Math.min(itemCount, mMaxColumns)); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | Drawable getIcon(Resources res, int resId) { |
| 182 | Drawable result; |
| 183 | try { |
| 184 | result = res.getDrawableForDensity(resId, mIconDpi); |
| 185 | } catch (Resources.NotFoundException e) { |
| 186 | result = null; |
| 187 | } |
| 188 | |
| 189 | return result; |
| 190 | } |
| 191 | |
| 192 | Drawable loadIconForResolveInfo(ResolveInfo ri) { |
| 193 | Drawable dr; |
| 194 | try { |
| 195 | if (ri.resolvePackageName != null && ri.icon != 0) { |
| 196 | dr = getIcon(mPm.getResourcesForApplication(ri.resolvePackageName), ri.icon); |
| 197 | if (dr != null) { |
| 198 | return dr; |
| 199 | } |
| 200 | } |
| 201 | final int iconRes = ri.getIconResource(); |
| 202 | if (iconRes != 0) { |
| 203 | dr = getIcon(mPm.getResourcesForApplication(ri.activityInfo.packageName), iconRes); |
| 204 | if (dr != null) { |
| 205 | return dr; |
| 206 | } |
| 207 | } |
| 208 | } catch (NameNotFoundException e) { |
| 209 | Log.e(TAG, "Couldn't find resources for package", e); |
| 210 | } |
| 211 | return ri.loadIcon(mPm); |
| 212 | } |
| 213 | |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 214 | @Override |
| 215 | protected void onRestart() { |
| 216 | super.onRestart(); |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 217 | if (!mRegistered) { |
| 218 | mPackageMonitor.register(this, getMainLooper(), false); |
| 219 | mRegistered = true; |
| 220 | } |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 221 | mAdapter.handlePackagesChanged(); |
| 222 | } |
| 223 | |
| 224 | @Override |
| 225 | protected void onStop() { |
| 226 | super.onStop(); |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 227 | if (mRegistered) { |
| 228 | mPackageMonitor.unregister(); |
| 229 | mRegistered = false; |
| 230 | } |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 231 | if ((getIntent().getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0) { |
| 232 | // This resolver is in the unusual situation where it has been |
| 233 | // launched at the top of a new task. We don't let it be added |
| 234 | // to the recent tasks shown to the user, and we need to make sure |
| 235 | // that each time we are launched we get the correct launching |
| 236 | // uid (not re-using the same resolver from an old launching uid), |
| 237 | // so we will now finish ourself since being no longer visible, |
| 238 | // the user probably can't get back to us. |
| 239 | if (!isChangingConfigurations()) { |
| 240 | finish(); |
| 241 | } |
| 242 | } |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 245 | @Override |
Adam Powell | 9bee466 | 2012-05-08 11:07:23 -0700 | [diff] [blame] | 246 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 247 | super.onRestoreInstanceState(savedInstanceState); |
| 248 | if (mAlwaysUseOption) { |
| 249 | final int checkedPos = mGrid.getCheckedItemPosition(); |
| 250 | final boolean enabled = checkedPos != GridView.INVALID_POSITION; |
Adam Powell | d81cc4a | 2012-07-19 13:51:39 -0700 | [diff] [blame] | 251 | mLastSelected = checkedPos; |
Adam Powell | 9bee466 | 2012-05-08 11:07:23 -0700 | [diff] [blame] | 252 | mAlwaysButton.setEnabled(enabled); |
| 253 | mOnceButton.setEnabled(enabled); |
| 254 | if (enabled) { |
| 255 | mGrid.setSelection(checkedPos); |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | @Override |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 261 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
Adam Powell | d81cc4a | 2012-07-19 13:51:39 -0700 | [diff] [blame] | 262 | final int checkedPos = mGrid.getCheckedItemPosition(); |
| 263 | final boolean hasValidSelection = checkedPos != GridView.INVALID_POSITION; |
Adam Powell | bdda4e7 | 2012-07-20 11:22:03 -0700 | [diff] [blame] | 264 | if (mAlwaysUseOption && (!hasValidSelection || mLastSelected != checkedPos)) { |
Adam Powell | d81cc4a | 2012-07-19 13:51:39 -0700 | [diff] [blame] | 265 | mAlwaysButton.setEnabled(hasValidSelection); |
| 266 | mOnceButton.setEnabled(hasValidSelection); |
| 267 | if (hasValidSelection) { |
Adam Powell | 9bee466 | 2012-05-08 11:07:23 -0700 | [diff] [blame] | 268 | mGrid.smoothScrollToPosition(checkedPos); |
| 269 | } |
Adam Powell | d81cc4a | 2012-07-19 13:51:39 -0700 | [diff] [blame] | 270 | mLastSelected = checkedPos; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 271 | } else { |
| 272 | startSelected(position, false); |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | public void onButtonClick(View v) { |
| 277 | final int id = v.getId(); |
| 278 | startSelected(mGrid.getCheckedItemPosition(), id == R.id.button_always); |
| 279 | dismiss(); |
| 280 | } |
| 281 | |
| 282 | void startSelected(int which, boolean always) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | ResolveInfo ri = mAdapter.resolveInfoForPosition(which); |
| 284 | Intent intent = mAdapter.intentForPosition(which); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 285 | onIntentSelected(ri, intent, always); |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 286 | finish(); |
| 287 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 289 | protected void onIntentSelected(ResolveInfo ri, Intent intent, boolean alwaysCheck) { |
| 290 | if (alwaysCheck) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 291 | // Build a reasonable intent filter, based on what matched. |
| 292 | IntentFilter filter = new IntentFilter(); |
| 293 | |
| 294 | if (intent.getAction() != null) { |
| 295 | filter.addAction(intent.getAction()); |
| 296 | } |
| 297 | Set<String> categories = intent.getCategories(); |
| 298 | if (categories != null) { |
| 299 | for (String cat : categories) { |
| 300 | filter.addCategory(cat); |
| 301 | } |
| 302 | } |
| 303 | filter.addCategory(Intent.CATEGORY_DEFAULT); |
| 304 | |
| 305 | int cat = ri.match&IntentFilter.MATCH_CATEGORY_MASK; |
| 306 | Uri data = intent.getData(); |
| 307 | if (cat == IntentFilter.MATCH_CATEGORY_TYPE) { |
| 308 | String mimeType = intent.resolveType(this); |
| 309 | if (mimeType != null) { |
| 310 | try { |
| 311 | filter.addDataType(mimeType); |
| 312 | } catch (IntentFilter.MalformedMimeTypeException e) { |
| 313 | Log.w("ResolverActivity", e); |
| 314 | filter = null; |
| 315 | } |
| 316 | } |
Dianne Hackborn | 5ef402b | 2010-03-26 17:17:25 -0700 | [diff] [blame] | 317 | } |
| 318 | if (data != null && data.getScheme() != null) { |
| 319 | // We need the data specification if there was no type, |
| 320 | // OR if the scheme is not one of our magical "file:" |
| 321 | // or "content:" schemes (see IntentFilter for the reason). |
| 322 | if (cat != IntentFilter.MATCH_CATEGORY_TYPE |
| 323 | || (!"file".equals(data.getScheme()) |
| 324 | && !"content".equals(data.getScheme()))) { |
| 325 | filter.addDataScheme(data.getScheme()); |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 326 | |
Dianne Hackborn | 5ef402b | 2010-03-26 17:17:25 -0700 | [diff] [blame] | 327 | // Look through the resolved filter to determine which part |
| 328 | // of it matched the original Intent. |
| 329 | Iterator<IntentFilter.AuthorityEntry> aIt = ri.filter.authoritiesIterator(); |
| 330 | if (aIt != null) { |
| 331 | while (aIt.hasNext()) { |
| 332 | IntentFilter.AuthorityEntry a = aIt.next(); |
| 333 | if (a.match(data) >= 0) { |
| 334 | int port = a.getPort(); |
| 335 | filter.addDataAuthority(a.getHost(), |
| 336 | port >= 0 ? Integer.toString(port) : null); |
| 337 | break; |
| 338 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 339 | } |
| 340 | } |
Dianne Hackborn | 5ef402b | 2010-03-26 17:17:25 -0700 | [diff] [blame] | 341 | Iterator<PatternMatcher> pIt = ri.filter.pathsIterator(); |
| 342 | if (pIt != null) { |
| 343 | String path = data.getPath(); |
| 344 | while (path != null && pIt.hasNext()) { |
| 345 | PatternMatcher p = pIt.next(); |
| 346 | if (p.match(path)) { |
| 347 | filter.addDataPath(p.getPath(), p.getType()); |
| 348 | break; |
| 349 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | if (filter != null) { |
| 356 | final int N = mAdapter.mList.size(); |
| 357 | ComponentName[] set = new ComponentName[N]; |
| 358 | int bestMatch = 0; |
| 359 | for (int i=0; i<N; i++) { |
| 360 | ResolveInfo r = mAdapter.mList.get(i).ri; |
| 361 | set[i] = new ComponentName(r.activityInfo.packageName, |
| 362 | r.activityInfo.name); |
| 363 | if (r.match > bestMatch) bestMatch = r.match; |
| 364 | } |
| 365 | getPackageManager().addPreferredActivity(filter, bestMatch, set, |
Amith Yamasani | 203a2f4 | 2012-10-03 20:16:40 -0700 | [diff] [blame] | 366 | intent.getComponent()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | |
| 370 | if (intent != null) { |
Amith Yamasani | 203a2f4 | 2012-10-03 20:16:40 -0700 | [diff] [blame] | 371 | startActivity(intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | } |
| 374 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 375 | void showAppDetails(ResolveInfo ri) { |
| 376 | Intent in = new Intent().setAction("android.settings.APPLICATION_DETAILS_SETTINGS") |
Adam Powell | 0fc5b2b | 2012-07-18 18:20:29 -0700 | [diff] [blame] | 377 | .setData(Uri.fromParts("package", ri.activityInfo.packageName, null)) |
| 378 | .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
Amith Yamasani | 203a2f4 | 2012-10-03 20:16:40 -0700 | [diff] [blame] | 379 | startActivity(in); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 380 | } |
| 381 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | private final class DisplayResolveInfo { |
| 383 | ResolveInfo ri; |
| 384 | CharSequence displayLabel; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 385 | Drawable displayIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | CharSequence extendedInfo; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 387 | Intent origIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 389 | DisplayResolveInfo(ResolveInfo pri, CharSequence pLabel, |
| 390 | CharSequence pInfo, Intent pOrigIntent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | ri = pri; |
| 392 | displayLabel = pLabel; |
| 393 | extendedInfo = pInfo; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 394 | origIntent = pOrigIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | } |
| 396 | } |
| 397 | |
| 398 | private final class ResolveListAdapter extends BaseAdapter { |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 399 | private final Intent[] mInitialIntents; |
| 400 | private final List<ResolveInfo> mBaseResolveList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | private final Intent mIntent; |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 402 | private final int mLaunchedFromUid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | private final LayoutInflater mInflater; |
| 404 | |
| 405 | private List<DisplayResolveInfo> mList; |
| 406 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 407 | public ResolveListAdapter(Context context, Intent intent, |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 408 | Intent[] initialIntents, List<ResolveInfo> rList, int launchedFromUid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | mIntent = new Intent(intent); |
| 410 | mIntent.setComponent(null); |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 411 | mInitialIntents = initialIntents; |
| 412 | mBaseResolveList = rList; |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 413 | mLaunchedFromUid = launchedFromUid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 415 | mList = new ArrayList<DisplayResolveInfo>(); |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 416 | rebuildList(); |
| 417 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 419 | public void handlePackagesChanged() { |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 420 | final int oldItemCount = getCount(); |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 421 | rebuildList(); |
| 422 | notifyDataSetChanged(); |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 423 | final int newItemCount = getCount(); |
| 424 | if (newItemCount == 0) { |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 425 | // We no longer have any items... just finish the activity. |
| 426 | finish(); |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 427 | } else if (newItemCount != oldItemCount) { |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 428 | resizeGrid(); |
| 429 | } |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | private void rebuildList() { |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 433 | List<ResolveInfo> currentResolveList; |
| 434 | |
| 435 | mList.clear(); |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 436 | if (mBaseResolveList != null) { |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 437 | currentResolveList = mBaseResolveList; |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 438 | } else { |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 439 | currentResolveList = mPm.queryIntentActivities( |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 440 | mIntent, PackageManager.MATCH_DEFAULT_ONLY |
Amith Yamasani | 203a2f4 | 2012-10-03 20:16:40 -0700 | [diff] [blame] | 441 | | (mAlwaysUseOption ? PackageManager.GET_RESOLVED_FILTER : 0)); |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 442 | // Filter out any activities that the launched uid does not |
| 443 | // have permission for. We don't do this when we have an explicit |
| 444 | // list of resolved activities, because that only happens when |
| 445 | // we are being subclassed, so we can safely launch whatever |
| 446 | // they gave us. |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 447 | if (currentResolveList != null) { |
| 448 | for (int i=currentResolveList.size()-1; i >= 0; i--) { |
| 449 | ActivityInfo ai = currentResolveList.get(i).activityInfo; |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 450 | int granted = ActivityManager.checkComponentPermission( |
| 451 | ai.permission, mLaunchedFromUid, |
| 452 | ai.applicationInfo.uid, ai.exported); |
| 453 | if (granted != PackageManager.PERMISSION_GRANTED) { |
| 454 | // Access not allowed! |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 455 | currentResolveList.remove(i); |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 456 | } |
| 457 | } |
| 458 | } |
Jeff Hamilton | d88e9aa | 2011-01-24 14:53:00 -0600 | [diff] [blame] | 459 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | int N; |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 461 | if ((currentResolveList != null) && ((N = currentResolveList.size()) > 0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | // Only display the first matches that are either of equal |
| 463 | // priority or have asked to be default options. |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 464 | ResolveInfo r0 = currentResolveList.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | for (int i=1; i<N; i++) { |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 466 | ResolveInfo ri = currentResolveList.get(i); |
| 467 | if (DEBUG) Log.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 468 | "ResolveListActivity", |
| 469 | r0.activityInfo.name + "=" + |
| 470 | r0.priority + "/" + r0.isDefault + " vs " + |
| 471 | ri.activityInfo.name + "=" + |
| 472 | ri.priority + "/" + ri.isDefault); |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 473 | if (r0.priority != ri.priority || |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | r0.isDefault != ri.isDefault) { |
| 475 | while (i < N) { |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 476 | currentResolveList.remove(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | N--; |
| 478 | } |
| 479 | } |
| 480 | } |
| 481 | if (N > 1) { |
| 482 | ResolveInfo.DisplayNameComparator rComparator = |
| 483 | new ResolveInfo.DisplayNameComparator(mPm); |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 484 | Collections.sort(currentResolveList, rComparator); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 485 | } |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 486 | // First put the initial items at the top. |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 487 | if (mInitialIntents != null) { |
| 488 | for (int i=0; i<mInitialIntents.length; i++) { |
| 489 | Intent ii = mInitialIntents[i]; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 490 | if (ii == null) { |
| 491 | continue; |
| 492 | } |
| 493 | ActivityInfo ai = ii.resolveActivityInfo( |
| 494 | getPackageManager(), 0); |
| 495 | if (ai == null) { |
| 496 | Log.w("ResolverActivity", "No activity found for " |
| 497 | + ii); |
| 498 | continue; |
| 499 | } |
| 500 | ResolveInfo ri = new ResolveInfo(); |
| 501 | ri.activityInfo = ai; |
| 502 | if (ii instanceof LabeledIntent) { |
| 503 | LabeledIntent li = (LabeledIntent)ii; |
| 504 | ri.resolvePackageName = li.getSourcePackage(); |
| 505 | ri.labelRes = li.getLabelResource(); |
| 506 | ri.nonLocalizedLabel = li.getNonLocalizedLabel(); |
| 507 | ri.icon = li.getIconResource(); |
| 508 | } |
| 509 | mList.add(new DisplayResolveInfo(ri, |
| 510 | ri.loadLabel(getPackageManager()), null, ii)); |
| 511 | } |
| 512 | } |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 513 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 514 | // Check for applications with same name and use application name or |
| 515 | // package name if necessary |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 516 | r0 = currentResolveList.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 517 | int start = 0; |
| 518 | CharSequence r0Label = r0.loadLabel(mPm); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 519 | mShowExtended = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | for (int i = 1; i < N; i++) { |
| 521 | if (r0Label == null) { |
| 522 | r0Label = r0.activityInfo.packageName; |
| 523 | } |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 524 | ResolveInfo ri = currentResolveList.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 525 | CharSequence riLabel = ri.loadLabel(mPm); |
| 526 | if (riLabel == null) { |
| 527 | riLabel = ri.activityInfo.packageName; |
| 528 | } |
| 529 | if (riLabel.equals(r0Label)) { |
| 530 | continue; |
| 531 | } |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 532 | processGroup(currentResolveList, start, (i-1), r0, r0Label); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | r0 = ri; |
| 534 | r0Label = riLabel; |
| 535 | start = i; |
| 536 | } |
| 537 | // Process last group |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 538 | processGroup(currentResolveList, start, (N-1), r0, r0Label); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | |
| 542 | private void processGroup(List<ResolveInfo> rList, int start, int end, ResolveInfo ro, |
| 543 | CharSequence roLabel) { |
| 544 | // Process labels from start to i |
| 545 | int num = end - start+1; |
| 546 | if (num == 1) { |
| 547 | // No duplicate labels. Use label for entry at start |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 548 | mList.add(new DisplayResolveInfo(ro, roLabel, null, null)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 549 | } else { |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 550 | mShowExtended = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | boolean usePkg = false; |
| 552 | CharSequence startApp = ro.activityInfo.applicationInfo.loadLabel(mPm); |
| 553 | if (startApp == null) { |
| 554 | usePkg = true; |
| 555 | } |
| 556 | if (!usePkg) { |
| 557 | // Use HashSet to track duplicates |
| 558 | HashSet<CharSequence> duplicates = |
| 559 | new HashSet<CharSequence>(); |
| 560 | duplicates.add(startApp); |
| 561 | for (int j = start+1; j <= end ; j++) { |
| 562 | ResolveInfo jRi = rList.get(j); |
| 563 | CharSequence jApp = jRi.activityInfo.applicationInfo.loadLabel(mPm); |
| 564 | if ( (jApp == null) || (duplicates.contains(jApp))) { |
| 565 | usePkg = true; |
| 566 | break; |
| 567 | } else { |
| 568 | duplicates.add(jApp); |
| 569 | } |
| 570 | } |
| 571 | // Clear HashSet for later use |
| 572 | duplicates.clear(); |
| 573 | } |
| 574 | for (int k = start; k <= end; k++) { |
| 575 | ResolveInfo add = rList.get(k); |
| 576 | if (usePkg) { |
| 577 | // Use application name for all entries from start to end-1 |
| 578 | mList.add(new DisplayResolveInfo(add, roLabel, |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 579 | add.activityInfo.packageName, null)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 580 | } else { |
| 581 | // Use package name for all entries from start to end-1 |
| 582 | mList.add(new DisplayResolveInfo(add, roLabel, |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 583 | add.activityInfo.applicationInfo.loadLabel(mPm), null)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | } |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | public ResolveInfo resolveInfoForPosition(int position) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | return mList.get(position).ri; |
| 591 | } |
| 592 | |
| 593 | public Intent intentForPosition(int position) { |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 594 | DisplayResolveInfo dri = mList.get(position); |
| 595 | |
| 596 | Intent intent = new Intent(dri.origIntent != null |
| 597 | ? dri.origIntent : mIntent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 598 | intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT |
| 599 | |Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 600 | ActivityInfo ai = dri.ri.activityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | intent.setComponent(new ComponentName( |
| 602 | ai.applicationInfo.packageName, ai.name)); |
| 603 | return intent; |
| 604 | } |
| 605 | |
| 606 | public int getCount() { |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 607 | return mList.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | public Object getItem(int position) { |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 611 | return mList.get(position); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | public long getItemId(int position) { |
| 615 | return position; |
| 616 | } |
| 617 | |
| 618 | public View getView(int position, View convertView, ViewGroup parent) { |
| 619 | View view; |
| 620 | if (convertView == null) { |
| 621 | view = mInflater.inflate( |
| 622 | com.android.internal.R.layout.resolve_list_item, parent, false); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 623 | |
| 624 | // Fix the icon size even if we have different sized resources |
| 625 | ImageView icon = (ImageView)view.findViewById(R.id.icon); |
| 626 | ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) icon.getLayoutParams(); |
| 627 | lp.width = lp.height = mIconSize; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 628 | } else { |
| 629 | view = convertView; |
| 630 | } |
| 631 | bindView(view, mList.get(position)); |
| 632 | return view; |
| 633 | } |
| 634 | |
| 635 | private final void bindView(View view, DisplayResolveInfo info) { |
| 636 | TextView text = (TextView)view.findViewById(com.android.internal.R.id.text1); |
| 637 | TextView text2 = (TextView)view.findViewById(com.android.internal.R.id.text2); |
| 638 | ImageView icon = (ImageView)view.findViewById(R.id.icon); |
| 639 | text.setText(info.displayLabel); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 640 | if (mShowExtended) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | text2.setVisibility(View.VISIBLE); |
| 642 | text2.setText(info.extendedInfo); |
| 643 | } else { |
| 644 | text2.setVisibility(View.GONE); |
| 645 | } |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 646 | if (info.displayIcon == null) { |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 647 | info.displayIcon = loadIconForResolveInfo(info.ri); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 648 | } |
| 649 | icon.setImageDrawable(info.displayIcon); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 650 | } |
| 651 | } |
| 652 | |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 653 | class ItemLongClickListener implements AdapterView.OnItemLongClickListener { |
| 654 | |
| 655 | @Override |
| 656 | public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { |
| 657 | ResolveInfo ri = mAdapter.resolveInfoForPosition(position); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 658 | showAppDetails(ri); |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 659 | return true; |
| 660 | } |
| 661 | |
| 662 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 663 | } |
| 664 | |