Mihai Nita | d7d48fd | 2016-01-12 08:55:05 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.settings.localepicker; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.util.AttributeSet; |
| 21 | import android.widget.CheckBox; |
| 22 | import android.widget.ImageView; |
Mihai Nita | 7f78a4b | 2016-02-05 11:55:45 -0800 | [diff] [blame] | 23 | import android.widget.RelativeLayout; |
Mihai Nita | d7d48fd | 2016-01-12 08:55:05 -0800 | [diff] [blame] | 24 | import android.widget.TextView; |
| 25 | |
| 26 | import com.android.settings.R; |
| 27 | |
Mihai Nita | 7f78a4b | 2016-02-05 11:55:45 -0800 | [diff] [blame] | 28 | class 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 Nita | d7d48fd | 2016-01-12 08:55:05 -0800 | [diff] [blame] | 32 | private TextView mLabel; |
Mihai Nita | d7d48fd | 2016-01-12 08:55:05 -0800 | [diff] [blame] | 33 | private CheckBox mCheckbox; |
Mihai Nita | 7f78a4b | 2016-02-05 11:55:45 -0800 | [diff] [blame] | 34 | private TextView mMiniLabel; |
| 35 | private TextView mLocalized; |
tom hsu | f33ac49 | 2022-08-11 23:51:24 +0800 | [diff] [blame] | 36 | private TextView mCurrentDefault; |
Mihai Nita | d7d48fd | 2016-01-12 08:55:05 -0800 | [diff] [blame] | 37 | 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 Nita | 7f78a4b | 2016-02-05 11:55:45 -0800 | [diff] [blame] | 47 | mLocalized = (TextView) findViewById(R.id.l10nWarn); |
tom hsu | f33ac49 | 2022-08-11 23:51:24 +0800 | [diff] [blame] | 48 | mCurrentDefault = (TextView) findViewById(R.id.default_locale); |
Mihai Nita | d7d48fd | 2016-01-12 08:55:05 -0800 | [diff] [blame] | 49 | 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 Nita | 7f78a4b | 2016-02-05 11:55:45 -0800 | [diff] [blame] | 55 | // 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 Nita | d7d48fd | 2016-01-12 08:55:05 -0800 | [diff] [blame] | 60 | invalidate(); |
| 61 | requestLayout(); |
| 62 | } |
| 63 | |
| 64 | public void setShowCheckbox(boolean showCheckbox) { |
Mihai Nita | 7f78a4b | 2016-02-05 11:55:45 -0800 | [diff] [blame] | 65 | // "Opposite" visibility for label / checkbox |
Zoey Chen | e9f6efa | 2023-04-12 13:19:31 +0000 | [diff] [blame] | 66 | mCheckbox.setVisibility(showCheckbox ? VISIBLE : GONE); |
Mihai Nita | d7d48fd | 2016-01-12 08:55:05 -0800 | [diff] [blame] | 67 | 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 Nita | d86cba7 | 2016-04-19 09:20:20 -0700 | [diff] [blame] | 86 | public void setLabelAndDescription(String labelText, String description) { |
Mihai Nita | d7d48fd | 2016-01-12 08:55:05 -0800 | [diff] [blame] | 87 | mLabel.setText(labelText); |
Mihai Nita | d86cba7 | 2016-04-19 09:20:20 -0700 | [diff] [blame] | 88 | mLabel.setContentDescription(description); |
Mihai Nita | d7d48fd | 2016-01-12 08:55:05 -0800 | [diff] [blame] | 89 | invalidate(); |
| 90 | } |
| 91 | |
| 92 | public void setLocalized(boolean localized) { |
Mihai Nita | 7f78a4b | 2016-02-05 11:55:45 -0800 | [diff] [blame] | 93 | mLocalized.setVisibility(localized ? GONE : VISIBLE); |
Mihai Nita | d7d48fd | 2016-01-12 08:55:05 -0800 | [diff] [blame] | 94 | invalidate(); |
| 95 | } |
| 96 | |
tom hsu | f33ac49 | 2022-08-11 23:51:24 +0800 | [diff] [blame] | 97 | /** |
| 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 Nita | d7d48fd | 2016-01-12 08:55:05 -0800 | [diff] [blame] | 105 | public ImageView getDragHandle() { |
| 106 | return mDragHandle; |
| 107 | } |
| 108 | |
Zoey Chen | e9f6efa | 2023-04-12 13:19:31 +0000 | [diff] [blame] | 109 | public TextView getLabelView() { |
| 110 | return mLabel; |
| 111 | } |
| 112 | |
Mihai Nita | d7d48fd | 2016-01-12 08:55:05 -0800 | [diff] [blame] | 113 | public CheckBox getCheckbox() { |
| 114 | return mCheckbox; |
| 115 | } |
| 116 | } |