Compare commits

...

10 commits

Author SHA1 Message Date
ef243968c3 small change 2024-06-12 22:49:36 +08:00
35fae8019f Stage Last Version 2024-06-02 12:53:54 +08:00
2418dfcac2 Add Color Theme 2024-06-02 10:28:58 +08:00
b781948911 Add theme 2024-06-02 00:42:29 +08:00
96dd0869d4 Refactor naming, fix kalculate 2024-06-01 17:14:53 +08:00
14b41f2f2d 1.5.8 UI Fix 2024-06-01 16:21:54 +08:00
001975aab1 1.5.7 New UI 2024-06-01 10:55:56 +08:00
90478c881d Stage Change For page 5 2024-05-31 11:04:43 +08:00
daeaee0d3e 1.5.3 2024-05-24 12:48:34 +08:00
a1cccd9890 智能++ 2024-05-23 21:48:12 +08:00
51 changed files with 2216 additions and 692 deletions

2
.gitignore vendored
View file

@ -15,3 +15,5 @@
local.properties
app/release
/.idea/inspectionProfiles/Project_Default.xml
/.idea/deploymentTargetSelector.xml
/.idea/studiobot.xml

View file

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AndroidTestResultsUserPreferences">
<option name="androidTestResultsTableState">
<map>
<entry key="231168827">
<value>
<AndroidTestResultsTableState>
<option name="preferredColumnWidths">
<map>
<entry key="Duration" value="90" />
<entry key="Resizable_Experimental_API_34" value="120" />
<entry key="Tests" value="360" />
</map>
</option>
</AndroidTestResultsTableState>
</value>
</entry>
<entry key="383667187">
<value>
<AndroidTestResultsTableState>
<option name="preferredColumnWidths">
<map>
<entry key="Duration" value="90" />
<entry key="Resizable_Experimental_API_34" value="120" />
<entry key="Tests" value="360" />
</map>
</option>
</AndroidTestResultsTableState>
</value>
</entry>
<entry key="1145031456">
<value>
<AndroidTestResultsTableState>
<option name="preferredColumnWidths">
<map>
<entry key="Duration" value="90" />
<entry key="Resizable_Experimental_API_34" value="120" />
<entry key="Tests" value="360" />
</map>
</option>
</AndroidTestResultsTableState>
</value>
</entry>
</map>
</option>
</component>
</project>

View file

@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.jetbrainsKotlinAndroid)
}
android {
@ -11,8 +12,8 @@ android {
applicationId = "uk.kagurach.android101"
minSdk = 31
targetSdk = 34
versionCode = 151
versionName = "1.5.1"
versionCode = 160
versionName = "1.6"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
@ -43,6 +44,9 @@ android {
androidResources {
generateLocaleConfig = true
}
buildFeatures{
viewBinding = true
}
}
dependencies {
@ -68,6 +72,8 @@ dependencies {
implementation(libs.androidx.annotation)
implementation(libs.androidx.lifecycle.livedata.ktx)
implementation(libs.androidx.lifecycle.viewmodel.ktx)
implementation(libs.androidx.datastore.rxjava3)
implementation(libs.androidx.datastore.preferences)
testImplementation(libs.junit)

View file

@ -0,0 +1,31 @@
package uk.kagurach.android101
import org.junit.Assert
import org.junit.Test
import uk.kagurach.android101.helper.ColorHelper
import org.junit.runner.RunWith
class TestColorHelper {
val colorHelper = ColorHelper()
@Test
fun Test_toColorInt(){
Assert.assertEquals(0,colorHelper.toColorInt(0, 0, 0))
Assert.assertEquals(0xfffffe,colorHelper.toColorInt(255, 0xff, 254))
}
@Test(expected = Exception::class)
fun Test_error(){
val wtf1 = colorHelper.toColorInt(-1,256,1)
}
@Test
fun Test_toString(){
Assert.assertEquals("$000000",colorHelper.toString(0,"$"))
Assert.assertEquals("#ffffff",colorHelper.toString(0xffffff))
Assert.assertEquals("#ABCD12",colorHelper.toString(0xabcd12, upperCase = true))
}
}

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
@ -12,8 +12,24 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Android101"
tools:targetApi="31">
android:theme="@style/Theme.Android101">
<activity
android:name=".baoleme.BaolemaMainActivity"
android:exported="false" />
<activity
android:name=".SettingPage"
android:exported="false" />
<receiver
android:name=".misc.vibrationBroadcastReceiver.vibrationBroadcastReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.VIBRATE">
<intent-filter>
<action android:name="uk.kagurach.android101.vibrationBroadcastReceiver" />
</intent-filter>
</receiver>
<activity
android:name=".Page4OtherActivity"
android:exported="false" />
@ -44,9 +60,9 @@
android:label="@string/title_activity_add_page"
android:theme="@style/Theme.TODOList" />
<activity
android:name=".todoList.MainActivity"
android:name=".todoList.TodoListMainActivity"
android:exported="true"
android:label="todoListMain"
android:label="@string/todo_app"
android:theme="@style/Theme.TODOList">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View file

@ -0,0 +1,93 @@
package chatgpt;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class AnimalDatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "AnimalDatabase.db";
private static final int DATABASE_VERSION = 1;
private static final String TABLE_NAME = "AnimalData";
// Columns
private static final String COLUMN_ID = "_id";
private static final String COLUMN_NAME = "name";
private static final String COLUMN_TYPE = "type";
public AnimalDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String createTable = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " +
COLUMN_NAME + " VARCHAR NOT NULL, " +
COLUMN_TYPE + " VARCHAR NOT NULL);";
db.execSQL(createTable);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Handle database upgrade as needed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
// Method to check if the name already exists
public boolean isNameExists(String name) {
SQLiteDatabase db = this.getReadableDatabase();
String query = "SELECT * FROM " + TABLE_NAME + " WHERE " + COLUMN_NAME + " = ?";
Cursor cursor = db.rawQuery(query, new String[]{name});
boolean exists = cursor.getCount() > 0;
cursor.close();
return exists;
}
// Method to insert new animal data if the name does not exist
public boolean insertAnimalData(String name, String type) {
if (!isNameExists(name)) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COLUMN_NAME, name);
values.put(COLUMN_TYPE, type);
long result = db.insert(TABLE_NAME, null, values);
return result != -1; // Return true if insert is successful
} else {
return false; // Name already exists
}
}
// Method to clear the table
public void clearTable() {
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DELETE FROM " + TABLE_NAME);
db.execSQL("VACUUM"); // Optional: Reclaims database space after delete
}
// Method to get all data as a formatted string
public String getAllDataAsString() {
SQLiteDatabase db = this.getReadableDatabase();
StringBuilder result = new StringBuilder();
String query = "SELECT " + COLUMN_NAME + ", " + COLUMN_TYPE + " FROM " + TABLE_NAME;
Cursor cursor = db.rawQuery(query, null);
int id = 1;
if (cursor.moveToFirst()) {
do {
String name = cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_NAME));
String type = cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_TYPE));
result.append(id++).append(": name:'").append(name).append("'@'").append(type).append("'\n");
} while (cursor.moveToNext());
}
cursor.close();
return result.toString();
}
}

View file

@ -0,0 +1,14 @@
package uk.kagurach.android101
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import kotlinx.coroutines.runBlocking
open class KaBaseActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val storage = SettingStorage(this)
this.setTheme(runBlocking { storage.getDefaultTheme() })
}
}

View file

@ -1,114 +0,0 @@
package uk.kagurach.android101
import android.content.Context
import kotlin.math.pow
fun Kaculate(src: String,ctx :Context) : String{
if (src.isBlank()){
return src
}
val OpList = charArrayOf('+','-','x','/','^')
var numStack = floatArrayOf()
var opStack = charArrayOf()
var _curnum = ""
for (i in src.indices){
if (src[i] in '0'..'9' || src[i] == '.'){
_curnum += src[i]
}
else if (src[i] in OpList){
try {
numStack += _curnum.toFloat()
_curnum = ""
}catch (e:Exception){
ToastHelper.ShowToast(e.toString(),ctx)
return src
}
opStack += src[i]
}
else{
ToastHelper.ShowToast("Unknown input char:" + src[i].toString(),ctx)
return src
}
}
if (_curnum.isNotEmpty()){
try {
numStack += _curnum.toFloat()
}catch (e:Exception){
ToastHelper.ShowToast(e.toString(),ctx)
return src
}
}
if (numStack.size != opStack.size+1 ){
ToastHelper.ShowToast("Ops and nums Not Match!",ctx)
return src
}
// ^
if ('^' in opStack){
var intStackCurr = 0
for (i in opStack.indices){
if (opStack[i]!='^'){
intStackCurr ++
continue
}
val a = numStack[intStackCurr]
val b = numStack[intStackCurr+1]
numStack[intStackCurr] = a.pow(b)
numStack = dropAtIdx(numStack,intStackCurr+1)
}
}
// x and /
var intStackCurr = 0
for (i in opStack.indices){
if (opStack[i]!='x'&&opStack[i]!='/'){
intStackCurr ++
continue
}
val a = numStack[intStackCurr]
val b = numStack[intStackCurr+1]
if (opStack[i] == 'x'){
numStack[intStackCurr] = a*b
}else{
numStack[intStackCurr] = a/b
}
numStack = dropAtIdx(numStack,intStackCurr+1)
}
// + and -
if (opStack.isNotEmpty()) {
for (i in opStack) {
if (i == '+') {
numStack[0] += numStack[1]
numStack = dropAtIdx(numStack,1)
} else if (i=='-') {
numStack[0] -= numStack[1]
numStack = dropAtIdx(numStack,1)
}
}
}
return numStack[0].toString()
}
private fun dropAtIdx(array: FloatArray, idx:Int): FloatArray{
if (idx>array.size){
throw IndexOutOfBoundsException()
}
var newArray = floatArrayOf()
for (i in array.indices){
if (i!=idx){
newArray += array[i]
}
}
return newArray
}

View file

@ -25,8 +25,11 @@ import androidx.core.view.WindowInsetsCompat;
import java.util.Arrays;
public class MainActivity extends AppCompatActivity {
import uk.kagurach.android101.helper.PageHelper;
public class MainActivity extends KaBaseActivity {
PageHelper pageHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -41,59 +44,49 @@ public class MainActivity extends AppCompatActivity {
}
@Override
protected void onResume(){
protected void onResume() {
super.onResume();
TextView tv = findViewById(R.id.tv_hello);
textViewAppendString(tv,"Starting Initialize");
textViewAppendString(tv, "Starting Initialize");
if (Build.VERSION.SDK_INT >= 33) {
textViewAppendString(tv,"Find api > 33, checking permission");
textViewAppendString(tv, "Find api > 33, checking permission");
if (ContextCompat
.checkSelfPermission
(MainActivity.this, Manifest.permission.POST_NOTIFICATIONS)
!= PackageManager.PERMISSION_GRANTED) {
textViewAppendString(tv,"Acquiring POST_NOTIFICATIONS");
(MainActivity.this, Manifest.permission.POST_NOTIFICATIONS)
!= PackageManager.PERMISSION_GRANTED) {
textViewAppendString(tv, "Acquiring POST_NOTIFICATIONS");
ActivityCompat.requestPermissions
(MainActivity.this,
new String[]{Manifest.permission.POST_NOTIFICATIONS},
101);
}
textViewAppendString(tv,"Check Finished");
textViewAppendString(tv,"提示:常桉有惊喜");
textViewAppendString(tv, "Check Finished");
textViewAppendString(tv, "提示:常按有惊喜");
}
textViewAppendString(tv,"*************************\nfinished");
textViewAppendString(tv, "*************************\nfinished");
// Initialize Page Helper
pageHelper = new PageHelper(this,null,MainActivity2.class,this);
pageHelper = new PageHelper(this, null, MainActivity2.class, this);
Button button = findViewById(R.id.Page1NextPage);
button.setEnabled(true);
button.setOnClickListener(pageHelper.pageButtonHandler);
button.setOnLongClickListener(new LongClickHandler(this));
Button SettingPageButton = findViewById(R.id.P1OpenAppSettingsLayout);
SettingPageButton.setOnClickListener(new SettingPageHandler());
}
private void textViewAppendString(@NonNull TextView tv, String s){
private void textViewAppendString(@NonNull TextView tv, String s) {
String last = tv.getText().toString();
if (!last.endsWith("\n")){
if (!last.endsWith("\n")) {
last += "\n";
}
last += s;
tv.setText(last);
}
private final class LongClickHandler implements View.OnLongClickListener
{
LongClickHandler(Context ctx){
context = ctx;
}
Context context;
@Override
public boolean onLongClick(View v){
CreateShortcut(context);
return false;
}
}
private void CreateShortcut(Context context) {
ShortcutManager shortcutManager =
this.getSystemService(ShortcutManager.class);
@ -102,7 +95,7 @@ public class MainActivity extends AppCompatActivity {
try {
pinShortcutInfo =
new ShortcutInfo.Builder(context, "start_TODO").build();
}catch (Exception e){
} catch (Exception e) {
Log.e("ShortCutManager", Arrays.toString(e.getStackTrace()));
return;
}
@ -117,4 +110,29 @@ public class MainActivity extends AppCompatActivity {
successCallback.getIntentSender());
}
}
private final class LongClickHandler implements View.OnLongClickListener {
final Context context;
LongClickHandler(Context ctx) {
context = ctx;
}
@Override
public boolean onLongClick(View v) {
CreateShortcut(context);
return false;
}
}
private final class SettingPageHandler implements View.OnClickListener {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(),SettingPage.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}
}
}

View file

@ -10,6 +10,9 @@ import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
@ -18,11 +21,18 @@ import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity2 extends AppCompatActivity {
import uk.kagurach.android101.helper.ColorHelper;
import uk.kagurach.android101.helper.PageHelper;
import uk.kagurach.android101.helper.ToastHelper;
public class MainActivity2 extends KaBaseActivity {
PageHelper pageHelper;
int _text_size = 70;
int _text_color = Color.rgb(0,0,0);
String _text_unit = "sp";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -33,44 +43,61 @@ public class MainActivity2 extends AppCompatActivity {
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
pageHelper = new PageHelper(this,MainActivity.class,Page3.class);
pageHelper = new PageHelper(this, MainActivity.class, Page3.class);
}
@Override
protected void onResume(){
protected void onResume() {
super.onResume();
Button button = findViewById(R.id.next_page_nav_2);
button.setOnClickListener(pageHelper.pageButtonHandler);
button.setOnLongClickListener(pageHelper.longClickHandler);
Button SettingButton = findViewById(R.id.P2OpenSettingsButton);
SettingButton.setOnClickListener(new SettingButtonHandler());
ImageButton CloseSettingButton = findViewById(R.id.P2SettingsCloseButton);
CloseSettingButton.setOnClickListener(new CloseSettingButtonHandler());
Button TestColorButton = findViewById(R.id.P2TestColorButton);
TestColorButton.setOnClickListener(new TestColorButtonHandler());
}
public void set70sp(View view) {
public void setUnit_sp(View view) {
TextView t = findViewById(R.id.test2strview);
t.setTextSize(TypedValue.COMPLEX_UNIT_SP,_text_size);
t.setTextSize(TypedValue.COMPLEX_UNIT_SP, _text_size);
_text_unit = "sp";
updateCurrentSettingShower();
}
public void set70dp(View view) {
public void setUnit_dp(View view) {
TextView t = findViewById(R.id.test2strview);
t.setTextSize(TypedValue.COMPLEX_UNIT_DIP,_text_size);
t.setTextSize(TypedValue.COMPLEX_UNIT_DIP, _text_size);
_text_unit = "dp";
updateCurrentSettingShower();
}
public void set70px(View view) {
public void setUnit_px(View view) {
TextView t = findViewById(R.id.test2strview);
t.setTextSize(TypedValue.COMPLEX_UNIT_PX,_text_size);
t.setTextSize(TypedValue.COMPLEX_UNIT_PX, _text_size);
_text_unit = "px";
updateCurrentSettingShower();
}
public void setColor(View view) {
TextView t = findViewById(R.id.test2strview);
EditText r_edit = findViewById(R.id.EditText_R);
EditText g_edit = findViewById(R.id.G);
EditText b_edit = findViewById(R.id.B);
EditText r_edit = findViewById(R.id.P2SetColorR);
EditText g_edit = findViewById(R.id.P2SetColorG);
EditText b_edit = findViewById(R.id.P2SetColorB);
int _r,_g,_b;
int _r, _g, _b;
// Here we are testing toast
if( r_edit.getText().toString().isEmpty() ||
g_edit.getText().toString().isEmpty()||
b_edit.getText().toString().isEmpty() ){
if (r_edit.getText().toString().isEmpty() ||
g_edit.getText().toString().isEmpty() ||
b_edit.getText().toString().isEmpty()) {
ToastHelper.SmartToast.ShowToast("""
Please input R,G,B within 0-255
请在大小选择下方输入0-255的RGB""",
@ -81,26 +108,29 @@ public class MainActivity2 extends AppCompatActivity {
_r = Integer.parseInt(r_edit.getText().toString());
_g = Integer.parseInt(g_edit.getText().toString());
_b = Integer.parseInt(b_edit.getText().toString());
} catch (NumberFormatException e){
ToastHelper.SmartToast.ShowToast(e.toString(),this);
} catch (NumberFormatException e) {
ToastHelper.SmartToast.ShowToast(e.toString(), this);
return;
}
if (_r>=0&&_g>=0&&_b>=0&&_r<=255&&_g<=255&&_b<=255){
t.setTextColor(Color.rgb(_r,_g,_b));
}else{
if (_r >= 0 && _g >= 0 && _b >= 0 && _r <= 255 && _g <= 255 && _b <= 255) {
_text_color = Color.rgb(_r, _g, _b);
t.setTextColor(_text_color);
} else {
ToastHelper.SmartToast.ShowToast(
"The color: R="+_r+" G="+_g+" B="+_b+" is invalid!",this);
"The color: R=" + _r + " G=" + _g + " B=" + _b + " is invalid!", this);
}
updateCurrentSettingShower();
}
public void setText(View view) {
TextView textView = findViewById(R.id.test2strview);
EditText editText = findViewById(R.id.Page2SetTestText);
String s;
try {
s = editText.getText().toString();
}catch (Exception e){
ToastHelper.SmartToast.ShowToast(e.toString(),this);
} catch (Exception e) {
ToastHelper.SmartToast.ShowToast(e.toString(), this);
return;
}
textView.setText(s);
@ -116,21 +146,108 @@ public class MainActivity2 extends AppCompatActivity {
int size;
try {
size = Integer.parseInt(ed.getText().toString());
}catch (Exception e){
ToastHelper.SmartToast.ShowToast(e.toString(),this);
} catch (Exception e) {
ToastHelper.SmartToast.ShowToast(e.toString(), this);
return;
}
_text_size = size;
sp.setText(size +"SP");
dp.setText(size +"DP");
px.setText(size +"PX");
sp.setText(size + "SP");
dp.setText(size + "DP");
px.setText(size + "PX");
updateCurrentSettingShower();
}
private void updateCurrentSettingShower(){
TextView tv = findViewById(R.id.P2SettingResult);
String sb = "Color = " +
new ColorHelper().toString(_text_color,"#",false) +
"; TextSize = " +
_text_size +
"." +
_text_unit;
tv.setText(sb);
}
class SettingButtonHandler implements View.OnClickListener{
@Override
public void onClick(View v) {
FrameLayout fl = findViewById(R.id.P2SettingPage);
fl.setVisibility(View.VISIBLE);
// Disable NextPage Button
Button nextPageButton = findViewById(R.id.next_page_nav_2);
nextPageButton.setEnabled(false);
}
}
class CloseSettingButtonHandler implements View.OnClickListener{
@Override
public void onClick(View v) {
FrameLayout fl = findViewById(R.id.P2SettingPage);
fl.setVisibility(View.GONE);
// Close Input Method
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
Button nextPageButton = findViewById(R.id.next_page_nav_2);
nextPageButton.setEnabled(true);
}
}
class TestColorButtonHandler implements View.OnClickListener{
@Override
public void onClick(View v) {
ImageView imageView = findViewById(R.id.P2ColorShower);
int _test_color = 0;
EditText r_edit = findViewById(R.id.P2SetColorR);
EditText g_edit = findViewById(R.id.P2SetColorG);
EditText b_edit = findViewById(R.id.P2SetColorB);
int _r, _g, _b;
// Here we are testing toast
if (r_edit.getText().toString().isEmpty() ||
g_edit.getText().toString().isEmpty() ||
b_edit.getText().toString().isEmpty()) {
ToastHelper.SmartToast.ShowToast("""
Please input R,G,B within 0-255
请在大小选择下方输入0-255的RGB""",
v.getContext());
}
try {
_r = Integer.parseInt(r_edit.getText().toString());
_g = Integer.parseInt(g_edit.getText().toString());
_b = Integer.parseInt(b_edit.getText().toString());
} catch (NumberFormatException e) {
ToastHelper.SmartToast.ShowToast(e.toString(), v.getContext());
return;
}
if (_r >= 0 && _g >= 0 && _b >= 0 && _r <= 255 && _g <= 255 && _b <= 255) {
_test_color = Color.rgb(_r, _g, _b);
imageView.setBackgroundColor(_test_color);
} else {
ToastHelper.SmartToast.ShowToast(
"The color: R=" + _r + " G=" + _g + " B=" + _b + " is invalid!", v.getContext());
}
}
}
// Fix: hide keyboard
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (getCurrentFocus() != null) {
// If the Setting float window shows, do nothing
FrameLayout fl = findViewById(R.id.P2SettingPage);
if (fl!=null){
if (fl.getVisibility() == View.VISIBLE){
return super.dispatchTouchEvent(ev);
}
}
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}

View file

@ -9,28 +9,30 @@ import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat.getSystemService
import kotlin.random.Random
class NotificationHelper(_ctx: Context) {
val CHANNEL_ID = "DBG_PUSHER"
val name = "Debug Pusher"
var ctx: Context = _ctx
companion object { // Make notify id always increase
var notifyID = 1
}
private val notificationManager =
getSystemService(ctx,NotificationManager::class.java) as NotificationManager
getSystemService(ctx, NotificationManager::class.java) as NotificationManager
fun pushNotification(title:String,content:String) {
fun pushNotification(title: String, content: String) {
val builder = NotificationCompat.Builder(ctx, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle(title)
.setContentText(content)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true)
.setStyle(NotificationCompat.BigTextStyle()
.bigText(content))
.setStyle(
NotificationCompat.BigTextStyle()
.bigText(content)
)
with(NotificationManagerCompat.from(ctx)) {
if (ActivityCompat.checkSelfPermission(
@ -55,7 +57,7 @@ class NotificationHelper(_ctx: Context) {
notificationManager.createNotificationChannel(channel)
}
protected fun deleteNotificationChannel(){
protected fun deleteNotificationChannel() {
notificationManager.deleteNotificationChannel(CHANNEL_ID)
}
}

View file

@ -1,6 +1,6 @@
package uk.kagurach.android101;
import static uk.kagurach.android101.KaculateKt.Kaculate;
import static uk.kagurach.android101.misc.KaculateKt.Kaculate;
import android.os.Bundle;
import android.view.View;
@ -14,11 +14,12 @@ import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import java.util.List;
import uk.kagurach.android101.helper.PageHelper;
public class Page3 extends AppCompatActivity {
public class Page3 extends KaBaseActivity {
PageHelper pageHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -30,7 +31,7 @@ public class Page3 extends AppCompatActivity {
return insets;
});
pageHelper = new PageHelper(this,MainActivity2.class,Page4.class);
pageHelper = new PageHelper(this, MainActivity2.class, Page4.class);
findViewById(R.id.P3_0).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3_1).setOnClickListener(new CalculateOnClickListener());
@ -59,62 +60,7 @@ public class Page3 extends AppCompatActivity {
findViewById(R.id.P3Nextpage).setOnLongClickListener(pageHelper.longClickHandler);
}
class CalculateOnClickListener implements View.OnClickListener{
@Override
public void onClick(View v){
TextView tv = findViewById(R.id.P3CalcResult);
String s = tv.getText().toString();
String o = ((Button)v).getText().toString();
Button dot = findViewById(R.id.P3Dot);
switch (o){
case "退格":
if (!s.isEmpty()){
if (s.length()==1){
s = "";
dot.setEnabled(true);
setOpButton(true);
findViewById(R.id.P3EqualButton).setEnabled(true);
}else {
s = s.substring(0, s.length() - 1);
dot.setEnabled(!isNumberWithDot(s));
setOpButton(s.substring(s.length()-1).matches("\\d|\\."));
}
}
break;
case "CE":
s = "";
dot.setEnabled(true);
setOpButton(true);
findViewById(R.id.P3EqualButton).setEnabled(true);
break;
case "=":
calc();
s = tv.getText().toString();
dot.setEnabled(!s.contains("."));
setOpButton(true);
findViewById(R.id.P3EqualButton).setEnabled(
!s.toLowerCase().contains("n")); // For Inf & NaN
return;
case ".":
dot.setEnabled(false);
s+='.';
break;
default:
s += o;
if (o.matches("\\d")) { // If inputted a number
setOpButton(true);
}else{ // Else an operator
dot.setEnabled(true);
setOpButton(false);
}
}
tv.setText(s);
}
}
private void setOpButton(boolean state){
private void setOpButton(boolean state) {
findViewById(R.id.P3X).setEnabled(state);
findViewById(R.id.P3Plus).setEnabled(state);
findViewById(R.id.P3Minus).setEnabled(state);
@ -122,25 +68,25 @@ public class Page3 extends AppCompatActivity {
findViewById(R.id.P3ChengFang).setEnabled(state);
}
private boolean isNumberWithDot(@NonNull String s){
if (!s.contains(".")){
private boolean isNumberWithDot(@NonNull String s) {
if (!s.contains(".")) {
return false;
}
boolean hasDot = false;
for (int i = s.length()-1; i >= 0; i--) {
for (int i = s.length() - 1; i >= 0; i--) {
char c = s.charAt(i);
if (c=='+'||c=='-'||c=='x'||c=='/'||c=='^'){
if (c == '+' || c == '-' || c == 'x' || c == '/' || c == '^') {
return hasDot;
}else if (c=='.'){
} else if (c == '.') {
hasDot = true;
}
}
return hasDot;
}
private void calc(){
private void calc() {
TextView textView = findViewById(R.id.P3CalcResult);
String result = Kaculate(textView.getText().toString(),this);
String result = Kaculate(textView.getText().toString(), this);
if (result.contains(".")) { // In case of Infinity or NaN as a result
int i = 0;
@ -162,4 +108,58 @@ public class Page3 extends AppCompatActivity {
textView.setText(result);
}
class CalculateOnClickListener implements View.OnClickListener {
@Override
public void onClick(View v) {
TextView tv = findViewById(R.id.P3CalcResult);
String s = tv.getText().toString();
String o = ((Button) v).getText().toString();
Button dot = findViewById(R.id.P3Dot);
switch (o) {
case "退格":
case "BackSpace":
if (!s.isEmpty()) {
if (s.length() == 1) {
s = "";
dot.setEnabled(true);
setOpButton(true);
findViewById(R.id.P3EqualButton).setEnabled(true);
} else {
s = s.substring(0, s.length() - 1);
dot.setEnabled(!isNumberWithDot(s));
setOpButton(s.substring(s.length() - 1).matches("\\d|\\."));
}
}
break;
case "CE":
s = "";
dot.setEnabled(true);
setOpButton(true);
findViewById(R.id.P3EqualButton).setEnabled(true);
break;
case "=":
calc();
s = tv.getText().toString();
dot.setEnabled(!s.contains("."));
setOpButton(true);
findViewById(R.id.P3EqualButton).setEnabled(
!s.toLowerCase().contains("n")); // For Inf & NaN
return;
case ".":
dot.setEnabled(false);
s += '.';
break;
default:
s += o;
if (o.matches("\\d")) { // If inputted a number
setOpButton(true);
} else { // Else an operator
dot.setEnabled(true);
setOpButton(false);
}
}
tv.setText(s);
}
}
}

View file

@ -1,9 +1,12 @@
package uk.kagurach.android101;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
@ -11,16 +14,20 @@ import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class Page4 extends AppCompatActivity {
import uk.kagurach.android101.helper.PageHelper;
import uk.kagurach.android101.misc.vibrationBroadcastReceiver.vibrationBroadcastReceiver;
public class Page4 extends KaBaseActivity {
PageHelper pageHelper;
ActivityResultLauncher mLauncher;
ActivityResultLauncher<Intent> mLauncher;
long startTime = 0;
long endTime = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -32,49 +39,74 @@ public class Page4 extends AppCompatActivity {
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
pageHelper = new PageHelper(this, Page3.class,Page5.class);
pageHelper = new PageHelper(this, Page3.class, Page5.class);
Button askAI = findViewById(R.id.P4AskAI);
askAI.setOnClickListener(new ButtonHandler());
Button nextPage = findViewById(R.id.P4PageButton);
nextPage.setOnClickListener(pageHelper.pageButtonHandler);
nextPage.setOnLongClickListener(pageHelper.longClickHandler);
mLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
if (result!=null && result.getResultCode() == RESULT_OK ){
assert result.getData() != null;
Bundle bundle = result.getData().getExtras();
if (bundle!=null) {
String response = bundle.getString("reply");
TextView tv = findViewById(R.id.P4Result);
tv.setText(response);
}
Button vibrate = findViewById(R.id.P4Vibrate);
vibrate.setOnClickListener(new VibrateButtonHandler());
mLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
if (result != null && result.getResultCode() == RESULT_OK) {
assert result.getData() != null;
Bundle bundle = result.getData().getExtras();
if (bundle != null) {
String response = bundle.getString("reply");
TextView tv = findViewById(R.id.P4Result);
tv.setText(response);
}
endTime = System.currentTimeMillis();
TextView timetv = findViewById(R.id.P4AIRuntime);
timetv.setText("使用了" + (endTime - startTime) + "毫秒");
}
);
});
}
private void callOtherActivity(){
private void callOtherActivity() {
EditText editText = findViewById(R.id.P4Ask);
String request = editText.getText().toString();
Intent intent = new Intent(this,Page4OtherActivity.class);
Intent intent = new Intent(this, Page4OtherActivity.class);
Bundle bundle = new Bundle();
bundle.putString("request_content",request);
bundle.putString("request_content", request);
intent.putExtras(bundle);
TextView tv = findViewById(R.id.P4Result);
tv.setText("正在询问AI");
startTime = System.currentTimeMillis();
mLauncher.launch(intent);
}
private final class ButtonHandler implements View.OnClickListener
{
@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);
}
private final class ButtonHandler implements View.OnClickListener {
@Override
public void onClick(View v){
public void onClick(View v) {
callOtherActivity();
}
}
private final class VibrateButtonHandler implements View.OnClickListener {
@Override
public void onClick(View v) {
String receivierPath = "uk.kagurach.android101.vibrationBroadcastReceiver.vibrationBroadcastReceiver";
Intent intent = new Intent(vibrationBroadcastReceiver.VIBRATION_ACTION_NAME);
ComponentName componentName = new ComponentName("uk.kagurach.android101",receivierPath);
intent.setComponent(componentName);
sendBroadcast(intent);
}
}
}

View file

@ -1,11 +1,15 @@
package uk.kagurach.android101;
import static uk.kagurach.misc.AIAnswerServiceKt.AIAnswerService;
import static uk.kagurach.android101.misc.AIAnswerServiceKt.AIAnswerService;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import uk.kagurach.android101.helper.ToastHelper;
public class Page4OtherActivity extends AppCompatActivity {
@Override
@ -14,17 +18,30 @@ public class Page4OtherActivity extends AppCompatActivity {
Bundle bundle = getIntent().getExtras();
if (bundle == null) throw new NullPointerException();
String content = bundle.getString("request_content");
if (content!=null){
if (content != null) {
if (content.contains("想似") ||
content.contains("相似") ||
content.contains("相死") ||
content.contains("想死")) {
ToastHelper.SmartToast.ShowToast("不可以!", this);
Log.wtf("呜呜", "要好好活着");
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(-1);
}
content = AIAnswerService(content);
}else {
} else {
content = "对不起坏掉了";
}
Intent intent = new Intent();
Bundle bundle1 = new Bundle();
bundle1.putString("reply",content);
bundle1.putString("reply", content);
intent.putExtras(bundle1);
setResult(RESULT_OK,intent);
setResult(RESULT_OK, intent);
finish();
}
}

View file

@ -1,6 +1,15 @@
package uk.kagurach.android101;
import android.content.Context;
import android.os.Bundle;
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.FrameLayout;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
@ -8,8 +17,19 @@ import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class Page5 extends AppCompatActivity {
import java.io.IOException;
import java.util.Objects;
import chatgpt.AnimalDatabaseHelper;
import uk.kagurach.android101.helper.PageHelper;
import uk.kagurach.android101.helper.ToastHelper;
import uk.kagurach.android101.helper.AutoCompleHelper.AnimalTypeAutoCompleteHelper;
public class Page5 extends KaBaseActivity {
AnimalTypeAutoCompleteHelper completeHelper = null;
final AnimalDatabaseHelper dbHelper = new AnimalDatabaseHelper(this);
PageHelper pageHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -20,5 +40,134 @@ public class Page5 extends AppCompatActivity {
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
pageHelper = new PageHelper(this, Page4.class,null);
// 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 AddAnimalButtonHandler());
Button P5CleanDataButton = findViewById(R.id.P5CleanDataButton);
P5CleanDataButton.setOnLongClickListener(new CleanButtonHandler());
Button P5CloseQueryButton = findViewById(R.id.P5CloseQueryButton);
P5CloseQueryButton.setOnClickListener(new P5CloseQueryButtonHandler());
Button P5QueryButton = findViewById(R.id.P5QueryButton);
P5QueryButton.setOnClickListener(new QueryButtonHandler());
Button P5NextPage = findViewById(R.id.P5NextPage);
P5NextPage.setOnClickListener(pageHelper.pageButtonHandler);
P5NextPage.setOnLongClickListener(pageHelper.longClickHandler);
}
}
class AddAnimalButtonHandler implements View.OnClickListener {
@Override
public void onClick(View v) {
TextView name = findViewById(R.id.P5AnimalNameInput);
AutoCompleteTextView type = findViewById(R.id.AnimalTypeAutoCompleteInput);
String animal_name = name.getText().toString();
String animal_type = type.getText().toString();
if (animal_name.isEmpty()||animal_type.isEmpty()){
ToastHelper.SmartToast.ShowToast("Please input all fields",v.getContext());
return;
}
// Add to database
if (dbHelper.insertAnimalData(animal_name, animal_type.replace(" ","_"))) {
// Insert was successful
ToastHelper.SmartToast.ShowToast( "Animal added successfully!",v.getContext());
} else {
// Name already exists
ToastHelper.SmartToast.ShowToast( "Animal with this name already exists!",v.getContext());
return;
}
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
));
}
}
class CleanButtonHandler implements View.OnLongClickListener {
@Override
public boolean onLongClick(View v) {
AutoCompleteTextView _a = findViewById(R.id.AnimalTypeAutoCompleteInput);
try {
completeHelper.Clean();
} catch (IOException e) {
throw new RuntimeException(e);
}
_a.setAdapter(
completeHelper.GetArrayAdapter(
v.getContext(),android.R.layout.simple_list_item_1
));
ToastHelper.SmartToast.ShowToast("Cleaned Data",v.getContext());
// Clean DataBase
dbHelper.clearTable();
ToastHelper.SmartToast.ShowToast("Cleaned Database",v.getContext());
return true;
}
}
class P5CloseQueryButtonHandler implements View.OnClickListener{
@Override
public void onClick(View v) {
FrameLayout fl = findViewById(R.id.P5Flyout);
fl.setVisibility(View.GONE);
}
}
class QueryButtonHandler implements View.OnClickListener{
@Override
public void onClick(View v) {
String res = dbHelper.getAllDataAsString();
if (res.isEmpty()){
res = "No animals qwq";
}
TextView tv = findViewById(R.id.P5QueryResult);
tv.setText(res);
FrameLayout fl = findViewById(R.id.P5Flyout);
fl.setVisibility(View.VISIBLE);
}
}
@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);
}
}

View file

@ -0,0 +1,78 @@
package uk.kagurach.android101
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import kotlinx.coroutines.runBlocking
import uk.kagurach.android101.databinding.ActivitySettingPageBinding
val Context.datastore by preferencesDataStore(name = "settings")
val DefaultColor = intPreferencesKey("default_color")
class SettingPage : KaBaseActivity() {
lateinit var binding: ActivitySettingPageBinding
lateinit var settingStorage: SettingStorage
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_setting_page)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
binding = ActivitySettingPageBinding.inflate(layoutInflater)
setContentView(binding.root)
settingStorage = SettingStorage(this)
binding.ThemeRed.setOnClickListener(SetColorHandler())
binding.ThemeBlue.setOnClickListener(SetColorHandler())
binding.ThemeCyan.setOnClickListener(SetColorHandler())
binding.ThemePink.setOnClickListener(SetColorHandler())
binding.ThemeGreen.setOnClickListener(SetColorHandler())
binding.SettingPageSubmit.setOnClickListener(FinishButtonHandler())
}
inner class SetColorHandler: View.OnClickListener {
override fun onClick(v: View?) {
if (v == null){
return
}
val colorTheme = when(v.id){
R.id.ThemeBlue -> R.style.Theme_Blue
R.id.ThemeGreen -> R.style.Theme_Green
R.id.ThemeRed -> R.style.Theme_Red
R.id.ThemeCyan -> R.style.Theme_Cyan
R.id.ThemePink -> R.style.Theme_Pink
else -> {throw RuntimeException("Impossible branch met!")}
}
runBlocking {
settingStorage.setDefaultTheme(colorTheme)
}
val intent = Intent(v.context,this@SettingPage::class.java)
startActivity(intent)
finish()
}
}
inner class FinishButtonHandler: View.OnClickListener{
override fun onClick(v: View?) {
val intent = Intent(v!!.context,MainActivity::class.java)
startActivity(intent)
finish()
}
}
}

View file

@ -0,0 +1,28 @@
package uk.kagurach.android101
import android.content.Context
import androidx.datastore.preferences.core.edit
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
class SettingStorage(val context: Context) {
suspend fun getDefaultTheme(): Int {
return getDefaultColorFlow.first()
}
suspend fun setDefaultTheme(newValue: Int) {
context.datastore.edit {
preferences ->
preferences[DefaultColor] = newValue
}
}
private val getDefaultColorFlow: Flow<Int> =
context.datastore.data
.map {
preferences ->
preferences[DefaultColor] ?: R.id.ThemeBlue
}
}

View file

@ -1,27 +0,0 @@
package uk.kagurach.android101
import android.content.Context
import android.widget.Toast
class ToastHelper(text: String,ctx: Context) {
val _text = text
val _ctx = ctx
companion object SmartToast {
fun ShowToast(text: String,ctx: Context){
val helper = ToastHelper(text,ctx)
helper.autoShow()
}
}
fun autoShow(){
if (_text.contains('\n')){
for (line in _text.split('\n')){
Toast.makeText(_ctx,line,Toast.LENGTH_SHORT).show()
Thread.sleep(Toast.LENGTH_SHORT.toLong()+5)
}
}else{
Toast.makeText(_ctx,_text,Toast.LENGTH_LONG).show()
}
}
}

View file

@ -0,0 +1,22 @@
package uk.kagurach.android101.baoleme
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import uk.kagurach.android101.KaBaseActivity
import uk.kagurach.android101.R
class BaolemaMainActivity : KaBaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.baolema_main)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
}
}

View file

@ -0,0 +1,93 @@
package uk.kagurach.android101.helper.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 {
while (scanner.hasNextLine()){
data.add(scanner.nextLine());
}
// 去重
Set<String> set = new LinkedHashSet<>(data);
data = new ArrayList<>(set);
}
}
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);
public void Clean() throws IOException {
if (dataFile!=null){
File _data = new File(dataFile);
if (!_data.isFile()){
_data.createNewFile();
}
if (!_data.canRead() || !_data.canWrite()){
throw new RuntimeException("File permission denied");
}
try (FileWriter fileWriter = new FileWriter(_data,false)) {
fileWriter.write("");
}catch (IOException e){
throw new IOException(e);
}
}
}
}

View file

@ -0,0 +1,48 @@
package uk.kagurach.android101.helper.AutoCompleHelper;
import android.content.Context;
import android.widget.ArrayAdapter;
import androidx.annotation.LayoutRes;
import java.io.File;
import java.io.IOException;
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");
}
name = name.replace(" ","_");
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);
}
}

View file

@ -0,0 +1,23 @@
package uk.kagurach.android101.helper
import android.graphics.Color
import androidx.compose.ui.util.fastJoinToString
class ColorHelper {
fun toColorInt(r: Int, g: Int, b: Int): Int {
if (r !in 0..255 || g !in 0..255 || b !in 0..255) {
throw Exception("RGB not in range")
}
return Color.rgb(r, g, b).and(0xffffff) // Preserve only low 48 bit
}
@OptIn(ExperimentalStdlibApi::class)
fun toString(colorInt: Int, start: String = "#", upperCase: Boolean = false): String {
val colorInt = colorInt.and(0xffffff) // Keep only low six digit
val colorString = colorInt.toHexString(
if (upperCase) { HexFormat.UpperCase }
else{ HexFormat.Default }
).drop(2)
return "$start$colorString"
}
}

View file

@ -1,4 +1,4 @@
package uk.kagurach.android101;
package uk.kagurach.android101.helper;
import static androidx.core.content.ContextCompat.startActivity;
@ -8,73 +8,84 @@ import android.content.Intent;
import android.view.View;
public class PageHelper {
private final Context _curr;
private final Class<?> _prev;
private final Class<?> _next;
private Activity _activity = null;
public final LongClickHandler longClickHandler = new LongClickHandler();
public final PageButtonHandler pageButtonHandler = new PageButtonHandler();
PageHelper(Context curr, Class<?> prev, Class<?> next){
private final Context _curr;
private final Class<?> _prev;
private final Class<?> _next;
private Activity _activity = null;
public PageHelper(Context curr, Class<?> prev, Class<?> next) {
_curr = curr;
_prev = prev;
_next = next;
}
PageHelper(Context curr, Class<?> prev, Class<?> next,Activity activity){
public PageHelper(Context curr, Class<?> prev, Class<?> next, Activity activity) {
_curr = curr;
_prev = prev;
_next = next;
_activity = activity;
}
void goPrev(){
if (_prev==null){
void goPrev(){// Keep no parameter signature
goPrev(true);
}
void goPrev(boolean keepOneInstance) {
if (_prev == null) {
return;
}
Intent myIntent = new Intent(_curr, _prev);
startActivity(_curr,myIntent,null);
if (keepOneInstance) {
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // 仅保留一个实例
}
startActivity(_curr, myIntent, null);
}
void goNext(){
if (_next==null){
void goNext() {
goNext(true);
}
void goNext(boolean keepOneInstance) {
if (_next == null) {
return;
}
Intent myIntent = new Intent(_curr, _next);
startActivity(_curr,myIntent,null);
if (keepOneInstance) {
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
startActivity(_curr, myIntent, null);
}
void goNextFinish(){
if (_activity == null){
void goNextFinish() {
if (_activity == null) {
throw new IllegalStateException("activity is null, cannot finish the activity");
}
if (_next==null){
if (_next == null) {
return;
}
Intent myIntent = new Intent(_curr, _next);
startActivity(_curr,myIntent,null);
startActivity(_curr, myIntent, null);
_activity.finish();
}
private final class LongClickHandler implements View.OnLongClickListener
{
private final class LongClickHandler implements View.OnLongClickListener {
@Override
public boolean onLongClick(View v){
public boolean onLongClick(View v) {
goPrev();
return false;
}
}
private final class PageButtonHandler implements View.OnClickListener
{
private final class PageButtonHandler implements View.OnClickListener {
@Override
public void onClick(View v){
public void onClick(View v) {
if (_activity == null) {
goNext();
}else {
} else {
goNextFinish();
}
}

View file

@ -0,0 +1,28 @@
package uk.kagurach.android101.helper
import android.content.Context
import android.widget.Toast
class ToastHelper(text: String, ctx: Context) {
val _text = text
val _ctx = ctx
companion object SmartToast {
fun ShowToast(text: String, ctx: Context) {
val helper = ToastHelper(text, ctx)
helper.autoShow()
}
}
fun autoShow() {
if (_text.contains('\n')) {
for (line in _text.split('\n')) {
Toast.makeText(_ctx, line, Toast.LENGTH_SHORT).show()
Thread.sleep(Toast.LENGTH_SHORT.toLong() + 5)
}
} else {
Toast.makeText(_ctx, _text, Toast.LENGTH_LONG).show()
}
}
}

View file

@ -0,0 +1,72 @@
package uk.kagurach.android101.misc
import java.time.Instant
import java.util.Date
import kotlin.random.Random
fun AIAnswerService(s: String): String {
val rng = Random(Date.from(Instant.now()).time)
var result = s
result = result.replace("", "?")
val isMoral = s.contains("")
val needAI = s.contains("")
result = result.replace("", "^")
result = result.replace("", "")
result = result.replace("", "@")
if (isMoral) {
result = if (rng.nextBoolean()) {
"谢谢@的提问,$result"
} else {
if (result.endsWith(".") ||
result.endsWith("") ||
result.endsWith("?")
) {
result = result.dropLast(1);
}
"$result,谢谢。"
}
result = result.replace("", "")
}
if (needAI) {
result = result.replace("", "")
}
result = result.replace(
"",""
)
result = result.replace(
"要要",""
)
result = result.replace(
"",
if (rng.nextBoolean()) {
"可以"
} else {
"不可以"
}
)
result = result.replace("什么", "很多")
result = result.replace("", "")
result = result.replace("?", "")
result = result.replace("^", "")
result = result.replace("@", "")
return result
}
fun main() {
println(AIAnswerService("我想要吃饭"))
println(AIAnswerService("咱可以吃饭吗"))
println(AIAnswerService("您可以做什么?"))
println(AIAnswerService("您吃了吗?"))
}

View file

@ -0,0 +1,127 @@
package uk.kagurach.android101.misc
import android.content.Context
import uk.kagurach.android101.helper.ToastHelper
import kotlin.math.pow
fun Kaculate(src: String, ctx: Context): String {
if (src.isBlank()) {
return src
}
val opList = charArrayOf('+', '-', 'x', '/', '^')
var numStack = floatArrayOf()
var opStack = charArrayOf()
var _curnum = ""
// Fix for expression starts with operator
val src = if (src[0] in opList){
"0$src"
}else{
src
}
for (i in src.indices) {
if (src[i] in '0'..'9' || src[i] == '.') {
_curnum += src[i]
} else if (src[i] in opList) {
try {
numStack += _curnum.toFloat()
_curnum = ""
} catch (e: Exception) {
ToastHelper.ShowToast(e.toString(), ctx)
return src
}
opStack += src[i]
} else {
ToastHelper.ShowToast("Unknown input char:" + src[i].toString(), ctx)
return src
}
}
if (_curnum.isNotEmpty()) {
try {
numStack += _curnum.toFloat()
} catch (e: Exception) {
ToastHelper.ShowToast(e.toString(), ctx)
return src
}
}
if (numStack.size != opStack.size + 1) {
ToastHelper.ShowToast("Ops and nums Not Match!", ctx)
return src
}
// ^
if ('^' in opStack) {
var intStackCurr = 0
for (i in opStack.indices) {
if (opStack[i] != '^') {
intStackCurr++
continue
}
val a = numStack[intStackCurr]
val b = numStack[intStackCurr + 1]
numStack[intStackCurr] = a.pow(b)
numStack = dropAtIdx(numStack, intStackCurr + 1)
}
var tmpStack = charArrayOf()
for(i in opStack){
if (i!='^'){
tmpStack += i
}
}
opStack = tmpStack
}
// x and /
var intStackCurr = 0
for (i in opStack.indices) {
if (opStack[i] != 'x' && opStack[i] != '/') {
intStackCurr++
continue
}
val a = numStack[intStackCurr]
val b = numStack[intStackCurr + 1]
if (opStack[i] == 'x') {
numStack[intStackCurr] = a * b
} else {
numStack[intStackCurr] = a / b
}
numStack = dropAtIdx(numStack, intStackCurr + 1)
}
// + and -
if (opStack.isNotEmpty()) {
for (i in opStack) {
if (i == '+') {
numStack[0] += numStack[1]
numStack = dropAtIdx(numStack, 1)
} else if (i == '-') {
numStack[0] -= numStack[1]
numStack = dropAtIdx(numStack, 1)
}
}
}
return numStack[0].toString()
}
private fun dropAtIdx(array: FloatArray, idx: Int): FloatArray {
if (idx > array.size) {
throw IndexOutOfBoundsException()
}
var newArray = floatArrayOf()
for (i in array.indices) {
if (i != idx) {
newArray += array[i]
}
}
return newArray
}

View file

@ -0,0 +1,30 @@
package uk.kagurach.android101.misc.vibrationBroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.CombinedVibration;
import android.os.VibrationEffect;
import android.os.VibratorManager;
import android.util.Log;
import java.util.Objects;
public class vibrationBroadcastReceiver extends BroadcastReceiver {
public static final String VIBRATION_ACTION_NAME = "uk.kagurach.android101.vibrationBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
if (Objects.equals(intent.getAction(), VIBRATION_ACTION_NAME)) {
VibratorManager vibrator = (VibratorManager) context.getSystemService(
Context.VIBRATOR_MANAGER_SERVICE
);
vibrator.vibrate(
CombinedVibration.createParallel(
VibrationEffect.createOneShot(1500,VibrationEffect.DEFAULT_AMPLITUDE)
));
Log.d("Debug","Vibrate!");
}
}
}

View file

@ -45,6 +45,7 @@ import androidx.core.content.ContextCompat
import uk.kagurach.android101.R
import uk.kagurach.android101.todoList.ui.theme.LightBlue100
import java.text.SimpleDateFormat
import java.util.Locale
class AddPage() : ComponentActivity() {
@ -73,12 +74,12 @@ class AddPage() : ComponentActivity() {
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AddPageLayout(){
fun AddPageLayout() {
val context = LocalContext.current
var title by remember {
mutableStateOf(
when (item){
when (item) {
null -> ""
else -> item!!.title
}
@ -88,8 +89,13 @@ class AddPage() : ComponentActivity() {
val timePickerState by remember {
mutableStateOf(
when (item){
null -> TimePickerState(c.get(Calendar.HOUR_OF_DAY),c.get(Calendar.MINUTE),true)
when (item) {
null -> TimePickerState(
c.get(Calendar.HOUR_OF_DAY),
c.get(Calendar.MINUTE),
true
)
else -> TimePickerState(
item!!.dueDate.split(" ")[1].split(":")[0].toInt(),
item!!.dueDate.split(" ")[1].split(":")[1].toInt(),
@ -103,7 +109,7 @@ class AddPage() : ComponentActivity() {
initialDisplayedMonthMillis = System.currentTimeMillis(),
yearRange = 2024..2099
)
Scaffold (
Scaffold(
topBar = {
Surface(
modifier = Modifier
@ -148,24 +154,24 @@ class AddPage() : ComponentActivity() {
floatingActionButtonPosition = FabPosition.End,
floatingActionButton = {
Submit {
if (title.isBlank()||datePickerState.selectedDateMillis==null){
Toast.makeText(context,"Please Fill Every field",Toast.LENGTH_SHORT)
if (title.isBlank() || datePickerState.selectedDateMillis == null) {
Toast.makeText(context, "Please Fill Every field", Toast.LENGTH_SHORT)
.show()
return@Submit
}
val loader = TodoItemLoader(context)
val sdf = SimpleDateFormat("yyyy-MM-dd")
val sdf = SimpleDateFormat("yyyy-MM-dd", Locale.CHINA)
val todoItem = TodoItem(
loader.getLastId()+1,
title.replace("\t"," "),
sdf.format(datePickerState.selectedDateMillis) + " " +
loader.getLastId() + 1,
title.replace("\t", " "),
sdf.format(datePickerState.selectedDateMillis) + " " +
timePickerState.hour.toString() + ":" +
timePickerState.minute.toString()
)
)
loader.changeItem(todoItem)
val myIntent = Intent(context, MainActivity::class.java)
val myIntent = Intent(context, TodoListMainActivity::class.java)
ContextCompat.startActivity(context, myIntent, null)
}
},

View file

@ -11,7 +11,7 @@ data class TodoItem(
var title: String,
var dueDate: String,
var isCompleted:Boolean = false,
var isCompleted: Boolean = false,
var MarkDeleted:Boolean = false
var MarkDeleted: Boolean = false
)

View file

@ -6,38 +6,38 @@ import java.io.File
import java.io.FileWriter
class TodoItemLoader(private val context: Context) {
private val db = File(context.filesDir,"db")
private val db = File(context.filesDir, "db")
public fun getTodoItems(): List<TodoItem>?{
if (!db.exists()){
public fun getTodoItems(): List<TodoItem>? {
if (!db.exists()) {
return null
}
val lines = db.readLines()
if (lines.isEmpty()){
if (lines.isEmpty()) {
return null
}
var list: List<TodoItem> = listOf()
for (line in lines){
for (line in lines) {
val split = line.split("\t")
val item: TodoItem
try {
item = TodoItem(split[0].toInt(),split[1],split[2], split[3].toBooleanStrict())
item = TodoItem(split[0].toInt(), split[1], split[2], split[3].toBooleanStrict())
list = list + item
} catch (e: Exception){
} catch (e: Exception) {
Log.e("DB Error", e.printStackTrace().toString())
}
}
if (list.isNotEmpty()){
if (list.isNotEmpty()) {
return list
}
return null
}
public fun saveTodoItems(list:List<TodoItem>){
public fun saveTodoItems(list: List<TodoItem>) {
var result = ""
for (i in list){
if(!i.MarkDeleted) {
for (i in list) {
if (!i.MarkDeleted) {
result += "%s\t%s\t%s\t%s\n".format(
i.id.toString(),
i.title,
@ -51,14 +51,14 @@ class TodoItemLoader(private val context: Context) {
fileWriter.close()
}
public fun getLastId():Int{
public fun getLastId(): Int {
val items = getTodoItems();
return if (items==null){
return if (items == null) {
0
}else{
} else {
var max = 0
for (i in items){
if (i.id>max){
for (i in items) {
if (i.id > max) {
max = i.id
}
}
@ -66,12 +66,12 @@ class TodoItemLoader(private val context: Context) {
}
}
public fun changeItem(todoItem: TodoItem){
public fun changeItem(todoItem: TodoItem) {
var items = getTodoItems()
var changeFlag = false
if (items != null) {
for (i in items){
if (i.id==todoItem.id){
for (i in items) {
if (i.id == todoItem.id) {
i.title = todoItem.title
i.dueDate = todoItem.dueDate
i.MarkDeleted = todoItem.MarkDeleted
@ -80,22 +80,22 @@ class TodoItemLoader(private val context: Context) {
break
}
}
if (!changeFlag){
if (!changeFlag) {
items = items + todoItem
}
}else{
} else {
items = listOf(todoItem)
}
saveTodoItems(items)
}
public fun searchItem(id:Int): TodoItem?{
public fun searchItem(id: Int): TodoItem? {
val items = getTodoItems();
return if (items==null){
return if (items == null) {
null
}else{
for (i in items){
if (i.id>id){
} else {
for (i in items) {
if (i.id > id) {
return i
}
}

View file

@ -24,7 +24,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.core.content.ContextCompat
import uk.kagurach.android101.todoList.ui.theme.LightBlue100
class MainActivity : ComponentActivity() {
class TodoListMainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
val loader = TodoItemLoader(this)
val tmpList = loader.getTodoItems()
@ -35,51 +35,52 @@ class MainActivity : ComponentActivity() {
}
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LayOut(tmpList : List<TodoItem>?) {
val context = LocalContext.current
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LayOut(tmpList: List<TodoItem>?) {
val context = LocalContext.current
Scaffold (
topBar = {
TopAppBar(
title = { Text("Simple TODO ^_^") }
)
},
content = {
padding ->
Surface(
modifier = Modifier.padding(padding)
.verticalScroll(rememberScrollState())
) {
if (tmpList != null) {
Column {
for (i in tmpList) {
TodoItemView(todoItem = i)
}
}
Scaffold(
topBar = {
TopAppBar(
title = { Text("Simple TODO ^_^") }
)
},
content = { padding ->
Surface(
modifier = Modifier
.padding(padding)
.verticalScroll(rememberScrollState())
) {
if (tmpList != null) {
Column {
for (i in tmpList) {
TodoItemView(todoItem = i)
}
}
},
floatingActionButtonPosition = FabPosition.End,
floatingActionButton = {
NextPage {
val myIntent = Intent(context, AddPage::class.java)
ContextCompat.startActivity(context, myIntent, null)
}
},
)
}
},
floatingActionButtonPosition = FabPosition.End,
floatingActionButton = {
NextPage {
val myIntent = Intent(context, AddPage::class.java)
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
ContextCompat.startActivity(context, myIntent, null)
}
},
)
}
@Composable
fun NextPage(onClick: () -> Unit) {
FloatingActionButton(
onClick = { onClick() },
containerColor = LightBlue100
) {
Icon(Icons.Filled.Add, "Floating action button.")
}
@Composable
fun NextPage(onClick: () -> Unit) {
FloatingActionButton(
onClick = { onClick() },
containerColor = LightBlue100
) {
Icon(Icons.Filled.Add, "Floating action button.")
}
}
}

View file

@ -42,7 +42,7 @@ fun TodoItemView(todoItem: TodoItem) {
}
var bgColor by remember {
mutableStateOf(
when (todoItem.isCompleted){
when (todoItem.isCompleted) {
true -> Green100
false -> Blue100
}
@ -51,7 +51,7 @@ fun TodoItemView(todoItem: TodoItem) {
var needShow by remember {
mutableStateOf(true)
}
if (!needShow){
if (!needShow) {
return
}
@ -68,14 +68,14 @@ fun TodoItemView(todoItem: TodoItem) {
start = 10.dp,
end = 10.dp
)
){
) {
Text(
text = todoItem.title,
color = Color.Black,
fontSize = 30.sp,
fontFamily = FontFamily.Monospace
)
Row{
Row {
Spacer(modifier = Modifier.weight(1f))
Text(
text = todoItem.dueDate,
@ -87,11 +87,12 @@ fun TodoItemView(todoItem: TodoItem) {
Row {
TextButton(
onClick = {
if (!todoItem.isCompleted){
Toast.makeText( context,
context.getText(R.string.yes_not_finish)
,Toast.LENGTH_SHORT).show()
}else{
if (!todoItem.isCompleted) {
Toast.makeText(
context,
context.getText(R.string.yes_not_finish), Toast.LENGTH_SHORT
).show()
} else {
todoItem.isCompleted = false
loader.changeItem(todoItem)
bgColor = Blue100
@ -105,11 +106,12 @@ fun TodoItemView(todoItem: TodoItem) {
Spacer(modifier = Modifier.width(20.dp))
TextButton(
onClick = {
if (todoItem.isCompleted){
Toast.makeText( context,
context.getText(R.string.already_finish)
,Toast.LENGTH_SHORT).show()
}else{
if (todoItem.isCompleted) {
Toast.makeText(
context,
context.getText(R.string.already_finish), Toast.LENGTH_SHORT
).show()
} else {
todoItem.isCompleted = true
loader.changeItem(todoItem)
bgColor = Green100
@ -123,9 +125,10 @@ fun TodoItemView(todoItem: TodoItem) {
Spacer(modifier = Modifier.width(20.dp))
TextButton(
onClick = {
when (deleteText){
when (deleteText) {
context.getText(R.string.first_delete).toString() ->
deleteText=context.getText(R.string.second_delete).toString()
deleteText = context.getText(R.string.second_delete).toString()
else -> {
needShow = false
todoItem.MarkDeleted = true
@ -147,12 +150,12 @@ fun TodoItemView(todoItem: TodoItem) {
@Preview(showBackground = true)
@Composable
fun TodoItemPreview(){
fun TodoItemPreview() {
val todoItem = TodoItem(
0,"Test TODO Item","2024-04-30 11:45",
0, "Test TODO Item", "2024-04-30 11:45",
)
val todoItem2 = TodoItem(
1,"测试喵","2024-11-01 22:33",true
1, "测试喵", "2024-11-01 22:33", true
)
Column {
TodoItemView(todoItem)
@ -160,8 +163,8 @@ fun TodoItemPreview(){
}
}
fun NextPage(context:Context,item: TodoItem) {
fun NextPage(context: Context, item: TodoItem) {
val myIntent = Intent(context, AddPage::class.java)
myIntent.putExtra("ITEM",item.id)
myIntent.putExtra("ITEM", item.id)
ContextCompat.startActivity(context, myIntent, null)
}

View file

@ -1,63 +0,0 @@
package uk.kagurach.misc
import java.time.Instant
import java.util.Date
import kotlin.random.Random
fun AIAnswerService(s: String):String {
val rng = Random(Date.from(Instant.now()).time)
var result = s
result = result.replace("","?")
val isMoral = s.contains("")
val needAI = s.contains("")
result = result.replace("","^")
result = result.replace("","")
result = result.replace("","@")
if (isMoral){
result = if (rng.nextBoolean()) {
"谢谢@的提问,$result"
} else{
if (result.endsWith(".")||
result.endsWith("")||
result.endsWith("?")){
result = result.dropLast(1);
}
"$result,谢谢。"
}
result = result.replace("","")
}
if (needAI){
result = result.replace("","")
}
result = result.replace("",
if (rng.nextBoolean()){
"可以"
}else{
"不可以"
}
)
result = result.replace("什么","很多")
result = result.replace("","")
result = result.replace("?","")
result = result.replace("^","")
result = result.replace("@","")
return result
}
fun main(){
println(AIAnswerService("我想吃饭"))
println(AIAnswerService("咱可以吃饭吗"))
println(AIAnswerService("您可以做什么?"))
println(AIAnswerService("您吃了吗?"))
}

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="m256,760 l-56,-56 224,-224 -224,-224 56,-56 224,224 224,-224 56,56 -224,224 224,224 -56,56 -224,-224 -224,224Z"
android:fillColor="#5f6368"/>
</vector>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#E8EAF6" />
<corners android:radius="20dp" />
<padding android:left="20dp"
android:top="20dp"
android:right="20dp"
android:bottom="20dp"/>
<stroke android:color="#6A000000" android:width="3dp"/>
</shape>

View file

@ -0,0 +1,9 @@
<!-- res/drawable/rounded_corner.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#B3E5FC" />
<corners android:radius="16dp" />
<padding android:left="16dp"
android:top="16dp"
android:right="16dp"
android:bottom="16dp"/>
</shape>

View file

@ -1,39 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
tools:context=".MainActivity"
tools:viewBindingIgnore="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:orientation="vertical"
android:layout_marginHorizontal="15dp"
android:layout_marginVertical="10dp"
>
<View
android:id="@+id/view"
<ScrollView
android:layout_width="match_parent"
android:layout_height="35dp" />
android:layout_height="wrap_content"
android:minHeight="500dp"
>
<TextView
android:id="@+id/tv_hello"
android:layout_width="match_parent"
android:layout_height="620dp"
android:text="@string/hello_world"
android:textSize="15sp"
android:visibility="visible" />
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_hello"
android:layout_width="match_parent"
android:layout_height="620dp"
android:text="@string/hello_world"
android:textSize="15sp"
android:visibility="visible" />
<Button
android:id="@+id/P1OpenAppSettingsLayout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/settings"
/>
</LinearLayout>
<Button
android:id="@+id/Page1NextPage"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginVertical="10dp"
android:layout_marginHorizontal="15dp"
android:layout_weight="1"
android:text="@string/next_page"
android:onClick="jumpToNext"
android:enabled="false"
/>
android:backgroundTint="?colorSecondary" />

View file

@ -5,165 +5,316 @@
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity2">
android:windowSoftInputMode="adjustResize"
tools:context=".MainActivity2"
tools:viewBindingIgnore="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="35dp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="350dp">
android:layout_height="300dp">
<TextView
android:id="@+id/test2strview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/test_str"
android:textSize="60sp"/>
android:textColor="#000000"
android:textSize="70sp"/>
</ScrollView>
<LinearLayout
<TextView
android:id="@+id/P2SettingResult"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="horizontal">
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:textSize="20sp"
android:text="@string/p2_default_setting"/>
<LinearLayout
android:layout_width="80dp"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/P2SetTextSize"
android:layout_width="80dp"
android:layout_height="0dp"
android:layout_weight="1"
android:ems="10"
android:inputType="number"
android:hint="字体大小"
/>
<Button
android:id="@+id/Page2SetSize"
android:layout_width="80dp"
android:layout_height="5dp"
android:layout_weight="1"
android:onClick="setSize"
android:text="设置" />
</LinearLayout>
<Button
android:id="@+id/Page2SetSP"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="set70sp"
android:text="70sp" />
<Button
android:id="@+id/Page2SetDP"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="set70dp"
android:text="70dp" />
<Button
android:id="@+id/Page2SetPX"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="set70px"
android:text="70px" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal">
<EditText
android:id="@+id/EditText_R"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:ems="10"
android:inputType="number"
android:hint="R:0-255"
/>
<EditText
android:id="@+id/G"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:ems="10"
android:inputType="number"
android:hint="G:0-255"
/>
<EditText
android:id="@+id/B"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:ems="10"
android:inputType="number"
android:hint="B:0-255"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_height="wrap_content"
android:minHeight="140dp"
android:orientation="horizontal">
<EditText
android:id="@+id/Page2SetTestText"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:ems="10"
android:importantForAutofill="no"
android:inputType="text"
android:text="测试文本"
android:text="@string/test_str"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="25dp"
android:hint="@string/test_str"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="20dp"
android:orientation="vertical"
>
<Button
android:id="@+id/Page2SetTestTextButton"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/setText"
android:onClick="setText"
android:backgroundTint="@color/tfb"
/>
<Button
android:id="@+id/P2OpenSettingsButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/settings"
android:backgroundTint="@color/tfp"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
android:orientation="vertical"
android:layout_marginHorizontal="20dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textAllCaps="false"
android:text="@string/font_size"
android:textSize="18sp"
android:layout_marginTop="5dp"/>
<Button
android:id="@+id/Page2SetColor"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/set_color"
android:onClick="setColor"/>
<Button
android:id="@+id/Page2SetSP"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="setUnit_sp"
android:layout_marginStart="5dp"
android:backgroundTint="?colorPrimary"
android:text="70sp" />
<Button
android:id="@+id/Page2SetDP"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="setUnit_dp"
android:layout_marginHorizontal="10dp"
android:backgroundTint="?colorSecondary"
android:text="70dp" />
<Button
android:id="@+id/Page2SetPX"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="setUnit_px"
android:text="70px"
android:backgroundTint="?colorTertiary"
tools:ignore="PxUsage" />
</LinearLayout>
<Button
android:id="@+id/next_page_nav_2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="20dp"
android:text="@string/two_way_page"
/>
</LinearLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/P2SettingPage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginHorizontal="20dp"
app:layout_constraintBottom_toBottomOf="parent"
android:background="@drawable/p2_settings_layout"
android:visibility="invisible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="@string/settings"
android:layout_weight="1"
android:textSize="35sp"
android:textColor="#B71C1C"
/>
<ImageButton
android:id="@+id/P2SettingsCloseButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="2dp"
android:background="@drawable/close_24"
android:contentDescription="@string/close" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:layout_marginVertical="5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/set_color"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
>
<EditText
android:id="@+id/P2SetColorR"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:ems="10"
android:importantForAutofill="no"
android:inputType="number"
android:hint="@string/rgb_r_range"
/>
<EditText
android:id="@+id/P2SetColorG"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:ems="10"
android:importantForAutofill="no"
android:inputType="number"
android:hint="@string/rgb_g_range"
android:layout_marginHorizontal="20dp"
/>
<EditText
android:id="@+id/P2SetColorB"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:ems="10"
android:importantForAutofill="no"
android:inputType="number"
android:hint="@string/rgb_b_range"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:layout_marginStart="10dp">
<ImageView
android:id="@+id/P2ColorShower"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginVertical="15dp"
android:background="@color/black"
android:contentDescription="@string/add" />
<Button
android:id="@+id/P2TestColorButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginStart="20dp"
android:text="@string/test_color"
android:backgroundTint="?colorPrimary"
android:textAllCaps="false"/>
<Button
android:id="@+id/Page2SetColor"
android:layout_width="0dp"
android:layout_marginStart="15dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/set_color"
android:textAllCaps="false"
android:backgroundTint="?colorTertiary"
android:onClick="setColor"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:layout_marginTop="15dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="@string/set_per_unit_font_size"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:layout_marginBottom="15dp"
>
<EditText
android:id="@+id/P2SetTextSize"
android:layout_width="0dp"
android:layout_height="match_parent"
android:ems="10"
android:layout_weight="1"
android:inputType="number"
android:hint="设置字体大小"
/>
<Button
android:id="@+id/Page2SetSize"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="30dp"
android:onClick="setSize"
android:textAllCaps="false"
android:backgroundTint="?colorTertiary"
android:text="@string/set" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,20 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Page3">
tools:context=".Page3"
tools:viewBindingIgnore="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="35dp" />
android:orientation="vertical">
<TextView
android:id="@+id/P3CalcName"
android:layout_width="match_parent"

View file

@ -1,34 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Page4">
tools:context=".Page4"
tools:viewBindingIgnore="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<View
android:layout_width="match_parent"
android:layout_height="50dp" />
android:layout_marginTop="10dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40sp"
android:text="@string/user"/>
<EditText
android:layout_width="match_parent"
android:layout_height="200dp"
android:textSize="40sp"
android:layout_height="wrap_content"
android:textSize="35sp"
android:layout_marginStart="10dp"
android:id="@+id/P4Ask"
android:importantForAutofill="no"
android:text="你吃了吗?"
android:text="@string/AI_ASK_DEFAULT_STRING"
android:textColor="@color/tfp"
android:hint="@string/AI_ASK_DEFAULT_STRING"
android:inputType="text" />
<View
android:layout_width="match_parent"
android:layout_height="50dp" />
@ -38,27 +39,51 @@
android:textSize="40sp"
android:text="@string/ai"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_marginStart="10dp">
<TextView
android:layout_width="match_parent"
android:textSize="35sp"
android:layout_height="wrap_content"
android:id="@+id/P4Result"
android:textColor="@color/tfb"
/>
</ScrollView>
<TextView
android:layout_width="match_parent"
android:textSize="40sp"
android:layout_height="200dp"
android:id="@+id/P4Result"
android:textColor="@color/tfb"
/>
android:layout_height="wrap_content"
android:textSize="25sp"
android:id="@+id/P4AIRuntime"
android:text="@string/ai_ready"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="130dp"
android:layout_marginHorizontal="5dp"
android:orientation="horizontal">
<Button
android:layout_width="140dp"
android:layout_marginVertical="20dp"
android:layout_height="match_parent"
android:id="@+id/P4AskAI"
android:text="@string/ask_ai"
/>
<Button
android:layout_width="120dp"
android:layout_marginVertical="20dp"
android:layout_marginHorizontal="10dp"
android:layout_height="match_parent"
android:id="@+id/P4Vibrate"
android:backgroundTint="?colorTertiary"
android:text="@string/vibrate"
/>
<Button
android:layout_width="match_parent"
android:layout_marginVertical="20dp"
android:layout_height="match_parent"
android:id="@+id/P4PageButton"
android:text="@string/next_page"

View file

@ -1,10 +1,158 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Page5">
tools:context=".Page5"
tools:viewBindingIgnore="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_marginTop="15dp"
android:background="#E0F7FA"
android:text="@string/animal_manage_system"
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:inputType="text"
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:inputType="text"
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_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="?colorTertiary"
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="?colorSecondary"
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>
<FrameLayout
android:id="@+id/P5Flyout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginVertical="50dp"
android:layout_marginHorizontal="20dp"
android:background="@drawable/p5_flyout_layout"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<TextView
android:id="@+id/P5QueryResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="monospace"
android:textSize="25sp"
/>
</ScrollView>
<Button
android:id="@+id/P5CloseQueryButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#FFF59D"
android:text="@string/close"
android:layout_marginVertical="10dp"
android:layout_marginHorizontal="30dp"
android:textColor="@color/black"
/>
</LinearLayout>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SettingPage"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/settings"
android:textSize="45sp"
android:fontFamily="serif-monospace"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginVertical="15dp"
android:layout_marginHorizontal="20sp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/set_default_theme"
android:textSize="30sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<ImageButton
android:id="@+id/ThemeBlue"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginVertical="15dp"
android:layout_marginStart="15dp"
android:background="#039BE5"
android:contentDescription="@string/add" />
<ImageButton
android:id="@+id/ThemeGreen"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginVertical="15dp"
android:layout_marginStart="30dp"
android:background="#43A047"
android:contentDescription="@string/add" />
<ImageButton
android:id="@+id/ThemeRed"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginVertical="15dp"
android:layout_marginStart="30dp"
android:background="#E57373"
android:contentDescription="@string/add" />
<ImageButton
android:id="@+id/ThemeCyan"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginVertical="15dp"
android:layout_marginStart="30dp"
android:background="#00ACC1"
android:contentDescription="@string/add" />
<ImageButton
android:id="@+id/ThemePink"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginVertical="15dp"
android:layout_marginStart="30dp"
android:background="#FF80AB"
android:contentDescription="@string/add" />
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/SettingPageSubmit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/finish_button"
android:textSize="35sp"
android:textAllCaps="false"
android:layout_marginBottom="20dp"
android:layout_marginHorizontal="60sp"
/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".baoleme.BaolemaMainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="8dp"
android:paddingBottom="15dp"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="15dp"
android:orientation="vertical"
android:background="?colorSecondary"
>
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="123456"
android:textSize="20sp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,14 +1,11 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- Base application theme. -->
<style name="Theme.Android101" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorPrimary">@color/tfb</item>
<item name="colorPrimaryVariant">@color/tfp </item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->

View file

@ -14,4 +14,36 @@
<string name="user">用户</string>
<string name="ai">AI</string>
<string name="ask_ai">询问AI</string>
<string name="ai_ready">AI 准备好了</string>
<string name="AI_ASK_DEFAULT_STRING">你吃了吗?</string>
<string name="vibrate">振动手机</string>
<string name="animal_manage_system">动物管理系统\n当前后端: SQLite</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>
<string name="close">关闭</string>
<string name="settings">设置</string>
<string name="test_color">测试颜色</string>
<string name="rgb_r_range">R:0-255</string>
<string name="rgb_g_range">G:0-255</string>
<string name="rgb_b_range">B:0-255</string>
<string name="set_per_unit_font_size">设置每个单位的字体大小</string>
<string name="font_size">字体\n大小</string>
<string name="p2_default_setting">Color = #000000; TextSize = 70.sp</string>
<string name="set_default_theme">设置默认主题</string>
<string name="finish_button">完成</string>
</resources>

View file

@ -1,10 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>

View file

@ -4,24 +4,46 @@
<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>
<string name="ask_ai">ASK AI</string>
<string name="ai_ready">AI Ready</string>
<string name="AI_ASK_DEFAULT_STRING">你吃了吗?</string>
<string name="vibrate">Vibrate</string>
<string name="animal_manage_system">Animal Manage System\nCurrent Backend: SQLite</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>
<string name="close">close</string>
<string name="settings">Settings</string>
<string name="test_color">Test color</string>
<string name="rgb_r_range">R:0-255</string>
<string name="rgb_g_range">G:0-255</string>
<string name="rgb_b_range">B:0-255</string>
<string name="set_per_unit_font_size">Set per unit font size</string>
<string name="font_size">Font\nSize</string>
<string name="p2_default_setting">Color = #000000; TextSize = 70.sp</string>
<string name="set_default_theme">Set Default Theme</string>
<string name="finish_button">Finish</string>
</resources>

View file

@ -1,20 +1,66 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- 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="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>
<item name="colorPrimary">#039BE5</item>
<item name="colorSecondary">#03e5bf</item>
<item name="colorTertiary">#e5039a</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<item name="overlapAnchor">false</item>
<item name="android:dropDownVerticalOffset">?attr/actionBarSize</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">#0D47A1</item>
<!-- Customize your theme here. -->
</style>
<style name="Theme.TODOList" parent="android:Theme.Material.Light.NoActionBar" />
<!-- Base application theme. -->
<style name="Base.Theme.TODOList" parent="Theme.Material3.DayNight.NoActionBar"/>
<style name="Theme.Blue" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="colorPrimary">#039BE5</item>
<item name="colorSecondary">#03e5bf</item>
<item name="colorTertiary">#e5039a</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">#0D47A1</item>
<item name="overlapAnchor">false</item>
<item name="android:dropDownVerticalOffset">?attr/actionBarSize</item>
</style>
<style name="Theme.Green" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="colorPrimary">#43A047</item>
<item name="colorSecondary">#a0439b</item>
<item name="colorTertiary">#439ba0</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">#0D47A1</item>
<item name="overlapAnchor">false</item>
<item name="android:dropDownVerticalOffset">?attr/actionBarSize</item>
</style>
<style name="Theme.Red" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="colorPrimary">#E57373</item>
<item name="colorSecondary">#e573ac</item>
<item name="colorTertiary">#73e573</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">#0D47A1</item>
<item name="overlapAnchor">false</item>
<item name="android:dropDownVerticalOffset">?attr/actionBarSize</item>
</style>
<style name="Theme.Cyan" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="colorPrimary">#00ACC1</item>
<item name="colorSecondary">#00c177</item>
<item name="colorTertiary">#c100aa</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">#0D47A1</item>
<item name="overlapAnchor">false</item>
<item name="android:dropDownVerticalOffset">?attr/actionBarSize</item>
</style>
<style name="Theme.Pink" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="colorPrimary">#FF80AB</item>
<item name="colorSecondary">#ff80ea</item>
<item name="colorTertiary">#ffb51f</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">#0D47A1</item>
<item name="overlapAnchor">false</item>
<item name="android:dropDownVerticalOffset">?attr/actionBarSize</item>
</style>
</resources>

View file

@ -9,7 +9,7 @@
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="uk.kagurach.android101"
android:targetClass="uk.kagurach.android101.todoList.MainActivity" />
android:targetClass="uk.kagurach.android101.todoList.TodoListMainActivity" />
<categories android:name="android.shortcut.conversation" />
<capability-binding android:key="actions.intent.CREATE_MESSAGE" />
</shortcut>

View file

@ -1,27 +1,30 @@
[versions]
agp = "8.3.2"
agp = "8.4.1"
datastorePreferences = "1.1.1"
kotlin = "1.9.0"
coreKtx = "1.13.0"
coreKtx = "1.13.1"
junit = "4.13.2"
junitVersion = "1.1.5"
espressoCore = "3.5.1"
appcompat = "1.6.1"
material = "1.11.0"
appcompat = "1.7.0"
material = "1.12.0"
activity = "1.9.0"
constraintlayout = "2.1.4"
lifecycleRuntimeKtx = "2.7.0"
lifecycleRuntimeKtx = "2.8.1"
activityCompose = "1.9.0"
composeBom = "2024.04.01"
composeBom = "2024.05.00"
roomCommon = "2.6.1"
roomKtx = "2.6.1"
navigationFragmentKtx = "2.7.7"
navigationUiKtx = "2.7.7"
annotation = "1.7.1"
lifecycleLivedataKtx = "2.7.0"
lifecycleViewmodelKtx = "2.7.0"
annotation = "1.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" }
androidx-datastore-preferences = { module = "androidx.datastore:datastore-preferences", version.ref = "datastorePreferences" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
@ -46,6 +49,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" }

View file

@ -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