Skip to content

Instantly share code, notes, and snippets.

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
doSomethingCool();
}
});
button.setOnClickListener { doSomethingCool() }
Picasso.with(context).load("http://i.imgur.com/W3C6LA1.png").into(imageView);
Glide.with(context).load("http://i.imgur.com/W3C6LA1.png").into(imageView);
@AOrobator
AOrobator / .zshrc
Last active November 8, 2016 00:31
Commonly Used Aliases
alias c="clear" # Clears your terminal window of all output
alias d="adb devices" # Lists all connected Android devices and emulators
alias gs="git status" # Displays status of your working tree in a repository
alias gb="git branch" # Displays local branches
alias gas="git add *" # Adds all files to the git staging area
alias log="adb logcat" # Displays the android logcat
alias adbr="adb kill-server; adb start-server; d" # Restarts the adb server, adb can be quite finnicky and restarting helps to alleviate those problems. That last d character is a reference to the alias defined above, which points to “adb devices”
@AOrobator
AOrobator / AndroidManifest.xml
Last active December 3, 2016 18:15
Implementing Android App Shortcuts - AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.orobator.konstellations">
<application
android:name=".KonstellationsApplication"
android:allowBackup="true"
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:supportsRtl="true"
@AOrobator
AOrobator / shortcuts.xml
Created December 3, 2016 18:16
Implementing App Shortcuts - shortcuts.xml
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:enabled="true"
android:icon="@drawable/random_constellation"
android:shortcutDisabledMessage="@string/shortcut_disabled_message"
android:shortcutId="random_constellation"
android:shortcutLongLabel="@string/shortcut_long_label"
android:shortcutShortLabel="@string/shortcut_short_label">
<!-- Each one of these intents needs an android:action, even if you don't
@AOrobator
AOrobator / GettingTheShortcutManager.kt
Last active December 3, 2016 18:37
Implementing App Shortcuts - Getting the ShortcutManager
val shortcutManager = context.getSystemService(ShortcutManager::class.java)
@AOrobator
AOrobator / RestoreShortcuts.java
Last active December 5, 2016 00:34
Implementing App Shortcuts - Restoring shortcuts
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
if (shortcutManager.getDynamicShortcuts().size() == 0) {
// Application restored. Need to re-publish dynamic shortcuts.
if (shortcutManager.getPinnedShortcuts().size() > 0) {
// Pinned shortcuts have been restored. Use
// updateShortcuts(List) to make sure they
// contain up-to-date information.
@AOrobator
AOrobator / ShortcutHelper.kt
Last active December 6, 2016 01:22
Implementing App Shortcuts - Tracking usage pt. 2
@TargetApi(N_MR1)
fun trackShortcutUsed(shortcutManager: ShortcutManager, constellation: Constellation) {
shortcutManager.reportShortcutUsed(constellation.name)
val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(APP_CONTEXT)
val seenCount = sharedPrefs.getInt(constellation.name, 0)
sharedPrefs
.edit()
.putInt(constellation.name, seenCount + 1)
.apply()
updateShortcuts(shortcutManager)
@AOrobator
AOrobator / ConstellationDetailActivity.kt
Last active December 6, 2016 01:22
Implementing App Shortcuts - Tracking usage pt. 1
shortcutAction {
trackShortcutUsed(it, constellation)
}