Guest User

Untitled

a guest
Jul 18th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.08 KB | None | 0 0
  1. public class Test extends Activity implements OnClickListener {
  2. ImageView paint, wheels, shadow;
  3.  
  4. Button b;
  5. int j = 2;
  6. int i = 1;
  7. String pathToWheels, pathToPaint, pathToShadow;
  8. String stringAngle;
  9.  
  10. /** Called when the activity is first created. */
  11. @Override
  12. public void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.main);
  15.  
  16. MemoryInfo dbm = new MemoryInfo();
  17. Debug.getMemoryInfo(dbm);
  18. b = (Button) findViewById(R.id.button1);
  19. b.setOnClickListener(this);
  20.  
  21.  
  22.  
  23. wheels = (ImageView) findViewById(R.id.imageView3);
  24. paint = (ImageView) findViewById(R.id.imageView2);
  25. shadow = (ImageView) findViewById(R.id.imageView1);
  26.  
  27.  
  28.  
  29. while (i < 13) {
  30.  
  31. stringAngle = Integer.toString(i);
  32. String pathToWheels = url;
  33. String pathToPaint = url;
  34. String pathToShadow = url;
  35.  
  36. if (Cache.getCacheFile(pathToWheels) == null) {
  37. ImageDownloader downloader1 = new ImageDownloader(wheels);
  38. downloader1
  39. .execute(url);
  40. } else if (Cache.getCacheFile(pathToShadow) == null) {
  41. ImageDownloader downloader2 = new ImageDownloader(shadow);
  42. downloader2
  43. .execute(url);
  44.  
  45.  
  46. } else if (Cache.getCacheFile(pathToPaint) == null) {
  47.  
  48. ImageDownloader downloader = new ImageDownloader(paint);
  49. downloader
  50. .execute(url);
  51.  
  52.  
  53. }
  54.  
  55. i++;
  56.  
  57.  
  58. }
  59.  
  60. }
  61.  
  62.  
  63.  
  64. @Override
  65. protected void onPause() {
  66. super.onPause();
  67. Toast.makeText(getApplicationContext(),"Pause",
  68. Toast.LENGTH_SHORT).show();
  69.  
  70. }
  71.  
  72. @Override
  73. public void onClick(View v) {
  74.  
  75.  
  76. if (v.getId() == R.id.button1) {
  77. if (j == 13)
  78. {
  79. j = 1;
  80. }
  81. String s = Integer.toString(j);
  82. wheels.setImageBitmap(Cache
  83. .getCacheFile(url));
  84. paint.setImageBitmap(Cache
  85. .getCacheFile(url));
  86. shadow.setImageBitmap(Cache
  87. .getCacheFile(url));
  88. j++;
  89.  
  90.  
  91.  
  92. }
  93. }
  94.  
  95. public static void saveCacheFile(String cacheUri, Bitmap image) {
  96. if(!isCacheWritable()) return;
  97. Log.i("CACHE S",cacheUri);
  98. cache.saveCacheFile(cacheUri, image);
  99.  
  100. public Bitmap getCacheFile(String cacheUri) {
  101. if(bitmapMap.containsKey(cacheUri)) return (Bitmap)bitmapMap.get(cacheUri);
  102.  
  103. if(!cacheMap.containsKey(cacheUri)) return null;
  104. String fileLocalName = cacheMap.get(cacheUri);
  105. File fullCacheDir = new File(Environment.getExternalStorageDirectory().toString(),cacheDir);
  106. File fileUri = new File(fullCacheDir.toString(), fileLocalName);
  107. if(!fileUri.exists()) return null;
  108. Log.i("CACHE", "File "+cacheUri+" has been found in the Cache");
  109. Bitmap bm = BitmapFactory.decodeFile(fileUri.toString());
  110. Bitmap.createScaledBitmap(bm, 480, 320, true);
  111. bitmapMap.put(cacheUri, bm);
  112. return bm;
  113. }
  114.  
  115. 07-06 23:40:20.720: ERROR/dalvikvm-heap(1844): 691200-byte external allocation too large for this process.
  116. 07-06 23:40:20.720: ERROR/GraphicsJNI(1844): VM won't let us allocate 691200 bytes
  117. 07-06 23:40:20.770: DEBUG/skia(1844): --- decoder->decode returned false
  118. 07-06 23:40:20.790: DEBUG/AndroidRuntime(1844): Shutting down VM
  119. 07-06 23:40:20.830: WARN/dalvikvm(1844): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
  120. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): FATAL EXCEPTION: main
  121. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
  122. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
  123. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:459)
  124. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:271)
  125. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:296)
  126. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): at com.cache.CacheStore.getCacheFile(CacheStore.java:117)
  127. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): at com.cache.Cache.getCacheFile(Cache.java:38)
  128. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): at com.cache.Test.onClick(Test.java:118)
  129. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): at android.view.View.performClick(View.java:2408)
  130. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): at android.view.View$PerformClick.run(View.java:8816)
  131. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): at android.os.Handler.handleCallback(Handler.java:587)
  132. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): at android.os.Handler.dispatchMessage(Handler.java:92)
  133. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): at android.os.Looper.loop(Looper.java:123)
  134. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): at android.app.ActivityThread.main(ActivityThread.java:4627)
  135. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): at java.lang.reflect.Method.invokeNative(Native Method)
  136. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): at java.lang.reflect.Method.invoke(Method.java:521)
  137. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  138. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  139. 07-06 23:40:20.890: ERROR/AndroidRuntime(1844): at dalvik.system.NativeStart.main(Native Method)
  140.  
  141. //somewhere inside image downloader class...
  142. {...}
  143.  
  144. BitmapFactory.Options options = new BitmapFactory.Options();
  145.  
  146. if(enableSampling)
  147. options.inSampleSize = 2;
  148.  
  149. returnBitmap = BitmapFactory.decodeStream(is, null, options);
  150.  
  151. if(returnBitmap != null)
  152. {
  153.  
  154. if(scaleImage)
  155. returnBitmap = Bitmap.createScaledBitmap(returnBitmap, width, height, true);
  156.  
  157. // insert the image into the cache
  158. imageCache.put(url, new SoftReference<Bitmap>(returnBitmap));
  159.  
  160.  
  161. // Check the ImageView for nulls
  162. if(imageView != null && callback != null){
  163. ImageDisplayer displayer = new ImageDisplayer(imageView, returnBitmap, parentView, tag);
  164. callback.onImageReceived(displayer);
  165. }
  166.  
  167. }
  168.  
  169. {...}
Add Comment
Please, Sign In to add comment