Android Open Source - LyricHere Util






From Project

Back to project page LyricHere.

License

The source code is released under:

Apache License

If you think the Android project LyricHere 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 cn.zhaiyifan.lyrichere.utils;
/*  ww w  . ja v  a  2s  .co m*/
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import android.webkit.MimeTypeMap;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

import cn.zhaiyifan.lyrichere.Constants;

public final class Util {

    public static final int PASTE_MODE_COPY = 0;
    public static final int PASTE_MODE_MOVE = 1;
    private static final String TAG = Util.class.getName();
    private static File COPIED_FILE = null;
    private static int pasteMode = 1;

    private Util() {
    }

    public static void log(String tag, String msg) {
        if (Constants.DEBUG_ON) {
            Log.d(tag, msg);
        }
    }

    public static synchronized void setPasteSrcFile(File f, int mode) {
        COPIED_FILE = f;
        pasteMode = mode % 2;
    }

    public static synchronized File getFileToPaste() {
        return COPIED_FILE;
    }

    public static synchronized int getPasteMode() {
        return pasteMode;
    }

    static boolean isMusic(File file) {

        Uri uri = Uri.fromFile(file);
        String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(uri.toString()));

        if (type == null)
            return false;
        else
            return (type.toLowerCase().startsWith("audio/"));

    }

    static boolean isVideo(File file) {

        Uri uri = Uri.fromFile(file);
        String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(uri.toString()));

        if (type == null)
            return false;
        else
            return (type.toLowerCase().startsWith("video/"));
    }

    public static boolean isPicture(File file) {

        Uri uri = Uri.fromFile(file);
        String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(uri.toString()));

        if (type == null)
            return false;
        else
            return (type.toLowerCase().startsWith("image/"));
    }

    public static boolean isProtected(File path) {
        return (!path.canRead() && !path.canWrite());
    }

    public static boolean isUnzippable(File path) {
        return (path.isFile() && path.canRead() && path.getName().endsWith(".zip"));
    }


    public static boolean isRoot(File dir) {

        return dir.getAbsolutePath().equals("/");
    }


    public static boolean isSdCard(File file) {

        try {
            return (file.getCanonicalPath().equals(Environment.getExternalStorageDirectory().getCanonicalPath()));
        } catch (IOException e) {
            return false;
        }
    }

    public static Map<String, Long> getDirSizes(File dir) {
        Map<String, Long> sizes = new HashMap<String, Long>();

        try {

            Process du = Runtime.getRuntime().exec("/system/bin/du -b -d1 " + dir.getCanonicalPath(), new String[]{}, Environment.getRootDirectory());

            BufferedReader in = new BufferedReader(new InputStreamReader(
                    du.getInputStream()));
            String line = null;
            while ((line = in.readLine()) != null) {
                String[] parts = line.split("\\s+");

                String sizeStr = parts[0];
                Long size = Long.parseLong(sizeStr);

                String path = parts[1];

                sizes.put(path, size);
            }

        } catch (IOException e) {
            Log.w(TAG, "Could not execute DU command for " + dir.getAbsolutePath(), e);
        }

        return sizes;

    }

    public static File getDownloadsFolder() {
        return new File("/sdcard/" + Environment.DIRECTORY_DOWNLOADS);
    }

    public static File getDcimFolder() {
        return new File("/sdcard/" + Environment.DIRECTORY_DCIM);
    }
}




Java Source Code List

cn.zhaiyifan.lyrichere.ApplicationTest.java
cn.zhaiyifan.lyrichere.Constants.java
cn.zhaiyifan.lyrichere.MusicBroadcastReceiver.java
cn.zhaiyifan.lyrichere.adapters.LyricCursorAdapter.java
cn.zhaiyifan.lyrichere.db.DbHelper.java
cn.zhaiyifan.lyrichere.db.LyricContentProvider.java
cn.zhaiyifan.lyrichere.model.Lyric.java
cn.zhaiyifan.lyrichere.prefs.SettingsActivity.java
cn.zhaiyifan.lyrichere.prefs.SettingsFragment.java
cn.zhaiyifan.lyrichere.prefs.colorpicker.AlphaPatternDrawable.java
cn.zhaiyifan.lyrichere.prefs.colorpicker.ColorPickerDialog.java
cn.zhaiyifan.lyrichere.prefs.colorpicker.ColorPickerPanelView.java
cn.zhaiyifan.lyrichere.prefs.colorpicker.ColorPickerPreference.java
cn.zhaiyifan.lyrichere.prefs.colorpicker.ColorPickerView.java
cn.zhaiyifan.lyrichere.prefs.colorpicker.Test.java
cn.zhaiyifan.lyrichere.ui.AboutActivity.java
cn.zhaiyifan.lyrichere.ui.DownloadFragment.java
cn.zhaiyifan.lyrichere.ui.ListScrollTextView.java
cn.zhaiyifan.lyrichere.ui.LyricExplorerActivity.java
cn.zhaiyifan.lyrichere.ui.LyricExplorerFragment.java
cn.zhaiyifan.lyrichere.ui.LyricPlayerActivity.java
cn.zhaiyifan.lyrichere.ui.LyricPlayerFragment.java
cn.zhaiyifan.lyrichere.ui.LyricSearchView.java
cn.zhaiyifan.lyrichere.ui.LyricView.java
cn.zhaiyifan.lyrichere.utils.DbUtils.java
cn.zhaiyifan.lyrichere.utils.FileUtils.java
cn.zhaiyifan.lyrichere.utils.LyricCache.java
cn.zhaiyifan.lyrichere.utils.LyricProvider.java
cn.zhaiyifan.lyrichere.utils.LyricUtils.java
cn.zhaiyifan.lyrichere.utils.Util.java
cn.zhaiyifan.lyrichere.workers.Finder.java
cn.zhaiyifan.lyrichere.workers.LyricEncodingUpdater.java
cn.zhaiyifan.lyrichere.workers.LyricLastVisitUpdater.java
cn.zhaiyifan.lyrichere.workers.LyricOpener.java