kotlin转化完结

This commit is contained in:
2022-08-30 09:32:14 +08:00
parent f8db723bdb
commit da853f7bac
36 changed files with 568 additions and 1820 deletions
@@ -15,11 +15,8 @@ import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.dahe.mylibrary.R;
import com.dahe.mylibrary.adapter.CarAdapter;
import com.dahe.mylibrary.adapter.NodeAdapter;
import com.dahe.mylibrary.bean.CarBean;
import com.dahe.mylibrary.bean.NodeBean;
import com.dahe.mylibrary.net.JsonUtils;
import com.dahe.mylibrary.utils.ToastUtils;
import com.lxj.xpopup.core.CenterPopupView;
import org.jetbrains.annotations.NotNull;
@@ -14,7 +14,6 @@ import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.dahe.mylibrary.R;
import com.dahe.mylibrary.adapter.CenterSimAdapter;
import com.dahe.mylibrary.bean.StateBean;
import com.dahe.mylibrary.wapper.SelectSimAdapter;
import com.luck.picture.lib.decoration.GridSpacingItemDecoration;
import com.lxj.xpopup.impl.PartShadowPopupView;
@@ -1,90 +0,0 @@
package com.dahe.mylibrary.cuspop;
import android.content.Context;
import android.util.Log;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.dahe.mylibrary.R;
import com.dahe.mylibrary.adapter.SelectDicAdapter;
import com.dahe.mylibrary.bean.DictBean;
import com.dahe.mylibrary.bean.StateBean;
import com.lxj.xpopup.core.AttachPopupView;
import java.util.List;
/**
* Description: 自定义局部阴影弹窗
* Create by dance, at 2018/12/21
*/
public class CustomDicPopView extends AttachPopupView {
private Context ctx;
private RecyclerView recyclerView;
private List<StateBean> wordList;
private SelectDicAdapter adapter;
private int selectPos;
public CustomDicPopView(@NonNull Context context, List<StateBean> wordList, int selectPos) {
super(context);
this.ctx = context;
this.wordList= wordList;
this.selectPos = selectPos;
}
@Override
protected int getImplLayoutId() {
return R.layout.custom_dic_popup;
}
@Override
protected void onCreate() {
super.onCreate();
recyclerView = findViewById(R.id.recyclerView);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(ctx, RecyclerView.VERTICAL, false);
// recyclerView.addItemDecoration(new RecycleViewDivider(ctx,RecyclerView.VERTICAL));
recyclerView.setLayoutManager(linearLayoutManager);
adapter = new SelectDicAdapter(-1, wordList,selectPos);
recyclerView.setAdapter(adapter);
adapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
if (listener!=null){
listener.selectChange(wordList.get(position),position);
}
((SelectDicAdapter)adapter).setSelect(position);
adapter.notifyDataSetChanged();
dismiss();
}
});
}
@Override
protected void onShow() {
super.onShow();
Log.e("tag", "CustomPartShadowPopupView onShow");
}
@Override
protected void onDismiss() {
super.onDismiss();
Log.e("tag", "CustomPartShadowPopupView onDismiss");
}
private OnSelectChangeListener listener;
public CustomDicPopView setOnSelectChangeListener(OnSelectChangeListener listener){
this.listener = listener;
return this;
}
public interface OnSelectChangeListener{
void selectChange(StateBean item ,int postion);
}
}
@@ -1,90 +0,0 @@
package com.dahe.mylibrary.cuspop;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.dahe.mylibrary.R;
import com.dahe.mylibrary.wapper.SelectSimAdapter;
import com.luck.picture.lib.decoration.GridSpacingItemDecoration;
import com.lxj.xpopup.impl.PartShadowPopupView;
import java.util.List;
/**
* Description: 自定义局部阴影弹窗
* Create by dance, at 2018/12/21
*/
public class CustomPartShadowPopupView extends PartShadowPopupView {
private Context ctx;
private RecyclerView recyclerView;
private List<String> wordList;
private SelectSimAdapter adapter;
private String selectString;
public CustomPartShadowPopupView(@NonNull Activity context, List<String> wordList, String selectString) {
super(context);
this.wordList= wordList;
this.selectString = selectString;
}
@Override
protected int getImplLayoutId() {
return R.layout.custom_part_shadow_popup;
}
@Override
protected void onCreate() {
super.onCreate();
recyclerView = findViewById(R.id.recyclerView);
GridLayoutManager gridLayoutManager = new GridLayoutManager(ctx, 4);
recyclerView.addItemDecoration(new GridSpacingItemDecoration(4, 20, false));
recyclerView.setLayoutManager(gridLayoutManager);
adapter = new SelectSimAdapter(-1, wordList,selectString);
recyclerView.setAdapter(adapter);
adapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
if (listener!=null){
listener.selectChange(wordList.get(position),position);
}
((SelectSimAdapter)adapter).setSelect(wordList.get(position));
adapter.notifyDataSetChanged();
dismiss();
}
});
}
@Override
protected void onShow() {
super.onShow();
Log.e("tag", "CustomPartShadowPopupView onShow");
}
@Override
protected void onDismiss() {
super.onDismiss();
Log.e("tag", "CustomPartShadowPopupView onDismiss");
}
private OnSelectChangeListener listener;
public CustomPartShadowPopupView setOnSelectChangeListener(OnSelectChangeListener listener){
this.listener = listener;
return this;
}
public interface OnSelectChangeListener{
void selectChange(String item ,int postion);
}
}
@@ -1,80 +0,0 @@
package com.dahe.mylibrary.cuspop;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.dahe.mylibrary.R;
import com.dahe.mylibrary.utils.ToastUtils;
import com.lxj.xpopup.core.CenterPopupView;
import com.lxj.xpopup.util.KeyboardUtils;
/**
* Description: 自定义局部阴影弹窗
* Create by dance, at 2018/12/21
*/
public class InputPopupView extends CenterPopupView {
private Context ctx;
public InputPopupView(@NonNull Context context) {
super(context);
this.ctx = context;
}
@Override
protected int getImplLayoutId() {
return R.layout.my_confim_popup_input;
}
@Override
protected void onCreate() {
super.onCreate();
EditText etInput = findViewById(R.id.et_input);
TextView tvCancel = findViewById(R.id.tv_cancel);
TextView tvConfirm = findViewById(R.id.tv_confirm);
if (listener != null) {
tvConfirm.setOnClickListener(view -> {
if (TextUtils.isEmpty(etInput.getText().toString().trim())){
KeyboardUtils.hideSoftInput(tvConfirm);
ToastUtils.showToast(ctx,"请填写取消原因");
return;
}
listener.okClick(etInput.getText().toString());
dismiss();
});
}
tvCancel.setOnClickListener(v -> dismiss());
}
@Override
protected void onShow() {
super.onShow();
Log.e("tag", "CustomPartShadowPopupView onShow");
}
@Override
protected void onDismiss() {
super.onDismiss();
Log.e("tag", "CustomPartShadowPopupView onDismiss");
}
private OnOkListener listener;
public InputPopupView setOnOkListener(OnOkListener listener) {
this.listener = listener;
return this;
}
public interface OnOkListener {
void okClick(String item);
}
}
@@ -1,107 +0,0 @@
package com.dahe.mylibrary.cuspop;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.dahe.mylibrary.R;
import com.dahe.mylibrary.adapter.NodeAdapter;
import com.dahe.mylibrary.bean.NodeBean;
import com.dahe.mylibrary.net.JsonUtils;
import com.dahe.mylibrary.utils.ToastUtils;
import com.lxj.xpopup.core.CenterPopupView;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class NodePopupView extends CenterPopupView {
private Context context;
private List<NodeBean> data;
public NodePopupView(Context context,String data) {
super(context);
this.context = context;
ArrayList<NodeBean> nodeBeans = JsonUtils.getInstance().jsonToList(data, NodeBean.class);
this.data = nodeBeans;
}
@Override
protected int getImplLayoutId() {
return R.layout.view_node;
}
@Override
protected void onCreate() {
super.onCreate();
TextView tvTitle = (TextView) findViewById(R.id.tvTitle);
ImageView ivCha = (ImageView) findViewById(R.id.ivCha);
LinearLayout llCha = (LinearLayout) findViewById(R.id.llCha);
Button btnOK = (Button) findViewById(R.id.btnOK);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(context,RecyclerView.VERTICAL,false));
recyclerView.setHasFixedSize(true);
NodeAdapter nodeAdapter = new NodeAdapter(-1,data);
recyclerView.setAdapter(nodeAdapter);
nodeAdapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(@NonNull @NotNull BaseQuickAdapter<?, ?> adapter, @NonNull @NotNull View view, int position) {
NodeBean nodeSelectBean = data.get(position);
if (!"0".equals(nodeSelectBean.getState())){
ToastUtils.showToast(context,"该节点不可操作");
return;
}
nodeSelectBean.setSelect("1".equals(nodeSelectBean.isSelect())?"0":"1");
nodeAdapter.notifyItemChanged(position);
}
});
btnOK.setOnClickListener(v -> {
if (listener!=null){
ArrayList<NodeBean> temp = new ArrayList<>();
for (int i = 0; i < data.size(); i++) {
NodeBean nodeSelectBean = data.get(i);
if ("1".equals(nodeSelectBean.isSelect())){
temp.add(nodeSelectBean);
}
}
if (temp.size()<=0){
ToastUtils.showToast(context,"至少存在一个节点");
return;
}
listener.okClick(JsonUtils.getInstance().toJson(data));
temp = null;
dismiss();
}
});
llCha.setOnClickListener(v -> {
dismiss();
});
}
private OnOkListener listener;
public NodePopupView setOnOkListener(OnOkListener listener) {
this.listener = listener;
return this;
}
public interface OnOkListener {
void okClick(String data);
}
}
@@ -1,77 +0,0 @@
package com.dahe.mylibrary.cuspop;
import android.content.Context;
import android.util.Log;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.dahe.mylibrary.R;
import com.dahe.mylibrary.bean.TipsBean;
import com.lxj.xpopup.core.CenterPopupView;
/**
* Description: 自定义局部阴影弹窗
* Create by dance, at 2018/12/21
*/
public class TextPopupTipsView extends CenterPopupView {
private TipsBean data;
private Context ctx;
public TextPopupTipsView(@NonNull Context context, TipsBean data) {
super(context);
this.data = data;
}
@Override
protected int getImplLayoutId() {
return R.layout.my_confim_popup_tip;
}
@Override
protected void onCreate() {
super.onCreate();
TextView etInput = findViewById(R.id.tv_input);
TextView tvTitle = findViewById(R.id.tv_title);
TextView tvCancel = findViewById(R.id.tv_cancel);
TextView tvConfirm = findViewById(R.id.tv_confirm);
tvTitle.setText(data.getTitle());
etInput.setText(data.getContent());
if (listener != null) {
tvConfirm.setOnClickListener(view -> {
listener.okClick();
dismiss();
});
}
tvCancel.setOnClickListener(v -> dismiss());
}
@Override
protected void onShow() {
super.onShow();
Log.e("tag", "CustomPartShadowPopupView onShow");
}
@Override
protected void onDismiss() {
super.onDismiss();
Log.e("tag", "CustomPartShadowPopupView onDismiss");
}
private OnOkListener listener;
public TextPopupTipsView setOnOkListener(OnOkListener listener) {
this.listener = listener;
return this;
}
public interface OnOkListener {
void okClick();
}
}
@@ -1,74 +0,0 @@
package com.dahe.mylibrary.cuspop;
import android.content.Context;
import android.util.Log;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.dahe.mylibrary.R;
import com.lxj.xpopup.core.CenterPopupView;
/**
* Description: 自定义局部阴影弹窗
* Create by dance, at 2018/12/21
*/
public class TextPopupView extends CenterPopupView {
private String data;
private Context ctx;
public TextPopupView(@NonNull Context context,String data) {
super(context);
this.data = data;
}
@Override
protected int getImplLayoutId() {
return R.layout.my_confim_popup_unus;
}
@Override
protected void onCreate() {
super.onCreate();
TextView etInput = findViewById(R.id.tv_input);
TextView tvCancel = findViewById(R.id.tv_cancel);
TextView tvConfirm = findViewById(R.id.tv_confirm);
etInput.setText(data);
if (listener != null) {
tvConfirm.setOnClickListener(view -> {
listener.okClick(etInput.getText().toString());
dismiss();
});
}
tvCancel.setOnClickListener(v -> dismiss());
}
@Override
protected void onShow() {
super.onShow();
Log.e("tag", "CustomPartShadowPopupView onShow");
}
@Override
protected void onDismiss() {
super.onDismiss();
Log.e("tag", "CustomPartShadowPopupView onDismiss");
}
private OnOkListener listener;
public TextPopupView setOnOkListener(OnOkListener listener) {
this.listener = listener;
return this;
}
public interface OnOkListener {
void okClick(String item);
}
}
@@ -2,11 +2,6 @@ package com.dahe.mylibrary.net;
import android.text.TextUtils;
import android.util.Log;
import com.google.zxing.common.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.IOException;
@@ -1,325 +0,0 @@
package com.dahe.mylibrary.utils;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.Bundle;
import android.util.Log;
import androidx.core.app.ActivityCompat;
import java.io.IOException;
import java.util.List;
import io.reactivex.rxjava3.annotations.Nullable;
import pub.devrel.easypermissions.EasyPermissions;
public class LocationUtil {
private static OnResponseListener responseListener;
private static LocationUtil locationUtil;
private LocationManager locationManager;
private Location currentBestLocation;
private NetworkListener networkListener;
private GPSLocationListener gpsListener;
private LocationUtil() {
}
/**
* 定位模式
*/
public enum Mode {
NETWORK, //网络定位
GPS, //GPS定位
AUTO //自动定位,使用网络或GPS定位
}
public static final int NO_PERMISSION = 1; //没权限
public static final int GPS_CLOSE = 2; //GPS是关闭的
public static final int UNAVAILABLE = 3; //不可用
/**
* 请求定位
*/
public static void requestLocation(Context context, Mode mode, OnResponseListener onResponseListener) {
LocationUtil.responseListener = onResponseListener;
if (EasyPermissions.hasPermissions(context, Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION)) {
Log.i("lj", "获取定位权限,开始定位");
//开始定位
locationUtil = new LocationUtil();
locationUtil.startLocation(context, mode);
} else {
Log.i("lj", "没有定位权限,定位失败");
String provider = mode == Mode.GPS ? LocationManager.GPS_PROVIDER : LocationManager.NETWORK_PROVIDER;
onResponseListener.onErrorResponse(provider, NO_PERMISSION);
}
}
/**
* 开始定位
*/
private void startLocation(Context context, Mode mode) {
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
switch (mode) {
case NETWORK:
if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
Log.i("lj", "网络定位");
networkListener = new NetworkListener();
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 500, 0.1f, networkListener);
} else {
responseListener.onErrorResponse(LocationManager.NETWORK_PROVIDER, UNAVAILABLE);
}
break;
case GPS:
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Log.i("lj","GPS定位");
gpsListener = new GPSLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000 * 2, 0.1f, gpsListener);
} else {
responseListener.onErrorResponse(LocationManager.GPS_PROVIDER, GPS_CLOSE);
}
break;
case AUTO:
if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
Log.i("lj","自动定位选择网络定位");
networkListener = new NetworkListener();
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 500, 0.1f, networkListener);
} else if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Log.i("lj","自动定位选择gps");
gpsListener = new GPSLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000 * 2, 0.1f, gpsListener);
} else {
responseListener.onErrorResponse(LocationManager.NETWORK_PROVIDER, UNAVAILABLE);
}
break;
default:
break;
}
} else {
Log.i("lj","无权限");
}
}
/**
* 停止定位
*/
public static void stopLocation() {
if (locationUtil == null) {
Log.i("lj","locationUtil is null");
return;
}
if (locationUtil.networkListener != null) {
locationUtil.locationManager.removeUpdates(locationUtil.networkListener);
}
if (locationUtil.gpsListener != null) {
locationUtil.locationManager.removeUpdates(locationUtil.gpsListener);
}
// L.i("停止定位");
}
private class GPSLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
// L.i("onLocationChanged");
if (location != null) {
// L.i("GPS定位成功");
// L.i("GPS定位耗时:" + ((System.currentTimeMillis() - l) / 1000) + "秒");
boolean isBetter = isBetterLocation(location, currentBestLocation);
if (isBetter) {
currentBestLocation = location;
}
double latitude = currentBestLocation.getLatitude(); //纬度
double longitude = currentBestLocation.getLongitude(); //经度
responseListener.onSuccessResponse(latitude, longitude);
} else {
// L.i("location is null");
}
}
@SuppressLint("MissingPermission")
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// L.i("onStatusChanged:" + status);
if (status == LocationProvider.OUT_OF_SERVICE || status == LocationProvider.TEMPORARILY_UNAVAILABLE) {
// L.i("GPS定位失败");
//如果之前没有开启过网络定位,自动切换到网络定位
if (networkListener == null) {
//开启网络定位
networkListener = new NetworkListener();
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, networkListener);
}
}
}
@Override
public void onProviderEnabled(String provider) {
// L.i("onProviderEnabled");
}
@Override
public void onProviderDisabled(String provider) {
// L.i("onProviderDisabled");
}
}
private class NetworkListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
if (location != null) {
// L.i("网络定位成功");
boolean isBetter = isBetterLocation(location, currentBestLocation);
if (isBetter) {
currentBestLocation = location;
}
double latitude = currentBestLocation.getLatitude(); //纬度
double longitude = currentBestLocation.getLongitude(); //经度
responseListener.onSuccessResponse(latitude, longitude);
}
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
if (status == LocationProvider.OUT_OF_SERVICE || status == LocationProvider.TEMPORARILY_UNAVAILABLE) {
// Log.i("网络定位失败");
responseListener.onErrorResponse(LocationManager.NETWORK_PROVIDER, UNAVAILABLE);
}
}
@Override
public void onProviderEnabled(String provider) {
// L.e("可用");
}
@Override
public void onProviderDisabled(String provider) {
// L.e("不可用");
}
}
private static final int TWO_MINUTES = 1000 * 60 * 2;
/**
* 比较最新获取到的位置是否比当前最好的位置更好
*
* @param location 最新获得的位置
* @param currentBestLocation 当前获取到的最好的位置
* @return 最新获取的位置比当前最好的位置更好则返回true
*/
private boolean isBetterLocation(Location location, Location currentBestLocation) {
if (currentBestLocation == null) {
// A new locationUtil is always better than no locationUtil
return true;
}
//实时性
// Check whether the new locationUtil fix is newer or older
long timeDelta = location.getTime() - currentBestLocation.getTime();
boolean isSignificantlyNewer = timeDelta > TWO_MINUTES; //最新位置比当前位置晚两分钟定位
boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;//最新位置比当前位置早两分钟定位
boolean isNewer = timeDelta > 0;
// If it's been more than two minutes since the current locationUtil, use the new locationUtil
// because the user has likely moved
if (isSignificantlyNewer) {
return true;
// If the new locationUtil is more than two minutes older, it must be worse
} else if (isSignificantlyOlder) {
return false;
}
//精确性
// Check whether the new locationUtil fix is more or less accurate
//locationUtil.getAccuracy()值越小越精确
int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
boolean isLessAccurate = accuracyDelta > 0; //最新的位置不如当前的精确
boolean isMoreAccurate = accuracyDelta < 0; //最新的位置比当前的精确
//最新的位置不如当前的精确,但是相差在一定范围之内
boolean isSignificantlyLessAccurate = accuracyDelta > 200;
// Check if the old and new locationUtil are from the same provider
boolean isFromSameProvider = isSameProvider(location.getProvider(),
currentBestLocation.getProvider());
// Determine locationUtil quality using a combination of timeliness and accuracy
if (isMoreAccurate) {
return true;
} else if (isNewer && !isLessAccurate) {
return true;
} else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
return true;
}
return false;
}
/**
* Checks whether two providers are the same
*/
private boolean isSameProvider(String provider1, String provider2) {
if (provider1 == null) {
return provider2 == null;
}
return provider1.equals(provider2);
}
public interface OnResponseListener {
/**
* 定位成功
*
* @param latitude 纬度
* @param longitude 经度
*/
void onSuccessResponse(double latitude, double longitude);
/**
* 定位失败
*
* @param provider provider
* @param status 失败码
*/
void onErrorResponse(String provider, int status);
}
/**
* 获取地址
*
* @param context Context
* @param latitude 纬度
* @param longitude 经度
* @return Address
*/
public static @Nullable
Address getAddress(Context context, double latitude, double longitude) {
Geocoder geocoder = new Geocoder(context);
try {
List<Address> list = geocoder.getFromLocation(latitude, longitude, 3);
if (list.size() > 0) {
Address address = list.get(0);
// Log.i("省:" + address.getAdminArea());
// Log.i("市:" + address.getLocality());
// Log.i("县/区:" + address.getSubLocality());
return address;
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
@@ -1,181 +0,0 @@
package com.dahe.mylibrary.utils;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.allenliu.versionchecklib.core.http.HttpParams;
import com.allenliu.versionchecklib.core.http.HttpRequestMethod;
import com.allenliu.versionchecklib.v2.AllenVersionChecker;
import com.allenliu.versionchecklib.v2.builder.DownloadBuilder;
import com.allenliu.versionchecklib.v2.builder.RequestVersionBuilder;
import com.allenliu.versionchecklib.v2.builder.UIData;
import com.allenliu.versionchecklib.v2.callback.CustomDownloadingDialogListener;
import com.allenliu.versionchecklib.v2.callback.CustomVersionDialogListener;
import com.allenliu.versionchecklib.v2.callback.RequestVersionListener;
import com.dahe.mylibrary.R;
import com.dahe.mylibrary.bean.VersionBean;
import com.dahe.mylibrary.dialog.VersionDialog;
import com.dahe.mylibrary.net.CommonResponseBean;
import com.dahe.mylibrary.net.JsonUtils;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
public class VersionUtils {
private static class SingletonHolder {
private static final VersionUtils INSTANCE = new VersionUtils();
}
private VersionUtils() {
}
public static final VersionUtils getInstance() {
return SingletonHolder.INSTANCE;
}
public void checkVersion(Context ctx, String api,boolean isShow) {
HttpParams httpParams = new HttpParams();
httpParams.put("appType", "1");
DownloadBuilder request = AllenVersionChecker
.getInstance()
.requestVersion()
.setRequestMethod(HttpRequestMethod.GET)
.setRequestUrl(api)
.setRequestParams(httpParams)
.request(new RequestVersionListener() {
@Nullable
@org.jetbrains.annotations.Nullable
@Override
public UIData onRequestVersionSuccess(DownloadBuilder downloadBuilder, String result) {
try {
if (StringUtils.isEmpty(result))
return null;
Type type = new TypeToken<CommonResponseBean<VersionBean>>() {
}.getType();
CommonResponseBean<VersionBean> o = JsonUtils.getInstance().fromJson(result, type);
VersionBean.ParamsDao data = o.getData().getData();
if ("1".equals(data.getUpdateType())) {
downloadBuilder.setForceRedownload(true);
}else{
downloadBuilder.setForceRedownload(false);
}
if (AppUtils.getAppVersionCode() < data.getVersion()) {
UIData uiData = UIData.create();
uiData.setTitle(data.getVersionName());
uiData.setDownloadUrl(data.getApkUrl());
uiData.setContent(data.getIntroduce());
return uiData;
}
if (isShow){
ToastUtils.showToast(ctx,"当前已是最新版本啊!");
}
return null;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
public void onRequestVersionFailure(String message) {
}
});
request.setCustomVersionDialogListener(createCustomDialogTwo(request));
request.setCustomDownloadingDialogListener(createCustomDownloadingDialog(ctx)).executeMission(ctx);
}
private CustomVersionDialogListener createCustomDialogTwo(DownloadBuilder request) {
return (context, versionBundle) -> {
VersionDialog baseDialog = new VersionDialog(context, R.style.BaseDialog, R.layout.custom_dialog_two_layout2);
TextView textView = baseDialog.findViewById(R.id.tv_msg);
TextView tvVersion = baseDialog.findViewById(R.id.tvVersion);
tvVersion.setText(request.getVersionBundle().getTitle()+" 版本更新");
textView.setMovementMethod(ScrollingMovementMethod.getInstance());
RequestVersionBuilder requestVersionBuilder = request.getRequestVersionBuilder();
// TextView tvTitle = baseDialog.findViewById(R.id.tv_title);
baseDialog.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean forceRedownload = request.isForceRedownload();
if (forceRedownload){
ToastUtils.showToast(context,"请更新版本");
}else{
baseDialog.cancel();
baseDialog.dismiss();
AllenVersionChecker.getInstance().cancelAllMission();
}
}
});
// textView.setText(versionBundle.getContent());
textView.setText(versionBundle.getContent());
baseDialog.setCanceledOnTouchOutside(request.isForceRedownload()?false:true);
baseDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (KeyEvent.KEYCODE_BACK==event.getKeyCode()&&request.isForceRedownload()){
ToastUtils.showToast(context,"请更新版本");
return true;
}
return false;
}
});
baseDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
}
});
return baseDialog;
};
}
/**
* 自定义下载中对话框,下载中会连续回调此方法 updateUI
* 务必用库传回来的context 实例化你的dialog
*
* @param ctx
* @return
*/
private CustomDownloadingDialogListener createCustomDownloadingDialog(Context ctx) {
return new CustomDownloadingDialogListener() {
@Override
public Dialog getCustomDownloadingDialog(Context context, int progress, UIData versionBundle) {
VersionDialog baseDialog = new VersionDialog(context, R.style.BaseDialog, R.layout.dialog_download_layout);
return baseDialog;
}
@Override
public void updateUI(Dialog dialog, int progress, UIData versionBundle) {
TextView tvProgress = dialog.findViewById(R.id.tv_progress);
ProgressBar progressBar = dialog.findViewById(R.id.pb);
progressBar.setProgress(progress);
tvProgress.setText(ctx.getString(R.string.versionchecklib_progress, progress));
}
};
}
// private NotificationBuilder createCustomNotification(Context ctx) {
// return NotificationBuilder.create()
// .setRingtone(true)
// .setIcon(R.mipmap.)
// .setTicker("custom_ticker")
// .setContentTitle("custom title")
// .setContentText(ctx.getString(R.string.custom_content_text));
// }
}
@@ -1,53 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="300dp"
android:layout_height="381dp"
android:background="@drawable/version_top_bg"
android:orientation="vertical">
<TextView
android:layout_weight="1"
android:id="@+id/tv_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="200dp"
android:layout_marginRight="50dp"
android:nestedScrollingEnabled="true"
android:scrollbars="vertical"
android:text="SL会计法士大夫撒离开尽量快点撒发了喀什角SL会计法士大夫撒离开尽量快点撒发了喀什角SL会计法士大夫撒离开尽量快点撒发了喀什角SL会计法士大夫撒离开尽量快点撒发了喀什角动量反馈阿斯利康大家分厘卡士大夫刻录机阿斯利康的飞机流口水克拉斯JFK垃圾啊收到了开发"
android:textColor="@color/colorBlack0"
android:textSize="@dimen/text_14sp" />
<Button
android:id="@id/versionchecklib_version_dialog_commit"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/shape_bind_phone_background"
android:text="立即更新"
android:textColor="@android:color/white" />
</LinearLayout>
<ImageView
android:id="@+id/close"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="26dp"
android:background="@drawable/error" />
</LinearLayout>
@@ -1,75 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:gravity="center"
android:orientation="vertical">
<RelativeLayout
android:layout_width="300dp"
android:layout_height="217dp">
<ImageView
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="@drawable/update_head"
></ImageView>
<TextView
android:id="@+id/tvVersion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="版本号"
android:gravity="center"
android:textSize="18dp"
android:textStyle="bold"
android:textColor="@color/black"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
></TextView>
<ImageView
android:id="@+id/close"
android:layout_alignParentRight="true"
android:layout_marginTop="48dp"
android:layout_marginRight="14dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/diss"
></ImageView>
</RelativeLayout>
<LinearLayout
android:layout_width="300dp"
android:layout_height="wrap_content"
android:minHeight="120dp"
android:gravity="center"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:orientation="vertical"
android:background="@drawable/shape_bottom_bgw16">
<TextView
android:gravity="center_vertical"
android:id="@+id/tv_msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="120dp"
android:maxHeight="220dp"
android:text=""
android:textColor="@color/colorBlack6"
android:textSize="@dimen/text_14sp"
></TextView>
<Button
android:id="@id/versionchecklib_version_dialog_commit"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"
android:background="@drawable/shape_log_btn_bg22"
android:text="立即更新"
android:textColor="@android:color/white" />
</LinearLayout>
</LinearLayout>
@@ -1,39 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="20dp">
<androidx.core.widget.ContentLoadingProgressBar
android:id="@+id/pb"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="15dp"
android:max="100"
android:progress="0"
android:progressDrawable="@drawable/progressbar_horizontal" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/versionchecklib_downloading"
android:textColor="@color/versionchecklib_theme_color"
android:textSize="15sp" />
<TextView
android:id="@+id/tv_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="@string/versionchecklib_progress"
android:textColor="@color/versionchecklib_theme_color"
android:textSize="15sp" />
</RelativeLayout>
</LinearLayout>