Skip to content

Instantly share code, notes, and snippets.

View snadjafi's full-sized avatar

Shervin Nadjafi snadjafi

  • San Francisco, CA
View GitHub Profile
@snadjafi
snadjafi / RecyclerViewScrollManager.java
Last active February 21, 2017 05:38
observable ScrollListener
public class RecyclerViewScrollManager {
//region Variables
private int totalItemCount;
private int lastVisibleItem;
private final int visibleThreshold;
private final PublishRelay<Integer> relay;
private RecyclerView recyclerView;
@Nullable private RecyclerView.OnScrollListener scrollListener;
//endregion
@snadjafi
snadjafi / colors.xml
Created December 9, 2016 23:32
Hex Opacity Values
<resources>
<!--Hex Opacity Values:
100% — FF
99% — FC
98% — FA
97% — F7
96% — F5
95% — F2
94% — F0
public class Triple<F, S, T> {
public final F first;
public final S second;
public final T third;
private static <F, S, T> Triple<F, S, T> create(F first, S second, T third) {
return new Triple<>(first, second, third);
}
public Triple(F first, S second, T third) {
@snadjafi
snadjafi / ToStringConverterFactory.java
Created March 18, 2016 07:29
latest to string converter factory for retrofit 2.0
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;
<com.snad.loadingbutton.LoadingButton
    android:id="@+id/first"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#BE6E46"
    app:pbLoadingText="@string/loading"
    app:pbProgressColor="#F9D8FB"
    app:pbText="@string/click_me"
 app:pbTextColor="#8A4FFF"
@Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    findViewById(R.id.first).setOnClickListener(this);

    LoadingButton button = new LoadingButton(this);
    LoadingButton.ViewSwitcherFactory factory = new LoadingButton.ViewSwitcherFactory(this,
            getResources().getColor(android.R.color.white),
 44F,
@snadjafi
snadjafi / sample.java
Last active March 10, 2017 07:40
TreeObserver example
mView.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
int width = mView.getWidth();
int height = mView.getHeight();
if (mView.getViewTreeObserver().isAlive()) {
// remove this layout listener
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
@snadjafi
snadjafi / device.java
Created October 25, 2014 20:01
helper class to get device device info
public class Device {
public static final boolean GTE_HC = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
private static String emailAddress = null;
private static Boolean isTablet = null;
private static DisplayMetrics displayMetrics = null;
public static void onConfigurationChanged(Configuration newConfig) {
displayMetrics = new DisplayMetrics();
@snadjafi
snadjafi / savePhotoTask.java
Created October 12, 2014 22:46
flipping and save the photo if you take a photo using front camera
@Override protected PatientPhoto doInBackground(PatientPhoto... intakePhotos) {
PatientPhoto photo = intakePhotos[0];
File file = null;
if (photo != null) {
Matrix matrix = flip(new Matrix());
Bitmap bitmap = BitmapFactory.decodeByteArray(photo.getPhotoBytes(), 0, photo.getPhotoBytes().length);
Bitmap flipped = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
photo.setThumbnail(ThumbnailUtils.extractThumbnail(flipped, 250, 250));
@snadjafi
snadjafi / Api.java
Created September 28, 2014 23:21
android retrofit setup example
public final class Api {
//region Variables
private static final String API_HOST = Application.string(R.string.api_server);
private static final Object sLockObject = new Object();
private static Service sService = null;
static final int DISK_CACHE_SIZE = 50 * 1024 * 1024; // 50MB
//endregion