├── .gitignore ├── LICENSE ├── Readme.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── release │ ├── app-release.apk │ └── output.json └── src │ ├── androidTest │ └── java │ │ └── cn │ │ └── iamywang │ │ └── mapchats │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── cn │ │ │ └── iamywang │ │ │ └── mapchats │ │ │ ├── activity │ │ │ ├── friend │ │ │ │ ├── ChatRoomActivity.kt │ │ │ │ ├── ExploreActivity.kt │ │ │ │ ├── FriendsListActivity.kt │ │ │ │ └── LocationShareActivity.java │ │ │ ├── misc │ │ │ │ ├── AboutActivity.kt │ │ │ │ ├── FeedBackActivity.kt │ │ │ │ └── SplashActivity.kt │ │ │ ├── path │ │ │ │ ├── HisrotyLocationActivity.java │ │ │ │ ├── HistoryPathListActivity.kt │ │ │ │ ├── PathRecordActivity.java │ │ │ │ └── PathResultActivity.kt │ │ │ └── user │ │ │ │ ├── LoginActivity.kt │ │ │ │ ├── MainActivity.kt │ │ │ │ ├── RegisterActivity.kt │ │ │ │ └── UserInfoActivity.kt │ │ │ └── util │ │ │ ├── list │ │ │ ├── HistoryPathItem.kt │ │ │ ├── HistoryPathItemAdapter.java │ │ │ ├── MessageListItem.kt │ │ │ ├── MessageListItemAdapter.java │ │ │ ├── UserItemAdapter.java │ │ │ └── UserListItem.kt │ │ │ ├── misc │ │ │ ├── SensorEventHelper.java │ │ │ └── UIHandler.kt │ │ │ └── network │ │ │ └── JavaHttpKolley.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_user_admin.png │ │ ├── drawable │ │ ├── bubble.9.png │ │ ├── ic_about.xml │ │ ├── ic_chat.xml │ │ ├── ic_feedback.xml │ │ ├── ic_friend.xml │ │ ├── ic_history.xml │ │ ├── ic_launcher.xml │ │ ├── ic_login.xml │ │ ├── ic_map.xml │ │ ├── ic_path.xml │ │ ├── ic_path_run.xml │ │ ├── ic_send.xml │ │ ├── ic_share.xml │ │ ├── ic_user.xml │ │ ├── ic_user_color.xml │ │ ├── ic_user_color_2.xml │ │ ├── ic_user_color_3.xml │ │ └── side_nav_bar.xml │ │ ├── layout │ │ ├── activity_about.xml │ │ ├── activity_chat_room.xml │ │ ├── activity_explore.xml │ │ ├── activity_feed_back.xml │ │ ├── activity_friends_list.xml │ │ ├── activity_hisroty_location.xml │ │ ├── activity_history_path_list.xml │ │ ├── activity_location_share.xml │ │ ├── activity_login.xml │ │ ├── activity_main.xml │ │ ├── activity_path_record.xml │ │ ├── activity_path_result.xml │ │ ├── activity_register.xml │ │ ├── activity_splash.xml │ │ ├── activity_user_info.xml │ │ ├── app_bar_main.xml │ │ ├── content_main.xml │ │ ├── item_msg_list.xml │ │ ├── item_path_list.xml │ │ ├── item_user_list.xml │ │ └── nav_header_main.xml │ │ ├── menu │ │ └── activity_main_drawer.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ ├── navi_map_gps_locked.png │ │ ├── point.png │ │ └── run.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values-v21 │ │ └── styles.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── ic_launcher_background.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── cn │ └── iamywang │ └── mapchats │ └── ExampleUnitTest.kt ├── build.gradle ├── demo.png ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .idea 15 | key.jks 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Y.Wang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # GPS地图社交系统 Version 2019.a.190610 2 | 3 | ### 基本说明 4 | * 使用Kotlin语言开发 5 | * SDK API 28 6 | * 高德地图API 7 | https://lbs.amap.com 8 | 9 | ### 界面一览 10 | 11 | ![](demo.png) 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 | * 问题反馈 -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdkVersion 28 9 | defaultConfig { 10 | applicationId "cn.iamywang.mapchats" 11 | minSdkVersion 24 12 | targetSdkVersion 27 13 | versionCode 20190612 14 | versionName "2019.a.190612v2--release" 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(dir: 'libs', include: ['*.jar']) 27 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 28 | implementation 'com.android.support:appcompat-v7:28.0.0' 29 | implementation 'com.android.support:support-v4:28.0.0' 30 | implementation 'com.android.support:design:28.0.0' 31 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 32 | testImplementation 'junit:junit:4.12' 33 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 34 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 35 | 36 | implementation 'com.amap.api:3dmap:6.8.0' 37 | implementation 'com.amap.api:location:4.6.0' 38 | implementation 'com.amap.api:search:6.5.0.1' 39 | implementation 'com.ohmerhe.kolley:kolley:0.3.1' 40 | implementation 'com.alibaba:fastjson:1.1.71.android' 41 | } 42 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/release/app-release.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamywang/Dating-Android/d6f91baf2f7ccb7100925857dc952a9e199e3e11/app/release/app-release.apk -------------------------------------------------------------------------------- /app/release/output.json: -------------------------------------------------------------------------------- 1 | [{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":20190612,"versionName":"2019.a.190612v2--release","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] -------------------------------------------------------------------------------- /app/src/androidTest/java/cn/iamywang/mapchats/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("cn.iamywang.mapchats", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 24 | 27 | 28 | 31 | 32 | 33 | 34 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 51 | 55 | 59 | 60 | 64 | 65 | 69 | 70 | 74 | 75 | 79 | 80 | 84 | 85 | 89 | 90 | 94 | 95 | 99 | 100 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/activity/friend/ChatRoomActivity.kt: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.activity.friend 2 | 3 | import android.support.v7.app.AppCompatActivity 4 | import android.os.Bundle 5 | import android.support.constraint.ConstraintLayout 6 | import android.support.v7.widget.Toolbar 7 | import android.view.MenuItem 8 | import android.view.View 9 | import android.widget.* 10 | import cn.iamywang.mapchats.R 11 | import cn.iamywang.mapchats.util.list.MessageListItem 12 | import cn.iamywang.mapchats.util.list.MessageListItemAdapter 13 | import cn.iamywang.mapchats.util.network.JavaHttpKolley 14 | import java.util.* 15 | 16 | class ChatRoomActivity : AppCompatActivity(), AdapterView.OnItemClickListener { 17 | 18 | private var USERID = "" 19 | private var REMOTE_ID = "" 20 | private var REMOTE_NAME = "" 21 | var list = LinkedList() 22 | var mAdapter = MessageListItemAdapter(list, this) 23 | 24 | override fun onCreate(savedInstanceState: Bundle?) { 25 | super.onCreate(savedInstanceState) 26 | setContentView(R.layout.activity_chat_room) 27 | val actionBar = findViewById(R.id.chatbar) 28 | setSupportActionBar(actionBar) 29 | window.statusBarColor = getColor(R.color.colorPrimaryDark) 30 | val toolbar = supportActionBar 31 | if (toolbar != null) { 32 | toolbar.setHomeButtonEnabled(true) 33 | toolbar.setDisplayHomeAsUpEnabled(true) 34 | } 35 | 36 | val chat_intent = intent 37 | this.USERID = chat_intent.getStringExtra("local_id").toString() 38 | this.REMOTE_ID = chat_intent.getStringExtra("remote_id").toString() 39 | this.REMOTE_NAME = chat_intent.getStringExtra("remote_name").toString() 40 | title = this.REMOTE_NAME 41 | actionBar.subtitle = "连接中..." 42 | actionBar.setLogo(R.drawable.ic_user_color) 43 | actionBar.logo.setBounds(0, 0, 48, 48) 44 | 45 | val v = findViewById(R.id.msg_item_view) 46 | v.visibility = View.INVISIBLE 47 | 48 | val thread_this = this 49 | val thread = Thread(object : Runnable { 50 | override fun run() { 51 | val jhk = JavaHttpKolley() 52 | while (true) { 53 | jhk.getChatMessages(USERID, REMOTE_ID, thread_this) 54 | Thread.sleep(3000) 55 | } 56 | } 57 | }) 58 | thread.start() 59 | } 60 | 61 | fun setAdapter() { 62 | val list_view = findViewById(R.id.message_list) 63 | list_view.dividerHeight = 0 64 | list_view.adapter = mAdapter 65 | list_view.setOnItemClickListener(this) 66 | list_view.setSelection(mAdapter.count - 1) 67 | } 68 | 69 | override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { 70 | 71 | } 72 | 73 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 74 | if (item.getItemId() == android.R.id.home) { 75 | this.finish() 76 | return true 77 | } 78 | return super.onOptionsItemSelected(item) 79 | } 80 | 81 | fun sendMsg(view: View) { 82 | val text_view = findViewById(R.id.chat_text) 83 | val jhk = JavaHttpKolley() 84 | jhk.addNewMessage(this.USERID, this.REMOTE_ID, text_view.text.toString(), this) 85 | text_view.text.clear() 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/activity/friend/ExploreActivity.kt: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.activity.friend 2 | 3 | import android.support.v7.app.AppCompatActivity 4 | import android.os.Bundle 5 | import android.view.MenuItem 6 | import cn.iamywang.mapchats.R 7 | 8 | class ExploreActivity : AppCompatActivity() { 9 | 10 | override fun onCreate(savedInstanceState: Bundle?) { 11 | super.onCreate(savedInstanceState) 12 | setContentView(R.layout.activity_explore) 13 | val actionBar = supportActionBar 14 | if (actionBar != null) { 15 | actionBar.setHomeButtonEnabled(true) 16 | actionBar.setDisplayHomeAsUpEnabled(true) 17 | } 18 | } 19 | 20 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 21 | if (item.getItemId() == android.R.id.home) { 22 | this.finish() 23 | return true 24 | } 25 | return super.onOptionsItemSelected(item) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/activity/friend/FriendsListActivity.kt: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.activity.friend 2 | 3 | import android.support.v7.app.AppCompatActivity 4 | import android.os.Bundle 5 | import android.support.constraint.ConstraintLayout 6 | import android.view.MenuItem 7 | import android.view.View 8 | import android.widget.AdapterView 9 | import android.widget.ListView 10 | import cn.iamywang.mapchats.R 11 | import cn.iamywang.mapchats.util.network.JavaHttpKolley 12 | import cn.iamywang.mapchats.util.list.UserItemAdapter 13 | import cn.iamywang.mapchats.util.list.UserListItem 14 | import java.util.* 15 | 16 | class FriendsListActivity : AppCompatActivity(), AdapterView.OnItemClickListener { 17 | val list = LinkedList() 18 | val mAdapter = UserItemAdapter(list, this) 19 | 20 | override fun onCreate(savedInstanceState: Bundle?) { 21 | super.onCreate(savedInstanceState) 22 | setContentView(R.layout.activity_friends_list) 23 | val actionBar = supportActionBar 24 | if (actionBar != null) { 25 | actionBar.setHomeButtonEnabled(true) 26 | actionBar.setDisplayHomeAsUpEnabled(true) 27 | } 28 | 29 | val v = findViewById(R.id.user_item_view) 30 | v.visibility = View.INVISIBLE 31 | 32 | val jhk = JavaHttpKolley() 33 | jhk.getUserList(this) 34 | } 35 | 36 | fun setAdapter() { 37 | val list_view = findViewById(R.id.friends_list) 38 | list_view.adapter = mAdapter 39 | list_view.setOnItemClickListener(this) 40 | } 41 | 42 | override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { 43 | 44 | } 45 | 46 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 47 | if (item.getItemId() == android.R.id.home) { 48 | this.finish() 49 | return true 50 | } 51 | return super.onOptionsItemSelected(item) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/activity/friend/LocationShareActivity.java: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.activity.friend; 2 | 3 | import android.content.Intent; 4 | import android.graphics.BitmapFactory; 5 | import android.graphics.Color; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.os.Bundle; 8 | import android.view.MenuItem; 9 | import android.view.View; 10 | import android.widget.TextView; 11 | import cn.iamywang.mapchats.R; 12 | import cn.iamywang.mapchats.util.network.JavaHttpKolley; 13 | import cn.iamywang.mapchats.util.misc.SensorEventHelper; 14 | import com.amap.api.location.AMapLocation; 15 | import com.amap.api.location.AMapLocationClient; 16 | import com.amap.api.location.AMapLocationClientOption; 17 | import com.amap.api.location.AMapLocationListener; 18 | import com.amap.api.maps.*; 19 | import com.amap.api.maps.model.*; 20 | 21 | import java.text.DecimalFormat; 22 | 23 | public class LocationShareActivity extends AppCompatActivity implements LocationSource, 24 | AMapLocationListener { 25 | 26 | private AMap aMap; 27 | private MapView mapView; 28 | private LocationSource.OnLocationChangedListener mListener; 29 | private AMapLocationClient mlocationClient; 30 | private AMapLocationClientOption mLocationOption; 31 | 32 | private static final int STROKE_COLOR = Color.argb(180, 3, 145, 255); 33 | private static final int FILL_COLOR = Color.argb(10, 0, 0, 180); 34 | private boolean mFirstFix = false; 35 | private Marker mLocMarker; 36 | private SensorEventHelper mSensorHelper; 37 | private Circle mCircle; 38 | public static final String LOCATION_MARKER_FLAG = "当前位置"; 39 | private double curLat, curLon; 40 | private String USERID; 41 | 42 | @Override 43 | protected void onCreate(Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | setContentView(R.layout.activity_location_share); 46 | android.support.v7.app.ActionBar actionBar = getSupportActionBar(); 47 | if (actionBar != null) { 48 | actionBar.setHomeButtonEnabled(true); 49 | actionBar.setDisplayHomeAsUpEnabled(true); 50 | } 51 | Intent infointent = getIntent(); 52 | this.USERID = infointent.getStringExtra("id"); 53 | mapView = (MapView) findViewById(R.id.map); 54 | mapView.onCreate(savedInstanceState);// 此方法必须重写 55 | init(); 56 | JavaHttpKolley jkh = new JavaHttpKolley(); 57 | jkh.getHisMarker(this.USERID, this); 58 | jkh.getOnlineUser(this.USERID, this); 59 | } 60 | 61 | @Override 62 | public boolean onOptionsItemSelected(MenuItem item) { 63 | if (item.getItemId() == android.R.id.home) { 64 | this.finish(); 65 | return true; 66 | } 67 | return super.onOptionsItemSelected(item); 68 | } 69 | 70 | public void OnButtonUploadClick(View view) { 71 | DecimalFormat df = new DecimalFormat("0.000000"); 72 | String loc = df.format(this.curLat) + "," + df.format(this.curLon); 73 | JavaHttpKolley jhk = new JavaHttpKolley(); 74 | jhk.addLocation(this.USERID, loc, this); 75 | } 76 | 77 | /** 78 | * 初始化 79 | */ 80 | private void init() { 81 | if (aMap == null) { 82 | aMap = mapView.getMap(); 83 | setUpMap(); 84 | } 85 | mSensorHelper = new SensorEventHelper(this); 86 | mSensorHelper.registerSensorListener(); 87 | } 88 | 89 | /** 90 | * 设置一些amap的属性 91 | */ 92 | private void setUpMap() { 93 | UiSettings uiSettings = aMap.getUiSettings(); 94 | uiSettings.setCompassEnabled(true);// 设置指南针是否显示 95 | uiSettings.setZoomControlsEnabled(true);// 设置缩放按钮是否显示 96 | uiSettings.setScaleControlsEnabled(true);// 设置比例尺是否显示 97 | uiSettings.setRotateGesturesEnabled(true);// 设置地图旋转是否可用 98 | uiSettings.setMyLocationButtonEnabled(true);// 设置默认定位按钮是否显示 99 | aMap.setLocationSource(this);// 设置定位监听 100 | aMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false 101 | // 设置定位的类型为定位模式 ,可以由定位、跟随或地图根据面向方向旋转几种 102 | aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE); 103 | aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(36.6507007,117.1140042),11)); 104 | } 105 | 106 | /** 107 | * 方法必须重写 108 | */ 109 | @Override 110 | protected void onResume() { 111 | super.onResume(); 112 | mapView.onResume(); 113 | if (mSensorHelper != null) { 114 | mSensorHelper.registerSensorListener(); 115 | } 116 | } 117 | 118 | /** 119 | * 方法必须重写 120 | */ 121 | @Override 122 | protected void onPause() { 123 | super.onPause(); 124 | if (mSensorHelper != null) { 125 | mSensorHelper.unRegisterSensorListener(); 126 | mSensorHelper.setCurrentMarker(null); 127 | mSensorHelper = null; 128 | } 129 | mapView.onPause(); 130 | deactivate(); 131 | mFirstFix = false; 132 | } 133 | 134 | /** 135 | * 方法必须重写 136 | */ 137 | @Override 138 | protected void onSaveInstanceState(Bundle outState) { 139 | super.onSaveInstanceState(outState); 140 | mapView.onSaveInstanceState(outState); 141 | } 142 | 143 | /** 144 | * 方法必须重写 145 | */ 146 | @Override 147 | protected void onDestroy() { 148 | super.onDestroy(); 149 | if (mLocMarker != null) { 150 | mLocMarker.destroy(); 151 | } 152 | mapView.onDestroy(); 153 | if (null != mlocationClient) { 154 | mlocationClient.onDestroy(); 155 | } 156 | } 157 | 158 | /** 159 | * 定位成功后回调函数 160 | */ 161 | @Override 162 | public void onLocationChanged(AMapLocation amapLocation) { 163 | if (mListener != null && amapLocation != null) { 164 | if (amapLocation.getErrorCode() == 0) { 165 | LatLng location = new LatLng(amapLocation.getLatitude(), amapLocation.getLongitude()); 166 | DecimalFormat df = new DecimalFormat("0.000000"); 167 | this.curLat = location.latitude; 168 | this.curLon = location.longitude; 169 | TextView loc = findViewById(R.id.map_t1); 170 | String res = "当前位置:" + df.format(this.curLat) + "," + df.format(this.curLon); 171 | loc.setText(res); 172 | if (!mFirstFix) { 173 | mFirstFix = true; 174 | addCircle(location, amapLocation.getAccuracy());//添加定位精度圆 175 | addMarker(location);//添加定位图标 176 | mSensorHelper.setCurrentMarker(mLocMarker);//定位图标旋转 177 | aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 18)); 178 | } else { 179 | mCircle.setCenter(location); 180 | mCircle.setRadius(amapLocation.getAccuracy()); 181 | mLocMarker.setPosition(location); 182 | aMap.moveCamera(CameraUpdateFactory.changeLatLng(location)); 183 | } 184 | } 185 | } 186 | JavaHttpKolley jkh = new JavaHttpKolley(); 187 | aMap.getMapScreenMarkers().clear(); 188 | jkh.getHisMarker(this.USERID, this); 189 | jkh.getOnlineUser(this.USERID, this); 190 | } 191 | 192 | /** 193 | * 激活定位 194 | */ 195 | @Override 196 | public void activate(LocationSource.OnLocationChangedListener listener) { 197 | mListener = listener; 198 | if (mlocationClient == null) { 199 | mlocationClient = new AMapLocationClient(this); 200 | mLocationOption = new AMapLocationClientOption(); 201 | //设置定位监听 202 | mlocationClient.setLocationListener(this); 203 | //设置为高精度定位模式 204 | mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Device_Sensors); 205 | //设置定位参数 206 | mLocationOption.setInterval(10000); 207 | mlocationClient.setLocationOption(mLocationOption); 208 | // 此方法为每隔固定时间会发起一次定位请求,为了减少电量消耗或网络流量消耗, 209 | // 注意设置合适的定位时间的间隔(最小间隔支持为2000ms),并且在合适时间调用stopLocation()方法来取消定位请求 210 | // 在定位结束后,在合适的生命周期调用onDestroy()方法 211 | // 在单次定位情况下,定位无论成功与否,都无需调用stopLocation()方法移除请求,定位sdk内部会移除 212 | mlocationClient.startLocation(); 213 | } 214 | } 215 | 216 | /** 217 | * 停止定位 218 | */ 219 | @Override 220 | public void deactivate() { 221 | mListener = null; 222 | if (mlocationClient != null) { 223 | mlocationClient.stopLocation(); 224 | mlocationClient.onDestroy(); 225 | } 226 | mlocationClient = null; 227 | } 228 | 229 | private void addCircle(LatLng latlng, double radius) { 230 | CircleOptions options = new CircleOptions(); 231 | options.strokeWidth(1f); 232 | options.fillColor(FILL_COLOR); 233 | options.strokeColor(STROKE_COLOR); 234 | options.center(latlng); 235 | options.radius(radius); 236 | mCircle = aMap.addCircle(options); 237 | } 238 | 239 | private void addMarker(LatLng latlng) { 240 | if (mLocMarker != null) { 241 | return; 242 | } 243 | MarkerOptions options = new MarkerOptions(); 244 | options.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(this.getResources(), 245 | R.mipmap.navi_map_gps_locked))); 246 | options.anchor(0.5f, 0.5f); 247 | options.position(latlng); 248 | mLocMarker = aMap.addMarker(options); 249 | mLocMarker.setTitle(LOCATION_MARKER_FLAG); 250 | } 251 | 252 | public void addHisLoc(LatLng latlng, String uid, String time) { 253 | MarkerOptions options = new MarkerOptions(); 254 | options.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(this.getResources(), 255 | R.mipmap.point))); 256 | options.anchor(0.5f, 0.5f); 257 | options.position(latlng); 258 | options.title(uid); 259 | options.snippet(time); 260 | aMap.addMarker(options); 261 | } 262 | 263 | public void addShareLoc(LatLng latlng, String uid, String time) { 264 | MarkerOptions options = new MarkerOptions(); 265 | options.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(this.getResources(), 266 | R.mipmap.run))); 267 | options.anchor(0.5f, 0.5f); 268 | options.position(latlng); 269 | options.title(uid); 270 | options.snippet(time); 271 | aMap.addMarker(options); 272 | } 273 | } 274 | -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/activity/misc/AboutActivity.kt: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.activity.misc 2 | 3 | import android.support.v7.app.AppCompatActivity 4 | import android.os.Bundle 5 | import android.view.MenuItem 6 | import cn.iamywang.mapchats.R 7 | 8 | class AboutActivity : AppCompatActivity() { 9 | 10 | override fun onCreate(savedInstanceState: Bundle?) { 11 | super.onCreate(savedInstanceState) 12 | setContentView(R.layout.activity_about) 13 | val actionBar = supportActionBar 14 | if (actionBar != null) { 15 | actionBar.setHomeButtonEnabled(true) 16 | actionBar.setDisplayHomeAsUpEnabled(true) 17 | } 18 | } 19 | 20 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 21 | if (item.getItemId() == android.R.id.home) { 22 | this.finish() 23 | return true 24 | } 25 | return super.onOptionsItemSelected(item) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/activity/misc/FeedBackActivity.kt: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.activity.misc 2 | 3 | import android.support.v7.app.AppCompatActivity 4 | import android.os.Bundle 5 | import android.view.MenuItem 6 | import android.view.View 7 | import android.widget.TextView 8 | import android.widget.Toast 9 | import cn.iamywang.mapchats.R 10 | import com.ohmerhe.kolley.request.Http 11 | 12 | class FeedBackActivity : AppCompatActivity() { 13 | 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | setContentView(R.layout.activity_feed_back) 17 | val actionBar = supportActionBar 18 | if (actionBar != null) { 19 | actionBar.setHomeButtonEnabled(true) 20 | actionBar.setDisplayHomeAsUpEnabled(true) 21 | } 22 | val feed_intent = intent 23 | val userid = feed_intent.getStringExtra("id").toString() 24 | val usernick = feed_intent.getStringExtra("nick").toString() 25 | val id_view:TextView = findViewById(R.id.feed_e1) 26 | val nick_view:TextView = findViewById(R.id.feed_e2) 27 | id_view.setText(userid) 28 | nick_view.setText(usernick) 29 | Http.init(this) 30 | } 31 | 32 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 33 | if (item.getItemId() == android.R.id.home) { 34 | this.finish() 35 | return true 36 | } 37 | return super.onOptionsItemSelected(item) 38 | } 39 | 40 | fun OnButtonClick(view: View){ 41 | this.finish() 42 | Toast.makeText(this, "反馈成功", Toast.LENGTH_LONG).show() 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/activity/misc/SplashActivity.kt: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.activity.misc 2 | 3 | import android.content.Intent 4 | import android.support.v7.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.os.Message 7 | import cn.iamywang.mapchats.activity.user.MainActivity 8 | import cn.iamywang.mapchats.R 9 | import cn.iamywang.mapchats.util.misc.UIHandler 10 | 11 | class SplashActivity : AppCompatActivity() { 12 | 13 | private val mHandler = SplashHandle(this) 14 | 15 | // 将常量放入这里 16 | companion object { 17 | 18 | // 正常跳转到登录界面 常量 防止以后增加业务逻辑 19 | val MSG_LAUNCH: Int = 0 20 | 21 | // 延时时间 22 | val SLEEP_TIME = 800 23 | } 24 | 25 | override fun onCreate(savedInstanceState: Bundle?) { 26 | super.onCreate(savedInstanceState) 27 | setContentView(R.layout.activity_splash) 28 | 29 | } 30 | 31 | override fun onResume() { 32 | super.onResume() 33 | 34 | val start = System.currentTimeMillis() 35 | 36 | /* 37 | 这里计算了两个时间 38 | 两个时间间可以放入判断条件:是否需要自动登录等 39 | */ 40 | 41 | var costTime = System.currentTimeMillis() - start 42 | 43 | val left = SLEEP_TIME - costTime 44 | 45 | // kotlin中取消了java中的三目运算,换成if...else... 46 | mHandler.postDelayed(runnable, if (left > 0) left else 0) 47 | } 48 | 49 | 50 | val runnable = Runnable { 51 | kotlin.run { 52 | val message = mHandler.obtainMessage(MSG_LAUNCH) 53 | mHandler.sendMessage(message) 54 | } 55 | } 56 | 57 | // 弱引用handler内部类 58 | private class SplashHandle(cls: SplashActivity) : UIHandler(cls) { 59 | 60 | override fun handleMessage(msg: Message?) { 61 | super.handleMessage(msg) 62 | val activity = ref?.get() 63 | if (null != activity) { 64 | 65 | if (activity.isFinishing) 66 | return 67 | 68 | when (msg?.what) { 69 | 70 | // 正常跳转到登录界面 71 | MSG_LAUNCH -> { 72 | activity.startActivity(Intent(activity, MainActivity::class.java)) 73 | activity.finish() 74 | } 75 | } 76 | } 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/activity/path/HisrotyLocationActivity.java: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.activity.path; 2 | 3 | import android.content.Intent; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.graphics.Color; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.os.Bundle; 9 | import android.view.MenuItem; 10 | import android.widget.TextView; 11 | import cn.iamywang.mapchats.R; 12 | import cn.iamywang.mapchats.util.network.JavaHttpKolley; 13 | import com.amap.api.maps.*; 14 | import com.amap.api.maps.model.*; 15 | 16 | import java.text.DecimalFormat; 17 | import java.util.List; 18 | 19 | public class HisrotyLocationActivity extends AppCompatActivity { 20 | private AMap aMap; 21 | private MapView mapView; 22 | public String USERID, PATHID; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.activity_hisroty_location); 28 | android.support.v7.app.ActionBar actionBar = getSupportActionBar(); 29 | if (actionBar != null) { 30 | actionBar.setHomeButtonEnabled(true); 31 | actionBar.setDisplayHomeAsUpEnabled(true); 32 | } 33 | Intent infointent = getIntent(); 34 | this.USERID = infointent.getStringExtra("id"); 35 | this.PATHID = infointent.getStringExtra("path"); 36 | 37 | TextView path_view = findViewById(R.id.his_text_tag); 38 | path_view.setText(this.PATHID); 39 | 40 | mapView = (MapView) findViewById(R.id.his_map); 41 | mapView.onCreate(savedInstanceState);// 此方法必须重写 42 | init(); 43 | 44 | if (this.PATHID.equals("0")) { 45 | JavaHttpKolley jhk = new JavaHttpKolley(); 46 | jhk.getHisRoadList(this.USERID, this); 47 | } else { 48 | JavaHttpKolley jhk = new JavaHttpKolley(); 49 | jhk.getHisLine(this.USERID, this.PATHID, this); 50 | } 51 | } 52 | 53 | @Override 54 | public boolean onOptionsItemSelected(MenuItem item) { 55 | if (item.getItemId() == android.R.id.home) { 56 | this.finish(); 57 | return true; 58 | } 59 | return super.onOptionsItemSelected(item); 60 | } 61 | 62 | /** 63 | * 初始化 64 | */ 65 | private void init() { 66 | if (aMap == null) { 67 | aMap = mapView.getMap(); 68 | setUpMap(); 69 | } 70 | } 71 | 72 | /** 73 | * 设置一些amap的属性 74 | */ 75 | private void setUpMap() { 76 | UiSettings uiSettings = aMap.getUiSettings(); 77 | uiSettings.setCompassEnabled(true);// 设置指南针是否显示 78 | uiSettings.setZoomControlsEnabled(true);// 设置缩放按钮是否显示 79 | uiSettings.setScaleControlsEnabled(true);// 设置比例尺是否显示 80 | uiSettings.setRotateGesturesEnabled(true);// 设置地图旋转是否可用 81 | aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(36.6507007, 117.1140042), 11)); 82 | } 83 | 84 | @Override 85 | protected void onResume() { 86 | super.onResume(); 87 | mapView.onResume(); 88 | } 89 | 90 | @Override 91 | protected void onPause() { 92 | super.onPause(); 93 | mapView.onPause(); 94 | } 95 | 96 | @Override 97 | protected void onSaveInstanceState(Bundle outState) { 98 | super.onSaveInstanceState(outState); 99 | mapView.onSaveInstanceState(outState); 100 | } 101 | 102 | @Override 103 | protected void onDestroy() { 104 | super.onDestroy(); 105 | mapView.onDestroy(); 106 | } 107 | 108 | public void addHisLine(List list, int color, String start, String end) { 109 | PolylineOptions options = new PolylineOptions(); 110 | options.addAll(list); 111 | options.width(12); 112 | options.color(Color.argb(255, 0, 128, 255)); 113 | options.lineJoinType(PolylineOptions.LineJoinType.LineJoinRound); 114 | options.lineCapType(PolylineOptions.LineCapType.LineCapRound); 115 | // options.setDottedLine(true); 116 | aMap.addMarker(new MarkerOptions().position(list.get(0)).title("起点").snippet(start)); 117 | aMap.addPolyline(options); 118 | double result_length = 0.00; 119 | for (int i = 1; i < list.size(); i++) { 120 | result_length += calculateLineDistance(list.get(i - 1), list.get(i)); 121 | } 122 | DecimalFormat df2 = new DecimalFormat("0.00"); 123 | String length = df2.format(result_length) + "m"; 124 | TextView start_view = findViewById(R.id.his_text_time); 125 | TextView length_view = findViewById(R.id.his_text_length); 126 | start_view.setText(start); 127 | length_view.setText(length); 128 | 129 | MarkerOptions pathMarkerOptions = new MarkerOptions(); 130 | pathMarkerOptions.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(this.getResources(), 131 | R.mipmap.run))); 132 | pathMarkerOptions.anchor(0.5f, 0.5f); 133 | pathMarkerOptions.position(list.get(0)); 134 | aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(list.get(0), 18)); 135 | Marker pathMarker = aMap.addMarker(pathMarkerOptions); 136 | 137 | class PathReviewThread extends Thread { 138 | private Marker pathMarker; 139 | private List list; 140 | 141 | private PathReviewThread(List list, Marker pathMarker) { 142 | this.list = list; 143 | this.pathMarker = pathMarker; 144 | } 145 | 146 | @Override 147 | public void run() { 148 | try { 149 | for (int i = 1; i < list.size(); i++) { 150 | Thread.sleep(200); 151 | pathMarker.setPosition(list.get(i)); 152 | aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(list.get(i), 18)); 153 | } 154 | Thread.sleep(200); 155 | } catch (InterruptedException e) { 156 | e.printStackTrace(); 157 | } 158 | pathMarker.remove(); 159 | } 160 | } 161 | PathReviewThread t = new PathReviewThread(list, pathMarker); 162 | t.start(); 163 | aMap.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)).position(list.get(list.size() - 1)).title("终点").snippet(end)); 164 | } 165 | 166 | public double calculateLineDistance(LatLng start, LatLng end) { 167 | if ((start == null) || (end == null)) { 168 | throw new IllegalArgumentException("非法坐标值,不能为null"); 169 | } 170 | double d1 = 0.01745329251994329D; 171 | double d2 = start.longitude; 172 | double d3 = start.latitude; 173 | double d4 = end.longitude; 174 | double d5 = end.latitude; 175 | d2 *= d1; 176 | d3 *= d1; 177 | d4 *= d1; 178 | d5 *= d1; 179 | double d6 = Math.sin(d2); 180 | double d7 = Math.sin(d3); 181 | double d8 = Math.cos(d2); 182 | double d9 = Math.cos(d3); 183 | double d10 = Math.sin(d4); 184 | double d11 = Math.sin(d5); 185 | double d12 = Math.cos(d4); 186 | double d13 = Math.cos(d5); 187 | double[] arrayOfDouble1 = new double[3]; 188 | double[] arrayOfDouble2 = new double[3]; 189 | arrayOfDouble1[0] = (d9 * d8); 190 | arrayOfDouble1[1] = (d9 * d6); 191 | arrayOfDouble1[2] = d7; 192 | arrayOfDouble2[0] = (d13 * d12); 193 | arrayOfDouble2[1] = (d13 * d10); 194 | arrayOfDouble2[2] = d11; 195 | double d14 = Math.sqrt((arrayOfDouble1[0] - arrayOfDouble2[0]) * (arrayOfDouble1[0] - arrayOfDouble2[0]) 196 | + (arrayOfDouble1[1] - arrayOfDouble2[1]) * (arrayOfDouble1[1] - arrayOfDouble2[1]) 197 | + (arrayOfDouble1[2] - arrayOfDouble2[2]) * (arrayOfDouble1[2] - arrayOfDouble2[2])); 198 | 199 | return (Math.asin(d14 / 2.0D) * 12742001.579854401D); 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/activity/path/HistoryPathListActivity.kt: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.activity.path 2 | 3 | import android.content.Intent 4 | import android.support.v7.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.support.constraint.ConstraintLayout 7 | import android.view.MenuItem 8 | import android.widget.ListView 9 | import cn.iamywang.mapchats.R 10 | import cn.iamywang.mapchats.util.list.HistoryPathItem 11 | import cn.iamywang.mapchats.util.list.HistoryPathItemAdapter 12 | import cn.iamywang.mapchats.util.network.JavaHttpKolley 13 | import java.util.* 14 | import android.widget.AdapterView 15 | import android.view.View 16 | 17 | 18 | class HistoryPathListActivity : AppCompatActivity(), AdapterView.OnItemClickListener { 19 | 20 | val list = LinkedList() 21 | val mAdapter = HistoryPathItemAdapter(list, this) 22 | 23 | override fun onCreate(savedInstanceState: Bundle?) { 24 | super.onCreate(savedInstanceState) 25 | setContentView(R.layout.activity_history_path_list) 26 | val actionBar = supportActionBar 27 | if (actionBar != null) { 28 | actionBar.setHomeButtonEnabled(true) 29 | actionBar.setDisplayHomeAsUpEnabled(true) 30 | } 31 | 32 | val v = findViewById(R.id.path_item_view) 33 | v.visibility = View.INVISIBLE 34 | 35 | val user_id = intent.getStringExtra("id").toString() 36 | val jhk = JavaHttpKolley() 37 | jhk.getHistoryPathList(user_id, this) 38 | } 39 | 40 | fun setAdapter() { 41 | val list_view = findViewById(R.id.path_list) 42 | list_view.adapter = mAdapter 43 | list_view.setOnItemClickListener(this) 44 | } 45 | 46 | override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { 47 | val intent = Intent(this, HisrotyLocationActivity::class.java) 48 | intent.putExtra("id", list.get(position).user_id) 49 | intent.putExtra("path", list.get(position).path_id) 50 | startActivity(intent) 51 | } 52 | 53 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 54 | if (item.getItemId() == android.R.id.home) { 55 | this.finish() 56 | return true 57 | } 58 | return super.onOptionsItemSelected(item) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/activity/path/PathResultActivity.kt: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.activity.path 2 | 3 | import android.content.Intent 4 | import android.support.v7.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.view.MenuItem 7 | import android.view.View 8 | import android.widget.TextView 9 | import android.widget.Toast 10 | import cn.iamywang.mapchats.R 11 | 12 | class PathResultActivity : AppCompatActivity() { 13 | 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | setContentView(R.layout.activity_path_result) 17 | val actionBar = supportActionBar 18 | if (actionBar != null) { 19 | actionBar.setHomeButtonEnabled(true) 20 | actionBar.setDisplayHomeAsUpEnabled(true) 21 | } 22 | val path_intent = intent 23 | 24 | val info_id = path_intent.getStringExtra("id").toString() 25 | val info_nick = path_intent.getStringExtra("nick").toString() 26 | val info_num = path_intent.getStringExtra("num").toString() 27 | val info_time = path_intent.getStringExtra("time").toString() 28 | val info_length = path_intent.getStringExtra("length").toString() 29 | val info_start = path_intent.getStringExtra("start").toString() 30 | 31 | val id_View: TextView = findViewById(R.id.result_id); 32 | val nick_View: TextView = findViewById(R.id.result_nick); 33 | val start_View: TextView = findViewById(R.id.result_time); 34 | val length_View: TextView = findViewById(R.id.result_length); 35 | val num_View: TextView = findViewById(R.id.result_tag); 36 | val time_View: TextView = findViewById(R.id.result_run); 37 | val speed_View: TextView = findViewById(R.id.result_speed); 38 | 39 | val min = info_time.split(':')[0].toInt() 40 | val sec = info_time.split(':')[1].toInt() 41 | val speed = String.format("%.2f", (3.6 * info_length.toDouble() / (min * 60 + sec))) + "km/h" 42 | 43 | id_View.setText(info_id) 44 | nick_View.setText(info_nick) 45 | start_View.setText(info_start) 46 | length_View.setText(String.format("%.2f", info_length.toDouble())) 47 | num_View.setText(info_num) 48 | time_View.setText(info_time) 49 | speed_View.setText(speed) 50 | } 51 | 52 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 53 | if (item.getItemId() == android.R.id.home) { 54 | this.finish() 55 | return true 56 | } 57 | return super.onOptionsItemSelected(item) 58 | } 59 | 60 | fun lookPathLine(view: View) { 61 | val intent = Intent(this, HisrotyLocationActivity::class.java) 62 | intent.putExtra("id", findViewById(R.id.result_id).text) 63 | intent.putExtra("path", findViewById(R.id.result_tag).text) 64 | startActivity(intent) 65 | } 66 | 67 | fun sharePath(view: View) { 68 | Toast.makeText(this, "分享功能正在开发...", Toast.LENGTH_LONG).show() 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/activity/user/LoginActivity.kt: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.activity.user 2 | 3 | import android.Manifest 4 | import android.content.Intent 5 | import android.os.Bundle 6 | import android.support.v7.app.AppCompatActivity 7 | import android.view.MenuItem 8 | import android.view.View 9 | import android.widget.EditText 10 | import cn.iamywang.mapchats.R 11 | import cn.iamywang.mapchats.util.network.JavaHttpKolley 12 | import com.ohmerhe.kolley.request.Http 13 | 14 | 15 | class LoginActivity : AppCompatActivity() { 16 | 17 | override fun onCreate(savedInstanceState: Bundle?) { 18 | super.onCreate(savedInstanceState) 19 | setContentView(R.layout.activity_login) 20 | val actionBar = supportActionBar 21 | if (actionBar != null) { 22 | actionBar.setHomeButtonEnabled(true) 23 | actionBar.setDisplayHomeAsUpEnabled(true) 24 | } 25 | val permissions = arrayOf( 26 | Manifest.permission.ACCESS_COARSE_LOCATION, 27 | Manifest.permission.ACCESS_FINE_LOCATION, 28 | Manifest.permission.ACCESS_NETWORK_STATE, 29 | Manifest.permission.ACCESS_WIFI_STATE, 30 | Manifest.permission.CHANGE_WIFI_STATE, 31 | Manifest.permission.INTERNET, 32 | Manifest.permission.READ_PHONE_STATE, 33 | Manifest.permission.WRITE_EXTERNAL_STORAGE, 34 | Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS, 35 | Manifest.permission.BLUETOOTH, 36 | Manifest.permission.BLUETOOTH_ADMIN 37 | ) 38 | requestPermissions(permissions, 1233) 39 | } 40 | 41 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 42 | if (item.getItemId() == android.R.id.home) { 43 | this.finish() 44 | return true 45 | } 46 | return super.onOptionsItemSelected(item) 47 | } 48 | 49 | fun onButtonClick(view: View) { 50 | val user: EditText = findViewById(R.id.editText) 51 | val pswd: EditText = findViewById(R.id.editText2) 52 | Http.init(this) 53 | val jhk = JavaHttpKolley() 54 | jhk.loginApp(user.text.toString(), pswd.text.toString(),this) 55 | } 56 | 57 | fun onButtonClick1(view: View) { 58 | startActivityForResult(Intent(this, RegisterActivity::class.java),208) 59 | } 60 | public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 61 | super.onActivityResult(requestCode, resultCode, data) 62 | // 在申请码和返回码都符合的时候,接收返回的数据 63 | if (requestCode == 208 && resultCode == 209) { 64 | val id = data!!.getStringExtra("id").toString() 65 | val passwd = data.getStringExtra("passwd").toString() 66 | val id_view = findViewById(R.id.editText) 67 | val passwd_view = findViewById(R.id.editText2) 68 | id_view.setText(id) 69 | passwd_view.setText(passwd) 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/activity/user/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.activity.user 2 | 3 | import android.content.Intent 4 | import android.os.Bundle 5 | import android.support.constraint.ConstraintLayout 6 | import android.support.design.widget.NavigationView 7 | import android.support.v4.view.GravityCompat 8 | import android.support.v4.widget.DrawerLayout 9 | import android.support.v7.app.ActionBarDrawerToggle 10 | import android.support.v7.app.AppCompatActivity 11 | import android.support.v7.widget.Toolbar 12 | import android.view.KeyEvent 13 | import android.view.MenuItem 14 | import android.view.View 15 | import android.widget.* 16 | 17 | import cn.iamywang.mapchats.R 18 | import cn.iamywang.mapchats.activity.friend.ChatRoomActivity 19 | import cn.iamywang.mapchats.activity.friend.ExploreActivity 20 | import cn.iamywang.mapchats.activity.friend.FriendsListActivity 21 | import cn.iamywang.mapchats.activity.friend.LocationShareActivity 22 | import cn.iamywang.mapchats.activity.misc.AboutActivity 23 | import cn.iamywang.mapchats.activity.misc.FeedBackActivity 24 | import cn.iamywang.mapchats.activity.path.HistoryPathListActivity 25 | import cn.iamywang.mapchats.activity.path.PathRecordActivity 26 | import cn.iamywang.mapchats.util.network.JavaHttpKolley 27 | import cn.iamywang.mapchats.util.list.UserItemAdapter 28 | import cn.iamywang.mapchats.util.list.UserListItem 29 | import java.util.* 30 | 31 | 32 | 33 | class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener, 34 | AdapterView.OnItemClickListener { 35 | private var USERID = "" 36 | private var exitTime = System.currentTimeMillis() 37 | val list = LinkedList() 38 | val mAdapter = UserItemAdapter(list, this) 39 | 40 | override fun onCreate(savedInstanceState: Bundle?) { 41 | super.onCreate(savedInstanceState) 42 | setContentView(R.layout.activity_main) 43 | val toolbar = findViewById(R.id.toolbar) 44 | setSupportActionBar(toolbar) 45 | val drawer = findViewById(R.id.drawer_layout) 46 | val navigationView = findViewById(R.id.nav_view) 47 | val toggle = ActionBarDrawerToggle( 48 | this, drawer, toolbar, 49 | R.string.app_name, 50 | R.string.app_name 51 | ) 52 | drawer.addDrawerListener(toggle) 53 | toggle.syncState() 54 | navigationView.setNavigationItemSelectedListener(this) 55 | this.startActivityForResult(Intent(this, LoginActivity::class.java), 109) 56 | val v = findViewById(R.id.user_item_view) 57 | v.visibility = View.INVISIBLE 58 | } 59 | 60 | fun setAdapter() { 61 | val list_view = findViewById(R.id.friends_list) 62 | list_view.adapter = mAdapter 63 | list_view.setOnItemClickListener(this) 64 | } 65 | 66 | public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 67 | super.onActivityResult(requestCode, resultCode, data) 68 | // 在申请码和返回码都符合的时候,接收返回的数据 69 | if (requestCode == 109 && resultCode == 110) { 70 | val id = findViewById(R.id.textView_id) 71 | val nick = findViewById(R.id.textView_name) 72 | val head_img = findViewById(R.id.nav_head_image) 73 | if (data != null) { 74 | this.USERID = data.getStringExtra("id") 75 | id.text = this.USERID 76 | nick.text = data.getStringExtra("name") 77 | if (this.USERID == "1") { 78 | head_img.setImageResource(R.drawable.ic_user_admin) 79 | } else if (data.getStringExtra("sex") == "男") { 80 | head_img.setImageResource(R.drawable.ic_user_color) 81 | } else if (data.getStringExtra("sex") == "女") { 82 | head_img.setImageResource(R.drawable.ic_user_color_2) 83 | } 84 | } 85 | 86 | val thread_this = this 87 | val thread = Thread(object : Runnable { 88 | override fun run() { 89 | val jhk = JavaHttpKolley() 90 | while (true) { 91 | jhk.getFakeUserMsgList(thread_this.USERID, thread_this) 92 | Thread.sleep(3000) 93 | } 94 | } 95 | }) 96 | thread.start() 97 | } 98 | } 99 | 100 | override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { 101 | val intent = Intent(this, ChatRoomActivity::class.java) 102 | intent.putExtra("local_id", this.USERID) 103 | intent.putExtra("remote_id", list.get(position).user_id) 104 | intent.putExtra("remote_name", list.get(position).user_name) 105 | startActivity(intent) 106 | } 107 | 108 | override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean { 109 | if (keyCode == KeyEvent.KEYCODE_BACK) { 110 | exit() 111 | return false 112 | } 113 | return super.onKeyDown(keyCode, event) 114 | } 115 | 116 | fun exit() { 117 | if (System.currentTimeMillis() - exitTime > 2000) { 118 | Toast.makeText( 119 | applicationContext, "再按一次退出程序", 120 | Toast.LENGTH_SHORT 121 | ).show() 122 | exitTime = System.currentTimeMillis() 123 | } else { 124 | val jhk = JavaHttpKolley() 125 | jhk.setOffline(this.USERID, this) 126 | finish() 127 | } 128 | } 129 | 130 | override fun onNavigationItemSelected(item: MenuItem): Boolean { 131 | // Handle navigation view item clicks here. 132 | val id = item.itemId 133 | if (id == R.id.nav_map) { 134 | val intent = Intent(this, LocationShareActivity::class.java) 135 | intent.putExtra("id", this.USERID) 136 | startActivity(intent) 137 | } else if (id == R.id.nav_gps) { 138 | val intent = Intent(this, HistoryPathListActivity::class.java) 139 | intent.putExtra("id", this.USERID) 140 | startActivity(intent) 141 | } else if (id == R.id.nav_record) { 142 | val intent = Intent(this, PathRecordActivity::class.java) 143 | intent.putExtra("id", this.USERID) 144 | intent.putExtra("nick", findViewById(R.id.textView_name).text) 145 | startActivity(intent) 146 | } else if (id == R.id.nav_friends) { 147 | val intent = Intent(this, FriendsListActivity::class.java) 148 | intent.putExtra("id", this.USERID) 149 | startActivity(intent) 150 | } else if (id == R.id.nav_chat) { 151 | val intent = Intent(this, ChatRoomActivity::class.java) 152 | intent.putExtra("local_id", this.USERID) 153 | intent.putExtra("remote_id", "0") 154 | intent.putExtra("remote_name", "聊天室") 155 | startActivity(intent) 156 | } else if (id == R.id.nav_explore) { 157 | val intent = Intent(this, ExploreActivity::class.java) 158 | startActivity(intent) 159 | }else if (id == R.id.nav_feed) { 160 | val intent = Intent(this, FeedBackActivity::class.java) 161 | intent.putExtra("id", this.USERID) 162 | intent.putExtra("nick", findViewById(R.id.textView_name).text) 163 | startActivity(intent) 164 | } else if (id == R.id.nav_share) { 165 | val share_intent = Intent(Intent.ACTION_SEND) 166 | share_intent.type = "text/plain" 167 | share_intent.putExtra(Intent.EXTRA_TEXT, "分享内容") 168 | startActivity(share_intent) 169 | } else if (id == R.id.nav_about) { 170 | val intent = Intent(this, AboutActivity::class.java) 171 | startActivity(intent) 172 | } 173 | val drawer = findViewById(R.id.drawer_layout) 174 | drawer.closeDrawer(GravityCompat.START) 175 | return true 176 | } 177 | 178 | fun startUserInfo(view: View) { 179 | val intent = Intent(this, UserInfoActivity::class.java) 180 | intent.putExtra("id", this.USERID) 181 | intent.putExtra("loc", "中国山东省济南市") 182 | startActivity(intent) 183 | } 184 | } -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/activity/user/RegisterActivity.kt: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.activity.user 2 | 3 | import android.icu.util.Calendar 4 | import android.support.v7.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.view.MenuItem 7 | import android.view.View 8 | import android.widget.EditText 9 | import android.widget.TextView 10 | import cn.iamywang.mapchats.R 11 | import cn.iamywang.mapchats.util.network.JavaHttpKolley 12 | import com.ohmerhe.kolley.request.Http 13 | import kotlin.random.Random 14 | 15 | class RegisterActivity : AppCompatActivity() { 16 | 17 | override fun onCreate(savedInstanceState: Bundle?) { 18 | super.onCreate(savedInstanceState) 19 | setContentView(R.layout.activity_register) 20 | val actionBar = supportActionBar 21 | if (actionBar != null) { 22 | actionBar.setHomeButtonEnabled(true) 23 | actionBar.setDisplayHomeAsUpEnabled(true) 24 | } 25 | val id: TextView = findViewById(R.id.register_e1) 26 | val regdate: TextView = findViewById(R.id.register_e8) 27 | val calendar = Calendar.getInstance() 28 | val year = calendar.get(Calendar.YEAR) 29 | val month = calendar.get(Calendar.MONTH) + 1 30 | val day = calendar.get(Calendar.DAY_OF_MONTH) 31 | val hour = calendar.get(Calendar.HOUR_OF_DAY) 32 | val minute = calendar.get(Calendar.MINUTE) 33 | val second = calendar.get(Calendar.SECOND) 34 | val hou = String.format("%0" + 2 + "d", hour) 35 | val min = String.format("%0" + 2 + "d", minute) 36 | val sec = String.format("%0" + 2 + "d", second) 37 | val rand = Random(hour * minute * sec.toInt()) 38 | val str = StringBuffer("") 39 | str.append(year).append(".").append(month).append(".").append(day).append(" ").append(hou).append(":") 40 | .append(min).append(":").append(sec) 41 | id.setText(rand.nextInt(100000).toString()) 42 | regdate.setText(str.toString()) 43 | } 44 | 45 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 46 | if (item.getItemId() == android.R.id.home) { 47 | this.finish() 48 | return true 49 | } 50 | return super.onOptionsItemSelected(item) 51 | } 52 | 53 | fun Submit(view: View) { 54 | val id: TextView = findViewById(R.id.register_e1) 55 | val nick: EditText = findViewById(R.id.register_e2) 56 | val passwd: EditText = findViewById(R.id.register_e10) 57 | val sex: EditText = findViewById(R.id.register_e3) 58 | val birth: EditText = findViewById(R.id.register_e4) 59 | val height: EditText = findViewById(R.id.register_e5) 60 | val weight: EditText = findViewById(R.id.register_e6) 61 | val regdate: TextView = findViewById(R.id.register_e8) 62 | Http.init(this) 63 | val jhk = JavaHttpKolley() 64 | jhk.registerUser( 65 | id.text.toString(), 66 | nick.text.toString(), 67 | passwd.text.toString(), 68 | sex.text.toString(), 69 | birth.text.toString(), 70 | height.text.toString(), 71 | weight.text.toString(), 72 | regdate.text.toString(), 73 | this 74 | ) 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/activity/user/UserInfoActivity.kt: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.activity.user 2 | 3 | import android.support.v7.app.AppCompatActivity 4 | import android.os.Bundle 5 | import android.view.MenuItem 6 | import android.view.View 7 | import android.widget.EditText 8 | import android.widget.ImageView 9 | import android.widget.TextView 10 | import android.widget.Toast 11 | import cn.iamywang.mapchats.R 12 | import com.alibaba.fastjson.JSON 13 | import com.ohmerhe.kolley.request.Http 14 | import java.nio.charset.Charset 15 | 16 | class UserInfoActivity : AppCompatActivity() { 17 | 18 | val root = "http://39.105.44.114:58000" 19 | 20 | override fun onCreate(savedInstanceState: Bundle?) { 21 | super.onCreate(savedInstanceState) 22 | setContentView(R.layout.activity_user_info) 23 | val actionBar = supportActionBar 24 | if (actionBar != null) { 25 | actionBar.setHomeButtonEnabled(true) 26 | actionBar.setDisplayHomeAsUpEnabled(true) 27 | } 28 | val info_intent = intent 29 | val info_id = info_intent.getStringExtra("id").toString() 30 | val info_loc = info_intent.getStringExtra("loc").toString() 31 | val id: TextView = findViewById(R.id.user_e1) 32 | val loc: TextView = findViewById(R.id.user_e9) 33 | id.setText(info_id) 34 | loc.setText(info_loc) 35 | getInfo(info_id) 36 | } 37 | 38 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 39 | if (item.getItemId() == android.R.id.home) { 40 | this.finish() 41 | return true 42 | } 43 | return super.onOptionsItemSelected(item) 44 | } 45 | 46 | fun getInfo(info_id: String) { 47 | Http.init(this) 48 | Http.post { 49 | url = root + "/getUserInfo/" 50 | params { 51 | "id" - info_id 52 | } 53 | onSuccess { bytes -> 54 | val str = bytes.toString(Charset.defaultCharset()) 55 | val list = JSON.parseObject(str) 56 | val head_name: TextView = findViewById(R.id.user_t_name) 57 | val head_img: ImageView = findViewById(R.id.user_head) 58 | val nick: EditText = findViewById(R.id.user_e2) 59 | val sex: EditText = findViewById(R.id.user_e3) 60 | val birth: EditText = findViewById(R.id.user_e4) 61 | val height: EditText = findViewById(R.id.user_e5) 62 | val weight: EditText = findViewById(R.id.user_e6) 63 | val regdate: TextView = findViewById(R.id.user_e7) 64 | val logdate: TextView = findViewById(R.id.user_e8) 65 | head_name.setText(list["name"].toString()) 66 | nick.setText(list["name"].toString()) 67 | sex.setText(list["sex"].toString()) 68 | if (info_id == "1") { 69 | head_img.setImageResource(R.drawable.ic_user_admin) 70 | } else if (list["sex"].toString() == "男") { 71 | head_img.setImageResource(R.drawable.ic_user_color) 72 | } else if (list["sex"].toString() == "女") { 73 | head_img.setImageResource(R.drawable.ic_user_color_2) 74 | } 75 | birth.setText(list["birth"].toString()) 76 | height.setText(list["height"].toString()) 77 | weight.setText(list["weight"].toString()) 78 | regdate.setText(list["reg"].toString()) 79 | logdate.setText(list["login"].toString()) 80 | } 81 | } 82 | } 83 | 84 | fun Submit(view: View) { 85 | Http.init(this) 86 | val act = this 87 | val id: TextView = findViewById(R.id.user_e1) 88 | val nick: EditText = findViewById(R.id.user_e2) 89 | val sex: EditText = findViewById(R.id.user_e3) 90 | val birth: EditText = findViewById(R.id.user_e4) 91 | val height: EditText = findViewById(R.id.user_e5) 92 | val weight: EditText = findViewById(R.id.user_e6) 93 | val regdate: TextView = findViewById(R.id.user_e7) 94 | val logdate: TextView = findViewById(R.id.user_e8) 95 | Http.post { 96 | url = root + "/updateUser/" 97 | params { 98 | "id" - id.text.toString() 99 | "name" - nick.text.toString() 100 | "sex" - sex.text.toString() 101 | "birth" - birth.text.toString() 102 | "height" - height.text.toString() 103 | "weight" - weight.text.toString() 104 | "reg" - regdate.text.toString() 105 | "login" - logdate.text.toString() 106 | } 107 | onSuccess { bytes -> 108 | // handle data 109 | Toast.makeText(act, bytes.toString(Charset.defaultCharset()), Toast.LENGTH_LONG).show() 110 | getInfo(id.text.toString()) 111 | } 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/util/list/HistoryPathItem.kt: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.util.list 2 | 3 | class HistoryPathItem constructor(user_id: String, path_id: String, start_time: String, start_loc: String) { 4 | var user_id: String = "" 5 | var path_id: String = "" 6 | var start_time: String = "" 7 | var start_loc: String = "" 8 | 9 | init { 10 | this.user_id = user_id 11 | this.path_id = path_id 12 | this.start_time = start_time 13 | this.start_loc = start_loc 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/util/list/HistoryPathItemAdapter.java: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.util.list; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.BaseAdapter; 9 | import android.widget.TextView; 10 | import cn.iamywang.mapchats.R; 11 | import cn.iamywang.mapchats.util.list.HistoryPathItem; 12 | 13 | import java.util.LinkedList; 14 | 15 | public class HistoryPathItemAdapter extends BaseAdapter { 16 | private LinkedList mData; 17 | private Context mContext; 18 | 19 | public HistoryPathItemAdapter(LinkedList mData, Context mContext) { 20 | this.mData = mData; 21 | this.mContext = mContext; 22 | } 23 | 24 | @Override 25 | public int getCount() { 26 | return mData.size(); 27 | } 28 | 29 | @Override 30 | public Object getItem(int position) { 31 | return null; 32 | } 33 | 34 | @Override 35 | public long getItemId(int position) { 36 | return position; 37 | } 38 | 39 | @SuppressLint("ViewHolder") 40 | @Override 41 | public View getView(int position, View convertView, ViewGroup parent) { 42 | convertView = LayoutInflater.from(mContext).inflate(R.layout.item_path_list, parent, false); 43 | TextView path_item_time = (TextView) convertView.findViewById(R.id.path_item_time); 44 | TextView path_item_tag = (TextView) convertView.findViewById(R.id.path_item_tag); 45 | TextView path_item_loc = (TextView) convertView.findViewById(R.id.path_item_loc); 46 | path_item_time.setText(mData.get(position).getStart_time()); 47 | path_item_tag.setText(mData.get(position).getPath_id()); 48 | path_item_loc.setText(mData.get(position).getStart_loc()); 49 | return convertView; 50 | } 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/util/list/MessageListItem.kt: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.util.list 2 | 3 | class MessageListItem constructor(id: String, name: String, sex: String, msg: String, time: String, read: String) { 4 | var message_id: String = "" 5 | var message_name: String = "" 6 | var message_sex: String = "" 7 | var message_msg: String = "" 8 | var message_time: String = "" 9 | var message_read: String = "" 10 | 11 | init { 12 | this.message_id = id 13 | this.message_name = name 14 | this.message_sex = sex 15 | this.message_msg = msg 16 | this.message_time = time 17 | this.message_read = read 18 | } 19 | } -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/util/list/MessageListItemAdapter.java: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.util.list; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.graphics.Color; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.BaseAdapter; 10 | import android.widget.ImageView; 11 | import android.widget.TextView; 12 | import cn.iamywang.mapchats.R; 13 | 14 | import java.util.LinkedList; 15 | 16 | public class MessageListItemAdapter extends BaseAdapter { 17 | private LinkedList mData; 18 | private Context mContext; 19 | 20 | public MessageListItemAdapter(LinkedList mData, Context mContext) { 21 | this.mData = mData; 22 | this.mContext = mContext; 23 | } 24 | 25 | @Override 26 | public int getCount() { 27 | return mData.size(); 28 | } 29 | 30 | @Override 31 | public Object getItem(int position) { 32 | return null; 33 | } 34 | 35 | @Override 36 | public long getItemId(int position) { 37 | return position; 38 | } 39 | 40 | @SuppressLint("ViewHolder") 41 | @Override 42 | public View getView(int position, View convertView, ViewGroup parent) { 43 | convertView = LayoutInflater.from(mContext).inflate(R.layout.item_msg_list, parent, false); 44 | ImageView head_image = (ImageView) convertView.findViewById(R.id.msg_item_sex); 45 | TextView msg_item_name = (TextView) convertView.findViewById(R.id.msg_item_name); 46 | TextView msg_item_msg = (TextView) convertView.findViewById(R.id.msg_item_msg); 47 | TextView msg_item_time = (TextView) convertView.findViewById(R.id.msg_item_time); 48 | TextView msg_item_read = (TextView) convertView.findViewById(R.id.msg_item_read); 49 | 50 | msg_item_name.setText(mData.get(position).getMessage_name()); 51 | msg_item_msg.setText(mData.get(position).getMessage_msg()); 52 | msg_item_time.setText(mData.get(position).getMessage_time()); 53 | if (mData.get(position).getMessage_id().equals("1")) { 54 | head_image.setImageResource(R.drawable.ic_user_admin); 55 | } else if (mData.get(position).getMessage_sex().equals("男")) { 56 | head_image.setImageResource(R.drawable.ic_user_color); 57 | } else { 58 | head_image.setImageResource(R.drawable.ic_user_color_2); 59 | } 60 | if (mData.get(position).getMessage_read().equals("yes")) { 61 | msg_item_read.setText("已读"); 62 | } else if (mData.get(position).getMessage_read().equals("no")) { 63 | msg_item_read.setText("未读"); 64 | msg_item_read.setTextColor(Color.RED); 65 | } 66 | return convertView; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/util/list/UserItemAdapter.java: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.util.list; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.BaseAdapter; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | import cn.iamywang.mapchats.R; 12 | 13 | import java.util.LinkedList; 14 | 15 | public class UserItemAdapter extends BaseAdapter { 16 | private LinkedList mData; 17 | private Context mContext; 18 | 19 | public UserItemAdapter(LinkedList mData, Context mContext) { 20 | this.mData = mData; 21 | this.mContext = mContext; 22 | } 23 | 24 | @Override 25 | public int getCount() { 26 | return mData.size(); 27 | } 28 | 29 | @Override 30 | public Object getItem(int position) { 31 | return null; 32 | } 33 | 34 | @Override 35 | public long getItemId(int position) { 36 | return position; 37 | } 38 | 39 | @SuppressLint("ViewHolder") 40 | @Override 41 | public View getView(int position, View convertView, ViewGroup parent) { 42 | convertView = LayoutInflater.from(mContext).inflate(R.layout.item_user_list, parent, false); 43 | ImageView head_image = (ImageView) convertView.findViewById(R.id.user_item_sex); 44 | TextView user_item_name = (TextView) convertView.findViewById(R.id.user_item_name); 45 | TextView user_item_msg = (TextView) convertView.findViewById(R.id.user_item_msg); 46 | TextView user_item_time = (TextView) convertView.findViewById(R.id.user_item_time); 47 | TextView user_item_num = (TextView) convertView.findViewById(R.id.user_item_num); 48 | 49 | String name_and_id = mData.get(position).getUser_name() + "(ID:" + mData.get(position).getUser_id() + ")"; 50 | user_item_name.setText(name_and_id); 51 | user_item_msg.setText(mData.get(position).getUser_msg()); 52 | user_item_time.setText(mData.get(position).getUser_time()); 53 | if (mData.get(position).getUser_id().equals("1")) { 54 | head_image.setImageResource(R.drawable.ic_user_admin); 55 | } else if (mData.get(position).getUser_sex().equals("男")) { 56 | head_image.setImageResource(R.drawable.ic_user_color); 57 | } else if (mData.get(position).getUser_sex().equals("女")) { 58 | head_image.setImageResource(R.drawable.ic_user_color_2); 59 | } else if (mData.get(position).getUser_sex().equals("room")) { 60 | head_image.setImageResource(R.drawable.ic_user_color_3); 61 | } 62 | if (Integer.parseInt(mData.get(position).getUser_num()) == 0) { 63 | user_item_num.setVisibility(View.INVISIBLE); 64 | } else { 65 | user_item_num.setText(mData.get(position).getUser_num()); 66 | } 67 | return convertView; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/util/list/UserListItem.kt: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.util.list 2 | 3 | class UserListItem constructor(id: String, name: String, sex: String, msg: String, time: String, num: String) { 4 | var user_id: String = "" 5 | var user_name: String = "" 6 | var user_sex: String = "" 7 | var user_msg: String = "" 8 | var user_time: String = "" 9 | var user_num: String = "" 10 | 11 | init { 12 | this.user_id = id 13 | this.user_name = name 14 | this.user_sex = sex 15 | this.user_msg = msg 16 | this.user_time = time 17 | this.user_num = num 18 | } 19 | } -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/util/misc/SensorEventHelper.java: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.util.misc; 2 | 3 | import android.content.Context; 4 | import android.hardware.Sensor; 5 | import android.hardware.SensorEvent; 6 | import android.hardware.SensorEventListener; 7 | import android.hardware.SensorManager; 8 | import android.view.Display; 9 | import android.view.Surface; 10 | import android.view.WindowManager; 11 | 12 | import com.amap.api.maps.model.Marker; 13 | 14 | public class SensorEventHelper implements SensorEventListener { 15 | 16 | private SensorManager mSensorManager; 17 | private Sensor mSensor; 18 | private long lastTime = 0; 19 | private final int TIME_SENSOR = 100; 20 | private float mAngle; 21 | private Context mContext; 22 | private Marker mMarker; 23 | 24 | public SensorEventHelper(Context context) { 25 | mContext = context; 26 | mSensorManager = (SensorManager) context 27 | .getSystemService(Context.SENSOR_SERVICE); 28 | mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); 29 | 30 | } 31 | 32 | public void registerSensorListener() { 33 | mSensorManager.registerListener(this, mSensor, 34 | SensorManager.SENSOR_DELAY_NORMAL); 35 | } 36 | 37 | public void unRegisterSensorListener() { 38 | mSensorManager.unregisterListener(this, mSensor); 39 | } 40 | 41 | public void setCurrentMarker(Marker marker) { 42 | mMarker = marker; 43 | } 44 | 45 | @Override 46 | public void onAccuracyChanged(Sensor sensor, int accuracy) { 47 | // TODO Auto-generated method stub 48 | 49 | } 50 | 51 | @Override 52 | public void onSensorChanged(SensorEvent event) { 53 | if (System.currentTimeMillis() - lastTime < TIME_SENSOR) { 54 | return; 55 | } 56 | switch (event.sensor.getType()) { 57 | case Sensor.TYPE_ORIENTATION: { 58 | float x = event.values[0]; 59 | x += getScreenRotationOnPhone(mContext); 60 | x %= 360.0F; 61 | if (x > 180.0F) 62 | x -= 360.0F; 63 | else if (x < -180.0F) 64 | x += 360.0F; 65 | 66 | if (Math.abs(mAngle - x) < 3.0f) { 67 | break; 68 | } 69 | mAngle = Float.isNaN(x) ? 0 : x; 70 | if (mMarker != null) { 71 | mMarker.setRotateAngle(360 - mAngle); 72 | } 73 | lastTime = System.currentTimeMillis(); 74 | } 75 | } 76 | 77 | } 78 | 79 | /** 80 | * 获取当前屏幕旋转角度 81 | * 82 | * @param context 83 | * @return 0表示是竖屏; 90表示是左横屏; 180表示是反向竖屏; 270表示是右横屏 84 | */ 85 | public static int getScreenRotationOnPhone(Context context) { 86 | final Display display = ((WindowManager) context 87 | .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); 88 | 89 | switch (display.getRotation()) { 90 | case Surface.ROTATION_0: 91 | return 0; 92 | 93 | case Surface.ROTATION_90: 94 | return 90; 95 | 96 | case Surface.ROTATION_180: 97 | return 180; 98 | 99 | case Surface.ROTATION_270: 100 | return -90; 101 | } 102 | return 0; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /app/src/main/java/cn/iamywang/mapchats/util/misc/UIHandler.kt: -------------------------------------------------------------------------------- 1 | package cn.iamywang.mapchats.util.misc 2 | 3 | import android.os.Handler 4 | import java.lang.ref.WeakReference 5 | 6 | open class UIHandler(cls: T) : Handler() { 7 | 8 | protected var ref: WeakReference? = null 9 | 10 | init { 11 | ref = WeakReference(cls) 12 | } 13 | 14 | fun getRef(): T? { 15 | return if (ref != null) ref!!.get() else null 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_user_admin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamywang/Dating-Android/d6f91baf2f7ccb7100925857dc952a9e199e3e11/app/src/main/res/drawable-v24/ic_user_admin.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/bubble.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamywang/Dating-Android/d6f91baf2f7ccb7100925857dc952a9e199e3e11/app/src/main/res/drawable/bubble.9.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_about.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_chat.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_feedback.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_friend.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_history.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_login.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_map.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_path.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_path_run.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_send.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_share.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_user.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_user_color.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_user_color_2.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_user_color_3.xml: -------------------------------------------------------------------------------- 1 | 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 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/side_nav_bar.xml: -------------------------------------------------------------------------------- 1 | 3 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_about.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 15 | 24 | 33 | 40 |