Skip to content

Instantly share code, notes, and snippets.

View imandaliya's full-sized avatar
🐢

Rahul Mandaliya imandaliya

🐢
View GitHub Profile
[
{
"background_image": "#ffebee"
},
{
"background_image": "#ffcdd2"
},
{
"background_image": "#ef9a9a"
},
@imandaliya
imandaliya / NotificationDemo.txt
Created June 11, 2018 06:32
Send Notification for Android O and Lower
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) {
@imandaliya
imandaliya / AutoScrollViewPager.java
Last active June 12, 2018 05:34
AutoScrollview with Dot indicator using TabLayout
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;
@imandaliya
imandaliya / EndlessRecyclerViewScrollListener.java
Created August 2, 2018 13:39 — forked from rogerhu/EndlessRecyclerViewScrollListener.java
Endless RecyclerView scrolling for different layout managers
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;
// 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
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;
// Remove Support Animatoin
public class RecyclerViewUtils {
((SimpleItemAnimator) RecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
}
Draw smooth bitmap on canvas
https://medium.com/@ali.muzaffar/android-why-your-canvas-shapes-arent-smooth-aa2a3f450eb5
// 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 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