init_activity
This commit is contained in:
parent
3f25a23f96
commit
57d16e0e8c
@ -47,5 +47,9 @@ dependencies {
|
||||
androidTestImplementation libs.androidx.junit
|
||||
androidTestImplementation libs.androidx.espresso.core
|
||||
|
||||
implementation 'com.google.code.gson:gson:2.10.1'
|
||||
implementation 'com.github.bumptech.glide:glide:4.12.0'
|
||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
|
||||
|
||||
|
||||
}
|
||||
@ -4,43 +4,37 @@ import android.content.Intent
|
||||
import android.content.pm.PackageInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Color
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.GravityCompat
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.drawerlayout.widget.DrawerLayout
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.timber.soft.myemoticon.databinding.ActivityMainBinding
|
||||
import com.timber.soft.myemoticon.model.RootDataModel
|
||||
import com.timber.soft.myemoticon.tools.AppTools
|
||||
import com.timber.soft.myemoticon.tools.AppTools.dpCovertPx
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
private lateinit var fragmentList: ArrayList<Fragment>
|
||||
private var fragmentList: ArrayList<Fragment> = arrayListOf()
|
||||
private val rootModelList: MutableList<RootDataModel> = mutableListOf()
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
val view = binding.root
|
||||
setContentView(view)
|
||||
|
||||
// 设置Padding上边距留出沉浸式状态栏空间
|
||||
binding.root.setPadding(0, dpCovertPx(this), 0, 0)
|
||||
// 设置沉浸式状态栏
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
window.decorView.systemUiVisibility =
|
||||
(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE) or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
|
||||
window.statusBarColor = Color.TRANSPARENT
|
||||
}
|
||||
window.decorView.systemUiVisibility =
|
||||
(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE) or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
|
||||
window.statusBarColor = Color.TRANSPARENT
|
||||
|
||||
binding.layoutShop.setOnClickListener() {
|
||||
val url = getString(R.string.google_play_link) + packageName
|
||||
@ -66,20 +60,32 @@ class MainActivity : AppCompatActivity() {
|
||||
binding.drawerRoot.addDrawerListener(object : DrawerLayout.DrawerListener {
|
||||
override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
|
||||
}
|
||||
|
||||
override fun onDrawerOpened(drawerView: View) {
|
||||
drawerView.isClickable = true
|
||||
}
|
||||
|
||||
override fun onDrawerClosed(drawerView: View) {
|
||||
}
|
||||
|
||||
override fun onDrawerStateChanged(newState: Int) {
|
||||
}
|
||||
})
|
||||
|
||||
rootModelList.addAll(
|
||||
AppTools.parseJsonFile(assets.open("data.json"))
|
||||
)
|
||||
rootModelList.shuffle()
|
||||
for (i in rootModelList) {
|
||||
binding.tabLayout.addTab(
|
||||
binding.tabLayout.newTab().setCustomView(R.layout.item_custom_tab)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private fun getVersionName(): String {
|
||||
val pInfo: PackageInfo
|
||||
try {
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
package com.timber.soft.myemoticon.tools
|
||||
|
||||
import android.content.Context
|
||||
import com.google.gson.Gson
|
||||
import com.timber.soft.myemoticon.model.RootDataModel
|
||||
import java.io.BufferedReader
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.io.InputStreamReader
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
object AppTools {
|
||||
|
||||
@ -19,24 +18,10 @@ object AppTools {
|
||||
return result
|
||||
}
|
||||
|
||||
fun parseJsonGsonTool(context: Context, fileName: String): List<RootDataModel>? {
|
||||
var dataItems: List<RootDataModel>? = null
|
||||
try {
|
||||
val inputStream = context.assets.open(fileName)
|
||||
val reader = BufferedReader(InputStreamReader(inputStream, StandardCharsets.UTF_8))
|
||||
val stringBuilder = StringBuilder()
|
||||
var line: String?
|
||||
while (reader.readLine().also { line = it } != null) {
|
||||
stringBuilder.append(line)
|
||||
}
|
||||
inputStream.close()
|
||||
reader.close()
|
||||
val gson = Gson()
|
||||
val dataItemArray = gson.fromJson(stringBuilder.toString(), Array<RootDataModel>::class.java)
|
||||
dataItems = dataItemArray.toList()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
return dataItems
|
||||
fun parseJsonFile(jsonInputStream: InputStream): List<RootDataModel> {
|
||||
val reader = InputStreamReader(jsonInputStream)
|
||||
val jsonString = reader.readText()
|
||||
return Gson().fromJson(jsonString, Array<RootDataModel>::class.java).toList()
|
||||
}
|
||||
|
||||
}
|
||||
8
app/src/main/res/drawable/shape_theme_color.xml
Normal file
8
app/src/main/res/drawable/shape_theme_color.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/theme_color"/>
|
||||
<corners android:radius="24dp"/>
|
||||
|
||||
</shape>
|
||||
24
app/src/main/res/layout/item_custom_tab.xml
Normal file
24
app/src/main/res/layout/item_custom_tab.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_tab_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:padding="18dp"
|
||||
android:text="text_TAB"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<View
|
||||
android:id="@+id/tab_line"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="2dp"
|
||||
android:background="@color/theme_color" />
|
||||
|
||||
</LinearLayout>
|
||||
Loading…
Reference in New Issue
Block a user