登录
首页 » Java » android 读取通讯录/短信,短信删除 例子源码下载( 智能短信)

android 读取通讯录/短信,短信删除 例子源码下载( 智能短信)

于 2015-04-09 发布
0 100
下载积分: 1 下载次数: 0

代码说明:

读取通讯录,短信,编辑短信

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • 安卓日历小部件源码(AppWidgetProvider)
    一款关于日历与行程安排的项目源码,点击日期可以转跳到日程新增界面,事件是提前定好的类型,提醒周期很丰富,可以按照周、年、月、日、小时和分钟为周期进行提醒,日历默认会显示一些节假日和纪念日信息。当日期被标记上事件以后会在日期右上角显示一个小红角作为提醒。
    2019-09-10下载
    积分:1
  • android下创建一个sqlite数据库 - android入门视频32
    android下创建一个sqlite数据库 - android入门视频32
    2015-12-03下载
    积分:1
  • BidirSlidingLayout_Android双向滑动菜单完全解析,教你如何一分钟实现双向滑动特效
    BidirSlidingLayout_Android双向滑动菜单完全解析,教你如何一分钟实现双向滑动特效package com.example.bidirslidinglayout;import android.content.Context;import android.os.AsyncTask;import android.util.AttributeSet;import android.view.MotionEvent;import android.view.VelocityTracker;import android.view.View;import android.view.ViewConfiguration;import android.view.View.OnTouchListener;import android.view.WindowManager;import android.widget.RelativeLayout;/** * 双向滑动菜单框架 * * @author guolin */public class BidirSlidingLayout extends RelativeLayout implements OnTouchListener { /** * 滚动显示和隐藏左侧布局时,手指滑动需要达到的速度。 */ public static final int SNAP_VELOCITY = 200; /** * 滑动状态的一种,表示未进行任何滑动。 */ public static final int DO_NOTHING = 0; /** * 滑动状态的一种,表示正在滑出左侧菜单。 */ public static final int SHOW_LEFT_MENU = 1; /** * 滑动状态的一种,表示正在滑出右侧菜单。 */ public static final int SHOW_RIGHT_MENU = 2; /** * 滑动状态的一种,表示正在隐藏左侧菜单。 */ public static final int HIDE_LEFT_MENU = 3; /** * 滑动状态的一种,表示正在隐藏右侧菜单。 */ public static final int HIDE_RIGHT_MENU = 4; /** * 记录当前的滑动状态 */ private int slideState; /** * 屏幕宽度值。 */ private int screenWidth; /** * 在被判定为滚动之前用户手指可以移动的最大值。 */ private int touchSlop; /** * 记录手指按下时的横坐标。 */ private float xDown; /** * 记录手指按下时的纵坐标。 */ private float yDown; /** * 记录手指移动时的横坐标。 */ private float xMove; /** * 记录手指移动时的纵坐标。 */ private float yMove; /** * 记录手机抬起时的横坐标。 */ private float xUp; /** * 左侧菜单当前是显示还是隐藏。只有完全显示或隐藏时才会更改此值,滑动过程中此值无效。 */ private boolean isLeftMenuVisible; /** * 右侧菜单当前是显示还是隐藏。只有完全显示或隐藏时才会更改此值,滑动过程中此值无效。 */ private boolean isRightMenuVisible; /** * 是否正在滑动。 */ private boolean isSliding; /** * 左侧菜单布局对象。 */ private View leftMenuLayout; /** * 右侧菜单布局对象。 */ private View rightMenuLayout; /** * 内容布局对象。 */ private View contentLayout; /** * 用于监听滑动事件的View。 */ private View mBindView; /** * 左侧菜单布局的参数。 */ private MarginLayoutParams leftMenuLayoutParams; /** * 右侧菜单布局的参数。 */ private MarginLayoutParams rightMenuLayoutParams; /** * 内容布局的参数。 */ private RelativeLayout.LayoutParams contentLayoutParams; /** * 用于计算手指滑动的速度。 */ private VelocityTracker mVelocityTracker; /** * 重写BidirSlidingLayout的构造函数,其中获取了屏幕的宽度和touchSlop的值。 * * @param context * @param attrs */ public BidirSlidingLayout(Context context, AttributeSet attrs) { super(context, attrs); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); screenWidth = wm.getDefaultDisplay().getWidth(); touchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); } /** * 绑定监听滑动事件的View。 * * @param bindView * 需要绑定的View对象。 */ public void setScrollEvent(View bindView) { mBindView = bindView; mBindView.setOnTouchListener(this); } /** * 将界面滚动到左侧菜单界面,滚动速度设定为-30. */ public void scrollToLeftMenu() { new LeftMenuScrollTask().execute(-30); } /** * 将界面滚动到右侧菜单界面,滚动速度设定为-30. */ public void scrollToRightMenu() { new RightMenuScrollTask().execute(-30); } /** * 将界面从左侧菜单滚动到内容界面,滚动速度设定为30. */ public void scrollToContentFromLeftMenu() { new LeftMenuScrollTask().execute(30); } /** * 将界面从右侧菜单滚动到内容界面,滚动速度设定为30. */ public void scrollToContentFromRightMenu() { new RightMenuScrollTask().execute(30); } /** * 左侧菜单是否完全显示出来,滑动过程中此值无效。 * * @return 左侧菜单完全显示返回true,否则返回false。 */ public boolean isLeftLayoutVisible() { return isLeftMenuVisible; } /** * 右侧菜单是否完全显示出来,滑动过程中此值无效。 * * @return 右侧菜单完全显示返回true,否则返回false。 */ public boolean isRightLayoutVisible() { return isRightMenuVisible; } /** * 在onLayout中重新设定左侧菜单、右侧菜单、以及内容布局的参数。 */ @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); if (changed) { // 获取左侧菜单布局对象 leftMenuLayout = getChildAt(0); leftMenuLayoutParams = (MarginLayoutParams) leftMenuLayout.getLayoutParams(); // 获取右侧菜单布局对象 rightMenuLayout = getChildAt(1); rightMenuLayoutParams = (MarginLayoutParams) rightMenuLayout.getLayoutParams(); // 获取内容布局对象 contentLayout = getChildAt(2); contentLayoutParams = (RelativeLayout.LayoutParams) contentLayout.getLayoutParams(); contentLayoutParams.width = screenWidth; contentLayout.setLayoutParams(contentLayoutParams); } } @Override public boolean onTouch(View v, MotionEvent event) { createVelocityTracker(event); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // 手指按下时,记录按下时的坐标 xDown = event.getRawX(); yDown = event.getRawY(); // 将滑动状态初始化为DO_NOTHING slideState = DO_NOTHING; break; case MotionEvent.ACTION_MOVE: xMove = event.getRawX(); yMove = event.getRawY(); // 手指移动时,对比按下时的坐标,计算出移动的距离。 int moveDistanceX = (int) (xMove - xDown); int moveDistanceY = (int) (yMove - yDown); // 检查当前的滑动状态 checkSlideState(moveDistanceX, moveDistanceY); // 根据当前滑动状态决定如何偏移内容布局 switch (slideState) { case SHOW_LEFT_MENU: contentLayoutParams.rightMargin = -moveDistanceX; checkLeftMenuBorder(); contentLayout.setLayoutParams(contentLayoutParams); break; case HIDE_LEFT_MENU: contentLayoutParams.rightMargin = -leftMenuLayoutParams.width - moveDistanceX; checkLeftMenuBorder(); contentLayout.setLayoutParams(contentLayoutParams); case SHOW_RIGHT_MENU: contentLayoutParams.leftMargin = moveDistanceX; checkRightMenuBorder(); contentLayout.setLayoutParams(contentLayoutParams); break; case HIDE_RIGHT_MENU: contentLayoutParams.leftMargin = -rightMenuLayoutParams.width moveDistanceX; checkRightMenuBorder(); contentLayout.setLayoutParams(contentLayoutParams); default: break; } break; case MotionEvent.ACTION_UP: xUp = event.getRawX(); int upDistanceX = (int) (xUp - xDown); if (isSliding) { // 手指抬起时,进行判断当前手势的意图 switch (slideState) { case SHOW_LEFT_MENU: if (shouldScrollToLeftMenu()) { scrollToLeftMenu(); } else { scrollToContentFromLeftMenu(); } break; case HIDE_LEFT_MENU: if (shouldScrollToContentFromLeftMenu()) { scrollToContentFromLeftMenu(); } else { scrollToLeftMenu(); } break; case SHOW_RIGHT_MENU: if (shouldScrollToRightMenu()) { scrollToRightMenu(); } else { scrollToContentFromRightMenu(); } break; case HIDE_RIGHT_MENU: if (shouldScrollToContentFromRightMenu()) { scrollToContentFromRightMenu(); } else { scrollToRightMenu(); } break; default: break; } } else if (upDistanceX < touchSlop && isLeftMenuVisible) { // 当左侧菜单显示时,如果用户点击一下内容部分,则直接滚动到内容界面 scrollToContentFromLeftMenu(); } else if (upDistanceX < touchSlop && isRightMenuVisible) { // 当右侧菜单显示时,如果用户点击一下内容部分,则直接滚动到内容界面 scrollToContentFromRightMenu(); } recycleVelocityTracker(); break; } if (v.isEnabled()) { if (isSliding) { // 正在滑动时让控件得不到焦点 unFocusBindView(); return true; } if (isLeftMenuVisible || isRightMenuVisible) { // 当左侧或右侧布局显示时,将绑定控件的事件屏蔽掉 return true; } return false; } return true; } /** * 根据手指移动的距离,判断当前用户的滑动意图,然后给slideState赋值成相应的滑动状态值。 * * @param moveDistanceX * 横向移动的距离 * @param moveDistanceY * 纵向移动的距离 */ private void checkSlideState(int moveDistanceX, int moveDistanceY) { if (isLeftMenuVisible) { if (!isSliding && Math.abs(moveDistanceX) >= touchSlop && moveDistanceX < 0) { isSliding = true; slideState = HIDE_LEFT_MENU; } } else if (isRightMenuVisible) { if (!isSliding && Math.abs(moveDistanceX) >= touchSlop && moveDistanceX > 0) { isSliding = true; slideState = HIDE_RIGHT_MENU; } } else { if (!isSliding && Math.abs(moveDistanceX) >= touchSlop && moveDistanceX > 0 && Math.abs(moveDistanceY) < touchSlop) { isSliding = true; slideState = SHOW_LEFT_MENU; contentLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0); contentLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); contentLayout.setLayoutParams(contentLayoutParams); // 如果用户想要滑动左侧菜单,将左侧菜单显示,右侧菜单隐藏 leftMenuLayout.setVisibility(View.VISIBLE); rightMenuLayout.setVisibility(View.GONE); } else if (!isSliding && Math.abs(moveDistanceX) >= touchSlop && moveDistanceX < 0 && Math.abs(moveDistanceY) < touchSlop) { isSliding = true; slideState = SHOW_RIGHT_MENU; contentLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0); contentLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); contentLayout.setLayoutParams(contentLayoutParams); // 如果用户想要滑动右侧菜单,将右侧菜单显示,左侧菜单隐藏 rightMenuLayout.setVisibility(View.VISIBLE); leftMenuLayout.setVisibility(View.GONE); } } } /** * 在滑动过程中检查左侧菜单的边界值,防止绑定布局滑出屏幕。 */ private void checkLeftMenuBorder() { if (contentLayoutParams.rightMargin > 0) { contentLayoutParams.rightMargin = 0; } else if (contentLayoutParams.rightMargin < -leftMenuLayoutParams.width) { contentLayoutParams.rightMargin = -leftMenuLayoutParams.width; } } /** * 在滑动过程中检查右侧菜单的边界值,防止绑定布局滑出屏幕。 */ private void checkRightMenuBorder() { if (contentLayoutParams.leftMargin > 0) { contentLayoutParams.leftMargin = 0; } else if (contentLayoutParams.leftMargin < -rightMenuLayoutParams.width) { contentLayoutParams.leftMargin = -rightMenuLayoutParams.width; } } /** * 判断是否应该滚动将左侧菜单展示出来。如果手指移动距离大于左侧菜单宽度的1/2,或者手指移动速度大于SNAP_VELOCITY, * 就认为应该滚动将左侧菜单展示出来。 * * @return 如果应该将左侧菜单展示出来返回true,否则返回false。 */ private boolean shouldScrollToLeftMenu() { return xUp - xDown > leftMenuLayoutParams.width / 2 || getScrollVelocity() > SNAP_VELOCITY; } /** * 判断是否应该滚动将右侧菜单展示出来。如果手指移动距离大于右侧菜单宽度的1/2,或者手指移动速度大于SNAP_VELOCITY, * 就认为应该滚动将右侧菜单展示出来。 * * @return 如果应该将右侧菜单展示出来返回true,否则返回false。 */ private boolean shouldScrollToRightMenu() { return xDown - xUp > rightMenuLayoutParams.width / 2 || getScrollVelocity() > SNAP_VELOCITY; } /** * 判断是否应该从左侧菜单滚动到内容布局,如果手指移动距离大于左侧菜单宽度的1/2,或者手指移动速度大于SNAP_VELOCITY, * 就认为应该从左侧菜单滚动到内容布局。 * * @return 如果应该从左侧菜单滚动到内容布局返回true,否则返回false。 */ private boolean shouldScrollToContentFromLeftMenu() { return xDown - xUp > leftMenuLayoutParams.width / 2 || getScrollVelocity() > SNAP_VELOCITY; } /** * 判断是否应该从右侧菜单滚动到内容布局,如果手指移动距离大于右侧菜单宽度的1/2,或者手指移动速度大于SNAP_VELOCITY, * 就认为应该从右侧菜单滚动到内容布局。 * * @return 如果应该从右侧菜单滚动到内容布局返回true,否则返回false。 */ private boolean shouldScrollToContentFromRightMenu() { return xUp - xDown > rightMenuLayoutParams.width / 2 || getScrollVelocity() > SNAP_VELOCITY; } /** * 创建VelocityTracker对象,并将触摸事件加入到VelocityTracker当中。 * * @param event * 右侧布局监听控件的滑动事件 */ private void createVelocityTracker(MotionEvent event) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); } /** * 获取手指在绑定布局上的滑动速度。 * * @return 滑动速度,以每秒钟移动了多少像素值为单位。 */ private int getScrollVelocity() { mVelocityTracker.computeCurrentVelocity(1000); int velocity = (int) mVelocityTracker.getXVelocity(); return Math.abs(velocity); } /** * 回收VelocityTracker对象。 */ private void recycleVelocityTracker() { mVelocityTracker.recycle(); mVelocityTracker = null; } /** * 使用可以获得焦点的控件在滑动的时候失去焦点。 */ private void unFocusBindView() { if (mBindView != null) { mBindView.setPressed(false); mBindView.setFocusable(false); mBindView.setFocusableInTouchMode(false); } } class LeftMenuScrollTask extends AsyncTask { @Override protected Integer doInBackground(Integer... speed) { int rightMargin = contentLayoutParams.rightMargin; // 根据传入的速度来滚动界面,当滚动到达边界值时,跳出循环。 while (true) { rightMargin = rightMargin speed[0]; if (rightMargin < -leftMenuLayoutParams.width) { rightMargin = -leftMenuLayoutParams.width; break; } if (rightMargin > 0) { rightMargin = 0; break; } publishProgress(rightMargin); // 为了要有滚动效果产生,每次循环使线程睡眠一段时间,这样肉眼才能够看到滚动动画。 sleep(15); } if (speed[0] > 0) { isLeftMenuVisible = false; } else { isLeftMenuVisible = true; } isSliding = false; return rightMargin; } @Override protected void onProgressUpdate(Integer... rightMargin) { contentLayoutParams.rightMargin = rightMargin[0]; contentLayout.setLayoutParams(contentLayoutParams); unFocusBindView(); } @Override protected void onPostExecute(Integer rightMargin) { contentLayoutParams.rightMargin = rightMargin; contentLayout.setLayoutParams(contentLayoutParams); } } class RightMenuScrollTask extends AsyncTask { @Override protected Integer doInBackground(Integer... speed) { int leftMargin = contentLayoutParams.leftMargin; // 根据传入的速度来滚动界面,当滚动到达边界值时,跳出循环。 while (true) { leftMargin = leftMargin speed[0]; if (leftMargin < -rightMenuLayoutParams.width) { leftMargin = -rightMenuLayoutParams.width; break; } if (leftMargin > 0) { leftMargin = 0; break; } publishProgress(leftMargin); // 为了要有滚动效果产生,每次循环使线程睡眠一段时间,这样肉眼才能够看到滚动动画。 sleep(15); } if (speed[0] > 0) { isRightMenuVisible = false; } else { isRightMenuVisible = true; } isSliding = false; return leftMargin; } @Override protected void onProgressUpdate(Integer... leftMargin) { contentLayoutParams.leftMargin = leftMargin[0]; contentLayout.setLayoutParams(contentLayoutParams); unFocusBindView(); } @Override protected void onPostExecute(Integer leftMargin) { contentLayoutParams.leftMargin = leftMargin; contentLayout.setLayoutParams(contentLayoutParams); } } /** * 使当前线程睡眠指定的毫秒数。 * * @param millis * 指定当前线程睡眠多久,以毫秒为单位 */ private void sleep(long millis) { try { Thread.sleep(millis); } catch (InterruptedException e) { e.printStackTrace(); } }}  
    2014-04-10下载
    积分:1
  • android 打飞机游戏 源码下载
    import com.pic.SpriteCmd.MainState;import android.app.Activity;import android.content.Context;import android.graphics.Bitmap;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Rect;import android.graphics.drawable.BitmapDrawable;import android.hardware.Sensor;import android.hardware.SensorEvent;import android.hardware.SensorEventListener;import android.hardware.SensorManager;import android.media.MediaPlayer;import android.os.Bundle;import android.view.MotionEvent;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;public class PictureView extends View implements Runnable,SensorEventListener{private Context context;private  int scrWidth;//屏幕的宽度private  int scrHeight;//屏幕的高度private  int MainTime = 0; //主计时器private  Bitmap imgBackground = null;//背景图片private  Bitmap imgBackground2 = null;private ButtonUtil ButtonStart = null;//开始按钮private ButtonUtil ButtonHelp = null;//帮助按钮private ButtonUtil ButtonScore = null;private ButtonUtil ButtonDetail = null;private  Bitmap imgStart = null;//开始按钮对应的图片private  Bitmap imgHelp = null;//帮助按钮对应的图片private  Bitmap imgScore = null;private  Bitmap imgDetail = null;private ButtonUtil ButtonFirst = null;//选关界面第一关对应按钮private ButtonUtil ButtonSecond = null;//选关界面第二关对应按钮private Bitmap imgFirst = null;//第一关对应图片private Bitmap imgSecond = null;//第二关对应图片private Bitmap imgHelpDisplay = null;//帮助图片private Bitmap imgScoreDisplay = null;//高分图片private Bitmap imgDetailDisplay = null;private ButtonUtil ButtonReturn = null;//返回按钮private Bitmap imgReturn = null;//返回按钮对应图片private ButtonUtil ButtonSound = null;//声音开关按钮private Bitmap imgSoundOn = null;//开声音对应图片private Bitmap imgSoundOff = null;//关声音对应图片private Boolean is_SoundOn = true;//声音是否开private Boolean is_LeverUp = false;//是否过关private int DeadEnemyCnt = 0;//敌人死亡计数器     当死亡敌人个数达到某个数时   过关private int LeverCnt = 0;//过关界面的计数器private static MediaPlayer mediaPlayer = null;//声音播放对象public enum GameState//游戏状态{GAMESTATE_MENU, //菜单GAMESTATE_LEVELGUIDE, //关数提示,显示第一关,第二关 。。GAMESTATE_HELP, GAMESTATE_SCORE,GAMESTATE_DETAIL,GAMESTATE_GAME, //游戏}public  GameState GameState; // 游戏状态public static final int STAR_NUM = 30;public SpriteCmd rgSpriteCmd = new SpriteCmd();////主角SpriteCmd类对象实例化public SpriteCmd rgCmdStar[] = new SpriteCmd[30];//星星对象public SpriteCmd rgBulletCmd[] = new SpriteCmd[20];//主角子弹对象public SpriteCmd rgEnemy1Cmd = new SpriteCmd();//敌人1的SpriteCmd类对象public SpriteCmd rgEnemy2Cmd = new SpriteCmd();//敌人2对象public SpriteCmd rgEnemy3Cmd = new SpriteCmd();//敌人3对象public SpriteCmd rgEnemy4Cmd = new SpriteCmd();public SpriteCmd rgEnemy5Cmd = new SpriteCmd();public SpriteCmd rgBombCmds[] = new SpriteCmd[5];//敌人死亡时候爆炸的对象private int LeverNum;//关数计数器public Bitmap imgPlane;//主角飞机对应图片public Bitmap imgStar;//星星对应图片public Bitmap imgBullet;//子弹图片public Bitmap imgEnemy1;//敌人1对应图片public Bitmap imgEnemy2;//敌人2对象图片public Bitmap imgEnemy3;public Bitmap imgEnemy4;public Bitmap imgEnemy5;public Bitmap imgBomb; //炸弹对应图片public Bitmap imgPassLerver;//过关图片public SpriteCmd rgGameover = new SpriteCmd();public Bitmap imgBloodBg;//血量框图片public Bitmap imgBlood;//血量图片public boolean IsRightKeyRealess = true;//右键是否释放public boolean IsLeftKeyRealess = true;//左键是否释放public boolean IsUpKeyRealess = true;//上键是否释放public boolean IsDownKeyRealess = true;//下键是否释放private SensorManager sm;//传感器管理器private Sensor sensor;//重力传感器对象public float x_sensor = 0;//重力传感器x方向的位置偏移public float y_sensor = 0;//重力传感器y方向的位置偏移public float z_sensor = 0;//重力传感器z方向的位置偏移public SpriteCmd rgBackground1 = new SpriteCmd();//背景对象1public SpriteCmd rgBackground2 = new SpriteCmd();//背景对象2public SpriteCmd rgLerver = new SpriteCmd();//“恭喜过关”对象public SpriteCmd rgBloodBg = new SpriteCmd();//“血量框”对象public SpriteCmd rgBlood = new SpriteCmd();//“血量”对象public boolean  Is_exit = false;//是否退出游戏public PictureView(Context context){      super(context);//调用父类的构造方法      MainTime = 0; // 主计时清零      sm = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);  sensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);// 得到一个重力传感器实例  sm.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);      new Thread(this).start(); //启动线程    通过start()方法找到run()方法      this.context = context;      Is_exit = false;      }public void TurnToMenu()//进入菜单{imgBackground =((BitmapDrawable)getResources().getDrawable(R.drawable.bg1)).getBitmap();//背景图片if (imgStart == null){imgStart = ((BitmapDrawable)getResources().getDrawable(R.drawable.start)).getBitmap();//“开始游戏”的图片}if (imgHelp == null){imgHelp = ((BitmapDrawable)getResources().getDrawable(R.drawable.help)).getBitmap();//“游戏帮助”的图片}if (imgScore == null){imgScore = ((BitmapDrawable)getResources().getDrawable(R.drawable.score)).getBitmap();//“高分”的图}if (imgDetail == null){imgDetail = ((BitmapDrawable)getResources().getDrawable(R.drawable.detail)).getBitmap();//“信息”的图}if (imgReturn == null){imgReturn = ((BitmapDrawable)getResources().getDrawable(R.drawable.back)).getBitmap();//“返回”的图片}ButtonStart = new ButtonUtil(imgStart,(scrWidth - imgStart.getWidth())/2,100);//把“开始游戏”的图片与按钮绑定ButtonHelp = new ButtonUtil(imgHelp,(scrWidth - imgHelp.getWidth())/2,200);ButtonScore = new ButtonUtil(imgScore,(scrWidth - imgScore.getWidth())/2,300);ButtonDetail = new ButtonUtil(imgDetail,(scrWidth - imgDetail.getWidth())/2,400);ButtonReturn = new ButtonUtil(imgReturn,scrWidth - imgReturn.getWidth() - 10,scrHeight - 50);//把“返回”的图片与按钮绑定GameState = GameState.GAMESTATE_MENU; //状态转换成菜单状态}public void TurnToLeverGuide()//进入选关{ReleaseImage(imgBackground);imgBackground =((BitmapDrawable)getResources().getDrawable(R.drawable.bg2)).getBitmap();//背景图片if (imgFirst == null){imgFirst = ((BitmapDrawable)getResources().getDrawable(R.drawable.firstlever)).getBitmap();//“第1关”的图片}if (imgSecond == null){imgSecond = ((BitmapDrawable)getResources().getDrawable(R.drawable.secondlever)).getBitmap();//“第2关”的图片}ButtonFirst = new ButtonUtil(imgFirst,(scrWidth - imgFirst.getWidth())/2,150);ButtonSecond = new ButtonUtil(imgSecond,(scrWidth - imgSecond.getWidth())/2,300);GameState = GameState.GAMESTATE_LEVELGUIDE;}public void TurnToHelp()//进入帮助{if (imgHelpDisplay == null){imgHelpDisplay = ((BitmapDrawable)getResources().getDrawable(R.drawable.helpdisplay)).getBitmap();}GameState = GameState.GAMESTATE_HELP;}public void TurnToScore()//进入高分榜{if (imgScoreDisplay == null){TextView a=new TextView(context);a.setText("a");//imgScoreDisplay = ((BitmapDrawable)getResources().getDrawable(R.drawable.scoredisplay)).getBitmap();}GameState = GameState.GAMESTATE_SCORE;}public void TurnToDetail()//进入信息{if (imgDetailDisplay == null){imgDetailDisplay = ((BitmapDrawable)getResources().getDrawable(R.drawable.detaildisplay)).getBitmap();}GameState = GameState.GAMESTATE_DETAIL;}public void TurnToGame()//进入游戏{   LoadResource();InitLever();//GameState = GameState.GAMESTATE_GAME;//////////为背景图定义了SpriteCmd类的两个对象,为背景图设定两个位置同时画出来//// rgBackground1.x = 0;rgBackground1.y = -scrHeight;rgBackground1.unLayer = 0;rgBackground1.unWidth = scrWidth;  //背景图的宽度设为全屏rgBackground1.unHeight = scrHeight;//背景图的宽度设为全屏rgBackground2.x = 0;rgBackground2.y = 0;rgBackground2.unLayer = 0;rgBackground2.unWidth = scrWidth;//背景图的宽度设为全屏rgBackground2.unHeight = scrHeight; //背景图的宽度设为全屏///////////////////////////////////////////////////////////// imgSoundOn =((BitmapDrawable)getResources().getDrawable(R.drawable.bgsoundon)).getBitmap();imgSoundOff =((BitmapDrawable)getResources().getDrawable(R.drawable.bgsoundoff)).getBitmap();ButtonSound = new ButtonUtil(imgSoundOn,10,scrHeight - 20);rgLerver.unWidth = 200;rgLerver.unHeight = 40;rgLerver.unLayer = 255;rgGameover.unWidth = 200;rgGameover.unHeight = 40;rgGameover.unLayer = 255;rgBloodBg.unWidth = 100;rgBloodBg.unHeight = 32;rgBloodBg.unLayer = 0;rgBloodBg.x = 0;rgBloodBg.y = 0;rgBlood.unWidth = 96;rgBlood.unHeight = 14;rgBlood.unLayer = 0;rgBlood.x = rgBloodBg.x;rgBlood.y = rgBloodBg.y   10;mediaPlayer = MediaPlayer.create(context, R.raw.game);    mediaPlayer.start();    mediaPlayer.setLooping(true);is_LeverUp = false;}void InitLever(){int i;switch (LeverNum) {case 1:   //第一关rgSpriteCmd.unWidth = 36;rgSpriteCmd.unHeight = 34;rgSpriteCmd.x = (scrWidth - rgSpriteCmd.unWidth)/2;rgSpriteCmd.y = scrHeight - rgSpriteCmd.unHeight;rgSpriteCmd.unLayer = 0;rgSpriteCmd.unSpriteIndex = 0;rgSpriteCmd.CurrentState = MainState.enSTAND;rgSpriteCmd.WalkCount = 0;rgSpriteCmd.IsHurt = false;rgSpriteCmd.IsLeftStop = false;rgSpriteCmd.IsRight = false;rgSpriteCmd.IsTopStop = false;rgSpriteCmd.IsDownStop = false;//敌人初始化rgEnemy1Cmd.unWidth = 35;rgEnemy1Cmd.unHeight = 30;rgEnemy1Cmd.unLayer = 255;rgEnemy3Cmd.unWidth = 35;rgEnemy3Cmd.unHeight = 30;rgEnemy3Cmd.unLayer = 255;rgEnemy3Cmd.IsRight = false;rgEnemy4Cmd.unWidth = 35;rgEnemy4Cmd.unHeight = 30;rgEnemy4Cmd.unLayer = 255;rgEnemy4Cmd.IsRight = false;break;case 2:  //第二关rgSpriteCmd.unWidth = 36;rgSpriteCmd.unHeight = 34;rgSpriteCmd.x = (scrWidth - rgSpriteCmd.unWidth)/4;rgSpriteCmd.y = scrHeight - rgSpriteCmd.unHeight;rgSpriteCmd.unLayer = 0;rgSpriteCmd.unSpriteIndex = 0;rgSpriteCmd.CurrentState = MainState.enSTAND;rgSpriteCmd.WalkCount = 0;rgSpriteCmd.IsHurt = false;rgSpriteCmd.IsLeftStop = false;rgSpriteCmd.IsRight = false;rgSpriteCmd.IsTopStop = false;rgSpriteCmd.IsDownStop = false;//敌人初始化rgEnemy1Cmd.unWidth = 35;rgEnemy1Cmd.unHeight = 30;rgEnemy1Cmd.unLayer = 255;rgEnemy2Cmd.unWidth = 35;rgEnemy2Cmd.unHeight = 30;rgEnemy2Cmd.unLayer = 255;rgEnemy3Cmd.unWidth = 35;rgEnemy3Cmd.unHeight = 30;rgEnemy3Cmd.unLayer = 255;rgEnemy3Cmd.IsRight = false;rgEnemy4Cmd.unWidth = 35;rgEnemy4Cmd.unHeight = 30;rgEnemy4Cmd.unLayer = 255;rgEnemy5Cmd.unWidth = 35;rgEnemy5Cmd.unHeight = 30;rgEnemy5Cmd.unLayer = 255;rgEnemy5Cmd.IsRight = false;break;default:break;}////星星的初始化///////////////////////////////for (i = 0; i < STAR_NUM; i  = 1){rgCmdStar[i] = new SpriteCmd();//每颗星星都实例化SpriteCmd类对象}for (i = 0; i < STAR_NUM; i  = 2) //偶数个星星的图片索引值为0{rgCmdStar[i].unSpriteIndex = 0;}for (i = 1; i < STAR_NUM; i  = 2) //基数个星星的图片索引值为1{rgCmdStar[i].unSpriteIndex = 1;}for (i = 0; i < STAR_NUM; i   ){rgCmdStar[i].unWidth = 3; //每颗星星图片的宽度和高度rgCmdStar[i].unHeight = 3;rgCmdStar[i].x = scrWidth/STAR_NUM*i   10;//每颗星星图片绘制在屏幕上的位置rgCmdStar[i].y = scrHeight/STAR_NUM*i;} //////////////每颗子弹实例化SpriteCmd类对象,初始化////////for(i=0;i scrHeight) {//到达地图下边界rgSpriteCmd.IsDownStop = true;rgSpriteCmd.y = scrHeight - rgSpriteCmd.unHeight;}else {rgSpriteCmd.IsDownStop = false;}////主机与敌机的碰撞判断及处理///////////////////////////////if ((CheckHitEnemy(rgSpriteCmd, rgEnemy1Cmd) || CheckHitEnemy(rgSpriteCmd, rgEnemy2Cmd)|| CheckHitEnemy(rgSpriteCmd, rgEnemy3Cmd)) || CheckHitEnemy(rgSpriteCmd, rgEnemy4Cmd)|| CheckHitEnemy(rgSpriteCmd, rgEnemy5Cmd)&& !rgSpriteCmd.IsHurt) {rgSpriteCmd.CurrentState = MainState.enHURT;rgSpriteCmd.ProtectCount = 18;rgSpriteCmd.IsHurt = true;rgBlood.unWidth -= 19;if (rgBlood.unWidth < 0) {rgBlood.unWidth = 96;}}/////主机子弹与敌机1的碰撞////////////////////////////////for(i=0;i -1 && y_sensor < 1) {rgSpriteCmd.CurrentState = MainState.enSTAND;}else {rgSpriteCmd.unSpriteIndex = 0;rgSpriteCmd.y  = 10;}}else if (rgSpriteCmd.CurrentState == MainState.enHURT) {rgSpriteCmd.unSpriteIndex = MainTime%2 - 1; rgSpriteCmd.ProtectCount--;if (rgSpriteCmd.ProtectCount == 0) {rgSpriteCmd.CurrentState = MainState.enSTAND;rgSpriteCmd.IsHurt = false;}}}   ///////把图片画成全屏///////////////////////////////////////////public  void DisplayImage(Canvas canvas, Bitmap bitmap,int width, int height){    if(bitmap!=null)    {    Rect scrRect = new Rect(); //绘制区域在屏幕上的矩形范围        scrRect.left = 0; //绘制区域左上角顶点在屏幕上的x坐标        scrRect.top = 0; //绘制区域左上角顶点在屏幕上的y坐标        scrRect.right = scrWidth;//width; //绘制区域右下角顶点在屏幕上的x坐标        scrRect.bottom = scrHeight;//height; //绘制区域右下角顶点在屏幕上的y坐标        Rect imgRect = new Rect(); //绘制区域在图片上的矩形范围        imgRect.left = 0; //绘制区域左上角顶点距离图片左上角的x坐标        imgRect.top = 0; //绘制区域左上角顶点距离图片左上角的y坐标        imgRect.right = 0   width; //绘制区域右下角顶点距离图片左上角的x坐标        imgRect.bottom = 0   height; //绘制区域右下角顶点距离图片左上角的y坐标        canvas.drawBitmap(bitmap, imgRect, scrRect, null); //绘制图片    }    }///////////////////////////////////////////////////////////////////////////  ////////画精灵(相对于屏幕的相对位置)//////////////////////public   void DrawSprites(Canvas canvas, Bitmap bitmap, SpriteCmd spriteCmd){if (spriteCmd.unLayer != 255) {DisplayImage(canvas, bitmap, //要画的图片spriteCmd.x, //图片左上角画在屏幕上的x位置spriteCmd.y, //图片左上角画在屏幕上的y位置spriteCmd.unWidth, //图片的宽度spriteCmd.unHeight, //图片的高度0, //要画的图片在整个图片中的x方向位置spriteCmd.unSpriteIndex * spriteCmd.unHeight); //要画的图片在整个图片中的y方向位置}}//画图片//参数依次为画布Canvas对象,位图对象,在屏幕上的x坐标,在屏幕上的y坐标,//绘制的宽度,绘制的高度,在图片上的x坐标,在图片上的y坐标public  void DisplayImage(Canvas canvas, Bitmap bitmap, int scrX, int scrY, int width, int height, int imgX, int imgY){if(bitmap!=null){Rect scrRect = new Rect(); //绘制区域在屏幕上的矩形范围scrRect.left = scrX; //绘制区域左上角顶点在屏幕上的x坐标scrRect.top = scrY; //绘制区域左上角顶点在屏幕上的y坐标scrRect.right = scrX   width; //绘制区域右下角顶点在屏幕上的x坐标scrRect.bottom = scrY   height; //绘制区域右下角顶点在屏幕上的y坐标Rect imgRect = new Rect(); //绘制区域在图片上的矩形范围imgRect.left = imgX; //绘制区域左上角顶点距离图片左上角的x坐标imgRect.top = imgY; //绘制区域左上角顶点距离图片左上角的y坐标imgRect.right = imgX   width; //绘制区域右下角顶点距离图片左上角的x坐标imgRect.bottom = imgY   height; //绘制区域右下角顶点距离图片左上角的y坐标canvas.drawBitmap(bitmap, imgRect, scrRect, null); //绘制图片}}//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////触屏事件////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////public boolean onTouchEvent(MotionEvent event){switch (event.getAction()){case MotionEvent.ACTION_DOWN: // 当触摸到屏幕IsRightKeyRealess = false;IsLeftKeyRealess = false;IsUpKeyRealess = false;IsDownKeyRealess = false;switch (GameState){case GAMESTATE_MENU:onTouchEventInMenu(event); // 菜单界面的触屏事件处理break;case GAMESTATE_LEVELGUIDE:onTouchEventLeverGuide(event);// 选关界面的触屏事件处理break;case GAMESTATE_HELP:onTouchEventHelp(event);// 帮助界面的触屏事件处理break;case GAMESTATE_SCORE:onTouchEventScore(event);// 分数界面的触屏事件处理break;case GAMESTATE_DETAIL:onTouchEventHelp(event);// 信息界面的触屏事件处理break;case GAMESTATE_GAME:onTouchEventInGame(event);// 游戏界面的触屏事件处理break;default:break;}return true;case MotionEvent.ACTION_UP:// 当手抬起,离开屏幕IsRightKeyRealess = true;IsLeftKeyRealess = true;IsUpKeyRealess = true;IsDownKeyRealess = true;return true;default:break;} return super.onTouchEvent(event);}public void onTouchEventInMenu(MotionEvent event)// 菜单界面的触屏事件处理{float x, y;x = event.getX();y = event.getY();if (ButtonStart.isClick(x, y)) {TurnToLeverGuide();}else if (ButtonHelp.isClick(x, y)) {TurnToHelp();}else if (ButtonScore.isClick(x, y)) {TurnToScore();}else if (ButtonDetail.isClick(x, y)) {TurnToDetail();}else if (ButtonReturn.isClick(x, y)) {Is_exit = true;CloseGame();}}public void onTouchEventLeverGuide(MotionEvent event)// 选关界面的触屏事件处理{float x, y;x = event.getX();y = event.getY();if (ButtonReturn.isClick(x, y)) {TurnToMenu();}else if (ButtonFirst.isClick(x, y)) {LeverNum = 1;TurnToGame();}else if (ButtonSecond.isClick(x, y)) {LeverNum = 2;TurnToGame();}}public void onTouchEventHelp(MotionEvent event)// 帮助界面的触屏事件处理{float x, y;x = event.getX();y = event.getY();if (ButtonReturn.isClick(x, y)) {TurnToMenu();}}public void onTouchEventScore(MotionEvent event)// 帮助界面的触屏事件处理{float x, y;x = event.getX();y = event.getY();if (ButtonReturn.isClick(x, y)) {TurnToMenu();}}public void onTouchEventInGame(MotionEvent event)// 游戏界面的触屏事件处理{float x, y;x = event.getX();y = event.getY();//////处理返回键/////////////////////////////// if (ButtonReturn.isClick(x, y)) {TurnToMenu();mediaPlayer.pause();}/////////////////////////////////////////// ///////////////声音处理///////////////////////////else if(ButtonSound.isClick(x, y)){if (is_SoundOn) {ButtonSound.setButtonPic(imgSoundOff);is_SoundOn = false;mediaPlayer.pause();}else {ButtonSound.setButtonPic(imgSoundOn);is_SoundOn = true;    mediaPlayer.start();    mediaPlayer.setLooping(true);}}/////////////////////////////////////////////////////////////////根据触摸点的位置判断主角飞机的运动状态////////////////////if ((x- rgSpriteCmd.x - rgSpriteCmd.unWidth/2) > (y - rgSpriteCmd.y - rgSpriteCmd.unHeight / 2)&& (x- rgSpriteCmd.x - rgSpriteCmd.unWidth/2) > -(y - rgSpriteCmd.y - rgSpriteCmd.unHeight / 2)&& !rgSpriteCmd.IsRigtStop && rgSpriteCmd.CurrentState != MainState.enHURT &&!ButtonSound.isClick(x, y)){rgSpriteCmd.CurrentState = MainState.enWALKRIGHT;//向右走}else if ((x - rgSpriteCmd.x - rgSpriteCmd.unWidth / 2 < (y - rgSpriteCmd.y - rgSpriteCmd.unHeight / 2)) && (x- rgSpriteCmd.x - rgSpriteCmd.unWidth/2) < -(y - rgSpriteCmd.y - rgSpriteCmd.unHeight / 2)&& !rgSpriteCmd.IsLeftStop && rgSpriteCmd.CurrentState != MainState.enHURT &&!ButtonSound.isClick(x, y)){rgSpriteCmd.CurrentState = MainState.enWALKLEFT;//向左走}else if ((y - rgSpriteCmd.y - rgSpriteCmd.unHeight / 2) = (x - rgSpriteCmd.x - rgSpriteCmd.unWidth / 2) && (y - rgSpriteCmd.y - rgSpriteCmd.unHeight / 2) >= -(x - rgSpriteCmd.x - rgSpriteCmd.unWidth / 2)&& !rgSpriteCmd.IsDownStop && rgSpriteCmd.CurrentState != MainState.enHURT &&!ButtonSound.isClick(x, y)){rgSpriteCmd.CurrentState = MainState.enWALKDOWN;//向下走}}/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public Boolean  CheckHitEnemy(SpriteCmd Cmd,SpriteCmd SpCmd) {if (Cmd.unLayer!=255 && SpCmd.unLayer != 255) {if (Cmd.x   Cmd.unWidth > SpCmd.x && Cmd.x < SpCmd.x   SpCmd.unWidth &&    Cmd.y   Cmd.unHeight > SpCmd.y && Cmd.y < SpCmd.y   SpCmd.unHeight) {return true;}} return false;}/////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void onAccuracyChanged(Sensor sensor, int accuracy) {// TODO Auto-generated method stub}public void onSensorChanged(SensorEvent event) {// TODO Auto-generated method stubx_sensor = event.values[0]; // 手机横向翻滚// x>0 说明当前手机左翻 x0 说明当前手机下翻 y0 手机屏幕朝上 z
    2015-07-02下载
    积分:1
  • android listview实现复选框(checkboxlist) 例子源码下载设计
    android listview实现复选框(checkboxlist) 例子源码下载设计
    2015-05-05下载
    积分:1
  • UCI数据集
    UCI数据集
    2020-12-02下载
    积分:1
  • commons-net-3.3-src源码下载(含ftp/ntp/nntp/mail/telnet/unix等类库实例)
    非常强大的 网络通讯类库,含实例源码
    2015-03-16下载
    积分:1
  • android 多线程实例源码下载
    android 多线程实例源码下载
    2015-05-13下载
    积分:1
  • WiFi编程例子
    WiFi编程例子
    2015-02-03下载
    积分:1
  • android系统控制onvif协议摄像头app源码
    android-onvif是一个基于android系统控制onvif协议摄像头的软件项目,例如海康摄像头等。本项目已将接口封装,使用简单。后续将扩展更多功能。。。功能介绍探索与发现摄像头摄像头参数获取和获取摄像头账号密码修改摄像头的固件升级摄像头截图修改摄像头时间重启摄像头修改摄像头ip
    2021-05-06下载
    积分:1
  • 696524资源总数
  • 103920会员总数
  • 65今日下载