Android: a login dialog like facebook with cancel button
public class LoginFragment extends DialogFragment {
/**The webview for load url**/
WebView webView;
/**a progressBar to show the progress**/
ProgressBar pb;
ImageView crossImageView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.AppTheme);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
//Create a new context for login dialog
FrameLayout contentFrameLayout = new FrameLayout(getActivity());
contentFrameLayout.setPadding(0, 0, 0, 0);
//create a x imageview
createCrossImage();
int crossWidth = crossImageView.getDrawable().getIntrinsicWidth();
int margin =crossWidth/2+1;
LinearLayout webViewContainer = new LinearLayout(getActivity());
webViewContainer.setOrientation(LinearLayout.VERTICAL);
webView = new WebView(getActivity());
webView.setVerticalScrollBarEnabled(false);
webView.setHorizontalScrollBarEnabled(false);
initWebView(webView);
webViewContainer.setPadding(margin, margin, margin, margin);
//For dialog get the focus
EditText edit = new EditText(getActivity());
edit.setWidth(0);
edit.setHeight(0);
edit.setFocusable(true);
edit.requestFocus();
edit.setVisibility(View.INVISIBLE);
webViewContainer.addView(webView);
webViewContainer.addView(edit);
pb=new ProgressBar(getActivity());
webViewContainer.addView(pb,new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
contentFrameLayout.addView(webViewContainer);
contentFrameLayout.addView(crossImageView, new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
String loginurl ="www.google.com";
webView.loadUrl(loginurl);
builder.setTitle("Sign in with facebook");
builder.setView(contentFrameLayout);
return builder.create();
}
private void createCrossImage() {
crossImageView = new ImageView(getActivity());
// Dismiss the dialog when user click on the 'x'
crossImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
Drawable crossDrawable = getActivity().getResources().getDrawable(R.drawable.com_facebook_close);
crossImageView.setImageDrawable(crossDrawable);
/* 'x' should not be visible while webview is loading
* make it visible only after webview has fully loaded
*/
crossImageView.setVisibility(View.INVISIBLE);
}
/**
* Set the webview initial configure
* @param wv
*/
@SuppressLint("SetJavaScriptEnabled")
private void initWebView(WebView wv) {
wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
wv.getSettings().setJavaScriptEnabled(true);
wv.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url) {
crossImageView.setVisibility(View.VISIBLE);
super.onPageFinished(view, url);
}
});
}
public void onCancel(DialogInterface dialog) {
// send cancel command
Message msg = new Message();
msg.what = MainActivity.LOGIN_CANCEL_CODE;
mainHandler.sendMessage(msg);
// stop load pages. to avoid null point
webView.stopLoading();
}
}
You must Sign up as a member of Effecthub to view the content.
A PHP Error was encountered
Severity: Notice
Message: Undefined index: HTTP_ACCEPT_LANGUAGE
Filename: helpers/time_helper.php
Line Number: 22
Latest Posts
- Android: CookieManager removeAllCookie() Crash
- XlistView: A listview which can pull to refresh and load more (1)
- Millions of Android Phones Could Be Affected by the Heartbleed Bug. Check to See if Yours Is One of Them
- TOP 10 ANDROID GAMES FOR MARCH 2014
- Android:Button with different textcolor and background in different states
3939 views 1 comments
You must Sign up as a member of Effecthub to join the conversation.