From 58572ba858835437011d2f450bd90fb93455b5c9 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Wed, 6 Apr 2016 20:08:31 +0200 Subject: basic overlay for avatar as 'logo' added to action bar --- .../conversationsplus/ui/ConversationActivity.java | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java') diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java index 5942bac6..dbaa5a7c 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java @@ -22,14 +22,18 @@ import android.util.Log; import android.util.Pair; import android.view.Gravity; import android.view.KeyEvent; +import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.Surface; import android.view.View; +import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.CheckBox; +import android.widget.ImageView; import android.widget.PopupMenu; import android.widget.PopupMenu.OnMenuItemClickListener; import android.widget.Toast; @@ -45,6 +49,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.ConversationsPlusPreferences; +import de.thedevstack.conversationsplus.services.AvatarService; import de.thedevstack.conversationsplus.ui.dialogs.UserDecisionDialog; import de.thedevstack.conversationsplus.ui.listeners.ResizePictureUserDecisionListener; import de.timroes.android.listview.EnhancedListView; @@ -110,6 +115,7 @@ public class ConversationActivity extends XmppActivity private boolean conversationWasSelectedByKeyboard = false; private View mContentView; + private View avatarLogoView; private List conversationList = new ArrayList<>(); private Conversation swipedConversation = null; @@ -348,6 +354,7 @@ public class ConversationActivity extends XmppActivity final Conversation conversation = getSelectedConversation(); if (ab != null) { if (titleShouldBeName && conversation != null) { + this.updateLogoAvatar(true); ab.setDisplayHomeAsUpEnabled(true); ab.setHomeButtonEnabled(true); if (conversation.getMode() == Conversation.MODE_SINGLE || ConversationsPlusPreferences.useSubject()) { @@ -359,10 +366,66 @@ public class ConversationActivity extends XmppActivity ab.setDisplayHomeAsUpEnabled(false); ab.setHomeButtonEnabled(false); ab.setTitle(R.string.app_name); + this.updateLogoAvatar(false); } } } + private void updateLogoAvatar(boolean show) { + if (null == this.avatarLogoView) { + this.avatarLogoView = LayoutInflater.from(this).inflate(R.layout.logo_view, null, false); + ViewGroup decorViewGroup = (ViewGroup) getWindow().getDecorView(); + decorViewGroup.addView(avatarLogoView); + int resId = getResources().getIdentifier("action_bar_container", "id", "android"); + final View actionBarView = decorViewGroup.findViewById(resId); + final View iconPlaceholderView = decorViewGroup.findViewById(R.id.icon_placeholder); + if (actionBarView != null) { + actionBarView.getViewTreeObserver().addOnGlobalLayoutListener( + new ViewTreeObserver.OnGlobalLayoutListener() { + public void onGlobalLayout() { + // Remove the listener + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + actionBarView.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } else { + actionBarView.getViewTreeObserver().removeGlobalOnLayoutListener(this); + } + + // Measure views + int[] location = new int[2]; + actionBarView.getLocationOnScreen(location); + + int[] logoLocation = new int[2]; + avatarLogoView.getLocationOnScreen(logoLocation); + + int[] iconPlaceHolderLocation = new int[2]; + if (null != iconPlaceholderView) { + iconPlaceholderView.getLocationOnScreen(iconPlaceHolderLocation); + }else { + iconPlaceHolderLocation[0] = 0; + } + + // Add top padding if necessary + if (location[1] > logoLocation[1]) { + avatarLogoView.setPadding(iconPlaceHolderLocation[0], actionBarView.getMeasuredHeight() / 4 + location[1] - logoLocation[1], 0, 0); + } + /*if (iconPlaceHolderLocation[0] > logoLocation[0]) { + avatarLogoView.setPadding + }*/ + } + } + ); + } + } + if (show) { + ImageView avatarView = (ImageView) this.avatarLogoView.findViewById(R.id.logoViewAvatar); + avatarView.setImageBitmap(AvatarService.getInstance().get(getSelectedConversation(), getPixel(56))); + //avatarView.setAlpha(0.5f); + avatarLogoView.setVisibility(View.VISIBLE); + } else { + avatarLogoView.setVisibility(View.GONE); + } + } + private void openConversation() { this.updateActionBarTitle(); this.invalidateOptionsMenu(); -- cgit v1.2.3