Skip to content

Commit

Permalink
Remove handler and use toast length constant
Browse files Browse the repository at this point in the history
  • Loading branch information
Sesow29 committed May 2, 2024
1 parent f4a373f commit d0ec2be
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import android.content.res.Configuration;
import android.content.res.Resources;
import helium314.keyboard.latin.utils.Log;

import android.os.Handler;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -480,7 +478,7 @@ public void showFakeToast(final int resId, final int timeMillis) {
isToastShowing = true;
mFakeToastView.startAnimation(AnimationUtils.loadAnimation(mLatinIME, R.anim.fade_in));

new Handler().postDelayed(() -> {
mFakeToastView.postDelayed(() -> {
mFakeToastView.startAnimation(AnimationUtils.loadAnimation(mLatinIME, R.anim.fade_out));
mFakeToastView.setVisibility(View.GONE);
isToastShowing = false;
Expand Down
15 changes: 12 additions & 3 deletions app/src/main/java/helium314/keyboard/latin/LatinIME.java
Original file line number Diff line number Diff line change
Expand Up @@ -1614,14 +1614,23 @@ public void getSuggestedWords(final int inputStyle, final int sequenceNumber,
mKeyboardSwitcher.getKeyboardShiftMode(), inputStyle, sequenceNumber, callback);
}

public void showToast(final int resId, final int timeMillis, final boolean fallback){
/**
* Displays a toast message.
*
* @param resId The resource ID of the string to display in the toast message.
* @param briefToast If true, the toast duration will be short; otherwise, it will last longer.
* @param fallback If true, falls back to a workaround for API 33+ to display the toast.
*/
public void showToast(final int resId, final boolean briefToast, final boolean fallback){
// In API 32 and below, toasts can be shown without a notification permission.
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2){
final Toast toast = Toast.makeText(this, resId, timeMillis);
final int toastLength = briefToast ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG;
final Toast toast = Toast.makeText(this, resId, toastLength);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
} else if (fallback) {
mKeyboardSwitcher.showFakeToast(resId, timeMillis); // workaround for API 33+.
final int toastLength = briefToast ? 2000 : 3500;
mKeyboardSwitcher.showFakeToast(resId, toastLength);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ public void copyText() {
if (text == null || text.length() == 0) return;
final ClipboardManager cm = (ClipboardManager) mParent.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setPrimaryClip(ClipData.newPlainText("copied text", text));
((LatinIME)mParent).showToast(R.string.toast_msg_clipboard_copy, 2000, false);
((LatinIME)mParent).showToast(R.string.toast_msg_clipboard_copy, true, false);
}

public void commitCorrection(final CorrectionInfo correctionInfo) {
Expand Down

0 comments on commit d0ec2be

Please sign in to comment.