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.storagemanager.deletionhelper; 18 19 import android.content.Context; 20 import android.support.v7.preference.CheckBoxPreference; 21 import android.support.v7.preference.PreferenceViewHolder; 22 import android.text.format.Formatter; 23 import android.view.View; 24 import android.widget.CheckBox; 25 import android.widget.TextView; 26 import com.android.storagemanager.R; 27 28 /** 29 * NestedCheckboxPreference is a CheckBoxPreference which is nested in to align with a {@link 30 * CollapsibleCheckboxPreferenceGroup}. 31 */ 32 public class NestedDeletionPreference extends CheckBoxPreference { 33 private TextView mSize; 34 private long mAppSize; 35 NestedDeletionPreference(Context context)36 public NestedDeletionPreference(Context context) { 37 super(context); 38 setLayoutResource(com.android.storagemanager.R.layout.preference_nested); 39 setWidgetLayoutResource(com.android.storagemanager.R.layout.preference_widget_checkbox); 40 } 41 42 @Override onClick()43 protected void onClick() { 44 super.onClick(); 45 mSize.setActivated(isChecked()); 46 } 47 48 @Override onBindViewHolder(PreferenceViewHolder holder)49 public void onBindViewHolder(PreferenceViewHolder holder) { 50 super.onBindViewHolder(holder); 51 CheckBox checkboxWidget = 52 (CheckBox) holder.findViewById(com.android.internal.R.id.checkbox); 53 checkboxWidget.setVisibility(View.VISIBLE); 54 mSize = (TextView) holder.findViewById(R.id.deletion_type_size); 55 mSize.setActivated(checkboxWidget.isChecked()); 56 mSize.setText(getItemSize()); 57 } 58 setItemSize(long itemSize)59 void setItemSize(long itemSize) { 60 mAppSize = itemSize; 61 } 62 getItemSize()63 public String getItemSize() { 64 return Formatter.formatFileSize(getContext(), mAppSize); 65 } 66 67 } 68