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; 23 import android.widget.RelativeLayout; 24 import android.widget.TextView; 25 26 import com.android.settings.R; 27 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. 32 private TextView mLabel; 33 private CheckBox mCheckbox; 34 private TextView mMiniLabel; 35 private TextView mLocalized; 36 private ImageView mDragHandle; 37 LocaleDragCell(Context context, AttributeSet attrs)38 public LocaleDragCell(Context context, AttributeSet attrs) { 39 super(context, attrs); 40 } 41 42 @Override onFinishInflate()43 protected void onFinishInflate() { 44 super.onFinishInflate(); 45 mLabel = (TextView) findViewById(R.id.label); 46 mLocalized = (TextView) findViewById(R.id.l10nWarn); 47 mMiniLabel = (TextView) findViewById(R.id.miniLabel); 48 mCheckbox = (CheckBox) findViewById(R.id.checkbox); 49 mDragHandle = (ImageView) findViewById(R.id.dragHandle); 50 } 51 setShowHandle(boolean showHandle)52 public void setShowHandle(boolean showHandle) { 53 // We want invisible, not gone, so that everything else stays the same. 54 // With GONE there is more space for the labels and the text wrapping change. 55 // So the transition between "normal" mode (with numbers) and 56 // "remove mode" (with checkboxes) is not that "smooth" 57 mDragHandle.setVisibility(showHandle ? VISIBLE : INVISIBLE); 58 invalidate(); 59 requestLayout(); 60 } 61 setShowCheckbox(boolean showCheckbox)62 public void setShowCheckbox(boolean showCheckbox) { 63 // "Opposite" visibility for label / checkbox 64 if (showCheckbox) { 65 mCheckbox.setVisibility(VISIBLE); 66 mLabel.setVisibility(INVISIBLE); 67 } else { 68 mCheckbox.setVisibility(INVISIBLE); 69 mLabel.setVisibility(VISIBLE); 70 } 71 invalidate(); 72 requestLayout(); 73 } 74 setChecked(boolean checked)75 public void setChecked(boolean checked) { 76 mCheckbox.setChecked(checked); 77 } 78 setShowMiniLabel(boolean showMiniLabel)79 public void setShowMiniLabel(boolean showMiniLabel) { 80 mMiniLabel.setVisibility(showMiniLabel ? VISIBLE : GONE); 81 invalidate(); 82 requestLayout(); 83 } 84 setMiniLabel(String miniLabelText)85 public void setMiniLabel(String miniLabelText) { 86 mMiniLabel.setText(miniLabelText); 87 invalidate(); 88 } 89 setLabelAndDescription(String labelText, String description)90 public void setLabelAndDescription(String labelText, String description) { 91 mLabel.setText(labelText); 92 mCheckbox.setText(labelText); 93 mLabel.setContentDescription(description); 94 mCheckbox.setContentDescription(description); 95 invalidate(); 96 } 97 setLocalized(boolean localized)98 public void setLocalized(boolean localized) { 99 mLocalized.setVisibility(localized ? GONE : VISIBLE); 100 invalidate(); 101 } 102 getDragHandle()103 public ImageView getDragHandle() { 104 return mDragHandle; 105 } 106 getCheckbox()107 public CheckBox getCheckbox() { 108 return mCheckbox; 109 } 110 } 111