Skip to content

Instantly share code, notes, and snippets.

@rock3r
rock3r / WidgetHelper.java
Last active August 29, 2015 13:57
How to update an homescreen widget (the right way)
package net.frakbot.gists.widgethelper;
/*
* Copyright 2014 Sebastiano Poggi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
Android Fragment Dialog
@Nilzor
Nilzor / ApkVersionPostfix.build.gradle
Last active August 29, 2015 14:08
build.gradle snippet for automatically adding version code postfix to APK file name
import javax.xml.xpath.XPathConstants
import javax.xml.xpath.XPathFactory
// Set output filename of APK based on version code from manifest when doing release build
// Note: This script will add a couple of seconds to the build script build time
gradle.projectsEvaluated {
preReleaseBuild.doFirst {
android.applicationVariants.all { variant ->
// Check version number configured in AndroidManifest
if (variant.name != "release") return
import android.content.Intent;
import android.support.annotation.NonNull;
import java.io.Serializable;
import java.util.Map;
/**
* Provides a way to wrap a serializable {@link Map} in order to preserve its class
* during serialization inside an {@link Intent}, otherwise it would be "flattened"
* in a {@link android.os.Parcel} and unparceled as a {@link java.util.HashMap}.
@JustinAngel
JustinAngel / compareJarsApi22AndAndroidM
Last active August 29, 2015 14:22
API delta between API22 and Android M: New APIs
===== Results of comparing two JARs =====
Generated by @ https://github.com/JustinAngel/compareJars
Showing API additions only. Removed APIs aren't shown.
Comparing 3479 classes from C:\Program Files (x86)\Android\sdk\platforms\android-MNC\android.jar
To 3683 classes from C:\Program Files (x86)\Android\sdk\platforms\android-22\android.jar
public static final class android.Manifest$permission extends Object {
@shekaroppo
shekaroppo / percent_relative_layout.xml
Last active August 29, 2015 14:23
Played with all new PercentRelativeLayout, its very easy to build complex UI structure using percentage concept now. Everything will be scaled automatically on different screen size.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
style="@style/match">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
style="@style/match"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
@johnkil
johnkil / ConvertDimensionUtils.java
Created September 29, 2012 15:17
Convert DIP to PX and PX to DIP
/**
* This method convets dp unit to equivalent device specific value in pixels.
*
* @param dp A value in dp(Device independent pixels) unit. Which we need to convert into pixels
* @param context Context to get resources and device specific display metrics
* @return A float value to represent Pixels equivalent to dp according to device
*/
public static float convertDpToPixel(float dp,Context context){
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
@API-Beast
API-Beast / Components.cpp
Last active December 28, 2015 09:59
Component-Entity system.
#include <map>
#include <typeinfo>
#include <set>
typedef size_t EntityID;
struct BaseComponent
{
virtual ~BaseComponent(){};
EntityID BelongsTo;
};
@fiskurgit
fiskurgit / screenshot.sh
Last active January 15, 2016 21:30
Pass image resize width argument to the Android screenshot.sh script: screenshot.sh 480 open
#!/bin/sh
width=$1
openInPreview=$2
timestamp=$(date +%s)
filepath=/sdcard/$timestamp.png
echo $filepath
@futtetennista
futtetennista / ThreadPoolIdlingResource.java
Last active October 12, 2016 23:53
Code taken from Espresso's AsyncTaskPoolMonitor and adapter to be used as an idling resource for any ThreadPoolExecutor
/*
* Copyright (C) 2013 Google, 2014 Stefano Dacchille
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software