capacitor-google-navigation 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -118,6 +118,10 @@ public class GoogleNavigation {
118
118
  }
119
119
 
120
120
  NavigationFragment fragment = NavigationFragment.newInstance();
121
+ fragment.setOnCloseListener(() -> {
122
+ fm.beginTransaction().remove(fragment).commitAllowingStateLoss();
123
+ plugin.fireEvent("onNavigationClosed", new JSObject());
124
+ });
121
125
  fm.beginTransaction()
122
126
  .add(android.R.id.content, fragment, FRAGMENT_TAG)
123
127
  .commitAllowingStateLoss();
@@ -1,9 +1,15 @@
1
1
  package com.attributeai.navigation;
2
2
 
3
+ import android.graphics.Color;
4
+ import android.graphics.Typeface;
3
5
  import android.os.Bundle;
6
+ import android.util.TypedValue;
7
+ import android.view.Gravity;
4
8
  import android.view.LayoutInflater;
5
9
  import android.view.View;
6
10
  import android.view.ViewGroup;
11
+ import android.widget.Button;
12
+ import android.widget.FrameLayout;
7
13
 
8
14
  import androidx.annotation.NonNull;
9
15
  import androidx.annotation.Nullable;
@@ -19,11 +25,16 @@ import com.google.android.libraries.navigation.NavigationView;
19
25
  public class NavigationFragment extends Fragment {
20
26
 
21
27
  private NavigationView navigationView;
28
+ private Runnable onCloseListener;
22
29
 
23
30
  public static NavigationFragment newInstance() {
24
31
  return new NavigationFragment();
25
32
  }
26
33
 
34
+ public void setOnCloseListener(Runnable listener) {
35
+ this.onCloseListener = listener;
36
+ }
37
+
27
38
  @Nullable
28
39
  @Override
29
40
  public View onCreateView(
@@ -33,7 +44,37 @@ public class NavigationFragment extends Fragment {
33
44
  ) {
34
45
  navigationView = new NavigationView(requireContext());
35
46
  navigationView.onCreate(savedInstanceState);
36
- return navigationView;
47
+
48
+ FrameLayout root = new FrameLayout(requireContext());
49
+ root.addView(navigationView, new FrameLayout.LayoutParams(
50
+ FrameLayout.LayoutParams.MATCH_PARENT,
51
+ FrameLayout.LayoutParams.MATCH_PARENT
52
+ ));
53
+
54
+ Button closeButton = new Button(requireContext());
55
+ closeButton.setText("✕");
56
+ closeButton.setTextColor(Color.WHITE);
57
+ closeButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
58
+ closeButton.setTypeface(null, Typeface.BOLD);
59
+ closeButton.setBackgroundColor(Color.argb(153, 0, 0, 0)); // 60% black
60
+ closeButton.setOnClickListener(v -> {
61
+ if (onCloseListener != null) onCloseListener.run();
62
+ });
63
+
64
+ int sizePx = (int) TypedValue.applyDimension(
65
+ TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics()
66
+ );
67
+ int marginPx = (int) TypedValue.applyDimension(
68
+ TypedValue.COMPLEX_UNIT_DIP, 16, getResources().getDisplayMetrics()
69
+ );
70
+
71
+ FrameLayout.LayoutParams btnParams = new FrameLayout.LayoutParams(sizePx, sizePx);
72
+ btnParams.gravity = Gravity.TOP | Gravity.START;
73
+ btnParams.topMargin = marginPx;
74
+ btnParams.leftMargin = marginPx;
75
+ root.addView(closeButton, btnParams);
76
+
77
+ return root;
37
78
  }
38
79
 
39
80
  @Override
@@ -109,7 +109,19 @@ import GoogleNavigation
109
109
  self?.mapViewController?.setCameraFollowing()
110
110
  completion(true, nil)
111
111
  } else {
112
- completion(false, "Route calculation failed: \(routeStatus.rawValue)")
112
+ let reason: String
113
+ switch routeStatus {
114
+ case .apiKeyNotAuthorized: reason = "API key not authorized for Navigation SDK"
115
+ case .networkError: reason = "Network error — check internet connection"
116
+ case .noRouteFound: reason = "No route found to destination"
117
+ case .locationUnavailable: reason = "Location unavailable — check permissions"
118
+ case .quotaExceeded: reason = "API quota exceeded"
119
+ case .waypointError: reason = "Invalid waypoint coordinates"
120
+ case .travelModeUnsupported: reason = "Travel mode not supported"
121
+ case .canceled: reason = "Route request was canceled"
122
+ default: reason = "Unknown error (code \(routeStatus.rawValue))"
123
+ }
124
+ completion(false, "Route calculation failed: \(reason)")
113
125
  }
114
126
  }
115
127
  }
@@ -16,18 +16,22 @@ class NavigationMapViewController: UIViewController {
16
16
  fatalError("init(coder:) not supported")
17
17
  }
18
18
 
19
- override func viewDidLoad() {
20
- super.viewDidLoad()
21
-
19
+ override func loadView() {
22
20
  let options = GMSMapViewOptions()
23
- options.frame = view.bounds
21
+ options.frame = UIScreen.main.bounds
24
22
  let mapView = GMSMapView(options: options)
25
- mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
26
- view.addSubview(mapView)
27
23
  self.mapView = mapView
24
+ self.view = mapView
25
+ }
28
26
 
29
- _ = mapView.enableNavigation(with: session)
30
- mapView.cameraMode = .following
27
+ override func viewDidLoad() {
28
+ super.viewDidLoad()
29
+
30
+ guard let mapView = mapView else { return }
31
+ let enabled = mapView.enableNavigation(with: session)
32
+ if enabled {
33
+ mapView.cameraMode = .following
34
+ }
31
35
 
32
36
  addCloseButton()
33
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-google-navigation",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Google maps turn by turn navigation for capcitor",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",