Java Code Examples for org.chromium.components.bookmarks.BookmarkId#getBookmarkIdFromString()

The following examples show how to use org.chromium.components.bookmarks.BookmarkId#getBookmarkIdFromString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BookmarkUIState.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * @return A state corresponding to the URI object. If the URI is not valid,
 *         return all_bookmarks.
 */
static BookmarkUIState createStateFromUrl(Uri uri, BookmarkModel bookmarkModel) {
    BookmarkUIState state = new BookmarkUIState();
    state.mState = STATE_INVALID;
    state.mUrl = uri.toString();

    if (state.mUrl.equals(UrlConstants.BOOKMARKS_URL)) {
        return createFolderState(bookmarkModel.getDefaultFolder(), bookmarkModel);
    } else if (state.mUrl.startsWith(UrlConstants.BOOKMARKS_FOLDER_URL)) {
        String path = uri.getLastPathSegment();
        if (!path.isEmpty()) {
            state.mFolder = BookmarkId.getBookmarkIdFromString(path);
            state.mState = STATE_FOLDER;
        }
    }

    if (!state.isValid(bookmarkModel)) {
        state = createFolderState(bookmarkModel.getDefaultFolder(), bookmarkModel);
    }

    return state;
}
 
Example 2
Source File: BookmarkUIState.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * @return A state corresponding to the URI object. If the URI is not valid,
 *         return all_bookmarks.
 */
static BookmarkUIState createStateFromUrl(Uri uri, BookmarkModel bookmarkModel) {
    BookmarkUIState state = new BookmarkUIState();
    state.mState = STATE_INVALID;
    state.mUrl = uri.toString();

    if (state.mUrl.equals(UrlConstants.BOOKMARKS_URL)) {
        return createFolderState(bookmarkModel.getDefaultFolder(), bookmarkModel);
    } else if (state.mUrl.startsWith(UrlConstants.BOOKMARKS_FOLDER_URL)) {
        String path = uri.getLastPathSegment();
        if (!path.isEmpty()) {
            state.mFolder = BookmarkId.getBookmarkIdFromString(path);
            state.mState = STATE_FOLDER;
        }
    }

    if (!state.isValid(bookmarkModel)) {
        state = createFolderState(bookmarkModel.getDefaultFolder(), bookmarkModel);
    }

    return state;
}
 
Example 3
Source File: BookmarkFolderSelectActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mModel = new BookmarkModel();
    mModel.addObserver(mBookmarkModelObserver);
    List<String> stringList = getIntent().getStringArrayListExtra(INTENT_BOOKMARKS_TO_MOVE);
    mBookmarksToMove = new ArrayList<>(stringList.size());
    for (String string : stringList) {
        BookmarkId bookmarkId = BookmarkId.getBookmarkIdFromString(string);
        if (mModel.doesBookmarkExist(bookmarkId)) {
            mBookmarksToMove.add(bookmarkId);
        }
    }
    if (mBookmarksToMove.isEmpty()) {
        finish();
        return;
    }

    mIsCreatingFolder = getIntent().getBooleanExtra(INTENT_IS_CREATING_FOLDER, false);
    if (mIsCreatingFolder) {
        mParentId = mModel.getMobileFolderId();
    } else {
        mParentId = mModel.getBookmarkById(mBookmarksToMove.get(0))
                .getParentId();
    }

    setContentView(R.layout.bookmark_folder_select_activity);
    mBookmarkIdsList = (ListView) findViewById(R.id.bookmark_folder_list);
    mBookmarkIdsList.setOnItemClickListener(this);
    mBookmarkIdsAdapter = new FolderListAdapter(this);
    mBookmarkIdsList.setAdapter(mBookmarkIdsAdapter);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    updateFolderList();
}
 
Example 4
Source File: BookmarkUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @return The parent {@link BookmarkId} that the user used the last time or null if the user
 *         has never selected a parent folder to use.
 */
static BookmarkId getLastUsedParent(Context context) {
    SharedPreferences preferences = ContextUtils.getAppSharedPreferences();
    if (!preferences.contains(PREF_LAST_USED_PARENT)) return null;

    return BookmarkId.getBookmarkIdFromString(
            preferences.getString(PREF_LAST_USED_PARENT, null));
}
 
Example 5
Source File: BookmarkFolderSelectActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mModel = new BookmarkModel();
    mModel.addObserver(mBookmarkModelObserver);
    List<String> stringList = getIntent().getStringArrayListExtra(INTENT_BOOKMARKS_TO_MOVE);
    mBookmarksToMove = new ArrayList<>(stringList.size());
    for (String string : stringList) {
        BookmarkId bookmarkId = BookmarkId.getBookmarkIdFromString(string);
        if (mModel.doesBookmarkExist(bookmarkId)) {
            mBookmarksToMove.add(bookmarkId);
        }
    }
    if (mBookmarksToMove.isEmpty()) {
        finish();
        return;
    }

    mIsCreatingFolder = getIntent().getBooleanExtra(INTENT_IS_CREATING_FOLDER, false);
    if (mIsCreatingFolder) {
        mParentId = mModel.getMobileFolderId();
    } else {
        mParentId = mModel.getBookmarkById(mBookmarksToMove.get(0))
                .getParentId();
    }

    setContentView(R.layout.bookmark_folder_select_activity);
    mBookmarkIdsList = (ListView) findViewById(R.id.bookmark_folder_list);
    mBookmarkIdsList.setOnItemClickListener(this);
    mBookmarkIdsAdapter = new FolderListAdapter(this);
    mBookmarkIdsList.setAdapter(mBookmarkIdsAdapter);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    updateFolderList();
}
 
Example 6
Source File: BookmarkActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == EDIT_BOOKMARK_REQUEST_CODE && resultCode == RESULT_OK) {
        BookmarkId bookmarkId = BookmarkId.getBookmarkIdFromString(data.getStringExtra(
                INTENT_VISIT_BOOKMARK_ID));
        mBookmarkManager.openBookmark(bookmarkId, BookmarkLaunchLocation.BOOKMARK_EDITOR);
    }
}
 
Example 7
Source File: BookmarkEditActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mModel = new BookmarkModel();
    mBookmarkId = BookmarkId.getBookmarkIdFromString(
            getIntent().getStringExtra(INTENT_BOOKMARK_ID));
    mModel.addObserver(mBookmarkModelObserver);
    BookmarkItem item = mModel.getBookmarkById(mBookmarkId);
    if (!mModel.doesBookmarkExist(mBookmarkId) || item == null) {
        finish();
        return;
    }

    setContentView(R.layout.bookmark_edit);
    mTitleEditText = (EmptyAlertEditText) findViewById(R.id.title_text);
    mFolderTextView = (TextView) findViewById(R.id.folder_text);
    mUrlEditText = (EmptyAlertEditText) findViewById(R.id.url_text);

    mFolderTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            BookmarkFolderSelectActivity.startFolderSelectActivity(
                    BookmarkEditActivity.this, mBookmarkId);
        }
    });

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    updateViewContent(false);
}
 
Example 8
Source File: BookmarkWidgetService.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@BinderThread
private void updateBookmarkList() {
    BookmarkId folderId = BookmarkId
            .getBookmarkIdFromString(mPreferences.getString(PREF_CURRENT_FOLDER, null));
    mCurrentFolder = loadBookmarks(folderId);
    mPreferences.edit().putString(PREF_CURRENT_FOLDER, mCurrentFolder.folder.id.toString())
            .apply();
}
 
Example 9
Source File: BookmarkActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == EDIT_BOOKMARK_REQUEST_CODE && resultCode == RESULT_OK) {
        BookmarkId bookmarkId = BookmarkId.getBookmarkIdFromString(data.getStringExtra(
                INTENT_VISIT_BOOKMARK_ID));
        mBookmarkManager.openBookmark(bookmarkId, BookmarkLaunchLocation.BOOKMARK_EDITOR);
    }
}
 
Example 10
Source File: BookmarkUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @return The parent {@link BookmarkId} that the user used the last time or null if the user
 *         has never selected a parent folder to use.
 */
static BookmarkId getLastUsedParent(Context context) {
    SharedPreferences preferences = ContextUtils.getAppSharedPreferences();
    if (!preferences.contains(PREF_LAST_USED_PARENT)) return null;

    return BookmarkId.getBookmarkIdFromString(
            preferences.getString(PREF_LAST_USED_PARENT, null));
}
 
Example 11
Source File: BookmarkEditActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mModel = new BookmarkModel();
    mBookmarkId = BookmarkId.getBookmarkIdFromString(
            getIntent().getStringExtra(INTENT_BOOKMARK_ID));
    mModel.addObserver(mBookmarkModelObserver);
    BookmarkItem item = mModel.getBookmarkById(mBookmarkId);
    if (!mModel.doesBookmarkExist(mBookmarkId) || item == null) {
        finish();
        return;
    }

    setContentView(R.layout.bookmark_edit);
    mTitleEditText = (EmptyAlertEditText) findViewById(R.id.title_text);
    mFolderTextView = (TextView) findViewById(R.id.folder_text);
    mUrlEditText = (EmptyAlertEditText) findViewById(R.id.url_text);

    mFolderTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            BookmarkFolderSelectActivity.startFolderSelectActivity(
                    BookmarkEditActivity.this, mBookmarkId);
        }
    });

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    updateViewContent(false);
}
 
Example 12
Source File: BookmarkAddEditFolderActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    assert mIsAddMode;
    if (requestCode == PARENT_FOLDER_REQUEST_CODE && resultCode == RESULT_OK) {
        BookmarkId selectedBookmark = BookmarkId.getBookmarkIdFromString(data.getStringExtra(
                BookmarkFolderSelectActivity.INTENT_SELECTED_FOLDER));
        updateParent(selectedBookmark);
    }
}
 
Example 13
Source File: BookmarkEditActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mModel = new BookmarkModel();
    mBookmarkId = BookmarkId.getBookmarkIdFromString(
            getIntent().getStringExtra(INTENT_BOOKMARK_ID));
    mModel.addObserver(mBookmarkModelObserver);
    BookmarkItem item = mModel.getBookmarkById(mBookmarkId);
    if (!mModel.doesBookmarkExist(mBookmarkId) || item == null) {
        finish();
        return;
    }

    setContentView(R.layout.bookmark_edit);
    mTitleEditText = (EmptyAlertEditText) findViewById(R.id.title_text);
    mFolderTextView = (TextView) findViewById(R.id.folder_text);
    mUrlEditText = (EmptyAlertEditText) findViewById(R.id.url_text);

    mFolderTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            BookmarkFolderSelectActivity.startFolderSelectActivity(
                    BookmarkEditActivity.this, mBookmarkId);
        }
    });

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    updateViewContent(false);
}
 
Example 14
Source File: BookmarkWidgetService.java    From delion with Apache License 2.0 5 votes vote down vote up
@BinderThread
private void updateBookmarkList() {
    BookmarkId folderId = BookmarkId
            .getBookmarkIdFromString(mPreferences.getString(PREF_CURRENT_FOLDER, null));
    mCurrentFolder = loadBookmarks(folderId);
    mPreferences.edit().putString(PREF_CURRENT_FOLDER, mCurrentFolder.folder.id.toString())
            .apply();
}
 
Example 15
Source File: BookmarkActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == EDIT_BOOKMARK_REQUEST_CODE && resultCode == RESULT_OK) {
        BookmarkId bookmarkId = BookmarkId.getBookmarkIdFromString(data.getStringExtra(
                INTENT_VISIT_BOOKMARK_ID));
        mBookmarkManager.openBookmark(bookmarkId, BookmarkLaunchLocation.BOOKMARK_EDITOR);
    }
}
 
Example 16
Source File: BookmarkUtils.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * @return The parent {@link BookmarkId} that the user used the last time or null if the user
 *         has never selected a parent folder to use.
 */
static BookmarkId getLastUsedParent(Context context) {
    SharedPreferences preferences = ContextUtils.getAppSharedPreferences();
    if (!preferences.contains(PREF_LAST_USED_PARENT)) return null;

    return BookmarkId.getBookmarkIdFromString(
            preferences.getString(PREF_LAST_USED_PARENT, null));
}
 
Example 17
Source File: BookmarkAddEditFolderActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    assert mIsAddMode;
    if (requestCode == PARENT_FOLDER_REQUEST_CODE && resultCode == RESULT_OK) {
        BookmarkId selectedBookmark = BookmarkId.getBookmarkIdFromString(data.getStringExtra(
                BookmarkFolderSelectActivity.INTENT_SELECTED_FOLDER));
        updateParent(selectedBookmark);
    }
}
 
Example 18
Source File: BookmarkUIState.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the url and generates the corresponding state.
 */
static BookmarkUIState createStateFromUrl(String url, BookmarkModel bookmarkModel) {
    if (url.equals(UrlConstants.BOOKMARKS_URL)) {
        return createAllBookmarksState(bookmarkModel);
    } else if (url.startsWith(UrlConstants.BOOKMARKS_FOLDER_URL)) {
        String path = url.substring(UrlConstants.BOOKMARKS_FOLDER_URL.length());
        if (!path.isEmpty()) {
            BookmarkId folder = BookmarkId.getBookmarkIdFromString(path);
            return createFolderState(folder, bookmarkModel);
        }
    }
    // If this line is reached, the url is not valid. Fall back to all bookmarks.
    return createAllBookmarksState(bookmarkModel);
}
 
Example 19
Source File: BookmarkAddEditFolderActivity.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@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));
}
 
Example 20
Source File: BookmarkAddEditFolderActivity.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@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));
}