Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/bookmark/EditBookmarkHelper.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.bookmark;
6
7 import android.app.Activity;
8 import android.app.AlertDialog;
9 import android.content.Context;
10 import android.content.DialogInterface;
11 import android.content.Intent;
12 import android.text.Editable;
13 import android.text.TextUtils;
14 import android.text.TextWatcher;
15 import android.view.LayoutInflater;
16 import android.view.View;
17 import android.widget.EditText;
18 import android.widget.TextView;
19
20 import com.google.android.apps.chrome.R;
21
22 import org.chromium.chrome.browser.profiles.Profile;
23 import org.chromium.ui.UiUtils;
24
25 /**
26 * A helper for editing bookmarks.
27 */
28 public class EditBookmarkHelper {
29 /**
30 * Opens the standard "edit bookmark" dialog.
31 * @param bookmarkId ID of the bookmark to be edited
32 * @param isFolder True if it is a folder
33 */
34 public static void editBookmark(Context context, long bookmarkId, boolean is Folder) {
35 Intent intent = new Intent(context, ManageBookmarkActivity.class);
36 if (!(context instanceof Activity)) intent.addFlags(Intent.FLAG_ACTIVITY _NEW_TASK);
37 intent.putExtra(ManageBookmarkActivity.BOOKMARK_INTENT_IS_FOLDER, isFold er);
38 intent.putExtra(ManageBookmarkActivity.BOOKMARK_INTENT_ID, bookmarkId);
39 context.startActivity(intent);
40 }
41
42 /**
43 * Opens an "edit bookmark" dialog for a partner bookmark.
44 * @param bookmarkId ID of the bookmark to be edited
45 * @param oldTitle Old title of the bookmark
46 * @param isFolder True if it is a folder
47 */
48 public static void editPartnerBookmark(Context context, final Profile profil e,
49 final long bookmarkId, String oldTitle, boolean isFolder) {
50 // TODO(aruslan): http://crbug.com/313853
51 View view = ((LayoutInflater) context.getSystemService(Context.LAYOUT_IN FLATER_SERVICE))
52 .inflate(R.layout.single_line_edit_dialog, null);
53 AlertDialog.Builder builder = new AlertDialog.Builder(context)
54 .setTitle(isFolder ? R.string.edit_folder : R.string.edit_bookma rk)
55 .setNegativeButton(R.string.cancel,
56 new DialogInterface.OnClickListener() {
57 @Override
58 public void onClick(DialogInterface dialog, int id) {
59 dialog.dismiss();
60 }
61 });
62 final AlertDialog dialog = builder.create();
63
64 // On click of "Save", changes are committed.
65 // Default title is the title of the bookmark.
66 // OK button is disabled if the title text is empty.
67 TextView titleLabel = (TextView) view.findViewById(R.id.title);
68 final EditText input = (EditText) view.findViewById(R.id.text);
69 titleLabel.setText(R.string.bookmark_name);
70 input.setText(oldTitle);
71 input.setSelection(0, oldTitle.length());
72 input.requestFocus();
73 input.post(new Runnable() {
74 @Override
75 public void run() {
76 UiUtils.showKeyboard(input);
77 }
78 });
79 input.addTextChangedListener(new TextWatcher() {
80 @Override
81 public void onTextChanged(CharSequence s, int start, int before, int count) {
82 }
83
84 @Override
85 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
86 }
87
88 @Override
89 public void afterTextChanged(Editable editableText) {
90 if (TextUtils.isEmpty(editableText)) {
91 dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled (false);
92 } else {
93 dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled (true);
94 }
95 }
96 });
97 dialog.setView(view);
98 dialog.setButton(DialogInterface.BUTTON_POSITIVE,
99 context.getResources().getString(R.string.save),
100 new DialogInterface.OnClickListener() {
101 @Override
102 public void onClick(DialogInterface dialog, int id) {
103 String newTitle = input.getText().toString();
104 nativeSetPartnerBookmarkTitle(profile, bookmarkId, newTi tle);
105 }
106 });
107 dialog.show();
108 }
109
110 // JNI
111 private static native void nativeSetPartnerBookmarkTitle(
112 Profile profile, long partnerBookmarkId, String newTitle);
113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698