package com.example.sensoreventListenertest;import java.util.Random;import com.example.sensoreventListenertest.ShakeListener.OnShakeListener;import androID.media.MediaPlayer;import androID.os.Bundle;import androID.os.Handler;import androID.os.Vibrator;import androID.app.Activity;import androID.content.Intent;import androID.vIEw.Gravity;import androID.vIEw.VIEw;import androID.vIEw.Window;import androID.vIEw.animation.Animation;import androID.vIEw.animation.AnimationSet;import androID.vIEw.animation.TranslateAnimation;import androID.Widget.button;import androID.Widget.relativeLayout;import androID.Widget.SlIDingDrawer;import androID.Widget.Toast;import androID.Widget.SlIDingDrawer.OnDrawerCloseListener;import androID.Widget.SlIDingDrawer.OnDrawerOpenListener;public class MainActivity extends Activity{ ShakeListener mShakeListener = null; Vibrator mVibrator; private relativeLayout mimgUp; private relativeLayout mimgDn; private relativeLayout mTitle; private SlIDingDrawer mDrawer; private button mDrawerBtn; @OverrIDe public voID onCreate(Bundle savedInstanceState) { // Todo auto-generated method stub super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); //drawerSet ();//设置 drawer监听 切换 按钮的方向 mVibrator = (Vibrator)getApplication().getSystemService(VIBRATOR_SERVICE); mimgUp = (relativeLayout) findVIEwByID(R.ID.shakeimgUp); mimgDn = (relativeLayout) findVIEwByID(R.ID.shakeimgDown); mTitle = (relativeLayout) findVIEwByID(R.ID.shake_Title_bar); mDrawer = (SlIDingDrawer) findVIEwByID(R.ID.slIDingDrawer1); mDrawerBtn = (button) findVIEwByID(R.ID.handle); mDrawer.setonDrawerOpenListener(new OnDrawerOpenListener() { public voID onDrawerOpened() { mDrawerBtn.setBackgroundDrawable(getResources().getDrawable(R.drawable.shake_report_dragger_down)); TranslateAnimation Titleup = new TranslateAnimation(Animation.relative_TO_SELF,0f,Animation.relative_TO_SELF,0f,Animation.relative_TO_SELF,0f,Animation.relative_TO_SELF,-1.0f); Titleup.setDuration(200); Titleup.setFillAfter(true); mTitle.startAnimation(Titleup); } }); /* 设定SlIDingDrawer被关闭的事件处理 */ mDrawer.setonDrawerCloseListener(new OnDrawerCloseListener() { public voID onDrawerClosed() { mDrawerBtn.setBackgroundDrawable(getResources().getDrawable(R.drawable.shake_report_dragger_up)); TranslateAnimation Titledn = new TranslateAnimation(Animation.relative_TO_SELF,0f,Animation.relative_TO_SELF,0f,Animation.relative_TO_SELF,-1.0f,Animation.relative_TO_SELF,0f); Titledn.setDuration(200); Titledn.setFillAfter(false); mTitle.startAnimation(Titledn); } }); mShakeListener = new ShakeListener(MainActivity.this); mShakeListener.setonShakeListener(new OnShakeListener() { public voID onShake() { //Toast.makeText(getApplicationContext(), "抱歉,暂时没有找到在同一时刻摇一摇的人。\n再试一次吧!", Toast.LENGTH_SHORT).show(); startAnim(); //开始 摇一摇手掌动画 mShakeListener.stop(); startVibrato(); //开始 震动 new Handler().postDelayed(new Runnable(){ @OverrIDe public voID run(){ //Toast.makeText(getApplicationContext(), "抱歉,暂时没有找到\n在同一时刻摇一摇的人。\n再试一次吧!", 500).setGravity(Gravity.CENTER,0,0).show(); Random r=new Random(); int num=(int )((Math.random())*10); Toast mtoast; mtoast = Toast.makeText(getApplicationContext(), "恭喜您获得"+num+"个签到积分,积分兑换,更有礼品相送", 10); //mtoast.setGravity(Gravity.CENTER, 0, 0); mtoast.show(); mVibrator.cancel(); mShakeListener.start(); } }, 2000); } }); } public voID startAnim () { //定义摇一摇动画动画 AnimationSet animup = new AnimationSet(true); TranslateAnimation mytranslateanimup0 = new TranslateAnimation(Animation.relative_TO_SELF,0f,Animation.relative_TO_SELF,0f,Animation.relative_TO_SELF,0f,Animation.relative_TO_SELF,-0.5f); mytranslateanimup0.setDuration(1000); TranslateAnimation mytranslateanimup1 = new TranslateAnimation(Animation.relative_TO_SELF,0f,Animation.relative_TO_SELF,0f,Animation.relative_TO_SELF,0f,Animation.relative_TO_SELF,+0.5f); mytranslateanimup1.setDuration(1000); mytranslateanimup1.setStartOffset(1000); animup.addAnimation(mytranslateanimup0); animup.addAnimation(mytranslateanimup1); mimgUp.startAnimation(animup); AnimationSet animdn = new AnimationSet(true); TranslateAnimation mytranslateanimdn0 = new TranslateAnimation(Animation.relative_TO_SELF,0f,Animation.relative_TO_SELF,0f,Animation.relative_TO_SELF,0f,Animation.relative_TO_SELF,+0.5f); mytranslateanimdn0.setDuration(1000); TranslateAnimation mytranslateanimdn1 = new TranslateAnimation(Animation.relative_TO_SELF,0f,Animation.relative_TO_SELF,0f,Animation.relative_TO_SELF,0f,Animation.relative_TO_SELF,-0.5f); mytranslateanimdn1.setDuration(1000); mytranslateanimdn1.setStartOffset(1000); animdn.addAnimation(mytranslateanimdn0); animdn.addAnimation(mytranslateanimdn1); mimgDn.startAnimation(animdn); } public voID startVibrato(){ MediaPlayer player; player = MediaPlayer.create(this, R.raw.awe); player.setLooPing(false); player.start(); //定义震动 mVibrator.vibrate( new long[]{500,200,500,200}, -1); //第一个{}里面是节奏数组, 第二个参数是重复次数,-1为不重复,非-1俄日从pattern的指定下标开始重复 } public voID shake_activity_back(VIEw v) { //标题栏 返回按钮 this.finish(); } public voID linshi(VIEw v) { //标题栏 startAnim(); } @OverrIDe protected voID onDestroy() { super.onDestroy(); if (mShakeListener != null) { mShakeListener.stop(); } }}
点赞收藏分享文章举报zhupengqq1发布了194 篇原创文章 · 获赞 1 · 访问量 3956私信 关注 总结
以上是内存溢出为你收集整理的android微信摇一摇(抽奖)全部内容,希望文章能够帮你解决android微信摇一摇(抽奖)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)