- 浏览: 942588 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (385)
- 搜索引擎学习 (62)
- 算法 (1)
- 数据库 (15)
- web开发 (38)
- solr开发 (17)
- nutch 1.2 系统学习 (8)
- cms (1)
- 系统架构 (11)
- linux 与 unix 编程 (16)
- android (15)
- maven (1)
- 关注物流 (1)
- 网址收集 (1)
- 分布式,集群 (1)
- mysql (5)
- apache (1)
- 资料文档备份 (7)
- 上班有感 (0)
- 工作流 (15)
- javascript (1)
- weblogic (1)
- eclipse 集成 (1)
- JMS (7)
- Hibernate (1)
- 性能测试 (1)
- spring (6)
- 缓存cache (1)
- mongodb (2)
- webservice (1)
- HTML5 COCOS2D-HTML5 (1)
- BrowserQuest (2)
最新评论
-
avi9111:
内陷到android, ios, winphone里面也是随便 ...
【HTML5游戏开发】二次开发 BrowserQuest 第一集 -
avi9111:
呵呵,做不下去了吧,没有第二集了吧,游戏是个深坑,谨慎进入,其 ...
【HTML5游戏开发】二次开发 BrowserQuest 第一集 -
excaliburace:
方案3亲测完全可用,顺便解决了我其他方面的一些疑问,非常感谢
spring security 2添加用户验证码 -
yuanliangding:
Spring太强大了。
Spring Data JPA 简单介绍 -
小高你好:
什么是hibernate懒加载?什么时候用懒加载?为什么要用懒加载?
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.wallpaper.WallpaperService;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
public class ALiveWall extends WallpaperService{
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(SurfaceHolder surfaceHolder) {
super.onCreate(surfaceHolder);
// 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 onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
super.onSurfaceChanged(holder, format, width, height);
// store the center of the surface, so we can draw the cube in the right spot
mCenterX = width/2.0f;
mCenterY = height/2.0f;
drawFrame();
}
@Override
public void onSurfaceCreated(SurfaceHolder holder) {
super.onSurfaceCreated(holder);
}
@Override
public void onSurfaceDestroyed(SurfaceHolder holder) {
super.onSurfaceDestroyed(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;
mTouchY = -1;
}
super.onTouchEvent(event);
}
/*
* Draw one frame of the animation. This method gets called repeatedly
* by posting a delayed Runnable. You can do any drawing you want in
* here. This example draws a wireframe cube.
*/
void drawFrame() {
final SurfaceHolder holder = getSurfaceHolder();
Canvas c = null;
try {
c = holder.lockCanvas();
if (c != null) {
// draw something
drawCube(c);
drawTouchPoint(c);
}
} finally {
if (c != null) holder.unlockCanvasAndPost(c);
}
// Reschedule the next redraw
mHandler.removeCallbacks(mDrawCube);
if (mVisible) {
mHandler.postDelayed(mDrawCube, 1000 / 25);
}
}
/*
* Draw a wireframe cube by drawing 12 3 dimensional lines between
* adjacent corners of the cube
*/
void drawCube(Canvas c) {
c.save();
c.translate(mCenterX, mCenterY);
c.drawColor(0xff000000);
drawLine(c, -400, -400, -400, 400, -400, -400);
drawLine(c, 400, -400, -400, 400, 400, -400);
drawLine(c, 400, 400, -400, -400, 400, -400);
drawLine(c, -400, 400, -400, -400, -400, -400);
drawLine(c, -400, -400, 400, 400, -400, 400);
drawLine(c, 400, -400, 400, 400, 400, 400);
drawLine(c, 400, 400, 400, -400, 400, 400);
drawLine(c, -400, 400, 400, -400, -400, 400);
drawLine(c, -400, -400, 400, -400, -400, -400);
drawLine(c, 400, -400, 400, 400, -400, -400);
drawLine(c, 400, 400, 400, 400, 400, -400);
drawLine(c, -400, 400, 400, -400, 400, -400);
c.restore();
}
/*
* Draw a 3 dimensional line on to the screen
*/
void drawLine(Canvas c, int x1, int y1, int z1, int x2, int y2, int z2) {
long now = SystemClock.elapsedRealtime();
float xrot = ((float)(now - mStartTime)) / 1000;
float yrot = (0.5f - mOffset) * 2.0f;
float zrot = 0;
// 3D transformations
// rotation around X-axis
float newy1 = (float)(Math.sin(xrot) * z1 + Math.cos(xrot) * y1);
float newy2 = (float)(Math.sin(xrot) * z2 + Math.cos(xrot) * y2);
float newz1 = (float)(Math.cos(xrot) * z1 - Math.sin(xrot) * y1);
float newz2 = (float)(Math.cos(xrot) * z2 - Math.sin(xrot) * y2);
// rotation around Y-axis
float newx1 = (float)(Math.sin(yrot) * newz1 + Math.cos(yrot) * x1);
float newx2 = (float)(Math.sin(yrot) * newz2 + Math.cos(yrot) * x2);
newz1 = (float)(Math.cos(yrot) * newz1 - Math.sin(yrot) * x1);
newz2 = (float)(Math.cos(yrot) * newz2 - Math.sin(yrot) * x2);
// 3D-to-2D projection
float startX = newx1 / (4 - newz1 / 400);
float startY = newy1 / (4 - newz1 / 400);
float stopX = newx2 / (4 - newz2 / 400);
float stopY = newy2 / (4 - newz2 / 400);
c.drawLine(startX, startY, stopX, stopY, mPaint);
}
/*
* Draw a circle around the current touch point, if any.
*/
void drawTouchPoint(Canvas c) {
if (mTouchX >=0 && mTouchY >= 0) {
c.drawCircle(mTouchX, mTouchY, 80, mPaint);
}
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android
"
package="com.mwongxming.LiveWall" android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<service android:label="@string/app_name" android:name=".ALiveWall"
android:permission="android.permission.BIND_WALLPAPER">
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data android:name="android.service.wallpaper"
android:resource="@xml/alive_wall" />
</service>
</application>
<uses-sdk android:minSdkVersion="7" />
</manifest>
动态壁纸----线条
在原基础上进修了修改,一下贴出增加的代码:
private int x_point = 0;// 保存x坐标
private int y_point = 0;// 保存y坐标
private int height = 0;// 保存屏幕的长度
private int width = 0;// 保存屏幕的宽度
private int count;
private int i = 0;
效果实现代码:
mPaint.setAntiAlias(true);
mPaint.setColor(Color.BLUE);
mPaint.setTextSize(10);
mPaint.setStyle(Paint.Style.FILL);
height = c.getHeight();
width = c.getWidth();
for (i = 0; i <y_point; i = i + 10) {// 绘制前面所有行
c.drawLine(0, i, width, i, mPaint);
count++;
}
if (x_point > 0 && x_point <= width) {// 绘制当前行当前坐标之前的
c.drawLine(0, i, x_point, i, mPaint);
}
if (x_point <= width && y_point + 10 <= height) {// 当前要绘制的
c.drawLine(x_point, y_point, x_point + 40, y_point, mPaint);
x_point += 40;
if (x_point == width) {// 换行处理
y_point = y_point + 10;
x_point = 0;
}
}
发表评论
-
android之uses-permission
2011-10-21 01:26 997在编写Android程序时经常会忘记添加权限,下面是网上收集的 ... -
android 使用include 调用内部组件
2011-10-20 23:50 4440http://androidbiancheng.blogspo ... -
【转】android Frame动画概述+示例
2011-08-25 14:25 1208大家平时见到的最多的可能就是Frame动画了,Android中 ... -
【转】玩转Android---UI篇---ZoomControls放大缩小图片
2011-08-25 14:20 1279ZoomControls控件是一个可 ... -
android EditText 使用
2011-08-25 00:50 1342文本改变化要增加监听才能适时地返回文本数据,如代码,如果直接. ... -
google 资源还得好好利用
2011-08-18 23:55 996http://www.google.com/codesearc ... -
【转】Android 翻页效果 电子书
2011-08-17 10:32 1290先上个效果图: 效果还是很不错的,不过 ... -
【转】收藏:Android中利用画图类和线程画出闪烁的心形,送给亲爱的他
2011-08-17 10:16 1668大家先看图片: 因为前一段时间在写画图类,刚好有一个线程 ... -
Android 轻松实现语音识别的完整代码[转]
2011-08-15 23:33 2036苹果的iphone 有语音识别用的是Google 的技术, ... -
android gmail send email
2011-08-15 23:31 682package org.apache.android.mail ... -
Android 应用程序之间数据共享—ContentResolver【转】
2011-08-14 08:58 919Android是如何实现应用程 ... -
android手指缩放效果【转】
2011-07-25 20:18 4480写这篇文章,是因为试了这篇《Android通过手势实现的缩放处 ... -
认识 android 中的 LayoutInflater
2011-07-23 19:45 1046Inflater英文意思是膨胀,在Android中应该是扩展的 ... -
android学习初步之一
2011-03-28 09:50 936这星期看了看android应用的开发,感觉出它有不同的魅力,可 ...
相关推荐
内容包含:android-support-v4_1.6.0_26_20120316.jar android-support-v4_1.6.0_26_20120623.jar android-support-v4_1.6.0_26_20120730.jar android-support-v4_1.6.0_26_20121109.jar android-support-v4_1.6.0_26...
android-support-v4-v7-v13-v14-v17(官方最新完整版),官方最新版的,压缩包内包含android-support-v4、android-support-v7-appcompat,android-support-v7-cardview,android-support-v7-gridlayout,android-support-...
动态壁纸实现 游戏与动态壁纸的结合 坦克大战,很经典的游戏 想学习壁纸游戏的程序员,是一个好的入门案例
导入eclipse即可运行,程序功能一分钟更换一张壁纸实现报时功能。用到的知识点 壁纸引擎 线程间通信 配置文件读写 遍历文件夹等。注释详细适合android初学者。欢迎讨论学习!
玩转Android---组件篇---Handler的使用玩转Android---组件篇---Handler的使用玩转Android---组件篇---Handler的使用
android-sdk-windowsandroid-sdk-windowsandroid-sdk-windowsandroid-sdk-windowsandroid-sdk-windowsandroid-sdk-windowsandroid-sdk-windows
Android-Skin-Loader > 联系我 : fengjun.dev@gmail.com > > 个人博客 : http://allenfeng.com/ > > 一个通过动态加载本地皮肤包进行换肤的皮肤框架 更新日志 导入到Android Studio,使用gradle构建皮肤包(见7. ...
•Android---UI篇---Tab Layout(选项卡布局) • •Andorid---UI篇---TableLayout(表格布局) • •Android---UI篇---RelativeLayout(相对布局) • •Android---UI篇---GridView(网格布局) • •Android---UI篇-...
将android-17.zip解压到 Android\android-sdk\platforms 文件夹下。
最新版的android-support-v4.jar,1.39M左右,包含常用的类库,最新版的android-support-v4.jar,1.39M左右,包含常用的类库
最新android studio 2015/10/12日更新 2015/10/12 android-studio-bundle-141.2288178-windows
ksoap2-android-assembly-2.6.5-jar-with-dependencies.jar 要是需要最新的,下载地址: http://code.google.com/p/ksoap2-android/
Android 动态绘图-反弹球 扩大缩小
asmack-android-8-4.0.7jar 2015-02-20更新,现在asmack已经托管到github上,费了很长时间才找到,在这里分享给大家
sunlight Project includes 3D live wallpaper for OpenGL ES 2.0 capable androind devices. Your very own sun This application is a 3D live wallpaper. It renders sun as well as other star types using ...
android-support-v7-preference.jar
Android使用android-beacon-library接收beacon
安卓开发之串口通信android-serialport-api-master,虽然是从Github上面下载下来的,但是从下载到使用还是有很多问题,其中之一就是由于该api是今年前开发出来的,sdk版本过低导致现在的eclipse不能直接使用,关于此...
最近研究QMUI遇到各种问题,一会儿SDK版本问题,一会儿依赖插件问题,android-support-v4和android-support-v7
android-sdk_r24.4.1-windows和android-ndk-r10e-windows-x86_64。文件太大只能传到百度云上