Skip to content

Instantly share code, notes, and snippets.

View saurabharora90's full-sized avatar

Saurabh saurabharora90

View GitHub Profile
@saurabharora90
saurabharora90 / styles_themes.xml
Last active February 17, 2018 12:35
Primer on Styles and Themes
<!-- A theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/randomRed</item>
<item name="alertDialogTheme">@style/MyDialog</item>
</style>
<style name="MyDialog" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<item name="colorAccent">@color/secondary</item>
public static Description getDescriptionsFromJson(JsonElement jsonElement){
Description description = new Description();
for (Map.Entry<String, JsonElement> entry :jsonElement.getAsJsonObject().entrySet()){
if(entry.getKey().equalsIgnoreCase("en") || entry.getKey().equalsIgnoreCase(getDefaultLangCode()))
description.descriptionMap.put(entry.getKey(), entry.getValue().getAsString());
}
return description;
}
public static String getDefaultCode(Context context){
@saurabharora90
saurabharora90 / Placeholder.java
Created January 10, 2018 08:33
Performance at Viki
public static @DrawableRes int getPlaceHolder(Context context, @DrawableRes int actualPlaceholder) {
if(isLowRamDevice(context))
return R.drawable.low_ram_placeholder;
else
return actualPlaceholder;
}
public static boolean isLowRamDevice(Context context) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
return activityManager != null && ActivityManagerCompat.isLowRamDevice(activityManager);