Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- String username ;
- String password;
- public void doLgin(View view) {
- if(Build.VERSION.SDK_INT >= 10){
- StrictMode.ThreadPolicy policy = StrictMode.ThreadPolicy.LAX;
- StrictMode.setThreadPolicy(policy);
- }
- username = ((EditText)findViewById(R.id.editTextUsername)).getText().toString();
- password = ((EditText)findViewById(R.id.editTextPassword)).getText().toString();
- try {
- HttpClient httpClient = new DefaultHttpClient();
- HttpGet httpPost = new HttpGet("http://182.18.163.39/m/login.php?username=" + username + "&key=" + password);
- HttpResponse response = httpClient.execute(httpPost);
- HttpEntity entity = response.getEntity();
- String responseString = EntityUtils.toString(entity);
- JSONArray jsonarray = new JSONArray(responseString);
- JSONObject jsonObj = new JSONObject();
- jsonObj.put("Result", jsonarray);
- String error = jsonObj.getJSONArray("Result").getJSONObject(0).toString();
- String errormsg = "{"Error":"Problem with authentication,Please login."}";
- if (error.equalsIgnoreCase(errormsg)) {
- Toast.makeText(getApplicationContext(), "Invalid username or password", Toast.LENGTH_SHORT).show();
- } else {
- // Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).show();
- Intent i = new Intent(MainActivity.this, Main2Activity.class);
- startActivity(i);
- }
- }
- public class Main2Activity extends AppCompatActivity {
- MainActivity m = new MainActivity();
- String user = m.username;
- String pass = m.password;
- String JSON_URL = "http://182.18.163.39/m/list.php?username=admin&key=admin";
- ListView listView;
- java.util.List<List> tktList;
- String link;
- Button logoutbt;
- Button ubt;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main2);
- logoutbt = (Button)findViewById(R.id.lbt);
- logoutbt.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- SharedPreferences SM = getSharedPreferences("userrecord", 0);
- SharedPreferences.Editor edit = SM.edit();
- edit.putBoolean("username", false);
- edit.commit();
- Intent intent = new Intent(Main2Activity.this, MainActivity.class);
- startActivity(intent);
- finish();
- }
- });
- //initializing listview and hero list
- listView = (ListView) findViewById(R.id.listView);
- tktList = new ArrayList<>();
- //this method will fetch and parse the data
- loadHeroList();
- }
- private void loadHeroList() {
- //getting the progressbar
- final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
- //making the progressbar visible
- progressBar.setVisibility(View.VISIBLE);
- //creating a string request to send request to the url
- StringRequest stringRequest = new StringRequest(Request.Method.GET, JSON_URL,
- new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- //hiding the progressbar after completion
- progressBar.setVisibility(View.INVISIBLE);
- try {
- JSONArray jsonarray = new JSONArray(response);
- for (int i = 0; i < jsonarray.length(); i++) {
- JSONObject jsonobject = jsonarray.getJSONObject(i);
- String name = jsonobject.getString("Sno");
- String Tktid = jsonobject.getString("TKTID");
- link = jsonobject.getString("Link");
- List list = new List(jsonobject.getString("Sno"), jsonobject.getString("TKTID"),jsonobject.getString("Link"));
- tktList.add(list);
- Log.i("website content", name);
- Log.i("website content", Tktid);
- Log.i("website content", link);
- }
- //creating custom adapter object
- ListViewAdapter adapter = new ListViewAdapter(tktList, getApplicationContext());
- //adding the adapter to listview
- listView.setAdapter(adapter);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- },
- new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- //displaying the error in toast if occurrs
- Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
- }
- });
- //creating a request queue
- com.android.volley.RequestQueue requestQueue = Volley.newRequestQueue(this);
- //adding the string request to request queue
- requestQueue.add(stringRequest);
- }
- }
- MainActivity m = new MainActivity();
- String user = m.username;
- String pass = m.password;
Add Comment
Please, Sign In to add comment