Permalink
Browse files

Remove the title for dialogs and add the 'x' on the top left corner

Summary: For the oauth, feed, request dialogs, removed the title bar and added
the 'x' button on the top left corner which when pressed dismisses the dialog.

Test Plan: Launched Hackbook and click on Login or requests, feed dialogs and
confirm that there is no title bar and the cross button is rightly displayed and
dismisses the dialog.

Reviewers: lshepard, yariv, jimbru, dkim, ttung, omids, raghuc1

Reviewed By: ttung

CC: caabernathy, brent, vksgupta, mattwkelly, lshepard, ttung

Differential Revision: 333017

Task ID: 700698
  • Loading branch information...
1 parent 5d44d0c commit da41838c5859484375ec1411d2033a3262e35fa7 Vikas Gupta committed Sep 26, 2011
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -20,22 +20,21 @@
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
-import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Color;
-import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
-import android.view.Display;
+import android.view.View;
import android.view.ViewGroup;
+import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
+import android.widget.ImageView;
import android.widget.LinearLayout;
-import android.widget.TextView;
import com.facebook.android.Facebook.DialogListener;
@@ -55,12 +54,12 @@
private String mUrl;
private DialogListener mListener;
private ProgressDialog mSpinner;
+ private ImageView mCrossImage;
private WebView mWebView;
- private LinearLayout mContent;
- private TextView mTitle;
+ private FrameLayout mContent;
public FbDialog(Context context, String url, DialogListener listener) {
- super(context);
+ super(context, android.R.style.Theme_Translucent_NoTitleBar);
mUrl = url;
mListener = listener;
}
@@ -71,49 +70,61 @@ protected void onCreate(Bundle savedInstanceState) {
mSpinner = new ProgressDialog(getContext());
mSpinner.requestWindowFeature(Window.FEATURE_NO_TITLE);
mSpinner.setMessage("Loading...");
-
- mContent = new LinearLayout(getContext());
- mContent.setOrientation(LinearLayout.VERTICAL);
- setUpTitle();
- setUpWebView();
- Display display = getWindow().getWindowManager().getDefaultDisplay();
- final float scale =
- getContext().getResources().getDisplayMetrics().density;
- int orientation =
- getContext().getResources().getConfiguration().orientation;
- float[] dimensions =
- (orientation == Configuration.ORIENTATION_LANDSCAPE)
- ? DIMENSIONS_DIFF_LANDSCAPE : DIMENSIONS_DIFF_PORTRAIT;
- addContentView(mContent, new LinearLayout.LayoutParams(
- display.getWidth() - ((int) (dimensions[0] * scale + 0.5f)),
- display.getHeight() - ((int) (dimensions[1] * scale + 0.5f))));
- }
-
- private void setUpTitle() {
+
requestWindowFeature(Window.FEATURE_NO_TITLE);
- Drawable icon = getContext().getResources().getDrawable(
- R.drawable.facebook_icon);
- mTitle = new TextView(getContext());
- mTitle.setText("Facebook");
- mTitle.setTextColor(Color.WHITE);
- mTitle.setTypeface(Typeface.DEFAULT_BOLD);
- mTitle.setBackgroundColor(FB_BLUE);
- mTitle.setPadding(MARGIN + PADDING, MARGIN, MARGIN, MARGIN);
- mTitle.setCompoundDrawablePadding(MARGIN + PADDING);
- mTitle.setCompoundDrawablesWithIntrinsicBounds(
- icon, null, null, null);
- mContent.addView(mTitle);
+ mContent = new FrameLayout(getContext());
+
+ /* Create the 'x' image, but don't add to the mContent layout yet
+ * at this point, we only need to know its drawable width and height
+ * to place the webview
+ */
+ createCrossImage();
+
+ /* Now we know 'x' drawable width and height,
+ * layout the webivew and add it the mContent layout
+ */
+ int crossWidth = mCrossImage.getDrawable().getIntrinsicWidth();
+ setUpWebView(crossWidth / 2);
+
+ /* Finally add the 'x' image to the mContent layout and
+ * add mContent to the Dialog view
+ */
+ mContent.addView(mCrossImage, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
+ addContentView(mContent, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
+ }
+
+ private void createCrossImage() {
+ mCrossImage = new ImageView(getContext());
+ // Dismiss the dialog when user click on the 'x'
+ mCrossImage.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mListener.onCancel();
+ FbDialog.this.dismiss();
+ }
+ });
+ Drawable crossDrawable = getContext().getResources().getDrawable(R.drawable.close);
+ mCrossImage.setImageDrawable(crossDrawable);
+ /* 'x' should not be visible while webview is loading
+ * make it visible only after webview has fully loaded
+ */
+ mCrossImage.setVisibility(View.INVISIBLE);
}
- private void setUpWebView() {
+ private void setUpWebView(int margin) {
+ LinearLayout webViewContainer = new LinearLayout(getContext());
mWebView = new WebView(getContext());
mWebView.setVerticalScrollBarEnabled(false);
mWebView.setHorizontalScrollBarEnabled(false);
mWebView.setWebViewClient(new FbDialog.FbWebViewClient());
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl(mUrl);
mWebView.setLayoutParams(FILL);
- mContent.addView(mWebView);
+ mWebView.setVisibility(View.INVISIBLE);
+
+ webViewContainer.setPadding(margin, margin, margin, margin);
+ webViewContainer.addView(mWebView);
+ mContent.addView(webViewContainer);
}
private class FbWebViewClient extends WebViewClient {
@@ -172,12 +183,14 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
- String title = mWebView.getTitle();
- if (title != null && title.length() > 0) {
- mTitle.setText(title);
- }
mSpinner.dismiss();
+ /*
+ * Once webview is fully loaded, set the mContent background to be transparent
+ * and make visible the 'x' image.
+ */
+ mContent.setBackgroundColor(Color.TRANSPARENT);
+ mWebView.setVisibility(View.VISIBLE);
+ mCrossImage.setVisibility(View.VISIBLE);
}
-
}
}

1 comment on commit da41838

kwanste commented on da41838 Nov 2, 2011

I pulled down these changes and updated my jar, and I got something that doesn't seem to look right. Is anyone else getting a borderless dialog with a small Fb icon in the top left and no close button?

Please sign in to comment.