Skip to content

Instantly share code, notes, and snippets.

@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”
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 / 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 / ShortcutHelper.kt
Last active December 6, 2016 01:27
Implementing App Shortcuts - ShortcutActions
inline fun shortcutAction(action: (ShortcutManager) -> Unit): Unit {
if (SDK_INT >= N_MR1) {
val shortcutManager = APP_CONTEXT.getSystemService(ShortcutManager::class.java)
action(shortcutManager)
}
}
@AOrobator
AOrobator / ShortcutHelper.kt
Last active December 18, 2016 23:55
Implementing App Shortcuts - Updating your shortcuts
/**
* Sets the new Shortcut List by providing the three most visited
* constellations
* */
@TargetApi(N_MR1)
fun updateShortcuts(shortcutManager: ShortcutManager) {
shortcutManager.dynamicShortcuts =
Constellation
.values()
.sortedWith(compareBy { -getConstellationVisitedCount(it) })
@AOrobator
AOrobator / ConstellationDetailActivity.kt
Last active December 18, 2016 23:59
Implementing App Shortcuts - Enabling/Disabling Shortcuts
@TargetApi(N_MR1)
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.enable_shortcut -> shortcutAction {
it.enableShortcuts(listOf(constellation.name))
alertUser(R.string.shortcut_enabled)
}
R.id.disable_shortcut -> shortcutAction {
it.disableShortcuts(listOf(constellation.name))
alertUser(R.string.shortcut_disabled)