38 President of Epitech. |
38 President of Epitech. |
39 |
39 |
40 Flavien Astraud, November 26, 2009 |
40 Flavien Astraud, November 26, 2009 |
41 Head of the EIP Laboratory. |
41 Head of the EIP Laboratory. |
42 |
42 |
43 */ |
43 */ |
44 package com.beem.project.beem.ui; |
44 package com.beem.project.beem.ui; |
45 |
45 |
|
46 import java.util.ArrayList; |
|
47 import java.util.List; |
|
48 |
|
49 import android.accounts.Account; |
|
50 import android.accounts.AccountManager; |
46 import android.app.Activity; |
51 import android.app.Activity; |
47 import android.app.AlertDialog; |
52 import android.app.AlertDialog; |
48 import android.app.Application; |
53 import android.app.Application; |
49 import android.content.DialogInterface; |
54 import android.content.DialogInterface; |
50 import android.content.Intent; |
55 import android.content.Intent; |
51 import android.content.pm.PackageInfo; |
56 import android.content.pm.PackageInfo; |
52 import android.content.pm.PackageManager; |
57 import android.content.pm.PackageManager; |
53 import android.os.Bundle; |
58 import android.os.Bundle; |
|
59 import android.view.LayoutInflater; |
54 import android.view.Menu; |
60 import android.view.Menu; |
55 import android.view.MenuInflater; |
61 import android.view.MenuInflater; |
56 import android.view.MenuItem; |
62 import android.view.MenuItem; |
|
63 import android.view.View; |
|
64 import android.view.ViewGroup; |
|
65 import android.widget.AdapterView; |
|
66 import android.widget.BaseAdapter; |
|
67 import android.widget.ListView; |
57 import android.widget.TextView; |
68 import android.widget.TextView; |
58 import android.widget.Toast; |
69 import android.widget.Toast; |
|
70 import android.widget.AdapterView.OnItemClickListener; |
59 |
71 |
60 import com.beem.project.beem.BeemApplication; |
72 import com.beem.project.beem.BeemApplication; |
61 import com.beem.project.beem.R; |
73 import com.beem.project.beem.R; |
62 import com.beem.project.beem.ui.wizard.Account; |
|
63 import com.beem.project.beem.utils.BeemConnectivity; |
|
64 |
74 |
65 /** |
75 /** |
66 * This class is the main Activity for the Beem project. |
76 * This class is the main Activity for the Beem project. |
67 * @author Da Risk <darisk@beem-project.com> |
77 * @author Da Risk <darisk@beem-project.com> |
68 */ |
78 */ |
69 public class Login extends Activity { |
79 public class Login extends Activity { |
70 |
80 |
71 private static final int LOGIN_REQUEST_CODE = 1; |
81 private static final int LOGIN_REQUEST_CODE = 1; |
72 private TextView mTextView; |
82 private TextView mTextView; |
73 private boolean mIsResult; |
|
74 private BeemApplication mBeemApplication; |
83 private BeemApplication mBeemApplication; |
|
84 |
|
85 List<String> mListAccount = new ArrayList<String>(); |
|
86 private BeemAccountList mAdapterAccountList; |
|
87 private final BeemAccountListOnClick mOnAccountClick = new BeemAccountListOnClick(); |
75 |
88 |
76 /** |
89 /** |
77 * Constructor. |
90 * Constructor. |
78 */ |
91 */ |
79 public Login() { |
92 public Login() { |
93 finish(); |
106 finish(); |
94 } |
107 } |
95 } |
108 } |
96 setContentView(R.layout.login); |
109 setContentView(R.layout.login); |
97 mTextView = (TextView) findViewById(R.id.log_as_msg); |
110 mTextView = (TextView) findViewById(R.id.log_as_msg); |
|
111 ListView listView = (ListView) findViewById(R.id.accountlist); |
|
112 mAdapterAccountList = new BeemAccountList(getLayoutInflater()); |
|
113 listView.setOnItemClickListener(mOnAccountClick); |
|
114 listView.setAdapter(mAdapterAccountList); |
98 } |
115 } |
99 |
116 |
100 @Override |
117 @Override |
101 protected void onStart() { |
118 protected void onStart() { |
102 super.onStart(); |
119 super.onStart(); |
103 if (mBeemApplication.isAccountConfigured() && !mIsResult |
120 mTextView.setText(R.string.login_start_msg); |
104 && BeemConnectivity.isConnected(getApplicationContext())) { |
|
105 mTextView.setText(""); |
|
106 Intent i = new Intent(this, LoginAnim.class); |
|
107 startActivityForResult(i, LOGIN_REQUEST_CODE); |
|
108 mIsResult = false; |
|
109 } else { |
|
110 mTextView.setText(R.string.login_start_msg); |
|
111 } |
|
112 } |
121 } |
113 |
122 |
114 @Override |
123 @Override |
115 protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
124 protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
116 if (requestCode == LOGIN_REQUEST_CODE) { |
125 if (requestCode == LOGIN_REQUEST_CODE) { |
117 mIsResult = true; |
|
118 if (resultCode == Activity.RESULT_OK) { |
126 if (resultCode == Activity.RESULT_OK) { |
119 startActivity(new Intent(this, ContactList.class)); |
127 startActivity(new Intent(this, ContactList.class)); |
120 finish(); |
128 finish(); |
121 } else if (resultCode == Activity.RESULT_CANCELED) { |
129 } else if (resultCode == Activity.RESULT_CANCELED) { |
122 if (data != null) { |
130 if (data != null) { |
185 } |
193 } |
186 }); |
194 }); |
187 AlertDialog aboutDialog = builder.create(); |
195 AlertDialog aboutDialog = builder.create(); |
188 aboutDialog.show(); |
196 aboutDialog.show(); |
189 } |
197 } |
|
198 |
|
199 private class BeemAccountList extends BaseAdapter { |
|
200 |
|
201 private LayoutInflater mInflater; |
|
202 |
|
203 public BeemAccountList(LayoutInflater layoutInflater) { |
|
204 mInflater = layoutInflater; |
|
205 AccountManager am = AccountManager.get(Login.this); |
|
206 Account allAccount[] = am.getAccountsByType("com.beem.project.com"); |
|
207 for (Account account : allAccount) { |
|
208 mListAccount.add(account.name); |
|
209 mListAccount.add(account.name); |
|
210 |
|
211 } |
|
212 } |
|
213 |
|
214 @Override |
|
215 public int getCount() { |
|
216 return mListAccount.size(); |
|
217 } |
|
218 |
|
219 @Override |
|
220 public Object getItem(int position) { |
|
221 return mListAccount.get(position); |
|
222 } |
|
223 |
|
224 @Override |
|
225 public long getItemId(int position) { |
|
226 return position; |
|
227 } |
|
228 |
|
229 @Override |
|
230 public View getView(int position, View convertView, ViewGroup parent) { |
|
231 View v = convertView; |
|
232 if (convertView == null) { |
|
233 v = mInflater.inflate(R.layout.login_row_account, null); |
|
234 } |
|
235 TextView tv = (TextView) v.findViewById(R.id.accountname); |
|
236 tv.setText(mListAccount.get(position)); |
|
237 return v; |
|
238 } |
|
239 } |
|
240 |
|
241 /** |
|
242 * Event simple click on item of the contact list. |
|
243 */ |
|
244 private class BeemAccountListOnClick implements OnItemClickListener { |
|
245 /** |
|
246 * Constructor. |
|
247 */ |
|
248 public BeemAccountListOnClick() { |
|
249 } |
|
250 |
|
251 /** |
|
252 * {@inheritDoc} |
|
253 */ |
|
254 @Override |
|
255 public void onItemClick(AdapterView<?> arg0, View v, int pos, long lpos) { |
|
256 Intent i = new Intent(Login.this, LoginAnim.class); |
|
257 i.putExtra("account_name", mListAccount.get(pos)); |
|
258 startActivityForResult(i, LOGIN_REQUEST_CODE); |
|
259 } |
|
260 } |
190 } |
261 } |