1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.example.android.slidingfragments;
18 
19 import android.animation.Animator;
20 import android.animation.AnimatorInflater;
21 import android.animation.AnimatorListenerAdapter;
22 import android.app.Fragment;
23 import android.os.Bundle;
24 import android.view.LayoutInflater;
25 import android.view.View;
26 import android.view.ViewGroup;
27 
28 public class TextFragment extends Fragment {
29 
30     View.OnClickListener clickListener;
31     OnTextFragmentAnimationEndListener mListener;
32 
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)33     public View onCreateView(LayoutInflater inflater, ViewGroup container,
34                              Bundle savedInstanceState) {
35         View view = inflater.inflate(R.layout.text_fragment, container, false);
36         view.setOnClickListener(clickListener);
37         return view;
38     }
39 
setClickListener(View.OnClickListener clickListener)40     public void setClickListener(View.OnClickListener clickListener) {
41         this.clickListener = clickListener;
42     }
43 
44     @Override
onCreateAnimator(int transit, boolean enter, int nextAnim)45     public Animator onCreateAnimator(int transit, boolean enter, int nextAnim)
46     {
47         int id = enter ? R.animator.slide_fragment_in : R.animator.slide_fragment_out;
48         final Animator anim = AnimatorInflater.loadAnimator(getActivity(), id);
49         if (enter) {
50             anim.addListener(new AnimatorListenerAdapter() {
51                 @Override
52                 public void onAnimationEnd(Animator animation) {
53                     mListener.onAnimationEnd();
54                 }
55             });
56         }
57         return anim;
58     }
59 
setOnTextFragmentAnimationEnd(OnTextFragmentAnimationEndListener listener)60     public void setOnTextFragmentAnimationEnd(OnTextFragmentAnimationEndListener listener)
61     {
62         mListener = listener;
63     }
64 
65 }
66