Skip to content

Commit

Permalink
first release
Browse files Browse the repository at this point in the history
  • Loading branch information
mdminhazulhaque committed Aug 26, 2014
0 parents commit 4586e18
Show file tree
Hide file tree
Showing 16 changed files with 382 additions and 0 deletions.
49 changes: 49 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!--
Remote Control Application
File: AndroidManifest.xml
Copyright (c) 2014 Md. Minhazul Haque <mdminhazulhaque@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.minhazulhaque.remotecontrol"
android:versionCode="1"
android:versionName="1.0" >

<uses-permission android:name="android.permission.INTERNET" />

<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="19" />

<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Main"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Remote Control
==============

A socket based Android application to control computer cursor.

## TODO ##
* Add scroll gesture
* Add sticky click
Binary file added bin/RemoteControl.apk
Binary file not shown.
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target=android-19
Binary file added res/drawable-hdpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xhdpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxhdpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions res/layout/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="vertical"
tools:context=".Main" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<TextView
android:id="@+id/server"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/server"
android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
android:id="@+id/hostaddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:inputType="text"
android:text="@string/defaulthost" />

<Button
android:id="@+id/connect"
style="@style/AppBaseTheme"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="connect"
android:text="@string/connect" />

<Button
android:id="@+id/menu"
style="@style/AppBaseTheme"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="click"
android:text="@string/menu" />
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<View
android:id="@+id/touchpad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#ffe8e8e8"
android:onClick="click" />
</LinearLayout>

</LinearLayout>
11 changes: 11 additions & 0 deletions res/values-v11/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<resources>

<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>

</resources>
12 changes: 12 additions & 0 deletions res/values-v14/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<resources>

<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>

</resources>
9 changes: 9 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Remote Control</string>
<string name="connect">Connect</string>
<string name="disconnect">Disconnect</string>
<string name="defaulthost">192.168.0.101</string>
<string name="server">Server</string>
<string name="menu">Menu</string>
</resources>
6 changes: 6 additions & 0 deletions res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
220 changes: 220 additions & 0 deletions src/com/minhazulhaque/remotecontrol/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
/**
Remote Control Application
File: Main.java
Copyright (c) 2014 Md. Minhazul Haque <mdminhazulhaque@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.minhazulhaque.remotecontrol;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Calendar;

import android.os.Bundle;
import android.os.StrictMode;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
//import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.EditText;

public class Main extends Activity {

Socket socket = null;
boolean connected = false;
float mPosX;
float mPosY;

float mLastTouchX;
float mLastTouchY;

@Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);

super.onCreate(savedInstanceState);
setContentView(R.layout.main);

View touchpad = (View) findViewById(R.id.touchpad);
touchpad.setOnTouchListener(new OnTouchListener() {

private static final int MAX_CLICK_DURATION = 200;
private long startClickTime;
private boolean twoFingers = false;

@Override
public boolean onTouch(View view, MotionEvent event) {

if (event.getPointerCount() == 2) {
twoFingers = true;
}

final int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN: {

startClickTime = Calendar.getInstance().getTimeInMillis();

final float x = event.getX();
final float y = event.getY();

mLastTouchX = x;
mLastTouchY = y;
break;
}

case MotionEvent.ACTION_MOVE: {
final float x = event.getX();
final float y = event.getY();

final float dx = x - mLastTouchX;
final float dy = y - mLastTouchY;

mPosX += dx;
mPosY += dy;
mLastTouchX = x;
mLastTouchY = y;

sendData(dx + "," + dy);

break;
}

case MotionEvent.ACTION_UP: {
long clickDuration = (Calendar.getInstance().getTimeInMillis() - startClickTime);
if (clickDuration < MAX_CLICK_DURATION) {
if (twoFingers) {
sendData("menu");
twoFingers = false;
} else {
sendData("click");
}
}
}
break;
}
return true;
}
});

EditText server = (EditText) findViewById(R.id.hostaddress);
server.setSelection(server.getText().length());

} // onCreate

public void onPause() {
super.onPause();
try {
if (connected) {
sendData("disconnect");
socket.close();
}
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}

finish();
}

public void click(View view) {
sendData(this.getResources().getResourceEntryName(view.getId()));
}

private void sendData(String message) {

if (connected) {
OutputStream out;
try {
String eMessage = message + "|";
out = socket.getOutputStream();
out.write(eMessage.getBytes());
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}

public void connect(View view) {

if (connected) {
sendData("disconnect");
try {
socket.close();
connected = false;
Button connectButton = (Button) findViewById(R.id.connect);
connectButton.setText(R.string.connect);
EditText serverAddress = (EditText) findViewById(R.id.hostaddress);
serverAddress.setEnabled(true);
} catch (IOException e) {
e.printStackTrace();
}
} else {

EditText serverAddress = (EditText) findViewById(R.id.hostaddress);
String hostAddress = serverAddress.getText().toString();

try {
socket = new Socket();
socket.connect(
(new InetSocketAddress(InetAddress
.getByName(hostAddress), 7777)), 1000);

} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

if (socket.isConnected()) {
connected = true;
sendData("connect");
Button connectButton = (Button) findViewById(R.id.connect);
connectButton.setText(R.string.disconnect);
serverAddress.setEnabled(false);

showAlertDialog("Success", "Connected to server");
} else {
showAlertDialog("Fail", "Could not connect to server");
}
}
}

private void showAlertDialog(String title, String message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(message).setCancelable(false).setTitle(title)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
}
}

0 comments on commit 4586e18

Please sign in to comment.