diff options
10 files changed, 183 insertions, 149 deletions
diff --git a/core/java/com/android/internal/app/AbstractMultiProfilePagerAdapter.java b/core/java/com/android/internal/app/AbstractMultiProfilePagerAdapter.java index 2fd5bfd71656..c64b7051276a 100644 --- a/core/java/com/android/internal/app/AbstractMultiProfilePagerAdapter.java +++ b/core/java/com/android/internal/app/AbstractMultiProfilePagerAdapter.java @@ -15,6 +15,7 @@ */ package com.android.internal.app; import android.annotation.IntDef; +import android.annotation.Nullable; import android.content.Context; import android.os.UserHandle; import android.view.View; @@ -60,7 +61,7 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter { @Override public void onPageSelected(int position) { mCurrentPage = position; - getCurrentListAdapter().rebuildList(); + getActiveListAdapter().rebuildList(); } }); viewPager.setAdapter(this); @@ -89,7 +90,7 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter { } UserHandle getCurrentUserHandle() { - return getCurrentListAdapter().mResolverListController.getUserHandle(); + return getActiveListAdapter().mResolverListController.getUserHandle(); } @Override @@ -136,7 +137,17 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter { abstract Object getAdapterForIndex(int pageIndex); @VisibleForTesting - public abstract ResolverListAdapter getCurrentListAdapter(); + public abstract ResolverListAdapter getActiveListAdapter(); + + /** + * If this is a device with a work profile, returns the {@link ResolverListAdapter} instance + * of the profile that is not the active one. Otherwise returns {@code null}. For example, + * if the share sheet is launched in the work profile, this method returns the personal + * profile {@link ResolverListAdapter}. + * @see #getActiveListAdapter() + */ + @VisibleForTesting + public abstract @Nullable ResolverListAdapter getInactiveListAdapter(); abstract Object getCurrentRootAdapter(); diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index 1af39265dbcb..8856f99272b6 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -362,9 +362,7 @@ public class ChooserActivity extends ResolverActivity implements Log.i(TAG, "Hiding image preview area. Timed out waiting for preview to load" + " within " + mImageLoadTimeoutMillis + "ms."); collapseParentView(); - if (mChooserMultiProfilePagerAdapter.getCurrentRootAdapter() != null) { - mChooserMultiProfilePagerAdapter.getCurrentRootAdapter().hideContentPreview(); - } + hideContentPreview(); mHideParentOnFail = false; } } @@ -431,14 +429,14 @@ public class ChooserActivity extends ResolverActivity implements logDirectShareTargetReceived( MetricsEvent.ACTION_DIRECT_SHARE_TARGETS_LOADED_CHOOSER_SERVICE); sendVoiceChoicesIfNeeded(); - mChooserMultiProfilePagerAdapter.getCurrentListAdapter() + mChooserMultiProfilePagerAdapter.getActiveListAdapter() .completeServiceTargetLoading(); } } @Override public void handleMessage(Message msg) { - if (mChooserMultiProfilePagerAdapter.getCurrentListAdapter() == null || isDestroyed()) { + if (mChooserMultiProfilePagerAdapter.getActiveListAdapter() == null || isDestroyed()) { return; } @@ -455,7 +453,7 @@ public class ChooserActivity extends ResolverActivity implements if (sri.resultTargets != null) { // TODO(arangelov): Instead of using getCurrentListAdapter(), pass the // profileId as part of the message. - mChooserMultiProfilePagerAdapter.getCurrentListAdapter().addServiceResults( + mChooserMultiProfilePagerAdapter.getActiveListAdapter().addServiceResults( sri.originalTarget, sri.resultTargets, TARGET_TYPE_CHOOSER_TARGET); } unbindService(sri.connection); @@ -479,14 +477,14 @@ public class ChooserActivity extends ResolverActivity implements Log.d(TAG, "LIST_VIEW_UPDATE_MESSAGE; "); } - mChooserMultiProfilePagerAdapter.getCurrentListAdapter().refreshListView(); + mChooserMultiProfilePagerAdapter.getActiveListAdapter().refreshListView(); break; case SHORTCUT_MANAGER_SHARE_TARGET_RESULT: if (DEBUG) Log.d(TAG, "SHORTCUT_MANAGER_SHARE_TARGET_RESULT"); final ServiceResultInfo resultInfo = (ServiceResultInfo) msg.obj; if (resultInfo.resultTargets != null) { - mChooserMultiProfilePagerAdapter.getCurrentListAdapter().addServiceResults( + mChooserMultiProfilePagerAdapter.getActiveListAdapter().addServiceResults( resultInfo.originalTarget, resultInfo.resultTargets, msg.arg1); } break; @@ -646,7 +644,7 @@ public class ChooserActivity extends ResolverActivity implements if (isFinishing() || isDestroyed()) { return; } - if (mChooserMultiProfilePagerAdapter.getCurrentListAdapter().getCount() == 0) { + if (mChooserMultiProfilePagerAdapter.getActiveListAdapter().getCount() == 0) { return; } if (resultList.isEmpty()) { @@ -654,12 +652,12 @@ public class ChooserActivity extends ResolverActivity implements //TODO(arangelov) queryDirectShareTargets indirectly uses mIntents. // Investigate implications for work tab. queryDirectShareTargets( - mChooserMultiProfilePagerAdapter.getCurrentListAdapter(), true); + mChooserMultiProfilePagerAdapter.getActiveListAdapter(), true); return; } final List<DisplayResolveInfo> driList = getDisplayResolveInfos( - mChooserMultiProfilePagerAdapter.getCurrentListAdapter()); + mChooserMultiProfilePagerAdapter.getActiveListAdapter()); final List<ShortcutManager.ShareShortcutInfo> shareShortcutInfos = new ArrayList<>(); for (AppTarget appTarget : resultList) { @@ -809,7 +807,7 @@ public class ChooserActivity extends ResolverActivity implements @Override protected boolean postRebuildList(boolean rebuildCompleted) { - mChooserMultiProfilePagerAdapter.getCurrentRootAdapter().maybeLogActionShareWithPreview(); + updateContentPreview(); return postRebuildListInternal(rebuildCompleted); } @@ -862,7 +860,7 @@ public class ChooserActivity extends ResolverActivity implements public void onSomePackagesChanged() { // TODO(arangelov): Dispatch this to all adapters when we have the helper methods // in a follow-up CL - mChooserMultiProfilePagerAdapter.getCurrentListAdapter().handlePackagesChanged(); + mChooserMultiProfilePagerAdapter.getActiveListAdapter().handlePackagesChanged(); updateProfileViewButton(); } }; @@ -952,6 +950,12 @@ public class ChooserActivity extends ResolverActivity implements } } + private ViewGroup createContentPreviewView(ViewGroup parent) { + Intent targetIntent = getTargetIntent(); + int previewType = findPreferredContentPreview(targetIntent, getContentResolver()); + return displayContentPreview(previewType, targetIntent, getLayoutInflater(), parent); + } + private ViewGroup displayContentPreview(@ContentPreviewType int previewType, Intent targetIntent, LayoutInflater layoutInflater, ViewGroup parent) { ViewGroup layout = null; @@ -1319,7 +1323,7 @@ public class ChooserActivity extends ResolverActivity implements public void onPrepareAdapterView(ResolverListAdapter adapter) { mChooserMultiProfilePagerAdapter.getCurrentAdapterView().setVisibility(View.VISIBLE); if (mCallerChooserTargets != null && mCallerChooserTargets.length > 0) { - mChooserMultiProfilePagerAdapter.getCurrentListAdapter().addServiceResults( + mChooserMultiProfilePagerAdapter.getActiveListAdapter().addServiceResults( /* origTarget */ null, Lists.newArrayList(mCallerChooserTargets), TARGET_TYPE_DEFAULT); @@ -1404,7 +1408,7 @@ public class ChooserActivity extends ResolverActivity implements @Override public void startSelected(int which, boolean always, boolean filtered) { ChooserListAdapter currentListAdapter = - mChooserMultiProfilePagerAdapter.getCurrentListAdapter(); + mChooserMultiProfilePagerAdapter.getActiveListAdapter(); TargetInfo targetInfo = currentListAdapter .targetInfoForPosition(which, filtered); if (targetInfo != null && targetInfo instanceof NotSelectableTargetInfo) { @@ -1487,7 +1491,7 @@ public class ChooserActivity extends ResolverActivity implements String targetPackageName = targetInfo.getChooserTarget().getComponentName().getPackageName(); ChooserListAdapter currentListAdapter = - mChooserMultiProfilePagerAdapter.getCurrentListAdapter(); + mChooserMultiProfilePagerAdapter.getActiveListAdapter(); int maxRankedResults = Math.min(currentListAdapter.mDisplayList.size(), MAX_LOG_RANK_POSITION); @@ -1841,7 +1845,7 @@ public class ChooserActivity extends ResolverActivity implements Intent targetIntent = getTargetIntent(); if (ri != null && ri.activityInfo != null && targetIntent != null) { ChooserListAdapter currentListAdapter = - mChooserMultiProfilePagerAdapter.getCurrentListAdapter(); + mChooserMultiProfilePagerAdapter.getActiveListAdapter(); if (currentListAdapter != null) { currentListAdapter.updateModel(info.getResolvedComponentName()); currentListAdapter.updateChooserCounts(ri.activityInfo.packageName, getUserId(), @@ -2146,8 +2150,7 @@ public class ChooserActivity extends ResolverActivity implements final int bottomInset = mSystemWindowInsets != null ? mSystemWindowInsets.bottom : 0; int offset = bottomInset; - int rowsToShow = gridAdapter.getContentPreviewRowCount() - + gridAdapter.getProfileRowCount() + int rowsToShow = gridAdapter.getProfileRowCount() + gridAdapter.getServiceTargetRowCount() + gridAdapter.getCallerAndRankedTargetRowCount(); @@ -2159,13 +2162,17 @@ public class ChooserActivity extends ResolverActivity implements // still zero? then use a default height and leave, which // can happen when there are no targets to show - if (rowsToShow == 0) { + if (rowsToShow == 0 && !shouldShowContentPreview()) { offset += getResources().getDimensionPixelSize( R.dimen.chooser_max_collapsed_height); mResolverDrawerLayout.setCollapsibleHeightReserved(offset); return; } + if (shouldShowContentPreview()) { + offset += findViewById(R.id.content_preview_container).getHeight(); + } + int directShareHeight = 0; rowsToShow = Math.min(4, rowsToShow); for (int i = 0, childCount = recyclerView.getChildCount(); @@ -2216,13 +2223,13 @@ public class ChooserActivity extends ResolverActivity implements @Override // ResolverListCommunicator public void onHandlePackagesChanged() { mServicesRequested.clear(); - mChooserMultiProfilePagerAdapter.getCurrentListAdapter().notifyDataSetChanged(); + mChooserMultiProfilePagerAdapter.getActiveListAdapter().notifyDataSetChanged(); super.onHandlePackagesChanged(); } @Override // SelectableTargetInfoCommunicator public ActivityInfoPresentationGetter makePresentationGetter(ActivityInfo info) { - return mChooserMultiProfilePagerAdapter.getCurrentListAdapter().makePresentationGetter(info); + return mChooserMultiProfilePagerAdapter.getActiveListAdapter().makePresentationGetter(info); } @Override // SelectableTargetInfoCommunicator @@ -2244,22 +2251,21 @@ public class ChooserActivity extends ResolverActivity implements } @Override - public void onListRebuilt() { - final ChooserListAdapter currentListAdapter = - mChooserMultiProfilePagerAdapter.getCurrentListAdapter(); - if (currentListAdapter.mDisplayList == null - || currentListAdapter.mDisplayList.isEmpty()) { - currentListAdapter.notifyDataSetChanged(); + public void onListRebuilt(ResolverListAdapter listAdapter) { + ChooserListAdapter chooserListAdapter = (ChooserListAdapter) listAdapter; + if (chooserListAdapter.mDisplayList == null + || chooserListAdapter.mDisplayList.isEmpty()) { + chooserListAdapter.notifyDataSetChanged(); } else { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... voids) { - currentListAdapter.updateAlphabeticalList(); + chooserListAdapter.updateAlphabeticalList(); return null; } @Override protected void onPostExecute(Void aVoid) { - currentListAdapter.notifyDataSetChanged(); + chooserListAdapter.notifyDataSetChanged(); } }.execute(); } @@ -2275,14 +2281,14 @@ public class ChooserActivity extends ResolverActivity implements Log.d(TAG, "querying direct share targets from ShortcutManager"); } - queryDirectShareTargets(currentListAdapter, false); + queryDirectShareTargets(chooserListAdapter, false); } if (USE_CHOOSER_TARGET_SERVICE_FOR_DIRECT_TARGETS) { if (DEBUG) { Log.d(TAG, "List built querying services"); } - queryTargetServices(currentListAdapter); + queryTargetServices(chooserListAdapter); } } @@ -2304,10 +2310,43 @@ public class ChooserActivity extends ResolverActivity implements return false; } + private boolean shouldShowContentPreview() { + return mMultiProfilePagerAdapter.getActiveListAdapter().getCount() > 0 + && isSendAction(getTargetIntent()); + } + + private void updateContentPreview() { + if (shouldShowContentPreview()) { + showContentPreview(); + } else { + hideContentPreview(); + } + } + + private void showContentPreview() { + ViewGroup contentPreviewContainer = findViewById(R.id.content_preview_container); + contentPreviewContainer.setVisibility(View.VISIBLE); + ViewGroup contentPreviewView = createContentPreviewView(contentPreviewContainer); + contentPreviewContainer.addView(contentPreviewView); + logActionShareWithPreview(); + } + + private void hideContentPreview() { + ViewGroup contentPreviewContainer = findViewById(R.id.content_preview_container); + contentPreviewContainer.removeAllViews(); + contentPreviewContainer.setVisibility(View.GONE); + } + + private void logActionShareWithPreview() { + Intent targetIntent = getTargetIntent(); + int previewType = findPreferredContentPreview(targetIntent, getContentResolver()); + getMetricsLogger().write(new LogMaker(MetricsEvent.ACTION_SHARE_WITH_PREVIEW) + .setSubtype(previewType)); + } + /** * Used to bind types of individual item including * {@link ChooserGridAdapter#VIEW_TYPE_NORMAL}, - * {@link ChooserGridAdapter#VIEW_TYPE_CONTENT_PREVIEW}, * {@link ChooserGridAdapter#VIEW_TYPE_PROFILE}, * and {@link ChooserGridAdapter#VIEW_TYPE_AZ_LABEL}. */ @@ -2323,7 +2362,7 @@ public class ChooserActivity extends ResolverActivity implements false/* always */, true/* filterd */)); itemView.setOnLongClickListener(v -> { showTargetDetails( - mChooserMultiProfilePagerAdapter.getCurrentListAdapter() + mChooserMultiProfilePagerAdapter.getActiveListAdapter() .resolveInfoForPosition(mListPosition, /* filtered */ true)); return true; }); @@ -2368,15 +2407,13 @@ public class ChooserActivity extends ResolverActivity implements private int mChooserTargetWidth = 0; private boolean mShowAzLabelIfPoss; - private boolean mHideContentPreview = false; private boolean mLayoutRequested = false; private static final int VIEW_TYPE_DIRECT_SHARE = 0; private static final int VIEW_TYPE_NORMAL = 1; - private static final int VIEW_TYPE_CONTENT_PREVIEW = 2; - private static final int VIEW_TYPE_PROFILE = 3; - private static final int VIEW_TYPE_AZ_LABEL = 4; - private static final int VIEW_TYPE_CALLER_AND_RANK = 5; + private static final int VIEW_TYPE_PROFILE = 2; + private static final int VIEW_TYPE_AZ_LABEL = 3; + private static final int VIEW_TYPE_CALLER_AND_RANK = 4; private static final int MAX_TARGETS_PER_ROW_PORTRAIT = 4; private static final int MAX_TARGETS_PER_ROW_LANDSCAPE = 8; @@ -2433,12 +2470,6 @@ public class ChooserActivity extends ResolverActivity implements return maxTargets; } - public void hideContentPreview() { - mHideContentPreview = true; - mLayoutRequested = true; - notifyDataSetChanged(); - } - public boolean consumeLayoutRequest() { boolean oldValue = mLayoutRequested; mLayoutRequested = false; @@ -2447,8 +2478,7 @@ public class ChooserActivity extends ResolverActivity implements public int getRowCount() { return (int) ( - getContentPreviewRowCount() - + getProfileRowCount() + getProfileRowCount() + getServiceTargetRowCount() + getCallerAndRankedTargetRowCount() + getAzLabelRowCount() @@ -2458,19 +2488,6 @@ public class ChooserActivity extends ResolverActivity implements ); } - public int getContentPreviewRowCount() { - if (!isSendAction(getTargetIntent())) { - return 0; - } - - if (mHideContentPreview || mChooserListAdapter == null - || mChooserListAdapter.getCount() == 0) { - return 0; - } - - return 1; - } - public int getProfileRowCount() { return mChooserListAdapter.getOtherProfile() == null ? 0 : 1; } @@ -2499,8 +2516,7 @@ public class ChooserActivity extends ResolverActivity implements @Override public int getItemCount() { return (int) ( - getContentPreviewRowCount() - + getProfileRowCount() + getProfileRowCount() + getServiceTargetRowCount() + getCallerAndRankedTargetRowCount() + getAzLabelRowCount() @@ -2511,8 +2527,6 @@ public class ChooserActivity extends ResolverActivity implements @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { switch (viewType) { - case VIEW_TYPE_CONTENT_PREVIEW: - return new ItemViewHolder(createContentPreviewView(parent), false); case VIEW_TYPE_PROFILE: return new ItemViewHolder(createProfileView(parent), false); case VIEW_TYPE_AZ_LABEL: @@ -2547,10 +2561,7 @@ public class ChooserActivity extends ResolverActivity implements public int getItemViewType(int position) { int count; - int countSum = (count = getContentPreviewRowCount()); - if (count > 0 && position < countSum) return VIEW_TYPE_CONTENT_PREVIEW; - - countSum += (count = getProfileRowCount()); + int countSum = (count = getProfileRowCount()); if (count > 0 && position < countSum) return VIEW_TYPE_PROFILE; countSum += (count = getServiceTargetRowCount()); @@ -2569,12 +2580,6 @@ public class ChooserActivity extends ResolverActivity implements return mChooserListAdapter.getPositionTargetType(getListPosition(position)); } - private ViewGroup createContentPreviewView(ViewGroup parent) { - Intent targetIntent = getTargetIntent(); - int previewType = findPreferredContentPreview(targetIntent, getContentResolver()); - return displayContentPreview(previewType, targetIntent, mLayoutInflater, parent); - } - private View createProfileView(ViewGroup parent) { View profileRow = mLayoutInflater.inflate(R.layout.chooser_profile_row, parent, false); profileRow.setBackground( @@ -2770,7 +2775,7 @@ public class ChooserActivity extends ResolverActivity implements } int getListPosition(int position) { - position -= getContentPreviewRowCount() + getProfileRowCount(); + position -= getProfileRowCount(); final int serviceCount = mChooserListAdapter.getServiceTargetCount(); final int serviceRows = (int) Math.ceil((float) serviceCount @@ -2814,16 +2819,6 @@ public class ChooserActivity extends ResolverActivity implements return mChooserListAdapter; } - void maybeLogActionShareWithPreview() { - if (getContentPreviewRowCount() == 0) { - return; - } - Intent targetIntent = getTargetIntent(); - int previewType = findPreferredContentPreview(targetIntent, getContentResolver()); - getMetricsLogger().write(new LogMaker(MetricsEvent.ACTION_SHARE_WITH_PREVIEW) - .setSubtype(previewType)); - } - boolean shouldCellSpan(int position) { return getItemViewType(position) == VIEW_TYPE_NORMAL; } @@ -3010,7 +3005,7 @@ public class ChooserActivity extends ResolverActivity implements // only expand if we have more than maxTargetsPerRow, and delay that decision // until they start to scroll - if (mChooserMultiProfilePagerAdapter.getCurrentListAdapter() + if (mChooserMultiProfilePagerAdapter.getActiveListAdapter() .getSelectableServiceTargetCount() <= maxTargetsPerRow) { mHideDirectShareExpansion = true; return; diff --git a/core/java/com/android/internal/app/ChooserMultiProfilePagerAdapter.java b/core/java/com/android/internal/app/ChooserMultiProfilePagerAdapter.java index aa8ab2865d92..7d856e1b945d 100644 --- a/core/java/com/android/internal/app/ChooserMultiProfilePagerAdapter.java +++ b/core/java/com/android/internal/app/ChooserMultiProfilePagerAdapter.java @@ -102,11 +102,20 @@ public class ChooserMultiProfilePagerAdapter extends AbstractMultiProfilePagerAd @Override @VisibleForTesting - public ChooserListAdapter getCurrentListAdapter() { + public ChooserListAdapter getActiveListAdapter() { return getAdapterForIndex(getCurrentPage()).getListAdapter(); } @Override + @VisibleForTesting + public ChooserListAdapter getInactiveListAdapter() { + if (getCount() == 1) { + return null; + } + return getAdapterForIndex(1 - getCurrentPage()).getListAdapter(); + } + + @Override ChooserActivity.ChooserGridAdapter getCurrentRootAdapter() { return getAdapterForIndex(getCurrentPage()); } diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index 9cf5e9f47e7f..39bd80960d0b 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -240,7 +240,7 @@ public class ResolverActivity extends Activity implements return new PackageMonitor() { @Override public void onSomePackagesChanged() { - mMultiProfilePagerAdapter.getCurrentListAdapter().handlePackagesChanged(); + mMultiProfilePagerAdapter.getActiveListAdapter().handlePackagesChanged(); updateProfileViewButton(); } @@ -372,7 +372,7 @@ public class ResolverActivity extends Activity implements } final Set<String> categories = intent.getCategories(); - MetricsLogger.action(this, mMultiProfilePagerAdapter.getCurrentListAdapter().hasFilteredItem() + MetricsLogger.action(this, mMultiProfilePagerAdapter.getActiveListAdapter().hasFilteredItem() ? MetricsProto.MetricsEvent.ACTION_SHOW_APP_DISAMBIG_APP_FEATURED : MetricsProto.MetricsEvent.ACTION_SHOW_APP_DISAMBIG_NONE_FEATURED, intent.getAction() + ":" + intent.getType() + ":" @@ -461,7 +461,7 @@ public class ResolverActivity extends Activity implements protected void onProfileClick(View v) { final DisplayResolveInfo dri = - mMultiProfilePagerAdapter.getCurrentListAdapter().getOtherProfile(); + mMultiProfilePagerAdapter.getActiveListAdapter().getOtherProfile(); if (dri == null) { return; } @@ -508,7 +508,7 @@ public class ResolverActivity extends Activity implements @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - mMultiProfilePagerAdapter.getCurrentListAdapter().handlePackagesChanged(); + mMultiProfilePagerAdapter.getActiveListAdapter().handlePackagesChanged(); if (mSystemWindowInsets != null) { mResolverDrawerLayout.setPadding(mSystemWindowInsets.left, mSystemWindowInsets.top, @@ -523,10 +523,10 @@ public class ResolverActivity extends Activity implements return; } - int count = mMultiProfilePagerAdapter.getCurrentListAdapter().getCount(); + int count = mMultiProfilePagerAdapter.getActiveListAdapter().getCount(); final Option[] options = new Option[count]; for (int i = 0, N = options.length; i < N; i++) { - TargetInfo target = mMultiProfilePagerAdapter.getCurrentListAdapter().getItem(i); + TargetInfo target = mMultiProfilePagerAdapter.getActiveListAdapter().getItem(i); if (target == null) { // If this occurs, a new set of targets is being loaded. Let that complete, // and have the next call to send voice choices proceed instead. @@ -576,7 +576,7 @@ public class ResolverActivity extends Activity implements } final DisplayResolveInfo dri = - mMultiProfilePagerAdapter.getCurrentListAdapter().getOtherProfile(); + mMultiProfilePagerAdapter.getActiveListAdapter().getOtherProfile(); if (dri != null && !ENABLE_TABBED_VIEW) { mProfileView.setVisibility(View.VISIBLE); View text = mProfileView.findViewById(R.id.profile_button); @@ -629,7 +629,7 @@ public class ResolverActivity extends Activity implements // While there may already be a filtered item, we can only use it in the title if the list // is already sorted and all information relevant to it is already in the list. final boolean named = - mMultiProfilePagerAdapter.getCurrentListAdapter().getFilteredPosition() >= 0; + mMultiProfilePagerAdapter.getActiveListAdapter().getFilteredPosition() >= 0; if (title == ActionTitle.DEFAULT && defaultTitleRes != 0) { return getString(defaultTitleRes); } else if (isHttpSchemeAndViewAction(intent)) { @@ -638,14 +638,14 @@ public class ResolverActivity extends Activity implements String dialogTitle = null; if (named && !mUseLayoutForBrowsables) { dialogTitle = getString(ActionTitle.BROWSABLE_APP_TITLE_RES, - mMultiProfilePagerAdapter.getCurrentListAdapter().getFilteredItem() + mMultiProfilePagerAdapter.getActiveListAdapter().getFilteredItem() .getDisplayLabel()); } else if (named && mUseLayoutForBrowsables) { dialogTitle = getString(ActionTitle.BROWSABLE_HOST_APP_TITLE_RES, intent.getData().getHost(), - mMultiProfilePagerAdapter.getCurrentListAdapter().getFilteredItem() + mMultiProfilePagerAdapter.getActiveListAdapter().getFilteredItem() .getDisplayLabel()); - } else if (mMultiProfilePagerAdapter.getCurrentListAdapter().areAllTargetsBrowsers()) { + } else if (mMultiProfilePagerAdapter.getActiveListAdapter().areAllTargetsBrowsers()) { dialogTitle = getString(ActionTitle.BROWSABLE_TITLE_RES); } else { dialogTitle = getString(ActionTitle.BROWSABLE_HOST_TITLE_RES, @@ -655,7 +655,7 @@ public class ResolverActivity extends Activity implements } else { return named ? getString(title.namedTitleRes, mMultiProfilePagerAdapter - .getCurrentListAdapter().getFilteredItem().getDisplayLabel()) + .getActiveListAdapter().getFilteredItem().getDisplayLabel()) : getString(title.titleRes); } } @@ -673,7 +673,7 @@ public class ResolverActivity extends Activity implements mPackageMonitor.register(this, getMainLooper(), false); mRegistered = true; } - mMultiProfilePagerAdapter.getCurrentListAdapter().handlePackagesChanged(); + mMultiProfilePagerAdapter.getActiveListAdapter().handlePackagesChanged(); updateProfileViewButton(); } @@ -706,8 +706,8 @@ public class ResolverActivity extends Activity implements if (!isChangingConfigurations() && mPickOptionRequest != null) { mPickOptionRequest.cancel(); } - if (mMultiProfilePagerAdapter.getCurrentListAdapter() != null) { - mMultiProfilePagerAdapter.getCurrentListAdapter().onDestroy(); + if (mMultiProfilePagerAdapter.getActiveListAdapter() != null) { + mMultiProfilePagerAdapter.getActiveListAdapter().onDestroy(); } } @@ -757,7 +757,7 @@ public class ResolverActivity extends Activity implements boolean enabled = false; ResolveInfo ri = null; if (hasValidSelection) { - ri = mMultiProfilePagerAdapter.getCurrentListAdapter() + ri = mMultiProfilePagerAdapter.getActiveListAdapter() .resolveInfoForPosition(checkedPos, filtered); if (ri == null) { Log.e(TAG, "Invalid position supplied to setAlwaysButtonEnabled"); @@ -800,7 +800,7 @@ public class ResolverActivity extends Activity implements public void onButtonClick(View v) { final int id = v.getId(); ListView listView = (ListView) mMultiProfilePagerAdapter.getCurrentAdapterView(); - ResolverListAdapter currentListAdapter = mMultiProfilePagerAdapter.getCurrentListAdapter(); + ResolverListAdapter currentListAdapter = mMultiProfilePagerAdapter.getActiveListAdapter(); int which = currentListAdapter.hasFilteredItem() ? currentListAdapter.getFilteredPosition() : listView.getCheckedItemPosition(); @@ -836,7 +836,7 @@ public class ResolverActivity extends Activity implements if (isFinishing()) { return; } - ResolveInfo ri = mMultiProfilePagerAdapter.getCurrentListAdapter() + ResolveInfo ri = mMultiProfilePagerAdapter.getActiveListAdapter() .resolveInfoForPosition(which, hasIndexBeenFiltered); if (mResolvingHome && hasManagedProfile() && !supportsManagedProfiles(ri)) { Toast.makeText(this, String.format(getResources().getString( @@ -846,7 +846,7 @@ public class ResolverActivity extends Activity implements return; } - TargetInfo target = mMultiProfilePagerAdapter.getCurrentListAdapter() + TargetInfo target = mMultiProfilePagerAdapter.getActiveListAdapter() .targetInfoForPosition(which, hasIndexBeenFiltered); if (target == null) { return; @@ -863,7 +863,7 @@ public class ResolverActivity extends Activity implements this, MetricsProto.MetricsEvent.ACTION_APP_DISAMBIG_TAP); } MetricsLogger.action(this, - mMultiProfilePagerAdapter.getCurrentListAdapter().hasFilteredItem() + mMultiProfilePagerAdapter.getActiveListAdapter().hasFilteredItem() ? MetricsProto.MetricsEvent.ACTION_HIDE_APP_DISAMBIG_APP_FEATURED : MetricsProto.MetricsEvent.ACTION_HIDE_APP_DISAMBIG_NONE_FEATURED); finish(); @@ -879,18 +879,17 @@ public class ResolverActivity extends Activity implements } @Override // ResolverListCommunicator - public void onPostListReady() { + public void onPostListReady(ResolverListAdapter listAdapter) { setHeader(); resetButtonBar(); - onListRebuilt(); + onListRebuilt(listAdapter); } - protected void onListRebuilt() { - int count = mMultiProfilePagerAdapter.getCurrentListAdapter().getUnfilteredCount(); - if (count == 1 && mMultiProfilePagerAdapter.getCurrentListAdapter().getOtherProfile() == null) { + protected void onListRebuilt(ResolverListAdapter listAdapter) { + int count = listAdapter.getUnfilteredCount(); + if (count == 1 && listAdapter.getOtherProfile() == null) { // Only one target, so we're a candidate to auto-launch! - final TargetInfo target = - mMultiProfilePagerAdapter.getCurrentListAdapter().targetInfoForPosition(0, false); + final TargetInfo target = listAdapter.targetInfoForPosition(0, false); if (shouldAutoLaunchSingleChoice(target)) { safelyStartActivity(target); finish(); @@ -903,8 +902,8 @@ public class ResolverActivity extends Activity implements final Intent intent = target != null ? target.getResolvedIntent() : null; if (intent != null && (mSupportsAlwaysUseOption - || mMultiProfilePagerAdapter.getCurrentListAdapter().hasFilteredItem()) - && mMultiProfilePagerAdapter.getCurrentListAdapter().getUnfilteredResolveList() != null) { + || mMultiProfilePagerAdapter.getActiveListAdapter().hasFilteredItem()) + && mMultiProfilePagerAdapter.getActiveListAdapter().getUnfilteredResolveList() != null) { // Build a reasonable intent filter, based on what matched. IntentFilter filter = new IntentFilter(); Intent filterIntent; @@ -989,14 +988,14 @@ public class ResolverActivity extends Activity implements } if (filter != null) { - final int N = mMultiProfilePagerAdapter.getCurrentListAdapter() + final int N = mMultiProfilePagerAdapter.getActiveListAdapter() .getUnfilteredResolveList().size(); ComponentName[] set; // If we don't add back in the component for forwarding the intent to a managed // profile, the preferred activity may not be updated correctly (as the set of // components we tell it we knew about will have changed). final boolean needToAddBackProfileForwardingComponent = - mMultiProfilePagerAdapter.getCurrentListAdapter().getOtherProfile() != null; + mMultiProfilePagerAdapter.getActiveListAdapter().getOtherProfile() != null; if (!needToAddBackProfileForwardingComponent) { set = new ComponentName[N]; } else { @@ -1005,7 +1004,7 @@ public class ResolverActivity extends Activity implements int bestMatch = 0; for (int i=0; i<N; i++) { - ResolveInfo r = mMultiProfilePagerAdapter.getCurrentListAdapter() + ResolveInfo r = mMultiProfilePagerAdapter.getActiveListAdapter() .getUnfilteredResolveList().get(i).getResolveInfoAt(0); set[i] = new ComponentName(r.activityInfo.packageName, r.activityInfo.name); @@ -1013,9 +1012,9 @@ public class ResolverActivity extends Activity implements } if (needToAddBackProfileForwardingComponent) { - set[N] = mMultiProfilePagerAdapter.getCurrentListAdapter() + set[N] = mMultiProfilePagerAdapter.getActiveListAdapter() .getOtherProfile().getResolvedComponentName(); - final int otherProfileMatch = mMultiProfilePagerAdapter.getCurrentListAdapter() + final int otherProfileMatch = mMultiProfilePagerAdapter.getActiveListAdapter() .getOtherProfile().getResolveInfo().match; if (otherProfileMatch > bestMatch) bestMatch = otherProfileMatch; } @@ -1055,7 +1054,7 @@ public class ResolverActivity extends Activity implements } } else { try { - mMultiProfilePagerAdapter.getCurrentListAdapter() + mMultiProfilePagerAdapter.getActiveListAdapter() .mResolverListController.setLastChosen(intent, filter, bestMatch); } catch (RemoteException re) { Log.d(TAG, "Error calling setLastChosenActivity\n" + re); @@ -1200,10 +1199,14 @@ public class ResolverActivity extends Activity implements * @return <code>true</code> if the activity is finishing and creation should halt. */ private boolean configureContentView() { - if (mMultiProfilePagerAdapter.getCurrentListAdapter() == null) { - throw new IllegalStateException("mAdapter cannot be null."); + if (mMultiProfilePagerAdapter.getActiveListAdapter() == null) { + throw new IllegalStateException("mMultiProfilePagerAdapter.getCurrentListAdapter() " + + "cannot be null."); + } + boolean rebuildCompleted = mMultiProfilePagerAdapter.getActiveListAdapter().rebuildList(); + if (mMultiProfilePagerAdapter.getInactiveListAdapter() != null) { + mMultiProfilePagerAdapter.getInactiveListAdapter().rebuildList(); } - boolean rebuildCompleted = mMultiProfilePagerAdapter.getCurrentListAdapter().rebuildList(); if (useLayoutWithDefault()) { mLayoutId = R.layout.resolver_list_with_default; } else { @@ -1231,15 +1234,15 @@ public class ResolverActivity extends Activity implements */ final boolean postRebuildListInternal(boolean rebuildCompleted) { - int count = mMultiProfilePagerAdapter.getCurrentListAdapter().getUnfilteredCount(); + int count = mMultiProfilePagerAdapter.getActiveListAdapter().getUnfilteredCount(); // We only rebuild asynchronously when we have multiple elements to sort. In the case where // we're already done, we can check if we should auto-launch immediately. if (rebuildCompleted) { if (count == 1 - && mMultiProfilePagerAdapter.getCurrentListAdapter().getOtherProfile() == null) { + && mMultiProfilePagerAdapter.getActiveListAdapter().getOtherProfile() == null) { // Only one target, so we're a candidate to auto-launch! - final TargetInfo target = mMultiProfilePagerAdapter.getCurrentListAdapter() + final TargetInfo target = mMultiProfilePagerAdapter.getActiveListAdapter() .targetInfoForPosition(0, false); if (shouldAutoLaunchSingleChoice(target)) { safelyStartActivity(target); @@ -1257,12 +1260,12 @@ public class ResolverActivity extends Activity implements private void setupViewVisibilities(int count) { if (count == 0 - && mMultiProfilePagerAdapter.getCurrentListAdapter().getPlaceholderCount() == 0) { + && mMultiProfilePagerAdapter.getActiveListAdapter().getPlaceholderCount() == 0) { final TextView emptyView = findViewById(R.id.empty); emptyView.setVisibility(View.VISIBLE); findViewById(R.id.profile_pager).setVisibility(View.GONE); } else { - onPrepareAdapterView(mMultiProfilePagerAdapter.getCurrentListAdapter()); + onPrepareAdapterView(mMultiProfilePagerAdapter.getActiveListAdapter()); } } @@ -1295,8 +1298,8 @@ public class ResolverActivity extends Activity implements * Configure the area above the app selection list (title, content preview, etc). */ public void setHeader() { - if (mMultiProfilePagerAdapter.getCurrentListAdapter().getCount() == 0 - && mMultiProfilePagerAdapter.getCurrentListAdapter().getPlaceholderCount() == 0) { + if (mMultiProfilePagerAdapter.getActiveListAdapter().getCount() == 0 + && mMultiProfilePagerAdapter.getActiveListAdapter().getPlaceholderCount() == 0) { final TextView titleView = findViewById(R.id.title); if (titleView != null) { titleView.setVisibility(View.GONE); @@ -1317,7 +1320,7 @@ public class ResolverActivity extends Activity implements final ImageView iconView = findViewById(R.id.icon); if (iconView != null) { - mMultiProfilePagerAdapter.getCurrentListAdapter().loadFilteredItemIconTaskAsync(iconView); + mMultiProfilePagerAdapter.getActiveListAdapter().loadFilteredItemIconTaskAsync(iconView); } } @@ -1345,7 +1348,7 @@ public class ResolverActivity extends Activity implements } private void resetAlwaysOrOnceButtonBar() { - int filteredPosition = mMultiProfilePagerAdapter.getCurrentListAdapter() + int filteredPosition = mMultiProfilePagerAdapter.getActiveListAdapter() .getFilteredPosition(); if (useLayoutWithDefault() && filteredPosition != ListView.INVALID_POSITION) { setAlwaysButtonEnabled(true, filteredPosition, false); @@ -1365,7 +1368,7 @@ public class ResolverActivity extends Activity implements @Override // ResolverListCommunicator public boolean useLayoutWithDefault() { return mSupportsAlwaysUseOption - && mMultiProfilePagerAdapter.getCurrentListAdapter().hasFilteredItem(); + && mMultiProfilePagerAdapter.getActiveListAdapter().hasFilteredItem(); } /** @@ -1389,7 +1392,7 @@ public class ResolverActivity extends Activity implements @Override // ResolverListCommunicator public void onHandlePackagesChanged() { - if (mMultiProfilePagerAdapter.getCurrentListAdapter().getCount() == 0) { + if (mMultiProfilePagerAdapter.getActiveListAdapter().getCount() == 0) { // We no longer have any items... just finish the activity. finish(); } @@ -1464,7 +1467,7 @@ public class ResolverActivity extends Activity implements return; } // If we're still loading, we can't yet enable the buttons. - if (mMultiProfilePagerAdapter.getCurrentListAdapter() + if (mMultiProfilePagerAdapter.getActiveListAdapter() .resolveInfoForPosition(position, true) == null) { return; } @@ -1497,7 +1500,7 @@ public class ResolverActivity extends Activity implements // Header views don't count. return false; } - ResolveInfo ri = mMultiProfilePagerAdapter.getCurrentListAdapter() + ResolveInfo ri = mMultiProfilePagerAdapter.getActiveListAdapter() .resolveInfoForPosition(position, true); showTargetDetails(ri); return true; @@ -1538,7 +1541,7 @@ public class ResolverActivity extends Activity implements final ResolverActivity ra = (ResolverActivity) getActivity(); if (ra != null) { - final TargetInfo ti = ra.mMultiProfilePagerAdapter.getCurrentListAdapter() + final TargetInfo ti = ra.mMultiProfilePagerAdapter.getActiveListAdapter() .getItem(selections[0].getIndex()); if (ra.onTargetSelected(ti, false)) { ra.mPickOptionRequest = null; diff --git a/core/java/com/android/internal/app/ResolverListAdapter.java b/core/java/com/android/internal/app/ResolverListAdapter.java index 48064da7c35c..aa48869642b7 100644 --- a/core/java/com/android/internal/app/ResolverListAdapter.java +++ b/core/java/com/android/internal/app/ResolverListAdapter.java @@ -351,12 +351,12 @@ public class ResolverListAdapter extends BaseAdapter { * determine the layout known. We therefore can't update the UI inline and post to the * handler thread to update after the current task is finished. */ - private void postListReadyRunnable() { + void postListReadyRunnable() { if (mPostListReadyRunnable == null) { mPostListReadyRunnable = new Runnable() { @Override public void run() { - mResolverListCommunicator.onPostListReady(); + mResolverListCommunicator.onPostListReady(ResolverListAdapter.this); mPostListReadyRunnable = null; } }; @@ -599,7 +599,7 @@ public class ResolverListAdapter extends BaseAdapter { Intent getReplacementIntent(ActivityInfo activityInfo, Intent defIntent); - void onPostListReady(); + void onPostListReady(ResolverListAdapter listAdapter); void sendVoiceChoicesIfNeeded(); diff --git a/core/java/com/android/internal/app/ResolverMultiProfilePagerAdapter.java b/core/java/com/android/internal/app/ResolverMultiProfilePagerAdapter.java index 9e814ab5d0aa..d72c52bfe6b6 100644 --- a/core/java/com/android/internal/app/ResolverMultiProfilePagerAdapter.java +++ b/core/java/com/android/internal/app/ResolverMultiProfilePagerAdapter.java @@ -87,13 +87,22 @@ public class ResolverMultiProfilePagerAdapter extends AbstractMultiProfilePagerA @Override @VisibleForTesting - public ResolverListAdapter getCurrentListAdapter() { + public ResolverListAdapter getActiveListAdapter() { return getAdapterForIndex(getCurrentPage()); } @Override + @VisibleForTesting + public ResolverListAdapter getInactiveListAdapter() { + if (getCount() == 1) { + return null; + } + return getAdapterForIndex(1 - getCurrentPage()); + } + + @Override ResolverListAdapter getCurrentRootAdapter() { - return getCurrentListAdapter(); + return getActiveListAdapter(); } @Override diff --git a/core/res/res/layout/chooser_grid.xml b/core/res/res/layout/chooser_grid.xml index 9f296f8f7c08..0c45e45e7980 100644 --- a/core/res/res/layout/chooser_grid.xml +++ b/core/res/res/layout/chooser_grid.xml @@ -55,6 +55,12 @@ android:layout_centerHorizontal="true"/> </RelativeLayout> + <FrameLayout + android:id="@+id/content_preview_container" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:visibility="gone" /> + <com.android.internal.widget.ViewPager android:id="@+id/profile_pager" android:layout_width="match_parent" diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 90343e07d4e4..803d4dbde305 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -248,6 +248,7 @@ <java-symbol type="id" name="overlay" /> <java-symbol type="id" name="app_ops" /> <java-symbol type="id" name="profile_pager" /> + <java-symbol type="id" name="content_preview_container" /> <java-symbol type="attr" name="actionModeShareDrawable" /> <java-symbol type="attr" name="alertDialogCenterButtons" /> diff --git a/core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java b/core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java index a2e0095c2aee..2a1044361d42 100644 --- a/core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java +++ b/core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java @@ -48,7 +48,7 @@ public class ChooserWrapperActivity extends ChooserActivity { private UsageStatsManager mUsm; ChooserListAdapter getAdapter() { - return mChooserMultiProfilePagerAdapter.getCurrentListAdapter(); + return mChooserMultiProfilePagerAdapter.getActiveListAdapter(); } boolean getIsSelected() { return mIsSuccessfullySelected; } diff --git a/core/tests/coretests/src/com/android/internal/app/ResolverWrapperActivity.java b/core/tests/coretests/src/com/android/internal/app/ResolverWrapperActivity.java index 93357af406e8..c5d2cfaa9512 100644 --- a/core/tests/coretests/src/com/android/internal/app/ResolverWrapperActivity.java +++ b/core/tests/coretests/src/com/android/internal/app/ResolverWrapperActivity.java @@ -46,7 +46,7 @@ public class ResolverWrapperActivity extends ResolverActivity { } ResolverWrapperAdapter getAdapter() { - return (ResolverWrapperAdapter) mMultiProfilePagerAdapter.getCurrentListAdapter(); + return (ResolverWrapperAdapter) mMultiProfilePagerAdapter.getActiveListAdapter(); } @Override |