当前位置:操作系统 > 安卓/Android >>

android动态壁纸---线条

android SDK2.1中有关于动态壁纸的2个演示DEMO,本人在网上查了相关资料。找到了一个演示DEMO的源代码,希望和大家分享。
同时谢谢提供代码的LZ.并且再此基础上本人做了一个简单的线条动态壁纸,后续还有动态壁纸---球的感应动作实例和大家一起分享学习。
 
DEMO

 
ALiveWall.java
 
package com.mwongxming.LiveWall;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Handler;
import android.os.SystemClock;
import android.service.wall易做图.Wall易做图Service;
import android.view.MotionEvent;
import android.view.Su易做图ceHolder;
public class ALiveWall extends Wall易做图Service{
 private final Handler mHandler = new Handler();
 
 @Override
    public Engine onCreateEngine() {
        return new CubeEngine();
    }
    class CubeEngine extends Engine {
        private final Paint mPaint = new Paint();
        private float mOffset;
        private float mTouchX = -1;
        private float mTouchY = -1;
        private long mStartTime;
        private float mCenterX;
        private float mCenterY;
        private final Runnable mDrawCube = new Runnable() {
            public void run() {
                drawFrame();
            }
        };
        private boolean mVisible;
        CubeEngine() {
            // Create a Paint to draw the lines for our cube
            final Paint paint = mPaint;
            paint.setColor(0xffffffff);
            paint.setAntiAlias(true);
            paint.setStrokeWidth(2);
            paint.setStrokeCap(Paint.Cap.ROUND);
            paint.setStyle(Paint.Style.STROKE);
            mStartTime = SystemClock.elapsedRealtime();
        }
        @Override
        public void onCreate(Su易做图ceHolder su易做图ceHolder) {
            super.onCreate(su易做图ceHolder);
            // By default we don't get touch events, so enable them.
            setTouchEventsEnabled(true);
        }
        @Override
        public void onDestroy() {
            super.onDestroy();
            mHandler.removeCallbacks(mDrawCube);
        }
        @Override
        public void onVisibilityChanged(boolean visible) {
            mVisible = visible;
            if (visible) {
                drawFrame();
            } else {
                mHandler.removeCallbacks(mDrawCube);
            }
        }
        @Override
        public void onSu易做图ceChanged(Su易做图ceHolder holder, int format, int width, int height) {
            super.onSu易做图ceChanged(holder, format, width, height);
            // store the center of the su易做图ce, so we can draw the cube in the right spot
            mCenterX = width/2.0f;
            mCenterY = height/2.0f;
            drawFrame();
        }
        @Override
        public void onSu易做图ceCreated(Su易做图ceHolder holder) {
            super.onSu易做图ceCreated(holder);
        }
        @Override
        public void onSu易做图ceDestroyed(Su易做图ceHolder holder) {
            super.onSu易做图ceDestroyed(holder);
            mVisible = false;
            mHandler.removeCallbacks(mDrawCube);
        }
        @Override
        public void onOffsetsChanged(float xOffset, float yOffset,
                float xStep, float yStep, int xPixels, int yPixels) {
            mOffset = xOffset;
            drawFrame();
        }
        /*
         * Store the position of the touch event so we can use it for drawing later
         */
        @Override
        public void onTouchEvent(MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_MOVE) {
                mTouchX = event.getX();
                mTouchY = event.getY();
            } else {
                mTouchX = -1;

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,