diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java index de69c1e6..7138f8e3 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.thedevstack.conversationsplus.utils.ConversationUtil; @@ -112,6 +117,7 @@ public class ConversationActivity extends XmppActivity protected boolean mUsingEnterKey = false; private View mContentView; + private View avatarLogoView; private List<Conversation> conversationList = new ArrayList<>(); private Conversation swipedConversation = null; @@ -351,6 +357,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()) { @@ -362,10 +369,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(); |