Advertisement
jitbiswas11

Untitled

Jul 30th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public ArrayList<Aluno> buscarTodosUsuarios() {
  2.  
  3. ArrayList<Aluno> lista = new ArrayList<Aluno>();
  4.  
  5. try {
  6.  
  7. Connection conn = ConectaMySql.obtemConexao();
  8.  
  9. String queryInserir = "SELECT * FROM ALUNO ORDER BY NOME";
  10.  
  11. PreparedStatement ppStm = conn.prepareStatement(queryInserir);
  12.  
  13. ResultSet rSet = ppStm.executeQuery();
  14.  
  15. while (rSet.next()) {
  16.  
  17. Aluno user = new Aluno();
  18.  
  19. user.setId(rSet.getInt(1));
  20.  
  21. user.setNome(rSet.getString(2));
  22.  
  23. user.setLogin(rSet.getString(3));
  24.  
  25. user.setPass(rSet.getString(4));
  26.  
  27. user.setCurso(rSet.getString(5));
  28.  
  29. user.setSegunda(rSet.getString(6));
  30.  
  31. user.setM1(rSet.getString(7));
  32.  
  33. user.setTerca(rSet.getString(8));
  34.  
  35. user.setM2(rSet.getString(9));
  36.  
  37. user.setQuarta(rSet.getString(10));
  38.  
  39. user.setM3(rSet.getString(11));
  40.  
  41. user.setQuinta(rSet.getString(12));
  42.  
  43. user.setM4(rSet.getString(13));
  44.  
  45. user.setSexta(rSet.getString(14));
  46.  
  47. user.setM5(rSet.getString(15));
  48.  
  49. user.setFoto(rSet.getBytes(16));
  50.  
  51. lista.add(user);
  52.  
  53. }
  54.  
  55. conn.close();
  56.  
  57. } catch (Exception e) {
  58.  
  59. e.printStackTrace();
  60.  
  61. return null;
  62.  
  63. }
  64.  
  65. return lista;
  66.  
  67. }
  68.  
  69. public List<Aluno> buscarTodosUsuarios() {
  70.  
  71. List<Aluno> listaUsr = new ArrayList<Aluno>();
  72.  
  73. SoapObject buscarUsuarios = new SoapObject(NAMESPACE, BUSCAR_TODOS);
  74.  
  75. SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
  76. SoapEnvelope.VER11);
  77.  
  78. envelope.setOutputSoapObject(buscarUsuarios);
  79.  
  80. envelope.implicitTypes = true;
  81.  
  82. HttpTransportSE http = new HttpTransportSE(URL);
  83.  
  84. try {
  85. http.call("urn:" + BUSCAR_TODOS, envelope);
  86.  
  87. if (envelope.getResponse() instanceof SoapObject) {
  88. SoapObject resposta = (SoapObject) envelope.getResponse();
  89.  
  90. Aluno usr = new Aluno();
  91.  
  92. usr.setId(Integer.parseInt(resposta.getProperty("id")
  93. .toString()));
  94. usr.setNome(resposta.getProperty("nome").toString());
  95. usr.setCurso(resposta.getProperty("curso").toString());
  96. usr.setSegunda(resposta.getProperty("segunda").toString());
  97. usr.setM1(resposta.getProperty("m1").toString());
  98. usr.setTerca(resposta.getProperty("terca").toString());
  99. usr.setM2(resposta.getProperty("m2").toString());
  100. usr.setQuarta(resposta.getProperty("quarta").toString());
  101. usr.setM3(resposta.getProperty("m3").toString());
  102. usr.setQuinta(resposta.getProperty("quinta").toString());
  103. usr.setM4(resposta.getProperty("m4").toString());
  104. usr.setSexta(resposta.getProperty("sexta").toString());
  105. usr.setM5(resposta.getProperty("m5").toString());
  106. String foto = resposta.getProperty("foto").toString();
  107.  
  108. usr.setTesteFoto(foto.toString());
  109.  
  110. byte[] bt = Base64.decode(foto, Base64.DEFAULT);
  111. usr.setFoto(bt);
  112. listaUsr.add(usr);
  113. } else {
  114. Vector<SoapObject> retorno = (Vector<SoapObject>) envelope
  115. .getResponse();
  116.  
  117. for (SoapObject resposta : retorno) {
  118.  
  119. Aluno usr = new Aluno();
  120.  
  121. usr.setId(Integer.parseInt(resposta.getProperty("id")
  122. .toString()));
  123. usr.setNome(resposta.getProperty("nome").toString());
  124. usr.setCurso(resposta.getProperty("curso").toString());
  125. usr.setSegunda(resposta.getProperty("segunda").toString());
  126. usr.setM1(resposta.getProperty("m1").toString());
  127. usr.setTerca(resposta.getProperty("terca").toString());
  128. usr.setM2(resposta.getProperty("m2").toString());
  129. usr.setQuarta(resposta.getProperty("quarta").toString());
  130. usr.setM3(resposta.getProperty("m3").toString());
  131. usr.setQuinta(resposta.getProperty("quinta").toString());
  132. usr.setM4(resposta.getProperty("m4").toString());
  133. usr.setSexta(resposta.getProperty("sexta").toString());
  134. usr.setM5(resposta.getProperty("m5").toString());
  135. String foto = resposta.getProperty("foto").toString();
  136.  
  137. usr.setTesteFoto(foto.toString());
  138.  
  139. byte[] bt = Base64.decode(foto, Base64.DEFAULT);
  140. usr.setFoto(bt);
  141. listaUsr.add(usr);
  142. }
  143. }
  144.  
  145. } catch (Exception e) {
  146. e.printStackTrace();
  147. return null;
  148. }
  149.  
  150. return listaUsr;
  151. }
  152.  
  153. public class ListarTodosActivity extends Activity {
  154.  
  155. private ListView lvUsuario;
  156. private List<Aluno> usrs;
  157. private AlunoDAO dao;
  158.  
  159. @Override
  160. protected void onCreate(Bundle savedInstanceState) {
  161. super.onCreate(savedInstanceState);
  162. setContentView(R.layout.activity_listartodos);
  163.  
  164. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
  165. .permitAll().build();
  166. StrictMode.setThreadPolicy(policy);
  167.  
  168. dao = new AlunoDAO();
  169. lvUsuario = (ListView) findViewById(R.id.lvListarTodos);
  170.  
  171. usrs = dao.buscarTodosUsuarios();
  172.  
  173. AlunoAdapter usrAdp = new AlunoAdapter(this, usrs);
  174. lvUsuario.setAdapter(usrAdp);
  175.  
  176. lvUsuario.setOnItemClickListener(new OnItemClickListener() {
  177.  
  178. public void onItemClick(AdapterView<?> parent, View view,
  179. int position, long id) {
  180.  
  181. Aluno aluno = (Aluno) lvUsuario.getItemAtPosition(position);
  182.  
  183. Intent intent = new Intent(ListarTodosActivity.this,
  184. DetalhesActivity.class);
  185. intent.putExtra("ALUNO_NOME", aluno.getNome().toString());
  186. intent.putExtra("ALUNO_CURSO", aluno.getCurso().toString());
  187. intent.putExtra("ALUNO_FOTO", aluno.getTesteFoto().toString());// envio
  188. // a
  189. // string
  190. // da
  191. // foto
  192. // do
  193. // banco
  194. // para
  195. // meu
  196. // detalhesActivity.class
  197. intent.putExtra("ALUNO_DIA1", aluno.getSegunda().toString());
  198. intent.putExtra("ALUNO_M1", aluno.getM1().toString());
  199. intent.putExtra("ALUNO_DIA2", aluno.getTerca().toString());
  200. intent.putExtra("ALUNO_M2", aluno.getM2().toString());
  201. intent.putExtra("ALUNO_DIA3", aluno.getQuarta().toString());
  202. intent.putExtra("ALUNO_M3", aluno.getM3().toString());
  203. intent.putExtra("ALUNO_DIA4", aluno.getQuinta().toString());
  204. intent.putExtra("ALUNO_M4", aluno.getM4().toString());
  205. intent.putExtra("ALUNO_DIA5", aluno.getSexta().toString());
  206. intent.putExtra("ALUNO_M5", aluno.getM5().toString());
  207.  
  208. startActivity(intent);
  209.  
  210. }
  211.  
  212. });
  213. }
  214.  
  215. public class AlunoAdapter extends BaseAdapter {
  216.  
  217. private List<Aluno> usrs;
  218. private Context context;
  219.  
  220. public AlunoAdapter(Context context, List<Aluno> usrs) {
  221. this.usrs = usrs;
  222. this.context = context;
  223. }
  224.  
  225. @Override
  226. public int getCount() {
  227. return usrs.size();
  228. }
  229.  
  230. @Override
  231. public Object getItem(int arg0) {
  232. return usrs.get(arg0);
  233. }
  234.  
  235. @Override
  236. public long getItemId(int arg0) {
  237. return usrs.get(arg0).getId();
  238. }
  239.  
  240. @Override
  241. public View getView(int position, View convertView, ViewGroup parent) {
  242.  
  243. View rootView = LayoutInflater.from(context).inflate(
  244. R.layout.activity_modelo_aluno, parent, false);
  245.  
  246. ImageView imgFoto = (ImageView) rootView.findViewById(R.id.imgFoto);
  247. TextView txtNome = (TextView) rootView.findViewById(R.id.txtNome);
  248. TextView txtCurso = (TextView) rootView.findViewById(R.id.txtCurso);
  249.  
  250. Aluno usuarioDaVez = usrs.get(position);
  251.  
  252. txtNome.setText(usuarioDaVez.getNome());
  253. txtCurso.setText(usuarioDaVez.getCurso());
  254.  
  255. Bitmap bitmap = BitmapFactory.decodeByteArray(usuarioDaVez.getFoto(),
  256. 0, usuarioDaVez.getFoto().length);
  257. imgFoto.setImageBitmap(bitmap);
  258.  
  259. return rootView;
  260. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement