blob: 409f9ea058899e73cb1876c8cfb6bbeb49873824 [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;
tmfang2badb3e2018-12-10 00:25:02 +080037 // A number indicates this bar's height. The larger number shows a higher bar view.
Fan Zhang7989dfc2018-12-19 12:03:53 -080038 private int mHeight;
tmfang2badb3e2018-12-10 00:25:02 +080039 // A real height of bar view.
Fan Zhang7989dfc2018-12-19 12:03:53 -080040 private int mNormalizedHeight;
tmfang2badb3e2018-12-10 00:25:02 +080041
42 /**
43 * Construct a BarViewInfo instance.
44 *
Fan Zhang7989dfc2018-12-19 12:03:53 -080045 * @param icon The icon of bar view.
46 * @param barHeight The height of bar view. Larger number shows a higher bar view.
47 * @param summary The string resource id for summary.
tmfang2badb3e2018-12-10 00:25:02 +080048 */
Fan Zhang7989dfc2018-12-19 12:03:53 -080049 public BarViewInfo(Drawable icon, @IntRange(from = 0) int barHeight, @StringRes int summary) {
tmfang2badb3e2018-12-10 00:25:02 +080050 mIcon = icon;
Fan Zhang7989dfc2018-12-19 12:03:53 -080051 mHeight = barHeight;
52 mSummary = summary;
tmfang2badb3e2018-12-10 00:25:02 +080053 }
54
tmfang7081e7f2018-12-19 14:14:34 +080055 /**
56 * Set a click listener for bar view.
57 */
58 public void setClickListener(@Nullable View.OnClickListener listener) {
59 mClickListener = listener;
60 }
61
tmfang2badb3e2018-12-10 00:25:02 +080062 @Override
63 public int compareTo(BarViewInfo other) {
64 // Descending order
Fan Zhang7989dfc2018-12-19 12:03:53 -080065 return Comparator.comparingInt((BarViewInfo barViewInfo) -> barViewInfo.mHeight)
tmfang2badb3e2018-12-10 00:25:02 +080066 .compare(other, this);
67 }
68
Fan Zhang7989dfc2018-12-19 12:03:53 -080069 void setHeight(@IntRange(from = 0) int height) {
70 mHeight = height;
71 }
72
73 void setSummary(@StringRes int resId) {
74 mSummary = resId;
75 }
76
Fan Zhang7989dfc2018-12-19 12:03:53 -080077 Drawable getIcon() {
78 return mIcon;
79 }
80
81 int getHeight() {
82 return mHeight;
83 }
84
85 View.OnClickListener getClickListener() {
tmfang7081e7f2018-12-19 14:14:34 +080086 return mClickListener;
Fan Zhang7989dfc2018-12-19 12:03:53 -080087 }
88
89 @StringRes
90 int getSummary() {
91 return mSummary;
92 }
93
94 void setNormalizedHeight(@IntRange(from = 0) int barHeight) {
95 mNormalizedHeight = barHeight;
96 }
97
98 int getNormalizedHeight() {
99 return mNormalizedHeight;
tmfang2badb3e2018-12-10 00:25:02 +0800100 }
101}