From fe78f858bacf54f8285db31b7d6aa65ff3628f15 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Mon, 16 May 2016 01:35:46 +0200 Subject: avatar displayed as a circle, positioning adjusted, colors changed back to correct ones, positioning moved to own class file --- .../listeners/AvatarLogoPositioningListener.java | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/main/java/de/thedevstack/conversationsplus/ui/listeners/AvatarLogoPositioningListener.java (limited to 'src/main/java/de/thedevstack/conversationsplus/ui/listeners/AvatarLogoPositioningListener.java') diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/AvatarLogoPositioningListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/AvatarLogoPositioningListener.java new file mode 100644 index 00000000..e6846d9b --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/AvatarLogoPositioningListener.java @@ -0,0 +1,57 @@ +package de.thedevstack.conversationsplus.ui.listeners; + +import android.os.Build; +import android.view.View; +import android.view.ViewTreeObserver; + +import de.thedevstack.conversationsplus.R; + +/** + * This listener aims to position the avatar logo. + */ +public class AvatarLogoPositioningListener implements ViewTreeObserver.OnGlobalLayoutListener { + private View actionBarView; + private View avatarLogoView; + + public AvatarLogoPositioningListener(View actionBarView, View avatarLogoView) { + this.actionBarView = actionBarView; + this.avatarLogoView = avatarLogoView; + } + + @Override + public void onGlobalLayout() { + // Measure views + int[] location = new int[2]; + this.actionBarView.getLocationOnScreen(location); + + int[] logoLocation = new int[2]; + this.avatarLogoView.getLocationOnScreen(logoLocation); + + int[] titleViewLocation = new int[2]; + View titleView = this.actionBarView.findViewById(R.id.conversationsTitle); + int oldTitleViewLeftPadding = 0; + if (null != titleView) { + // Remove the listener only if all necessary view elements are there + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + this.actionBarView.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } else { + this.actionBarView.getViewTreeObserver().removeGlobalOnLayoutListener(this); + } + + titleView.getLocationOnScreen(titleViewLocation); + int avatarWidth = (int) (58 * titleView.getResources().getDisplayMetrics().density); + int newTitleViewLeftPadding = titleViewLocation[0] + avatarWidth; + titleView.setPadding(newTitleViewLeftPadding, titleView.getPaddingTop(), 0, 0); + oldTitleViewLeftPadding = titleViewLocation[0]; + } + + // Add top padding if necessary + if (location[1] > logoLocation[1]) { + int actionBarViewHeight = this.actionBarView.getMeasuredHeight(); + int newAvatarLogoTopPadding = location[1]; // Move to the top padding of the action bar (below the notification bar) + newAvatarLogoTopPadding += actionBarViewHeight; + newAvatarLogoTopPadding -= 58 * avatarLogoView.getResources().getDisplayMetrics().density * 0.6; + this.avatarLogoView.setPadding(oldTitleViewLeftPadding, newAvatarLogoTopPadding, 0, 0); + } + } +} -- cgit v1.2.3