Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.dish.menu;
- import android.app.Activity;
- import android.content.Intent;
- import android.graphics.Color;
- import android.graphics.drawable.ColorDrawable;
- import android.os.Bundle;
- import android.os.Handler;
- import android.view.View;
- import android.view.Window;
- import android.view.WindowManager;
- import android.widget.Button;
- import android.widget.Toast;
- import com.dish.menu.Login.login;
- import com.dish.nama.Awal;
- import com.dish.nama.JSONParser;
- import com.dish.nama.MainMenu;
- import com.dish.nama.R;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.util.Log;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.content.SharedPreferences.Editor;
- import java.util.ArrayList;
- import java.util.List;
- import org.apache.http.NameValuePair;
- import org.apache.http.message.BasicNameValuePair;
- import org.json.JSONException;
- import org.json.JSONObject;
- import com.dish.sharedpreferences.SharedPreference;
- import com.dish.nama.Bayar;
- import com.dish.nama.Detail;
- import com.dish.nama.Edit;
- import com.dish.nama.JSONParser;
- import com.dish.nama.MainActivity;
- import com.dish.nama.Next;
- import com.dish.nama.Print;
- import com.dish.nama.R;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.content.Intent;
- import android.view.Menu;
- import android.view.View.OnClickListener;
- import android.widget.EditText;
- import android.widget.TextView;
- public class Login extends Activity implements View.OnClickListener {
- Button login;
- private boolean doubleBackToExitPressedOnce;
- private Handler mHandler = new Handler();
- //EditText nama, no_samb, no_pin, status1, status2, status3;
- JSONParser jsonParser = new JSONParser();
- //ANNISA
- private EditText et_Username;
- // Password
- private EditText et_Password;
- // Sign In
- // private Button bt_SignIn;
- // Message
- //private TextView tv_Message;
- String username;
- String password;
- String id;
- String hak_akses;
- String uname;
- String kode;
- String pwd;
- // TextView login;
- // String [] data;
- private static String url_cari = "http://cavendish.esy.es/pdam/db_login.php";
- // JSONParser jsonParser = new JSONParser();
- private ProgressDialog pDialog;
- //sharedpreference
- private SharedPreference sharedPreference;
- Activity context = this;
- Activity context2 = this;
- Activity context3 = this;
- Activity context4 = this;
- private String text;
- private String text2;
- private String text3;
- private Boolean status_login;
- private static final String TAG_Loket = "Loket";
- class login extends AsyncTask<String, String, String> {
- /**
- * Menampilkan Progress Dialog
- */
- String username;
- String password;
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- pDialog = new ProgressDialog(Login.this);
- pDialog.setMessage("Autentikasi . . . ");
- pDialog.setIndeterminate(false);
- pDialog.setCancelable(true);
- pDialog.show();
- }
- public login(String username, String password){
- this.username = username;
- this.password = password;
- runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(Login.this.getApplicationContext(), "Masuk Asynctask", 0).show();
- }
- });
- runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(Login.this.getApplicationContext(), "Ini di class login Async: "+Login.this.username, 0).show();
- }
- });
- }
- /**
- * Menyimpan Data
- */
- protected String doInBackground(String... args) {
- // String username = et_Username.getText().toString();
- // String password = et_Password.getText().toString();
- runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(Login.this.getApplicationContext(), "Masuk DoInBackground", 0).show();
- }
- });
- try {
- ArrayList localArrayList = new ArrayList();
- localArrayList.add(new BasicNameValuePair("Username", Login.this.username));
- localArrayList.add(new BasicNameValuePair("Password", Login.this.password));
- System.out.println(localArrayList);
- JSONObject localJSONObject1 = Login.this.jsonParser.makeHttpRequest(Login.url_cari, "GET",
- localArrayList);
- Log.d("Hasil", localJSONObject1.toString());
- if (localJSONObject1.getInt("success") == 1) {
- JSONObject localJSONObject2 = localJSONObject1.getJSONArray("Hasil").getJSONObject(0);
- Login.this.id = localJSONObject2.getString("ID");
- Login.this.uname = localJSONObject2.getString("Username");
- Login.this.pwd = localJSONObject2.getString("Password");
- Login.this.hak_akses = localJSONObject2.getString("HakAkses");
- Login.this.kode = localJSONObject2.getString("Kode");
- } else {
- //Toast.makeText(Bayar.this.getApplicationContext(), "Pelanggan Telah Membayar", 0).show();
- }
- runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(Login.this.getApplicationContext(), "doinbackground "+uname, 0).show();
- }
- });
- } catch (JSONException localJSONException) {
- localJSONException.printStackTrace();
- }
- return null;
- }
- /**
- * Setalah selesai dialog menghilang
- **/
- protected void onPostExecute(String file_url) {
- // menutup progres dialog jika sudah selesai
- // super.onPostExecute(file_url);
- pDialog.dismiss();
- }
- }
- public void onClick(View arg0) {
- // Stores User name
- username = String.valueOf(et_Username.getText());
- // Stores Password
- password = String.valueOf(et_Password.getText());
- // switch (arg0.getId()) {
- // case R.id.btn_dialog_cari:
- if(text==null){
- new login(et_Username.getText().toString(), et_Password.getText().toString()).execute();
- // login a = new login();
- // Validates the User name and Password for admin, admin
- if (username.equals(this.uname) && password.equals(this.pwd)) {
- // Save the text in SharedPreference
- text = this.kode;
- text2 = this.hak_akses;
- text3 = this.username;
- sharedPreference.save(context, text);
- sharedPreference.save(context2, text2);
- sharedPreference.save(context3, text3);
- runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(Login.this.getApplicationContext(), "Login Berhasil: "+text3, 0).show();
- }
- });
- Intent localIntent = new Intent(this, MainMenu.class);
- localIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(localIntent);
- runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(Login.this.getApplicationContext(), "sharedpreference "+text3, 0).show();
- }
- });
- // finish();
- } else {
- runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(Login.this.getApplicationContext(), "Layar "+username+" database "+uname, 0).show();
- }
- });
- runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(Login.this.getApplicationContext(), "Login Gagal "+text3, 0).show();
- }
- });
- }
- }else{
- Intent localIntent = new Intent(this, MainMenu.class);
- localIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(localIntent);
- }
- //---------------------------
- // Intent localIntent = new Intent(this, MainMenu.class);
- // localIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- // startActivity(localIntent);
- // finish();
- // break;}
- }
- protected void onCreate(Bundle paramBundle) {
- super.onCreate(paramBundle);
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);
- //Remove notification bar
- this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.login);
- //sharedpreferences
- sharedPreference = new SharedPreference();
- // Initialization
- et_Username = (EditText) findViewById(R.id.ed_dialog_cari);
- et_Password = (EditText) findViewById(R.id.editText2);
- // bt_SignIn = (Button) findViewById(R.id.btn_dialog_cari);
- this.login = ((Button) findViewById(R.id.btn_dialog_cari));
- this.login.setOnClickListener(this);
- }
- private final Runnable mRunnable = new Runnable() {
- @Override
- public void run() {
- doubleBackToExitPressedOnce = false;
- }
- };
- @Override
- protected void onDestroy()
- {
- super.onDestroy();
- finish ();
- if (mHandler != null) { mHandler.removeCallbacks(mRunnable); }
- }
- @Override
- public void onBackPressed() {
- if (doubleBackToExitPressedOnce) {
- super.onBackPressed();
- return;
- }
- this.doubleBackToExitPressedOnce = true;
- Toast.makeText(this, "Tekan tombol back lagi untuk keluar", Toast.LENGTH_SHORT).show();
- mHandler.postDelayed(mRunnable, 2000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement