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