Advertisement
Guest User

What I currently have

a guest
Jul 24th, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. import android.content.Context;
  2. import android.graphics.Bitmap;
  3. import android.graphics.BitmapFactory;
  4. import android.graphics.Canvas;
  5. import android.util.AttributeSet;
  6. import android.view.SurfaceHolder;
  7. import android.view.SurfaceView;
  8.  
  9. public class MySurface extends SurfaceView implements Runnable {
  10.    
  11.     SurfaceHolder ourHolder;
  12.     Thread ourThread = null;
  13.     boolean isRunning = true;
  14.    
  15.     Bitmap Background;
  16.     Bitmap clouda;
  17.    
  18.     Bitmap scaledBitmap = Bitmap.createScaledBitmap(Background, getWidth(), getHeight(), true);
  19.    
  20.    
  21.  
  22.     public MySurface(Context context) {
  23.         super(context);
  24.         init(context);
  25.        
  26.     }
  27.  
  28.     public MySurface(Context context, AttributeSet attrs) {
  29.         super(context, attrs);
  30.         init(context);
  31.     }
  32.  
  33.     public MySurface(Context context, AttributeSet attrs, int defStyle) {
  34.         super(context, attrs, defStyle);
  35.         init(context);
  36.     }
  37.  
  38.     private void init(Context context) {
  39.         // do stuff that was in your original constructor...
  40.         ourHolder = getHolder();
  41.         ourThread = new Thread(this);
  42.         ourThread.start();
  43.        
  44.         Background = BitmapFactory.decodeResource(getResources(), R.drawable.island);
  45.         clouda = BitmapFactory.decodeResource(getResources(), R.drawable.clouda);
  46.  
  47.        
  48.        
  49.  
  50.     }
  51.    
  52.    
  53.    
  54.     public void pause(){
  55.        
  56.     }
  57.    
  58.     public void resume(){
  59.        
  60.     }
  61.  
  62.     @Override
  63.     public void run() {
  64.         // TODO Auto-generated method stub
  65.         while(isRunning){
  66.             if (!ourHolder.getSurface().isValid())
  67.                 continue;
  68.            
  69.             Canvas canvas = ourHolder.lockCanvas();
  70.            
  71.            
  72.             canvas.drawBitmap(scaledBitmap, 0, 0, null);
  73.             canvas.drawBitmap(clouda, 0, 0, null);
  74.            
  75.            
  76.            
  77.             ourHolder.unlockCanvasAndPost(canvas);
  78.            
  79.         }
  80.        
  81.     }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement