Skip to content

Commit dbd4156

Browse files
committed
Yet another improvement of navbar layout heuristics
1 parent 23499e7 commit dbd4156

File tree

1 file changed

+45
-20
lines changed

1 file changed

+45
-20
lines changed

src/com/ceco/gm2/gravitybox/ModNavigationBar.java

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -213,19 +213,12 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
213213

214214
// insert app key
215215
ViewGroup vRot, navButtons;
216-
LinearLayout.LayoutParams lp;
217216

218217
// insert app key in rot0 view
219218
vRot = (ViewGroup) ((ViewGroup) param.thisObject).findViewById(
220219
mResources.getIdentifier("rot0", "id", PACKAGE_NAME));
221220
if (vRot != null) {
222221
KeyButtonView appKey = new KeyButtonView(context);
223-
lp = new LinearLayout.LayoutParams(
224-
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40,
225-
mResources.getDisplayMetrics()),
226-
LinearLayout.LayoutParams.MATCH_PARENT);
227-
lp.weight = 0;
228-
appKey.setLayoutParams(lp);
229222
appKey.setScaleType(ScaleType.FIT_CENTER);
230223
appKey.setClickable(true);
231224
appKey.setImageDrawable(gbRes.getDrawable(R.drawable.ic_sysbar_apps));
@@ -240,19 +233,6 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
240233
mResources.getIdentifier("rot90", "id", PACKAGE_NAME));
241234
if (vRot != null) {
242235
KeyButtonView appKey = new KeyButtonView(context);
243-
if (Utils.isPhoneUI(context)) {
244-
lp = new LinearLayout.LayoutParams(
245-
LinearLayout.LayoutParams.MATCH_PARENT,
246-
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40,
247-
mResources.getDisplayMetrics()));
248-
} else {
249-
lp = new LinearLayout.LayoutParams(
250-
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40,
251-
mResources.getDisplayMetrics()),
252-
LinearLayout.LayoutParams.MATCH_PARENT);
253-
}
254-
lp.weight = 0;
255-
appKey.setLayoutParams(lp);
256236
appKey.setClickable(true);
257237
appKey.setImageDrawable(gbRes.getDrawable(R.drawable.ic_sysbar_apps));
258238
appKey.setOnClickListener(mAppKeyOnClickListener);
@@ -297,6 +277,10 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
297277

298278
private static void prepareNavbarViewInfo(ViewGroup navButtons, int index, KeyButtonView appView) {
299279
try {
280+
final int size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
281+
40, navButtons.getResources().getDisplayMetrics());
282+
if (DEBUG) log("App key view minimum size=" + size);
283+
300284
mNavbarViewInfo[index] = new NavbarViewInfo();
301285
mNavbarViewInfo[index].navButtons = navButtons;
302286
mNavbarViewInfo[index].appLauncherView = appView;
@@ -313,6 +297,47 @@ private static void prepareNavbarViewInfo(ViewGroup navButtons, int index, KeyBu
313297
}
314298
}
315299
mNavbarViewInfo[index].position = searchPosition;
300+
301+
// determine app key layout
302+
LinearLayout.LayoutParams lp = null;
303+
if (mNavbarViewInfo[index].originalView != null) {
304+
// determine layout from layout of placeholder view we found
305+
ViewGroup.LayoutParams ovlp = mNavbarViewInfo[index].originalView.getLayoutParams();
306+
if (DEBUG) log("originalView: lpWidth=" + ovlp.width + "; lpHeight=" + ovlp.height);
307+
if (ovlp.width >= 0) {
308+
lp = new LinearLayout.LayoutParams(size, LinearLayout.LayoutParams.MATCH_PARENT, 0);
309+
} else if (ovlp.height >= 0) {
310+
lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, size, 0);
311+
} else {
312+
log("Weird layout of placeholder view detected");
313+
}
314+
} else {
315+
// determine layout from Back key
316+
final int resId = navButtons.getResources().getIdentifier("back", "id", PACKAGE_NAME);
317+
if (resId != 0) {
318+
View back = navButtons.findViewById(resId);
319+
if (back != null) {
320+
ViewGroup.LayoutParams blp = back.getLayoutParams();
321+
if (blp.width >= 0) {
322+
lp = new LinearLayout.LayoutParams(size, LinearLayout.LayoutParams.MATCH_PARENT, 0);
323+
} else if (blp.height >= 0) {
324+
lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, size, 0);
325+
} else {
326+
log("Weird layout of back button view detected");
327+
}
328+
} else {
329+
log("Could not find back button view");
330+
}
331+
} else {
332+
log("Could not find back button resource ID");
333+
}
334+
}
335+
// worst case scenario (should never happen, but just to make sure)
336+
if (lp == null) {
337+
lp = new LinearLayout.LayoutParams(size, size, 0);
338+
}
339+
if (DEBUG) log("appView: lpWidth=" + lp.width + "; lpHeight=" + lp.height);
340+
mNavbarViewInfo[index].appLauncherView.setLayoutParams(lp);
316341
} catch (Throwable t) {
317342
log("Error preparing NavbarViewInfo: " + t.getMessage());
318343
}

0 commit comments

Comments
 (0)