Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1adc29d8 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Make sure to close popup before orientation changes..

to avoid window leak.

Even with this CL there'll be an error message shown on orientaion changes,
but it's a framework issue that even the framework Spinner has.
(bug filed)

Bug 5209304

Change-Id: I0b8335e9b875a23c48b19bf65462d037c0dba6c1
parent 1a6ffdef
Loading
Loading
Loading
Loading
+19 −12
Original line number Diff line number Diff line
@@ -211,6 +211,8 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen
    private boolean mIsUniqueNumber;
    private boolean mIsUniqueEmail;

    private ListPopupWindow mPopup;

    public ContactDetailFragment() {
        // Explicit constructor for inflation
    }
@@ -235,6 +237,7 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen

    @Override
    public void onPause() {
        dismissPopupIfShown();
        super.onPause();
    }

@@ -288,10 +291,6 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen
        return mView;
    }

    protected View inflate(int resource, ViewGroup root, boolean attachToRoot) {
        return mInflater.inflate(resource, root, attachToRoot);
    }

    public void setListener(Listener value) {
        mListener = value;
    }
@@ -1006,23 +1005,31 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen
     */
    private void showListPopup(View anchorView, ListAdapter adapter,
            final AdapterView.OnItemClickListener onItemClickListener) {
        final ListPopupWindow popup = new ListPopupWindow(mContext, null);
        popup.setAnchorView(anchorView);
        popup.setWidth(anchorView.getWidth());
        popup.setAdapter(adapter);
        popup.setModal(true);
        dismissPopupIfShown();
        mPopup = new ListPopupWindow(mContext, null);
        mPopup.setAnchorView(anchorView);
        mPopup.setWidth(anchorView.getWidth());
        mPopup.setAdapter(adapter);
        mPopup.setModal(true);

        // We need to wrap the passed onItemClickListener here, so that we can dismiss() the
        // popup afterwards.  Otherwise we could directly use the passed listener.
        popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        mPopup.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position,
                    long id) {
                onItemClickListener.onItemClick(parent, view, position, id);
                popup.dismiss();
                dismissPopupIfShown();
            }
        });
        popup.show();
        mPopup.show();
    }

    private void dismissPopupIfShown() {
        if (mPopup != null && mPopup.isShowing()) {
            mPopup.dismiss();
        }
        mPopup = null;
    }

    /**