Merge "Removing unused app discovery support" into ub-launcher3-master

This commit is contained in:
TreeHugger Robot
2018-01-23 22:26:52 +00:00
committed by Android (Google) Code Review
14 changed files with 8 additions and 665 deletions
-27
View File
@@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="12dp"
android:height="12dp"
android:viewportWidth="12"
android:viewportHeight="12">
<path
android:fillColor="#FB8C00"
android:fillType="evenOdd"
android:strokeWidth="1"
android:pathData="M 9.76511755 11.9348136 L 8.33665684 7.16088817 L 12.080006 4.41656311 L 7.49967039 4.41856896 L 6.03138903 0 L 4.57932894 4.41856896 L -1.34115008e-16 4.41656311 L 3.72612122 7.16088817 L 2.29967385 11.9348136 L 6.03138903 8.82574452 Z" />
</vector>
-102
View File
@@ -1,102 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<com.android.launcher3.discovery.AppDiscoveryItemView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:background="?android:selectableItemBackground">
<ImageView
android:id="@+id/image"
android:layout_width="56dp"
android:layout_height="56dp"
android:padding="8dp"
android:scaleType="fitCenter"
android:focusable="false"
android:importantForAccessibility="no"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/image">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
android:textSize="15sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
android:textSize="14sp"
android:layout_gravity="center_vertical"
android:includeFontPadding="false"/>
<com.android.launcher3.discovery.RatingView
android:id="@+id/rating_view"
android:layout_width="70dp"
android:layout_height="16dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_gravity="center_vertical"/>
<TextView
android:id="@+id/review_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textColor="?android:textColorHint"
android:textSize="14sp"
android:layout_gravity="center_vertical"/>
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
<TextView
android:id="@+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorHint"
android:textSize="14sp"
android:layout_marginRight="12dp"
android:textAllCaps="true"/>
</LinearLayout>
</LinearLayout>
<ImageView
android:importantForAccessibility="no"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingLeft="@dimen/dynamic_grid_edge_margin"
android:paddingRight="@dimen/dynamic_grid_edge_margin"
android:src="@drawable/all_apps_divider"
android:scaleType="fitXY"
android:focusable="false" />
</com.android.launcher3.discovery.AppDiscoveryItemView>
@@ -1,40 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="6dp"
android:paddingLeft="@dimen/dynamic_grid_edge_margin"
android:paddingRight="@dimen/dynamic_grid_edge_margin">
<ProgressBar
android:id="@+id/loadingProgressBar"
style="@android:style/Widget.Material.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="6dp"
android:maxHeight="6dp"
android:indeterminate="true"
android:layout_gravity="center"/>
<View
android:id="@+id/loadedDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@drawable/all_apps_divider"
android:layout_gravity="bottom"
android:visibility="invisible"/>
</FrameLayout>
@@ -43,8 +43,6 @@ import com.android.launcher3.allapps.AlphabeticalAppsList.AdapterItem;
import com.android.launcher3.anim.SpringAnimationHandler;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.discovery.AppDiscoveryAppInfo;
import com.android.launcher3.discovery.AppDiscoveryItemView;
import com.android.launcher3.util.PackageManagerHelper;
import java.util.List;
@@ -72,17 +70,13 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter.
public static final int VIEW_TYPE_ALL_APPS_DIVIDER = 1 << 5;
// The divider that separates prediction icons from the app list
public static final int VIEW_TYPE_PREDICTION_DIVIDER = 1 << 6;
public static final int VIEW_TYPE_APPS_LOADING_DIVIDER = 1 << 7;
public static final int VIEW_TYPE_DISCOVERY_ITEM = 1 << 8;
public static final int VIEW_TYPE_WORK_TAB_FOOTER = 1 << 9;
public static final int VIEW_TYPE_WORK_TAB_FOOTER = 1 << 7;
// Common view type masks
public static final int VIEW_TYPE_MASK_DIVIDER = VIEW_TYPE_ALL_APPS_DIVIDER
| VIEW_TYPE_PREDICTION_DIVIDER;
public static final int VIEW_TYPE_MASK_ICON = VIEW_TYPE_ICON
| VIEW_TYPE_PREDICTION_ICON;
public static final int VIEW_TYPE_MASK_CONTENT = VIEW_TYPE_MASK_ICON
| VIEW_TYPE_DISCOVERY_ITEM;
public static final int VIEW_TYPE_MASK_HAS_SPRINGS = VIEW_TYPE_MASK_ICON
| VIEW_TYPE_PREDICTION_DIVIDER;
@@ -161,7 +155,7 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter.
adapterPosition = Math.max(adapterPosition, mApps.getAdapterItems().size() - 1);
int extraRows = 0;
for (int i = 0; i <= adapterPosition; i++) {
if (!isViewType(items.get(i).viewType, VIEW_TYPE_MASK_CONTENT)) {
if (!isViewType(items.get(i).viewType, VIEW_TYPE_MASK_ICON)) {
extraRows++;
}
}
@@ -301,12 +295,6 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter.
// Ensure the all apps icon height matches the workspace icons in portrait mode.
icon.getLayoutParams().height = mLauncher.getDeviceProfile().allAppsCellHeightPx;
return new ViewHolder(icon);
case VIEW_TYPE_DISCOVERY_ITEM:
AppDiscoveryItemView appDiscoveryItemView = (AppDiscoveryItemView) mLayoutInflater
.inflate(R.layout.all_apps_discovery_item, parent, false);
appDiscoveryItemView.init(mIconClickListener, mLauncher.getAccessibilityDelegate(),
mIconLongClickListener);
return new ViewHolder(appDiscoveryItemView);
case VIEW_TYPE_EMPTY_SEARCH:
return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_empty_search,
parent, false));
@@ -320,10 +308,6 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter.
}
});
return new ViewHolder(searchMarketView);
case VIEW_TYPE_APPS_LOADING_DIVIDER:
View loadingDividerView = mLayoutInflater.inflate(
R.layout.all_apps_discovery_loading_divider, parent, false);
return new ViewHolder(loadingDividerView);
case VIEW_TYPE_PREDICTION_DIVIDER:
case VIEW_TYPE_ALL_APPS_DIVIDER:
return new ViewHolder(mLayoutInflater.inflate(
@@ -346,12 +330,6 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter.
icon.reset();
icon.applyFromApplicationInfo(info);
break;
case VIEW_TYPE_DISCOVERY_ITEM:
AppDiscoveryAppInfo appDiscoveryAppInfo = (AppDiscoveryAppInfo)
mApps.getAdapterItems().get(position).appInfo;
AppDiscoveryItemView view = (AppDiscoveryItemView) holder.itemView;
view.apply(appDiscoveryAppInfo);
break;
case VIEW_TYPE_EMPTY_SEARCH:
TextView emptyViewText = (TextView) holder.itemView;
emptyViewText.setText(mEmptySearchMessage);
@@ -366,12 +344,6 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter.
searchView.setVisibility(View.GONE);
}
break;
case VIEW_TYPE_APPS_LOADING_DIVIDER:
int visLoading = mApps.isAppDiscoveryRunning() ? View.VISIBLE : View.GONE;
int visLoaded = !mApps.isAppDiscoveryRunning() ? View.VISIBLE : View.GONE;
holder.itemView.findViewById(R.id.loadingProgressBar).setVisibility(visLoading);
holder.itemView.findViewById(R.id.loadedDivider).setVisibility(visLoaded);
break;
case VIEW_TYPE_ALL_APPS_DIVIDER:
// nothing to do
break;
@@ -170,12 +170,6 @@ public class AllAppsRecyclerView extends BaseRecyclerView implements LogContaine
AllAppsGridAdapter.VIEW_TYPE_EMPTY_SEARCH);
putSameHeightFor(adapter, widthMeasureSpec, heightMeasureSpec,
AllAppsGridAdapter.VIEW_TYPE_WORK_TAB_FOOTER);
if (FeatureFlags.DISCOVERY_ENABLED) {
putSameHeightFor(adapter, widthMeasureSpec, heightMeasureSpec,
AllAppsGridAdapter.VIEW_TYPE_APPS_LOADING_DIVIDER);
putSameHeightFor(adapter, widthMeasureSpec, heightMeasureSpec,
AllAppsGridAdapter.VIEW_TYPE_DISCOVERY_ITEM);
}
}
private void putSameHeightFor(AllAppsGridAdapter adapter, int w, int h, int... viewTypes) {
@@ -263,7 +257,7 @@ public class AllAppsRecyclerView extends BaseRecyclerView implements LogContaine
// Always scroll the view to the top so the user can see the changed results
scrollToTop();
if (mApps.shouldShowEmptySearch()) {
if (mApps.hasNoFilteredResults()) {
if (mEmptySearchBackground == null) {
mEmptySearchBackground = DrawableFactory.get(getContext())
.getAllAppsBackground(getContext());
@@ -27,9 +27,6 @@ import com.android.launcher3.Launcher;
import com.android.launcher3.Utilities;
import com.android.launcher3.compat.AlphabeticIndexCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.discovery.AppDiscoveryAppInfo;
import com.android.launcher3.discovery.AppDiscoveryItem;
import com.android.launcher3.discovery.AppDiscoveryUpdateState;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.ComponentKeyMapper;
@@ -58,8 +55,6 @@ public class AlphabeticalAppsList {
private final int mFastScrollDistributionMode = FAST_SCROLL_FRACTION_DISTRIBUTE_BY_NUM_SECTIONS;
private AppDiscoveryUpdateState mAppDiscoveryUpdateState;
/**
* Info about a fast scroller section, depending if sections are merged, the fast scroller
* sections will not be the same set as the section headers.
@@ -118,17 +113,6 @@ public class AlphabeticalAppsList {
return item;
}
public static AdapterItem asDiscoveryItem(int pos, String sectionName, AppInfo appInfo,
int appIndex) {
AdapterItem item = new AdapterItem();
item.viewType = AllAppsGridAdapter.VIEW_TYPE_DISCOVERY_ITEM;
item.position = pos;
item.sectionName = sectionName;
item.appInfo = appInfo;
item.appIndex = appIndex;
return item;
}
public static AdapterItem asEmptySearch(int pos) {
AdapterItem item = new AdapterItem();
item.viewType = AllAppsGridAdapter.VIEW_TYPE_EMPTY_SEARCH;
@@ -150,13 +134,6 @@ public class AlphabeticalAppsList {
return item;
}
public static AdapterItem asLoadingDivider(int pos) {
AdapterItem item = new AdapterItem();
item.viewType = AllAppsGridAdapter.VIEW_TYPE_APPS_LOADING_DIVIDER;
item.position = pos;
return item;
}
public static AdapterItem asMarketSearch(int pos) {
AdapterItem item = new AdapterItem();
item.viewType = AllAppsGridAdapter.VIEW_TYPE_SEARCH_MARKET;
@@ -188,7 +165,6 @@ public class AlphabeticalAppsList {
private final List<ComponentKeyMapper<AppInfo>> mPredictedAppComponents = new ArrayList<>();
// The set of predicted apps resolved from the component names and the current set of apps
private final List<AppInfo> mPredictedApps = new ArrayList<>();
private final List<AppDiscoveryAppInfo> mDiscoveredApps = new ArrayList<>();
// Is it the work profile app list.
private final boolean mIsWork;
@@ -293,10 +269,6 @@ public class AlphabeticalAppsList {
return (mSearchResults != null) && mFilteredApps.isEmpty();
}
boolean shouldShowEmptySearch() {
return hasNoFilteredResults() && !isAppDiscoveryRunning() && mDiscoveredApps.isEmpty();
}
/**
* Sets the sorted list of filtered components.
*/
@@ -310,20 +282,6 @@ public class AlphabeticalAppsList {
return false;
}
public void onAppDiscoverySearchUpdate(@Nullable AppDiscoveryItem app,
@NonNull AppDiscoveryUpdateState state) {
mAppDiscoveryUpdateState = state;
switch (state) {
case START:
mDiscoveredApps.clear();
break;
case UPDATE:
mDiscoveredApps.add(new AppDiscoveryAppInfo(app));
break;
}
updateAdapterItems();
}
private List<AppInfo> processPredictedAppComponents(List<ComponentKeyMapper<AppInfo>> components) {
if (mComponentToAppMap.isEmpty()) {
// Apps have not been bound yet.
@@ -540,32 +498,13 @@ public class AlphabeticalAppsList {
}
if (hasFilter()) {
if (isAppDiscoveryRunning() || mDiscoveredApps.size() > 0) {
mAdapterItems.add(AdapterItem.asLoadingDivider(position++));
// Append all app discovery results
for (int i = 0; i < mDiscoveredApps.size(); i++) {
AppDiscoveryAppInfo appDiscoveryAppInfo = mDiscoveredApps.get(i);
if (appDiscoveryAppInfo.isRecent) {
// already handled in getFilteredAppInfos()
continue;
}
AdapterItem item = AdapterItem.asDiscoveryItem(position++,
"", appDiscoveryAppInfo, appIndex++);
mAdapterItems.add(item);
}
if (!isAppDiscoveryRunning()) {
mAdapterItems.add(AdapterItem.asMarketSearch(position++));
}
// Append the search market item
if (hasNoFilteredResults()) {
mAdapterItems.add(AdapterItem.asEmptySearch(position++));
} else {
// Append the search market item
if (hasNoFilteredResults()) {
mAdapterItems.add(AdapterItem.asEmptySearch(position++));
} else {
mAdapterItems.add(AdapterItem.asAllAppsDivider(position++));
}
mAdapterItems.add(AdapterItem.asMarketSearch(position++));
mAdapterItems.add(AdapterItem.asAllAppsDivider(position++));
}
mAdapterItems.add(AdapterItem.asMarketSearch(position++));
}
if (mNumAppsPerRow != 0) {
@@ -635,11 +574,6 @@ public class AlphabeticalAppsList {
== PackageManager.PERMISSION_GRANTED);
}
public boolean isAppDiscoveryRunning() {
return mAppDiscoveryUpdateState == AppDiscoveryUpdateState.START
|| mAppDiscoveryUpdateState == AppDiscoveryUpdateState.UPDATE;
}
private List<AppInfo> getFiltersAppInfos() {
if (mSearchResults == null) {
return mApps;
@@ -651,17 +585,6 @@ public class AlphabeticalAppsList {
result.add(match);
}
}
// adding recently used instant apps
if (mDiscoveredApps.size() > 0) {
for (int i = 0; i < mDiscoveredApps.size(); i++) {
AppDiscoveryAppInfo discoveryAppInfo = mDiscoveredApps.get(i);
if (discoveryAppInfo.isRecent) {
result.add(discoveryAppInfo);
}
}
Collections.sort(result, mAppNameComparator);
}
return result;
}
@@ -28,8 +28,6 @@ import android.widget.TextView.OnEditorActionListener;
import com.android.launcher3.ExtendedEditText;
import com.android.launcher3.Launcher;
import com.android.launcher3.Utilities;
import com.android.launcher3.discovery.AppDiscoveryItem;
import com.android.launcher3.discovery.AppDiscoveryUpdateState;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.PackageManagerHelper;
@@ -164,18 +162,6 @@ public class AllAppsSearchBarController
* Called when the search results should be cleared.
*/
void clearSearchResult();
/**
* Called when the app discovery is providing an update of search, which can either be
* START for starting a new discovery,
* UPDATE for providing a new search result, can be called multiple times,
* END for indicating the end of results.
*
* @param app result item if UPDATE, else null
* @param app the update state, START, UPDATE or END
*/
void onAppDiscoverySearchUpdate(@Nullable AppDiscoveryItem app,
@NonNull AppDiscoveryUpdateState state);
}
}
@@ -39,8 +39,6 @@ import com.android.launcher3.R;
import com.android.launcher3.allapps.AllAppsContainerView;
import com.android.launcher3.allapps.AlphabeticalAppsList;
import com.android.launcher3.allapps.SearchUiManager;
import com.android.launcher3.discovery.AppDiscoveryItem;
import com.android.launcher3.discovery.AppDiscoveryUpdateState;
import com.android.launcher3.graphics.TintedDrawableSpan;
import com.android.launcher3.util.ComponentKey;
@@ -187,15 +185,6 @@ public class AppsSearchContainerLayout extends FrameLayout
mAppsView.onClearSearchResult();
}
@Override
public void onAppDiscoverySearchUpdate(
@Nullable AppDiscoveryItem app, @NonNull AppDiscoveryUpdateState state) {
if (!mLauncher.isDestroyed()) {
mApps.onAppDiscoverySearchUpdate(app, state);
notifyResultChanged();
}
}
private void notifyResultChanged() {
mElevationController.reset();
mAppsView.onSearchResultsChanged();
@@ -44,8 +44,6 @@ abstract class BaseFlags {
public static final boolean QSB_ON_FIRST_SCREEN = true;
// When enabled the all-apps icon is not added to the hotseat.
public static final boolean NO_ALL_APPS_ICON = true;
// When enabled, app discovery will be enabled if service is implemented
public static final boolean DISCOVERY_ENABLED = false;
// When true, custom widgets are loaded using CustomWidgetParser.
public static final boolean ENABLE_CUSTOM_WIDGETS = false;
@@ -1,74 +0,0 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.discovery;
import android.content.ComponentName;
import android.content.Intent;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.android.launcher3.AppInfo;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.graphics.ColorExtractor;
public class AppDiscoveryAppInfo extends AppInfo {
public final boolean showAsDiscoveryItem;
public final boolean isInstantApp;
public final boolean isRecent;
public final float rating;
public final long reviewCount;
public final @NonNull String publisher;
public final @NonNull Intent installIntent;
public final @NonNull Intent launchIntent;
public final @Nullable String priceFormatted;
public AppDiscoveryAppInfo(AppDiscoveryItem item) {
this.intent = item.isInstantApp ? item.launchIntent : item.installIntent;
this.title = item.title;
this.iconBitmap = item.bitmap;
this.iconColor = iconBitmap == null ? Color.TRANSPARENT :
ColorExtractor.findDominantColorByHue(item.bitmap);
this.usingLowResIcon = false;
this.isInstantApp = item.isInstantApp;
this.isRecent = item.isRecent;
this.rating = item.starRating;
this.showAsDiscoveryItem = true;
this.publisher = item.publisher != null ? item.publisher : "";
this.priceFormatted = item.price;
this.componentName = new ComponentName(item.packageName, "");
this.installIntent = item.installIntent;
this.launchIntent = item.launchIntent;
this.reviewCount = item.reviewCount;
this.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
}
@Override
public ShortcutInfo makeShortcut() {
if (!isDragAndDropSupported()) {
throw new RuntimeException("DnD is currently not supported for discovered store apps");
}
return super.makeShortcut();
}
public boolean isDragAndDropSupported() {
return isInstantApp;
}
}
@@ -1,64 +0,0 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.discovery;
import android.content.Intent;
import android.graphics.Bitmap;
/**
* This class represents the model for a discovered app via app discovery.
* It holds all information for one result retrieved from an app discovery service.
*/
public class AppDiscoveryItem {
public final String packageName;
public final boolean isInstantApp;
public final boolean isRecent;
public final float starRating;
public final long reviewCount;
public final Intent launchIntent;
public final Intent installIntent;
public final CharSequence title;
public final String publisher;
public final String price;
public final Bitmap bitmap;
public AppDiscoveryItem(String packageName,
boolean isInstantApp,
boolean isRecent,
float starRating,
long reviewCount,
CharSequence title,
String publisher,
Bitmap bitmap,
String price,
Intent launchIntent,
Intent installIntent) {
this.packageName = packageName;
this.isInstantApp = isInstantApp;
this.isRecent = isRecent;
this.starRating = starRating;
this.reviewCount = reviewCount;
this.launchIntent = launchIntent;
this.installIntent = installIntent;
this.title = title;
this.publisher = publisher;
this.price = price;
this.bitmap = bitmap;
}
}
@@ -1,97 +0,0 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.discovery;
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.android.launcher3.R;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class AppDiscoveryItemView extends RelativeLayout {
private static boolean SHOW_REVIEW_COUNT = false;
private ImageView mImage;
private TextView mTitle;
private TextView mRatingText;
private RatingView mRatingView;
private TextView mReviewCount;
private TextView mPrice;
private OnLongClickListener mOnLongClickListener;
public AppDiscoveryItemView(Context context) {
this(context, null);
}
public AppDiscoveryItemView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public AppDiscoveryItemView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
this.mImage = (ImageView) findViewById(R.id.image);
this.mTitle = (TextView) findViewById(R.id.title);
this.mRatingText = (TextView) findViewById(R.id.rating);
this.mRatingView = (RatingView) findViewById(R.id.rating_view);
this.mPrice = (TextView) findViewById(R.id.price);
this.mReviewCount = (TextView) findViewById(R.id.review_count);
}
public void init(OnClickListener clickListener,
AccessibilityDelegate accessibilityDelegate,
OnLongClickListener onLongClickListener) {
setOnClickListener(clickListener);
mImage.setOnClickListener(clickListener);
setAccessibilityDelegate(accessibilityDelegate);
mOnLongClickListener = onLongClickListener;
}
public void apply(@NonNull AppDiscoveryAppInfo info) {
setTag(info);
mImage.setTag(info);
mImage.setImageBitmap(info.iconBitmap);
mImage.setOnLongClickListener(info.isDragAndDropSupported() ? mOnLongClickListener : null);
mTitle.setText(info.title);
mPrice.setText(info.priceFormatted != null ? info.priceFormatted : "");
mReviewCount.setVisibility(SHOW_REVIEW_COUNT ? View.VISIBLE : View.GONE);
if (info.rating >= 0) {
mRatingText.setText(new DecimalFormat("#.0").format(info.rating));
mRatingView.setRating(info.rating);
mRatingView.setVisibility(View.VISIBLE);
String reviewCountFormatted = NumberFormat.getInstance().format(info.reviewCount);
mReviewCount.setText("(" + reviewCountFormatted + ")");
} else {
// if we don't have a rating
mRatingView.setVisibility(View.GONE);
mRatingText.setText("");
mReviewCount.setText("");
}
}
}
@@ -1,21 +0,0 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.discovery;
public enum AppDiscoveryUpdateState {
START, UPDATE, END
}
@@ -1,94 +0,0 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.discovery;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.ClipDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import com.android.launcher3.R;
/**
* A simple rating view that shows stars with a rating from 0-5.
*/
public class RatingView extends View {
private static final float WIDTH_FACTOR = 0.9f;
private static final int MAX_LEVEL = 10000;
private static final int MAX_STARS = 5;
private final Drawable mStarDrawable;
private final int mColorGray;
private final int mColorHighlight;
private float rating;
public RatingView(Context context) {
this(context, null);
}
public RatingView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public RatingView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mStarDrawable = getResources().getDrawable(R.drawable.ic_star_rating, null);
mColorGray = 0x1E000000;
mColorHighlight = 0x8A000000;
}
public void setRating(float rating) {
this.rating = Math.min(Math.max(rating, 0), MAX_STARS);
}
@Override
protected void onDraw(Canvas canvas) {
drawStars(canvas, MAX_STARS, mColorGray);
drawStars(canvas, rating, mColorHighlight);
}
private void drawStars(Canvas canvas, float stars, int color) {
int fullWidth = getLayoutParams().width;
int cellWidth = fullWidth / MAX_STARS;
int starWidth = (int) (cellWidth * WIDTH_FACTOR);
int padding = cellWidth - starWidth;
int fullStars = (int) stars;
float partialStarFactor = stars - fullStars;
for (int i = 0; i < fullStars; i++) {
int x = i * cellWidth + padding;
Drawable star = mStarDrawable.getConstantState().newDrawable().mutate();
star.setTint(color);
star.setBounds(x, padding, x + starWidth, padding + starWidth);
star.draw(canvas);
}
if (partialStarFactor > 0f) {
int x = fullStars * cellWidth + padding;
ClipDrawable star = new ClipDrawable(mStarDrawable,
Gravity.LEFT, ClipDrawable.HORIZONTAL);
star.setTint(color);
star.setLevel((int) (MAX_LEVEL * partialStarFactor));
star.setBounds(x, padding, x + starWidth, padding + starWidth);
star.draw(canvas);
}
}
}