Android Open Source - amulet Task Instructions Activity






From Project

Back to project page amulet.

License

The source code is released under:

MIT License

If you think the Android project amulet listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package scamell.michael.amulet;
/*from www . ja v a2 s .c  o  m*/
/*
* Screen Slider Source : http://developer.android.com/training/animation/screen-slide.html
* */

import android.content.pm.ActivityInfo;
import android.media.AudioManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;

import java.util.ArrayList;
import java.util.List;


public class TaskInstructionsActivity extends FragmentActivity {

    /**
     * The number of pages for each task instruction
     */
    private static final int INSPECTION_TASK_NUM_PAGES = 4;
    private static final int SEQUENCE_TASK_NUM_PAGES = 5;

    /**
     * The pager widget, which handles animation and allows swiping horizontally to access previous
     * and next wizard steps.
     */
    private static ViewPager mPager;
    private final List<Fragment> fragmentList = new ArrayList<Fragment>();
    /**
     * The pager adapter, which provides the pages to the view pager widget.
     */
    private PagerAdapter mPagerAdapter;

    public static void setNull() {
        mPager.setAdapter(null);
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_task_instructions);

        setVolumeControlStream(AudioManager.STREAM_MUSIC);

        //lock to portrait for the duration of the instructions
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        String taskType = getIntent().getExtras().getString("task_type");

        //if this is their first time doing the task after logging in then show them instructions
        if (taskType.equals("inspection")) {
            fragmentList.add(0, new TasksFirstStartWelcomeFragment());
            fragmentList.add(1, new InspectionTaskInstructions1Fragment());
            fragmentList.add(2, new InspectionTaskInstructions2Fragment());

            Bundle args = new Bundle();
            args.putString("task_type", "inspection");
            Fragment lastTaskInstructionFragment = new LastTaskInstructionFragment() {
                @Override
                void onTaskStart() {
                    //closes the activity once started so user returns to main menu if back button
                    //is presses
                    finish();
                }
            };
            lastTaskInstructionFragment.setArguments(args);
            fragmentList.add(3, lastTaskInstructionFragment);
            mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager(), INSPECTION_TASK_NUM_PAGES);
        } else if (taskType.equals("sequence")) {
            fragmentList.add(0, new TasksFirstStartWelcomeFragment());
            fragmentList.add(1, new SequenceTaskInstruction1Fragment());
            fragmentList.add(2, new SequenceTaskInstruction2Fragment());
            fragmentList.add(3, new SequenceTaskInstruction3Fragment());

            //create bundle with which task is being started and send to the last taskInstructionFragment
            // to know which task to start
            Bundle args = new Bundle();
            args.putString("task_type", "sequence");
            Fragment lastTaskInstructionFragment = new LastTaskInstructionFragment() {
                @Override
                void onTaskStart() {
                    //closes the activity once started so user returns to main menu if back button
                    //is presses
                    finish();
                }
            };
            lastTaskInstructionFragment.setArguments(args);
            fragmentList.add(4, lastTaskInstructionFragment);

            mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager(), SEQUENCE_TASK_NUM_PAGES);
        }
        // Instantiate a ViewPager and a PagerAdapter.
        mPager = (ViewPager) findViewById(R.id.pager);
        mPager.setOffscreenPageLimit(3);
        mPager.setAdapter(mPagerAdapter);
    }

    @Override
    public void onBackPressed() {
        if (mPager.getCurrentItem() == 0) {
            // If the user is currently looking at the first step, allow the system to handle the
            // Back button. This calls finish() on this activity and pops the back stack.
            super.onBackPressed();
        } else {
            // Otherwise, select the previous step.
            mPager.setCurrentItem(mPager.getCurrentItem() - 1);
        }
    }

    /**
     * A simple pager adapter that represents 4 ScreenSlidePageFragment objects, in
     * sequence.
     */
    public class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {

        private final int numberOfPages;

        public ScreenSlidePagerAdapter(FragmentManager fm, int numberOfPages) {
            super(fm);
            this.numberOfPages = numberOfPages;
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return numberOfPages;
        }

    }
}




Java Source Code List

scamell.michael.amulet.AboutDialogFragment.java
scamell.michael.amulet.AccountDetailsFragment.java
scamell.michael.amulet.ChangePasswordDialogFragment.java
scamell.michael.amulet.CoolveticaTextView.java
scamell.michael.amulet.DateAndTime.java
scamell.michael.amulet.DrinkDiaryEntries.java
scamell.michael.amulet.DrinkDiaryEntryAdapter.java
scamell.michael.amulet.DrinkDiaryEntry.java
scamell.michael.amulet.DrinkDiaryFavouriteDrinksDialogFragment.java
scamell.michael.amulet.DrinkDiaryFragment.java
scamell.michael.amulet.ExampleDrinksDialogFragment.java
scamell.michael.amulet.FavouriteDrinkUtility.java
scamell.michael.amulet.HomeFragment.java
scamell.michael.amulet.InspectionTaskActivity.java
scamell.michael.amulet.InspectionTaskInstructions1Fragment.java
scamell.michael.amulet.InspectionTaskInstructions2Fragment.java
scamell.michael.amulet.LastTaskInstructionFragment.java
scamell.michael.amulet.LoginActivity.java
scamell.michael.amulet.LogoutDialogFragment.java
scamell.michael.amulet.MainActivity.java
scamell.michael.amulet.OnPostHttpData.java
scamell.michael.amulet.OnRetrieveHttpData.java
scamell.michael.amulet.PostHTTPDataAsync.java
scamell.michael.amulet.RegisterActivity.java
scamell.michael.amulet.ResumeTaskDialogFragment.java
scamell.michael.amulet.RetrieveHTTPDataAsync.java
scamell.michael.amulet.RetrieveHTTPData.java
scamell.michael.amulet.RetrieveTaskDataFromServer.java
scamell.michael.amulet.SaveDrinkDiaryUtility.java
scamell.michael.amulet.SendDrinkDiaryEntriesToServer.java
scamell.michael.amulet.SendDrinkDiaryEntryToServer.java
scamell.michael.amulet.SendTaskEntriesToServer.java
scamell.michael.amulet.SendTaskEntryToServer.java
scamell.michael.amulet.SequenceTaskActivity.java
scamell.michael.amulet.SequenceTaskInstruction1Fragment.java
scamell.michael.amulet.SequenceTaskInstruction2Fragment.java
scamell.michael.amulet.SequenceTaskInstruction3Fragment.java
scamell.michael.amulet.SharedPreferencesWrapper.java
scamell.michael.amulet.Sound.java
scamell.michael.amulet.TaskEntries.java
scamell.michael.amulet.TaskEntry.java
scamell.michael.amulet.TaskFinishFragment.java
scamell.michael.amulet.TaskInstructionsActivity.java
scamell.michael.amulet.TaskStartCountdownFragment.java
scamell.michael.amulet.TasksFirstStartWelcomeFragment.java
scamell.michael.amulet.TasksMenuFragment.java
scamell.michael.amulet.UnitCalculatorFavouriteDrinksDialogFragment.java
scamell.michael.amulet.UnitCalculatorFragment.java
scamell.michael.amulet.UnitCalculator.java