Commit 26a43747 authored by rajneesh's avatar rajneesh

Android comments added to xml and java file

parent 0bbabcf2
package com.example.wireless_x; /*! \file
\brief This is where the main code of the Wireless-X android application is written.
*/
package com.example.wireless_x;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationCompatSideChannelService; import androidx.core.app.NotificationCompatSideChannelService;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.SharedPreferences; import android.content.SharedPreferences;
...@@ -42,7 +43,6 @@ import android.widget.Space; ...@@ -42,7 +43,6 @@ import android.widget.Space;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import org.opencv.android.BaseLoaderCallback; import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.LoaderCallbackInterface;
...@@ -63,9 +63,15 @@ import java.io.PrintWriter; ...@@ -63,9 +63,15 @@ import java.io.PrintWriter;
import java.net.Socket; import java.net.Socket;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
import javax.security.auth.login.LoginException; import javax.security.auth.login.LoginException;
/*! \brief This is where the main code of the Wireless-X android application is written.
*
* The MainActivity consists of the methods that initialize all the required variables and fields
* when the app starts, methods which keep listening to the mouse and keyboard events such as a mouse
* click event or a key press event, screen touch events, methods which send the camera frames to
* the virtual camera device running on the laptop and so on.
*/
public class MainActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 { public class MainActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 {
private TextView textView; private TextView textView;
...@@ -94,7 +100,6 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -94,7 +100,6 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
private SharedPreferences preferences; private SharedPreferences preferences;
private String MY_PREFS_NAME="ip_store"; private String MY_PREFS_NAME="ip_store";
private Button wave_key, l_shift, r_shift, forward_slash_key, period_key, comma_key, semicolon_key, apostrophe_key, left_box_brac_key, capslock_key; private Button wave_key, l_shift, r_shift, forward_slash_key, period_key, comma_key, semicolon_key, apostrophe_key, left_box_brac_key, capslock_key;
private Button right_box_brac_key, back_slash_key, one_key, two_key, three_key, four_key, five_key, six_key, seven_key, eight_key, nine_key, zero_key, minus_key, equal_key; private Button right_box_brac_key, back_slash_key, one_key, two_key, three_key, four_key, five_key, six_key, seven_key, eight_key, nine_key, zero_key, minus_key, equal_key;
...@@ -110,10 +115,13 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -110,10 +115,13 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
private int mouse_space_height, mouse_space_width; private int mouse_space_height, mouse_space_width;
private int desktop_width=1, desktop_height=1; private int desktop_width=1, desktop_height=1;
private TextView title_wirelessx;
/*! \brief OpenCV Initialization
*
* Wireless-X works with OpenCV manager in an asynchronous manner, the onManagerConnected callback
* will be called in the UI thread once the initialization finishes.
*/
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override @Override
public void onManagerConnected(int status) { public void onManagerConnected(int status) {
...@@ -130,9 +138,11 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -130,9 +138,11 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
} }
}; };
/*! \brief Sets up the app layout and contains the methods to handle various touch-related events.
*
* Initializes all the app components and contains an listener for those events which can occur when
* the user interacts with the screen by single tap, double tap, scrolling or some gesture on the screen.
*/
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -174,29 +184,41 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -174,29 +184,41 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
minus_key=findViewById(R.id.minus_key); minus_key=findViewById(R.id.minus_key);
equal_key=findViewById(R.id.equal_key); equal_key=findViewById(R.id.equal_key);
capslock_key=findViewById(R.id.capslock_key); capslock_key=findViewById(R.id.capslock_key);
mouse_space=findViewById(R.id.mouse_space); mouse_space=findViewById(R.id.mouse_space);
/*! \brief Method which listens for screen-touch related events.
*
* When the user performs a double tap, it is translated to the double left-click on a physical mouse.
* Similarly, when the user performs a single tap, it's effect is same as a single click on any physical mouse.
* There is also an onScroll event which corresponds to the mouse scrolling event.
* This listener uses the GestureDetector class to handle such events.
*/
mouse_space.setOnTouchListener(new View.OnTouchListener() { mouse_space.setOnTouchListener(new View.OnTouchListener() {
private GestureDetector gestureDetector = new GestureDetector(getApplicationContext(), new GestureDetector.SimpleOnGestureListener() { private GestureDetector gestureDetector = new GestureDetector(getApplicationContext(), new GestureDetector.SimpleOnGestureListener() {
@Override @Override
/*! \brief Method to handle the double-tap event.
*
* When the user performs a double tap, it is translated to the double left-click on a physical mouse.
* This is done by starting two threads simultaneously, which product the effect of two single-clicks
* without much delay, thus corresponding to a double-click.
*/
public boolean onDoubleTap(MotionEvent e) { public boolean onDoubleTap(MotionEvent e) {
//Log.e("TEST", "onDoubleTap");
Thread thread1 = new Thread(new SendMouseClicks("LEFT \nCLICK")); Thread thread1 = new Thread(new SendMouseClicks("LEFT \nCLICK"));
thread1.start(); thread1.start();
Thread thread2 = new Thread(new SendMouseClicks("LEFT \nCLICK")); Thread thread2 = new Thread(new SendMouseClicks("LEFT \nCLICK"));
thread2.start(); thread2.start();
return super.onDoubleTap(e); return super.onDoubleTap(e);
} }
@Override @Override
/*! \brief Method to handle the single-tap event.
*
* When the user performs a single tap, it is translated to the single left-click on a physical mouse.
* This is done by starting a thread, which sends the event information to the server running on laptop
* and then the server acts accordingly.
*/
public boolean onSingleTapConfirmed(MotionEvent e) { public boolean onSingleTapConfirmed(MotionEvent e) {
//Log.e("TEST", "onSingleTapConfirmed"); //Log.e("TEST", "onSingleTapConfirmed");
...@@ -208,10 +230,12 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -208,10 +230,12 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
@Override @Override
/*! \brief Method to handle the mouse scrolling event.
*
* When the user performs a scroll event, the coordinates are transferred to the server, which
* translates those coordinates to the position with respect to the laptop screen.
*/
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
x=e2.getX()/mouse_space_width; x=e2.getX()/mouse_space_width;
y=e2.getY()/mouse_space_height; y=e2.getY()/mouse_space_height;
...@@ -223,10 +247,14 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -223,10 +247,14 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
return super.onScroll(e1, e2, distanceX, distanceY); return super.onScroll(e1, e2, distanceX, distanceY);
} }
}); });
@Override @Override
/*! \brief Method to handle the screen-touch event.
*
* This method calls the GestureDetector object to handle the screen-touch event which can be
* any one of the single-tap, double-tap or scroll events.
*/
public boolean onTouch(View view, MotionEvent motionEvent) { public boolean onTouch(View view, MotionEvent motionEvent) {
gestureDetector.onTouchEvent(motionEvent); gestureDetector.onTouchEvent(motionEvent);
...@@ -234,19 +262,8 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -234,19 +262,8 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
switch (motionEvent.getAction()) { switch (motionEvent.getAction()) {
case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_MOVE:
// x=motionEvent.getX()/mouse_space_width;
// y=motionEvent.getY()/mouse_space_height;
//
// if(x>=0 && x<=1 && y>=0 && y<=1)
// {
// Thread thread1 = new Thread(new SendMouseCoordinatesThread(x, y));
// thread1.start();
// }
//
break; break;
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
Log.i("TAG", "touched up"); Log.i("TAG", "touched up");
break; break;
...@@ -255,18 +272,20 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -255,18 +272,20 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
break; break;
} }
return true; return true;
} }
}); });
cameraRadioButton=findViewById(R.id.camera_radio); cameraRadioButton=findViewById(R.id.camera_radio);
mouseRadioButton=findViewById(R.id.mouse_radio); mouseRadioButton=findViewById(R.id.mouse_radio);
cameraSwitchRadioButton=findViewById(R.id.camera_switch_radio); cameraSwitchRadioButton=findViewById(R.id.camera_switch_radio);
} }
/*! \brief Displays the keys which correspond to special characters.
*
* When the shift-key is pressed on the keyboard in Wireless-X app, this method changes the layout
* of some keys to those keys which correspond to special characters such as brackets, '@', etc.
*/
public void shiftPress(View view) { public void shiftPress(View view) {
shift_enabled=!shift_enabled; shift_enabled=!shift_enabled;
...@@ -370,14 +389,14 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -370,14 +389,14 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
zero_key.getBackground().clearColorFilter(); zero_key.getBackground().clearColorFilter();
minus_key.getBackground().clearColorFilter(); minus_key.getBackground().clearColorFilter();
equal_key.getBackground().clearColorFilter(); equal_key.getBackground().clearColorFilter();
} }
} }
/*! \brief Describes the action to be performed when Test IP is clicked on the app.
*
* This method tries to set-up a connection with the IP address entered in the textfield to check
* if the IP address entered by the user is valid or not.
*/
public void test_IP(View view) { public void test_IP(View view) {
SERVER_IP = String.valueOf(ip_address_editText.getText()); SERVER_IP = String.valueOf(ip_address_editText.getText());
...@@ -396,7 +415,11 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -396,7 +415,11 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
} }
/*! \brief Tests whether the server's IP address is valid or not.
*
* This method tries to set-up a connection with the server's IP address and if the address is
* invalid then it displays the appropriate error message.
*/
class TestIP_Thread implements Runnable { class TestIP_Thread implements Runnable {
public void run() { public void run() {
...@@ -439,14 +462,10 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -439,14 +462,10 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
if (response.contains("Success")) if (response.contains("Success"))
{ {
enter_wireless_x_button.setVisibility(View.VISIBLE); enter_wireless_x_button.setVisibility(View.VISIBLE);
test_textView.setText("Connection Success!! "+getEmojiByUnicode(0x1F47D)+"\nEnter Wireless-X"); test_textView.setText("Connection Success!! "+getEmojiByUnicode(0x1F47D)+"\nEnter Wireless-X");
enter_wireless_x_button.setEnabled(true); enter_wireless_x_button.setEnabled(true);
enter_wireless_x_button.setClickable(true); enter_wireless_x_button.setClickable(true);
} }
else{ else{
test_textView.setText("Connection Failed!! "+getEmojiByUnicode(0x1F615)+ test_textView.setText("Connection Failed!! "+getEmojiByUnicode(0x1F615)+
...@@ -463,11 +482,16 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -463,11 +482,16 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
} }
} }
/*! \brief Returns the emoji corresponding to an unicode
*/
public String getEmojiByUnicode(int unicode){ public String getEmojiByUnicode(int unicode){
return new String(Character.toChars(unicode)); return new String(Character.toChars(unicode));
} }
/*! \brief Performs the action when the "Enter Wireless-X" button is clicked
*
* This method displays the mouse layout once the user clicks on "Enter Wireless-X" button.
*/
public void enter_wireless_x(View view){ public void enter_wireless_x(View view){
ip_address_linear_layout.setVisibility(View.GONE); ip_address_linear_layout.setVisibility(View.GONE);
mouse_layout.setVisibility(View.VISIBLE); mouse_layout.setVisibility(View.VISIBLE);
...@@ -479,15 +503,17 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -479,15 +503,17 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
mouse_space.getViewTreeObserver().removeOnGlobalLayoutListener(this); mouse_space.getViewTreeObserver().removeOnGlobalLayoutListener(this);
mouse_space_height = mouse_space.getHeight(); mouse_space_height = mouse_space.getHeight();
mouse_space_width=mouse_space.getWidth(); mouse_space_width=mouse_space.getWidth();
//textView.setText( String.valueOf(mouse_space.getHeight()) + "\t Width: "+ mouse_space.getWidth() );
} }
}); });
} }
@Override @Override
/*! \brief Performs the action when the back button is pressed
*
* It checks whether the back button is pressed twice within 2 seconds, if it is, then it exits the app.
* It also saves the IP address of the server so that the user doesn't need to re-enter it the next time he/she
* opens the app.
*/
public void onBackPressed() { public void onBackPressed() {
if (doubleBackToExitPressedOnce) { if (doubleBackToExitPressedOnce) {
super.onBackPressed(); super.onBackPressed();
...@@ -507,14 +533,13 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -507,14 +533,13 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
ip_address_editText.setText(SERVER_IP); ip_address_editText.setText(SERVER_IP);
mouse_enabled=false; mouse_enabled=false;
if (mOpenCvCameraView != null && cameraRadioButton.isChecked()) {
if (mOpenCvCameraView != null && cameraRadioButton.isChecked()){
mOpenCvCameraView.disableView(); mOpenCvCameraView.disableView();
mOpenCvCameraView.setVisibility(SurfaceView.INVISIBLE); mOpenCvCameraView.setVisibility(SurfaceView.INVISIBLE);
cameraRadioButton.setChecked(false); cameraRadioButton.setChecked(false);
camera_switch_radio_layout.setVisibility(View.GONE); camera_switch_radio_layout.setVisibility(View.GONE);
} }
else if(mOpenCvCameraView != null){ else if(mOpenCvCameraView != null) {
mOpenCvCameraView.disableView(); mOpenCvCameraView.disableView();
} }
...@@ -530,14 +555,15 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -530,14 +555,15 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
}, 2000); }, 2000);
} }
/*! \brief Enables or disables the visibility of Mouse UI
*
*/
public void mouse_on_off(View view) { public void mouse_on_off(View view) {
if(mouse_enabled)
if(mouse_enabled) { {
textView.setText(R.string.wireless_x_mode_keyboard); textView.setText(R.string.wireless_x_mode_keyboard);
mouse_layout.setVisibility(View.GONE); mouse_layout.setVisibility(View.GONE);
keyboard_layout.setVisibility(View.VISIBLE); keyboard_layout.setVisibility(View.VISIBLE);
} }
else else
{ {
...@@ -550,9 +576,9 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -550,9 +576,9 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
mouse_enabled=!mouse_enabled; mouse_enabled=!mouse_enabled;
} }
/*! \brief Enables or disables the camera layout
*
*/
public void camera_on_off(View view) { public void camera_on_off(View view) {
if(camera_enabled) { if(camera_enabled) {
...@@ -571,9 +597,11 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -571,9 +597,11 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
camera_enabled=!camera_enabled; camera_enabled=!camera_enabled;
} }
/*! \brief Implementation of the camera switch button functionality
*
* This method changes the main camera to the front or rear camera of the smartphone depending
* upon what the user has selected.
*/
public void camera_switch(View view){ public void camera_switch(View view){
if(mOpenCvCameraView != null) if(mOpenCvCameraView != null)
...@@ -595,12 +623,11 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -595,12 +623,11 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
mOpenCvCameraView.enableView(); mOpenCvCameraView.enableView();
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE); mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
} }
} }
/*! \brief Checks whether all the required permissions are granted by the user or not
*
*/
private boolean allPermissionsGranted(){ private boolean allPermissionsGranted(){
for(String permission : REQUIRED_PERMISSIONS){ for(String permission : REQUIRED_PERMISSIONS){
...@@ -613,6 +640,11 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -613,6 +640,11 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
@Override @Override
/*! \brief Sets up the camera view if all the permissions are granted
*
* This method initializes all the camera parameters subject to the condition that all the required
* permissions are granted by the user. If this is not the case, then an error message is displayed.
*/
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == REQUEST_CODE_PERMISSIONS) { if (requestCode == REQUEST_CODE_PERMISSIONS) {
...@@ -643,6 +675,11 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -643,6 +675,11 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
@Override @Override
/*! \brief Handles the onResume state of the app
*
* If the app reaches an "onResume" state in the lifecycle, then this method checks if all the permissions
* are granted or not, if they are, then it sets up camera parameters otherwise it requests the permissions.
*/
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
...@@ -671,12 +708,16 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -671,12 +708,16 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
String ip = preferences.getString("ip_addr", "");//"No name defined" is the default value. String ip = preferences.getString("ip_addr", "");//"No name defined" is the default value.
ip_address_editText.setText(ip); ip_address_editText.setText(ip);
SERVER_IP=ip; SERVER_IP=ip;
} }
@Override @Override
/*! \brief Handles the onPause state of the app
*
* If the app reaches the "onPause" state in the lifecycle, then this method disables the camera
* view. It also saves the server's IP address so that the next time the app is opened, the user
* doesn't require to enter the same address again.
*/
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
if (mOpenCvCameraView != null) if (mOpenCvCameraView != null)
...@@ -689,31 +730,40 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -689,31 +730,40 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
} }
/*! \brief Handles the onDestroy state of the app
*
* If the app reaches the "onDestroy" state in the lifecycle, then this method disables the camera
* view.
*/
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
if (mOpenCvCameraView != null) if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView(); mOpenCvCameraView.disableView();
} }
@Override @Override
/// @cond DO_NOT_DOCUMENT
public void onCameraViewStarted(int width, int height) { public void onCameraViewStarted(int width, int height) {
// mRGBA= new Mat(height, width, CvType.CV_8UC4); // mRGBA= new Mat(height, width, CvType.CV_8UC4);
} }
/// @endcond
@Override @Override
/// @cond DO_NOT_DOCUMENT
public void onCameraViewStopped() { public void onCameraViewStopped() {
// mRGBA.release(); // mRGBA.release();
} }
/// @endcond
Socket soc; Socket soc;
PrintWriter outToServer; PrintWriter outToServer;
Mat mat_t, mat; Mat mat_t, mat;
@Override @Override
/*! \brief Transmits the camera frames to the server
*
* On receiving a camera frame, this method encodes that frame and transmits it to the server.
*/
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) { public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
mat= inputFrame.rgba(); mat= inputFrame.rgba();
...@@ -725,7 +775,6 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -725,7 +775,6 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
try { try {
soc = new Socket(SERVER_IP,9998); soc = new Socket(SERVER_IP,9998);
outToServer = new PrintWriter(new OutputStreamWriter(soc.getOutputStream())); outToServer = new PrintWriter(new OutputStreamWriter(soc.getOutputStream()));
//here it sends the data
outToServer.print(yourString + "#$#$#$"); outToServer.print(yourString + "#$#$#$");
outToServer.flush(); outToServer.flush();
soc.close(); soc.close();
...@@ -738,15 +787,18 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -738,15 +787,18 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
} }
/*! \brief Sets up the layout as defined in the "activity_main.xml" file
*
*/
public void layout_switch(View view) { public void layout_switch(View view) {
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
} }
/*! \brief Sends the mouse coordinates to the server
*
* This method encodes the mouse coordinates such that the server is able to interpret that
* the coordinates are that of mouse.
*/
class SendMouseCoordinatesThread implements Runnable { class SendMouseCoordinatesThread implements Runnable {
float x = 0; float x = 0;
...@@ -777,19 +829,20 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -777,19 +829,20 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
} }
/*! \brief Sends the mouse clicks
*
*/
public void mouse_click(View view) { public void mouse_click(View view) {
String Key = (String) ((Button) view).getText(); String Key = (String) ((Button) view).getText();
Thread thread1 = new Thread(new SendMouseClicks(Key)); Thread thread1 = new Thread(new SendMouseClicks(Key));
thread1.start(); thread1.start();
} }
/*! \brief Used to send the mouse click events to the server
*
* This class implements the runnable interface, which encodes the mouse click events and sends it
* to the server.
*/
class SendMouseClicks implements Runnable { class SendMouseClicks implements Runnable {
String click_message=""; String click_message="";
...@@ -818,7 +871,10 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -818,7 +871,10 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
} }
/*! \brief Handles the key press event
*
* This method handles the key press event and also handles the scroll button available on mouse layout.
*/
public void keyPress(View view) { public void keyPress(View view) {
String Key = (String) ((Button) view).getText(); String Key = (String) ((Button) view).getText();
...@@ -880,10 +936,13 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -880,10 +936,13 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
} }
}; };
}); });
} }
/*! \brief Used to send the keyboard events to the server
*
* This class implements the runnable interface, which encodes the keyboard events and sends it
* to the server.
*/
class SendKeyboardPressesThread implements Runnable { class SendKeyboardPressesThread implements Runnable {
String key, device; String key, device;
...@@ -921,6 +980,4 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB ...@@ -921,6 +980,4 @@ public class MainActivity extends AppCompatActivity implements CameraBridgeViewB
} }
} }
} }
} }
\ No newline at end of file
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
<!-- First screen after starting app -->
<!-- Testing server connection layout-->
<LinearLayout <LinearLayout
android:id="@+id/ip_address_linear_layout" android:id="@+id/ip_address_linear_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -114,6 +117,7 @@ ...@@ -114,6 +117,7 @@
android:layout_weight="0.1"/> android:layout_weight="0.1"/>
</LinearLayout> </LinearLayout>
</LinearLayout>
...@@ -121,10 +125,7 @@ ...@@ -121,10 +125,7 @@
</LinearLayout> <!-- Upper Bar which gives the mode in which wirelessX is and also radio buttons as switches-->
<!-- Upper Bar-->
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -238,10 +239,13 @@ ...@@ -238,10 +239,13 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<!-- Green border of 2dp--> <!-- Green border of 2dp-->
<LinearLayout <LinearLayout
...@@ -254,7 +258,12 @@ ...@@ -254,7 +258,12 @@
<!-- Mouse Layout will go in this-->
<!-- Mouse Layout Interface which includes buttons and track pad area-->
<!-- android:visibility="gone" --> <!-- android:visibility="gone" -->
<LinearLayout <LinearLayout
...@@ -389,13 +398,16 @@ ...@@ -389,13 +398,16 @@
</LinearLayout> </LinearLayout>
</LinearLayout>
</LinearLayout>
<!-- Keyboard Layout will go in this-->
<!-- Keyboard Layout Interface which includes all the keys UI elements related to keyboard-->
<LinearLayout <LinearLayout
android:background="#1A1A1A" android:background="#1A1A1A"
...@@ -1248,13 +1260,8 @@ ...@@ -1248,13 +1260,8 @@
android:text="→" android:text="→"
android:onClick="keyPress"/> android:onClick="keyPress"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment