blob: 1ef36a2a75b7643416f5df6b3096d30f9d4fe211 [file] [log] [blame]
tmfang2badb3e2018-12-10 00:25:02 +08001/*
2 * Copyright (C) 2018 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.settingslib.widget;
18
19import android.graphics.drawable.Drawable;
20import android.view.View;
21
22import androidx.annotation.IntRange;
23import androidx.annotation.Nullable;
24import androidx.annotation.StringRes;
25
26import java.util.Comparator;
27
28/**
29 * A class responsible for saving bar view information.
30 */
31public class BarViewInfo implements Comparable<BarViewInfo> {
32
33 private final Drawable mIcon;
tmfang7081e7f2018-12-19 14:14:34 +080034 private View.OnClickListener mClickListener;
Fan Zhang7989dfc2018-12-19 12:03:53 -080035 @StringRes
36 private int mSummary;
Joel Galenson9842425f2019-03-05 14:14:14 -080037 private @Nullable CharSequence mContentDescription;
tmfang2badb3e2018-12-10 00:25:02 +080038 // A number indicates this bar's height. The larger number shows a higher bar view.
Fan Zhang7989dfc2018-12-19 12:03:53 -080039 private int mHeight;
tmfang2badb3e2018-12-10 00:25:02 +080040 // A real height of bar view.
Fan Zhang7989dfc2018-12-19 12:03:53 -080041 private int mNormalizedHeight;
tmfang2badb3e2018-12-10 00:25:02 +080042
43 /**
44 * Construct a BarViewInfo instance.
45 *
Fan Zhang7989dfc2018-12-19 12:03:53 -080046 * @param icon The icon of bar view.
47 * @param barHeight The height of bar view. Larger number shows a higher bar view.
48 * @param summary The string resource id for summary.
Joel Galenson9842425f2019-03-05 14:14:14 -080049 * @param contentDescription Optional text that briefly describes the contents of the icon.
tmfang2badb3e2018-12-10 00:25:02 +080050 */
Joel Galenson9842425f2019-03-05 14:14:14 -080051 public BarViewInfo(Drawable icon, @IntRange(from = 0) int barHeight, @StringRes int summary,
52 @Nullable CharSequence contentDescription) {
tmfang2badb3e2018-12-10 00:25:02 +080053 mIcon = icon;
Fan Zhang7989dfc2018-12-19 12:03:53 -080054 mHeight = barHeight;
55 mSummary = summary;
Joel Galenson9842425f2019-03-05 14:14:14 -080056 mContentDescription = contentDescription;
tmfang2badb3e2018-12-10 00:25:02 +080057 }
58
tmfang7081e7f2018-12-19 14:14:34 +080059 /**
60 * Set a click listener for bar view.
61 */
62 public void setClickListener(@Nullable View.OnClickListener listener) {
63 mClickListener = listener;
64 }
65
tmfang2badb3e2018-12-10 00:25:02 +080066 @Override
67 public int compareTo(BarViewInfo other) {
68 // Descending order
Fan Zhang7989dfc2018-12-19 12:03:53 -080069 return Comparator.comparingInt((BarViewInfo barViewInfo) -> barViewInfo.mHeight)
tmfang2badb3e2018-12-10 00:25:02 +080070 .compare(other, this);
71 }
72
Fan Zhang7989dfc2018-12-19 12:03:53 -080073 void setHeight(@IntRange(from = 0) int height) {
74 mHeight = height;
75 }
76
77 void setSummary(@StringRes int resId) {
78 mSummary = resId;
79 }
80
Fan Zhang7989dfc2018-12-19 12:03:53 -080081 Drawable getIcon() {
82 return mIcon;
83 }
84
85 int getHeight() {
86 return mHeight;
87 }
88
89 View.OnClickListener getClickListener() {
tmfang7081e7f2018-12-19 14:14:34 +080090 return mClickListener;
Fan Zhang7989dfc2018-12-19 12:03:53 -080091 }
92
93 @StringRes
94 int getSummary() {
95 return mSummary;
96 }
97
Joel Galenson9842425f2019-03-05 14:14:14 -080098 public @Nullable CharSequence getContentDescription() {
99 return mContentDescription;
100 }
101
Fan Zhang7989dfc2018-12-19 12:03:53 -0800102 void setNormalizedHeight(@IntRange(from = 0) int barHeight) {
103 mNormalizedHeight = barHeight;
104 }
105
106 int getNormalizedHeight() {
107 return mNormalizedHeight;
tmfang2badb3e2018-12-10 00:25:02 +0800108 }
109}