1 /* 2 * Copyright (C) 2014 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.app.Activity; 20 import android.app.Fragment; 21 import android.os.Bundle; 22 import android.os.Parcelable; 23 import android.text.format.Formatter; 24 import android.view.LayoutInflater; 25 import android.view.View; 26 import android.view.ViewGroup; 27 import android.widget.ImageView; 28 import android.widget.TextView; 29 30 import com.android.tv.settings.dialog.old.BaseContentFragment; 31 import com.android.tv.settings.dialog.old.ContentFragment; 32 import com.android.tv.settings.R; 33 34 import java.util.ArrayList; 35 import java.util.Collections; 36 import java.util.List; 37 38 /** 39 * Fragment that shows storage info. 40 */ 41 public class StorageContentFragment extends ContentFragment { 42 private View mView; 43 44 public static StorageContentFragment newInstance(String title, 45 String breadcrumb, String description, int iconResourceId, int iconBackgroundColor) { 46 StorageContentFragment fragment = new StorageContentFragment(); 47 fragment.setArguments(BaseContentFragment.buildArgs(title, breadcrumb, description, 48 iconResourceId, iconBackgroundColor)); 49 return fragment; 50 } 51 52 @Override 53 public View onCreateView( 54 LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 55 return (mView = super.onCreateView(inflater, container, savedInstanceState)); 56 } 57 58 public void updateEntries(ArrayList<PercentageBarChart.Entry> entries) { 59 setIcon(buildPercentageBarChart(entries)); 60 } 61 62 private PercentageBarChart buildPercentageBarChart(ArrayList<PercentageBarChart.Entry> entries) 63 { 64 return new PercentageBarChart(entries, 65 getColor(R.color.storage_avail), getPixelSize(R.dimen.storage_bar_min_tick_width), 66 getPixelSize(R.dimen.content_fragment_icon_width), 67 getPixelSize(R.dimen.content_fragment_icon_width), mView.isLayoutRtl()); 68 } 69 70 private int getColor(int resource) { 71 return getActivity().getResources().getColor(resource); 72 } 73 74 private int getPixelSize(int resource) { 75 return getActivity().getResources().getDimensionPixelSize(resource); 76 } 77 } 78