package com.android.remotecontrolppt;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageButton;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
public class RemoteControlPPTActivity extends Activity implements View.OnClickListener,OnGestureListener{
/**
* 第一个字节用来区分事件类型(1为鼠标,2为键盘)
* 第二个字节用来存放操作指令
* 第三个字节用来存放操作指令值
* 第四个字节为预留
* 第5-12字节为数据位
*/
private byte cmdBuffer[] = new byte[Constant.bufferSize];
private ImageButton start = null;
private ImageButton stop = null;
private ImageButton mouse_left = null;
private ImageButton mouse_right = null;
private ImageButton move_up = null;
private ImageButton move_down = null;
private ImageButton previous = null;
private ImageButton next = null;
private ImageButton center = null;
private MulticastSocket multicastSocket = null;
private InetAddress remoteInetAddress = null;
private GestureDetector mGestureDetector = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mGestureDetector = new GestureDetector(this);//构造方法new GestureDetector(GestureListener listener);
start = (ImageButton)findViewById(R.id.start);
start.setOnClickListener(this);
stop = (ImageButton)findViewById(R.id.stop);
stop.setOnClickListener(this);
mouse_left = (ImageButton)findViewById(R.id.mouse_left);
mouse_left.setOnClickListener(this);
mouse_right = (ImageButton)findViewById(R.id.mouse_right);
mouse_right.setOnClickListener(this);
center = (ImageButton)findViewById(R.id.center);
center.setOnClickListener(this);
move_up = (ImageButton)findViewById(R.id.move_up);
move_up.setOnClickListener(this);
move_down = (ImageButton)findViewById(R.id.move_down);
move_down.setOnClickListener(this);
previous = (ImageButton)findViewById(R.id.previous);
previous.setOnClickListener(this);
next = (ImageButton)findViewById(R.id.next);
next.setOnClickListener(this);
}
//按钮事件处理
@Override
public void onClick(View view) {
for(int i=0;i<4;i++)cmdBuffer[i]=0;
boolean opr = false;
switch(view.getId()){
case R.id.start://播放映片指令
cmdBuffer[0]=Constant.RULE_KEY_EVENT;
cmdBuffer[1]=Constant.KEY_F5;
opr = true;
break;
case R.id.stop://停止播放映片指令
cmdBuffer[0]=Constant.RULE_KEY_EVENT;
cmdBuffer[1]=Constant.KEY_ESC;
opr = true;
break;
case R.id.center://鼠标左键点击
case R.id.mouse_left://鼠标左键点击
cmdBuffer[0]=Constant.RULE_MOUSE_EVENT;
cmdBuffer[1]=Constant.MOUSE_LEFT;
opr = true;
break;
case R.id.mouse_right://鼠标右键点击
cmdBuffer[0]=Constant.RULE_MOUSE_EVENT;
cmdBuffer[1]=Constant.MOUSE_RIGHT;
opr = true;
break;
case R.id.move_up://向左翻页
case R.id.previous://向左翻页
cmdBuffer[0]=Constant.RULE_KEY_EVENT;
cmdBuffer[1]=Constant.KEY_ARROW_LEFT;
opr = true;
break;
case R.id.move_down://向右翻页
case R.id.next://向右翻页
cmdBuffer[0]=Constant.RULE_KEY_EVENT;
cmdBuffer[1]=Constant.KEY_ARROW_RIGHT;
opr = true;
break;
}
if(opr){
sendCMD();
}
}
//向电脑端发送指令
private void sendCMD(){
try {
DatagramPacket sdp = new DatagramPacket(cmdBuffer, Constant.bufferSize,remoteInetAddress,Constant.commPort);
multicastSocket.send(sdp);
} catch (Exception e) {
e.printStackTrace();
}
}
//侦测屏幕滑动事件
@Override
public boolean onTouchEvent(MotionEvent event) {
/**
* 把滑动事件传给GestureDetector进行事件分析,因我们当前实现了GestureDetector.GestureListener接口,
* 因此,会把该事件传给下面几个方法来处理
*/
return mGestureDetector.onTouchEvent(event);
}
//初始化Socket连接
@Override
protected void onResume() {
super.onResume();
try {
if(null==multicastSocket){
remoteInetAddress = InetAddress.getByName(Constant.multicastIp);
multicastSocket = new MulticastSocket(Constant.commPort);
multicastSocket.joinGroup(remoteInetAddress);
}
}catch(IOException e) {
e.printStackTrace();
}
}
//------------------------------------下面部分为GestureListener接口实现部分-----------------------------------------------------------------------------
/**
* 下面部分为GestureListener接口实现部分
*/
@Override
public boolean onDown(MotionEvent event) {
System.out.println("onDown...");
return false;
}
/**
* X轴的坐标位移大于FLING_MIN_DISTANCE,且移动速度大于FLING_MIN_VELOCITY个像素/秒,时会触发该事件
* downEvent当屏幕按下时触发的事件,由MotionEvent.ACTION_DOWN提供
* upEvent当滑动停止时触发的事件,由滑动的最后一个MotionEvent.ACTION_MOVE提供,即弹起
* xVelocity: X轴上的移动速度,像素/秒
* yVelocity: Y轴上的移动速度,像素/秒
*/
@Override
public boolean onFling(MotionEvent downEvent, MotionEvent upEvent, float xVelocity,float yVelocity) {
if((upEvent.getX()-downEvent.getX())>0){//向左翻页
cmdBuffer[0]=Constant.RULE_KEY_EVENT;
cmdBuffer[1]=Constant.KEY_ARROW_LEFT;
sendCMD();
}else{//向右翻页
cmdBuffer[0]=Constant.RULE_KEY_EVENT;
cmdBuffer[1]=Constant.KEY_ARROW_RIGHT;
sendCMD();
}
System.out.println("onFling...");
return false;
}
@Override
public void onLongPress(MotionEvent event) {
System.out.println("onLongPress...");
}
/**
*用户按下触摸屏,并拖动,由1个MotionEvent.ACTION_DOWN, 多个MotionEvent.ACTION_MOVE触发
*downEvent为MotionEvent.ACTION_DOWN触发的事件
*movEvent为MotionEvent.ACTION_MOVE触发的事件
*distance_X表示在X方向上滑动的距离,该值由上一个坐标值减去当前坐标值p1.x-p2.x,因此当正向滑动时为负值
*distance_Y表示在Y方向上滑动的距离,该值由上一个坐标值减去当前坐标值p1.y-p2.y,因此当正向滑动时为负值
*因我们需要当移动端正向滑动时电脑端鼠标也跟着正向移动,因此所要把这两个值反一下
*/
@Override
public boolean onScroll(MotionEvent downEvent, MotionEvent movEvent, float distance_X,float distance_Y) {
//把本次移动的距离发送到服务端以此来控制服务端鼠标的移动
try {
cmdBuffer[0]=Constant.RULE_MOUSE_EVENT;
cmdBuffer[1]=Constant.MOUSE_GESTURE;
byte xValue[]=ByteAndInt.int2ByteArray((int)(-distance_X));//把滑动距离反一下,这样当正向滑动时电脑端也为正向移动
byte yValue[]=ByteAndInt.int2ByteArray((int)(-distance_Y));
System.arraycopy(xValue, 0, cmdBuffer, 4, 4);
System.arraycopy(yValue, 0, cmdBuffer, 8, 4);
DatagramPacket sdp = new DatagramPacket(cmdBuffer, Constant.bufferSize,remoteInetAddress,Constant.commPort);
multicastSocket.send(sdp);
} catch (Exception e) {
e.printStackTrace();
}
return super.onTouchEvent(downEvent);
}
@Override
public void onShowPress(MotionEvent event) {
System.out.println("onShowPress...");
}
@Override
public boolean onSingleTapUp(MotionEvent event) {
//轻触,发送鼠标点击指令
cmdBuffer[0]=Constant.RULE_MOUSE_EVENT;
cmdBuffer[1]=Constant.MOUSE_LEFT;
sendCMD();
System.out.println("onSingleTapUp...");
return false;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
手机控制ppt翻页源码
共65个文件
jpg:19个
class:13个
xml:12个
5星 · 超过95%的资源 需积分: 50 116 下载量 13 浏览量
2013-10-30
09:54:05
上传
评论 5
收藏 216KB RAR 举报
温馨提示
通过手机上的app控制电脑ppt翻页。用手机遥控PPT的东西,从此把讲师彻底从讲台前解放出来。 项目说明: 1、项目分为手机端(ppt_mobile.apk)和pc端(ppt_server.jar) 2、手机端支持触屏和滑动ppt翻页。
资源推荐
资源详情
资源评论
收起资源包目录
remote_ppt_src.rar (65个子文件)
ppt_mobile
bin
classes.dex 9KB
com
android
remotecontrolppt
R$layout.class 424B
R$id.class 664B
R$drawable.class 1KB
RemoteControlPPTActivity.class 5KB
R$attr.class 370B
R.class 601B
Constant.class 1KB
ByteAndInt.class 2KB
R$string.class 734B
resources.ap_ 124KB
ppt_mobile.apk 132KB
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
drawable
next_btn.xml 343B
move_left_btn.xml 358B
click_btn.xml 346B
stop_btn.xml 343B
move_down_btn.xml 358B
previous_btn.xml 355B
move_up_btn.xml 352B
start_btn.xml 346B
move_right_btn.xml 361B
values
strings.xml 594B
drawable-mdpi
move_left_off.jpg 5KB
move_left_on.jpg 5KB
move_up_on.jpg 5KB
move_right_on.jpg 5KB
remote_bg.jpg 11KB
click_on.jpg 4KB
ppt.png 29KB
previous_on.jpg 5KB
next_on.jpg 5KB
move_up_off.jpg 4KB
stop_off.jpg 5KB
previous_off.jpg 5KB
next_off.jpg 5KB
start_off.jpg 5KB
click_off.jpg 4KB
move_down_off.jpg 5KB
move_down_on.jpg 5KB
move_right_off.jpg 5KB
icon.png 3KB
start_on.jpg 6KB
stop_on.jpg 6KB
layout
main.xml 3KB
assets
default.properties 362B
gen
com
android
remotecontrolppt
R.java 3KB
proguard.cfg 1KB
src
com
android
remotecontrolppt
RemoteControlPPTActivity.java 8KB
ByteAndInt.java 2KB
Constant.java 2KB
.project 846B
.classpath 280B
AndroidManifest.xml 788B
ppt_server
bin
MouseControl.class 5KB
MouseControl$StartSocket.class 3KB
Constant.class 1KB
ByteAndInt.class 2KB
.settings
org.eclipse.jdt.core.prefs 629B
src
ByteAndInt.java 2KB
MouseControl.java 7KB
Constant.java 2KB
.project 386B
.classpath 445B
共 65 条
- 1
egxsun
- 粉丝: 8
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页