1 /* 2 * Copyright (C) 2018 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.documentsui.dirlist; 18 19 import android.content.Context; 20 import android.content.pm.PackageManager; 21 import android.content.pm.ResolveInfo; 22 import android.graphics.drawable.Drawable; 23 24 import com.android.documentsui.ActionHandler; 25 import com.android.documentsui.base.RootInfo; 26 import com.android.documentsui.sidebar.AppItem; 27 import com.android.documentsui.sidebar.Item; 28 import com.android.documentsui.sidebar.RootItem; 29 30 /** 31 * A bacis data class stored data which apps row chip required. 32 * This is abstract class and it will be implemented by {@link AppData} and {@link RootData}, 33 * both classes are different by the item is {@link AppItem} or {@link RootItem}. 34 */ 35 public abstract class AppsRowItemData { 36 37 private final String mTitle; 38 protected final ActionHandler mActionHandler; 39 AppsRowItemData(Item item, ActionHandler actionHandler)40 public AppsRowItemData(Item item, ActionHandler actionHandler) { 41 mTitle = item.title; 42 mActionHandler = actionHandler; 43 } 44 getTitle()45 public final String getTitle() { 46 return mTitle; 47 } 48 getIconDrawable(Context context)49 protected abstract Drawable getIconDrawable(Context context); onClicked()50 protected abstract void onClicked(); showExitIcon()51 protected abstract boolean showExitIcon(); 52 53 public static class AppData extends AppsRowItemData { 54 55 private final ResolveInfo mResolveInfo; 56 AppData(AppItem item, ActionHandler actionHandler)57 public AppData(AppItem item, ActionHandler actionHandler) { 58 super(item, actionHandler); 59 mResolveInfo = item.info; 60 } 61 62 @Override getIconDrawable(Context context)63 protected Drawable getIconDrawable(Context context) { 64 return mResolveInfo.loadIcon(context.getPackageManager()); 65 } 66 67 @Override onClicked()68 protected void onClicked() { 69 mActionHandler.openRoot(mResolveInfo); 70 } 71 72 @Override showExitIcon()73 protected boolean showExitIcon() { 74 return true; 75 } 76 } 77 78 public static class RootData extends AppsRowItemData { 79 80 private final RootInfo mRootInfo; 81 RootData(RootItem item, ActionHandler actionHandler)82 public RootData(RootItem item, ActionHandler actionHandler) { 83 super(item, actionHandler); 84 mRootInfo = item.root; 85 } 86 87 @Override getIconDrawable(Context context)88 protected Drawable getIconDrawable(Context context) { 89 return mRootInfo.loadIcon(context); 90 } 91 92 @Override onClicked()93 protected void onClicked() { 94 mActionHandler.openRoot(mRootInfo); 95 } 96 97 @Override showExitIcon()98 protected boolean showExitIcon() { 99 return false; 100 } 101 } 102 } 103