Skip to content

Instantly share code, notes, and snippets.

@mandhor
mandhor / gist:e89d2547eaad7b9ab82b
Created April 6, 2015 21:58
Convert DP to PX ( android dip dp pixels px )
int dp = 123;
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics());
@mandhor
mandhor / gist:92ce23904437d83e673d
Created April 6, 2015 21:54
[ SOLUTION ] SwipeRefreshLayout spinner not showing when .setRefreshing(true) called right after creating Fragment. ( android bug solution swiperefreshlayout pull to refresh not showing )
TypedValue typed_value = new TypedValue();
getActivity().getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, typed_value, true);
mSwipeRefreshLayout.setProgressViewOffset(false, 0, getResources().getDimensionPixelSize(typed_value.resourceId));
@mandhor
mandhor / burgerArrowTransition.java
Created April 6, 2015 17:13
Android - method for animating ActionBarDrawerToggle between hamburger (drawer) and back arrow (home)
android.support.v7.app.ActionBarDrawerToggle mDrawerToggle;
android.support.v4.widget.DrawerLayout mDrawerLayout;
public void burgerArrowTransition(final boolean burgerToArrow) {
float start, end;
mDrawerToggle.setDrawerIndicatorEnabled(true);
if(burgerToArrow) {
start = 0.0f;
@mandhor
mandhor / CustomMarkerGenerator
Last active August 29, 2015 14:18
Custom GoogleMap marker with text drawn
//add dependency: com.google.maps.android:android-maps-utils:0.3.4
GoogleMap map; //map reference
LatLng point; //LatLng point reference
String markerText = "123"; //text on marker
IconGenerator iconFactory = new IconGenerator(context);
iconFactory.setBackground(context.getResources().getDrawable(R.drawable.custom_marker));
iconFactory.setTextAppearance(context, R.style.custom_text_apperance);
Bitmap icon = iconFactory.makeIcon(markerText);