/**
* download by http://www.codefans.net
*/
package com.himi;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.LayoutInflater.Factory;
import android.view.SurfaceHolder.Callback;
/**
* @author Himi
*
*/
public class MySurfaceView extends SurfaceView implements Callback, Runnable {
private SurfaceHolder sh;
private Thread th;
private Paint paint;
private Canvas canvas;
private Resources res;
private Bitmap bp;
private Bitmap bp_backGround;
private int ScreenH, ScreenW;
private boolean flag;
public static String str_zh = "Himi";
public static String str_pass = "Android进阶群:109367315";
private int bp_x, bp_y;
private boolean flag_zh = true;
public MySurfaceView(Context context) {
super(context);
res = this.getResources();
bp = BitmapFactory.decodeResource(res, R.drawable.register);
bp_backGround = BitmapFactory.decodeResource(res, R.drawable.duola);
th = new Thread(this);
sh = this.getHolder();
sh.addCallback(this);
paint = new Paint();
paint.setColor(Color.RED);
paint.setAntiAlias(true);
this.setKeepScreenOn(true);
this.setFocusable(true);
}
public void surfaceCreated(SurfaceHolder holder) {
ScreenW = this.getWidth();
ScreenH = this.getHeight();
bp_x = ScreenW / 2 - bp.getWidth() / 2;
bp_y = ScreenH / 2 - bp.getHeight() / 2;
th.start();
}
public void draw() {
canvas = sh.lockCanvas();
paint.setColor(Color.RED);
if (canvas != null) {// 当点击home键 或者返回按键的时候canvas是得不到的,这里要注意
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(bp_backGround,
-(bp_backGround.getWidth() - ScreenW), -(bp_backGround
.getHeight() - ScreenH), paint);
canvas.drawBitmap(bp, bp_x, bp_y, paint);
canvas.drawText(str_zh, bp_x + 20, bp_y + 43 + 15, paint);
String temp_pass = "";
int temp_passLength = 0;
temp_passLength = str_pass.toCharArray().length;
if (temp_passLength > 15) {
temp_passLength = 15;
}
for (int i = 0; i < temp_passLength; i++) {
temp_pass += "*";
}
canvas.drawText(temp_pass, bp_x + 21, bp_y + 79 + 15, paint);
paint.setColor(Color.YELLOW);
if (flag_zh) {
canvas.drawCircle(bp_x + 23, bp_y + 113, 4, paint);
}
sh.unlockCanvasAndPost(canvas);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float pointx = event.getX();
float pointy = event.getY();
if (pointx > bp_x + 14 && pointx < bp_x + 14 + 117) {
if (pointy > bp_y + 43 && pointy < bp_y + 43 + 15) {
// 帐号
Intent i = new Intent();
i.putExtra("count", 1);
i.putExtra("himi", str_zh);
i.setClass(MainActivity.instance, Register.class);
MainActivity.instance.startActivity(i);
}
}
if (pointx > bp_x + 14 && pointx < bp_x + 14 + 117) {
if (pointy > bp_y + 79 && pointy < bp_y + 79 + 15) {
// 密码
Intent i = new Intent();
i.putExtra("count", 2);
i.putExtra("himi", str_pass);
i.setClass(MainActivity.instance, Register.class);
MainActivity.instance.startActivity(i);
}
}
if (pointx > bp_x + 42 && pointx < bp_x + 42 + 60) {
if (pointy > bp_y + 123 && pointy < bp_y + 123 + 24) {
// 登录信息
Intent i = new Intent();
i.putExtra("count", 3);
i.putExtra("himi_zh", str_zh);
i.putExtra("himi_pass", str_pass);
i.setClass(MainActivity.instance, Register.class);
MainActivity.instance.startActivity(i);
}
}
if (pointx > bp_x + 15 && pointx < bp_x + 15 + 15) {
if (pointy > bp_y + 104 && pointy < bp_y + 104 + 15) {
// 记住帐号
flag_zh = !flag_zh;
}
}
if (pointx > bp_x + 120 && pointx < bp_x + 120 + 22) {
if (pointy > bp_y + 5 && pointy < bp_y + 5 + 22) {
// 退出
try {
MainActivity.instance.finish();
android.os.Process.killProcess(android.os.Process.myPid());
MainActivity.instance = null;
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return super.onTouchEvent(event);
}
public void run() {
while (!flag) {
draw();
try {
Thread.sleep(100);
} catch (Exception ex) {
Log.v("Run", "Error");
}
}
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Register_Project_一个全屏显示的Android注册界面示例.rar (25个子文件)
codefans.net
Register_Project
.project 852B
src
com
himi
MainActivity.java 972B
MySurfaceView.java 5KB
Register.java 2KB
AndroidManifest.xml 772B
res
drawable
icon.png 3KB
register.jpg 9KB
duola.jpg 147KB
layout
main.xml 382B
values
strings.xml 176B
assets
gen
com
himi
R.java 735B
default.properties 364B
.classpath 280B
bin
Register_Project.apk 167KB
resources.ap_ 161KB
com
himi
R$layout.class 364B
R$drawable.class 431B
R$attr.class 310B
Register.class 3KB
MySurfaceView.class 6KB
R.class 429B
Register$1.class 1KB
R$string.class 397B
MainActivity.class 992B
classes.dex 9KB
共 25 条
- 1
资源评论
- Page_ZZ2015-09-24额,我只能说 我用android studio是没有导入成功~~
- qq_231363892015-09-27学习一下界面制作。很好的例子。
*任逍遥*
- 粉丝: 13
- 资源: 52
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功