Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. package com.example.android.apis;
  2.  
  3. import java.util.Timer;
  4. import java.util.TimerTask;
  5.  
  6. //import com.msi.manning.chapter9.xmlanimate.R;
  7.  
  8. import android.app.Activity;
  9. import android.content.Context;
  10. import android.graphics.drawable.AnimationDrawable;
  11. import android.graphics.drawable.Drawable;
  12. import android.view.LayoutInflater;
  13. import android.view.View;
  14. import android.view.ViewGroup;
  15. import android.widget.ArrayAdapter;
  16. import android.widget.ImageView;
  17. import android.widget.TextView;
  18.  
  19. public class MyArrayAdapter extends ArrayAdapter<String> {
  20.  
  21. private final Activity context;
  22. private final String[] names;
  23. private int getViewTimesCalled = 0;
  24.  
  25.  
  26.  
  27. public MyArrayAdapter(Activity context, String[] names) {
  28. super(context, R.layout.rowlayout, names);
  29. // TODO Auto-generated constructor stub
  30. this.context = context;
  31. this.names = names;
  32. }
  33.  
  34.  
  35. public View getView(int position, View convertView, ViewGroup parent){
  36.  
  37. LayoutInflater inflater = context.getLayoutInflater();
  38. View rowView = inflater.inflate(R.layout.rowlayout, null, true);
  39. Drawable dDraw = null;
  40. dView holderView = new dView(context, position);
  41.  
  42. dDraw = holderView.dDraw;
  43. /*
  44. * There is currently an issue where only the first 4
  45. * imageViews for icon are being set to loop through
  46. * I suspect it has something to do with my animation
  47. *
  48. */
  49. TextView label = (TextView) rowView.findViewById(R.id.label);
  50. ImageView gestureImage = (ImageView) rowView.findViewById(R.id.icon);
  51. gestureImage.setBackgroundResource(R.anim.simple_animation);
  52. ImageView image = (ImageView) rowView.findViewById(R.id.icon1);
  53.  
  54. MyAnimation nAnim = new MyAnimation();
  55. Timer t = new Timer(false);
  56. t.schedule(nAnim, 100);
  57.  
  58.  
  59. image.setImageDrawable(dDraw);
  60. label.setText(names[position]);
  61.  
  62. if(names[position].startsWith("Windows7") || names[position].startsWith("iPhone")){
  63. ImageView imageView = (ImageView) rowView.findViewById(R.id.circle);
  64.  
  65.  
  66. // imageView.setImageResource(android.R.drawable.btn_star_big_on);
  67. }// the line above causes a nullpoint exception
  68.  
  69.  
  70.  
  71. return rowView;
  72. }
  73.  
  74. private class dView extends View{
  75. /* Sets an Integer array that contains the values
  76. * of all the gesture and symbol images
  77. * returns the drawable for the int you send in
  78. */
  79. Drawable dDraw = null;
  80. Integer[] symbolImage = new Integer[10];
  81. Integer[] gestureImage = new Integer[10];
  82. public dView(Context context, int i) {
  83. super(context);
  84.  
  85. setImageArray();
  86. // TODO Auto-generated constructor stub
  87. if(i < 5)
  88. dDraw = this.getResources().getDrawable(symbolImage[i]);
  89. else
  90. dDraw = this.getResources().getDrawable(symbolImage[4]);
  91.  
  92. }
  93. private void setImageArray(){
  94. symbolImage[0]= R.drawable.circle;
  95. symbolImage[1]= R.drawable.triangle;
  96. symbolImage[2]= R.drawable.upsidedowntriangle;
  97. symbolImage[3]= R.drawable.square;
  98. symbolImage[4]= R.drawable.star;
  99.  
  100. }
  101. }
  102.  
  103. class MyAnimation extends TimerTask{
  104.  
  105. public void run(){
  106.  
  107. ImageView img = (ImageView)context.findViewById(R.id.icon);
  108. if(img != null){
  109. AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
  110. frameAnimation.start();
  111. }
  112. }
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement