Pārlūkot izejas kodu

1.修改Android Apex Mobile地图缩放。

Pen Li 8 gadi atpakaļ
vecāks
revīzija
be04f07606

+ 31 - 1
Apex Mobile/app/src/main/java/com/usai/apex/DetailFragment.java

@@ -59,7 +59,7 @@ import java.io.File;
 import java.io.InputStream;
 import java.util.regex.Pattern;
 
-public class DetailFragment extends Fragment implements OnClickListener /*
+public class DetailFragment extends Fragment implements OnClickListener, ShipMap.ShipMapListener /*
 																		 * ,
 																		 * OnGestureListener
 																		 */
@@ -70,6 +70,25 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 	private String copiedKey;
 	private String copiedVal;
 	private View touchedView;
+
+	@Override
+	public void shipMapTryToZoomIn(ShipMap shipMap, boolean zoomIn) {
+
+		if (zoomIn) {
+
+			LinearLayout.LayoutParams lfLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0);
+			mDetailContainer.setLayoutParams(lfLayoutParams);
+
+		} else {
+
+			LinearLayout.LayoutParams lfLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0,2.0f);
+			mDetailContainer.setLayoutParams(lfLayoutParams);
+		}
+
+		mMapZoomIn = zoomIn;
+
+	}
+
 	private class GestureListener extends GestureDetector.SimpleOnGestureListener {
 
 		@Override
@@ -313,6 +332,7 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 		outState.putInt("selectContactPosition",mSelectContactPosition);
 		outState.putInt("selectTrackingPosition",mSelectTrackingPosition);
 		outState.putInt("selectTrackingChild",mSelectTrackingChild);
+		outState.putBoolean("mapZoomIn",mMapZoomIn);
 	}
 
 	private void configureMap(ShipMap map) {
@@ -327,8 +347,13 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 		map.setShowPoe(true);
 		map.setShowPod(true);
 		map.setShowPol(true);
+
+		map.setShipMapListener(this);
 	}
 
+	private RelativeLayout mDetailContainer;
+	private boolean mMapZoomIn = false;
+
 	@Override
 	public View onCreateView(LayoutInflater inflater, ViewGroup container,
 			Bundle savedInstanceState)
@@ -344,6 +369,7 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 			view = inflater.inflate(R.layout.detail_fragment_withmap, null);
 			mTrackingMap = view.findViewById(R.id.tracking_map);
 			configureMap(mTrackingMap);
+			mDetailContainer = view.findViewById(R.id.detail_list_container);
 		} else {
 			view = inflater.inflate(R.layout.detail_fragment, null);
 			mTrackingMap = null;
@@ -354,8 +380,12 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 			mSelectContactPosition = savedInstanceState.getInt("selectContactPosition");
 			mSelectTrackingPosition = savedInstanceState.getInt("selectTrackingPosition");
 			mSelectTrackingChild = savedInstanceState.getInt("selectTrackingChild");
+			mMapZoomIn = savedInstanceState.getBoolean("mapZoomIn");
 		}
 
+		if (mTrackingMap != null) {
+			mTrackingMap.setZoomIn(mMapZoomIn);
+		}
 
 //		if(this.getArguments().getString("action_type").equals("Tracing"))
 //		{

+ 67 - 0
Apex Mobile/app/src/main/java/com/usai/apex/ShipMap/ShipMap.java

@@ -12,6 +12,7 @@ import android.support.annotation.Nullable;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.View;
+import android.widget.ImageButton;
 import android.widget.RelativeLayout;
 import android.widget.TextView;
 
@@ -49,6 +50,11 @@ public class ShipMap extends RelativeLayout implements GoogleMap.OnMarkerClickLi
     private Context mContext;
     private Boolean mUseGoogleMap;
 
+    private ShipMapListener mListener;
+    private ShipMap self = this;
+
+    private ImageButton mResizeBtn;
+
     public ShipMap(Context context) {
         super(context);
         init(context);
@@ -134,6 +140,53 @@ public class ShipMap extends RelativeLayout implements GoogleMap.OnMarkerClickLi
             LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
             addView(mBaiduMap,layoutParams);
         }
+
+        ImageButton resizeBtn = new ImageButton(mContext);
+        resizeBtn.setImageResource(R.drawable.rect_history);
+        resizeBtn.setTag(false);
+
+        LayoutParams layoutParams = new LayoutParams(dp2px(mContext,40.0f),dp2px(mContext,40.0f));
+        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
+        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
+        layoutParams.setMargins(0,dp2px(mContext,10.0f),dp2px(mContext,10.0f),0);
+
+        addView(resizeBtn,layoutParams);
+        mResizeBtn = resizeBtn;
+
+        resizeBtn.setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                ImageButton zoomBtn = (ImageButton)v;
+                boolean selected = (boolean) zoomBtn.getTag();
+                selected = !selected;
+
+                setZoomIn(selected);
+
+            }
+        });
+
+    }
+
+    public void setZoomIn(boolean zoomIn) {
+
+        mResizeBtn.setTag(zoomIn);
+
+        if (zoomIn) {
+            mResizeBtn.setImageResource(R.drawable.rect_announcements);
+        } else {
+            mResizeBtn.setImageResource(R.drawable.rect_history);
+        }
+
+        if (mListener != null) {
+            mListener.shipMapTryToZoomIn(self,zoomIn);
+        }
+
+    }
+
+
+    public static int dp2px(Context context, float dpValue) {
+        float scale = context.getResources().getDisplayMetrics().density;
+        return (int) (dpValue * scale + 0.5f);
     }
 
     private static int AnnotationDisplayPriorityRequired = 2;
@@ -434,6 +487,14 @@ public class ShipMap extends RelativeLayout implements GoogleMap.OnMarkerClickLi
         return mShowCurrent;
     }
 
+    public void setShipMapListener(ShipMapListener listener) {
+        mListener = listener;
+    }
+
+    public ShipMapListener getShipMapListener() {
+        return mListener;
+    }
+
     /**
      * Google
      * */
@@ -554,4 +615,10 @@ public class ShipMap extends RelativeLayout implements GoogleMap.OnMarkerClickLi
         }
 
     }
+
+    public interface ShipMapListener {
+
+        void shipMapTryToZoomIn(ShipMap shipMap,boolean zoomIn);
+
+    }
 }

+ 38 - 1
Apex Mobile/app/src/main/java/com/usai/apex/mainframe/TrackingListFragment.java

@@ -43,7 +43,7 @@ import java.util.Map;
 /**
  * A simple {@link Fragment} subclass.
  */
-public class TrackingListFragment extends ListFragment implements View.OnClickListener{
+public class TrackingListFragment extends ListFragment implements View.OnClickListener, ShipMap.ShipMapListener {
     protected BaseAdapter adapter;
     boolean bdirty = false;
 //    List<Map<String, Object>> list_data;
@@ -55,6 +55,7 @@ TrackingListSearchResult searchresult	= new TrackingListSearchResult();
 
         outState.putSerializable("searchresult",searchresult);
         outState.putBoolean("dirty",bdirty);
+        outState.putBoolean("mapZoomIn",mMapZoomIn);
 
     }
 
@@ -202,6 +203,29 @@ TrackingListSearchResult searchresult	= new TrackingListSearchResult();
 
     public int mSelectedIndex = -1;
 
+    private boolean mMapZoomIn = false;
+
+    @Override
+    public void shipMapTryToZoomIn(ShipMap shipMap, boolean zoomIn) {
+
+        if (zoomIn) {
+
+            LinearLayout.LayoutParams lfLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, dp2px(mContext,96.0f));
+            mShipTable.setLayoutParams(lfLayoutParams);
+
+        } else {
+//            LinearLayout.LayoutParams mapLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0,1.0f);
+//            shipMap.setLayoutParams(mapLayoutParams);
+
+
+            LinearLayout.LayoutParams lfLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0,2.0f);
+            mShipTable.setLayoutParams(lfLayoutParams);
+        }
+
+        mMapZoomIn = zoomIn;
+
+    }
+
     private class TrackingAdapter extends BaseAdapter
     {
         private LayoutInflater mInflater;	// 动态布局映射
@@ -572,8 +596,12 @@ TrackingListSearchResult searchresult	= new TrackingListSearchResult();
         map.setShowPoe(true);
         map.setShowPod(true);
         map.setShowPol(true);
+
+        map.setShipMapListener(self);
     }
 
+    private FrameLayout mShipTable;
+
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
                              Bundle savedInstanceState) {
@@ -647,6 +675,8 @@ TrackingListSearchResult searchresult	= new TrackingListSearchResult();
         LinearLayout.LayoutParams lfLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0,2.0f);
         linearLayout.addView(lframe,lfLayoutParams);
 
+        mShipTable = lframe;
+
 //        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));
 
@@ -663,6 +693,13 @@ TrackingListSearchResult searchresult	= new TrackingListSearchResult();
 
         mProgressLayout = progress;
 
+        if (savedInstanceState != null) {
+            mMapZoomIn = savedInstanceState.getBoolean("mapZoomIn");
+        }
+        if (mShipMap != null) {
+            mShipMap.setZoomIn(mMapZoomIn);
+        }
+
         return root;
     }