Home | History | Annotate | Download | only in phone
      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 
     17 package com.android.systemui.statusbar.phone;
     18 
     19 import android.graphics.Canvas;
     20 import android.graphics.Point;
     21 import android.graphics.Rect;
     22 import android.graphics.drawable.Drawable;
     23 import android.view.View;
     24 import android.widget.ImageView;
     25 
     26 /** Creates a scaled-up version of an app icon for dragging. */
     27 class AppIconDragShadowBuilder extends View.DragShadowBuilder {
     28     private final static int ICON_SCALE = 2;
     29     final Drawable mDrawable;
     30     final int mIconSize;  // Height and width in device-pixels.
     31 
     32     public AppIconDragShadowBuilder(ImageView icon) {
     33         mDrawable = icon.getDrawable();
     34         // The Drawable may not be the same size as the ImageView, so use the ImageView size.
     35         // The ImageView is not square because it has additional left and right padding to create
     36         // a wider drop target, so use the height to create a square drag shadow.
     37         mIconSize = icon.getHeight() * ICON_SCALE;
     38     }
     39 
     40     @Override
     41     public void onProvideShadowMetrics(Point size, Point touch) {
     42         size.set(mIconSize, mIconSize);
     43         // Shift the drag shadow up slightly because the apps are at the bottom edge of the
     44         // screen.
     45         touch.set(mIconSize / 2, mIconSize * 2 / 3);
     46     }
     47 
     48     @Override
     49     public void onDrawShadow(Canvas canvas) {
     50         // The Drawable's native bounds may be different than the source ImageView. Force it
     51         // to the correct size.
     52         Rect oldBounds = mDrawable.copyBounds();
     53         mDrawable.setBounds(0, 0, mIconSize, mIconSize);
     54         mDrawable.draw(canvas);
     55         mDrawable.setBounds(oldBounds);
     56     }
     57 }
     58