@@ -44,7 +44,6 @@ public class MainActivity extends Activity implements OnCameraChangeListener,
4444
4545 private LinearLayout mDestinationContainer ;
4646
47-
4847 private TextView mRouteCostText ;
4948
5049 private TextView mDesitinationText ;
@@ -54,11 +53,13 @@ public class MainActivity extends Activity implements OnCameraChangeListener,
5453 private ImageView mLocationImage ;
5554
5655 private LinearLayout mFromToContainer ;
57-
56+
5857 private Button mCancelButton ;
5958
6059 private boolean mIsFirst = true ;
6160
61+ private boolean mIsRouteSuccess = false ;
62+
6263 public interface OnGetLocationListener {
6364 public void getLocation (String locationAddress );
6465 }
@@ -72,11 +73,11 @@ protected void onCreate(Bundle savedInstanceState) {
7273 mLocationTask .setOnLocationGetListener (this );
7374 mRegeocodeTask = new RegeocodeTask (getApplicationContext ());
7475 RouteTask .getInstance (getApplicationContext ())
75- .addRouteCalculateListener (this );
76+ .addRouteCalculateListener (this );
7677 }
7778
7879 private void init (Bundle savedInstanceState ) {
79-
80+
8081 mAddressTextView = (TextView ) findViewById (R .id .address_text );
8182 mDestinationButton = (Button ) findViewById (R .id .destination_button );
8283 mDestinationButton .setOnClickListener (this );
@@ -86,16 +87,15 @@ private void init(Bundle savedInstanceState) {
8687 mAmap .getUiSettings ().setZoomControlsEnabled (false );
8788 mAmap .setOnMapLoadedListener (this );
8889 mAmap .setOnCameraChangeListener (this );
89-
90+
9091 mDestinationContainer = (LinearLayout ) findViewById (R .id .destination_container );
9192 mRouteCostText = (TextView ) findViewById (R .id .routecost_text );
9293 mDesitinationText = (TextView ) findViewById (R .id .destination_text );
9394 mDesitinationText .setOnClickListener (this );
9495 mLocationImage = (ImageView ) findViewById (R .id .location_image );
9596 mLocationImage .setOnClickListener (this );
9697 mFromToContainer = (LinearLayout ) findViewById (R .id .fromto_container );
97- mCancelButton =(Button ) findViewById (R .id .cancel_button );
98-
98+ mCancelButton = (Button ) findViewById (R .id .cancel_button );
9999
100100 }
101101
@@ -109,7 +109,9 @@ private void hideView() {
109109 private void showView () {
110110 mFromToContainer .setVisibility (View .VISIBLE );
111111 mDestinationButton .setVisibility (View .VISIBLE );
112- mCancelButton .setVisibility (View .VISIBLE );
112+ if (mIsRouteSuccess ) {
113+ mCancelButton .setVisibility (View .VISIBLE );
114+ }
113115 }
114116
115117 @ Override
@@ -126,8 +128,8 @@ public void onCameraChangeFinish(CameraPosition cameraPosition) {
126128 .search (mStartPosition .latitude , mStartPosition .longitude );
127129 if (mIsFirst ) {
128130 Utils .addEmulateData (mAmap , mStartPosition );
129- if (mPositionMark != null ){
130- mPositionMark .setToTop ();
131+ if (mPositionMark != null ) {
132+ mPositionMark .setToTop ();
131133 }
132134 mIsFirst = false ;
133135 }
@@ -177,11 +179,10 @@ public void onMapLoaded() {
177179 markerOptions .setFlat (true );
178180 markerOptions .anchor (0.5f , 0.5f );
179181 markerOptions .position (new LatLng (0 , 0 ));
180- markerOptions .icon (
181- BitmapDescriptorFactory .fromBitmap (
182- BitmapFactory .decodeResource (getResources (), R .drawable .icon_loaction_start )
183- )
184- );
182+ markerOptions
183+ .icon (BitmapDescriptorFactory .fromBitmap (BitmapFactory
184+ .decodeResource (getResources (),
185+ R .drawable .icon_loaction_start )));
185186 mPositionMark = mAmap .addMarker (markerOptions );
186187
187188 mPositionMark .setPositionByPixels (mMapView .getWidth () / 2 ,
@@ -230,15 +231,14 @@ public void onRegecodeGet(PositionEntity entity) {
230231 }
231232
232233 @ Override
233- public void onRouteCalculate (float cost ,float distance ,int duration ) {
234+ public void onRouteCalculate (float cost , float distance , int duration ) {
234235 mDestinationContainer .setVisibility (View .VISIBLE );
235-
236+ mIsRouteSuccess = true ;
236237 mRouteCostText .setVisibility (View .VISIBLE );
237238 mDesitinationText .setText (RouteTask
238239 .getInstance (getApplicationContext ()).getEndPoint ().address );
239- mRouteCostText .setText (
240- String .format ("预估费用%.2f元,距离%.1fkm,用时%d分" , cost ,distance ,duration )
241- );
240+ mRouteCostText .setText (String .format ("预估费用%.2f元,距离%.1fkm,用时%d分" , cost ,
241+ distance , duration ));
242242 mDestinationButton .setText ("我要用车" );
243243 mCancelButton .setVisibility (View .VISIBLE );
244244 mDestinationButton .setOnClickListener (null );
0 commit comments