Fix wallpaper transparency, Recents setup guide, drawer animation, and widget resizing (#2)
Launcher / test (push) Successful in 1m21s
Launcher / apk (push) Successful in 17s

This commit was merged in pull request #2.
This commit is contained in:
nandi committed 2026-11-23 05:36:23 +00:00
1 parent 2fa7bd745b
commit 3070db4fb4
15 files changed
+1011 -161

No files matched your search

@@ -36,6 +36,7 @@ import android.view.View;
import android.view.ViewConfiguration;
import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.webkit.JavascriptInterface;
import android.webkit.RenderProcessGoneDetail;
@@ -77,9 +78,10 @@ import java.util.concurrent.Executors;
*
* and exposes window.Android (launch, appInfo, uninstall, addWidget, removeWidget,
* placeWidgets, coverWidgets, widgetLimits, excludeGestures, loadIcons, haptic, keyboard,
* openSettings, pickWallpaper, openRecents, httpGet, installApk, installedVersion,
* declinedVersion) for the page's host effects. No decisions are made here: the page
* (core/ and app/ in MoonBit) decides, this class carries them out.
* openSettings, pickWallpaper, openRecents, recentsEnabled, openAccessibilitySettings,
* openSelfAppInfo, httpGet, installApk, installedVersion, declinedVersion) for the page's
* host effects. No decisions are made here: the page (core/ and app/ in MoonBit) decides,
* this class carries them out.
*
* Widgets are real AppWidgetHostViews in a layer above the WebView. The page reports where
* its live widget slots are (placeWidgets), and this class moves the views there. Package
@@ -103,6 +105,7 @@ public class HomeActivity extends Activity {
private final Map<Integer, Long> widgetSizes = new HashMap<>(); // last size told to each widget
private int pendingWidget = -1;
private int editingWidget = -1; // showing resize handles: a press on it moves it
private int editingResizeMode; // RESIZE_HORIZONTAL | RESIZE_VERTICAL for editingWidget
private boolean ready;
private int insetTop, insetBottom; // CSS px
private LauncherApps launcher;
@@ -110,6 +113,12 @@ public class HomeActivity extends Activity {
private final Map<String, byte[]> icons = new ConcurrentHashMap<>();
private final Map<String, LauncherActivityInfo> activities = new ConcurrentHashMap<>();
private final Handler main = new Handler(Looper.getMainLooper());
private final Runnable showIme = () -> {
if (!ready || web == null) return;
web.requestFocus();
InputMethodManager imm = getSystemService(InputMethodManager.class);
if (imm != null) imm.showSoftInput(web, InputMethodManager.SHOW_IMPLICIT);
};
private final ExecutorService iconThread = Executors.newSingleThreadExecutor();
private final LauncherApps.Callback packages = new LauncherApps.Callback() {
@@ -129,6 +138,11 @@ public class HomeActivity extends Activity {
widgetHost = new Host(this);
Window w = getWindow();
w.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
if (Build.VERSION.SDK_INT >= 29) {
w.setNavigationBarContrastEnforced(false);
w.setStatusBarContrastEnforced(false);
}
if (Build.VERSION.SDK_INT >= 30) {
w.setDecorFitsSystemWindows(false);
} else {
@@ -139,6 +153,7 @@ public class HomeActivity extends Activity {
}
private void createWebView() {
main.removeCallbacks(showIme);
ready = false;
web = new WebView(this);
web.setBackgroundColor(Color.TRANSPARENT);
@@ -174,7 +189,9 @@ public class HomeActivity extends Activity {
widgetViews.clear();
widgetSizes.clear();
widgetLayer = new CoverLayer(this);
widgetLayer.setBackgroundColor(Color.TRANSPARENT);
FrameLayout root = new FrameLayout(this);
root.setBackgroundColor(Color.TRANSPARENT);
root.addView(web);
root.addView(widgetLayer);
setContentView(root);
@@ -196,6 +213,7 @@ public class HomeActivity extends Activity {
@Override
protected void onDestroy() {
launcher.unregisterCallback(packages);
main.removeCallbacks(showIme);
iconThread.shutdownNow();
web.destroy();
super.onDestroy();
@@ -553,6 +571,14 @@ public class HomeActivity extends Activity {
return;
}
editingWidget = editing;
if (editing != -1) {
AppWidgetProviderInfo editInfo = widgets.getAppWidgetInfo(editing);
editingResizeMode = editInfo != null
? editInfo.resizeMode
: (AppWidgetProviderInfo.RESIZE_HORIZONTAL | AppWidgetProviderInfo.RESIZE_VERTICAL);
} else {
editingResizeMode = 0;
}
for (Map.Entry<Integer, AppWidgetHostView> e : widgetViews.entrySet()) {
if (!want.containsKey(e.getKey())) e.getValue().setVisibility(View.GONE);
}
@@ -573,7 +599,7 @@ public class HomeActivity extends Activity {
v.setLayoutParams(lp);
v.setVisibility(View.VISIBLE);
// Scrolling moves a widget without resizing it; only tell it about new sizes.
long size = ((long) r[4] << 32) | r[5];
long size = ((long) r[4] << 32) | (r[5] & 0xffffffffL);
Long was = widgetSizes.put(id, size);
if (was == null || was != size) {
if (Build.VERSION.SDK_INT >= 31) {
@@ -657,6 +683,23 @@ public class HomeActivity extends Activity {
super.setPadding(0, 0, 0, 0);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (home.editingWidget == id && ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
int mode = home.editingResizeMode;
boolean canH = (mode & AppWidgetProviderInfo.RESIZE_HORIZONTAL) != 0;
boolean canV = (mode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0;
float d = getResources().getDisplayMetrics().density;
float insetX = Math.min(18f * d, getWidth() * 0.3f);
float insetY = Math.min(18f * d, getHeight() * 0.3f);
float x = ev.getX(), y = ev.getY();
boolean nearH = canH && (x < insetX || x > getWidth() - insetX);
boolean nearV = canV && (y < insetY || y > getHeight() - insetY);
if (nearH || nearV) return false;
}
return super.dispatchTouchEvent(ev);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
switch (e.getActionMasked()) {
@@ -752,13 +795,16 @@ public class HomeActivity extends Activity {
}
/**
* Show Recents through RecentsService. Until the user has turned the service on, take
* them to Accessibility settings, with our service highlighted where Settings supports it.
* Show Recents through RecentsService, falling back to Accessibility settings if
* invoked directly while the service isn't running.
*/
private void openRecents() {
if (RecentsService.showRecents()) return;
Toast.makeText(this, "Turn on \"" + getString(R.string.recents_service_label)
+ "\" to show open windows", Toast.LENGTH_LONG).show();
openAccessibilitySettings();
}
/** Open Accessibility settings with RecentsService highlighted where Settings supports it. */
private void openAccessibilitySettings() {
String me = new ComponentName(this, RecentsService.class).flattenToString();
Bundle args = new Bundle();
args.putString(":settings:fragment_args_key", me);
@@ -767,6 +813,12 @@ public class HomeActivity extends Activity {
.putExtra(":settings:show_fragment_args", args));
}
/** Open ultra Home's own App info page (for "Allow restricted settings" on Android 13+). */
private void openSelfAppInfo() {
startIntent(new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.fromParts("package", getPackageName(), null)));
}
/** window.Android: called from the page's @jscall imports on a binder thread. */
final class Bridge {
@JavascriptInterface public void launch(String component) {
@@ -833,16 +885,14 @@ public class HomeActivity extends Activity {
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING));
}
/** The page focused the drawer's search box; show the keyboard for it. */
/** The page focused the drawer's search box; show the keyboard once the entrance finishes. */
@JavascriptInterface public void showKeyboard() {
main.postDelayed(() -> {
web.requestFocus();
InputMethodManager imm = getSystemService(InputMethodManager.class);
if (imm != null) imm.showSoftInput(web, InputMethodManager.SHOW_IMPLICIT);
}, 50);
main.removeCallbacks(showIme);
main.postDelayed(showIme, 190);
}
@JavascriptInterface public void hideKeyboard() {
main.removeCallbacks(showIme);
main.post(() -> {
InputMethodManager imm = getSystemService(InputMethodManager.class);
if (imm != null) imm.hideSoftInputFromWindow(web.getWindowToken(), 0);
@@ -857,8 +907,22 @@ public class HomeActivity extends Activity {
main.post(() -> startIntent(Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER), "Wallpaper")));
}
@JavascriptInterface public void openRecents() {
@JavascriptInterface public boolean openRecents() {
if (!RecentsService.isRunning()) return false;
main.post(HomeActivity.this::openRecents);
return true;
}
@JavascriptInterface public boolean recentsEnabled() {
return RecentsService.isRunning();
}
@JavascriptInterface public void openAccessibilitySettings() {
main.post(HomeActivity.this::openAccessibilitySettings);
}
@JavascriptInterface public void openSelfAppInfo() {
main.post(HomeActivity.this::openSelfAppInfo);
}
/** GET a URL on a background thread; the page hears back through launcher.httpResult(tag, ok, text). */
@@ -13,6 +13,11 @@ import android.view.accessibility.AccessibilityEvent;
public class RecentsService extends AccessibilityService {
private static volatile RecentsService running;
/** Whether the accessibility service is currently connected. */
static boolean isRunning() {
return running != null;
}
/** Open Recents; false when the service isn't turned on. */
static boolean showRecents() {
RecentsService s = running;
+1 -1
View File
@@ -3,5 +3,5 @@
<string name="app_name">ultra Home</string>
<string name="recents_service_label">ultra Home window list</string>
<string name="recents_service_summary">Lets the home screen\'s Windows button open Recents</string>
<string name="recents_service_description">Turn this on so the Windows button on the ultra Home screen can show your open windows (Recents). Android only lets accessibility services open Recents. This service reads nothing on screen and does nothing else.</string>
<string name="recents_service_description">Turn this on so the Windows button on the ultra Home screen can show your open windows (Recents). Android only lets accessibility services open Recents. If Android blocks this as a restricted setting, open ultra Home\'s App info and turn on Allow restricted settings once. This service reads nothing on screen and does nothing else.</string>
</resources>