Skip to content

Commit

Permalink
resolve reference null object problem. cause by intent for broadcast …
Browse files Browse the repository at this point in the history
…is non initialized.
  • Loading branch information
skyforcetw committed Mar 14, 2019
1 parent 75c0aa7 commit 0b4878f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void onLocationChanged(Location location) {
updateHUD();

//send lat/lon for recognize history
sendLocationExtraByBroadcast(getString(R.string.broadcast_receiver_notification_monitor), getString(R.string.location), location);
// sendLocationExtraByBroadcast(getString(R.string.broadcast_receiver_notification_monitor), getString(R.string.location), location);
// final double latitude = location.getLatitude();
// final double longitude = location.getLongitude();
// this.sendBroadcast();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ public void SetTime(int nH, int nM, boolean bFlag, boolean bTraffic, boolean bCo
SendHud2(arr);
}

public void SetRemainTime(int nH, int nM ) {
final boolean bTraffic=false;
final boolean bH=true;
public void SetRemainTime(int nH, int nM) {
final boolean bTraffic = false;
final boolean bH = true;
final boolean bFlag = true;

boolean noHour = 0 == nH;
Expand Down Expand Up @@ -282,7 +282,7 @@ public void SetDirection(eOutAngle nDir) {
* @param nType 圓環方向
* @param nRoundaboutOut 圓環out
*/
public void SetDirection(eOutAngle nDir, eOutType nType, eOutAngle nRoundaboutOut) {
public void SetDirection(final eOutAngle nDir, final eOutType nType, final eOutAngle nRoundaboutOut) {
char arr[] = {(char) 0x01,
(nDir == eOutAngle.LeftDown) ? (char) 0x10 : ((nDir == eOutAngle.RightDown) ? (char) 0x20 : (char) nType.value),
(nType == eOutType.RightRoundabout || nType == eOutType.LeftRoundabout) ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import chutka.bitman.com.speedometersimplified.LocationService;
import sky4s.garminhud.Arrow;
import sky4s.garminhud.GarminHUD;
import sky4s.garminhud.eOutAngle;

public class MainActivity extends AppCompatActivity {
//for test with virtual device which no BT device
Expand Down Expand Up @@ -98,6 +99,7 @@ private void sendBooleanExtraByBroadcast(String receiver, String key, boolean b)
}

private MsgReceiver msgReceiver;
private boolean lastReallyInNavigation = false;

private class MsgReceiver extends BroadcastReceiver {
@Override
Expand All @@ -119,18 +121,25 @@ public void onReceive(Context context, Intent intent) {
}
} else {
//pass success
boolean notify_catched = intent.getBooleanExtra(getString(R.string.notify_catched),
final boolean notify_catched = intent.getBooleanExtra(getString(R.string.notify_catched),
null != switchNotificationCaught ? switchNotificationCaught.isChecked() : false);
boolean gmaps_notify_catched = intent.getBooleanExtra(getString(R.string.gmaps_notify_catched),
final boolean gmaps_notify_catched = intent.getBooleanExtra(getString(R.string.gmaps_notify_catched),
null != switchGmapsNotificationCaught ? switchGmapsNotificationCaught.isChecked() : false);

final boolean is_in_navigation = intent.getBooleanExtra(getString(R.string.is_in_navigation), false);

if (null != switchNotificationCaught && null != switchGmapsNotificationCaught) {
if (!notify_catched) {
if (!notify_catched) { //no notify catched
switchNotificationCaught.setChecked(false);
switchGmapsNotificationCaught.setChecked(false);
} else {
switchNotificationCaught.setChecked(notify_catched);
switchGmapsNotificationCaught.setChecked(gmaps_notify_catched);
final boolean is_really_in_navigation = gmaps_notify_catched && is_in_navigation;
switchGmapsNotificationCaught.setChecked(is_really_in_navigation);
if (lastReallyInNavigation != is_really_in_navigation && null != garminHud) {
garminHud.SetDirection(eOutAngle.AsDirection);
}
lastReallyInNavigation =is_really_in_navigation;
}
}

Expand Down Expand Up @@ -482,7 +491,7 @@ public void buttonOnClicked(View view) {

case R.id.button1:
if (null != NotificationMonitor.getStaticInstance()) {
NotificationMonitor.getStaticInstance().processArrow(Arrow.LeaveRoundaboutSharpRight);
NotificationMonitor.getStaticInstance().processArrow(Arrow.Convergence);
}
break;
case R.id.button2:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,22 +194,28 @@ public IBinder onBind(Intent intent) {
return super.onBind(intent);
}

private Intent intent2Main=null;
private Intent intent2Main = null;

private void checkIntentForExtra() {
if(null==intent2Main) {
if (null == intent2Main) {
intent2Main = new Intent(getString(R.string.broadcast_receiver_main_activity));
}
}
private void addBooleanExtra(String key,boolean b) {

private void addBooleanExtra(String key, boolean b) {
checkIntentForExtra();
intent2Main.putExtra(key, b);
}

private void addStringExtra(String key,String string) {
private void addStringExtra(String key, String string) {
checkIntentForExtra();
intent2Main.putExtra(string, string);
}

private void sendIntent2MainActivity() {
sendBroadcast(intent2Main);
if (null != intent2Main) {
sendBroadcast(intent2Main);
}
}

// private void sendBooleanExtra2MainActivity(String string, boolean b) {
Expand Down Expand Up @@ -260,6 +266,7 @@ private void processGoogleMapsNotification(Notification notification) {
} else {
addBooleanExtra(getString(R.string.notify_parse_failed), false);
addBooleanExtra(getString(R.string.gmaps_notify_catched), true);
addBooleanExtra(getString(R.string.is_in_navigation), isInNavigation);
sendIntent2MainActivity();
}
}
Expand Down Expand Up @@ -403,6 +410,8 @@ private void logParseMessage() {
sendIntent2MainActivity();
}

private boolean isInNavigation = false;

private boolean parseNotificationByExtras(Notification notification) {
if (null == notification) {
return false;
Expand Down Expand Up @@ -435,7 +444,8 @@ private boolean parseNotificationByExtras(Notification notification) {
}
}

if (null != subText && !subTextEmpty) {
final boolean somethingCanParse = null != subText && !subTextEmpty;
if (somethingCanParse) {
parseTimeAndDistanceToDest(subText);

String[] title_str = title.split("–");
Expand Down Expand Up @@ -473,6 +483,9 @@ private boolean parseNotificationByExtras(Notification notification) {
}
logParseMessage();
updateGaminHudInformation();
isInNavigation = true;
} else {
isInNavigation = false;
}
return true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum eOutType {
LeftRoundabout(0x04),
RightRoundabout(0x08),

// Roundabout(0x04+0x08),

RightFlag(0x40), //with eOutAngle: Straight,Right,Left
ArrowOnly(0x80);
Expand Down
6 changes: 3 additions & 3 deletions GoogleMaps_HUD/gmaps_hud/version.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Wed Mar 13 01:59:33 CST 2019
VERSION_NAME=0.3.2
VERSION_CODE=71
#Fri Mar 15 00:15:27 CST 2019
VERSION_NAME=0.3.3
VERSION_CODE=91

0 comments on commit 0b4878f

Please sign in to comment.