Android Open Source - mobilib Mbl Image Folder Scanner






From Project

Back to project page mobilib.

License

The source code is released under:

MIT License

If you think the Android project mobilib 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.datdo.mobilib.imageinput;
/*  www.  j  ava2  s. c  o  m*/
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import android.os.Environment;
import android.util.Log;

import com.datdo.mobilib.util.MblUtils;


class MblImageFolderScanner {

    private static final String TAG = MblUtils.getTag(MblImageFolderScanner.class);

    public static String[] getAllImageFolders() {
        List<String> ret = new ArrayList<String>();
        List<String> mountPoints = getAllSdcardMountPoints();
        for (String mp : mountPoints) {
            for (String folder : MblImageInput.sFoldersToPickImages) {
                ret.add(mp + "/" + folder);
            }
        }
        return ret.toArray(new String[ret.size()]);
    }

    // reference this: http://stackoverflow.com/a/9315813
    // also reference this: https://source.android.com/devices/tech/storage/config.html
    private static List<String> getAllSdcardMountPoints() {

        List<String> ret = new ArrayList<String>();

        Scanner scanner = null;
        try {
            // add main sdcard which is always available
            ret.add(Environment.getExternalStorageDirectory().getCanonicalPath());

            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 mountPoint = lineElements[2];

                    // what for?
                    if (mountPoint.contains(":")) {
                        mountPoint = mountPoint.substring(0, mountPoint.indexOf(":"));
                    }

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


                    if (!isReadableFolderPath(mountPoint)) {
                        continue;
                    }

                    if (!ret.contains(mountPoint)) {
                        ret.add(mountPoint);
                    }
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "Failed to scan sdcards", e);
        } finally {
            if (scanner != null) {
                scanner.close();
            }
        }

        return ret;
    }

    private static boolean isReadableFolderPath(String path) {
        File folder = new File(path);
        return folder.exists() && folder.isDirectory() && folder.canRead();
    }
}




Java Source Code List

com.datdo.mobilib.api.DBBase.java
com.datdo.mobilib.api.DBHelper.java
com.datdo.mobilib.api.MblApi.java
com.datdo.mobilib.api.MblCache.java
com.datdo.mobilib.api.MblException.java
com.datdo.mobilib.api.MblSSLCertificateUtils.java
com.datdo.mobilib.base.MblActivityPlugin.java
com.datdo.mobilib.base.MblBaseActionBarActivity.java
com.datdo.mobilib.base.MblBaseActivity.java
com.datdo.mobilib.base.MblBaseAdapter.java
com.datdo.mobilib.base.MblBaseApplication.java
com.datdo.mobilib.base.MblBaseFragmentActivity.java
com.datdo.mobilib.base.MblDecorView.java
com.datdo.mobilib.base.MblNetworkStatusChangedReceiver.java
com.datdo.mobilib.event.MblCommonEvents.java
com.datdo.mobilib.event.MblEventCenter.java
com.datdo.mobilib.event.MblEventListener.java
com.datdo.mobilib.event.MblStrongEventListener.java
com.datdo.mobilib.event.MblWeakArrayList.java
com.datdo.mobilib.imageinput.MblAutoResizeSquareImageView.java
com.datdo.mobilib.imageinput.MblDataInputActivity.java
com.datdo.mobilib.imageinput.MblImageFolderScanner.java
com.datdo.mobilib.imageinput.MblImageInput.java
com.datdo.mobilib.imageinput.MblImagePickingScanEngine.java
com.datdo.mobilib.imageinput.MblPickImageActivity.java
com.datdo.mobilib.imageinput.MblPickImageGridViewAdapter.java
com.datdo.mobilib.imageinput.MblTakeImageActivity.java
com.datdo.mobilib.util.MblAsyncTask.java
com.datdo.mobilib.util.MblImageLoader.java
com.datdo.mobilib.util.MblLinkMovementMethod.java
com.datdo.mobilib.util.MblUrlRecognizer.java
com.datdo.mobilib.util.MblUtils.java
com.datdo.mobilib.widget.MblHorizontalViewPager.java
com.datdo.mobilib.widget.MblListViewWithScrollableItems.java
com.datdo.mobilib.widget.MblSequenceImage.java
com.datdo.mobilib.widget.MblSideMenuEnabledLayout.java
com.datdo.mobilib.widget.MblTouchImageView.java