Skip to content

Instantly share code, notes, and snippets.

View kibotu's full-sized avatar
🎯
Focusing

Jan Rabe kibotu

🎯
Focusing
View GitHub Profile
@kibotu
kibotu / drawable scaling
Last active May 27, 2020 12:12
Android: scale a drawable by dp
public static Drawable getScaledDrawable(Context context, int resourceId, int scaleInDp) {
BitmapFactory.Options options = new BitmapFactory.Options();
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
options.inScreenDensity = metrics.densityDpi;
options.inTargetDensity = metrics.densityDpi;
options.inDensity = DisplayMetrics.DENSITY_DEFAULT;
final int px = roundToInt(convertDpToPixel(scaleInDp));
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
BitmapDrawable drawable = new BitmapDrawable(context.getResources(), Bitmap.createScaledBitmap(bitmap, px, px, true));
Log.v("Scaling", "Scaling image [" + scaleInDp + "dp to " + px + "px] => [" + bitmap.getWidth() + "x" + bitmap.getHeight() + " px] to [" + drawable.getIntrinsicWidth() + "x" + drawable.getIntrinsicHeight() + " px]");
@kibotu
kibotu / build.gradle
Created June 26, 2015 16:40
android install obb
task installObb() << {
description = "Install all OBB packages"
def stdout = new ByteArrayOutputStream()
def obbFile = "main." + getVersionCode() + "." + getApplicationId() + ".obb"
def source = "../" + obbFile + ".zip"
def destination = "/sdcard/Android/obb/" + getApplicationId() + "/" + obbFile
println("adb push " + source + " " + destination)
@kibotu
kibotu / crashlytics fix for intellij fabric plugin
Last active May 1, 2018 11:00
crashlytics fix for intellij fabric plugin
preBuild << { delete('src/main/res/values/com_crashlytics_export_strings.xml') }
public static class ClassFactory {
public static <T> T getInstance() {
final Class<T> clazzOfT = null;
T t = null;
try {
t = clazzOfT.newInstance();
} catch (final InstantiationException | IllegalAccessException e) {
@kibotu
kibotu / build.gradle
Created July 21, 2015 13:55
git version count and version name
def getCommitCount() {
final Scanner s = new Scanner(getCommitNumberFromGit());
int count = 0;
while (s.hasNextLine()) {
s.nextLine();
count++;
}
return count;
@kibotu
kibotu / foorloopvsiterator.java
Created July 31, 2015 16:54
remove elements from for loop vs iterator
package com.java.forloopvsiterator.test;
import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.List;
public class Main {
public static void main(String[] args) {
@kibotu
kibotu / FeedbackFragment.java
Created August 5, 2015 18:21
mandrill send message
private void sendMessage(@NotNull final String fromEmail, @NotNull final String fromName) {
final String apiKey = AppConfig.getValue(MANDRILLAPP_API_KEY);
final MandrillServiceFactory serviceFactory = new MandrillServiceFactory(apiKey, new GsonJsonHandler(new Gson()), new HttpComponentsHandler(new DefaultHttpClient()));
final Category.Messages messages = serviceFactory.getService(Category.Messages.class);
final Struct message = Struct.with("text", "" + feedbackMessage.getText().toString())
.set("to", StructArray.with(Struct.with("email", Localization.getString(R.string.kEmailTitle))))
.set("subject", Localization.getString(currentMode.resourceId))
.set("from_email", fromEmail)
.set("from_name", fromName);
@kibotu
kibotu / ListStorage.java
Created September 1, 2015 18:40
ArrayList for Shared Preferences
/**
* Created by Jan Rabe on 01/09/15.
*/
public class ListStorage<T> implements IStorage<T> {
private final Type listType = new TypeToken<ArrayList<T>>() {
}.getType();
@NotNull
@kibotu
kibotu / set crashlytics custom version name
Last active September 18, 2015 12:23
crashlytics hack to set different version name
private void setupCrashlytics(@NotNull final Activity activity) {
final Crashlytics crashlytics = new Crashlytics();
// hack to set fully classified version name @see gradle task.canonicalReleaseVersionName
try {
final Field versionNameField = CrashlyticsCore.class.getDeclaredField("versionName");
versionNameField.setAccessible(true);
versionNameField.set(crashlytics.core, Build.getValue(CANONICAL_VERSION_NAME));
} catch (Exception e) {
e.printStackTrace();
@kibotu
kibotu / gist:d80545ef4d3700a4f832
Created September 22, 2015 13:45
parse date format
/**
* Format dd.MM.yy hh:mm e.g.: 24.09.15 12:26
*/
public static Date parseDate(final String date) {
final DateFormat df = new SimpleDateFormat("dd.MM.yy hh:mm");
Date result = null;
try {
result = df.parse(date);