Skip to content

Commit

Permalink
Call JNI, fullscreen, show keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
desttinghim authored and ikskuh committed Oct 12, 2022
1 parent a0b0ca2 commit 84aa31a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 18 deletions.
1 change: 1 addition & 0 deletions devshell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ devshell.mkShell {
android-sdk
gradle
jdk11
zig
];
}
30 changes: 15 additions & 15 deletions example/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ pub const AndroidApp = struct {
/// It should create a background thread that processes the events and runs until
/// the application gets destroyed.
pub fn start(self: *Self) !void {
// This code somehow crashes yet. Needs more investigations
// {
// var jni = JNI.init(self.activity);
// defer jni.deinit();

// // Must be called from main thread…
// _ = jni.AndroidMakeFullscreen();
// }
self.thread = try std.Thread.spawn(.{}, mainLoop, .{self});
}

Expand Down Expand Up @@ -255,18 +247,19 @@ pub const AndroidApp = struct {
defer jni.deinit();

// Show/Hide keyboard
// _ = jni.AndroidDisplayKeyboard(true);
_ = jni.AndroidDisplayKeyboard(true);

// this allows you to send the app in the background
// const success = jni.AndroidSendToBack(true);
// std.app_log.debug(.app, "SendToBack() = {}\n", .{success});
// _ = success;
// std.log.scoped(.input).debug("SendToBack() = {}\n", .{success});

// This is a demo on how to request permissions:
// if (event_type == .AMOTION_EVENT_ACTION_UP) {
// if (!JNI.AndroidHasPermissions(self.activity, "android.permission.RECORD_AUDIO")) {
// JNI.AndroidRequestAppPermissions(self.activity, "android.permission.RECORD_AUDIO");
// }
// }
if (event_type == .AMOTION_EVENT_ACTION_UP) {
if (!JNI.AndroidHasPermissions(&jni, "android.permission.RECORD_AUDIO")) {
JNI.AndroidRequestAppPermissions(&jni, "android.permission.RECORD_AUDIO");
}
}
}

std.log.scoped(.input).debug(
Expand Down Expand Up @@ -347,6 +340,13 @@ pub const AndroidApp = struct {
}

fn mainLoop(self: *Self) !void {
// This code somehow crashes yet. Needs more investigations
var jni = JNI.init(self.activity);
defer jni.deinit();

// Must be called from main thread…
_ = jni.AndroidMakeFullscreen();

var loop: usize = 0;
app_log.info("mainLoop() started\n", .{});

Expand Down
53 changes: 52 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
devshell.url = "github:numtide/devshell";
flake-utils.url = "github:numtide/flake-utils";
android.url = "github:tadfisher/android-nixpkgs";
zig.url = "github:mitchellh/zig-overlay";
};

outputs = { self, nixpkgs, devshell, flake-utils, android }:
outputs = { self, nixpkgs, devshell, flake-utils, android, zig }:
{
overlay = final: prev: {
inherit (self.packages.${final.system}) android-sdk android-studio;
inherit (self.packages.${final.system}) android-sdk android-studio zig;
};
}
//
Expand All @@ -28,6 +29,7 @@
in
{
packages = {
zig = zig.packages.${system}.master;
android-sdk = android.sdk.${system} (sdkPkgs: with sdkPkgs; [
# Useful packages for building and testing.
build-tools-30-0-2
Expand Down

0 comments on commit 84aa31a

Please sign in to comment.