diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-04-13 23:53:48 +0200 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-04-14 03:12:14 +0200 |
commit | db091bfd1db36ab66340ccad2eb7b6393a0aa3da (patch) | |
tree | 5a70412afcb4d32086effffe84d7de3161790f46 | |
parent | e27870b137aeab108816f4eb80ddaea1e639c3fb (diff) | |
download | android-jetpack-compose-redo-db091bfd1db36ab66340ccad2eb7b6393a0aa3da.tar.gz android-jetpack-compose-redo-db091bfd1db36ab66340ccad2eb7b6393a0aa3da.tar.xz android-jetpack-compose-redo-db091bfd1db36ab66340ccad2eb7b6393a0aa3da.zip |
Basic kotlin java application working
-rw-r--r-- | .gitignore | 10 | ||||
-rw-r--r-- | .vars.rc.do | 57 | ||||
-rw-r--r-- | AndroidManifest.xml | 14 | ||||
-rw-r--r-- | MainActivity.kt | 25 | ||||
-rw-r--r-- | R.java.do | 13 | ||||
-rw-r--r-- | all.do | 1 | ||||
-rwxr-xr-x | clean | 4 | ||||
-rw-r--r-- | default.apk.do | 21 | ||||
-rw-r--r-- | default.flat.do | 14 | ||||
-rw-r--r-- | default.jar.do | 22 | ||||
-rw-r--r-- | default.signed.apk.do | 10 | ||||
-rw-r--r-- | kotlin.dex.do | 11 | ||||
-rw-r--r-- | paste.dex.do | 12 | ||||
-rw-r--r-- | res/layout/activity_main.xml | 42 | ||||
-rw-r--r-- | res/values/strings.xml | 9 | ||||
-rw-r--r-- | res/values/styles.xml | 6 | ||||
-rw-r--r-- | resources.rc | 1 |
17 files changed, 272 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fbc55e6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +*.aar +*.apk +*.dex +*.flat +*.idsig +*.jar +.redo/ +.vars.rc +R.java +config.rc diff --git a/.vars.rc.do b/.vars.rc.do new file mode 100644 index 0000000..f9ccc80 --- /dev/null +++ b/.vars.rc.do @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +set -e + +unset ANDROID_SDK ANDROID_VER BUILD_TOOLS BUILD_TOOLS_VER JAVAC KEYSTORE KEYSTORE_ARGS KEYSTORE_PASS KOTLIN KOTLINC PLATFORM verbose + +ANDROID_VER=android-33-ext5 +BUILD_TOOLS_VER=33.0.2 +APKSIGNER_SIGN_ARGS=() + +if [ -e config.rc ]; then + redo-ifchange config.rc + . ./config.rc +else + redo-ifcreate config.rc +fi + +if [[ ! ( $BUILD_TOOLS || $PLATFORM ) && ! $ANDROID_SDK ]]; then + cat <<-"EOF" >&2 + $BUILD_TOOLS or $PLATFORM unset without setting $ANDROID_SDK. + Either set both $BUILD_TOOLS and $PLATFORM or set $ANDROID_SDK. + EOF + exit 1 +fi + +BUILD_TOOLS=${BUILD_TOOLS-$ANDROID_SDK/build-tools/$BUILD_TOOLS_VER} +PLATFORM=${PLATFORM-$ANDROID_SDK/platforms/$ANDROID_VER} +KOTLIN=${KOTLIN-/usr/share/kotlin} + +KEYSTORE=${KEYSTORE-$HOME/.android/debug.keystore} +KEYSTORE_PASS=${KEYSTORE_PASS-pass:android} + +check() { + what=$1 + shift + for p do + if command -v "$p" >/dev/null 2>&1; then + command -v "$p" + return + fi + done + echo "$what not set or found" >&2 + return 1 +} + +JAVAC=$(check '$JAVAC or javac' "$JAVAC" javac) || exit +KOTLINC=$(check '$KOTLINC or kotlinc' "$KOTLINC" kotlinc) || exit + +{ + printf "# generated by %s\n" "$0" + declare -p APKSIGNER_SIGN_ARGS BUILD_TOOLS JAVAC KEYSTORE KEYSTORE_PASS KOTLIN KOTLINC PLATFORM +} >"$3" + +if [[ $verbose ]]; then + echo "# Configuration regenerated:" >&2 + cat "$3" >&2 +fi +# vim:ft=bash diff --git a/AndroidManifest.xml b/AndroidManifest.xml new file mode 100644 index 0000000..7f77dd9 --- /dev/null +++ b/AndroidManifest.xml @@ -0,0 +1,14 @@ +<?xml version='1.0'?> +<manifest xmlns:android='http://schemas.android.com/apk/res/android' xmlns:app='http://schemas.android.com/apk/res-auto' xmlns:tools='http://schemas.android.com/tools' package='ski.kramkow.paste' android:versionCode='0' android:versionName='0'> + <uses-sdk android:minSdkVersion="33" android:targetSdkVersion="33" /> + <uses-permission android:name="android.permission.INTERNET" /> + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> + <application android:label='@string/app_name' android:theme='@style/app_style'> + <activity android:name='.MainActivity' android:exported='true'> + <intent-filter> + <category android:name='android.intent.category.LAUNCHER'/> + <action android:name='android.intent.action.MAIN'/> + </intent-filter> + </activity> + </application> +</manifest> diff --git a/MainActivity.kt b/MainActivity.kt new file mode 100644 index 0000000..b11b0fc --- /dev/null +++ b/MainActivity.kt @@ -0,0 +1,25 @@ +package ski.kramkow.paste + +import android.app.Activity +import android.os.Bundle +//import java.net.HttpURLConnection; +//import java.net.URL; +//import java.io.OutputStream; + +class MainActivity : Activity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + //URL url = new URL("http://192.168.1.32:8000"); + //HttpURLConnection con = (HttpURLConnection)url.openConnection(); + //con.setRequestMethod("POST"); + //con.setRequestProperty("Content-Type", "text/plain"); + //con.setDoOutput(true); + //String data = "This is a test\n"; + //try(OutputStream os = con.getOutputStream()) { + //byte[] block = data.getBytes("utf-8"); + //os.write(block, 0, block.length); + //} + } +} diff --git a/R.java.do b/R.java.do new file mode 100644 index 0000000..30389fe --- /dev/null +++ b/R.java.do @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -e +redo-ifchange .vars.rc resources.rc +. ./.vars.rc +. ./resources.rc +android="$PLATFORM/android.jar" +manifest=AndroidManifest.xml +redo-ifchange "$BUILD_TOOLS/aapt2" "$android" "$manifest" "${resources[@]}" +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT +"$BUILD_TOOLS/aapt2" link --java "$tmp" --manifest "$manifest" -o /dev/null -I "$android" "${resources[@]}" +find "$tmp" -name "R.java" -exec mv {} "$3" \; -quit +# vim:ft=bash @@ -0,0 +1 @@ +redo-ifchange paste.signed.apk @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +rm -f .vars.rc R.java +find . \( -name '*.apk' -o -name '*.dex' -o -name '*.flat' -o -name '*.idsig' -o -name '*.jar' -o -name '*.aar' \) -delete diff --git a/default.apk.do b/default.apk.do new file mode 100644 index 0000000..e56df77 --- /dev/null +++ b/default.apk.do @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -e + +redo-ifchange .vars.rc resources.rc +. ./.vars.rc +. ./resources.rc + +src=${1%.apk}.dex + +android="$PLATFORM/android.jar" +manifest=AndroidManifest.xml + +redo-ifchange "$BUILD_TOOLS/aapt2" "$BUILD_TOOLS/zipalign" "${resources[@]}" "$src" "$manifest" "$android" + +tmp=$(mktemp) +trap 'rm -f "$tmp"' EXIT +"$BUILD_TOOLS/aapt2" link --manifest "$manifest" -o "$tmp" -I "$android" "${resources[@]}" +7z a -tzip "$tmp" "$src" +7z rn -tzip "$tmp" "$src" classes.dex +"$BUILD_TOOLS/zipalign" -f 4 "$tmp" "$3" +# vim:ft=bash diff --git a/default.flat.do b/default.flat.do new file mode 100644 index 0000000..e8b2558 --- /dev/null +++ b/default.flat.do @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -e +src=${1%.flat} +dir=${src%%_*} +file=${src#*_} +src=res/$dir/$file +redo-ifchange .vars.rc +. ./.vars.rc +redo-ifchange "$BUILD_TOOLS/aapt2" "$src" +tmp=$(mktemp) +trap 'rm -f "$tmp"' EXIT +"$BUILD_TOOLS/aapt2" compile -o "$tmp" "$src" +unzip -p "$tmp" >"$3" +# vim:ft=bash diff --git a/default.jar.do b/default.jar.do new file mode 100644 index 0000000..a324074 --- /dev/null +++ b/default.jar.do @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -e +src=${1%.jar} +redo-ifchange .vars.rc +. ./.vars.rc +classpath=($PLATFORM/android.jar) +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT +if [[ $1 != R.jar ]]; then classpath+=(R.jar); fi +for e in "${classpath[@]}"; do redo-ifchange "$e"; done +IFS=:; classpath=${classpath[*]} +if [[ -f "$src.kt" ]]; then + src="$src.kt" + redo-ifchange "$KOTLINC" "$src" + "$KOTLINC" -jvm-target 1.8 -cp "$classpath" -d "$tmp" "$src" +else + src="$src.java" + redo-ifchange "$JAVAC" "$src" + "$JAVAC" -source 11 -target 11 -classpath "$classpath" -d "$tmp" "$src" +fi +jar --create --no-compress --date=2000-01-01T00:00:00Z --file "$3" -C "$tmp" . +# vim:ft=bash diff --git a/default.signed.apk.do b/default.signed.apk.do new file mode 100644 index 0000000..c2c5d48 --- /dev/null +++ b/default.signed.apk.do @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -e +src=${1%.signed.apk}.apk +redo-ifchange .vars.rc +. ./.vars.rc +if [[ $KEYSTORE_PASS =~ ^file: ]]; then redo-ifchange "${KEYSTORE_PASS#file:}"; fi +redo-ifchange "$BUILD_TOOLS/apksigner" "$KEYSTORE" "$src" +"$BUILD_TOOLS/apksigner" sign --ks "$KEYSTORE" --ks-pass "$KEYSTORE_PASS" "${APKSIGNER_SIGN_ARGS[@]}" --out "$3" "$src" +rm "$3.idsig" +# vim:ft=bash diff --git a/kotlin.dex.do b/kotlin.dex.do new file mode 100644 index 0000000..5cd3eef --- /dev/null +++ b/kotlin.dex.do @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -e +redo-ifchange .vars.rc +. ./.vars.rc +src="$KOTLIN/lib/kotlin-stdlib.jar" +redo-ifchange "$BUILD_TOOLS/d8" "$PLATFORM/android.jar" "$src" +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT +"$BUILD_TOOLS/d8" --intermediate "$src" --classpath "$PLATFORM/android.jar" --output "$tmp" +mv "$tmp/classes.dex" "$3" +# vim:ft=bash diff --git a/paste.dex.do b/paste.dex.do new file mode 100644 index 0000000..53ec7c2 --- /dev/null +++ b/paste.dex.do @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -e +jars=(R.jar MainActivity.jar) +redo-ifchange .vars.rc +. ./.vars.rc +android="$PLATFORM/android.jar" +redo-ifchange "$BUILD_TOOLS/d8" "$android" kotlin.dex "${jars[@]}" +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT +"$BUILD_TOOLS/d8" --classpath "$android" --output "$tmp" kotlin.dex "${jars[@]}" +mv "$tmp/classes.dex" "$3" +# vim:ft=bash diff --git a/res/layout/activity_main.xml b/res/layout/activity_main.xml new file mode 100644 index 0000000..0807716 --- /dev/null +++ b/res/layout/activity_main.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:paddingLeft="16dp" + android:paddingRight="16dp" + android:orientation="vertical" +> + <RadioGroup + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" + > + <RadioButton + android:id="@+id/radio_post" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/POST" + /> + <RadioButton + android:id="@+id/radio_put" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/PUT" + /> + </RadioGroup> + <!--<Button--> + <!--android:id="@+id/button_choose_file"--> + <!--android:layout_width="match_parent"--> + <!--android:layout_height="wrap_content"--> + <!--android:text="@string/submit"--> + <!--/>--> + <Button + android:id="@+id/button_submit" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/submit" + /> +</LinearLayout> diff --git a/res/values/strings.xml b/res/values/strings.xml new file mode 100644 index 0000000..c215c34 --- /dev/null +++ b/res/values/strings.xml @@ -0,0 +1,9 @@ +<resources> + <string name="app_name">Paste</string> + <string name="menu_settings">Settings</string> + <string name="title_activity_main">MainActivity</string> + <string name="content_hint">Content</string> + <string name="submit">Submit</string> + <string name="PUT">PUT</string> + <string name="POST">POST</string> +</resources> diff --git a/res/values/styles.xml b/res/values/styles.xml new file mode 100644 index 0000000..96fe7ee --- /dev/null +++ b/res/values/styles.xml @@ -0,0 +1,6 @@ +<resources> + <style name="app_style" parent="@android:style/Theme.Light"> + <item name="android:windowActionBar">true</item> + <item name="android:windowNoTitle">true</item> + </style> +</resources> diff --git a/resources.rc b/resources.rc new file mode 100644 index 0000000..de9db9e --- /dev/null +++ b/resources.rc @@ -0,0 +1 @@ +resources=(values_strings.xml.flat values_styles.xml.flat layout_activity_main.xml.flat) |