Android Open Source - UltraExplorer Preference Activity






From Project

Back to project page UltraExplorer.

License

The source code is released under:

GNU General Public License

If you think the Android project UltraExplorer 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

/* 
 * Copyright (C) 2008 OpenIntents.org//from w w w . j  a v a2 s.  co m
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mirrorlabs.filebrowser;

import java.util.LinkedList;
import java.util.List;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceManager;
import android.widget.Toast;

public class PreferenceActivity extends android.preference.PreferenceActivity
                                implements OnSharedPreferenceChangeListener {

  public static final String PREFS_MEDIASCAN = "mediascan";
  /**
   * @since 2011-09-30
   */
  public static final String PREFS_SHOWALLWARNING = "showallwarning";
  
  
  public static final String PREFS_DISPLAYHIDDENFILES = "displayhiddenfiles";
  
  public static final String PREFS_CACHEFILES ="cachefiles";
   
  public static final String PREFS_SORTBY = "sortby";
  
  public static final String PREFS_ASCENDING = "ascending";
  
  public static final String PREFS_DEFAULTPICKFILEPATH = "defaultpickfilepath";
  
  private static final int DIALOG_DELETE_BOOKMARKS = 1;
  
  private Cursor deleteBookmarksCursor;
  private List<Uri> bookmarksToDelete = new LinkedList<Uri>();
  
  @Override
  protected void onCreate(Bundle icicle) {
    
    super.onCreate(icicle);

    addPreferencesFromResource(R.xml.app_preferences);
    
    Preference editBookmarks = findPreference("editbookmarks");
    editBookmarks.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference pref){
          showDialog(DIALOG_DELETE_BOOKMARKS);
            return false;
        }
    });
    
    /* Register the onSharedPreferenceChanged listener to update the SortBy ListPreference summary */
    getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
    /* Set the onSharedPreferenceChanged listener summary to its initial value */
    changeListPreferenceSummaryToCurrentValue((ListPreference)findPreference("sortby"));
  }

  @Override
  protected void onResume() {
    super.onResume();
  }

  static boolean getMediaScanFromPreference(Context context) {
    return PreferenceManager.getDefaultSharedPreferences(context)
          .getBoolean(PREFS_MEDIASCAN, false);
  }

  /**
   * @since 2011-09-30
   */
  static void setShowAllWarning(Context context, boolean enabled) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = settings.edit();
    editor.putBoolean(PREFS_SHOWALLWARNING, enabled);
    editor.commit();
  }

  /**
   * @since 2011-09-30
   */
  static boolean getShowAllWarning(Context context) {
    return PreferenceManager.getDefaultSharedPreferences(context)
        .getBoolean(PREFS_SHOWALLWARNING, true);
  }
  

  
  static void setDisplayHiddenFiles(Context context, boolean enabled) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = settings.edit();
    editor.putBoolean(PREFS_DISPLAYHIDDENFILES, enabled);
    editor.commit();
  }


  static boolean getDisplayHiddenFiles(Context context) {
    return PreferenceManager.getDefaultSharedPreferences(context)
        .getBoolean(PREFS_DISPLAYHIDDENFILES, true);
  }
  
  static void CacheFiles(Context context, boolean enabled) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = settings.edit();
    editor.putBoolean(PREFS_CACHEFILES, enabled);
    editor.commit();
  }


  static boolean CacheFiles(Context context) {
    return PreferenceManager.getDefaultSharedPreferences(context)
        .getBoolean(PREFS_CACHEFILES, true);
  }
  
  static void setDefaultPickFilePath(Context context, String path) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = settings.edit();
    editor.putString(PREFS_DEFAULTPICKFILEPATH, path);
    editor.commit();
  }


  static String getDefaultPickFilePath(Context context) {
    return PreferenceManager.getDefaultSharedPreferences(context)
        .getString(PREFS_DEFAULTPICKFILEPATH, null);
  }
  
  
  
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if(key.equals("sortby")){
      changeListPreferenceSummaryToCurrentValue((ListPreference)findPreference(key));
    }
  }
  
  private void changeListPreferenceSummaryToCurrentValue(ListPreference listPref){
    listPref.setSummary(listPref.getEntry());
  }
  

  static int getSortBy(Context context) {
    /* entryValues must be a string-array while we need integers */
    return Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context)
                 .getString(PREFS_SORTBY, "1"));
  }
  
  static boolean getAscending(Context context) {
    return PreferenceManager.getDefaultSharedPreferences(context)
        .getBoolean(PREFS_ASCENDING, true);
  }
  
  @Override
  protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_DELETE_BOOKMARKS:
      deleteBookmarksCursor = getBookmarksCursor();
      AlertDialog dialog = 
        new AlertDialog.Builder(this)
          .setTitle(R.string.bookmarks_select_to_delete)
              .setMultiChoiceItems(deleteBookmarksCursor,
                BookmarksProvider.CHECKED, BookmarksProvider.NAME,
                new DialogInterface.OnMultiChoiceClickListener() {
                    public void onClick(DialogInterface dialog, int item, boolean checked) {
                      if (deleteBookmarksCursor.moveToPosition(item)) {
                        Uri deleteUri = ContentUris.withAppendedId(
                                  BookmarksProvider.CONTENT_URI,
                                  deleteBookmarksCursor.getInt(
                                    deleteBookmarksCursor.getColumnIndex(
                                      BookmarksProvider._ID)));
                        if(checked)
                          bookmarksToDelete.add(deleteUri);
                        else
                          bookmarksToDelete.remove(deleteUri);
                        

                        ((AlertDialog)dialog).getButton(AlertDialog.BUTTON_POSITIVE)
                      .setEnabled((bookmarksToDelete.size() > 0) ? true : false);
                          
                        ContentValues checkedValues = new ContentValues();
                        checkedValues.put(BookmarksProvider.CHECKED, checked ? 1 : 0);
                        getContentResolver().update(deleteUri, checkedValues, null, null);
                        //Have to use the deprecated requery()
                        //(see http://code.google.com/p/android/issues/detail?id=2998)
                        deleteBookmarksCursor.requery();
                      }
                      ((AlertDialog)dialog).getListView().invalidate();
                    }
              })
              .setPositiveButton(R.string.bookmarks_delete, new DialogInterface.OnClickListener() {
            
            
            public void onClick(DialogInterface dialog, int which) {
              for(Uri uri : bookmarksToDelete){
                      getContentResolver().delete(uri, null, null);
              }
                    Toast.makeText(PreferenceActivity.this,
                        R.string.bookmarks_deleted, Toast.LENGTH_SHORT).show();
                  restartBookmarksChecked();
            }
          })
              .setNegativeButton(R.string.bookmarks_cancel, new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int item) {
                    restartBookmarksChecked();
                  }
              }).create();
      // TODO: need to fix
      /*  Commenting this out for now.  Need another way to do this or check for SDK > 7.
       *  With this in, Android 1.5 crashes upon launch.
      dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
          ((AlertDialog)dialog).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
        }
      });*/
      return dialog;
    }
    return super.onCreateDialog(id);
  }
  
  private void restartBookmarksChecked(){
    ContentValues checkedValues = new ContentValues();
    checkedValues.put(BookmarksProvider.CHECKED, 0);
      getContentResolver().update(BookmarksProvider.CONTENT_URI, checkedValues, null, null);
      deleteBookmarksCursor.requery();
      bookmarksToDelete.clear();
  }
  
  private Cursor getBookmarksCursor(){
    return managedQuery(BookmarksProvider.CONTENT_URI,
        new String[] {
          BookmarksProvider._ID,
          BookmarksProvider.NAME,
          BookmarksProvider.PATH,
          BookmarksProvider.CHECKED
        }, null, null, null);
  }
}




Java Source Code List

com.android.gestures.CreateGestureActivity.java
com.android.gestures.GestureBuilderActivity.java
com.android.gestures.GestureMonitorActivity.java
com.markupartist.android.widget.ActionBar.java
com.markupartist.android.widget.ScrollingTextView.java
com.mirrorlabs.customcheckboxwidget.DontPressWithParentCheckBox.java
com.mirrorlabs.customtoast.Toaster.java
com.mirrorlabs.filebrowser.BackupManager.java
com.mirrorlabs.filebrowser.BaseActivity.java
com.mirrorlabs.filebrowser.BitmapManager.java
com.mirrorlabs.filebrowser.BookmarksProvider.java
com.mirrorlabs.filebrowser.CMDProcessor.java
com.mirrorlabs.filebrowser.CompressManager.java
com.mirrorlabs.filebrowser.DesEncrypter.java
com.mirrorlabs.filebrowser.DrawableManager.java
com.mirrorlabs.filebrowser.DrawableThreadLoader.java
com.mirrorlabs.filebrowser.DuplicatesManager.java
com.mirrorlabs.filebrowser.ExtractManager.java
com.mirrorlabs.filebrowser.FileUtils.java
com.mirrorlabs.filebrowser.FilebrowserULTRAActivity.java
com.mirrorlabs.filebrowser.ImageThreadLoader.java
com.mirrorlabs.filebrowser.LinuxShell.java
com.mirrorlabs.filebrowser.MimeTypes.java
com.mirrorlabs.filebrowser.MyApplication.java
com.mirrorlabs.filebrowser.PDFViewer.java
com.mirrorlabs.filebrowser.PreferenceActivity.java
com.mirrorlabs.filebrowser.ProcessManager.java
com.mirrorlabs.filebrowser.RootUtils.java
com.mirrorlabs.filebrowser.SearchFilesDialog.java
com.mirrorlabs.filebrowser.SearchFilesWidget.java
com.mirrorlabs.filebrowser.UltraBaseAdapter.java
com.mirrorlabs.imageviewer.EclairMotionEvent.java
com.mirrorlabs.imageviewer.ExpandImage.java
com.mirrorlabs.imageviewer.TouchImageView.java
com.mirrorlabs.imageviewer.WrapMotionEvent.java
com.mirrorlabs.menupopup.MenuItem.java
com.mirrorlabs.menupopup.PopupMenu.java
com.mirrorlabs.musicplayer.DBHelper.java
com.mirrorlabs.musicplayer.PlayerActivity.java
com.mirrorlabs.quickaction3D.ActionItem.java
com.mirrorlabs.quickaction3D.PopupWindows.java
com.mirrorlabs.quickaction3D.QuickAction.java
com.mirrorlabs.quickaction.ActionItem.java
com.mirrorlabs.quickaction.PopupWindows.java
com.mirrorlabs.quickaction.QuickAction.java
com.mirrorlabs.ui.widgets.ClickableSlidingDrawer.java
com.mirrorlabs.ui.widgets.DropDownMenu.java
com.mirrorlabs.ui.widgets.IcsListPopupWindow.java
com.mirrorlabs.ui.widgets.JavaYoutubeDownloader.java
com.mirrorlabs.ui.widgets.Panel.java
com.mirrorlabs.ui.widgets.ScrollPager.java
com.mirrorlabs.ui.widgets.SlidingFrameLayout.java
com.mirrorlabs.widgets.ExampleAppWidgetProvider1.java
com.mirrorlabs.widgets.ExampleAppWidgetProvider.java
com.mirrorlabs.widgets.UpdateWidgetService1.java
com.mirrorlabs.widgets.UpdateWidgetService.java
org.zeroxlab.widget.AnimationLayout.java
org.zeroxlab.widget.MyHorizontalScrollView.java