PageIndicatorCaretLandscape.java revision 1f06427266c0cb5de4561fc7c620ff542f625300
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 */
16package com.android.launcher3.pageindicators;
17
18import android.content.Context;
19import android.content.res.Resources;
20import android.graphics.Canvas;
21import android.graphics.Paint;
22import android.graphics.Rect;
23import android.util.AttributeSet;
24
25import com.android.launcher3.Launcher;
26import 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 */
33public class PageIndicatorCaretLandscape extends PageIndicator {
34    // all apps pull up handle drawable.
35
36    public PageIndicatorCaretLandscape(Context context) {
37        this(context, null);
38    }
39
40    public PageIndicatorCaretLandscape(Context context, AttributeSet attrs) {
41        this(context, attrs, 0);
42    }
43
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) context;
53        setOnTouchListener(l.getHapticFeedbackTouchListener());
54        setOnClickListener(l);
55        setOnFocusChangeListener(l.mFocusHandler);
56    }
57
58    @Override
59    protected void onDraw(Canvas canvas) {
60        Rect drawableBounds = getCaretDrawable().getBounds();
61        int count = canvas.save();
62        canvas.translate(getWidth() - drawableBounds.width(),
63                getHeight() - drawableBounds.height());
64        getCaretDrawable().draw(canvas);
65        canvas.restoreToCount(count);
66    }
67}
68