|
59 | 59 | import android.os.Build;
|
60 | 60 | import android.os.IBinder;
|
61 | 61 | import android.provider.Settings;
|
| 62 | +import android.util.TypedValue; |
62 | 63 | import android.view.LayoutInflater;
|
63 | 64 | import android.view.MotionEvent;
|
64 | 65 | import android.view.View;
|
65 | 66 | import android.view.View.MeasureSpec;
|
66 | 67 | import android.view.ViewGroup;
|
67 | 68 | import android.widget.FrameLayout;
|
68 | 69 | import android.widget.ImageView;
|
| 70 | +import android.widget.LinearLayout; |
69 | 71 | import android.widget.TextView;
|
70 | 72 | import de.robv.android.xposed.XC_MethodHook;
|
71 | 73 | import de.robv.android.xposed.XC_MethodReplacement;
|
@@ -270,43 +272,98 @@ private static void updateTileOrderAndVisibility() {
|
270 | 272 | XposedHelpers.callMethod(mContainerView, "updateResources");
|
271 | 273 | }
|
272 | 274 |
|
| 275 | + private static TextView findTileTextView(ViewGroup viewGroup) { |
| 276 | + if (viewGroup == null) return null; |
| 277 | + |
| 278 | + TextView textView = null; |
| 279 | + final int childCount = viewGroup.getChildCount(); |
| 280 | + for (int i = 0; i < childCount; i++) { |
| 281 | + View childView = viewGroup.getChildAt(i); |
| 282 | + if (childView instanceof ViewGroup) { |
| 283 | + textView = findTileTextView((ViewGroup) childView); |
| 284 | + } else if (childView instanceof TextView) { |
| 285 | + textView = (TextView) childView; |
| 286 | + } |
| 287 | + if (textView != null) { |
| 288 | + break; |
| 289 | + } |
| 290 | + } |
| 291 | + |
| 292 | + return textView; |
| 293 | + } |
| 294 | + |
273 | 295 | private static void updateTileLayout(FrameLayout container, int orientation) {
|
274 | 296 | if (container == null) return;
|
275 | 297 |
|
276 | 298 | int tileCount = container.getChildCount();
|
277 | 299 | int textSize = 12;
|
278 | 300 |
|
| 301 | + final Resources res = container.getResources(); |
| 302 | + int imgMarginTop = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, |
| 303 | + 27, res.getDisplayMetrics()); |
| 304 | + int imgMarginBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, |
| 305 | + 17, res.getDisplayMetrics()); |
| 306 | + final int imgResId = res.getIdentifier("image", "id", PACKAGE_NAME); |
| 307 | + final int rssiImgResId = res.getIdentifier("rssi_image", "id", PACKAGE_NAME); |
| 308 | + |
279 | 309 | if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
280 | 310 | switch (mNumColumns) {
|
281 |
| - case 4: textSize = 10; break; |
282 |
| - case 5: textSize = 8; break; |
| 311 | + case 4: |
| 312 | + textSize = 10; |
| 313 | + imgMarginTop = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, |
| 314 | + 17, res.getDisplayMetrics()); |
| 315 | + imgMarginBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, |
| 316 | + 10, res.getDisplayMetrics()); |
| 317 | + break; |
| 318 | + case 5: |
| 319 | + imgMarginTop = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, |
| 320 | + 10, res.getDisplayMetrics()); |
| 321 | + imgMarginBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, |
| 322 | + 5, res.getDisplayMetrics()); |
| 323 | + textSize = 8; |
| 324 | + break; |
283 | 325 | case 3:
|
284 |
| - default: textSize = 12; |
| 326 | + default: |
| 327 | + textSize = 12; |
| 328 | + break; |
285 | 329 | }
|
286 | 330 | }
|
287 | 331 |
|
288 | 332 | for(int i = 0; i < tileCount; i++) {
|
289 | 333 | ViewGroup viewGroup = (ViewGroup) mContainerView.getChildAt(i);
|
290 | 334 | if (viewGroup != null) {
|
291 |
| - int childCount = viewGroup.getChildCount(); |
292 |
| - for(int j = 0; j < childCount; j++) { |
293 |
| - View childView = viewGroup.getChildAt(j); |
294 |
| - TextView targetView = null; |
295 |
| - if (childView instanceof ViewGroup) { |
296 |
| - int innerChildCount = ((ViewGroup) childView).getChildCount(); |
297 |
| - for (int k = 0; k < innerChildCount; k++) { |
298 |
| - View innerChildView = ((ViewGroup) childView).getChildAt(k); |
299 |
| - if (innerChildView instanceof TextView) { |
300 |
| - targetView = (TextView) innerChildView; |
| 335 | + TextView textView = findTileTextView(viewGroup); |
| 336 | + if (textView != null) { |
| 337 | + textView.setTextSize(1, textSize); |
| 338 | + textView.setSingleLine(false); |
| 339 | + textView.setAllCaps(true); |
| 340 | + } |
| 341 | + |
| 342 | + // adjust layout in case it's AOSP 4.3 tile |
| 343 | + if (Build.VERSION.SDK_INT > 17 && imgResId != 0 && rssiImgResId != 0) { |
| 344 | + ImageView img = (ImageView) viewGroup.findViewById(imgResId); |
| 345 | + if (img != null) { |
| 346 | + // basic tile |
| 347 | + if (img.getLayoutParams() instanceof LinearLayout.LayoutParams) { |
| 348 | + LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) img.getLayoutParams(); |
| 349 | + lp.topMargin = imgMarginTop; |
| 350 | + lp.bottomMargin = imgMarginBottom; |
| 351 | + img.setLayoutParams(lp); |
| 352 | + img.requestLayout(); |
| 353 | + } |
| 354 | + } else { |
| 355 | + // RSSI special tile |
| 356 | + img = (ImageView) viewGroup.findViewById(rssiImgResId); |
| 357 | + if (img != null && img.getParent() instanceof FrameLayout) { |
| 358 | + FrameLayout fl = (FrameLayout) img.getParent(); |
| 359 | + if (fl.getLayoutParams() instanceof LinearLayout.LayoutParams) { |
| 360 | + LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) fl.getLayoutParams(); |
| 361 | + lp.topMargin = imgMarginTop; |
| 362 | + lp.bottomMargin = imgMarginBottom; |
| 363 | + fl.setLayoutParams(lp); |
| 364 | + fl.requestLayout(); |
301 | 365 | }
|
302 | 366 | }
|
303 |
| - } else if (childView instanceof TextView) { |
304 |
| - targetView = (TextView) childView; |
305 |
| - } |
306 |
| - if (targetView != null) { |
307 |
| - targetView.setTextSize(1, textSize); |
308 |
| - targetView.setSingleLine(false); |
309 |
| - targetView.setAllCaps(true); |
310 | 367 | }
|
311 | 368 | }
|
312 | 369 | }
|
|
0 commit comments