Skip to content

Commit dc0cffc

Browse files
authored
Merge pull request #2 from kivy/develop
update to latest develop branch
2 parents be10c02 + aadcfc4 commit dc0cffc

File tree

29 files changed

+242
-84
lines changed

29 files changed

+242
-84
lines changed

.github/workflows/push.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Checkout python-for-android
1212
uses: actions/checkout@v2
1313
- name: Set up Python 3.7
14-
uses: actions/setup-python@v2
14+
uses: actions/setup-python@v2.2.1
1515
with:
1616
python-version: 3.7
1717
- name: Run flake8
@@ -32,7 +32,7 @@ jobs:
3232
- name: Checkout python-for-android
3333
uses: actions/checkout@v2
3434
- name: Set up Python ${{ matrix.python-version }}
35-
uses: actions/setup-python@v2
35+
uses: actions/setup-python@v2.2.1
3636
with:
3737
python-version: ${{ matrix.python-version }}
3838
- name: Tox tests

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ jobs:
2424
- type -t deactivate && deactivate || true
2525
- export PATH=/opt/python/3.7.1/bin:$PATH
2626
# Install tox
27-
- pip3.7 install tox>=2.0
27+
- python3.7 -m pip install tox>=2.0
2828
# Install coveralls & dependencies
2929
# Note: pyOpenSSL needed to send the coveralls reports
30-
- pip3.7 install pyOpenSSL
31-
- pip3.7 install coveralls
30+
- python3.7 -m pip install pyOpenSSL
31+
- python3.7 -m pip install coveralls
3232
script:
3333
# ignores test_pythonpackage.py since it runs for too long
3434
- tox -- tests/ --ignore tests/test_pythonpackage.py

ci/makefiles/osx.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ all: install_java upgrade_cython install_android_ndk_sdk install_p4a
77

88
install_java:
99
brew tap adoptopenjdk/openjdk
10-
brew cask install adoptopenjdk13
10+
brew install --cask adoptopenjdk13
1111
/usr/libexec/java_home -V
1212

1313
upgrade_cython:

doc/source/services.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ options.
5353

5454
To create the service, create a python script with your service code
5555
and add a :code:`--service=myservice:/path/to/myservice.py` argument
56-
when calling python-for-android. The ``myservice`` name before the
57-
colon is the name of the service class, via which you will interact
58-
with it later. You can add multiple
59-
:code:`--service` arguments to include multiple services, which you
60-
will later be able to stop and start from your app.
56+
when calling python-for-android, or in buildozer.spec, a
57+
:code:`services = myservice:/path/to/myservice.py` [app] setting.
58+
The ``myservice`` name before the colon is the name of the service
59+
class, via which you will interact with it later. You can add multiple
60+
:code:`--service` arguments to include multiple services, or separate
61+
them with a comma in buildozer.spec, all of which you will later be
62+
able to stop and start from your app.
6163

6264
To run the services (i.e. starting them from within your main app
6365
code), you must use PyJNIus to interact with the java class

doc/source/troubleshooting.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ particular.
7272
Unpacking an APK
7373
----------------
7474

75-
It is sometimes useful to unpack a pacakged APK to see what is inside,
75+
It is sometimes useful to unpack a packaged APK to see what is inside,
7676
especially when debugging python-for-android itself.
7777

7878
APKs are just zip files, so you can extract the contents easily::

pythonforandroid/bootstraps/common/build/build.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ def make_package(args):
485485
"service_names": service_names,
486486
"android_api": android_api,
487487
"debug": "debug" in args.build_mode,
488+
"native_services": args.native_services
488489
}
489490
if get_bootstrap_name() == "sdl2":
490491
render_args["url_scheme"] = url_scheme
@@ -643,6 +644,9 @@ def parse_args_and_make_package(args=None):
643644
ap.add_argument('--service', dest='services', action='append', default=[],
644645
help='Declare a new service entrypoint: '
645646
'NAME:PATH_TO_PY[:foreground]')
647+
ap.add_argument('--native-service', dest='native_services', action='append', default=[],
648+
help='Declare a new native service: '
649+
'package.name.service')
646650
if get_bootstrap_name() != "service_only":
647651
ap.add_argument('--presplash', dest='presplash',
648652
help=('A jpeg file to use as a screen while the '

pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/PythonUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ protected static ArrayList<String> getLibraries(File libsDir) {
4343
libsList.add("python3.5m");
4444
libsList.add("python3.6m");
4545
libsList.add("python3.7m");
46-
libsList.add("python3.8m");
46+
libsList.add("python3.8");
47+
libsList.add("python3.9");
4748
libsList.add("main");
4849
return libsList;
4950
}
@@ -63,7 +64,7 @@ public static void loadLibraries(File filesDir, File libsDir) {
6364
// load, and it has failed, give a more
6465
// general error
6566
Log.v(TAG, "Library loading error: " + e.getMessage());
66-
if (lib.startsWith("python3.8") && !foundPython) {
67+
if (lib.startsWith("python3.9") && !foundPython) {
6768
throw new RuntimeException("Could not load any libpythonXXX.so");
6869
} else if (lib.startsWith("python")) {
6970
continue;

pythonforandroid/bootstraps/common/build/templates/build.tmpl.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:3.1.4'
8+
classpath 'com.android.tools.build:gradle:3.5.2'
99
}
1010
}
1111

@@ -100,17 +100,18 @@ android {
100100

101101
dependencies {
102102
{%- for aar in aars %}
103-
compile(name: '{{ aar }}', ext: 'aar')
103+
implementation(name: '{{ aar }}', ext: 'aar')
104104
{%- endfor -%}
105105
{%- for jar in jars %}
106-
compile files('src/main/libs/{{ jar }}')
106+
implementation files('src/main/libs/{{ jar }}')
107107
{%- endfor -%}
108108
{%- if args.depends -%}
109109
{%- for depend in args.depends %}
110-
compile '{{ depend }}'
110+
implementation '{{ depend }}'
111111
{%- endfor %}
112112
{%- endif %}
113113
{% if args.presplash_lottie %}
114114
implementation 'com.airbnb.android:lottie:3.4.0'
115115
{%- endif %}
116116
}
117+

pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@
117117
<service android:name="{{ args.package }}.Service{{ name|capitalize }}"
118118
android:process=":service_{{ name }}" />
119119
{% endfor %}
120+
{% for name in native_services %}
121+
<service android:name="{{ name }}" />
122+
{% endfor %}
120123

121124
{% if args.billing_pubkey %}
122125
<service android:name="org.kivy.android.billing.BillingReceiver"

pythonforandroid/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.InputStream;
66
import java.io.File;
77
import java.io.IOException;
8+
import java.lang.reflect.InvocationTargetException;
89
import java.util.Collections;
910
import java.util.Iterator;
1011
import java.util.List;
@@ -33,6 +34,7 @@
3334

3435
import android.webkit.WebViewClient;
3536
import android.webkit.WebView;
37+
import android.net.Uri;
3638

3739
import org.renpy.android.ResourceManager;
3840

@@ -44,6 +46,7 @@ public class PythonActivity extends Activity {
4446
private static final String TAG = "PythonActivity";
4547

4648
public static PythonActivity mActivity = null;
49+
public static boolean mOpenExternalLinksInBrowser = false;
4750

4851
/** If shared libraries (e.g. SDL or the native application) could not be loaded. */
4952
public static boolean mBrokenLibraries;
@@ -162,6 +165,13 @@ public void onClick(DialogInterface dialog,int id) {
162165
mWebView.setWebViewClient(new WebViewClient() {
163166
@Override
164167
public boolean shouldOverrideUrlLoading(WebView view, String url) {
168+
if (mOpenExternalLinksInBrowser) {
169+
if (!(url.startsWith("file:") || url.startsWith("http://127.0.0.1:"))) {
170+
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
171+
startActivity(i);
172+
return true;
173+
}
174+
}
165175
view.loadUrl(url);
166176
return false;
167177
}
@@ -239,6 +249,16 @@ public void run() {
239249
mActivity.runOnUiThread(new LoadUrl(url));
240250
}
241251

252+
public static void enableZoom() {
253+
mActivity.runOnUiThread(new Runnable() {
254+
@Override
255+
public void run() {
256+
mWebView.getSettings().setBuiltInZoomControls(true);
257+
mWebView.getSettings().setDisplayZoomControls(false);
258+
}
259+
});
260+
}
261+
242262
public static ViewGroup getLayout() {
243263
return mLayout;
244264
}
@@ -455,6 +475,73 @@ public static void stop_service() {
455475
public static native void nativeSetenv(String name, String value);
456476
public static native int nativeInit(Object arguments);
457477

478+
479+
/**
480+
* Used by android.permissions p4a module to register a call back after
481+
* requesting runtime permissions
482+
**/
483+
public interface PermissionsCallback {
484+
void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults);
485+
}
486+
487+
private PermissionsCallback permissionCallback;
488+
private boolean havePermissionsCallback = false;
489+
490+
public void addPermissionsCallback(PermissionsCallback callback) {
491+
permissionCallback = callback;
492+
havePermissionsCallback = true;
493+
Log.v(TAG, "addPermissionsCallback(): Added callback for onRequestPermissionsResult");
494+
}
495+
496+
@Override
497+
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
498+
Log.v(TAG, "onRequestPermissionsResult()");
499+
if (havePermissionsCallback) {
500+
Log.v(TAG, "onRequestPermissionsResult passed to callback");
501+
permissionCallback.onRequestPermissionsResult(requestCode, permissions, grantResults);
502+
}
503+
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
504+
}
505+
506+
/**
507+
* Used by android.permissions p4a module to check a permission
508+
**/
509+
public boolean checkCurrentPermission(String permission) {
510+
if (android.os.Build.VERSION.SDK_INT < 23)
511+
return true;
512+
513+
try {
514+
java.lang.reflect.Method methodCheckPermission =
515+
Activity.class.getMethod("checkSelfPermission", String.class);
516+
Object resultObj = methodCheckPermission.invoke(this, permission);
517+
int result = Integer.parseInt(resultObj.toString());
518+
if (result == PackageManager.PERMISSION_GRANTED)
519+
return true;
520+
} catch (IllegalAccessException | NoSuchMethodException |
521+
InvocationTargetException e) {
522+
}
523+
return false;
524+
}
525+
526+
/**
527+
* Used by android.permissions p4a module to request runtime permissions
528+
**/
529+
public void requestPermissionsWithRequestCode(String[] permissions, int requestCode) {
530+
if (android.os.Build.VERSION.SDK_INT < 23)
531+
return;
532+
try {
533+
java.lang.reflect.Method methodRequestPermission =
534+
Activity.class.getMethod("requestPermissions",
535+
String[].class, int.class);
536+
methodRequestPermission.invoke(this, permissions, requestCode);
537+
} catch (IllegalAccessException | NoSuchMethodException |
538+
InvocationTargetException e) {
539+
}
540+
}
541+
542+
public void requestPermissions(String[] permissions) {
543+
requestPermissionsWithRequestCode(permissions, 1);
544+
}
458545
}
459546

460547

0 commit comments

Comments
 (0)