Example usage for android.view.animation AnimationUtils loadInterpolator

List of usage examples for android.view.animation AnimationUtils loadInterpolator

Introduction

In this page you can find the example usage for android.view.animation AnimationUtils loadInterpolator.

Prototype

public static Interpolator loadInterpolator(Context context, @AnimRes @InterpolatorRes int id)
        throws NotFoundException 

Source Link

Document

Loads an Interpolator object from a resource

Usage

From source file:com.ameron32.apps.tapnotes._trial.ui.CollapsingTitleLayout.java

public CollapsingTitleLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);/*  w w  w.  j  av a  2 s  .c  o  m*/

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingTitleLayout);

    mExpandedMarginLeft = mExpandedMarginRight = mExpandedMarginBottom = a
            .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMargin, 0);

    final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginStart)) {
        final int marginStart = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginStart,
                0);
        if (isRtl) {
            mExpandedMarginRight = marginStart;
        } else {
            mExpandedMarginLeft = marginStart;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginEnd)) {
        final int marginEnd = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginEnd, 0);
        if (isRtl) {
            mExpandedMarginLeft = marginEnd;
        } else {
            mExpandedMarginRight = marginEnd;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginBottom)) {
        mExpandedMarginBottom = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginBottom,
                0);
    }

    final int tp = a.getResourceId(R.styleable.CollapsingTitleLayout_android_textAppearance,
            android.R.style.TextAppearance);
    setTextAppearance(tp);

    if (a.hasValue(R.styleable.CollapsingTitleLayout_collapsedTextSize)) {
        mCollapsedTitleTextSize = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_collapsedTextSize,
                0);
    }

    mRequestedExpandedTitleTextSize = a
            .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedTextSize, mCollapsedTitleTextSize);

    final int interpolatorId = a.getResourceId(R.styleable.CollapsingTitleLayout_textSizeInterpolator,
            android.R.anim.accelerate_interpolator);
    mTextSizeInterpolator = AnimationUtils.loadInterpolator(context, interpolatorId);

    a.recycle();

    mToolbarContentBounds = new Rect();

    setWillNotDraw(false);
}

From source file:au.com.zacher.popularmovies.activity.layout.CollapsingTitleLayout.java

public CollapsingTitleLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    this.mTextPaint = new TextPaint();
    this.mTextPaint.setAntiAlias(true);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingTitleLayout);

    this.mExpandedMarginLeft = this.mExpandedMarginRight = this.mExpandedMarginBottom = a
            .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMargin, 0);

    final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginStart)) {
        final int marginStart = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginStart,
                0);/*from  w  w  w .j ava  2s.  c  o  m*/
        if (isRtl) {
            this.mExpandedMarginRight = marginStart;
        } else {
            this.mExpandedMarginLeft = marginStart;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginEnd)) {
        final int marginEnd = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginEnd, 0);
        if (isRtl) {
            this.mExpandedMarginLeft = marginEnd;
        } else {
            this.mExpandedMarginRight = marginEnd;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginBottom)) {
        this.mExpandedMarginBottom = a
                .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginBottom, 0);
    }

    final int tp = a.getResourceId(R.styleable.CollapsingTitleLayout_android_textAppearance,
            android.R.style.TextAppearance);
    this.setTextAppearance(tp);

    if (a.hasValue(R.styleable.CollapsingTitleLayout_collapsedTextSize)) {
        this.mCollapsedTitleTextSize = a
                .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_collapsedTextSize, 0);
    }

    this.mRequestedExpandedTitleTextSize = a.getDimensionPixelSize(
            R.styleable.CollapsingTitleLayout_expandedTextSize, this.mCollapsedTitleTextSize);

    final int interpolatorId = a.getResourceId(R.styleable.CollapsingTitleLayout_textSizeInterpolator,
            android.R.anim.accelerate_interpolator);
    this.mTextSizeInterpolator = AnimationUtils.loadInterpolator(context, interpolatorId);

    a.recycle();

    this.mToolbarContentBounds = new Rect();

    this.setWillNotDraw(false);
}

From source file:io.plaidapp.ui.SearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    ButterKnife.bind(this);
    setupSearchView();//  w  ww.j  ava 2 s .c o m
    auto = TransitionInflater.from(this).inflateTransition(R.transition.auto);

    dataManager = new SearchDataManager(this) {
        @Override
        public void onDataLoaded(List<? extends PlaidItem> data) {
            if (data != null && data.size() > 0) {
                if (results.getVisibility() != View.VISIBLE) {
                    TransitionManager.beginDelayedTransition(container, auto);
                    progress.setVisibility(View.GONE);
                    results.setVisibility(View.VISIBLE);
                    fab.setVisibility(View.VISIBLE);
                    fab.setAlpha(0.6f);
                    fab.setScaleX(0f);
                    fab.setScaleY(0f);
                    fab.animate().alpha(1f).scaleX(1f).scaleY(1f).setStartDelay(800L).setDuration(300L)
                            .setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                                    android.R.interpolator.linear_out_slow_in));
                }
                adapter.addAndResort(data);
            } else {
                TransitionManager.beginDelayedTransition(container, auto);
                progress.setVisibility(View.GONE);
                setNoResultsVisibility(View.VISIBLE);
            }
        }
    };
    adapter = new FeedAdapter(this, dataManager, PocketUtils.isPocketInstalled(this));
    results.setAdapter(adapter);
    GridLayoutManager layoutManager = new GridLayoutManager(this, columns);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            return position == adapter.getDataItemCount() ? columns : 1;
        }
    });
    results.setLayoutManager(layoutManager);
    results.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {
        @Override
        public void onLoadMore() {
            dataManager.loadMore();
        }
    });
    results.setHasFixedSize(true);
    results.addOnScrollListener(gridScroll);

    // extract the search icon's location passed from the launching activity, minus 4dp to
    // compensate for different paddings in the views
    searchBackDistanceX = getIntent().getIntExtra(EXTRA_MENU_LEFT, 0) - (int) TypedValue
            .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics());
    searchIconCenterX = getIntent().getIntExtra(EXTRA_MENU_CENTER_X, 0);

    // translate icon to match the launching screen then animate back into position
    searchBackContainer.setTranslationX(searchBackDistanceX);
    searchBackContainer.animate().translationX(0f).setDuration(650L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in));
    // transform from search icon to back icon
    AnimatedVectorDrawable searchToBack = (AnimatedVectorDrawable) ContextCompat.getDrawable(this,
            R.drawable.avd_search_to_back);
    searchBack.setImageDrawable(searchToBack);
    searchToBack.start();
    // for some reason the animation doesn't always finish (leaving a part arrow!?) so after
    // the animation set a static drawable. Also animation callbacks weren't added until API23
    // so using post delayed :(
    // TODO fix properly!!
    searchBack.postDelayed(new Runnable() {
        @Override
        public void run() {
            searchBack.setImageDrawable(
                    ContextCompat.getDrawable(SearchActivity.this, R.drawable.ic_arrow_back_padded));
        }
    }, 600);

    // fade in the other search chrome
    searchBackground.animate().alpha(1f).setDuration(300L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in));
    searchView.animate().alpha(1f).setStartDelay(400L).setDuration(400L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in))
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    searchView.requestFocus();
                    ImeUtils.showIme(searchView);
                }
            });

    // animate in a scrim over the content behind
    scrim.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            scrim.getViewTreeObserver().removeOnPreDrawListener(this);
            AnimatorSet showScrim = new AnimatorSet();
            showScrim.playTogether(
                    ViewAnimationUtils.createCircularReveal(scrim, searchIconCenterX,
                            searchBackground.getBottom(), 0,
                            (float) Math.hypot(searchBackDistanceX,
                                    scrim.getHeight() - searchBackground.getBottom())),
                    ObjectAnimator.ofArgb(scrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT,
                            ContextCompat.getColor(SearchActivity.this, R.color.scrim)));
            showScrim.setDuration(400L);
            showScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                    android.R.interpolator.linear_out_slow_in));
            showScrim.start();
            return false;
        }
    });
    onNewIntent(getIntent());
}

From source file:io.plaidapp.ui.SearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    ButterKnife.bind(this);
    setupSearchView();//from w w w . j  a  va  2  s.  c om
    auto = TransitionInflater.from(this).inflateTransition(R.transition.auto);

    dataManager = new SearchDataManager(this) {
        @Override
        public void onDataLoaded(List<? extends PlaidItem> data) {
            if (data != null && data.size() > 0) {
                if (results.getVisibility() != View.VISIBLE) {
                    TransitionManager.beginDelayedTransition(container, auto);
                    progress.setVisibility(View.GONE);
                    results.setVisibility(View.VISIBLE);
                    fab.setVisibility(View.VISIBLE);
                    fab.setAlpha(0.6f);
                    fab.setScaleX(0f);
                    fab.setScaleY(0f);
                    fab.animate().alpha(1f).scaleX(1f).scaleY(1f).setStartDelay(800L).setDuration(300L)
                            .setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                                    android.R.interpolator.linear_out_slow_in));
                }
                adapter.addAndResort(data);
            } else {
                TransitionManager.beginDelayedTransition(container, auto);
                progress.setVisibility(View.GONE);
                setNoResultsVisibility(View.VISIBLE);
            }
        }
    };
    adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this));
    results.setAdapter(adapter);
    GridLayoutManager layoutManager = new GridLayoutManager(this, columns);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            return adapter.getItemColumnSpan(position);
        }
    });
    results.setLayoutManager(layoutManager);
    results.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {
        @Override
        public void onLoadMore() {
            dataManager.loadMore();
        }
    });
    results.setHasFixedSize(true);
    results.addOnScrollListener(gridScroll);

    // extract the search icon's location passed from the launching activity, minus 4dp to
    // compensate for different paddings in the views
    searchBackDistanceX = getIntent().getIntExtra(EXTRA_MENU_LEFT, 0) - (int) TypedValue
            .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics());
    searchIconCenterX = getIntent().getIntExtra(EXTRA_MENU_CENTER_X, 0);

    // translate icon to match the launching screen then animate back into position
    searchBackContainer.setTranslationX(searchBackDistanceX);
    searchBackContainer.animate().translationX(0f).setDuration(650L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in));
    // transform from search icon to back icon
    AnimatedVectorDrawable searchToBack = (AnimatedVectorDrawable) ContextCompat.getDrawable(this,
            R.drawable.avd_search_to_back);
    searchBack.setImageDrawable(searchToBack);
    searchToBack.start();
    // for some reason the animation doesn't always finish (leaving a part arrow!?) so after
    // the animation set a static drawable. Also animation callbacks weren't added until API23
    // so using post delayed :(
    // TODO fix properly!!
    searchBack.postDelayed(new Runnable() {
        @Override
        public void run() {
            searchBack.setImageDrawable(
                    ContextCompat.getDrawable(SearchActivity.this, R.drawable.ic_arrow_back_padded));
        }
    }, 600L);

    // fade in the other search chrome
    searchBackground.animate().alpha(1f).setDuration(300L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in));
    searchView.animate().alpha(1f).setStartDelay(400L).setDuration(400L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in))
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    searchView.requestFocus();
                    ImeUtils.showIme(searchView);
                }
            });

    // animate in a scrim over the content behind
    scrim.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            scrim.getViewTreeObserver().removeOnPreDrawListener(this);
            AnimatorSet showScrim = new AnimatorSet();
            showScrim.playTogether(
                    ViewAnimationUtils.createCircularReveal(scrim, searchIconCenterX,
                            searchBackground.getBottom(), 0,
                            (float) Math.hypot(searchBackDistanceX,
                                    scrim.getHeight() - searchBackground.getBottom())),
                    ObjectAnimator.ofArgb(scrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT,
                            ContextCompat.getColor(SearchActivity.this, R.color.scrim)));
            showScrim.setDuration(400L);
            showScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                    android.R.interpolator.linear_out_slow_in));
            showScrim.start();
            return false;
        }
    });
    onNewIntent(getIntent());
}

From source file:de.cellular.lib.lightlib.ui.fragment.LLRequestingFragment.java

protected void startRotate3dAnimationIn() {
    // Initialize the animations.
    Display display = ((WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();/*from w ww .  j  a  v  a2  s.com*/

    int h2 = display.getHeight() / 2;
    int w2 = display.getWidth() / 2;

    Rotate3dAnimation outAnim = new Rotate3dAnimation(0, 90, w2, h2, 0.0f, false);
    outAnim.setDuration(FLIP_ANIMATION_DURATION_OUT);
    outAnim.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationStart(Animation _animation) {
        }

        @Override
        public void onAnimationRepeat(Animation _animation) {
        }

        @Override
        public void onAnimationEnd(Animation _animation) {
            if (getView() != null)
                getView().setVisibility(View.VISIBLE);
        }
    });
    Rotate3dAnimation inAnim = new Rotate3dAnimation(-90, 0, w2, h2, 0.0f, false);
    inAnim.setDuration(FLIP_ANIMATION_DURATION_IN);
    inAnim.setStartOffset(FLIP_ANIMATION_DURATION_OUT);
    inAnim.setInterpolator(
            AnimationUtils.loadInterpolator(getActivity(), android.R.anim.decelerate_interpolator));
    outAnim.setInterpolator(
            AnimationUtils.loadInterpolator(getActivity(), android.R.anim.accelerate_interpolator));

    if (getView() != null)
        getView().startAnimation(inAnim);
}

From source file:net.xpece.commons.android.widget.CollapsingTitleLayout.java

public CollapsingTitleLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);/*from  w w w . j av  a 2s .  c o m*/

    if (AndroidUtils.API_21) {
        Typeface tf = Typeface.create("sans-serif-medium", Typeface.NORMAL);
        mTextPaint.setTypeface(tf);
    } else {
        Typeface tf = Typeface.create("sans-serif", Typeface.NORMAL);
        mTextPaint.setTypeface(tf);
    }

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingTitleLayout);

    mExpandedMarginLeft = mExpandedMarginRight = mExpandedMarginBottom = a
            .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMargin, 0);

    final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginStart)) {
        final int marginStart = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginStart,
                0);
        if (isRtl) {
            mExpandedMarginRight = marginStart;
        } else {
            mExpandedMarginLeft = marginStart;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginEnd)) {
        final int marginEnd = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginEnd, 0);
        if (isRtl) {
            mExpandedMarginLeft = marginEnd;
        } else {
            mExpandedMarginRight = marginEnd;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginBottom)) {
        mExpandedMarginBottom = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginBottom,
                0);
    }

    final int tp = a.getResourceId(R.styleable.CollapsingTitleLayout_android_textAppearance,
            android.R.style.TextAppearance);
    setTextAppearance(tp);

    if (a.hasValue(R.styleable.CollapsingTitleLayout_collapsedTextSize)) {
        mCollapsedTitleTextSize = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_collapsedTextSize,
                0);
    }

    mRequestedExpandedTitleTextSize = a
            .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedTextSize, mCollapsedTitleTextSize);

    final int interpolatorId = a.getResourceId(R.styleable.CollapsingTitleLayout_textSizeInterpolator,
            android.R.anim.accelerate_interpolator);
    mTextSizeInterpolator = AnimationUtils.loadInterpolator(context, interpolatorId);

    a.recycle();

    mToolbarContentBounds = new Rect();

    setWillNotDraw(false);
}

From source file:io.plaidapp.ui.FilterAdapter.java

@Override
public FilterViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
    final FilterViewHolder holder = new FilterViewHolder(
            LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.filter_item, viewGroup, false));
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override//from   w w w  .  j  a  v  a2 s  . c o  m
        public void onClick(View v) {
            final int position = holder.getAdapterPosition();
            if (position == RecyclerView.NO_POSITION)
                return;
            final Source filter = filters.get(position);
            if (isAuthorisedDribbbleSource(filter)
                    && !DribbblePrefs.get(holder.itemView.getContext()).isLoggedIn()) {
                authoriser.requestDribbbleAuthorisation(holder.filterIcon, filter);
            } else {
                holder.itemView.setHasTransientState(true);
                ObjectAnimator fade = ObjectAnimator.ofInt(holder.filterIcon, ViewUtils.IMAGE_ALPHA,
                        filter.active ? FILTER_ICON_DISABLED_ALPHA : FILTER_ICON_ENABLED_ALPHA);
                fade.setDuration(300);
                fade.setInterpolator(AnimationUtils.loadInterpolator(holder.itemView.getContext(),
                        android.R.interpolator.fast_out_slow_in));
                fade.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        holder.itemView.setHasTransientState(false);
                    }
                });
                fade.start();
                filter.active = !filter.active;
                holder.filterName.setEnabled(filter.active);
                notifyItemChanged(position);
                SourceManager.updateSource(filter, holder.itemView.getContext());
                dispatchFiltersChanged(filter);
            }
        }
    });
    return holder;
}

From source file:com.android.mail.ui.TwoPaneLayout.java

public TwoPaneLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    final Resources res = getResources();

    // The conversation list might be visible now, depending on the layout: in portrait we
    // don't show the conversation list, but in landscape we do.  This information is stored
    // in the constants
    mListCollapsible = res.getBoolean(R.bool.list_collapsible);

    mSlideInterpolator = AnimationUtils.loadInterpolator(context, android.R.interpolator.decelerate_cubic);

    final int folderListWeight = res.getInteger(R.integer.folder_list_weight);
    final int convListWeight = res.getInteger(R.integer.conversation_list_weight);
    final int convViewWeight = res.getInteger(R.integer.conversation_view_weight);
    mFolderListWeight = (double) folderListWeight / (folderListWeight + convListWeight);
    mConversationListWeight = (double) convListWeight / (convListWeight + convViewWeight);

    mIsExpansiveLayout = res.getBoolean(R.bool.use_expansive_tablet_ui);
    mDrawerInitialSetupComplete = false;
}

From source file:io.plaidapp.ui.PostNewDesignerNewsStory.java

@Override
public void onBackPressed() {
    if (isShareIntent()) {
        bottomSheetContent.animate().translationY(bottomSheetContent.getHeight()).setDuration(160L)
                .setInterpolator(AnimationUtils.loadInterpolator(PostNewDesignerNewsStory.this,
                        android.R.interpolator.fast_out_linear_in))
                .setListener(new AnimatorListenerAdapter() {
                    @Override// w w  w  .  j ava2  s .  c o  m
                    public void onAnimationEnd(Animator animation) {
                        finishAfterTransition();
                    }
                });
    } else {
        super.onBackPressed();
    }
}

From source file:us.phyxsi.gameshelf.ui.SearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    ButterKnife.bind(this);
    setupSearchView();//from   w ww . ja v a2s.  c  o m
    auto = TransitionInflater.from(this).inflateTransition(R.transition.auto);

    dataManager = new SearchDataManager(this) {
        @Override
        public void onDataLoaded(List<? extends Boardgame> data) {
            if (data != null && data.size() > 0) {
                if (results.getVisibility() != View.VISIBLE) {
                    TransitionManager.beginDelayedTransition(container, auto);
                    progress.setVisibility(View.GONE);
                    results.setVisibility(View.VISIBLE);
                }
                adapter.addAndResort(data);
            } else {
                TransitionManager.beginDelayedTransition(container, auto);
                progress.setVisibility(View.GONE);
                setNoResultsVisibility(View.VISIBLE);
            }
        }
    };
    adapter = new FeedAdapter(this, SearchActivity.this, dataManager, columns);
    results.setAdapter(adapter);
    GridLayoutManager layoutManager = new GridLayoutManager(this, columns);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            return adapter.getItemColumnSpan(position);
        }
    });
    results.setLayoutManager(layoutManager);
    results.setHasFixedSize(true);

    // extract the search icon's location passed from the launching activity, minus 4dp to
    // compensate for different paddings in the views
    searchBackDistanceX = getIntent().getIntExtra(EXTRA_MENU_LEFT, 0) - (int) TypedValue
            .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics());
    searchIconCenterX = getIntent().getIntExtra(EXTRA_MENU_CENTER_X, 0);

    // translate icon to match the launching screen then animate back into position
    searchBackContainer.setTranslationX(searchBackDistanceX);
    searchBackContainer.animate().translationX(0f).setDuration(650L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in));
    // transform from search icon to back icon
    AnimatedVectorDrawable searchToBack = (AnimatedVectorDrawable) ContextCompat.getDrawable(this,
            R.drawable.avd_search_to_back);
    searchBack.setImageDrawable(searchToBack);
    searchToBack.start();
    // for some reason the animation doesn't always finish (leaving a part arrow!?) so after
    // the animation set a static drawable. Also animation callbacks weren't added until API23
    // so using post delayed :(
    // TODO fix properly!!
    searchBack.postDelayed(new Runnable() {
        @Override
        public void run() {
            searchBack.setImageDrawable(
                    ContextCompat.getDrawable(SearchActivity.this, R.drawable.ic_arrow_back_padded));
        }
    }, 600L);

    // fade in the other search chrome
    searchBackground.animate().alpha(1f).setDuration(300L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in));
    searchView.animate().alpha(1f).setStartDelay(400L).setDuration(400L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in))
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    searchView.requestFocus();
                    ImeUtils.showIme(searchView);
                }
            });

    // animate in a scrim over the content behind
    scrim.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            scrim.getViewTreeObserver().removeOnPreDrawListener(this);
            AnimatorSet showScrim = new AnimatorSet();
            showScrim.playTogether(
                    ViewAnimationUtils.createCircularReveal(scrim, searchIconCenterX,
                            searchBackground.getBottom(), 0,
                            (float) Math.hypot(searchBackDistanceX,
                                    scrim.getHeight() - searchBackground.getBottom())),
                    ObjectAnimator.ofArgb(scrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT,
                            ContextCompat.getColor(SearchActivity.this, R.color.scrim)));
            showScrim.setDuration(400L);
            showScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                    android.R.interpolator.linear_out_slow_in));
            showScrim.start();
            return false;
        }
    });
    onNewIntent(getIntent());
}