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();
- JSONParser jsonParser = new JSONParser();
- private static final String SUCCESS_TAG = "success";
- private static final String FAILED_TAG = "failed";
- //ANNISA
- private EditText et_Username;
- // Password
- private EditText et_Password;
- String username;
- String password;
- String id;
- String hak_akses;
- String uname;
- String kode;
- String pwd;
- 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;
- int success;
- 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;
- }
- /**
- * Menyimpan Data
- */
- protected String doInBackground(String... args) {
- //int success;
- try{
- //build parameter
- List<NameValuePair> parameter = new ArrayList<NameValuePair>();
- parameter.add(new BasicNameValuePair("Username", username));
- parameter.add(new BasicNameValuePair("Password", password));
- //log watching
- Log.d("request", "starting");
- //create connection http
- JSONObject jsonObject = jsonParser.makeHttpRequest(url_cari, "GET", parameter);
- //log json respond
- Log.d("request", jsonObject.toString());
- //json usccess tag
- success = jsonObject.getInt(SUCCESS_TAG);
- if(success == 1){
- Log.d("request", "Login Success"+jsonObject.toString());
- if (jsonObject.getInt("success") == 1) {
- JSONObject localJSONObject2 = jsonObject.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");
- text = Login.this.kode;
- text2 = Login.this.hak_akses;
- text3 = Login.this.uname;
- sharedPreference.save(context, text);
- sharedPreference.save(context2, text2);
- sharedPreference.save(context3, text3);
- } else {
- }
- runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(Login.this.getApplicationContext(), "Login Berhasil", 0).show();
- }
- });
- }else{
- runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(Login.this.getApplicationContext(), "GAGAL", 0).show();
- }
- });
- Log.d("request", jsonObject.getString(FAILED_TAG));
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return null;
- }
- /**
- * Setalah selesai dialog menghilang
- **/
- protected void onPostExecute(String file_url) {
- super.onPostExecute(file_url);
- pDialog.dismiss();
- }
- }
- public void onClick(View arg0) {
- }
- 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);
- this.login = ((Button) findViewById(R.id.btn_dialog_cari));
- this.login.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- new login(et_Username.getText().toString(), et_Password.getText().toString()).execute();
- //yg ini langsung, kalau gagal harusnya tetap di halaman login tapi masih belum
- Intent localIntent = new Intent(v.getContext(),MainMenu.class);
- // localIntent(this, MainMenu.class);
- localIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(localIntent);
- runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(Login.this.getApplicationContext(), "Username: "+text3, 0).show();
- }
- });
- // if(success==1){
- // Intent localIntent = new Intent(v.getContext(),MainMenu.class);
- // // localIntent(this, MainMenu.class);
- // localIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- // startActivity(localIntent);
- // runOnUiThread(new Runnable() {
- //
- // public void run() {
- //
- // Toast.makeText(Login.this.getApplicationContext(), "Username: "+text3, 0).show();
- //
- // }
- // });
- // }else if(success==0){
- // Intent localIntent = new Intent(v.getContext(),Login.class);
- // // localIntent(this, MainMenu.class);
- // localIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- // startActivity(localIntent);
- // runOnUiThread(new Runnable() {
- //
- // public void run() {
- //
- // Toast.makeText(Login.this.getApplicationContext(), "Username dan Pass salah ", 0).show();
- //
- // }
- // });
- // }
- // else{
- // runOnUiThread(new Runnable() {
- //
- // public void run() {
- //
- // Toast.makeText(Login.this.getApplicationContext(), "beneran gagal nih ", 0).show();
- //
- // }
- // });
- // }
- }
- private void localIntent(OnClickListener onClickListener, Class<MainMenu> class1) {
- // TODO Auto-generated method stub
- }
- });
- }
- 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