-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoggedActivity.java
124 lines (102 loc) · 4.33 KB
/
LoggedActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package com.example.fred.securitycenter;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class LoggedActivity extends AppCompatActivity {
private AccessServiceAPI m_serviceAccess;
private ProgressDialog m_progressDialog;
private ListView listaModulos;
private List<Module> customList;
private ModuleAdapter adapter;
private String username;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_logged);
m_serviceAccess = new AccessServiceAPI();
adapter = new ModuleAdapter(new ArrayList(), this);
listaModulos = (ListView) findViewById(R.id.listView_modules);
listaModulos.setAdapter(adapter);
Intent intent = getIntent();
username = intent.getStringExtra("username");
Log.d("GetExtra (Username): ",username);
new TaskModules().execute(username.toString());
//CLICK EVENT: ListView
listaModulos.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int codigoModulo = position;
Module moduloClicado = (Module) listaModulos.getItemAtPosition(codigoModulo);
Toast.makeText(getApplicationContext(), moduloClicado.getDominio(), Toast.LENGTH_SHORT).show();
try
{
Class moduloAtivo = Class.forName("com.example.fred.securitycenter.ModuleActivity");
Intent intSelecionado = new Intent(getApplicationContext(), moduloAtivo);
intSelecionado.putExtra("id_modulo",moduloClicado.getId_modulo().toString());
intSelecionado.putExtra("dominio",moduloClicado.getDominio().toString());
intSelecionado.putExtra("username", username.toString());
startActivity(intSelecionado);
} catch (ClassNotFoundException e)
{
e.printStackTrace();
}
}
});
//CLICK EVENT: FIM
}//fim OnCreate
//AsyncTask pra montar o listview
public class TaskModules extends AsyncTask<String, Void, List<Module>>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
//Abre dialog de progresso durante o login
m_progressDialog = ProgressDialog.show(LoggedActivity.this, "Espere por favor...", "Em progresso...", true);
}
@Override
protected List<Module> doInBackground(String... params) {
try {
customList = new ArrayList<>();
Map<String, String> param = new HashMap<>();
param.put("action", "loadModules");
param.put("username", params[0]);
//Recebe a resposta do web service (JsonArray) para montar a listview de módulos:
JSONArray arr = m_serviceAccess.getJSONArrayWithParam_POST(Common.SERVICE_API_URL, param);
Gson gson = new Gson();
Type type = new TypeToken<List<Module>>(){}.getType();
customList = gson.fromJson(arr.toString(), type);
}
catch (Throwable t)
{
t.printStackTrace();
}
//return null;
return customList;
}
@Override
protected void onPostExecute(List<Module> result)
{
super.onPostExecute(result);
m_progressDialog.dismiss();
adapter.setItemList(result);
adapter.notifyDataSetChanged();
}
}
}