Android Open Source - Tacere Tutorial Activity






From Project

Back to project page Tacere.

License

The source code is released under:

MIT License

If you think the Android project Tacere 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

/*
 * Copyright (c) 2014 Jonathan Nelson/*from ww  w  . j av a2s  .  c om*/
 * Released under the BSD license.  For details see the COPYING file.
 */

package org.ciasaboark.tacere.activity;

/**
 * Created by Jonathan Nelson on 9/27/14.
 */

import android.os.Bundle;
import android.support.v4.app.Fragment;
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 android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.viewpagerindicator.CirclePageIndicator;

import org.ciasaboark.tacere.R;
import org.ciasaboark.tacere.activity.fragment.TutorialCrashReporterFragment;
import org.ciasaboark.tacere.activity.fragment.TutorialEventListFragment;
import org.ciasaboark.tacere.activity.fragment.TutorialProVersionFragment;
import org.ciasaboark.tacere.activity.fragment.TutorialRingerPriorityFragment;
import org.ciasaboark.tacere.activity.fragment.TutorialWelcomeFragment;
import org.ciasaboark.tacere.manager.AlarmManagerWrapper;
import org.ciasaboark.tacere.service.RequestTypes;

public class TutorialActivity extends ActionBarActivity {
    private static final String TAG = "TutorialActivity";
    private static final int TOTAL_PAGES = 5;
    private ViewPager viewPager;
    private PagerAdapter pagerAdapter;
    private int currentPage = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        android.support.v7.app.ActionBar actionBar = getSupportActionBar();
        if (actionBar == null) {
            Log.w(TAG, "could not get reference to actionbar, can not hide.");
        } else {
            actionBar.hide();
        }

        setContentView(R.layout.activity_tutorial);

        // Instantiate a ViewPager and a PagerAdapter.
        viewPager = (ViewPager) findViewById(R.id.pager);
        pagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(pagerAdapter);
        viewPager.setPageTransformer(true, new ZoomOutPageTransformer());
        viewPager.setOffscreenPageLimit(5);

        final Button skipButton = (Button) findViewById(R.id.tutorial_button_skip);
        skipButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });


        final CirclePageIndicator pageIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
        pageIndicator.setViewPager(viewPager);
        pageIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i2) {
                //nothing to do here
            }

            @Override
            public void onPageSelected(int pageSelected) {
                int pageAdapterCount = pagerAdapter.getCount() - 1;
                if (pageSelected == pageAdapterCount) {
                    Button nextButton = (Button) findViewById(R.id.tutorial_button_next);
                    if (nextButton != null) {
                        nextButton.setText("Done");
                        nextButton.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                finish();
                            }
                        });
                    }

                    Button skipButton = (Button) findViewById(R.id.tutorial_button_skip);
                    if (skipButton != null) {
                        skipButton.setVisibility(View.GONE);
                    }
                }
            }

            @Override
            public void onPageScrollStateChanged(int i) {
                //nothing to do here
            }
        });
        final Button nextButton = (Button) findViewById(R.id.tutorial_button_next);
        nextButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int curPage = viewPager.getCurrentItem();
                pageIndicator.setCurrentItem(curPage + 1);
            }
        });
    }

    @Override
    protected void onStop() {
        super.onStop();
        AlarmManagerWrapper alarmManagerWrapper = new AlarmManagerWrapper(this);
        alarmManagerWrapper.scheduleImmediateAlarm(RequestTypes.NORMAL);
    }

    @Override
    public void onBackPressed() {
        if (viewPager.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.
            viewPager.setCurrentItem(viewPager.getCurrentItem() - 1);
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        currentPage = viewPager.getCurrentItem();
    }

    @Override
    protected void onStart() {
        super.onStart();
        viewPager.setCurrentItem(currentPage);
    }

    private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
        public ScreenSlidePagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            Fragment pageFragment;
            switch (position) {
                case 0:
                    pageFragment = new TutorialWelcomeFragment();
                    break;
                case 1:
                    pageFragment = new TutorialEventListFragment();
                    break;
                case 2:
                    pageFragment = new TutorialRingerPriorityFragment();
                    break;
                case 3:
                    pageFragment = new TutorialProVersionFragment();
                    break;
                case 4:
                    pageFragment = new TutorialCrashReporterFragment();
                    break;
                default:
                    pageFragment = new Fragment();
            }

            return pageFragment;
        }

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


    private class ZoomOutPageTransformer implements ViewPager.PageTransformer {
        private static final float MIN_SCALE = 0.85f;
        private static final float MIN_ALPHA = 0.5f;

        public void transformPage(View view, float position) {
            int pageWidth = view.getWidth();
            int pageHeight = view.getHeight();

            if (position < -1) { // [-Infinity,-1)
                // This page is way off-screen to the left.
                view.setAlpha(0);

            } else if (position <= 1) { // [-1,1]
                // Modify the default slide transition to shrink the page as well
                float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
                float vertMargin = pageHeight * (1 - scaleFactor) / 2;
                float horzMargin = pageWidth * (1 - scaleFactor) / 2;
                if (position < 0) {
                    view.setTranslationX(horzMargin - vertMargin / 2);
                } else {
                    view.setTranslationX(-horzMargin + vertMargin / 2);
                }

                // Scale the page down (between MIN_SCALE and 1)
                view.setScaleX(scaleFactor);
                view.setScaleY(scaleFactor);

                // Fade the page relative to its size.
                view.setAlpha(MIN_ALPHA +
                        (scaleFactor - MIN_SCALE) /
                                (1 - MIN_SCALE) * (1 - MIN_ALPHA));

            } else { // (1,+Infinity]
                // This page is way off-screen to the right.
                view.setAlpha(0);
            }
        }
    }

    private class FadePageTransformer implements ViewPager.PageTransformer {
        private static final String TAG = "FadePageTransformer";

        public void transformPage(View view, float position) {
            Log.d(TAG, "position: " + position);
            int pageWidth = view.getWidth();
            if (position <= -1 || position >= 1) {
                //this page is off-screen
                view.setVisibility(View.GONE);
            } else { // [-1,0]
                //this page is comming into view, or fading out
                view.setVisibility(View.VISIBLE);
                //keep the page centered while fading in/out
                view.setTranslationX(pageWidth * -position);
                view.setAlpha(1 - Math.abs(position));

            }

        }
    }
}




Java Source Code List

.EventInstanceTest.java
com.viewpagerindicator.BuildConfig.java
com.viewpagerindicator.BuildConfig.java
com.viewpagerindicator.CirclePageIndicator.java
com.viewpagerindicator.IconPageIndicator.java
com.viewpagerindicator.IconPagerAdapter.java
com.viewpagerindicator.IcsLinearLayout.java
com.viewpagerindicator.LinePageIndicator.java
com.viewpagerindicator.PageIndicator.java
com.viewpagerindicator.TabPageIndicator.java
com.viewpagerindicator.TitlePageIndicator.java
com.viewpagerindicator.UnderlinePageIndicator.java
org.ciasaboark.tacere.ApplicationTest.java
org.ciasaboark.tacere.Tacere.java
org.ciasaboark.tacere.activity.AboutActivity.java
org.ciasaboark.tacere.activity.AboutLicenseActivity.java
org.ciasaboark.tacere.activity.AdvancedSettingsActivity.java
org.ciasaboark.tacere.activity.BetaReleaseActivity.java
org.ciasaboark.tacere.activity.BetaSettingsActivity.java
org.ciasaboark.tacere.activity.BugReportActivity.java
org.ciasaboark.tacere.activity.DonationActivityTest.java
org.ciasaboark.tacere.activity.LicenseCheckWrapper.java
org.ciasaboark.tacere.activity.MainActivity.java
org.ciasaboark.tacere.activity.ProUpgradeActivity.java
org.ciasaboark.tacere.activity.SelectCalendarsActivity.java
org.ciasaboark.tacere.activity.SettingsActivity.java
org.ciasaboark.tacere.activity.ShowUpdatesActivity.java
org.ciasaboark.tacere.activity.TutorialActivity.java
org.ciasaboark.tacere.activity.fragment.AdvancedSettingsFragment.java
org.ciasaboark.tacere.activity.fragment.BetaSettingsFragment.java
org.ciasaboark.tacere.activity.fragment.EventDetailsFragment.java
org.ciasaboark.tacere.activity.fragment.MainSettingsFragment.java
org.ciasaboark.tacere.activity.fragment.SelectCalendarsFragment.java
org.ciasaboark.tacere.activity.fragment.TutorialCrashReporterFragment.java
org.ciasaboark.tacere.activity.fragment.TutorialEndFragment.java
org.ciasaboark.tacere.activity.fragment.TutorialEventListFragment.java
org.ciasaboark.tacere.activity.fragment.TutorialProVersionFragment.java
org.ciasaboark.tacere.activity.fragment.TutorialRingerPriorityFragment.java
org.ciasaboark.tacere.activity.fragment.TutorialWelcomeFragment.java
org.ciasaboark.tacere.adapter.EventCursorAdapter.java
org.ciasaboark.tacere.billing.Authenticator.java
org.ciasaboark.tacere.billing.google.Base64DecoderException.java
org.ciasaboark.tacere.billing.google.Base64.java
org.ciasaboark.tacere.billing.google.IabException.java
org.ciasaboark.tacere.billing.google.IabHelper.java
org.ciasaboark.tacere.billing.google.IabResult.java
org.ciasaboark.tacere.billing.google.Inventory.java
org.ciasaboark.tacere.billing.google.Purchase.java
org.ciasaboark.tacere.billing.google.Security.java
org.ciasaboark.tacere.billing.google.SkuDetails.java
org.ciasaboark.tacere.bug.CrashReportManager.java
org.ciasaboark.tacere.converter.DateConverterTest.java
org.ciasaboark.tacere.converter.DateConverter.java
org.ciasaboark.tacere.converter.TimeConverter.java
org.ciasaboark.tacere.database.Columns.java
org.ciasaboark.tacere.database.DataSetManager.java
org.ciasaboark.tacere.database.DatabaseInterface.java
org.ciasaboark.tacere.database.EventDatabaseOpenHelper.java
org.ciasaboark.tacere.database.NoSuchEventInstanceException.java
org.ciasaboark.tacere.database.TooltipManager.java
org.ciasaboark.tacere.event.Calendar.java
org.ciasaboark.tacere.event.EventInstance.java
org.ciasaboark.tacere.event.EventManager.java
org.ciasaboark.tacere.event.ringer.Intervals.java
org.ciasaboark.tacere.event.ringer.RingerSource.java
org.ciasaboark.tacere.event.ringer.RingerType.java
org.ciasaboark.tacere.key.ApplicationTest.java
org.ciasaboark.tacere.key.MainActivity.java
org.ciasaboark.tacere.manager.AlarmManagerWrapper.java
org.ciasaboark.tacere.manager.NotificationManagerWrapper.java
org.ciasaboark.tacere.manager.RingerStateManager.java
org.ciasaboark.tacere.manager.ServiceStateManager.java
org.ciasaboark.tacere.manager.VolumesManager.java
org.ciasaboark.tacere.notifier.WidgetNotifier.java
org.ciasaboark.tacere.prefs.BetaPrefs.java
org.ciasaboark.tacere.prefs.DefaultPrefs.java
org.ciasaboark.tacere.prefs.PrefsTest.java
org.ciasaboark.tacere.prefs.Prefs.java
org.ciasaboark.tacere.prefs.Updates.java
org.ciasaboark.tacere.receiver.BootCompletedReceiver.java
org.ciasaboark.tacere.receiver.ProviderChangedReceiver.java
org.ciasaboark.tacere.service.EventSilencerService.java
org.ciasaboark.tacere.service.ExtendEventService.java
org.ciasaboark.tacere.service.ExtendQuicksilenceService.java
org.ciasaboark.tacere.service.RequestTypes.java
org.ciasaboark.tacere.service.ResetEventServiceTest.java
org.ciasaboark.tacere.service.ResetEventService.java
org.ciasaboark.tacere.service.SkipEventService.java
org.ciasaboark.tacere.versioning.Versioning.java
org.ciasaboark.tacere.view.EventListItem.java
org.ciasaboark.tacere.widget.ActiveEventWidgetProvider.java
org.ciasaboark.tacere.widget.EventListWidgetProvider.java
org.ciasaboark.tacere.widget.QuickSilenceTinyWidgetProvider.java
org.ciasaboark.tacere.widget.QuickSilenceWidgetProvider.java
org.ciasaboark.tacere.widget.activity.WidgetPopupRinger.java
org.ciasaboark.tacere.widget.adapter.WidgetEventListAdapter.java
org.ciasaboark.tacere.widget.service.WidgetService.java