|
8 | 8 | import android.view.KeyEvent;
|
9 | 9 | import android.view.Window;
|
10 | 10 | import android.view.WindowManager;
|
| 11 | +import android.view.ViewTreeObserver; |
11 | 12 | import android.widget.Toast;
|
12 | 13 | import android.util.Log;
|
13 | 14 | import android.content.pm.PackageManager;
|
14 | 15 | import android.content.pm.ApplicationInfo;
|
| 16 | +import android.graphics.Rect; |
15 | 17 |
|
16 | 18 | import java.io.InputStream;
|
17 | 19 | import java.io.FileInputStream;
|
@@ -150,6 +152,9 @@ protected void onCreate(Bundle savedInstanceState) {
|
150 | 152 | getWindow().getDecorView().setBackgroundColor(
|
151 | 153 | this.mInfo.metaData.getInt("android.background_color"));
|
152 | 154 | }
|
| 155 | + |
| 156 | + this._layout_listener = new PythonLayoutListener(this); |
| 157 | + this.mView.getViewTreeObserver().addOnGlobalLayoutListener(this._layout_listener); |
153 | 158 | }
|
154 | 159 |
|
155 | 160 | /**
|
@@ -623,5 +628,45 @@ static String billingGetPendingMessage() {
|
623 | 628 | return mActivity.mBillingQueue.remove(0);
|
624 | 629 | }
|
625 | 630 |
|
| 631 | + |
| 632 | + //Layout Listener for kivy |
| 633 | + //replaces use of pyjnius in "android" package which can result in deadlock |
| 634 | + //on app pause |
| 635 | + public class PythonLayoutListener implements ViewTreeObserver.OnGlobalLayoutListener { |
| 636 | + |
| 637 | + private int height = 0; |
| 638 | + private PythonActivity mActivity = null; |
| 639 | + |
| 640 | + public PythonLayoutListener(PythonActivity _mActivity) { |
| 641 | + this.mActivity = _mActivity; |
| 642 | + } |
| 643 | + |
| 644 | + @Override |
| 645 | + public void onGlobalLayout() { |
| 646 | + Rect rctx = new Rect(); |
| 647 | + // print('rctx_bottom: {0}, top: {1}'.format(rctx.bottom, rctx.top)) |
| 648 | + this.mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rctx); |
| 649 | + // print('rctx_bottom: {0}, top: {1}'.format(rctx.bottom, rctx.top)) |
| 650 | + // print('activity height: {0}'.format(mActivity.getWindowManager().getDefaultDisplay().getHeight())) |
| 651 | + // NOTE top should always be zero |
| 652 | + rctx.top = 0; |
| 653 | + this.height = this.mActivity.getWindowManager().getDefaultDisplay().getHeight() - (rctx.bottom - rctx.top); |
| 654 | + // print('final height: {0}'.format(self.height)) |
| 655 | + |
| 656 | + } |
| 657 | + |
| 658 | + public int getHeight() { |
| 659 | + return this.height; |
| 660 | + } |
| 661 | + |
| 662 | + } |
| 663 | + |
| 664 | + private PythonLayoutListener _layout_listener = null; |
| 665 | + |
| 666 | + public int getLayoutListenerHeight() { |
| 667 | + return this._layout_listener.getHeight(); |
| 668 | + } |
| 669 | + |
626 | 670 | }
|
627 | 671 |
|
| 672 | + |
0 commit comments