Home | History | Annotate | Download | only in deviceinfo
      1 // Copyright 2011 Google Inc. All Rights Reserved.
      2 
      3 package com.android.settings.deviceinfo;
      4 
      5 import com.android.settings.R;
      6 
      7 import android.content.Context;
      8 import android.os.Environment;
      9 import android.util.AttributeSet;
     10 import android.view.ViewDebug;
     11 import android.widget.CheckBox;
     12 import android.widget.Checkable;
     13 import android.widget.RelativeLayout;
     14 import android.widget.TextView;
     15 
     16 /**
     17  * Handles display of a single row entry on Settings --> Storage --> Misc Files screen
     18  */
     19 public class FileItemInfoLayout extends RelativeLayout implements Checkable {
     20     private TextView mFileNameView;
     21     private TextView mFileSizeView;
     22     private CheckBox mCheckbox;
     23     private static final int mLengthExternalStorageDirPrefix =
     24             Environment.getExternalStorageDirectory().getAbsolutePath().length() + 1;
     25 
     26     public FileItemInfoLayout(Context context) {
     27         this(context, null);
     28     }
     29 
     30     public FileItemInfoLayout(Context context, AttributeSet attrs) {
     31         this(context, attrs, 0);
     32     }
     33 
     34     public FileItemInfoLayout(Context context, AttributeSet attrs, int defStyle) {
     35         super(context, attrs, defStyle);
     36     }
     37 
     38     public void toggle() {
     39         setChecked(!mCheckbox.isChecked());
     40     }
     41 
     42     /* (non-Javadoc)
     43      * @see android.view.View#onFinishInflate()
     44      */
     45     @Override
     46     protected void onFinishInflate() {
     47         super.onFinishInflate();
     48         mFileNameView = (TextView) findViewById(R.id.misc_filename);
     49         mFileSizeView = (TextView) findViewById(R.id.misc_filesize);
     50         mCheckbox = (CheckBox) findViewById(R.id.misc_checkbox);
     51     }
     52 
     53     public void setFileName(String fileName) {
     54         mFileNameView.setText(fileName.substring(mLengthExternalStorageDirPrefix));
     55     }
     56 
     57     public void setFileSize(String filesize) {
     58         mFileSizeView.setText(filesize);
     59     }
     60 
     61     @ViewDebug.ExportedProperty
     62     public boolean isChecked() {
     63         return mCheckbox.isChecked();
     64     }
     65 
     66     public CheckBox getCheckBox() {
     67         return mCheckbox;
     68     }
     69 
     70     /**
     71      * <p>Changes the checked state of this text view.</p>
     72      *
     73      * @param checked true to check the text, false to uncheck it
     74      */
     75     public void setChecked(boolean checked) {
     76         mCheckbox.setChecked(checked);
     77     }
     78 }