Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.51 KB | None | 0 0
  1. package ua.gamstudiostandart.logo;
  2.  
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.content.SharedPreferences;
  6. import android.os.AsyncTask;
  7. import android.os.Handler;
  8. import android.support.v7.app.AppCompatActivity;
  9. import android.os.Bundle;
  10. import android.util.Log;
  11. import android.view.View;
  12. import android.view.animation.Animation;
  13. import android.view.animation.AnimationUtils;
  14. import android.widget.EditText;
  15. import android.widget.ImageButton;
  16. import android.widget.ProgressBar;
  17. import android.widget.TextView;
  18. import android.widget.Toast;
  19.  
  20. import org.json.JSONException;
  21. import org.json.JSONObject;
  22.  
  23. import java.io.IOException;
  24.  
  25. import okhttp3.FormBody;
  26. import okhttp3.OkHttpClient;
  27. import okhttp3.Request;
  28. import okhttp3.RequestBody;
  29. import okhttp3.Response;
  30.  
  31. public class ActivityLogoTwo extends AppCompatActivity implements View.OnClickListener{
  32.  
  33.     Intent intentLogoTwo;
  34.     ProgressBar progressBar2;
  35.     EditText editEmailLogoTwo, editPasworldLogoTwo;
  36.     ImageButton imageButtonSignInLogoTwo;
  37.     TextView textViewFprgotPassLogoTwo;
  38.     SharedPreferences sPref1;
  39.     final String SAVE_EMALE_LOGO_TWO = "save_email";
  40.     Context mContext2;
  41.     String emailLogoTwo;
  42.     String passwordLogoTwo;
  43.     Animation anim;
  44.     Handler h;
  45.     String rer;
  46.     int a;
  47.     public static String API_DOMAINONE = "http://dev.mypos.com.sg/api/";
  48.  
  49.     @Override
  50.     protected void onCreate(Bundle savedInstanceState) {
  51.         super.onCreate(savedInstanceState);
  52.         setContentView(R.layout.activity_activity_logo_two);
  53.         intentLogoTwo = new Intent(this, MainActivity.class);
  54.         mContext2 = getApplicationContext ();
  55.         progressBar2 = (ProgressBar) findViewById(R.id.progressBar2);
  56.         imageButtonSignInLogoTwo = (ImageButton)findViewById(R.id.imageButtonSignInLogoTwo);
  57.         imageButtonSignInLogoTwo.setOnClickListener(this);
  58.         editEmailLogoTwo = (EditText)findViewById(R.id.editEmailLogoTwo);
  59.         editPasworldLogoTwo = (EditText)findViewById(R.id.editPasworldLogoTwo);
  60.         textViewFprgotPassLogoTwo = (TextView)findViewById(R.id.textViewFprgotPassLogoTwo);
  61.         textViewFprgotPassLogoTwo.setOnClickListener(this);
  62.         anim = AnimationUtils.loadAnimation(this, R.anim.myalpha);
  63.  
  64.         h = new Handler(){
  65.             public void handleMessage(android.os.Message msg){
  66.                 if (msg.what == 1){
  67.                     starterLogo();
  68.  
  69.                 }else {
  70.                     tos();
  71.                 }
  72.             }
  73.         };
  74.     }
  75.  
  76.     public class FeedTask extends AsyncTask<String, View, String> {
  77.         @Override
  78.         protected String doInBackground(String... params) {
  79.             OkHttpClient client = new OkHttpClient();
  80.             RequestBody formBody = new FormBody.Builder()
  81.                     .add("identity", emailLogoTwo)
  82.                     .add("password", passwordLogoTwo)
  83.                     .build();
  84.             Request request = new Request.Builder()
  85.                     .url(ActivityLogo.API_DOMAIN + "auth/login")
  86.                     .post(formBody)
  87.                     .build();
  88.             Response response = null;
  89.             try {
  90.                 response = client.newCall(request).execute();
  91.             } catch (IOException e) {
  92.                 e.printStackTrace();
  93.             }
  94.             try {
  95.                 JSONObject jsonObj = null;
  96.                 if (response != null) {
  97.                     jsonObj = new JSONObject(response.body().string());
  98.                     String trufalse = jsonObj.getString("status");
  99.                     Log.d("myLOG", "" + trufalse);
  100.                     rer = trufalse;
  101.                     if (rer == "true") {
  102.                         a = 1;
  103.                     } else {
  104.                         a = 2;
  105.                     }
  106.                     h.sendEmptyMessage(a);
  107.                 }
  108.             } catch (JSONException | IOException | NullPointerException e) {
  109.                 e.printStackTrace();
  110.             }
  111.             return null;
  112.         }
  113.     }
  114.     @Override
  115.     public void onClick(View v) {
  116.         switch (v.getId()){
  117.             case R.id.imageButtonSignInLogoTwo:
  118.                 imageButtonSignInLogoTwo.startAnimation(anim);
  119.                 imageButtonSignInLogoTwo.setEnabled(false);
  120.                 progressBar2.setVisibility(View.VISIBLE);
  121.                 emailLogoTwo = editEmailLogoTwo.getText().toString();
  122.                 passwordLogoTwo = editPasworldLogoTwo.getText().toString();
  123.                 saveTextLodoTwo();
  124.                 Thread t = new Thread(new Runnable() {
  125.                     public void run() {
  126.                         new FeedTask().execute();
  127.                     }
  128.                 });
  129.                 t.start();
  130.                 break;
  131.             case R.id.textViewFprgotPassLogoTwo:
  132.                 break;
  133.         }
  134.     }
  135.     private void saveTextLodoTwo (){
  136.         sPref1 = mContext2.getSharedPreferences("myAppPrefs", Context.MODE_PRIVATE);
  137.         SharedPreferences.Editor ed = sPref1.edit();
  138.         ed.putString(SAVE_EMALE_LOGO_TWO, emailLogoTwo);
  139.         ed.commit();
  140.     }
  141.     public void starterLogo(){
  142.         startActivity(intentLogoTwo);
  143.         this.finish();
  144.         progressBar2.setVisibility(View.GONE);
  145.         imageButtonSignInLogoTwo.setEnabled(true);
  146.     }
  147.     public void tos(){
  148.         Toast.makeText(this, "Not correct Username or Password", Toast.LENGTH_LONG).show();
  149.         progressBar2.setVisibility(View.GONE);
  150.         imageButtonSignInLogoTwo.setEnabled(true);
  151.     }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement