Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4012b115 authored by Frank Preel's avatar Frank Preel
Browse files

Test dark mode & only display icon if on suggestion

parent d724f1ae
Loading
Loading
Loading
Loading
+27 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.pm.PackageManager;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import android.app.ActivityOptions;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
@@ -908,11 +909,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
                switchToSttIme();
            }
        });
        updateFloatingButtonTint(view);
        manageFloatingButtonVisibility();
    }

    private void manageFloatingButtonVisibility() {
        if (shouldShowFloatingButton()) {
        final SettingsValues currentSettingsValues = mSettings.getCurrent();
        if (shouldShowFloatingButton() && currentSettingsValues.mInputAttributes.mShouldShowSuggestions) {
            floatingButton.setVisibility(View.VISIBLE);
        } else {
            floatingButton.setVisibility(View.GONE);
@@ -2117,6 +2120,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
        if (mInputView == null)
            return;

        android.util.Log.d("xxx", "updateNavigationBarColor");

        if (BuildCompatUtils.EFFECTIVE_SDK_INT > Build.VERSION_CODES.R) {
            Drawable bg = mInputView.findViewById(R.id.keyboard_view).getBackground();
            Window w = getWindow().getWindow();
@@ -2133,4 +2138,25 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
            w.getDecorView().setSystemUiVisibility(flags);
        }
    }

    private void updateFloatingButtonTint(View view) {
        ImageButton floatingButton = view.findViewById(R.id.floating_button);
        if (floatingButton == null) return;
        int currentNightMode = view.getResources().getConfiguration().uiMode
                & Configuration.UI_MODE_NIGHT_MASK;

        int tintColor;
        if (currentNightMode == Configuration.UI_MODE_NIGHT_YES) {
            tintColor = ContextCompat.getColor(view.getContext(), 0xFFFFFFFF);
        } else {
            tintColor = ContextCompat.getColor(view.getContext(), 0xFF000000);
        }

        Drawable icon = ContextCompat.getDrawable(view.getContext(), R.drawable.ic_ime_switch);
        if (icon != null) {
            icon = DrawableCompat.wrap(icon.mutate());
            DrawableCompat.setTint(icon, tintColor);
            floatingButton.setImageDrawable(icon);
        }
    }
}