Skip to content

Instantly share code, notes, and snippets.

@luhaiwork
luhaiwork / VersionInfo.groovy
Created December 24, 2019 06:26 — forked from jasonwyatt/VersionInfo.groovy
Get versionName and versionCode from APK file.
class VersionInfo {
public static Pattern VERSION_NAME_PATTERN = Pattern.compile("versionName='([0-9]+(\\.[0-9]+)+)'", Pattern.MULTILINE)
public static Pattern VERSION_CODE_PATTERN = Pattern.compile("versionCode='([0-9]+)'", Pattern.MULTILINE)
public File apkFile;
public String versionName;
public int versionCode;
public VersionInfo(File apkFile, String versionName, int versionCode) {
this.apkFile = apkFile;
this.versionName = versionName
@luhaiwork
luhaiwork / NFCReaderActivity.java
Created April 16, 2019 02:48
前台NFC读卡
package com.synjones.imageacquisition.activity;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
int isMyApp(JNIEnv *env, jobject context) {
// 获得 Context 类
jclass native_clazz = (*env)->GetObjectClass(env, context);
// 得到 getPackageManager 方法的 ID
jmethodID methodID_func = (*env)->GetMethodID(env, native_clazz,
"getPackageManager",
"()Landroid/content/pm/PackageManager;");
// 获得应用包的管理器
jobject package_manager = (*env)->CallObjectMethod(env, context, methodID_func);
// 获得 PackageManager 类
@luhaiwork
luhaiwork / Camera.java
Created December 28, 2018 01:10
Android camera 相关代码
private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
final double ASPECT_TOLERANCE = 0.1;
double targetRatio = (double) w / h;
if (sizes == null) return null;
Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = h;
// Try to find an size match aspect ratio and size
for (Size size : sizes) {
double ratio = (double) size.width / size.height;
@luhaiwork
luhaiwork / MyApp.java
Created November 1, 2018 07:54 — forked from artem-zinnatullin/MyApp.java
If you need to set one font for all TextViews in android application you can use this solution. It will override ALL TextView's typefaces, includes action bar and other standard components, but EditText's password font won't be overriden.
public class MyApp extends Application {
@Override
public void onCreate() {
TypefaceUtil.overrideFont(getApplicationContext(), "SERIF", "fonts/Roboto-Regular.ttf"); // font from assets: "assets/fonts/Roboto-Regular.ttf
}
}
@luhaiwork
luhaiwork / TranslateAnimation.java
Last active June 26, 2018 02:27
View Animate Demo
package wangxu.com.testn;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.view.View;
@luhaiwork
luhaiwork / getAppPackageByAppName.java
Created June 21, 2018 02:21
Android get app package name by app name.
private String getAppPackageName(Context context,String searchName) {
PackageManager packageManager = context.getPackageManager();
List<ApplicationInfo> installedApplications = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo info:installedApplications){
String appName=packageManager.getApplicationLabel(info).toString();
if(searchName.equals(appName)){
Log.e("tag","------appName:"+appName+"packageName:"+info.packageName);
return info.packageName;
}
}
@luhaiwork
luhaiwork / clearYoudaoSearch.js
Created April 8, 2016 09:25
用于在浏览器页签切换的时候,自动清空查询内容,并将查询框设置焦点,可以直接应用于TamperMonkey
document.addEventListener('visibilitychange', function(){
document.getElementById("query").focus();
document.getElementById("query").value="";
window.scrollTo (0,0);
})
@luhaiwork
luhaiwork / surge.conf
Last active September 23, 2016 08:37 — forked from soffchen/surge.conf
surge.conf
[General]
skip-proxy = 192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12, 100.64.0.0/10, localhost, *.local
bypass-tun = 0.0.0.0/8, 1.0.0.0/9, 1.160.0.0/11, 1.192.0.0/11, 10.0.0.0/8, 14.0.0.0/11, 14.96.0.0/11, 14.128.0.0/11, 14.192.0.0/11, 27.0.0.0/10, 27.96.0.0/11, 27.128.0.0/9, 36.0.0.0/10, 36.96.0.0/11, 36.128.0.0/9, 39.0.0.0/11, 39.64.0.0/10, 39.128.0.0/10, 42.0.0.0/8, 43.224.0.0/11, 45.64.0.0/10, 47.64.0.0/10, 49.0.0.0/9, 49.128.0.0/11, 49.192.0.0/10, 54.192.0.0/11, 58.0.0.0/9, 58.128.0.0/11, 58.192.0.0/10, 59.32.0.0/11, 59.64.0.0/10, 59.128.0.0/9, 60.0.0.0/10, 60.160.0.0/11, 60.192.0.0/10, 61.0.0.0/10, 61.64.0.0/11, 61.128.0.0/10, 61.224.0.0/11, 100.64.0.0/10, 101.0.0.0/9, 101.128.0.0/11, 101.192.0.0/10, 103.0.0.0/10, 103.192.0.0/10, 106.0.0.0/9, 106.224.0.0/11, 110.0.0.0/7, 112.0.0.0/9, 112.128.0.0/11, 112.192.0.0/10, 113.0.0.0/9, 113.128.0.0/11, 113.192.0.0/10, 114.0.0.0/9, 114.128.0.0/11, 114.192.0.0/10, 115.0.0.0/8, 116.0.0.0/8, 117.0.0.0/9, 117.128.0.0/10, 118.0.0.0/11, 118.64.0.0/10, 118.128.0.0/9, 119.0.
---Java
//I used this on Android
//before you proceed, you need to ensure your private key is PKCS8 since that is what can be read natively in java.
//If your key begins with -----BEGIN RSA PRIVATE KEY-----, the it is ssleay and you need to convert it using the openssl command below
//openssl pkcs8 -topk8 -inform pem -in ssleay-private-key.key -outform pem -nocrypt -out pkcs8-private-key.pem
final private static String RSA_PRIVATE_KEY =
"-----BEGIN PRIVATE KEY-----\n" +
"MI...\n" +