IconTextArrayAdapter.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package epson.print;
  2. import android.content.Context;
  3. import android.view.LayoutInflater;
  4. import android.view.View;
  5. import android.view.ViewGroup;
  6. import android.widget.ImageView;
  7. import android.widget.LinearLayout;
  8. import android.widget.TextView;
  9. import com.felipecsl.asymmetricgridview.library.widget.AsymmetricGridView;
  10. import com.felipecsl.asymmetricgridview.library.widget.AsymmetricGridViewAdapter;
  11. import java.util.List;
  12. public class IconTextArrayAdapter extends AsymmetricGridViewAdapter<IconTextArrayItem> {
  13. private static float LANDSCAPE_FONTSIZE_RATIO = 4.2f;
  14. private static float LANDSCAPE_RATIO = 2.8f;
  15. private static float PORTRATE_FONTSIZE_RATIO = 7.5f;
  16. private static float PORTRATE_RATIO = 1.0f;
  17. private static final String TAG = "IconTextArrayAdapter";
  18. private int height = 0;
  19. private LayoutInflater inflater;
  20. private List<IconTextArrayItem> items;
  21. private int line = 0;
  22. private int textViewResourceId;
  23. private ViewGroup viewGroup = null;
  24. public IconTextArrayAdapter(Context context, int i, List<IconTextArrayItem> list, AsymmetricGridView asymmetricGridView) {
  25. super(context, asymmetricGridView, list);
  26. textViewResourceId = i;
  27. items = list;
  28. inflater = (LayoutInflater) context.getSystemService(Service.LAYOUT_INFLATER_SERVICE);
  29. }
  30. public View getActualView(int i, View view, ViewGroup viewGroup2) {
  31. if (view == null) {
  32. view = inflater.inflate(textViewResourceId, (ViewGroup) null);
  33. }
  34. switch (line) {
  35. case 0:
  36. view.setBackgroundColor(view.getContext().getResources().getColor(R.color.home_line1));
  37. break;
  38. case 1:
  39. view.setBackgroundColor(view.getContext().getResources().getColor(R.color.home_line2));
  40. break;
  41. case 2:
  42. view.setBackgroundColor(view.getContext().getResources().getColor(R.color.home_line3));
  43. break;
  44. case 3:
  45. view.setBackgroundColor(view.getContext().getResources().getColor(R.color.home_line4));
  46. break;
  47. case 4:
  48. view.setBackgroundColor(view.getContext().getResources().getColor(R.color.home_line5));
  49. break;
  50. case 5:
  51. view.setBackgroundColor(view.getContext().getResources().getColor(R.color.home_line6));
  52. break;
  53. }
  54. switch (view.getResources().getConfiguration().orientation) {
  55. case 2:
  56. ((LinearLayout) view).setOrientation(0);
  57. View findViewById = view.findViewById(R.id.screen_image);
  58. ViewGroup.LayoutParams layoutParams = findViewById.getLayoutParams();
  59. layoutParams.width = 0;
  60. layoutParams.height = -1;
  61. findViewById.setLayoutParams(layoutParams);
  62. findViewById.requestLayout();
  63. View findViewById2 = view.findViewById(R.id.rl_text);
  64. ViewGroup.LayoutParams layoutParams2 = findViewById2.getLayoutParams();
  65. layoutParams2.width = 0;
  66. layoutParams2.height = -1;
  67. findViewById2.setLayoutParams(layoutParams2);
  68. findViewById.requestLayout();
  69. break;
  70. }
  71. IconTextArrayItem iconTextArrayItem = items.get(i);
  72. TextView textView = (TextView) view.findViewWithTag("text");
  73. textView.setText(iconTextArrayItem.menuId);
  74. switch (view.getResources().getConfiguration().orientation) {
  75. case 1:
  76. textView.setTextSize(0, ((float) height) / PORTRATE_FONTSIZE_RATIO);
  77. break;
  78. case 2:
  79. textView.setTextSize(0, ((float) height) / LANDSCAPE_FONTSIZE_RATIO);
  80. textView.setGravity(19);
  81. break;
  82. }
  83. ((ImageView) view.findViewWithTag("icon")).setImageResource(iconTextArrayItem.imageID);
  84. return view;
  85. }
  86. public View getView(int i, View view, ViewGroup viewGroup2) {
  87. line = i;
  88. switch (viewGroup2.getResources().getConfiguration().orientation) {
  89. case 1:
  90. height = (((float) ((AsymmetricGridView) viewGroup2).getColumnWidth()) / PORTRATE_RATIO);
  91. break;
  92. case 2:
  93. height = (((float) ((AsymmetricGridView) viewGroup2).getColumnWidth()) / LANDSCAPE_RATIO);
  94. break;
  95. }
  96. View view2 = super.getView(i, view, viewGroup2);
  97. int i2 = 0;
  98. while (true) {
  99. ViewGroup viewGroup3 = (ViewGroup) view2;
  100. if (i2 >= viewGroup3.getChildCount()) {
  101. return view2;
  102. }
  103. ViewGroup viewGroup4 = (ViewGroup) viewGroup3.getChildAt(i2);
  104. ViewGroup.LayoutParams layoutParams = viewGroup4.getChildAt(0).getLayoutParams();
  105. layoutParams.height = height;
  106. viewGroup4.getChildAt(0).setLayoutParams(layoutParams);
  107. viewGroup4.getChildAt(0).requestLayout();
  108. i2++;
  109. }
  110. }
  111. }