Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
R
RatelVirtualLocation
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
RatelVirtualLocation
Commits
aff2b4c3
Commit
aff2b4c3
authored
Aug 25, 2020
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
bacff822
Pipeline
#1809
failed with stages
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
108 additions
and
22 deletions
+108
-22
MainActivity.java
...top/littlerich/virtuallocation/activity/MainActivity.java
+37
-9
AppApplication.java
...top/littlerich/virtuallocation/common/AppApplication.java
+21
-13
PermissionUtil.java
...a/top/littlerich/virtuallocation/util/PermissionUtil.java
+50
-0
No files found.
app/src/main/java/top/littlerich/virtuallocation/activity/MainActivity.java
View file @
aff2b4c3
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
();
}
...
...
app/src/main/java/top/littlerich/virtuallocation/common/AppApplication.java
View file @
aff2b4c3
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
app/src/main/java/top/littlerich/virtuallocation/util/PermissionUtil.java
0 → 100644
View file @
aff2b4c3
/*
* 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
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment