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

Unified Diff: blimp/client/android/java/src/org/chromium/blimp/toolbar/UrlBar.java

Issue 1422363008: Add a basic UI to the Android Blimp client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed unused icon Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: blimp/client/android/java/src/org/chromium/blimp/toolbar/UrlBar.java
diff --git a/blimp/client/android/java/src/org/chromium/blimp/toolbar/UrlBar.java b/blimp/client/android/java/src/org/chromium/blimp/toolbar/UrlBar.java
new file mode 100644
index 0000000000000000000000000000000000000000..9f019280ba614c2963f019c4b42c211b1c924162
--- /dev/null
+++ b/blimp/client/android/java/src/org/chromium/blimp/toolbar/UrlBar.java
@@ -0,0 +1,81 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.blimp.toolbar;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.KeyEvent;
+import android.view.View;
+import android.view.View.OnKeyListener;
+import android.widget.EditText;
+
+import org.chromium.base.ObserverList;
+import org.chromium.ui.UiUtils;
+
+/**
+ * A {@link View} that a;lows users to enter text and URLs.
+ */
+public class UrlBar extends EditText implements OnKeyListener {
+ /**
+ * An observer that gets notified of relevant URL bar text changes.
+ */
+ public interface UrlBarObserver {
+ /**
+ * Will be called when the user presses enter after typing something into this
+ * {@link EditText}.
+ * @param text The new text the user entered.
+ */
+ void onNewTextEntered(String text);
+ }
+
+ private ObserverList<UrlBarObserver> mObservers = new ObserverList<UrlBarObserver>();
nyquist 2015/11/09 01:58:45 Nit: final
David Trainor- moved to gerrit 2015/11/09 17:17:45 Done.
+
+ /**
+ * Builds a new {@link UrlBar}.
+ * @param context A {@link Context} instance.
+ * @param attrs An {@link AttributeSet} instance.
+ */
+ public UrlBar(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ setOnKeyListener(this);
+ }
+
+ /**
+ * @return The current text of this {@link EditText}. Guaranteed to be not {@code null}.
+ */
+ public String getQueryText() {
+ return getEditableText() != null ? getEditableText().toString() : "";
nyquist 2015/11/09 01:58:45 Optional nit: Flip the != to have the positive cas
David Trainor- moved to gerrit 2015/11/09 17:17:45 Done.
+ }
+
+ /**
+ * @param observer An {@link UrlBarObserver} that will be notified of future text entries.
+ */
+ public void addUrlBarObserver(UrlBarObserver observer) {
+ mObservers.addObserver(observer);
+ }
+
+ /**
+ * @param observer An {@link UrlBarObserver} that will no longer be notified of future text
+ * entries.
+ */
+ public void removeUrlBarObserver(UrlBarObserver observer) {
+ mObservers.removeObserver(observer);
+ }
+
+ // OnKeyListener interface.
+ @Override
+ public boolean onKey(View view, int keyCode, KeyEvent event) {
+ if (event.getAction() == KeyEvent.ACTION_UP
+ && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER
+ || event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_ENTER)) {
+ UiUtils.hideKeyboard(view);
+ clearFocus();
+ for (UrlBarObserver observer : mObservers) {
+ observer.onNewTextEntered(getQueryText());
+ }
+ }
+ return false;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698