|
| 1 | +package com.dvinfosys.WidgetsExample.Fragments; |
| 2 | + |
| 3 | +import android.graphics.Color; |
| 4 | +import android.os.Bundle; |
| 5 | +import android.support.annotation.NonNull; |
| 6 | +import android.support.annotation.Nullable; |
| 7 | +import android.support.v4.app.Fragment; |
| 8 | +import android.view.LayoutInflater; |
| 9 | +import android.view.View; |
| 10 | +import android.view.ViewGroup; |
| 11 | +import android.widget.Toast; |
| 12 | + |
| 13 | +import com.dvinfosys.WidgetsExample.R; |
| 14 | +import com.dvinfosys.widgets.paperonboarding.PaperOnboardingEngine; |
| 15 | +import com.dvinfosys.widgets.paperonboarding.PaperOnboardingPage; |
| 16 | +import com.dvinfosys.widgets.paperonboarding.listeners.PaperOnboardingOnChangeListener; |
| 17 | +import com.dvinfosys.widgets.paperonboarding.listeners.PaperOnboardingOnRightOutListener; |
| 18 | + |
| 19 | +import java.util.ArrayList; |
| 20 | + |
| 21 | +public class PaperOnboardingFragment extends Fragment { |
| 22 | + |
| 23 | + @Override |
| 24 | + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| 25 | + View v = inflater.inflate(R.layout.onboarding_main_layout, container, false); |
| 26 | + |
| 27 | + PaperOnboardingEngine engine = new PaperOnboardingEngine(v.findViewById(R.id.onboardingRootView), getDataForOnboarding(), getContext()); |
| 28 | + engine.setOnChangeListener(new PaperOnboardingOnChangeListener() { |
| 29 | + @Override |
| 30 | + public void onPageChanged(int oldElementIndex, int newElementIndex) { |
| 31 | + Toast.makeText(getContext(), "Swiped from " + oldElementIndex + " to " + newElementIndex, Toast.LENGTH_SHORT).show(); |
| 32 | + } |
| 33 | + }); |
| 34 | + |
| 35 | + engine.setOnRightOutListener(new PaperOnboardingOnRightOutListener() { |
| 36 | + @Override |
| 37 | + public void onRightOut() { |
| 38 | + // Probably here will be your exit action |
| 39 | + Toast.makeText(getContext(), "Swiped out right", Toast.LENGTH_SHORT).show(); |
| 40 | + } |
| 41 | + }); |
| 42 | + return v; |
| 43 | + } |
| 44 | + |
| 45 | + private ArrayList<PaperOnboardingPage> getDataForOnboarding() { |
| 46 | + // prepare data |
| 47 | + PaperOnboardingPage scr1 = new PaperOnboardingPage("Hotels", "All hotels and hostels are sorted by hospitality rating", |
| 48 | + Color.parseColor("#678FB4"), R.drawable.hotels, R.drawable.key); |
| 49 | + PaperOnboardingPage scr2 = new PaperOnboardingPage("Banks", "We carefully verify all banks before add them into the app", |
| 50 | + Color.parseColor("#65B0B4"), R.drawable.banks, R.drawable.wallet); |
| 51 | + PaperOnboardingPage scr3 = new PaperOnboardingPage("Stores", "All local stores are categorized for your convenience", |
| 52 | + Color.parseColor("#9B90BC"), R.drawable.stores, R.drawable.shopping_cart); |
| 53 | + |
| 54 | + ArrayList<PaperOnboardingPage> elements = new ArrayList<>(); |
| 55 | + elements.add(scr1); |
| 56 | + elements.add(scr2); |
| 57 | + elements.add(scr3); |
| 58 | + return elements; |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { |
| 63 | + super.onViewCreated(view, savedInstanceState); |
| 64 | + getActivity().setTitle("Paper On Boarding Example"); |
| 65 | + } |
| 66 | +} |
0 commit comments