]> rtime.felk.cvut.cz Git - orte.git/commitdiff
ROBOT_DEMO: make use of WifiLock and modify WakeLock
authorMartin Vajnar <martin.vajnar@gmail.com>
Sun, 25 Aug 2013 17:58:34 +0000 (19:58 +0200)
committerPavel Pisa <pisa@cmp.felk.cvut.cz>
Mon, 23 Sep 2013 09:06:28 +0000 (11:06 +0200)
Modify WakeLock, so that when acquired on activity start, it wakes up
the phone if then screen was already dimmed or switched off.

Add WifiLock to improve network latency and overall responsiveness.
This solves issues with slow and unreliable Publisher-Subscriber
communication.

Add margins to the CTU logo.

orte/Robot_Demo/res/layout/hokuyo_view.xml
orte/Robot_Demo/src/org/ocera/orte/demo/MainActivity.java

index 40f1bc2908ff57257bc7c747309b3813aa71b334..6d6938f4986abc4bec4d9e1051afaf55a9b4981a 100644 (file)
@@ -7,6 +7,8 @@
         android:id="@+id/hokuyo_view_bg"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:layout_marginTop="5dp"
+        android:layout_marginRight="5dp"
         android:layout_alignParentRight="true"
         android:layout_alignParentTop="true"
         android:adjustViewBounds="true"
index d50b0fe9858edc634afd45b3f386d849f67211d6..76320d893994a3ccb27b4b436f5fdd2f2e371193 100644 (file)
@@ -11,6 +11,8 @@ import android.hardware.Sensor;
 import android.hardware.SensorEvent;
 import android.hardware.SensorEventListener;
 import android.hardware.SensorManager;
+import android.net.wifi.WifiManager;
+import android.net.wifi.WifiManager.WifiLock;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
@@ -64,7 +66,9 @@ public class MainActivity extends Activity {
     private Sensor mGravity = null;
     private SensorEventListener accel = null;
     private PowerManager mPowerManager = null;
+    private WifiManager mWifiManager = null;
     private WakeLock mWakeLock = null;
+    private WifiLock mWifiLock = null;
     private DomainApp appDomain = null;
     private HokuyoView hokuyo_view = null;
     private MenuItem speed_publ_item = null;
@@ -80,6 +84,7 @@ public class MainActivity extends Activity {
         super.onResume();
 
         mWakeLock.acquire();
+        mWifiLock.acquire();
     }
 
     @Override
@@ -114,6 +119,7 @@ public class MainActivity extends Activity {
         }
         
         mWakeLock.release();
+        mWifiLock.release();
     }
     
     @Override
@@ -139,6 +145,7 @@ public class MainActivity extends Activity {
         }
     }
        
+       @SuppressWarnings("deprecation")
        @Override
     public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
@@ -164,7 +171,14 @@ public class MainActivity extends Activity {
         mGravity = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
         
         mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
-        mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, getClass().getName());
+        mWakeLock = mPowerManager.newWakeLock(
+                       PowerManager.SCREEN_BRIGHT_WAKE_LOCK
+                       | PowerManager.ACQUIRE_CAUSES_WAKEUP
+                       | PowerManager.ON_AFTER_RELEASE,
+                       getClass().getName());
+        
+        mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
+        mWifiLock = mWifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, getClass().getName());
         
         hokuyo_view = (HokuyoView) findViewById(R.id.hokuyo_view);