├── .gitattributes
├── .gitignore
├── README.md
├── header.png
├── library
├── AndroidManifest.xml
├── proguard-project.txt
├── project.properties
├── res
│ ├── drawable-xhdpi
│ │ ├── item_focused.9.png
│ │ └── item_pressed.9.png
│ ├── drawable
│ │ ├── done_backgrounds.xml
│ │ ├── review_backgrounds.xml
│ │ └── selectable_item_background.xml
│ ├── layout
│ │ ├── activity_wizard.xml
│ │ ├── activity_wizard_side.xml
│ │ ├── fragment_page.xml
│ │ ├── fragment_page_customer_info.xml
│ │ └── list_item_review.xml
│ ├── values-hdpi
│ │ └── dimens.xml
│ ├── values-land
│ │ └── dimens.xml
│ ├── values-xhdpi
│ │ └── dimens.xml
│ └── values
│ │ ├── attrs.xml
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
└── src
│ └── dev
│ └── dworks
│ └── libs
│ └── awizard
│ ├── WizardActivity.java
│ ├── WizardActivitySide.java
│ └── model
│ ├── PageFragmentCallbacks.java
│ ├── PageList.java
│ ├── PageTreeNode.java
│ ├── ReviewCallbacks.java
│ ├── ReviewItem.java
│ ├── WizardModel.java
│ ├── WizardModelCallbacks.java
│ ├── page
│ ├── BranchPage.java
│ ├── CustomerInfoPage.java
│ ├── DonePage.java
│ ├── ListChoicePage.java
│ ├── MultipleFixedChoicePage.java
│ ├── Page.java
│ ├── ReviewPage.java
│ └── SingleFixedChoicePage.java
│ └── ui
│ ├── CustomerInfoFragment.java
│ ├── DoneFragment.java
│ ├── MultipleChoiceFragment.java
│ ├── ReviewFragment.java
│ ├── SingleChoiceFragment.java
│ └── StepPagerStrip.java
└── sample
├── AndroidManifest.xml
├── libs
└── GoogleAdMobAdsSdk-6.4.1.jar
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ ├── card_black.9.png
│ ├── ic_launcher.png
│ ├── ic_menu_feedback.png
│ ├── ic_menu_github.png
│ ├── ic_menu_gplus.png
│ ├── ic_menu_rate.png
│ ├── ic_menu_support.png
│ └── ic_menu_twitter.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── drawable-xxxhdpi
│ └── ic_launcher.png
├── drawable
│ ├── dots.png
│ ├── dworks.png
│ ├── item_background.9.png
│ ├── logo_big.png
│ └── made_with_love.png
├── layout
│ ├── activity_about.xml
│ ├── activity_main.xml
│ ├── activity_wizard.xml
│ └── activity_wizard_side.xml
├── menu
│ ├── about.xml
│ ├── main.xml
│ └── order.xml
├── values-sw600dp
│ └── dimens.xml
├── values-sw720dp-land
│ └── dimens.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
└── values
│ ├── attrs.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── src
└── dev
│ └── dworks
│ └── libs
│ └── awizard
│ └── demo
│ ├── AboutActivity.java
│ ├── MainActivity.java
│ ├── OrderSideWizardActivity.java
│ ├── OrderWizardActivity.java
│ └── SandwichWizardModel.java
└── web_hi_res_512.png
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #Android generated
2 | bin
3 | gen
4 | lint.xml
5 |
6 | #Eclipse
7 | .project
8 | .classpath
9 | .settings
10 | .checkstyle
11 |
12 | #IntelliJ IDEA
13 | .idea
14 | *.iml
15 | *.ipr
16 | *.iws
17 | classes
18 | gen-external-apklibs
19 |
20 | #Maven
21 | target
22 | release.properties
23 | pom.xml.*
24 |
25 | #Ant
26 | build.xml
27 | ant.properties
28 | local.properties
29 | proguard.cfg
30 | proguard-project.txt
31 |
32 | #Other
33 | .DS_Store
34 | tmp
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | AWizard
2 | ==========
3 |
4 |
5 |
6 | 
7 |
8 | `AWizard` library can be used for creating wizards very easily. It's based of Roman Nurik's wizard pager (https://code.google.com/p/romannurik-code/source/browse/misc/wizardpager)
9 |
10 | You can use from out-of-box pages from the library or create your own pages easily. Review page and Done page can be placed any where.
11 |
12 | ## Sample App
13 |
14 | [](http://play.google.com/store/apps/details?id=dev.dworks.libs.awizard.demo)
15 |
16 |
17 | Developed By
18 | ============
19 |
20 | * Hari Krishna Dulipudi -
21 |
22 |
23 | License
24 | =======
25 |
26 | Copyright 2016 Hari Krishna Dulipudi
27 |
28 | Licensed under the Apache License, Version 2.0 (the "License");
29 | you may not use this file except in compliance with the License.
30 | You may obtain a copy of the License at
31 |
32 | http://www.apache.org/licenses/LICENSE-2.0
33 |
34 | Unless required by applicable law or agreed to in writing, software
35 | distributed under the License is distributed on an "AS IS" BASIS,
36 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37 | See the License for the specific language governing permissions and
38 | limitations under the License.
39 |
40 |
41 |
42 |
43 |
44 | [](https://bitdeli.com/free "Bitdeli Badge")
45 |
46 |
--------------------------------------------------------------------------------
/header.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/header.png
--------------------------------------------------------------------------------
/library/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/library/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/library/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 | android.library=true
16 | android.library.reference.1=../../../Android Development/Android Developement Studio/work/appcompat_v7
17 |
--------------------------------------------------------------------------------
/library/res/drawable-xhdpi/item_focused.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/library/res/drawable-xhdpi/item_focused.9.png
--------------------------------------------------------------------------------
/library/res/drawable-xhdpi/item_pressed.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/library/res/drawable-xhdpi/item_pressed.9.png
--------------------------------------------------------------------------------
/library/res/drawable/done_backgrounds.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/library/res/drawable/review_backgrounds.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/library/res/drawable/selectable_item_background.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/library/res/layout/activity_wizard.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
17 |
18 |
23 |
24 |
29 |
30 |
35 |
36 |
43 |
44 |
50 |
51 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/library/res/layout/activity_wizard_side.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
18 |
19 |
23 |
24 |
29 |
30 |
35 |
36 |
41 |
42 |
49 |
50 |
56 |
57 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/library/res/layout/fragment_page.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
13 |
14 |
--------------------------------------------------------------------------------
/library/res/layout/fragment_page_customer_info.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
11 |
12 |
16 |
17 |
20 |
21 |
29 |
30 |
33 |
34 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/library/res/layout/list_item_review.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
27 |
28 |
37 |
38 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/library/res/values-hdpi/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 25sp
5 |
--------------------------------------------------------------------------------
/library/res/values-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 25sp
5 | 40dp
--------------------------------------------------------------------------------
/library/res/values-xhdpi/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 32sp
5 |
--------------------------------------------------------------------------------
/library/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/library/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #4433b5e5
4 | #ff0099cc
5 | #ff669900
6 | #10000000
7 | #ff669900
8 | #ff0099cc
9 | #66000000
10 | #333333
11 | #28000000
12 |
13 |
--------------------------------------------------------------------------------
/library/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 32dp
4 | 3dp
5 | 4dp
6 |
7 | 3dp
8 | 32dp
9 | 4dp
10 |
11 | 10dp
12 | 10dp
13 | 48dp
14 |
15 | 25sp
16 | 48dp
17 |
--------------------------------------------------------------------------------
/library/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | Next
19 | Previous
20 | Submit
21 | Done
22 | Review
23 |
24 | Name
25 | Email
26 | e.g. Larry
27 | Optional
28 |
29 | Confirm?
30 | Confirm
31 |
32 |
--------------------------------------------------------------------------------
/library/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
13 |
14 |
19 |
20 |
25 |
26 |
39 |
40 |
51 |
52 |
57 |
58 |
68 |
69 |
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/WizardActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | * Copyright 2013 Hari Krishna Dulipudi
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dev.dworks.libs.awizard;
19 |
20 | import java.util.List;
21 |
22 | import android.os.Bundle;
23 | import android.support.v4.app.Fragment;
24 | import android.support.v4.app.FragmentManager;
25 | import android.support.v4.app.FragmentStatePagerAdapter;
26 | import android.support.v4.view.ViewPager;
27 | import android.support.v7.app.ActionBarActivity;
28 | import android.util.TypedValue;
29 | import android.view.View;
30 | import android.view.ViewGroup;
31 | import android.widget.Button;
32 | import dev.dworks.libs.awizard.model.PageFragmentCallbacks;
33 | import dev.dworks.libs.awizard.model.ReviewCallbacks;
34 | import dev.dworks.libs.awizard.model.WizardModel;
35 | import dev.dworks.libs.awizard.model.WizardModelCallbacks;
36 | import dev.dworks.libs.awizard.model.page.DonePage;
37 | import dev.dworks.libs.awizard.model.page.Page;
38 | import dev.dworks.libs.awizard.model.page.ReviewPage;
39 | import dev.dworks.libs.awizard.model.ui.StepPagerStrip;
40 |
41 | /**
42 | * @author HaKr
43 | *
44 | */
45 | public class WizardActivity extends ActionBarActivity implements
46 | PageFragmentCallbacks,
47 | ReviewCallbacks,
48 | WizardModelCallbacks {
49 | public static final int HORIZONTAL = 0;
50 | public static final int VERTICAL = 1;
51 |
52 | //The view pager for the wizard
53 | private ViewPager mPager;
54 | //FragmentStatePagerAdapter adapter for the wizard
55 | private PagerAdapter mPagerAdapter;
56 |
57 | //Set to true to edit data at review
58 | private boolean mEditingAfterReview;
59 |
60 | private String mReviewText = null;
61 | private String mDoneText = null;
62 |
63 | //The wizard model for the wizard
64 | protected WizardModel mWizardModel;
65 |
66 | private boolean mConsumePageSelectedEvent;
67 |
68 | //Next button in the wizard
69 | private Button mNextButton;
70 | //Previous button in the wizard
71 | private Button mPrevButton;
72 |
73 | private List mCurrentPageSequence;
74 | private StepPagerStrip mStepPagerStrip;
75 | private int mReviewPagePosition;
76 | private int mDonePagePosition;
77 | private int mOrientation = HORIZONTAL;
78 | private boolean mDataChanged = false;
79 |
80 | public void onCreate(Bundle savedInstanceState) {
81 | super.onCreate(savedInstanceState);
82 | setContentView(R.layout.activity_wizard);
83 |
84 | if (savedInstanceState != null) {
85 | mWizardModel.load(savedInstanceState.getBundle("model"));
86 | mDataChanged = savedInstanceState.getBoolean("dataChanged");
87 | }
88 | }
89 |
90 | private void ensureControls() {
91 | mPagerAdapter = new PagerAdapter(getSupportFragmentManager());
92 | mPager = (ViewPager) findViewById(R.id.pager);
93 | if (mPager == null) {
94 | throw new RuntimeException(
95 | "Your content must have a android.support.v4.view.ViewPager whose id attribute is " +
96 | "'R.id.pager'");
97 | }
98 | //mPager.setOrientation(mOrientation);
99 | mPager.setAdapter(mPagerAdapter);
100 | mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
101 | @Override
102 | public void onPageSelected(int position) {
103 | mStepPagerStrip.setCurrentPage(position);
104 |
105 | if (mConsumePageSelectedEvent) {
106 | mConsumePageSelectedEvent = false;
107 | return;
108 | }
109 |
110 | mEditingAfterReview = false;
111 | updateBottomBar();
112 | }
113 | });
114 |
115 | mStepPagerStrip = (StepPagerStrip) findViewById(R.id.strip);
116 | mStepPagerStrip.setOrientation(mOrientation);
117 | mStepPagerStrip.setOnPageSelectedListener(new StepPagerStrip.OnPageSelectedListener() {
118 | @Override
119 | public void onPageStripSelected(int position) {
120 | position = Math.min(mPagerAdapter.getCount() - 1, position);
121 | if (mPager.getCurrentItem() != position) {
122 | mPager.setCurrentItem(position);
123 | }
124 | }
125 | });
126 |
127 | mNextButton = (Button) findViewById(R.id.next_button);
128 | mNextButton.setOnClickListener(new View.OnClickListener() {
129 | @Override
130 | public void onClick(View view) {
131 | if (mPager.getCurrentItem() == mCurrentPageSequence.size() - 1) {
132 | onDoneClick();
133 | } else {
134 | if (mEditingAfterReview) {
135 | mPager.setCurrentItem(mReviewPagePosition);
136 | } else {
137 | if(mPager.getCurrentItem() == mReviewPagePosition){
138 | Page page = mCurrentPageSequence.get(mReviewPagePosition);
139 | page.getData().putBoolean(ReviewPage.PROCESS_DATA_KEY, true);
140 | page.notifyDataChanged();
141 | }
142 | mPager.setCurrentItem(mPager.getCurrentItem() + 1);
143 | }
144 | }
145 | }
146 | });
147 |
148 | mPrevButton = (Button) findViewById(R.id.prev_button);
149 | mPrevButton.setOnClickListener(new View.OnClickListener() {
150 | @Override
151 | public void onClick(View view) {
152 | mPager.setCurrentItem(mPager.getCurrentItem() - 1);
153 | }
154 | });
155 |
156 | mDonePagePosition = getDonePagePosition();
157 | mReviewPagePosition = getReviewPagePosition();
158 | mStepPagerStrip.setReviewPagePosition(mReviewPagePosition);
159 | mStepPagerStrip.setDonePagePosition(mDonePagePosition);;
160 | }
161 |
162 | /**
163 | * @param showReview the show review to set
164 | */
165 | public final void setReviewText(String finish) {
166 | this.mReviewText = finish;
167 | }
168 |
169 |
170 | /**
171 | * @param showReview the show review to set
172 | */
173 | public final void setDoneText(String finish) {
174 | this.mDoneText = finish;
175 | }
176 |
177 | /**
178 | * on Review next action
179 | */
180 | public void onConfirmClick() {
181 | finish();
182 | }
183 |
184 | /**
185 | * on Done next action
186 | */
187 | public void onDoneClick() {
188 | finish();
189 | }
190 |
191 | @Override
192 | public final void onPageTreeChanged() {
193 | mCurrentPageSequence = mWizardModel.getCurrentPageSequence();
194 | updatePagerStrip();
195 | mPagerAdapter.notifyDataSetChanged();
196 | updateBottomBar();
197 | }
198 |
199 | private void updatePagerStrip() {
200 | int pageCount = mCurrentPageSequence.size();
201 | recalculateCutOffPage();
202 | mStepPagerStrip.setPageCount(pageCount);
203 | mReviewPagePosition = getReviewPagePosition();
204 | mDonePagePosition = getDonePagePosition();
205 | mStepPagerStrip.setReviewPagePosition(mReviewPagePosition);
206 | mStepPagerStrip.setDonePagePosition(mDonePagePosition);;
207 | }
208 |
209 | private void updateBottomBar() {
210 | if(null == mNextButton || null == mPrevButton){
211 | return;
212 | }
213 | TypedValue v = new TypedValue();
214 | getTheme().resolveAttribute(android.R.attr.textAppearanceMedium, v, true);
215 | int position = mPager.getCurrentItem();
216 | if (position == mReviewPagePosition) {
217 | mReviewText = mReviewText != null ? mReviewText : getResources().getString(R.string.review_next);
218 | mNextButton.setText(mReviewText);
219 | mNextButton.setBackgroundResource(R.drawable.review_backgrounds);
220 | mNextButton.setTextAppearance(this, R.style.TextAppearanceFinish);
221 | }else if (position == mDonePagePosition) {
222 | mDoneText = mDoneText != null ? mDoneText : getResources().getString(R.string.done_next);
223 | mNextButton.setText(mDoneText);
224 | mNextButton.setBackgroundResource(R.drawable.done_backgrounds);
225 | mNextButton.setTextAppearance(this, R.style.TextAppearanceFinish);
226 | }else if (position == mCurrentPageSequence.size() - 1) {
227 | mNextButton.setText(R.string.done_next);
228 | if(mDonePagePosition != -1){
229 | mNextButton.setBackgroundResource(R.drawable.selectable_item_background);
230 | mNextButton.setTextAppearance(this, v.resourceId);
231 | }
232 | else{
233 | mNextButton.setBackgroundResource(R.drawable.done_backgrounds);
234 | mNextButton.setTextAppearance(this, R.style.TextAppearanceFinish);
235 | }
236 | }else {
237 | mNextButton.setText(mEditingAfterReview ? R.string.review : R.string.next);
238 | mNextButton.setBackgroundResource(R.drawable.selectable_item_background);
239 | mNextButton.setTextAppearance(this, v.resourceId);
240 | mPrevButton.setTextAppearance(this, v.resourceId);
241 | mNextButton.setEnabled(position != mPagerAdapter.getCutOffPage());
242 | }
243 |
244 | mPrevButton.setVisibility(position <= 0 ? View.INVISIBLE : View.VISIBLE);
245 | }
246 |
247 | @Override
248 | protected void onDestroy() {
249 | super.onDestroy();
250 | mWizardModel.unregisterListener(this);
251 | }
252 |
253 | @Override
254 | protected void onSaveInstanceState(Bundle outState) {
255 | super.onSaveInstanceState(outState);
256 | outState.putBundle("model", mWizardModel.save());
257 | outState.putBoolean("dataChanged", mDataChanged);
258 | }
259 |
260 | @Override
261 | public final WizardModel getWizardModel() {
262 | return mWizardModel;
263 | }
264 |
265 | public final void setWizardModel(WizardModel wizardModel) {
266 | mWizardModel = wizardModel;
267 | if (mWizardModel == null) {
268 | throw new RuntimeException("Wizard Model cannot be empty");
269 | }
270 |
271 | mWizardModel.registerListener(this);
272 | //TODO: Change in support lib causing null pointer
273 | mCurrentPageSequence = mWizardModel.getCurrentPageSequence();
274 |
275 | ensureControls();
276 | onPageTreeChanged();
277 | }
278 |
279 | public int getOrientation() {
280 | return mOrientation;
281 | }
282 |
283 | public void setOrientation(int orientation) {
284 | switch (orientation) {
285 | case HORIZONTAL:
286 | case VERTICAL:
287 | break;
288 |
289 | default:
290 | throw new IllegalArgumentException("Only HORIZONTAL and VERTICAL are valid orientations.");
291 | }
292 | mOrientation = orientation;
293 | if(null != mStepPagerStrip){
294 | mStepPagerStrip.setOrientation(mOrientation);
295 | }
296 | }
297 |
298 | @Override
299 | public final void onEditScreenAfterReview(String key) {
300 | for (int i = mCurrentPageSequence.size() - 1; i >= 0; i--) {
301 | if (mCurrentPageSequence.get(i).getKey().equals(key)) {
302 | mConsumePageSelectedEvent = true;
303 | mEditingAfterReview = true;
304 | mPager.setCurrentItem(i);
305 | updateBottomBar();
306 | break;
307 | }
308 | }
309 | }
310 |
311 | @Override
312 | public final void onPageDataChanged(Page page) {
313 | mDataChanged = true;
314 | if (page.isRequired()) {
315 | if (recalculateCutOffPage()) {
316 | mPagerAdapter.notifyDataSetChanged();
317 | updateBottomBar();
318 | }
319 | }
320 | }
321 |
322 | @Override
323 | public Page onGetPage(String key) {
324 | return mWizardModel.findByKey(key);
325 | }
326 |
327 | public boolean getDataChanged() {
328 | return mDataChanged;
329 | }
330 |
331 | private final int getReviewPagePosition() {
332 | int pagePosition = -1;
333 | for (int i = 0; i < mCurrentPageSequence.size(); i++) {
334 | Page page = mCurrentPageSequence.get(i);
335 | if (page instanceof ReviewPage) {
336 | pagePosition = i;
337 | break;
338 | }
339 | }
340 | return pagePosition;
341 | }
342 |
343 | private final int getDonePagePosition() {
344 | int pagePosition = -1;
345 | for (int i = 0; i < mCurrentPageSequence.size(); i++) {
346 | Page page = mCurrentPageSequence.get(i);
347 | if (page instanceof DonePage) {
348 | pagePosition = i;
349 | break;
350 | }
351 | }
352 | return pagePosition;
353 | }
354 |
355 | private final boolean recalculateCutOffPage() {
356 | // Cut off the pager adapter at first required page that isn't completed
357 | int cutOffPage = mCurrentPageSequence.size() + 1;
358 | for (int i = 0; i < mCurrentPageSequence.size(); i++) {
359 | Page page = mCurrentPageSequence.get(i);
360 | if (page.isRequired() && !page.isCompleted()) {
361 | cutOffPage = i;
362 | break;
363 | }
364 | }
365 |
366 | if (mPagerAdapter.getCutOffPage() != cutOffPage) {
367 | mPagerAdapter.setCutOffPage(cutOffPage);
368 | return true;
369 | }
370 |
371 | return false;
372 | }
373 |
374 | /*
375 | * Adapter for fragments
376 | * */
377 | private class PagerAdapter extends FragmentStatePagerAdapter {
378 | private int mCutOffPage;
379 | private Fragment mPrimaryItem;
380 |
381 | public PagerAdapter(FragmentManager fm) {
382 | super(fm);
383 | }
384 |
385 | @Override
386 | public Fragment getItem(int i) {
387 | /* if (i >= mCurrentPageSequence.size()) {
388 | return new ReviewFragment();
389 | }
390 | */
391 | return mCurrentPageSequence.get(i).createFragment();
392 | }
393 |
394 | @Override
395 | public int getItemPosition(Object object) {
396 | // TODO: be smarter about this
397 | if (object == mPrimaryItem) {
398 | // Re-use the current fragment (its position never changes)
399 | return POSITION_UNCHANGED;
400 | }
401 |
402 | return POSITION_NONE;
403 | }
404 |
405 | @Override
406 | public void setPrimaryItem(ViewGroup container, int position, Object object) {
407 | super.setPrimaryItem(container, position, object);
408 | mPrimaryItem = (Fragment) object;
409 | }
410 |
411 | @Override
412 | public int getCount() {
413 | if (mCurrentPageSequence == null) {
414 | return 0;
415 | }
416 | return Math.min(mCutOffPage + 1, mCurrentPageSequence.size() /* + 1 */);
417 | }
418 |
419 | public void setCutOffPage(int cutOffPage) {
420 | if (cutOffPage < 0) {
421 | cutOffPage = Integer.MAX_VALUE;
422 | }
423 | mCutOffPage = cutOffPage;
424 | }
425 |
426 | public int getCutOffPage() {
427 | return mCutOffPage;
428 | }
429 | }
430 | }
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/WizardActivitySide.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | * Copyright 2013 Hari Krishna Dulipudi
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dev.dworks.libs.awizard;
19 |
20 | import android.os.Bundle;
21 |
22 | public class WizardActivitySide extends WizardActivity {
23 |
24 | @Override
25 | public void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_wizard_side);
28 | setOrientation(VERTICAL);
29 | }
30 | }
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/PageFragmentCallbacks.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model;
18 |
19 | import dev.dworks.libs.awizard.model.page.Page;
20 |
21 |
22 | public interface PageFragmentCallbacks {
23 | Page onGetPage(String key);
24 | }
25 |
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/PageList.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model;
18 |
19 | import java.util.ArrayList;
20 |
21 | import dev.dworks.libs.awizard.model.page.Page;
22 |
23 |
24 | /**
25 | * Represents a list of wizard pages.
26 | */
27 | @SuppressWarnings("serial")
28 | public class PageList extends ArrayList implements PageTreeNode {
29 | public PageList(Page... pages) {
30 | for (Page page : pages) {
31 | add(page);
32 | }
33 | }
34 |
35 | @Override
36 | public Page findByKey(String key) {
37 | for (Page childPage : this) {
38 | Page found = childPage.findByKey(key);
39 | if (found != null) {
40 | return found;
41 | }
42 | }
43 |
44 | return null;
45 | }
46 |
47 | @Override
48 | public void flattenCurrentPageSequence(ArrayList dest) {
49 | for (Page childPage : this) {
50 | childPage.flattenCurrentPageSequence(dest);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/PageTreeNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model;
18 |
19 | import java.util.ArrayList;
20 |
21 | import dev.dworks.libs.awizard.model.page.Page;
22 |
23 |
24 | /**
25 | * Represents a node in the page tree. Can either be a single page, or a page container.
26 | */
27 | public interface PageTreeNode {
28 | public Page findByKey(String key);
29 | public void flattenCurrentPageSequence(ArrayList dest);
30 | }
31 |
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/ReviewCallbacks.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model;
18 |
19 | import dev.dworks.libs.awizard.model.page.Page;
20 | import dev.dworks.libs.awizard.model.ui.ReviewFragment;
21 |
22 |
23 | /**
24 | * Callback interface connecting {@link Page}, {@link ReviewFragment}, and wizard model container
25 | * objects (e.g. {@link dev.dworks.libs.awizard.wizard.WizardActivity}.
26 | */
27 | public interface ReviewCallbacks {
28 | WizardModel getWizardModel();
29 | void onEditScreenAfterReview(String pageKey);
30 | }
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/ReviewItem.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model;
18 |
19 | /**
20 | * Represents a single line item on the final review page.
21 | *
22 | * @see dev.dworks.libs.awizard.model.ui.ReviewFragment
23 | */
24 | public class ReviewItem {
25 | public static final int DEFAULT_WEIGHT = 0;
26 |
27 | private int mWeight;
28 | private String mTitle;
29 | private String mDisplayValue;
30 | private String mPageKey;
31 |
32 | public ReviewItem(String title, String displayValue, String pageKey) {
33 | this(title, displayValue, pageKey, DEFAULT_WEIGHT);
34 | }
35 |
36 | public ReviewItem(String title, String displayValue, String pageKey, int weight) {
37 | mTitle = title;
38 | mDisplayValue = displayValue;
39 | mPageKey = pageKey;
40 | mWeight = weight;
41 | }
42 |
43 | public String getDisplayValue() {
44 | return mDisplayValue;
45 | }
46 |
47 | public void setDisplayValue(String displayValue) {
48 | mDisplayValue = displayValue;
49 | }
50 |
51 | public String getPageKey() {
52 | return mPageKey;
53 | }
54 |
55 | public void setPageKey(String pageKey) {
56 | mPageKey = pageKey;
57 | }
58 |
59 | public String getTitle() {
60 | return mTitle;
61 | }
62 |
63 | public void setTitle(String title) {
64 | mTitle = title;
65 | }
66 |
67 | public int getWeight() {
68 | return mWeight;
69 | }
70 |
71 | public void setWeight(int weight) {
72 | mWeight = weight;
73 | }
74 | }
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/WizardModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import android.content.Context;
23 | import android.os.Bundle;
24 | import dev.dworks.libs.awizard.model.page.Page;
25 |
26 |
27 | /**
28 | * Represents a wizard model, including the pages/steps in the wizard, their dependencies, and their
29 | * currently populated choices/values/selections.
30 | *
31 | * To create an actual wizard model, extend this class and implement {@link #onNewRootPageList()}.
32 | */
33 | public abstract class WizardModel implements WizardModelCallbacks {
34 | protected Context mContext;
35 |
36 | private List mListeners = new ArrayList();
37 | private PageList mRootPageList;
38 |
39 | public WizardModel(Context context) {
40 | mRootPageList = onNewRootPageList();
41 | mContext = context;
42 | }
43 |
44 | /**
45 | * Override this to define a new wizard model.
46 | */
47 | protected abstract PageList onNewRootPageList();
48 |
49 | @Override
50 | public void onPageDataChanged(Page page) {
51 | // can't use for each because of concurrent modification (review fragment
52 | // can get added or removed and will register itself as a listener)
53 | for (int i = 0; i < mListeners.size(); i++) {
54 | mListeners.get(i).onPageDataChanged(page);
55 | }
56 | }
57 |
58 | @Override
59 | public void onPageTreeChanged() {
60 | // can't use for each because of concurrent modification (review fragment
61 | // can get added or removed and will register itself as a listener)
62 | for (int i = 0; i < mListeners.size(); i++) {
63 | mListeners.get(i).onPageTreeChanged();
64 | }
65 | }
66 |
67 | public Page findByKey(String key) {
68 | return mRootPageList.findByKey(key);
69 | }
70 |
71 | public void load(Bundle savedValues) {
72 | for (String key : savedValues.keySet()) {
73 | mRootPageList.findByKey(key).resetData(savedValues.getBundle(key));
74 | }
75 | }
76 |
77 | public void registerListener(WizardModelCallbacks listener) {
78 | mListeners.add(listener);
79 | }
80 |
81 | public Bundle save() {
82 | Bundle bundle = new Bundle();
83 | for (Page page : getCurrentPageSequence()) {
84 | bundle.putBundle(page.getKey(), page.getData());
85 | }
86 | return bundle;
87 | }
88 |
89 | public Bundle saveIntoSingle() {
90 | Bundle bundle = new Bundle();
91 | for (Page page : getCurrentPageSequence()) {
92 | bundle.putAll(page.getData());
93 | }
94 | return bundle;
95 | }
96 |
97 | /**
98 | * Gets the current list of wizard steps, flattening nested (dependent) pages based on the
99 | * user's choices.
100 | */
101 | public List getCurrentPageSequence() {
102 | ArrayList flattened = new ArrayList();
103 | mRootPageList.flattenCurrentPageSequence(flattened);
104 | return flattened;
105 | }
106 |
107 | public void unregisterListener(WizardModelCallbacks listener) {
108 | mListeners.remove(listener);
109 | }
110 | }
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/WizardModelCallbacks.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model;
18 |
19 | import dev.dworks.libs.awizard.model.page.Page;
20 |
21 |
22 | /**
23 | * Callback interface connecting {@link Page}, {@link WizardModel}, and model container
24 | * objects (e.g. {@link com.example.WizardActivity.wizardpager.MainActivity}.
25 | */
26 | public interface WizardModelCallbacks {
27 | void onPageDataChanged(Page page);
28 | void onPageTreeChanged();
29 | }
30 |
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/page/BranchPage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model.page;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import android.support.v4.app.Fragment;
23 | import android.text.TextUtils;
24 | import dev.dworks.libs.awizard.model.PageList;
25 | import dev.dworks.libs.awizard.model.ReviewItem;
26 | import dev.dworks.libs.awizard.model.WizardModelCallbacks;
27 | import dev.dworks.libs.awizard.model.ui.SingleChoiceFragment;
28 |
29 | /**
30 | * A page representing a branching point in the wizard. Depending on which choice is selected, the
31 | * next set of steps in the wizard may change.
32 | */
33 | public class BranchPage extends SingleFixedChoicePage {
34 | private List mBranches = new ArrayList();
35 |
36 | public BranchPage(WizardModelCallbacks callbacks, String title) {
37 | super(callbacks, title);
38 | }
39 |
40 | @Override
41 | public Page findByKey(String key) {
42 | if (getKey().equals(key)) {
43 | return this;
44 | }
45 |
46 | for (Branch branch : mBranches) {
47 | Page found = branch.childPageList.findByKey(key);
48 | if (found != null) {
49 | return found;
50 | }
51 | }
52 |
53 | return null;
54 | }
55 |
56 | @Override
57 | public void flattenCurrentPageSequence(ArrayList destination) {
58 | super.flattenCurrentPageSequence(destination);
59 | for (Branch branch : mBranches) {
60 | if (branch.choice.equals(mData.getString(Page.SIMPLE_DATA_KEY))) {
61 | branch.childPageList.flattenCurrentPageSequence(destination);
62 | break;
63 | }
64 | }
65 | }
66 |
67 | public BranchPage addBranch(String choice, Page... childPages) {
68 | PageList childPageList = new PageList(childPages);
69 | for (Page page : childPageList) {
70 | page.setParentKey(choice);
71 | }
72 | mBranches.add(new Branch(choice, childPageList));
73 | return this;
74 | }
75 |
76 | @Override
77 | public Fragment createFragment() {
78 | return SingleChoiceFragment.create(getKey());
79 | }
80 |
81 | public String getOptionAt(int position) {
82 | return mBranches.get(position).choice;
83 | }
84 |
85 | public int getOptionCount() {
86 | return mBranches.size();
87 | }
88 |
89 | @Override
90 | public void getReviewItems(ArrayList dest) {
91 | dest.add(new ReviewItem(getTitle(), mData.getString(SIMPLE_DATA_KEY), getKey()));
92 | }
93 |
94 | @Override
95 | public boolean isCompleted() {
96 | return !TextUtils.isEmpty(mData.getString(SIMPLE_DATA_KEY));
97 | }
98 |
99 | @Override
100 | public void notifyDataChanged() {
101 | mCallbacks.onPageTreeChanged();
102 | super.notifyDataChanged();
103 | }
104 |
105 | public BranchPage setValue(String value) {
106 | mData.putString(SIMPLE_DATA_KEY, value);
107 | return this;
108 | }
109 |
110 | private static class Branch {
111 | public String choice;
112 | public PageList childPageList;
113 |
114 | private Branch(String choice, PageList childPageList) {
115 | this.choice = choice;
116 | this.childPageList = childPageList;
117 | }
118 | }
119 | }
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/page/CustomerInfoPage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model.page;
18 |
19 | import java.util.ArrayList;
20 |
21 | import android.support.v4.app.Fragment;
22 | import android.text.TextUtils;
23 | import dev.dworks.libs.awizard.model.ReviewItem;
24 | import dev.dworks.libs.awizard.model.WizardModelCallbacks;
25 | import dev.dworks.libs.awizard.model.ui.CustomerInfoFragment;
26 |
27 | /**
28 | * A page asking for a name and an email.
29 | */
30 | public class CustomerInfoPage extends Page {
31 | public static final String NAME_DATA_KEY = "name";
32 | public static final String EMAIL_DATA_KEY = "email";
33 |
34 | public CustomerInfoPage(WizardModelCallbacks callbacks, String title) {
35 | super(callbacks, title);
36 | }
37 |
38 | @Override
39 | public Fragment createFragment() {
40 | return CustomerInfoFragment.create(getKey());
41 | }
42 |
43 | @Override
44 | public void getReviewItems(ArrayList dest) {
45 | dest.add(new ReviewItem("Your name", mData.getString(NAME_DATA_KEY), getKey(), -1));
46 | dest.add(new ReviewItem("Your email", mData.getString(EMAIL_DATA_KEY), getKey(), -1));
47 | }
48 |
49 | @Override
50 | public boolean isCompleted() {
51 | return !TextUtils.isEmpty(mData.getString(NAME_DATA_KEY));
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/page/DonePage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model.page;
18 |
19 | import java.util.ArrayList;
20 |
21 | import dev.dworks.libs.awizard.model.ReviewItem;
22 | import dev.dworks.libs.awizard.model.WizardModelCallbacks;
23 |
24 | /**
25 | * A page asking for a name and an email.
26 | */
27 | public abstract class DonePage extends Page {
28 |
29 | public DonePage(WizardModelCallbacks callbacks, String title) {
30 | super(callbacks, title);
31 | }
32 |
33 | @Override
34 | public void getReviewItems(ArrayList dest) {
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/page/ListChoicePage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model.page;
18 |
19 | import java.util.ArrayList;
20 | import java.util.Arrays;
21 |
22 | import android.support.v4.app.Fragment;
23 | import android.text.TextUtils;
24 | import dev.dworks.libs.awizard.model.ReviewItem;
25 | import dev.dworks.libs.awizard.model.WizardModelCallbacks;
26 |
27 | /**
28 | * A page offering the user a number of mutually exclusive choices.
29 | */
30 | public class ListChoicePage extends Page {
31 | protected ArrayList mChoices = new ArrayList();
32 |
33 | public ListChoicePage(WizardModelCallbacks callbacks, String title) {
34 | super(callbacks, title);
35 | }
36 |
37 | @Override
38 | public Fragment createFragment() {
39 | return null;
40 | //TODO
41 | // return ListChoiceFragment.create(getKey());
42 | }
43 |
44 | @Override
45 | public void getReviewItems(ArrayList dest) {
46 | dest.add(new ReviewItem(getTitle(), mData.getString(SIMPLE_DATA_KEY), getKey()));
47 | }
48 |
49 | public String getOptionAt(int position) {
50 | return mChoices.get(position);
51 | }
52 |
53 | public int getOptionCount() {
54 | return mChoices.size();
55 | }
56 |
57 | @Override
58 | public boolean isCompleted() {
59 | return !TextUtils.isEmpty(mData.getString(SIMPLE_DATA_KEY));
60 | }
61 |
62 | public ListChoicePage setChoices(String... choices) {
63 | mChoices.addAll(Arrays.asList(choices));
64 | return this;
65 | }
66 |
67 | public ListChoicePage setValue(String value) {
68 | mData.putString(SIMPLE_DATA_KEY, value);
69 | return this;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/page/MultipleFixedChoicePage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model.page;
18 |
19 | import java.util.ArrayList;
20 |
21 | import android.support.v4.app.Fragment;
22 | import dev.dworks.libs.awizard.model.ReviewItem;
23 | import dev.dworks.libs.awizard.model.WizardModelCallbacks;
24 | import dev.dworks.libs.awizard.model.ui.MultipleChoiceFragment;
25 |
26 | /**
27 | * A page offering the user a number of non-mutually exclusive choices.
28 | */
29 | public class MultipleFixedChoicePage extends SingleFixedChoicePage {
30 | public MultipleFixedChoicePage(WizardModelCallbacks callbacks, String title) {
31 | super(callbacks, title);
32 | }
33 |
34 | @Override
35 | public Fragment createFragment() {
36 | return MultipleChoiceFragment.create(getKey());
37 | }
38 |
39 | @Override
40 | public void getReviewItems(ArrayList dest) {
41 | StringBuilder sb = new StringBuilder();
42 |
43 | ArrayList selections = mData.getStringArrayList(Page.SIMPLE_DATA_KEY);
44 | if (selections != null && selections.size() > 0) {
45 | for (String selection : selections) {
46 | if (sb.length() > 0) {
47 | sb.append(", ");
48 | }
49 | sb.append(selection);
50 | }
51 | }
52 |
53 | dest.add(new ReviewItem(getTitle(), sb.toString(), getKey()));
54 | }
55 |
56 | @Override
57 | public boolean isCompleted() {
58 | ArrayList selections = mData.getStringArrayList(Page.SIMPLE_DATA_KEY);
59 | return selections != null && selections.size() > 0;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/page/Page.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model.page;
18 |
19 | import java.util.ArrayList;
20 |
21 | import android.os.Bundle;
22 | import android.support.v4.app.Fragment;
23 | import dev.dworks.libs.awizard.model.PageTreeNode;
24 | import dev.dworks.libs.awizard.model.ReviewItem;
25 | import dev.dworks.libs.awizard.model.WizardModelCallbacks;
26 |
27 |
28 | /**
29 | * Represents a single page in the wizard.
30 | */
31 | public abstract class Page implements PageTreeNode {
32 | /**
33 | * The key into {@link #getData()} used for wizards with simple (single) values.
34 | */
35 | public static final String SIMPLE_DATA_KEY = "_";
36 |
37 | protected WizardModelCallbacks mCallbacks;
38 |
39 | /**
40 | * Current wizard values/selections.
41 | */
42 | protected Bundle mData = new Bundle();
43 | protected String mTitle;
44 | protected boolean mRequired = false;
45 | protected String mParentKey;
46 |
47 | protected Page(WizardModelCallbacks callbacks, String title) {
48 | mCallbacks = callbacks;
49 | mTitle = title;
50 | }
51 |
52 | public Bundle getData() {
53 | return mData;
54 | }
55 |
56 | public String getTitle() {
57 | return mTitle;
58 | }
59 |
60 | public boolean isRequired() {
61 | return mRequired;
62 | }
63 |
64 | void setParentKey(String parentKey) {
65 | mParentKey = parentKey;
66 | }
67 |
68 | @Override
69 | public Page findByKey(String key) {
70 | return getKey().equals(key) ? this : null;
71 | }
72 |
73 | @Override
74 | public void flattenCurrentPageSequence(ArrayList dest) {
75 | dest.add(this);
76 | }
77 |
78 | public abstract Fragment createFragment();
79 |
80 | public String getKey() {
81 | return (mParentKey != null) ? mParentKey + ":" + mTitle : mTitle;
82 | }
83 |
84 | public abstract void getReviewItems(ArrayList dest);
85 |
86 | public boolean isCompleted() {
87 | return true;
88 | }
89 |
90 | public final void resetData(Bundle data) {
91 | mData = data;
92 | notifyDataChanged();
93 | }
94 |
95 | public void notifyDataChanged() {
96 | mCallbacks.onPageDataChanged(this);
97 | }
98 |
99 | public final Page setRequired(boolean required) {
100 | mRequired = required;
101 | return this;
102 | }
103 | }
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/page/ReviewPage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model.page;
18 |
19 | import java.util.ArrayList;
20 |
21 | import android.support.v4.app.Fragment;
22 | import dev.dworks.libs.awizard.model.ReviewItem;
23 | import dev.dworks.libs.awizard.model.WizardModelCallbacks;
24 | import dev.dworks.libs.awizard.model.ui.ReviewFragment;
25 |
26 | /**
27 | * A page asking for a name and an email.
28 | */
29 | public class ReviewPage extends Page {
30 | public static final String TITLE = "Overview";
31 | public static final String PROCESS_DATA_KEY = "PROCESS";
32 |
33 | public ReviewPage(WizardModelCallbacks callbacks, String title) {
34 | super(callbacks, title);
35 | }
36 |
37 | @Override
38 | public Fragment createFragment() {
39 | return ReviewFragment.create(getKey());
40 | }
41 |
42 | @Override
43 | public void getReviewItems(ArrayList dest) {
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/page/SingleFixedChoicePage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model.page;
18 |
19 | import java.util.ArrayList;
20 | import java.util.Arrays;
21 |
22 | import android.support.v4.app.Fragment;
23 | import android.text.TextUtils;
24 | import dev.dworks.libs.awizard.model.ReviewItem;
25 | import dev.dworks.libs.awizard.model.WizardModelCallbacks;
26 | import dev.dworks.libs.awizard.model.ui.SingleChoiceFragment;
27 |
28 | /**
29 | * A page offering the user a number of mutually exclusive choices.
30 | */
31 | public class SingleFixedChoicePage extends Page {
32 | protected ArrayList mChoices = new ArrayList();
33 |
34 | public SingleFixedChoicePage(WizardModelCallbacks callbacks, String title) {
35 | super(callbacks, title);
36 | }
37 |
38 | @Override
39 | public Fragment createFragment() {
40 | return SingleChoiceFragment.create(getKey());
41 | }
42 |
43 | public String getOptionAt(int position) {
44 | return mChoices.get(position);
45 | }
46 |
47 | public int getOptionCount() {
48 | return mChoices.size();
49 | }
50 |
51 | @Override
52 | public void getReviewItems(ArrayList dest) {
53 | dest.add(new ReviewItem(getTitle(), mData.getString(SIMPLE_DATA_KEY), getKey()));
54 | }
55 |
56 | @Override
57 | public boolean isCompleted() {
58 | return !TextUtils.isEmpty(mData.getString(SIMPLE_DATA_KEY));
59 | }
60 |
61 | public SingleFixedChoicePage setChoices(String... choices) {
62 | mChoices.addAll(Arrays.asList(choices));
63 | return this;
64 | }
65 |
66 | public SingleFixedChoicePage setValue(String value) {
67 | mData.putString(SIMPLE_DATA_KEY, value);
68 | return this;
69 | }
70 | }
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/ui/CustomerInfoFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | * Copyright 2013 Hari Krishna Dulipudi
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dev.dworks.libs.awizard.model.ui;
19 |
20 | import android.app.Activity;
21 | import android.content.Context;
22 | import android.os.Bundle;
23 | import android.support.v4.app.Fragment;
24 | import android.text.Editable;
25 | import android.text.TextWatcher;
26 | import android.view.LayoutInflater;
27 | import android.view.View;
28 | import android.view.ViewGroup;
29 | import android.view.inputmethod.InputMethodManager;
30 | import android.widget.TextView;
31 | import dev.dworks.libs.awizard.R;
32 | import dev.dworks.libs.awizard.model.PageFragmentCallbacks;
33 | import dev.dworks.libs.awizard.model.page.CustomerInfoPage;
34 |
35 | public class CustomerInfoFragment extends Fragment {
36 | private static final String ARG_KEY = "key";
37 |
38 | private PageFragmentCallbacks mCallbacks;
39 | private String mKey;
40 | private CustomerInfoPage mPage;
41 | private TextView mNameView;
42 | private TextView mEmailView;
43 |
44 | public static CustomerInfoFragment create(String key) {
45 | Bundle args = new Bundle();
46 | args.putString(ARG_KEY, key);
47 |
48 | CustomerInfoFragment fragment = new CustomerInfoFragment();
49 | fragment.setArguments(args);
50 | return fragment;
51 | }
52 |
53 | public CustomerInfoFragment() {
54 | }
55 |
56 | @Override
57 | public void onCreate(Bundle savedInstanceState) {
58 | super.onCreate(savedInstanceState);
59 |
60 | Bundle args = getArguments();
61 | mKey = args.getString(ARG_KEY);
62 | mPage = (CustomerInfoPage) mCallbacks.onGetPage(mKey);
63 | }
64 |
65 | @Override
66 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
67 | Bundle savedInstanceState) {
68 | View rootView = inflater.inflate(R.layout.fragment_page_customer_info, container, false);
69 | ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());
70 |
71 | mNameView = ((TextView) rootView.findViewById(R.id.your_name));
72 | mNameView.setText(mPage.getData().getString(CustomerInfoPage.NAME_DATA_KEY));
73 |
74 | mEmailView = ((TextView) rootView.findViewById(R.id.your_email));
75 | mEmailView.setText(mPage.getData().getString(CustomerInfoPage.EMAIL_DATA_KEY));
76 | return rootView;
77 | }
78 |
79 | @Override
80 | public void onAttach(Activity activity) {
81 | super.onAttach(activity);
82 |
83 | if (!(activity instanceof PageFragmentCallbacks)) {
84 | throw new ClassCastException("Activity must implement PageFragmentCallbacks");
85 | }
86 |
87 | mCallbacks = (PageFragmentCallbacks) activity;
88 | }
89 |
90 | @Override
91 | public void onDetach() {
92 | super.onDetach();
93 | mCallbacks = null;
94 | }
95 |
96 | @Override
97 | public void onViewCreated(View view, Bundle savedInstanceState) {
98 | super.onViewCreated(view, savedInstanceState);
99 |
100 | mNameView.addTextChangedListener(new TextWatcher() {
101 | @Override
102 | public void beforeTextChanged(CharSequence charSequence, int i, int i1,
103 | int i2) {
104 | }
105 |
106 | @Override
107 | public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
108 | }
109 |
110 | @Override
111 | public void afterTextChanged(Editable editable) {
112 | mPage.getData().putString(CustomerInfoPage.NAME_DATA_KEY,
113 | (editable != null) ? editable.toString() : null);
114 | mPage.notifyDataChanged();
115 | }
116 | });
117 |
118 | mEmailView.addTextChangedListener(new TextWatcher() {
119 | @Override
120 | public void beforeTextChanged(CharSequence charSequence, int i, int i1,
121 | int i2) {
122 | }
123 |
124 | @Override
125 | public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
126 | }
127 |
128 | @Override
129 | public void afterTextChanged(Editable editable) {
130 | mPage.getData().putString(CustomerInfoPage.EMAIL_DATA_KEY,
131 | (editable != null) ? editable.toString() : null);
132 | mPage.notifyDataChanged();
133 | }
134 | });
135 | }
136 |
137 | @Override
138 | public void setUserVisibleHint(boolean isVisibleToUser) {
139 | super.setUserVisibleHint(isVisibleToUser);
140 | // In a future update to the support library, this should override setUserVisibleHint
141 | // instead of setMenuVisibility.
142 | if (mNameView != null) {
143 | InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(
144 | Context.INPUT_METHOD_SERVICE);
145 | if (!isVisibleToUser) {
146 | imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
147 | }
148 | }
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/ui/DoneFragment.java:
--------------------------------------------------------------------------------
1 | package dev.dworks.libs.awizard.model.ui;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import dev.dworks.libs.awizard.model.ReviewCallbacks;
7 | import dev.dworks.libs.awizard.model.WizardModel;
8 | import dev.dworks.libs.awizard.model.WizardModelCallbacks;
9 | import dev.dworks.libs.awizard.model.page.Page;
10 |
11 | public abstract class DoneFragment extends Fragment implements WizardModelCallbacks {
12 |
13 | private ReviewCallbacks mCallbacks;
14 | private WizardModel mWizardModel;
15 | private Bundle mAllData;
16 |
17 | public DoneFragment() {
18 | }
19 |
20 | @Override
21 | public void onAttach(Activity activity) {
22 | super.onAttach(activity);
23 |
24 | if (!(activity instanceof ReviewCallbacks)) {
25 | throw new ClassCastException("Activity must implement fragment's callbacks");
26 | }
27 |
28 | mCallbacks = (ReviewCallbacks) activity;
29 | mWizardModel = mCallbacks.getWizardModel();
30 | mWizardModel.registerListener(this);
31 | onPageTreeChanged();
32 | }
33 |
34 | @Override
35 | public void onDetach() {
36 | super.onDetach();
37 | mCallbacks = null;
38 | mWizardModel.unregisterListener(this);
39 | }
40 |
41 | @Override
42 | public void onPageTreeChanged() {
43 | onPageDataChanged(null);
44 | }
45 |
46 | @Override
47 | public void onPageDataChanged(Page changedPage) {
48 | Bundle bundle = new Bundle();
49 | for (Page page : mWizardModel.getCurrentPageSequence()) {
50 | bundle.putAll(page.getData());
51 | }
52 |
53 | mAllData = bundle;
54 | }
55 |
56 | public Bundle getAllData() {
57 | return mAllData;
58 | }
59 | }
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/ui/MultipleChoiceFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model.ui;
18 |
19 | import java.util.ArrayList;
20 | import java.util.HashSet;
21 | import java.util.List;
22 | import java.util.Set;
23 |
24 | import android.app.Activity;
25 | import android.os.Bundle;
26 | import android.os.Handler;
27 | import android.support.v4.app.ListFragment;
28 | import android.util.SparseBooleanArray;
29 | import android.view.LayoutInflater;
30 | import android.view.View;
31 | import android.view.ViewGroup;
32 | import android.widget.ArrayAdapter;
33 | import android.widget.ListView;
34 | import android.widget.TextView;
35 | import dev.dworks.libs.awizard.R;
36 | import dev.dworks.libs.awizard.model.PageFragmentCallbacks;
37 | import dev.dworks.libs.awizard.model.page.MultipleFixedChoicePage;
38 | import dev.dworks.libs.awizard.model.page.Page;
39 |
40 | public class MultipleChoiceFragment extends ListFragment {
41 | private static final String ARG_KEY = "key";
42 |
43 | private PageFragmentCallbacks mCallbacks;
44 | private String mKey;
45 | private List mChoices;
46 | private Page mPage;
47 |
48 | public static MultipleChoiceFragment create(String key) {
49 | Bundle args = new Bundle();
50 | args.putString(ARG_KEY, key);
51 |
52 | MultipleChoiceFragment fragment = new MultipleChoiceFragment();
53 | fragment.setArguments(args);
54 | return fragment;
55 | }
56 |
57 | public MultipleChoiceFragment() {
58 | }
59 |
60 | @Override
61 | public void onCreate(Bundle savedInstanceState) {
62 | super.onCreate(savedInstanceState);
63 |
64 | Bundle args = getArguments();
65 | mKey = args.getString(ARG_KEY);
66 | mPage = mCallbacks.onGetPage(mKey);
67 |
68 | MultipleFixedChoicePage fixedChoicePage = (MultipleFixedChoicePage) mPage;
69 | mChoices = new ArrayList();
70 | for (int i = 0; i < fixedChoicePage.getOptionCount(); i++) {
71 | mChoices.add(fixedChoicePage.getOptionAt(i));
72 | }
73 | }
74 |
75 | @Override
76 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
77 | Bundle savedInstanceState) {
78 | View rootView = inflater.inflate(R.layout.fragment_page, container, false);
79 | ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());
80 |
81 | final ListView listView = (ListView) rootView.findViewById(android.R.id.list);
82 | setListAdapter(new ArrayAdapter(getActivity(),
83 | android.R.layout.simple_list_item_multiple_choice,
84 | android.R.id.text1,
85 | mChoices));
86 | listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
87 |
88 | // Pre-select currently selected items.
89 | new Handler().post(new Runnable() {
90 | @Override
91 | public void run() {
92 | ArrayList selectedItems = mPage.getData().getStringArrayList(
93 | Page.SIMPLE_DATA_KEY);
94 | if (selectedItems == null || selectedItems.size() == 0) {
95 | return;
96 | }
97 |
98 | Set selectedSet = new HashSet(selectedItems);
99 |
100 | for (int i = 0; i < mChoices.size(); i++) {
101 | if (selectedSet.contains(mChoices.get(i))) {
102 | listView.setItemChecked(i, true);
103 | }
104 | }
105 | }
106 | });
107 |
108 | return rootView;
109 | }
110 |
111 | @Override
112 | public void onAttach(Activity activity) {
113 | super.onAttach(activity);
114 |
115 | if (!(activity instanceof PageFragmentCallbacks)) {
116 | throw new ClassCastException("Activity must implement PageFragmentCallbacks");
117 | }
118 |
119 | mCallbacks = (PageFragmentCallbacks) activity;
120 | }
121 |
122 | @Override
123 | public void onDetach() {
124 | super.onDetach();
125 | mCallbacks = null;
126 | }
127 |
128 | @Override
129 | public void onListItemClick(ListView l, View v, int position, long id) {
130 | SparseBooleanArray checkedPositions = getListView().getCheckedItemPositions();
131 | ArrayList selections = new ArrayList();
132 | for (int i = 0; i < checkedPositions.size(); i++) {
133 | if (checkedPositions.valueAt(i)) {
134 | selections.add(getListAdapter().getItem(checkedPositions.keyAt(i)).toString());
135 | }
136 | }
137 |
138 | mPage.getData().putStringArrayList(Page.SIMPLE_DATA_KEY, selections);
139 | mPage.notifyDataChanged();
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/ui/ReviewFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model.ui;
18 |
19 | import java.util.ArrayList;
20 | import java.util.Collections;
21 | import java.util.Comparator;
22 | import java.util.List;
23 |
24 | import android.app.Activity;
25 | import android.os.Bundle;
26 | import android.support.v4.app.ListFragment;
27 | import android.text.TextUtils;
28 | import android.view.LayoutInflater;
29 | import android.view.View;
30 | import android.view.ViewGroup;
31 | import android.widget.BaseAdapter;
32 | import android.widget.ListView;
33 | import android.widget.TextView;
34 | import dev.dworks.libs.awizard.R;
35 | import dev.dworks.libs.awizard.model.PageFragmentCallbacks;
36 | import dev.dworks.libs.awizard.model.ReviewCallbacks;
37 | import dev.dworks.libs.awizard.model.ReviewItem;
38 | import dev.dworks.libs.awizard.model.WizardModel;
39 | import dev.dworks.libs.awizard.model.WizardModelCallbacks;
40 | import dev.dworks.libs.awizard.model.page.Page;
41 | import dev.dworks.libs.awizard.model.page.ReviewPage;
42 |
43 | public class ReviewFragment extends ListFragment implements WizardModelCallbacks {
44 | protected static final String ARG_KEY = "key";
45 |
46 | private ReviewCallbacks mCallbacks;
47 | private PageFragmentCallbacks mPageCallbacks;
48 | private WizardModel mWizardModel;
49 | private List mCurrentReviewItems;
50 |
51 | protected ReviewAdapter mReviewAdapter;
52 | private ReviewPage mPage;
53 | private String mKey;
54 |
55 | public static ReviewFragment create(String key) {
56 | Bundle args = new Bundle();
57 | args.putString(ARG_KEY, key);
58 |
59 | ReviewFragment fragment = new ReviewFragment();
60 | fragment.setArguments(args);
61 | return fragment;
62 | }
63 |
64 | public ReviewFragment() {
65 | }
66 |
67 | @Override
68 | public void onCreate(Bundle savedInstanceState) {
69 | super.onCreate(savedInstanceState);
70 | mReviewAdapter = new ReviewAdapter();
71 | Bundle args = getArguments();
72 | mKey = args.getString(ARG_KEY);
73 | mPage = (ReviewPage) mPageCallbacks.onGetPage(mKey);
74 | }
75 |
76 | @Override
77 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
78 | View rootView = inflater.inflate(R.layout.fragment_page, container, false);
79 |
80 | TextView titleView = (TextView) rootView.findViewById(android.R.id.title);
81 | titleView.setText(R.string.review);
82 | ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());
83 | titleView.setTextColor(getResources().getColor(R.color.review_green));
84 |
85 | ListView listView = (ListView) rootView.findViewById(android.R.id.list);
86 | setListAdapter(mReviewAdapter);
87 | listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
88 | return rootView;
89 | }
90 |
91 | @Override
92 | public void onAttach(Activity activity) {
93 | super.onAttach(activity);
94 |
95 | if (!(activity instanceof ReviewCallbacks)) {
96 | throw new ClassCastException("Activity must implement fragment's callbacks");
97 | }
98 |
99 | mCallbacks = (ReviewCallbacks) activity;
100 | mPageCallbacks = (PageFragmentCallbacks) activity;
101 | mWizardModel = mCallbacks.getWizardModel();
102 | mWizardModel.registerListener(this);
103 | onPageTreeChanged();
104 | }
105 |
106 | @Override
107 | public void onDetach() {
108 | super.onDetach();
109 | mCallbacks = null;
110 | mPageCallbacks = null;
111 | mWizardModel.unregisterListener(this);
112 | }
113 |
114 | @Override
115 | public void onPageTreeChanged() {
116 | onPageDataChanged(null);
117 | }
118 |
119 | @Override
120 | public void onPageDataChanged(Page changedPage) {
121 | ArrayList reviewItems = new ArrayList();
122 | for (Page page : mWizardModel.getCurrentPageSequence()) {
123 | page.getReviewItems(reviewItems);
124 | }
125 | Collections.sort(reviewItems, new Comparator() {
126 | @Override
127 | public int compare(ReviewItem a, ReviewItem b) {
128 | return a.getWeight() > b.getWeight() ? +1 : a.getWeight() < b.getWeight() ? -1 : 0;
129 | }
130 | });
131 | mCurrentReviewItems = reviewItems;
132 |
133 | if (mReviewAdapter != null) {
134 | mReviewAdapter.notifyDataSetInvalidated();
135 | }
136 | }
137 |
138 | @Override
139 | public void onListItemClick(ListView l, View v, int position, long id) {
140 | mCallbacks.onEditScreenAfterReview(mCurrentReviewItems.get(position).getPageKey());
141 | }
142 |
143 | protected class ReviewAdapter extends BaseAdapter {
144 | @Override
145 | public boolean hasStableIds() {
146 | return true;
147 | }
148 |
149 | @Override
150 | public int getItemViewType(int position) {
151 | return 0;
152 | }
153 |
154 | @Override
155 | public int getViewTypeCount() {
156 | return 1;
157 | }
158 |
159 | @Override
160 | public boolean areAllItemsEnabled() {
161 | return true;
162 | }
163 |
164 | @Override
165 | public Object getItem(int position) {
166 | return mCurrentReviewItems.get(position);
167 | }
168 |
169 | @Override
170 | public long getItemId(int position) {
171 | return mCurrentReviewItems.get(position).hashCode();
172 | }
173 |
174 | @Override
175 | public View getView(int position, View view, ViewGroup container) {
176 | LayoutInflater inflater = LayoutInflater.from(getActivity());
177 | View rootView = inflater.inflate(R.layout.list_item_review, container, false);
178 |
179 | ReviewItem reviewItem = mCurrentReviewItems.get(position);
180 | String value = reviewItem.getDisplayValue();
181 | if (TextUtils.isEmpty(value)) {
182 | value = "(None)";
183 | }
184 | ((TextView) rootView.findViewById(android.R.id.text1)).setText(reviewItem.getTitle());
185 | ((TextView) rootView.findViewById(android.R.id.text2)).setText(value);
186 | return rootView;
187 | }
188 |
189 | @Override
190 | public int getCount() {
191 | return mCurrentReviewItems.size();
192 | }
193 | }
194 |
195 | @Override
196 | public void setUserVisibleHint(boolean isVisibleToUser) {
197 | super.setUserVisibleHint(isVisibleToUser);
198 | if(isVisibleToUser && null != mPage){
199 | mPage.getData().putBoolean(ReviewPage.PROCESS_DATA_KEY, false);
200 | //FIXME: illegalstateexception, pager fragment destroyed
201 | //mPage.notifyDataChanged();
202 | }
203 | }
204 | }
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/ui/SingleChoiceFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model.ui;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import android.app.Activity;
23 | import android.os.Bundle;
24 | import android.os.Handler;
25 | import android.support.v4.app.ListFragment;
26 | import android.view.LayoutInflater;
27 | import android.view.View;
28 | import android.view.ViewGroup;
29 | import android.widget.ArrayAdapter;
30 | import android.widget.ListView;
31 | import android.widget.TextView;
32 | import dev.dworks.libs.awizard.R;
33 | import dev.dworks.libs.awizard.model.PageFragmentCallbacks;
34 | import dev.dworks.libs.awizard.model.page.Page;
35 | import dev.dworks.libs.awizard.model.page.SingleFixedChoicePage;
36 |
37 | public class SingleChoiceFragment extends ListFragment {
38 | private static final String ARG_KEY = "key";
39 |
40 | private PageFragmentCallbacks mCallbacks;
41 | private List mChoices;
42 | private String mKey;
43 | private Page mPage;
44 |
45 | public static SingleChoiceFragment create(String key) {
46 | Bundle args = new Bundle();
47 | args.putString(ARG_KEY, key);
48 |
49 | SingleChoiceFragment fragment = new SingleChoiceFragment();
50 | fragment.setArguments(args);
51 | return fragment;
52 | }
53 |
54 | public SingleChoiceFragment() {
55 | }
56 |
57 | @Override
58 | public void onCreate(Bundle savedInstanceState) {
59 | super.onCreate(savedInstanceState);
60 |
61 | Bundle args = getArguments();
62 | mKey = args.getString(ARG_KEY);
63 | mPage = mCallbacks.onGetPage(mKey);
64 |
65 | SingleFixedChoicePage fixedChoicePage = (SingleFixedChoicePage) mPage;
66 | mChoices = new ArrayList();
67 | for (int i = 0; i < fixedChoicePage.getOptionCount(); i++) {
68 | mChoices.add(fixedChoicePage.getOptionAt(i));
69 | }
70 | }
71 |
72 | @Override
73 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
74 | Bundle savedInstanceState) {
75 | View rootView = inflater.inflate(R.layout.fragment_page, container, false);
76 | ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());
77 |
78 | final ListView listView = (ListView) rootView.findViewById(android.R.id.list);
79 | setListAdapter(new ArrayAdapter(getActivity(),
80 | android.R.layout.simple_list_item_single_choice,
81 | android.R.id.text1,
82 | mChoices));
83 | listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
84 |
85 | // Pre-select currently selected item.
86 | new Handler().post(new Runnable() {
87 | @Override
88 | public void run() {
89 | String selection = mPage.getData().getString(Page.SIMPLE_DATA_KEY);
90 | for (int i = 0; i < mChoices.size(); i++) {
91 | if (mChoices.get(i).equals(selection)) {
92 | listView.setItemChecked(i, true);
93 | break;
94 | }
95 | }
96 | }
97 | });
98 |
99 | return rootView;
100 | }
101 |
102 | @Override
103 | public void onAttach(Activity activity) {
104 | super.onAttach(activity);
105 |
106 | if (!(activity instanceof PageFragmentCallbacks)) {
107 | throw new ClassCastException("Activity must implement PageFragmentCallbacks");
108 | }
109 |
110 | mCallbacks = (PageFragmentCallbacks) activity;
111 | }
112 |
113 | @Override
114 | public void onDetach() {
115 | super.onDetach();
116 | mCallbacks = null;
117 | }
118 |
119 | @Override
120 | public void onListItemClick(ListView l, View v, int position, long id) {
121 | mPage.getData().putString(Page.SIMPLE_DATA_KEY, getListAdapter().getItem(position).toString());
122 | mPage.notifyDataChanged();
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/library/src/dev/dworks/libs/awizard/model/ui/StepPagerStrip.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Roman Nurik
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.model.ui;
18 |
19 | import android.content.Context;
20 | import android.content.res.Resources;
21 | import android.content.res.TypedArray;
22 | import android.graphics.Canvas;
23 | import android.graphics.Paint;
24 | import android.graphics.RectF;
25 | import android.util.AttributeSet;
26 | import android.view.Gravity;
27 | import android.view.MotionEvent;
28 | import android.view.View;
29 | import dev.dworks.libs.awizard.R;
30 |
31 | public class StepPagerStrip extends View {
32 | private static final String XML_NS = "http://schemas.android.com/apk/res/android";
33 | private static final int[] ATTRS = new int[]{
34 | android.R.attr.gravity
35 | };
36 | public static final int HORIZONTAL = 0;
37 | public static final int VERTICAL = 1;
38 |
39 | private int mOrientation = HORIZONTAL;
40 |
41 | private int mPageCount;
42 | private int mCurrentPage;
43 |
44 | private int mGravity = Gravity.LEFT | Gravity.TOP;
45 | private float mTabWidth;
46 | private float mTabHeight;
47 | private float mTabSpacing;
48 |
49 | private Paint mPrevTabPaint;
50 | private Paint mSelectedTabPaint;
51 | private Paint mSelectedLastTabPaint;
52 | private Paint mNextTabPaint;
53 |
54 | private RectF mTempRectF = new RectF();
55 |
56 | //private Scroller mScroller;
57 |
58 | private OnPageSelectedListener mOnPageSelectedListener;
59 | private int mReviewPage;
60 | @SuppressWarnings("unused")
61 | private int mDonePage;
62 |
63 | public StepPagerStrip(Context context) {
64 | this(context, null, 0);
65 | }
66 |
67 | public StepPagerStrip(Context context, AttributeSet attrs) {
68 | this(context, attrs, 0);
69 | }
70 |
71 | public StepPagerStrip(Context context, AttributeSet attrs, int defStyle) {
72 | super(context, attrs, defStyle);
73 |
74 | final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
75 | mGravity = a.getInteger(0, mGravity);
76 | a.recycle();
77 |
78 | //We default to horizontal, only change if a value is explicitly specified
79 | int orientation = attrs.getAttributeIntValue(XML_NS, "orientation", -1);
80 | if (orientation != -1) {
81 | setOrientation(orientation);
82 | }
83 |
84 | final Resources res = getResources();
85 | if(mOrientation == HORIZONTAL){
86 | mTabWidth = res.getDimensionPixelSize(R.dimen.step_pager_tab_width);
87 | mTabHeight = res.getDimensionPixelSize(R.dimen.step_pager_tab_height);
88 | mTabSpacing = res.getDimensionPixelSize(R.dimen.step_pager_tab_spacing);
89 | }
90 | else{
91 | mTabWidth = res.getDimensionPixelSize(R.dimen.step_pager_vertical_tab_width);
92 | mTabHeight = res.getDimensionPixelSize(R.dimen.step_pager_vertical_tab_height);
93 | mTabSpacing = res.getDimensionPixelSize(R.dimen.step_pager_vertical_tab_spacing);
94 | }
95 |
96 | mPrevTabPaint = new Paint();
97 | mPrevTabPaint.setColor(res.getColor(R.color.step_pager_previous_tab_color));
98 |
99 | mSelectedTabPaint = new Paint();
100 | mSelectedTabPaint.setColor(res.getColor(R.color.step_pager_selected_tab_color));
101 |
102 | mSelectedLastTabPaint = new Paint();
103 | mSelectedLastTabPaint.setColor(res.getColor(R.color.step_pager_selected_last_tab_color));
104 |
105 | mNextTabPaint = new Paint();
106 | mNextTabPaint.setColor(res.getColor(R.color.step_pager_next_tab_color));
107 |
108 | }
109 |
110 | public int getOrientation() {
111 | return mOrientation;
112 | }
113 |
114 | public void setOrientation(int orientation) {
115 | switch (orientation) {
116 | case HORIZONTAL:
117 | case VERTICAL:
118 | break;
119 |
120 | default:
121 | throw new IllegalArgumentException("Only HORIZONTAL and VERTICAL are valid orientations.");
122 | }
123 |
124 | if (orientation == mOrientation) {
125 | return;
126 | }
127 |
128 | //Adjust scroll for new orientation
129 | mOrientation = orientation;
130 | final Resources res = getResources();
131 | if(orientation == HORIZONTAL){
132 | mTabWidth = res.getDimensionPixelSize(R.dimen.step_pager_tab_width);
133 | mTabHeight = res.getDimensionPixelSize(R.dimen.step_pager_tab_height);
134 | mTabSpacing = res.getDimensionPixelSize(R.dimen.step_pager_tab_spacing);
135 | }
136 | else{
137 | mTabWidth = res.getDimensionPixelSize(R.dimen.step_pager_vertical_tab_width);
138 | mTabHeight = res.getDimensionPixelSize(R.dimen.step_pager_vertical_tab_height);
139 | mTabSpacing = res.getDimensionPixelSize(R.dimen.step_pager_vertical_tab_spacing);
140 | }
141 |
142 | requestLayout();
143 | }
144 |
145 |
146 | public void setOnPageSelectedListener(OnPageSelectedListener onPageSelectedListener) {
147 | mOnPageSelectedListener = onPageSelectedListener;
148 | }
149 |
150 | @Override
151 | protected void onDraw(Canvas canvas) {
152 | super.onDraw(canvas);
153 |
154 | if (mPageCount == 0) {
155 | return;
156 | }
157 |
158 | if (mOrientation == HORIZONTAL) {
159 | onDrawX(canvas);
160 | } else {
161 | onDrawY(canvas);
162 | }
163 | }
164 |
165 | protected void onDrawX(Canvas canvas){
166 | float totalWidth = mPageCount * (mTabWidth + mTabSpacing) - mTabSpacing;
167 | float totalLeft;
168 | boolean fillHorizontal = false;
169 |
170 | switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
171 | case Gravity.CENTER_HORIZONTAL:
172 | totalLeft = (getWidth() - totalWidth) / 2;
173 | break;
174 | case Gravity.RIGHT:
175 | totalLeft = getWidth() - getPaddingRight() - totalWidth;
176 | break;
177 | case Gravity.FILL_HORIZONTAL:
178 | totalLeft = getPaddingLeft();
179 | fillHorizontal = true;
180 | break;
181 | default:
182 | totalLeft = getPaddingLeft();
183 | }
184 |
185 | switch (mGravity & Gravity.VERTICAL_GRAVITY_MASK) {
186 | case Gravity.CENTER_VERTICAL:
187 | mTempRectF.top = (int) (getHeight() - mTabHeight) / 2;
188 | break;
189 | case Gravity.BOTTOM:
190 | mTempRectF.top = getHeight() - getPaddingBottom() - mTabHeight;
191 | break;
192 | default:
193 | mTempRectF.top = getPaddingTop();
194 | }
195 |
196 | mTempRectF.bottom = mTempRectF.top + mTabHeight;
197 |
198 | float tabWidth = mTabWidth;
199 | if (fillHorizontal) {
200 | tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft()
201 | - (mPageCount - 1) * mTabSpacing) / mPageCount;
202 | }
203 |
204 | for (int i = 0; i < mPageCount; i++) {
205 | mTempRectF.left = totalLeft + (i * (tabWidth + mTabSpacing));
206 | mTempRectF.right = mTempRectF.left + tabWidth;
207 | Paint paint; /*= i < mCurrentPage
208 | ? mPrevTabPaint
209 | : (i > mCurrentPage
210 | ? mNextTabPaint
211 | : (i == mReviewPage
212 | ? mSelectedLastTabPaint
213 | : mSelectedTabPaint));*/
214 | if(i < mCurrentPage){
215 | paint = mPrevTabPaint;
216 | }else{
217 | if (i > mCurrentPage) {
218 | paint = mNextTabPaint;
219 | } else {
220 | if(i == mReviewPage){
221 | paint = mSelectedLastTabPaint;
222 | }else{
223 | paint = mSelectedTabPaint;
224 | }
225 | }
226 | }
227 | canvas.drawRect(mTempRectF, paint);
228 | }
229 | }
230 |
231 | protected void onDrawY(Canvas canvas){
232 | if (mPageCount == 0) {
233 | return;
234 | }
235 |
236 | float totalHeight = mPageCount * (mTabHeight + mTabSpacing) - mTabSpacing;
237 | float totalTop;
238 | boolean fillHorizontal = false;
239 |
240 | switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
241 | case Gravity.CENTER_HORIZONTAL:
242 | totalTop = (getHeight() - totalHeight) / 2;
243 | break;
244 | case Gravity.RIGHT:
245 | totalTop = getHeight() - getPaddingBottom() - totalHeight;
246 | break;
247 | case Gravity.FILL_HORIZONTAL:
248 | totalTop = getPaddingTop();
249 | //fillHorizontal = true;
250 | break;
251 | default:
252 | totalTop = getPaddingTop();
253 | }
254 |
255 | switch (mGravity & Gravity.VERTICAL_GRAVITY_MASK) {
256 | case Gravity.CENTER_VERTICAL:
257 | mTempRectF.left = (int) (getWidth() - mTabWidth) / 2;
258 | break;
259 | case Gravity.BOTTOM:
260 | mTempRectF.left = getWidth() - getPaddingRight() - mTabWidth;
261 | break;
262 | default:
263 | mTempRectF.left = getPaddingLeft();
264 | }
265 |
266 | mTempRectF.right = mTempRectF.left + mTabWidth;
267 |
268 | float tabHeight = mTabHeight;
269 | if (fillHorizontal) {
270 | tabHeight = (getWidth() - getPaddingRight() - getPaddingLeft()
271 | - (mPageCount - 1) * mTabSpacing) / mPageCount;
272 | }
273 |
274 | for (int i = 0; i < mPageCount; i++) {
275 | mTempRectF.top = totalTop + (i * (tabHeight + mTabSpacing));
276 | mTempRectF.bottom = mTempRectF.top + tabHeight;
277 | Paint paint = i < mCurrentPage
278 | ? mPrevTabPaint
279 | : (i > mCurrentPage
280 | ? mNextTabPaint
281 | : (i == mReviewPage
282 | ? mSelectedLastTabPaint
283 | : mSelectedTabPaint));
284 | canvas.drawRect(mTempRectF, paint);
285 | }
286 | }
287 |
288 | @Override
289 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
290 | if(mOrientation == HORIZONTAL){
291 | setMeasuredDimension(
292 | View.resolveSize(
293 | (int) (mPageCount * (mTabWidth + mTabSpacing) - mTabSpacing)
294 | + getPaddingLeft() + getPaddingRight(),
295 | widthMeasureSpec),
296 | View.resolveSize(
297 | (int) mTabHeight
298 | + getPaddingTop() + getPaddingBottom(),
299 | heightMeasureSpec));
300 | }
301 | else{
302 | setMeasuredDimension(
303 | View.resolveSize(
304 | (int) mTabWidth
305 | + getPaddingLeft() + getPaddingRight(),
306 | widthMeasureSpec),
307 | View.resolveSize(
308 | (int) (mPageCount * (mTabHeight+ mTabSpacing) - mTabSpacing)
309 | + getPaddingTop() + getPaddingBottom(),
310 | heightMeasureSpec));
311 | }
312 | }
313 |
314 | @Override
315 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
316 | scrollCurrentPageIntoView();
317 | super.onSizeChanged(w, h, oldw, oldh);
318 | }
319 |
320 | @Override
321 | public boolean onTouchEvent(MotionEvent event) {
322 | if (mOnPageSelectedListener != null) {
323 | switch (event.getActionMasked()) {
324 | case MotionEvent.ACTION_DOWN:
325 | case MotionEvent.ACTION_MOVE:
326 | int position;
327 | if(mOrientation == HORIZONTAL){
328 | position = hitTestX(event.getX());
329 | }
330 | else{
331 | position = hitTestY(event.getY());
332 | }
333 |
334 | if (position >= 0) {
335 | mOnPageSelectedListener.onPageStripSelected(position);
336 | }
337 | return true;
338 | }
339 | }
340 | return super.onTouchEvent(event);
341 | }
342 |
343 | private int hitTestX(float x) {
344 | if (mPageCount == 0) {
345 | return -1;
346 | }
347 |
348 | float totalWidth = mPageCount * (mTabWidth + mTabSpacing) - mTabSpacing;
349 | float totalLeft;
350 | boolean fillHorizontal = false;
351 |
352 | switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
353 | case Gravity.CENTER_HORIZONTAL:
354 | totalLeft = (getWidth() - totalWidth) / 2;
355 | break;
356 | case Gravity.RIGHT:
357 | totalLeft = getWidth() - getPaddingRight() - totalWidth;
358 | break;
359 | case Gravity.FILL_HORIZONTAL:
360 | totalLeft = getPaddingLeft();
361 | fillHorizontal = true;
362 | break;
363 | default:
364 | totalLeft = getPaddingLeft();
365 | }
366 |
367 | float tabWidth = mTabWidth;
368 | if (fillHorizontal) {
369 | tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft()
370 | - (mPageCount - 1) * mTabSpacing) / mPageCount;
371 | }
372 |
373 | float totalRight = totalLeft + (mPageCount * (tabWidth + mTabSpacing));
374 | if (x >= totalLeft && x <= totalRight && totalRight > totalLeft) {
375 | return (int) (((x - totalLeft) / (totalRight - totalLeft)) * mPageCount);
376 | } else {
377 | return -1;
378 | }
379 | }
380 |
381 | private int hitTestY(float y) {
382 | if (mPageCount == 0) {
383 | return -1;
384 | }
385 |
386 | float totalHeight = mPageCount * (mTabHeight + mTabSpacing) - mTabSpacing;
387 | float totalTop;
388 | boolean fillHorizontal = false;
389 |
390 | switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
391 | case Gravity.CENTER_HORIZONTAL:
392 | totalTop = (getHeight() - totalHeight) / 2;
393 | break;
394 | case Gravity.RIGHT:
395 | totalTop = getHeight() - getPaddingBottom() - totalHeight;
396 | break;
397 | case Gravity.FILL_HORIZONTAL:
398 | totalTop = getPaddingTop();
399 | //fillHorizontal = true;
400 | break;
401 | default:
402 | totalTop = getPaddingTop();
403 | }
404 |
405 | float tabWidth = mTabHeight;
406 | if (fillHorizontal) {
407 | tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft()
408 | - (mPageCount - 1) * mTabSpacing) / mPageCount;
409 | }
410 |
411 | float totalBottom = totalTop + (mPageCount * (tabWidth + mTabSpacing));
412 | if (y >= totalTop && y <= totalBottom && totalBottom > totalTop) {
413 | return (int) (((y - totalTop) / (totalBottom - totalTop)) * mPageCount);
414 | } else {
415 | return -1;
416 | }
417 | }
418 |
419 | public void setReviewPagePosition(int page) {
420 | mReviewPage = page;
421 | }
422 |
423 | public void setDonePagePosition(int page) {
424 | mDonePage = page;
425 | }
426 |
427 | public void setCurrentPage(int currentPage) {
428 | mCurrentPage = currentPage;
429 | invalidate();
430 | scrollCurrentPageIntoView();
431 |
432 | // TODO: Set content description appropriately
433 | }
434 |
435 | private void scrollCurrentPageIntoView() {
436 | // TODO: only works with left gravity for now
437 | //
438 | // float widthToActive = getPaddingLeft() + (mCurrentPage + 1) * (mTabWidth + mTabSpacing)
439 | // - mTabSpacing;
440 | // int viewWidth = getWidth();
441 | //
442 | // int startScrollX = getScrollX();
443 | // int destScrollX = (widthToActive > viewWidth) ? (int) (widthToActive - viewWidth) : 0;
444 | //
445 | // if (mScroller == null) {
446 | // mScroller = new Scroller(getContext());
447 | // }
448 | //
449 | // mScroller.abortAnimation();
450 | // mScroller.startScroll(startScrollX, 0, destScrollX - startScrollX, 0);
451 | // postInvalidate();
452 | }
453 |
454 | public void setPageCount(int count) {
455 | mPageCount = count;
456 | invalidate();
457 |
458 | // TODO: Set content description appropriately
459 | }
460 |
461 | public static interface OnPageSelectedListener {
462 | void onPageStripSelected(int position);
463 | }
464 |
465 | //
466 | // @Override
467 | // public void computeScroll() {
468 | // super.computeScroll();
469 | // if (mScroller.computeScrollOffset()) {
470 | // setScrollX(mScroller.getCurrX());
471 | // }
472 | // }
473 | }
474 |
--------------------------------------------------------------------------------
/sample/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
34 |
37 |
38 |
41 |
44 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/sample/libs/GoogleAdMobAdsSdk-6.4.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/libs/GoogleAdMobAdsSdk-6.4.1.jar
--------------------------------------------------------------------------------
/sample/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/sample/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 | android.library.reference.1=..\\library
16 | android.library.reference.2=../../../Android Development/Android Developement Studio/work/appcompat_v7
17 |
--------------------------------------------------------------------------------
/sample/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/res/drawable-xhdpi/card_black.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/res/drawable-xhdpi/card_black.9.png
--------------------------------------------------------------------------------
/sample/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/res/drawable-xhdpi/ic_menu_feedback.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/res/drawable-xhdpi/ic_menu_feedback.png
--------------------------------------------------------------------------------
/sample/res/drawable-xhdpi/ic_menu_github.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/res/drawable-xhdpi/ic_menu_github.png
--------------------------------------------------------------------------------
/sample/res/drawable-xhdpi/ic_menu_gplus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/res/drawable-xhdpi/ic_menu_gplus.png
--------------------------------------------------------------------------------
/sample/res/drawable-xhdpi/ic_menu_rate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/res/drawable-xhdpi/ic_menu_rate.png
--------------------------------------------------------------------------------
/sample/res/drawable-xhdpi/ic_menu_support.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/res/drawable-xhdpi/ic_menu_support.png
--------------------------------------------------------------------------------
/sample/res/drawable-xhdpi/ic_menu_twitter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/res/drawable-xhdpi/ic_menu_twitter.png
--------------------------------------------------------------------------------
/sample/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/res/drawable-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/res/drawable-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/res/drawable/dots.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/res/drawable/dots.png
--------------------------------------------------------------------------------
/sample/res/drawable/dworks.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/res/drawable/dworks.png
--------------------------------------------------------------------------------
/sample/res/drawable/item_background.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/res/drawable/item_background.9.png
--------------------------------------------------------------------------------
/sample/res/drawable/logo_big.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/res/drawable/logo_big.png
--------------------------------------------------------------------------------
/sample/res/drawable/made_with_love.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/res/drawable/made_with_love.png
--------------------------------------------------------------------------------
/sample/res/layout/activity_about.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
13 |
19 |
20 |
29 |
30 |
41 |
42 |
50 |
51 |
60 |
61 |
65 |
66 |
71 |
72 |
83 |
84 |
93 |
94 |
95 |
99 |
100 |
106 |
107 |
108 |
114 |
115 |
116 |
117 |
118 |
--------------------------------------------------------------------------------
/sample/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
20 |
21 |
28 |
29 |
--------------------------------------------------------------------------------
/sample/res/layout/activity_wizard.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
18 |
19 |
24 |
25 |
30 |
31 |
36 |
37 |
44 |
45 |
51 |
52 |
59 |
60 |
61 |
68 |
69 |
--------------------------------------------------------------------------------
/sample/res/layout/activity_wizard_side.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
19 |
20 |
24 |
25 |
30 |
31 |
36 |
37 |
42 |
43 |
50 |
51 |
57 |
58 |
65 |
66 |
67 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/sample/res/menu/about.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sample/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sample/res/menu/order.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sample/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/sample/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 | 128dp
8 |
9 |
10 |
--------------------------------------------------------------------------------
/sample/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/sample/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/sample/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/sample/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/sample/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | AWizard Demo
5 | Another Wizard v1.0
6 | Developed By DWorkS
7 | http://www.dworks.in
8 | To make a small difference.
9 | Contributions by Hari Krishna Dulipudi
10 | This library can be used for creating wizards very easily
11 | Twitter
12 | Google+
13 | Order Wizard
14 | Order Wizard Side
15 |
16 |
--------------------------------------------------------------------------------
/sample/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
27 |
28 |
--------------------------------------------------------------------------------
/sample/src/dev/dworks/libs/awizard/demo/AboutActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Hari Krishna Dulipudi
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.demo;
18 |
19 | import android.content.Intent;
20 | import android.net.Uri;
21 | import android.os.Bundle;
22 | import android.support.v7.app.ActionBarActivity;
23 | import android.view.Menu;
24 | import android.view.MenuItem;
25 |
26 | public class AboutActivity extends ActionBarActivity {
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_about);
32 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
33 | }
34 |
35 | @Override
36 | public boolean onCreateOptionsMenu(Menu menu) {
37 | getMenuInflater().inflate(R.menu.about, menu);
38 | return true;
39 | }
40 |
41 | @Override
42 | public boolean onOptionsItemSelected(MenuItem item) {
43 | switch (item.getItemId()) {
44 | case android.R.id.home:
45 | finish();
46 | break;
47 | case R.id.action_github:
48 | startActivity(new Intent("android.intent.action.VIEW",
49 | Uri.parse("https://github.com/DWorkS")));
50 | break;
51 | case R.id.action_gplus:
52 | startActivity(new Intent("android.intent.action.VIEW",
53 | Uri.parse("https://plus.google.com/109240246596102887385")));
54 | break;
55 | case R.id.action_twitter:
56 | startActivity(new Intent("android.intent.action.VIEW",
57 | Uri.parse("https://twitter.com/1HaKr")));
58 | break;
59 | case R.id.action_feedback:
60 | Intent intentFeedback = new Intent("android.intent.action.SEND");
61 | intentFeedback.setType("text/email");
62 | intentFeedback.putExtra("android.intent.extra.EMAIL", new String[]{"hakr@dworks.in"});
63 | intentFeedback.putExtra("android.intent.extra.SUBJECT", "AWizard Feedback");
64 | startActivity(Intent.createChooser(intentFeedback, "Send Feedback"));
65 | break;
66 | case R.id.action_support:
67 | Intent intentMarketAll = new Intent("android.intent.action.VIEW");
68 | intentMarketAll.setData(Uri.parse("market://search?q=pub:D WorkS"));
69 | startActivity(intentMarketAll);
70 | break;
71 | }
72 | return super.onOptionsItemSelected(item);
73 | }
74 | }
--------------------------------------------------------------------------------
/sample/src/dev/dworks/libs/awizard/demo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package dev.dworks.libs.awizard.demo;
2 |
3 | import java.util.ArrayList;
4 |
5 | import android.content.ComponentName;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.content.pm.ActivityInfo;
9 | import android.content.pm.PackageInfo;
10 | import android.content.pm.PackageManager;
11 | import android.content.pm.PackageManager.NameNotFoundException;
12 | import android.os.Bundle;
13 | import android.support.v7.app.ActionBarActivity;
14 | import android.text.TextUtils;
15 | import android.view.LayoutInflater;
16 | import android.view.Menu;
17 | import android.view.MenuItem;
18 | import android.view.View;
19 | import android.view.ViewGroup;
20 | import android.widget.AdapterView;
21 | import android.widget.AdapterView.OnItemClickListener;
22 | import android.widget.BaseAdapter;
23 | import android.widget.ListAdapter;
24 | import android.widget.ListView;
25 | import android.widget.TextView;
26 |
27 | public class MainActivity extends ActionBarActivity implements OnItemClickListener {
28 |
29 | private ListView mList;
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_main);
35 | mList = (ListView)findViewById(android.R.id.list);
36 | mList.setOnItemClickListener(this);
37 | mList.setAdapter(getSampleAdapter());
38 | }
39 |
40 | @Override
41 | public boolean onCreateOptionsMenu(Menu menu) {
42 | getMenuInflater().inflate(R.menu.main, menu);
43 | return true;
44 | }
45 |
46 | @Override
47 | public boolean onOptionsItemSelected(MenuItem item) {
48 | switch (item.getItemId()) {
49 | case R.id.action_about:
50 | Intent aboutIntent = new Intent(getApplicationContext(), AboutActivity.class);
51 | startActivity(aboutIntent);
52 | break;
53 | }
54 | return super.onOptionsItemSelected(item);
55 | }
56 |
57 | private ListAdapter getSampleAdapter() {
58 | ArrayList items = new ArrayList();
59 | final String thisClazzName = getClass().getName();
60 |
61 | try {
62 | PackageInfo pInfo = getPackageManager().getPackageInfo(
63 | getPackageName(), PackageManager.GET_ACTIVITIES);
64 | ActivityInfo[] aInfos = pInfo.activities;
65 |
66 | for (ActivityInfo aInfo : aInfos) {
67 | if (!thisClazzName.equals(aInfo.name) && !aInfo.name.endsWith("AboutActivity")
68 | && !aInfo.name.endsWith("AdActivity")) {
69 | items.add(aInfo);
70 | }
71 | }
72 | } catch (NameNotFoundException e) {
73 | e.printStackTrace();
74 | }
75 |
76 | return new SampleAdapter(this, items);
77 | }
78 |
79 | private static class SampleAdapter extends BaseAdapter {
80 |
81 | private final ArrayList mItems;
82 |
83 | private final LayoutInflater mInflater;
84 |
85 | public SampleAdapter(Context context, ArrayList activities) {
86 | mItems = activities;
87 | mInflater = LayoutInflater.from(context);
88 | }
89 |
90 | @Override
91 | public int getCount() {
92 | return mItems.size();
93 | }
94 |
95 | @Override
96 | public ActivityInfo getItem(int position) {
97 | return mItems.get(position);
98 | }
99 |
100 | @Override
101 | public long getItemId(int position) {
102 | return position;
103 | }
104 |
105 | @Override
106 | public View getView(int position, View convertView, ViewGroup parent) {
107 | TextView tv = (TextView) convertView;
108 | if (tv == null) {
109 | tv = (TextView) mInflater.inflate(
110 | android.R.layout.simple_list_item_1, parent, false);
111 | }
112 | ActivityInfo item = getItem(position);
113 | if (!TextUtils.isEmpty(item.nonLocalizedLabel)) {
114 | tv.setText(item.nonLocalizedLabel);
115 | } else {
116 | tv.setText(item.labelRes);
117 | }
118 | return tv;
119 | }
120 | }
121 |
122 | @Override
123 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
124 | ActivityInfo info = (ActivityInfo) parent.getItemAtPosition(position);
125 | Intent intent = new Intent();
126 | intent.setComponent(new ComponentName(this, info.name));
127 | startActivity(intent);
128 | }
129 | }
--------------------------------------------------------------------------------
/sample/src/dev/dworks/libs/awizard/demo/OrderSideWizardActivity.java:
--------------------------------------------------------------------------------
1 | package dev.dworks.libs.awizard.demo;
2 |
3 | import android.os.Bundle;
4 | import android.view.Menu;
5 | import android.view.MenuItem;
6 | import dev.dworks.libs.awizard.WizardActivitySide;
7 |
8 | public class OrderSideWizardActivity extends WizardActivitySide {
9 |
10 | @Override
11 | public void onCreate(Bundle savedInstanceState) {
12 | mWizardModel = new SandwichWizardModel(this);
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_wizard_side);
15 | setWizardModel(mWizardModel);
16 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
17 | }
18 |
19 | @Override
20 | public boolean onCreateOptionsMenu(Menu menu) {
21 | getMenuInflater().inflate(R.menu.order, menu);
22 | return true;
23 | }
24 |
25 | @Override
26 | public boolean onOptionsItemSelected(MenuItem item) {
27 | switch (item.getItemId()) {
28 | case android.R.id.home:
29 | finish();
30 | break;
31 | case R.id.action_cancel:
32 | finish();
33 | break;
34 | }
35 | return super.onOptionsItemSelected(item);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/sample/src/dev/dworks/libs/awizard/demo/OrderWizardActivity.java:
--------------------------------------------------------------------------------
1 | package dev.dworks.libs.awizard.demo;
2 |
3 | import android.os.Bundle;
4 | import android.view.Menu;
5 | import android.view.MenuItem;
6 | import dev.dworks.libs.awizard.WizardActivity;
7 |
8 | public class OrderWizardActivity extends WizardActivity {
9 |
10 | @Override
11 | public void onCreate(Bundle savedInstanceState) {
12 | mWizardModel = new SandwichWizardModel(this);
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_wizard);
15 | setWizardModel(mWizardModel);
16 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
17 | }
18 |
19 | @Override
20 | public boolean onCreateOptionsMenu(Menu menu) {
21 | getMenuInflater().inflate(R.menu.order, menu);
22 | return true;
23 | }
24 |
25 | @Override
26 | public boolean onOptionsItemSelected(MenuItem item) {
27 | switch (item.getItemId()) {
28 | case android.R.id.home:
29 | finish();
30 | break;
31 | case R.id.action_cancel:
32 | finish();
33 | break;
34 | }
35 | return super.onOptionsItemSelected(item);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/sample/src/dev/dworks/libs/awizard/demo/SandwichWizardModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Hari Krishna Dulipudi
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package dev.dworks.libs.awizard.demo;
18 |
19 | import android.content.Context;
20 | import dev.dworks.libs.awizard.model.PageList;
21 | import dev.dworks.libs.awizard.model.WizardModel;
22 | import dev.dworks.libs.awizard.model.page.BranchPage;
23 | import dev.dworks.libs.awizard.model.page.CustomerInfoPage;
24 | import dev.dworks.libs.awizard.model.page.MultipleFixedChoicePage;
25 | import dev.dworks.libs.awizard.model.page.ReviewPage;
26 | import dev.dworks.libs.awizard.model.page.SingleFixedChoicePage;
27 |
28 | public class SandwichWizardModel extends WizardModel {
29 | public SandwichWizardModel(Context context) {
30 | super(context);
31 | }
32 |
33 | @Override
34 | protected PageList onNewRootPageList() {
35 | BranchPage branchPage = new BranchPage(this, "Order type");
36 | branchPage.addBranch("Sandwich",
37 | new SingleFixedChoicePage(this, "Bread")
38 | .setChoices("White", "Wheat", "Rye", "Pretzel", "Ciabatta")
39 | .setRequired(true),
40 |
41 | new MultipleFixedChoicePage(this, "Meats")
42 | .setChoices("Pepperoni", "Turkey", "Ham", "Pastrami",
43 | "Roast Beef", "Bologna"),
44 |
45 | new MultipleFixedChoicePage(this, "Veggies")
46 | .setChoices("Tomatoes", "Lettuce", "Onions", "Pickles",
47 | "Cucumbers", "Peppers"),
48 |
49 | new MultipleFixedChoicePage(this, "Cheeses")
50 | .setChoices("Swiss", "American", "Pepperjack", "Muenster",
51 | "Provolone", "White American", "Cheddar", "Bleu"),
52 |
53 | new BranchPage(this, "Toasted?")
54 | .addBranch("Yes",
55 | new SingleFixedChoicePage(this, "Toast time")
56 | .setChoices("30 seconds", "1 minute",
57 | "2 minutes"))
58 | .addBranch("No")
59 | .setValue("No"))
60 |
61 | .addBranch("Salad",
62 | new SingleFixedChoicePage(this, "Salad type")
63 | .setChoices("Greek", "Caesar")
64 | .setRequired(true),
65 |
66 | new SingleFixedChoicePage(this, "Dressing")
67 | .setChoices("No dressing", "Balsamic", "Oil & vinegar",
68 | "Thousand Island", "Italian")
69 | .setValue("No dressing")
70 | ).setRequired(true);
71 |
72 | return new PageList(branchPage,
73 | new CustomerInfoPage(this, "Your info")
74 | .setRequired(true),
75 | new ReviewPage(this, "Review")
76 | );
77 | }
78 | }
--------------------------------------------------------------------------------
/sample/web_hi_res_512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DWorkS/AWizard/0dc8c40588d16d565194eb8dfa39b25b976102ab/sample/web_hi_res_512.png
--------------------------------------------------------------------------------