Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ua.gamstudiostandart.logo;
- 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.File;
- import java.io.IOException;
- import okhttp3.FormBody;
- import okhttp3.OkHttpClient;
- import okhttp3.Request;
- import okhttp3.RequestBody;
- import okhttp3.Response;
- public class ActivityLogo extends AppCompatActivity implements View.OnClickListener{
- File f;
- Intent intentProverkaLogoOne, intentLogoOne;
- ProgressBar progressBar;
- TextView textViewEmailLogoOne, textViewForgetPassLogoOne, textViewNotYourMailLogoOne;
- ImageButton imageButtonSingInLogoOne;
- EditText editPasworldLogoOne;
- SharedPreferences sPref1;
- final String SAVE_EMALE_LOGO_ONE = "save_email";
- String emailLogoOne;
- String passwordLogoOne;
- Animation anim;
- Handler h;
- String rer;
- int a;
- public static String API_DOMAIN = "http://dev.mypos.com.sg/api/";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- f = new File("/data/data/" + getPackageName() + "/shared_prefs/myAppPrefs.xml");
- intentProverkaLogoOne = new Intent(this, ActivityLogoTwo.class);
- intentLogoOne = new Intent(this, MainActivity.class);
- anim = AnimationUtils.loadAnimation(this, R.anim.myalpha);
- if (f.exists() == false){
- startActivity(intentProverkaLogoOne);
- this.finish();
- }else {
- load_textLogoOne();
- }
- setContentView(R.layout.activity_logo);
- progressBar =(ProgressBar)findViewById(R.id.progressBar);
- textViewEmailLogoOne = (TextView)findViewById(R.id.textViewEmailLogoOne);
- textViewEmailLogoOne.setText(emailLogoOne);
- textViewForgetPassLogoOne = (TextView)findViewById(R.id.textViewForgetPassLogoOne);
- textViewForgetPassLogoOne.setOnClickListener(this);
- textViewNotYourMailLogoOne = (TextView)findViewById(R.id.textViewNotYourMailLogoOne);
- textViewNotYourMailLogoOne.setOnClickListener(this);
- imageButtonSingInLogoOne = (ImageButton)findViewById(R.id.imageButtonSingInLogoOne);
- imageButtonSingInLogoOne.setOnClickListener(this);
- editPasworldLogoOne = (EditText)findViewById(R.id.editPasworldLogoOne);
- 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", emailLogoOne)
- .add("password", passwordLogoOne)
- .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.imageButtonSingInLogoOne:
- imageButtonSingInLogoOne.startAnimation(anim);
- String etLogPas = editPasworldLogoOne.getText().toString();
- passwordLogoOne = etLogPas;
- imageButtonSingInLogoOne.setEnabled(false);
- progressBar.setVisibility(View.VISIBLE);
- Thread t = new Thread(new Runnable() {
- public void run() {
- new FeedTask().execute();
- }
- });
- t.start();
- break;
- case R.id.textViewForgetPassLogoOne:
- break;
- case R.id.textViewNotYourMailLogoOne:
- startActivity(intentProverkaLogoOne);
- this.finish();
- break;
- }
- }
- public void load_textLogoOne(){
- sPref1 = getSharedPreferences("myAppPrefs", MODE_PRIVATE);
- emailLogoOne = sPref1.getString(SAVE_EMALE_LOGO_ONE, "");
- }
- public void starterLogo(){
- startActivity(intentLogoOne);
- this.finish();
- progressBar.setVisibility(View.GONE);
- imageButtonSingInLogoOne.setEnabled(true);
- }
- public void tos(){
- Toast.makeText(this, "Not correct Username or Password", Toast.LENGTH_LONG).show();
- progressBar.setVisibility(View.GONE);
- imageButtonSingInLogoOne.setEnabled(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement