├── README.md
├── src
├── main
│ ├── res
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-hdpi
│ │ │ └── ic_action_cast.png
│ │ ├── drawable-mdpi
│ │ │ └── ic_action_cast.png
│ │ ├── drawable-xhdpi
│ │ │ └── ic_action_cast.png
│ │ ├── drawable-xxhdpi
│ │ │ └── ic_action_cast.png
│ │ ├── values
│ │ │ ├── styles.xml
│ │ │ ├── dimens.xml
│ │ │ └── strings.xml
│ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ ├── menu
│ │ │ └── menu_main.xml
│ │ └── layout
│ │ │ └── activity_main.xml
│ ├── java
│ │ └── in
│ │ │ └── codesmith
│ │ │ └── remotedroid
│ │ │ ├── Constants.java
│ │ │ └── MainActivity.java
│ └── AndroidManifest.xml
└── androidTest
│ └── java
│ └── in
│ └── codesmith
│ └── remotedroid
│ └── ApplicationTest.java
├── .gitignore
├── proguard-rules.pro
└── app.iml
/README.md:
--------------------------------------------------------------------------------
1 | # RemoteDroid
2 | Sample code for an android remote control for VLC media player.
3 |
--------------------------------------------------------------------------------
/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourabh86/RemoteDroid/HEAD/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourabh86/RemoteDroid/HEAD/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourabh86/RemoteDroid/HEAD/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourabh86/RemoteDroid/HEAD/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/drawable-hdpi/ic_action_cast.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourabh86/RemoteDroid/HEAD/src/main/res/drawable-hdpi/ic_action_cast.png
--------------------------------------------------------------------------------
/src/main/res/drawable-mdpi/ic_action_cast.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourabh86/RemoteDroid/HEAD/src/main/res/drawable-mdpi/ic_action_cast.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xhdpi/ic_action_cast.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourabh86/RemoteDroid/HEAD/src/main/res/drawable-xhdpi/ic_action_cast.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xxhdpi/ic_action_cast.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sourabh86/RemoteDroid/HEAD/src/main/res/drawable-xxhdpi/ic_action_cast.png
--------------------------------------------------------------------------------
/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RemoteDroid
3 |
4 | Hello world!
5 | Settings
6 | Connect
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Log Files
26 | *.log
27 |
--------------------------------------------------------------------------------
/src/androidTest/java/in/codesmith/remotedroid/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package in.codesmith.remotedroid;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/src/main/java/in/codesmith/remotedroid/Constants.java:
--------------------------------------------------------------------------------
1 | package in.codesmith.remotedroid;
2 |
3 | /**
4 | * Created by Sourabh Soni on 07-03-2015.
5 | */
6 | public class Constants {
7 | public static final String SERVER_IP = "192.168.1.104";
8 | public static final int SERVER_PORT = 8998;
9 | public static final String PLAY="play";
10 | public static final String NEXT="next";
11 | public static final String PREVIOUS="previous";
12 | public static final String MOUSE_LEFT_CLICK="left_click";
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\Sourabh Soni\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
13 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
15 |
16 |
23 |
24 |
32 |
33 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/src/main/java/in/codesmith/remotedroid/MainActivity.java:
--------------------------------------------------------------------------------
1 | package in.codesmith.remotedroid;
2 |
3 | import android.content.Context;
4 | import android.os.AsyncTask;
5 | import android.support.v7.app.ActionBarActivity;
6 | import android.os.Bundle;
7 | import android.util.Log;
8 | import android.view.Menu;
9 | import android.view.MenuItem;
10 | import android.view.MotionEvent;
11 | import android.view.View;
12 | import android.widget.Button;
13 | import android.widget.TextView;
14 | import android.widget.Toast;
15 |
16 | import java.io.BufferedWriter;
17 | import java.io.IOException;
18 | import java.io.OutputStreamWriter;
19 | import java.io.PrintWriter;
20 | import java.net.InetAddress;
21 | import java.net.Socket;
22 |
23 | public class MainActivity extends ActionBarActivity implements View.OnClickListener {
24 |
25 | Context context;
26 | Button playPauseButton;
27 | Button nextButton;
28 | Button previousButton;
29 | TextView mousePad;
30 |
31 | private boolean isConnected=false;
32 | private boolean mouseMoved=false;
33 | private Socket socket;
34 | private PrintWriter out;
35 |
36 | private float initX =0;
37 | private float initY =0;
38 | private float disX =0;
39 | private float disY =0;
40 |
41 | @Override
42 | protected void onCreate(Bundle savedInstanceState) {
43 | super.onCreate(savedInstanceState);
44 | setContentView(R.layout.activity_main);
45 |
46 | context = this; //save the context to show Toast messages
47 |
48 | //Get references of all buttons
49 | playPauseButton = (Button)findViewById(R.id.playPauseButton);
50 | nextButton = (Button)findViewById(R.id.nextButton);
51 | previousButton = (Button)findViewById(R.id.previousButton);
52 |
53 | //this activity extends View.OnClickListener, set this as onClickListener
54 | //for all buttons
55 | playPauseButton.setOnClickListener(this);
56 | nextButton.setOnClickListener(this);
57 | previousButton.setOnClickListener(this);
58 |
59 | //Get reference to the TextView acting as mousepad
60 | mousePad = (TextView)findViewById(R.id.mousePad);
61 |
62 | //capture finger taps and movement on the textview
63 | mousePad.setOnTouchListener(new View.OnTouchListener() {
64 | @Override
65 | public boolean onTouch(View v, MotionEvent event) {
66 | if(isConnected && out!=null){
67 | switch(event.getAction()){
68 | case MotionEvent.ACTION_DOWN:
69 | //save X and Y positions when user touches the TextView
70 | initX =event.getX();
71 | initY =event.getY();
72 | mouseMoved=false;
73 | break;
74 | case MotionEvent.ACTION_MOVE:
75 | disX = event.getX()- initX; //Mouse movement in x direction
76 | disY = event.getY()- initY; //Mouse movement in y direction
77 | /*set init to new position so that continuous mouse movement
78 | is captured*/
79 | initX = event.getX();
80 | initY = event.getY();
81 | if(disX !=0|| disY !=0){
82 | out.println(disX +","+ disY); //send mouse movement to server
83 | }
84 | mouseMoved=true;
85 | break;
86 | case MotionEvent.ACTION_UP:
87 | //consider a tap only if usr did not move mouse after ACTION_DOWN
88 | if(!mouseMoved){
89 | out.println(Constants.MOUSE_LEFT_CLICK);
90 | }
91 | }
92 | }
93 | return true;
94 | }
95 | });
96 | }
97 |
98 |
99 | @Override
100 | public boolean onCreateOptionsMenu(Menu menu) {
101 | // Inflate the menu; this adds items to the action bar if it is present.
102 | getMenuInflater().inflate(R.menu.menu_main, menu);
103 | return true;
104 | }
105 |
106 | @Override
107 | public boolean onOptionsItemSelected(MenuItem item) {
108 | // Handle action bar item clicks here. The action bar will
109 | // automatically handle clicks on the Home/Up button, so long
110 | // as you specify a parent activity in AndroidManifest.xml.
111 | int id = item.getItemId();
112 |
113 | //noinspection SimplifiableIfStatement
114 | if(id == R.id.action_connect) {
115 | ConnectPhoneTask connectPhoneTask = new ConnectPhoneTask();
116 | connectPhoneTask.execute(Constants.SERVER_IP); //try to connect to server in another thread
117 | return true;
118 | }
119 |
120 | return super.onOptionsItemSelected(item);
121 | }
122 |
123 | //OnClick method is called when any of the buttons are pressed
124 | @Override
125 | public void onClick(View v) {
126 | switch (v.getId()) {
127 | case R.id.playPauseButton:
128 | if (isConnected && out!=null) {
129 | out.println(Constants.PLAY);//send "play" to server
130 | }
131 | break;
132 | case R.id.nextButton:
133 | if (isConnected && out!=null) {
134 | out.println(Constants.NEXT); //send "next" to server
135 | }
136 | break;
137 | case R.id.previousButton:
138 | if (isConnected && out!=null) {
139 | out.println(Constants.PREVIOUS); //send "previous" to server
140 | }
141 | break;
142 | }
143 |
144 | }
145 |
146 | @Override
147 | public void onDestroy()
148 | {
149 | super.onDestroy();
150 | if(isConnected && out!=null) {
151 | try {
152 | out.println("exit"); //tell server to exit
153 | socket.close(); //close socket
154 | } catch (IOException e) {
155 | Log.e("remotedroid", "Error in closing socket", e);
156 | }
157 | }
158 | }
159 |
160 | public class ConnectPhoneTask extends AsyncTask {
161 |
162 | @Override
163 | protected Boolean doInBackground(String... params) {
164 | boolean result = true;
165 | try {
166 | InetAddress serverAddr = InetAddress.getByName(params[0]);
167 | socket = new Socket(serverAddr, Constants.SERVER_PORT);//Open socket on server IP and port
168 | } catch (IOException e) {
169 | Log.e("remotedroid", "Error while connecting", e);
170 | result = false;
171 | }
172 | return result;
173 | }
174 |
175 | @Override
176 | protected void onPostExecute(Boolean result)
177 | {
178 | isConnected = result;
179 | Toast.makeText(context,isConnected?"Connected to server!":"Error while connecting",Toast.LENGTH_LONG).show();
180 | try {
181 | if(isConnected) {
182 | out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket
183 | .getOutputStream())), true); //create output stream to send data to server
184 | }
185 | }catch (IOException e){
186 | Log.e("remotedroid", "Error while creating OutWriter", e);
187 | Toast.makeText(context,"Error while connecting",Toast.LENGTH_LONG).show();
188 | }
189 | }
190 | }
191 | }
--------------------------------------------------------------------------------