forked from guolindev/booksource
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tony
committed
Oct 4, 2016
1 parent
00ed153
commit 41eb65f
Showing
42 changed files
with
631 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 24 | ||
buildToolsVersion "24.0.2" | ||
|
||
defaultConfig { | ||
applicationId "com.example.lbstest" | ||
minSdkVersion 15 | ||
targetSdkVersion 24 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:appcompat-v7:24.2.1' | ||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in C:\Users\Administrator\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
13 changes: 13 additions & 0 deletions
13
chapter11/LBSTest/app/src/androidTest/java/com/example/lbstest/ApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.example.lbstest; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> { | ||
public ApplicationTest() { | ||
super(Application.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.lbstest"> | ||
|
||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> | ||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> | ||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | ||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/> | ||
<uses-permission android:name="android.permission.READ_PHONE_STATE"/> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
<uses-permission android:name="android.permission.INTERNET"/> | ||
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> | ||
<uses-permission android:name="android.permission.WAKE_LOCK"/> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<meta-data | ||
android:name="com.baidu.lbsapi.API_KEY" | ||
android:value="i6VD2fHKM3msMfZtIOXAhFSzDiYGFIwL" /> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<service android:name="com.baidu.location.f" android:enabled="true" android:process=":remote"> | ||
</service> | ||
</application> | ||
|
||
</manifest> |
167 changes: 167 additions & 0 deletions
167
chapter11/LBSTest/app/src/main/java/com/example/lbstest/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
package com.example.lbstest; | ||
|
||
import android.Manifest; | ||
import android.content.pm.PackageManager; | ||
import android.support.v4.app.ActivityCompat; | ||
import android.support.v4.content.ContextCompat; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import com.baidu.location.BDLocation; | ||
import com.baidu.location.BDLocationListener; | ||
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.MapStatusUpdate; | ||
import com.baidu.mapapi.map.MapStatusUpdateFactory; | ||
import com.baidu.mapapi.map.MapView; | ||
import com.baidu.mapapi.map.MyLocationData; | ||
import com.baidu.mapapi.model.LatLng; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
public LocationClient mLocationClient; | ||
|
||
private TextView positionText; | ||
|
||
private MapView mapView; | ||
|
||
private BaiduMap baiduMap; | ||
|
||
private boolean isFirstLocate = true; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
mLocationClient = new LocationClient(getApplicationContext()); | ||
mLocationClient.registerLocationListener(new MyLocationListener()); | ||
SDKInitializer.initialize(getApplicationContext()); | ||
setContentView(R.layout.activity_main); | ||
mapView = (MapView) findViewById(R.id.bmapView); | ||
baiduMap = mapView.getMap(); | ||
baiduMap.setMyLocationEnabled(true); | ||
positionText = (TextView) findViewById(R.id.position_text_view); | ||
List<String> permissionList = new ArrayList<>(); | ||
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { | ||
permissionList.add(Manifest.permission.ACCESS_FINE_LOCATION); | ||
} | ||
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { | ||
permissionList.add(Manifest.permission.READ_PHONE_STATE); | ||
} | ||
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { | ||
permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); | ||
} | ||
if (!permissionList.isEmpty()) { | ||
String [] permissions = permissionList.toArray(new String[permissionList.size()]); | ||
ActivityCompat.requestPermissions(MainActivity.this, permissions, 1); | ||
} else { | ||
requestLocation(); | ||
} | ||
} | ||
|
||
private void navigateTo(BDLocation location) { | ||
if (isFirstLocate) { | ||
Toast.makeText(this, "nav to " + location.getAddrStr(), Toast.LENGTH_SHORT).show(); | ||
LatLng ll = new LatLng(location.getLatitude(), location.getLongitude()); | ||
MapStatusUpdate update = MapStatusUpdateFactory.newLatLng(ll); | ||
baiduMap.animateMapStatus(update); | ||
update = MapStatusUpdateFactory.zoomTo(16f); | ||
baiduMap.animateMapStatus(update); | ||
isFirstLocate = false; | ||
} | ||
MyLocationData.Builder locationBuilder = new MyLocationData. | ||
Builder(); | ||
locationBuilder.latitude(location.getLatitude()); | ||
locationBuilder.longitude(location.getLongitude()); | ||
MyLocationData locationData = locationBuilder.build(); | ||
baiduMap.setMyLocationData(locationData); | ||
} | ||
|
||
private void requestLocation() { | ||
initLocation(); | ||
mLocationClient.start(); | ||
} | ||
|
||
private void initLocation(){ | ||
LocationClientOption option = new LocationClientOption(); | ||
option.setScanSpan(5000); | ||
option.setIsNeedAddress(true); | ||
mLocationClient.setLocOption(option); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
mapView.onResume(); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
mapView.onPause(); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
mLocationClient.stop(); | ||
mapView.onDestroy(); | ||
baiduMap.setMyLocationEnabled(false); | ||
} | ||
|
||
@Override | ||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { | ||
switch (requestCode) { | ||
case 1: | ||
if (grantResults.length > 0) { | ||
for (int result : grantResults) { | ||
if (result != PackageManager.PERMISSION_GRANTED) { | ||
Toast.makeText(this, "必须同意所有权限才能使用本程序", Toast.LENGTH_SHORT).show(); | ||
finish(); | ||
return; | ||
} | ||
} | ||
requestLocation(); | ||
} else { | ||
Toast.makeText(this, "发生未知错误", Toast.LENGTH_SHORT).show(); | ||
finish(); | ||
} | ||
break; | ||
default: | ||
} | ||
} | ||
|
||
public class MyLocationListener implements BDLocationListener { | ||
|
||
@Override | ||
public void onReceiveLocation(BDLocation location) { | ||
// StringBuilder currentPosition = new StringBuilder(); | ||
// currentPosition.append("纬度:").append(location.getLatitude()).append("\n"); | ||
// currentPosition.append("经线:").append(location.getLongitude()).append("\n"); | ||
// currentPosition.append("国家:").append(location.getCountry()).append("\n"); | ||
// currentPosition.append("省:").append(location.getProvince()).append("\n"); | ||
// currentPosition.append("市:").append(location.getCity()).append("\n"); | ||
// currentPosition.append("区:").append(location.getDistrict()).append("\n"); | ||
// currentPosition.append("街道:").append(location.getStreet()).append("\n"); | ||
// currentPosition.append("定位方式:"); | ||
// if (location.getLocType() == BDLocation.TypeGpsLocation) { | ||
// currentPosition.append("GPS"); | ||
// } else if (location.getLocType() == BDLocation.TypeNetWorkLocation) { | ||
// currentPosition.append("网络"); | ||
// } | ||
// positionText.setText(currentPosition); | ||
if (location.getLocType() == BDLocation.TypeGpsLocation | ||
|| location.getLocType() == BDLocation.TypeNetWorkLocation) { | ||
navigateTo(location); | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
Binary file added
BIN
+1.12 MB
chapter11/LBSTest/app/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_base_v4_0_0.so
Binary file not shown.
Binary file added
BIN
+1.97 MB
chapter11/LBSTest/app/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_map_v4_0_0.so
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+645 KB
chapter11/LBSTest/app/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_base_v4_0_0.so
Binary file not shown.
Binary file added
BIN
+1020 KB
chapter11/LBSTest/app/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_map_v4_0_0.so
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+660 KB
chapter11/LBSTest/app/src/main/jniLibs/armeabi/libBaiduMapSDK_base_v4_0_0.so
Binary file not shown.
Binary file added
BIN
+1.03 MB
chapter11/LBSTest/app/src/main/jniLibs/armeabi/libBaiduMapSDK_map_v4_0_0.so
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+1.16 MB
chapter11/LBSTest/app/src/main/jniLibs/x86/libBaiduMapSDK_base_v4_0_0.so
Binary file not shown.
Binary file added
BIN
+2.08 MB
chapter11/LBSTest/app/src/main/jniLibs/x86/libBaiduMapSDK_map_v4_0_0.so
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+1.18 MB
chapter11/LBSTest/app/src/main/jniLibs/x86_64/libBaiduMapSDK_base_v4_0_0.so
Binary file not shown.
Binary file added
BIN
+2.17 MB
chapter11/LBSTest/app/src/main/jniLibs/x86_64/libBaiduMapSDK_map_v4_0_0.so
Binary file not shown.
Binary file not shown.
19 changes: 19 additions & 0 deletions
19
chapter11/LBSTest/app/src/main/res/layout/activity_main.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" > | ||
|
||
<TextView | ||
android:id="@+id/position_text_view" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:visibility="gone" /> | ||
|
||
<com.baidu.mapapi.map.MapView | ||
android:id="@+id/bmapView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:clickable="true" /> | ||
|
||
</LinearLayout> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<resources> | ||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml | ||
(such as screen margins) for screens with more than 820dp of available width. This | ||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> | ||
<dimen name="activity_horizontal_margin">64dp</dimen> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="colorPrimary">#3F51B5</color> | ||
<color name="colorPrimaryDark">#303F9F</color> | ||
<color name="colorAccent">#FF4081</color> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<resources> | ||
<!-- Default screen margins, per the Android Design guidelines. --> | ||
<dimen name="activity_horizontal_margin">16dp</dimen> | ||
<dimen name="activity_vertical_margin">16dp</dimen> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<string name="app_name">LBSTest</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<resources> | ||
|
||
<!-- Base application theme. --> | ||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | ||
<!-- Customize your theme here. --> | ||
<item name="colorPrimary">@color/colorPrimary</item> | ||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | ||
<item name="colorAccent">@color/colorAccent</item> | ||
</style> | ||
|
||
</resources> |
15 changes: 15 additions & 0 deletions
15
chapter11/LBSTest/app/src/test/java/com/example/lbstest/ExampleUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.example.lbstest; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* To work on unit tests, switch the Test Artifact in the Build Variants view. | ||
*/ | ||
public class ExampleUnitTest { | ||
@Test | ||
public void addition_isCorrect() throws Exception { | ||
assertEquals(4, 2 + 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
|
||
buildscript { | ||
repositories { | ||
jcenter() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:2.2.0' | ||
|
||
// NOTE: Do not place your application dependencies here; they belong | ||
// in the individual module build.gradle files | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
jcenter() | ||
} | ||
} | ||
|
||
task clean(type: Delete) { | ||
delete rootProject.buildDir | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Project-wide Gradle settings. | ||
|
||
# IDE (e.g. Android Studio) users: | ||
# Gradle settings configured through the IDE *will override* | ||
# any settings specified in this file. | ||
|
||
# For more details on how to configure your build environment visit | ||
# http://www.gradle.org/docs/current/userguide/build_environment.html | ||
|
||
# Specifies the JVM arguments used for the daemon process. | ||
# The setting is particularly useful for tweaking memory settings. | ||
# Default value: -Xmx10248m -XX:MaxPermSize=256m | ||
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 | ||
|
||
# When configured, Gradle will run in incubating parallel mode. | ||
# This option should only be used with decoupled projects. More details, visit | ||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects | ||
# org.gradle.parallel=true |
Binary file not shown.
Oops, something went wrong.