3

How can I change dialog size for Android Facebook SDK? It's almost fullscreen which is OK for phone, but not OK for tablet. I would like to have different dialog size for tables and phones.

Marcin
  • 65
  • 5

3 Answers3

2

Why not instantiate it, or the pieces you want, in a Fragment?

Here is the doc for Webview Fragments http://developer.android.com/reference/android/webkit/WebViewFragment.html

Now Facebook does have some native Fragments integrated into their SDK, like the Picker Fragment: https://developers.facebook.com/docs/reference/android/3.0/PickerFragment

This is what the webfragment would look like when you place it in your Layout:

 <fragment 
    android:id="@+id/webFragment"
    android:layout_width="150dip"
    android:layout_height="match_parent"
    android:name="my.proj.WebViewer"></fragment >

You should be able to Fragmentize what you need for Tablets. Justin Breitfeller posted this code on stackoverflow: How to detect 7" Android tablet in code

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

float widthInInches = metrics.widthPixels / metrics.xdpi;
float heightInInches = metrics.heightPixels / metrics.ydpi

double sizeInInchesSquared = (widthInInches * widthInInches) + (heightInInches * heightInInches);
//0.5" buffer for 7" devices (6.5^2 = 42.25) (7.5^2 = 56.25)
boolean is7inchTablet = sizeInInchesSquared >= 42.25 && sizeInInchesSquared <= 56.25; 

I have used this in the past to make a different view for 7" and above screens in the past effectively. Then, you can call a different layout using different fragments or having fragments change size dynamically to effectively fit a screen based on type.

It would be helpful if you gave us a bit more detail about what exactly you are trying to do.

Community
  • 1
  • 1
childofthehorn
  • 697
  • 1
  • 4
  • 12
2

In the Android Facebook 3.0 SDK make sure the LoginActivity Activity declaration in your manifest looks like this:

<activity android:name="com.facebook.LoginActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar"/>

Setting the theme like this still starts the facebook activity as a fullscreen activity, but the entire activity is transparent so it looks like only a dialog appears.

I guess this is more of a hack than anything else, but that's how Facebook does this in the Scrumptious sample project.

*****EDIT*****

If you're using version 4.x of the Facebook SDK you need to override and REPLACE the theme of the FacebookActivity in your AndroidManifest like so ::

        <activity
            tools:replace="android:theme"
            android:name="com.facebook.FacebookActivity"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
dell116
  • 5,835
  • 9
  • 52
  • 70
  • I'm not sure it's still valid now, no transparent with facebook SDK 3.21.1 on Lollipop 5.0.2 – Mia Mar 03 '15 at 10:52
  • Interesting. This may have changed depending on the theme FB is using in their new SDK. I assume you may have to do some work with theming, but can't be sure at the moment. I will certainly find out when I get to updating the fb SDK in my apps. In the meantime, if you find a solution please don't hesitate to share ;-) – dell116 Mar 03 '15 at 17:36
1

If anyone cares - Facebook doesn't support this out of the box. You have to hack the code with some special cases, using calculations similar to childofthehorn's to check if the device is tablet or not, and then resize it manually.

Marcin
  • 65
  • 5