Implement messagebox and enable resize

This commit is contained in:
mittorn 2016-05-09 15:05:28 +00:00
parent 57f3f03236
commit 0735d551ff
3 changed files with 85 additions and 3 deletions

@ -1 +1 @@
Subproject commit d2bd0aaa30d53ae460b9cb74a6066ec40b55e0b6
Subproject commit f6e28e5dc876ab0269f8f0ff97c375029a2864c8

View file

@ -60,8 +60,8 @@ public class XashActivity extends Activity {
// fullscreen
requestWindowFeature(Window.FEATURE_NO_TITLE);
if(sdk >= 12)
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//if(sdk >= 12)
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// landscapeSensor is not supported until API9
if( sdk < 9 )
@ -125,6 +125,7 @@ public class XashActivity extends Activity {
InstallReceiver.extractPAK(this, false);
mPixelFormat = mPref.getInt("pixelformat", 0);
AndroidBug5497Workaround.assistActivity(this);
}
// Events
@ -170,6 +171,38 @@ public class XashActivity extends Activity {
public static Context getContext() {
return mSingleton;
}
protected final String[] messageboxData = new String[2];
public static void messageBox(String title, String text)
{
mSingleton.messageboxData[0] = title;
mSingleton.messageboxData[1] = text;
mSingleton.runOnUiThread(new Runnable() {
@Override
public void run()
{
new AlertDialog.Builder(mSingleton)
.setTitle(mSingleton.messageboxData[0])
.setMessage(mSingleton.messageboxData[1])
.setPositiveButton( "Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
synchronized(mSingleton.messageboxData)
{
mSingleton.messageboxData.notify();
}
}
})
.setCancelable(false)
.show();
}
});
synchronized (mSingleton.messageboxData) {
try {
mSingleton.messageboxData.wait();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
public static boolean handleKey( int keyCode, KeyEvent event )
{
@ -613,3 +646,51 @@ class EngineTouchListener_v5 implements View.OnTouchListener{
return true;
}
}
class AndroidBug5497Workaround {
// For more information, see https://code.google.com/p/android/issues/detail?id=5497
// To use this class, simply invoke assistActivity() on an Activity that already has its content view set.
public static void assistActivity (Activity activity) {
new AndroidBug5497Workaround(activity);
}
private View mChildOfContent;
private int usableHeightPrevious;
private FrameLayout.LayoutParams frameLayoutParams;
private AndroidBug5497Workaround(Activity activity) {
FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
mChildOfContent = content.getChildAt(0);
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
possiblyResizeChildOfContent();
}
});
frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
}
private void possiblyResizeChildOfContent() {
int usableHeightNow = computeUsableHeight();
if (usableHeightNow != usableHeightPrevious) {
int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
int heightDifference = usableHeightSansKeyboard - usableHeightNow;
if (heightDifference > (usableHeightSansKeyboard/4)) {
// keyboard probably just became visible
frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
} else {
// keyboard probably just became hidden
frameLayoutParams.height = usableHeightSansKeyboard;
}
mChildOfContent.requestLayout();
usableHeightPrevious = usableHeightNow;
}
}
private int computeUsableHeight() {
Rect r = new Rect();
mChildOfContent.getWindowVisibleDisplayFrame(r);
return (r.bottom - r.top);
}
}

View file

@ -76,6 +76,7 @@
<activity android:name="in.celest.xash3d.XashActivity"
android:screenOrientation="sensorLandscape"
android:configChanges="orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:label="@string/app_name">
<intent-filter>
<action android:name="in.celest.xash3d.START" />