Home | History | Annotate | Download | only in launcher2
      1 /*
      2  * Copyright (C) 2010 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.launcher2;
     18 
     19 import android.content.Context;
     20 import android.graphics.Bitmap;
     21 import android.graphics.Canvas;
     22 import android.graphics.Paint;
     23 import android.widget.TextView;
     24 
     25 
     26 
     27 /**
     28  * An icon on a PagedView, specifically for items in the launcher's paged view (with compound
     29  * drawables on the top).
     30  */
     31 public class HolographicPagedViewIcon extends TextView  {
     32     PagedViewIcon mOriginalIcon;
     33     Paint mPaint;
     34 
     35     public HolographicPagedViewIcon(Context context, PagedViewIcon original) {
     36         super(context);
     37         mOriginalIcon = original;
     38         mPaint = new Paint();
     39     }
     40 
     41     @Override
     42     protected void onDraw(Canvas canvas) {
     43         Bitmap overlay = mOriginalIcon.getHolographicOutline();
     44         if (overlay != null) {
     45             final int offset = getScrollX();
     46             final int compoundPaddingLeft = getCompoundPaddingLeft();
     47             final int compoundPaddingRight = getCompoundPaddingRight();
     48             int hspace = getWidth() - compoundPaddingRight - compoundPaddingLeft;
     49             canvas.drawBitmap(overlay,
     50                     offset + compoundPaddingLeft + (hspace - overlay.getWidth()) / 2,
     51                     mOriginalIcon.getPaddingTop(),
     52                     mPaint);
     53         }
     54     }
     55 }
     56