Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- menu.add(0, sign_up, 0, R.string.signup);
- menu.add(0, exit, 0, R.string.exit);
- return result;
- }
- public class LogginIn extends Activity {
- public static final int Connected_to_service = 0;
- public static final int not_Connected_to_service = 4;
- public static final int FILL_BOTH_USERNAME_PASSWORD = 1;
- public static final String Authentical_Failed = "failed";
- public static final String Friend_List = "friend_list";
- public static final int Make_sure_username_password = 2;
- public static final int Connected_to_network = 3;
- public static final int not_connected_to_network = 0;
- public EditText username;
- public EditText password;
- public Manager serviceProvider;
- public static final int sign_up = Menu.FIRST;
- public static final int exit = Menu.FIRST + 1;
- private ServiceConnection mConnection = new ServiceConnection() {
- public void onServiceConnected(ComponentName className, IBinder service) {
- serviceProvider = ((MessagingService.IMBinder)service).getService();
- if(serviceProvider.isUserAuthenticated() == true)
- {
- Intent i = new Intent(LogginIn.this, ListOfFriends.class);
- startActivity(i);
- LogginIn.this.finish();
- }
- }
- public void onServiceDisconnected(ComponentName className) {
- serviceProvider = null;
- Toast.makeText(LogginIn.this, R.string.local_service_stopped,
- Toast.LENGTH_SHORT).show();
- }
- };
- private int message;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- startService(new Intent(LogginIn.this, MessagingService.class));
- setContentView(R.layout.loggin_in);
- setTitle("login");
- ImageButton button= (ImageButton) findViewById(R.id.button);
- username = (EditText) findViewById(R.id.username);
- password = (EditText) findViewById(R.id.password);
- button.setOnClickListener(new OnClickListener() {
- @SuppressWarnings("unused")
- public void onClick1(View arg0) {
- if (serviceProvider == null) {
- Toast.makeText(getApplicationContext(), R.string.not_connected_to_service, Toast.LENGTH_LONG).show();
- return;
- } else if (serviceProvider.isNetworkConnected() == false) {
- Toast.makeText(getApplicationContext(), R.string.not_connected_to_service, Toast.LENGTH_LONG).show();
- } else if (username.length() > 0 &&
- password.length() > 0) {
- Thread loginThread = new Thread() {
- private Handler handler = new Handler();
- @Override
- public void run() {
- String result = null;
- try {
- result = serviceProvider.authenticateUser(username.getText().toString(), password.getText().toString());
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- if (result == null || result.equals(Authentical_Failed)) {
- handler.post(new Runnable() {
- public void run() {
- Toast.makeText(getApplicationContext(), R.string.not_connected_to_service, Toast.LENGTH_LONG).show();
- }
- });
- } else {
- handler.post(new Runnable() {
- public void run() {
- Intent i = new Intent(LogginIn.this, ListOfFriends.class);
- startActivity(i);
- LogginIn.this.finish();
- }
- });
- }
- }
- };
- loginThread.start();
- } else {
- Toast.makeText(getApplicationContext(), R.string.fill_both_username_password, Toast.LENGTH_LONG).show();
- }
- }
- @Override
- public void onClick(View arg0) {
- }
- });
- }
- @Override
- protected Dialog onCreateDialog(int id)
- {
- switch (id)
- {
- case not_Connected_to_service:
- message = R.string.not_connected_to_service;
- break;
- case FILL_BOTH_USERNAME_PASSWORD:
- message = R.string.fill_both_username_password;
- break;
- case Make_sure_username_password:
- message = R.string.make_sure_username_password_correct;
- break;
- case not_connected_to_network:
- message = R.string.not_connected_to_service;
- break;
- default:
- break;
- }
- return null;
- }
- public boolean onMenuItemSelected(int featureId, Menu menu){
- boolean result = super.onCreateOptionsMenu(menu);
- menu.add(0, sign_up, 0, R.string.signup);
- menu.add(0, exit, 0, R.string.exit);
- return result;
- }
- @Override
- public boolean onMenuItemSelected(int featureId, MenuItem item) {
- switch (item.getItemId())
- {
- case sign_up:
- Intent i = new Intent(LogginIn.this, SigningUp.class);
- startActivity(i);
- return true;
- case exit:
- return true;
- }
- return super.onMenuItemSelected(featureId, item);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement