Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package appisode.gepro;
- /**
- * @author Tobias
- */
- import java.util.ArrayList;
- import java.util.List;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.ViewGroup;
- import android.widget.Button;
- import android.widget.ViewFlipper;
- public abstract class SplashActivity extends Activity {
- private ViewFlipper flipper = null;
- private Button prev = null;
- private Button next = null;
- private int currentPos = 0;
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(null);
- setContentView(R.layout.general_splash);
- viewHolder = new ArrayList<View[]>(getCount());
- flipper = (ViewFlipper) findViewById(R.id.splashFlipper);
- prev = (Button) findViewById(R.id.prev);
- next = (Button) findViewById(R.id.next);
- for(int i = 0; i < getCount(); i++) {
- View v = getLayoutInflater().inflate(getLayout(i), null);
- flipper.addView(v);
- viewHolder.add(create(i, (ViewGroup) v));
- if(savedInstanceState != null) {
- Bundle b = savedInstanceState.getBundle("screen"+i);
- if(b != null) {
- restore(i, viewHolder.get(i), b);
- }
- }
- }
- flipper.setDisplayedChild(0);
- prev.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- if(currentPos > 0) {
- if(move(currentPos, currentPos-1)) {
- return;
- }
- prev.setText(R.string.back);
- next.setText(R.string.fwd);
- next.setVisibility(View.VISIBLE);
- currentPos--;
- if(currentPos == 0) {
- prev.setVisibility(View.INVISIBLE);
- }
- flipper.setDisplayedChild(currentPos);
- moved(currentPos);
- }
- }
- });
- next.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- if(currentPos < getCount()-1) {
- if(move(currentPos, currentPos+1)) {
- return;
- }
- prev.setVisibility(View.VISIBLE);
- currentPos++;
- if(currentPos == getCount()-1) {
- next.setText(R.string.finish);
- }
- flipper.setDisplayedChild(currentPos);
- moved(currentPos);
- }
- else if(currentPos == getCount()-1) {
- onFinish();
- }
- }
- });
- }
- public void onSaveInstanceState(Bundle out) {
- for(int i = 0; i < getCount(); i++) {
- out.putBundle("screen"+i, save(i, viewHolder.get(i)));
- }
- }
- public ViewGroup getItem(int pos) {
- return (ViewGroup) flipper.getChildAt(pos);
- }
- private List<View[]> viewHolder = null;
- public abstract int getCount();
- public abstract int getLayout(int pos);
- public abstract View[] create(int pos, ViewGroup v);
- public abstract Bundle save(int pos, View[] holder);
- public abstract void restore(int pos, View[] holder, Bundle restore);
- public abstract void reset(int pos, ViewGroup v, View[] holder);
- public abstract boolean move(int current, int to);
- public abstract void moved(int pos);
- public abstract void onFinish();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement