blob: f012db74b0071901dda04f9d22ee00f06d532261 [file] [log] [blame]
Winson Chungd2be3812013-07-16 11:11:32 -07001/*
2 * Copyright (C) 2011 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
17package com.android.launcher3;
18
Winson Chungd2be3812013-07-16 11:11:32 -070019import android.content.Context;
Winson Chung7819a562013-09-19 15:55:45 -070020import android.content.res.Resources;
Winson Chungd2be3812013-07-16 11:11:32 -070021import android.util.AttributeSet;
Winson Chungd2be3812013-07-16 11:11:32 -070022import android.widget.FrameLayout;
Michael Jurka34c2e6c2013-12-13 16:07:45 +010023import android.widget.ImageView;
Winson Chungd2be3812013-07-16 11:11:32 -070024
25public class PageIndicatorMarker extends FrameLayout {
26 @SuppressWarnings("unused")
27 private static final String TAG = "PageIndicator";
28
Winson Chung5bc865e2013-07-18 15:18:25 -070029 private static final int MARKER_FADE_DURATION = 175;
Winson Chungd2be3812013-07-16 11:11:32 -070030
Winson Chung7819a562013-09-19 15:55:45 -070031 private ImageView mActiveMarker;
32 private ImageView mInactiveMarker;
Winson Chung5bc865e2013-07-18 15:18:25 -070033 private boolean mIsActive = false;
Winson Chungd2be3812013-07-16 11:11:32 -070034
35 public PageIndicatorMarker(Context context) {
36 this(context, null);
37 }
38
39 public PageIndicatorMarker(Context context, AttributeSet attrs) {
40 this(context, attrs, 0);
41 }
42
43 public PageIndicatorMarker(Context context, AttributeSet attrs, int defStyle) {
44 super(context, attrs, defStyle);
45 }
46
47 protected void onFinishInflate() {
Winson Chung7819a562013-09-19 15:55:45 -070048 mActiveMarker = (ImageView) findViewById(R.id.active);
49 mInactiveMarker = (ImageView) findViewById(R.id.inactive);
50 }
51
52 void setMarkerDrawables(int activeResId, int inactiveResId) {
53 Resources r = getResources();
54 mActiveMarker.setImageDrawable(r.getDrawable(activeResId));
55 mInactiveMarker.setImageDrawable(r.getDrawable(inactiveResId));
Winson Chungd2be3812013-07-16 11:11:32 -070056 }
57
Winson Chung5bc865e2013-07-18 15:18:25 -070058 void activate(boolean immediate) {
59 if (immediate) {
60 mActiveMarker.animate().cancel();
61 mActiveMarker.setAlpha(1f);
Daniel Sandlerbb701aa2013-09-19 15:03:00 -040062 mActiveMarker.setScaleX(1f);
63 mActiveMarker.setScaleY(1f);
Winson Chung5bc865e2013-07-18 15:18:25 -070064 mInactiveMarker.animate().cancel();
65 mInactiveMarker.setAlpha(0f);
66 } else {
Daniel Sandlerbb701aa2013-09-19 15:03:00 -040067 mActiveMarker.animate()
68 .alpha(1f)
69 .scaleX(1f)
70 .scaleY(1f)
Winson Chung5bc865e2013-07-18 15:18:25 -070071 .setDuration(MARKER_FADE_DURATION).start();
Daniel Sandlerbb701aa2013-09-19 15:03:00 -040072 mInactiveMarker.animate()
73 .alpha(0f)
Winson Chung5bc865e2013-07-18 15:18:25 -070074 .setDuration(MARKER_FADE_DURATION).start();
75 }
76 mIsActive = true;
Winson Chungd2be3812013-07-16 11:11:32 -070077 }
Daniel Sandlerbb701aa2013-09-19 15:03:00 -040078
Winson Chung5bc865e2013-07-18 15:18:25 -070079 void inactivate(boolean immediate) {
80 if (immediate) {
81 mInactiveMarker.animate().cancel();
82 mInactiveMarker.setAlpha(1f);
83 mActiveMarker.animate().cancel();
84 mActiveMarker.setAlpha(0f);
Daniel Sandlerbb701aa2013-09-19 15:03:00 -040085 mActiveMarker.setScaleX(0.5f);
86 mActiveMarker.setScaleY(0.5f);
Winson Chung5bc865e2013-07-18 15:18:25 -070087 } else {
88 mInactiveMarker.animate().alpha(1f)
89 .setDuration(MARKER_FADE_DURATION).start();
Daniel Sandlerbb701aa2013-09-19 15:03:00 -040090 mActiveMarker.animate()
91 .alpha(0f)
92 .scaleX(0.5f)
93 .scaleY(0.5f)
Winson Chung5bc865e2013-07-18 15:18:25 -070094 .setDuration(MARKER_FADE_DURATION).start();
95 }
96 mIsActive = false;
97 }
98
99 boolean isActive() {
100 return mIsActive;
Winson Chungd2be3812013-07-16 11:11:32 -0700101 }
102}