· 8 years ago · Aug 07, 2018, 02:30 PM
1package com.lmt;
2
3import android.app.Activity;
4import android.app.AlertDialog;
5import android.content.DialogInterface;
6import android.content.Intent;
7import android.database.Cursor;
8import android.database.sqlite.SQLiteDatabase;
9import android.os.Bundle;
10import android.text.InputType;
11import android.text.TextUtils.TruncateAt;
12import android.text.method.PasswordTransformationMethod;
13import android.util.Log;
14import android.view.View;
15import android.view.Window;
16import android.widget.Button;
17import android.widget.CheckBox;
18import android.widget.CompoundButton;
19import android.widget.EditText;
20import android.widget.ImageView;
21import android.widget.Toast;
22
23public class Home extends Activity {
24
25 AlertDialog.Builder alert;
26 EditText home_password;
27 CheckBox home_pwd_revel;
28 Button home_ok,home_reset;
29 String TAG="lmt";
30 String get_pwd;
31 SQLiteDatabase myDB= null;
32 String TableName = "password";
33 String last_stored_data;
34 String Name;
35 @Override
36 public void onCreate(Bundle savedInstanceState)
37 {
38 super.onCreate(savedInstanceState);
39 setContentView(R.layout.home);
40
41 home_password = (EditText)findViewById(R.id.home_pwd);
42 home_pwd_revel = (CheckBox)findViewById(R.id.checkBox2);
43 home_ok = (Button)findViewById(R.id.home_ok);
44 home_reset = (Button)findViewById(R.id.home_reset);
45
46 home_reset.setOnClickListener(new Button.OnClickListener() {
47 @Override
48 public void onClick(View v) {
49 // TODO Auto-generated method stub
50 Log.v(TAG, "EditText Resetted");
51 home_password.requestFocus();
52 home_password.setText("");
53 }
54 });
55
56 home_password.setEllipsize(TruncateAt.END);
57 home_password.setSingleLine();
58 home_password.setTransformationMethod(PasswordTransformationMethod.getInstance());
59
60
61 home_pwd_revel.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
62
63 @Override
64 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
65 // TODO Auto-generated method stub
66 if(isChecked)
67 {
68 Log.v(TAG, "Show Password");
69 home_password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
70
71 }
72 else
73 {
74 Log.v(TAG, "Hide Password");
75 home_password.setTransformationMethod(PasswordTransformationMethod.getInstance());
76
77 }
78 }
79 });
80
81 // Get Intent value
82
83 Intent intent = getIntent();
84 get_pwd = intent.getStringExtra("startact_pass");
85 Log.v(TAG,"Intent Received :"+get_pwd);
86
87
88
89 // Create Database Insert into Database
90
91 try {
92 myDB = openOrCreateDatabase("myTestDb", SQLiteDatabase.CREATE_IF_NECESSARY, null);
93
94 /* Create a Table in the Database. */
95 myDB.execSQL("CREATE TABLE IF NOT EXISTS "
96 + TableName
97 + " (Field1 VARCHAR);");
98
99 /* Insert data to a Table*/
100 myDB.execSQL("INSERT INTO "
101 + TableName
102 + " (Field1)"
103 + " VALUES ('" + get_pwd + "' );");
104
105 }
106 catch(Exception e)
107 {
108 Log.d("lmt", "Error :"+ e.toString());
109 }
110 finally
111 {
112 if (myDB != null)
113 myDB.close();
114 }
115
116 // read Database
117 myDB = openOrCreateDatabase("myTestDb", SQLiteDatabase.CREATE_IF_NECESSARY, null);
118
119
120 Cursor c = myDB.rawQuery("SELECT * FROM " + TableName , null);
121
122 // Used To Display Last Insrted Record
123 int Column1 = c.getColumnIndex("Field1");
124 // Check if our result was valid.
125 c.moveToLast();
126 if (c != null) {
127 // Loop through all Results
128 do {
129 Name = c.getString(Column1);
130 last_stored_data = Name;
131 Log.v(TAG, "Inserted Database :"+ Name);;
132 }while(c.moveToNext());
133 }
134 Log.v(TAG, "Read Last Inserted Database :"+ last_stored_data);
135 c.close();
136 myDB.close();
137
138 home_ok.setOnClickListener(new Button.OnClickListener() {
139
140 @Override
141 public void onClick(View v) {
142 // TODO Auto-generated method stub
143 if(home_password.length() > 5)
144 {
145 Log.v(TAG,"home password > 5");
146 Log.v(TAG,"EdiText pwd :"+home_password.getText().toString());
147 Log.v(TAG,"Last Stored PWd In DB :"+last_stored_data);
148 if(home_password.getText().toString().equals(Name))
149 {
150 Log.v(TAG,"Entered password == Last Stored Pwd on Database ");
151 Intent i = new Intent(Home.this,AndroidTabLayoutActivity.class);
152 startActivity(i);
153 finish();
154 }
155 else
156 {
157 Log.v(TAG, "Read :"+ last_stored_data);
158 Toast.makeText(getApplicationContext(), "Last stored data != entered password", Toast.LENGTH_LONG).show();
159 }
160 }
161 else
162 {
163 home_password.setError("Password Must be Greater Then 6 Charachetrs");
164 }
165 }
166 });
167 }
168 @Override
169 public void onBackPressed()
170 {
171 Log.e("lmt ", "Back is pressed! ");
172 AlertDialog.Builder delmessagebuilder = new AlertDialog.Builder(this);
173 delmessagebuilder.setCancelable(false);
174 delmessagebuilder.setMessage("Do You Really Want to Exit !");
175 delmessagebuilder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
176
177 @Override
178 public void onClick(DialogInterface dialog, int which) {
179 // TODO Auto-generated method stub
180 dialog.dismiss();
181 finish();
182 }
183 });
184 delmessagebuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
185
186 @Override
187 public void onClick(DialogInterface dialog, int which) {
188 // TODO Auto-generated method stub
189
190 }
191 });
192 delmessagebuilder.show();
193 }
194}