use of org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem in project AndroidChromium by JackyAndroid.
the class BookmarkEditActivity method updateViewContent.
/**
* @param modelChanged Whether this view update is due to a model change in background.
*/
private void updateViewContent(boolean modelChanged) {
BookmarkItem bookmarkItem = mModel.getBookmarkById(mBookmarkId);
// While the user is editing the bookmark, do not override user's input.
if (!modelChanged) {
mTitleEditText.setText(bookmarkItem.getTitle());
mUrlEditText.setText(bookmarkItem.getUrl());
}
mFolderTextView.setText(mModel.getBookmarkTitle(bookmarkItem.getParentId()));
mTitleEditText.setEnabled(bookmarkItem.isEditable());
mUrlEditText.setEnabled(bookmarkItem.isUrlEditable());
mFolderTextView.setEnabled(bookmarkItem.isMovable());
}
use of org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem in project AndroidChromium by JackyAndroid.
the class BookmarkActionBar method onSelectionStateChange.
@Override
public void onSelectionStateChange(List<BookmarkId> selectedBookmarks) {
super.onSelectionStateChange(selectedBookmarks);
if (mIsSelectionEnabled) {
// Editing a bookmark action on multiple selected items doesn't make sense. So disable.
getMenu().findItem(R.id.selection_mode_edit_menu_id).setVisible(selectedBookmarks.size() == 1);
getMenu().findItem(R.id.selection_open_in_incognito_tab_id).setVisible(PrefServiceBridge.getInstance().isIncognitoModeEnabled());
// It does not make sense to open a folder in new tab.
for (BookmarkId bookmark : selectedBookmarks) {
BookmarkItem item = mDelegate.getModel().getBookmarkById(bookmark);
if (item != null && item.isFolder()) {
getMenu().findItem(R.id.selection_open_in_new_tab_id).setVisible(false);
getMenu().findItem(R.id.selection_open_in_incognito_tab_id).setVisible(false);
break;
}
}
// disable the move button.
for (BookmarkId bookmark : selectedBookmarks) {
if (bookmark.getType() == BookmarkType.PARTNER) {
getMenu().findItem(R.id.selection_mode_move_menu_id).setVisible(false);
break;
}
}
} else {
mDelegate.notifyStateChange(this);
}
}
use of org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem in project AndroidChromium by JackyAndroid.
the class BookmarkAddEditFolderActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mModel = new BookmarkModel();
mModel.addObserver(mBookmarkModelObserver);
mIsAddMode = getIntent().getBooleanExtra(INTENT_IS_ADD_MODE, false);
if (mIsAddMode) {
List<String> stringList = getIntent().getStringArrayListExtra(BookmarkFolderSelectActivity.INTENT_BOOKMARKS_TO_MOVE);
mBookmarksToMove = new ArrayList<>(stringList.size());
for (String string : stringList) {
mBookmarksToMove.add(BookmarkId.getBookmarkIdFromString(string));
}
} else {
mFolderId = BookmarkId.getBookmarkIdFromString(getIntent().getStringExtra(INTENT_BOOKMARK_ID));
}
setContentView(R.layout.bookmark_add_edit_folder_activity);
mParentTextView = (TextView) findViewById(R.id.parent_folder);
mFolderTitle = (EmptyAlertEditText) findViewById(R.id.folder_title);
mParentTextView.setOnClickListener(this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (mIsAddMode) {
getSupportActionBar().setTitle(R.string.add_folder);
updateParent(mModel.getDefaultFolder());
} else {
// Edit mode
getSupportActionBar().setTitle(R.string.edit_folder);
BookmarkItem bookmarkItem = mModel.getBookmarkById(mFolderId);
updateParent(bookmarkItem.getParentId());
mFolderTitle.setText(bookmarkItem.getTitle());
mFolderTitle.setSelection(mFolderTitle.getText().length());
mParentTextView.setEnabled(bookmarkItem.isMovable());
}
mParentTextView.setText(mModel.getBookmarkTitle(mParentId));
}
use of org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem in project AndroidChromium by JackyAndroid.
the class BookmarkRow method showMenu.
/**
* Show drop-down menu after user click on more-info icon
* @param view The anchor view for the menu
*/
private void showMenu(View view) {
if (mPopupMenu == null) {
mPopupMenu = new ListPopupWindow(getContext(), null, 0, R.style.BookmarkMenuStyle);
mPopupMenu.setAdapter(new ArrayAdapter<String>(getContext(), R.layout.bookmark_popup_item, new String[] { getContext().getString(R.string.bookmark_item_select), getContext().getString(R.string.bookmark_item_edit), getContext().getString(R.string.bookmark_item_move), getContext().getString(R.string.bookmark_item_delete) }) {
private static final int MOVE_POSITION = 2;
@Override
public boolean areAllItemsEnabled() {
return false;
}
@Override
public boolean isEnabled(int position) {
// activity is killed (crbug.com/594213), so null check here.
if (mDelegate == null || mDelegate.getModel() == null)
return false;
if (position == MOVE_POSITION) {
BookmarkItem bookmark = mDelegate.getModel().getBookmarkById(mBookmarkId);
if (bookmark == null)
return false;
return bookmark.isMovable();
}
return true;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
view.setEnabled(isEnabled(position));
return view;
}
});
mPopupMenu.setAnchorView(view);
mPopupMenu.setWidth(getResources().getDimensionPixelSize(R.dimen.bookmark_item_popup_width));
mPopupMenu.setVerticalOffset(-view.getHeight());
mPopupMenu.setModal(true);
mPopupMenu.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position == 0) {
setChecked(mDelegate.getSelectionDelegate().toggleSelectionForItem(mBookmarkId));
} else if (position == 1) {
BookmarkItem item = mDelegate.getModel().getBookmarkById(mBookmarkId);
if (item.isFolder()) {
BookmarkAddEditFolderActivity.startEditFolderActivity(getContext(), item.getId());
} else {
BookmarkUtils.startEditActivity(getContext(), item.getId());
}
} else if (position == 2) {
BookmarkFolderSelectActivity.startFolderSelectActivity(getContext(), mBookmarkId);
} else if (position == 3) {
if (mDelegate != null && mDelegate.getModel() != null) {
mDelegate.getModel().deleteBookmarks(mBookmarkId);
}
}
// http://crbug.com/600642
if (mPopupMenu != null)
mPopupMenu.dismiss();
}
});
}
mPopupMenu.show();
mPopupMenu.getListView().setDivider(null);
}
use of org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem in project AndroidChromium by JackyAndroid.
the class BookmarkActionBar method onMenuItemClick.
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
SelectionDelegate<BookmarkId> selectionDelegate = mDelegate.getSelectionDelegate();
if (menuItem.getItemId() == R.id.edit_menu_id) {
BookmarkAddEditFolderActivity.startEditFolderActivity(getContext(), mCurrentFolder.getId());
return true;
} else if (menuItem.getItemId() == R.id.close_menu_id) {
BookmarkUtils.finishActivityOnPhone(getContext());
return true;
} else if (menuItem.getItemId() == R.id.search_menu_id) {
mDelegate.openSearchUI();
return true;
} else if (menuItem.getItemId() == R.id.selection_mode_edit_menu_id) {
List<BookmarkId> list = selectionDelegate.getSelectedItems();
assert list.size() == 1;
BookmarkItem item = mDelegate.getModel().getBookmarkById(list.get(0));
if (item.isFolder()) {
BookmarkAddEditFolderActivity.startEditFolderActivity(getContext(), item.getId());
} else {
BookmarkUtils.startEditActivity(getContext(), item.getId());
}
return true;
} else if (menuItem.getItemId() == R.id.selection_mode_move_menu_id) {
List<BookmarkId> list = selectionDelegate.getSelectedItems();
if (list.size() >= 1) {
BookmarkFolderSelectActivity.startFolderSelectActivity(getContext(), list.toArray(new BookmarkId[list.size()]));
}
return true;
} else if (menuItem.getItemId() == R.id.selection_mode_delete_menu_id) {
mDelegate.getModel().deleteBookmarks(selectionDelegate.getSelectedItems().toArray(new BookmarkId[0]));
return true;
} else if (menuItem.getItemId() == R.id.selection_open_in_new_tab_id) {
openBookmarksInNewTabs(selectionDelegate.getSelectedItems(), new TabDelegate(false), mDelegate.getModel());
selectionDelegate.clearSelection();
return true;
} else if (menuItem.getItemId() == R.id.selection_open_in_incognito_tab_id) {
openBookmarksInNewTabs(selectionDelegate.getSelectedItems(), new TabDelegate(true), mDelegate.getModel());
selectionDelegate.clearSelection();
return true;
}
assert false : "Unhandled menu click.";
return false;
}
Aggregations