use of android.support.v7.widget.Toolbar.OnMenuItemClickListener in project AndroidChromium by JackyAndroid.
the class EditorView method prepareToolbar.
/**
* Prepares the toolbar for use.
*
* Many of the things that would ideally be set as attributes don't work and need to be set
* programmatically. This is likely due to how we compile the support libraries.
*/
private void prepareToolbar() {
EditorDialogToolbar toolbar = (EditorDialogToolbar) mLayout.findViewById(R.id.action_bar);
toolbar.setTitle(mEditorModel.getTitle());
toolbar.setTitleTextColor(Color.WHITE);
toolbar.setShowDeleteMenuItem(false);
// Show the help article when the user asks.
toolbar.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
launchAutofillHelpPage(mContext);
return true;
}
});
// Cancel editing when the user hits the back arrow.
toolbar.setNavigationContentDescription(R.string.cancel);
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cancelEdit();
}
});
// Make it appear that the toolbar is floating by adding a shadow.
FadingShadowView shadow = (FadingShadowView) mLayout.findViewById(R.id.shadow);
shadow.init(ApiCompatibilityUtils.getColor(mContext.getResources(), R.color.toolbar_shadow_color), FadingShadow.POSITION_TOP);
// The top shadow is handled by the toolbar, so hide the one used in the field editor.
FadingEdgeScrollView scrollView = (FadingEdgeScrollView) mLayout.findViewById(R.id.scroll_view);
scrollView.setShadowVisibility(false, true);
}
use of android.support.v7.widget.Toolbar.OnMenuItemClickListener in project UltimateAndroid by cymcsg.
the class RecyclerViewStickyHeadersActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recycler_view_sticky_head_activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
list = (RecyclerView) findViewById(R.id.list);
samplesSpinner = (Spinner) findViewById(R.id.samples_spinner);
list.setLayoutManager(new LinearLayoutManager(RecyclerViewStickyHeadersActivity.this, LinearLayoutManager.VERTICAL, false));
personDataProvider = new PersonDataProvider();
personAdapter = new PersonAdapter(personDataProvider);
top = new StickyHeadersBuilder().setAdapter(personAdapter).setRecyclerView(list).setStickyHeadersAdapter(new BigramHeaderAdapter(personDataProvider.getItems())).build();
overlay = new StickyHeadersBuilder().setAdapter(personAdapter).setRecyclerView(list).setStickyHeadersAdapter(new InitialHeaderAdapter(personDataProvider.getItems()), true).build();
// Inflate a menu to be displayed in the toolbar
toolbar.inflateMenu(R.menu.recycler_view_stick_header);
// Set an OnMenuItemClickListener to handle menu item clicks
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.add_item) {
int addedPosition = personDataProvider.insertAfter(list.getChildPosition(list.getChildAt(0)));
personAdapter.notifyItemInserted(addedPosition);
return true;
} else if (item.getItemId() == R.id.github) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/eowise/recyclerview-stickyheaders/"));
startActivity(browserIntent);
return true;
}
return false;
}
});
samplesSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
if (i == 0) {
list.setAdapter(personAdapter);
list.removeItemDecoration(overlay);
list.addItemDecoration(top);
} else {
list.setAdapter(personAdapter);
list.removeItemDecoration(top);
list.addItemDecoration(overlay);
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
use of android.support.v7.widget.Toolbar.OnMenuItemClickListener in project MadMax by deviz92.
the class MainActivity method itemLongClicked.
// Apro popup menu quando ho tenuto premuto un friend o gruppo per 1 secondo
@Override
public void itemLongClicked(String fragmentName, final String itemID, final View v) {
Log.i(TAG, "fragmentName " + fragmentName + " itemID " + itemID);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Bundle bundle = new Bundle();
Intent intent = null;
switch(fragmentName) {
case "FriendsFragment":
PopupMenu popup = new PopupMenu(MainActivity.this, v, Gravity.RIGHT);
popup.getMenuInflater().inflate(R.menu.longclick_popup_menu, popup.getMenu());
one = popup.getMenu().findItem(R.id.one);
one.setTitle("Remove Friend");
popup.getMenu().findItem(R.id.two).setVisible(false);
popup.getMenu().findItem(R.id.three).setVisible(false);
// registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
FirebaseUtils.getInstance().removeFromFriends(currentUID, itemID);
Toast.makeText(MainActivity.this, getString(R.string.friend_removed), Toast.LENGTH_SHORT).show();
return true;
}
});
// showing popup menu
popup.show();
break;
case "GroupsFragment":
popup = new PopupMenu(MainActivity.this, v, Gravity.RIGHT);
popup.getMenuInflater().inflate(R.menu.longclick_popup_menu, popup.getMenu());
one = popup.getMenu().findItem(R.id.one);
one.setTitle("Leave this Group");
two = popup.getMenu().findItem(R.id.two);
two.setTitle("Remove this Group");
popup.getMenu().findItem(R.id.three).setVisible(false);
// registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch((String) item.getTitle()) {
case "Leave this Group":
Integer returnValue = FirebaseUtils.getInstance().leaveGroupFirebase(currentUID, itemID);
if (returnValue == 0) {
Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.credit_group), Toast.LENGTH_LONG);
toast.show();
} else if (returnValue == 1) {
makeText(getApplicationContext(), getString(R.string.debit_group), Toast.LENGTH_LONG).show();
} else if (returnValue == 2) {
makeText(getApplicationContext(), getString(R.string.leaving), Toast.LENGTH_LONG).show();
} else if (returnValue == null) {
makeText(getApplicationContext(), getString(R.string.balance_not_available), Toast.LENGTH_LONG).show();
}
break;
case "Remove this Group":
FirebaseUtils.getInstance().removeGroupFirebase(currentUID, itemID, getApplicationContext());
break;
}
return true;
}
});
// showing popup menu
popup.show();
break;
case "PendingExpensesFragment":
popup = new PopupMenu(MainActivity.this, v, Gravity.RIGHT);
popup.getMenuInflater().inflate(R.menu.longclick_popup_menu, popup.getMenu());
one = popup.getMenu().findItem(R.id.one);
one.setTitle("Remove Pending");
popup.getMenu().findItem(R.id.two).setVisible(false);
popup.getMenu().findItem(R.id.three).setVisible(false);
// registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
databaseReference.child("proposedExpenses").child(itemID).child("creatorID").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (MainActivity.getCurrentUser().getID().matches(dataSnapshot.getValue(String.class))) {
FirebaseUtils.getInstance().removePendingExpenseFirebase(itemID, getApplicationContext());
// add event for PENDING_EXPENSE_REMOVE
/*databaseReference.child("proposedExpenses").child(itemID)
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
User currentUser = MainActivity.getCurrentUser();
Event event = new Event(
dataSnapshot.child("groupID").getValue(String.class),
Event.EventType.PENDING_EXPENSE_REMOVE,
currentUser.getName() + " " + currentUser.getSurname(),
dataSnapshot.child("description").getValue(String.class)
);
event.setDate(new SimpleDateFormat("yyyy.MM.dd").format(new java.util.Date()));
event.setTime(new SimpleDateFormat("HH:mm").format(new java.util.Date()));
FirebaseUtils.getInstance().addEvent(event);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, databaseError.toException());
}
}
);*/
} else
Toast.makeText(MainActivity.this, getString(R.string.not_creator), Toast.LENGTH_SHORT).show();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return true;
}
});
// showing popup menu
popup.show();
break;
}
}
use of android.support.v7.widget.Toolbar.OnMenuItemClickListener in project MadMax by deviz92.
the class GroupDetailActivity method itemLongClicked.
// Apro popup menu quando ho tenuto premuto un friend o gruppo per 1 secondo
@Override
public void itemLongClicked(String fragmentName, final String itemID, View v) {
Log.i(TAG, "fragmentName " + fragmentName + " itemID " + itemID);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Bundle bundle = new Bundle();
Intent intent = null;
switch(fragmentName) {
case "FriendsFragment":
break;
case "GroupsFragment":
popup = new PopupMenu(GroupDetailActivity.this, v, Gravity.RIGHT);
popup.getMenuInflater().inflate(R.menu.longclick_popup_menu, popup.getMenu());
one = popup.getMenu().findItem(R.id.one);
one.setTitle("Remove friend");
popup.getMenu().findItem(R.id.two).setVisible(false);
popup.getMenu().findItem(R.id.three).setVisible(false);
// registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(GroupDetailActivity.this, getString(R.string.clicked) + " " + item.getTitle(), Toast.LENGTH_SHORT).show();
return true;
}
});
// showing popup menu
popup.show();
case "ExpensesFragment":
popup = new PopupMenu(GroupDetailActivity.this, v, Gravity.RIGHT);
popup.getMenuInflater().inflate(R.menu.longclick_popup_menu, popup.getMenu());
one = popup.getMenu().findItem(R.id.one);
one.setTitle("Remove expense");
popup.getMenu().findItem(R.id.two).setVisible(false);
popup.getMenu().findItem(R.id.three).setVisible(false);
// registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
// Toast.makeText(GroupDetailActivity.this,"You Clicked : " + item.getTitle(),Toast.LENGTH_SHORT).show();
FirebaseUtils.getInstance().removeExpenseFirebase(itemID, getApplicationContext());
return true;
}
});
// showing popup menu
popup.show();
break;
}
}
Aggregations