1111import android .annotation .SuppressLint ;
1212import android .widget .LinearLayout ;
1313import android .view .Gravity ;
14+ import android .os .Build ;
1415
1516import android .app .DialogFragment ;
1617import android .content .DialogInterface ;
2526import android .view .ViewGroup .LayoutParams ;
2627import android .content .Context ;
2728import android .util .DisplayMetrics ;
29+ import android .view .Display ;
30+ import java .lang .reflect .Method ;
31+ import android .view .WindowManager ;
2832
2933import com .github .scribejava .core .model .OAuth1AccessToken ;
3034import com .github .scribejava .core .model .OAuth1RequestToken ;
3337import android .os .Bundle ;
3438import android .app .Fragment ;
3539import java .io .IOException ;
40+ import com .facebook .react .bridge .ReactContext ;
3641
3742public class OAuthManagerDialogFragment extends DialogFragment implements AdvancedWebView .Listener {
3843
@@ -42,52 +47,72 @@ public class OAuthManagerDialogFragment extends DialogFragment implements Advanc
4247 private static final String TAG = "OAuthManagerDialogFragment" ;
4348 private OAuthManagerFragmentController mController ;
4449
50+ private ReactContext mReactContext ;
4551 private AdvancedWebView mWebView ;
4652
4753 public static final OAuthManagerDialogFragment newInstance (
54+ final ReactContext reactContext ,
4855 OAuthManagerFragmentController controller
4956 ) {
5057 Bundle args = new Bundle ();
5158 OAuthManagerDialogFragment frag =
52- new OAuthManagerDialogFragment (controller );
59+ new OAuthManagerDialogFragment (reactContext , controller );
5360
5461 return frag ;
5562 }
5663
5764 public OAuthManagerDialogFragment (
65+ final ReactContext reactContext ,
5866 OAuthManagerFragmentController controller
5967 ) {
6068 this .mController = controller ;
69+ this .mReactContext = reactContext ;
6170 }
6271
6372 @ Override
6473 public View onCreateView (LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) {
6574 // View rootView = inflater.inflate(R.id.primary, container, false);
66- final Context context = inflater .getContext ();
75+ // final Context context = inflater.getContext();
6776 // DisplayMetrics metrics = context.getResources().getDisplayMetrics();
68- // final int DIALOG_HEIGHT = (int) Math.min(0.8f * metrics.heightPixels, 1024);
77+ // final int DIALOG_HEIGHT = (int) Math.min(0.99f * metrics.heightPixels, 1024);
78+
79+ // LayoutParams rootViewLayoutParams = new LayoutParams(
80+ // LayoutParams.FILL_PARENT,
81+ // LayoutParams.FILL_PARENT
82+ // );
83+ final Context context = mReactContext ;
84+ LayoutParams rootViewLayoutParams = this .getFullscreenLayoutParams (context );
6985
7086 FrameLayout rootView = new FrameLayout (context );
7187 getDialog ().setCanceledOnTouchOutside (true );
72- rootView .setLayoutParams (new LayoutParams ( LayoutParams . FILL_PARENT , LayoutParams . FILL_PARENT ) );
88+ rootView .setLayoutParams (rootViewLayoutParams );
7389
7490 // mWebView = (AdvancedWebView) rootView.findViewById(R.id.webview);
7591 Log .d (TAG , "Creating webview" );
7692 mWebView = new AdvancedWebView (context );
7793 mWebView .setId (WEBVIEW_TAG );
7894 mWebView .setListener (this , this );
7995 mWebView .setVisibility (View .VISIBLE );
96+ mWebView .getSettings ().setJavaScriptEnabled (true );
97+ mWebView .getSettings ().setDomStorageEnabled (true );
98+
99+ LayoutParams layoutParams = this .getFullscreenLayoutParams (context );
100+ //new LayoutParams(
101+ // LayoutParams.FILL_PARENT,
102+ // DIALOG_HEIGHT
103+ // );
104+ // mWebView.setLayoutParams(layoutParams);
80105
81- rootView .addView (mWebView , new LayoutParams ( LayoutParams . FILL_PARENT , LayoutParams . FILL_PARENT ) );
106+ rootView .addView (mWebView , layoutParams );
82107
83- LinearLayout pframe = new LinearLayout (context );
84- pframe .setId (WIDGET_TAG );
85- pframe .setOrientation (LinearLayout .VERTICAL );
86- pframe .setVisibility (View .GONE );
87- pframe .setGravity (Gravity .CENTER );
108+ // LinearLayout pframe = new LinearLayout(context);
109+ // pframe.setId(WIDGET_TAG);
110+ // pframe.setOrientation(LinearLayout.VERTICAL);
111+ // pframe.setVisibility(View.GONE);
112+ // pframe.setGravity(Gravity.CENTER);
113+ // pframe.setLayoutParams(layoutParams);
88114
89- rootView .addView (pframe ,
90- new LayoutParams (LayoutParams .FILL_PARENT , LayoutParams .FILL_PARENT ));
115+ // rootView.addView(pframe, layoutParams);
91116
92117 this .setupWebView (mWebView );
93118 mController .getRequestTokenUrlAndLoad (mWebView );
@@ -96,12 +121,49 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
96121 return rootView ;
97122 }
98123
124+ private LayoutParams getFullscreenLayoutParams (Context context ) {
125+ WindowManager wm = (WindowManager ) context .getSystemService (Context .WINDOW_SERVICE );
126+ // DisplayMetrics metrics = context.getResources().getDisplayMetrics();
127+ Display display = wm .getDefaultDisplay ();
128+ int realWidth ;
129+ int realHeight ;
130+
131+ if (Build .VERSION .SDK_INT >= 17 ){
132+ //new pleasant way to get real metrics
133+ DisplayMetrics realMetrics = new DisplayMetrics ();
134+ display .getRealMetrics (realMetrics );
135+ realWidth = realMetrics .widthPixels ;
136+ realHeight = realMetrics .heightPixels ;
137+
138+ } else if (Build .VERSION .SDK_INT >= 14 ) {
139+ //reflection for this weird in-between time
140+ try {
141+ Method mGetRawH = Display .class .getMethod ("getRawHeight" );
142+ Method mGetRawW = Display .class .getMethod ("getRawWidth" );
143+ realWidth = (Integer ) mGetRawW .invoke (display );
144+ realHeight = (Integer ) mGetRawH .invoke (display );
145+ } catch (Exception e ) {
146+ //this may not be 100% accurate, but it's all we've got
147+ realWidth = display .getWidth ();
148+ realHeight = display .getHeight ();
149+ Log .e ("Display Info" , "Couldn't use reflection to get the real display metrics." );
150+ }
151+
152+ } else {
153+ //This should be close, as lower API devices should not have window navigation bars
154+ realWidth = display .getWidth ();
155+ realHeight = display .getHeight ();
156+ }
157+
158+ return new LayoutParams (realWidth , realHeight );
159+ }
160+
161+
99162 private void setupWebView (AdvancedWebView webView ) {
100163 webView .setWebViewClient (new WebViewClient () {
101164 @ Override
102165 public boolean shouldOverrideUrlLoading (WebView view , String url ) {
103- interceptUrl (view , url , true );
104- return true ;
166+ return interceptUrl (view , url , true );
105167 }
106168
107169 @ Override
@@ -112,6 +174,7 @@ public void onReceivedError(WebView view, int code, String desc, String failingU
112174 }
113175
114176 private boolean interceptUrl (WebView view , String url , boolean loadUrl ) {
177+ Log .i (TAG , "interceptUrl called with url: " + url );
115178 if (isCallbackUri (url , mController .getCallbackUrl ())) {
116179 mController .getAccessToken (mWebView , url );
117180
@@ -192,6 +255,7 @@ public void onPageStarted(String url, Bitmap favicon) {
192255 @ Override
193256 public void onPageFinished (String url ) {
194257 Log .d (TAG , "onPageFinished: " + url );
258+ // mController.onComplete(url);
195259 }
196260
197261 @ Override
0 commit comments