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 TextView mCurrentDefault; 37 private ImageView mDragHandle; 38 LocaleDragCell(Context context, AttributeSet attrs)39 public LocaleDragCell(Context context, AttributeSet attrs) { 40 super(context, attrs); 41 } 42 43 @Override onFinishInflate()44 protected void onFinishInflate() { 45 super.onFinishInflate(); 46 mLabel = (TextView) findViewById(R.id.label); 47 mLocalized = (TextView) findViewById(R.id.l10nWarn); 48 mCurrentDefault = (TextView) findViewById(R.id.default_locale); 49 mMiniLabel = (TextView) findViewById(R.id.miniLabel); 50 mCheckbox = (CheckBox) findViewById(R.id.checkbox); 51 mDragHandle = (ImageView) findViewById(R.id.dragHandle); 52 } 53 setShowHandle(boolean showHandle)54 public void setShowHandle(boolean showHandle) { 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); 60 invalidate(); 61 requestLayout(); 62 } 63 setShowCheckbox(boolean showCheckbox)64 public void setShowCheckbox(boolean showCheckbox) { 65 // "Opposite" visibility for label / checkbox 66 mCheckbox.setVisibility(showCheckbox ? VISIBLE : GONE); 67 invalidate(); 68 requestLayout(); 69 } 70 setChecked(boolean checked)71 public void setChecked(boolean checked) { 72 mCheckbox.setChecked(checked); 73 } 74 setShowMiniLabel(boolean showMiniLabel)75 public void setShowMiniLabel(boolean showMiniLabel) { 76 mMiniLabel.setVisibility(showMiniLabel ? VISIBLE : GONE); 77 invalidate(); 78 requestLayout(); 79 } 80 setMiniLabel(String miniLabelText)81 public void setMiniLabel(String miniLabelText) { 82 mMiniLabel.setText(miniLabelText); 83 invalidate(); 84 } 85 setLabelAndDescription(String labelText, String description)86 public void setLabelAndDescription(String labelText, String description) { 87 mLabel.setText(labelText); 88 mLabel.setContentDescription(description); 89 invalidate(); 90 } 91 setLocalized(boolean localized)92 public void setLocalized(boolean localized) { 93 mLocalized.setVisibility(localized ? GONE : VISIBLE); 94 invalidate(); 95 } 96 97 /** 98 * Indicate current locale is system default. 99 */ setCurrentDefault(boolean isCurrentDefault)100 public void setCurrentDefault(boolean isCurrentDefault) { 101 mCurrentDefault.setVisibility(isCurrentDefault ? VISIBLE : GONE); 102 invalidate(); 103 } 104 getDragHandle()105 public ImageView getDragHandle() { 106 return mDragHandle; 107 } 108 getLabelView()109 public TextView getLabelView() { 110 return mLabel; 111 } 112 getCheckbox()113 public CheckBox getCheckbox() { 114 return mCheckbox; 115 } 116 } 117