Android Open Source - android_Findex Storage Options






From Project

Back to project page android_Findex.

License

The source code is released under:

Apache License

If you think the Android project android_Findex 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 com.lithidsw.findex.utils;
/* ww w .j a  v a2  s. c  o m*/
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Environment;

import com.lithidsw.findex.R;

import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;

@SuppressLint("NewApi")
public class StorageOptions {
    public static String[] labels;
    public static String[] paths;
    public static int count = 0;

    private static Context sContext;
    private static ArrayList<String> sVold = new ArrayList<String>();

    public static void determineStorageOptions(Context context) {
        sContext = context.getApplicationContext();
        readVoldFile();
        testAndCleanList();
        setProperties();
    }

    private static void readVoldFile() {
    /*
     * Scan the /system/etc/vold.fstab file and look for lines like this:
     * dev_mount sdcard /mnt/sdcard 1
     * /devices/platform/s3c-sdhci.0/mmc_host/mmc0
     *
     * When one is found, split it into its elements and then pull out the
     * path to the that mount point and add it to the arraylist
     *
     * some devices are missing the vold file entirely so we add a path here
     * to make sure the list always includes the path to the first sdcard,
     * whether real or emulated.
     */

        try {
            Scanner scanner = new Scanner(new File("/system/etc/vold.fstab"));
            while (scanner.hasNext()) {
                String line = scanner.nextLine();
                if (line.startsWith("dev_mount")) {
                    String[] lineElements = line.split(" ");
                    String element = lineElements[2];

                    if (element.contains(":")) {
                        element = element.substring(0, element.indexOf(":"));
                    }

                    if (element.contains("usb")) {
                        continue;
                    }

                    if (!sVold.contains(element)) {
                        sVold.add(element);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void testAndCleanList() {
    /*
     * Now that we have a cleaned list of mount paths, test each one to make
     * sure it's a valid and available path. If it is not, remove it from
     * the list.
     */

        for (int i = 0; i < sVold.size(); i++) {
            String voldPath = sVold.get(i);
            File path = new File(voldPath);
            if (!path.exists() || !path.isDirectory() || !path.canWrite())
                sVold.remove(i--);
        }

        if (sVold.size() == 0) {
            sVold.add("/mnt/sdcard");
        }
    }

    private static void setProperties() {
    /*
     * At this point all the paths in the list should be valid. Build the
     * public properties.
     */

        ArrayList<String> labelList = new ArrayList<String>();

        int j = 0;
        if (sVold.size() > 0) {
            if (!Environment.isExternalStorageRemovable() || Environment.isExternalStorageEmulated()) {
                labelList.add(sContext.getString(R.string.text_internal_storage));
            } else {
                labelList.add(sContext.getString(R.string.text_external_storage) + " 1");
                j = 1;
            }

            if (sVold.size() > 1) {
                for (int i = 1; i < sVold.size(); i++) {
                    labelList.add(sContext.getString(R.string.text_external_storage)
                            + " " + (i + j));
                }
            }
        }

        labels = new String[labelList.size()];
        labelList.toArray(labels);
        paths = new String[sVold.size()];
        sVold.toArray(paths);
        count = Math.min(labels.length, paths.length);
        sVold.clear();
    }
}




Java Source Code List

com.lithidsw.findex.AddTagActivity.java
com.lithidsw.findex.FileInfoActivity.java
com.lithidsw.findex.IntroActivity.java
com.lithidsw.findex.IntroFragment.java
com.lithidsw.findex.MainActivity.java
com.lithidsw.findex.MainFragment.java
com.lithidsw.findex.SettingsActivity.java
com.lithidsw.findex.adapter.DrawerListAdapter.java
com.lithidsw.findex.adapter.FilePageAdapter.java
com.lithidsw.findex.adapter.InfoTagListAdapter.java
com.lithidsw.findex.adapter.StorageListAdapter.java
com.lithidsw.findex.adapter.WidgetListAdapter.java
com.lithidsw.findex.db.DBHelper.java
com.lithidsw.findex.db.DBUtils.java
com.lithidsw.findex.ef.DirectoryAdapter.java
com.lithidsw.findex.ef.DirectoryListActivity.java
com.lithidsw.findex.ef.DirectoryManager.java
com.lithidsw.findex.info.DirPickerInfo.java
com.lithidsw.findex.info.FileInfo.java
com.lithidsw.findex.loader.ImageLoader.java
com.lithidsw.findex.loader.MemoryCache.java
com.lithidsw.findex.receiver.ActionReceiver.java
com.lithidsw.findex.service.IndexService.java
com.lithidsw.findex.utils.C.java
com.lithidsw.findex.utils.DateBuilder.java
com.lithidsw.findex.utils.FileStartActivity.java
com.lithidsw.findex.utils.FileUtils.java
com.lithidsw.findex.utils.FileWalker.java
com.lithidsw.findex.utils.ItemCountLoader.java
com.lithidsw.findex.utils.MrToast.java
com.lithidsw.findex.utils.StorageOptions.java
com.lithidsw.findex.widget.WidgetConfigActivity.java
com.lithidsw.findex.widget.WidgetInfo.java
com.lithidsw.findex.widget.WidgetLoadStub.java
com.lithidsw.findex.widget.WidgetProvider.java
com.lithidsw.findex.widget.WidgetService.java
com.lithidsw.findex.widget.WidgetUtils.java
com.lithidsw.findex.widget.WidgetViews.java