forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Autofill Assistant] Introduce a simple bar to show scripts.
R=gogerald@chromium.org Bug: 806868 Change-Id: I1b7503c801916fb7bd7e0bcde2361f0bfd15d7cf Reviewed-on: https://chromium-review.googlesource.com/1202205 Commit-Queue: Ganggui Tang <gogerald@chromium.org> Reviewed-by: Ganggui Tang <gogerald@chromium.org> Cr-Commit-Position: refs/heads/master@{#589703}
- Loading branch information
Mathias Carlen
authored and
Commit Bot
committed
Sep 7, 2018
1 parent
c2fffce
commit e8ca310
Showing
12 changed files
with
186 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
.../android/java/src/org/chromium/chrome/browser/autofill_assistant/BottomBarController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// Copyright 2018 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.chrome.browser.autofill_assistant; | ||
|
||
import android.app.Activity; | ||
import android.graphics.Color; | ||
import android.support.design.widget.CoordinatorLayout; | ||
import android.view.Gravity; | ||
import android.view.ViewGroup; | ||
import android.view.ViewGroup.LayoutParams; | ||
import android.widget.HorizontalScrollView; | ||
import android.widget.LinearLayout; | ||
import android.widget.TextView; | ||
|
||
import org.chromium.chrome.R; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** Controller to interact with the bottom bar. */ | ||
class BottomBarController { | ||
private static final String SCRIPTS_STATUS_MESSAGE = "Scripts"; | ||
|
||
private final Activity mActivity; | ||
private final LinearLayout mBottomBar; | ||
private ViewGroup mScriptsViewContainer; | ||
private TextView mStatusMessageView; | ||
|
||
/** | ||
* Constructs a bottom bar. | ||
* | ||
* @param activity The Activity | ||
*/ | ||
public BottomBarController(Activity activity) { | ||
mActivity = activity; | ||
|
||
mBottomBar = createBottomBar(); | ||
((ViewGroup) mActivity.findViewById(R.id.coordinator)).addView(mBottomBar); | ||
|
||
CoordinatorLayout.LayoutParams params = | ||
(CoordinatorLayout.LayoutParams) mBottomBar.getLayoutParams(); | ||
params.gravity = Gravity.BOTTOM; | ||
|
||
showStatusMessage(SCRIPTS_STATUS_MESSAGE); | ||
} | ||
|
||
/** | ||
* Shows a message in the status bar. | ||
* | ||
* @param message Message to display. | ||
*/ | ||
public void showStatusMessage(@Nullable String message) { | ||
mStatusMessageView.setText(message); | ||
} | ||
|
||
/** | ||
* Updates the list of scripts in the bar. | ||
* | ||
* @param scripts List of scripts to show. | ||
*/ | ||
public void updateScripts(String[] scripts) { | ||
mScriptsViewContainer.removeAllViews(); | ||
if (scripts.length == 0) { | ||
return; | ||
} | ||
|
||
for (String script : scripts) { | ||
mScriptsViewContainer.addView(createScriptView(script)); | ||
} | ||
} | ||
|
||
private LinearLayout createBottomBar() { | ||
LinearLayout bottomBar = createContainer(); | ||
mStatusMessageView = createTextView(); | ||
bottomBar.addView(mStatusMessageView); | ||
bottomBar.addView(createScrollView()); | ||
return bottomBar; | ||
} | ||
|
||
private LinearLayout createContainer() { | ||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( | ||
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | ||
LinearLayout layout = createLinearLayout(params, LinearLayout.VERTICAL); | ||
layout.setBackgroundColor(Color.parseColor("#f0f0f0")); | ||
layout.setPadding(10, 10, 10, 10); | ||
return layout; | ||
} | ||
|
||
private TextView createTextView() { | ||
TextView textView = new TextView(mActivity); | ||
textView.setLayoutParams( | ||
new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); | ||
textView.setGravity(Gravity.CENTER_HORIZONTAL); | ||
return textView; | ||
} | ||
|
||
private HorizontalScrollView createScrollView() { | ||
HorizontalScrollView scrollView = new HorizontalScrollView(mActivity); | ||
scrollView.setLayoutParams( | ||
new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); | ||
scrollView.setHorizontalScrollBarEnabled(false); | ||
mScriptsViewContainer = createLinearLayout( | ||
new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT), | ||
LinearLayout.HORIZONTAL); | ||
scrollView.addView(mScriptsViewContainer); | ||
return scrollView; | ||
} | ||
|
||
private LinearLayout createLinearLayout(LayoutParams layoutParams, int orientation) { | ||
LinearLayout layout = new LinearLayout(mActivity); | ||
layout.setLayoutParams(layoutParams); | ||
layout.setOrientation(orientation); | ||
return layout; | ||
} | ||
|
||
private TextView createScriptView(String text) { | ||
TextView scriptView = new TextView(mActivity); | ||
scriptView.setPadding(20, 20, 20, 20); | ||
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( | ||
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); | ||
layoutParams.setMargins(10, 10, 10, 10); | ||
scriptView.setLayoutParams(layoutParams); | ||
scriptView.setMaxLines(1); | ||
scriptView.setText(text); | ||
scriptView.setBackgroundColor(Color.parseColor("#e0e0e0")); | ||
return scriptView; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters