Forráskód Böngészése

1.修改Android Apex Ship Map当前位置点闪烁。

Pen Li 8 éve
szülő
commit
779d233cd6

+ 98 - 2
Apex Mobile/app/src/main/java/com/usai/apex/ShipMap/ShipMap.java

@@ -8,9 +8,12 @@ import android.graphics.Color;
 import android.location.Location;
 import android.location.LocationManager;
 import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
 import android.support.annotation.CallSuper;
 import android.support.annotation.Nullable;
 import android.util.AttributeSet;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.ImageButton;
@@ -42,6 +45,10 @@ import com.usai.apex.R;
 import org.json.JSONException;
 import org.json.JSONObject;
 
+import java.lang.ref.WeakReference;
+import java.util.Timer;
+import java.util.TimerTask;
+
 public class ShipMap extends RelativeLayout implements GoogleMap.OnMarkerClickListener, BaiduMap.OnMarkerClickListener, GoogleMap.OnInfoWindowClickListener, OnMapReadyCallback, InfoWindow.OnInfoWindowClickListener {
 
     private MapFragment mGoogleMapView;
@@ -87,6 +94,8 @@ public class ShipMap extends RelativeLayout implements GoogleMap.OnMarkerClickLi
         if (mUseGoogleMap && mGoogleMapView != null && mContext != null) {
             ((Activity)mContext).getFragmentManager().beginTransaction().remove(mGoogleMapView).commit();
         }
+
+        stopTwinkle();
     }
 
     private void init(Context ctx) {
@@ -203,6 +212,8 @@ public class ShipMap extends RelativeLayout implements GoogleMap.OnMarkerClickLi
 
     private JSONObject mAnnotation;
 
+    private Marker mCurrentBaiduMarker;
+    private com.google.android.gms.maps.model.Marker mCurrentGoogleMarker;
     public void showShipAnnotation(JSONObject annotation) {
         if (annotation == null) {
             return;
@@ -314,14 +325,67 @@ public class ShipMap extends RelativeLayout implements GoogleMap.OnMarkerClickLi
 
         if (current != null && showCurrent()) {
             moveToLocation(current);
+
         } else if (pol != null && showPol()) {
             moveToLocation(pol);
         } else if (pod != null && showPod()) {
             moveToLocation(pod);
         }
+        startTwinkle();
+
+    }
+
+    private Timer mTimer;
+    private TimerHandler mTimerHandler = new TimerHandler(this);
+    private TimerTask mTimerTask;
+    private void startTwinkle() {
+
+        if (mCurrentGoogleMarker == null && mCurrentBaiduMarker == null) {
+            return;
+        }
+
+        if (mTimer != null && mTimerTask != null) {
+            return;
+        }
+
+        mTimer = new Timer();
+        mTimerTask = new TimerTask() {
+            @Override
+            public void run() {
+                Message msg = new Message();
+                mTimerHandler.sendMessage(msg);
+            }
+        };
+        mTimer.schedule(mTimerTask,100,100);
+    }
+
+    private void stopTwinkle() {
+        if (mTimer != null) {
+            mTimer.cancel();
+        }
+        if (mTimerTask != null) {
+            mTimerTask.cancel();
+        }
+    }
+
+    private void twinkleCurrentAlpha(double alpha) {
+
+        Log.d("Twinkle", "twinkleCurrentAlpha: " + alpha);
 
+        if (mUseGoogleMap) {
+            if (mCurrentGoogleMarker != null) {
+                mCurrentGoogleMarker.setAlpha((float) alpha);
+            }
+
+        } else {
+            if (mCurrentBaiduMarker != null) {
+                mCurrentBaiduMarker.setAlpha((float) alpha);
+            }
+        }
     }
 
+
+
     private void moveToLocation(JSONObject location) {
 
         if (location == null) {
@@ -394,8 +458,11 @@ public class ShipMap extends RelativeLayout implements GoogleMap.OnMarkerClickLi
                     .snippet(port + " " + addr);
             options.zIndex(priority);
 
-            mGoogleMap.addMarker(options);
+            com.google.android.gms.maps.model.Marker marker = mGoogleMap.addMarker(options);
 
+            if (port.equals("Port Of Discharge")) {
+                mCurrentGoogleMarker = marker;
+            }
 
         } else {
             return;
@@ -429,7 +496,11 @@ public class ShipMap extends RelativeLayout implements GoogleMap.OnMarkerClickLi
             MarkerOptions markeroption = new MarkerOptions().position(llA).icon(icon).zIndex(9).title(name).extraInfo(extrainfo).draggable(true);
             markeroption.zIndex(priority);
 
-            mBaiduMap.getMap().addOverlay(markeroption);
+            Marker marker = (Marker) mBaiduMap.getMap().addOverlay(markeroption);
+
+            if (port.equals("Port Of Discharge")) {
+                mCurrentBaiduMarker = marker;
+            }
 
         } else {
             return;
@@ -630,4 +701,29 @@ public class ShipMap extends RelativeLayout implements GoogleMap.OnMarkerClickLi
         void shipMapTryToZoomIn(ShipMap shipMap,boolean zoomIn);
 
     }
+
+    private static final class TimerHandler extends Handler {
+
+        double angle = 0;
+        WeakReference<ShipMap> weakMap;
+
+        TimerHandler(ShipMap map) {
+            if (map == null) {
+                return;
+            }
+            weakMap = new WeakReference<>(map);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+
+            angle += 0.1;
+            if (angle == 3.1) {
+                angle = 0;
+            }
+            double alpha = Math.abs(Math.cos(angle));
+            ShipMap shipMap = weakMap.get();
+            shipMap.twinkleCurrentAlpha(alpha);
+        }
+    }
 }