集合位置优先地图跳转

chengzhenyu 8 anni fa
parent
commit
3c9ae120c9

+ 18 - 2
app/src/main/java/ai/pai/client/db/Preferences.java

@@ -47,11 +47,27 @@ public class Preferences {
47 47
         mPrefs.edit().putString("gatherLocation",gatherLocation).commit();
48 48
     }
49 49
 
50
-    public String getTourGatherLocation(){
51
-        return mPrefs.getString("gatherLocation",NullStr);
50
+    public String getTourGatherLon(){
51
+        return mPrefs.getString("gatherLon",NullStr);
52
+    }
53
+
54
+
55
+    public void setTourGatherLat(String gatherLat){
56
+        mPrefs.edit().putString("gatherLat",gatherLat).commit();
57
+    }
58
+
59
+    public String getTourGatherLat(){
60
+        return mPrefs.getString("gatherLat",NullStr);
52 61
     }
53 62
 
54 63
 
64
+    public void setTourGatherLon(String gatherLon){
65
+        mPrefs.edit().putString("gatherLon",gatherLon).commit();
66
+    }
67
+
68
+    public String getTourGatherLocation(){
69
+        return mPrefs.getString("gatherLocation",NullStr);
70
+    }
55 71
     public void setTourGuidePhone(String phone){
56 72
         mPrefs.edit().putString("tour_phone",phone).commit();
57 73
     }

+ 8 - 0
app/src/main/java/ai/pai/client/fragments/TabRecentPhotoFragment.java

@@ -170,6 +170,14 @@ public class TabRecentPhotoFragment extends BaseFragment implements SwipeRefresh
170 170
                                 String gatherMap = group.getString("gather_screenshot");
171 171
                                 Preferences.getInstance(context).setGatherMap(gatherMap);
172 172
                             }
173
+                            if(group.has("gather_lat")){
174
+                                String lat = group.getString("gather_lat");
175
+                                Preferences.getInstance(context).setTourGatherLat(lat);
176
+                            }
177
+                            if(group.has("gather_lon")){
178
+                                String lon = group.getString("gather_lon");
179
+                                Preferences.getInstance(context).setTourGatherLon(lon);
180
+                            }
173 181
                         }
174 182
                     }else{
175 183
                         Preferences.getInstance(context).setTourMode(false);

+ 8 - 0
app/src/main/java/ai/pai/client/services/MyLocationService.java

@@ -154,6 +154,14 @@ public class MyLocationService extends Service implements Handler.Callback{
154 154
                                 String gatherMap = group.getString("gather_screenshot");
155 155
                                 Preferences.getInstance(context).setGatherMap(gatherMap);
156 156
                             }
157
+                            if(group.has("gather_lat")){
158
+                                String lat = group.getString("gather_lat");
159
+                                Preferences.getInstance(context).setTourGatherLat(lat);
160
+                            }
161
+                            if(group.has("gather_lon")){
162
+                                String lon = group.getString("gather_lon");
163
+                                Preferences.getInstance(context).setTourGatherLon(lon);
164
+                            }
157 165
                         }
158 166
                     }else{
159 167
                         Preferences.getInstance(context).setTourGatherLocation("");

+ 68 - 10
app/src/main/java/ai/pai/client/views/GatherInfoPopup.java

@@ -1,6 +1,7 @@
1 1
 package ai.pai.client.views;
2 2
 
3 3
 import android.app.Activity;
4
+import android.content.Intent;
4 5
 import android.text.TextUtils;
5 6
 import android.view.LayoutInflater;
6 7
 import android.view.View;
@@ -48,29 +49,86 @@ public class GatherInfoPopup extends BasePopupWindow {
48 49
         return popupView;
49 50
     }
50 51
 
51
-    private void init(){
52
-        String time = TimeUtils.getGatherTimeStr(Preferences.getInstance(context).getGatherTime()-30*60*1000);
53
-        if(time.length()==0){
52
+    private void init() {
53
+        String time = TimeUtils.getGatherTimeStr(Preferences.getInstance(context).getGatherTime() - 30 * 60 * 1000);
54
+        if (time.length() == 0) {
54 55
             time = context.getString(R.string.gather_no_time);
55 56
         }
56 57
         String location = Preferences.getInstance(context).getTourGatherLocation();
57
-        if(location.length()==0){
58
+        if (location.length() == 0) {
58 59
             location = context.getString(R.string.gather_no_location);
59 60
         }
60
-        gatherInfoText.setText(context.getString(R.string.gather_info,time ,location));
61
-        if(!TextUtils.isEmpty(Preferences.getInstance(context).getGatherMap())){
62
-            PhotoLoader.getInstance(context).displayImage(Preferences.getInstance(context).getGatherMap(),gatherMap);
63
-            gatherMap.setOnClickListener(new View.OnClickListener(){
61
+        gatherInfoText.setText(context.getString(R.string.gather_info, time, location));
62
+        if (!TextUtils.isEmpty(Preferences.getInstance(context).getGatherMap())) {
63
+            PhotoLoader.getInstance(context).displayImage(Preferences.getInstance(context).getGatherMap(), gatherMap);
64
+            gatherMap.setOnClickListener(new View.OnClickListener() {
64 65
                 @Override
65 66
                 public void onClick(View v) {
66
-                    new FullScreenImgPopup(context,Preferences.getInstance(context).getGatherMap()).showPopupWindow();
67
+                    String lat = Preferences.getInstance(context).getTourGatherLat();
68
+                    String lon = Preferences.getInstance(context).getTourGatherLon();
69
+                    if (TextUtils.isEmpty(lat) || TextUtils.isEmpty(lon) || !callThirdPartyMap(lat, lon)) {
70
+                        new FullScreenImgPopup(context, Preferences.getInstance(context).getGatherMap()).showPopupWindow();
71
+                    }
67 72
                 }
68 73
             });
69
-        }else{
74
+        } else {
70 75
             gatherMap.setVisibility(View.GONE);
71 76
         }
72 77
     }
73 78
 
79
+    private boolean callThirdPartyMap(String lat, String lon) {
80
+
81
+        if (isAppExist("com.autonavi.minimap")) {
82
+            try {
83
+                Intent intent = Intent.getIntent("androidamap://viewMap?sourceApplication=paiai&lat=" + lat + "&lon=" + lon + "&dev=0");
84
+                context.startActivity(intent);
85
+                return true;
86
+            } catch (Exception e) {
87
+                e.printStackTrace();
88
+            }
89
+
90
+        } else if (isAppExist("com.baidu.BaiduMap")) {
91
+            double latd = Double.parseDouble(lat);
92
+            double lond = Double.parseDouble(lon);
93
+            Double[] loc = GCJ02ToBD09(latd, lond);
94
+            latd = loc[0];
95
+            lond = loc[1];
96
+            try {
97
+                Intent intent = Intent.getIntent("intent://map/marker?location=" + String.valueOf(latd) + "," + String.valueOf(lond) + "&title=集合位置&src=paiai#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end");
98
+                context.startActivity(intent);
99
+                return true;
100
+            } catch (Exception e) {
101
+                e.printStackTrace();
102
+            }
103
+        }
104
+        return false;
105
+    }
106
+
107
+
108
+    private boolean isAppExist(String packageName) {
109
+        if (TextUtils.isEmpty(packageName))
110
+            return false;
111
+        try {
112
+            context.getPackageManager().getPackageInfo(packageName, 0);
113
+            return true;
114
+        } catch (Exception e) {
115
+            return false;
116
+        }
117
+
118
+    }
119
+
120
+    private static double x_PI = 3.14159265358979324 * 3000.0 / 180.0;
121
+
122
+    public static Double[] GCJ02ToBD09(Double gcj_lon, Double gcj_lat) {
123
+        double z =
124
+                Math.sqrt(gcj_lon * gcj_lon + gcj_lat * gcj_lat) + 0.00002 * Math.sin(gcj_lat * x_PI);
125
+        double theta = Math.atan2(gcj_lat, gcj_lon) + 0.000003 * Math.cos(gcj_lon * x_PI);
126
+        Double[] arr = new Double[2];
127
+        arr[0] = z * Math.cos(theta) + 0.0065;
128
+        arr[1] = z * Math.sin(theta) + 0.006;
129
+        return arr;
130
+    }
131
+
74 132
     @Override
75 133
     public View getAnimaView() {
76 134
         return popupView.findViewById(R.id.popup_anima);