mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 02:38:02 +00:00
Support detecting whether device is a tablet and use that to determine whether to enforce portrait orientation
This commit is contained in:
@@ -8,6 +8,7 @@ import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
@@ -29,13 +30,15 @@ public class Main extends AndroidApplication {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//setup portrait orientation
|
||||
AndroidAdapter adapter = new AndroidAdapter(this.getContext());
|
||||
|
||||
//enforce portrait orientation for non-tablet screens
|
||||
if (!adapter.isTablet) {
|
||||
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
if (Build.VERSION.SDK_INT > 8) { //use dual-side portrait mode if supported
|
||||
this.setRequestedOrientation(7);
|
||||
}
|
||||
|
||||
AndroidAdapter adapter = new AndroidAdapter();
|
||||
}
|
||||
|
||||
//establish assets directory
|
||||
if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||
@@ -88,8 +91,15 @@ public class Main extends AndroidApplication {
|
||||
}
|
||||
|
||||
private class AndroidAdapter implements IDeviceAdapter {
|
||||
private final boolean isTablet;
|
||||
private final ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
private AndroidAdapter(Context context) {
|
||||
isTablet = (context.getResources().getConfiguration().screenLayout
|
||||
& Configuration.SCREENLAYOUT_SIZE_MASK)
|
||||
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectedToInternet() {
|
||||
return Boolean.TRUE.equals(ThreadUtil.executeWithTimeout(new Callable<Boolean>() {
|
||||
@@ -146,5 +156,10 @@ public class Main extends AndroidApplication {
|
||||
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); // hide (remove, in this case) task from recents
|
||||
startActivity(relaunch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTablet() {
|
||||
return isTablet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,5 +58,10 @@ public class Main {
|
||||
public void exit() {
|
||||
Gdx.app.exit(); //can just use Gdx.app.exit for desktop
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTablet() {
|
||||
return true; //treat desktop the same as a tablet
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package forge.interfaces;
|
||||
public interface IDeviceAdapter {
|
||||
boolean isConnectedToInternet();
|
||||
boolean isConnectedToWifi();
|
||||
boolean isTablet();
|
||||
String getDownloadsDir();
|
||||
boolean openFile(String filename);
|
||||
void exit();
|
||||
|
||||
Reference in New Issue
Block a user