Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Mobile conf erich

2,181 views

Published on

Mobile conf erich

  1. 1. Aplicações Flexíveis e de fácil manutençãoFriday, April 5, 13
  2. 2. à vista 10% OFF!Friday, April 5, 13
  3. 3. MOBILECONF 10% OFF!Friday, April 5, 13
  4. 4. Erich Egert Instrutor e desenvolvedor pela Caelum encontre-me: @erichegt github.com/erichegtFriday, April 5, 13
  5. 5. ErissssshhhhhhFriday, April 5, 13
  6. 6. Friday, April 5, 13
  7. 7. Primeira tela: listagem!Friday, April 5, 13
  8. 8. De onde vêm os dados?Friday, April 5, 13
  9. 9. JSONFriday, April 5, 13
  10. 10. public class ListagemActivity extends Activity { //... @Override protected void onCreate(Bundle bundle) { //... try { HttpClient httpclient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(endereco); HttpResponse resp = httpclient.execute(httpGet); String jsonCarros = EntityUtils.toString(resp.getEntity()); // colocar no ListView } catch (Exception e) { // ... }Friday, April 5, 13
  11. 11. public class ListagemActivity extends Activity { //... @Override protected void onCreate(Bundle bundle) { //... Quem roda? try { HttpClient httpclient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(endereco); HttpResponse resp = httpclient.execute(httpGet); String jsonCarros = EntityUtils.toString(resp.getEntity()); // colocar no ListView } catch (Exception e) { // ... }Friday, April 5, 13
  12. 12. public class ListagemActivity extends Activity { //... UIThread @Override protected void onCreate(Bundle bundle) { //... try { HttpClient httpclient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(endereco); HttpResponse resp = httpclient.execute(httpGet); String jsonCarros = EntityUtils.toString(resp.getEntity()); // colocar no ListView } catch (Exception e) { // ... }Friday, April 5, 13
  13. 13. Friday, April 5, 13
  14. 14. EM PARALELO!Friday, April 5, 13
  15. 15. AsyncTask UIThread Thread (tarefa pesada)Friday, April 5, 13
  16. 16. JSON e no fim da tarefa pesada?Friday, April 5, 13
  17. 17. Tela! UIThreadFriday, April 5, 13
  18. 18. AsyncTask UIThread onPreExecute Thread doInBackground (tarefa pesada) UIThread onPostExecuteFriday, April 5, 13
  19. 19. AsyncTask UIThread onPreExecute Thread doInBackground (tarefa pesada) UIThread onPostExecuteFriday, April 5, 13
  20. 20. public class BuscaCarrosTask extends AsyncTask<Void, Void, List<Carro>>{ //... protected void onPostExecute(final List<Carro> result) { ListView listaCarros = (...) activity.findViewById(...); ArrayAdapter<Carro> adapter = new ArrayAdapter<Carro>(...); listaCarros.setAdapter(adapter); listaCarros.setOnItemClickListener( new OnItemClickListener() { public void onItemClick(...) { Carro carroSelecionado = result.get(posicao); Friday, April 5, 13
  21. 21. public class BuscaCarrosTask extends AsyncTask<Void, Void, List<Carro>>{ //... protected void onPostExecute(final List<Carro> result) { ListView listaCarros = (...) activity.findViewById(...); ArrayAdapter<Carro> adapter = new ArrayAdapter<Carro>(...); listaCarros.setAdapter(adapter); UIThread listaCarros.setOnItemClickListener( new OnItemClickListener() { public void onItemClick(...) { Carro carroSelecionado = result.get(posicao); Friday, April 5, 13
  22. 22. public class BuscaCarrosTask extends AsyncTask<Void, Void, List<Carro>>{ //... protected void onPostExecute(final List<Carro> result) { ListView listaCarros = (...) activity.findViewById(...); ArrayAdapter<Carro> adapter = new ArrayAdapter<Carro>(...); listaCarros.setAdapter(adapter); UIThread listaCarros.setOnItemClickListener( new OnItemClickListener() { public void onItemClick(...) { Carro carroSelecionado = result.get(posicao); Friday, April 5, 13
  23. 23. Task manipular tela?Friday, April 5, 13
  24. 24. Acoplamento...Friday, April 5, 13
  25. 25. DelegateFriday, April 5, 13
  26. 26. Delegate ActivityFriday, April 5, 13
  27. 27. Delegate delega! ActivityFriday, April 5, 13
  28. 28. Delegate delega! Activity AsyncTaskFriday, April 5, 13
  29. 29. Delegate delega! Activity AsyncTask lida com resultado!Friday, April 5, 13
  30. 30. public class BuscaCarrosTask extends AsyncTask<Void, Void, List<Carro>>{ //... protected void onPostExecute(final List<Carro> result) { ListView listaCarros = (...) activity.findViewById(...); ArrayAdapter<Carro> adapter = new ArrayAdapter<Carro>(...); listaCarros.setAdapter(adapter); listaCarros.setOnItemClickListener( new OnItemClickListener() { public void onItemClick(...) { Carro carroSelecionado = result.get(posicao); Friday, April 5, 13
  31. 31. public class BuscaCarrosTask extends AsyncTask<Void, Void, List<Carro>>{ //... public class BuscaCarrosTask( I quemMeChamou) {..,} protected void onPostExecute(final List<Carro> result) { quemMeChamou.lidaComResultado(result); ListView listaCarros = (...) activity.findViewById(...); } Delegate ArrayAdapter<Carro> adapter = new ArrayAdapter<Carro>(...); //... listaCarros.setAdapter(adapter); listaCarros.setOnItemClickListener( new OnItemClickListener() { public void onItemClick(...) { Carro carroSelecionado = result.get(posicao); Friday, April 5, 13
  32. 32. Tasks: DELEGATEFriday, April 5, 13
  33. 33. Segunda tela: detalhes! ...Friday, April 5, 13
  34. 34. ActivityFriday, April 5, 13
  35. 35. Intent ActivityFriday, April 5, 13
  36. 36. Intent Activity ActivityFriday, April 5, 13
  37. 37. Intent “apelido” Activity ActivityFriday, April 5, 13
  38. 38. public void onItemClick(...) { Activity 1 Carro carro = result.get(posicao); Intent irParaDetalhes = new Intent(this,DetalhesActivity.class); irParaDetalhes.putExtra("carroSelecionado",carro); } Activity 2 protected void onCreate(Bundle savedInstanceState) { TextView modelo = (TextView) findViewById(R.id.modelo); Carro carroSelecionado = (Carro) getIntent() .getSerializableExtra("carroSelecionado"); if (carroSelecionado != null) { modelo.setText(carroSelecionado.getModelo());Friday, April 5, 13
  39. 39. public void onItemClick(...) { Activity 1 Carro carro = result.get(posicao); Intent irParaDetalhes = new Intent(this,DetalhesActivity.class); irParaDetalhes.putExtra("carroSelecionado",carro); } “carroSelecionado” Activity 2 protected void onCreate(Bundle savedInstanceState) { TextView modelo = (TextView) findViewById(R.id.modelo); Carro carroSelecionado = (Carro) getIntent() .getSerializableExtra("carroSelecionado"); if (carroSelecionado != null) { modelo.setText(carroSelecionado.getModelo());Friday, April 5, 13
  40. 40. Constantes...Friday, April 5, 13
  41. 41. Intent ActivityFriday, April 5, 13
  42. 42. Intent ActivityFriday, April 5, 13
  43. 43. Intent ActivityFriday, April 5, 13
  44. 44. Intent Activity DalvikFriday, April 5, 13
  45. 45. Intent Activity Dalvik DalvikFriday, April 5, 13
  46. 46. Como passar de uma VM pra outra?Friday, April 5, 13
  47. 47. Serializar... 11 01 0 1Friday, April 5, 13
  48. 48. Serializar na mesma VM... 11 01 0 1Friday, April 5, 13
  49. 49. Serializar na mesma VM... 11 01 0 1Friday, April 5, 13
  50. 50. ParceableFriday, April 5, 13
  51. 51. Tem mais...Friday, April 5, 13
  52. 52. Friday, April 5, 13
  53. 53. Activity 2 em 1?Friday, April 5, 13
  54. 54. Vamos dividir em pedaços!Friday, April 5, 13
  55. 55. FragmentFriday, April 5, 13
  56. 56. Fragment == IF’s INFINITOS!Friday, April 5, 13
  57. 57. protected void onCreate(Bundle savedInstanceState) { //... FragmentManager manager = getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); if (isTabletNaHorizontal()) { transaction.replace(R.id.esquerda, new ListagemFragment()); transaction.replace(R.id.direita, DetalhesFragment.fragmentComCarro(null)); } else { transaction.replace(R.id.unico, new ListagemFragment()); } transaction.commit(); }Friday, April 5, 13
  58. 58. protected void onCreate(Bundle savedInstanceState) { //... FragmentManager manager = getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); if (isTabletNaHorizontal()) { transaction.replace(R.id.esquerda, new ListagemFragment()); transaction.replace(R.id.direita, DetalhesFragment.fragmentComCarro(null)); } else { transaction.replace(R.id.unico, new ListagemFragment()); } transaction.commit(); }Friday, April 5, 13
  59. 59. STRATEGYFriday, April 5, 13
  60. 60. public class FabricaDeConteudo { public static Conteudo getConteudo(CarrosActivity activity) { boolean ehTabletNaHorizontal = activity.getResources() .getBoolean(R.bool.ehTabletNaHorizontal); if (ehTabletNaHorizontal) { return new ConteudoTablet(activity); } else { return new ConteudoSmart(activity); } } }Friday, April 5, 13
  61. 61. I public class FabricaDeConteudo { public static Conteudo getConteudo(CarrosActivity activity) { boolean ehTabletNaHorizontal = activity.getResources() .getBoolean(R.bool.ehTabletNaHorizontal); if (ehTabletNaHorizontal) { return new ConteudoTablet(activity); } else { return new ConteudoSmart(activity); } } }Friday, April 5, 13
  62. 62. I public class FabricaDeConteudo { public static Conteudo getConteudo(CarrosActivity activity) { boolean ehTabletNaHorizontal = activity.getResources() .getBoolean(R.bool.ehTabletNaHorizontal); if (ehTabletNaHorizontal) { return new ConteudoTablet(activity); } else { return new ConteudoSmart(activity); } } }Friday, April 5, 13
  63. 63. public class CarrosActivity extends FragmentActivity { private Conteudo conteudo; @Override protected void onCreate(Bundle savedInstanceState) { //... conteudo = FabricaDeConteudo.getConteudo(this); } public void lidaComSelecaoDo(Carro carroSelecionado) { conteudo.lidaComSelecaoDo(carroSelecionado); } }Friday, April 5, 13
  64. 64. public class CarrosActivity extends FragmentActivity { private Conteudo conteudo; @Override protected void onCreate(Bundle savedInstanceState) { //... conteudo = FabricaDeConteudo.getConteudo(this); OU } public void lidaComSelecaoDo(Carro carroSelecionado) { conteudo.lidaComSelecaoDo(carroSelecionado); } }Friday, April 5, 13
  65. 65. public class CarrosActivity extends FragmentActivity { private Conteudo conteudo; @Override protected void onCreate(Bundle savedInstanceState) { //... conteudo = FabricaDeConteudo.getConteudo(this); OU } public void lidaComSelecaoDo(Carro carroSelecionado) { conteudo.lidaComSelecaoDo(carroSelecionado); OU } }Friday, April 5, 13
  66. 66. Fragments: Strategy!Friday, April 5, 13
  67. 67. E como ganhar $ facil?Friday, April 5, 13
  68. 68. Venda a mesma app varias vezes...Friday, April 5, 13
  69. 69. Friday, April 5, 13
  70. 70. Adapter AsyncTaskLayoutInflater LocationManager ExpandableListView MapActivityFriday, April 5, 13
  71. 71. busao SPFriday, April 5, 13
  72. 72. busao SP busao ACFriday, April 5, 13
  73. 73. busao SP busao AC busao UKFriday, April 5, 13
  74. 74. Dar uma cara novaFriday, April 5, 13
  75. 75. Plural de ônibus?Friday, April 5, 13
  76. 76. Plural de ônibus? ônibusesFriday, April 5, 13
  77. 77. LÓGICAFriday, April 5, 13
  78. 78. project librariesFriday, April 5, 13
  79. 79. Friday, April 5, 13
  80. 80. Application ResourcesFriday, April 5, 13
  81. 81. values colors.xml background_geralFriday, April 5, 13
  82. 82. values colors.xml background_geral values colors.xml background_geralFriday, April 5, 13
  83. 83. Reaproveitamento: Project Libraries! Flexibilidade: Application Resources!Friday, April 5, 13
  84. 84. comportamentos diferentesFriday, April 5, 13
  85. 85. Friday, April 5, 13
  86. 86. Friday, April 5, 13
  87. 87. Fragment ajuda nesse caso?!?Friday, April 5, 13
  88. 88. Fragment ajuda nesse caso?!?Friday, April 5, 13
  89. 89. Mas e a Activity?Friday, April 5, 13
  90. 90. Só serve pra... Intent Activity Dalvik DalvikFriday, April 5, 13
  91. 91. Na mesma App... startActivity(this, UmaActivity.class );Friday, April 5, 13
  92. 92. startActivity(???.class )Friday, April 5, 13
  93. 93. startActivity(“apelido” )Friday, April 5, 13
  94. 94. AndroidManifest Activity “apelido”Friday, April 5, 13
  95. 95. Friday, April 5, 13
  96. 96. startActivity(“apelido” )Friday, April 5, 13
  97. 97. startActivity(“apelido” )Friday, April 5, 13
  98. 98. Opis sou euzis! startActivity(“apelido” )Friday, April 5, 13
  99. 99. Intent FiltersFriday, April 5, 13
  100. 100. AndroidManifest <activity android:name=".MussumActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:host="localhost" android:pathPattern="/acao/customizada/mussum" android:scheme="busao" /> </intent-filter> </activity>Friday, April 5, 13
  101. 101. Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse( "busao://localhost/acao/customizada/"+ getResources().getString( R.string.tag_intent_implicita))); startActivity(i);Friday, April 5, 13
  102. 102. Baixo acoplamento e integração: Intent Filters!Friday, April 5, 13
  103. 103. Friday, April 5, 13
  104. 104. OBRIGADO! @erichegt github.com/erichegtFriday, April 5, 13
  105. 105. Friday, April 5, 13
  106. 106. ORM...Friday, April 5, 13
  107. 107. Friday, April 5, 13
  108. 108. Friday, April 5, 13

×