0
|
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
|
|
52 this.flipper.addView(helpView);
|
|
53 // Add a view for each help topic we want the user to see.
|
|
54 String[] topics = getResources().getStringArray(R.array.list_wizard_topics);
|
|
55
|
|
56 for (String topic : topics) {
|
|
57 flipper.addView(new HelpTopicView(this).setTopic(topic));
|
|
58 }
|
|
59
|
|
60 next = (Button)this.findViewById(R.id.action_next);
|
|
61 next.setOnClickListener(new OnClickListener() {
|
|
62 public void onClick(View v) {
|
|
63 if (isLastDisplayed()) {
|
|
64 // user walked past end of wizard, so return okay
|
|
65 WizardActivity.this.setResult(Activity.RESULT_OK);
|
|
66 WizardActivity.this.finish();
|
|
67 }
|
|
68 else {
|
|
69 // show next step and update buttons
|
|
70 flipper.showNext();
|
|
71 updateButtons();
|
|
72 }
|
|
73 }
|
|
74 });
|
|
75 prev = (Button)this.findViewById(R.id.action_prev);
|
|
76 prev.setOnClickListener(new OnClickListener() {
|
|
77 public void onClick(View v) {
|
|
78 if (isFirstDisplayed()) {
|
|
79 // user walked past beginning of wizard, so return that they cancelled
|
|
80 WizardActivity.this.setResult(Activity.RESULT_CANCELED);
|
|
81 WizardActivity.this.finish();
|
|
82 }
|
|
83 else {
|
|
84 // show previous step and update buttons
|
|
85 flipper.showPrevious();
|
|
86 updateButtons();
|
|
87 }
|
|
88 }
|
|
89 });
|
|
90 this.updateButtons();
|
|
91 }
|
|
92
|
|
93 protected boolean isFirstDisplayed() {
|
|
94 return (flipper.getDisplayedChild() == 0);
|
|
95 }
|
|
96
|
|
97 protected boolean isLastDisplayed() {
|
|
98 return (flipper.getDisplayedChild() == flipper.getChildCount() - 1);
|
|
99 }
|
|
100
|
|
101 protected void updateButtons() {
|
|
102 boolean eula = (flipper.getDisplayedChild() == 0);
|
|
103 next.setText(eula ? getString(R.string.wizard_agree) : getString(R.string.wizard_next));
|
|
104 prev.setText(eula ? getString(R.string.delete_neg) : getString(R.string.wizard_back));
|
|
105 }
|
|
106 }
|