11package de .vogella .android .userinterface ;
22
33import android .app .Activity ;
4+ import android .graphics .Bitmap ;
45import android .graphics .BitmapFactory ;
56import android .os .Bundle ;
67import android .os .Handler ;
@@ -23,36 +24,40 @@ public void onCreate(Bundle savedInstanceState) {
2324 }
2425
2526 public void onClick (View view ) {
26- final View photo = findViewById (R .id .editablePhoto1 );
27+ final RoundImageView photo = ( RoundImageView ) findViewById (R .id .editablePhoto1 );
2728 final View progress = findViewById (R .id .progressBar1 );
2829 progress .setVisibility (View .VISIBLE );
2930 refreshButton .setVisibility (View .GONE );
3031 Runnable runnable = new Runnable () {
3132
33+ private Bitmap decodeStream ;
34+
3235 @ Override
3336 public void run () {
3437 try {
3538 Thread .sleep (2000 );
3639 } catch (InterruptedException e1 ) {
3740 e1 .printStackTrace ();
3841 }
42+ decodeStream = null ;
43+ try {
44+ if (photo != null
45+ && photo instanceof RoundImageView ) {
46+ decodeStream = BitmapFactory
47+ .decodeStream (getAssets ().open (
48+ "lars.png" ));
49+ }
50+
51+
52+ } catch (Exception e ) {
53+ e .printStackTrace ();
54+ }
3955 handler .post (new Runnable () {
4056 @ Override
4157 public void run () {
42- try {
43- if (photo != null
44- && photo instanceof RoundImageView ) {
45- RoundImageView photo2 = (RoundImageView ) photo ;
46- photo2 .setImageBitmap (BitmapFactory
47- .decodeStream (getAssets ().open (
48- "lars.png" )));
49- }
50-
51- progress .setVisibility (View .GONE );
52- refreshButton .setVisibility (View .VISIBLE );
53- } catch (Exception e ) {
54- e .printStackTrace ();
55- }
58+ photo .setImageBitmap (decodeStream );
59+ progress .setVisibility (View .GONE );
60+ refreshButton .setVisibility (View .VISIBLE );
5661 }
5762 });
5863
0 commit comments