Skip to content

Commit

Permalink
Fixes #435 Added support for alert/prompt/confirm (#905)
Browse files Browse the repository at this point in the history
* Fixes #435 Added support for alert/prompt/confirm

* Fixed layout reference that caused a TC failure

* Improve resizing glitch
  • Loading branch information
keianhzo authored and bluemarvin committed Dec 20, 2018
1 parent 853b724 commit f666370
Show file tree
Hide file tree
Showing 19 changed files with 901 additions and 259 deletions.
Expand Up @@ -79,7 +79,7 @@ public void setDefaultSecondValue(String value) {
}

public String getSecondText() {
return mEdit2.getText().equals(mEdit2.getHint()) ? mDefaultSecondValue : mEdit2.getText().toString();
return mEdit2.getText().toString().equals(mEdit2.getHint()) ? mDefaultSecondValue : mEdit2.getText().toString();
}

public void setSecondText(String text) {
Expand Down
Expand Up @@ -2,13 +2,16 @@

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;

import org.mozilla.vrbrowser.R;

import androidx.annotation.Nullable;

@SuppressLint("AppCompatCustomView")
Expand All @@ -18,17 +21,19 @@ public class SettingsEditText extends EditText {
private int mHighlightedTextColor = 0;

public SettingsEditText(Context context) {
super(context);
initialize();
this(context, null);
}

public SettingsEditText(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initialize();
this(context, attrs, 0);
}

public SettingsEditText(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);

TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.EditSetting, defStyleAttr, 0);
mHighlightedTextColor = attributes.getColor(R.styleable.EditSetting_highlightedTextColor, 0);

initialize();
}

Expand Down
Expand Up @@ -126,7 +126,7 @@ public void setDefaultFirstValue(String value) {
}

public String getFirstText() {
return mEdit1.getText().equals(mEdit1.getHint()) ? mDefaultFirstValue : mEdit1.getText().toString();
return mEdit1.getText().toString().equals(mEdit1.getHint()) ? mDefaultFirstValue : mEdit1.getText().toString();
}

public void setFirstText(String text) {
Expand Down
Expand Up @@ -38,7 +38,7 @@ public TopBarWidget(Context aContext, AttributeSet aAttrs, int aDefStyle) {
private void initialize(Context aContext) {
inflate(aContext, R.layout.top_bar, this);

mCloseButton = findViewById(R.id.closeButton);
mCloseButton = findViewById(R.id.negativeButton);
mCloseButton.setOnClickListener(view -> {
view.requestFocusFromTouch();
if (mAudio != null) {
Expand Down
Expand Up @@ -26,7 +26,10 @@
import org.mozilla.vrbrowser.browser.SessionStore;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.ui.views.BookmarksView;
import org.mozilla.vrbrowser.ui.widgets.prompts.AlertPromptWidget;
import org.mozilla.vrbrowser.ui.widgets.prompts.ChoicePromptWidget;
import org.mozilla.vrbrowser.ui.widgets.prompts.ConfirmPromptWidget;
import org.mozilla.vrbrowser.ui.widgets.prompts.TextPromptWidget;


public class WindowWidget extends UIWidget implements SessionStore.SessionChangeListener,
Expand All @@ -43,6 +46,9 @@ public class WindowWidget extends UIWidget implements SessionStore.SessionChange
private WidgetPlacement mWidgetPlacement;
private WidgetManagerDelegate mWidgetManager;
private ChoicePromptWidget mChoicePrompt;
private AlertPromptWidget mAlertPrompt;
private ConfirmPromptWidget mConfirmPrompt;
private TextPromptWidget mTextPrompt;
private int mWidthBackup;
private int mHeightBackup;
private int mBorderWidth;
Expand Down Expand Up @@ -548,19 +554,38 @@ private void setPrivateBrowsingEnabled(boolean isEnabled) {
// TODO: Fade in/out the browser window. Waiting for https://github.com/MozillaReality/FirefoxReality/issues/77
}

// PromptDelegate

@Override
public void onAlert(GeckoSession session, String title, String msg, AlertCallback callback) {

mAlertPrompt = new AlertPromptWidget(getContext());
mAlertPrompt.mWidgetPlacement.parentHandle = getHandle();
mAlertPrompt.setTitle(title);
mAlertPrompt.setMessage(msg);
mAlertPrompt.setDelegate(callback);
mAlertPrompt.show();
}

@Override
public void onButtonPrompt(GeckoSession session, String title, String msg, String[] btnMsg, ButtonCallback callback) {

mConfirmPrompt = new ConfirmPromptWidget(getContext());
mConfirmPrompt.mWidgetPlacement.parentHandle = getHandle();
mConfirmPrompt.setTitle(title);
mConfirmPrompt.setMessage(msg);
mConfirmPrompt.setButtons(btnMsg);
mConfirmPrompt.setDelegate(callback);
mConfirmPrompt.show();
}

@Override
public void onTextPrompt(GeckoSession session, String title, String msg, String value, TextCallback callback) {

mTextPrompt = new TextPromptWidget(getContext());
mTextPrompt.mWidgetPlacement.parentHandle = getHandle();
mTextPrompt.setTitle(title);
mTextPrompt.setMessage(msg);
mTextPrompt.setDefaultText(value);
mTextPrompt.setDelegate(callback);
mTextPrompt.show();
}

@Override
Expand All @@ -570,20 +595,13 @@ public void onAuthPrompt(GeckoSession session, String title, String msg, AuthOpt

@Override
public void onChoicePrompt(GeckoSession session, String title, String msg, int type, final Choice[] choices, final ChoiceCallback callback) {
if (mChoicePrompt == null) {
mChoicePrompt = new ChoicePromptWidget(getContext());
mChoicePrompt.mWidgetPlacement.parentHandle = getHandle();
}

mChoicePrompt = new ChoicePromptWidget(getContext());
mChoicePrompt.mWidgetPlacement.parentHandle = getHandle();
mChoicePrompt.setTitle(title);
mChoicePrompt.setMessage(msg);
mChoicePrompt.setChoices(choices);
mChoicePrompt.setMenuType(type);
mChoicePrompt.setDelegate(ids -> {
callback.confirm(ids);
mChoicePrompt.hide(UIWidget.REMOVE_WIDGET);
});

mChoicePrompt.setDelegate(callback);
mChoicePrompt.show();
}

Expand Down
@@ -0,0 +1,71 @@
package org.mozilla.vrbrowser.ui.widgets.prompts;

import android.content.Context;
import android.text.method.ScrollingMovementMethod;
import android.util.AttributeSet;
import android.widget.Button;

import org.mozilla.geckoview.GeckoSession;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.audio.AudioEngine;

public class AlertPromptWidget extends PromptWidget {

private AudioEngine mAudio;
private Button mOkButton;
private GeckoSession.PromptDelegate.AlertCallback mCallback;

public AlertPromptWidget(Context aContext) {
super(aContext);
initialize(aContext);
}

public AlertPromptWidget(Context aContext, AttributeSet aAttrs) {
super(aContext, aAttrs);
initialize(aContext);
}

public AlertPromptWidget(Context aContext, AttributeSet aAttrs, int aDefStyle) {
super(aContext, aAttrs, aDefStyle);
initialize(aContext);
}

@Override
protected void initialize(Context aContext) {
super.initialize(aContext);

inflate(aContext, R.layout.prompt_alert, this);

mAudio = AudioEngine.fromContext(aContext);

mLayout = findViewById(R.id.layout);

mTitle = findViewById(R.id.alertTitle);
mMessage = findViewById(R.id.alertMessage);
mMessage.setMovementMethod(new ScrollingMovementMethod());

mOkButton = findViewById(R.id.positiveButton);
mOkButton.setSoundEffectsEnabled(false);
mOkButton.setOnClickListener(view -> {
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}

onDismiss();
});
}

@Override
protected void onDismiss() {
hide(REMOVE_WIDGET);

if (mCallback != null) {
mCallback.dismiss();
}
}

public void setDelegate(GeckoSession.PromptDelegate.AlertCallback delegate) {
mCallback = delegate;
}

}

0 comments on commit f666370

Please sign in to comment.