Commit aff2b4c3 authored by Administrator's avatar Administrator

update

parent bacff822
Pipeline #1809 failed with stages
package top.littlerich.virtuallocation.activity;
import android.Manifest;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.View;
......@@ -17,6 +21,7 @@ import android.widget.Toast;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
......@@ -39,6 +44,7 @@ import top.littlerich.virtuallocation.listener.GeoCoderListener;
import top.littlerich.virtuallocation.listener.MapClickListener;
import top.littlerich.virtuallocation.listener.MarkerDragListener;
import top.littlerich.virtuallocation.util.LocationUtil;
import top.littlerich.virtuallocation.util.PermissionUtil;
import top.littlerich.virtuallocation.view.TopBanner;
import static top.littlerich.virtuallocation.util.LocationUtil.hasAddTestProvider;
......@@ -46,7 +52,7 @@ import static top.littlerich.virtuallocation.util.LocationUtil.hasAddTestProvide
/**
* Created by xuqingfu on 2017/4/15.
*/
public class MainActivity extends BaseActivity implements View.OnClickListener{
public class MainActivity extends BaseActivity implements View.OnClickListener {
private String mMockProviderName = LocationManager.GPS_PROVIDER;
private Button bt_Ok;
......@@ -84,15 +90,37 @@ public class MainActivity extends BaseActivity implements View.OnClickListener{
}
@Override
protected void onCreate(Bundle savedInstanceState) {
PermissionUtil.requestPermissions(this,
new String[]{
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.ACCESS_FINE_LOCATION},
99);
super.onCreate(savedInstanceState);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (PermissionUtil.checkPermission(this, Manifest.permission.READ_PHONE_STATE)
== PackageManager.PERMISSION_GRANTED) {
// 在使用 SDK 各组间之前初始化 context 信息,传入 ApplicationContext
SDKInitializer.initialize(this);
} else {
Toast.makeText(this, "没有权限,无法工作", Toast.LENGTH_SHORT).show();
}
}
@Override
protected void IniView() {
bt_Ok = (Button) findViewById(R.id.bt_Ok);
tv_location = (TextView) findViewById(R.id.tv_location);
mDrawerLayout = (DrawerLayout) findViewById(R.id.dl_left);
mTopbanner = (TopBanner) findViewById(R.id.topbanner);
mAboutAuthor = (TextView) findViewById(R.id.tv_about_me);
mCurrentLocation = (ImageView)findViewById(R.id.iv_location);
mStopMock = (ImageView)findViewById(R.id.iv_stop_location);
mPreciseLocation = (TextView)findViewById(R.id.tv_precise);
mCurrentLocation = (ImageView) findViewById(R.id.iv_location);
mStopMock = (ImageView) findViewById(R.id.iv_stop_location);
mPreciseLocation = (TextView) findViewById(R.id.tv_precise);
mAddProcess = (TextView) findViewById(R.id.tv_add_app);
//加载旋转动画
mOperatingAnim = AnimationUtils.loadAnimation(this, R.anim.spinloaing);
......@@ -126,9 +154,9 @@ public class MainActivity extends BaseActivity implements View.OnClickListener{
mTopbanner.setTopBannerListener(new TopBanner.OnTopBannerListener() {
@Override
public void leftClick(View v) {
if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)){
if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
mDrawerLayout.closeDrawer(Gravity.LEFT);
}else {
} else {
mDrawerLayout.openDrawer(Gravity.LEFT);
}
}
......@@ -154,7 +182,7 @@ public class MainActivity extends BaseActivity implements View.OnClickListener{
mBaiduMap.setOnMapLoadedCallback(new BaiduMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
new Handler().postDelayed(new Runnable(){
new Handler().postDelayed(new Runnable() {
public void run() {
mCurrentLocation.clearAnimation();
......@@ -294,7 +322,7 @@ public class MainActivity extends BaseActivity implements View.OnClickListener{
@Override
protected void onPause() {
mMapView.onPause();
if (mDrawerLayout != null && mDrawerLayout.isDrawerOpen(Gravity.LEFT)){
if (mDrawerLayout != null && mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
mDrawerLayout.closeDrawer(Gravity.LEFT);
}
super.onPause();
......@@ -330,7 +358,7 @@ public class MainActivity extends BaseActivity implements View.OnClickListener{
latitude = curLatlng.latitude;
longitude = curLatlng.longitude;
try {
if (!hasAddTestProvider){
if (!hasAddTestProvider) {
LocationUtil.initLocation(MainActivity.this);
LocationUtil.initLocationManager();
}
......
package top.littlerich.virtuallocation.common;
import android.Manifest;
import android.app.Application;
import android.content.pm.PackageManager;
import com.baidu.mapapi.SDKInitializer;
import top.littlerich.virtuallocation.model.Gps;
import top.littlerich.virtuallocation.util.PermissionUtil;
/**
* Created by xuqingfu on 2017/4/15.
*/
public class AppApplication extends Application {
/**全局GPS*/
public static Gps mMockGps;
static {
mMockGps = Config.COMPANY;
}
@Override
public void onCreate() {
super.onCreate();
// 在使用 SDK 各组间之前初始化 context 信息,传入 ApplicationContext
SDKInitializer.initialize(this);
}
/**
* 全局GPS
*/
public static Gps mMockGps;
static {
mMockGps = Config.COMPANY;
}
@Override
public void onCreate() {
super.onCreate();
if (PermissionUtil.checkPermission(this, Manifest.permission.READ_PHONE_STATE)
== PackageManager.PERMISSION_GRANTED) {
// 在使用 SDK 各组间之前初始化 context 信息,传入 ApplicationContext
SDKInitializer.initialize(this);
}
}
}
\ No newline at end of file
/*
* Copyright (c) 2019 The sky Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.littlerich.virtuallocation.util;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Process;
/**
* Created by sky on 2019/4/8.
*/
public class PermissionUtil {
private PermissionUtil() {
}
public static int checkPermission(Context context, String permission) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// 请求权限
return context.checkPermission(permission, Process.myPid(), Process.myUid());
}
return PackageManager.PERMISSION_GRANTED;
}
public static void requestPermissions(Activity activity, String[] permissions, int requestCode) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// 请求权限
activity.requestPermissions(permissions, requestCode);
}
}
}
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