Advertisement
Guest User

Untitled

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