comparison src/com/five_ten_sg/connectbot/WizardActivity.java @ 0:0ce5cc452d02

initial version
author Carl Byington <carl@five-ten-sg.com>
date Thu, 22 May 2014 10:41:19 -0700
parents
children 29a431920007
comparison
equal deleted inserted replaced
-1:000000000000 0:0ce5cc452d02
1 /*
2 * ConnectBot: simple, powerful, open-source SSH client for Android
3 * Copyright 2007 Kenny Root, Jeffrey Sharkey
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 com.five_ten_sg.connectbot;
19
20 import com.five_ten_sg.connectbot.util.HelpTopicView;
21 import android.app.Activity;
22 import android.content.pm.PackageManager.NameNotFoundException;
23 import android.os.Bundle;
24 import android.util.Log;
25 import android.view.LayoutInflater;
26 import android.view.View;
27 import android.view.View.OnClickListener;
28 import android.widget.Button;
29 import android.widget.TextView;
30 import android.widget.ViewFlipper;
31
32 /**
33 * Show a series of wizard-like steps to the user, which might include an EULA,
34 * program credits, and helpful hints.
35 *
36 * @author jsharkey
37 */
38 public class WizardActivity extends Activity {
39 protected ViewFlipper flipper = null;
40 private Button next, prev;
41 private static final String TAG = "ConnectBot.WizardActivity";
42
43 @Override
44 public void onCreate(Bundle savedInstanceState) {
45 super.onCreate(savedInstanceState);
46 setContentView(R.layout.act_wizard);
47 this.flipper = (ViewFlipper) findViewById(R.id.wizard_flipper);
48 // inflate the layout for EULA step
49 LayoutInflater inflater = LayoutInflater.from(this);
50 View helpView = inflater.inflate(R.layout.wiz_eula, this.flipper, false);
51 TextView appVersionView = (TextView) helpView.findViewById(R.id.app_version);
52
53 // get package version
54 try {
55 appVersionView.setText(getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
56 }
57 catch (NameNotFoundException e) {
58 Log.e(TAG, "Problem retrieving application version", e);
59 }
60
61 this.flipper.addView(helpView);
62 // Add a view for each help topic we want the user to see.
63 String[] topics = getResources().getStringArray(R.array.list_wizard_topics);
64
65 for (String topic : topics) {
66 flipper.addView(new HelpTopicView(this).setTopic(topic));
67 }
68
69 next = (Button)this.findViewById(R.id.action_next);
70 next.setOnClickListener(new OnClickListener() {
71 public void onClick(View v) {
72 if (isLastDisplayed()) {
73 // user walked past end of wizard, so return okay
74 WizardActivity.this.setResult(Activity.RESULT_OK);
75 WizardActivity.this.finish();
76 }
77 else {
78 // show next step and update buttons
79 flipper.showNext();
80 updateButtons();
81 }
82 }
83 });
84 prev = (Button)this.findViewById(R.id.action_prev);
85 prev.setOnClickListener(new OnClickListener() {
86 public void onClick(View v) {
87 if (isFirstDisplayed()) {
88 // user walked past beginning of wizard, so return that they cancelled
89 WizardActivity.this.setResult(Activity.RESULT_CANCELED);
90 WizardActivity.this.finish();
91 }
92 else {
93 // show previous step and update buttons
94 flipper.showPrevious();
95 updateButtons();
96 }
97 }
98 });
99 this.updateButtons();
100 }
101
102 protected boolean isFirstDisplayed() {
103 return (flipper.getDisplayedChild() == 0);
104 }
105
106 protected boolean isLastDisplayed() {
107 return (flipper.getDisplayedChild() == flipper.getChildCount() - 1);
108 }
109
110 protected void updateButtons() {
111 boolean eula = (flipper.getDisplayedChild() == 0);
112 next.setText(eula ? getString(R.string.wizard_agree) : getString(R.string.wizard_next));
113 prev.setText(eula ? getString(R.string.delete_neg) : getString(R.string.wizard_back));
114 }
115 }