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

Android version.

- added code to resize 4k images in apk build.
- added code to resize '4k' cardsets in apk build.
- deleted obsolet directory android as anounced earlier.
This commit is contained in:
lufebe16 2023-11-05 09:58:19 +01:00
parent 92f1870b23
commit e01d0fe7a7
24 changed files with 173 additions and 465 deletions

View file

@ -1,11 +0,0 @@
This android build setup ist out-dated.
Please use the new setup presented in directory
buildozer.
LB221118.
This Directory will soon be deleted from the Repo.
LB230919.

View file

@ -1,16 +0,0 @@
Actions to take upon a freshly installed Debian stretch/xfce (virtualbox).
Do something like:
user$ su
- enter root password.
root$ ./apt-install.sh
- .... some output.
root$ exit
Now all required packages are installed to proceed with the
android build.
LB170709.

View file

@ -1,34 +0,0 @@
#!/bin/sh
set -e
# install as root
apt-get install -y \
git \
openjdk-8-jdk \
cython3 \
python3-pip \
python3-yaml \
virtualenv \
pkg-config \
automake autoconf libtool \
zlib1g-dev \
libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev \
libtinfo5 \
lld
update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
apt-get install -y --no-install-recommends \
imagemagick \
python3-tk \
ccache \
libltdl-dev
# set python3 as default.
# make python alternatives selectable.
# (debian stretch, adapt for different versions)
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2

View file

@ -1,31 +0,0 @@
#!/bin/bash
set -eux
# This script mimics the instructions laid out in the p4a documentation:
# https://python-for-android.readthedocs.io/en/latest/quickstart/
. mkp4a.common
urlbase=https://dl.google.com/android/repository/
if [[ -d $ndkdir ]]; then
echo "Skipping NDK installation: NDK directory already exists."
else
mkdir -p $ndkdir
ndk_zip=android-ndk-${ndkver}-linux-x86_64.zip
[ -a $ndk_zip ] || wget $urlbase/$ndk_zip
unzip -d $(dirname $ndkdir) $ndk_zip
fi
if [[ -d $sdkdir ]]; then
echo "Skipping SDK installation: SDK directory already exists."
else
mkdir -p $sdkdir
tools_zip=sdk-tools-linux-4333796.zip
[ -a $tools_zip ] || wget $urlbase/$tools_zip
unzip -d $sdkdir $tools_zip
$sdkdir/tools/bin/sdkmanager 'platforms;android-27'
$sdkdir/tools/bin/sdkmanager 'build-tools;29.0.1'
fi

View file

@ -1,10 +0,0 @@
#!/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"
. mkp4a.preload supportlib ${liburl} ${libname}

View file

@ -1,37 +0,0 @@
#!/usr/bin/env python3
# ---------------------------------------------------------------------------
#
# PySol -- a Python Solitaire game
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.
# If not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# ---------------------------------------------------------------------------
# Starter for kivy/android using buildozer: Needs an explizitly
# named main.py as startpoint.
import sys
if '--kivy' not in sys.argv:
sys.argv.append('--kivy')
runmain = True
if runmain:
from pysollib.init import init
init()
if runmain:
from pysollib.main import main
sys.exit(main(sys.argv))

View file

@ -1,27 +0,0 @@
#!/bin/bash
set -eux
. mkp4a.common
echo '### prepare cardsets'
if [ ! -f ${cardsets_file} ]; then
echo '### downloading cardsets'
wget https://netix.dl.sourceforge.net/project/pysolfc/PySolFC-Cardsets/minimal/${cardsets_file}
fi
if [ ! -d ${cardsets_dir} ]; then
echo '### extracting cardsets'
tar -xf ${cardsets_file}
fi
echo '### processing cardsets'
(
cd ${cardsets_dir}
../../scripts/cardconv gif png
for i in cardset-*-png; do
rm -rf `basename $i -png`
done
)
echo '### end cardsets'

View file

@ -1,13 +0,0 @@
#!/bin/bash
set -eux
# memo:
# keytool -genkey -v -keystore my-release-keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 12000
mkdir -p bin
if [ -f ./bin/keystore ]; then
echo "keystore is already defined"
else
keytool -genkey -v -keystore ./bin/keystore -alias python -keyalg RSA -keysize 2048 -validity 12000
fi

View file

@ -1,8 +0,0 @@
#!/bin/bash
set -eux
rm -rf tmp
python3 -m pythonforandroid.toolchain clean_dists
python3 -m pythonforandroid.toolchain clean_builds
rm -f *.apk
rm -rf PySolFC-Cardsets--Minimal-2.2.0

View file

@ -1,13 +0,0 @@
#!/bin/bash
set -e
rm -rf tmp
rm -f *.apk
rm -f *.bz2
rm -f *.zip
rm -rf PySolFC-Cardsets-2.0
rm -rf ~/.local/share/python-for-android/packages
rm -rf ~/.local/share/python-for-android/build
rm -rf ~/.local/share/python-for-android/dists
python3 -m pip uninstall python-for-android -y
exit 0

View file

@ -1,36 +0,0 @@
# Common constants for various scripts in this directory.
version=$(PYTHONPATH=.. python3 -c \
'from pysollib.settings import VERSION; print(VERSION)')
tmpdir=${HOME}/.cache/tmp-for-p4a/pysolfc/src
cardsets_dir='PySolFC-Cardsets--Minimal-2.2.0'
cardsets_file="${cardsets_dir}.tar.xz"
p4aver="2019.10.6"
ndkver="r19c"
sdkdir="${HOME}/.cache/sdk-for-p4a/sdk"
ndkdir="${HOME}/.cache/sdk-for-p4a/android-ndk-${ndkver}"
pkgdir="${HOME}/.local/share/python-for-android/packages"
# gradle may need this.
export TERM="xterm"
p4a_options="\
--sdk-dir ${sdkdir} \
--ndk-dir ${ndkdir} \
--dist-name pysolfc \
--name PySolFC \
--package org.lufebe16.pysolfc \
--version ${version} \
--bootstrap sdl2 \
--requirements python3,attrs,configobj,kivy,pysol-cards,random2,six \
--private ${tmpdir} \
--orientation sensor \
--icon ${tmpdir}/data/images/icons/48x48/pysol.png \
--presplash ${tmpdir}/data/images/logo-with-margin-1024.png \
--copy-libs \
--add-jar ${tmpdir}/support-v4-24.1.1.aar \
--color always"

View file

@ -1,11 +0,0 @@
#!/bin/bash
set -eux
. mkp4a.common
new_options=${p4a_options}
new_options=${new_options/PySolFC/PySolFCdbg}
new_options=${new_options/org.lufebe16.pysolfc/org.lufebe16.pysolfc.dbg}
python3 -m pythonforandroid.toolchain apk \
${new_options}

View file

@ -1,71 +0,0 @@
#!/bin/bash
set -eux
. mkp4a.common
# NOTE: $1 will be set with fdroid builds only.
echo '### prepare sdk'
if [[ $# == 0 ]]
then
./initsupport
./initsdk
fi
echo '### install p4a'
if [[ $# == 0 ]]
then
if not python3 -m pip install -q --user "python-for-android==${p4aver}"
then
echo "obviously inside a virtualenv, so omit --user"
if python3 -m pip install -q "python-for-android==${p4aver}"
then
echo "done"
fi
else
echo "done"
fi
fi
echo '### prepare source'
(cd .. && make rules && make all_games_html && make mo)
mkdir -p ${tmpdir}
rm -rf ${tmpdir}
cp -a .. ${tmpdir}
rm -rf ${tmpdir}/android
rm -rf ${tmpdir}/src
# remove useless load from the app
rm -rf ${tmpdir}/.git
rm -rf ${tmpdir}/.gitignore
rm -rf ${tmpdir}/Screenshots
rm -rf ${tmpdir}/build
rm -rf ${tmpdir}/contrib
rm -rf ${tmpdir}/dist
rm -rf ${tmpdir}/runtests.pl
rm -rf ${tmpdir}/tests
rm -rf ${tmpdir}/Brewfile
rm -rf ${tmpdir}/.appveyor.yml
rm -rf ${tmpdir}/.perltidyrc
rm -rf ${tmpdir}/.travis.yml
rm -rf ${tmpdir}/setup.py
rm -rf ${tmpdir}/setup_osx.py
rm -rf ${tmpdir}/setup.cfg
cp -a ${pkgdir}/supportlib/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
echo '### prepare cardsets'
./mkcards
cp -a ${cardsets_dir}/* ${tmpdir}/data
echo '### end init'

View file

@ -1,30 +0,0 @@
#!/bin/bash
# package preload helper for fdroid build.
set -eux
if [[ $# < 3 ]]
then
exit 1
fi
packagebase=${HOME}'/.local/share/python-for-android/packages'
packagedir=${packagebase}/$1
packageurl=$2
packagename=$3
packagemark='.mark-'${packagename}
if [[ $# == 4 ]]
then
packagemark='.mark'$4
fi
mkdir -p ${packagedir}
cd ${packagedir}
if [ ! -f ${packagemark} ]
then
wget -nv ${packageurl}/${packagename}
touch ${packagemark}
fi

View file

@ -1,43 +0,0 @@
#!/bin/bash
set -e
. mkp4a.common
pass1=""
pass2=""
keyalias="python"
keystore="${PWD}/bin/keystore"
if [ $1 ]; then
pass1=$1
pass2=$1
else
echo "usage: ./mkp4a.release <keystore-password> [<keyalias-password>] [<keyalias>] [<keystore-path>]"
echo " (use ./mkkeystore to create one in default location)"
exit
fi
if [ $2 ]; then
pass2=$2
fi
if [ $3 ]; then
keyalias=$3
fi
if [ $4 ]; then
keystore=$4
fi
export P4A_RELEASE_KEYSTORE="$keystore"
export P4A_RELEASE_KEYSTORE_PASSWD="$pass1"
export P4A_RELEASE_KEYALIAS_PASSWD="$pass2"
export P4A_RELEASE_KEYALIAS="$keyalias"
python3 -m pythonforandroid.toolchain apk \
${p4a_options} \
--release \
--sign
# keystore options (instead environment vars):
#
# keystore: --keystore <file>
# key alias --signkey <keyalias>
# keystore passwd --keystorepw <pass1>
# key passwd --signkeypw <pass2>

View file

@ -1,29 +0,0 @@
#!/bin/bash
set -eux
. mkp4a.common
# NOTE: $1 and $2 (sdk and ndk) used with fdroid build only.
if [[ $# == 2 ]]
then
sdkdir=$1
ndkdir=$2
fi
python3 -m pythonforandroid.toolchain apk \
${p4a_options} \
--sdk-dir ${sdkdir} \
--ndk-dir ${ndkdir} \
--release
# python3 -m pythonforandroid.toolchain apk
# ...
# --release #1
# --sign #2
# ...
#
# ad 1,2:
# ohne: -> debug version
# 1: -> release unsigned
# 1 und 2: -> release version.

View file

@ -1,33 +0,0 @@
#!/usr/bin/env python3
# ---------------------------------------------------------------------------
#
# PySol -- a Python Solitaire game
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.
# If not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# ---------------------------------------------------------------------------
# import pychecker.checker
# Starter for kivy/android using buildozer: Needs an explizitly
# named main.py as startpoint.
if True:
import sys
sys.path.insert(0, '..')
if True:
from pysollib.settings import VERSION
print(VERSION)

View file

@ -28,6 +28,7 @@ echo "" > ${tmpdir}/data/images/cards/bottoms/trumps-only/.keep
echo '### prepare cardsets' echo '### prepare cardsets'
./mkcards ./mkcards
./resize4k ${tmpdir}/data/tiles
cp -a cardsets/* ${tmpdir}/data cp -a cardsets/* ${tmpdir}/data

View file

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
set -eux #set -eux
#loadmode="forge" #loadmode="forge"
loadmode="" loadmode=""
@ -58,16 +58,22 @@ else
done done
rm repo -rf rm repo -rf
echo '### processing cardsets' echo '### processing cardsets'
../../scripts/cardconv gif png ../../scripts/cardconv gif png
for i in cardset-*-png; do for i in cardset-*-png; do
rm -rf `basename $i -png` rm -rf `basename $i -png`
done done
popd popd
fi fi
ln -s ${cardsets_dir} cardsets ln -s ${cardsets_dir} cardsets
fi fi
pushd cardsets
for i in cardset-*; do
../resizecards $i
done
popd
echo '### end cardsets' echo '### end cardsets'

37
buildozer/resize4k Executable file
View file

@ -0,0 +1,37 @@
#!/usr/bin/bash
location='.'
if [ $1 ]
then
location=$1
fi
pushd $location
dir='save-aspect-4k'
if [ -d $dir ]
then
pushd 'save-aspect-4k'
for f in *.jpg
do
echo $f
convert $f -resize 1920x1920 -quality 65 temp_$f
mv -f temp_$f $f
done
popd
fi
dir='stretch-4k'
if [ -d $dir ]
then
pushd 'stretch-4k'
for f in *.jpg
do
echo $f
convert $f -resize 1920x1920 -quality 65 temp_$f
mv -f temp_$f $f
done
popd
fi
popd

110
buildozer/resizecards Executable file
View file

@ -0,0 +1,110 @@
#!/usr/bin/env python3
# -*- mode: python; coding: utf-8; -*-
import sys
import os
import math
carddir = ""
filename = ""
maxw = 120
maxh = 180
# arguments:
# 1: cardset directory
# 2: maximum card width
# 3: maximum card height
if len(sys.argv) < 2:
exit (1)
if len(sys.argv) > 1:
carddir = sys.argv[1]
filename = sys.argv[1]+"/config.txt"
if len(sys.argv) > 2:
maxw = int(sys.argv[2])
if len(sys.argv) > 3:
maxh = int(sys.argv[3])
#print (filename)
#print (carddir)
#print (maxw,"x",maxh)
# 1: read the config file line by line and extract x,y, xoffset, yoffset.
lines_list = None
with open(filename, "rt") as f:
lines_list = f.readlines()
lines_list = [line.strip() for line in lines_list]
if not lines_list[0].startswith("PySol"):
exit (1)
#print (lines_list)
cardw, cardh, cardd = (int(x) for x in lines_list[2].split())
xoffs, yoffs, sxoffs, syoffs = (int(x) for x in lines_list[3].split())
#print (cardw,cardh)
#print (xoffs,yoffs)
# 2: calculate scale factor.
scale = maxw / cardw
scaleh = maxh / cardh
if scaleh < scale:
scale = scaleh
#print (scale)
if scale >= 1.0:
exit (0)
# 3: convert all images to (width)x(height) with imagemagick if needed.
def img_size(f):
stream = os.popen('identify '+f)
info = stream.read().split()
dims = info[2].split('x')
w = int(dims[0])
h = int(dims[1])
return (w,h)
cardw = int(math.floor(cardw*scale))
cardh = int(math.floor(cardh*scale))
xoffs = int(math.ceil(xoffs*scale))
yoffs = int(math.ceil(yoffs*scale))
#print (cardw,cardh)
#print (xoffs,yoffs)
for fn in os.listdir(path=carddir):
file = carddir+'/'+fn
fileo = carddir+'/conv-'+fn
if fn.endswith('.png') and not fn.startswith('shadow'):
cmd = "convert "+file+" -resize "+str(cardw)+"x"+str(cardh)+" "+fileo
cmd2 = "mv -f "+fileo+" "+file
#print (cmd)
os.system(cmd)
os.system(cmd2)
if fn.endswith('.png') and fn.startswith('shadow'):
w,h = img_size(file)
if w>h:
w = int(w*scale)
else:
h = int(h*scale)
cmd = "convert "+file+" -resize '"+str(w)+"x"+str(h)+"!' "+fileo
cmd2 = "mv -f "+fileo+" "+file
#print (cmd)
os.system(cmd)
os.system(cmd2)
# 4: rewrite the config file.
print ('rescaled by',scale,':',carddir)
lines_list[2] = str(cardw)+" "+str(cardh)+" "+str(cardd)
lines_list[3] = str(xoffs)+" "+str(yoffs)+" "+str(sxoffs)+" "+str(syoffs)
#print (lines_list)
with open(carddir+"/config.txt", "w") as f:
for l in lines_list:
f.write(l+"\n")

View file

@ -1,11 +1,13 @@
Android specific: Android specific:
- Temporary screen orientation lock added. Long tap (2.5 seconds) to the - Temporary screen orientation lock added. Long tap (3 seconds) to the
playground locks screen rotation. playground locks screen rotation, pause unlocks.
- Toolbar: configuration of displayed toolbar buttons added to options menu. - Toolbar: configuration of displayed toolbar buttons added to the options menu.
- Toolbar: dynamic updates on Toolbar and Options settings. - Toolbar: dynamic updates on Toolbar and Options settings.
- Toolbar buttons for 'new deal' and 'restart' have now display a - Toolbar buttons for 'new deal' and 'restart' now display a
toast instead of executing immediatley. Tap to the toast accept. toast. Tap to it to accept.
- Implementation of full picture hint for the new puzzle type games. - Implementation of full picture hint for the new puzzle type games.
- Background images from the save-aspect folder now are preserving
correct aspect ratio (bug fix).
Main version: Main version:
- consult NEWS.asscidoc or html-src/news.html on - consult NEWS.asscidoc or html-src/news.html on
github for more change informations. github for more change informations.

View file

@ -38,6 +38,7 @@ from pysollib.kivy.LApp import LScrollView
from pysollib.kivy.LApp import LTopLevel from pysollib.kivy.LApp import LTopLevel
from pysollib.kivy.LApp import LTreeNode from pysollib.kivy.LApp import LTreeNode
from pysollib.kivy.LApp import LTreeRoot from pysollib.kivy.LApp import LTreeRoot
from pysollib.kivy.androidrot import AndroidScreenRotation
from pysollib.kivy.findcarddialog import destroy_find_card_dialog from pysollib.kivy.findcarddialog import destroy_find_card_dialog
from pysollib.kivy.fullpicturedialog import destroy_full_picture_dialog from pysollib.kivy.fullpicturedialog import destroy_full_picture_dialog
from pysollib.kivy.selectcardset import SelectCardsetDialogWithPreview from pysollib.kivy.selectcardset import SelectCardsetDialogWithPreview
@ -55,7 +56,6 @@ from pysollib.pysoltk import connect_game_full_picture_dialog
from pysollib.settings import SELECT_GAME_MENU from pysollib.settings import SELECT_GAME_MENU
from pysollib.settings import TITLE from pysollib.settings import TITLE
# ************************************************************************ # ************************************************************************
# * tk emuls: # * tk emuls:
# ************************************************************************ # ************************************************************************
@ -2031,6 +2031,7 @@ class PysolMenubarTk:
return return
self.game.doPause() self.game.doPause()
self.tkopt.pause.set(self.game.pause) self.tkopt.pause.set(self.game.pause)
AndroidScreenRotation.unlock()
def mOptLanguage(self, *args): def mOptLanguage(self, *args):
if self._cancelDrag(break_pause=False): if self._cancelDrag(break_pause=False):

View file

@ -652,6 +652,10 @@ class MfxCanvas(Widget):
hh = r.tex_coords[5] - v hh = r.tex_coords[5] - v
w = ww * stepsx w = ww * stepsx
h = hh * stepsy h = hh * stepsy
# move reference point to top left:
v = stepsy - math.floor(stepsy)
r.tex_coords = ( u, v, u + w, v, u + w, v + h, u, v + h ) # noqa r.tex_coords = ( u, v, u + w, v, u + w, v + h, u, v + h ) # noqa
def setBackgroundImage(self, event=None): def setBackgroundImage(self, event=None):