Skip to content

Commit

Permalink
[52229] Some whitespace changes and deleting of unused code. Changed …
Browse files Browse the repository at this point in the history
…the magic string fob signal service names to use constants. Moved isUnlocked boolean to VehicleNode.
  • Loading branch information
lillialexis committed Nov 18, 2015
1 parent 4e42b3e commit 8333874
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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<String, Object> 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);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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";
Expand Down Expand Up @@ -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?

Expand All @@ -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);
}


}

0 comments on commit 8333874

Please sign in to comment.