فهرست منبع

1.修改Android Apex Mobile Recent在Restore的时候崩溃。
2.修改Android Apex Mobile增加Ship Map。

Pen Li 8 سال پیش
والد
کامیت
4b19162b99

+ 34 - 5
Apex Mobile/app/src/main/java/com/usai/apex/ShipMap/ShipMap.java

@@ -1,5 +1,7 @@
 package com.usai.apex.ShipMap;
 
+import android.app.Activity;
+import android.app.Fragment;
 import android.content.Context;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
@@ -8,6 +10,7 @@ import android.support.annotation.Nullable;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.View;
+import android.widget.RelativeLayout;
 import android.widget.TextView;
 
 import com.baidu.mapapi.SDKInitializer;
@@ -20,7 +23,9 @@ import com.baidu.mapapi.map.Marker;
 import com.baidu.mapapi.map.MarkerOptions;
 import com.baidu.mapapi.model.LatLng;
 
+import com.google.android.gms.common.GooglePlayServicesUtil;
 import com.google.android.gms.maps.GoogleMap;
+import com.google.android.gms.maps.MapFragment;
 import com.google.android.gms.maps.OnMapReadyCallback;
 import com.usai.apex.ApexTrackingApplication;
 import com.usai.apex.R;
@@ -28,9 +33,9 @@ import com.usai.apex.R;
 
 import org.json.JSONObject;
 
-public class ShipMap extends View implements GoogleMap.OnMarkerClickListener, BaiduMap.OnMarkerClickListener, GoogleMap.OnInfoWindowClickListener, OnMapReadyCallback, InfoWindow.OnInfoWindowClickListener {
+public class ShipMap extends RelativeLayout implements GoogleMap.OnMarkerClickListener, BaiduMap.OnMarkerClickListener, GoogleMap.OnInfoWindowClickListener, OnMapReadyCallback, InfoWindow.OnInfoWindowClickListener {
 
-    private com.google.android.gms.maps.MapView mGoogleMapView;
+    private MapFragment mGoogleMapView;
     private GoogleMap mGoogleMap;
     private MapView mBaiduMap;
     private Context mContext;
@@ -69,18 +74,31 @@ public class ShipMap extends View implements GoogleMap.OnMarkerClickListener, Ba
             mUseGoogleMap = true;
             System.out.println("已经安装");
         }
+//        mUseGoogleMap = false;
+
+//        GooglePlayServicesUtil.isGooglePlayServicesAvailable(mContext.getApplicationContext());
 
         if (mUseGoogleMap) {
 
+//            googleMap = ((MapFragment)((Activity)mContext).getFragmentManager().findFragmentById(R.id.ship_google_map));
+
             View relativeLayout = LayoutInflater.from(mContext).inflate(R.layout.ship_google_map,null);
-            mGoogleMapView = relativeLayout.findViewById(R.id.ship_google_map);
+//            mGoogleMapView = relativeLayout.findViewById(R.id.ship_google_map);
+            mGoogleMapView = ((MapFragment)((Activity)mContext).getFragmentManager().findFragmentById(R.id.ship_google_map));
             mGoogleMapView.getMapAsync(this);
 
+
+            LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
+            addView(relativeLayout,layoutParams);
+
         } else {
 
             SDKInitializer.initialize(ApexTrackingApplication.get_instance());
             mBaiduMap = new MapView(mContext);
             mBaiduMap.getMap().setOnMarkerClickListener(this);
+
+            LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
+            addView(mBaiduMap,layoutParams);
         }
     }
 
@@ -88,17 +106,25 @@ public class ShipMap extends View implements GoogleMap.OnMarkerClickListener, Ba
     private static int AnnotationDisplayPriorityHigh= 1;
     private static int AnnotationDisplayPriorityLow = 2;
 
+    private JSONObject mAnnotation;
+
     public void showShipAnnotation(JSONObject annotation) {
         if (annotation == null) {
             return;
         }
 
+
         if (mUseGoogleMap) {
-            mGoogleMap.clear();
+           if (mGoogleMap != null) {
+               mGoogleMap.clear();
+           } else {
+               mAnnotation = annotation;
+               return;
+           }
         } else {
             mBaiduMap.getMap().clear();
         }
-
+        mAnnotation = null;
 
         if (showPol()) {
             JSONObject pol = annotation.optJSONObject("pol");
@@ -286,6 +312,9 @@ public class ShipMap extends View implements GoogleMap.OnMarkerClickListener, Ba
 //            mGoogleMap.moveCamera(CameraUpdateFactory.newCameraPosition(US));
             mGoogleMap.setOnMarkerClickListener(this);
             mGoogleMap.setOnInfoWindowClickListener(this);
+            if (mAnnotation != null) {
+                showShipAnnotation(mAnnotation);
+            }
         }
     }
 

+ 58 - 0
Apex Mobile/app/src/main/java/com/usai/apex/TestActivity.java

@@ -3,11 +3,69 @@ package com.usai.apex;
 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
 
+import com.usai.apex.ShipMap.ShipMap;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
 public class TestActivity extends AppCompatActivity {
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_test);
+
+        String test = "{\n" +
+                "            \"title\":\"SH - PT. WANGSA MANUNGGAL JAYA PERKASA\",\n" +
+                "            \"icon\":\"status_vd\",\n" +
+                "            \"serial_no\":\"85625278dbaae299ffbbd10ee22cf875\",\n" +
+                "            \"hbol\":\"A1805340018\",\n" +
+                "            \"description\":\"A1805340018(1 containers)\",\n" +
+                "            \"detail\":\"Vessel Departure; IDSUB (SURABAYA, INDONESIA 2018-05-05)\",\n" +
+                "            \"date\":\"05/05/2018 - 06/02/2018\",\n" +
+                "            \"port\":\"IDSUB - USOAK\",\n" +
+                "            \"transport_stage\":\"3\",\n" +
+                "            \"locations\":{\n" +
+                "                \"por\":{\n" +
+                "                    \"icon\":\"\",\n" +
+                "                    \"lat\":\"-7.2000000000\",\n" +
+                "                    \"lon\":\"112.7333333333\",\n" +
+                "                    \"name\":\"SURABAYA\",\n" +
+                "                    \"addr\":\"\"\n" +
+                "                },\n" +
+                "                \"pol\":{\n" +
+                "                    \"icon\":\"\",\n" +
+                "                    \"lat\":\"-7.2000000000\",\n" +
+                "                    \"lon\":\"112.7333333333\",\n" +
+                "                    \"name\":\"SURABAYA\",\n" +
+                "                    \"addr\":\"\"\n" +
+                "                },\n" +
+                "                \"pod\":{\n" +
+                "                    \"icon\":\"\",\n" +
+                "                    \"lat\":\"37.7978400000\",\n" +
+                "                    \"lon\":\"-122.2864000000\",\n" +
+                "                    \"name\":\"OAKLAND\",\n" +
+                "                    \"addr\":\"\"\n" +
+                "                }\n" +
+                "            }\n" +
+                "        }";
+
+        ShipMap shipMap = findViewById(R.id.ship_map);
+
+        shipMap.setShowPol(true);
+        shipMap.setShowPod(true);
+        shipMap.setShowPoe(true);
+        shipMap.setShowPor(true);
+        shipMap.setShowOrigin(true);
+        shipMap.setShowDestination(true);
+        shipMap.setShowCurrent(true);
+
+        try {
+            JSONObject j = new JSONObject(test);
+            shipMap.showShipAnnotation(j.getJSONObject("locations"));
+
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
     }
 }

+ 20 - 0
Apex Mobile/app/src/main/java/com/usai/apex/mainframe/RecentFragment.java

@@ -14,6 +14,7 @@ import android.widget.ListView;
 import com.usai.apex.ApexTrackingApplication;
 import com.usai.apex.DetailActivity;
 import com.usai.apex.R;
+import com.usai.apex.ShipMap.ShipMap;
 import com.usai.util.Network;
 import com.usai.util.dbUtil;
 
@@ -21,6 +22,9 @@ import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
+import java.util.HashMap;
+import java.util.Map;
+
 
 /**
  * A simple {@link Fragment} subclass.
@@ -252,4 +256,20 @@ if(TextUtils.isEmpty(serial_no))
 
         Log.d("RecentFragment", "onSaveInstanceState: ");
     }
+
+    @Override
+    public void onClick(View v) {
+//        super.onClick(v);
+        int position = (Integer) v.getTag();
+        Map<String,Object> item = searchresult.getData().get(position);
+        if (item != null) {
+            JSONObject locations = (JSONObject) item.get("locations");
+            ShipMap shipMap = getShipMap();
+            if (shipMap != null) {
+                shipMap.showShipAnnotation(locations);
+            }
+        }
+
+//        getListView().setSelection(position);
+    }
 }

+ 48 - 4
Apex Mobile/app/src/main/java/com/usai/apex/mainframe/TrackingListFragment.java

@@ -21,12 +21,15 @@ import android.view.ViewGroup;
 import android.widget.BaseAdapter;
 import android.widget.FrameLayout;
 import android.widget.ImageView;
+import android.widget.LinearLayout;
 import android.widget.ProgressBar;
 import android.widget.TextView;
 
 import com.usai.apex.ApexTrackingApplication;
 import com.usai.apex.R;
 import com.usai.apex.Result.PullRefreshListView;
+import com.usai.apex.ShipMap.ShipMap;
+import com.usai.util.RAUtil;
 import com.usai.util.commonUtil;
 
 import org.apache.http.util.EncodingUtils;
@@ -39,7 +42,7 @@ import java.util.Map;
 /**
  * A simple {@link Fragment} subclass.
  */
-public class TrackingListFragment extends ListFragment {
+public class TrackingListFragment extends ListFragment implements View.OnClickListener{
     protected BaseAdapter adapter;
     boolean bdirty = false;
 //    List<Map<String, Object>> list_data;
@@ -77,7 +80,14 @@ TrackingListSearchResult searchresult	= new TrackingListSearchResult();
 //            requestData();
     }
 
-//    protected class TrackingListSearchResult implements Serializable
+    public TrackingListFragment self = this;
+
+    @Override
+    public void onClick(View v) {
+
+    }
+
+    //    protected class TrackingListSearchResult implements Serializable
 //    {
 //        private static final long serialVersionUID = 335021506170621905L;
 //        List<Map<String, Object>>	datalist	= new ArrayList<Map<String, Object>>();
@@ -268,6 +278,10 @@ TrackingListSearchResult searchresult	= new TrackingListSearchResult();
                     .findViewById(R.id.iv_status);
             iv_status.setImageResource((int)result.getData().get(position).get("icon"));
 
+            // new icon click
+            iv_status.setOnClickListener(self);
+            iv_status.setTag(position);
+
             View v=(View) convertView
                     .findViewById(R.id.v_transport_stage);
 
@@ -516,6 +530,17 @@ TrackingListSearchResult searchresult	= new TrackingListSearchResult();
         }
     }
 
+    public static int dp2px(Context context, float dpValue) {
+        float scale = context.getResources().getDisplayMetrics().density;
+        return (int) (dpValue * scale + 0.5f);
+    }
+
+    private ShipMap mShipMap;
+
+    public ShipMap getShipMap() {
+        return mShipMap;
+    }
+
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
                              Bundle savedInstanceState) {
@@ -530,6 +555,22 @@ TrackingListSearchResult searchresult	= new TrackingListSearchResult();
         IntentFilter intentFilter = new IntentFilter("com.apex.broadcast.person_mode");
         localBroadcastManager.registerReceiver(mReceiver,intentFilter);
 
+        // -------------------------
+
+        LinearLayout linearLayout = new LinearLayout(context);
+        linearLayout.setOrientation(LinearLayout.VERTICAL);
+
+        if (this instanceof RecentFragment) {
+
+            ShipMap shipMap = new ShipMap(context);
+            mShipMap = shipMap;
+
+            LinearLayout.LayoutParams mapLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0,1.0f);
+            mapLayoutParams.setMargins(dp2px(context,5),dp2px(context,2),dp2px(context,5),dp2px(context,2));
+
+            linearLayout.addView(shipMap,mapLayoutParams);
+
+        }
 
         // ------------------------------------------------------------------
 
@@ -564,8 +605,11 @@ TrackingListSearchResult searchresult	= new TrackingListSearchResult();
         lframe.addView(swipeRefreshLayout, new FrameLayout.LayoutParams(
                 ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
 
-        root.addView(lframe, new FrameLayout.LayoutParams(
-                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+        LinearLayout.LayoutParams lfLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0,2.0f);
+        linearLayout.addView(lframe,lfLayoutParams);
+
+//        root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+        root.addView(linearLayout, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
 
         // ------------------------------------------------------------------
 

+ 32 - 1
Apex Mobile/app/src/main/java/com/usai/apex/mainframe/TrackingListSearchResult.java

@@ -1,6 +1,9 @@
 package com.usai.apex.mainframe;
 
 
+import android.os.Parcel;
+import android.os.Parcelable;
+
 import com.usai.apex.ApexTrackingApplication;
 import com.usai.util.commonUtil;
 
@@ -15,11 +18,39 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-public class TrackingListSearchResult implements Serializable
+public class TrackingListSearchResult implements Serializable, Parcelable
 {
     private static final long serialVersionUID = 335021506170621905L;
     List<Map<String, Object>> datalist	= new ArrayList<Map<String, Object>>();
 
+    TrackingListSearchResult() {
+
+    }
+
+    protected TrackingListSearchResult(Parcel in) {
+    }
+
+    @Override
+    public void writeToParcel(Parcel dest, int flags) {
+    }
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    public static final Creator<TrackingListSearchResult> CREATOR = new Creator<TrackingListSearchResult>() {
+        @Override
+        public TrackingListSearchResult createFromParcel(Parcel in) {
+            return new TrackingListSearchResult(in);
+        }
+
+        @Override
+        public TrackingListSearchResult[] newArray(int size) {
+            return new TrackingListSearchResult[size];
+        }
+    };
+
     public int get_count()
     {
         return datalist.size();

+ 11 - 4
Apex Mobile/app/src/main/res/layout/ship_google_map.xml

@@ -3,11 +3,18 @@
                 android:layout_width="match_parent"
                 android:layout_height="match_parent">
 
-    <com.google.android.gms.maps.MapView
+    <!--<com.google.android.gms.maps.MapView-->
+        <!--android:id="@+id/ship_google_map"-->
+        <!--android:layout_width="match_parent"-->
+        <!--android:layout_height="match_parent">-->
+
+    <!--</com.google.android.gms.maps.MapView>-->
+
+    <fragment
         android:id="@+id/ship_google_map"
+        android:name="com.google.android.gms.maps.MapFragment"
         android:layout_width="match_parent"
-        android:layout_height="match_parent">
-
-    </com.google.android.gms.maps.MapView>
+        android:layout_height="match_parent"
+        />
 
 </RelativeLayout>