Android Open Source - Text-Edit-for-Android Default Dir Preference






From Project

Back to project page Text-Edit-for-Android.

License

The source code is released under:

GNU General Public License

If you think the Android project Text-Edit-for-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.paulmach.textedit;
//from w  w w  .  ja  va 2 s  . co m
import java.io.File;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.util.AttributeSet;

/* DefaultDirPreference
 *     Special to show and browser for the default directory
 */
public class DefaultDirPreference extends Preference
{
  private final static int REQUEST_FILE_BROWSER = 1;
  
  // This is the constructor called by the inflater
  public DefaultDirPreference(Context context, AttributeSet attrs) {
    super(context, attrs);

    // define what happens when we click the preference
    setOnPreferenceClickListener(new Preference.OnPreferenceClickListener()
    {
      public boolean onPreferenceClick(Preference arg0)
      {
        // figure out what is currently selected
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
        String current = sharedPref.getString("defaultdir", "/sdcard/");
  
        // figure out what to display. should just be the directory
        String location = "/sdcard/";
        
        File f = new File(current);
        if (f.toString().equals("/"))
          location = "/";
        else if (f.isDirectory())
          location = f.toString() + "/";  
        else if (f.getParent().toString().equals("/"))
          location = "/";
        else
          location = f.getParent() + "/";
        
        if (f != null)
          location = f.toString();

        // start the intent
        Intent intent = new Intent(getContext(), FileBrowser.class);
        intent.setAction(location);
        ((Activity) getContext()).startActivityForResult(intent, REQUEST_FILE_BROWSER);
        
        return false;
      }
    });
    
    // so the summary says the current
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
    String current = sharedPref.getString("defaultdir", "/sdcard/");
    
    this.setSummary(current);
  }
} // end class DefaultDirPreference





Java Source Code List

org.paulmach.textedit.ClearRecentFileListPreference.java
org.paulmach.textedit.ClearSearchSuggestions.java
org.paulmach.textedit.ColorPreference.java
org.paulmach.textedit.DefaultDirPreference.java
org.paulmach.textedit.EditPreferences.java
org.paulmach.textedit.FileAutoCompleteArrayAdapter.java
org.paulmach.textedit.FileBrowser.java
org.paulmach.textedit.FileViewArrayAdapter.java
org.paulmach.textedit.FontSizePreference.java
org.paulmach.textedit.FontTypePreference.java
org.paulmach.textedit.SearchSuggestions.java
org.paulmach.textedit.WarrantyPreference.java
org.paulmach.textedit.pmTextEdit.java