This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"background_image": "#ffebee" | |
}, | |
{ | |
"background_image": "#ffcdd2" | |
}, | |
{ | |
"background_image": "#ef9a9a" | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final String NOTIFICATION_CHANNEL_ID = "1001"; | |
private static final int NOTIFICATION_ID = 1001; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_demo); | |
try { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.os.Handler; | |
import android.os.Message; | |
import android.support.v4.view.MotionEventCompat; | |
import android.support.v4.view.PagerAdapter; | |
import android.support.v4.view.ViewPager; | |
import android.util.AttributeSet; | |
import android.view.MotionEvent; | |
import android.view.animation.Interpolator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class EndlessRecyclerViewScrollListener extends RecyclerView.OnScrollListener { | |
// The minimum amount of items to have below your current scroll position | |
// before loading more. | |
private int visibleThreshold = 5; | |
// The current offset index of data you have loaded | |
private int currentPage = 0; | |
// The total number of items in the dataset after the last load | |
private int previousTotalItemCount = 0; | |
// True if we are still waiting for the last set of data to load. | |
private boolean loading = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Smooth scroll grid view item to center using | |
private void smoothScrollToCenter(GridView gridView, View child) { | |
Rect rect = new Rect(); | |
gridView.getGlobalVisibleRect(rect); | |
gridView.smoothScrollBy(child.getBottom() - gridView.getScrollY() - rect.centerY() + child.getHeight() / 2, 200); | |
} | |
// now call in setOnItemClickListener method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration { | |
private int spanCount; | |
private int spacing; | |
private boolean includeEdge; | |
public GridSpacingItemDecoration(int spanCount, int spacing, boolean includeEdge) { | |
this.spanCount = spanCount; | |
this.spacing = spacing; | |
this.includeEdge = includeEdge; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Remove Support Animatoin | |
public class RecyclerViewUtils { | |
((SimpleItemAnimator) RecyclerView.getItemAnimator()).setSupportsChangeAnimations(false); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Draw smooth bitmap on canvas | |
https://medium.com/@ali.muzaffar/android-why-your-canvas-shapes-arent-smooth-aa2a3f450eb5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get Width and height of the screen | |
// this method only give available space for application screen | |
DisplayMetrics displayMetrics = new DisplayMetrics(); | |
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); | |
int height = displayMetrics.heightPixels; | |
int width = displayMetrics.widthPixels; | |
// get real height and width of the device | |
WindowManager windowManager = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This method allow to handle Drawer and back functionality with state. | |
public class ToolbarToggleUtils { | |
public static void enableViews(boolean enable) { | |
// To keep states of ActionBar and ActionBarDrawerToggle synchronized, | |
// when you enable on one, you disable on the other. | |
// And as you may notice, the order for this operation is disable first, then enable - VERY VERY IMPORTANT. | |
if(enable) { | |
//You may not want to open the drawer on swipe from the left in this case |
OlderNewer