Home | History | Annotate | Download | only in animationsdemo
      1 /*
      2  * Copyright 2012 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.animationsdemo;
     18 
     19 import android.app.Fragment;
     20 import android.os.Bundle;
     21 import android.view.LayoutInflater;
     22 import android.view.View;
     23 import android.view.ViewGroup;
     24 import android.widget.TextView;
     25 
     26 /**
     27  * A fragment representing a single step in a wizard. The fragment shows a dummy title indicating
     28  * the page number, along with some dummy text.
     29  *
     30  * <p>This class is used by the {@link CardFlipActivity} and {@link
     31  * ScreenSlideActivity} samples.</p>
     32  */
     33 public class ScreenSlidePageFragment extends Fragment {
     34     /**
     35      * The argument key for the page number this fragment represents.
     36      */
     37     public static final String ARG_PAGE = "page";
     38 
     39     /**
     40      * The fragment's page number, which is set to the argument value for {@link #ARG_PAGE}.
     41      */
     42     private int mPageNumber;
     43 
     44     /**
     45      * Factory method for this fragment class. Constructs a new fragment for the given page number.
     46      */
     47     public static ScreenSlidePageFragment create(int pageNumber) {
     48         ScreenSlidePageFragment fragment = new ScreenSlidePageFragment();
     49         Bundle args = new Bundle();
     50         args.putInt(ARG_PAGE, pageNumber);
     51         fragment.setArguments(args);
     52         return fragment;
     53     }
     54 
     55     public ScreenSlidePageFragment() {
     56     }
     57 
     58     @Override
     59     public void onCreate(Bundle savedInstanceState) {
     60         super.onCreate(savedInstanceState);
     61         mPageNumber = getArguments().getInt(ARG_PAGE);
     62     }
     63 
     64     @Override
     65     public View onCreateView(LayoutInflater inflater, ViewGroup container,
     66             Bundle savedInstanceState) {
     67         // Inflate the layout containing a title and body text.
     68         ViewGroup rootView = (ViewGroup) inflater
     69                 .inflate(R.layout.fragment_screen_slide_page, container, false);
     70 
     71         // Set the title view to show the page number.
     72         ((TextView) rootView.findViewById(android.R.id.text1)).setText(
     73                 getString(R.string.title_template_step, mPageNumber + 1));
     74 
     75         return rootView;
     76     }
     77 
     78     /**
     79      * Returns the page number represented by this fragment object.
     80      */
     81     public int getPageNumber() {
     82         return mPageNumber;
     83     }
     84 }
     85