From 8333874d64320d30533311c3080fe9b73b07394c Mon Sep 17 00:00:00 2001 From: "Lilli Szafranski (Jaguar - Land Rover)" Date: Wed, 18 Nov 2015 15:56:42 -0800 Subject: [PATCH] [52229] Some whitespace changes and deleting of unused code. Changed the magic string fob signal service names to use constants. Moved isUnlocked boolean to VehicleNode. --- .../vehicleentry/LockActivityFragment.java | 14 +++--- .../auto/remote/vehicleentry/RviService.java | 45 +++++-------------- .../auto/remote/vehicleentry/ServerNode.java | 3 -- .../auto/remote/vehicleentry/VehicleNode.java | 17 +++++-- 4 files changed, 33 insertions(+), 46 deletions(-) diff --git a/app/src/main/java/com/jaguarlandrover/auto/remote/vehicleentry/LockActivityFragment.java b/app/src/main/java/com/jaguarlandrover/auto/remote/vehicleentry/LockActivityFragment.java index d3f183f..ca85950 100644 --- a/app/src/main/java/com/jaguarlandrover/auto/remote/vehicleentry/LockActivityFragment.java +++ b/app/src/main/java/com/jaguarlandrover/auto/remote/vehicleentry/LockActivityFragment.java @@ -173,32 +173,32 @@ public void onClick(View v) { case R.id.lock: Log.i(TAG, "LockBtn"); ed.putBoolean(LOCKED_LBL, true); - buttonListener.onButtonCommand("lock"); + buttonListener.onButtonCommand(VehicleNode.FOB_SIGNAL_LOCK); break; case R.id.unlock: Log.i(TAG, "UnlockBtn"); ed.putBoolean(LOCKED_LBL, false); - buttonListener.onButtonCommand("unlock"); + buttonListener.onButtonCommand(VehicleNode.FOB_SIGNAL_UNLOCK); break; case R.id.trunk: Log.i(TAG, "TrunkBtn"); ed.putBoolean("Gruka", false); - buttonListener.onButtonCommand("trunk"); + buttonListener.onButtonCommand(VehicleNode.FOB_SIGNAL_TRUNK); break; case R.id.find: Log.i(TAG, "FindBtn"); ed.putBoolean("77", false); - buttonListener.onButtonCommand("lights"); + buttonListener.onButtonCommand(VehicleNode.FOB_SIGNAL_LIGHTS); break; case R.id.start: Log.i(TAG, "StartBtn"); ed.putBoolean(STOPPED_LBL, true); - buttonListener.onButtonCommand("start"); + buttonListener.onButtonCommand(VehicleNode.FOB_SIGNAL_START); break; case R.id.stop: Log.i(TAG, "StopBtn"); ed.putBoolean(STOPPED_LBL, false); - buttonListener.onButtonCommand("stop"); + buttonListener.onButtonCommand(VehicleNode.FOB_SIGNAL_STOP); break; case R.id.share: Log.i(TAG, "ShareBtn"); @@ -216,7 +216,7 @@ public void onClick(View v) { // isPanic = false; // // } -// buttonListener.onButtonCommand("panic"); +// buttonListener.onButtonCommand(VehicleNode.FOB_SIGNAL_PANIC); // Log.i(TAG, "PanicBtn swap 1 "); // Handler handler = new Handler(Looper.getMainLooper()); // handler.postDelayed(new Runnable() diff --git a/app/src/main/java/com/jaguarlandrover/auto/remote/vehicleentry/RviService.java b/app/src/main/java/com/jaguarlandrover/auto/remote/vehicleentry/RviService.java index d6cbd63..a5f671d 100644 --- a/app/src/main/java/com/jaguarlandrover/auto/remote/vehicleentry/RviService.java +++ b/app/src/main/java/com/jaguarlandrover/auto/remote/vehicleentry/RviService.java @@ -32,8 +32,6 @@ public class RviService extends Service { private static final String TAG = "RVI:RVIService"; - private static boolean unlocked = false; - private SharedPreferences prefs; public RviService() { @@ -100,12 +98,17 @@ private void connectServerNode() { ServerNode.connect(); } + public void connectVehicleNode(String deviceAddress) { + VehicleNode.setDeviceAddress(deviceAddress); + VehicleNode.connect(); + } + // This is the object that receives interactions from clients. See // RemoteService for a more complete example. private final IBinder mBinder = new RviBinder(); @Override - public int onStartCommand (Intent intent, int flags, int startId) { + public int onStartCommand(Intent intent, int flags, int startId) { Log.d(TAG, "onStartCommand"); connectServerNode(); starting(intent); @@ -141,18 +144,20 @@ public void onError(Throwable e) { @Override public void onNext(final RangeObject ro) { - final double unlockDistance = Double.parseDouble(prefs.getString("pref_auto_unlock_dist", "1")); + final boolean connected = VehicleNode.isConnected(); + final boolean connecting = VehicleNode.isConnecting(); + final boolean unlocked = VehicleNode.isUnlocked(); + + final double unlockDistance = Double.parseDouble(prefs.getString("pref_auto_unlock_dist", "1")); final double connectDistance = Double.parseDouble(prefs.getString("pref_auto_conn_dist", "3")); - double grayArea = Double.parseDouble(prefs.getString("pref_auto_lock_unlock_cutoff_gray_area", "0.4")); + double grayArea = Double.parseDouble(prefs.getString("pref_auto_lock_unlock_cutoff_gray_area", "0.4")); if (grayArea > 1.0 || grayArea < 0.0) { Log.d(TAG, "Invalid grayArea: " + grayArea + "! Resetting to default value of 0.4"); grayArea = 0.4; } final double weightedCutoff = ((1.0 - grayArea) / 2.0); - final boolean connected = VehicleNode.isConnected(); - final boolean connecting = VehicleNode.isConnecting(); Log.d(TAG, "distance:" + ro.distance + ", weightedDistance:" + ro.weightedDistance + ", unlockDistance:" + unlockDistance + ", connectDistance:" + connectDistance); Log.d(TAG, "connected:" + connected + ", connecting:" + connecting + ", unlocked:" + unlocked); @@ -176,18 +181,12 @@ public void onNext(final RangeObject ro) { } if (connected && (!unlocked) && ro.weightedDistance <= weightedCutoff) { - unlocked = true; - - //RviService.triggerFobSignal("unlock", RviService.this); VehicleNode.sendFobSignal(VehicleNode.FOB_SIGNAL_UNLOCK); sendNotification(RviService.this, getResources().getString(R.string.not_auto_unlock)); return; } if (connected && unlocked && ro.weightedDistance >= (1.0 - weightedCutoff)) { - unlocked = false; - - //RviService.triggerFobSignal("lock", RviService.this); VehicleNode.sendFobSignal(VehicleNode.FOB_SIGNAL_LOCK); sendNotification(RviService.this, getResources().getString(R.string.not_auto_lock)); return; @@ -212,15 +211,9 @@ public void onNext(final RangeObject ro) { connectVehicleNode(ro.addr); } - } }; - public void connectVehicleNode(String deviceAddress) { - VehicleNode.setDeviceAddress(deviceAddress); - VehicleNode.connect(); - } - static void sendNotification(Context ctx, String action, String... extras) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); @@ -245,18 +238,4 @@ static void sendNotification(Context ctx, String action, String... extras) { builder.setContentIntent(contentIntent); nm.notify(0, builder.build()); } - -// public static void triggerFobSignal(String service, Context ctx) { -// Log.i(TAG, "Invoking service : " + service + " the car, conn = " + btSender); -// -// UserCredentials userCredentials = ServerNode.getUserCredentials(); -// -// HashMap params = new HashMap(4); -// params.put("username", userCredentials.getUserName()); -// params.put("vehicleVIN", userCredentials.getVehicleVin()); -// params.put("latitude", latit); -// params.put("longitude", longi); -// -// VehicleNode.sendFobSignal(service, params); -// } } diff --git a/app/src/main/java/com/jaguarlandrover/auto/remote/vehicleentry/ServerNode.java b/app/src/main/java/com/jaguarlandrover/auto/remote/vehicleentry/ServerNode.java index 3415ebb..095a21d 100644 --- a/app/src/main/java/com/jaguarlandrover/auto/remote/vehicleentry/ServerNode.java +++ b/app/src/main/java/com/jaguarlandrover/auto/remote/vehicleentry/ServerNode.java @@ -21,12 +21,9 @@ import android.util.Base64; import android.util.Log; import com.google.gson.Gson; -import com.google.gson.JsonElement; import com.google.gson.reflect.TypeToken; import com.jaguarlandrover.rvi.RVINode; import com.jaguarlandrover.rvi.ServiceBundle; -import org.json.JSONArray; -import org.json.JSONObject; import java.lang.reflect.Type; import java.util.*; diff --git a/app/src/main/java/com/jaguarlandrover/auto/remote/vehicleentry/VehicleNode.java b/app/src/main/java/com/jaguarlandrover/auto/remote/vehicleentry/VehicleNode.java index 2c0f66e..58afa26 100644 --- a/app/src/main/java/com/jaguarlandrover/auto/remote/vehicleentry/VehicleNode.java +++ b/app/src/main/java/com/jaguarlandrover/auto/remote/vehicleentry/VehicleNode.java @@ -27,9 +27,11 @@ public class VehicleNode { private final static String TAG = "UnlockDemo:VehicleNode"; - /* Static objects */ + /* Static variables */ private static Context applicationContext = UnlockApplication.getContext(); + private static boolean isUnlocked; + private static SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(applicationContext); private static RVINode rviNode = new RVINode(null); @@ -41,8 +43,8 @@ public class VehicleNode /* Remote service identifiers */ public final static String FOB_SIGNAL_UNLOCK = "unlock"; public final static String FOB_SIGNAL_LOCK = "lock"; - public final static String FOB_SIGNAL_AUTO_UNLOCK = "auto_unlock"; - public final static String FOB_SIGNAL_AUTO_LOCK = "auto_lock"; +// public final static String FOB_SIGNAL_AUTO_UNLOCK = "auto_unlock"; +// public final static String FOB_SIGNAL_AUTO_LOCK = "auto_lock"; public final static String FOB_SIGNAL_START = "start"; public final static String FOB_SIGNAL_STOP = "stop"; public final static String FOB_SIGNAL_HORN = "horn"; @@ -122,6 +124,10 @@ public static boolean isConnected() { return (connectionStatus == ConnectionStatus.CONNECTED); } + public static boolean isUnlocked() { + return isUnlocked; + } + public static void connect() { if (connectionStatus == ConnectionStatus.CONNECTING) return; // TODO: Do we want to move this logic down into the SDK? @@ -147,9 +153,14 @@ public static void sendFobSignal(String fobSignal) {//}, Object params) { if (connectionStatus == ConnectionStatus.DISCONNECTED) connect(); fobSignalServiceBundle.invokeService(fobSignal, new FobParamsManager.FobParams(), 5000); + + if (fobSignal.equals(FOB_SIGNAL_LOCK)) isUnlocked = false; + if (fobSignal.equals(FOB_SIGNAL_UNLOCK)) isUnlocked = true; } public static void setDeviceAddress(String deviceAddress) { rviNode.setBluetoothDeviceAddress(deviceAddress); } + + }