make TransportOptionsPopup a ListPopupWindow

disable circular reveal at least for now

Fixes #3600
Closes #3607
// FREEBIE
master
Jake McGinty 2015-07-10 16:11:58 -07:00 committed by Moxie Marlinspike
parent e603142215
commit 35159ac456
3 changed files with 18 additions and 114 deletions

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?conversation_transport_popup_background"
android:elevation="2dp">
<ListView android:id="@+id/transport_selection_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -1,124 +1,40 @@
package org.thoughtcrime.securesms;
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.support.v7.widget.ListPopupWindow;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.PopupWindow;
import java.util.LinkedList;
import java.util.List;
public class TransportOptionsPopup implements ListView.OnItemClickListener {
public class TransportOptionsPopup extends ListPopupWindow implements ListView.OnItemClickListener {
private final TransportOptionsAdapter adapter;
private final PopupWindow popupWindow;
private final SelectedListener listener;
private OnGlobalLayoutListener observer;
private View parent;
public TransportOptionsPopup(@NonNull Context context, @NonNull SelectedListener listener) {
public TransportOptionsPopup(@NonNull Context context, @NonNull View anchor, @NonNull SelectedListener listener) {
super(context);
this.listener = listener;
this.adapter = new TransportOptionsAdapter(context, new LinkedList<TransportOption>());
View selectionMenu = LayoutInflater.from(context).inflate(R.layout.transport_selection, null);
ListView listView = (ListView) selectionMenu.findViewById(R.id.transport_selection_list);
setVerticalOffset(context.getResources().getDimensionPixelOffset(R.dimen.transport_selection_popup_yoff));
setHorizontalOffset(context.getResources().getDimensionPixelOffset(R.dimen.transport_selection_popup_xoff));
setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
setModal(true);
setAnchorView(anchor);
setAdapter(adapter);
setContentWidth(context.getResources().getDimensionPixelSize(R.dimen.transport_selection_popup_width));
listView.setAdapter(adapter);
this.popupWindow = new PopupWindow(selectionMenu);
this.popupWindow.setFocusable(true);
this.popupWindow.setBackgroundDrawable(new BitmapDrawable(context.getResources(), ""));
this.popupWindow.setOutsideTouchable(true);
this.popupWindow.setWindowLayoutMode(0, WindowManager.LayoutParams.WRAP_CONTENT);
this.popupWindow.setWidth(context.getResources().getDimensionPixelSize(R.dimen.transport_selection_popup_width));
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
this.popupWindow.setAnimationStyle(0);
this.popupWindow.setElevation(context.getResources().getDimensionPixelSize(R.dimen.transport_selection_popup_yoff));
}
listView.setOnItemClickListener(this);
setOnItemClickListener(this);
}
public void display(Context context, final View parent, List<TransportOption> enabledTransports) {
this.adapter.setEnabledTransports(enabledTransports);
this.adapter.notifyDataSetChanged();
final int xoff = context.getResources().getDimensionPixelOffset(R.dimen.transport_selection_popup_xoff);
final int yoff = context.getResources().getDimensionPixelOffset(R.dimen.transport_selection_popup_yoff);
popupWindow.showAsDropDown(parent, xoff, yoff);
animateInIfAvailable();
this.parent = parent;
this.observer = new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
popupWindow.update(parent, xoff, yoff, -1, -1);
}
};
parent.getViewTreeObserver().addOnGlobalLayoutListener(observer);
}
@TargetApi(VERSION_CODES.LOLLIPOP) private Animator getCircularReveal(View v, boolean in) {
int outBound = Math.max(v.getWidth(), v.getHeight());
return ViewAnimationUtils.createCircularReveal(v,
v.getMeasuredWidth(),
v.getMeasuredHeight(),
in ? 0 : outBound,
in ? outBound : 0)
.setDuration(200);
}
private void animateInIfAvailable() {
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
popupWindow.getContentView().getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override @TargetApi(VERSION_CODES.LOLLIPOP) public void onGlobalLayout() {
parent.getViewTreeObserver().removeGlobalOnLayoutListener(this);
if (popupWindow.getContentView().isAttachedToWindow()) {
getCircularReveal(popupWindow.getContentView(), true).start();
}
}
});
}
}
private void animateOutIfAvailable() {
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
Animator animator = getCircularReveal(popupWindow.getContentView(), false);
animator.addListener(new AnimatorListener() {
@Override public void onAnimationStart(Animator animation) {}
@Override public void onAnimationCancel(Animator animation) {}
@Override public void onAnimationRepeat(Animator animation) {}
@Override public void onAnimationEnd(Animator animation) {
popupWindow.dismiss();
}
});
animator.start();
} else {
popupWindow.dismiss();
}
}
public void dismiss() {
animateOutIfAvailable();
if (this.observer != null && this.parent != null) {
parent.getViewTreeObserver().removeGlobalOnLayoutListener(observer);
}
this.observer = null;
this.parent = null;
public void display(List<TransportOption> enabledTransports) {
adapter.setEnabledTransports(enabledTransports);
adapter.notifyDataSetChanged();
show();
}
@Override

View File

@ -50,7 +50,7 @@ public class SendButton extends ImageButton
}
private TransportOptionsPopup initializeTransportOptionsPopup() {
return new TransportOptionsPopup(getContext(), this);
return new TransportOptionsPopup(getContext(), this, this);
}
public boolean isManualSelection() {
@ -92,7 +92,7 @@ public class SendButton extends ImageButton
@Override
public boolean onLongClick(View v) {
if (transportOptions.getEnabledTransports().size() > 1) {
transportOptionsPopup.display(getContext(), SendButton.this, transportOptions.getEnabledTransports());
transportOptionsPopup.display(transportOptions.getEnabledTransports());
return true;
}