use of android.webkit.WebResourceError in project mobile-center-sdk-android by Microsoft.
the class MSALoginActivity method signOut.
@SuppressWarnings("unused")
public void signOut(View view) {
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
if (url.startsWith(REDIRECT_URL)) {
clearCookies();
Uri uri = Uri.parse(url);
sSharedPreferences.edit().remove(MSA_REFRESH_TOKEN_SCOPE_KEY).apply();
sSharedPreferences.edit().remove(MSA_REFRESH_TOKEN_KEY).apply();
sSharedPreferences.edit().remove(MSA_AUTH_TYPE_KEY).apply();
sSharedPreferences.edit().remove(MSA_TOKEN_KEY).apply();
String error = uri.getQueryParameter("error");
if (error != null) {
failSignOut(0, error);
} else {
signIn(null);
}
}
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
clearCookies();
failSignOut(errorCode, description);
}
@Override
@TargetApi(Build.VERSION_CODES.M)
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
clearCookies();
failSignOut(error.getErrorCode(), error.getDescription());
}
});
mWebView.loadUrl(SIGN_OUT_URL + REDIRECT_URI_PARAM + CLIENT_ID_PARAM);
}
use of android.webkit.WebResourceError in project collect by opendatakit.
the class WebViewActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close);
String url = getIntent().getStringExtra(ExternalWebPageHelper.OPEN_URL);
webView = (WebView) findViewById(R.id.webView);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
getSupportActionBar().setTitle(url);
progressBar.setVisibility(View.VISIBLE);
invalidateOptionsMenu();
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
webView.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
getSupportActionBar().setTitle(view.getTitle());
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
progressBar.setVisibility(View.GONE);
}
});
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);
webView.setHorizontalScrollBarEnabled(false);
webView.loadUrl(url);
}
use of android.webkit.WebResourceError in project MQTTPushClient_Android by RadioShuttle.
the class DashBoardAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
final ViewHolder h = (ViewHolder) holder;
Item item = mData.get(position);
// Log.d(TAG, "onBindViewHolder: " + item.label );
h.label.setText(item.label);
if (mSelectedItems.contains(item.id)) {
h.itemView.setActivated(true);
if (h.selectedImageView != null && h.selectedImageView.getVisibility() != View.VISIBLE) {
h.selectedImageView.setVisibility(View.VISIBLE);
}
} else {
h.itemView.setActivated(false);
if (h.selectedImageView != null && h.selectedImageView.getVisibility() != View.GONE) {
h.selectedImageView.setVisibility(View.GONE);
}
}
ViewGroup.LayoutParams lp = h.itemView.getLayoutParams();
if (h.getItemViewType() != TYPE_GROUP) {
/* set item container cell width including cell padding*/
lp.width = mWidth + 2 * mCellSpacing;
h.itemView.setLayoutParams(lp);
lp = h.contentContainer.getLayoutParams();
if (lp.width != mWidth || lp.height != mWidth) {
lp.width = mWidth;
lp.height = mWidth;
h.contentContainer.setLayoutParams(lp);
}
item.setViewBackground(h.contentContainer, mDefaultBackground, false);
} else {
// if (h.viewType == TYPE_GROUP) {
lp.width = (mWidth + mCellSpacing * 2) * mSpanCnt;
h.itemView.setLayoutParams(lp);
lp = h.label.getLayoutParams();
lp.width = mSpanCnt * mWidth + (mSpanCnt - 1) * mCellSpacing * 2;
h.label.setLayoutParams(lp);
item.setViewBackground(h.label, mDefaultBackground, false);
item.setViewTextAppearance(h.label, h.defaultColor);
}
Object publishError = item.data.get("error2");
if (h.errorImage2 != null) {
if (publishError instanceof String) {
// value set?
ColorStateList csl = ColorStateList.valueOf(h.defaultColor);
ImageViewCompat.setImageTintList(h.errorImage2, csl);
h.errorImage2.setBackgroundResource(R.drawable.ic_error_image_background);
if (h.errorImage2.getVisibility() != View.VISIBLE) {
h.errorImage2.setVisibility(View.VISIBLE);
}
} else {
if (h.errorImage2.getVisibility() != View.GONE) {
h.errorImage2.setVisibility(View.GONE);
}
}
}
Object javaScriptError = item.data.get("error");
if (h.getItemViewType() == TYPE_PROGRESS && h.progressBar != null) {
ProgressItem p = (ProgressItem) item;
long pcolor = (p.data.get("ctrl_color") != null ? (Long) p.data.get("ctrl_color") : p.progresscolor);
int color;
if (pcolor == DColor.OS_DEFAULT || pcolor == DColor.CLEAR) {
color = mDefaultProgressColor;
} else {
color = (int) pcolor;
}
tintProgressBar(color, h.progressBar);
int value = 0;
/* if java script error, there is no valid data, set progress bar to 0 */
if (javaScriptError instanceof String) {
} else {
String val = (String) item.data.get("content");
if (!Utils.isEmpty(val)) {
try {
double v = Double.parseDouble(val);
if (p.range_min < p.range_max && v >= p.range_min && v <= p.range_max) {
double f = ProgressItem.calcProgessInPercent(v, p.range_min, p.range_max) / 100d;
value = (int) ((double) h.progressBar.getMax() * f);
}
} catch (Exception e) {
}
}
}
h.progressBar.setProgress(value);
}
// Log.d(TAG, "ui: " + item.label);
if (h.value != null) {
// TEXT
String content = (String) item.data.get("content");
if (h.getItemViewType() == TYPE_PROGRESS) {
if (item.data.get("content.progress") instanceof String) {
content = (String) item.data.get("content.progress");
}
} else if (item instanceof OptionList) {
// (h.getItemViewType() == TYPE_OPTIONLIST)
OptionList ol = (OptionList) item;
String displayValue = ol.getDisplayValue();
OptionList.Option selOption = ol.getSelectedOption();
boolean hasImage = selOption != null && !Utils.isEmpty(selOption.imageURI) && selOption.uiImage != null;
if (Utils.isEmpty(displayValue) && !hasImage) {
/* if content does not match an option, show content */
// TODO: consider showing an error if content does not match an option
displayValue = content;
/*
if (javaScriptError != null) { // only set error if there is not already an error
if (ol.optionList == null || ol.optionList.size() == 0) {
}
}
*/
}
content = displayValue;
if (!Utils.isEmpty(content)) {
// TODO: consider using own layout resource file
if (h.contentContainer instanceof TextView) {
TextView textView = (TextView) h.contentContainer;
OptionList.Option sel = ol.getSelectedOption();
if (sel != null && !Utils.isEmpty(sel.imageURI) && sel.uiImage != null) {
textView.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
} else {
textView.setGravity(Gravity.CENTER);
}
}
}
}
item.setViewTextAppearance(h.value, h.defaultColor);
h.value.setText(content);
}
// switch
if (item instanceof Switch) {
final Switch sw = (Switch) item;
/* if stateless, show onValue */
String val = null;
long fcolor;
long bcolor;
boolean noTint;
boolean isOnState = sw.isOnState();
Drawable icon;
if (isOnState) {
val = sw.val;
fcolor = sw.data.containsKey("ctrl_color") ? (Long) sw.data.get("ctrl_color") : sw.color;
bcolor = sw.data.containsKey("ctrl_background") ? (Long) sw.data.get("ctrl_background") : sw.bgcolor;
icon = (Drawable) sw.data.get("ctrl_image_blob");
if (icon == null) {
icon = sw.image;
}
noTint = fcolor == DColor.CLEAR;
} else {
val = sw.valOff;
fcolor = sw.data.containsKey("ctrl_color_off") ? (Long) sw.data.get("ctrl_color_off") : sw.colorOff;
bcolor = sw.data.containsKey("ctrl_background_off") ? (Long) sw.data.get("ctrl_background_off") : sw.bgcolorOff;
icon = (Drawable) sw.data.get("ctrl_image_off_blob");
if (icon == null) {
icon = sw.imageOff;
}
noTint = fcolor == DColor.CLEAR;
}
ColorStateList csl;
if (bcolor == DColor.OS_DEFAULT || bcolor == DColor.CLEAR) {
csl = ColorStateList.valueOf(mDefaultButtonBackground);
} else {
csl = ColorStateList.valueOf((int) bcolor);
}
/* show button or image button */
if (icon == null) {
if (h.button.getVisibility() != View.VISIBLE) {
h.button.setVisibility(View.VISIBLE);
}
if (h.imageButton.getVisibility() != View.GONE) {
h.imageButton.setVisibility(View.GONE);
;
}
/* if stateless, show onValue */
h.button.setText(val);
int color;
if (fcolor == DColor.OS_DEFAULT || fcolor == DColor.CLEAR) {
color = mDefaultButtonTextColor;
} else {
color = (int) fcolor;
}
h.button.setTextColor(color);
ViewCompat.setBackgroundTintList(h.button, csl);
} else {
if (h.button.getVisibility() != View.GONE) {
h.button.setVisibility(View.GONE);
}
if (h.imageButton.getVisibility() != View.VISIBLE) {
h.imageButton.setVisibility(View.VISIBLE);
;
}
if (h.imageButton.getDrawable() != icon) {
h.imageButton.setImageDrawable(icon);
}
ViewCompat.setBackgroundTintList(h.imageButton, csl);
int color;
if (fcolor == DColor.OS_DEFAULT) {
color = mDefaultButtonTintColor;
} else {
color = (int) fcolor;
}
ColorStateList tcsl = ColorStateList.valueOf(color);
if (noTint) {
ImageViewCompat.setImageTintList(h.imageButton, null);
} else {
ImageViewCompat.setImageTintList(h.imageButton, tcsl);
}
}
}
if (item instanceof CustomItem) {
final WebView webView = (WebView) h.contentContainer;
final CustomItem citem = (CustomItem) item;
boolean resourceLoadErr = false;
if (DBUtils.isHTMLResource(citem.htmlUri) && Utils.isEmpty(citem.getHtml())) {
File userDir = ImportFiles.getUserFilesDir(mActivity, mAccount.getAccountDirName());
String resourceName = ImageResource.getURIPath(citem.htmlUri);
File htmlResource = new File(userDir, resourceName + "." + Cmd.DASH_HTML);
try {
citem.setHtml(Utils.readStringFromFile(htmlResource));
} catch (IOException e) {
javaScriptError = mActivity.getString(R.string.error_html_not_found);
citem.data.put("error", javaScriptError);
resourceLoadErr = true;
}
}
long xcolor = citem.getTextcolor();
int color;
if (xcolor == DColor.OS_DEFAULT || xcolor == DColor.CLEAR) {
// clear is inavalid, treat as DEFAULT
color = h.defaultColor;
} else {
color = (int) xcolor;
}
tintProgressBar(color, h.progressBar);
if (h.html != citem || citem.reloadRequested) {
// load html, if not already done or changed
// Log.d(TAG, "custom item loading: " + citem.label);
citem.reloadRequested = false;
h.html = citem;
citem.isLoading = true;
if (!resourceLoadErr) {
javaScriptError = null;
// clear erros
citem.data.remove("error");
}
citem.data.remove("error2");
CustomItem.JSObject webInterface = citem.getWebInterface();
webInterface.setViewModel(mActivity.mViewModel);
webView.addJavascriptInterface(citem.getWebInterface(), "MQTT");
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
if (newProgress < 100 && h.progressBar.getVisibility() != View.VISIBLE) {
h.progressBar.setVisibility(View.VISIBLE);
} else if (newProgress == 100 && h.progressBar.getVisibility() != View.GONE) {
h.progressBar.setVisibility(View.GONE);
}
}
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
// TODO: do not report errors or other updates when detail view open !?
String err = "" + consoleMessage.message() + ", line: " + consoleMessage.lineNumber();
handleWebViewError(err, citem);
return true;
}
});
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
citem.isLoading = false;
// remove after test
Log.d(TAG, "on page finished.");
StringBuilder js = new StringBuilder();
if (Build.VERSION.SDK_INT < 19) {
js.append("javascript:");
}
js.append(wrapper_webview_js);
js.append(' ');
js.append(javascript_color_js);
// buildJS_readyState
/*
StringBuilder tmp = new StringBuilder();
tmp.append(CustomItem.build_onMqttPushClientInitCall(mAccount, citem));
tmp.append(CustomItem.build_onMqttMessageCall(citem));
js.append(CustomItem.buildJS_readyState(tmp.toString()));
*/
js.append(CustomItem.build_onMqttPushClientInitCall(mAccount, citem, false));
if (citem.hasMessageData()) {
js.append(CustomItem.build_onMqttMessageCall(citem));
}
if (Build.VERSION.SDK_INT >= 19) {
webView.evaluateJavascript(js.toString(), null);
} else {
webView.loadUrl(js.toString());
}
}
@TargetApi(23)
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
// super.onReceivedError(view, request, error);
/* check if error already reported */
String err = error.getDescription().toString();
handleWebViewError(err, citem);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
// super.onReceivedError(view, errorCode, description, failingUrl);
handleWebViewError(description, citem);
}
@TargetApi(21)
@Nullable
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
// Log.d(TAG, "shouldInterceptRequest 1: " + request.getUrl().toString());
return ImageResource.handleWebResource(mActivity, mAccount.getAccountDirName(), request.getUrl());
}
@Nullable
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
// Log.d(TAG, "shouldInterceptRequest 2: " + url);
WebResourceResponse r = null;
try {
r = ImageResource.handleWebResource(mActivity, mAccount.getAccountDirName(), Uri.parse(url));
} catch (Exception e) {
// TODO: remove after test
}
return r;
}
});
webView.loadDataWithBaseURL(CustomItem.BASE_URL, citem.getHtml(), "text/html", "utf-8", null);
} else {
if (!citem.isLoading && citem.hasMessageData()) {
String jsOnMqttMessageCall = CustomItem.build_onMqttMessageCall(citem);
if (Build.VERSION.SDK_INT >= 19) {
webView.evaluateJavascript(jsOnMqttMessageCall, null);
} else {
webView.loadUrl("javascript:" + jsOnMqttMessageCall);
}
}
}
}
if (h.errorImage != null) {
if (javaScriptError instanceof String) {
// TYPE_TEXT
ColorStateList csl = ColorStateList.valueOf(h.defaultColor);
ImageViewCompat.setImageTintList(h.errorImage, csl);
h.errorImage.setBackgroundResource(R.drawable.ic_error_image_background);
if (h.errorImage.getVisibility() != View.VISIBLE) {
h.errorImage.setVisibility(View.VISIBLE);
}
} else {
if (h.errorImage.getVisibility() != View.GONE) {
h.errorImage.setVisibility(View.GONE);
}
}
}
// Log.d(TAG, "width: " + lp.width);
// Log.d(TAG, "height: " + lp.height);
}
use of android.webkit.WebResourceError in project appcenter-sdk-android by microsoft.
the class MSALoginActivity method signIn.
@SuppressWarnings("unused")
public void signIn(View view) {
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
checkSignInCompletion(url);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
failSignIn(errorCode, description);
}
@Override
@TargetApi(Build.VERSION_CODES.M)
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
failSignIn(error.getErrorCode(), error.getDescription());
}
});
boolean compactTicket = mAuthType == AuthenticationProvider.Type.MSA_COMPACT;
String responseType = compactTicket ? "token" : "code";
String[] scopes = compactTicket ? SCOPES_COMPACT : SCOPES_DELEGATE;
mWebView.loadUrl(AUTHORIZE_URL + REDIRECT_URI_PARAM + CLIENT_ID_PARAM + "&response_type=" + responseType + "&scope=" + TextUtils.join("+", scopes));
}
use of android.webkit.WebResourceError in project gigya-android-sdk by SAP.
the class ProviderFragment method setUpWebView.
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void setUpWebView() {
super.setUpWebView();
/* Content UI & scrolling */
_webView.setVerticalScrollBarEnabled(true);
_webView.setHorizontalScrollBarEnabled(true);
_webView.setInitialScale(1);
_webView.setFocusable(true);
/* Web settings */
final WebSettings webSettings = _webView.getSettings();
webSettings.setSupportZoom(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setUseWideViewPort(true);
_webView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
result.confirm();
return true;
}
});
_webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
GigyaLogger.debug(LOG_TAG, "onPageStarted: with Url = " + url);
_progressBar.setVisibility(View.VISIBLE);
}
@Override
public void onPageFinished(WebView view, String url) {
GigyaLogger.debug(LOG_TAG, "onPageFinished: with Url = " + url);
_progressBar.setVisibility(View.INVISIBLE);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
final String result = getOverrideResult(url);
if (result != null) {
handleResult(UrlUtils.parseUrlParameters(result));
return true;
}
return false;
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
final String result = getOverrideResult(request.getUrl().toString());
if (result != null) {
handleResult(UrlUtils.parseUrlParameters(result));
return true;
}
return false;
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
GigyaLogger.debug(LOG_TAG, error.toString());
}
@Nullable
private String getOverrideResult(String url) {
if (_redirectPrefix != null && _url != null) {
if (url.startsWith(_redirectPrefix)) {
try {
final String decodedUrl = URLDecoder.decode(url, "UTF8");
return decodedUrl.replace("gsapi", "http");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
return null;
}
});
_webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
if (newProgress == 100 && _webView.getVisibility() == View.INVISIBLE) {
// Actual loading finished.
// Stub.
}
}
});
}
Aggregations