blob: d0b7cfb152ea6c6424349b22d1997e8c1c1982e5 [file] [log] [blame]
Mihai Nitad7d48fd2016-01-12 08:55:05 -08001/*
2 * Copyright (C) 2016 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.settings.localepicker;
18
19import android.content.Context;
20import android.util.AttributeSet;
21import android.widget.CheckBox;
22import android.widget.ImageView;
Mihai Nita7f78a4b2016-02-05 11:55:45 -080023import android.widget.RelativeLayout;
Mihai Nitad7d48fd2016-01-12 08:55:05 -080024import android.widget.TextView;
25
26import com.android.settings.R;
27
Mihai Nita7f78a4b2016-02-05 11:55:45 -080028class LocaleDragCell extends RelativeLayout {
29 // We need to keep the label and the checkbox "in sync"
30 // The checkbox shows in remove mode, and the label shows in normal mode, in the same position.
31 // So we need to set the same text to both of them, and coordinate the show / hide.
Mihai Nitad7d48fd2016-01-12 08:55:05 -080032 private TextView mLabel;
Mihai Nitad7d48fd2016-01-12 08:55:05 -080033 private CheckBox mCheckbox;
Mihai Nita7f78a4b2016-02-05 11:55:45 -080034 private TextView mMiniLabel;
35 private TextView mLocalized;
tom hsuf33ac492022-08-11 23:51:24 +080036 private TextView mCurrentDefault;
Mihai Nitad7d48fd2016-01-12 08:55:05 -080037 private ImageView mDragHandle;
38
39 public LocaleDragCell(Context context, AttributeSet attrs) {
40 super(context, attrs);
41 }
42
43 @Override
44 protected void onFinishInflate() {
45 super.onFinishInflate();
46 mLabel = (TextView) findViewById(R.id.label);
Mihai Nita7f78a4b2016-02-05 11:55:45 -080047 mLocalized = (TextView) findViewById(R.id.l10nWarn);
tom hsuf33ac492022-08-11 23:51:24 +080048 mCurrentDefault = (TextView) findViewById(R.id.default_locale);
Mihai Nitad7d48fd2016-01-12 08:55:05 -080049 mMiniLabel = (TextView) findViewById(R.id.miniLabel);
50 mCheckbox = (CheckBox) findViewById(R.id.checkbox);
51 mDragHandle = (ImageView) findViewById(R.id.dragHandle);
52 }
53
54 public void setShowHandle(boolean showHandle) {
Mihai Nita7f78a4b2016-02-05 11:55:45 -080055 // We want invisible, not gone, so that everything else stays the same.
56 // With GONE there is more space for the labels and the text wrapping change.
57 // So the transition between "normal" mode (with numbers) and
58 // "remove mode" (with checkboxes) is not that "smooth"
59 mDragHandle.setVisibility(showHandle ? VISIBLE : INVISIBLE);
Mihai Nitad7d48fd2016-01-12 08:55:05 -080060 invalidate();
61 requestLayout();
62 }
63
64 public void setShowCheckbox(boolean showCheckbox) {
Mihai Nita7f78a4b2016-02-05 11:55:45 -080065 // "Opposite" visibility for label / checkbox
Zoey Chene9f6efa2023-04-12 13:19:31 +000066 mCheckbox.setVisibility(showCheckbox ? VISIBLE : GONE);
Mihai Nitad7d48fd2016-01-12 08:55:05 -080067 invalidate();
68 requestLayout();
69 }
70
71 public void setChecked(boolean checked) {
72 mCheckbox.setChecked(checked);
73 }
74
75 public void setShowMiniLabel(boolean showMiniLabel) {
76 mMiniLabel.setVisibility(showMiniLabel ? VISIBLE : GONE);
77 invalidate();
78 requestLayout();
79 }
80
81 public void setMiniLabel(String miniLabelText) {
82 mMiniLabel.setText(miniLabelText);
83 invalidate();
84 }
85
Mihai Nitad86cba72016-04-19 09:20:20 -070086 public void setLabelAndDescription(String labelText, String description) {
Mihai Nitad7d48fd2016-01-12 08:55:05 -080087 mLabel.setText(labelText);
Mihai Nitad86cba72016-04-19 09:20:20 -070088 mLabel.setContentDescription(description);
Mihai Nitad7d48fd2016-01-12 08:55:05 -080089 invalidate();
90 }
91
92 public void setLocalized(boolean localized) {
Mihai Nita7f78a4b2016-02-05 11:55:45 -080093 mLocalized.setVisibility(localized ? GONE : VISIBLE);
Mihai Nitad7d48fd2016-01-12 08:55:05 -080094 invalidate();
95 }
96
tom hsuf33ac492022-08-11 23:51:24 +080097 /**
98 * Indicate current locale is system default.
99 */
100 public void setCurrentDefault(boolean isCurrentDefault) {
101 mCurrentDefault.setVisibility(isCurrentDefault ? VISIBLE : GONE);
102 invalidate();
103 }
104
Mihai Nitad7d48fd2016-01-12 08:55:05 -0800105 public ImageView getDragHandle() {
106 return mDragHandle;
107 }
108
Zoey Chene9f6efa2023-04-12 13:19:31 +0000109 public TextView getLabelView() {
110 return mLabel;
111 }
112
Mihai Nitad7d48fd2016-01-12 08:55:05 -0800113 public CheckBox getCheckbox() {
114 return mCheckbox;
115 }
116}