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 */ 16package com.android.launcher3.allapps; 17 18import android.content.Context; 19import android.graphics.Bitmap; 20import android.util.AttributeSet; 21import android.view.View; 22import android.view.ViewGroup; 23import android.widget.RelativeLayout; 24 25import com.android.launcher3.BubbleTextView; 26import com.android.launcher3.BubbleTextView.BubbleTextShadowHandler; 27import com.android.launcher3.ClickShadowView; 28import com.android.launcher3.DeviceProfile; 29import com.android.launcher3.Launcher; 30import 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 */ 36public class AllAppsRecyclerViewContainerView extends RelativeLayout 37 implements BubbleTextShadowHandler { 38 39 private final ClickShadowView mTouchFeedbackView; 40 41 public AllAppsRecyclerViewContainerView(Context context) { 42 this(context, null); 43 } 44 45 public AllAppsRecyclerViewContainerView(Context context, AttributeSet attrs) { 46 this(context, attrs, 0); 47 } 48 49 public AllAppsRecyclerViewContainerView(Context context, AttributeSet attrs, int defStyleAttr) { 50 super(context, attrs, defStyleAttr); 51 52 Launcher launcher = Launcher.getLauncher(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 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 View rv = findViewById(R.id.apps_list_view); 69 mTouchFeedbackView.alignWithIconView(icon, (ViewGroup) icon.getParent(), rv); 70 mTouchFeedbackView.animateShadow(); 71 } 72 } 73} 74