Skip to content

Instantly share code, notes, and snippets.

View rezaiyan's full-sized avatar
👋

Ali Rezaiyan rezaiyan

👋
View GitHub Profile
@rezaiyan
rezaiyan / CustomTabLayoutAnim
Last active September 19, 2017 03:42
Animate tabs of Tablayout with add or removing tabs programmatically
private void addTab(TextView tv) {
View v = tab.getCustomView();
if (v instanceof TextView) {
tv.setScaleX(0f);
tv.setScaleY(0f);
tv.animate()
.scaleX(1f)
.scaleY(1f)
.setInterpolator(new FastOutSlowInInterpolator())
.setDuration(450)
@rezaiyan
rezaiyan / HidingScrollListener
Created September 18, 2017 10:01
hide show view with scrolling recyclerview
package com.daimajia.slider.library;
import android.support.v7.widget.RecyclerView;
/**
* Created by Rezaiyan on 9/18/2017.
*/
public abstract class HidingScrollListener extends RecyclerView.OnScrollListener {
private static final int HIDE_THRESHOLD = 20;
@rezaiyan
rezaiyan / CustomToast
Created September 18, 2017 10:02
Custom Toast
public class CustomToast {
public static void showToast(Context context,String message) {
Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 3, toast.getYOffset() / 3);
TextView textView = new TextView(context);
textView.setBackgroundColor(Color.DKGRAY);
textView.setTextColor(Color.WHITE);
textView.setTypeface(FontManager.Iransens(context));
@rezaiyan
rezaiyan / ViewTransaction
Last active September 18, 2017 10:22
View transaction
//Start View
Intent intent = new Intent(context, SearchActivity.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ActivityOptions options = ActivityOptions.
makeSceneTransitionAnimation(getActivity(), v, "transition");
startActivity(intent, options.toBundle());
}else
startActivity(intent);
//End View
@rezaiyan
rezaiyan / SearchFragment.java
Last active October 2, 2017 05:22
Endless recyclerview with two methodlogy
//Old endless recyclerview methodology
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
visibleItemCount = recyclerView.getChildCount();
totalItemCount = gridLayoutManager.getItemCount();
firstVisibleItem = gridLayoutManager.findFirstVisibleItemPosition();
if (loading) {
@rezaiyan
rezaiyan / MoviesListingAdapter.java
Created October 2, 2017 06:43
Load image with glide sample
Glide.with(context).load(Api.getPosterPath(holder.movie.getPosterPath()))
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.RESULT)
.into(new BitmapImageViewTarget(holder.poster)
{
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim)
{
super.onResourceReady(bitmap, anim);
@rezaiyan
rezaiyan / ItemAnimatorAdpater.java
Created October 3, 2017 06:31
Set animation to items list
private int lastPosition = 0;
private void setAnimation(View viewToAnimate, int position) {
if (position > lastPosition) {
Animation animation = AnimationUtils.loadAnimation(context, R.anim.fadei_list);
viewToAnimate.startAnimation(animation);
lastPosition = position;
}
}
@rezaiyan
rezaiyan / AlertBuilder.java
Created October 28, 2017 08:21
This is AlertDialogBuilder with abstaction that can decrease boilerplate
public abstract class AlertBuilder {
public abstract void ok();
public AlertDialog.Builder create(Context context, String message) {
final AlertDialog.Builder builder;
builder = new AlertDialog.Builder(context);
builder.setMessage(message)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

Keybase proof

I hereby claim:

  • I am rezaiyan on github.
  • I am rezaiyan (https://keybase.io/rezaiyan) on keybase.
  • I have a public key ASCIL3cT6Mr4wkhTVwCcwM3APTtPGesOSSBd3sMDra_Znwo

To claim this, I am signing this object:

package ir.parvazyab.android.common.cache;
import android.content.SharedPreferences;
import java.util.Set;
import javax.inject.Inject;
/**