/*
* Copyright 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.parworks.mars.view.intro;
import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.parworks.mars.R;
import com.parworks.mars.utils.ImageHelper;
import com.parworks.mars.utils.Utilities;
/**
* A fragment representing a single step in a wizard. The fragment shows a dummy
* title indicating the page number, along with some dummy text.
*
* <p>
* This class is used by the {@link CardFlipActivity} and
* {@link ScreenSlideActivity} samples.
* </p>
*/
@SuppressLint("ValidFragment")
public class IntroFirstPageFragment extends Fragment {
/**
* The argument key for the page number this fragment represents.
*/
public static final String ARG_PAGE = "page";
/**
* The fragment's page number, which is set to the argument value for
* {@link #ARG_PAGE}.
*/
private int mPageNumber;
private FragmentActivity mContext;
private int mResId;
/**
* Factory method for this fragment class. Constructs a new fragment for the
* given page number.
*/
public static IntroFirstPageFragment create(int pageNumber, int resId) {
IntroFirstPageFragment fragment = new IntroFirstPageFragment(resId);
Bundle args = new Bundle();
args.putInt(ARG_PAGE, pageNumber);
fragment.setArguments(args);
return fragment;
}
public IntroFirstPageFragment() {
}
public IntroFirstPageFragment(int resId) {
mResId = resId;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this.getActivity();
mPageNumber = getArguments().getInt(ARG_PAGE);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_intro_first_page,
container, false);
Bitmap b = ImageHelper.getRoundedCornerBitmap(
BitmapFactory.decodeResource(mContext.getResources(), mResId),
Utilities.getDensityPixels(5, mContext));
ImageView mPageImageView = ((ImageView) rootView
.findViewById(R.id.introPageImageView));
mPageImageView.setImageBitmap(b);
return rootView;
}
/**
* Returns the page number represented by this fragment object.
*/
public int getPageNumber() {
return mPageNumber;
}
}