1 /* 2 * Copyright (C) 2015 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.allapps; 17 18 import android.content.Context; 19 import android.graphics.Bitmap; 20 import android.graphics.Canvas; 21 import android.util.AttributeSet; 22 import android.view.View; 23 import android.view.ViewGroup; 24 import android.widget.FrameLayout; 25 import com.android.launcher3.BubbleTextView; 26 import com.android.launcher3.BubbleTextView.BubbleTextShadowHandler; 27 import com.android.launcher3.ClickShadowView; 28 import com.android.launcher3.DeviceProfile; 29 import com.android.launcher3.Launcher; 30 import com.android.launcher3.R; 31 32 /** 33 * A container for RecyclerView to allow for the click shadow view to be shown behind an icon that 34 * is launching. 35 */ 36 public class AllAppsRecyclerViewContainerView extends FrameLayout 37 implements BubbleTextShadowHandler { 38 39 private final ClickShadowView mTouchFeedbackView; 40 AllAppsRecyclerViewContainerView(Context context)41 public AllAppsRecyclerViewContainerView(Context context) { 42 this(context, null); 43 } 44 AllAppsRecyclerViewContainerView(Context context, AttributeSet attrs)45 public AllAppsRecyclerViewContainerView(Context context, AttributeSet attrs) { 46 this(context, attrs, 0); 47 } 48 AllAppsRecyclerViewContainerView(Context context, AttributeSet attrs, int defStyleAttr)49 public AllAppsRecyclerViewContainerView(Context context, AttributeSet attrs, int defStyleAttr) { 50 super(context, attrs, defStyleAttr); 51 52 Launcher launcher = (Launcher) context; 53 DeviceProfile grid = launcher.getDeviceProfile(); 54 55 mTouchFeedbackView = new ClickShadowView(context); 56 57 // Make the feedback view large enough to hold the blur bitmap. 58 int size = grid.allAppsIconSizePx + mTouchFeedbackView.getExtraSize(); 59 addView(mTouchFeedbackView, size, size); 60 } 61 62 @Override setPressedIcon(BubbleTextView icon, Bitmap background)63 public void setPressedIcon(BubbleTextView icon, Bitmap background) { 64 if (icon == null || background == null) { 65 mTouchFeedbackView.setBitmap(null); 66 mTouchFeedbackView.animate().cancel(); 67 } else if (mTouchFeedbackView.setBitmap(background)) { 68 mTouchFeedbackView.alignWithIconView(icon, (ViewGroup) icon.getParent()); 69 mTouchFeedbackView.animateShadow(); 70 } 71 } 72 } 73