Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.slema.barber_schedule;
- import android.app.ProgressDialog;
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- import android.content.IntentFilter;
- import android.net.ConnectivityManager;
- import android.net.NetworkInfo;
- import android.support.v4.content.LocalBroadcastManager;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.ProgressBar;
- import android.widget.Toast;
- import com.example.slema.barber_schedule.networking.sha256;
- import android.os.Handler;
- public class MainActivity extends AppCompatActivity {
- private ProgressBar spinner;
- EditText email,password;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- email=(EditText) findViewById(R.id.email);
- password=(EditText) findViewById(R.id.pass);
- spinner = (ProgressBar) findViewById(R.id.progressBar);
- spinner.setVisibility(View.GONE);
- }
- //------------------------------------------------------------------------------------------------------
- public void login(View view)
- {
- if(isNetworkAvailable())// check for network
- {
- if (!(isempty(email.getEditableText().toString(), password.getText().toString()))) {
- this.login();
- spinner.setVisibility(View.VISIBLE);
- }
- else
- {
- Toast.makeText(getApplicationContext(),"Please Fill Missing Spaces",Toast.LENGTH_LONG).show();
- }
- }
- else
- {
- Toast.makeText(getApplicationContext(),"No Network available",Toast.LENGTH_LONG).show();
- }
- }
- //--------------------------------------------------------------------------------------------------------
- public void signup(View view)
- {
- if(isNetworkAvailable()) { // check for network
- Intent intent = new Intent(this, Signup.class);
- startActivity(intent);
- }
- else
- {
- Toast.makeText(getApplicationContext(),"No Network available",Toast.LENGTH_LONG).show();
- }
- }
- //--------------------------------------------------------------------------------------------------------
- public void recover_account(View view){
- Intent intent =new Intent(this,RecoveryEmail.class);
- startActivity(intent);
- }
- //--------------------------------------------------------------------------------------------------------
- private boolean isNetworkAvailable() {
- ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(this.CONNECTIVITY_SERVICE);
- NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
- return activeNetworkInfo != null && activeNetworkInfo.isConnected();
- }
- //---------------------------------------------------------------------------------------------------------
- public boolean isempty(String email ,String password)
- {
- if(email.equals("") || password.equals(""))
- {
- return true;
- }
- return false;
- }
- //-------------------------------------------------------------------------------------------------------------
- /**calls the nethread class to send the client's
- email;the recived list of favourite barbers data
- is handled by the onReceive function which updates the
- listview respectively.
- */
- public void login()
- {
- Intent network=new Intent(this,com.example.slema.barber_schedule.networking.nethread.class);
- String[] credentials=new String[]{"login",email.getText().toString(),sha256.sha256(password.getText().toString())};
- network.putExtra("cred", credentials);
- startService(network);
- }
- //--------------------------------------------------------------------------------------------------------------
- /**
- * the following three function i.e (onResume,onPause,onReceive)
- * are responsible for handeling the broadcast service which
- * in turn makes it possible to communicate with the nethread class.
- *
- * the onReceive method is responsible for receiving and also
- * updating the listview whith new data.
- */
- @Override
- protected void onResume() {
- super.onResume();
- // Register for the particular broadcast based on ACTION string
- IntentFilter filter = new IntentFilter(com.example.slema.barber_schedule.networking.nethread.ACTION);
- LocalBroadcastManager.getInstance(this).registerReceiver(testReceiver, filter);
- // or `registerReceiver(testReceiver, filter)` for a normal broadcast
- }
- @Override
- protected void onPause() {
- super.onPause();
- // Unregister the listener when the application is paused
- LocalBroadcastManager.getInstance(this).unregisterReceiver(testReceiver);
- // or `unregisterReceiver(testReceiver)` for a normal broadcast
- }
- // Define the callback for what to do when data is received
- private BroadcastReceiver testReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- int resultCode = intent.getIntExtra("resultCode", RESULT_CANCELED);
- if (resultCode == RESULT_OK) {
- String resultValue = intent.getStringExtra("resultValue");
- if (resultValue.equals("client_1")) {
- Intent intent_client = new Intent(getApplicationContext(), com.example.slema.barber_schedule.client_gui.client_interface.class);
- startActivity(intent_client);
- spinner.setVisibility(View.GONE);
- } else if (resultValue.equals("barber_1")) {
- Intent intent_barber = new Intent(getApplicationContext(), com.example.slema.barber_schedule.client_gui.client_interface.class);
- startActivity(intent_barber);
- spinner.setVisibility(View.GONE);
- } else {
- Toast.makeText(getApplicationContext(), (resultValue), Toast.LENGTH_LONG).show();
- spinner.setVisibility(View.GONE);
- }
- }
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement