Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ua.gamstudiostandart.logo;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.os.AsyncTask;
- import android.os.Handler;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.view.animation.Animation;
- import android.view.animation.AnimationUtils;
- import android.widget.EditText;
- import android.widget.ImageButton;
- import android.widget.ProgressBar;
- import android.widget.TextView;
- import android.widget.Toast;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.io.IOException;
- import okhttp3.FormBody;
- import okhttp3.OkHttpClient;
- import okhttp3.Request;
- import okhttp3.RequestBody;
- import okhttp3.Response;
- public class ActivityLogoTwo extends AppCompatActivity implements View.OnClickListener{
- Intent intentLogoTwo;
- ProgressBar progressBar2;
- EditText editEmailLogoTwo, editPasworldLogoTwo;
- ImageButton imageButtonSignInLogoTwo;
- TextView textViewFprgotPassLogoTwo;
- SharedPreferences sPref1;
- final String SAVE_EMALE_LOGO_TWO = "save_email";
- Context mContext2;
- String emailLogoTwo;
- String passwordLogoTwo;
- Animation anim;
- Handler h;
- String rer;
- int a;
- public static String API_DOMAINONE = "http://dev.mypos.com.sg/api/";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_activity_logo_two);
- intentLogoTwo = new Intent(this, MainActivity.class);
- mContext2 = getApplicationContext ();
- progressBar2 = (ProgressBar) findViewById(R.id.progressBar2);
- imageButtonSignInLogoTwo = (ImageButton)findViewById(R.id.imageButtonSignInLogoTwo);
- imageButtonSignInLogoTwo.setOnClickListener(this);
- editEmailLogoTwo = (EditText)findViewById(R.id.editEmailLogoTwo);
- editPasworldLogoTwo = (EditText)findViewById(R.id.editPasworldLogoTwo);
- textViewFprgotPassLogoTwo = (TextView)findViewById(R.id.textViewFprgotPassLogoTwo);
- textViewFprgotPassLogoTwo.setOnClickListener(this);
- anim = AnimationUtils.loadAnimation(this, R.anim.myalpha);
- h = new Handler(){
- public void handleMessage(android.os.Message msg){
- if (msg.what == 1){
- starterLogo();
- }else {
- tos();
- }
- }
- };
- }
- public class FeedTask extends AsyncTask<String, View, String> {
- @Override
- protected String doInBackground(String... params) {
- OkHttpClient client = new OkHttpClient();
- RequestBody formBody = new FormBody.Builder()
- .add("identity", emailLogoTwo)
- .add("password", passwordLogoTwo)
- .build();
- Request request = new Request.Builder()
- .url(ActivityLogo.API_DOMAIN + "auth/login")
- .post(formBody)
- .build();
- Response response = null;
- try {
- response = client.newCall(request).execute();
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- JSONObject jsonObj = null;
- if (response != null) {
- jsonObj = new JSONObject(response.body().string());
- String trufalse = jsonObj.getString("status");
- Log.d("myLOG", "" + trufalse);
- rer = trufalse;
- if (rer == "true") {
- a = 1;
- } else {
- a = 2;
- }
- h.sendEmptyMessage(a);
- }
- } catch (JSONException | IOException | NullPointerException e) {
- e.printStackTrace();
- }
- return null;
- }
- }
- @Override
- public void onClick(View v) {
- switch (v.getId()){
- case R.id.imageButtonSignInLogoTwo:
- imageButtonSignInLogoTwo.startAnimation(anim);
- imageButtonSignInLogoTwo.setEnabled(false);
- progressBar2.setVisibility(View.VISIBLE);
- emailLogoTwo = editEmailLogoTwo.getText().toString();
- passwordLogoTwo = editPasworldLogoTwo.getText().toString();
- saveTextLodoTwo();
- Thread t = new Thread(new Runnable() {
- public void run() {
- new FeedTask().execute();
- }
- });
- t.start();
- break;
- case R.id.textViewFprgotPassLogoTwo:
- break;
- }
- }
- private void saveTextLodoTwo (){
- sPref1 = mContext2.getSharedPreferences("myAppPrefs", Context.MODE_PRIVATE);
- SharedPreferences.Editor ed = sPref1.edit();
- ed.putString(SAVE_EMALE_LOGO_TWO, emailLogoTwo);
- ed.commit();
- }
- public void starterLogo(){
- startActivity(intentLogoTwo);
- this.finish();
- progressBar2.setVisibility(View.GONE);
- imageButtonSignInLogoTwo.setEnabled(true);
- }
- public void tos(){
- Toast.makeText(this, "Not correct Username or Password", Toast.LENGTH_LONG).show();
- progressBar2.setVisibility(View.GONE);
- imageButtonSignInLogoTwo.setEnabled(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement