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