commit 1db1c84a846d5ed69c1ca9d58883f97f6f516aaf Author: 15873037570 <3112724511@qq.com> Date: Mon May 27 11:49:16 2024 +0800 project diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..223cde8 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,40 @@ +plugins { + id("com.android.application") +} + +android { + namespace = "com.example.eventbase" + compileSdk = 34 + + defaultConfig { + applicationId = "com.example.eventbase" + minSdk = 24 + targetSdk = 34 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation("androidx.appcompat:appcompat:1.6.1") + implementation("com.google.android.material:material:1.9.0") + implementation("androidx.constraintlayout:constraintlayout:2.1.4") + testImplementation("junit:junit:4.13.2") + androidTestImplementation("androidx.test.ext:junit:1.1.5") + androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") + implementation("org.greenrobot:eventbus:3.3.1") +} \ No newline at end of file diff --git a/proguard-rules.pro b/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# 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 *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/src/androidTest/java/com/example/eventbase/ExampleInstrumentedTest.java b/src/androidTest/java/com/example/eventbase/ExampleInstrumentedTest.java new file mode 100644 index 0000000..68a817f --- /dev/null +++ b/src/androidTest/java/com/example/eventbase/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.eventbase; + +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.example.eventbase", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml new file mode 100644 index 0000000..23f9698 --- /dev/null +++ b/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/example/eventbase/DBTools.java b/src/main/java/com/example/eventbase/DBTools.java new file mode 100644 index 0000000..a1423a3 --- /dev/null +++ b/src/main/java/com/example/eventbase/DBTools.java @@ -0,0 +1,23 @@ +package com.example.eventbase; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; + +import androidx.annotation.Nullable; + +public class DBTools extends SQLiteOpenHelper { + public DBTools(@Nullable Context context,@Nullable String name,@Nullable SQLiteDatabase.CursorFactory factory,int version){ + super(context,name,factory,version); + + } + @Override + public void onCreate(SQLiteDatabase db) { + db.execSQL("create table user(id integer primary key autoincrement,username varchar(20),age integer)"); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + + } +} diff --git a/src/main/java/com/example/eventbase/MainActivity.java b/src/main/java/com/example/eventbase/MainActivity.java new file mode 100644 index 0000000..906267b --- /dev/null +++ b/src/main/java/com/example/eventbase/MainActivity.java @@ -0,0 +1,104 @@ +package com.example.eventbase; + +import androidx.appcompat.app.AppCompatActivity; + +import android.animation.ObjectAnimator; +import android.animation.PropertyValuesHolder; +import android.animation.ValueAnimator; +import android.content.ContentValues; +import android.content.Intent; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.ImageView; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + EventBus.getDefault().register(this); + findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(MainActivity.this, MainActivity2.class); + startActivity(intent); + } + }); + ImageView imageView = findViewById(R.id.imageView); + findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { +// ObjectAnimator objectAnimator =ObjectAnimator.ofFloat(imageView,"translationX",0,500); +//// objectAnimator.setDuration(5000); +//// objectAnimator.start(); + DBTools dbTools =new DBTools(MainActivity.this,"test",null,1); + SQLiteDatabase sqLiteDatabase = dbTools.getReadableDatabase(); + ContentValues contentValues =new ContentValues(); + contentValues.put("username","计科一班"); + contentValues.put("age",20); + sqLiteDatabase.insert("user",null,contentValues); + } + }); + findViewById(R.id.button4).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { +// ObjectAnimator objectAnimator =ObjectAnimator.ofFloat(imageView,"alpha",1,0); +// objectAnimator.setDuration(5000); +// objectAnimator.start(); + DBTools dbTools =new DBTools(MainActivity.this,"test",null,1); + SQLiteDatabase sqLiteDatabase = dbTools.getReadableDatabase(); + sqLiteDatabase.delete("user","username=?",new String[]{"test1"}); + } + }); + findViewById(R.id.button5).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { +// ObjectAnimator objectAnimator =ObjectAnimator.ofFloat(imageView,"scaleX",1,0,2); +// objectAnimator.setDuration(5000); +// objectAnimator.start(); + DBTools dbTools =new DBTools(MainActivity.this,"test",null,1); + SQLiteDatabase sqLiteDatabase = dbTools.getReadableDatabase(); + Cursor cursor = sqLiteDatabase.query("user",new String[]{"id","username","age"}, + "username=?",new String[]{"计科一班"},null,null,null); + while (cursor.moveToNext()){ + int id = cursor.getInt(cursor.getColumnIndex("id")); + String username = cursor.getString(cursor.getColumnIndex("username")); + int age =cursor.getInt(cursor.getColumnIndex("age")); + Log.i("test",id+username+age); + } + } + }); + findViewById(R.id.button6).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + ObjectAnimator objectAnimator =ObjectAnimator.ofFloat(imageView,"rotation",0,180); + objectAnimator.setDuration(5000); + objectAnimator.start(); + } + }); + findViewById(R.id.button7).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { +// PropertyValuesHolder propertyValuesHolder = PropertyValuesHolder.ofFloat("scaleX",0,2f); +// PropertyValuesHolder propertyValuesHolder1 = PropertyValuesHolder.ofFloat("scaleY",0,2f); +// PropertyValuesHolder propertyValuesHolder2 = PropertyValuesHolder.ofFloat("alpha",0,2f); +// ValueAnimator valueAnimator =ObjectAnimator.ofPropertyValuesHolder(imageView,propertyValuesHolder,propertyValuesHolder1,propertyValuesHolder2); +// valueAnimator.setDuration(5000); +// valueAnimator.start(); + } + }); + } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onMassage(String massage){ + Log.i("test",massage); + } + +} \ No newline at end of file diff --git a/src/main/java/com/example/eventbase/MainActivity2.java b/src/main/java/com/example/eventbase/MainActivity2.java new file mode 100644 index 0000000..15594c4 --- /dev/null +++ b/src/main/java/com/example/eventbase/MainActivity2.java @@ -0,0 +1,23 @@ +package com.example.eventbase; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; +import android.view.View; + +import org.greenrobot.eventbus.EventBus; + +public class MainActivity2 extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main2); + findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + EventBus.getDefault().post("hello world"); + } + }); + } +} \ No newline at end of file diff --git a/src/main/res/drawable/ic_launcher_background.xml b/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/res/drawable/ic_launcher_foreground.xml b/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/img.png b/src/main/res/drawable/img.png new file mode 100644 index 0000000..73c061e Binary files /dev/null and b/src/main/res/drawable/img.png differ diff --git a/src/main/res/layout/activity_main.xml b/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..350a995 --- /dev/null +++ b/src/main/res/layout/activity_main.xml @@ -0,0 +1,90 @@ + + + + + +