Skip to content

Instantly share code, notes, and snippets.

View TomasValenta's full-sized avatar

Tomáš Valenta TomasValenta

View GitHub Profile
@TomasValenta
TomasValenta / SharedPreferencesExtensions.kt
Last active November 14, 2018 09:36
Kotlin Extensions - Android SharedPreferences
import android.content.SharedPreferences
import android.text.TextUtils
import java.security.spec.InvalidParameterSpecException
/**
* Return value on the given key.
* [T] is the type of value
* @param defaultValue optional default value
*/
inline operator fun <reified T : Any> SharedPreferences.get(key: String, defaultValue: T? = null): T {
public class WidgetProvider extends AppWidgetProvider {
@StringDef({Actions.MANUAL_REFRESH, Actions.DETAIL_ACTIVITY, Actions.RECONFIGURATION_ACTIVITY})
@Retention(RetentionPolicy.SOURCE)
private @interface Actions {
String MANUAL_REFRESH = BuildConfig.APPLICATION_ID + ".widget.MANUAL_REFRESH_ACTION";
String DETAIL_ACTIVITY = BuildConfig.APPLICATION_ID + ".widget.DETAIL_ACTIVITY_ACTION";
String RECONFIGURATION_ACTIVITY = BuildConfig.APPLICATION_ID + ".widget.RECONFIGURATION_ACTIVITY_ACTION";
}