List of usage examples for android.webkit WebView loadUrl
public void loadUrl(String url)
From source file:com.near.chimerarevo.fragments.CommentsFragment.java
@SuppressLint("SetJavaScriptEnabled") private void loadDisqusOAuth() { if (getActivity().getSharedPreferences(Constants.PREFS_TAG, Context.MODE_PRIVATE) .getString(Constants.KEY_REFRESH_TOKEN, "").length() > 1) { RequestBody formBody = new FormEncodingBuilder().add("grant_type", "refresh_token") .add("client_id", Constants.DISQUS_API_KEY).add("client_secret", Constants.DISQUS_API_SECRET) .add("refresh_token", getActivity().getSharedPreferences(Constants.PREFS_TAG, Context.MODE_PRIVATE) .getString(Constants.KEY_REFRESH_TOKEN, "")) .build();//from ww w .ja v a2 s . c o m Request request = new Request.Builder().url(Constants.DISQUS_TOKEN_URL).post(formBody).tag(FRAGMENT_TAG) .build(); if (mDialog == null) mDialog = ProgressDialogUtils.getInstance(getActivity(), R.string.text_login); else mDialog = ProgressDialogUtils.modifyInstance(mDialog, R.string.text_login); mDialog.show(); OkHttpUtils.getInstance().newCall(request).enqueue(new PostAccessTokenCallback()); return; } final Dialog dialog = new Dialog(getActivity()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.webview_layout); dialog.setCancelable(true); dialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { isDialogOpen = false; mFab.show(); } }); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface arg0) { isDialogOpen = false; mFab.show(); } }); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) CookieManager.getInstance().removeAllCookies(null); else { CookieSyncManager.createInstance(getActivity()); CookieManager.getInstance().removeAllCookie(); } WebView wv = (WebView) dialog.findViewById(R.id.webview); wv.getSettings().setJavaScriptEnabled(true); wv.getSettings().setSaveFormData(false); wv.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); dialog.findViewById(R.id.progressContainer).setVisibility(View.GONE); dialog.findViewById(R.id.webViewContainer).setVisibility(View.VISIBLE); } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); dialog.findViewById(R.id.progressContainer).setVisibility(View.VISIBLE); dialog.findViewById(R.id.webViewContainer).setVisibility(View.GONE); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { boolean state = super.shouldOverrideUrlLoading(view, url); if (url.contains(Constants.SITE_URL)) { String code = url.split("code=")[1]; RequestBody formBody = new FormEncodingBuilder().add("grant_type", "authorization_code") .add("client_id", Constants.DISQUS_API_KEY) .add("client_secret", Constants.DISQUS_API_SECRET) .add("redirect_uri", Constants.SITE_URL).add("code", code).build(); Request request = new Request.Builder().url(Constants.DISQUS_TOKEN_URL).post(formBody) .tag(FRAGMENT_TAG).build(); if (mDialog == null) mDialog = ProgressDialogUtils.getInstance(getActivity(), R.string.text_login); else mDialog = ProgressDialogUtils.modifyInstance(mDialog, R.string.text_login); dialog.dismiss(); mDialog.show(); OkHttpUtils.getInstance().newCall(request).enqueue(new PostAccessTokenCallback()); } return state; } @Override public void onReceivedSslError(WebView view, @NonNull SslErrorHandler handler, SslError error) { handler.proceed(); } }); wv.loadUrl(URLUtils.getDisqusAuthUrl()); isDialogOpen = true; mFab.hide(); dialog.show(); }
From source file:li.klass.fhem.fragments.AbstractWebViewFragment.java
@SuppressLint("SetJavaScriptEnabled") @Override//w ww. j a v a 2s. c o m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); if (view != null) return view; view = inflater.inflate(R.layout.webview, container, false); assert view != null; final WebView webView = (WebView) view.findViewById(R.id.webView); WebSettings settings = webView.getSettings(); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); settings.setJavaScriptEnabled(true); settings.setBuiltInZoomControls(true); final ProgressDialog progressDialog = new ProgressDialog(getActivity()); progressDialog.setMessage(getResources().getString(R.string.loading)); webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { super.onProgressChanged(view, newProgress); if (newProgress < 100) { progressDialog.setProgress(newProgress); progressDialog.show(); } else { progressDialog.hide(); } } }); webView.setWebViewClient(new WebViewClient() { @Override public void onReceivedSslError(WebView view, @NotNull SslErrorHandler handler, SslError error) { handler.proceed(); } @SuppressWarnings("ConstantConditions") @Override public void onReceivedHttpAuthRequest(WebView view, @NotNull HttpAuthHandler handler, String host, String realm) { FHEMServerSpec currentServer = connectionService.getCurrentServer(getActivity()); String url = currentServer.getUrl(); String alternativeUrl = trimToNull(currentServer.getAlternateUrl()); try { String fhemUrlHost = new URL(url).getHost(); String alternativeUrlHost = alternativeUrl == null ? null : new URL(alternativeUrl).getHost(); String username = currentServer.getUsername(); String password = currentServer.getPassword(); if (host.startsWith(fhemUrlHost) || (alternativeUrlHost != null && host.startsWith(alternativeUrlHost))) { handler.proceed(username, password); } else { handler.cancel(); Intent intent = new Intent(Actions.SHOW_TOAST); intent.putExtra(BundleExtraKeys.STRING_ID, R.string.error_authentication); getActivity().sendBroadcast(intent); } } catch (MalformedURLException e) { Intent intent = new Intent(Actions.SHOW_TOAST); intent.putExtra(BundleExtraKeys.STRING_ID, R.string.error_host_connection); getActivity().sendBroadcast(intent); LOG.error("malformed URL: " + url, e); handler.cancel(); } } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if ("about:blank".equalsIgnoreCase(url)) { Optional<String> alternativeUrl = getAlternateLoadUrl(); if (alternativeUrl.isPresent()) { webView.loadUrl(alternativeUrl.get()); } } else { onPageLoadFinishedCallback(view, url); } } }); return view; }
From source file:com.sentaroh.android.TaskAutomation.Config.ActivityMain.java
@SuppressLint("NewApi") final private void aboutTaskAutomation() { // common ??/*www. j a v a 2 s .c om*/ final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.about_dialog); ((TextView) dialog.findViewById(R.id.about_dialog_title)) .setText(getString(R.string.msgs_about_dlg_title) + " Ver " + getApplVersionName()); final WebView func_view = (WebView) dialog.findViewById(R.id.about_dialog_function); // func_view.setWebViewClient(new WebViewClient()); // func_view.getSettings().setJavaScriptEnabled(true); func_view.getSettings().setSupportZoom(true); // func_view.setVerticalScrollbarOverlay(true); func_view.setBackgroundColor(Color.LTGRAY); // func_view.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); func_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET); func_view.setVerticalScrollBarEnabled(true); func_view.setScrollbarFadingEnabled(false); if (Build.VERSION.SDK_INT > 10) { func_view.getSettings().setDisplayZoomControls(true); func_view.getSettings().setBuiltInZoomControls(true); } else { func_view.getSettings().setBuiltInZoomControls(true); } func_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_about_dlg_func_html)); final WebView change_view = (WebView) dialog.findViewById(R.id.about_dialog_change_history); if (Build.VERSION.SDK_INT > 10) { func_view.getSettings().setDisplayZoomControls(true); func_view.getSettings().setBuiltInZoomControls(true); } else { func_view.getSettings().setBuiltInZoomControls(true); } change_view.loadDataWithBaseURL("file:///android_asset/", getString(R.string.msgs_about_dlg_change_desc), "text/html", "UTF-8", ""); change_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); change_view.getSettings().setSupportZoom(true); if (Build.VERSION.SDK_INT > 10) { change_view.getSettings().setDisplayZoomControls(true); change_view.getSettings().setBuiltInZoomControls(true); } else { change_view.getSettings().setBuiltInZoomControls(true); } final Button btnFunc = (Button) dialog.findViewById(R.id.about_dialog_btn_show_func); final Button btnChange = (Button) dialog.findViewById(R.id.about_dialog_btn_show_change); final Button btnOk = (Button) dialog.findViewById(R.id.about_dialog_btn_ok); func_view.setVisibility(TextView.VISIBLE); change_view.setVisibility(TextView.GONE); btnChange.setBackgroundResource(R.drawable.button_back_ground_color_selector); btnFunc.setBackgroundResource(R.drawable.button_back_ground_color_selector); btnChange.setTextColor(Color.DKGRAY); btnFunc.setTextColor(Color.GREEN); btnFunc.setEnabled(false); CommonDialog.setDlgBoxSizeLimit(dialog, true); // func? btnFunc.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { change_view.setVisibility(TextView.GONE); func_view.setVisibility(TextView.VISIBLE); CommonDialog.setDlgBoxSizeLimit(dialog, true); btnFunc.setTextColor(Color.GREEN); btnChange.setTextColor(Color.DKGRAY); btnChange.setEnabled(true); btnFunc.setEnabled(false); } }); // change? btnChange.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { change_view.setVisibility(TextView.VISIBLE); func_view.setVisibility(TextView.GONE); CommonDialog.setDlgBoxSizeLimit(dialog, true); btnChange.setTextColor(Color.GREEN); btnFunc.setTextColor(Color.DKGRAY); btnChange.setEnabled(false); btnFunc.setEnabled(true); } }); // OK? btnOk.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btnOk.performClick(); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); // dialog.setCancelable(false); dialog.show(); }
From source file:com.sentaroh.android.SMBSync2.ActivityMain.java
@SuppressLint("InflateParams") private void aboutSMBSync() { final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.about_dialog); final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.about_dialog_title_view); final TextView title = (TextView) dialog.findViewById(R.id.about_dialog_title); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setTextColor(mGp.themeColorList.text_color_dialog_title); title.setText(getString(R.string.msgs_dlg_title_about) + "(Ver " + packageVersionName + ")"); // get our tabHost from the xml final TabHost tab_host = (TabHost) dialog.findViewById(R.id.about_tab_host); tab_host.setup();/*from w ww .j ava 2 s . c om*/ final TabWidget tab_widget = (TabWidget) dialog.findViewById(android.R.id.tabs); if (Build.VERSION.SDK_INT >= 11) { tab_widget.setStripEnabled(false); tab_widget.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE); } CustomTabContentView tabViewProf = new CustomTabContentView(this, getString(R.string.msgs_about_dlg_func_btn)); tab_host.addTab(tab_host.newTabSpec("func").setIndicator(tabViewProf).setContent(android.R.id.tabcontent)); CustomTabContentView tabViewHist = new CustomTabContentView(this, getString(R.string.msgs_about_dlg_change_btn)); tab_host.addTab( tab_host.newTabSpec("change").setIndicator(tabViewHist).setContent(android.R.id.tabcontent)); LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout ll_func = (LinearLayout) vi.inflate(R.layout.about_dialog_func, null); LinearLayout ll_change = (LinearLayout) vi.inflate(R.layout.about_dialog_change, null); final WebView func_view = (WebView) ll_func.findViewById(R.id.about_dialog_function); func_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_dlg_title_about_func_desc)); func_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); func_view.getSettings().setBuiltInZoomControls(true); final WebView change_view = (WebView) ll_change.findViewById(R.id.about_dialog_change_history); change_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_dlg_title_about_change_desc)); change_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); change_view.getSettings().setBuiltInZoomControls(true); final CustomViewPagerAdapter mAboutViewPagerAdapter = new CustomViewPagerAdapter(this, new WebView[] { func_view, change_view }); final CustomViewPager mAboutViewPager = (CustomViewPager) dialog.findViewById(R.id.about_view_pager); // mMainViewPager.setBackgroundColor(mThemeColorList.window_color_background); mAboutViewPager.setAdapter(mAboutViewPagerAdapter); mAboutViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { // util.addDebugMsg(2,"I","onPageSelected entered, pos="+position); tab_widget.setCurrentTab(position); tab_host.setCurrentTab(position); } @Override public void onPageScrollStateChanged(int state) { // util.addDebugMsg(2,"I","onPageScrollStateChanged entered, state="+state); } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { // util.addDebugMsg(2,"I","onPageScrolled entered, pos="+position); } }); tab_host.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { util.addDebugMsg(2, "I", "onTabchanged entered. tab=" + tabId); mAboutViewPager.setCurrentItem(tab_host.getCurrentTab()); } }); final Button btnOk = (Button) dialog.findViewById(R.id.about_dialog_btn_ok); CommonDialog.setDlgBoxSizeLimit(dialog, true); // OK? btnOk.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btnOk.performClick(); } }); dialog.show(); }
From source file:com.sentaroh.android.SMBSync.SMBSyncMain.java
private void aboutSMBSync() { // common ??//from www.j a va 2 s .co m final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.about_dialog); ((TextView) dialog.findViewById(R.id.about_dialog_title)) .setText(getString(R.string.msgs_dlg_title_about) + "(Ver " + packageVersionName + ")"); final WebView func_view = (WebView) dialog.findViewById(R.id.about_dialog_function); // func_view.loadDataWithBaseURL("file:///android_asset/", // getString(R.string.msgs_dlg_title_about_func_desc),"text/html","UTF-8",""); func_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_dlg_title_about_func_desc)); func_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); func_view.getSettings().setBuiltInZoomControls(true); final WebView change_view = (WebView) dialog.findViewById(R.id.about_dialog_change_history); change_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_dlg_title_about_change_desc)); change_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); change_view.getSettings().setBuiltInZoomControls(true); final Button btnFunc = (Button) dialog.findViewById(R.id.about_dialog_btn_show_func); final Button btnChange = (Button) dialog.findViewById(R.id.about_dialog_btn_show_change); final Button btnOk = (Button) dialog.findViewById(R.id.about_dialog_btn_ok); func_view.setVisibility(TextView.VISIBLE); change_view.setVisibility(TextView.GONE); btnChange.setBackgroundResource(R.drawable.button_bg_color_selector); btnFunc.setBackgroundResource(R.drawable.button_bg_color_selector); btnChange.setTextColor(Color.DKGRAY); btnFunc.setTextColor(Color.GREEN); btnFunc.setEnabled(false); // btnOk.setTextColor(Color.DKGRAY); // btnOk.setTextColor(Color.GREEN); // btnOk.setBackgroundResource(R.drawable.button_back_ground_color_selector); CommonDialog.setDlgBoxSizeLimit(dialog, true); // func? btnFunc.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { change_view.setVisibility(TextView.GONE); func_view.setVisibility(TextView.VISIBLE); CommonDialog.setDlgBoxSizeLimit(dialog, true); // func_view.setEnabled(true); // change_view.setEnabled(false); btnFunc.setTextColor(Color.GREEN); btnChange.setTextColor(Color.DKGRAY); btnChange.setEnabled(true); btnFunc.setEnabled(false); } }); // change? btnChange.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { change_view.setVisibility(TextView.VISIBLE); func_view.setVisibility(TextView.GONE); CommonDialog.setDlgBoxSizeLimit(dialog, true); // func_view.setEnabled(true); // change_view.setEnabled(false); btnChange.setTextColor(Color.GREEN); btnFunc.setTextColor(Color.DKGRAY); btnChange.setEnabled(false); btnFunc.setEnabled(true); } }); // OK? btnOk.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btnOk.performClick(); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(mContext)); // dialog.setCancelable(false); dialog.show(); }
From source file:com.lemon.lime.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getBatteryPercentage();//from w ww. j a va 2 s . c om setContentView(R.layout.activity_main); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(false); mWebView = (ObservableWebView) findViewById(R.id.activity_main_webview); mWebView.setScrollViewCallbacks(this); LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflator.inflate(R.layout.bar, null); getSupportActionBar().setCustomView(v); WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath()); swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipeToRefresh); swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { mWebView.reload(); } }); swipeLayout.setColorSchemeResources(R.color.lili, R.color.colorPrimary, R.color.red); window = getWindow(); favicon = (ImageView) findViewById(R.id.favicon); editurl = (EditText) findViewById(R.id.editurl); mWebView.setDownloadListener(new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Uri uri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } }); favicon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (lili == 5) { lilimode(); lili = 0; lilimode = true; } else { lili = lili + 1; } } }); editurl.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER) { if (event.getAction() == KeyEvent.ACTION_UP) { if (editurl.getText().toString().contains("file:///")) { filemgr(); } else if (editurl.getText().toString().contains("gaymode")) { gaymode(); } else if (editurl.getText().toString().contains("exitapp")) { finish(); } else if (editurl.getText().toString().contains("light")) { flash(); } if (isconnected()) { if (editurl.getText().toString().contains("http://") || editurl.getText().toString().contains("https://")) { mWebView.loadUrl(editurl.getText().toString()); } else if (editurl.getText().toString().contains(".com") || editurl.getText().toString().contains(".net") || editurl.getText().toString().contains(".org") || editurl.getText().toString().contains(".gov") || editurl.getText().toString().contains(".hu") || editurl.getText().toString().contains(".sk") || editurl.getText().toString().contains(".co.uk") || editurl.getText().toString().contains(".co.in") || editurl.getText().toString().contains(".cn") || editurl.getText().toString().contains(".it") || editurl.getText().toString().contains(".de") || editurl.getText().toString().contains(".aus") || editurl.getText().toString().contains(".hr") || editurl.getText().toString().contains(".cz") || editurl.getText().toString().contains(".xyz") || editurl.getText().toString().contains(".pl") || editurl.getText().toString().contains(".io")) { mWebView.loadUrl("http://" + editurl.getText().toString()); InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editurl.getWindowToken(), 0); } else { mWebView.loadUrl("https://www.google.com/search?q=" + editurl.getText().toString()); InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editurl.getWindowToken(), 0); } } return true; } return false; } return true; } }); // Enable Javascript WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); webSettings.setSupportMultipleWindows(true); if (isconnected()) { mWebView.loadUrl("http://google.com"); } else { final View coordinatorLayoutView = findViewById(R.id.snackbarPosition); mWebView.loadUrl("file:///android_asset/nonet.html"); Snackbar snackbar = Snackbar.make(coordinatorLayoutView, R.string.offline, Snackbar.LENGTH_LONG); snackbar.show(); } mWebView.setWebChromeClient(new WebChromeClient() { @Override public void onReceivedIcon(WebView mWebView, Bitmap icon) { super.onReceivedIcon(mWebView, icon); favicon.setImageBitmap(icon); } public void onProgressChanged(WebView view, int progress) { activity.setProgress(progress * 100); int a = progress; if (lilimode) { editurl.setText("Liling: " + Integer.toString(a) + "?"); } else editurl.setText("Liming: " + Integer.toString(a) + "%"); if (progress == 100) { editurl.setHint(view.getTitle()); activity.setTitle(view.getTitle()); editurl.setText(view.getUrl()); fav(); //battery if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (level <= 20) { window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setNavigationBarColor(Color.RED); window.setStatusBarColor(Color.RED); getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.RED)); } } } } }); mWebView.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView mWebView, String url) { swipeLayout.setRefreshing(false); } }); }
From source file:com.microsoft.windowsazure.mobileservices.LoginManager.java
/** * Creates the UI for the interactive authentication process * // w w w . j av a2 s.c o m * @param provider * The provider used for the authentication process * @param startUrl * The initial URL for the authentication process * @param endUrl * The final URL for the authentication process * @param context * The context used to create the authentication dialog * @param callback * Callback to invoke when the authentication process finishes */ private void showLoginUI(final String startUrl, final String endUrl, final Context context, LoginUIOperationCallback callback) { if (startUrl == null || startUrl == "") { throw new IllegalArgumentException("startUrl can not be null or empty"); } if (endUrl == null || endUrl == "") { throw new IllegalArgumentException("endUrl can not be null or empty"); } if (context == null) { throw new IllegalArgumentException("context can not be null"); } final LoginUIOperationCallback externalCallback = callback; final AlertDialog.Builder builder = new AlertDialog.Builder(context); // Create the Web View to show the login page final WebView wv = new WebView(context); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException("User Canceled")); } } }); wv.getSettings().setJavaScriptEnabled(true); DisplayMetrics displaymetrics = new DisplayMetrics(); ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); int webViewHeight = displaymetrics.heightPixels; wv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, webViewHeight)); wv.requestFocus(View.FOCUS_DOWN); wv.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { int action = event.getAction(); if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) { if (!view.hasFocus()) { view.requestFocus(); } } return false; } }); // Create a LinearLayout and add the WebView to the Layout LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(wv); // Add a dummy EditText to the layout as a workaround for a bug // that prevents showing the keyboard for the WebView on some devices EditText dummyEditText = new EditText(context); dummyEditText.setVisibility(View.GONE); layout.addView(dummyEditText); // Add the layout to the dialog builder.setView(layout); final AlertDialog dialog = builder.create(); wv.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { // If the URL of the started page matches with the final URL // format, the login process finished if (isFinalUrl(url)) { if (externalCallback != null) { externalCallback.onCompleted(url, null); } dialog.dismiss(); } super.onPageStarted(view, url, favicon); } // Checks if the given URL matches with the final URL's format private boolean isFinalUrl(String url) { if (url == null) { return false; } return url.startsWith(endUrl); } // Checks if the given URL matches with the start URL's format private boolean isStartUrl(String url) { if (url == null) { return false; } return url.startsWith(startUrl); } @Override public void onPageFinished(WebView view, String url) { if (isStartUrl(url)) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException( "Logging in with the selected authentication provider is not enabled")); } dialog.dismiss(); } } }); wv.loadUrl(startUrl); dialog.show(); }
From source file:com.github.dfa.diaspora_android.activity.ShareActivity2.java
@SuppressLint("SetJavaScriptEnabled") @Override// w w w .j a v a2 s. c o m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); progressBar = (ProgressBar) findViewById(R.id.progressBar); swipeView = (SwipeRefreshLayout) findViewById(R.id.swipe); swipeView.setEnabled(false); toolbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (Helpers.isOnline(ShareActivity2.this)) { Intent intent = new Intent(ShareActivity2.this, MainActivity.class); startActivityForResult(intent, 100); overridePendingTransition(0, 0); } else { Snackbar.make(swipeView, R.string.no_internet, Snackbar.LENGTH_LONG).show(); } } }); podDomain = ((App) getApplication()).getSettings().getPodDomain(); fab = (com.getbase.floatingactionbutton.FloatingActionsMenu) findViewById(R.id.fab_expand_menu_button); fab.setVisibility(View.GONE); webView = (WebView) findViewById(R.id.webView); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); WebSettings wSettings = webView.getSettings(); wSettings.setJavaScriptEnabled(true); wSettings.setBuiltInZoomControls(true); if (Build.VERSION.SDK_INT >= 21) wSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); /* * WebViewClient */ webView.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { Log.d(TAG, url); if (!url.contains(podDomain)) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(i); return true; } return false; } public void onPageFinished(WebView view, String url) { Log.i(TAG, "Finished loading URL: " + url); } }); /* * WebChromeClient */ webView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView wv, int progress) { progressBar.setProgress(progress); if (progress > 0 && progress <= 60) { Helpers.getNotificationCount(wv); } if (progress > 60) { Helpers.hideTopBar(wv); } if (progress == 100) { progressBar.setVisibility(View.GONE); } else { progressBar.setVisibility(View.VISIBLE); } } @Override public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { if (mFilePathCallback != null) mFilePathCallback.onReceiveValue(null); mFilePathCallback = filePathCallback; Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); } catch (IOException ex) { // Error occurred while creating the File Snackbar.make(getWindow().findViewById(R.id.drawer_layout), "Unable to get image", Snackbar.LENGTH_SHORT).show(); } // Continue only if the File was successfully created if (photoFile != null) { mCameraPhotoPath = "file:" + photoFile.getAbsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } else { takePictureIntent = null; } } Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); contentSelectionIntent.setType("image/*"); Intent[] intentArray; if (takePictureIntent != null) { intentArray = new Intent[] { takePictureIntent }; } else { intentArray = new Intent[0]; } Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE); return true; } }); Intent intent = getIntent(); final Bundle extras = intent.getExtras(); String action = intent.getAction(); if (Intent.ACTION_SEND.equals(action)) { webView.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { if (extras.containsKey(Intent.EXTRA_TEXT) && extras.containsKey(Intent.EXTRA_SUBJECT)) { final String extraText = (String) extras.get(Intent.EXTRA_TEXT); final String extraSubject = (String) extras.get(Intent.EXTRA_SUBJECT); webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { finish(); Intent i = new Intent(ShareActivity2.this, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); overridePendingTransition(0, 0); return false; } }); webView.loadUrl("javascript:(function() { " + "document.getElementsByTagName('textarea')[0].style.height='110px'; " + "document.getElementsByTagName('textarea')[0].innerHTML = '**[" + extraSubject + "]** " + extraText + " *[shared with #DiasporaWebApp]*'; " + " if(document.getElementById(\"main_nav\")) {" + " document.getElementById(\"main_nav\").parentNode.removeChild(" + " document.getElementById(\"main_nav\"));" + " } else if (document.getElementById(\"main-nav\")) {" + " document.getElementById(\"main-nav\").parentNode.removeChild(" + " document.getElementById(\"main-nav\"));" + " }" + "})();"); } } }); } if (savedInstanceState == null) { if (Helpers.isOnline(ShareActivity2.this)) { webView.loadUrl("https://" + podDomain + "/status_messages/new"); } else { Snackbar.make(getWindow().findViewById(R.id.drawer_layout), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); } } }
From source file:ar.com.tristeslostrestigres.diasporanativewebapp.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); progressBar = findViewById(R.id.progressBar); pm = new PrefManager(MainActivity.this); SharedPreferences config = getSharedPreferences("PodSettings", MODE_PRIVATE); podDomain = config.getString("podDomain", null); fab = findViewById(R.id.multiple_actions); fab.setVisibility(View.GONE); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar);//from w w w . j a v a2s . c om getSupportActionBar().setTitle(null); txtTitle = (TextView) findViewById(R.id.toolbar_title); txtTitle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Helpers.isOnline(MainActivity.this)) { txtTitle.setText(R.string.jb_stream); webView.loadUrl("https://" + podDomain + "/stream"); } else { Snackbar.make(v, R.string.no_internet, Snackbar.LENGTH_SHORT).show(); } } }); webView = findViewById(R.id.webView); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.addJavascriptInterface(new JavaScriptInterface(), "NotificationCounter"); if (savedInstanceState != null) { webView.restoreState(savedInstanceState); } wSettings = webView.getSettings(); wSettings.setJavaScriptEnabled(true); wSettings.setUseWideViewPort(true); wSettings.setLoadWithOverviewMode(true); wSettings.setDomStorageEnabled(true); wSettings.setMinimumFontSize(pm.getMinimumFontSize()); wSettings.setLoadsImagesAutomatically(pm.getLoadImages()); if (android.os.Build.VERSION.SDK_INT >= 21) wSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); /* * WebViewClient */ webView.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { if (!url.contains(podDomain)) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(i); return true; } return false; } public void onPageFinished(WebView view, String url) { if (url.contains("/new") || url.contains("/sign_in")) { fab.setVisibility(View.GONE); } else { fab.setVisibility(View.VISIBLE); } } public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { new AlertDialog.Builder(MainActivity.this).setIcon(android.R.drawable.ic_dialog_alert) .setMessage(description).setPositiveButton("CLOSE", null).show(); } }); /* * WebChromeClient */ webView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView wv, int progress) { progressBar.setProgress(progress); if (progress > 0 && progress <= 60) { Helpers.getNotificationCount(wv); } if (progress > 60) { Helpers.hideTopBar(wv); fab.setVisibility(View.VISIBLE); } if (progress == 100) { fab.collapse(); progressBar.setVisibility(View.GONE); } else { progressBar.setVisibility(View.VISIBLE); } } @Override public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { if (mFilePathCallback != null) mFilePathCallback.onReceiveValue(null); mFilePathCallback = filePathCallback; Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); } catch (IOException ex) { // Error occurred while creating the File Snackbar.make(getWindow().findViewById(R.id.drawer), "Unable to get image", Snackbar.LENGTH_SHORT).show(); } // Continue only if the File was successfully created if (photoFile != null) { mCameraPhotoPath = "file:" + photoFile.getAbsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } else { takePictureIntent = null; } } Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); contentSelectionIntent.setType("image/*"); Intent[] intentArray; if (takePictureIntent != null) { intentArray = new Intent[] { takePictureIntent }; } else { intentArray = new Intent[0]; } Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE); return true; } public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return super.onJsAlert(view, url, message, result); } }); /* * NavigationView */ NavigationView navigationView = findViewById(R.id.navigation_view); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { if (menuItem.isChecked()) menuItem.setChecked(false); else menuItem.setChecked(true); drawerLayout.closeDrawers(); switch (menuItem.getItemId()) { default: Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return true; case R.id.jb_stream: if (Helpers.isOnline(MainActivity.this)) { txtTitle.setText(R.string.jb_stream); webView.loadUrl("https://" + podDomain + "/stream"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_public: setTitle(R.string.jb_public); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/public"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_liked: txtTitle.setText(R.string.jb_liked); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/liked"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_commented: txtTitle.setText(R.string.jb_commented); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/commented"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_contacts: txtTitle.setText(R.string.jb_contacts); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/contacts"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_mentions: txtTitle.setText(R.string.jb_mentions); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/mentions"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_activities: txtTitle.setText(R.string.jb_activities); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/activity"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_followed_tags: txtTitle.setText(R.string.jb_followed_tags); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/followed_tags"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_manage_tags: txtTitle.setText(R.string.jb_manage_tags); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/tag_followings/manage"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_license: txtTitle.setText(R.string.jb_license); new AlertDialog.Builder(MainActivity.this).setTitle(getString(R.string.license_title)) .setMessage(getString(R.string.license_text)) .setPositiveButton(getString(R.string.license_yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/mdev88/Diaspora-Native-WebApp")); startActivity(i); dialog.cancel(); } }) .setNegativeButton(getString(R.string.license_no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }) .show(); return true; case R.id.jb_aspects: txtTitle.setText(R.string.jb_aspects); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/aspects"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_settings: txtTitle.setText(R.string.jb_settings); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/user/edit"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_pod: txtTitle.setText(R.string.jb_pod); if (Helpers.isOnline(MainActivity.this)) { new AlertDialog.Builder(MainActivity.this).setTitle(getString(R.string.confirmation)) .setMessage(getString(R.string.change_pod_warning)) .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { @TargetApi(11) public void onClick(DialogInterface dialog, int id) { webView.clearCache(true); dialog.cancel(); Intent i = new Intent(MainActivity.this, PodsActivity.class); startActivity(i); finish(); } }).setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() { @TargetApi(11) public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).show(); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } } } }); /* * DrawerLayout */ drawerLayout = findViewById(R.id.drawer); ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.openDrawer, R.string.closeDrawer); drawerLayout.setDrawerListener(actionBarDrawerToggle); //calling sync state is necessary or else your hamburger icon wont show up actionBarDrawerToggle.syncState(); if (savedInstanceState == null) { if (Helpers.isOnline(MainActivity.this)) { webView.loadData("", "text/html", null); webView.loadUrl("https://" + podDomain); } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT) .show(); } } }
From source file:com.azure.webapi.LoginManager.java
/** * Creates the UI for the interactive authentication process * // w ww . jav a 2s . c o m * @param provider * The provider used for the authentication process * @param startUrl * The initial URL for the authentication process * @param endUrl * The final URL for the authentication process * @param context * The context used to create the authentication dialog * @param callback * Callback to invoke when the authentication process finishes */ protected void showLoginUI(MobileServiceAuthenticationProvider provider, final String startUrl, final String endUrl, final Context context, LoginUIOperationCallback callback) { if (startUrl == null || startUrl == "") { throw new IllegalArgumentException("startUrl can not be null or empty"); } if (endUrl == null || endUrl == "") { throw new IllegalArgumentException("endUrl can not be null or empty"); } if (context == null) { throw new IllegalArgumentException("context can not be null"); } final LoginUIOperationCallback externalCallback = callback; final AlertDialog.Builder builder = new AlertDialog.Builder(context); // Create the Web View to show the login page final WebView wv = new WebView(context); builder.setTitle("Connecting to a service"); builder.setCancelable(true); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException("User Canceled")); } } }); // Set cancel button's action builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException("User Canceled")); } wv.destroy(); } }); wv.getSettings().setJavaScriptEnabled(true); wv.requestFocus(View.FOCUS_DOWN); wv.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { int action = event.getAction(); if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) { if (!view.hasFocus()) { view.requestFocus(); } } return false; } }); // Create a LinearLayout and add the WebView to the Layout LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(wv); // Add a dummy EditText to the layout as a workaround for a bug // that prevents showing the keyboard for the WebView on some devices EditText dummyEditText = new EditText(context); dummyEditText.setVisibility(View.GONE); layout.addView(dummyEditText); // Add the layout to the dialog builder.setView(layout); final AlertDialog dialog = builder.create(); wv.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { // If the URL of the started page matches with the final URL // format, the login process finished if (isFinalUrl(url)) { if (externalCallback != null) { externalCallback.onCompleted(url, null); } dialog.dismiss(); } super.onPageStarted(view, url, favicon); } // Checks if the given URL matches with the final URL's format private boolean isFinalUrl(String url) { if (url == null) { return false; } return url.startsWith(endUrl); } // Checks if the given URL matches with the start URL's format private boolean isStartUrl(String url) { if (url == null) { return false; } return url.startsWith(startUrl); } @Override public void onPageFinished(WebView view, String url) { if (isStartUrl(url)) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException( "Logging in with the selected authentication provider is not enabled")); } dialog.dismiss(); } } }); wv.loadUrl(startUrl); dialog.show(); }