Skip to content

Commit

Permalink
Complete support for legacy multiple import
Browse files Browse the repository at this point in the history
  • Loading branch information
petabyt committed Jan 20, 2024
1 parent b8de944 commit a6d7507
Show file tree
Hide file tree
Showing 22 changed files with 270 additions and 4,194 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "lib/libuifw"]
path = lib/libuifw
url = https://github.com/petabyt/libuifw.git
[submodule "lib/camlib"]
path = lib/camlib
url = https://github.com/petabyt/camlib
Expand Down
1 change: 1 addition & 0 deletions .idea/vcs.xml

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

4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies {
implementation 'androidx.recyclerview:recyclerview:1.1.0'
}

/*
// https://github.com/Dushistov/flapigen-rs/blob/master/android-example/app/build.gradle
def rustBasePath = "../rust/"
def archTriplets = [
Expand All @@ -59,4 +60,5 @@ archTriplets.each { arch, target ->
rust.dependsOn "cargo-build-${arch}"
}
//tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn "rust" }
tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn "rust" }
*/
2 changes: 1 addition & 1 deletion app/src/main/java/dev/danielc/fujiapp/LibU.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ public static String readFileFromAssets(Context ctx, String file) throws Excepti
throw e;
}
}
}
}
65 changes: 53 additions & 12 deletions app/src/main/java/dev/danielc/fujiapp/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
Expand All @@ -17,9 +19,10 @@
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import java.io.File;

import camlib.SimpleSocket;
import camlib.WiFiComm;
import libui.LibU;
import libui.LibUI;

public class MainActivity extends AppCompatActivity {
Expand Down Expand Up @@ -54,16 +57,10 @@ public void onClick(View v) {
}
});

findViewById(R.id.scripts).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Backend.cFujiScriptsScreen(MainActivity.this);
}
});

((TextView)findViewById(R.id.bottomText)).setText(getString(R.string.url) + "\n" +
"Download location: " + Backend.getDownloads() + "\n" +
getString(R.string.motd_thing));
TextView bottomText = ((TextView)findViewById(R.id.bottomText));
bottomText.append(getString(R.string.url) + "\n");
bottomText.append("Download location: " + Backend.getDownloads() + "\n");
bottomText.append(getString(R.string.motd_thing) + " " + BuildConfig.VERSION_NAME);

findViewById(R.id.test_suite).setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -115,11 +112,55 @@ public void run() {

@Override
public boolean onOptionsItemSelected(MenuItem item) {
return LibUI.handleOptions(item, false);
if (item.getTitle() == "open") {

File[] fileList;
File file = new File(Backend.getDownloads());
if (!file.isDirectory()) {
return super.onOptionsItemSelected(item);
}

fileList = file.listFiles();
String mime = "*/*";
String path = Backend.getDownloads();
if (fileList.length != 0) {
path = fileList[0].getPath();
mime = "image/*";
}

if (Viewer.downloadedFilename != null) {
path = Viewer.downloadedFilename;
mime = "image/*";
}

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(path), mime);
startActivity(intent);
} else if (item.getTitle() == "script") {
Backend.cFujiScriptsScreen(MainActivity.this);
} else {
return LibUI.handleOptions(item, false);
}

return super.onOptionsItemSelected(item);
}

@Override
public void onBackPressed() {
LibUI.handleBack(false);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuItem menuItem = menu.add(Menu.NONE, Menu.NONE, Menu.NONE, "open");
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menuItem.setIcon(R.drawable.baseline_folder_open_24);

menuItem = menu.add(Menu.NONE, Menu.NONE, Menu.NONE, "script");
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menuItem.setIcon(R.drawable.baseline_terminal_24);

return super.onCreateOptionsMenu(menu);
}
}
1 change: 0 additions & 1 deletion app/src/main/java/dev/danielc/fujiapp/Tester.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import androidx.appcompat.app.AppCompatActivity;

import android.content.ClipData;
import android.os.Environment;
import android.util.Log;
import android.content.Intent;
import android.text.Html;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/dev/danielc/fujiapp/Viewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static void createDir(String directoryPath) {
}
}

String downloadedFilename = null;
public static String downloadedFilename = null;

// Must be ran on UI thread
public void writeFile(String filename, byte[] data) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/libui/LibUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class LibUI {

public static Boolean useActionBar = true;

public static void start(AppCompatActivity act) {
public static void start(Activity act) {
ctx = (Context)act;
waitUntilActivityLoaded(act);
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/baseline_folder_open_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M20,6h-8l-2,-2L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,8c0,-1.1 -0.9,-2 -2,-2zM20,18L4,18L4,8h16v10z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/baseline_terminal_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M20,4H4C2.89,4 2,4.9 2,6v12c0,1.1 0.89,2 2,2h16c1.1,0 2,-0.9 2,-2V6C22,4.9 21.11,4 20,4zM20,18H4V8h16V18zM18,17h-6v-2h6V17zM7.5,17l-1.41,-1.41L8.67,13l-2.59,-2.59L7.5,9l4,4L7.5,17z"/>
</vector>
8 changes: 1 addition & 7 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,13 @@
android:layout_height="wrap_content"
android:text="Connect" />

<Button
android:id="@+id/scripts"
style="@style/GreyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Scripts" />

<Button
android:id="@+id/test_suite"
style="@style/GreyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Run test suite"
android:textStyle="italic"
android:visibility="visible" />

<Button
Expand Down
8 changes: 7 additions & 1 deletion lib/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include $(CLEAR_VARS)
CAMLIB_CORE := $(addprefix camlib/src/,transport.c bind.c data.c enum_dump.c enums.c canon.c liveview.c no_usb.c operations.c packet.c lib.c ml.c conv.c generic.c)

FUDGE_CORE := main.c jni.c lib.c fuji.c tester.c models.c net.c viewer.c
FUDGE_CORE += libui.c scripts.c camlib.c
FUDGE_CORE += scripts.c camlib.c

LUA_CORE := $(addprefix lua/,lbaselib.c lauxlib.c lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c ltests.c)

Expand All @@ -14,6 +14,12 @@ LOCAL_SRC_FILES := $(FUDGE_CORE) $(CAMLIB_CORE) $(LUA_CORE)
LOCAL_C_INCLUDES += $(LOCAL_PATH) $(LOCAL_PATH)/camlib/src
LOCAL_LDLIBS += -llog

#LIBUIFW := libuifw
LIBUIFW := ../../libuifw

LOCAL_SRC_FILES += $(LIBUIFW)/libui.c
LOCAL_C_INCLUDES += $(LIBUIFW)

#LOCAL_SHARED_LIBRARIES += rust

include $(BUILD_SHARED_LIBRARY)
Expand Down
3 changes: 3 additions & 0 deletions lib/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ void jni_verbose_log(char *str);

void reset_connection();

// lib.c
int libu_write_file(JNIEnv *env, char *path, void *data, size_t length);

#endif
25 changes: 22 additions & 3 deletions lib/fuji.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,26 @@ int fuji_config_image_viewer(struct PtpRuntime *r) {
return 0;
}

int fuji_slow_download_object() {
// ...
return 0;
int fuji_slow_download_object(struct PtpRuntime *r, int handle, uint8_t **buffer, size_t size) {
int of = 0;
const int max = 0x100000;
while (1) {
int rc = ptp_get_partial_object(r, handle, of, max);
if (rc) return rc;

if (of + ptp_get_payload_length(r) >= size) {
size = size + 1 * 1000 * 1000;
(*buffer) = realloc((*buffer), size);
}

memcpy((*buffer) + of, ptp_get_payload(r), ptp_get_payload_length(r));

of += ptp_get_payload_length(r);

if (ptp_get_payload_length(r) != max) {
break;
}
}

return of;
}
2 changes: 2 additions & 0 deletions lib/fuji.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ int fuji_get_events(struct PtpRuntime *r);
int fuji_disable_compression(struct PtpRuntime *r);
int fuji_enable_compression(struct PtpRuntime *r);

int fuji_slow_download_object(struct PtpRuntime *r, int handle, uint8_t **buffer, size_t size);

// Holds runtime info about the camera
struct FujiDeviceKnowledge {
struct FujiCameraInfo *info;
Expand Down
40 changes: 34 additions & 6 deletions lib/lib.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
// Random patch to fix Android studio linking bug (???)
#include <stdio.h>
#include <stddef.h>
extern size_t strlen (const char *);
extern void *memcpy (void *, const void *, size_t);
char *stpcpy (char *dst, const char *src) {
const size_t len = strlen (src);
return (char *) memcpy (dst, src, len + 1) + len;
#include <string.h>
#include <jni.h>
#include <android/log.h>

#define LIBU(ret, name) JNIEXPORT ret JNICALL Java_libui_LibU_##name

int libu_write_file(JNIEnv *env, char *path, void *data, size_t length) {
jclass class = (*env)->FindClass(env, "libui/LibU");

jmethodID method = (*env)->GetStaticMethodID(env, class, "writeFile", "(Ljava/lang/String;[B)V");

jbyteArray jdata = (*env)->NewByteArray(env, length);
(*env)->SetByteArrayRegion(
env, jdata,
0, length, (const jbyte *)(data)
);

jstring jpath = (*env)->NewStringUTF(env, path);

(*env)->CallStaticVoidMethod(env, class, method,
jpath, jdata
);

(*env)->DeleteLocalRef(env, jdata);
(*env)->DeleteLocalRef(env, jpath);

return 0;
}

// Added in POSIX 2008, not C standard
char *stpcpy(char *dst, const char *src) {
const size_t len = strlen(src);
return (char *)memcpy (dst, src, len + 1) + len;
}
Loading

0 comments on commit a6d7507

Please sign in to comment.