1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

Added android permission request dialog

This commit is contained in:
lufebe16 2019-10-14 17:44:46 +02:00
parent 64cd1b73f2
commit 70fedf618a
6 changed files with 88 additions and 59 deletions

17
android/initsupport Executable file
View file

@ -0,0 +1,17 @@
#!/bin/bash
set -eux
# Download android support library from maven
. mkp4a.common
liburl="https://maven.google.com/com/android/support/support-v4/24.1.1"
libname="support-v4-24.1.1.aar"
if [[ ! -f ${libdir}/${libname} ]]; then
mkdir -p ${libdir}
pushd ${libdir}
wget ${liburl}/${libname}
popd
else
echo "Skipping supportlib download as already present."
fi

View file

@ -10,6 +10,7 @@ cardsets_file="${cardsets_dir}.tar.xz"
sdkdir="${HOME}/.cache/sdk-for-p4a/sdk"
ndkdir="${HOME}/.cache/sdk-for-p4a/android-ndk-r17c"
libdir="${HOME}/.cache/sdk-for-p4a/libs"
# gradle may need this.
export TERM="xterm"
@ -28,4 +29,5 @@ p4a_options="\
--icon ${tmpdir}/data/images/icons/48x48/pysol.png \
--presplash ${tmpdir}/data/images/icons/1024x1024/pysol.png \
--copy-libs \
--add-jar ${tmpdir}/support-v4-24.1.1.aar \
--color always"

View file

@ -9,6 +9,7 @@ echo '### prepare sdk'
if [[ $# == 0 ]]
then
./initsupport
./initsdk
fi
@ -47,6 +48,7 @@ rm -rf ${tmpdir}/setup.py
rm -rf ${tmpdir}/setup_osx.py
rm -rf ${tmpdir}/setup.cfg
cp -a ${libdir}/support-v4-24.1.1.aar ${tmpdir}
cp -a main.py ${tmpdir}
mkdir -p ${tmpdir}/data/images/cards/bottoms/trumps-only
echo "" > ${tmpdir}/data/images/cards/bottoms/trumps-only/.keep

View file

@ -52,6 +52,8 @@ from kivy.uix.treeview import TreeViewLabel
from kivy.uix.widget import Widget
from kivy.utils import platform
from pysollib.kivy.androidperms import requestStoragePerm
# =============================================================================
@ -1794,6 +1796,8 @@ class LApp(App):
self.mainloop = self.app.mainproc() # Einrichten
self.mainloop.send(None) # Spielprozess starten
logging.info("LApp: on_start processed")
# Android: Request missing android permissions.
requestStoragePerm()
def on_stop(self):
# Achtung wird u.U. 2 mal aufgerufen !!!
@ -1847,12 +1851,6 @@ class LApp(App):
except Exception:
traceback.print_exc()
pass
# save comments
try:
app.saveComments()
except Exception:
traceback.print_exc()
pass
logging.info("LApp: on_pause - gamesaved")
logging.info("LApp: on_pause, Window.size=%s" % str(Window.size))

View file

@ -0,0 +1,61 @@
import time
import logging
try:
import jnius
except ImportError:
jnius = None
# link address of related support library:
# https://maven.google.com/com/android/support/support-v4/24.1.1/support-v4-24.1.1.aar
# inspired by stackoverflow.com/questions/47510030/
# as functools (reduce,partial,map) do not seem to work in python3 on android,
# implemented in a classic functional way.
# LB190927.
# wait loop removed. (Implement it in external code if needed.)
# LB191011.
class AndroidPerms(object):
def __init__(self):
if jnius is None:
return
self.PythonActivity = jnius.autoclass('org.kivy.android.PythonActivity')
self.Compat = jnius.autoclass('android.support.v4.content.ContextCompat')
self.currentActivity = jnius.cast('android.app.Activity', self.PythonActivity.mActivity)
def getPerm(self,permission):
if jnius is None:
return True
p = self.Compat.checkSelfPermission(self.currentActivity,permission)
return p == 0
# check actual permissions
def getPerms(self,permissions):
if jnius is None:
return True
haveperms = True
for perm in permissions:
haveperms = haveperms and self.getPerm(perm)
return haveperms
# invoke the permissions dialog
def requestPerms(self,permissions):
if jnius is None:
return True
logging.info("androidperms: invoke permission dialog")
self.currentActivity.requestPermissions(permissions, 0)
return
def getStoragePerm():
ap = AndroidPerms()
return ap.getPerms(
["android.permission.WRITE_EXTERNAL_STORAGE"])
def requestStoragePerm():
ap = AndroidPerms()
#ap.requestPerms(
# ["android.permission.READ_EXTERNAL_STORAGE","android.permission.WRITE_EXTERNAL_STORAGE"])
ap.requestPerms(
["android.permission.WRITE_EXTERNAL_STORAGE"])

View file

@ -221,7 +221,7 @@ class PysolAboutDialog(object):
logging.info('PysolAboutDialog: txt=%s' % text)
text = text + '\n\n' + 'Adaptation to Kivy/Android\n' + \
' Copyright (C) (2016-17) LB'
' Copyright (C) (2016-19) LB'
self.parent = parent
self.app = app
@ -261,13 +261,6 @@ class PysolAboutDialog(object):
label = FText(text=text, halign='center', size_hint=(1, 1))
window.content.add_widget(label)
'''
label = LLabel(text=text)
label.texture_update()
label.size = label.texture_size
image = LImage(texture=label.texture)
window.content.add_widget(image)
'''
# ************************************************************************
# * a simple tooltip
@ -637,53 +630,9 @@ class MfxScrolledCanvas(object):
def scroll_bottom(self, *event):
return self._yview('moveto', 1)
# ************************************************************************
# *
# ************************************************************************
# not used witch kivy. would not nun as it refers TkInter.
'''
class StackDesc:
def __init__(self, game, stack):
self.game = game
self.stack = stack
self.canvas = game.canvas
self.bindings = []
font = game.app.getFont('canvas_small')
# print self.app.cardset.CARDW, self.app.images.CARDW
cardw = game.app.images.CARDW
x, y = stack.x + cardw / 2, stack.y
text = stack.getHelp() + '\n' + stack.getBaseCard()
text = text.strip()
if text:
frame = Tkinter.Frame(self.canvas)
self.frame = frame
label = Tkinter.Message(frame, font=font, text=text,
width=cardw - 8, relief='solid',
fg='#000000', bg='#ffffe0', bd=1)
label.pack()
self.label = label
self.id = self.canvas.create_window(
x, y, window=frame, anchor='n')
self.bindings.append(label.bind(
'<ButtonPress>', self._buttonPressEvent))
# self.bindings.append(label.bind('<Enter>', self._enterEvent))
else:
self.id = None
def _buttonPressEvent(self, *event):
# self.game.deleteStackDesc()
self.frame.tkraise()
def _enterEvent(self, *event):
self.frame.tkraise()
def delete(self):
if self.id:
self.canvas.delete(self.id)
for b in self.bindings:
self.label.unbind('<ButtonPress>', b)
'''