package com.emirac.bonk;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.service.wallpaper.WallpaperService;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
public class BonkWallpaper extends WallpaperService {
public static final String SHARED_PREFS_NAME="bonksettings";
private static final int MIN_NBONKS = 2;
private static final int MAX_AGE = 4000;
// after this many we start killing them off whenever
// we create a new one
private static final int MAX_NBONKS = 32;
private static final int MAX_NBONKS_GLASS = 8;
// colors
public static final int BG_COLOR = 0x000037;
public static final int FG_COLOR = 0xc8c800;
public static final int WAVE_COLOR = 0x7700aa;
// radius limits
private static final int MIN_RADIUS = 12;
private static final int MAX_RADIUS = 50;
private static final int MIN_RADIUS_GLASS = 20;
private static final int MAX_RADIUS_GLASS = 60;
// time between frames (msec)
private static final int FRAME_INTERVAL = 20;
// fader alpha value (0 - 255)
private static final int DEFAULT_ALPHA = 70;
private final Handler mHandler = new Handler();
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public Engine onCreateEngine() {
return new BonkEngine(this);
}
class BonkEngine extends Engine implements SharedPreferences.OnSharedPreferenceChangeListener {
private final List<Bonk> mBonks = new ArrayList<Bonk>();
private final Paint mPaint = new Paint();
private Canvas mCanvas = null;
public Bitmap mBitmap = null;
private SoundManager mSounds = null;;
private boolean mVisible = true;
private float mTouchDownY = 0;
private float mTouchDownX = 0;
private float mTouchUpX = 0;
private float mTouchUpY = 0;
private int mHeight = 0;
private int mWidth = 0;
private float mXOff = 0f;
private float mYOff = 0f;
private int mXOffPix = 0;
private int mYOffPix = 0;
private WallpaperService mContext = null;;
private SharedPreferences mPrefs = null;
private int mMaxRadius = MAX_RADIUS;
private int mMinRadius = MIN_RADIUS;
private int mMaxNumBonks = MAX_NBONKS;
private int mMinNumBonks = MIN_NBONKS;
private int mBgColor = BG_COLOR;
private int mFgColor = FG_COLOR;
private int mWaveColor = WAVE_COLOR;
private boolean mUseSound = true;
private boolean mTrails = false;
private boolean mShowBonks = true;
private int mBonkStyle = 0;
private String mBgImageString = null;
private Bitmap mBgBitmap = null;
private boolean mUseBgImage = false;
private final Runnable mDoNextFrame = new Runnable() {
public void run() {
doNextFrame();
}
};
BonkEngine(WallpaperService ws) {
// android.os.Debug.waitForDebugger();
final Paint paint = mPaint;
paint.setColor(0xffffffff);
paint.setAntiAlias(true);
paint.setStrokeWidth(2);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStyle(Paint.Style.STROKE);
mContext = ws;
mSounds = new SoundManager(mContext);
mPrefs = BonkWallpaper.this.getSharedPreferences(SHARED_PREFS_NAME, 0);
mPrefs.registerOnSharedPreferenceChangeListener(this);
onSharedPreferenceChanged(mPrefs, null);
}
@Override
public void onCreate(SurfaceHolder surfaceHolder) {
super.onCreate(surfaceHolder);
setTouchEventsEnabled(true);
}
public Bundle onCommand(String action, int x, int y, int z, Bundle extras, boolean resultRequested){
return (super.onCommand(action, x, y, z, extras, resultRequested));
}
@Override
public void onDestroy() {
super.onDestroy();
mSounds.off();
mHandler.removeCallbacks(mDoNextFrame);
}
@Override
public void onVisibilityChanged(boolean visible) {
mVisible = visible;
if (visible) {
mSounds.on();
doNextFrame();
}
else {
mSounds.off();
mHandler.removeCallbacks(mDoNextFrame);
}
}
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
super.onSurfaceChanged(holder, format, width, height);
mWidth = width;
mHeight = height;
mCanvas = createCanvasBuffer(format, width, height);
// make 3 bonks...so people don't freakout that "it doesn't do anything!"
if(mBonks.size() == 0){
mBonks.add(generateBonk(mWidth/2, mHeight/2, mWidth/2, mHeight/2));
mBonks.add(generateBonk(mWidth/2, mHeight/2, mWidth/2, mHeight/2));
mBonks.add(generateBonk(mWidth/2, mHeight/2, mWidth/2, mHeight/2));
}
loadBgBitmap();
return;
}
@Override
public void onSurfaceCreated(SurfaceHolder holder) {
super.onSurfaceCreated(holder);
return;
}
@Override
public void onSurfaceDestroyed(SurfaceHolder holder) {
super.onSurfaceDestroyed(holder);
mVisible = false;
mHandler.removeCallbacks(mDoNextFrame);
return;
}
@Override
public void onOffsetsChanged(float xOffset, float yOffset, float xStep, float yStep, int xPixels, int yPixels) {
mXOff = xOffset;
mYOff = yOffset;
if(mBgBitmap != null){
mXOffPix = (int) (mXOff * (mWidth - mBgBitmap.getWidth()));
mYOffPix = (int) (mYOff * (mHeight - mBgBitmap.getHeight()));
if(mCanvas != null){
mPaint.setAlpha(0xff);
mCanvas.drawBitmap(mBgBitmap, mXOffPix, mYOffPix, mPaint);
}
}
doNextFrame();
return;
}
@Override
public void onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mTouchDownX = event.getX();
mTouchDownY = event.getY();
}
else if (event.getAction() == MotionEvent.ACTION_UP) {
mTouchUpX = event.getX();
mTouchUpY = event.getY();
Bonk b = generateBonk(mTouchDownX, mTouchDownY, mTouchUpX, mTouchUpY);
mBonks.add(b);
}
super.onTouchEvent(event);
return;
}
private Bonk generateBonk(float x1, float y1, float x2, float y2){
Random rn = new Random();
int r = (int) (mMaxRadius * rn.nextDouble());
if(r <= mMinRadius){
r = mMinRadius;
}
int m = r / 2;
int vx = (int) (x2 - x1);
int vy = (int) (y2 - y1);
Bonk b = new Bonk((int)x1, (int)y1, r, m);
setV(b, vx, vy, rn);
return(b);
}
private void setV(Bonk b, int vx, int vy, Random r) {
int[] signs = {-1, 1};
vx /= (mWidth / 20);
vy /= (mHeight / 20);
if(vx == 0){
vx = signs[r.nextInt(2)];
}
if((vx < 5) && (vx > -5)){
vx *= 5;
}
if((vy < 5) && (vy > -5)){
vy = (int) ((mHeight / 60) * r.nextDouble());
vy *= signs[r.nextInt(2)];
}
b.setV(vx, vy);
return;
}
Canvas createCanvasBuffer(int fmt, int w, int h){
mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas newCanvas = new Canvas(mBitmap);
return(newCanvas);
}
// do one frame of the animation
void doNextFrame() {
final SurfaceHolder holder = getSurfaceHolder();
Canvas c = null;
// check for collisions
List<Bonk> collisionBonks = new ArrayList<Bonk>();
List<Bonk> bonks2 = new ArrayList<Bonk>(mBonks);
for(Bonk b: mBonks){
b.collide(mWidth,
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
bonk.zip (36个子文件)
bonk_wallpaper_public
.project 857B
project.properties 562B
src
com
emirac
bonk
SoundManager.java 6KB
ColorPreference.java 5KB
BonkSettings.java 5KB
BonkUtil.java 5KB
FlashPoint.java 2KB
BonkWallpaper.java 14KB
Bonk.java 7KB
AndroidManifest.xml 1KB
res
raw
owl.wav 7KB
banjo05.mp3 40KB
banjo01.mp3 13KB
lamb.wav 12KB
chicken.wav 22KB
frog1.wav 9KB
lion.wav 11KB
banjo02.mp3 21KB
birdatf2.wav 10KB
bonksound.wav 17KB
cricket2.wav 17KB
banjo04.mp3 22KB
banjo03.mp3 25KB
snort.wav 5KB
dog1.wav 2KB
chicks.wav 10KB
cow.wav 15KB
drawable-ldpi
icon.png 3KB
xml
settings.xml 4KB
bonk.xml 304B
drawable-hdpi
icon.png 15KB
drawable
thumbnail.png 15KB
drawable-mdpi
icon.png 9KB
layout
values
arrays.xml 2KB
strings.xml 392B
assets
.classpath 364B
共 36 条
- 1
nichloce
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 镜像资源包php7.4.33
- 基于LLM的命名实体识别(NER)和实体关系抽取(IE)
- 基于python和llm大模型开发的数据处理和任务调度系统
- JAVASpring mvc在线问卷答题系统源码数据库 MySQL源码类型 WebForm
- 作业1-视频1111111111111
- python-基于LLM multi agents的《谁是卧底》游戏模拟+项目源码+文档说明
- 实训做的STM32C8T6循迹小车, L298N,目前是实现了循迹功能,语音播报功能,蓝牙功能,原来代码是四轮的,改成两轮的了
- 744121054161446音悦时光_1.6.1.apk
- Matlab中常用的34种数据降维方法(数学建模)
- C#ASP.NET房屋所有权证书打印系统源码数据库 其他源码类型 WinForm
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页