├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── app
├── .gitignore
├── libs
│ ├── BaiduLBS_Android.jar
│ ├── mina-core-2.0.9.jar
│ └── slf4j-api-1.7.7.jar
├── src
│ ├── main
│ │ ├── jniLibs
│ │ │ ├── x86
│ │ │ │ ├── liblocSDK6a.so
│ │ │ │ ├── libBaiduMapSDK_base_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_map_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_util_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_cloud_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_radar_v3_6_1.so
│ │ │ │ └── libBaiduMapSDK_search_v3_6_1.so
│ │ │ ├── armeabi
│ │ │ │ ├── liblocSDK6a.so
│ │ │ │ ├── libBaiduMapSDK_base_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_cloud_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_map_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_radar_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_util_v3_6_1.so
│ │ │ │ └── libBaiduMapSDK_search_v3_6_1.so
│ │ │ ├── x86_64
│ │ │ │ ├── liblocSDK6a.so
│ │ │ │ ├── libBaiduMapSDK_map_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_base_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_cloud_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_radar_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_search_v3_6_1.so
│ │ │ │ └── libBaiduMapSDK_util_v3_6_1.so
│ │ │ ├── arm64-v8a
│ │ │ │ ├── liblocSDK6a.so
│ │ │ │ ├── libBaiduMapSDK_map_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_base_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_cloud_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_radar_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_util_v3_6_1.so
│ │ │ │ └── libBaiduMapSDK_search_v3_6_1.so
│ │ │ └── armeabi-v7a
│ │ │ │ ├── liblocSDK6a.so
│ │ │ │ ├── libBaiduMapSDK_map_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_base_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_cloud_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_radar_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_search_v3_6_1.so
│ │ │ │ └── libBaiduMapSDK_util_v3_6_1.so
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_marker_taxi_18dp.png
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── menu
│ │ │ │ └── menu_baidu_map.xml
│ │ │ ├── values-zh-rCN
│ │ │ │ └── strings.xml
│ │ │ └── layout
│ │ │ │ ├── content_baidu_map.xml
│ │ │ │ ├── activity_dest_search.xml
│ │ │ │ ├── activity_baidu_map.xml
│ │ │ │ ├── activity_login.xml
│ │ │ │ └── activity_waiting.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── zyw
│ │ │ │ └── calltaxi
│ │ │ │ ├── api
│ │ │ │ ├── OnDriverUpdateCallback.java
│ │ │ │ ├── OnMessageReceivedListener.java
│ │ │ │ └── OnMessageReceivedListenerAdapter.java
│ │ │ │ ├── app
│ │ │ │ └── App.java
│ │ │ │ ├── model
│ │ │ │ ├── Driver.java
│ │ │ │ ├── Passenger.java
│ │ │ │ ├── Destination.java
│ │ │ │ ├── User.java
│ │ │ │ └── Message.java
│ │ │ │ ├── utils
│ │ │ │ ├── ToastUtils.java
│ │ │ │ └── LogHelper.java
│ │ │ │ ├── adapter
│ │ │ │ └── SuggestionInfoAdapter.java
│ │ │ │ ├── socketclient
│ │ │ │ ├── TaxiRequestHandler.java
│ │ │ │ └── TaxiSocketClient.java
│ │ │ │ ├── ui
│ │ │ │ ├── LoginActivity.java
│ │ │ │ ├── DestSearchActivity.java
│ │ │ │ └── WaitingActivity.java
│ │ │ │ ├── service
│ │ │ │ └── TaxiSocketService.java
│ │ │ │ └── map
│ │ │ │ └── BaiduMapManager.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── zyw
│ │ │ └── calltaxi
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── zyw
│ │ └── calltaxi
│ │ └── ApplicationTest.java
├── proguard-rules.pro
├── build.gradle
└── app.iml
├── driver
├── .gitignore
├── libs
│ ├── mina-core-2.0.9.jar
│ ├── slf4j-api-1.7.7.jar
│ └── BaiduLBS_Android.jar
├── src
│ ├── main
│ │ ├── jniLibs
│ │ │ ├── x86
│ │ │ │ ├── liblocSDK6a.so
│ │ │ │ ├── libBaiduMapSDK_map_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_base_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_cloud_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_radar_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_search_v3_6_1.so
│ │ │ │ └── libBaiduMapSDK_util_v3_6_1.so
│ │ │ ├── armeabi
│ │ │ │ ├── liblocSDK6a.so
│ │ │ │ ├── libBaiduMapSDK_base_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_map_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_util_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_cloud_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_radar_v3_6_1.so
│ │ │ │ └── libBaiduMapSDK_search_v3_6_1.so
│ │ │ ├── x86_64
│ │ │ │ ├── liblocSDK6a.so
│ │ │ │ ├── libBaiduMapSDK_map_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_base_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_cloud_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_radar_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_util_v3_6_1.so
│ │ │ │ └── libBaiduMapSDK_search_v3_6_1.so
│ │ │ ├── arm64-v8a
│ │ │ │ ├── liblocSDK6a.so
│ │ │ │ ├── libBaiduMapSDK_base_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_cloud_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_map_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_radar_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_util_v3_6_1.so
│ │ │ │ └── libBaiduMapSDK_search_v3_6_1.so
│ │ │ └── armeabi-v7a
│ │ │ │ ├── liblocSDK6a.so
│ │ │ │ ├── libBaiduMapSDK_map_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_base_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_cloud_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_radar_v3_6_1.so
│ │ │ │ ├── libBaiduMapSDK_util_v3_6_1.so
│ │ │ │ └── libBaiduMapSDK_search_v3_6_1.so
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_right_arrow_24dp.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ ├── values-zh-rCN
│ │ │ │ └── strings.xml
│ │ │ └── layout
│ │ │ │ ├── content_main.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── activity_passenger_info.xml
│ │ │ │ ├── item_passenger_info.xml
│ │ │ │ └── activity_login.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── zyw
│ │ │ │ └── driver
│ │ │ │ ├── api
│ │ │ │ ├── OnLocationReceivedListener.java
│ │ │ │ ├── DriverServiceCallback.java
│ │ │ │ ├── OnMessageReceivedListener.java
│ │ │ │ └── OnMessageReceivedListenerAdapter.java
│ │ │ │ ├── app
│ │ │ │ └── App.java
│ │ │ │ ├── model
│ │ │ │ ├── Driver.java
│ │ │ │ ├── Passenger.java
│ │ │ │ ├── Destination.java
│ │ │ │ ├── User.java
│ │ │ │ └── Message.java
│ │ │ │ ├── utils
│ │ │ │ ├── ToastUtils.java
│ │ │ │ └── LogHelper.java
│ │ │ │ ├── baidulocation
│ │ │ │ └── LocationManager.java
│ │ │ │ ├── socketclient
│ │ │ │ ├── DriverHandler.java
│ │ │ │ └── DriverSocketClient.java
│ │ │ │ ├── ui
│ │ │ │ ├── LoginActivity.java
│ │ │ │ ├── PassengerInfoActivity.java
│ │ │ │ └── MainActivity.java
│ │ │ │ ├── adapter
│ │ │ │ └── PassengerInfoAdapter.java
│ │ │ │ └── service
│ │ │ │ └── DriverService.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── chaoyang805
│ │ │ └── driver
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── chaoyang805
│ │ └── driver
│ │ └── ApplicationTest.java
├── proguard-rules.pro
├── build.gradle
└── driver.iml
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── CallTaxi.iml
├── MyCallTaxi.iml
├── CallTaxi-1-master.iml
├── gradlew.bat
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | MyCallTaxi
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/driver/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':driver'
2 |
--------------------------------------------------------------------------------
/app/libs/BaiduLBS_Android.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/libs/BaiduLBS_Android.jar
--------------------------------------------------------------------------------
/app/libs/mina-core-2.0.9.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/libs/mina-core-2.0.9.jar
--------------------------------------------------------------------------------
/app/libs/slf4j-api-1.7.7.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/libs/slf4j-api-1.7.7.jar
--------------------------------------------------------------------------------
/driver/libs/mina-core-2.0.9.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/libs/mina-core-2.0.9.jar
--------------------------------------------------------------------------------
/driver/libs/slf4j-api-1.7.7.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/libs/slf4j-api-1.7.7.jar
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/driver/libs/BaiduLBS_Android.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/libs/BaiduLBS_Android.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | /captures
8 |
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86/liblocSDK6a.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/x86/liblocSDK6a.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi/liblocSDK6a.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/armeabi/liblocSDK6a.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86_64/liblocSDK6a.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/x86_64/liblocSDK6a.so
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/x86/liblocSDK6a.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/x86/liblocSDK6a.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/arm64-v8a/liblocSDK6a.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/arm64-v8a/liblocSDK6a.so
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/armeabi/liblocSDK6a.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/armeabi/liblocSDK6a.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/x86_64/liblocSDK6a.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/x86_64/liblocSDK6a.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi-v7a/liblocSDK6a.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/armeabi-v7a/liblocSDK6a.so
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/arm64-v8a/liblocSDK6a.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/arm64-v8a/liblocSDK6a.so
--------------------------------------------------------------------------------
/driver/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/driver/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/driver/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/driver/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/armeabi-v7a/liblocSDK6a.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/armeabi-v7a/liblocSDK6a.so
--------------------------------------------------------------------------------
/driver/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86/libBaiduMapSDK_base_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/x86/libBaiduMapSDK_base_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86/libBaiduMapSDK_map_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/x86/libBaiduMapSDK_map_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86/libBaiduMapSDK_util_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/x86/libBaiduMapSDK_util_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86/libBaiduMapSDK_cloud_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/x86/libBaiduMapSDK_cloud_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86/libBaiduMapSDK_radar_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/x86/libBaiduMapSDK_radar_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86/libBaiduMapSDK_search_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/x86/libBaiduMapSDK_search_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86_64/libBaiduMapSDK_map_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/x86_64/libBaiduMapSDK_map_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_marker_taxi_18dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_marker_taxi_18dp.png
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/x86/libBaiduMapSDK_map_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/x86/libBaiduMapSDK_map_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/res/mipmap-xhdpi/ic_right_arrow_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/res/mipmap-xhdpi/ic_right_arrow_24dp.png
--------------------------------------------------------------------------------
/app/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_map_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_map_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi/libBaiduMapSDK_base_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/armeabi/libBaiduMapSDK_base_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi/libBaiduMapSDK_cloud_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/armeabi/libBaiduMapSDK_cloud_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi/libBaiduMapSDK_map_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/armeabi/libBaiduMapSDK_map_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi/libBaiduMapSDK_radar_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/armeabi/libBaiduMapSDK_radar_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi/libBaiduMapSDK_util_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/armeabi/libBaiduMapSDK_util_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86_64/libBaiduMapSDK_base_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/x86_64/libBaiduMapSDK_base_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86_64/libBaiduMapSDK_cloud_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/x86_64/libBaiduMapSDK_cloud_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86_64/libBaiduMapSDK_radar_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/x86_64/libBaiduMapSDK_radar_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86_64/libBaiduMapSDK_search_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/x86_64/libBaiduMapSDK_search_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86_64/libBaiduMapSDK_util_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/x86_64/libBaiduMapSDK_util_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/x86/libBaiduMapSDK_base_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/x86/libBaiduMapSDK_base_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/x86/libBaiduMapSDK_cloud_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/x86/libBaiduMapSDK_cloud_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/x86/libBaiduMapSDK_radar_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/x86/libBaiduMapSDK_radar_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/x86/libBaiduMapSDK_search_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/x86/libBaiduMapSDK_search_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/x86/libBaiduMapSDK_util_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/x86/libBaiduMapSDK_util_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/x86_64/libBaiduMapSDK_map_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/x86_64/libBaiduMapSDK_map_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_base_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_base_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_cloud_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_cloud_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_radar_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_radar_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_util_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_util_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_map_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_map_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi/libBaiduMapSDK_search_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/armeabi/libBaiduMapSDK_search_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/armeabi/libBaiduMapSDK_base_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/armeabi/libBaiduMapSDK_base_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/armeabi/libBaiduMapSDK_map_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/armeabi/libBaiduMapSDK_map_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/armeabi/libBaiduMapSDK_util_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/armeabi/libBaiduMapSDK_util_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/x86_64/libBaiduMapSDK_base_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/x86_64/libBaiduMapSDK_base_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/x86_64/libBaiduMapSDK_cloud_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/x86_64/libBaiduMapSDK_cloud_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/x86_64/libBaiduMapSDK_radar_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/x86_64/libBaiduMapSDK_radar_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/x86_64/libBaiduMapSDK_util_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/x86_64/libBaiduMapSDK_util_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_search_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_search_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_base_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_base_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_cloud_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_cloud_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_radar_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_radar_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_search_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_search_v3_6_1.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_util_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/app/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_util_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_base_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_base_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_cloud_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_cloud_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_map_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_map_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_radar_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_radar_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_util_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_util_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_map_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_map_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/armeabi/libBaiduMapSDK_cloud_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/armeabi/libBaiduMapSDK_cloud_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/armeabi/libBaiduMapSDK_radar_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/armeabi/libBaiduMapSDK_radar_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/armeabi/libBaiduMapSDK_search_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/armeabi/libBaiduMapSDK_search_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/x86_64/libBaiduMapSDK_search_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/x86_64/libBaiduMapSDK_search_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_search_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_search_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_base_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_base_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_cloud_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_cloud_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_radar_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_radar_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_util_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_util_v3_6_1.so
--------------------------------------------------------------------------------
/driver/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_search_v3_6_1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbamoon/MyCallTaxi/HEAD/driver/src/main/jniLibs/armeabi-v7a/libBaiduMapSDK_search_v3_6_1.so
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Nov 07 21:50:11 CST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #0086f5
7 |
8 |
--------------------------------------------------------------------------------
/driver/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #0086f5
7 |
8 |
--------------------------------------------------------------------------------
/driver/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/api/OnDriverUpdateCallback.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.api;
2 |
3 | /**
4 | *Created by zyw on 2015/11/12.
5 | */
6 | public interface OnDriverUpdateCallback {
7 |
8 | void onUpdateDriver(String msg);
9 |
10 | void onDriverOffline(String message);
11 | }
12 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/api/OnLocationReceivedListener.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.api;
2 |
3 | import com.baidu.location.BDLocation;
4 |
5 | /**
6 | * Created by zyw on 2015/11/13.
7 | */
8 | public interface OnLocationReceivedListener {
9 |
10 | void onLocationReceived(BDLocation bdLocation);
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 | >
2 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/api/OnMessageReceivedListener.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.api;
2 |
3 | /**
4 | * Created by zyw on 2015/11/12.
5 | * 接收服务端司机信息的监听器
6 | */
7 | public interface OnMessageReceivedListener {
8 |
9 | void onUpdateDriver(String message);
10 |
11 | void onDriverAccept(String message);
12 |
13 | void onDriverOffline(String detail);
14 | }
15 |
--------------------------------------------------------------------------------
/driver/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 | >
2 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/api/DriverServiceCallback.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.api;
2 |
3 | /**
4 | * Created by zyw on 2015/11/12.
5 | */
6 | public interface DriverServiceCallback {
7 |
8 | void onUpdatePassenger(String msg);
9 |
10 | void onPassengerTaken(String msg);
11 |
12 | void onPassengerCancel(String msg);
13 |
14 | void onPassengerOffline(String msg);
15 | }
16 |
--------------------------------------------------------------------------------
/driver/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/app/App.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.app;
2 |
3 | import android.app.Application;
4 |
5 | import com.baidu.mapapi.SDKInitializer;
6 |
7 | /**
8 | * Created by zyw on 2015/11/7.
9 | */
10 | public class App extends Application {
11 |
12 | @Override
13 | public void onCreate() {
14 | super.onCreate();
15 | SDKInitializer.initialize(this);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/test/java/com/zyw/calltaxi/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/app/App.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.app;
2 |
3 | import android.app.Application;
4 |
5 | import com.baidu.mapapi.SDKInitializer;
6 |
7 | /**
8 | * Created by zyw on 2015/11/13.
9 | */
10 | public class App extends Application{
11 |
12 | @Override
13 | public void onCreate() {
14 | super.onCreate();
15 | SDKInitializer.initialize(this);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/api/OnMessageReceivedListener.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.api;
2 |
3 | /**
4 | * Created by zyw on 2015/11/12.
5 | */
6 | public interface OnMessageReceivedListener {
7 |
8 | void onUpdatePassenger(String message);
9 |
10 | void onPassengerTaken(String message);
11 |
12 | void onPassengerCancel(String message);
13 |
14 | void onPassengerOffline(String message);
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/driver/src/test/java/com/chaoyang805/driver/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.chaoyang805.driver;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/driver/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/zyw/calltaxi/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_baidu_map.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/driver/src/androidTest/java/com/chaoyang805/driver/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.chaoyang805.driver;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/driver/src/main/res/values-zh-rCN/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 设置
4 | 打车司机端
5 | 手机号
6 | 用户名
7 | 登录
8 | 打电话给他
9 | 接单成功!\n\n乘客:%1$s\n电话:%2$s\n目的地:%3$s %4$dkm\n距离我:%5$dm
10 | 完成订单
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/api/OnMessageReceivedListenerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.api;
2 |
3 | /**
4 | * Created by zyw on 2015/11/12.
5 | * 接口是不能实例化的,所以setOnMessageReceivedListener()传入的参数应是实现了OnMessageReceivedListener接口的类
6 | */
7 | public class OnMessageReceivedListenerAdapter implements OnMessageReceivedListener {
8 | @Override
9 | public void onUpdateDriver(String message) {}
10 | @Override
11 | public void onDriverAccept(String message) {}
12 | @Override
13 | public void onDriverOffline(String detail) {}
14 | }
15 |
--------------------------------------------------------------------------------
/driver/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Driver
3 | Settings
4 | user name
5 | phone number
6 | login
7 | Call Passenger
8 | Ordered successful!\n\nPassenger:%1$s\nPhone:%2$s\nDestination:%3$s %4$dkm\nDistance from me:%5$dm
9 | complete
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/model/Driver.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.model;
2 |
3 | /**
4 | * Created by zyw on 2015/11/10.
5 | */
6 | public class Driver extends User {
7 |
8 | /**
9 | * 司机已经接单
10 | */
11 | protected boolean mHasOrdered = false;
12 |
13 | public Driver(String name, String phoneNumber) {
14 | super(name, phoneNumber);
15 | }
16 |
17 | public void setHasOrdered(boolean hasOrdered) {
18 | mHasOrdered = hasOrdered;
19 | }
20 |
21 | public boolean isHasOrdered() {
22 | return mHasOrdered;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/api/OnMessageReceivedListenerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.api;
2 |
3 | /**
4 | * Created by zyw on 2015/11/12.
5 | */
6 | public class OnMessageReceivedListenerAdapter implements OnMessageReceivedListener {
7 |
8 | @Override
9 | public void onUpdatePassenger(String message) {}
10 |
11 | @Override
12 | public void onPassengerTaken(String message) {}
13 |
14 | @Override
15 | public void onPassengerCancel(String message) {}
16 |
17 | @Override
18 | public void onPassengerOffline(String message) {}
19 |
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/model/Driver.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.model;
2 |
3 | /**
4 | * Created by zyw on 2015/11/10.
5 | */
6 | public class Driver extends User {
7 |
8 | /**
9 | * 司机已经接单
10 | */
11 | protected boolean mHasOrdered = false;
12 |
13 | public Driver(String name, String phoneNumber) {
14 | super(name, phoneNumber);
15 | }
16 |
17 | public void setHasOrdered(boolean hasOrdered) {
18 | mHasOrdered = hasOrdered;
19 | }
20 |
21 | public boolean isHasOrdered() {
22 | return mHasOrdered;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values-zh-rCN/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 设置
4 | 打车
5 | 定位失败
6 | 手机号
7 | 用户名
8 | 登录
9 | 取消约车
10 | 正在等待司机接单...
11 | 已经有司机接单了\n司机:%1$s\n手机号%2$s\n(点击进行呼叫)
12 | 完成
13 | 打电话给他
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CallTaxi
3 | Settings
4 | failed to locate
5 | user name
6 | phone number
7 | log in
8 | cancel call taxi
9 | waiting for driver...
10 | you are being ordered by \n%1$s\nphone number:%2$s\n(click to dial)
11 | done
12 | call him
13 |
14 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\SDKs\AndroidSDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/driver/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/driver/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\SDKs\AndroidSDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_baidu_map.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/driver/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/model/Passenger.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.model;
2 |
3 | /**
4 | * Created by zyw on 2015/11/10.
5 | */
6 | public class Passenger extends User {
7 | /**
8 | * 乘客是否正在等待接单
9 | */
10 | protected boolean mIsWaitingOrder = false;
11 |
12 | protected Destination mDestination;
13 |
14 | public Passenger(String name, String phoneNumber) {
15 | super(name, phoneNumber);
16 | }
17 |
18 | public boolean isWaitingOrder() {
19 | return mIsWaitingOrder;
20 | }
21 |
22 | public void setIsWaitingOrder(boolean isWaitingOrder) {
23 | mIsWaitingOrder = isWaitingOrder;
24 | }
25 |
26 | public Destination getDestination() {
27 | return mDestination;
28 | }
29 |
30 | public void setDestination(Destination destination) {
31 | mDestination = destination;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/model/Passenger.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.model;
2 |
3 | /**
4 | * Created by zyw on 2015/11/10.
5 | */
6 | public class Passenger extends User {
7 | /**
8 | * 乘客是否正在等待接单
9 | */
10 | protected boolean mIsWaitingOrder = false;
11 |
12 | protected Destination mDestination;
13 |
14 |
15 | public Passenger(String name, String phoneNumber) {
16 | super(name, phoneNumber);
17 | }
18 |
19 | public boolean isWaitingOrder() {
20 | return mIsWaitingOrder;
21 | }
22 |
23 | public void setIsWaitingOrder(boolean isWaitingOrder) {
24 | mIsWaitingOrder = isWaitingOrder;
25 | }
26 |
27 | public Destination getDestination() {
28 | return mDestination;
29 | }
30 |
31 | public void setDestination(Destination destination) {
32 | mDestination = destination;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.zyw.calltaxi"
9 | minSdkVersion 14
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.1.0'
26 | compile 'com.android.support:design:23.1.0'
27 | compile files('libs/BaiduLBS_Android.jar')
28 | compile files('libs/mina-core-2.0.9.jar')
29 | compile files('libs/slf4j-api-1.7.7.jar')
30 | }
31 |
--------------------------------------------------------------------------------
/driver/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.zyw.driver"
9 | minSdkVersion 14
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.1.0'
26 | compile 'com.android.support:design:23.1.0'
27 | compile files('libs/mina-core-2.0.9.jar')
28 | compile files('libs/slf4j-api-1.7.7.jar')
29 | compile files('libs/BaiduLBS_Android.jar')
30 | }
31 |
--------------------------------------------------------------------------------
/CallTaxi.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/MyCallTaxi.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/model/Destination.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.model;
2 |
3 | /**
4 | * Created by zyw on 2015/11/10.
5 | */
6 | public class Destination {
7 | /**
8 | * 目的地哦详细地址信息
9 | */
10 | private String mDetailAdress;
11 | /**
12 | * 目的地在地图上的坐标
13 | */
14 | private double[] mLocation;
15 | /**
16 | * 目的地和乘客当前位置的距离
17 | */
18 | private double mDistance;
19 |
20 | public String getDetailAdress() {
21 | return mDetailAdress;
22 | }
23 |
24 | public void setDetailAdress(String detailAdress) {
25 | mDetailAdress = detailAdress;
26 | }
27 |
28 | public double[] getLocation() {
29 | return mLocation;
30 | }
31 |
32 | public void setLocation(double[] location) {
33 | mLocation = location;
34 | }
35 |
36 | public double getDistance() {
37 | return mDistance;
38 | }
39 |
40 | public void setDistance(double distance) {
41 | mDistance = distance;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/model/Destination.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.model;
2 |
3 | /**
4 | * Created by zyw on 2015/11/10.
5 | */
6 | public class Destination {
7 | /**
8 | * 目的地详细地址信息
9 | */
10 | private String mDetailAdress;
11 | /**
12 | * 目的地在地图上的坐标
13 | */
14 | private double[] mLocation;
15 | /**
16 | * 目的地和乘客当前位置的距离
17 | */
18 | private double mDistance;
19 |
20 | public String getDetailAdress() {
21 | return mDetailAdress;
22 | }
23 |
24 | public void setDetailAdress(String detailAdress) {
25 | mDetailAdress = detailAdress;
26 | }
27 |
28 | public double[] getLocation() {
29 | return mLocation;
30 | }
31 |
32 | public void setLocation(double[] location) {
33 | mLocation = location;
34 | }
35 |
36 | public double getDistance() {
37 | return mDistance;
38 | }
39 |
40 | public void setDistance(double distance) {
41 | mDistance = distance;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/CallTaxi-1-master.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_dest_search.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
18 |
19 |
26 |
27 |
28 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_baidu_map.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
22 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/model/User.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.model;
2 |
3 | import com.baidu.mapapi.model.LatLng;
4 |
5 | import org.apache.mina.core.session.IoSession;
6 |
7 | /**
8 | * Created by zyw on 2015/11/10.
9 | */
10 | public class User {
11 | protected String mName;
12 | protected String mPhoneNumber;
13 | protected double[] mLocation = new double[2];
14 | protected IoSession mSession;
15 |
16 | public User(String name,String phoneNumber){
17 | mName = name;
18 | mPhoneNumber = phoneNumber;
19 | }
20 |
21 | public String getName() {
22 | return mName;
23 | }
24 |
25 | public void setName(String name) {
26 | mName = name;
27 | }
28 |
29 | public String getPhoneNumber() {
30 | return mPhoneNumber;
31 | }
32 |
33 | public void setPhoneNumber(String phoneNumber) {
34 | mPhoneNumber = phoneNumber;
35 | }
36 |
37 | public double[] getLocation() {
38 | return mLocation;
39 | }
40 |
41 | public void setLocation(double[] location) {
42 | mLocation = location;
43 | }
44 |
45 | public IoSession getSession() {
46 | return mSession;
47 | }
48 |
49 | public void setSession(IoSession session) {
50 | mSession = session;
51 | }
52 |
53 | public LatLng getLatLng() {
54 | return new LatLng(getLocation()[0],getLocation()[1]);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/utils/ToastUtils.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.utils;
2 |
3 | import android.content.Context;
4 | import android.widget.Toast;
5 |
6 | /**
7 | * Created by zyw on 2015/8/15.
8 | * 显示Toast的工具类
9 | */
10 | public class ToastUtils {
11 |
12 | private static Toast mToast;
13 | /**
14 | * 是否使用Toast
15 | */
16 | private static boolean isUseToast = true;
17 |
18 | /**
19 | * 是否使用Toast
20 | * @param useToast
21 | */
22 | public static void setIsUseToast(boolean useToast) {
23 | isUseToast = useToast;
24 | }
25 |
26 | /**
27 | *显示Toast,下一个Toast会直接覆盖上一个,而不是上一个显示完才显示下一个
28 | * @param context
29 | * @param msg
30 | */
31 | public static void showToast(Context context, CharSequence msg) {
32 | //如果不使用Toast则直接返回
33 | if (!isUseToast) {
34 | return;
35 | }
36 | if (mToast == null) {
37 | mToast = Toast.makeText(context, msg,Toast.LENGTH_SHORT);
38 | } else {
39 | mToast.setText(msg);
40 | }
41 | mToast.show();
42 | }
43 |
44 | /**
45 | * 显示Toast,下一个Toast会直接覆盖上一个,而不是上一个显示完才显示下一个
46 | * @param context
47 | * @param strinResId 字符串资源id
48 | */
49 | public static void showToast(Context context, int strinResId) {
50 | String msg = context.getResources().getString(strinResId);
51 | showToast(context, msg);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/utils/ToastUtils.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.utils;
2 |
3 | import android.content.Context;
4 | import android.widget.Toast;
5 |
6 | /**
7 | * Created by zyw on 2015/8/15.
8 | * 显示Toast的工具类
9 | */
10 | public class ToastUtils {
11 |
12 | private static Toast mToast;
13 | /**
14 | * 是否使用Toast
15 | */
16 | private static boolean isUseToast = true;
17 |
18 | /**
19 | * 是否使用Toast
20 | * @param useToast
21 | */
22 | public static void setIsUseToast(boolean useToast) {
23 | isUseToast = useToast;
24 | }
25 |
26 | /**
27 | *显示Toast,下一个Toast会直接覆盖上一个,而不是上一个显示完才显示下一个
28 | * @param context
29 | * @param msg
30 | */
31 | public static void showToast(Context context, CharSequence msg) {
32 | //如果不使用Toast则直接返回
33 | if (!isUseToast) {
34 | return;
35 | }
36 | if (mToast == null) {
37 | mToast = Toast.makeText(context, msg,Toast.LENGTH_SHORT);
38 | } else {
39 | mToast.setText(msg);
40 | }
41 | mToast.show();
42 | }
43 |
44 | /**
45 | * 显示Toast,下一个Toast会直接覆盖上一个,而不是上一个显示完才显示下一个
46 | * @param context
47 | * @param strinResId 字符串资源id
48 | */
49 | public static void showToast(Context context, int strinResId) {
50 | String msg = context.getResources().getString(strinResId);
51 | showToast(context, msg);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/driver/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
22 |
23 |
24 |
25 |
26 |
27 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/model/User.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.model;
2 |
3 | import com.baidu.mapapi.model.LatLng;
4 |
5 | import org.apache.mina.core.session.IoSession;
6 |
7 | /**
8 | * Created by zyw on 2015/11/10.
9 | */
10 | public class User {
11 | protected String mName;
12 | protected String mPhoneNumber;
13 | protected double[] mLocation = new double[2];
14 | protected IoSession mSession;
15 | protected int mDistance;
16 | public User(String name,String phoneNumber){
17 | mName = name;
18 | mPhoneNumber = phoneNumber;
19 | }
20 |
21 | public int getDistance() {
22 | return mDistance;
23 | }
24 |
25 | public void setDistance(int distance) {
26 | mDistance = distance;
27 | }
28 |
29 | public String getName() {
30 | return mName;
31 | }
32 |
33 | public void setName(String name) {
34 | mName = name;
35 | }
36 |
37 | public String getPhoneNumber() {
38 | return mPhoneNumber;
39 | }
40 |
41 | public void setPhoneNumber(String phoneNumber) {
42 | mPhoneNumber = phoneNumber;
43 | }
44 |
45 | public double[] getLocation() {
46 | return mLocation;
47 | }
48 |
49 | public void setLocation(double[] location) {
50 | mLocation = location;
51 | }
52 |
53 | public IoSession getSession() {
54 | return mSession;
55 | }
56 |
57 | public void setSession(IoSession session) {
58 | mSession = session;
59 | }
60 |
61 | public LatLng getLatLng() {
62 | return new LatLng(getLocation()[0],getLocation()[1]);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/driver/src/main/res/layout/activity_passenger_info.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
18 |
19 |
23 |
33 |
44 |
45 |
--------------------------------------------------------------------------------
/driver/src/main/res/layout/item_passenger_info.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
10 |
11 |
15 |
16 |
25 |
26 |
32 |
33 |
34 |
41 |
42 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
12 |
13 |
16 |
17 |
25 |
26 |
29 |
30 |
38 |
39 |
48 |
--------------------------------------------------------------------------------
/driver/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
12 |
13 |
16 |
17 |
25 |
26 |
29 |
30 |
38 |
39 |
48 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/baidulocation/LocationManager.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.baidulocation;
2 |
3 | import android.content.Context;
4 |
5 | import com.baidu.location.BDLocation;
6 | import com.baidu.location.BDLocationListener;
7 | import com.baidu.location.LocationClient;
8 | import com.baidu.location.LocationClientOption;
9 | import com.zyw.driver.api.OnLocationReceivedListener;
10 |
11 | /**
12 | * Created by zyw on 2015/11/13.
13 | */
14 | public class LocationManager {
15 |
16 | private LocationClient mLocationClient;
17 |
18 | private int mScanSpanInMillis = 10000;
19 |
20 | private DriverLocationListener mLocationListener;
21 |
22 | private OnLocationReceivedListener mListener;
23 |
24 | public LocationManager(Context context){
25 | mLocationClient = new LocationClient(context);
26 | }
27 |
28 | public void init(OnLocationReceivedListener listener) {
29 | LocationClientOption option = new LocationClientOption();
30 | mListener = listener;
31 | option.setScanSpan(mScanSpanInMillis);
32 | option.setNeedDeviceDirect(true);
33 | option.setOpenGps(true);
34 | option.setEnableSimulateGps(true);
35 | option.setIsNeedAddress(true);
36 | option.setCoorType("bd09ll");
37 | mLocationClient.setLocOption(option);
38 | mLocationListener = new DriverLocationListener();
39 | mLocationClient.registerLocationListener(mLocationListener);
40 | }
41 |
42 | public void start(){
43 | mLocationClient.start();
44 | }
45 |
46 | public void stop(){
47 | mLocationClient.unRegisterLocationListener(mLocationListener);
48 | mLocationListener = null;
49 | mLocationClient.stop();
50 | }
51 |
52 | class DriverLocationListener implements BDLocationListener {
53 |
54 |
55 | @Override
56 | public void onReceiveLocation(BDLocation bdLocation) {
57 | if (mListener != null) {
58 | mListener.onLocationReceived(bdLocation);
59 | }
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/adapter/SuggestionInfoAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.adapter;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.TextView;
9 |
10 | import com.baidu.mapapi.search.sug.SuggestionResult;
11 |
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 | /**
16 | * Created by zyw on 2015/11/8.
17 | */
18 | public class SuggestionInfoAdapter extends BaseAdapter {
19 |
20 | private Context mContext;
21 |
22 | private List mInfoList;
23 |
24 | public SuggestionInfoAdapter(Context context){
25 | mContext = context;
26 | mInfoList = new ArrayList<>();
27 | }
28 |
29 | @Override
30 | public int getCount() {
31 | return mInfoList.size();
32 | }
33 |
34 | public void addAll(List list) {
35 | mInfoList.clear();
36 | mInfoList.addAll(list);
37 | notifyDataSetChanged();
38 | }
39 |
40 | @Override
41 | public SuggestionResult.SuggestionInfo getItem(int position) {
42 | return mInfoList.get(position);
43 | }
44 |
45 | @Override
46 | public long getItemId(int position) {
47 | return position;
48 | }
49 |
50 | @Override
51 | public View getView(int position, View convertView, ViewGroup parent) {
52 |
53 | ViewHolder holder = null;
54 | if (convertView == null) {
55 | holder = new ViewHolder();
56 | convertView = LayoutInflater.from(mContext).inflate(android.R.layout.simple_list_item_1, parent, false);
57 | holder.tvDest = (TextView) convertView.findViewById(android.R.id.text1);
58 | convertView.setTag(holder);
59 | } else {
60 | holder = (ViewHolder) convertView.getTag();
61 | }
62 | holder.tvDest.setText(getItem(position).key);
63 | return convertView;
64 | }
65 |
66 | static class ViewHolder {
67 | TextView tvDest;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/utils/LogHelper.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.utils;
2 |
3 | import android.util.Log;
4 |
5 | /**
6 | * Created by zyw on 2015/10/19.
7 | * 打印日志的帮助类
8 | */
9 | public class LogHelper {
10 |
11 | public static boolean isShouldUseLog = true;
12 | private static final String LOG_PREFIX = "blocksms_";
13 | private static final int LOG_PREFIX_LENGTH = LOG_PREFIX.length();
14 | private static final int MAX_LOG_TAG_LENGHT = 23;
15 |
16 |
17 | public static String makeLogTag(String str){
18 | if (str.length() > MAX_LOG_TAG_LENGHT - LOG_PREFIX_LENGTH) {
19 | return LOG_PREFIX + str.substring(0, MAX_LOG_TAG_LENGHT - LOG_PREFIX_LENGTH - 1);
20 | }
21 |
22 | return LOG_PREFIX + str;
23 | }
24 |
25 | public static String makeLogTag(Class cls) {
26 | return makeLogTag(cls.getSimpleName());
27 | }
28 |
29 | public static void v(String tag, Object... messages) {
30 | if (isShouldUseLog) {
31 | log(tag, Log.VERBOSE, null, messages);
32 | }
33 | }
34 |
35 | public static void d(String tag, Object... messages) {
36 | if (isShouldUseLog) {
37 | log(tag, Log.DEBUG, null, messages);
38 | }
39 | }
40 |
41 | public static void i(String tag, Object... messages) {
42 | log(tag,Log.INFO,null,messages);
43 | }
44 |
45 | public static void w(String tag, Object... messages) {
46 | log(tag,Log.WARN,null,messages);
47 | }
48 |
49 | public static void e(String tag, Object... messages) {
50 | log(tag, Log.ERROR, null, messages);
51 | }
52 |
53 |
54 | public static void log(String tag, int level, Throwable t, Object... messages) {
55 | String message;
56 | if (t == null && messages != null && messages.length == 1) {
57 | message = messages[0].toString();
58 | } else {
59 | StringBuilder sb = new StringBuilder();
60 | if (messages != null) for (Object m : messages) {
61 | sb.append(m);
62 | }
63 | if (t != null) sb.append("\n").append(Log.getStackTraceString(t));
64 | message = sb.toString();
65 | }
66 | Log.println(level, tag, message);
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/utils/LogHelper.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.utils;
2 |
3 | import android.util.Log;
4 |
5 | /**
6 | * Created by zyw on 2015/3/19.
7 | * 打印日志的帮助类
8 | */
9 | public class LogHelper {
10 |
11 | public static boolean isShouldUseLog = true;
12 | private static final String LOG_PREFIX = "blocksms_";
13 | private static final int LOG_PREFIX_LENGTH = LOG_PREFIX.length();
14 | private static final int MAX_LOG_TAG_LENGHT = 23;
15 |
16 |
17 | public static String makeLogTag(String str){
18 | if (str.length() > MAX_LOG_TAG_LENGHT - LOG_PREFIX_LENGTH) {
19 | return LOG_PREFIX + str.substring(0, MAX_LOG_TAG_LENGHT - LOG_PREFIX_LENGTH - 1);
20 | }
21 |
22 | return LOG_PREFIX + str;
23 | }
24 |
25 | public static String makeLogTag(Class cls) {
26 | return makeLogTag(cls.getSimpleName());
27 | }
28 |
29 | public static void v(String tag, Object... messages) {
30 | if (isShouldUseLog) {
31 | log(tag, Log.VERBOSE, null, messages);
32 | }
33 | }
34 |
35 | public static void d(String tag, Object... messages) {
36 | if (isShouldUseLog) {
37 | log(tag, Log.DEBUG, null, messages);
38 | }
39 | }
40 |
41 | public static void i(String tag, Object... messages) {
42 | log(tag,Log.INFO,null,messages);
43 | }
44 |
45 | public static void w(String tag, Object... messages) {
46 | log(tag,Log.WARN,null,messages);
47 | }
48 |
49 | public static void e(String tag, Object... messages) {
50 | log(tag, Log.ERROR, null, messages);
51 | }
52 |
53 |
54 | public static void log(String tag, int level, Throwable t, Object... messages) {
55 | String message;
56 | if (t == null && messages != null && messages.length == 1) {
57 | message = messages[0].toString();
58 | } else {
59 | StringBuilder sb = new StringBuilder();
60 | if (messages != null) for (Object m : messages) {
61 | sb.append(m);
62 | }
63 | if (t != null) sb.append("\n").append(Log.getStackTraceString(t));
64 | message = sb.toString();
65 | }
66 | Log.println(level, tag, message);
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/socketclient/DriverHandler.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.socketclient;
2 |
3 | import android.util.Log;
4 |
5 | import com.zyw.driver.api.OnMessageReceivedListener;
6 | import com.zyw.driver.utils.LogHelper;
7 |
8 | import org.apache.mina.core.service.IoHandlerAdapter;
9 | import org.apache.mina.core.session.IoSession;
10 |
11 | /**
12 | * Created by zyw on 2015/9/20.
13 | */
14 | public class DriverHandler extends IoHandlerAdapter {
15 | private static final String TAG = "TaxiRequestHandler";
16 |
17 | @Override
18 | public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
19 | Log.e(TAG, cause.getMessage(), cause);
20 | super.exceptionCaught(session, cause);
21 | }
22 |
23 | @Override
24 | public void messageReceived(IoSession session, Object message) throws Exception {
25 | super.messageReceived(session, message);
26 | //接受服务端的消息
27 | Log.d(TAG, (String) message);
28 | String msg = (String) message;
29 | String[] results = msg.split("://");
30 | String requestType = results[0];
31 | String detail = results[1];
32 | //根据action判断消息的类型
33 | switch (requestType) {
34 | case "update_passenger":
35 | //接受消息
36 | if (mListener != null) {
37 | mListener.onUpdatePassenger(detail);
38 | }
39 | break;
40 | case "passenger_cancel_call":
41 | if (mListener != null) {
42 | mListener.onPassengerCancel(detail);
43 | }
44 | break;
45 | case "passenger_taken":
46 | if (mListener != null) {
47 | mListener.onPassengerTaken(detail);
48 | }
49 | break;
50 | case "passenger_offline":
51 | if (mListener != null) {
52 | mListener.onPassengerOffline(detail);
53 | }
54 | break;
55 | default:
56 | LogHelper.d(TAG, "unknown request type:" + requestType);
57 | break;
58 | }
59 | }
60 |
61 | private OnMessageReceivedListener mListener;
62 |
63 | public void setOnMessageReceivedListener(OnMessageReceivedListener listener) {
64 | mListener = listener;
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
23 |
26 |
27 |
30 |
31 |
32 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/socketclient/TaxiRequestHandler.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.socketclient;
2 |
3 | import android.util.Log;
4 |
5 | import com.zyw.calltaxi.api.OnMessageReceivedListener;
6 | import com.zyw.calltaxi.utils.LogHelper;
7 |
8 | import org.apache.mina.core.service.IoHandlerAdapter;
9 | import org.apache.mina.core.session.IoSession;
10 |
11 | /**
12 | * Created by zyw on 2015/9/20.
13 | */
14 | public class TaxiRequestHandler extends IoHandlerAdapter {
15 | private static final String TAG = "TaxiRequestHandler";
16 |
17 | /**
18 | * 捕捉异常
19 | * @param session
20 | * @param cause
21 | * @throws Exception
22 | */
23 | @Override
24 | public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
25 | Log.e(TAG, cause.getMessage(), cause);
26 | super.exceptionCaught(session, cause);
27 | }
28 |
29 | /**
30 | * 接受服务端消息
31 | * @param session
32 | * @param message
33 | * @throws Exception
34 | */
35 | @Override
36 | public void messageReceived(IoSession session, Object message) throws Exception {
37 | super.messageReceived(session, message);
38 | //接受服务端的消息
39 | Log.d(TAG, (String) message);
40 | String msg = (String) message;
41 | //用"://"分割字符串
42 | String[] results = msg.split("://");
43 | //请求类型
44 | String requestType = results[0];
45 | //细节
46 | String detail = results[1];
47 | //根据action判断消息的类型
48 | switch (requestType) {
49 | //司机接单
50 | case "driver_accept":
51 | if (mListener != null) {
52 | mListener.onDriverAccept(detail);
53 | }
54 | break;
55 | //司机状态更新
56 | case "update_driver":
57 | if (mListener != null) {
58 | mListener.onUpdateDriver(detail);
59 | }
60 | break;
61 | //司机下线
62 | case "driver_offline":
63 | if (mListener != null){
64 | mListener.onDriverOffline(detail);
65 | }
66 | break;
67 | //未知的请求类型
68 | default:
69 | LogHelper.d(TAG, "unknown request type:" + requestType);
70 | break;
71 | }
72 | }
73 |
74 |
75 | private OnMessageReceivedListener mListener;
76 |
77 | /**
78 | * 注册接收服务端司机信息的监听器
79 | * @param listener
80 | */
81 | public void setOnMessageReceivedListener(OnMessageReceivedListener listener) {
82 | mListener = listener;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/driver/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
30 |
32 |
35 |
36 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_waiting.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
17 |
18 |
29 |
30 |
34 |
35 |
44 |
45 |
56 |
57 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/ui/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.ui;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.content.SharedPreferences;
6 | import android.os.Bundle;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.text.TextUtils;
9 | import android.view.View;
10 | import android.widget.Button;
11 | import android.widget.EditText;
12 |
13 | import com.zyw.driver.R;
14 | import com.zyw.driver.utils.ToastUtils;
15 |
16 | /**
17 | * Created by zyw on 2015/11/8.
18 | */
19 | public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
20 |
21 | public static final String SP_USER_NAME = "sp_name";
22 |
23 | public static final String SP_PHONE_NUMBER = "sp_phone_number";
24 |
25 | public static final String EXTRA_NAME = "extra_name";
26 |
27 | public static final String EXTRA_PHONE_NUMBER = "extra_phone_number";
28 |
29 | public static final String EXTRA_ADRESS = "extra_adress";
30 | public static final String EXTRA_DISTANCE = "extra_distance";
31 | public static final String EXTRA_DEST_DISTANCE = "extra_dest_distance";
32 |
33 | private EditText mEtName;
34 |
35 | private EditText mEtPhoneNumber;
36 |
37 | private Button mBtnLogin;
38 |
39 | private SharedPreferences mSharedPreferences;
40 |
41 | @Override
42 | protected void onCreate(Bundle savedInstanceState) {
43 | super.onCreate(savedInstanceState);
44 | setContentView(R.layout.activity_login);
45 | mSharedPreferences = getSharedPreferences("CallTaxi", Context.MODE_PRIVATE);
46 | initViews();
47 | }
48 |
49 | private void initViews() {
50 | mEtName = (EditText) findViewById(R.id.et_user_name);
51 | mEtPhoneNumber = (EditText) findViewById(R.id.et_phone_number);
52 |
53 | String userName = mSharedPreferences.getString(SP_USER_NAME, "");
54 | String phoneNumber = mSharedPreferences.getString(SP_PHONE_NUMBER, "");
55 | if (!TextUtils.isEmpty(userName)) {
56 | mEtName.setText(userName);
57 | }
58 | if (!TextUtils.isEmpty(phoneNumber)) {
59 | mEtPhoneNumber.setText(phoneNumber);
60 | }
61 | mBtnLogin = (Button) findViewById(R.id.btn_login);
62 | mBtnLogin.setOnClickListener(this);
63 | }
64 |
65 | @Override
66 | public void onClick(View view) {
67 | saveUserInfo();
68 | login();
69 | finish();
70 | }
71 |
72 | /**
73 | * 保存用户的信息到SharedPreferences
74 | */
75 | private void saveUserInfo() {
76 | SharedPreferences.Editor editor = mSharedPreferences.edit();
77 | editor.putString(SP_USER_NAME, mEtName.getText().toString());
78 | editor.putString(SP_PHONE_NUMBER, mEtPhoneNumber.getText().toString());
79 | editor.commit();
80 | }
81 |
82 | private void login() {
83 | String name = mEtName.getText().toString();
84 | String phoneNumber = mEtPhoneNumber.getText().toString();
85 | if (TextUtils.isEmpty(name) || TextUtils.isEmpty(phoneNumber)) {
86 | ToastUtils.showToast(this, "请输入用户名和手机号!");
87 | return;
88 | }
89 | Intent intent = new Intent(this, MainActivity.class);
90 | intent.putExtra(EXTRA_NAME, name);
91 | intent.putExtra(EXTRA_PHONE_NUMBER, phoneNumber);
92 | startActivity(intent);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/ui/PassengerInfoActivity.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.ui;
2 |
3 | import android.app.Activity;
4 | import android.app.AlertDialog;
5 | import android.content.DialogInterface;
6 | import android.content.Intent;
7 | import android.net.Uri;
8 | import android.os.Bundle;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.view.View;
11 | import android.widget.TextView;
12 |
13 | import com.zyw.driver.R;
14 |
15 | /**
16 | * Created by zyw on 2015/11/15.
17 | */
18 | public class PassengerInfoActivity extends AppCompatActivity implements View.OnClickListener {
19 |
20 | private TextView mTvPassengerInfo;
21 | private String mPassengerPhoneNumber;
22 | private AlertDialog mCompleteDialog = null;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_passenger_info);
28 | initViews();
29 | }
30 |
31 | private void initViews() {
32 | mTvPassengerInfo = (TextView) findViewById(R.id.tv_passenger_info);
33 | Intent intent = getIntent();
34 | String name = intent.getStringExtra(LoginActivity.EXTRA_NAME);
35 | mPassengerPhoneNumber = intent.getStringExtra(LoginActivity.EXTRA_PHONE_NUMBER);
36 | String adress = intent.getStringExtra(LoginActivity.EXTRA_ADRESS);
37 | int destDistance = intent.getIntExtra(LoginActivity.EXTRA_DEST_DISTANCE, -1);
38 | int distance = intent.getIntExtra(LoginActivity.EXTRA_DISTANCE, -1);
39 |
40 | mTvPassengerInfo.setText(getString(R.string.passenger_info, name, mPassengerPhoneNumber, adress, destDistance, distance));
41 | findViewById(R.id.btn_call_passenger).setOnClickListener(this);
42 | }
43 |
44 | @Override
45 | public void onClick(View v) {
46 | callPassenger();
47 | }
48 |
49 | private void callPassenger() {
50 | Intent intent = new Intent(Intent.ACTION_VIEW);
51 | intent.setData(Uri.parse("tel:"+getIntent().getStringExtra(LoginActivity.EXTRA_PHONE_NUMBER)));
52 | startActivity(intent);
53 | }
54 |
55 | @Override
56 | public void onBackPressed() {
57 | if (mCompleteDialog == null) {
58 | createDoneDialog();
59 | } else {
60 | if (mCompleteDialog.isShowing()) {
61 | mCompleteDialog.dismiss();
62 | }else {
63 | mCompleteDialog.show();
64 | }
65 | }
66 | }
67 |
68 | public void btnHandlerComplete(View view) {
69 | if (mCompleteDialog == null) {
70 | createDoneDialog();
71 | } else {
72 | if (mCompleteDialog.isShowing()){
73 | mCompleteDialog.dismiss();
74 | }else {
75 | mCompleteDialog.show();
76 | }
77 | }
78 | }
79 | private void createDoneDialog() {
80 | mCompleteDialog = new AlertDialog.Builder(this)
81 | .setTitle("将离开本页面")
82 | .setMessage("您确定已经记下了乘客的信息?\n手机:" + mPassengerPhoneNumber)
83 | .setNegativeButton("取消", null)
84 | .setPositiveButton("确定", new DialogInterface.OnClickListener() {
85 | @Override
86 | public void onClick(DialogInterface dialog, int which) {
87 | setResult(Activity.RESULT_OK);
88 | finish();
89 | }
90 | })
91 | .show();
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/adapter/PassengerInfoAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.adapter;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.TextView;
9 |
10 | import com.zyw.driver.R;
11 | import com.zyw.driver.model.Passenger;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | /**
17 | * Created by zyw on 2015/11/13.
18 | */
19 | public class PassengerInfoAdapter extends BaseAdapter {
20 |
21 | private Context mContext;
22 | private List mPassengers;
23 | private List mPassengerNumbers = new ArrayList<>();
24 |
25 | public PassengerInfoAdapter(Context context) {
26 | mContext = context;
27 | mPassengers = new ArrayList<>();
28 | }
29 |
30 | public void updatePassenger(Passenger passenger) {
31 | if (mPassengerNumbers.contains(passenger.getPhoneNumber())) {
32 | int position = mPassengerNumbers.indexOf(passenger.getPhoneNumber());
33 | Passenger p = mPassengers.get(position);
34 | p.setLocation(passenger.getLocation());
35 | p.setDestination(passenger.getDestination());
36 | p.setDistance(passenger.getDistance());
37 | } else {
38 | mPassengers.add(passenger);
39 | mPassengerNumbers.add(passenger.getPhoneNumber());
40 | }
41 | notifyDataSetChanged();
42 | }
43 |
44 | public void removePassenger(Passenger passenger) {
45 | if (mPassengerNumbers.contains(passenger.getPhoneNumber())) {
46 | int position = mPassengerNumbers.indexOf(passenger.getPhoneNumber());
47 | mPassengers.remove(position);
48 | mPassengerNumbers.remove(position);
49 | notifyDataSetChanged();
50 | }
51 | }
52 |
53 | @Override
54 | public int getCount() {
55 | return mPassengers.size();
56 | }
57 |
58 | @Override
59 | public Passenger getItem(int position) {
60 | return mPassengers.get(position);
61 | }
62 |
63 | @Override
64 | public long getItemId(int position) {
65 | return position;
66 | }
67 |
68 | @Override
69 | public View getView(int position, View convertView, ViewGroup parent) {
70 | ViewHolder holder;
71 | Passenger passenger = getItem(position);
72 | if (convertView == null) {
73 | holder = new ViewHolder();
74 | convertView = LayoutInflater.from(mContext).inflate(R.layout.item_passenger_info, parent, false);
75 | holder.tvName = (TextView) convertView.findViewById(R.id.tv_passenger_name);
76 | holder.tvDestination = (TextView) convertView.findViewById(R.id.tv_destination);
77 | holder.tvDistance = (TextView) convertView.findViewById(R.id.tv_distance);
78 | convertView.setTag(holder);
79 | } else {
80 | holder = (ViewHolder) convertView.getTag();
81 | }
82 | holder.tvName.setText(passenger.getName());
83 | holder.tvDistance.setText(passenger.getDistance() + "m");
84 | int destDistance = (int)(passenger.getDestination().getDistance()) / 1000;
85 | holder.tvDestination.setText(passenger.getDestination().getDetailAdress() + " " + destDistance + "km");
86 | return convertView;
87 | }
88 |
89 |
90 | static class ViewHolder {
91 | TextView tvName;
92 | TextView tvDistance;
93 | TextView tvDestination;
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/service/DriverService.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.service;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.os.Binder;
6 | import android.os.IBinder;
7 | import android.support.annotation.Nullable;
8 |
9 | import com.zyw.driver.api.DriverServiceCallback;
10 | import com.zyw.driver.api.OnMessageReceivedListenerAdapter;
11 | import com.zyw.driver.model.Passenger;
12 | import com.zyw.driver.socketclient.DriverSocketClient;
13 | import com.zyw.driver.ui.LoginActivity;
14 | import com.zyw.driver.utils.LogHelper;
15 |
16 | /**
17 | * Created by zyw on 2015/11/9.
18 | */
19 | public class DriverService extends Service {
20 | private static final String TAG = LogHelper.makeLogTag(DriverService.class);
21 |
22 | public static final String EXTRA_DRIVER_NAME = "extra_driver_name";
23 |
24 | public static final String EXTRA_DRIVER_PHONE_NUMBER = "extra_driver_phone_number";
25 |
26 | private DriverSocketClient mSocketClient;
27 |
28 | private DriverServiceBinder mBinder;
29 |
30 |
31 | private DriverServiceCallback mCallback;
32 | @Nullable
33 | @Override
34 | public IBinder onBind(Intent intent) {
35 | LogHelper.d(TAG, "service onBind");
36 | mBinder = new DriverServiceBinder();
37 | String name = intent.getStringExtra(LoginActivity.EXTRA_NAME);
38 | String phoneNumber = intent.getStringExtra(LoginActivity.EXTRA_PHONE_NUMBER);
39 | mSocketClient = new DriverSocketClient(name,phoneNumber,new DriverSocketClient.Callback() {
40 | @Override
41 | public void onTimeOut() {
42 | LogHelper.d(TAG, "onTimeOut");
43 | }
44 | @Override
45 | public void onConnected() {
46 | mBinder.passengerLogin();
47 | mSocketClient.getHandler().setOnMessageReceivedListener(new OnMessageReceivedListenerAdapter(){
48 | @Override
49 | public void onUpdatePassenger(String message) {
50 | if (mCallback != null) {
51 | mCallback.onUpdatePassenger(message);
52 | }
53 | }
54 |
55 | @Override
56 | public void onPassengerTaken(String message) {
57 | if (mCallback != null) {
58 | mCallback.onPassengerTaken(message);
59 | }
60 | }
61 |
62 | @Override
63 | public void onPassengerCancel(String message) {
64 | if (mCallback != null) {
65 | mCallback.onPassengerCancel(message);
66 | }
67 | }
68 |
69 | @Override
70 | public void onPassengerOffline(String message) {
71 | if (mCallback != null){
72 | mCallback.onPassengerOffline(message);
73 | }
74 | }
75 | });
76 | }
77 | });
78 | mSocketClient.init();
79 | return mBinder;
80 | }
81 |
82 | @Override
83 | public void onDestroy() {
84 | disconnect();
85 | super.onDestroy();
86 | }
87 |
88 | private void disconnect() {
89 | mSocketClient.disconnect();
90 | }
91 |
92 | public class DriverServiceBinder extends Binder {
93 |
94 | public void passengerLogin(){
95 | mSocketClient.driverLogin();
96 | }
97 |
98 | public void updateLocation(double[] location){
99 | mSocketClient.updateLocation(location);
100 | }
101 |
102 | public void driverAccept(Passenger passenger,double[] location){
103 | mSocketClient.driverAccept(passenger,location);
104 | }
105 |
106 | public void addCallback(DriverServiceCallback callback) {
107 | mCallback = callback;
108 | }
109 |
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/ui/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.ui;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.content.SharedPreferences;
6 | import android.os.Bundle;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.text.TextUtils;
9 | import android.view.View;
10 | import android.widget.Button;
11 | import android.widget.EditText;
12 |
13 | import com.baidu.mapapi.model.LatLng;
14 | import com.baidu.mapapi.utils.DistanceUtil;
15 | import com.zyw.calltaxi.R;
16 | import com.zyw.calltaxi.utils.LogHelper;
17 | import com.zyw.calltaxi.utils.ToastUtils;
18 |
19 | /**
20 | * Created by zyw on 2015/11/8.
21 | * 登陆
22 | */
23 | public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
24 |
25 | public static final String SP_USER_NAME = "sp_name";//给sharedpreferences的姓名
26 |
27 | public static final String SP_PHONE_NUMBER = "sp_phone_number";//给sharedpreferences的电话号
28 |
29 | public static final String EXTRA_NAME = "extra_name";//给intent的姓名
30 |
31 | public static final String EXTRA_PHONE_NUMBER = "extra_phone_number";//给intent的电话号
32 | /**
33 | * //{"passengerName":"zyw","location":{"lat":22.593371,"lng":114.279487}}
34 | handlePassengerUpdateLocation
35 | passengerName:zyw update_driver://{"driverName":"我是司机","location":{"lng":114.279458,"lat":22.593403}}
36 | //{"destination":{"detailAdress":"北京天安门","destLat":22.630564784549,"destLng":113.82012299723381,"distance":47333.79882022791}}
37 | distance=4.0
38 | */
39 | private EditText mEtName;//输入姓名
40 |
41 | private EditText mEtPhoneNumber;//输入电话
42 |
43 | private Button mBtnLogin;//登陆按钮
44 |
45 | private SharedPreferences mSharedPreferences;
46 |
47 | @Override
48 | protected void onCreate(Bundle savedInstanceState) {
49 | super.onCreate(savedInstanceState);
50 | setContentView(R.layout.activity_login);
51 |
52 | mSharedPreferences = getSharedPreferences("CallTaxi", Context.MODE_PRIVATE);//获取数据
53 | initViews();
54 |
55 | debug();
56 |
57 | }
58 |
59 | /**
60 | * 用一个特例检查代码是否正确
61 | */
62 | private void debug() {
63 | LatLng passenger = new LatLng(22.593371,114.279487);//乘客经纬度
64 | LatLng driver = new LatLng(22.593403,114.279458);//司机经纬度
65 | LatLng destination = new LatLng(22.630564784549,113.82012299723381);//目的地经纬度
66 | double p2d = DistanceUtil.getDistance(passenger, driver);//乘客和司机的距离
67 | double p2dest = DistanceUtil.getDistance(passenger,destination);//乘客和目的地的距离
68 | LogHelper.d("LoginActivity", "passenger to driver " + p2d + " passenger to destination " + p2dest);
69 | }
70 |
71 | /**
72 | * 初始化视图
73 | */
74 | private void initViews() {
75 | mEtName = (EditText) findViewById(R.id.et_user_name);
76 | mEtPhoneNumber = (EditText) findViewById(R.id.et_phone_number);
77 |
78 | String userName = mSharedPreferences.getString(SP_USER_NAME,"");//从sharedpreference中获取用户姓名
79 | String phoneNumber = mSharedPreferences.getString(SP_PHONE_NUMBER,"");//从sharedpreference中获取电话号
80 | if (!TextUtils.isEmpty(userName)){
81 | mEtName.setText(userName);//自动显示userName
82 | }
83 | if (!TextUtils.isEmpty(phoneNumber)){
84 | mEtPhoneNumber.setText(phoneNumber);//自动显示phoneNumber
85 | }
86 | mBtnLogin = (Button) findViewById(R.id.btn_login);//登陆按钮
87 | mBtnLogin.setOnClickListener(this);
88 | }
89 |
90 | /**
91 | * 登陆按钮点击事件
92 | * @param view
93 | */
94 | @Override
95 | public void onClick(View view){
96 | saveUserInfo();//保存用户的信息到SharedPreferences
97 | login();
98 | finish();
99 | }
100 |
101 | /**
102 | * 保存用户的信息到SharedPreferences
103 | */
104 | private void saveUserInfo() {
105 | SharedPreferences.Editor editor = mSharedPreferences.edit();//获得SharedPreferences编辑器
106 | editor.putString(SP_USER_NAME, mEtName.getText().toString());//添加用户名键值对
107 | editor.putString(SP_PHONE_NUMBER,mEtPhoneNumber.getText().toString());//添加电话号键值对
108 | editor.commit();//提交编辑
109 | }
110 |
111 | /**
112 | * 登陆
113 | */
114 | private void login() {
115 | String name = mEtName.getText().toString();
116 | String phoneNumber = mEtPhoneNumber.getText().toString();
117 | if (TextUtils.isEmpty(name) || TextUtils.isEmpty(phoneNumber)) {
118 | ToastUtils.showToast(this, "请输入用户名和手机号!");
119 | return;
120 | }
121 | Intent intent = new Intent(this,MapActivity.class);//跳转至MapActivity
122 | intent.putExtra(EXTRA_NAME,name);//添加姓名键值对
123 | intent.putExtra(EXTRA_PHONE_NUMBER,phoneNumber);//添加电话号键值对
124 | startActivity(intent);
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/ui/DestSearchActivity.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.ui;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.text.Editable;
8 | import android.text.TextWatcher;
9 | import android.util.Log;
10 | import android.view.View;
11 | import android.widget.AdapterView;
12 | import android.widget.Button;
13 | import android.widget.EditText;
14 | import android.widget.ListView;
15 |
16 | import com.baidu.mapapi.search.sug.OnGetSuggestionResultListener;
17 | import com.baidu.mapapi.search.sug.SuggestionResult;
18 | import com.baidu.mapapi.search.sug.SuggestionSearch;
19 | import com.baidu.mapapi.search.sug.SuggestionSearchOption;
20 | import com.zyw.calltaxi.R;
21 | import com.zyw.calltaxi.adapter.SuggestionInfoAdapter;
22 | import com.zyw.calltaxi.utils.ToastUtils;
23 |
24 | import java.util.List;
25 |
26 | /**
27 | * Created by zyw on 2015/11/8.
28 | * 目的地搜索
29 | */
30 | public class DestSearchActivity extends AppCompatActivity implements View.OnClickListener, AdapterView.OnItemClickListener, OnGetSuggestionResultListener {
31 |
32 | private EditText mEtInputDest;
33 |
34 | private Button mBtnSearchDest;
35 |
36 | private ListView mDestList;
37 |
38 | private SuggestionInfoAdapter mAdapter;
39 |
40 | private SuggestionSearch mSuggestionSearch;
41 |
42 | private String mCity;
43 |
44 | @Override
45 | protected void onCreate(Bundle savedInstanceState) {
46 | super.onCreate(savedInstanceState);
47 | setContentView(R.layout.activity_dest_search);
48 | initViews();//初始化视图
49 | mSuggestionSearch = SuggestionSearch.newInstance();//实例化建议搜索类
50 | mSuggestionSearch.setOnGetSuggestionResultListener(this);//设置获得建议结果的监听器
51 | }
52 |
53 | private void initViews() {
54 | mEtInputDest = (EditText) findViewById(R.id.et_input_dest);//输入目的地
55 | mBtnSearchDest = (Button) findViewById(R.id.btn_search_dest);//搜索目的地的按钮
56 | mDestList = (ListView) findViewById(R.id.lv_dest);//建议信息列表
57 |
58 | /**
59 | * 为EditText添加文字改变监听器,传入实现抽象方法的TextWatcher
60 | */
61 | mEtInputDest.addTextChangedListener(new TextWatcher() {
62 | /**
63 | * 在字符串s中,当从start开始的count个字符,替代了以前的before个字符时,触发的事件
64 | * @param s
65 | * @param start
66 | * @param before
67 | * @param count
68 | */
69 | @Override
70 | public void onTextChanged(CharSequence s, int start, int before, int count) {
71 | mSuggestionSearch.requestSuggestion(new SuggestionSearchOption()
72 | .keyword(s.toString())
73 | .city(getIntent().getStringExtra(MapActivity.EXTRA_CITY)));//建议搜索类调用请求建议方法,设置建议搜索选项的关键字和城市,s就是输入框里的内容
74 | }
75 |
76 | @Override
77 | public void beforeTextChanged(CharSequence s, int start, int count, int after) {
78 | }
79 |
80 | @Override
81 | public void afterTextChanged(Editable s) {
82 | }
83 | });
84 | mBtnSearchDest.setOnClickListener(this);//设置搜索目的地按钮点击事件
85 | mDestList.setOnItemClickListener(this);//设置建议信息listview的item点击事件
86 | mAdapter = new SuggestionInfoAdapter(this);//实例化建议信息适配器
87 | mDestList.setAdapter(mAdapter);//将建议信息适配器作为建议信息listview的适配器
88 | }
89 |
90 | /**
91 | * 设置搜索目的地按钮点击事件
92 | * @param v
93 | */
94 | @Override
95 | public void onClick(View v) {
96 | mSuggestionSearch.requestSuggestion(new SuggestionSearchOption()
97 | .keyword(mEtInputDest.getText().toString())
98 | .city(getIntent().getStringExtra(MapActivity.EXTRA_CITY)));//建议搜索类调用请求建议方法,配置建议搜索选项的关键字和城市
99 | }
100 |
101 | /**
102 | * 设置建议信息listview的item点击事件
103 | * @param parent
104 | * @param view
105 | * @param position
106 | * @param id
107 | */
108 | @Override
109 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
110 | SuggestionResult.SuggestionInfo suggestionInfo = mAdapter.getItem(position);//获得点击条目SuggestionInfo
111 | if (suggestionInfo != null) {
112 | Intent result = new Intent();
113 | result.putExtra(MapActivity.EXTRA_DEST, suggestionInfo.key);//关键字
114 | result.putExtra(MapActivity.EXTRA_LATITUDE, suggestionInfo.pt.latitude);//纬度
115 | result.putExtra(MapActivity.EXTRA_LONGITUDE, suggestionInfo.pt.longitude);//经度
116 | setResult(Activity.RESULT_OK, result);//带着关键字和经纬度信息返回MapActivity
117 | finish();//结束DestSearchActivity
118 | }else {
119 | ToastUtils.showToast(this,"搜索出错了,选别的试试吧");
120 | }
121 | }
122 |
123 | /**
124 | * 当获取到建议结果时,将建议结果集合通过adapter添加到listview中
125 | * @param result
126 | */
127 | @Override
128 | public void onGetSuggestionResult(SuggestionResult result) {
129 |
130 | if (result == null || result.getAllSuggestions() == null) {
131 | return;
132 | }
133 | List suggestions = result.getAllSuggestions();//获得建议集合
134 | mAdapter.addAll(suggestions);//建议集合添加到listview中
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/socketclient/DriverSocketClient.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.socketclient;
2 |
3 | import com.zyw.driver.model.Message;
4 | import com.zyw.driver.model.Passenger;
5 | import com.zyw.driver.utils.LogHelper;
6 |
7 | import org.apache.mina.core.future.ConnectFuture;
8 | import org.apache.mina.core.session.IoSession;
9 | import org.apache.mina.filter.codec.ProtocolCodecFilter;
10 | import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
11 | import org.apache.mina.transport.socket.nio.NioSocketConnector;
12 |
13 | import java.net.InetSocketAddress;
14 | import java.nio.charset.Charset;
15 |
16 | /**
17 | * Created by zyw on 2015/9/20.
18 | */
19 | public class DriverSocketClient {
20 |
21 | private static final String TAG = LogHelper.makeLogTag(DriverSocketClient.class);
22 | /**
23 | * socketConnector对象
24 | */
25 | private NioSocketConnector mConnector;
26 | /**
27 | * 处理消息的Handler对象
28 | */
29 | private DriverHandler mHandler;
30 | /**
31 | * 客户端连接成功后取得的会话对象
32 | */
33 | private IoSession mSession;
34 | /**
35 | * 是否连接到服务器端的标志位
36 | */
37 | private boolean isConnected = false;
38 | /**
39 | * 是否已经初始化完成
40 | */
41 | private boolean initiated = false;
42 |
43 | /**
44 | * 连接服务器超时的回调
45 | */
46 | private Callback mCallback;
47 | /**
48 | * 开启socket连接的用户名
49 | */
50 | private String mName;
51 | /**
52 | * 开启socket连接的手机号
53 | */
54 | private String mPhoneNumber;
55 |
56 | public DriverSocketClient(String name, String phoneNumber, Callback callback) {
57 | mHandler = new DriverHandler();
58 | mCallback = callback;
59 | mName = name;
60 | mPhoneNumber = phoneNumber;
61 | }
62 |
63 | /**
64 | * 初始化客户端
65 | */
66 | public void init() {
67 | //如果已经初始化。不再重复进行
68 | if (initiated) {
69 | return;
70 | }
71 | new Thread() {
72 | @Override
73 | public void run() {
74 | mConnector = new NioSocketConnector();
75 | mConnector.setHandler(mHandler);
76 | mConnector.getFilterChain().addLast("codec",
77 | new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
78 | mConnector.setConnectTimeoutMillis(10000);
79 | ConnectFuture future = mConnector.connect(new InetSocketAddress("192.168.1.101", 9988));
80 | future.awaitUninterruptibly();
81 | try {
82 | mSession = future.getSession();
83 | isConnected = mSession.isConnected();
84 | if (isConnected) {
85 | if (mCallback != null) {
86 | mCallback.onConnected();
87 | }
88 | }
89 | } catch (Exception e) {
90 | reset();
91 | if (mCallback != null) {
92 | mCallback.onTimeOut();
93 | }
94 | e.printStackTrace();
95 | }
96 | }
97 | }.start();
98 | initiated = true;
99 | }
100 |
101 | /**
102 | * 重置客户端
103 | */
104 | public void reset() {
105 | mConnector.dispose();
106 | mConnector = null;
107 | initiated = false;
108 | }
109 |
110 | public DriverHandler getHandler() {
111 | return mHandler;
112 | }
113 |
114 | public void sendMessage(Message msg) {
115 | mSession.write((msg.toString()));
116 | }
117 |
118 | public void updateLocation(double[] location) {
119 | String type = "driver_update_location";
120 | Message updateMsg = new Message.MessageBuilder()
121 | .setRequestType(type)
122 | .setDriverName(mName)
123 | .setDriverPhoneNumber(mPhoneNumber)
124 | .setLocation(location)
125 | .build();
126 | sendMessage(updateMsg);
127 | }
128 |
129 | public void driverLogin() {
130 | String type = "driver_login";
131 | Message msg = new Message.MessageBuilder()
132 | .setRequestType(type)
133 | .setDriverName(mName)
134 | .setDriverPhoneNumber(mPhoneNumber)
135 | .build();
136 | sendMessage(msg);
137 | }
138 |
139 | public void driverAccept(Passenger passenger,double[] location) {
140 | String type = "driver_accept";
141 | Message msg = new Message.MessageBuilder()
142 | .setRequestType(type)
143 | .setDriverName(mName)
144 | .setDriverPhoneNumber(mPhoneNumber)
145 | .setPassengerName(passenger.getName())
146 | .setPassengerPhoneNumber(passenger.getPhoneNumber())
147 | .setLocation(location)
148 | .build();
149 | sendMessage(msg);
150 | }
151 |
152 |
153 | /**
154 | * 关闭客户端连接的方法
155 | */
156 | public void disconnect() {
157 | LogHelper.d(TAG, "disconect");
158 | mCallback = null;
159 | if (mSession != null && isConnected) {
160 | Message msg = new Message.MessageBuilder()
161 | .setRequestType("disconnect")
162 | .setDriverName(mName)
163 | .setDriverPhoneNumber(mPhoneNumber)
164 | .build();
165 | sendMessage(msg);
166 | mSession.close(true);
167 | mConnector.dispose();
168 | }
169 | }
170 |
171 | public interface Callback {
172 | void onTimeOut();
173 |
174 | void onConnected();
175 | }
176 |
177 | }
178 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/service/TaxiSocketService.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.service;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.os.Binder;
6 | import android.os.IBinder;
7 | import android.support.annotation.Nullable;
8 |
9 | import com.zyw.calltaxi.api.OnDriverUpdateCallback;
10 | import com.zyw.calltaxi.api.OnMessageReceivedListenerAdapter;
11 | import com.zyw.calltaxi.model.Destination;
12 | import com.zyw.calltaxi.model.Message;
13 | import com.zyw.calltaxi.socketclient.TaxiSocketClient;
14 | import com.zyw.calltaxi.ui.LoginActivity;
15 | import com.zyw.calltaxi.ui.WaitingActivity;
16 | import com.zyw.calltaxi.utils.LogHelper;
17 |
18 | /**
19 | * Created by zyw on 2015/11/9.
20 | * socket通信的service
21 | */
22 | public class TaxiSocketService extends Service {
23 | private static final String TAG = LogHelper.makeLogTag(TaxiSocketService.class);
24 |
25 | public static final String EXTRA_DRIVER_NAME = "extra_driver_name";//司机姓名intent键
26 |
27 | public static final String EXTRA_DRIVER_PHONE_NUMBER = "extra_driver_phone_number";//司机电话号intent键
28 |
29 | private TaxiSocketClient mSocketClient;//socket通信客户端
30 |
31 | private TaxiSocketServiceBinder mBinder;//service与activity通信的通道
32 |
33 | private boolean isWaitingOrdered = false;//是否在等待订单
34 |
35 | private OnDriverUpdateCallback mCallback;//司机更新信息的回调
36 |
37 | /**
38 | * TaxiSocketService与Activity绑定成功要做的工作,工作内容是开始监听socket连接:超时、成功的事件
39 | * @param intent
40 | * @return
41 | */
42 | @Nullable
43 | @Override
44 | public IBinder onBind(Intent intent) {
45 | LogHelper.d(TAG, "service onBind");
46 | mBinder = new TaxiSocketServiceBinder();//service与activity通信的通道
47 | String name = intent.getStringExtra(LoginActivity.EXTRA_NAME);//获取乘客登陆姓名
48 | String phoneNumber = intent.getStringExtra(LoginActivity.EXTRA_PHONE_NUMBER);//获取乘客登陆电话号
49 | mSocketClient = new TaxiSocketClient(name,phoneNumber,new TaxiSocketClient.Callback() {//实例化socket通信客户端对象,传入参数实现了Callback接口(其实是new了一个实现Callback接口的匿名内部类,并不是实例化Callback接口,接口不能实例化)
50 | /**
51 | * 当socket连接超时时要做的工作,工作内容是打印超时日志
52 | */
53 | @Override
54 | public void onTimeOut() {
55 | LogHelper.d(TAG, "onTimeOut");
56 | }
57 |
58 | /**
59 | * 当socket连接成功时要做的工作,工作内容就是注册监听器OnMessageReceivedListener:司机接单、司机更新、司机下线事件
60 | */
61 | @Override
62 | public void onConnected() {
63 | //当连接成功后,先让用户登陆
64 | mBinder.passengerLogin();
65 | //注册服务端消息接收监听器,实现司机状态改变
66 | mSocketClient.getHandler().setOnMessageReceivedListener(new OnMessageReceivedListenerAdapter(){
67 |
68 | /**
69 | * 当司机接单时要做的工作,工作内容是发送Broadcast
70 | * @param msg
71 | */
72 | @Override
73 | public void onDriverAccept(String msg) {//msg包含司机姓名和电话号
74 | super.onDriverAccept(msg);
75 | LogHelper.d(TAG,"onDriverAccept");
76 | Message message = new Message(msg);
77 | Intent intent = new Intent(WaitingActivity.TaxiOrderReceiver.ACTION_DRIVER_ACCEPT);
78 | intent.putExtra(EXTRA_DRIVER_NAME,message.getDriverName());
79 | intent.putExtra(EXTRA_DRIVER_PHONE_NUMBER,message.getDriverPhoneNumber());
80 | sendBroadcast(intent);
81 | }
82 |
83 | /**
84 | * 司机更新时要做的工作,工作内容是
85 | * @param message
86 | */
87 | @Override
88 | public void onUpdateDriver(String message) {
89 | super.onUpdateDriver(message);
90 | if (mCallback != null) {//若OnDriverUpdateCallback已被MapActivity实现
91 | mCallback.onUpdateDriver(message);//执行MapActivity实现的onUpdateDriver方法,把message回调给MapActivity
92 | }
93 | }
94 |
95 |
96 | @Override
97 | public void onDriverOffline(String message) {
98 | if (mCallback != null){//若OnDriverUpdateCallback已被MapActivity实现
99 | mCallback.onDriverOffline(message);//执行MapActivity实现的onDriverOffline方法,把message回调给MapActivity
100 | }
101 | }
102 | });
103 | }
104 | });
105 | mSocketClient.init();
106 | return mBinder;
107 | }
108 |
109 | @Override
110 | public void onDestroy() {
111 | super.onDestroy();
112 | disconnect();
113 | }
114 |
115 | private void disconnect() {
116 | mSocketClient.disconnect();
117 | }
118 |
119 | /**
120 | * Socket与Activity通信的通道
121 | */
122 | public class TaxiSocketServiceBinder extends Binder {
123 |
124 | /**
125 | * 乘客登陆
126 | */
127 | public void passengerLogin(){
128 | mSocketClient.passengerLogin();
129 | }
130 |
131 | /**
132 | * 设置司机更新的回调
133 | * @param callback
134 | */
135 | public void setOnDriverUpdateCallback(OnDriverUpdateCallback callback) {
136 | mCallback = callback;
137 | }
138 |
139 | /**
140 | * 移除所有的回调
141 | */
142 | public void removeCallback(){
143 | mCallback = null;
144 | }
145 |
146 | /**
147 | * 乘客更新位置
148 | * @param location 经纬度数组
149 | */
150 | public void updateLocation(double[] location){
151 | mSocketClient.updateLocation(location);
152 | }
153 |
154 | /**
155 | * 乘客叫车
156 | * @param destination 目的地
157 | */
158 | public void callTaxi(Destination destination) {
159 | isWaitingOrdered = true;
160 | mSocketClient.callTaxi(destination);
161 | }
162 |
163 | /**
164 | * 乘客取消叫车
165 | */
166 | public void cancelCall() {
167 | if (isWaitingOrdered) {
168 | isWaitingOrdered = false;
169 | mSocketClient.cancelCall();
170 | }
171 | }
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/model/Message.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.model;
2 |
3 | import org.json.JSONException;
4 | import org.json.JSONObject;
5 |
6 | /**
7 | * Created by zyw on 2015/11/9.
8 | */
9 | public class Message {
10 |
11 | private String mMessageStr;
12 |
13 | private JSONObject mJsonMsg;
14 |
15 | public Message() {
16 |
17 | }
18 |
19 | public Message(String jsonMsg) {
20 | try {
21 | mJsonMsg = new JSONObject(jsonMsg);
22 | } catch (JSONException e) {
23 | e.printStackTrace();
24 | }
25 | }
26 |
27 | public String getDriverName() {
28 | String name = null;
29 | try {
30 | name = mJsonMsg.getString("driverName");
31 | } catch (JSONException e) {
32 | e.printStackTrace();
33 | }
34 | return name;
35 | }
36 |
37 | public String getDriverPhoneNumber() {
38 | String phoneNumber = null;
39 | try {
40 | phoneNumber = mJsonMsg.getString("driverPhoneNumber");
41 | } catch (JSONException e) {
42 | e.printStackTrace();
43 | }
44 | return phoneNumber;
45 | }
46 |
47 | public String getPassengerName(){
48 | String name = null;
49 | try{
50 | name = mJsonMsg.getString("passengerName");
51 | }catch (JSONException e){
52 | e.printStackTrace();
53 | }
54 | return name;
55 | }
56 |
57 | public String getPassengerPhoneNumber(){
58 | String phoneNumber = null;
59 | try {
60 | phoneNumber = mJsonMsg.getString("passengerPhoneNumber");
61 | }catch (JSONException e){
62 | e.printStackTrace();
63 | }
64 | return phoneNumber;
65 | }
66 |
67 | public double[] getLocation() {
68 | double[] latLng = new double[2];
69 | try {
70 | JSONObject location = mJsonMsg.getJSONObject("location");
71 | latLng[0] = location.getDouble("lat");
72 | latLng[1] = location.getDouble("lng");
73 | return latLng;
74 | } catch (JSONException e) {
75 | e.printStackTrace();
76 | }
77 | return null;
78 | }
79 |
80 | public Destination getDestination() {
81 | JSONObject destJson = null;
82 | Destination destination = null;
83 | try {
84 | destJson = mJsonMsg.getJSONObject("destination");
85 | destination = new Destination();
86 | destination.setDetailAdress(destJson.getString("detailAdress"));
87 | destination.setLocation(new double[]{destJson.getDouble("destLat"),
88 | destJson.getDouble("destLng")});
89 | destination.setDistance(destJson.getDouble("distance"));
90 |
91 | } catch (JSONException e) {
92 | e.printStackTrace();
93 | }
94 | return destination;
95 | }
96 |
97 | public void setJsonMsg(JSONObject jsonMsg) {
98 | mJsonMsg = jsonMsg;
99 | }
100 |
101 | public void setMessageStr(String messageStr) {
102 | mMessageStr = messageStr;
103 | }
104 |
105 | @Override
106 | public String toString() {
107 | return mMessageStr + mJsonMsg.toString();
108 | }
109 |
110 |
111 | public static class MessageBuilder {
112 | private final JSONObject J;
113 | private String type;
114 |
115 | public MessageBuilder() {
116 | J = new JSONObject();
117 | }
118 |
119 | public MessageBuilder setDriverName(String name) {
120 | try {
121 | J.put("driverName", name);
122 | return this;
123 | } catch (JSONException e) {
124 | e.printStackTrace();
125 | }
126 | return null;
127 | }
128 |
129 | public MessageBuilder setDriverPhoneNumber(String phoneNumber) {
130 | try {
131 | J.put("driverPhoneNumber", phoneNumber);
132 | return this;
133 | } catch (JSONException e) {
134 | e.printStackTrace();
135 | }
136 | return null;
137 | }
138 |
139 | public MessageBuilder setPassengerName(String name){
140 | try {
141 | J.put("passengerName", name);
142 | return this;
143 | } catch (JSONException e) {
144 | e.printStackTrace();
145 | }
146 | return null;
147 | }
148 | public MessageBuilder setPassengerPhoneNumber(String phoneNumber){
149 | try {
150 | J.put("passengerPhoneNumber", phoneNumber);
151 | return this;
152 | } catch (JSONException e) {
153 | e.printStackTrace();
154 | }
155 | return null;
156 | }
157 |
158 | public MessageBuilder setLocation(double[] location) {
159 | JSONObject locationJson = new JSONObject();
160 | try {
161 | locationJson.put("lat", location[0]);
162 | locationJson.put("lng", location[1]);
163 | J.put("location", locationJson);
164 | return this;
165 | } catch (JSONException e) {
166 | e.printStackTrace();
167 | }
168 | return null;
169 | }
170 |
171 | public MessageBuilder setDestination(Destination destination) {
172 | try {
173 | JSONObject destJson = new JSONObject();
174 | destJson.put("detailAdress", destination.getDetailAdress());
175 | destJson.put("destLat",destination.getLocation()[0]);
176 | destJson.put("destLng",destination.getLocation()[1]);
177 | destJson.put("distance", destination.getDistance());
178 | J.put("destination", destJson);
179 | return this;
180 | } catch (JSONException e) {
181 | e.printStackTrace();
182 | }
183 | return null;
184 | }
185 |
186 |
187 | public MessageBuilder setRequestType(String requestType) {
188 | this.type = requestType;
189 | return this;
190 | }
191 |
192 | public Message build() {
193 | final Message message = new Message();
194 | message.setJsonMsg(J);
195 | message.setMessageStr(type + "://");
196 | return message;
197 | }
198 | }
199 | }
200 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/socketclient/TaxiSocketClient.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.socketclient;
2 |
3 | import com.zyw.calltaxi.model.Destination;
4 | import com.zyw.calltaxi.model.Message;
5 | import com.zyw.calltaxi.utils.LogHelper;
6 |
7 | import org.apache.mina.core.future.ConnectFuture;
8 | import org.apache.mina.core.session.IoSession;
9 | import org.apache.mina.filter.codec.ProtocolCodecFilter;
10 | import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
11 | import org.apache.mina.transport.socket.nio.NioSocketConnector;
12 |
13 | import java.net.InetSocketAddress;
14 | import java.nio.charset.Charset;
15 |
16 | /**
17 | * Created by zyw on 2015/9/20.
18 | * socket通信代理
19 | */
20 | public class TaxiSocketClient {
21 |
22 | private static final String TAG = "LocationClient";
23 | /**
24 | * socketConnector对象
25 | */
26 | private NioSocketConnector mConnector;
27 | /**
28 | * 处理消息的Handler对象
29 | */
30 | private TaxiRequestHandler mHandler;
31 | /**
32 | * 客户端连接成功后取得的会话对象
33 | */
34 | private IoSession mSession;
35 | /**
36 | * 是否连接到服务器端的标志位
37 | */
38 | private boolean isConnected = false;
39 | /**
40 | * 是否已经初始化完成
41 | */
42 | private boolean initiated = false;
43 | /**
44 | * 会话是否创建的标志位,用来在第一次的时候给服务端发送客户端的用户信息
45 | */
46 | private boolean mSessionCreated = false;
47 | /**
48 | * 连接服务器超时的回调
49 | */
50 | private Callback mCallback;
51 | /**
52 | * 开启socket连接的用户名
53 | */
54 | private String mName;
55 | /**
56 | * 开启socket连接的手机号
57 | */
58 | private String mPhoneNumber;
59 |
60 | public TaxiSocketClient(String name, String phoneNumber, Callback callback) {
61 | mHandler = new TaxiRequestHandler();//注册处理消息的Handler对象
62 | mCallback = callback;//注册内部接口CallBack,有onTimeOut和onConnected两个抽象方法需要TaxiSocketService实现
63 | mName = name;
64 | mPhoneNumber = phoneNumber;
65 | }
66 |
67 | /**
68 | * 初始化客户端
69 | */
70 | public void init() {
71 | //如果已经初始化。不再重复进行
72 | if (initiated) {
73 | return;
74 | }
75 | new Thread() {
76 | @Override
77 | public void run() {
78 | mConnector = new NioSocketConnector();//实例化SocketConnector
79 | mConnector.setHandler(mHandler);//给SocketConnector设置消息处理器
80 | mConnector.getFilterChain().addLast("codec",
81 | new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));//给SocketConnector添加文本按行滤镜
82 | mConnector.setConnectTimeoutMillis(10000);//给SocketConnector设置10s连接超时
83 | ConnectFuture future = mConnector.connect(new InetSocketAddress("192.168.1.101", 9988));//通过SocketConnector与特定地址创建未来连接
84 | future.awaitUninterruptibly();//未来连接等待直到连接成功
85 | try {
86 | mSession = future.getSession();//未来连接成功后取得会话对象
87 | isConnected = mSession.isConnected();//socket是否连接成功
88 | if (isConnected) {
89 | if (mCallback != null) {//如果CallBack接口已被TaxiSocketService实现
90 | mCallback.onConnected();//调用被实现的onConnected方法进行socket连接成功后的工作
91 | }
92 | }
93 | } catch (Exception e) {
94 | reset();
95 | if (mCallback != null) {//如果CallBack接口已被TaxiSocketService实现
96 | mCallback.onTimeOut();//调用被实现的onTimeOut方法进行socket连接超时后的工作
97 | }
98 | e.printStackTrace();
99 | }
100 | }
101 | }.start();
102 | initiated = true;
103 | }
104 |
105 | /**
106 | * 重置SocketConnector
107 | */
108 | public void reset() {
109 | mConnector.dispose();
110 | mConnector = null;
111 | initiated = false;
112 | }
113 |
114 | public TaxiRequestHandler getHandler() {
115 | return mHandler;
116 | }
117 |
118 | /**
119 | * 通过socket向服务器发送信息
120 | * @param msg
121 | */
122 | public void sendMessage(Message msg) {
123 | mSession.write((msg.toString()));//将msg转化成字符串
124 | }
125 |
126 | /**
127 | * 乘客位置更新
128 | * @param location
129 | */
130 | public void updateLocation(double[] location) {
131 | String type = "passenger_update_location";
132 | Message updateMsg = new Message.MessageBuilder()
133 | .setRequestType(type)
134 | .setPassengerName(mName)
135 | .setPassengerPhoneNumber(mPhoneNumber)
136 | .setLocation(location)
137 | .build();
138 | sendMessage(updateMsg);
139 | }
140 |
141 | /**
142 | * 乘客登陆
143 | */
144 | public void passengerLogin() {
145 | String type = "passenger_login";
146 | Message msg = new Message.MessageBuilder()
147 | .setRequestType(type)
148 | .setPassengerName(mName)
149 | .setPassengerPhoneNumber(mPhoneNumber)
150 | .build();
151 | sendMessage(msg);
152 | }
153 |
154 | /**
155 | * 乘客叫车
156 | * @param destination 目的地
157 | */
158 | public void callTaxi(Destination destination) {
159 | Message msg = new Message.MessageBuilder()
160 | .setRequestType("passenger_call_taxi")
161 | .setPassengerName(mName)
162 | .setPassengerPhoneNumber(mPhoneNumber)
163 | .setDestination(destination)
164 | .build();
165 | sendMessage(msg);
166 | }
167 |
168 | /**
169 | * 乘客取消叫车
170 | */
171 | public void cancelCall() {
172 | Message msg = new Message.MessageBuilder()
173 | .setRequestType("passenger_cancel_call")
174 | .setPassengerName(mName)
175 | .setPassengerPhoneNumber(mPhoneNumber)
176 | .build();
177 | sendMessage(msg);
178 | }
179 |
180 |
181 | /**
182 | * 关闭客户端连接的方法
183 | */
184 | public void disconnect() {
185 | LogHelper.d(TAG, "disconnect");
186 | mCallback = null;//将实现的回调
187 | if (mSession != null && isConnected) {
188 | Message msg = new Message.MessageBuilder()
189 | .setRequestType("disconnect")
190 | .setPassengerName(mName)
191 | .setPassengerPhoneNumber(mPhoneNumber)
192 | .build();
193 | sendMessage(msg);//向服务端发送关闭连接的请求
194 | mSession.close(true);
195 | mConnector.dispose();
196 | }
197 | }
198 |
199 | /**
200 | * 交给TaxiSocketService实现,
201 | */
202 | public interface Callback {
203 | void onTimeOut();//socket连接成功怎么做由TaxiSocketService实现
204 |
205 | void onConnected();//socket连接超时怎么做由TaxiSocketService实现
206 | }
207 |
208 | }
209 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/ui/WaitingActivity.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.ui;
2 |
3 | import android.app.Activity;
4 | import android.app.AlertDialog;
5 | import android.app.Dialog;
6 | import android.content.BroadcastReceiver;
7 | import android.content.ComponentName;
8 | import android.content.Context;
9 | import android.content.DialogInterface;
10 | import android.content.Intent;
11 | import android.content.IntentFilter;
12 | import android.content.ServiceConnection;
13 | import android.net.Uri;
14 | import android.os.Bundle;
15 | import android.os.IBinder;
16 | import android.support.v7.app.AppCompatActivity;
17 | import android.view.View;
18 | import android.widget.Button;
19 | import android.widget.TextView;
20 |
21 | import com.zyw.calltaxi.R;
22 | import com.zyw.calltaxi.service.TaxiSocketService;
23 | import com.zyw.calltaxi.utils.LogHelper;
24 |
25 | /**
26 | * Created by zyw on 2015/11/12.
27 | */
28 | public class WaitingActivity extends AppCompatActivity {
29 |
30 | private ServiceConnection mServiceConnection;
31 | private String mDriverPhoneNumber;
32 | private TextView mTvWaiting;
33 | private TextView mTvOrdered;
34 | private Button mBtnCancel;
35 | private Button mBtnCall;
36 | private Button mBtnDone;
37 | private TaxiSocketService.TaxiSocketServiceBinder mBinder = null;
38 | private TaxiOrderReceiver mReceiver;
39 | private boolean mStillWaiting = true;
40 | private Dialog mDoneDialog = null;
41 | private Dialog mCancelDialog = null;
42 | @Override
43 | protected void onCreate(Bundle savedInstanceState) {
44 | super.onCreate(savedInstanceState);
45 | setContentView(R.layout.activity_waiting);
46 | initViews();
47 | bindService();
48 | IntentFilter filter = new IntentFilter();
49 | filter.addAction(TaxiOrderReceiver.ACTION_DRIVER_ACCEPT);
50 | mReceiver = new TaxiOrderReceiver();
51 | registerReceiver(mReceiver, filter);
52 | }
53 |
54 | private void initViews() {
55 | mTvWaiting = (TextView) findViewById(R.id.tv_waiting);
56 | mTvOrdered = (TextView) findViewById(R.id.tv_ordered);
57 | mBtnCancel = (Button) findViewById(R.id.btn_cancel);
58 | mBtnDone = (Button) findViewById(R.id.btn_done);
59 | mBtnCall = (Button) findViewById(R.id.btn_call);
60 | mBtnCancel.setOnClickListener(new View.OnClickListener() {
61 | @Override
62 | public void onClick(View v) {
63 | cancelCall();
64 | }
65 | });
66 | }
67 |
68 | private void cancelCall() {
69 | if (mBinder != null) {
70 | mBinder.cancelCall();
71 | finish();
72 | }
73 | }
74 |
75 | private void bindService() {
76 | mServiceConnection = new ServiceConnection() {
77 | @Override
78 | public void onServiceConnected(ComponentName name, IBinder service) {
79 | mBinder = (TaxiSocketService.TaxiSocketServiceBinder) service;
80 | }
81 |
82 | @Override
83 | public void onServiceDisconnected(ComponentName name) {
84 | mBinder = null;
85 | }
86 | };
87 | Intent intent = new Intent(this, TaxiSocketService.class);
88 | bindService(intent, mServiceConnection, BIND_AUTO_CREATE);
89 | }
90 |
91 | /**
92 | * 点击后退键
93 | */
94 | @Override
95 | public void onBackPressed() {
96 | if (mStillWaiting) {
97 | showCancelDialog();//等待司机接单,显示取消订单对话框
98 | } else {
99 | showDoneDialog();//司机已经接单,显示离开本页面对话框
100 | }
101 | }
102 |
103 | /**
104 | * 显示订单确认对话框
105 | */
106 | private void showDoneDialog() {
107 | if (mDoneDialog == null) {
108 | createDoneDialog();//若没有对话框实例则创建对话框
109 | } else {
110 | if (mDoneDialog.isShowing()) {
111 | mDoneDialog.dismiss();//若对话框已经显示则消失
112 | } else {
113 | mDoneDialog.show();//若没显示则显示
114 | }
115 | }
116 | }
117 |
118 | /**
119 | * 显示订单取消对话框
120 | */
121 | private void showCancelDialog() {
122 | if (mCancelDialog == null) {
123 | createCancelDialog();
124 | } else {
125 | if (mCancelDialog.isShowing()){
126 | mCancelDialog.dismiss();
127 | }else {
128 | mCancelDialog.show();
129 | }
130 | }
131 | }
132 |
133 | private void createCancelDialog() {
134 | mCancelDialog = new AlertDialog.Builder(this)
135 | .setTitle("取消订单")
136 | .setMessage("真的要取消约车?")
137 | .setPositiveButton("确定", new DialogInterface.OnClickListener() {
138 | @Override
139 | public void onClick(DialogInterface dialog, int which) {
140 | cancelCall();
141 | }
142 | })
143 | .setNegativeButton("不了",null)
144 | .show();
145 | }
146 |
147 | private void createDoneDialog() {
148 | mDoneDialog = new AlertDialog.Builder(this)
149 | .setTitle("将离开本页面")
150 | .setMessage("您确定已经记下了司机的信息?\n手机:" + mDriverPhoneNumber)
151 | .setNegativeButton("取消", null)
152 | .setPositiveButton("确定", new DialogInterface.OnClickListener() {
153 | @Override
154 | public void onClick(DialogInterface dialog, int which) {
155 | setResult(Activity.RESULT_OK);
156 | finish();
157 | }
158 | })
159 | .show();
160 | }
161 |
162 | /**
163 | * btnHandlerDone点击事件
164 | * @param view
165 | */
166 | public void btnHandlerDone(View view) {
167 | showDoneDialog();
168 | }
169 |
170 | /**
171 | * btnHandlerCall点击事件
172 | * @param view
173 | */
174 | public void btnHandlerCall(View view) {
175 | Intent dialIntent = new Intent(Intent.ACTION_VIEW);
176 | dialIntent.setData(Uri.parse("tel:" + mDriverPhoneNumber));
177 | startActivity(dialIntent);
178 | }
179 |
180 | @Override
181 | protected void onDestroy() {
182 | unbindService(mServiceConnection);
183 | mServiceConnection = null;
184 | unregisterReceiver(mReceiver);
185 | mReceiver = null;
186 | super.onDestroy();
187 | }
188 |
189 | /**
190 | * 广播接收器,接收司机接单广播
191 | */
192 | public class TaxiOrderReceiver extends BroadcastReceiver {
193 |
194 | public static final String ACTION_DRIVER_ACCEPT = "com.zyw.driver.DRIVER_ACCEPT";
195 | public final String TAG = LogHelper.makeLogTag(TaxiOrderReceiver.class);
196 |
197 | @Override
198 | public void onReceive(Context context, Intent intent) {
199 | LogHelper.d(TAG, "broadcast received " + intent.getAction());
200 | if (intent.getAction().equals(ACTION_DRIVER_ACCEPT)) {
201 | mStillWaiting = false;
202 | String driverName = intent.getStringExtra(TaxiSocketService.EXTRA_DRIVER_NAME);
203 | mDriverPhoneNumber = intent.getStringExtra(TaxiSocketService.EXTRA_DRIVER_PHONE_NUMBER);
204 | mTvWaiting.setVisibility(View.GONE);//隐藏,不保留控件占有的空间
205 | mBtnCancel.setVisibility(View.GONE);//取消订单,不可见
206 | mBtnDone.setVisibility(View.VISIBLE);//订单确认,可见
207 | mBtnCall.setVisibility(View.VISIBLE);//打电话,可见
208 | mTvOrdered.setVisibility(View.VISIBLE);//显示司机姓名、电话
209 | mTvOrdered.setText(getString(R.string.ordered, driverName, mDriverPhoneNumber));
210 | }
211 | }
212 | }
213 | }
214 |
--------------------------------------------------------------------------------
/driver/driver.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | generateDebugAndroidTestSources
19 | generateDebugSources
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/model/Message.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.model;
2 |
3 | import org.json.JSONException;
4 | import org.json.JSONObject;
5 |
6 | /**
7 | * Created by zyw on 2015/11/9.
8 | * 构造socket通信信息的类
9 | * 负责解析json数据
10 | */
11 | public class Message {
12 |
13 | private String mMessageStr;
14 |
15 | private JSONObject mJsonMsg;
16 |
17 | public Message() {
18 |
19 | }
20 |
21 | /**
22 | * 构造函数传入字符串jsonMsg转化为JSON对象mJsonMsg
23 | * @param jsonMsg
24 | */
25 | public Message(String jsonMsg) {
26 | try {
27 | mJsonMsg = new JSONObject(jsonMsg);
28 | } catch (JSONException e) {
29 | e.printStackTrace();
30 | }
31 | }
32 |
33 | /**
34 | * 从JSON对象中获得driverName
35 | * @return
36 | */
37 | public String getDriverName() {
38 | String name = null;
39 | try {
40 | name = mJsonMsg.getString("driverName");
41 | } catch (JSONException e) {
42 | e.printStackTrace();
43 | }
44 | return name;
45 | }
46 |
47 | /**
48 | * 从JSON对象中获得driverPhoneNumber
49 | * @return
50 | */
51 | public String getDriverPhoneNumber() {
52 | String phoneNumber = null;
53 | try {
54 | phoneNumber = mJsonMsg.getString("driverPhoneNumber");
55 | } catch (JSONException e) {
56 | e.printStackTrace();
57 | }
58 | return phoneNumber;
59 | }
60 |
61 | /**
62 | * 从JSON对象中获得passengerName
63 | * @return
64 | */
65 | public String getPassengerName(){
66 | String name = null;
67 | try{
68 | name = mJsonMsg.getString("passengerName");
69 | }catch (JSONException e){
70 | e.printStackTrace();
71 | }
72 | return name;
73 | }
74 |
75 | /**
76 | * 从JSON对象中获得passengerPhoneNumber
77 | * @return
78 | */
79 | public String getPassengerPhoneNumber(){
80 | String phoneNumber = null;
81 | try {
82 | phoneNumber = mJsonMsg.getString("passengerPhoneNumber");
83 | }catch (JSONException e){
84 | e.printStackTrace();
85 | }
86 | return phoneNumber;
87 | }
88 |
89 | /**
90 | * 从JSON对象中获得JSON对象location,再构造成double[]
91 | * @return
92 | */
93 | public double[] getLocation() {
94 | double[] latLng = new double[2];
95 | try {
96 | JSONObject location = mJsonMsg.getJSONObject("location");
97 | latLng[0] = location.getDouble("lat");
98 | latLng[1] = location.getDouble("lng");
99 | return latLng;
100 | } catch (JSONException e) {
101 | e.printStackTrace();
102 | }
103 | return null;
104 | }
105 |
106 | /**
107 | * 从JSON对象中获得JSON对象destination,再构造成Destination对象
108 | * @return
109 | */
110 | public Destination getDestination() {
111 | JSONObject destJson = null;
112 | Destination destination = null;
113 | try {
114 | destJson = mJsonMsg.getJSONObject("destination");
115 | destination = new Destination();
116 | destination.setDetailAdress(destJson.getString("detailAdress"));//具体地址
117 | destination.setLocation(new double[]{destJson.getDouble("destLat"),
118 | destJson.getDouble("destLng")});//经纬度数组
119 | destination.setDistance(destJson.getDouble("distance"));//距离
120 |
121 | } catch (JSONException e) {
122 | e.printStackTrace();
123 | }
124 | return destination;
125 | }
126 |
127 | /**
128 | * 设置JSON对象
129 | * @param jsonMsg
130 | */
131 | public void setJsonMsg(JSONObject jsonMsg) {
132 | mJsonMsg = jsonMsg;
133 | }
134 |
135 | /**
136 | * 设置mMessageStr
137 | * @param messageStr
138 | */
139 | public void setMessageStr(String messageStr) {
140 | mMessageStr = messageStr;
141 | }
142 |
143 | /**
144 | * 成员变量转化为字符串
145 | * @return
146 | */
147 | @Override
148 | public String toString() {
149 | return mMessageStr + mJsonMsg.toString();
150 | }
151 |
152 | /**
153 | * Message构造器
154 | */
155 | public static class MessageBuilder {
156 | private final JSONObject J;
157 | private String type;
158 |
159 | /**
160 | * 构造函数实例化J
161 | */
162 | public MessageBuilder() {
163 | J = new JSONObject();
164 | }
165 |
166 | /**
167 | * 设置司机名
168 | * @param name
169 | * @return
170 | */
171 | public MessageBuilder setDriverName(String name) {
172 | try {
173 | J.put("driverName", name);
174 | return this;
175 | } catch (JSONException e) {
176 | e.printStackTrace();
177 | }
178 | return null;
179 | }
180 |
181 | /**
182 | * 设置司机电话号
183 | * @param phoneNumber
184 | * @return
185 | */
186 | public MessageBuilder setDriverPhoneNumber(String phoneNumber) {
187 | try {
188 | J.put("driverPhoneNumber", phoneNumber);
189 | return this;
190 | } catch (JSONException e) {
191 | e.printStackTrace();
192 | }
193 | return null;
194 | }
195 |
196 | /**
197 | * 设置乘客名
198 | * @param name
199 | * @return
200 | */
201 | public MessageBuilder setPassengerName(String name){
202 | try {
203 | J.put("passengerName", name);
204 | return this;
205 | } catch (JSONException e) {
206 | e.printStackTrace();
207 | }
208 | return null;
209 | }
210 |
211 | /**
212 | * 设置乘客电话号
213 | * @param phoneNumber
214 | * @return
215 | */
216 | public MessageBuilder setPassengerPhoneNumber(String phoneNumber){
217 | try {
218 | J.put("passengerPhoneNumber", phoneNumber);
219 | return this;
220 | } catch (JSONException e) {
221 | e.printStackTrace();
222 | }
223 | return null;
224 | }
225 |
226 | /**
227 | * 设置乘客位置
228 | * @param location
229 | * @return
230 | */
231 | public MessageBuilder setLocation(double[] location) {
232 | JSONObject locationJson = new JSONObject();
233 | try {
234 | locationJson.put("lat", location[0]);
235 | locationJson.put("lng", location[1]);
236 | J.put("location", locationJson);
237 | return this;
238 | } catch (JSONException e) {
239 | e.printStackTrace();
240 | }
241 | return null;
242 | }
243 |
244 | /**
245 | * 设置目的地
246 | * @param destination
247 | * @return
248 | */
249 | public MessageBuilder setDestination(Destination destination) {
250 | try {
251 | JSONObject destJson = new JSONObject();
252 | destJson.put("detailAdress", destination.getDetailAdress());
253 | destJson.put("destLat",destination.getLocation()[0]);
254 | destJson.put("destLng",destination.getLocation()[1]);
255 | destJson.put("distance", destination.getDistance());
256 | J.put("destination", destJson);
257 | return this;
258 | } catch (JSONException e) {
259 | e.printStackTrace();
260 | }
261 | return null;
262 | }
263 |
264 | /**
265 | * 设置type字符串
266 | * @param requestType
267 | * @return
268 | */
269 | public MessageBuilder setRequestType(String requestType) {
270 | this.type = requestType;
271 | return this;
272 | }
273 |
274 | /**
275 | * 构造成Message
276 | * @return
277 | */
278 | public Message build() {
279 | final Message message = new Message();
280 | message.setJsonMsg(J);
281 | message.setMessageStr(type + "://");
282 | return message;
283 | }
284 | }
285 | }
286 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | generateDebugAndroidTestSources
19 | generateDebugSources
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/calltaxi/map/BaiduMapManager.java:
--------------------------------------------------------------------------------
1 | package com.zyw.calltaxi.map;
2 |
3 | import android.content.Context;
4 | import android.util.Log;
5 | import android.widget.LinearLayout;
6 |
7 | import com.baidu.location.BDLocation;
8 | import com.baidu.location.BDLocationListener;
9 | import com.baidu.location.LocationClient;
10 | import com.baidu.location.LocationClientOption;
11 | import com.baidu.mapapi.map.BaiduMap;
12 | import com.baidu.mapapi.map.BitmapDescriptor;
13 | import com.baidu.mapapi.map.BitmapDescriptorFactory;
14 | import com.baidu.mapapi.map.MapStatusUpdateFactory;
15 | import com.baidu.mapapi.map.MapView;
16 | import com.baidu.mapapi.map.Marker;
17 | import com.baidu.mapapi.map.MarkerOptions;
18 | import com.baidu.mapapi.map.MyLocationConfiguration;
19 | import com.baidu.mapapi.map.MyLocationData;
20 | import com.baidu.mapapi.map.OverlayOptions;
21 | import com.baidu.mapapi.model.LatLng;
22 | import com.zyw.calltaxi.R;
23 | import com.zyw.calltaxi.model.Driver;
24 | import com.zyw.calltaxi.utils.ToastUtils;
25 |
26 | import java.util.ArrayList;
27 | import java.util.HashMap;
28 | import java.util.List;
29 | import java.util.Map;
30 |
31 | /**
32 | * Created by zyw on 2015/9/7.
33 | * 对百度地图进行管理的manager类
34 | */
35 | public class BaiduMapManager implements BDLocationListener {
36 |
37 | private static final String TAG = "BaiduMapManager";
38 | /**
39 | * context对象
40 | */
41 | private Context mContext;
42 | /**
43 | * 百度地图对象
44 | */
45 | private BaiduMap mBaiduMap;
46 | /**
47 | * 地图控件对象
48 | */
49 | private MapView mMapView;
50 | /**
51 | * 定位client对象
52 | */
53 | private LocationClient mClient;
54 | /**
55 | * 是否是第一次定位,如果是则自动移动到屏幕中心
56 | */
57 | private boolean isFirstLocate = true;
58 | /**
59 | * 扫描间隔,默认为5min,多次定位失败后间隔越来越长
60 | */
61 | private int mScanSpanMillis = 5 * 60 * 1000;
62 | /**
63 | * 显示用户位置信息的view
64 | */
65 | private LinearLayout mUserMarkerView;
66 | /**
67 | * 持有所有的BitmapDescriptor,程序销毁时回收。
68 | */
69 | private List mMarkerViews = new ArrayList<>();
70 | /**
71 | * 保存用户id和对应的marker,每次将marker添加到地图上时,也要加入到map中
72 | */
73 | private Map mMarkers = new HashMap<>();
74 |
75 | public BaiduMapManager(Context context, MapView mapView) {
76 | mContext = context;
77 | mMapView = mapView;
78 | mMapView.showScaleControl(true);
79 | mMapView.showZoomControls(false);
80 | mBaiduMap = mapView.getMap();
81 | }
82 |
83 | /**
84 | * 初始化地图
85 | */
86 | public void init() {
87 | mBaiduMap.setMyLocationEnabled(true);
88 | mBaiduMap.setMapStatus(MapStatusUpdateFactory.zoomTo(15f));
89 | MyLocationConfiguration config = new MyLocationConfiguration
90 | (MyLocationConfiguration.LocationMode.FOLLOWING, true, null);
91 | mBaiduMap.setMyLocationConfigeration(config);
92 | mClient = new LocationClient(mContext);
93 |
94 | mClient.registerLocationListener(this);
95 | //配置mClient对象的参数信息
96 | LocationClientOption option = new LocationClientOption();
97 |
98 | option.setIsNeedLocationPoiList(true);
99 | //设置扫描间隔为5min
100 | option.setScanSpan(mScanSpanMillis);
101 | //开启GPS
102 | option.setOpenGps(true);
103 | option.setEnableSimulateGps(true);
104 | //是否需要地址
105 | option.setIsNeedAddress(true);
106 | //是否需要手机的方向
107 | option.setNeedDeviceDirect(true);
108 | //坐标类型
109 | option.setCoorType("bd09ll");
110 | mClient.setLocOption(option);
111 |
112 | }
113 |
114 | /**
115 | * 开始进行定位的方法
116 | */
117 | public void requestLocation() {
118 | mClient.start();
119 | // mClient.requestLocation();
120 | }
121 |
122 | /**
123 | * 停止请求位置
124 | */
125 | public void stopRequest() {
126 | if (mClient.isStarted()) {
127 | mClient.stop();
128 | }
129 | }
130 |
131 | /**
132 | * 定位失败的次数
133 | */
134 | private int mFailureCount = 0;
135 |
136 | private MyLocationData mLocationData;
137 |
138 | /**
139 | * 定位返回数据的回调
140 | *
141 | * @param bdLocation
142 | */
143 | @Override
144 | public void onReceiveLocation(BDLocation bdLocation) {
145 | Log.d("TAG", "onReceiveLocation");
146 | if (bdLocation == null) {
147 | return;
148 | }
149 | //定位成功的情况
150 | if (bdLocation.getLocType() == 61 ||
151 | bdLocation.getLocType() == 65 ||
152 | bdLocation.getLocType() == 66 ||
153 | bdLocation.getLocType() == 68 ||
154 | bdLocation.getLocType() == 161) {
155 | LatLng latLng = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude());
156 | mLocationData = new MyLocationData.Builder()
157 | .latitude(bdLocation.getLatitude())
158 | .longitude(bdLocation.getLongitude())
159 | .accuracy(bdLocation.getRadius())
160 | .direction(bdLocation.getDirection())
161 | .build();
162 | if (isFirstLocate) {
163 | mBaiduMap.setMyLocationData(mLocationData);
164 | isFirstLocate = false;
165 | }
166 | //我的位置得到了更新,将我的最新位置信息发送给服务器
167 | if (mListener != null) {
168 | mListener.onLocationUpdate(bdLocation);
169 | }
170 | //重新定位成功后,恢复默认的扫描间隔
171 | if (mFailureCount > 0) {
172 | mFailureCount = 0;
173 | setScanSpan(mScanSpanMillis);
174 | }
175 | } else {
176 | mFailureCount++;
177 | //随着失败次数的增加,逐渐延长扫描间隔
178 | if (mFailureCount > 0 && mFailureCount <= 3) {
179 | setScanSpan(10000);
180 | } else if (mFailureCount > 3 && mFailureCount <= 8) {
181 | setScanSpan(20000);
182 | } else {
183 | setScanSpan(60000);
184 | }
185 | ToastUtils.showToast(mContext, R.string.location_failed);
186 | }
187 | }
188 |
189 | /**
190 | * 设置定位扫描间隔
191 | *
192 | * @param timeInMillis
193 | */
194 | private void setScanSpan(int timeInMillis) {
195 | LocationClientOption option = mClient.getLocOption();
196 | option.setScanSpan(timeInMillis);
197 | mClient.setLocOption(option);
198 | }
199 |
200 | public void showDriversOnMap(Driver driver) {
201 | Marker marker;
202 | //如果传入的司机的位置还没显示在地图上,则先显示在地图上
203 | if (!containsDriver(driver)) {
204 | //添加用户对应的marker到地图上
205 | addNewMarker(driver);
206 | } else {
207 | //如果已在地图上显示,直接对位置进行更新
208 | marker = mMarkers.get(driver.getPhoneNumber());
209 | LatLng latLng = driver.getLatLng();
210 | marker.setPosition(latLng);
211 | }
212 | }
213 |
214 | private void addNewMarker(Driver driver) {
215 | Marker marker;
216 | BitmapDescriptor bd = BitmapDescriptorFactory.fromResource(R.mipmap.ic_marker_taxi_18dp);
217 | OverlayOptions overlayOptions = new MarkerOptions().position(driver.getLatLng()).title(driver.getName()).icon(bd);
218 | marker = (Marker) mBaiduMap.addOverlay(overlayOptions);
219 | mMarkers.put(driver.getPhoneNumber(), marker);
220 | }
221 |
222 | /**
223 | * 判断司机是否已显示在地图上
224 | *
225 | * @param driver
226 | * @return
227 | */
228 | public boolean containsDriver(Driver driver) {
229 | return mMarkers.containsKey(driver.getPhoneNumber());
230 | }
231 |
232 | /**
233 | * 移除掉已经离线的司机的marker
234 | *
235 | * @param phoneNumber
236 | */
237 | public void removeDriver(String phoneNumber) {
238 | //分别从地图和mMarkers中移除marker。
239 | if (mMarkers.containsKey(phoneNumber)) {
240 | mMarkers.remove(phoneNumber).remove();
241 | }
242 | }
243 |
244 | /**
245 | * 移除地图上显示的所有的marker
246 | */
247 | public void removeAllDrivers() {
248 | for (String key : mMarkers.keySet()) {
249 | mMarkers.get(key).remove();
250 | }
251 | mMarkers.clear();
252 | }
253 |
254 | /**
255 | * 位置信息更新时的回调接口
256 | */
257 | public interface OnLocationUpdateListener {
258 | void onLocationUpdate(BDLocation bdLocation);
259 | }
260 |
261 | private OnLocationUpdateListener mListener;
262 |
263 | /**
264 | * 注册位置更新监听的方法
265 | *
266 | * @param listener
267 | */
268 | public void registerLocationListener(OnLocationUpdateListener listener) {
269 | mListener = listener;
270 | }
271 |
272 | /**
273 | * 暂停地图
274 | */
275 | public void onPause() {
276 | mMapView.onPause();
277 | }
278 |
279 | /**
280 | * 恢复地图
281 | */
282 | public void onResume() {
283 | mMapView.onResume();
284 | }
285 |
286 | /**
287 | * 销毁地图
288 | */
289 | public void onDestroy() {
290 | // 退出时销毁定位
291 | mClient.unRegisterLocationListener(this);
292 | // 关闭定位图层
293 | mBaiduMap.setMyLocationEnabled(false);
294 | //销毁BitmapDescriptor
295 | for (BitmapDescriptor markerView : mMarkerViews) {
296 | markerView.recycle();
297 | }
298 | mMapView.onDestroy();
299 | mMapView = null;
300 | }
301 |
302 | }
303 |
--------------------------------------------------------------------------------
/driver/src/main/java/com/zyw/driver/ui/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.zyw.driver.ui;
2 |
3 | import android.app.Activity;
4 | import android.app.AlertDialog;
5 | import android.content.ComponentName;
6 | import android.content.DialogInterface;
7 | import android.content.Intent;
8 | import android.content.ServiceConnection;
9 | import android.os.Bundle;
10 | import android.os.Handler;
11 | import android.os.IBinder;
12 | import android.support.v7.app.AppCompatActivity;
13 | import android.support.v7.widget.Toolbar;
14 | import android.view.View;
15 | import android.widget.AdapterView;
16 | import android.widget.ListView;
17 |
18 | import com.baidu.location.BDLocation;
19 | import com.baidu.mapapi.model.LatLng;
20 | import com.baidu.mapapi.utils.DistanceUtil;
21 | import com.zyw.driver.R;
22 | import com.zyw.driver.adapter.PassengerInfoAdapter;
23 | import com.zyw.driver.api.DriverServiceCallback;
24 | import com.zyw.driver.api.OnLocationReceivedListener;
25 | import com.zyw.driver.baidulocation.LocationManager;
26 | import com.zyw.driver.model.Message;
27 | import com.zyw.driver.model.Passenger;
28 | import com.zyw.driver.service.DriverService;
29 | import com.zyw.driver.utils.LogHelper;
30 |
31 | public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
32 | private static final String TAG = LogHelper.makeLogTag(MainActivity.class);
33 | private static final int REQUEST_TAKE_ORDER = 0x1000;
34 |
35 | private ServiceConnection mServiceConnection;
36 |
37 | private DriverService.DriverServiceBinder mBinder;
38 |
39 | private double[] mCurrentLocation = new double[2];
40 |
41 | private LocationManager mLocationManager;
42 |
43 | private ListView mLvPassengerInfo;
44 |
45 | private PassengerInfoAdapter mAdapter;
46 |
47 | private Handler mHandler = new Handler();
48 |
49 | @Override
50 | protected void onCreate(Bundle savedInstanceState) {
51 | super.onCreate(savedInstanceState);
52 | setContentView(R.layout.activity_main);
53 | initViews();
54 | initLocationManager();
55 | prepareService();
56 | }
57 |
58 | private void prepareService() {
59 | Intent service = new Intent(MainActivity.this, DriverService.class);
60 | String name = getIntent().getStringExtra(LoginActivity.EXTRA_NAME);
61 | String phoneNumber = getIntent().getStringExtra(LoginActivity.EXTRA_PHONE_NUMBER);
62 | service.putExtra(LoginActivity.EXTRA_NAME, name);
63 | service.putExtra(LoginActivity.EXTRA_PHONE_NUMBER, phoneNumber);
64 |
65 | mServiceConnection = new ServiceConnection() {
66 | @Override
67 | public void onServiceConnected(ComponentName name, IBinder service) {
68 | LogHelper.d(TAG, "onServiceConnected");
69 | mBinder = (DriverService.DriverServiceBinder) service;
70 | DriverServiceCallback callback = new DriverServiceCallback() {
71 | @Override
72 | public void onUpdatePassenger(String msg) {
73 | updatePassenger(msg);
74 | }
75 |
76 | @Override
77 | public void onPassengerTaken(String msg) {
78 | passengerTaken(msg);
79 | }
80 |
81 | @Override
82 | public void onPassengerCancel(String msg) {
83 | passengerCancel(msg);
84 | }
85 |
86 | @Override
87 | public void onPassengerOffline(String msg) {
88 | passengerOffline(msg);
89 | }
90 | };
91 | mBinder.addCallback(callback);
92 | }
93 |
94 | @Override
95 | public void onServiceDisconnected(ComponentName name) {
96 | LogHelper.d(TAG, "onServiceDisconnected");
97 | }
98 | };
99 | bindService(service, mServiceConnection, BIND_AUTO_CREATE);
100 | }
101 |
102 | private void passengerOffline(String msg) {
103 | Message message = new Message(msg);
104 | final Passenger passenger = new Passenger(message.getPassengerName(), message.getPassengerPhoneNumber());
105 | mHandler.post(new Runnable() {
106 | @Override
107 | public void run() {
108 | mAdapter.removePassenger(passenger);
109 | }
110 | });
111 |
112 | }
113 |
114 | private void passengerCancel(String msg) {
115 | Message message = new Message(msg);
116 | final Passenger passenger = new Passenger(message.getPassengerName(), message.getPassengerPhoneNumber());
117 | mHandler.post(new Runnable() {
118 | @Override
119 | public void run() {
120 | mAdapter.removePassenger(passenger);
121 | }
122 | });
123 | }
124 |
125 | private void passengerTaken(String msg) {
126 | Message message = new Message(msg);
127 | final Passenger passenger = new Passenger(message.getPassengerName(), message.getPassengerPhoneNumber());
128 | mHandler.post(new Runnable() {
129 | @Override
130 | public void run() {
131 | mAdapter.removePassenger(passenger);
132 | }
133 | });
134 | }
135 |
136 | private void updatePassenger(String msg) {
137 | Message message = new Message(msg);
138 | final Passenger passenger = new Passenger(message.getPassengerName(), message.getPassengerPhoneNumber());
139 | passenger.setDestination(message.getDestination());
140 | passenger.setLocation(message.getLocation());
141 | LatLng passengerLocation = new LatLng(passenger.getLocation()[0], passenger.getLocation()[1]);
142 | //乘客和司机间的距离
143 | int distance = (int) DistanceUtil.getDistance(passengerLocation, new LatLng(mCurrentLocation[0], mCurrentLocation[1]));
144 |
145 | LogHelper.d(TAG, "distance = " + distance + "passengerLoc:" + passenger.getLocation()[0] + " " +
146 | passenger.getLocation()[1] + " driverLoc :" + mCurrentLocation[0] + " " + mCurrentLocation[1]);
147 | passenger.setDistance(distance);
148 | mHandler.post(new Runnable() {
149 | @Override
150 | public void run() {
151 | mAdapter.updatePassenger(passenger);
152 | }
153 | });
154 | }
155 |
156 | private void initViews() {
157 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
158 | setSupportActionBar(toolbar);
159 | mLvPassengerInfo = (ListView) findViewById(R.id.lv_passengers);
160 | mAdapter = new PassengerInfoAdapter(this);
161 | mLvPassengerInfo.setOnItemClickListener(this);
162 | mLvPassengerInfo.setAdapter(mAdapter);
163 | }
164 |
165 | private void initLocationManager() {
166 | mLocationManager = new LocationManager(this);
167 | mLocationManager.init(new OnLocationReceivedListener() {
168 | @Override
169 | public void onLocationReceived(BDLocation bdLocation) {
170 | LogHelper.d(TAG, "onLocationReceived");
171 | mCurrentLocation[0] = bdLocation.getLatitude();
172 | mCurrentLocation[1] = bdLocation.getLongitude();
173 | if (mBinder != null) {
174 | mBinder.updateLocation(mCurrentLocation);
175 | }
176 | }
177 | });
178 | mLocationManager.start();
179 | }
180 |
181 | @Override
182 | protected void onPause() {
183 | super.onPause();
184 | LogHelper.d(TAG, "onStop");
185 | }
186 |
187 | @Override
188 | protected void onDestroy() {
189 | unbindService(mServiceConnection);
190 | mLocationManager.stop();
191 | super.onDestroy();
192 | LogHelper.d(TAG, "onDestory");
193 | }
194 |
195 | @Override
196 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
197 | final Passenger passenger = mAdapter.getItem(position);
198 | final String name = passenger.getName();
199 | final String phoneNumber = passenger.getPhoneNumber();
200 | final String adress = passenger.getDestination().getDetailAdress();
201 | final int destDistance = (int) passenger.getDestination().getDistance() / 1000;
202 | final int distance = passenger.getDistance();
203 | new AlertDialog.Builder(this)
204 | .setTitle("是否接单?")
205 | .setMessage(String.format("乘客:%s\n手机号:%s\n目的地:%s %d\n",
206 | name, phoneNumber, adress, destDistance))
207 | .setPositiveButton("确定", new DialogInterface.OnClickListener() {
208 | @Override
209 | public void onClick(DialogInterface dialog, int which) {
210 | mBinder.driverAccept(passenger, mCurrentLocation);
211 | Intent intent = new Intent(MainActivity.this, PassengerInfoActivity.class);
212 | intent.putExtra(LoginActivity.EXTRA_NAME, name);
213 | intent.putExtra(LoginActivity.EXTRA_PHONE_NUMBER, phoneNumber);
214 | intent.putExtra(LoginActivity.EXTRA_ADRESS, adress);
215 | intent.putExtra(LoginActivity.EXTRA_DEST_DISTANCE, destDistance);
216 | intent.putExtra(LoginActivity.EXTRA_DISTANCE, distance);
217 | startActivityForResult(intent, REQUEST_TAKE_ORDER);
218 | }
219 | })
220 | .setNegativeButton("取消", null)
221 | .show();
222 | }
223 |
224 | @Override
225 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
226 |
227 | if (requestCode == REQUEST_TAKE_ORDER && resultCode == Activity.RESULT_OK){
228 |
229 | }
230 | }
231 | }
232 |
--------------------------------------------------------------------------------