import android.content.Context;
import android.content.SharedPreferences;
+import android.provider.Settings;
+import android.view.View;
+import com.farmerbb.taskbar.BuildConfig;
+import com.farmerbb.taskbar.R;
import com.farmerbb.taskbar.activity.SecondaryHomeActivity;
import com.farmerbb.taskbar.helper.LauncherHelper;
+import com.farmerbb.taskbar.util.CompatUtils;
+import com.farmerbb.taskbar.util.TaskbarPosition;
import com.farmerbb.taskbar.util.U;
import static com.farmerbb.taskbar.util.Constants.*;
public abstract class UIController {
protected Context context;
+ private boolean prevImeVisibility;
public UIController(Context context) {
this.context = context;
} else
host.terminate();
}
+
+ protected int getBottomMargin(Context context, UIHost host) {
+ return host instanceof SecondaryHomeActivity
+ && !U.isShowHideNavbarSupported()
+ && TaskbarPosition.isBottom(context) ? U.getNavbarHeight(context) : -1;
+ }
+
+ protected void applyMarginFix(UIHost host, View layout, ViewParams params) {
+ if(U.getCurrentApiVersion() <= 29.0 || !(host instanceof SecondaryHomeActivity))
+ return;
+
+ layout.setOnApplyWindowInsetsListener((v, insets) -> {
+ boolean isImeVisible = CompatUtils.isImeVisible(v);
+ if(isImeVisible != prevImeVisibility) {
+ prevImeVisibility = isImeVisible;
+
+ ViewParams newParams = isImeVisible ? params.updateBottomMargin(0) : params;
+ host.updateViewLayout(layout, newParams);
+
+ if(isImeFixDisabled() && !U.isLibrary(context)) {
+ SharedPreferences pref = U.getSharedPreferences(context);
+ if(!pref.getBoolean(PREF_DESKTOP_MODE_IME_FIX, false)) {
+ pref.edit().putBoolean(PREF_DESKTOP_MODE_IME_FIX, true).apply();
+ U.showToastLong(context, R.string.tb_desktop_mode_ime_fix_toast);
+ }
+ }
+ }
+
+ return insets;
+ });
+ }
+
+ protected boolean isImeFixDisabled() {
+ String ime = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
+ return !ime.startsWith(BuildConfig.BASE_APPLICATION_ID) && !ime.startsWith("com.farmerbb.secondscreen");
+ }
}
\ No newline at end of file