Java tutorial
/* * 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.rabross.android.minecraftskinwidget; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; /** * 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> */ public class InstructionPageFragment extends android.support.v4.app.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 = -1; private ImageView mImageView; private TextView mTextView; private Bitmap bitmap; /** * Factory method for this fragment class. Constructs a new fragment for the * given page number. */ public static android.support.v4.app.Fragment create(int pageNumber) { android.support.v4.app.Fragment fragment = new InstructionPageFragment(); Bundle args = new Bundle(); args.putInt(ARG_PAGE, pageNumber); fragment.setArguments(args); return fragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPageNumber = getArguments().getInt(ARG_PAGE); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_screen_slide_page, container, false); mTextView = (TextView) rootView.findViewById(R.id.instructions_text); mImageView = (ImageView) rootView.findViewById(R.id.instructions_image); setImage(mPageNumber); return rootView; } // ((BitmapDrawable) mImageView.getDrawable()).getBitmap().recycle(); public InstructionPageFragment() { } private void setImage(int pageNumber) { if (mTextView == null || mImageView == null) { return; } switch (pageNumber) { case 0: mTextView.setText(R.string.instructions); mTextView.setVisibility(View.VISIBLE); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.skinpreview); mImageView.setImageBitmap(bitmap); break; case 1: mImageView.setImageResource(R.drawable.screen1); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.screen1); mImageView.setImageBitmap(bitmap); break; case 2: mImageView.setImageResource(R.drawable.screen2); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.screen2); mImageView.setImageBitmap(bitmap); break; case 3: mImageView.setImageResource(R.drawable.screen3); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.screen3); mImageView.setImageBitmap(bitmap); break; case 4: mImageView.setImageResource(R.drawable.screen4); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.screen4); mImageView.setImageBitmap(bitmap); break; case 5: mImageView.setImageResource(R.drawable.screen5); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.screen5); mImageView.setImageBitmap(bitmap); break; case 6: mImageView.setImageResource(R.drawable.screen6); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.screen6); mImageView.setImageBitmap(bitmap); break; case 7: mImageView.setImageResource(R.drawable.screen7); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.screen7); mImageView.setImageBitmap(bitmap); break; case 8: mImageView.setImageResource(R.drawable.screen8); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.screen8); mImageView.setImageBitmap(bitmap); break; } } }