Skip to content

Commit

Permalink
0.1版本
Browse files Browse the repository at this point in the history
添加了基础的个人信息配置以及基本参数配置,尚未实现运动轨迹本地存储
  • Loading branch information
robinfoxnan committed Dec 11, 2023
1 parent d4691aa commit 5a986f1
Show file tree
Hide file tree
Showing 31 changed files with 1,705 additions and 79 deletions.
17 changes: 0 additions & 17 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

41 changes: 28 additions & 13 deletions app/src/main/java/com/bird2fish/travelbook/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
package com.bird2fish.travelbook

import android.Manifest
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.content.pm.PackageManager
import android.os.Bundle
import android.os.IBinder
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.Window
import android.widget.ImageView
import android.widget.TextView
import androidx.activity.result.contract.ActivityResultContracts
import com.google.android.material.navigation.NavigationView
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
Expand All @@ -23,16 +17,11 @@ import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import androidx.drawerlayout.widget.DrawerLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.view.GravityCompat
import androidx.core.view.get
import androidx.fragment.app.FragmentActivity
import com.bird2fish.travelbook.R
import com.bird2fish.travelbook.core.HttpService
import com.bird2fish.travelbook.core.UiHelper
import com.bird2fish.travelbook.databinding.ActivityMainBinding
import com.bird2fish.travelbook.helper.LogHelper
import com.bird2fish.travelbook.helper.PreferencesHelper
import com.bird2fish.travelbook.ui.data.model.CurrentUser

class MainActivity : AppCompatActivity() {
Expand All @@ -50,6 +39,7 @@ class MainActivity : AppCompatActivity() {
}

public fun openDrawer(){

binding.drawerLayout.openDrawer(GravityCompat.START);
}

Expand Down Expand Up @@ -94,7 +84,7 @@ class MainActivity : AppCompatActivity() {
//R.id.nav_newgroup,
R.id.nav_home, R.id.nav_playground, R.id.nav_favourite,
R.id.nav_map, R.id.nav_track,
R.id.nav_contract, R.id.nav_setting
R.id.nav_me, R.id.nav_contract, R.id.settingFragment
), drawerLayout
)
setupActionBarWithNavController(navController, appBarConfiguration)
Expand All @@ -118,6 +108,31 @@ class MainActivity : AppCompatActivity() {
// window.statusBarColor = resources.getColor(R.color.toolbar_gray)
// }


drawerLayout.addDrawerListener(object : DrawerLayout.DrawerListener {
override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
// 当侧边栏滑动时调用
}

override fun onDrawerOpened(drawerView: View) {
// 当侧边栏打开时调用
// 这里可以处理在侧边栏打开时需要执行的逻辑
val user = CurrentUser.getUser()
if (user != null){
setUserInfo()
}
}

override fun onDrawerClosed(drawerView: View) {
// 当侧边栏关闭时调用
// 这里可以处理在侧边栏关闭时需要执行的逻辑
}

override fun onDrawerStateChanged(newState: Int) {
// 当侧边栏状态发生变化时调用
}
})

}

private fun setUserInfo(){
Expand All @@ -126,7 +141,7 @@ class MainActivity : AppCompatActivity() {
var navigationView = this.findViewById<NavigationView>(R.id.nav_view);
// 侧边栏的头部栏的信息设置
var headerLayout = navigationView.getHeaderView(0);
var userNameview = headerLayout.findViewById<TextView>(R.id.textNick);
var userNameview = headerLayout.findViewById<TextView>(R.id.tvName);
var userInfoview = headerLayout.findViewById<TextView>(R.id.textInfo);
var userIcon = headerLayout.findViewById<ImageView>(R.id.imageViewIcon)

Expand Down
95 changes: 95 additions & 0 deletions app/src/main/java/com/bird2fish/travelbook/ServerSettingView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.bird2fish.travelbook

import android.content.Context
import android.content.res.Resources
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.Gravity
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.Button
import android.widget.PopupWindow
import android.widget.ScrollView
import android.widget.TextView
import com.bird2fish.travelbook.helper.PreferencesHelper

class ServerSettingView(context: Context) {

private var popupWindow: PopupWindow

init {
// 填充布局 R.layout.pop_location
val popupView = LayoutInflater.from(context).inflate(R.layout.setting_server, null)

// 创建 PopupWindow 实例
popupWindow = PopupWindow(
popupView,
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
true
)

// 设置 PopupWindow 的背景
popupWindow.setBackgroundDrawable(ColorDrawable(Color.WHITE))

// 设置 PopupWindow 的位置(在底部)
popupWindow.showAtLocation(popupView, Gravity.BOTTOM, 0, 0)

// 设置 PopupWindow 进入和退出的动画效果(可选)
popupWindow.animationStyle = R.style.PopupWindowAnimation

// 设置点击外部不关闭PopupWindow
popupWindow.isOutsideTouchable = false
// 设置背景为null,防止点击外部传递到下面的View
popupWindow.setBackgroundDrawable(null)

// 添加监听器,处理关闭事件
popupWindow.setOnDismissListener {
// 在这里添加处理 PopupWindow 关闭时的逻辑
}

// 如果需要处理点击事件等,可以在这里找到对应的 View 并设置相应的监听器
val schemaEdit = popupView.findViewById<TextView>(R.id.tv_shema)
val schema = PreferencesHelper.getHostSchema()
schemaEdit.setText(schema)


val hostEdit = popupView.findViewById<TextView>(R.id.tv_ip)
val host = PreferencesHelper.getHostName()
hostEdit.setText(host)

val saveBtn = popupView.findViewById<Button>(R.id.btn_server_ok)
val cancelBtn = popupView.findViewById<Button>(R.id.btn_server_cancel)

saveBtn.setOnClickListener{
val schema = schemaEdit.text.toString()
val host = hostEdit.text.toString()
PreferencesHelper.setHost(schema, host)
}

cancelBtn.setOnClickListener{
this.dismissPopupWindow()
}


}

// 如果需要在外部调用显示 PopupWindow 的方法,可以添加一个公共方法
fun showPopupWindow() {
if (!popupWindow.isShowing) {
popupWindow.showAtLocation(
popupWindow.contentView,
Gravity.BOTTOM,
0,
0
)
}
}

// 添加关闭 PopupWindow 的方法
fun dismissPopupWindow() {
if (popupWindow.isShowing) {
popupWindow.dismiss()
}
}
}
28 changes: 28 additions & 0 deletions app/src/main/java/com/bird2fish/travelbook/TencentMapActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class TencentMapActivity : AppCompatActivity() {
//private lateinit var layout: MapFragmentLayoutHolder
//private var trackerService: TrackerService? = null
private lateinit var mMarker:com.tencent.tencentmap.mapsdk.maps.model.Marker // 自己的位置
private lateinit var mImageView:ImageView
private var markersMap = mutableMapOf<String, com.tencent.tencentmap.mapsdk.maps.model.Marker>()
private var iconsMap = mutableMapOf<String, ImageView>()

Expand Down Expand Up @@ -128,6 +129,7 @@ class TencentMapActivity : AppCompatActivity() {
onImageIconClick(me)
}
linearLayout.addView(imageView)
this.mImageView = imageView
}

// 对点击的marker设置为顶层
Expand Down Expand Up @@ -772,6 +774,29 @@ class TencentMapActivity : AppCompatActivity() {
}
}

// 如果个人信息部分编辑了头像,这里需要更改
private fun updateAvarta(){
val user = CurrentUser.getUser()
if (user!!.isChanged){
val bitmapIcon = UiHelper.getSmallIconBitmap(CurrentUser.getUser()!!.icon, this)
val custom = BitmapDescriptorFactory.fromBitmap(bitmapIcon)
this.mMarker.setIcon(custom)

// 获取底部列表
val linearLayout = this.findViewById<LinearLayout>(R.id.linear_layout_icons)
// 先检查是否有不需要显示的, 不再朋友列表中,通信簿设置后说明不需要显示了

if (this.mImageView != null){
val icon = CurrentUser.getUser()!!.icon
val id = UiHelper.getIconResId(icon)
this.mImageView.setImageResource(id)
}


user!!.isChanged = false
}
}

/**
* mapview的生命周期管理
*/
Expand All @@ -788,6 +813,9 @@ class TencentMapActivity : AppCompatActivity() {

// 在恢复时重新启动任务
startRefreshInfo()

// 查看头像是否更改
updateAvarta()
}

// 当一个 Activity 即将失去焦点并进入后台时,系统会调用 onPause() 方法。
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/bird2fish/travelbook/core/GlobalData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class GlobalData {
}catch (e: Exception){
GlobalData.sportMode = GlobalData.SportModeEnum.SPORT_MODE_HIKE
}
GlobalData.intervalOfRefresh = PreferencesHelper.getRefreshInterval()
if (GlobalData.intervalOfRefresh < 2000){
GlobalData.intervalOfRefresh = 2000
}else if (GlobalData.intervalOfRefresh > 60000){
GlobalData.intervalOfRefresh = 60000
}
}

fun setCurrentLocation(pos :TencentLocation){
Expand Down
Loading

0 comments on commit 5a986f1

Please sign in to comment.