diff --git a/app/build.gradle b/app/build.gradle index ac8fda5b5678050ec19f0c8b5753ef7553e55b88..cef534034a08667bc73ab89478444731809baba9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,11 +1,8 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' -apply plugin: 'kotlin-kapt' - -/*plugins{ - id -}*/ +plugins { + id 'com.android.application' + id 'kotlin-android' + id 'kotlin-kapt' +} /*apply from '../gradlescript/config.gradle'*/ @@ -46,6 +43,7 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "junit:junit:4.12" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" /*kotlin的协程包*/ @@ -70,6 +68,9 @@ dependencies { /*引入protobuf*/ implementation 'com.google.protobuf:protoc:3.14.0' + /* 引入datastore */ + implementation 'androidx.datastore:datastore:1.0.0-alpha05' + /*数据库的greendao引入*/ implementation 'org.greenrobot:greendao:3.3.0' @@ -85,6 +86,9 @@ dependencies { /*Gson 引入*/ implementation 'com.google.code.gson:gson:2.8.6' + /*引入EventBus3*/ + implementation 'org.greenrobot:eventbus:3.1.1' + kapt "com.android.databinding:compiler:4.0.2" kapt project(':apt') diff --git a/app/src/androidTest/java/com/guiguzi/androidtest/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/guiguzi/androidtest/ExampleInstrumentedTest.kt index d7de16cdfb46e3faa31040c18516a417110882e5..43471d25b82197b347eb0fc8d351f5780e1ee6a1 100644 --- a/app/src/androidTest/java/com/guiguzi/androidtest/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/com/guiguzi/androidtest/ExampleInstrumentedTest.kt @@ -1,24 +1,23 @@ package com.guiguzi.androidtest -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.ext.junit.runners.AndroidJUnit4 - +import com.guiguzi.androidtest.jsonUtil.JsonBean +import com.guiguzi.androidtest.jsonUtil.JsonMain +import com.guiguzi.androidtest.jsonUtil.MpAppBean import org.junit.Test -import org.junit.runner.RunWith - -import org.junit.Assert.* /** * Instrumented test, which will execute on an Android device. * * See [testing documentation](http://d.android.com/tools/testing). */ -@RunWith(AndroidJUnit4::class) class ExampleInstrumentedTest { @Test fun useAppContext() { // Context of the app under test. - val appContext = InstrumentationRegistry.getInstrumentation().targetContext - assertEquals("com.guiguzi.androidtest", appContext.packageName) + } + + @Test + fun useJson() { + var mpAppBean = JsonMain.toJavaByStr(JsonBean.mpApp, MpAppBean::class.java) } } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 07e7e60ee2216d72114394f260f573f89f247f67..1455a2a241b59c144cc15b53ffe891139c2d9590 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -27,29 +27,24 @@ android:theme="@style/AppTheme" android:usesCleartextTraffic="true"> - + - + - - - + android:launchMode="singleTask" /> - + @@ -61,6 +56,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/guiguzi/androidtest/AppMainActivity.kt b/app/src/main/java/com/guiguzi/androidtest/AppMainActivity.kt index ea6479f439cdade9f2265ddbad387e1f70055e59..7acb0f2c6107cbc02b11f783450bea3d45916c7e 100644 --- a/app/src/main/java/com/guiguzi/androidtest/AppMainActivity.kt +++ b/app/src/main/java/com/guiguzi/androidtest/AppMainActivity.kt @@ -62,9 +62,19 @@ class AppMainActivity : AppCompatActivity() { } + override fun onStart() { + super.onStart() + Log.d(TAG,"AppMainActivity onStart().") + } + + override fun onRestart() { + super.onRestart() + Log.d(TAG,"AppMainActivity onStart().") + } override fun onResume() { super.onResume() + Log.d(TAG,"AppMainActivity onResume().") mHandler.postDelayed({ val message = Message.obtain() message.arg1 = 100 @@ -76,17 +86,28 @@ class AppMainActivity : AppCompatActivity() { }, 3 * 1000) } + override fun onPause() { + super.onPause() + Log.d(TAG,"AppMainActivity onPause().") + } + + override fun onStop() { + super.onStop() + Log.d(TAG,"AppMainActivity onStop().") + } + override fun onSaveInstanceState(outState: Bundle, outPersistentState: PersistableBundle) { super.onSaveInstanceState(outState, outPersistentState) - Log.d("GGZTest", "MainActivity onSaveInstanceState") + Log.d(TAG, "MainActivity onSaveInstanceState") } override fun onRestoreInstanceState(savedInstanceState: Bundle) { super.onRestoreInstanceState(savedInstanceState) - Log.d("GGZTest", "MainActivity onRestoreInstanceState") + Log.d(TAG, "MainActivity onRestoreInstanceState") } override fun onDestroy() { super.onDestroy() + Log.d(TAG,"AppMainActivity onDestroy().") } } diff --git a/app/src/main/java/com/guiguzi/androidtest/activity/ButtonsActivity.kt b/app/src/main/java/com/guiguzi/androidtest/activity/ButtonsActivity.kt new file mode 100644 index 0000000000000000000000000000000000000000..002b3530ca0557c22ea4b46b0d6affcec11a1528 --- /dev/null +++ b/app/src/main/java/com/guiguzi/androidtest/activity/ButtonsActivity.kt @@ -0,0 +1,59 @@ +package com.guiguzi.androidtest.activity + +import android.app.Activity +import android.content.Intent +import android.os.Bundle +import android.os.PersistableBundle +import android.util.Log +import android.view.ViewGroup +import android.widget.Button +import android.widget.FrameLayout +import android.widget.LinearLayout +import com.guiguzi.androidtest.R + +class ButtonsActivity : Activity() { + + companion object { + const val TAG = "ButtonsActivity" + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val linearLayout = LinearLayout(baseContext) + linearLayout.setBackgroundColor(resources.getColor(R.color.colorBlack)) + + val rootLayoutParams = FrameLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT + ) + + /*linearLayout.layoutParams = LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.MATCH_PARENT + )*/ + val matchParams = ViewGroup.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.MATCH_PARENT + ) + + val button1 = Button(baseContext) + val buttonParams = LinearLayout.LayoutParams( + LinearLayout.LayoutParams.WRAP_CONTENT, + LinearLayout.LayoutParams.WRAP_CONTENT + ) + button1.setText("brand") + button1.textSize = 22f + button1.setTextColor(resources.getColor(R.color.colorAccent)) + linearLayout.addView(button1, buttonParams) + + setContentView(linearLayout, rootLayoutParams) + + button1.setOnClickListener { + val brand = android.os.Build.BRAND + Log.d(TAG, "mobile brand = $brand") + } + + //测试显示启动 + val intent = Intent(this,MainActivity.javaClass) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/guiguzi/androidtest/activity/EventBusActivity.kt b/app/src/main/java/com/guiguzi/androidtest/activity/EventBusActivity.kt new file mode 100644 index 0000000000000000000000000000000000000000..b47742bf59312c0ddc858419a721f0c4abde529d --- /dev/null +++ b/app/src/main/java/com/guiguzi/androidtest/activity/EventBusActivity.kt @@ -0,0 +1,65 @@ +package com.guiguzi.androidtest.activity + +import android.app.Activity +import android.os.Bundle +import android.util.Log +import android.widget.Button +import android.widget.TextView +import com.guiguzi.androidtest.R +import com.guiguzi.androidtest.eventbus.EventString +import org.greenrobot.eventbus.EventBus +import org.greenrobot.eventbus.Subscribe +import org.greenrobot.eventbus.ThreadMode + + +class EventBusActivity : Activity() { + + companion object { + const val TAG = "EventBusTag" + } + + lateinit var mText: TextView + lateinit var mButton: Button + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_event_bus) + initView() + } + + fun initView() { + mText = findViewById(R.id.text) + mButton = findViewById(R.id.button_register) + + + mButton.setOnClickListener { + EventBus.getDefault().register(this) + } + + findViewById