Search in sources :

Example 86 with PopupMenu

use of android.widget.PopupMenu in project double-espresso by JakeWharton.

the class SendActivity method showPopupMenu.

public boolean showPopupMenu(View view) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        return false;
    }
    PopupMenu popup = new PopupMenu(this, view);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.popup_menu, popup.getMenu());
    popup.show();
    return true;
}
Also used : MenuInflater(android.view.MenuInflater) PopupMenu(android.widget.PopupMenu)

Example 87 with PopupMenu

use of android.widget.PopupMenu in project double-espresso by JakeWharton.

the class MenuActivity method showPopup.

public void showPopup(View view) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        TextView text = (TextView) findViewById(R.id.text_menu_result);
        text.setText("Not supported in API " + Build.VERSION.SDK_INT);
    } else {
        PopupMenu popup = new PopupMenu(this, view);
        popup.setOnMenuItemClickListener(new PopupMenuListener());
        popup.getMenuInflater().inflate(R.menu.popupmenu, popup.getMenu());
        popup.show();
    }
}
Also used : TextView(android.widget.TextView) PopupMenu(android.widget.PopupMenu)

Example 88 with PopupMenu

use of android.widget.PopupMenu in project NPSmiles by bmcglynn1.

the class NewsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View viewer = inflater.inflate(R.layout.activity_news_feed, container, false);
    View popupLayout = inflater.inflate(R.layout.popup_layout_logged_in, null);
    final ListView list = (ListView) viewer.findViewById(R.id.list);
    final ArrayList<NewsMessage> newsList = new ArrayList<>();
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference myRef = database.getReference("Reference");
    mAuth = FirebaseAuth.getInstance();
    if (mAuth.getCurrentUser() != null) {
        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                PopupMenu popup = new PopupMenu(parent.getContext(), view);
                popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu());
                final TextView title = (TextView) view.findViewById(R.id.title);
                final TextView message = (TextView) view.findViewById(R.id.information);
                if (mAuth.getCurrentUser() != null) {
                    popup.show();
                    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            switch(item.getItemId()) {
                                case R.id.EditMenu:
                                    // refresh view if needed
                                    break;
                                case R.id.DeleteMenu:
                                    // delete from firebase
                                    // refresh view
                                    FirebaseDatabase database = FirebaseDatabase.getInstance();
                                    DatabaseReference myRef = database.getReference("Reference");
                                    Query titleQuery = myRef.child(title.getText().toString());
                                    titleQuery.addListenerForSingleValueEvent(new ValueEventListener() {

                                        @Override
                                        public void onDataChange(DataSnapshot dataSnapshot) {
                                            for (DataSnapshot titleSnapshot : dataSnapshot.getChildren()) {
                                                dataSnapshot.getRef().removeValue();
                                            }
                                        }

                                        @Override
                                        public void onCancelled(DatabaseError databaseError) {
                                        }
                                    });
                                    break;
                            }
                            return true;
                        }
                    });
                }
            }
        });
    }
    myRef.addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            newsList.clear();
            for (DataSnapshot newsItem : dataSnapshot.getChildren()) {
                NewsMessage newsMessage = new NewsMessage();
                for (DataSnapshot item : newsItem.getChildren()) {
                    if (item.getKey().equals("title")) {
                        newsMessage.setTitle((String) item.getValue());
                    } else if (item.getKey().equals("message")) {
                        newsMessage.setMessage((String) item.getValue());
                    } else {
                        newsMessage.setDate((String) item.getValue());
                    }
                }
                newsList.add(newsMessage);
            }
            Collections.sort(newsList);
            CustomAdapter adapter = new CustomAdapter(context, newsList);
            list.setAdapter(adapter);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    return viewer;
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) Query(com.google.firebase.database.Query) DatabaseReference(com.google.firebase.database.DatabaseReference) ArrayList(java.util.ArrayList) MenuItem(android.view.MenuItem) DataSnapshot(com.google.firebase.database.DataSnapshot) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ListView(android.widget.ListView) DatabaseError(com.google.firebase.database.DatabaseError) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ValueEventListener(com.google.firebase.database.ValueEventListener) PopupMenu(android.widget.PopupMenu)

Aggregations

PopupMenu (android.widget.PopupMenu)88 MenuItem (android.view.MenuItem)52 View (android.view.View)38 TextView (android.widget.TextView)35 ImageView (android.widget.ImageView)29 RecyclerView (android.support.v7.widget.RecyclerView)21 TargetApi (android.annotation.TargetApi)20 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)19 Test (org.junit.Test)19 ShadowPopupMenu (org.robolectric.shadows.ShadowPopupMenu)19 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)18 Context (android.content.Context)12 DialogAction (com.afollestad.materialdialogs.DialogAction)12 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)12 Intent (android.content.Intent)11 NonNull (android.support.annotation.NonNull)8 Menu (android.view.Menu)7 AdapterView (android.widget.AdapterView)6 ListView (android.widget.ListView)6 Song (io.hefuyi.listener.mvp.model.Song)6