Stage Change For page 5
This commit is contained in:
parent
daeaee0d3e
commit
90478c881d
13 changed files with 366 additions and 36 deletions
|
@ -22,20 +22,7 @@
|
|||
<State />
|
||||
</entry>
|
||||
<entry key="app">
|
||||
<State>
|
||||
<runningDeviceTargetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="RUNNING_DEVICE_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="VIRTUAL_DEVICE_PATH" />
|
||||
<value value="$USER_HOME$/.android/avd/Resizable_Experimental_API_34.avd" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</runningDeviceTargetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2024-05-24T03:51:09.939185298Z" />
|
||||
</State>
|
||||
<State />
|
||||
</entry>
|
||||
</value>
|
||||
</component>
|
||||
|
|
|
@ -11,8 +11,8 @@ android {
|
|||
applicationId = "uk.kagurach.android101"
|
||||
minSdk = 31
|
||||
targetSdk = 34
|
||||
versionCode = 153
|
||||
versionName = "1.5.3"
|
||||
versionCode = 155
|
||||
versionName = "1.5.4"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ dependencies {
|
|||
implementation(libs.androidx.annotation)
|
||||
implementation(libs.androidx.lifecycle.livedata.ktx)
|
||||
implementation(libs.androidx.lifecycle.viewmodel.ktx)
|
||||
implementation(libs.androidx.datastore.rxjava3)
|
||||
|
||||
testImplementation(libs.junit)
|
||||
|
||||
|
|
|
@ -116,6 +116,7 @@ public class Page3 extends AppCompatActivity {
|
|||
Button dot = findViewById(R.id.P3Dot);
|
||||
switch (o) {
|
||||
case "退格":
|
||||
case "BackSpace":
|
||||
if (!s.isEmpty()) {
|
||||
if (s.length() == 1) {
|
||||
s = "";
|
||||
|
|
|
@ -1,15 +1,32 @@
|
|||
package uk.kagurach.android101;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
import androidx.datastore.rxjava3.RxDataStore;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import uk.kagurach.android101.misc.AutoCompleHelper.AnimalTypeAutoCompleteHelper;
|
||||
|
||||
public class Page5 extends AppCompatActivity {
|
||||
|
||||
AnimalTypeAutoCompleteHelper completeHelper = null;
|
||||
RxDataStore<String> mDataStore = null;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -20,5 +37,64 @@ public class Page5 extends AppCompatActivity {
|
|||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
|
||||
|
||||
// Set auto-suggestions for animals
|
||||
AutoCompleteTextView autoCompleteTextView = findViewById(R.id.AnimalTypeAutoCompleteInput);
|
||||
try {
|
||||
completeHelper = new AnimalTypeAutoCompleteHelper(this);
|
||||
completeHelper.Load();
|
||||
autoCompleteTextView.setAdapter(
|
||||
completeHelper.GetArrayAdapter(
|
||||
this,android.R.layout.simple_list_item_1
|
||||
));
|
||||
} catch (IOException e){
|
||||
Log.e("P5IOException", Objects.requireNonNull(e.getMessage()));
|
||||
}
|
||||
|
||||
// Set Button Handler
|
||||
Button P5AddAnimalButton = findViewById(R.id.P5AddAnimalButton);
|
||||
P5AddAnimalButton.setOnClickListener(new AddAminalButtonHander());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class AddAminalButtonHander implements View.OnClickListener {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
TextView name = findViewById(R.id.P5AnimalNameInput);
|
||||
AutoCompleteTextView type = findViewById(R.id.AnimalTypeAutoCompleteInput);
|
||||
|
||||
if (name.getText().toString().isEmpty()||type.getText().toString().isEmpty()){
|
||||
ToastHelper.SmartToast.ShowToast("Please input all fields",v.getContext());
|
||||
}
|
||||
|
||||
try {
|
||||
completeHelper.AddEntry(type.getText().toString());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
completeHelper.Sync();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
type.setAdapter(
|
||||
completeHelper.GetArrayAdapter(
|
||||
v.getContext(),android.R.layout.simple_list_item_1
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
if (getCurrentFocus() != null) {
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
|
||||
}
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
package uk.kagurach.android101.misc.AutoCompleHelper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class AbstractAutoCompleteHelper {
|
||||
List<String> data = null;
|
||||
public String dataFile = null;
|
||||
boolean loaded = false;
|
||||
|
||||
abstract void AddEntry(String name) throws IOException;
|
||||
abstract void DeleteEntry(String name);
|
||||
public void Load() throws IOException {
|
||||
if (dataFile==null){
|
||||
throw new RuntimeException("dataFile not specified");
|
||||
}
|
||||
File _data = new File(dataFile);
|
||||
if (!_data.isFile()){
|
||||
_data.createNewFile();
|
||||
}
|
||||
if (!_data.canRead() || !_data.canWrite()){
|
||||
throw new RuntimeException("File permission denied");
|
||||
}
|
||||
loaded = true;
|
||||
Scanner scanner = new Scanner(_data);
|
||||
|
||||
if (data == null) {
|
||||
data = new ArrayList<>();
|
||||
}else {
|
||||
// 去重
|
||||
Set<String> set = new LinkedHashSet<>(data);
|
||||
data = new ArrayList<>(set);
|
||||
}
|
||||
while (scanner.hasNextLine()){
|
||||
data.add(scanner.nextLine());
|
||||
}
|
||||
|
||||
}
|
||||
public void Sync() throws IOException {
|
||||
if (dataFile==null){
|
||||
throw new RuntimeException("dataFile not specified");
|
||||
}
|
||||
File _data = new File(dataFile);
|
||||
if (!_data.isFile()){
|
||||
_data.createNewFile();
|
||||
}
|
||||
if (!_data.canRead() || !_data.canWrite()){
|
||||
throw new RuntimeException("File permission denied");
|
||||
}
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (String name:data) {
|
||||
stringBuilder.append(name);
|
||||
stringBuilder.append('\n');
|
||||
}
|
||||
try (FileWriter fileWriter = new FileWriter(_data,false)) {
|
||||
fileWriter.write(stringBuilder.toString());
|
||||
}
|
||||
catch (IOException e){
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract ArrayAdapter<String> GetArrayAdapter(
|
||||
Context ctx, @LayoutRes int resource);
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package uk.kagurach.android101.misc.AutoCompleHelper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.LayoutRes;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class AnimalTypeAutoCompleteHelper extends AbstractAutoCompleteHelper {
|
||||
public AnimalTypeAutoCompleteHelper(Context ctx) throws IOException {
|
||||
dataFile = ctx.getFilesDir().getAbsolutePath() + File.separator + "animalTypes.dat";
|
||||
Load();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void AddEntry(String name) throws IOException {
|
||||
if (!loaded){
|
||||
throw new RuntimeException("Haven't loaded");
|
||||
}
|
||||
if (data.contains(name)){
|
||||
return;
|
||||
}
|
||||
data.add(name);
|
||||
Sync();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DeleteEntry(String name) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayAdapter<String> GetArrayAdapter(
|
||||
Context ctx, @LayoutRes int resource) {
|
||||
if (data == null) {
|
||||
return new ArrayAdapter<>(ctx, resource,
|
||||
new String[]{
|
||||
"cat","dog","喵喵"
|
||||
}
|
||||
);
|
||||
}
|
||||
return new ArrayAdapter<>(ctx, resource, data);
|
||||
}
|
||||
}
|
|
@ -32,6 +32,7 @@
|
|||
android:layout_weight="1"
|
||||
android:text="@string/next_page"
|
||||
android:enabled="false"
|
||||
android:backgroundTint="#81D4FA"
|
||||
/>
|
||||
|
||||
|
||||
|
|
|
@ -7,4 +7,114 @@
|
|||
android:layout_height="match_parent"
|
||||
tools:context=".Page5">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp" />
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:background="#E0F7FA"
|
||||
android:text="@string/animal_manage_system_n_kv_backend"
|
||||
android:textSize="30sp"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginVertical="15dp"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:textSize="28sp"
|
||||
android:text="@string/name"/>
|
||||
<EditText
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:hint="@string/animal_name_default"
|
||||
android:maxLines="1"
|
||||
android:id="@+id/P5AnimalNameInput"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="280dp"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginVertical="15dp"
|
||||
android:layout_marginHorizontal="10dp">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:textSize="28sp"
|
||||
android:text="@string/type"/>
|
||||
<AutoCompleteTextView
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:hint="@string/cat"
|
||||
android:maxLines="1"
|
||||
android:id="@+id/AnimalTypeAutoCompleteInput"/>
|
||||
</LinearLayout>
|
||||
|
||||
<ListView
|
||||
android:id="@+id/P5Suggestions"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_marginStart="65dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_height="200dp" />
|
||||
</LinearLayout>
|
||||
<Button
|
||||
android:id="@+id/P5AddAnimalButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="70dp"
|
||||
android:layout_marginVertical="20dp"
|
||||
android:layout_marginHorizontal="15dp"
|
||||
android:text="@string/add"
|
||||
android:backgroundTint="#4FC3F7"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="70dp"
|
||||
android:layout_marginVertical="20dp"
|
||||
android:layout_marginHorizontal="15dp"
|
||||
android:orientation="horizontal">
|
||||
<Button
|
||||
android:id="@+id/P5CleanDataButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginEnd="15dp"
|
||||
android:backgroundTint="#D50000"
|
||||
android:text="@string/clean_data"/>
|
||||
<Button
|
||||
android:id="@+id/P5QueryButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginEnd="15dp"
|
||||
android:backgroundTint="#9FA8DA"
|
||||
android:text="@string/query"/>
|
||||
<Button
|
||||
android:id="@+id/P5NextPage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginEnd="15dp"
|
||||
android:backgroundTint="#0091EA"
|
||||
android:text="@string/next_page"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -17,4 +17,22 @@
|
|||
<string name="ai_ready">AI 准备好了</string>
|
||||
<string name="AI_ASK_DEFAULT_STRING">你吃了吗?</string>
|
||||
<string name="vibrate">振动手机</string>
|
||||
<string name="animal_manage_system_n_kv_backend">动物管理系统\n当前后端: KV对</string>
|
||||
<string name="name">姓名</string>
|
||||
<string name="animal_name_default">可爱喵</string>
|
||||
<string name="type">类型</string>
|
||||
<string name="cat">喵喵</string>
|
||||
<string name="add">添加</string>
|
||||
<string name="clean_data">清除数据</string>
|
||||
<string name="title_activity_add_page">添加页面</string>
|
||||
<string name="hello_world">你好,世界!</string>
|
||||
<string name="next_page">下一页</string>
|
||||
<string name="two_way_page">单击下一页,长按上一页</string>
|
||||
<string name="test_str">测试文本</string>
|
||||
<string name="set_color">设置颜色</string>
|
||||
<string name="set">设置</string>
|
||||
<string name="setText">设置文本</string>
|
||||
<string name="kaculate">弱智计算器</string>
|
||||
<string name="Backspace">退格</string>
|
||||
<string name="query">查询</string>
|
||||
</resources>
|
|
@ -4,22 +4,14 @@
|
|||
<string name="yes_not_finish">You haven\'t finished😇</string>
|
||||
<string name="finish">Finish</string>
|
||||
<string name="unfinish">Not Finish</string>
|
||||
<string name="title_activity_add_page" translatable="false">add_page</string>
|
||||
<string name="title_activity_add_page">add_page</string>
|
||||
<string name="edit_page_title">Edit Your TODO Item Here</string>
|
||||
<string name="enter_title">Enter Title</string>
|
||||
<string name="first_delete">Delete</string>
|
||||
<string name="second_delete">Delete!!</string>
|
||||
|
||||
<string name="app_name">Android101</string>
|
||||
<string name="hello_world" translatable="false">你好,世界!</string>
|
||||
<string name="next_page" translatable="false">下一页</string>
|
||||
<string name="two_way_page" translatable="false">单击下一页,长按上一页</string>
|
||||
<string name="test_str" translatable="false">测试文本</string>
|
||||
<string name="set_color" translatable="false">设置颜色</string>
|
||||
<string name="set" translatable="false">设置</string>
|
||||
<string name="setText" translatable="false">设置文本</string>
|
||||
<string name="kaculate" translatable="false">弱智计算器</string>
|
||||
<string name="Backspace" translatable="false">退格</string>
|
||||
<string name="Backspace">BackSpace</string>
|
||||
<string name="todo_app_short_label">Open TODO</string>
|
||||
<string name="user">User</string>
|
||||
<string name="ai">AI</string>
|
||||
|
@ -27,4 +19,20 @@
|
|||
<string name="ai_ready">AI Ready</string>
|
||||
<string name="AI_ASK_DEFAULT_STRING">你吃了吗?</string>
|
||||
<string name="vibrate">Vibrate</string>
|
||||
<string name="animal_manage_system_n_kv_backend">Animal Manage System\nCurrent Backend: KV Pair</string>
|
||||
<string name="name">Name</string>
|
||||
<string name="animal_name_default">NachoNeko</string>
|
||||
<string name="type">Type</string>
|
||||
<string name="cat">Cat</string>
|
||||
<string name="add">add</string>
|
||||
<string name="clean_data">Clean DATA</string>
|
||||
<string name="query">Query</string>
|
||||
<string name="kaculate">Simple Calc</string>
|
||||
<string name="hello_world">Hello World!</string>
|
||||
<string name="next_page">Next Page</string>
|
||||
<string name="two_way_page">Next page for short press and previous for long</string>
|
||||
<string name="test_str">Test Text 123</string>
|
||||
<string name="set_color">Set Color</string>
|
||||
<string name="set">Set</string>
|
||||
<string name="setText">Set Text</string>
|
||||
</resources>
|
|
@ -2,15 +2,15 @@
|
|||
<!-- Base application theme. -->
|
||||
<style name="Theme.Android101" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<!-- Primary brand color. -->
|
||||
<item name="colorPrimary">@color/purple_500</item>
|
||||
<item name="colorPrimaryVariant">@color/purple_700</item>
|
||||
<item name="colorPrimary">#3D5AFE</item>
|
||||
<item name="colorPrimaryVariant">#D500F9</item>
|
||||
<item name="colorOnPrimary">@color/white</item>
|
||||
<!-- Secondary brand color. -->
|
||||
<item name="colorSecondary">@color/teal_200</item>
|
||||
<item name="colorSecondaryVariant">@color/teal_700</item>
|
||||
<item name="colorOnSecondary">@color/black</item>
|
||||
<!-- Status bar color. -->
|
||||
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
|
||||
<item name="android:statusBarColor">#0D47A1</item>
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
<style name="Theme.TODOList" parent="android:Theme.Material.Light.NoActionBar" />
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
[versions]
|
||||
agp = "8.3.2"
|
||||
agp = "8.4.1"
|
||||
kotlin = "1.9.0"
|
||||
coreKtx = "1.13.1"
|
||||
junit = "4.13.2"
|
||||
junitVersion = "1.1.5"
|
||||
espressoCore = "3.5.1"
|
||||
appcompat = "1.6.1"
|
||||
appcompat = "1.7.0"
|
||||
material = "1.12.0"
|
||||
activity = "1.9.0"
|
||||
constraintlayout = "2.1.4"
|
||||
lifecycleRuntimeKtx = "2.8.0"
|
||||
lifecycleRuntimeKtx = "2.8.1"
|
||||
activityCompose = "1.9.0"
|
||||
composeBom = "2024.05.00"
|
||||
roomCommon = "2.6.1"
|
||||
|
@ -17,8 +17,9 @@ roomKtx = "2.6.1"
|
|||
navigationFragmentKtx = "2.7.7"
|
||||
navigationUiKtx = "2.7.7"
|
||||
annotation = "1.8.0"
|
||||
lifecycleLivedataKtx = "2.8.0"
|
||||
lifecycleViewmodelKtx = "2.8.0"
|
||||
lifecycleLivedataKtx = "2.8.1"
|
||||
lifecycleViewmodelKtx = "2.8.1"
|
||||
datastoreRxjava3 = "1.1.1"
|
||||
|
||||
[libraries]
|
||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||
|
@ -46,6 +47,7 @@ androidx-navigation-ui-ktx = { group = "androidx.navigation", name = "navigation
|
|||
androidx-annotation = { group = "androidx.annotation", name = "annotation", version.ref = "annotation" }
|
||||
androidx-lifecycle-livedata-ktx = { group = "androidx.lifecycle", name = "lifecycle-livedata-ktx", version.ref = "lifecycleLivedataKtx" }
|
||||
androidx-lifecycle-viewmodel-ktx = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx", version.ref = "lifecycleViewmodelKtx" }
|
||||
androidx-datastore-rxjava3 = { group = "androidx.datastore", name = "datastore-rxjava3", version.ref = "datastoreRxjava3" }
|
||||
|
||||
[plugins]
|
||||
androidApplication = { id = "com.android.application", version.ref = "agp" }
|
||||
|
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,6 +1,6 @@
|
|||
#Fri Mar 08 22:31:04 CST 2024
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
Loading…
Reference in a new issue