This commit is contained in:
icewithcola 2024-05-24 12:48:34 +08:00
parent a1cccd9890
commit daeaee0d3e
24 changed files with 488 additions and 379 deletions

View file

@ -22,7 +22,20 @@
<State />
</entry>
<entry key="app">
<State />
<State>
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/Resizable_Experimental_API_34.avd" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-05-24T03:51:09.939185298Z" />
</State>
</entry>
</value>
</component>

View file

@ -11,8 +11,8 @@ android {
applicationId = "uk.kagurach.android101"
minSdk = 31
targetSdk = 34
versionCode = 151
versionName = "1.5.1"
versionCode = 153
versionName = "1.5.3"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

View file

@ -1,9 +1,10 @@
<?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"
android:dataExtractionRules="@xml/data_extraction_rules"
@ -12,8 +13,18 @@
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">
<receiver
android:name=".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" />

View file

@ -17,8 +17,7 @@ fun Kaculate(src: String,ctx :Context) : String{
for (i in src.indices) {
if (src[i] in '0'..'9' || src[i] == '.') {
_curnum += src[i]
}
else if (src[i] in OpList){
} else if (src[i] in OpList) {
try {
numStack += _curnum.toFloat()
_curnum = ""
@ -27,8 +26,7 @@ fun Kaculate(src: String,ctx :Context) : String{
return src
}
opStack += src[i]
}
else{
} else {
ToastHelper.ShowToast("Unknown input char:" + src[i].toString(), ctx)
return src
}

View file

@ -27,6 +27,7 @@ import java.util.Arrays;
public class MainActivity extends AppCompatActivity {
PageHelper pageHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -80,20 +81,7 @@ public class MainActivity extends AppCompatActivity {
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);
@ -117,4 +105,18 @@ public class MainActivity extends AppCompatActivity {
successCallback.getIntentSender());
}
}
private final class LongClickHandler implements View.OnLongClickListener {
Context context;
LongClickHandler(Context ctx) {
context = ctx;
}
@Override
public boolean onLongClick(View v) {
CreateShortcut(context);
return false;
}
}
}

View file

@ -23,6 +23,7 @@ public class MainActivity2 extends AppCompatActivity {
PageHelper pageHelper;
int _text_size = 70;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -93,6 +94,7 @@ public class MainActivity2 extends AppCompatActivity {
}
}
public void setText(View view) {
TextView textView = findViewById(R.id.test2strview);
EditText editText = findViewById(R.id.Page2SetTestText);

View file

@ -9,12 +9,12 @@ 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
}
@ -29,8 +29,10 @@ class NotificationHelper(_ctx: Context) {
.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(

View file

@ -14,11 +14,10 @@ import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import java.util.List;
public class Page3 extends AppCompatActivity {
PageHelper pageHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -59,7 +58,54 @@ public class Page3 extends AppCompatActivity {
findViewById(R.id.P3Nextpage).setOnLongClickListener(pageHelper.longClickHandler);
}
private void setOpButton(boolean state) {
findViewById(R.id.P3X).setEnabled(state);
findViewById(R.id.P3Plus).setEnabled(state);
findViewById(R.id.P3Minus).setEnabled(state);
findViewById(R.id.P3Div).setEnabled(state);
findViewById(R.id.P3ChengFang).setEnabled(state);
}
private boolean isNumberWithDot(@NonNull String s) {
if (!s.contains(".")) {
return false;
}
boolean hasDot = false;
for (int i = s.length() - 1; i >= 0; i--) {
char c = s.charAt(i);
if (c == '+' || c == '-' || c == 'x' || c == '/' || c == '^') {
return hasDot;
} else if (c == '.') {
hasDot = true;
}
}
return hasDot;
}
private void calc() {
TextView textView = findViewById(R.id.P3CalcResult);
String result = Kaculate(textView.getText().toString(), this);
if (result.contains(".")) { // In case of Infinity or NaN as a result
int i = 0;
while (result.charAt(i) != '.') {
i++;
}
int j = i;
boolean notZero = false;
for (i++; i < result.length(); i++) {
if (result.charAt(i) != '0') {
notZero = true;
}
}
if (!notZero) {
result = result.substring(0, j);
}
}
textView.setText(result);
}
class CalculateOnClickListener implements View.OnClickListener {
@Override
@ -113,53 +159,4 @@ public class Page3 extends AppCompatActivity {
tv.setText(s);
}
}
private void setOpButton(boolean state){
findViewById(R.id.P3X).setEnabled(state);
findViewById(R.id.P3Plus).setEnabled(state);
findViewById(R.id.P3Minus).setEnabled(state);
findViewById(R.id.P3Div).setEnabled(state);
findViewById(R.id.P3ChengFang).setEnabled(state);
}
private boolean isNumberWithDot(@NonNull String s){
if (!s.contains(".")){
return false;
}
boolean hasDot = false;
for (int i = s.length()-1; i >= 0; i--) {
char c = s.charAt(i);
if (c=='+'||c=='-'||c=='x'||c=='/'||c=='^'){
return hasDot;
}else if (c=='.'){
hasDot = true;
}
}
return hasDot;
}
private void calc(){
TextView textView = findViewById(R.id.P3CalcResult);
String result = Kaculate(textView.getText().toString(),this);
if (result.contains(".")) { // In case of Infinity or NaN as a result
int i = 0;
while (result.charAt(i) != '.') {
i++;
}
int j = i;
boolean notZero = false;
for (i++; i < result.length(); i++) {
if (result.charAt(i) != '0') {
notZero = true;
}
}
if (!notZero) {
result = result.substring(0, j);
}
}
textView.setText(result);
}
}

View file

@ -1,6 +1,6 @@
package uk.kagurach.android101;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@ -14,16 +14,19 @@ 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;
import uk.kagurach.android101.vibrationBroadcastReceiver.vibrationBroadcastReceiver;
public class Page4 extends AppCompatActivity {
PageHelper pageHelper;
ActivityResultLauncher mLauncher;
long startTime = 0;
long endTime = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -42,9 +45,10 @@ public class Page4 extends AppCompatActivity {
nextPage.setOnClickListener(pageHelper.pageButtonHandler);
nextPage.setOnLongClickListener(pageHelper.longClickHandler);
mLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
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();
@ -53,9 +57,11 @@ public class Page4 extends AppCompatActivity {
TextView tv = findViewById(R.id.P4Result);
tv.setText(response);
}
endTime = System.currentTimeMillis();
TextView timetv = findViewById(R.id.P4AIRuntime);
timetv.setText("使用了" + (endTime - startTime) + "毫秒");
}
}
);
});
}
@ -67,17 +73,12 @@ public class Page4 extends AppCompatActivity {
Bundle bundle = new Bundle();
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 void onClick(View v){
callOtherActivity();
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (getCurrentFocus() != null) {
@ -87,5 +88,24 @@ public class Page4 extends AppCompatActivity {
return super.dispatchTouchEvent(ev);
}
private final class ButtonHandler implements View.OnClickListener {
@Override
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

@ -8,15 +8,13 @@ import android.content.Intent;
import android.view.View;
public class PageHelper {
public final LongClickHandler longClickHandler = new LongClickHandler();
public final PageButtonHandler pageButtonHandler = new PageButtonHandler();
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) {
_curr = curr;
_prev = prev;
@ -60,16 +58,15 @@ public class PageHelper {
_activity.finish();
}
private final class LongClickHandler implements View.OnLongClickListener
{
private final class LongClickHandler implements View.OnLongClickListener {
@Override
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) {
if (_activity == null) {

View file

@ -13,6 +13,7 @@ class ToastHelper(text: String,ctx: Context) {
helper.autoShow()
}
}
fun autoShow() {
if (_text.contains('\n')) {
for (line in _text.split('\n')) {

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() {
@ -89,7 +90,12 @@ class AddPage() : ComponentActivity() {
val timePickerState by remember {
mutableStateOf(
when (item) {
null -> TimePickerState(c.get(Calendar.HOUR_OF_DAY),c.get(Calendar.MINUTE),true)
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(),
@ -154,7 +160,7 @@ class AddPage() : ComponentActivity() {
return@Submit
}
val loader = TodoItemLoader(context)
val sdf = SimpleDateFormat("yyyy-MM-dd")
val sdf = SimpleDateFormat("yyyy-MM-dd", Locale.CHINA)
val todoItem = TodoItem(

View file

@ -46,10 +46,10 @@ class MainActivity : ComponentActivity() {
title = { Text("Simple TODO ^_^") }
)
},
content = {
padding ->
content = { padding ->
Surface(
modifier = Modifier.padding(padding)
modifier = Modifier
.padding(padding)
.verticalScroll(rememberScrollState())
) {
if (tmpList != null) {

View file

@ -88,9 +88,10 @@ fun TodoItemView(todoItem: TodoItem) {
TextButton(
onClick = {
if (!todoItem.isCompleted) {
Toast.makeText( context,
context.getText(R.string.yes_not_finish)
,Toast.LENGTH_SHORT).show()
Toast.makeText(
context,
context.getText(R.string.yes_not_finish), Toast.LENGTH_SHORT
).show()
} else {
todoItem.isCompleted = false
loader.changeItem(todoItem)
@ -106,9 +107,10 @@ fun TodoItemView(todoItem: TodoItem) {
TextButton(
onClick = {
if (todoItem.isCompleted) {
Toast.makeText( context,
context.getText(R.string.already_finish)
,Toast.LENGTH_SHORT).show()
Toast.makeText(
context,
context.getText(R.string.already_finish), Toast.LENGTH_SHORT
).show()
} else {
todoItem.isCompleted = true
loader.changeItem(todoItem)
@ -126,6 +128,7 @@ fun TodoItemView(todoItem: TodoItem) {
when (deleteText) {
context.getText(R.string.first_delete).toString() ->
deleteText = context.getText(R.string.second_delete).toString()
else -> {
needShow = false
todoItem.MarkDeleted = true

View file

@ -0,0 +1,30 @@
package uk.kagurach.android101.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

@ -29,7 +29,8 @@ fun AIAnswerService(s: String):String {
} else {
if (result.endsWith(".") ||
result.endsWith("") ||
result.endsWith("?")){
result.endsWith("?")
) {
result = result.dropLast(1);
}
"$result,谢谢。"
@ -40,7 +41,8 @@ fun AIAnswerService(s: String):String {
result = result.replace("", "")
}
result = result.replace("",
result = result.replace(
"",
if (rng.nextBoolean()) {
"可以"
} else {

View file

@ -31,7 +31,6 @@
android:layout_height="0dp"
android:layout_weight="1"
android:text="@string/next_page"
android:onClick="jumpToNext"
android:enabled="false"
/>

View file

@ -20,15 +20,18 @@
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: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,14 +41,23 @@
android:textSize="40sp"
android:text="@string/ai"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="300dp">
<TextView
android:layout_width="match_parent"
android:textSize="40sp"
android:layout_height="200dp"
android:textSize="35sp"
android:layout_height="wrap_content"
android:id="@+id/P4Result"
android:textColor="@color/tfb"
/>
</ScrollView>
<TextView
android:layout_width="match_parent"
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"
@ -57,6 +69,14 @@
android:id="@+id/P4AskAI"
android:text="@string/ask_ai"
/>
<Button
android:layout_width="140dp"
android:layout_height="match_parent"
android:id="@+id/P4Vibrate"
android:text="@string/vibrate"
/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"

View file

@ -14,4 +14,7 @@
<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>
</resources>

View file

@ -24,4 +24,7 @@
<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>
</resources>

View file

@ -1,24 +1,24 @@
[versions]
agp = "8.3.2"
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"
material = "1.12.0"
activity = "1.9.0"
constraintlayout = "2.1.4"
lifecycleRuntimeKtx = "2.7.0"
lifecycleRuntimeKtx = "2.8.0"
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.0"
lifecycleViewmodelKtx = "2.8.0"
[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }