1 /* 2 * Copyright (C) 2019 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 package com.android.launcher3.folder; 17 18 import android.content.ComponentName; 19 import android.content.Context; 20 21 import com.android.launcher3.LauncherSettings.Favorites; 22 import com.android.launcher3.WorkspaceItemInfo; 23 24 import java.util.ArrayList; 25 26 /** 27 * Locates provider for the folder name. 28 */ 29 public class FolderNameProvider { 30 31 /** 32 * Returns suggested folder name. 33 */ getSuggestedFolderName(Context context, ArrayList<WorkspaceItemInfo> workspaceItemInfos, CharSequence[] suggestName)34 public CharSequence getSuggestedFolderName(Context context, 35 ArrayList<WorkspaceItemInfo> workspaceItemInfos, CharSequence[] suggestName) { 36 // Currently only run the algorithm on initial folder creation. 37 // For more than 2 items in the folder, the ranking algorithm for finding 38 // candidate folder name should be rewritten. 39 if (workspaceItemInfos.size() == 2) { 40 ComponentName cmp1 = workspaceItemInfos.get(0).getTargetComponent(); 41 ComponentName cmp2 = workspaceItemInfos.get(1).getTargetComponent(); 42 43 String pkgName0 = cmp1 == null ? "" : cmp1.getPackageName(); 44 String pkgName1 = cmp2 == null ? "" : cmp2.getPackageName(); 45 // If the two icons are from the same package, 46 // then assign the main icon's name 47 if (pkgName0.equals(pkgName1)) { 48 WorkspaceItemInfo wInfo0 = workspaceItemInfos.get(0); 49 WorkspaceItemInfo wInfo1 = workspaceItemInfos.get(1); 50 if (workspaceItemInfos.get(0).itemType == Favorites.ITEM_TYPE_APPLICATION) { 51 suggestName[0] = wInfo0.title; 52 } else if (wInfo1.itemType == Favorites.ITEM_TYPE_APPLICATION) { 53 suggestName[0] = wInfo1.title; 54 } 55 return suggestName[0]; 56 // two icons are all shortcuts. Don't assign title 57 } 58 } 59 return suggestName[0]; 60 } 61 } 62