コード例 #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    EnhancedBookmarkUtils.setTaskDescriptionInDocumentMode(this, getString(R.string.edit_bookmark));
    mEnhancedBookmarksModel = new EnhancedBookmarksModel();
    mBookmarkId =
        BookmarkId.getBookmarkIdFromString(getIntent().getStringExtra(INTENT_BOOKMARK_ID));
    mEnhancedBookmarksModel.addObserver(mBookmarkModelObserver);

    setContentView(R.layout.eb_edit);
    mTitleEditText = (EmptyAlertEditText) findViewById(R.id.title_text);
    mUrlEditText = (EmptyAlertEditText) findViewById(R.id.url_text);
    mFolderTextView = (TextView) findViewById(R.id.folder_text);
    mFolderTextView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            EnhancedBookmarkFolderSelectActivity.startFolderSelectActivity(
                EnhancedBookmarkEditActivity.this, mBookmarkId);
          }
        });
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    updateViewContent();
  }
コード例 #2
0
    /** @return A state corresponding to the url. If the url is not valid, return all_bookmarks. */
    private static UIState createStateFromUrl(String url, EnhancedBookmarksModel bookmarkModel) {
      UIState state = new UIState();
      state.mState = STATE_INVALID;
      state.mUrl = url;

      if (url.equals(UrlConstants.BOOKMARKS_URL)) {
        state.mState = STATE_ALL_BOOKMARKS;
      } else if (url.startsWith(UrlConstants.BOOKMARKS_FOLDER_URL)) {
        String suffix = decodeSuffix(url, UrlConstants.BOOKMARKS_FOLDER_URL);
        if (!suffix.isEmpty()) {
          state.mFolder = BookmarkId.getBookmarkIdFromString(suffix);
          state.mState = STATE_FOLDER;
        }
      } else if (url.startsWith(UrlConstants.BOOKMARKS_FILTER_URL)) {
        String suffix = decodeSuffix(url, UrlConstants.BOOKMARKS_FILTER_URL);
        if (!suffix.isEmpty()) {
          state.mState = STATE_FILTER;
          state.mFilter = EnhancedBookmarkFilter.valueOf(suffix);
        }
      }

      if (!state.isValid(bookmarkModel)) {
        state.mState = STATE_ALL_BOOKMARKS;
        state.mUrl = UrlConstants.BOOKMARKS_URL;
      }

      return state;
    }
コード例 #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int title =
        OfflinePageBridge.isEnabled() ? R.string.offline_pages_edit_item : R.string.edit_bookmark;
    setTitle(title);
    EnhancedBookmarkUtils.setTaskDescriptionInDocumentMode(this, getString(title));
    mEnhancedBookmarksModel = new EnhancedBookmarksModel();
    mBookmarkId =
        BookmarkId.getBookmarkIdFromString(getIntent().getStringExtra(INTENT_BOOKMARK_ID));
    mEnhancedBookmarksModel.addObserver(mBookmarkModelObserver);
    assert mEnhancedBookmarksModel.getBookmarkById(mBookmarkId).isEditable();

    setContentView(R.layout.eb_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) {
            EnhancedBookmarkFolderSelectActivity.startFolderSelectActivity(
                EnhancedBookmarkEditActivity.this, mBookmarkId);
          }
        });

    if (OfflinePageBridge.isEnabled()
        && OfflinePageBridge.canSavePage(
            mEnhancedBookmarksModel.getBookmarkById(mBookmarkId).getUrl())) {
      mOfflinePageModelObserver =
          new OfflinePageModelObserver() {
            @Override
            public void offlinePageDeleted(BookmarkId bookmarkId) {
              if (mBookmarkId.equals(bookmarkId)) {
                updateOfflineSection();
              }
            }
          };

      mEnhancedBookmarksModel.getOfflinePageBridge().addObserver(mOfflinePageModelObserver);
      // Make offline page section visible and find controls.
      findViewById(R.id.offline_page_group).setVisibility(View.VISIBLE);
      getIntent().setExtrasClassLoader(WebContents.class.getClassLoader());
      mWebContents = getIntent().getParcelableExtra(INTENT_WEB_CONTENTS);
      mActivityWindowAndroid = new ActivityWindowAndroid(this, false);
      updateOfflineSection();
    }

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

    updateViewContent();
  }
コード例 #4
0
 /**
  * Retrieve the bookmark previously saved in the arguments bundle.
  *
  * @param bundle Argument holder or savedInstanceState of the fragment/activity.
  * @return The ID of the bookmark to retrieve.
  */
 public static BookmarkId getBookmarkIdFromBundle(Bundle bundle) {
   return BookmarkId.getBookmarkIdFromString(bundle.getString(BOOKMARK_SAVE_NAME));
 }