mouseActivity.java ( File view )

  • By chengyuqiong 2014-05-08
  • View(s):17
  • Download(s):1
  • Point(s): 1
			package gjz.ControlPC;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

import android.app.Activity;
import android.util.Log;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener;
import android.os.Bundle;
import android.os.Message;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class mouseActivity extends Activity implements OnTouchListener, OnGestureListener  ,OnDoubleTapListener 
{

	private GestureDetector mGestureDetector;
	
	final int MOUSEEVENTF_CANCEL      =  0x0001; /* mouse move */
	final int MOUSEEVENTF_MOVE      =  0x0001; /* mouse move */
	
	final int MOUSEEVENTF_LEFTDOWN  =  0x0002; /* left button down */
	final int MOUSEEVENTF_LEFTUP    =  0x0003; /* left button up */
	final int MOUSEEVENTF_RIGHTDOWN =  0x0004; /* right button down */
	final int MOUSEEVENTF_RIGHTUP   =  0x0005; /* right button up */
	
	final int MOUSEEVENTF_TAP       =  0x0006; /* 单击 */
	final int MOUSEEVENTF_DOUBLETAP =  0x0007; /* 双击 */
	
	final int MOUSEEVENTF_ROLLUP    =  0x0008; /* 向上拖动滚动*/
	final int MOUSEEVENTF_ROLLDOWN  =  0x0009; /* 向下拖动滚动*/
	
	private TextView touchInof;
	private Button mouseRightButton, mouseLeftButton, rollUpButton, rollDownButton;	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {

	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.mouse_layout);
	        
	        touchInof = (TextView)findViewById(R.id.touchInfo);    
	        
	        mouseRightButton= (Button)findViewById(R.id.rightButton);
	        mouseRightButton.setOnClickListener(buttonClickListener);
	        mouseLeftButton= (Button)findViewById(R.id.leftButton);
	        mouseLeftButton.setOnClickListener(buttonClickListener);
	        
	        rollUpButton= (Button)findViewById(R.id.rollerButtonUp);
	        rollUpButton.setOnClickListener(buttonClickListener); 	        
	        rollUpButton.setOnLongClickListener(buttonlongClickListener);
	        rollUpButton.setLongClickable(true);
	        
	        rollDownButton= (Button)findViewById(R.id.rollerButtonDown);
	        rollDownButton.setOnClickListener(buttonClickListener);
	        rollDownButton.setLongClickable(true);
	        rollDownButton.setOnLongClickListener(buttonlongClickListener);
	        
	        mGestureDetector = new GestureDetector((OnGestureListener) this);     
	        RelativeLayout viewSnsLayout = (RelativeLayout)findViewById(R.id.touchLayout);     
	        viewSnsLayout.setOnTouchListener(this);     
	        viewSnsLayout.setLongClickable(true);
	    
}
	 private OnClickListener buttonClickListener = new OnClickListener() {

			@Override
			public void onClick(View arg0) {

				// TODO Auto-generated method stub
				switch(arg0.getId())
				{

				case R.id.rightButton://右击
					sendMessage(MOUSEEVENTF_RIGHTUP+"");
					break;
				case R.id.leftButton://单击
					sendMessage(MOUSEEVENTF_TAP+"");
					break;
					
				case R.id.rollerButtonUp://向上拖动滚动
					if(clickButton != 0)
					{

						clickButton = 0;
						mThread.interrupt();
						sendMessage("long click up");
					
}
					else
						sendMessage(MOUSEEVENTF_ROLLUP+"");
					break;
					
				case R.id.rollerButtonDown://向下拖动滚动
					if(clickButton != 0)
					{

						clickButton = 0;
						mThread.interrupt();
						sendMessage("long click dwon");
					
}
					else
						sendMessage(MOUSEEVENTF_ROLLDOWN+"");
					break;
				
}
			
}
	 
};
	 private Thread mThread = null;
	 private int clickButton = 0;
	 private OnLongClickListener buttonlongClickListener =  new OnLongClickListener()
	 {

		@Override
		public boolean onLongClick(View v) {

			// TODO Auto-generated method stub
			clickButton = v.getId();
			mThread = new Thread(mLongClickRunnable);
			mThread.start();	
			return false;
		
}		 
	 
};
	 
	private Runnable	mLongClickRunnable	= new Runnable() 
	{

			public void run()
			{

				while(clickButton!=0)
				{

					if(clickButton==R.id.rollerButtonDown)
						sendMessage(MOUSEEVENTF_ROLLDOWN+"");
					else if(clickButton==R.id.rollerButtonUp)
						sendMessage(MOUSEEVENTF_ROLLUP+"");
				
}
			
}
	
};
		
	private void sendMessage(String msgText)
	{

			if ( ControlPCActivity.mPrintWriterClient!=null ) 
			{

					try 
					{
				    	
						ControlPCActivity.mPrintWriterClient.print(msgText);//发送给服务器
						ControlPCActivity.mPrintWriterClient.flush();
					
}
					catch (Exception e) 
					{

						// TODO: handle exception
						Toast.makeText(this, "发送异常:" + e.getMessage(), Toast.LENGTH_SHORT).show();
					
}
			
}
			else if ( ControlPCActivity.mPrintWriterServer!=null ) 
			{

				try 
				{
				    	
					ControlPCActivity.mPrintWriterServer.print(msgText);//发送给服务器
					ControlPCActivity.mPrintWriterServer.flush();
				
}
				catch (Exception e) 
				{

					// TODO: handle exception
					Toast.makeText(this, "发送异常:" + e.getMessage(), Toast.LENGTH_SHORT).show();
				
}
		
}
	
}

		private boolean isLongPress  = false;
		private float touchMoveX=0, touchMoveY=0;
		@Override
		public boolean onTouch(View v, MotionEvent event) {

			// TODO Auto-generated method stub
			//return false;
			
			if(isLongPress)
			{

				if(event.getAction()==MotionEvent.ACTION_MOVE)
				{
					
					if(touchMoveX==0)
					{

						touchMoveX = event.getX();
						touchMoveY = event.getY();
					
}
					else
					{

						sendMessage(MOUSEEVENTF_MOVE+":" + (event.getX()-touchMoveX) + ";" + (event.getY()-touchMoveY));//左键弹起
						
						touchInof.setText("onTouch move: " + (event.getX()-touchMoveX) + " : " + (event.getY()-touchMoveY));
						touchMoveX = event.getX();
						touchMoveY = event.getY();
					
}
				
}
				else if(event.getAction()==MotionEvent.ACTION_UP)
				{

					touchInof.setText("onTouch up: " + event.getX() + " : " + event.getY());		
					isLongPress = false;
					sendMessage(MOUSEEVENTF_LEFTUP+"");//左键弹起
				
}
				else
				{

					touchMoveX = 0;
					isLongPress = false;
					sendMessage(MOUSEEVENTF_CANCEL+"");//左键弹起					
				
}
				return false;
			
}			
			return mGestureDetector.onTouchEvent(event); 
		
}

		@Override
		public boolean onDow
...
...
(Please download the complete source code to view)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
01.96 kB
.classpath364.00 B2011-12-26|15:52
.project845.00 B2011-12-26|15:52
AndroidManifest.xml1.05 kB2011-12-28|17:30
01.96 kB
01.96 kB
01.96 kB
classes.dex22.48 kB2011-12-30|16:41
01.96 kB
01.96 kB
ControlPCActivity$1.class2.26 kB2012-01-17|13:46
ControlPCActivity$2.class1.99 kB2012-01-17|13:46
ControlPCActivity$3.class2.00 kB2012-01-17|13:46
ControlPCActivity$4.class3.59 kB2012-01-17|13:46
ControlPCActivity$5.class1.27 kB2012-01-17|13:46
ControlPCActivity$6.class2.23 kB2012-01-17|13:46
ControlPCActivity$7.class3.15 kB2012-01-17|13:46
ControlPCActivity$8.class1.52 kB2012-01-17|13:46
ControlPCActivity.class9.50 kB2012-01-17|13:46
mouseActivity$1.class1.33 kB2012-01-17|13:46
mouseActivity$2.class1.13 kB2012-01-17|13:46
mouseActivity$3.class843.00 B2012-01-17|13:46
mouseActivity.class7.60 kB2012-01-17|13:46
R$attr.class325.00 B2012-01-17|13:46
R$drawable.class423.00 B2012-01-17|13:46
R$id.class1.16 kB2012-01-17|13:46
R$layout.class415.00 B2012-01-17|13:46
R$string.class412.00 B2012-01-17|13:46
R.class496.00 B2012-01-17|13:46
ControlPC.apk154.99 kB2011-12-30|16:41
01.96 kB
resources.ap_143.35 kB2011-12-30|15:39
01.96 kB
bg_chat.png129.57 kB2011-12-30|10:33
ic_launcher.png3.87 kB2011-12-30|10:33
01.96 kB
ic_launcher.png1.50 kB2011-12-30|10:33
01.96 kB
ic_launcher.png2.15 kB2011-12-30|10:33
01.96 kB
01.96 kB
01.96 kB
R.java2.10 kB2011-12-30|11:25
proguard.cfg1.22 kB2011-12-26|15:52
project.properties361.00 B2011-12-26|15:52
01.96 kB
01.96 kB
bg_chat.png132.86 kB1980-01-01|00:00
ic_launcher.png4.05 kB2011-12-26|15:52
01.96 kB
ic_launcher.png1.68 kB2011-12-26|15:52
01.96 kB
ic_launcher.png2.51 kB2011-12-26|15:52
01.96 kB
main.xml4.45 kB2011-12-30|15:13
mouse_layout.xml1.97 kB2011-12-30|10:33
01.96 kB
strings.xml184.00 B2011-12-26|15:52
01.96 kB
01.96 kB
01.96 kB
ControlPCActivity.java14.39 kB2011-12-30|11:42
mouseActivity.java9.63 kB2011-12-30|16:41
01.96 kB
01.96 kB
KeyboardHook.dll272.07 kB2011-12-27|19:48
KeyboardHook.lib2.51 kB2011-12-27|19:48
Keyexe.bsc5.17 MB2011-12-30|15:40
Keyexe.exe116.06 kB2011-12-30|15:40
Keyexe.ilk277.56 kB2011-12-30|15:40
Keyexe.obj13.34 kB2011-12-27|19:35
Keyexe.pch6.66 MB2011-12-22|18:15
Keyexe.pdb401.00 kB2011-12-30|15:40
Keyexe.res4.93 kB2011-12-30|11:59
Keyexe.sbr0.00 B2011-12-27|19:35
KeyexeDlg.obj59.41 kB2011-12-30|15:40
KeyexeDlg.sbr0.00 B2011-12-30|15:40
StdAfx.obj104.05 kB2011-12-22|18:15
StdAfx.sbr1.32 MB2011-12-22|18:15
vc60.idb41.00 kB2011-12-30|15:40
vc60.pdb364.00 kB2011-12-30|15:40
icon1.ico766.00 B2011-12-26|13:05
key.txt12.00 B2011-12-22|15:41
KeyboardHook.dll272.07 kB2011-12-27|19:48
KeyboardHook.lib2.51 kB2011-12-27|19:48
keydll3.H348.00 B2011-12-22|12:29
Keyexe.aps38.21 kB2011-12-30|11:59
Keyexe.clw1.86 kB2011-12-30|16:37
Keyexe.cpp3.05 kB2001-12-07|14:20
Keyexe.dsp4.38 kB2011-12-26|16:46
Keyexe.dsw537.00 B2001-12-05|12:23
Keyexe.h2.36 kB2001-12-07|14:20
Keyexe.ncb81.00 kB2011-12-30|17:34
Keyexe.opt56.50 kB2011-12-30|17:34
Keyexe.plg1.13 kB2011-12-30|15:40
Keyexe.rc7.15 kB2011-12-30|11:59
KeyexeDlg.cpp19.98 kB2011-12-30|14:42
KeyexeDlg.h3.08 kB2011-12-27|19:34
ReadMe.txt2.42 kB2001-12-07|22:07
01.96 kB
resource.h1.16 kB2011-12-27|19:35
icon1.ico766.00 B2011-12-26|14:50
Keyexe.ico1.05 kB2001-12-05|12:23
Keyexe.rc2398.00 B2001-12-05|12:23
notify.bmp1.82 kB2011-12-26|14:45
Thumbs.db6.50 kB2011-12-26|15:07
StdAfx.cpp1.35 kB2001-12-07|14:23
StdAfx.h2.06 kB2011-12-22|18:15
...
Sponsored links

mouseActivity.java (5.90 MB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D