WEB开发网
开发学院手机开发Android 开发 Live Wallpaper动态壁纸开发 阅读

Live Wallpaper动态壁纸开发

 2011-07-01 20:50:24 来源:本站整理   
核心提示:private StringmShape = "smpte";TestPatternEngine(){ final Paint paint = mPaint; paint.setColor(0xffffffff); paint.setAntiAlias(true); paint.setStrokeW

 private String  mShape  = "smpte";

 TestPatternEngine()
 {
  final Paint paint = mPaint;
  paint.setColor(0xffffffff);
  paint.setAntiAlias(true);
  paint.setStrokeWidth(2);
  paint.setStrokeCap(Paint.Cap.ROUND);
  paint.setStyle(Paint.Style.STROKE);

  mPreferences = LiveWallpaper.this.getSharedPreferences(SHARED_PREFS_NAME, 0);
  mPreferences.registerOnSharedPreferenceChangeListener(this);
  onSharedPreferenceChanged(mPreferences, null);
 }

 public void onSharedPreferenceChanged(SharedPreferences prefs,
  String key)
 {
  mShape = prefs.getString("livewallpaper_testpattern", "smpte");
  mMotion = prefs.getBoolean("livewallpaper_movement", true);
  readColors();
 }

 private void readColors()
 {

  int pid = getResources().getIdentifier(mShape + "colors", "array", getPackageName());

  rectColor = getResources().getIntArray(pid);
  mRectCount = rectColor.length;
  mColorRectangles = new Rect[mRectCount];

  System.out.println("mRectCount "+mRectCount);
  initFrameParams();
 }

 @Override
 public void onCreate(SurfaceHolder surfaceHolder)
 {
  super.onCreate(surfaceHolder);
  setTouchEventsEnabled(true);
 }

 @Override
 public void onDestroy()
 {
  super.onDestroy();
  mHandler.removeCallbacks(mDrawPattern);
 }

 @Override
 public void onVisibilityChanged(boolean visible)
 {
  mVisible = visible;
  if (visible)
  {
  drawFrame();
  }
  else
  {
  mHandler.removeCallbacks(mDrawPattern);
  }
 }

 @Override
 public void onSurfaceChanged(SurfaceHolder holder, int format,
  int width, int height)
 {
  super.onSurfaceChanged(holder, format, width, height);

  initFrameParams();

  drawFrame();
 }

 @Override
 public void onSurfaceCreated(SurfaceHolder holder)
 {
  super.onSurfaceCreated(holder);
 }

 @Override
 public void onSurfaceDestroyed(SurfaceHolder holder)
 {
  super.onSurfaceDestroyed(holder);
  mVisible = false;
  mHandler.removeCallbacks(mDrawPattern);
 }

 @Override
 public void onOffsetsChanged(float xOffset, float yOffset, float xStep,
  float yStep, int xPixels, int yPixels)
 {

  drawFrame();
 }

  @Override
 public void onTouchEvent(MotionEvent event)
 {
  if (event.getAction() == MotionEvent.ACTION_MOVE)
  {
  mTouchX = event.getX();
  mTouchY = event.getY();
  }
  else
  {
  mTouchX = -1;
  mTouchY = -1;
  }
  super.onTouchEvent(event);
 }

 void drawFrame()
 {
  final SurfaceHolder holder = getSurfaceHolder();

  Canvas c = null;
  try
  {
  c = holder.lockCanvas();
  if (c != null)
  {
   // draw something
   drawPattern(c);
   drawTouchPoint(c);
  }
  }
  finally
  {
  if (c != null)

上一页  1 2 3 4 5 6 7  下一页

Tags:Live Wallpaper 动态

编辑录入:coldstar [复制链接] [打 印]
赞助商链接