Commit 29d4c827 authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

[WebLayer] Make WebLayerShellActivity editable.

Switch between an EditText and a View object returned by
UrlBarController to build an editable URL bar as developers reply upon
this for testing.

Bug: 1025607
Change-Id: I93c8731457c4dd519b347ceaca1af79ea70e1f28
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2050690
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741078}
parent 202a62ca
...@@ -9,18 +9,34 @@ ...@@ -9,18 +9,34 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
tools:ignore="LabelFor,ContentDescription" tools:ignore="LabelFor,ContentDescription"
android:background="#FFc9c9c9"> android:background="#FFc9c9c9"
android:layout_width="match_parent">
<FrameLayout <ViewSwitcher
android:id="@+id/url_view_container" android:id="@+id/url_view_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp" android:layout_marginStart="5dp"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:layout_gravity="center_vertical" android:layout_toStartOf="@+id/menu_button">
android:layout_toStartOf="@+id/menu_button" />
<EditText
android:id="@+id/editable_url_view"
android:inputType="textUri"
android:selectAllOnFocus="true"
android:imeOptions="actionGo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"/>
<View
android:id="@+id/noneditable_url_view_placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</ViewSwitcher>
<ImageButton <ImageButton
android:id="@+id/menu_button" android:id="@+id/menu_button"
...@@ -28,10 +44,8 @@ ...@@ -28,10 +44,8 @@
android:background="@android:color/transparent" android:background="@android:color/transparent"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_gravity="end"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"/>
android:layout_marginBottom="-2px"
android:layout_alignBottom="@id/url_view_container" />
<ProgressBar <ProgressBar
android:id="@+id/progress_bar" android:id="@+id/progress_bar"
...@@ -41,10 +55,10 @@ ...@@ -41,10 +55,10 @@
android:visibility="invisible" android:visibility="invisible"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignBottom="@id/menu_button" android:layout_alignBottom="@id/url_view_container"
android:layout_marginTop="0dp" android:layout_marginTop="0dp"
android:layout_marginBottom="-10px" android:layout_marginBottom="-10px"
android:layout_marginLeft="0dp" android:layout_marginLeft="0dp"
android:layout_marginRight="0dp" /> android:layout_marginRight="0dp"/>
</RelativeLayout> </RelativeLayout>
...@@ -12,19 +12,19 @@ import android.support.v4.app.FragmentActivity; ...@@ -12,19 +12,19 @@ import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager; import android.view.WindowManager;
import android.webkit.ValueCallback; import android.webkit.ValueCallback;
import android.widget.FrameLayout; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.PopupMenu; import android.widget.PopupMenu;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.ViewSwitcher;
import org.chromium.weblayer.Browser; import org.chromium.weblayer.Browser;
import org.chromium.weblayer.DownloadCallback; import org.chromium.weblayer.DownloadCallback;
...@@ -37,6 +37,8 @@ import org.chromium.weblayer.NewTabCallback; ...@@ -37,6 +37,8 @@ import org.chromium.weblayer.NewTabCallback;
import org.chromium.weblayer.NewTabType; import org.chromium.weblayer.NewTabType;
import org.chromium.weblayer.Profile; import org.chromium.weblayer.Profile;
import org.chromium.weblayer.Tab; import org.chromium.weblayer.Tab;
import org.chromium.weblayer.TabCallback;
import org.chromium.weblayer.TabListCallback;
import org.chromium.weblayer.UnsupportedVersionException; import org.chromium.weblayer.UnsupportedVersionException;
import org.chromium.weblayer.UrlBarOptions; import org.chromium.weblayer.UrlBarOptions;
import org.chromium.weblayer.WebLayer; import org.chromium.weblayer.WebLayer;
...@@ -50,15 +52,21 @@ import java.util.List; ...@@ -50,15 +52,21 @@ import java.util.List;
public class WebLayerShellActivity extends FragmentActivity { public class WebLayerShellActivity extends FragmentActivity {
private static final String TAG = "WebLayerShell"; private static final String TAG = "WebLayerShell";
private static final String KEY_MAIN_VIEW_ID = "mainViewId"; private static final String KEY_MAIN_VIEW_ID = "mainViewId";
private static final float DEFAULT_TEXT_SIZE = 15.0F;
private static final int EDITABLE_URL_TEXT_VIEW = 0;
private static final int NONEDITABLE_URL_TEXT_VIEW = 1;
private Profile mProfile; private Profile mProfile;
private Browser mBrowser; private Browser mBrowser;
private ImageButton mMenuButton; private ImageButton mMenuButton;
private FrameLayout mUrlViewContainer; private ViewSwitcher mUrlViewContainer;
private EditText mEditUrlView;
// private View mNonEditUrlView;
private ProgressBar mLoadProgressBar; private ProgressBar mLoadProgressBar;
private View mMainView; private View mMainView;
private int mMainViewId; private int mMainViewId;
private View mTopContentsContainer; private View mTopContentsContainer;
private TabListCallback mTabListCallback;
private List<Tab> mPreviousTabList = new ArrayList<>(); private List<Tab> mPreviousTabList = new ArrayList<>();
private Runnable mExitFullscreenRunnable; private Runnable mExitFullscreenRunnable;
...@@ -87,15 +95,19 @@ public class WebLayerShellActivity extends FragmentActivity { ...@@ -87,15 +95,19 @@ public class WebLayerShellActivity extends FragmentActivity {
LayoutInflater.from(this).inflate(R.layout.shell_browser_controls, null); LayoutInflater.from(this).inflate(R.layout.shell_browser_controls, null);
mUrlViewContainer = mTopContentsContainer.findViewById(R.id.url_view_container); mUrlViewContainer = mTopContentsContainer.findViewById(R.id.url_view_container);
mEditUrlView = mUrlViewContainer.findViewById(R.id.editable_url_view);
mEditUrlView.setOnEditorActionListener((TextView v, int actionId, KeyEvent event) -> {
loadUrl(mEditUrlView.getText().toString());
mEditUrlView.clearFocus();
return true;
});
mUrlViewContainer.setDisplayedChild(EDITABLE_URL_TEXT_VIEW);
mMenuButton = mTopContentsContainer.findViewById(R.id.menu_button); mMenuButton = mTopContentsContainer.findViewById(R.id.menu_button);
mMenuButton.setOnClickListener(new View.OnClickListener() { mMenuButton.setOnClickListener(v -> {
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(WebLayerShellActivity.this, v); PopupMenu popup = new PopupMenu(WebLayerShellActivity.this, v);
popup.getMenuInflater().inflate(R.menu.app_menu, popup.getMenu()); popup.getMenuInflater().inflate(R.menu.app_menu, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { popup.setOnMenuItemClickListener(item -> {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.find_begin_menu_id) { if (item.getItemId() == R.id.find_begin_menu_id) {
// TODO(estade): add a UI for FIP. For now, just search for "cat", or go // TODO(estade): add a UI for FIP. For now, just search for "cat", or go
// to the next result if a search has already been initiated. // to the next result if a search has already been initiated.
...@@ -106,16 +118,13 @@ public class WebLayerShellActivity extends FragmentActivity { ...@@ -106,16 +118,13 @@ public class WebLayerShellActivity extends FragmentActivity {
} }
if (item.getItemId() == R.id.find_end_menu_id) { if (item.getItemId() == R.id.find_end_menu_id) {
mBrowser.getActiveTab().getFindInPageController().setFindInPageCallback( mBrowser.getActiveTab().getFindInPageController().setFindInPageCallback(null);
null);
return true; return true;
} }
return false; return false;
}
}); });
popup.show(); popup.show();
}
}); });
mLoadProgressBar = mTopContentsContainer.findViewById(R.id.progress_bar); mLoadProgressBar = mTopContentsContainer.findViewById(R.id.progress_bar);
...@@ -135,7 +144,11 @@ public class WebLayerShellActivity extends FragmentActivity { ...@@ -135,7 +144,11 @@ public class WebLayerShellActivity extends FragmentActivity {
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
mUrlViewContainer.removeAllViews(); mUrlViewContainer.reset();
if (mTabListCallback != null) {
mBrowser.unregisterTabListCallback(mTabListCallback);
mTabListCallback = null;
}
} }
private void onWebLayerReady(WebLayer webLayer, Bundle savedInstanceState) { private void onWebLayerReady(WebLayer webLayer, Bundle savedInstanceState) {
...@@ -155,12 +168,21 @@ public class WebLayerShellActivity extends FragmentActivity { ...@@ -155,12 +168,21 @@ public class WebLayerShellActivity extends FragmentActivity {
mProfile = mBrowser.getProfile(); mProfile = mBrowser.getProfile();
mBrowser.setTopView(mTopContentsContainer); mBrowser.setTopView(mTopContentsContainer);
UrlBarOptions urlBarOptions = UrlBarOptions.builder().setTextSizeSP(12.0F).build(); mTabListCallback = new TabListCallback() {
View urlView = mBrowser.getUrlBarController().createUrlBarView(urlBarOptions); @Override
public void onActiveTabChanged(Tab activeTab) {
mUrlViewContainer.setDisplayedChild(NONEDITABLE_URL_TEXT_VIEW);
}
};
mBrowser.registerTabListCallback(mTabListCallback);
View nonEditUrlView = mBrowser.getUrlBarController().createUrlBarView(
UrlBarOptions.builder().setTextSizeSP(DEFAULT_TEXT_SIZE).build());
nonEditUrlView.setOnClickListener(
v -> { mUrlViewContainer.setDisplayedChild(EDITABLE_URL_TEXT_VIEW); });
mUrlViewContainer.removeViewAt(NONEDITABLE_URL_TEXT_VIEW);
mUrlViewContainer.addView(nonEditUrlView, NONEDITABLE_URL_TEXT_VIEW);
mUrlViewContainer.setDisplayedChild(NONEDITABLE_URL_TEXT_VIEW);
mUrlViewContainer.addView(urlView,
new RelativeLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
if (getCurrentDisplayUrl() != null) { if (getCurrentDisplayUrl() != null) {
return; return;
} }
...@@ -236,6 +258,12 @@ public class WebLayerShellActivity extends FragmentActivity { ...@@ -236,6 +258,12 @@ public class WebLayerShellActivity extends FragmentActivity {
} }
} }
}); });
tab.registerTabCallback(new TabCallback() {
@Override
public void onVisibleUriChanged(Uri uri) {
mUrlViewContainer.setDisplayedChild(NONEDITABLE_URL_TEXT_VIEW);
}
});
tab.getNavigationController().registerNavigationCallback(new NavigationCallback() { tab.getNavigationController().registerNavigationCallback(new NavigationCallback() {
@Override @Override
public void onLoadStateChanged(boolean isLoading, boolean toDifferentDocument) { public void onLoadStateChanged(boolean isLoading, boolean toDifferentDocument) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment