• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.pageindicators;
17 
18 import android.content.Context;
19 import android.content.res.Resources;
20 import android.graphics.Canvas;
21 import android.graphics.Paint;
22 import android.graphics.Rect;
23 import android.util.AttributeSet;
24 
25 import com.android.launcher3.Launcher;
26 import com.android.launcher3.R;
27 
28 /**
29  * Simply draws the caret drawable bottom-right aligned in the view. This ensures that we can have
30  * a view with as large an area as we want (for touching) while maintaining a caret of size
31  * all_apps_caret_size.  Used only for the landscape layout.
32  */
33 public class PageIndicatorCaretLandscape extends PageIndicator {
34     // all apps pull up handle drawable.
35 
PageIndicatorCaretLandscape(Context context)36     public PageIndicatorCaretLandscape(Context context) {
37         this(context, null);
38     }
39 
PageIndicatorCaretLandscape(Context context, AttributeSet attrs)40     public PageIndicatorCaretLandscape(Context context, AttributeSet attrs) {
41         this(context, attrs, 0);
42     }
43 
PageIndicatorCaretLandscape(Context context, AttributeSet attrs, int defStyle)44     public PageIndicatorCaretLandscape(Context context, AttributeSet attrs, int defStyle) {
45         super(context, attrs, defStyle);
46 
47         int caretSize = context.getResources().getDimensionPixelSize(R.dimen.all_apps_caret_size);
48         CaretDrawable caretDrawable = new CaretDrawable(context);
49         caretDrawable.setBounds(0, 0, caretSize, caretSize);
50         setCaretDrawable(caretDrawable);
51 
52         Launcher l = Launcher.getLauncher(context);
53         setOnTouchListener(l.getHapticFeedbackTouchListener());
54         setOnClickListener(l);
55         setOnLongClickListener(l);
56         setOnFocusChangeListener(l.mFocusHandler);
57     }
58 
59     @Override
onDraw(Canvas canvas)60     protected void onDraw(Canvas canvas) {
61         Rect drawableBounds = getCaretDrawable().getBounds();
62         int count = canvas.save();
63         canvas.translate(getWidth() - drawableBounds.width(),
64                 getHeight() - drawableBounds.height());
65         getCaretDrawable().draw(canvas);
66         canvas.restoreToCount(count);
67     }
68 }
69