root / src / com / rackspace / cloud / android / TabViewActivity.java @ 6ba04c48
History | View | Annotate | Download (4.2 kB)
1 |
/**
|
---|---|
2 |
*
|
3 |
*/
|
4 |
package com.rackspace.cloud.android; |
5 |
|
6 |
import java.util.Calendar; |
7 |
|
8 |
import android.app.Dialog; |
9 |
import android.app.TabActivity; |
10 |
import android.content.Context; |
11 |
import android.content.Intent; |
12 |
import android.os.Bundle; |
13 |
import android.view.View; |
14 |
import android.view.View.OnClickListener; |
15 |
import android.widget.Button; |
16 |
import android.widget.EditText; |
17 |
import android.widget.TabHost; |
18 |
import android.widget.Toast; |
19 |
|
20 |
import com.rackspace.cloud.android.R; |
21 |
|
22 |
/**
|
23 |
* @author Mike Mayo - mike.mayo@rackspace.com - twitter.com/greenisus
|
24 |
*
|
25 |
*/
|
26 |
public class TabViewActivity extends TabActivity { |
27 |
|
28 |
protected AndroidCloudApplication app;
|
29 |
private final int PASSWORD_PROMPT = 123; |
30 |
private boolean loggedIn; |
31 |
|
32 |
@Override
|
33 |
public void onCreate(Bundle savedInstanceState) { |
34 |
super.onCreate(savedInstanceState);
|
35 |
|
36 |
TabHost tabs = getTabHost(); |
37 |
|
38 |
TabHost.TabSpec spec = tabs.newTabSpec("tab1");
|
39 |
spec.setContent(new Intent(this, ListContainerActivity.class)); |
40 |
spec.setIndicator("Pithos",
|
41 |
getResources().getDrawable(R.drawable.pithos_tab_icon)); |
42 |
tabs.addTab(spec); |
43 |
|
44 |
spec = tabs.newTabSpec("tab2");
|
45 |
spec.setContent(new Intent(this, PithosMySharedActivity.class)); |
46 |
spec.setIndicator("MyShared",
|
47 |
getResources().getDrawable(R.drawable.myshared)); |
48 |
tabs.addTab(spec); |
49 |
|
50 |
spec = tabs.newTabSpec("tab3");
|
51 |
spec.setContent(new Intent(this, PithosOthersActivity.class)); |
52 |
spec.setIndicator("Others",
|
53 |
getResources().getDrawable(R.drawable.othersshared)); |
54 |
tabs.addTab(spec); |
55 |
|
56 |
spec = tabs.newTabSpec("tab4");
|
57 |
spec.setContent(new Intent(this, PithosGroupsActivity.class)); |
58 |
spec.setIndicator("Groups",
|
59 |
getResources().getDrawable(R.drawable.groups_tab)); |
60 |
tabs.addTab(spec); |
61 |
/*
|
62 |
spec = tabs.newTabSpec("tab1");
|
63 |
spec.setContent(new Intent(this, ListServersActivity.class));
|
64 |
spec.setIndicator("Cloud Servers",
|
65 |
getResources().getDrawable(R.drawable.cloudservers_icon));
|
66 |
tabs.addTab(spec);
|
67 |
|
68 |
|
69 |
|
70 |
spec = tabs.newTabSpec("tab3");
|
71 |
spec.setContent(new Intent(this, ListLoadBalancersActivity.class));
|
72 |
spec.setIndicator("Load Balancers", getResources().getDrawable(R.drawable.load_balancers_icon));
|
73 |
tabs.addTab(spec);*/
|
74 |
} |
75 |
|
76 |
@Override
|
77 |
protected void onPause(){ |
78 |
super.onPause();
|
79 |
Calendar cal = Calendar.getInstance(); |
80 |
AndroidCloudApplication.lastPause = cal.getTimeInMillis(); |
81 |
} |
82 |
|
83 |
@Override
|
84 |
protected void onResume(){ |
85 |
super.onResume();
|
86 |
Calendar cal = Calendar.getInstance(); |
87 |
long curTime = cal.getTimeInMillis();
|
88 |
if(curTime - AndroidCloudApplication.lastPause > 5000){ |
89 |
verifyPassword(); |
90 |
} |
91 |
} |
92 |
|
93 |
/*
|
94 |
* if the application is password protected,
|
95 |
* the user must provide the password before
|
96 |
* gaining access
|
97 |
*/
|
98 |
private void verifyPassword(){ |
99 |
PasswordManager pwManager = new PasswordManager(getSharedPreferences(
|
100 |
Preferences.SHARED_PREFERENCES_NAME, MODE_PRIVATE));
|
101 |
if(pwManager.hasPassword() && !loggedIn){
|
102 |
createCustomDialog(PASSWORD_PROMPT); |
103 |
} |
104 |
} |
105 |
|
106 |
private boolean rightPassword(String password){ |
107 |
PasswordManager pwManager = new PasswordManager(getSharedPreferences(
|
108 |
Preferences.SHARED_PREFERENCES_NAME, MODE_PRIVATE));
|
109 |
return pwManager.verifyEnteredPassword(password);
|
110 |
} |
111 |
|
112 |
|
113 |
/*
|
114 |
* forces the user to enter a correct password
|
115 |
* before they gain access to application data
|
116 |
*/
|
117 |
private void createCustomDialog(int id) { |
118 |
final Dialog dialog = new Dialog(TabViewActivity.this); |
119 |
switch (id) {
|
120 |
case PASSWORD_PROMPT:
|
121 |
dialog.setContentView(R.layout.passworddialog); |
122 |
dialog.setTitle("Enter your password:");
|
123 |
dialog.setCancelable(false);
|
124 |
Button button = (Button) dialog.findViewById(R.id.submit_password); |
125 |
button.setOnClickListener(new OnClickListener() {
|
126 |
public void onClick(View v){ |
127 |
EditText passwordText = ((EditText)dialog.findViewById(R.id.submit_password_text)); |
128 |
if(!rightPassword(passwordText.getText().toString())){
|
129 |
passwordText.setText("");
|
130 |
showToast("Password was incorrect.");
|
131 |
loggedIn = false;
|
132 |
} |
133 |
else{
|
134 |
dialog.dismiss(); |
135 |
loggedIn = true;
|
136 |
} |
137 |
} |
138 |
|
139 |
}); |
140 |
dialog.show(); |
141 |
} |
142 |
} |
143 |
|
144 |
protected void showToast(String message) { |
145 |
Context context = getApplicationContext();
|
146 |
int duration = Toast.LENGTH_SHORT;
|
147 |
Toast toast = Toast.makeText(context, message, duration); |
148 |
toast.show(); |
149 |
} |
150 |
|
151 |
} |