Skip to content

Instantly share code, notes, and snippets.

View angeldevil's full-sized avatar

AngelDevil angeldevil

  • Wuhan, Hubei, China
View GitHub Profile
@angeldevil
angeldevil / Android配置AspectJ
Last active February 20, 2019 10:50
Configure aspectj on Android. Just copy this script to your module's build.gradle file.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.aspectj:aspectjtools:1.8.13'
}
}
final def log = project.logger
@angeldevil
angeldevil / ConvertViewToBitmap
Created July 21, 2014 14:52
Convert a view to bitmap without displaying it
public static Bitmap convertViewToBitmap(View view) {
view.destroyDrawingCache();
view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
view.setDrawingCacheEnabled(true);
return view.getDrawingCache(true);
}
@angeldevil
angeldevil / GoToMark
Created January 7, 2014 06:38
Let user mark our App from market
Uri uri = Uri.parse("market://details?id=" + getPackageName());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(intent, 0);
if (resolveInfo == null) {
// There is no market
} else {
startActivity(it);
}
@angeldevil
angeldevil / FixCrashWhenSystemHasNoEmailClient
Last active January 1, 2016 00:09
Resolve issue that app crashes when clicks a TextView with autoLink be set to email or all but the system has no email client.
@Override
public void startActivity(Intent intent) {
if (intent.toString().indexOf("mailto") != -1) { // Any way to judge that this is to sead an email
PackageManager pm = getPackageManager();
// The first Method
List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
if (activities == null || activities.size() == 0) {
// Do anything you like, or just return
return;
}
@angeldevil
angeldevil / RealScaleAndRotation
Last active June 27, 2022 14:46
Calculate the real scale and degree of rotation from an Android Matrix
float[] v = new float[9];
matrix.getValues(v);
// translation is simple
float tX = v[Matrix.MTRANS_X];
float tY = v[Matrix.MTRANS_Y];
// calculate real scale
float scaleX = values[Matrix.MSCALE_X];
float skewY = values[Matrix.MSKEW_Y];
float realScale = (float) Math.sqrt(scaleX * scaleX + skewY * skewY);
@angeldevil
angeldevil / Mount Samba
Created March 10, 2013 11:22
Mount Samba share into local directory.
1.Install smbfs
sudo apt-get install smbfs
2.mount
sudo smbmount //serverip/server_user localpath -o uid=local_uid,gid=local_gid,user=server_user,pass=server_pass,iocharset=utf8
3.umount
sudo umount -d localpath
@angeldevil
angeldevil / restart network
Created March 10, 2013 10:05
restart net interface in linux
sudo ifconfig eth0 down
sudo ifconfig eth0 up