package com.catiger.taxi;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.LatLngBounds;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.MyLocationStyle;
import com.amap.api.maps.utils.SpatialRelationUtil;
import com.amap.api.maps.utils.overlay.SmoothMoveMarker;
import com.amap.api.navi.AMapNavi;
import com.amap.api.navi.AMapNaviListener;
import com.amap.api.navi.enums.PathPlanningStrategy;
import com.amap.api.navi.model.AMapCalcRouteResult;
import com.amap.api.navi.model.AMapLaneInfo;
import com.amap.api.navi.model.AMapModelCross;
import com.amap.api.navi.model.AMapNaviCameraInfo;
import com.amap.api.navi.model.AMapNaviCross;
import com.amap.api.navi.model.AMapNaviLocation;
import com.amap.api.navi.model.AMapNaviPath;
import com.amap.api.navi.model.AMapNaviRouteNotifyData;
import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;
import com.amap.api.navi.model.AMapServiceAreaInfo;
import com.amap.api.navi.model.AimLessModeCongestionInfo;
import com.amap.api.navi.model.AimLessModeStat;
import com.amap.api.navi.model.NaviInfo;
import com.amap.api.navi.model.NaviLatLng;
import com.amap.api.navi.view.RouteOverLay;
import com.amap.api.services.core.AMapException;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.core.PoiItem;
import com.amap.api.services.poisearch.PoiResult;
import com.amap.api.services.poisearch.PoiSearch;
import com.amap.api.services.route.BusRouteResult;
import com.amap.api.services.route.DistanceResult;
import com.amap.api.services.route.DistanceSearch;
import com.amap.api.services.route.DriveRouteResult;
import com.amap.api.services.route.RideRouteResult;
import com.amap.api.services.route.RouteSearch;
import com.amap.api.services.route.RouteSearchV2;
import com.amap.api.services.route.WalkRouteResult;
import com.catiger.taxi.data.Driver;
import com.catiger.taxi.data.LoginRepository;
import com.catiger.taxi.data.model.LoggedInUser;
import com.catiger.taxi.tool.Order;
import com.catiger.taxi.ui.RippleView;
import com.catiger.taxi.utils.HttpUtil;
import com.catiger.taxi.utils.JsonUtil;
import com.catiger.taxi.utils.WebsocketUtil;
import com.catiger.taxi.view.FukuanDialog;
import com.catiger.taxi.view.VerificationCodeInput;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.util.Pair;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.widget.LinearLayoutCompat;
import androidx.core.app.NotificationCompat;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import com.catiger.taxi.databinding.ActivityCallBinding;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
public class CallActivity extends AppCompatActivity implements PoiSearch.OnPoiSearchListener, DistanceSearch.OnDistanceSearchListener, RouteSearch.OnRouteSearchListener {
private static String TAG = "CallActivity";
private static String sendOrderURL = "http://192.168.42.61:8083/assign";
private static String appOrderURL = "http://192.168.42.61:8083/task";
private static String cancelOrderURL = "http://192.168.42.61:8083/cancel";
private AppBarConfiguration appBarConfiguration;
private ActivityCallBinding binding;
private RouteSearch routeSearch;
private MapView mapView;
private AMap aMap;
private PoiSearch poiSearch;
private LatLonPoint startLatLonPoint, endLatLonPoint;
private RouteOverLay routeOverLay;
private AMapNavi aMapNavi;
private SmoothMoveMarker driverMarker;
private FloatingActionButton call;
private DistanceSearch distanceSearch;
private Driver driver;
private boolean picking = false;
private LatLng preLatLon, nextLatLon;
private Order currentOrder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//< Default Area Begin >
binding = ActivityCallBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
ImageView backImage = binding.registerBackButton;
backImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onBackPressed();
}
});
call = binding.callTaxiButton;
call.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!activated)
if(currentOrder.getApptime()==null)
sendOrder(sendOrderURL);
else
sendOrder(appOrderURL);
else
cancelOrder(cancelOrderURL);
}
});
Button phoneButton = binding.phoneBtn;
phoneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showPhone();
}
});
Button orderCancelButton = binding.canBtn;
orderCancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
cancelOrder();
}
});
//< Default Area End >
Intent intent = getIntent();
double slat = intent.getDoubleExtra("slat",0.0);
double slon = intent.getDoubleExtra("slon", 0.0);
double averMin = intent.getDoubleExtra("aver", 9999);
double averDis = intent.getDoubleExtra("dis", 9999);
int[] yuyue = intent.getIntArrayExtra("time");
String splace = intent.getStringExtra("splace");
String endPoiID = intent.getStringExtra("poiID");
String apptime = intent.getStringExtra("apptime");
if(yuyue!=null) {
TextView titleView = findViewById(R.id.reg_title);
titleView.setText("申请预约单");
}
TextView averTime = findViewById(R.id.estimateTime);
averTime.setText(averMin+"分钟");
LoggedInUser user = this.getLoggedUser();
currentOrder = new Order(user.getDisplayName());
currentOrder.setSlon(slon); currentOrder.setSlat(slat); currentOrder.setSplace(splace);
if(yuyue!=null) {
String str = yuyue[0]+"-";
if (yuyue[1]<10)
str += 0 + "" + yuyue[1];
else
str += yuyue[1];
str += "-";
if (yuyue[2]<10)
str += 0 + "" + yuyue[2];
else
str += yu