Add drawable for default thumbnail for Recents Go

This CL adds a drawable for the default thumbnail view and
refactors the logic to get the default icon/thumbnail/label if
null to separate methods for re-use in later CLs.

Bug: 114136250
Test: Manual; Go to icon recents
Change-Id: I511ea40ace040fc53ffc69c27149f24d69bda7b0
(cherry picked from commit 34ee30c4f9)
This commit is contained in:
Kevin 2019-04-08 17:09:19 -07:00
parent 3cccc666b6
commit 6092a6ee1e
2 changed files with 45 additions and 20 deletions

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2019 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.
-->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/darker_gray"/>
<corners android:radius="2dp"/>
</shape>

View File

@ -16,8 +16,9 @@
package com.android.quickstep.views; package com.android.quickstep.views;
import android.content.Context; import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
@ -25,6 +26,7 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.android.launcher3.R; import com.android.launcher3.R;
@ -36,14 +38,16 @@ public final class TaskItemView extends LinearLayout {
private static final String DEFAULT_LABEL = "..."; private static final String DEFAULT_LABEL = "...";
private final Drawable mDefaultIcon; private final Drawable mDefaultIcon;
private final Drawable mDefaultThumbnail;
private TextView mLabelView; private TextView mLabelView;
private ImageView mIconView; private ImageView mIconView;
private ImageView mThumbnailView; private ImageView mThumbnailView;
public TaskItemView(Context context, AttributeSet attrs) { public TaskItemView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
mDefaultIcon = context.getResources().getDrawable( Resources res = context.getResources();
android.R.drawable.sym_def_app_icon, context.getTheme()); mDefaultIcon = res.getDrawable(android.R.drawable.sym_def_app_icon, context.getTheme());
mDefaultThumbnail = res.getDrawable(R.drawable.default_thumbnail, context.getTheme());
} }
@Override @Override
@ -69,11 +73,7 @@ public final class TaskItemView extends LinearLayout {
* @param label task label * @param label task label
*/ */
public void setLabel(@Nullable String label) { public void setLabel(@Nullable String label) {
if (label == null) { mLabelView.setText(getSafeLabel(label));
mLabelView.setText(DEFAULT_LABEL);
return;
}
mLabelView.setText(label);
} }
/** /**
@ -86,11 +86,7 @@ public final class TaskItemView extends LinearLayout {
// The icon proper is actually smaller than the drawable and has "padding" on the side for // The icon proper is actually smaller than the drawable and has "padding" on the side for
// the purpose of drawing the shadow, allowing the icon to pop up, so we need to scale the // the purpose of drawing the shadow, allowing the icon to pop up, so we need to scale the
// view if we want the icon to be flush with the bottom of the thumbnail. // view if we want the icon to be flush with the bottom of the thumbnail.
if (icon == null) { mIconView.setImageDrawable(getSafeIcon(icon));
mIconView.setImageDrawable(mDefaultIcon);
return;
}
mIconView.setImageDrawable(icon);
} }
/** /**
@ -99,16 +95,23 @@ public final class TaskItemView extends LinearLayout {
* @param thumbnail task thumbnail for the task * @param thumbnail task thumbnail for the task
*/ */
public void setThumbnail(@Nullable Bitmap thumbnail) { public void setThumbnail(@Nullable Bitmap thumbnail) {
if (thumbnail == null) { mThumbnailView.setImageDrawable(getSafeThumbnail(thumbnail));
mThumbnailView.setImageBitmap(null);
mThumbnailView.setBackgroundColor(Color.GRAY);
return;
}
mThumbnailView.setBackgroundColor(Color.TRANSPARENT);
mThumbnailView.setImageBitmap(thumbnail);
} }
public View getThumbnailView() { public View getThumbnailView() {
return mThumbnailView; return mThumbnailView;
} }
private @NonNull Drawable getSafeIcon(@Nullable Drawable icon) {
return (icon != null) ? icon : mDefaultIcon;
}
private @NonNull Drawable getSafeThumbnail(@Nullable Bitmap thumbnail) {
return (thumbnail != null) ? new BitmapDrawable(getResources(), thumbnail)
: mDefaultThumbnail;
}
private @NonNull String getSafeLabel(@Nullable String label) {
return (label != null) ? label : DEFAULT_LABEL;
}
} }