Android常用方法摘记以及收集

本文用于记录安卓常用方法,俗话说:好记性不如烂笔头!apk打包文件位置输出applicationVariants.all { variant -> variant.outputs.all { output -> variant.mergedFlavor.versionName = getVersionName() + "_" + releaseTime() if (variant.buildType.name.equals('release')) { outputFileName = "App_${variant.mergedFlavor.versionName}_release.apk" } else if (variant.buildType.name.equals('debug')) { outputFileName = "App_${variant.mergedFlavor.versionName}_debug.apk" } if (outputFileName != null && outputFileName.endsWith('.apk')) { variant.getPackageApplication().outputDirectory = new File("D:\\APK") variant.getPackageApplication().outputScope.apkDatas.forEach { apkData -> apkData.outputFileName = outputFileName } } } } 设备是否已 Root/** * 当前设备root状态 */ private static boolean isDeviceRooted() { String su = "su"; String[] locations = {"/system/bin/", "/system/xbin/", "/sbin/", "/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/xbin/", "/data/local/bin/", "/data/local/", "/system/sbin/", "/usr/bin/", "/vendor/bin/"}; for (String location : locations) { if (new File(location + su).exists()) { return true; } } return false; } 自定义View(手写签名View)使用方法: 1,布局中直接集成 2,signView.reset(); 可以重置view 3,通过其他方法可以将view转成Bitmap /** * Created by yangjianan on 2018/5/10. * mail: yang.jianan0926@gmail.com * 手写签名文件 */ public class SignView extends View { private Paint mPaint; private Path mPath; public SignView(Context context) { super(context); } public SignView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); initPaint(); } private void initPaint() { mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setColor(Color.RED); mPaint.setStrokeWidth(10); mPaint.setStyle(Paint.Style.STROKE); mPath = new Path(); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawPath(mPath, mPaint); } @Override public boolean onTouchEvent(MotionEvent event) { switch (MotionEventCompat.getActionMasked(event)) { case MotionEvent.ACTION_DOWN: mPath.moveTo(event.getX(), event.getY()); break; case MotionEvent.ACTION_MOVE: mPath.lineTo(event.getX(), event.getY()); break; case MotionEvent.ACTION_UP: break; } invalidate(); return true; } public void reset() { mPath.reset(); invalidate(); } } /** * 把一个view转化成bitmap对象 */ private Bitmap loadBitmapFromView(View v) { int w = v.getWidth(); int h = v.getHeight(); Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bmp); c.drawColor(Color.WHITE); /** 如果不设置canvas画布为白色,则生成透明 */ v.layout(0, 0, w, h); v.draw(c); return bmp; } private void saveImage(Bitmap bmp) { String fileName = "0001.jpg"; File file = new File(getExternalCacheDir(), fileName); if (!file.exists()) { appDir.mkdir(); } try { FileOutputStream fos = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } catch (Exception e) { e.printStackTrace(); Log.i("rxjava","IOException e = " + e.getMessage()); } } Android Studio 无法关联 Api 26 源码 - 提示 Souces for android api 26 platform not found找到如下文件: C:\Users{USER_NAME}.AndroidStudio3.0\config\options\jdk.table.xml,修改节点 sourcePath <sourcePath> <root type="composite"> <root type="simple" url="file://E:/sdk/sources/android-26" /> </root> </sourcePath> exploded-aar 不显示问题gradle3.0 之后版本 compile aar 依赖,在 build\intermediates 下不会生成 exploded-aar 文件夹,建议使用 classpath ‘com.android.tools.build:gradle:2.2.2’ 和 distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip ubuntu 生成 key1, ssh-keygen -t rsa -C "yangjianan@begoit.com" 2, cd .ssh/ 3, cat id_rsa.pub 将美化后的 Json 字符串展示到 TextView 上     阅读全文
Bruce Yang's avatar
Bruce Yang 1月 08, 2016

Git使用

git 日志导出为 csv 格式文件、excel 格式文件git log --date=iso --pretty=format:'"%h","%an","%ad","%s"' >log.xls git回滚到指定版本方法(2016-01-08 14:55:44) git reset --hard <commit ID号> 例如: git reset --hard dc972ec 版本号查看方法: 打开github项目,点击commits就能看到提交记录以及版本号     阅读全文
Bruce Yang's avatar
Bruce Yang 1月 06, 2016