17d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song/*
27d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song * Copyright (C) 2016 The Android Open Source Project
37d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song *
47d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song * Licensed under the Apache License, Version 2.0 (the "License");
57d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song * you may not use this file except in compliance with the License.
67d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song * You may obtain a copy of the License at
77d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song *
87d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song *      http://www.apache.org/licenses/LICENSE-2.0
97d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song *
107d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song * Unless required by applicable law or agreed to in writing, software
117d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song * distributed under the License is distributed on an "AS IS" BASIS,
127d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song * See the License for the specific language governing permissions and
147d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song * limitations under the License.
157d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song */
167d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Songpackage com.android.launcher3.pageindicators;
177d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song
187d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Songimport android.content.Context;
191f06427266c0cb5de4561fc7c620ff542f625300Winsonimport android.content.res.Resources;
207d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Songimport android.graphics.Canvas;
211f06427266c0cb5de4561fc7c620ff542f625300Winsonimport android.graphics.Paint;
221f06427266c0cb5de4561fc7c620ff542f625300Winsonimport android.graphics.Rect;
237d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Songimport android.util.AttributeSet;
247d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song
257d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Songimport com.android.launcher3.Launcher;
261f06427266c0cb5de4561fc7c620ff542f625300Winsonimport com.android.launcher3.R;
277d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song
287d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song/**
291f06427266c0cb5de4561fc7c620ff542f625300Winson * Simply draws the caret drawable bottom-right aligned in the view. This ensures that we can have
301f06427266c0cb5de4561fc7c620ff542f625300Winson * a view with as large an area as we want (for touching) while maintaining a caret of size
311f06427266c0cb5de4561fc7c620ff542f625300Winson * all_apps_caret_size.  Used only for the landscape layout.
327d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song */
337d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Songpublic class PageIndicatorCaretLandscape extends PageIndicator {
347d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song    // all apps pull up handle drawable.
357d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song
367d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song    public PageIndicatorCaretLandscape(Context context) {
377d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song        this(context, null);
387d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song    }
397d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song
407d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song    public PageIndicatorCaretLandscape(Context context, AttributeSet attrs) {
417d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song        this(context, attrs, 0);
427d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song    }
437d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song
447d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song    public PageIndicatorCaretLandscape(Context context, AttributeSet attrs, int defStyle) {
457d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song        super(context, attrs, defStyle);
467d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song
471f06427266c0cb5de4561fc7c620ff542f625300Winson        int caretSize = context.getResources().getDimensionPixelSize(R.dimen.all_apps_caret_size);
481f06427266c0cb5de4561fc7c620ff542f625300Winson        CaretDrawable caretDrawable = new CaretDrawable(context);
491f06427266c0cb5de4561fc7c620ff542f625300Winson        caretDrawable.setBounds(0, 0, caretSize, caretSize);
501f06427266c0cb5de4561fc7c620ff542f625300Winson        setCaretDrawable(caretDrawable);
511f06427266c0cb5de4561fc7c620ff542f625300Winson
522fd020860533e18c64a93d14d11cb2d34bc9cbafTony        Launcher l = Launcher.getLauncher(context);
537d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song        setOnTouchListener(l.getHapticFeedbackTouchListener());
547d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song        setOnClickListener(l);
5568f98ac102a2719203883d87add6483797b516daHyunyoung Song        setOnLongClickListener(l);
567d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song        setOnFocusChangeListener(l.mFocusHandler);
577d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song    }
587d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song
597d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song    @Override
607d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song    protected void onDraw(Canvas canvas) {
611f06427266c0cb5de4561fc7c620ff542f625300Winson        Rect drawableBounds = getCaretDrawable().getBounds();
621f06427266c0cb5de4561fc7c620ff542f625300Winson        int count = canvas.save();
631f06427266c0cb5de4561fc7c620ff542f625300Winson        canvas.translate(getWidth() - drawableBounds.width(),
641f06427266c0cb5de4561fc7c620ff542f625300Winson                getHeight() - drawableBounds.height());
65a30b51ceb29e179caf7f441763ffeb6bfd336998Peter Schiller        getCaretDrawable().draw(canvas);
661f06427266c0cb5de4561fc7c620ff542f625300Winson        canvas.restoreToCount(count);
677d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song    }
687d2fc8120e549eaa9542b0985aab67d172cbd682Hyunyoung Song}
69