Skip to content

Instantly share code, notes, and snippets.

View mortenjust's full-sized avatar

Morten Just mortenjust

View GitHub Profile
@mortenjust
mortenjust / java
Created August 26, 2015 18:15
Android animation
Animation wobble = AnimationUtils.loadAnimation(this, R.anim.wobble);
//Now we can play the animation like this on our chosen UI object, in this case our button1 object:
button1.startAnimation(wobble);
//https://www.safaribooksonline.com/library/view/learning-java-by/9781784398859/ch05s05.html
@mortenjust
mortenjust / activity.java
Last active September 1, 2015 16:16
Dump android intent
public class LogUtil {
private static final String TAG = "IntentDump";
public static void dumpIntent(Intent i){
Bundle bundle = i.getExtras();
if (bundle != null) {
Set<String> keys = bundle.keySet();
StringBuilder stringBuilder = new StringBuilder();
@mortenjust
mortenjust / activity
Created September 1, 2015 02:02
resize bitmap android
public Bitmap resizeBitmap(Bitmap b, int newWidthDp){
Float density = getResources().getDisplayMetrics().density;
int newWidth = newWidthDp * Math.round(density);
int width = b.getWidth();
int height = b.getHeight();
float scaleWidth = ((float) newWidth) / width;
float ratio = (float) width / newWidth;
int newHeight = (int) (height / ratio);
@mortenjust
mortenjust / activity.java
Created September 1, 2015 16:13
Check for tethering, hotspot, access point on android
public static boolean isSharingWiFi(final WifiManager manager)
{
try
{
final Method method = manager.getClass().getDeclaredMethod("isWifiApEnabled");
method.setAccessible(true); //in the case of visibility change in future APIs
return (Boolean) method.invoke(manager);
}
catch (final Throwable ignored)
{
@mortenjust
mortenjust / AndroidManifest.xml
Last active September 3, 2015 06:05
auto-increase version number android
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mortenjust.wtfbbqwwjd"
android:versionCode="10"
android:versionName="1.1.0.6"
@mortenjust
mortenjust / activity.java
Last active September 3, 2015 06:34
Get version code from manifest
public int getVersion() {
int v = 0;
try {
Log.d("mj.store", "package name is: "+mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).packageName);
Log.d("mj.store", "versionName name is: "+mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionCode);
Log.d("mj.store", "versionCode name is: "+mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionName);
v = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionCode;
} catch (PackageManager.NameNotFoundException e) {
// Huh? Really?
}
@mortenjust
mortenjust / build.gradle
Last active September 3, 2015 07:01
Add versioncode to apk filename android
// android { ...
// defaultconfig ...
applicationVariants.all { variant ->
variant.outputs.each { output ->
def file = output.outputFile
output.outputFile = new File(file.parent, file.name.replace(".apk", "-" + variant.versionCode+ ".apk"))
}
}
@mortenjust
mortenjust / AndroidManifest.xml
Last active July 27, 2019 17:25
Adding Volley to Android Studio #android
<uses-permission android:name="android.permission.INTERNET"/>
@mortenjust
mortenjust / activity.java
Created September 9, 2015 02:07
Start an activity without back stack and kill current activity
Intent i = new Intent(this, WatchFaceActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
finish();
@mortenjust
mortenjust / activity.java
Created September 9, 2015 18:08
Delay an action #android
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
// your code here
}
}, 1000/* 1sec delay */);