Commit 816736af authored by jianglx's avatar jianglx

修改定位问题

parent 4792c921
......@@ -202,6 +202,7 @@
 
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:excludeFromRecents="true"
android:exported="true"
android:launchMode="singleTask">
......
......@@ -8,12 +8,16 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.database.ContentObserver;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
......@@ -41,6 +45,7 @@ import com.ruiwenliu.wrapper.bean.ActBean;
import com.ruiwenliu.wrapper.bean.UpdateTokenBean;
import com.ruiwenliu.wrapper.receiver.NetWorkReceiver;
import com.ruiwenliu.wrapper.statusbar.StatusBarUtil;
import com.ruiwenliu.wrapper.util.GpsManager;
import com.ruiwenliu.wrapper.util.UtilsManager;
import com.ruiwenliu.wrapper.util.listener.SwitchFragment;
import com.ruiwenliu.wrapper.weight.CustomScrollViewPager;
......@@ -147,6 +152,8 @@ public class MainActivity extends BaseActivity<CommonPresenter> implements DownL
private String imPassword;
private LocationManager locationManager;
public static Intent getIntent(Context context) {
return new Intent(context, MainActivity.class);
}
......@@ -164,10 +171,12 @@ public class MainActivity extends BaseActivity<CommonPresenter> implements DownL
EventBus.getDefault().register(this);
DownListenerManager.getInstance().addDownListener(this);
ListenerManager.getInstance().addChatMessageListener(this);
GpsManager.getInstance(this).rigister();
}
@Override
protected void initView(Bundle savedInstanceState, TitleView titleView, Intent intent) {
updateAppUtils = UpdateAppUtils.from(MainActivity.this);
viewPager = findViewById(R.id.pager_view_fragment);
showTitle(false);
......@@ -207,7 +216,7 @@ public class MainActivity extends BaseActivity<CommonPresenter> implements DownL
private boolean isGpsOpen() {
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}
......@@ -586,6 +595,8 @@ public class MainActivity extends BaseActivity<CommonPresenter> implements DownL
unregisterReceiver(netReceiver);
netReceiver = null;
}
GpsManager.getInstance(this).unRigister();
}
private ServiceConnection imServiceConnection;
......
......@@ -69,8 +69,8 @@ public class RvClientApplication extends FrameApp {
ShareInstall.getInstance().init(this);
ShareInstall.getInstance().reportRegister();
}
LogUtil.setLogEnable(BuildConfig.DEBUG, getApplicationContext());
if(BuildConfig.DEBUG){
LogUtil.setLogEnable(true, getApplicationContext());
CrashHandler.getInstance().init(getApplicationContext());
}
// 在使用 SDK 各组间之前初始化 context 信息,传入 ApplicationContext
......
package com.ruiwenliu.wrapper.util;
import android.content.Context;
import android.database.ContentObserver;
import android.location.LocationManager;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.provider.Settings;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
public class GpsManager {
private static GpsManager instance;
private LocationManager locationManager;
private Context mContext;
private GpsManager(Context context) {
mContext = context.getApplicationContext();
locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
}
public static GpsManager getInstance(Context context) {
if (instance == null) {
instance = new GpsManager(context);
}
return instance;
}
private final ContentObserver observer = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
boolean enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
Log.e("xxxxxxxxxxxxxxxxxxxx", "selfChange = " + enabled);
if (enabled) {
gpsChangeHandler.sendEmptyMessage(0);
} else {
gpsChangeHandler.sendEmptyMessage(1);
}
}
};
private Handler gpsChangeHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 0:
notifyGpsChange(true);
break;
case 1:
notifyGpsChange(false);
break;
default:
break;
}
}
};
/*****
* 注册gps开关监听
*/
public void rigister() {
mContext.getContentResolver().registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.LOCATION_PROVIDERS_ALLOWED), false, observer);
}
/*****
* 注销gps开关监听
*/
public void unRigister() {
mContext.getContentResolver().unregisterContentObserver(observer);
}
private List<GpsChangeListener> listeners = new ArrayList<>();
public void bindGpsListener(GpsChangeListener listener) {
listeners.add(listener);
}
public void unbindGpsListener(GpsChangeListener listener) {
if (listeners.contains(listener)) {
listeners.remove(listener);
}
}
private void notifyGpsChange(boolean b) {
for (GpsChangeListener listener : listeners) {
listener.gpsChange(b);
}
}
/******
* GPS 改变监听事件
*/
public interface GpsChangeListener {
void gpsChange(boolean b);
}
}
......@@ -42,6 +42,7 @@ import com.google.gson.Gson;
import com.ruiwenliu.wrapper.SPConstance;
import com.ruiwenliu.wrapper.base.BaseBean;
import com.ruiwenliu.wrapper.base.BaseFragment;
import com.ruiwenliu.wrapper.util.GpsManager;
import com.ruiwenliu.wrapper.util.LocationManager;
import com.ruiwenliu.wrapper.util.UtilsManager;
import com.ruiwenliu.wrapper.util.glide.GlideManager;
......@@ -95,7 +96,7 @@ import pub.devrel.easypermissions.AppSettingsDialog;
/**
* 首页
*/
public class HomeFragment extends BaseFragment<HomePresenter> implements ObservableScrollView.ScrollViewListener, SimpleRefreshLayout.OnSimpleRefreshListener {
public class HomeFragment extends BaseFragment<HomePresenter> implements ObservableScrollView.ScrollViewListener, SimpleRefreshLayout.OnSimpleRefreshListener, GpsManager.GpsChangeListener {
Unbinder unbinder;
@BindView(R2.id.ll_layout_home_renting_a_car)
LinearLayout llLayoutRentingACar;
......@@ -241,7 +242,7 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements Observa
private int countPage;
private int mPage;
private boolean hasNewMessage ;
private boolean hasNewMessage;
public static HomeFragment getInstance(int type) {
Bundle bundl = new Bundle();
......@@ -258,6 +259,7 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements Observa
@Override
protected void initView(Bundle savedInstanceState) {
GpsManager.getInstance(_mActivity).bindGpsListener(this);
mSimpleRefreshLayout.setHeaderView(new SimpleRefreshView(_mActivity));
mSimpleRefreshLayout.setOnSimpleRefreshListener(this);
permissionProcess();
......@@ -479,6 +481,13 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements Observa
onFreshLoadDisCovery();
}
@Override
public void gpsChange(boolean b) {
if (b) {
}
}
public class AbSpacesItemDecoration extends RecyclerView.ItemDecoration {
private int space;
......@@ -901,7 +910,7 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements Observa
scrollview.fullScroll(View.FOCUS_UP);
} else if (id == R.id.iv_home_travel_server_image) {
if (isLogin()) {
hasNewMessage = false ;
hasNewMessage = false;
if (llItemTop.getVisibility() != View.VISIBLE) {
travelServerImage.setImageResource(R.drawable.rv_rentingcar_icon_service_white);
} else {
......@@ -1081,8 +1090,8 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements Observa
}
break;
case 4:
if(travelCityText != null && !TextUtils.isEmpty(data))
travelCityText.setText(data);
if (travelCityText != null && !TextUtils.isEmpty(data))
travelCityText.setText(data);
// headTvGetCity.setText(data);
// headTvOutCity.setText(data);
if (tvRvCity != null && !TextUtils.isEmpty(data)) {
......@@ -1339,7 +1348,6 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements Observa
* 定位权限处理
*/
private void permissionProcess() {
/**
* 6.0以上手机做权限处理
*/
......@@ -1375,15 +1383,8 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements Observa
if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
//没有检索到结果
} else {
// latLatitude = result.getLocation().latitude;
// lonLongitude = result.getLocation().longitude;
// getLatitude = result.getLocation().latitude;
// getLongitude = result.getLocation().longitude;
// outLatitude = result.getLocation().latitude;
// outLongitude = result.getLocation().longitude;
rvTourLatitude = result.getLocation().latitude;
rvTourLongitude = result.getLocation().longitude;
// getShopList(false);
}
//获取地理编码结果
}
......@@ -1393,15 +1394,8 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements Observa
if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
//没有找到检索结果
} else {
// latLatitude = result.getLocation().latitude;
// lonLongitude = result.getLocation().longitude;
// getLatitude = result.getLocation().latitude;
// getLongitude = result.getLocation().longitude;
// outLatitude = result.getLocation().latitude;
// outLongitude = result.getLocation().longitude;
rvTourLatitude = result.getLocation().latitude;
rvTourLongitude = result.getLocation().longitude;
// getShopList(false);
}
}
});
......@@ -1469,5 +1463,6 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements Observa
if (locationManager != null) {
locationManager.onDestroy();
}
GpsManager.getInstance(_mActivity).unbindGpsListener(this);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment