2015-03-11 21:23:45 +00:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.support.annotation.NonNull;
|
2015-07-10 23:11:58 +00:00
|
|
|
import android.support.v7.widget.ListPopupWindow;
|
2015-03-11 21:23:45 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.ListView;
|
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-07-10 23:11:58 +00:00
|
|
|
public class TransportOptionsPopup extends ListPopupWindow implements ListView.OnItemClickListener {
|
2015-03-11 21:23:45 +00:00
|
|
|
|
|
|
|
private final TransportOptionsAdapter adapter;
|
|
|
|
private final SelectedListener listener;
|
|
|
|
|
2015-07-10 23:11:58 +00:00
|
|
|
public TransportOptionsPopup(@NonNull Context context, @NonNull View anchor, @NonNull SelectedListener listener) {
|
|
|
|
super(context);
|
2015-03-11 21:23:45 +00:00
|
|
|
this.listener = listener;
|
|
|
|
this.adapter = new TransportOptionsAdapter(context, new LinkedList<TransportOption>());
|
|
|
|
|
2015-07-10 23:11:58 +00:00
|
|
|
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));
|
2015-07-01 00:45:39 +00:00
|
|
|
|
2015-07-10 23:11:58 +00:00
|
|
|
setOnItemClickListener(this);
|
2015-03-11 21:23:45 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 23:11:58 +00:00
|
|
|
public void display(List<TransportOption> enabledTransports) {
|
|
|
|
adapter.setEnabledTransports(enabledTransports);
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
show();
|
2015-03-11 21:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
listener.onSelected((TransportOption)adapter.getItem(position));
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface SelectedListener {
|
2015-07-01 00:45:39 +00:00
|
|
|
void onSelected(TransportOption option);
|
2015-03-11 21:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|