Skip to content

Instantly share code, notes, and snippets.

View abhinav272's full-sized avatar

Abhinav Sharma abhinav272

View GitHub Profile
/*
* Copyright (C) 2007-2008 OpenIntents.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@abhinav272
abhinav272 / CommentAdapter.kt
Created December 28, 2018 10:00
RecyclerViewAdapter converted to PagedListAdapter
class CommentAdapter(private val fragment: SGFragment) : RecyclerView.Adapter<CommentViewHolder>() {
private val mCustomList = ArrayList<Comment>()
private val mListener = object : ListUpdateCallback {
override fun onChanged(position: Int, count: Int, payload: Any?) {
notifyItemRangeChanged(paged(position), count, payload)
}
override fun onMoved(fromPosition: Int, toPosition: Int) {
import android.util.Log;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import okhttp3.logging.HttpLoggingInterceptor;
public class CustomHttpLogger implements HttpLoggingInterceptor.Logger {
@Override
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@abhinav272
abhinav272 / README.md
Created November 28, 2018 04:45 — forked from shekibobo/README.md
Android: Base Styles for Button (not provided by AppCompat)

How to create custom button styles using Android's AppCompat-v7:21

Introduction

AppCompat is an Android support library to provide backwards-compatible functionality for Material design patterns. It currently comes bundled with a set of styles in the Theme.AppCompat and Widget.AppCompat namespaces. However, there is a critical component missing which I would have thought essential to provide the a default from which we could inherit our styles: Widget.AppCompat.Button. Sure, there's Widget.AppCompat.Light.ActionButton, but that doesn't actually inherit from Widget.ActionButton, which does not inherit from Widget.Button, so we might get some unexpected behavior using that as our base button style, mainly because Widget.ActionButton strictly belongs in the ActionBar.

So, if we want to have a decently normal default button style related to AppCompat, we need to make it ourselves. Let's start by digging into the Android SDK to see how it's doing default styles.

Digging In

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.provider.Settings;
import android.view.inputmethod.InputMethodManager;
public class AppUtils {
public static void hideKeyboard(Activity context) {
try {
@abhinav272
abhinav272 / CustomApiCallback.java
Created August 25, 2018 13:23
MediatorLiveData for retrofit response
import android.arch.lifecycle.MediatorLiveData;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.Observer;
import com.abhinav.basemvvmsample.data.model.FailureResponse;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import retrofit2.Call;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
public abstract class EndlessRecyclerVScrollListener 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
import android.graphics.BitmapFactory;
//Not thread safe
public class SizeFromImage implements ISize {
private String path;
private int width;
private int height;
public SizeFromImage(String path) {
this.path = path;