初始化
This commit is contained in:
@@ -0,0 +1,179 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.ui
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Message
|
||||
import android.view.KeyEvent
|
||||
import android.widget.*
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.arpa.hndahesudintocctmsdriver.R
|
||||
import com.arpa.hndahesudintocctmsdriver.ui.home.HomeFragment
|
||||
import com.arpa.hndahesudintocctmsdriver.ui.login.LoginActivity
|
||||
import com.arpa.hndahesudintocctmsdriver.ui.my.MyFragment
|
||||
import com.arpa.hndahesudintocctmsdriver.ui.news.NewsFragment
|
||||
import com.arpa.hndahesudintocctmsdriver.ui.wallet.WalletFragment
|
||||
import com.arpa.hndahesudintocctmsdriver.util.http.RequsetCodeConstants
|
||||
import com.arpa.hndahesudintocctmsdriver.util.statusbar.StateStyleUtil
|
||||
import com.arpa.hndahesudintocctmsdriver.util.view.BaseAppCompatActivity
|
||||
import com.arpa.hndahesudintocctmsdriver.util.view.BottomTabUtil
|
||||
import com.arpa.hndahesudintocctmsdriver.util.view.PanDuanUtil
|
||||
import com.google.gson.Gson
|
||||
import com.luck.picture.lib.permissions.RxPermissions
|
||||
import io.reactivex.functions.Consumer
|
||||
|
||||
class MainActivity : BaseAppCompatActivity() {
|
||||
|
||||
private var ibs = arrayOf<ImageView>()
|
||||
private var title_view=arrayOf<TextView>()
|
||||
private var imgs0= intArrayOf(R.mipmap.tab1,R.mipmap.tab2,R.mipmap.xiaoxi0,R.mipmap.tab3)
|
||||
private var imgs1= intArrayOf(R.mipmap.tab1_s,R.mipmap.tab2_s,R.mipmap.xiaoxi1,R.mipmap.tab3_s)
|
||||
private val gson = Gson()
|
||||
|
||||
override fun msgMethod(m: Message?) {
|
||||
super.msgMethod(m)
|
||||
when(m!!.what){
|
||||
1->{
|
||||
isExit = false;
|
||||
}
|
||||
RequsetCodeConstants.SUCCESS->{ }
|
||||
}
|
||||
}
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
StateStyleUtil.stateTextColor(this)
|
||||
setContentView(R.layout.activity_main)
|
||||
con=this
|
||||
act=this
|
||||
//隐藏标题栏
|
||||
val actionBar = supportActionBar
|
||||
actionBar?.hide()
|
||||
var r1=findViewById<LinearLayout>(R.id.r1)
|
||||
var r2=findViewById<LinearLayout>(R.id.r2)
|
||||
var r3=findViewById<LinearLayout>(R.id.r3)
|
||||
var r4=findViewById<LinearLayout>(R.id.r4)
|
||||
var fs = arrayOfNulls<Fragment>(4)
|
||||
fs[0] = HomeFragment()
|
||||
fs[1] = WalletFragment()
|
||||
fs[2] = NewsFragment()
|
||||
fs[3] = MyFragment()
|
||||
ibs=arrayOf(
|
||||
findViewById(R.id.huoyuan),
|
||||
findViewById(R.id.qianbao),
|
||||
findViewById(R.id.xiaoxi),
|
||||
findViewById(R.id.wode))
|
||||
title_view=arrayOf(findViewById(R.id.title1),findViewById(R.id.title2),findViewById(R.id.title3),findViewById(R.id.title4))
|
||||
var bt = BottomTabUtil(this, R.id.body, fs)
|
||||
bt.selectItem(fs[0])
|
||||
r1.setOnClickListener { v ->
|
||||
selectImage(bt.index,0)
|
||||
bt.setDefaultFragment(fs[0])
|
||||
bt.index=0
|
||||
}
|
||||
r2.setOnClickListener { v ->
|
||||
if (!PanDuanUtil.isLogin(con)){
|
||||
jumpLogin()
|
||||
}else{
|
||||
selectImage(bt.index,1)
|
||||
if (!fs[1]!!.isAdded) {
|
||||
bt.hide(fs[bt.index])
|
||||
bt.selectItem(fs[1])
|
||||
} else {
|
||||
bt.setDefaultFragment(fs[1])
|
||||
}
|
||||
bt.index = 1
|
||||
}
|
||||
}
|
||||
r3.setOnClickListener { v ->
|
||||
if (!PanDuanUtil.isLogin(con)){
|
||||
jumpLogin()
|
||||
}else{
|
||||
selectImage(bt.index,2)
|
||||
if (!fs[2]!!.isAdded) {
|
||||
bt.hide(fs[bt.index])
|
||||
bt.selectItem(fs[2])
|
||||
} else {
|
||||
bt.setDefaultFragment(fs[2])
|
||||
}
|
||||
bt.index = 2
|
||||
}
|
||||
}
|
||||
r4.setOnClickListener { v ->
|
||||
if (!PanDuanUtil.isLogin(con)){
|
||||
jumpLogin()
|
||||
}else{
|
||||
selectImage(bt.index,3)
|
||||
if (!fs[3]!!.isAdded) {
|
||||
bt.hide(fs[bt.index])
|
||||
bt.selectItem(fs[3])
|
||||
} else {
|
||||
bt.setDefaultFragment(fs[3])
|
||||
}
|
||||
bt.index = 3
|
||||
}
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
|
||||
getPression()
|
||||
}
|
||||
}
|
||||
|
||||
fun getPression(){
|
||||
var gpsPermissions = RxPermissions(this)
|
||||
gpsPermissions.request(
|
||||
Manifest.permission.ACCESS_FINE_LOCATION,
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||
Manifest.permission.ACCESS_BACKGROUND_LOCATION
|
||||
).subscribe(
|
||||
Consumer { b: Boolean ->
|
||||
if (b) {
|
||||
//判断GPS模块是否开启
|
||||
|
||||
} else {
|
||||
Toast.makeText(con,"开启权限失败,请在应用设置-权限-定位-始终允许",Toast.LENGTH_SHORT).show()
|
||||
//.show("开启权限失败,请在应用设置-权限-定位-始终允许")
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun selectImage(old:Int, new:Int){
|
||||
ibs[old].setImageResource(imgs0[old])
|
||||
ibs[new].setImageResource(imgs1[new])
|
||||
title_view[old].setTextColor(resources.getColor(R.color.tab_select_no,null))
|
||||
title_view[new].setTextColor(resources.getColor(R.color.tab_select,null))
|
||||
}
|
||||
|
||||
fun jumpLogin(){
|
||||
var inl=Intent(con,LoginActivity::class.java)
|
||||
startActivity(inl)
|
||||
}
|
||||
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
return if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
exit()
|
||||
false
|
||||
} else {
|
||||
super.onKeyDown(keyCode, event)
|
||||
}
|
||||
}
|
||||
|
||||
private var isExit = false
|
||||
|
||||
fun exit() {
|
||||
if (!isExit) {
|
||||
isExit = true
|
||||
Toast.makeText(applicationContext, "再按一次退出程序", Toast.LENGTH_SHORT).show()
|
||||
hd.sendEmptyMessageDelayed(0, 2000)
|
||||
} else {
|
||||
val intent = Intent(Intent.ACTION_MAIN)
|
||||
intent.addCategory(Intent.CATEGORY_HOME)
|
||||
startActivity(intent)
|
||||
System.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user