blob: 901cc104702e66bc229efd20452d0e7f5b3d7b7c [file] [log] [blame]
John Spurlockaf8d6c42014-05-07 17:49:08 -04001/*
2 * Copyright (C) 2014 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.systemui.qs;
18
19import android.animation.ValueAnimator;
20import android.content.Context;
John Spurlockfaa32622014-06-04 01:38:34 -040021import android.graphics.ColorFilter;
22import android.graphics.LightingColorFilter;
John Spurlockaf8d6c42014-05-07 17:49:08 -040023import android.view.View;
24import android.widget.FrameLayout;
25import android.widget.ImageView;
26
27import com.android.systemui.R;
28import com.android.systemui.qs.QSTile.SignalState;
29
30/** View that represents a custom quick settings tile for displaying signal info (wifi/cell). **/
31public final class SignalTileView extends QSTileView {
32 private static final long DEFAULT_DURATION = new ValueAnimator().getDuration();
33 private static final long SHORT_DURATION = DEFAULT_DURATION / 3;
John Spurlockfaa32622014-06-04 01:38:34 -040034 private static final ColorFilter FILTER = new LightingColorFilter(0xffffffff, 0xff283034);
John Spurlockaf8d6c42014-05-07 17:49:08 -040035
36 private FrameLayout mIconFrame;
37 private ImageView mSignal;
38 private ImageView mOverlay;
39 private ImageView mIn;
40 private ImageView mOut;
41
42 public SignalTileView(Context context) {
43 super(context);
44
45 mIn = new ImageView(context);
46 mIn.setImageResource(R.drawable.ic_qs_signal_in);
John Spurlockfaa32622014-06-04 01:38:34 -040047 mIn.setColorFilter(FILTER);
John Spurlockaf8d6c42014-05-07 17:49:08 -040048 addView(mIn);
49
50 mOut = new ImageView(context);
51 mOut.setImageResource(R.drawable.ic_qs_signal_out);
John Spurlockfaa32622014-06-04 01:38:34 -040052 mOut.setColorFilter(FILTER);
John Spurlockaf8d6c42014-05-07 17:49:08 -040053 addView(mOut);
54 }
55
56 @Override
57 protected View createIcon() {
58 mIconFrame = new FrameLayout(mContext);
59 mSignal = new ImageView(mContext);
60 mIconFrame.addView(mSignal);
61 mOverlay = new ImageView(mContext);
62 mIconFrame.addView(mOverlay);
63 return mIconFrame;
64 }
65
66 @Override
67 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
68 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
69 int hs = MeasureSpec.makeMeasureSpec(mIconFrame.getMeasuredHeight(), MeasureSpec.EXACTLY);
70 int ws = MeasureSpec.makeMeasureSpec(mIconFrame.getMeasuredHeight(), MeasureSpec.AT_MOST);
71 mIn.measure(ws, hs);
72 mOut.measure(ws, hs);
73 }
74
75 @Override
76 protected void onLayout(boolean changed, int l, int t, int r, int b) {
77 super.onLayout(changed, l, t, r, b);
78 layoutIndicator(mIn);
79 layoutIndicator(mOut);
80 }
81
82 private void layoutIndicator(View indicator) {
83 indicator.layout(
84 mIconFrame.getRight(),
85 mIconFrame.getBottom() - indicator.getMeasuredHeight(),
86 mIconFrame.getRight() + indicator.getMeasuredWidth(),
87 mIconFrame.getBottom());
88 }
89
90 @Override
91 protected void handleStateChanged(QSTile.State state) {
92 super.handleStateChanged(state);
93 final SignalState s = (SignalState) state;
94 mSignal.setImageDrawable(null); // force refresh
95 mSignal.setImageResource(s.iconId);
John Spurlockfaa32622014-06-04 01:38:34 -040096 mSignal.setColorFilter(FILTER);
John Spurlockaf8d6c42014-05-07 17:49:08 -040097 if (s.overlayIconId > 0) {
98 mOverlay.setVisibility(VISIBLE);
99 mOverlay.setImageDrawable(null); // force refresh
100 mOverlay.setImageResource(s.overlayIconId);
John Spurlockfaa32622014-06-04 01:38:34 -0400101 mOverlay.setColorFilter(FILTER);
John Spurlockaf8d6c42014-05-07 17:49:08 -0400102 } else {
103 mOverlay.setVisibility(GONE);
104 }
105 setVisibility(mIn, s.activityIn);
106 setVisibility(mOut, s.activityOut);
107 }
108
109 private void setVisibility(View view, boolean visible) {
110 final float newAlpha = visible ? 1 : 0;
111 if (view.getAlpha() != newAlpha) {
112 view.animate()
113 .setDuration(visible ? SHORT_DURATION : DEFAULT_DURATION)
114 .alpha(newAlpha)
115 .withLayer()
116 .start();
117 }
118 }
119}