poi上报功能开发
This commit is contained in:
@@ -5,6 +5,7 @@ import com.navinfo.outdoor.fragment.FindFragment;
|
||||
import com.navinfo.outdoor.fragment.MineFragment;
|
||||
import com.navinfo.outdoor.fragment.RecordFragment;
|
||||
import com.navinfo.outdoor.fragment.TreasureFragment;
|
||||
import com.navinfo.outdoor.util.BackHandlerHelper;
|
||||
import com.navinfo.outdoor.util.NoSlideViewPager;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
@@ -40,6 +41,7 @@ public class HomeActivity extends BaseActivity{
|
||||
protected void initView() {
|
||||
super.initView();
|
||||
ImmersionBar.with(this)
|
||||
.navigationBarColor(R.color.tipTextColor)
|
||||
.statusBarDarkFont(true, 0.2f)
|
||||
//原理:如果当前设备支持状态栏字体变色,会设置状态栏字体为黑色,如果当前设备不支持状态栏字体变色,会使当前状态栏加上透明度,否则不执行透明度
|
||||
.init();
|
||||
@@ -98,4 +100,11 @@ public class HomeActivity extends BaseActivity{
|
||||
img_title.setImageResource(image);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (!BackHandlerHelper.handleBackPress(this)) {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.navinfo.outdoor.activity;
|
||||
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import android.Manifest;
|
||||
@@ -9,9 +8,10 @@ import android.content.Intent;
|
||||
import android.os.CountDownTimer;
|
||||
|
||||
import com.navinfo.outdoor.R;
|
||||
import com.navinfo.outdoor.api.Constant;
|
||||
import com.navinfo.outdoor.base.BaseActivity;
|
||||
import com.kongzue.dialog.util.DialogSettings;
|
||||
import com.navinfo.outdoor.util.BackHandlerHelper;
|
||||
import com.navinfo.outdoor.util.PermissionUtil;
|
||||
|
||||
/**
|
||||
* 启动页
|
||||
@@ -54,14 +54,12 @@ public class MainActivity extends BaseActivity {
|
||||
Manifest.permission.READ_PHONE_STATE,
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION
|
||||
};
|
||||
ActivityCompat.requestPermissions(this, pers, Constant.PERMISSION_REQUEST_CODE);
|
||||
PermissionUtil.getInstance().checkPermission(this, pers, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable @org.jetbrains.annotations.Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
super.initView();
|
||||
|
||||
@@ -142,7 +142,6 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene
|
||||
long callbackTime = System.currentTimeMillis();
|
||||
captureTime = callbackTime - 300;
|
||||
Log.d("captureTime", captureTime + "");
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
@@ -187,7 +186,6 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene
|
||||
@Override
|
||||
protected void initData() {
|
||||
super.initData();
|
||||
|
||||
camera.setMode(Mode.VIDEO);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
package com.navinfo.outdoor.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowInsets;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.navinfo.outdoor.R;
|
||||
import com.navinfo.outdoor.bean.PoiBean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* poi 适配器
|
||||
*/
|
||||
public class PoiRecycleAdapter extends RecyclerView.Adapter<PoiRecycleAdapter.MyViewHolder> {
|
||||
private Context context;
|
||||
private List<PoiBean> list;
|
||||
|
||||
public PoiRecycleAdapter(Context context, List<PoiBean> list) {
|
||||
this.context = context;
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
|
||||
context).inflate(R.layout.item_poi, parent,
|
||||
false));
|
||||
return holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(MyViewHolder holder, final int position) {
|
||||
PoiBean poiBean = list.get(position);
|
||||
holder.tvPhone.setText(poiBean.getName());
|
||||
holder.image.setImageResource(poiBean.getImage());
|
||||
holder.image.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (initPoiClick != null) {
|
||||
initPoiClick.item(position);
|
||||
}
|
||||
}
|
||||
});
|
||||
holder.editPhoneNumber.addTextChangedListener(new TextWatcher() {
|
||||
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
//正在输入
|
||||
String str = holder.editPhoneNumber.getText().toString().trim();
|
||||
if(str.indexOf('1')==0){
|
||||
holder.llPoi.setVisibility(View.GONE);
|
||||
}else {
|
||||
holder.llPoi.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
//输入之前
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
String str = holder.editPhoneNumber.getText().toString().trim();
|
||||
if (initPoiEditClick!=null){
|
||||
initPoiEditClick.item(null,str,position);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
// 添加数据
|
||||
public void addData(PoiBean poiBean) {
|
||||
// 在list中添加数据,并通知条目加入一条
|
||||
list.add(poiBean);
|
||||
//添加动画
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
// 删除数据
|
||||
public void removeData(int position) {
|
||||
list.remove(position);
|
||||
//删除动画
|
||||
notifyItemRemoved(position);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* ViewHolder的类,用于缓存控件
|
||||
*/
|
||||
class MyViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView tvPhone;
|
||||
EditText editPhone, editPhoneNumber;
|
||||
ImageView image;
|
||||
LinearLayout llPoi;
|
||||
|
||||
//因为删除有可能会删除中间条目,然后会造成角标越界,所以必须整体刷新一下!
|
||||
public MyViewHolder(View view) {
|
||||
super(view);
|
||||
tvPhone = view.findViewById(R.id.tv_phone);
|
||||
editPhone = view.findViewById(R.id.edit_phone);
|
||||
llPoi = view.findViewById(R.id.ll_poi);
|
||||
editPhoneNumber = view.findViewById(R.id.edit_phone_number);
|
||||
image = view.findViewById(R.id.image);
|
||||
}
|
||||
}
|
||||
|
||||
initPoiClick initPoiClick;
|
||||
|
||||
public void setInitPoiClick(PoiRecycleAdapter.initPoiClick initPoiClick) {
|
||||
this.initPoiClick = initPoiClick;
|
||||
}
|
||||
|
||||
public interface initPoiClick {
|
||||
void item(int aInt);
|
||||
}
|
||||
initPoiEditClick initPoiEditClick;
|
||||
|
||||
public void setInitPoiEditClick(PoiRecycleAdapter.initPoiEditClick initPoiEditClick) {
|
||||
this.initPoiEditClick = initPoiEditClick;
|
||||
}
|
||||
|
||||
public interface initPoiEditClick {
|
||||
void item(String area,String data,int aInt);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ public class Constant {
|
||||
public static final String BASE_FOLDER = SdkFolderCreate.getSDPath()+"/navinfoOutDoor";
|
||||
// 保存图片的目录
|
||||
public static final String PICTURE_FOLDER = BASE_FOLDER+"/picture";
|
||||
public static final String PoiDao = BASE_FOLDER+"/poi";
|
||||
// 申请权限的RequestCode
|
||||
public static final int PERMISSION_REQUEST_CODE = 0x100;
|
||||
|
||||
@@ -31,8 +32,20 @@ public class Constant {
|
||||
|
||||
|
||||
|
||||
//message word 值
|
||||
public static final int TREASURE_FRAGMENT = 100;
|
||||
public static final int TREASURE_WORD_0 = 0;
|
||||
public static final int TREASURE_WORD_1 = 1;
|
||||
public static final int POI_WORD_2 = 2;
|
||||
public static final int POI_WORD_3 = 3;
|
||||
|
||||
/**
|
||||
* 用户当前位置
|
||||
*/
|
||||
public static TencentLocation currentLocation;
|
||||
public static TencentLocation markerCurrentLocation;
|
||||
public static double markerLatitude;
|
||||
|
||||
public static double markerLongitude;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.navinfo.outdoor.base;
|
||||
|
||||
import android.os.Message;
|
||||
|
||||
import com.navinfo.outdoor.api.Constant;
|
||||
import com.navinfo.outdoor.util.FragmentBackHandler;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
public abstract class BaseDialogFragment extends BaseFragment {
|
||||
@Override
|
||||
public void initEvent() {
|
||||
super.initEvent();
|
||||
// 监听到返回按钮点击事件
|
||||
Message obtain = Message.obtain();
|
||||
obtain.what= Constant.TREASURE_FRAGMENT;
|
||||
obtain.obj=true;
|
||||
EventBus.getDefault().post(obtain);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
// 监听到返回按钮点击事件
|
||||
Message obtain = Message.obtain();
|
||||
obtain.what= Constant.TREASURE_FRAGMENT;
|
||||
obtain.obj=false;
|
||||
EventBus.getDefault().post(obtain);
|
||||
}
|
||||
}
|
||||
@@ -13,18 +13,23 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.navinfo.outdoor.util.BackHandlerHelper;
|
||||
import com.navinfo.outdoor.util.FragmentBackHandler;
|
||||
|
||||
|
||||
public abstract class BaseFragment extends Fragment {
|
||||
public abstract class BaseFragment extends Fragment implements FragmentBackHandler {
|
||||
|
||||
private AlertDialog alertDialog;
|
||||
|
||||
public View mView;
|
||||
protected FragmentManager supportFragmentManager;
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View mView= LayoutInflater.from(getActivity()).inflate(getLayout(), container, false);
|
||||
mView = LayoutInflater.from(getActivity()).inflate(getLayout(), container, false);
|
||||
return mView;
|
||||
|
||||
}
|
||||
@@ -34,8 +39,17 @@ public abstract class BaseFragment extends Fragment {
|
||||
initMvp();
|
||||
initData();
|
||||
initView();
|
||||
initEvent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBackPressed() {
|
||||
getActivity().getSupportFragmentManager().popBackStack();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void initEvent(){}
|
||||
|
||||
protected <T extends View> T findViewById(@IdRes int id){
|
||||
return getView().findViewById(id);
|
||||
}
|
||||
@@ -78,5 +92,6 @@ public abstract class BaseFragment extends Fragment {
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
47
app/src/main/java/com/navinfo/outdoor/bean/Info.java
Normal file
47
app/src/main/java/com/navinfo/outdoor/bean/Info.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package com.navinfo.outdoor.bean;
|
||||
|
||||
public class Info {
|
||||
/**
|
||||
* photo :
|
||||
* x :
|
||||
* y :
|
||||
* t :
|
||||
*/
|
||||
|
||||
private String photo;
|
||||
private String x;
|
||||
private String y;
|
||||
private String t;
|
||||
|
||||
public String getPhoto() {
|
||||
return photo;
|
||||
}
|
||||
|
||||
public void setPhoto(String photo) {
|
||||
this.photo = photo;
|
||||
}
|
||||
|
||||
public String getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(String x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public String getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(String y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public String getT() {
|
||||
return t;
|
||||
}
|
||||
|
||||
public void setT(String t) {
|
||||
this.t = t;
|
||||
}
|
||||
}
|
||||
37
app/src/main/java/com/navinfo/outdoor/bean/PoiBean.java
Normal file
37
app/src/main/java/com/navinfo/outdoor/bean/PoiBean.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package com.navinfo.outdoor.bean;
|
||||
|
||||
public class PoiBean {
|
||||
String name;
|
||||
String phone;
|
||||
int image;
|
||||
|
||||
public PoiBean(String name, String phone, int image) {
|
||||
this.name = name;
|
||||
this.phone = phone;
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public int getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(int image) {
|
||||
this.image = image;
|
||||
}
|
||||
}
|
||||
@@ -2,79 +2,249 @@ package com.navinfo.outdoor.fragment;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Matrix;
|
||||
import android.media.ExifInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.kongzue.dialog.interfaces.OnDialogButtonClickListener;
|
||||
import com.kongzue.dialog.util.BaseDialog;
|
||||
import com.kongzue.dialog.util.DialogSettings;
|
||||
import com.kongzue.dialog.v3.MessageDialog;
|
||||
import com.navinfo.outdoor.R;
|
||||
import com.navinfo.outdoor.base.BaseFragment;
|
||||
import com.tencent.tencentmap.mapsdk.maps.MapView;
|
||||
import com.tencent.tencentmap.mapsdk.maps.TencentMap;
|
||||
import com.navinfo.outdoor.activity.FragmentManagement;
|
||||
import com.navinfo.outdoor.adapter.PoiRecycleAdapter;
|
||||
import com.navinfo.outdoor.api.Constant;
|
||||
import com.navinfo.outdoor.base.BaseDialogFragment;
|
||||
import com.navinfo.outdoor.bean.PoiBean;
|
||||
import com.navinfo.outdoor.room.PoiDao;
|
||||
import com.navinfo.outdoor.room.PoiDatabase;
|
||||
import com.navinfo.outdoor.room.PoiEntity;
|
||||
import com.navinfo.outdoor.util.BackHandlerHelper;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
|
||||
/**
|
||||
* 记录的Fragment
|
||||
* 2021-5-25
|
||||
*/
|
||||
public class PoiFragment extends BaseFragment implements View.OnClickListener {
|
||||
public class PoiFragment extends BaseDialogFragment implements View.OnClickListener {
|
||||
|
||||
private EditText editDescribe;
|
||||
private ImageView imagePanorama;
|
||||
private ImageView imageName;
|
||||
private ImageView imageInternalPhotos;
|
||||
private ImageView imageCard;
|
||||
private ImageView imageElse;
|
||||
private RelativeLayout rlPanorama, rlName, rlInternalPhotos, rlCard, rlElse;
|
||||
private TextView tvExplain;
|
||||
private ImageView ivPanorama,ivName,ivInternal,ivCard,ivElse;
|
||||
private TextView tvExamine;
|
||||
private EditText editNameContent;
|
||||
private RecyclerView recyclerPhone;
|
||||
private PoiRecycleAdapter poiRecycleAdapter;
|
||||
private ArrayList<String> phoneData;
|
||||
private ArrayList<PoiBean> poiBeans;
|
||||
private int aInts;
|
||||
private Button btnSaveLocal;
|
||||
private Button btnUploading;
|
||||
private PoiDatabase poiDatabase;
|
||||
private PoiDao poiDao;
|
||||
|
||||
@Override
|
||||
protected int getLayout() {
|
||||
return R.layout.poi_fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if(!EventBus.getDefault().isRegistered(this)){//加上判断
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
protected void initView() {
|
||||
super.initView();
|
||||
poiDatabase = PoiDatabase.getInstance(getContext());
|
||||
poiDao = poiDatabase.getPoiDao();
|
||||
CheckBox checkBoxLife = findViewById(R.id.check_pot_life);
|
||||
CheckBox checkBoxRight = findViewById(R.id.check_pot_right);
|
||||
checkBoxLife.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
Message obtain = Message.obtain();
|
||||
obtain.what= Constant.TREASURE_WORD_0;
|
||||
obtain.obj=isChecked;
|
||||
EventBus.getDefault().post(obtain);
|
||||
}
|
||||
});
|
||||
checkBoxRight.setVisibility(View.GONE);
|
||||
btnSaveLocal = findViewById(R.id.btn_save_local);
|
||||
btnSaveLocal.setOnClickListener(this::onClick);
|
||||
btnUploading = findViewById(R.id.btn_uploading);
|
||||
btnUploading.setOnClickListener(this::onClick);
|
||||
editNameContent = findViewById(R.id.tv_name_content);
|
||||
tvExamine = findViewById(R.id.tv_examine);
|
||||
tvExamine.setOnClickListener(this::onClick);
|
||||
editDescribe = findViewById(R.id.edit_describe);
|
||||
imagePanorama = findViewById(R.id.image_panorama);
|
||||
imagePanorama.setOnClickListener(this::onClick);
|
||||
imageName = findViewById(R.id.image_name);
|
||||
imageName.setOnClickListener(this::onClick);
|
||||
imageInternalPhotos = findViewById(R.id.image_internal_photos);
|
||||
imageInternalPhotos.setOnClickListener(this::onClick);
|
||||
imageCard = findViewById(R.id.image_card);
|
||||
imageCard.setOnClickListener(this::onClick);
|
||||
imageElse = findViewById(R.id.image_else);
|
||||
imageElse.setOnClickListener(this::onClick);
|
||||
tvExplain = findViewById(R.id.tv_explain);
|
||||
ivPanorama = findViewById(R.id.iv_panorama);
|
||||
ivName = findViewById(R.id.iv_name);
|
||||
ivInternal = findViewById(R.id.iv_internal);
|
||||
ivCard = findViewById(R.id.iv_card);
|
||||
ivElse = findViewById(R.id.iv_else);
|
||||
tvExplain.setOnClickListener(this::onClick);
|
||||
rlPanorama = findViewById(R.id.rl_panorama);
|
||||
rlPanorama.setOnClickListener(this::onClick);
|
||||
rlName = findViewById(R.id.rl_name);
|
||||
rlName.setOnClickListener(this::onClick);
|
||||
rlInternalPhotos = findViewById(R.id.rl_internal_photos);
|
||||
rlInternalPhotos.setOnClickListener(this::onClick);
|
||||
rlCard = findViewById(R.id.rl_card);
|
||||
rlCard.setOnClickListener(this::onClick);
|
||||
rlElse = findViewById(R.id.rl_else);
|
||||
rlElse.setOnClickListener(this::onClick);
|
||||
recyclerPhone = findViewById(R.id.recycler_phone);
|
||||
recyclerPhone.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
recyclerPhone.addItemDecoration(new DividerItemDecoration(getContext(),DividerItemDecoration.VERTICAL));
|
||||
poiBeans = new ArrayList<>();//存储对象
|
||||
phoneData = new ArrayList<>();//存储手机号
|
||||
poiBeans.add(new PoiBean("电话*","1000000",R.drawable.icon_add_bg));
|
||||
poiRecycleAdapter = new PoiRecycleAdapter(getContext(), poiBeans);
|
||||
recyclerPhone.setAdapter(poiRecycleAdapter);
|
||||
poiRecycleAdapter.setInitPoiClick(new PoiRecycleAdapter.initPoiClick() {
|
||||
@Override
|
||||
public void item(int aInt) {
|
||||
if (aInt == 0) {
|
||||
poiRecycleAdapter.addData(new PoiBean("", "100000", R.drawable.icon_del_bg));
|
||||
} else {
|
||||
poiRecycleAdapter.removeData(aInt);
|
||||
if (phoneData.size()>0){
|
||||
phoneData.remove(aInt);
|
||||
Log.d("TAG", "initView: "+phoneData.toString());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
poiRecycleAdapter.setInitPoiEditClick(new PoiRecycleAdapter.initPoiEditClick() {
|
||||
@Override
|
||||
public void item(String a,String data, int aInt) {
|
||||
if (data.length()==11){
|
||||
if (a!=null){
|
||||
phoneData.add(aInt,a+","+data);
|
||||
}else {
|
||||
phoneData.add(aInt,data);
|
||||
}
|
||||
Log.d("TAG", "initView: "+phoneData.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
@Override
|
||||
protected void initData() {
|
||||
super.initData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
// //主界面获取焦点
|
||||
// private void getFocus() {
|
||||
// getView().setFocusableInTouchMode(true);
|
||||
// getView().requestFocus();
|
||||
// getView().setOnKeyListener(new View.OnKeyListener() {
|
||||
// @Override
|
||||
// public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
// if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
//
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
getView().setFocusableInTouchMode(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
getView().setFocusableInTouchMode(false);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(Message data) {
|
||||
if (data.what==Constant.POI_WORD_2){
|
||||
String s = data.obj.toString();
|
||||
Toast.makeText(getContext(), s, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()){
|
||||
case R.id.image_panorama:
|
||||
case R.id.btn_save_local:
|
||||
case R.id.btn_uploading:
|
||||
Message obtain = Message.obtain();
|
||||
obtain.what= Constant.TREASURE_FRAGMENT;
|
||||
obtain.obj=false;
|
||||
EventBus.getDefault().post(obtain);
|
||||
PoiEntity poiEntity = new PoiEntity();
|
||||
poiDao.insertPoiEntity(poiEntity);
|
||||
break;
|
||||
case R.id.tv_examine:
|
||||
Toast.makeText(getContext(), editNameContent.getText().toString(), Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case R.id.tv_explain:
|
||||
Intent intentExplain = new Intent(getActivity(), FragmentManagement.class);
|
||||
intentExplain.putExtra("tag",7);
|
||||
startActivity(intentExplain);
|
||||
break;
|
||||
case R.id.rl_panorama:
|
||||
Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE");
|
||||
startActivityForResult(intentPanorama, 101);
|
||||
break;
|
||||
case R.id.image_name:
|
||||
case R.id.rl_name:
|
||||
Intent intentName = new Intent("android.media.action.IMAGE_CAPTURE");
|
||||
startActivityForResult(intentName, 102);
|
||||
break;
|
||||
case R.id.image_internal_photos:
|
||||
case R.id.rl_internal_photos:
|
||||
Intent intentInternal = new Intent("android.media.action.IMAGE_CAPTURE");
|
||||
startActivityForResult(intentInternal, 103);
|
||||
break;
|
||||
case R.id.image_card:
|
||||
case R.id.rl_card:
|
||||
Intent intentCard = new Intent("android.media.action.IMAGE_CAPTURE");
|
||||
startActivityForResult(intentCard, 104);
|
||||
break;
|
||||
case R.id.image_else:
|
||||
case R.id.rl_else:
|
||||
Intent intentElse = new Intent("android.media.action.IMAGE_CAPTURE");
|
||||
startActivityForResult(intentElse, 105);
|
||||
break;
|
||||
@@ -86,23 +256,153 @@ public class PoiFragment extends BaseFragment implements View.OnClickListener {
|
||||
if (requestCode == 101 && resultCode == RESULT_OK) {
|
||||
Bundle extras = data.getExtras();//从Intent中获取附加值
|
||||
Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像
|
||||
imagePanorama.setImageBitmap(bitmap);//显示图像
|
||||
int height= bitmap.getHeight();
|
||||
int width= bitmap.getWidth();
|
||||
if (height>width){
|
||||
DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
|
||||
MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照,要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() {
|
||||
@Override
|
||||
public boolean onClick(BaseDialog baseDialog, View v) {
|
||||
Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE");
|
||||
startActivityForResult(intentPanorama, 101);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}else {
|
||||
ivPanorama.setImageBitmap(bitmap);//显示图像
|
||||
}
|
||||
|
||||
} else if (requestCode == 102 && resultCode == RESULT_OK) {
|
||||
Bundle extras = data.getExtras();//从Intent中获取附加值
|
||||
Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像
|
||||
imageName.setImageBitmap(bitmap);//显示图像
|
||||
int height= bitmap.getHeight();
|
||||
int width= bitmap.getWidth();
|
||||
if (height>width){
|
||||
DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
|
||||
MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照,要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() {
|
||||
@Override
|
||||
public boolean onClick(BaseDialog baseDialog, View v) {
|
||||
Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE");
|
||||
startActivityForResult(intentPanorama, 102);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}else {
|
||||
ivName.setImageBitmap(bitmap);//显示图像
|
||||
}
|
||||
|
||||
}else if (requestCode == 103 && resultCode == RESULT_OK) {
|
||||
Bundle extras = data.getExtras();//从Intent中获取附加值
|
||||
Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像
|
||||
imageInternalPhotos.setImageBitmap(bitmap);//显示图像
|
||||
int height= bitmap.getHeight();
|
||||
int width= bitmap.getWidth();
|
||||
if (height>width){
|
||||
DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
|
||||
MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照,要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() {
|
||||
@Override
|
||||
public boolean onClick(BaseDialog baseDialog, View v) {
|
||||
Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE");
|
||||
startActivityForResult(intentPanorama, 103);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}else {
|
||||
ivInternal.setImageBitmap(bitmap);//显示图像
|
||||
}
|
||||
}else if (requestCode == 104 && resultCode == RESULT_OK) {
|
||||
Bundle extras = data.getExtras();//从Intent中获取附加值
|
||||
Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像
|
||||
imageCard.setImageBitmap(bitmap);//显示图像
|
||||
int height= bitmap.getHeight();
|
||||
int width= bitmap.getWidth();
|
||||
if (height>width){
|
||||
DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
|
||||
MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照,要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() {
|
||||
@Override
|
||||
public boolean onClick(BaseDialog baseDialog, View v) {
|
||||
Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE");
|
||||
startActivityForResult(intentPanorama, 104);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}else {
|
||||
ivCard.setImageBitmap(bitmap);//显示图像
|
||||
}
|
||||
}else if (requestCode == 105 && resultCode == RESULT_OK) {
|
||||
Bundle extras = data.getExtras();//从Intent中获取附加值
|
||||
Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像
|
||||
imageElse.setImageBitmap(bitmap);//显示图像
|
||||
int height= bitmap.getHeight();
|
||||
int width= bitmap.getWidth();
|
||||
if (height>width){
|
||||
DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
|
||||
MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照,要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() {
|
||||
@Override
|
||||
public boolean onClick(BaseDialog baseDialog, View v) {
|
||||
Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE");
|
||||
startActivityForResult(intentPanorama, 105);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}else {
|
||||
ivElse.setImageBitmap(bitmap);//显示图像
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public static int readPictureDegree(String path) {
|
||||
int degree = 0;
|
||||
try {
|
||||
ExifInterface exifInterface = new ExifInterface(path);
|
||||
int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
|
||||
ExifInterface.ORIENTATION_NORMAL);
|
||||
switch (orientation) {
|
||||
case ExifInterface.ORIENTATION_ROTATE_90:
|
||||
degree = 90;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_180:
|
||||
degree = 180;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_270:
|
||||
degree = 270;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return degree;
|
||||
}
|
||||
|
||||
public static Bitmap rotateBitmapByDegree(Bitmap bm, int degree) {
|
||||
if (bm == null) {
|
||||
return null;
|
||||
}
|
||||
Bitmap returnBm = null;
|
||||
|
||||
// 根据旋转角度,生成旋转矩阵
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postRotate(degree);
|
||||
try {
|
||||
// 将原始图片按照旋转矩阵进行旋转,并得到新的图片
|
||||
returnBm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
|
||||
bm.getHeight(), matrix, true);
|
||||
} catch (OutOfMemoryError e) {
|
||||
}
|
||||
if (returnBm == null) {
|
||||
returnBm = bm;
|
||||
}
|
||||
if (bm != returnBm) {
|
||||
bm.recycle();
|
||||
}
|
||||
return returnBm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if (EventBus.getDefault().isRegistered(this))//加上判断
|
||||
EventBus.getDefault().unregister(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.navinfo.outdoor.fragment;
|
||||
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import com.navinfo.outdoor.R;
|
||||
import com.navinfo.outdoor.base.BaseFragment;
|
||||
|
||||
@@ -8,6 +11,8 @@ import com.navinfo.outdoor.base.BaseFragment;
|
||||
* 2021-5-25
|
||||
*/
|
||||
public class RecordFragment extends BaseFragment {
|
||||
|
||||
|
||||
@Override
|
||||
protected int getLayout() {
|
||||
return R.layout.record_fragment;
|
||||
@@ -15,16 +20,8 @@ public class RecordFragment extends BaseFragment {
|
||||
@Override
|
||||
protected void initView() {
|
||||
super.initView();
|
||||
|
||||
}
|
||||
//界面可见时再加载数据
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if (isVisibleToUser) {
|
||||
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void initData() {
|
||||
super.initData();
|
||||
|
||||
@@ -17,9 +17,6 @@ import com.navinfo.outdoor.R;
|
||||
import com.navinfo.outdoor.activity.PictureActivity;
|
||||
import com.navinfo.outdoor.api.Constant;
|
||||
import com.navinfo.outdoor.base.BaseFragment;
|
||||
import com.otaliastudios.cameraview.size.AspectRatio;
|
||||
import com.otaliastudios.cameraview.size.SizeSelectors;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
@@ -59,12 +56,10 @@ public class RoadFragment extends BaseFragment implements View.OnClickListener {
|
||||
case R.id.et_height:
|
||||
String ssss = etHeight.getText().toString();
|
||||
if (ssss != null && !ssss.isEmpty()) {
|
||||
//
|
||||
Intent intent = new Intent(getContext(), PictureActivity.class);
|
||||
// PictureActivity activity = (PictureActivity) getActivity();
|
||||
// activity.
|
||||
intent.putExtra("pic", etHeight.getText().toString());
|
||||
Log.d("TAG", "onClick: jjjjjj"+etHeight.getText()+"");
|
||||
startActivity(intent);
|
||||
} else {
|
||||
Toast.makeText(getContext(), "不能为空", Toast.LENGTH_SHORT).show();
|
||||
|
||||
@@ -7,14 +7,19 @@ import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Point;
|
||||
import android.location.Location;
|
||||
import android.os.Build;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -23,15 +28,22 @@ import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import com.kongzue.dialog.interfaces.OnBackClickListener;
|
||||
import com.kongzue.dialog.interfaces.OnShowListener;
|
||||
import com.kongzue.dialog.util.BaseDialog;
|
||||
import com.kongzue.dialog.util.DialogSettings;
|
||||
import com.kongzue.dialog.v3.ShareDialog;
|
||||
import com.navinfo.outdoor.R;
|
||||
import com.navinfo.outdoor.activity.FragmentManagement;
|
||||
import com.navinfo.outdoor.api.Constant;
|
||||
import com.navinfo.outdoor.base.BaseFragment;
|
||||
import com.navinfo.outdoor.util.BackHandlerHelper;
|
||||
import com.navinfo.outdoor.util.NetWorkUtils;
|
||||
import com.navinfo.outdoor.util.PermissionUtil;
|
||||
import com.navinfo.outdoor.util.ToastUtil;
|
||||
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
|
||||
import com.tencent.map.geolocation.TencentLocation;
|
||||
import com.tencent.map.geolocation.TencentLocationListener;
|
||||
import com.tencent.map.geolocation.TencentLocationManager;
|
||||
@@ -42,12 +54,19 @@ import com.tencent.tencentmap.mapsdk.maps.LocationSource;
|
||||
import com.tencent.tencentmap.mapsdk.maps.MapView;
|
||||
import com.tencent.tencentmap.mapsdk.maps.TencentMap;
|
||||
import com.tencent.tencentmap.mapsdk.maps.UiSettings;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.AlphaAnimation;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.Animation;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.Marker;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -70,22 +89,36 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
private ImageView ivLocation;
|
||||
private ImageView ivSubmit;
|
||||
private ImageView ivRefish;
|
||||
private SlidingUpPanelLayout sliding_layout;
|
||||
private FragmentTransaction fragmentTransaction;
|
||||
private PoiFragment poiFragment;
|
||||
private Marker marker;
|
||||
|
||||
private CheckBox cbFootType;
|
||||
private ImageView ivFilter;
|
||||
private Point screenPosition; //marker的屏幕坐标
|
||||
private RoadFragment roadFragment;
|
||||
|
||||
@Override
|
||||
protected int getLayout() {
|
||||
return R.layout.treasure_fragment;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
super.initView();
|
||||
EventBus.getDefault().register(this);
|
||||
sliding_layout = findViewById(R.id.sliding_layout);
|
||||
ivRefish = findViewById(R.id.iv_refrish);
|
||||
ivRefish.setOnClickListener(this::onClick);
|
||||
ivFilter = findViewById(R.id.iv_filter);
|
||||
ivSubmit = findViewById(R.id.iv_submit);
|
||||
ivSubmit.setOnClickListener(this::onClick);
|
||||
treasureMap = (MapView) findViewById(R.id.treasure_map);
|
||||
tencentMap = treasureMap.getMap();
|
||||
cbMapType = (CheckBox) findViewById(R.id.cb_map_type);
|
||||
cbFootType = (CheckBox) findViewById(R.id.cb_foot_type);
|
||||
//地图转换
|
||||
cbMapType.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
@@ -116,8 +149,100 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
uiSettings.setLogoScale(0.7f);
|
||||
//开启定位权限
|
||||
checkNetWork();
|
||||
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(Message data) {
|
||||
if (data.what==Constant.TREASURE_WORD_0){
|
||||
initPoiMarker(Boolean.valueOf((Boolean) data.obj));
|
||||
|
||||
}else if (data.what==Constant.TREASURE_FRAGMENT){
|
||||
if ((boolean)data.obj){
|
||||
ivZoomAdd.setVisibility(View.GONE);
|
||||
ivZoomDel.setVisibility(View.GONE);
|
||||
ivLocation.setVisibility(View.GONE);
|
||||
ivRefish.setVisibility(View.GONE);
|
||||
cbMapType.setVisibility(View.GONE);
|
||||
cbFootType.setVisibility(View.GONE);
|
||||
ivSubmit.setVisibility(View.GONE);
|
||||
ivFilter.setVisibility(View.GONE);
|
||||
}else {
|
||||
ivZoomAdd.setVisibility(View.VISIBLE);
|
||||
ivZoomDel.setVisibility(View.VISIBLE);
|
||||
ivLocation.setVisibility(View.VISIBLE);
|
||||
ivRefish.setVisibility(View.VISIBLE);
|
||||
cbMapType.setVisibility(View.VISIBLE);
|
||||
cbFootType.setVisibility(View.VISIBLE);
|
||||
ivSubmit.setVisibility(View.VISIBLE);
|
||||
ivFilter.setVisibility(View.VISIBLE);
|
||||
|
||||
sliding_layout.setPanelHeight(0);
|
||||
sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN);
|
||||
if (poiFragment!=null){
|
||||
fragmentTransaction.hide(poiFragment);
|
||||
}
|
||||
if (roadFragment!=null){
|
||||
fragmentTransaction.hide(roadFragment);
|
||||
}
|
||||
if (marker!=null){
|
||||
marker.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void initPoiMarker(Boolean t) {
|
||||
if (t == true) {
|
||||
//移动地图
|
||||
CameraUpdate cameraSigma =
|
||||
CameraUpdateFactory.newCameraPosition(new CameraPosition(
|
||||
new LatLng(Constant.markerLatitude, Constant.markerLongitude), //中心点坐标,地图目标经纬度
|
||||
tencentMap.getCameraPosition().zoom, //目标缩放级别
|
||||
tencentMap.getCameraPosition().tilt, //目标倾斜角[0.0 ~ 45.0] (垂直地图时为0)
|
||||
tencentMap.getCameraPosition().bearing)); //目标旋转角 0~360° (正北方为0)
|
||||
tencentMap.animateCamera(cameraSigma, new TencentMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onFinish() {
|
||||
screenPosition = tencentMap.getProjection().toScreenLocation(new LatLng(Constant.markerLatitude, Constant.markerLongitude));
|
||||
sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
|
||||
//创建Marker对象之前,设置属性
|
||||
LatLng position = new LatLng(Constant.markerLatitude, Constant.markerLongitude);
|
||||
marker = tencentMap.addMarker(new MarkerOptions(position));
|
||||
marker.setFixingPoint(screenPosition.x, screenPosition.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (screenPosition != null) {
|
||||
sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
|
||||
LatLng latLng = tencentMap.getProjection().fromScreenLocation(screenPosition);
|
||||
marker.setPosition(latLng);
|
||||
marker.setFixingPointEnable(false);
|
||||
Constant.markerLatitude = latLng.latitude;
|
||||
Constant.markerLongitude = latLng.longitude;
|
||||
Message obtain = Message.obtain();
|
||||
obtain.what=Constant.POI_WORD_2;
|
||||
obtain.obj=Constant.markerLatitude + " " + Constant.markerLongitude;
|
||||
EventBus.getDefault().post(obtain);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public boolean onBackPressed() {
|
||||
//
|
||||
// return BackHandlerHelper.handleBackPress(supportFragmentManager);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 设置定位图标样式
|
||||
*/
|
||||
@@ -145,14 +270,13 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
//创建定位请求
|
||||
locationRequest = TencentLocationRequest.create();
|
||||
//设置定位周期(位置监听器回调周期)为3s
|
||||
// locationRequest.setInterval(3000);
|
||||
// locationRequest.setInterval(3000);
|
||||
//地图上设置定位数据源
|
||||
tencentMap.setLocationSource(this);
|
||||
//设置当前位置可见
|
||||
tencentMap.setMyLocationEnabled(true);
|
||||
//设置定位图标样式
|
||||
setLocMarkerStyle();
|
||||
// locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);
|
||||
tencentMap.setMyLocationStyle(locationStyle);
|
||||
}
|
||||
|
||||
@@ -203,6 +327,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
treasureMap.onDestroy();
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -217,7 +342,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
tencentMap.animateCamera(cameraUpdateOut);
|
||||
break;
|
||||
case R.id.iv_location://定位:
|
||||
if (Constant.currentLocation!=null){
|
||||
if (Constant.currentLocation != null) {
|
||||
Constant.currentLocation.getLongitude();
|
||||
CameraUpdate cameraSigma =
|
||||
CameraUpdateFactory.newCameraPosition(new CameraPosition(
|
||||
@@ -226,15 +351,15 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
0, //目标倾斜角[0.0 ~ 45.0] (垂直地图时为0)
|
||||
0)); //目标旋转角 0~360° (正北方为0)
|
||||
tencentMap.animateCamera(cameraSigma);
|
||||
}else {
|
||||
} else {
|
||||
Toast.makeText(getActivity(), "无定位", Toast.LENGTH_SHORT).show();
|
||||
checkNetWork();
|
||||
}
|
||||
|
||||
break;
|
||||
case R.id.iv_submit://弹窗
|
||||
//分享
|
||||
CharSequence title = "请选择上报类型";
|
||||
CharSequence title = "请选择上报类型";
|
||||
DialogSettings.style = DialogSettings.STYLE.STYLE_MIUI;
|
||||
List<ShareDialog.Item> itemList = new ArrayList<>();
|
||||
itemList.add(new ShareDialog.Item(getContext(), R.drawable.push_poi, "POI"));
|
||||
itemList.add(new ShareDialog.Item(getContext(), R.drawable.push_road, "道路"));
|
||||
@@ -243,20 +368,28 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
ShareDialog.show((AppCompatActivity) getActivity(), itemList, new ShareDialog.OnItemClickListener() {
|
||||
@Override
|
||||
public boolean onClick(ShareDialog shareDialog, int index, ShareDialog.Item item) {
|
||||
switch (index){
|
||||
supportFragmentManager = getActivity().getSupportFragmentManager();
|
||||
fragmentTransaction = supportFragmentManager.beginTransaction();
|
||||
poiFragment = new PoiFragment();
|
||||
roadFragment = new RoadFragment();
|
||||
fragmentTransaction.add(R.id.dragView, poiFragment).add(R.id.dragView,roadFragment).commit();
|
||||
switch (index) {
|
||||
case 0:
|
||||
Intent poiIntent = new Intent(getActivity(), FragmentManagement.class);
|
||||
poiIntent.putExtra("tag",27);
|
||||
startActivity(poiIntent);
|
||||
sliding_layout.setPanelHeight(1000);
|
||||
sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
|
||||
fragmentTransaction.show(poiFragment);
|
||||
fragmentTransaction.hide(roadFragment);
|
||||
fragmentTransaction.addToBackStack(null);
|
||||
break;
|
||||
case 1:
|
||||
Intent roadIntent = new Intent(getActivity(), FragmentManagement.class);
|
||||
roadIntent.putExtra("tag",28);
|
||||
startActivity(roadIntent);
|
||||
sliding_layout.setPanelHeight(1000);
|
||||
sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
|
||||
fragmentTransaction.show(roadFragment);
|
||||
fragmentTransaction.hide(poiFragment);
|
||||
fragmentTransaction.addToBackStack(null);
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
Toast.makeText(getContext(), item.getText(), Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
@@ -293,67 +426,20 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
String[] permission = {
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION
|
||||
};
|
||||
if (ContextCompat.checkSelfPermission(getContext(), permission[0]) == PackageManager.PERMISSION_GRANTED) { // 拥有权限
|
||||
//建立定位
|
||||
initLocation();
|
||||
} else { // 没有权限
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { //6.0
|
||||
requestPermissions(permission, 0);
|
||||
} else {
|
||||
// 此处为某些5.0动态权限的手机
|
||||
// goSystemLocationActivity(); // TODO =======待删除======
|
||||
tipPermissionAlertDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户授权回调
|
||||
*
|
||||
* @param requestCode
|
||||
* @param permissions
|
||||
* @param grantResults
|
||||
*/
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
UserAuthorization(requestCode, grantResults);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户授权情况
|
||||
*
|
||||
* @param requestCode
|
||||
* @param grantResults
|
||||
*/
|
||||
private void UserAuthorization(int requestCode, int[] grantResults) {
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { // 拥有了授权
|
||||
checkMyLocation();
|
||||
} else {
|
||||
tipPermissionAlertDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void tipPermissionAlertDialog() {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
builder.setTitle("提示");
|
||||
builder.setMessage(Constant.SET_LOCATION_PERMISSION);
|
||||
builder.setPositiveButton("我知道了", new DialogInterface.OnClickListener() {
|
||||
PermissionUtil.getInstance().checkPermission((AppCompatActivity) getActivity(), permission, new Runnable() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
AlertDialog alertDialog = builder.show();
|
||||
alertDialog.dismiss();
|
||||
public void run() {
|
||||
if (ContextCompat.checkSelfPermission(getContext(), permission[0]) == PackageManager.PERMISSION_GRANTED){
|
||||
//建立定位
|
||||
initLocation();
|
||||
}else {
|
||||
PermissionUtil.getInstance().showPermissionSettingDialog((AppCompatActivity) getActivity());
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转系统定位页面
|
||||
*/
|
||||
private void goSystemLocationActivity() {
|
||||
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activate(OnLocationChangedListener onLocationChangedListener) {
|
||||
@@ -398,15 +484,11 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
location.setLongitude(tencentLocation.getLongitude());
|
||||
location.setAccuracy(tencentLocation.getAccuracy());
|
||||
locationChangedListener.onLocationChanged(location);
|
||||
locationStyle = locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER);
|
||||
Constant.currentLocation = tencentLocation;
|
||||
//显示回调的实时位置信息
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//打印tencentLocation的json字符串
|
||||
// Toast.makeText(getApplicationContext(), new Gson().toJson(location), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
Constant.markerCurrentLocation = tencentLocation;
|
||||
Constant.markerLatitude = tencentLocation.getLatitude();
|
||||
Constant.markerLongitude = tencentLocation.getLongitude();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,4 +497,24 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
|
||||
//GPS, WiFi, Radio 等状态发生变化
|
||||
Log.v("State changed", s + "===" + s1);
|
||||
}
|
||||
//隐藏文字标注
|
||||
private void performPoiHide() {
|
||||
if ( tencentMap == null || tencentMap.isDestroyed()) {
|
||||
return;
|
||||
}
|
||||
tencentMap.setPoisEnabled(false);
|
||||
}
|
||||
//显示文字标注
|
||||
private void performPoiShow() {
|
||||
if (tencentMap == null || tencentMap.isDestroyed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
tencentMap.setPoisEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBackPressed() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
64
app/src/main/java/com/navinfo/outdoor/room/PoiDao.java
Normal file
64
app/src/main/java/com/navinfo/outdoor/room/PoiDao.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package com.navinfo.outdoor.room;
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Delete;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 访问数据库操作的接口
|
||||
*/
|
||||
@Dao
|
||||
public interface PoiDao {
|
||||
/**
|
||||
* 查询
|
||||
* @return
|
||||
*/
|
||||
@Query("SELECT * FROM poi")
|
||||
List<PoiEntity> getAllPoi();
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param poiEntities
|
||||
*/
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insertPoiEntity(PoiEntity... poiEntities);
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @param poiEntities
|
||||
*/
|
||||
@Update
|
||||
void updatePoiEntity(PoiEntity... poiEntities);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param poiEntities
|
||||
*/
|
||||
@Delete
|
||||
void deletePoiEntity(PoiEntity... poiEntities);
|
||||
|
||||
/**
|
||||
* 全部删除
|
||||
*/
|
||||
@Query("DELETE FROM poi")
|
||||
void deleteAllPoiEntity();
|
||||
|
||||
/**
|
||||
* 降序排列
|
||||
* @return
|
||||
*/
|
||||
@Query("SELECT * FROM poi ORDER BY ID DESC")
|
||||
List<PoiEntity> getAllPoiEntity();
|
||||
|
||||
@Query("SELECT * FROM poi where userId = :userId")
|
||||
PoiEntity queryPoiEntity(int userId);
|
||||
|
||||
@Query("DELETE FROM poi where userId = :userId")
|
||||
void deletePoiEntity(int userId);
|
||||
|
||||
}
|
||||
62
app/src/main/java/com/navinfo/outdoor/room/PoiDatabase.java
Normal file
62
app/src/main/java/com/navinfo/outdoor/room/PoiDatabase.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package com.navinfo.outdoor.room;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Database;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
import androidx.room.migration.Migration;
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase;
|
||||
|
||||
@Database(entities = {PoiEntity.class}, version = 1, exportSchema = false)
|
||||
public abstract class PoiDatabase extends RoomDatabase {
|
||||
private static final String DB_NAME = "navinfo.db";
|
||||
private static volatile PoiDatabase instance;
|
||||
|
||||
public static synchronized PoiDatabase getInstance(Context context) {
|
||||
if (instance == null) {
|
||||
instance = create(context);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private static PoiDatabase create(final Context context) {
|
||||
return Room.databaseBuilder(context, PoiDatabase.class, DB_NAME)
|
||||
.addMigrations(migration_1_2)
|
||||
.addMigrations(migration_2_3)
|
||||
.addMigrations(migration_3_4)
|
||||
.addMigrations(migration_4_5)
|
||||
.build();
|
||||
}
|
||||
|
||||
//@{版本号升级后一定要加migration
|
||||
private static Migration migration_1_2 = new Migration(1, 2) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("ALTER TABLE user ADD certify INTEGER NOT NULL DEFAULT 0");
|
||||
}
|
||||
};
|
||||
|
||||
private static Migration migration_2_3 = new Migration(2, 3) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("ALTER TABLE video_list ADD stage TEXT DEFAULT ''");
|
||||
}
|
||||
};
|
||||
private static Migration migration_3_4 = new Migration(3, 4) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("ALTER TABLE video_list ADD views INTEGER NOT NULL DEFAULT 0");
|
||||
}
|
||||
};
|
||||
private static Migration migration_4_5 = new Migration(4, 5) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("ALTER TABLE user ADD partner INTEGER NOT NULL DEFAULT 0");
|
||||
}
|
||||
};
|
||||
|
||||
public abstract PoiDao getPoiDao();
|
||||
|
||||
}
|
||||
172
app/src/main/java/com/navinfo/outdoor/room/PoiEntity.java
Normal file
172
app/src/main/java/com/navinfo/outdoor/room/PoiEntity.java
Normal file
@@ -0,0 +1,172 @@
|
||||
package com.navinfo.outdoor.room;
|
||||
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
import androidx.room.TypeConverters;
|
||||
|
||||
import com.navinfo.outdoor.bean.Info;
|
||||
import com.navinfo.outdoor.util.PhotoInfoConverter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//poi 的实体类
|
||||
@Entity(tableName = "poi")
|
||||
public class PoiEntity {
|
||||
@PrimaryKey(autoGenerate = true) // 设置主键,并且自动生长
|
||||
private int id;
|
||||
|
||||
private int pid; //采集id 保存本地或提交数据时时返回
|
||||
private int taskId;//任务id
|
||||
private int userId;//用户id
|
||||
private String createTime; //创建时间/采集时间
|
||||
private String name;//poi名称
|
||||
private String describe;//任务描述
|
||||
private String address;//poi地址
|
||||
private String telPhone;//poi电话
|
||||
private String memo;//备注
|
||||
private double precision;//金额
|
||||
private String photo;//照片信息
|
||||
//ROOM不支持直接存储集合
|
||||
@TypeConverters(PhotoInfoConverter.class)
|
||||
private List<Info> photoInfo;//照片信息
|
||||
private int existence;//是否存在
|
||||
private String x;//经度
|
||||
private String y;//纬度
|
||||
private String detail;//深度信息
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public int getTaskId() {
|
||||
return taskId;
|
||||
}
|
||||
|
||||
public void setTaskId(int taskId) {
|
||||
this.taskId = taskId;
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescribe() {
|
||||
return describe;
|
||||
}
|
||||
|
||||
public void setDescribe(String describe) {
|
||||
this.describe = describe;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getTelPhone() {
|
||||
return telPhone;
|
||||
}
|
||||
|
||||
public void setTelPhone(String telPhone) {
|
||||
this.telPhone = telPhone;
|
||||
}
|
||||
|
||||
public String getMemo() {
|
||||
return memo;
|
||||
}
|
||||
|
||||
public void setMemo(String memo) {
|
||||
this.memo = memo;
|
||||
}
|
||||
|
||||
public double getPrecision() {
|
||||
return precision;
|
||||
}
|
||||
|
||||
public void setPrecision(double precision) {
|
||||
this.precision = precision;
|
||||
}
|
||||
|
||||
public String getPhoto() {
|
||||
return photo;
|
||||
}
|
||||
|
||||
public void setPhoto(String photo) {
|
||||
this.photo = photo;
|
||||
}
|
||||
|
||||
public List<Info> getPhotoInfo() {
|
||||
return photoInfo;
|
||||
}
|
||||
|
||||
public void setPhotoInfo(List<Info> infoList) {
|
||||
this.photoInfo = infoList;
|
||||
}
|
||||
|
||||
public int getExistence() {
|
||||
return existence;
|
||||
}
|
||||
|
||||
public void setExistence(int existence) {
|
||||
this.existence = existence;
|
||||
}
|
||||
|
||||
public String getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(String x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public String getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(String y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public String getDetail() {
|
||||
return detail;
|
||||
}
|
||||
|
||||
public void setDetail(String detail) {
|
||||
this.detail = detail;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.navinfo.outdoor.util;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//监听fragment 的回退键
|
||||
public class BackHandlerHelper {
|
||||
/**
|
||||
* 将back事件分发给 FragmentManager 中管理的子Fragment,如果该 FragmentManager 中的所有Fragment都
|
||||
* 没有处理back事件,则尝试 FragmentManager.popBackStack()
|
||||
*
|
||||
* @return 如果处理了back键则返回 <b>true</b>
|
||||
* @see #handleBackPress(Fragment)
|
||||
*/
|
||||
public static boolean handleBackPress(FragmentManager fragmentManager) {
|
||||
List<Fragment> fragments = fragmentManager.getFragments();
|
||||
|
||||
if (fragments == null) return false;
|
||||
|
||||
for (int i = fragments.size() - 1; i >= 0; i--) {
|
||||
Fragment child = fragments.get(i);
|
||||
|
||||
if (isFragmentBackHandled(child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fragmentManager.getBackStackEntryCount() > 0) {
|
||||
fragmentManager.popBackStack();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean handleBackPress(Fragment fragment) {
|
||||
return handleBackPress(fragment.getChildFragmentManager());
|
||||
}
|
||||
|
||||
public static boolean handleBackPress(FragmentActivity fragmentActivity) {
|
||||
return handleBackPress(fragmentActivity.getSupportFragmentManager());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断Fragment是否处理了Back键
|
||||
*
|
||||
* @return 如果处理了back键则返回 <b>true</b>
|
||||
*/
|
||||
public static boolean isFragmentBackHandled(Fragment fragment) {
|
||||
return fragment != null
|
||||
&& fragment.isVisible()
|
||||
&& fragment.getUserVisibleHint() //for ViewPager
|
||||
&& fragment instanceof FragmentBackHandler
|
||||
&& ((FragmentBackHandler) fragment).onBackPressed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.navinfo.outdoor.util;
|
||||
//监听Fragment 的回退键
|
||||
public interface FragmentBackHandler {
|
||||
boolean onBackPressed();
|
||||
}
|
||||
176
app/src/main/java/com/navinfo/outdoor/util/PermissionUtil.java
Normal file
176
app/src/main/java/com/navinfo/outdoor/util/PermissionUtil.java
Normal file
@@ -0,0 +1,176 @@
|
||||
package com.navinfo.outdoor.util;
|
||||
|
||||
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
/**
|
||||
* 动态申请权限工具类
|
||||
*/
|
||||
public class PermissionUtil {
|
||||
|
||||
private final int PERMISSION_REQUEST_CODE = 100;
|
||||
private final int PERMISSION_SETTING_CODE = 101;
|
||||
|
||||
private AlertDialog permissionExplainDialog = null;
|
||||
private AlertDialog permissionSettingDialog = null;
|
||||
|
||||
|
||||
private PermissionUtil() {
|
||||
}
|
||||
|
||||
public static PermissionUtil getInstance() {
|
||||
return PermissionUtilHolder.instance;
|
||||
}
|
||||
|
||||
private static class PermissionUtilHolder {
|
||||
private static final PermissionUtil instance = new PermissionUtil();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 第一步,检查权限
|
||||
*
|
||||
* @param activity 上下文
|
||||
* @param permissions 权限数组
|
||||
* @param callBack 线程
|
||||
*/
|
||||
public void checkPermission(AppCompatActivity activity, String[] permissions, Runnable callBack) {
|
||||
boolean allGranted = true;
|
||||
|
||||
for (String permission : permissions) {
|
||||
int result = ContextCompat.checkSelfPermission(activity, permission);
|
||||
Log.d("检查权限:" + permission, "结果:" + result);
|
||||
|
||||
|
||||
// 有权限: PackageManager.PERMISSION_GRANTED
|
||||
// 无权限: PackageManager.PERMISSION_DENIED
|
||||
if (result != PackageManager.PERMISSION_GRANTED) {// 有权限
|
||||
allGranted = false;
|
||||
// Toast.makeText(activity, "拥有" + permission + "权限", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (allGranted) {// 拥有全部权限
|
||||
callBack.run();
|
||||
} else {// 申请权限
|
||||
startRequestPermission(activity, permissions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 第二步,如果用户之前拒绝过,展示需要权限的提示框,否则的话直接请求相关权限
|
||||
*
|
||||
* @param activity 上下文
|
||||
* @param permissions 权限数组
|
||||
*/
|
||||
private void startRequestPermission(AppCompatActivity activity, String[] permissions) {
|
||||
for (String permission : permissions) {
|
||||
/**
|
||||
* shouldShowRequestPermissionRationale
|
||||
* 如果应用之前请求过该权限但用户拒绝了该方法就会返回true
|
||||
*
|
||||
* 如果用户之前拒绝了权限请求并且勾选了权限请求对话框的”不再询问”,该方法会返回false,
|
||||
* 如果设备策略禁止该应用获得该权限也会返回false
|
||||
*/
|
||||
if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
|
||||
// 向用户显示一个解释,要以异步非阻塞的方式
|
||||
// 该线程将等待用户响应!等用户看完解释后再继续尝试请求权限
|
||||
Log.v("tag", "showPermissionExplainDialog()");
|
||||
showPermissionExplainDialog(activity, permissions);
|
||||
} else {
|
||||
/**
|
||||
* 当你的应用调用requestPermissions()方法时,系统会向用户展示一个标准对话框,
|
||||
* 你的应用不能修改也不能自定义这个对话框,如果你需要给用户一些额外的信息和解释你就需要在
|
||||
* 调用requestPermissions()之前像上面一样" 解释为什么应用需要这些权限"
|
||||
*/
|
||||
Log.v("tag", "requestPermission");
|
||||
requestPermission(activity, permissions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 不需要向用户解释了,我们可以直接请求该权限
|
||||
* 第三步. 请求权限
|
||||
*
|
||||
* @param activity 上下文
|
||||
* @param permissions 权限数组
|
||||
*/
|
||||
private void requestPermission(AppCompatActivity activity, String[] permissions) {
|
||||
ActivityCompat.requestPermissions(activity, permissions, PERMISSION_REQUEST_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当用户之前拒绝过,展示一个对话框,解释为什么需要此权限
|
||||
*
|
||||
* @param activity 上下文
|
||||
* @param permissions 权限数组
|
||||
*/
|
||||
private void showPermissionExplainDialog(final AppCompatActivity activity, final String[] permissions) {
|
||||
if (permissionExplainDialog == null) {
|
||||
permissionExplainDialog = new AlertDialog.Builder(activity).setTitle("权限申请").setMessage("您刚才拒绝了相关权限,但是现在应用需要这个权限," +
|
||||
"点击确定申请权限,点击取消将无法使用该功能")
|
||||
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
requestPermission(activity, permissions);
|
||||
dialog.cancel();
|
||||
}
|
||||
})
|
||||
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.cancel();
|
||||
}
|
||||
}).create();
|
||||
|
||||
permissionExplainDialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 最后一步,当用户拒绝并且勾选了不在提示,那么只能引导用户去设置页面打开权限
|
||||
*
|
||||
* @param activity 上下文
|
||||
*/
|
||||
public void showPermissionSettingDialog(final AppCompatActivity activity) {
|
||||
if (permissionSettingDialog == null) {
|
||||
permissionSettingDialog = new AlertDialog.Builder(activity)
|
||||
.setTitle("权限设置")
|
||||
.setMessage("您刚才拒绝了相关的权限,请到应用设置页面更改应用的权限")
|
||||
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
|
||||
activity.startActivityForResult(intent, PERMISSION_SETTING_CODE);
|
||||
dialog.cancel();
|
||||
}
|
||||
})
|
||||
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.cancel();
|
||||
}
|
||||
}).create();
|
||||
|
||||
permissionSettingDialog.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.navinfo.outdoor.util;
|
||||
|
||||
import androidx.room.TypeConverter;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.navinfo.outdoor.bean.Info;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
/**
|
||||
* describe:使用Room框架,room不支持对象中直接存储集合
|
||||
* https://stackoverflow.com/questions/53812636/android-error-cannot-figure-out-how-to-save-this-field-into-database-you-can
|
||||
*/
|
||||
public class PhotoInfoConverter {
|
||||
Gson gson = new Gson();
|
||||
|
||||
@TypeConverter
|
||||
public List<Info> stringToSomeObjectList(String data) {
|
||||
if (data == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Type listType = new TypeToken<List<Info>>() {}.getType();
|
||||
|
||||
return gson.fromJson(data, listType);
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public String someObjectListToString(List<Info> someObjects) {
|
||||
return gson.toJson(someObjects);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.navinfo.outdoor.util;
|
||||
|
||||
import androidx.room.TypeConverter;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* describe:使用Room框架,room不支持对象中直接存储集合
|
||||
* https://stackoverflow.com/questions/53812636/android-error-cannot-figure-out-how-to-save-this-field-into-database-you-can
|
||||
*/
|
||||
public class StringTypeConverter {
|
||||
Gson gson = new Gson();
|
||||
|
||||
@TypeConverter
|
||||
public List<String> stringToSomeObjectList(String data) {
|
||||
if (data == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Type listType = new TypeToken<List<String>>() {}.getType();
|
||||
|
||||
return gson.fromJson(data, listType);
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public String someObjectListToString(List<String> someObjects) {
|
||||
return gson.toJson(someObjects);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user