commit 4a3821c791de253cfdfe7d665c0e02fec48de77e Author: Andy0613 <841676382@qq.com> Date: Fri Oct 16 01:06:25 2026 +0800 feat: 上传第二次安卓课程代码(2026年09月18日) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000..4a53bee --- /dev/null +++ b/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b86273d --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..c2821a1 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..cdbc250 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0ef97c4 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..16660f1 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..312bb4b --- /dev/null +++ b/LICENSE @@ -0,0 +1,18 @@ +MIT License + +Copyright (c) 2026 ZITONG YAN + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the +following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8f7d3f0 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# ActivityTest + +这是第二章节的安卓课程代码 \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..16b5a7a --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,42 @@ +plugins { + alias(libs.plugins.android.application) +} + +android { + namespace 'com.yanzitong.activitytest6117' + compileSdk { + version = release(36) { + minorApiLevel = 1 + } + } + + defaultConfig { + applicationId "com.yanzitong.activitytest6117" + minSdk 26 + targetSdk 36 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + optimization { + enable false + } + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } +} + +dependencies { + implementation libs.appcompat + implementation libs.material + testImplementation libs.junit + androidTestImplementation libs.espresso.core + androidTestImplementation libs.ext.junit +} \ No newline at end of file diff --git a/app/src/androidTest/java/com/yanzitong/activitytest6117/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/yanzitong/activitytest6117/ExampleInstrumentedTest.java new file mode 100644 index 0000000..c92e5a5 --- /dev/null +++ b/app/src/androidTest/java/com/yanzitong/activitytest6117/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.yanzitong.activitytest6117; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.yanzitong.activitytest6117", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..7189923 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/yanzitong/activitytest6117/FirstActivity.java b/app/src/main/java/com/yanzitong/activitytest6117/FirstActivity.java new file mode 100644 index 0000000..5915681 --- /dev/null +++ b/app/src/main/java/com/yanzitong/activitytest6117/FirstActivity.java @@ -0,0 +1,85 @@ +package com.yanzitong.activitytest6117; + +import android.os.Bundle; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +// 组合键:shift + enter +public class FirstActivity extends AppCompatActivity { + private static final String TAG = "FirstActivity"; + + // 先声明(变量命名:小驼峰)再使用 + // 全局(成员)变量:m开头 + Button mFirstBtn1; + Button mFirstBtn2; + + /** + * 事件驱动机制 + * 事件源、什么事件、监听器(XXXListener) + * 按钮的单击事件实现方法一: + * 内部匿名 + */ + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.first_layout); + Log.d(TAG, "onCreate: 活动创建成功"); // 组合键2:alter + enter + mFirstBtn1 = findViewById(R.id.first_btn1); + mFirstBtn1.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Toast.makeText(FirstActivity.this, "6117严梓桐单击了按钮", Toast.LENGTH_SHORT).show(); + } + }); + mFirstBtn2 = findViewById(R.id.first_btn2); + mFirstBtn2.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Log.d(TAG, "onClick: Hello"); + Toast.makeText(FirstActivity.this, "我是严梓桐", Toast.LENGTH_SHORT).show(); + } + }); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { // 回调 + if (item.getItemId() == R.id.add_item) { + Toast.makeText(this, "6117单击了菜单项add", Toast.LENGTH_SHORT).show(); + Log.d(TAG, "onOptionsItemSelected: 6117单击了菜单项add"); + } else if (item.getItemId() == R.id.modify_item) { + Toast.makeText(this, "6117单击了菜单项modify", Toast.LENGTH_SHORT).show(); + Log.d(TAG, "onOptionsItemSelected: 6117单击了菜单项modify"); + } else if (item.getItemId() == R.id.delete_item) { + Toast.makeText(this, "6117单击了菜单项delete", Toast.LENGTH_SHORT).show(); + Log.d(TAG, "onOptionsItemSelected: 6117单击了菜单项delete"); + } + return super.onOptionsItemSelected(item); + } +} + +/** + * 添加一个按钮,id = first_btn2,完成单击事件:弹出Toast消息日志,内容自定义,带个人标识 + * mFirstBtn2 = findViewById(R.id.first_btn2); + * mFirstBtn2.setOnClickListener(new View.OnClickListener() { + * + * @Override public void onClick(View v) { + * Log.d(TAG, "onClick: Hello"); + * Toast.makeText(FirstActivity.this, "我是严梓桐", Toast.LENGTH_SHORT).show(); + * } + * }); + */ \ No newline at end of file diff --git a/app/src/main/keepRules/rules.keep b/app/src/main/keepRules/rules.keep new file mode 100644 index 0000000..d7e081a --- /dev/null +++ b/app/src/main/keepRules/rules.keep @@ -0,0 +1,12 @@ +# Add project specific R8 rules here. +# AGP will combine all keep rule files in src/main/keepRules to pass to R8 +# +# For more details, see +# https://d.android.com/r/tools/r8/keep-rules + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/first_layout.xml b/app/src/main/res/layout/first_layout.xml new file mode 100644 index 0000000..996b157 --- /dev/null +++ b/app/src/main/res/layout/first_layout.xml @@ -0,0 +1,22 @@ + + + +