Skip to content

Adds an option to allow add resources to Android res/ directory #2580

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 3 commits 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
61 changes: 60 additions & 1 deletion pythonforandroid/bootstraps/common/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import hashlib
import json
from os.path import (
dirname, join, isfile, realpath,
dirname, join, isfile, isdir, realpath,
relpath, split, exists, basename
)
from os import environ, listdir, makedirs, remove
Expand Down Expand Up @@ -342,10 +342,67 @@ def make_package(args):
res_dir = "src/main/res"
default_icon = 'templates/kivy-icon.png'
default_presplash = 'templates/kivy-presplash.jpg'

# Clean res directory
shutil.rmtree(res_dir)

# Create default p4a res dirs
default_res_dirs = [
"drawable", "drawable-mdpi", "drawable-hdpi", "drawable-xhdpi",
"drawable-xxhdpi", "layout", "mipmap", "mipmap-anydpi-v26", "values",
"xml"
]
for dir in default_res_dirs:
ensure_dir(join(res_dir, dir))

# Copy default xml layout files
if get_bootstrap_name() == "sdl2":
default_layout_xmls = [
"chooser_item.xml", "main.xml", "project_chooser.xml",
"project_empty.xml"
]
for xml in default_layout_xmls:
shutil.copy(
join("templates", xml),
join(res_dir, "layout", xml)
)

if args.res:
target_res_dirs = [
filename for filename in listdir(res_dir)
if isdir(join(res_dir, filename))
]
source_res_dirs = [
filename for filename in listdir(args.res)
if isdir(join(args.res, filename))
]
for directory in source_res_dirs:
if directory not in target_res_dirs:
ensure_dir(join(res_dir, directory))
source_dir = join(args.res, directory)
target_dir = join(res_dir, directory)

source_dir_files = [
filename for filename in listdir(source_dir)
if isfile(join(source_dir, filename))
]
for filename in source_dir_files:
shutil.copy(
join(source_dir, filename),
join(target_dir, filename)
)

# Removes :Zone.Identifier files, for WSL users.
# Issue: https://github.com/microsoft/WSL/issues/7456
for file in listdir(join(res_dir, directory)):
if file.endswith(':Zone.Identifier'):
remove(join(res_dir, directory, file))

shutil.copy(
args.icon or default_icon,
join(res_dir, 'mipmap/icon.png')
)

if args.icon_fg and args.icon_bg:
shutil.copy(args.icon_fg, join(res_dir, 'mipmap/icon_foreground.png'))
shutil.copy(args.icon_bg, join(res_dir, 'mipmap/icon_background.png'))
Expand Down Expand Up @@ -690,6 +747,8 @@ def parse_args_and_make_package(args=None):
action="append", default=[],
metavar="/path/to/source:dest",
help='Put this in the assets folder at assets/dest')
ap.add_argument('--add-res', dest='res',
help=('Copy/overwrite directories and its files in the android res directory'))
ap.add_argument('--icon', dest='icon',
help=('A png file to use as the icon for '
'the application.'))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:gravity="center"
>

<ImageView
android:id="@+id/icon"
android:layout_width="64sp"
android:layout_height="64sp"
android:scaleType="fitCenter"
android:padding="2sp"
/>

<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/title"
android:textSize="18sp"
android:textColor="#fff"
android:singleLine="true"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:id="@+id/author"
/>

</LinearLayout>
</LinearLayout>
13 changes: 13 additions & 0 deletions pythonforandroid/bootstraps/common/build/templates/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, SDLActivity"
/>
</LinearLayout>

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
>

<TextView
android:text="Please choose a project:"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="4sp"
/>

<ListView
android:id="@+id/projectList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>


</LinearLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
>

<TextView
android:id="@+id/emptyText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="4sp"
/>

</LinearLayout>