1 /* 2 * Copyright (C) 2015 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.tv.settings.device.storage; 18 19 import android.content.Context; 20 import android.support.annotation.Keep; 21 import android.support.v7.preference.Preference; 22 import android.text.format.Formatter; 23 import android.util.AttributeSet; 24 25 import com.android.tv.settings.R; 26 import com.android.tv.settings.device.StorageResetFragment; 27 28 public class StoragePreference extends Preference { 29 30 private static final long SIZE_CALCULATING = -1; 31 StoragePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)32 public StoragePreference(Context context, AttributeSet attrs, 33 int defStyleAttr, int defStyleRes) { 34 super(context, attrs, defStyleAttr, defStyleRes); 35 setSize(SIZE_CALCULATING); 36 } 37 StoragePreference(Context context, AttributeSet attrs, int defStyleAttr)38 public StoragePreference(Context context, AttributeSet attrs, 39 int defStyleAttr) { 40 super(context, attrs, defStyleAttr); 41 setSize(SIZE_CALCULATING); 42 } 43 StoragePreference(Context context, AttributeSet attrs)44 public StoragePreference(Context context, AttributeSet attrs) { 45 super(context, attrs); 46 setSize(SIZE_CALCULATING); 47 } 48 StoragePreference(Context context)49 public StoragePreference(Context context) { 50 super(context); 51 setSize(SIZE_CALCULATING); 52 } 53 setSize(long size)54 public void setSize(long size) { 55 setSummary(formatSize(getContext(), size)); 56 } 57 formatSize(Context context, long size)58 public static String formatSize(Context context, long size) { 59 return (size == SIZE_CALCULATING) 60 ? context.getString(R.string.storage_calculating_size) 61 : Formatter.formatShortFileSize(context, size); 62 } 63 } 64