2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com.android.settings;
18 import android.content.Context;
19 import android.util.AttributeSet;
20 import android.util.TypedValue;
21 import android.view.View;
22 import android.widget.Checkable;
23 import android.widget.LinearLayout;
25 public class CheckableLinearLayout extends LinearLayout implements Checkable {
27 private boolean mChecked;
28 private float mDisabledAlpha;
30 public CheckableLinearLayout(Context context, AttributeSet attrs) {
31 super(context, attrs);
32 TypedValue alpha = new TypedValue();
33 context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, alpha, true);
34 mDisabledAlpha = alpha.getFloat();
38 public void setEnabled(boolean enabled) {
39 super.setEnabled(enabled);
40 final int N = getChildCount();
41 for (int i = 0; i < N; i++) {
42 getChildAt(i).setAlpha(enabled ? 1 : mDisabledAlpha);
47 public void setChecked(boolean checked) {
53 public boolean isChecked() {
58 public void toggle() {
59 setChecked(!mChecked);
62 private void updateChecked() {
63 final int N = getChildCount();
64 for (int i = 0; i < N; i++) {
65 View child = getChildAt(i);
66 if (child instanceof Checkable) {
67 ((Checkable) child).setChecked(mChecked);