Search in sources :

Example 21 with SuppressLint

use of android.annotation.SuppressLint in project SimplifyReader by chentao0707.

the class SDCardManager method getExternalStorageDirectory.

/**
	 * 获得外部存储路径
	 * 
	 * @return /mnt/sdcard或者/storage/extSdCard等多种名称
	 */
@SuppressLint("NewApi")
public static ArrayList<SDCardInfo> getExternalStorageDirectory() {
    ArrayList<SDCardInfo> list = new ArrayList<SDCardInfo>();
    if (UIUtils.hasKitKat()) {
        // OS 4.4 以上读取外置 SD 卡
        final File[] externalFiles = YoukuPlayerApplication.context.getExternalFilesDirs(null);
        if (null != externalFiles) {
            SDCardInfo info = new SDCardInfo();
            info.path = getDefauleSDCardPath();
            info.isExternal = false;
            list.add(info);
            if (externalFiles.length > 1 && (null != externalFiles[1])) {
                SDCardInfo externalInfo = new SDCardInfo();
                externalInfo.path = externalFiles[1].getAbsolutePath();
                externalInfo.isExternal = true;
                list.add(externalInfo);
            }
        }
        return list;
    } else {
        Runtime runtime = Runtime.getRuntime();
        Process proc;
        try {
            proc = runtime.exec("mount");
            // InputStream is = Youku.context.getAssets().open("mount.txt");
            InputStream is = proc.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            String line;
            // String mount = new String();
            BufferedReader br = new BufferedReader(isr);
            String defauleSDCardPath = getDefauleSDCardPath();
            //用于盛放已经判断过的路径,省时高效
            HashMap<String, Integer> tempPath = new HashMap<String, Integer>();
            while ((line = br.readLine()) != null) {
                // "fat"为不可卸载的;"fuse"为可卸载的;但是有的手机不适用,所以统一去处理;storage为一些三星手机的存储路径标识
                if (line.contains("fat") || line.contains("fuse") || line.contains("storage")) {
                    if (line.contains("secure") || line.contains("asec") || line.contains("firmware") || line.contains("shell") || line.contains("obb") || line.contains("legacy") || line.contains("data") || line.contains("tmpfs")) {
                        continue;
                    }
                    String[] columns = line.split(" ");
                    for (int i = 0; i < columns.length; i++) {
                        String path = columns[i];
                        //一加手机的"/dev/fuse"是假地址
                        if (path.contains("/") && !path.contains("data") && !path.contains("Data") && !path.contains("/dev/fuse")) {
                            try {
                                if (tempPath.containsKey(path)) {
                                    continue;
                                } else {
                                    tempPath.put(path, 0);
                                    SDCardManager m = new SDCardManager(path);
                                    if (m.getTotalSize() >= 1024 * 1024 * 1024) {
                                        SDCardInfo info = new SDCardInfo();
                                        info.path = columns[i];
                                        if (info.path.equals(defauleSDCardPath)) {
                                            info.isExternal = false;
                                        } else {
                                            info.isExternal = true;
                                        }
                                        list.add(info);
                                    }
                                }
                            } catch (Exception e) {
                                continue;
                            }
                        }
                    }
                }
            }
            tempPath.clear();
            if (list.size() == 1) {
                if (!defauleSDCardPath.equals(list.get(0).path)) {
                    SDCardInfo info = new SDCardInfo();
                    info.path = defauleSDCardPath;
                    info.isExternal = false;
                    list.add(info);
                } else {
                    YoukuPlayerApplication.savePreference("download_file_path", defauleSDCardPath);
                }
            } else if (list.size() == 0) {
                if (defauleSDCardPath != null && defauleSDCardPath.length() != 0) {
                    SDCardInfo info = new SDCardInfo();
                    info.path = defauleSDCardPath;
                    info.isExternal = false;
                    list.add(info);
                }
            }
            if (list.size() > 1) {
                Set<SDCardInfo> s = new TreeSet<SDCardInfo>(new Comparator<SDCardInfo>() {

                    @Override
                    public int compare(SDCardInfo o1, SDCardInfo o2) {
                        return o1.path.compareTo(o2.path);
                    }
                });
                s.addAll(list);
                list = new ArrayList<SDCardInfo>(s);
            }
            return list;
        } catch (IOException e) {
        }
        return null;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SuppressLint(android.annotation.SuppressLint) IOException(java.io.IOException) TreeSet(java.util.TreeSet) BufferedReader(java.io.BufferedReader) File(java.io.File) SuppressLint(android.annotation.SuppressLint)

Example 22 with SuppressLint

use of android.annotation.SuppressLint in project UltimateAndroid by cymcsg.

the class RoundCornerProgressBar method setProgressColor.

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public void setProgressColor(int color) {
    progressColor = color;
    int radius = this.radius - padding / 2;
    GradientDrawable gradient = new GradientDrawable();
    gradient.setShape(GradientDrawable.RECTANGLE);
    gradient.setColor(progressColor);
    gradient.setCornerRadii(new float[] { radius, radius, radius, radius, radius, radius, radius, radius });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        layoutProgress.setBackground(gradient);
    } else {
        layoutProgress.setBackgroundDrawable(gradient);
    }
    if (!isProgressBarCreated) {
        isProgressColorSetBeforeDraw = true;
    }
}
Also used : SuppressLint(android.annotation.SuppressLint) GradientDrawable(android.graphics.drawable.GradientDrawable) SuppressLint(android.annotation.SuppressLint)

Example 23 with SuppressLint

use of android.annotation.SuppressLint in project UltimateAndroid by cymcsg.

the class RoundCornerProgressBar method setBackgroundColor.

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public void setBackgroundColor(int color) {
    backgroundColor = color;
    GradientDrawable gradient = new GradientDrawable();
    gradient.setShape(GradientDrawable.RECTANGLE);
    gradient.setColor(backgroundColor);
    gradient.setCornerRadius(radius);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        layoutBackground.setBackgroundDrawable(gradient);
    } else {
        layoutBackground.setBackground(gradient);
    }
    if (!isProgressBarCreated) {
        isBackgroundColorSetBeforeDraw = true;
    }
}
Also used : GradientDrawable(android.graphics.drawable.GradientDrawable) SuppressLint(android.annotation.SuppressLint)

Example 24 with SuppressLint

use of android.annotation.SuppressLint in project UltimateAndroid by cymcsg.

the class TextRoundCornerProgressBar method setProgressColor.

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public void setProgressColor(int color) {
    progressColor = color;
    int radius = this.radius - (padding / 2);
    GradientDrawable gradient = new GradientDrawable();
    gradient.setShape(GradientDrawable.RECTANGLE);
    gradient.setColor(progressColor);
    gradient.setCornerRadii(new float[] { radius, radius, radius, radius, radius, radius, radius, radius });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        layoutProgress.setBackground(gradient);
    } else {
        layoutProgress.setBackgroundDrawable(gradient);
    }
    if (!isProgressBarCreated) {
        isProgressColorSetBeforeDraw = true;
    }
}
Also used : SuppressLint(android.annotation.SuppressLint) GradientDrawable(android.graphics.drawable.GradientDrawable) SuppressLint(android.annotation.SuppressLint)

Example 25 with SuppressLint

use of android.annotation.SuppressLint in project UltimateAndroid by cymcsg.

the class TextRoundCornerProgressBar method setup.

@SuppressLint("NewApi")
private void setup(Context context, AttributeSet attrs) {
    int color;
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundCornerProgress);
    autoTextChange = typedArray.getBoolean(R.styleable.RoundCornerProgress_rcp_autoTextChange, false);
    DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radius, metrics);
    radius = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_backgroundRadius, radius);
    textViewValue = (TextView) findViewById(R.id.round_corner_progress_text);
    textSize = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_textProgressSize, textSize);
    textViewValue.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    textViewValue.setTextColor(typedArray.getColor(R.styleable.RoundCornerProgress_rcp_textProgressColor, textColor));
    text = typedArray.getString(R.styleable.RoundCornerProgress_rcp_textProgress);
    text = (text == null) ? "" : text;
    textViewValue.setText(text);
    textPadding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_textProgressPadding, textPadding);
    textViewValue.setPadding(textPadding, 0, textPadding, 0);
    textUnit = typedArray.getString(R.styleable.RoundCornerProgress_rcp_textProgressUnit);
    textUnit = (textUnit == null) ? "" : textUnit;
    textWidth = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_textProgressWidth, textWidth);
    layoutBackground = (LinearLayout) findViewById(R.id.round_corner_progress_background);
    padding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_backgroundPadding, padding);
    layoutBackground.setPadding(padding, padding, padding, padding);
    if (!isBackgroundColorSetBeforeDraw) {
        color = typedArray.getColor(R.styleable.RoundCornerProgress_rcp_backgroundColor, backgroundColor);
        setBackgroundColor(color);
    }
    ViewTreeObserver observer = layoutBackground.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            layoutBackground.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            int height = 0;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                backgroundWidth = layoutBackground.getMeasuredWidth() - textWidth;
                height = layoutBackground.getMeasuredHeight();
            } else {
                backgroundWidth = layoutBackground.getWidth() - textWidth;
                height = layoutBackground.getHeight();
            }
            backgroundHeight = (height == 0) ? (int) dp2px(DEFAULT_PROGRESS_BAR_HEIGHT) : height;
            ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) layoutBackground.getLayoutParams();
            params.width = backgroundWidth;
            params.height = backgroundHeight;
            layoutBackground.setLayoutParams(params);
            setProgress(progress);
        }
    });
    layoutProgress = (LinearLayout) findViewById(R.id.round_corner_progress_progress);
    if (!isProgressColorSetBeforeDraw) {
        color = typedArray.getColor(R.styleable.RoundCornerProgress_rcp_progressColor, progressColor);
        setProgressColor(color);
    }
    if (!isMaxProgressSetBeforeDraw) {
        max = (int) typedArray.getInt(R.styleable.RoundCornerProgress_rcp_max, 0);
    }
    if (!isProgressSetBeforeDraw) {
        progress = (int) typedArray.getInt(R.styleable.RoundCornerProgress_rcp_progress, 0);
    }
    typedArray.recycle();
}
Also used : ViewGroup(android.view.ViewGroup) TypedArray(android.content.res.TypedArray) OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) DisplayMetrics(android.util.DisplayMetrics) ViewTreeObserver(android.view.ViewTreeObserver) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)671 View (android.view.View)141 TextView (android.widget.TextView)89 Intent (android.content.Intent)71 Paint (android.graphics.Paint)61 ImageView (android.widget.ImageView)42 WebView (android.webkit.WebView)33 Bitmap (android.graphics.Bitmap)30 ListView (android.widget.ListView)30 File (java.io.File)28 ViewGroup (android.view.ViewGroup)26 AdapterView (android.widget.AdapterView)25 AlertDialog (android.app.AlertDialog)23 DialogInterface (android.content.DialogInterface)22 TypedArray (android.content.res.TypedArray)22 Uri (android.net.Uri)22 OnClickListener (android.view.View.OnClickListener)22 LayoutInflater (android.view.LayoutInflater)21 Point (android.graphics.Point)20 ArrayList (java.util.ArrayList)20