Add ToastHelper, New icon

This commit is contained in:
icewithcola 2024-03-29 08:38:52 +08:00
parent 022f9f2a3e
commit d2e8ef37db
27 changed files with 58 additions and 33 deletions

View file

@ -3,7 +3,20 @@
<component name="deploymentTargetDropDown">
<value>
<entry key="MainActivity">
<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-03-26T06:34:42.198995747Z" />
</State>
</entry>
<entry key="app">
<State />

View file

@ -11,8 +11,8 @@ android {
applicationId = "uk.kagurach.android101"
minSdk = 31
targetSdk = 34
versionCode = 1
versionName = "1.0"
versionCode = 101
versionName = "1.0.1"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

View file

@ -4,7 +4,6 @@ import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
@ -65,24 +64,28 @@ public class MainActivity2 extends AppCompatActivity {
EditText b_edit = (EditText) findViewById(R.id.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() ){
ToastHelper.SmartToast.ShowToast("""
Please input R,G,B within 0-255
请在大小选择下方输入0-255的RGB""",
this);
}
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){
NotificationHelper helper = new NotificationHelper(this);
helper.createNotificationChannel();
helper.pushNotification("Page 2: Error Setting Color",
e.toString());
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{
NotificationHelper helper = new NotificationHelper(this);
helper.createNotificationChannel();
helper.pushNotification("Page 2: Error Setting Color",
"The color: R="+_r+" G="+_g+" B="+_b+" is invalid!");
ToastHelper.SmartToast.ShowToast("The color: R="+_r+" G="+_g+" B="+_b+" is invalid!",this);
}
}
@ -93,10 +96,7 @@ public class MainActivity2 extends AppCompatActivity {
try {
s = editText.getText().toString();
}catch (Exception e){
NotificationHelper helper = new NotificationHelper(this);
helper.createNotificationChannel();
helper.pushNotification("Page 2: Error Setting Test Text",
e.toString());
ToastHelper.SmartToast.ShowToast(e.toString(),this);
return;
}
textView.setText(s);
@ -122,10 +122,7 @@ public class MainActivity2 extends AppCompatActivity {
try {
size = Integer.parseInt(ed.getText().toString());
}catch (Exception e){
NotificationHelper helper = new NotificationHelper(this);
helper.createNotificationChannel();
helper.pushNotification("Page 2: Error Setting Text Size",
e.toString());
ToastHelper.SmartToast.ShowToast(e.toString(),this);
return;
}
_text_size = size;

View file

@ -0,0 +1,27 @@
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

@ -23,7 +23,7 @@
android:layout_height="350dp">
<TextView
android:id="@+id/test2strview"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/test_str"
android:textSize="60sp"/>

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 852 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 982 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 840 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB