Skip to content

Instantly share code, notes, and snippets.

@Splagoon
Splagoon / time.kt
Created November 11, 2014 18:50
Time magics with Kotlin
import java.util.Date
import kotlin.concurrent.*
fun at(date: Date, func: () -> Unit) {
val waitTime = date.getTime() - Date().getTime()
thread {
Thread.sleep(waitTime)
func()
}
}
@seanKenkeremath
seanKenkeremath / Android Lollipop Widget Tinting Guide
Last active May 2, 2025 11:54
How base colors in Lollipop apply to different UI elements
Unless specified otherwise, all of the below tinting applies to both Lollipop and pre-Lollipop using AppCompat v21. To use the support version of these attributes, remove the android namespace. For instance, "android:colorControlNormal" becomes "colorControlNormal". These attributes will be propagated to their corresponding attributes within the android namespace for devices running Lollipop. Any exceptions to this will be noted by including the "android:" prefix.
All Clickable Views:
-----------
* ripple effect (Lollipop only) -- "colorControlHighlight"
Status Bar:
------------
* background (Lollipop only) - "colorPrimaryDark"
@koocbor
koocbor / CreateDialog.java
Last active June 20, 2022 15:50
Full Screen Dialog in Android
FullScreenDialog dialog = new FullScreenDialog();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
dialog.show(ft, FullScreenDialog.TAG);
@omegasoft7
omegasoft7 / SetID to View Programmatically
Created January 9, 2015 09:52
SetID to a View Programmatically
Google finally realized the need of generating unique IDs for programmatically created views...
From API level 17 and above, you can call
View.generateViewId()
Then use View.setId(int).
In case you need it for targets lower than level 17, here is its internal implementation in View.java you can use directly in your project, put it in your util class or somewhere:
@billmote
billmote / AndroidManifest.xml
Last active October 15, 2023 10:48 — forked from JakeWharton/gist:f50f3b4d87e57d8e96e9
When pushing code from your IDE, wake the device and show the activity.
<?xml version="1.0" encoding="utf-8"?>
<!-- Add this as a debug manifest so the permissions won't be required by your production app -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
</manifest>
@PaNaVTEC
PaNaVTEC / Coordinator.java
Last active November 4, 2016 22:49
Coordinates various actions and fires a callback when all are complete
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
public class Coordinator {
private List<String> actions;
private Set<String> completedActions = new TreeSet<>();
private CoordinatorCompleteAction coordinatorCompleteAction;
@Mun0n
Mun0n / ShareActivity
Created March 24, 2015 08:12
Android share image and text via intent with ShareActionProvider, using action button.
File shareFile;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_editor, menu);
ShareActionProvider shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(menu.findItem(R.id.action_share));
shareActionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
shareActionProvider.setShareIntent(getDefaultShareIntent());
shareActionProvider.setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener() {
@ungoldman
ungoldman / CHANGELOG.md
Last active November 23, 2020 17:39
change log template

${project-name} Change Log

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

1.0.0

  • engage
@curioustechizen
curioustechizen / UseApiKey.java
Created April 6, 2015 07:37
Android: Loading API Keys and other secrets from properties file using gradle
String apiKey = BuildConfig.API_KEY
@hector6872
hector6872 / CustomGenerateViewId.java
Created April 9, 2015 13:49
A backport of generateViewId() to API 10+
public class CustomGenerateViewId {
private static final AtomicInteger nextGeneratedId = new AtomicInteger(1);
public static int customGenerateViewId() {
for (; ; ) {
final int result = nextGeneratedId.get();
// aapt-generated IDs have the high byte nonzero; clamp to the range under that.
int newValue = result + 1;
if (newValue > 0x00FFFFFF) {
newValue = 1; // Roll over to 1, not 0.
}