8000 fixes for #890 (deadlock on pause/resume with pyjnius/pygame) by hottwaj · Pull Request #892 · kivy/python-for-android · GitHub
[go: up one dir, main page]

Skip to content

fixes for #890 (deadlock on pause/resume with pyjnius/pygame) #892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;
import android.view.ViewTreeObserver;
import android.widget.Toast;
import android.util.Log;
import android.content.pm.PackageManager;
import android.content.pm.ApplicationInfo;
import android.graphics.Rect;

import java.io.InputStream;
import java.io.FileInputStream;
Expand Down Expand Up @@ -150,6 +152,9 @@ protected void onCreate(Bundle savedInstanceState) {
getWindow().getDecorView().setBackgroundColor(
this.mInfo.metaData.getInt("android.background_color"));
}

this._layout_listener = new PythonLayoutListener(this);
this.mView.getViewTreeObserver().addOnGlobalLayoutListener(this._layout_listener);
}

/**
Expand Down Expand Up @@ -623,5 +628,45 @@ static String billingGetPendingMessage() {
return mActivity.mBillingQueue.remove(0);
}


//Layout Listener for kivy
//replaces use of pyjnius in "android" package which can result in deadlock
//on app pause
public class PythonLayoutListener implements ViewTreeObserver.OnGlobalLayoutListener {

private int height = 0;
private PythonActivity mActivity = null;

public PythonLayoutListener(PythonActivity _mActivity) {
this.mActivity = _mActivity;
}

@Override
public void onGlobalLayout() {
Rect rctx = new Rect();
// print('rctx_bottom: {0}, top: {1}'.format(rctx.bottom, rctx.top))
this.mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rctx);
// print('rctx_bottom: {0}, top: {1}'.format(rctx.bottom, rctx.top))
// print('activity height: {0}'.format(mActivity.getWindowManager().getDefaultDisplay().getHeight()))
// NOTE top should always be zero
rctx.top = 0;
this.height = this.mActivity.getWindowManager().getDefaultDisplay().getHeight() - (rctx.bottom - rctx.top);
// print('final height: {0}'.format(self.height))

}

public int getHeight() {
return this.height;
}

}

private PythonLayoutListener _layout_listener = null;

public int getLayoutListenerHeight() {
return this._layout_listener.getHeight();
}

}


13 changes: 8 additions & 5 deletions pythonforandroid/recipes/android/src/android/_android.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,17 @@ if mActivity:
self.height = mActivity.getWindowManager().getDefaultDisplay().getHeight() - (rctx.bottom - rctx.top)
# print('final height: {0}'.format(self.height))

ll = LayoutListener()
IF BOOTSTRAP == 'sdl2':
ll = LayoutListener()
python_act.getLayout().getViewTreeObserver().addOnGlobalLayoutListener(ll)
ELSE:
python_act.mView.getViewTreeObserver().addOnGlobalLayoutListener(ll)

def get_keyboard_height():
return ll.height
def get_keyboard_height():
return ll.height

ELSE:
def get_keyboard_height():
return python_act.getLayoutListenerHeight()

else:
def get_keyboard_height():
return 0
Expand Down
0