Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Fix cropped awesome bar placeholder #1908

Merged
merged 1 commit into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class NavigationURLBar extends FrameLayout {
private ImageView mLoadingView;
private Animation mLoadingAnimation;
private RelativeLayout mURLLeftContainer;
private View mHintFading;
private boolean mIsLoading = false;
private boolean mIsInsecure = false;
private int mDefaultURLLeftPadding = 0;
Expand Down Expand Up @@ -133,6 +134,7 @@ private void initialize(Context aContext) {
mURL.setOnFocusChangeListener((view, focused) -> {
showVoiceSearch(!focused || (mURL.getText().length() == 0));
showContextButtons(!focused && mIsContextButtonsEnabled);
updateHintFading();

mURL.setSelection(mURL.getText().length(), 0);
});
Expand Down Expand Up @@ -166,6 +168,7 @@ private void initialize(Context aContext) {
mUAModeButton.setOnClickListener(mUAModeListener);
setUAMode(mSessionStack.getUaMode());

mHintFading = findViewById(R.id.urlBarHintFadingEdge);
mURLLeftContainer = findViewById(R.id.urlLeftContainer);
mInsecureIcon = findViewById(R.id.insecureIcon);
mLoadingView = findViewById(R.id.loadingView);
Expand All @@ -188,6 +191,7 @@ private void initialize(Context aContext) {
setFocusable(true);
setClickable(true);
syncViews();
updateHintFading();
}

public void setSessionStack(SessionStack sessionStack) {
Expand Down Expand Up @@ -412,23 +416,42 @@ private void showContextButtons(boolean aEnabled) {
mBookmarkButton.setVisibility(GONE);
mUAModeButton.setVisibility(GONE);
}
updateRightPadding();
}

public void showVoiceSearch(boolean enabled) {
if (enabled) {
mURL.setPadding(mURL.getPaddingStart(), mURL.getPaddingTop(), WidgetPlacement.convertDpToPixel(getContext(), 100), mURL.getPaddingBottom());

mMicrophoneButton.setImageResource(R.drawable.ic_icon_microphone);
mMicrophoneButton.setTooltip(getResources().getString(R.string.voice_search_tooltip));
mMicrophoneButton.setOnClickListener(mMicrophoneListener);

} else if (mURL.hasFocus()){
mURL.setPadding(mURL.getPaddingStart(), mURL.getPaddingTop(), WidgetPlacement.convertDpToPixel(getContext(), 40), mURL.getPaddingBottom());

mMicrophoneButton.setImageResource(R.drawable.ic_icon_clear);
mMicrophoneButton.setTooltip(getResources().getString(R.string.clear_tooltip));
mMicrophoneButton.setOnClickListener(mClearListener);
}
updateRightPadding();
}

public void updateHintFading() {
mHintFading.setVisibility(StringUtils.isEmpty(mURL.getText()) ? View.VISIBLE : View.GONE);
mHintFading.setEnabled(mURL.isFocused());
}

private void updateRightPadding() {
int padding = WidgetPlacement.convertDpToPixel(getContext(), 5);
if (mMicrophoneButton.getVisibility() == View.VISIBLE) {
padding += mMicrophoneButton.getLayoutParams().width;
}
if (mUAModeButton.getVisibility() == View.VISIBLE) {
padding += mUAModeButton.getLayoutParams().width;
}
if (mBookmarkButton.getVisibility() == View.VISIBLE) {
padding += mBookmarkButton.getLayoutParams().width;
}
// Min padding of 20 if no icons are visible
padding = Math.max(padding, WidgetPlacement.convertDpToPixel(getContext(), 20));
mURL.setPadding(mURL.getPaddingLeft(), mURL.getPaddingTop(), padding, mURL.getPaddingBottom());
}

private void syncViews() {
Expand Down Expand Up @@ -563,6 +586,7 @@ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
String aURL = mURL.getText().toString();
showVoiceSearch(isEmptyUrl(aURL));
showContextButtons(isEmptyUrl(aURL) && mIsContextButtonsEnabled);
updateHintFading();
}

@Override
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/res/drawable/url_bar_hint_fading_edge.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
<shape>
<gradient
android:type="linear"
android:angle="0"
android:startColor="#00000000"
android:endColor="@color/void_color" />
</shape>
</item>
<item android:state_enabled="false">
<shape>
<gradient
android:type="linear"
android:angle="0"
android:startColor="#00000000"
android:endColor="@color/asphalt" />
</shape>
</item>
</selector>

8 changes: 8 additions & 0 deletions app/src/main/res/layout/navigation_url.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
android:layout_gravity="center_vertical|end"
android:orientation="horizontal">

<View
android:id="@+id/urlBarHintFadingEdge"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:background="@drawable/url_bar_hint_fading_edge"
android:visibility="gone"/>

<org.mozilla.vrbrowser.ui.views.UIButton
android:id="@+id/microphoneButton"
style="@style/urlBarIconTheme"
Expand Down