Android工具类、工具方法自总结

1.dp转px,下面工具类中的静态方法dp2px

 

public class DisplayUtils {

    public static Point getScreenResolution(Context context) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        Point screenResolution = new Point();
        if (android.os.Build.VERSION.SDK_INT >= 13) {
            display.getSize(screenResolution);
        } else {
            screenResolution.set(display.getWidth(), display.getHeight());
        }
        return screenResolution;
    }

    public static int dp2px(Context context, float dpValue) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, context.getResources().getDisplayMetrics());
    }
}

 

 

2.在手机相册中隐藏某个文件夹中的图片文件,在此文件中创建一个.nomedia或者.outside文件(华为手机兼容)即可

 

szName = szName.substring(0, szName.length() - 1);
File folder = new File(outPathString + File.separator + szName);
folder.mkdirs();
if (szName.endsWith("imgs")) {
    File nomedia = new File(folder.getPath(),".nomedia");
    File outside = new File(folder.getPath(), ".outside");
    try {
        if(!nomedia.exists()) {
            nomedia.createNewFile();
        }
        if (!outside.exists()) {
            outside.createNewFile();
        }
    }catch (IOException e){
        MLog.e("IOException","exception in unzip create nomedia file");
    }
}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值