try again
This commit is contained in:
1 parent
5517792387
commit
570624fb8b
10 files changed
+75
-35
No files matched your search
@@ -1,8 +1,6 @@
|
|||||||
name: Android
|
name: Android
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
|
||||||
pull_request:
|
|
||||||
release:
|
release:
|
||||||
types: [published]
|
types: [published]
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
@@ -22,8 +20,6 @@ jobs:
|
|||||||
- uses: android-actions/setup-android@v3
|
- uses: android-actions/setup-android@v3
|
||||||
# Gitea's act resolver cannot peel the annotated v4 tag alias.
|
# Gitea's act resolver cannot peel the annotated v4 tag alias.
|
||||||
- uses: gradle/actions/setup-gradle@ed408507eac070d1f99cc633dbcf757c94c7933a # v4.4.3
|
- uses: gradle/actions/setup-gradle@ed408507eac070d1f99cc633dbcf757c94c7933a # v4.4.3
|
||||||
with:
|
|
||||||
cache-read-only: ${{ gitea.event_name == 'pull_request' }}
|
|
||||||
- name: Install Android SDK packages
|
- name: Install Android SDK packages
|
||||||
run: sdkmanager "platforms;android-35" "build-tools;35.0.0"
|
run: sdkmanager "platforms;android-35" "build-tools;35.0.0"
|
||||||
- name: Lint and test
|
- name: Lint and test
|
||||||
|
|||||||
@@ -1,17 +1,34 @@
|
|||||||
package io.github.transui.android;
|
package io.github.transui.android;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
|
||||||
public final class PushToTalkButton extends ImageButton {
|
public final class PushToTalkButton extends ImageButton {
|
||||||
|
enum IconMode {
|
||||||
|
APPS,
|
||||||
|
STOP_CIRCLE
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Paint iconPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
private Runnable pressedAction;
|
private Runnable pressedAction;
|
||||||
private Runnable releasedAction;
|
private Runnable releasedAction;
|
||||||
private boolean trackingPress;
|
private boolean trackingPress;
|
||||||
|
private IconMode iconMode = IconMode.STOP_CIRCLE;
|
||||||
|
|
||||||
public PushToTalkButton(Context context, AttributeSet attributes) {
|
public PushToTalkButton(Context context, AttributeSet attributes) {
|
||||||
super(context, attributes);
|
super(context, attributes);
|
||||||
|
iconPaint.setColor(context.getColor(R.color.on_signal));
|
||||||
|
setImageDrawable(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setIconMode(IconMode iconMode) {
|
||||||
|
this.iconMode = iconMode;
|
||||||
|
setImageDrawable(null);
|
||||||
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPushToTalkActions(Runnable pressedAction, Runnable releasedAction) {
|
void setPushToTalkActions(Runnable pressedAction, Runnable releasedAction) {
|
||||||
@@ -55,4 +72,48 @@ public final class PushToTalkButton extends ImageButton {
|
|||||||
public boolean performClick() {
|
public boolean performClick() {
|
||||||
return super.performClick();
|
return super.performClick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
|
super.onDraw(canvas);
|
||||||
|
float contentWidth = getWidth() - getPaddingLeft() - getPaddingRight();
|
||||||
|
float contentHeight = getHeight() - getPaddingTop() - getPaddingBottom();
|
||||||
|
float size = Math.min(contentWidth, contentHeight);
|
||||||
|
float centerX = getWidth() / 2f;
|
||||||
|
float centerY = getHeight() / 2f;
|
||||||
|
if (iconMode == IconMode.APPS) {
|
||||||
|
drawAppsIcon(canvas, centerX, centerY, size);
|
||||||
|
} else {
|
||||||
|
drawStopCircleIcon(canvas, centerX, centerY, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawAppsIcon(Canvas canvas, float centerX, float centerY, float size) {
|
||||||
|
iconPaint.setStyle(Paint.Style.FILL);
|
||||||
|
float spacing = size * 0.27f;
|
||||||
|
float radius = size * 0.09f;
|
||||||
|
for (int row = -1; row <= 1; row++) {
|
||||||
|
for (int column = -1; column <= 1; column++) {
|
||||||
|
canvas.drawCircle(
|
||||||
|
centerX + column * spacing,
|
||||||
|
centerY + row * spacing,
|
||||||
|
radius,
|
||||||
|
iconPaint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawStopCircleIcon(Canvas canvas, float centerX, float centerY, float size) {
|
||||||
|
iconPaint.setStyle(Paint.Style.STROKE);
|
||||||
|
iconPaint.setStrokeWidth(size * 0.12f);
|
||||||
|
canvas.drawCircle(centerX, centerY, size * 0.42f, iconPaint);
|
||||||
|
iconPaint.setStyle(Paint.Style.FILL);
|
||||||
|
float squareHalfSize = size * 0.17f;
|
||||||
|
canvas.drawRect(
|
||||||
|
centerX - squareHalfSize,
|
||||||
|
centerY - squareHalfSize,
|
||||||
|
centerX + squareHalfSize,
|
||||||
|
centerY + squareHalfSize,
|
||||||
|
iconPaint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -83,13 +83,13 @@ public final class SpeechRecognitionActivity extends Activity {
|
|||||||
if (config.pushToTalk) {
|
if (config.pushToTalk) {
|
||||||
record.setBackgroundResource(R.drawable.voice_pill_button);
|
record.setBackgroundResource(R.drawable.voice_pill_button);
|
||||||
resizeRecordButton(132, 64, 16);
|
resizeRecordButton(132, 64, 16);
|
||||||
record.setImageResource(R.drawable.ic_apps);
|
record.setIconMode(PushToTalkButton.IconMode.APPS);
|
||||||
record.setContentDescription(getString(R.string.hold_to_talk));
|
record.setContentDescription(getString(R.string.hold_to_talk));
|
||||||
record.setPushToTalkActions(this::startRecording, this::stopRecording);
|
record.setPushToTalkActions(this::startRecording, this::stopRecording);
|
||||||
} else {
|
} else {
|
||||||
record.setBackgroundResource(R.drawable.voice_primary_button);
|
record.setBackgroundResource(R.drawable.voice_primary_button);
|
||||||
resizeRecordButton(64, 64, 19);
|
resizeRecordButton(64, 64, 19);
|
||||||
record.setImageResource(R.drawable.ic_stop);
|
record.setIconMode(PushToTalkButton.IconMode.STOP_CIRCLE);
|
||||||
record.setContentDescription(getString(R.string.stop));
|
record.setContentDescription(getString(R.string.stop));
|
||||||
record.setOnClickListener(view -> stopRecording());
|
record.setOnClickListener(view -> stopRecording());
|
||||||
}
|
}
|
||||||
@@ -198,7 +198,9 @@ public final class SpeechRecognitionActivity extends Activity {
|
|||||||
public void onRecording() {
|
public void onRecording() {
|
||||||
runOnUiThread(() -> {
|
runOnUiThread(() -> {
|
||||||
status.setText(R.string.listening);
|
status.setText(R.string.listening);
|
||||||
if (!config.pushToTalk) record.setImageResource(R.drawable.ic_stop);
|
if (!config.pushToTalk) {
|
||||||
|
record.setIconMode(PushToTalkButton.IconMode.STOP_CIRCLE);
|
||||||
|
}
|
||||||
recordingStartedAt = SystemClock.elapsedRealtime();
|
recordingStartedAt = SystemClock.elapsedRealtime();
|
||||||
elapsed.setText(R.string.elapsed_zero);
|
elapsed.setText(R.string.elapsed_zero);
|
||||||
handler.post(updateElapsed);
|
handler.post(updateElapsed);
|
||||||
|
|||||||
@@ -112,13 +112,13 @@ public final class TransuiInputMethodService extends InputMethodService {
|
|||||||
if (config.pushToTalk) {
|
if (config.pushToTalk) {
|
||||||
record.setBackgroundResource(R.drawable.voice_pill_button);
|
record.setBackgroundResource(R.drawable.voice_pill_button);
|
||||||
resizeRecordButton(132, 64, 16);
|
resizeRecordButton(132, 64, 16);
|
||||||
record.setImageResource(R.drawable.ic_apps);
|
record.setIconMode(PushToTalkButton.IconMode.APPS);
|
||||||
record.setContentDescription(getString(R.string.hold_to_talk));
|
record.setContentDescription(getString(R.string.hold_to_talk));
|
||||||
record.setPushToTalkActions(this::startRecording, this::stopRecording);
|
record.setPushToTalkActions(this::startRecording, this::stopRecording);
|
||||||
} else {
|
} else {
|
||||||
record.setBackgroundResource(R.drawable.voice_primary_button);
|
record.setBackgroundResource(R.drawable.voice_primary_button);
|
||||||
resizeRecordButton(64, 64, 19);
|
resizeRecordButton(64, 64, 19);
|
||||||
record.setImageResource(R.drawable.ic_stop);
|
record.setIconMode(PushToTalkButton.IconMode.STOP_CIRCLE);
|
||||||
record.setContentDescription(getString(R.string.stop));
|
record.setContentDescription(getString(R.string.stop));
|
||||||
record.setOnClickListener(view -> stopRecording());
|
record.setOnClickListener(view -> stopRecording());
|
||||||
}
|
}
|
||||||
@@ -180,7 +180,9 @@ public final class TransuiInputMethodService extends InputMethodService {
|
|||||||
public void onRecording() {
|
public void onRecording() {
|
||||||
handler.post(() -> {
|
handler.post(() -> {
|
||||||
status.setText(R.string.listening);
|
status.setText(R.string.listening);
|
||||||
if (!config.pushToTalk) record.setImageResource(R.drawable.ic_stop);
|
if (!config.pushToTalk) {
|
||||||
|
record.setIconMode(PushToTalkButton.IconMode.STOP_CIRCLE);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="24dp"
|
|
||||||
android:height="24dp"
|
|
||||||
android:viewportWidth="24"
|
|
||||||
android:viewportHeight="24">
|
|
||||||
<path
|
|
||||||
android:fillColor="@color/paper"
|
|
||||||
android:pathData="M4,8h4V4H4v4zM10,20h4v-4h-4v4zM4,20h4v-4H4v4zM4,14h4v-4H4v4zM10,14h4v-4h-4v4zM16,4v4h4V4h-4zM10,8h4V4h-4v4zM16,14h4v-4h-4v4zM16,20h4v-4h-4v4z" />
|
|
||||||
</vector>
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="24dp"
|
|
||||||
android:height="24dp"
|
|
||||||
android:viewportWidth="24"
|
|
||||||
android:viewportHeight="24">
|
|
||||||
<path
|
|
||||||
android:fillColor="@color/paper"
|
|
||||||
android:fillType="evenOdd"
|
|
||||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM16,16H8V8h8v8z" />
|
|
||||||
</vector>
|
|
||||||
@@ -60,8 +60,7 @@
|
|||||||
android:layout_marginTop="14dp"
|
android:layout_marginTop="14dp"
|
||||||
android:background="@drawable/voice_primary_button"
|
android:background="@drawable/voice_primary_button"
|
||||||
android:contentDescription="@string/stop"
|
android:contentDescription="@string/stop"
|
||||||
android:padding="16dp"
|
android:padding="16dp" />
|
||||||
android:src="@drawable/ic_stop" />
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/recognition_cancel"
|
android:id="@+id/recognition_cancel"
|
||||||
|
|||||||
@@ -75,7 +75,6 @@
|
|||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:background="@drawable/voice_primary_button"
|
android:background="@drawable/voice_primary_button"
|
||||||
android:contentDescription="@string/stop"
|
android:contentDescription="@string/stop"
|
||||||
android:padding="21dp"
|
android:padding="21dp" />
|
||||||
android:src="@drawable/ic_stop" />
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
<color name="mist">#11191D</color>
|
<color name="mist">#11191D</color>
|
||||||
<color name="paper">#192329</color>
|
<color name="paper">#192329</color>
|
||||||
<color name="line">#34444B</color>
|
<color name="line">#34444B</color>
|
||||||
|
<color name="on_signal">#142027</color>
|
||||||
<color name="ripple_on_signal">#3DFFFFFF</color>
|
<color name="ripple_on_signal">#3DFFFFFF</color>
|
||||||
<color name="ripple_signal">#3342C9C1</color>
|
<color name="ripple_signal">#3342C9C1</color>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
<color name="mist">#F2F6F7</color>
|
<color name="mist">#F2F6F7</color>
|
||||||
<color name="paper">#FFFFFF</color>
|
<color name="paper">#FFFFFF</color>
|
||||||
<color name="line">#D5E0E3</color>
|
<color name="line">#D5E0E3</color>
|
||||||
|
<color name="on_signal">#FFFFFF</color>
|
||||||
<color name="ripple_on_signal">#3DFFFFFF</color>
|
<color name="ripple_on_signal">#3DFFFFFF</color>
|
||||||
<color name="ripple_signal">#33008D87</color>
|
<color name="ripple_signal">#33008D87</color>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in new issue
Block a user