Skip to content

Commit

Permalink
Implement object table view, fix exif parser, add downloaded photos s…
Browse files Browse the repository at this point in the history
…creen,

finish off a last bunch of things
  • Loading branch information
petabyt committed Aug 18, 2024
1 parent 59336c1 commit 23d6ae3
Show file tree
Hide file tree
Showing 28 changed files with 678 additions and 458 deletions.
20 changes: 17 additions & 3 deletions app/src/main/java/dev/danielc/common/Camlib.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public PtpErr(int code) {

public static final int PTP_OF_JPEG = 0x3801;

public static final int OPEN_TIMEOUT = 500;
public static final int TIMEOUT = 1000;

// camlib error codes
public static final int PTP_OK = 0;
public static final int PTP_NO_DEVICE = -1;
Expand Down Expand Up @@ -46,4 +43,21 @@ public static JSONObject getObjectInfo(int handle) throws Exception {
if (x == null) return null;
return new JSONObject(x);
}

/// @brief Initialize object service on ptpruntime
public native static void cPtpObjectServiceStart(int[] handles);
public native static JSONObject cPtpObjectServiceGet(int handle);
public native static JSONObject cPtpObjectServiceGetIndex(int index);
public native static JSONObject[] cPtpObjectServiceGetFilled();
public native static int cPtpObjectServiceStep();
public native static void cPtpObjectServiceAddPriority(int handle);

public final static int PTP_SELET_JPEG = 1 << 0;
public final static int PTP_SELET_RAW = 1 << 1;
public final static int PTP_SELET_MOV = 1 << 2;
public final static int PTP_SORT_NEWEST = 1 << 3;
public final static int PTP_SORT_OLDEST = 1 << 4;
public final static int PTP_SORT_LARGEST = 1 << 5;
public final static int PTP_SORT_SMALLEST = 1 << 6;

};
7 changes: 7 additions & 0 deletions app/src/main/java/dev/danielc/common/Exif.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.danielc.common;

public class Exif {
/// @brief returns byte[] to JPEG thumb or NULL
public static native byte[] getThumbnail(String filepath);
public static native String getInformationJSON(String path);
}
4 changes: 2 additions & 2 deletions app/src/main/java/dev/danielc/common/WiFiComm.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ public static long getNetworkHandle() {

NetworkInfo wifiInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (!wifiInfo.isAvailable()) {
Log.d("wifi", "WiFi network not available");
return NOT_AVAILABLE;
} else if (!wifiInfo.isConnected()) {
return NOT_CONNECTED;
}

if (wifiDevice != null) {
Log.d("wifi", "Returning default WiFi");
return wifiDevice.getNetworkHandle();
}

Log.d("wifi", "WiFi network not available");
return NOT_AVAILABLE;
}
}
8 changes: 4 additions & 4 deletions app/src/main/java/dev/danielc/fujiapp/Backend.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ static void continueOpenUSB() {
usb.openConnection();
usb.getInterface();
usb.getEndpoints();

cUSBConnectNative(usb);

cClearKillSwitch();
} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -102,7 +100,8 @@ public static void init() {
public native static int[] cGetObjectHandles();
public native static int cFujiConfigImageGallery();
public native static byte[] cFujiGetThumb(int handle);
public native static int cFujiImportFiles(int[] handles);
/// Run mass gallery photo importer based on transport
public native static int cFujiImportFiles(int[] handles, int filter_mask);

// For tester only
public native static int cFujiTestSuite();
Expand Down Expand Up @@ -139,6 +138,7 @@ public void run() {
if (rc < 0) break;
if (rc == FUJI_D_INVALID_NETWORK || rc == FUJI_D_IO_ERR || rc == FUJI_D_OPEN_DENIED) {
Log.d("discovery", "error: " + rc);
Frontend.discoveryFailed();
break;
}
if (rc == FUJI_D_CANCELED || rc == FUJI_D_GO_PTP) {
Expand Down Expand Up @@ -169,7 +169,7 @@ public static String getDownloads() {
String fujifilm = mainStorage + File.separator + "fudge";
File directory = new File(fujifilm);
if (!directory.exists()) {
directory.mkdirs();
directory.mkdirs();
}
return fujifilm;
}
Expand Down
86 changes: 55 additions & 31 deletions app/src/main/java/dev/danielc/fujiapp/DownloadQueue.java
Original file line number Diff line number Diff line change
@@ -1,52 +1,76 @@
// This really sucks (for now)
package dev.danielc.fujiapp;
import java.util.ArrayList;

import android.view.View;
public class DownloadQueue {
private final ArrayList<Object> requests = new ArrayList<>();

import java.util.ArrayList;
private volatile boolean stopDownloading = false;
private volatile boolean pauseDownloading = false;

abstract public class DownloadQueue {
// LIFO stack
ArrayList<Object> requests = new ArrayList<Object>();
void perform(Object request) {

abstract void perform(Object request);
}

void enqueue(Object req) {
requests.add(req);
public void enqueue(Object req) {
synchronized (requests) {
requests.add(req);
requests.notifyAll();
}
}

volatile boolean haveCompletelyStopped = false;
boolean stop_downloading = false;
boolean pause_downloading = false;
public synchronized void stopRequestThread() {
stopDownloading = true;
notifyAll();
}

void stopRequestThread() {
stop_downloading = true;
// while (!haveCompletelyStopped) {
// ...
// }
public synchronized void pause() {
pauseDownloading = true;
notifyAll();
}
void pause() {
pause_downloading = true;

public synchronized void start() {
stopDownloading = false;
pauseDownloading = false;
notifyAll();
}
void start() {
pause_downloading = false;

void idle() {
Object req = null;
synchronized (requests) {
while (requests.isEmpty()) {
try {
requests.wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
if (stopDownloading) return;
}
req = requests.remove(requests.size() - 1);
}
if (req != null) {
perform(req);
}
}

void startRequestThread() {
public void startRequestThread() {
new Thread(new Runnable() {
@Override
public void run() {
while (!stop_downloading) {
if (requests.size() == 0 || pause_downloading) {
try {
Thread.sleep(100);
} catch (Exception ignored) {}
continue;
while (!stopDownloading) {
synchronized (DownloadQueue.this) {
while (pauseDownloading) {
try {
DownloadQueue.this.wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
}
}
Object req = requests.remove(requests.size() - 1);
perform(req);
if (stopDownloading) return;
idle();
}
haveCompletelyStopped = true;
}
}).start();
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/dev/danielc/fujiapp/FileGallery.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(getString(R.string.gallery));
actionBar.setTitle("Downloaded Photos");

RecyclerView rv = new RecyclerView(this);
rv.setLayoutManager(new GridLayoutManager(this, 4));
Expand Down
11 changes: 4 additions & 7 deletions app/src/main/java/dev/danielc/fujiapp/FileThumbAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.io.FileInputStream;
import java.util.ArrayList;

import dev.danielc.common.Exif;

public class FileThumbAdapter extends ThumbAdapter {
File[] files;
public FileThumbAdapter(Context context, String directory) {
Expand Down Expand Up @@ -52,14 +54,9 @@ void queueImage(ImageViewHolder holder, int position) {
@Override
public void run() {
try {
// This is very stupid
// Wait android doesn't have an API to get exif thumb without reading entire file??
// I have to read an entire 20mb raw to get a 15kb thumbnail?!?!?
// TODO: C code to get thumb from file
holder.filename = files[position].getPath();
FileInputStream fis = new FileInputStream(files[position]);
byte[] buffer = new byte[(int)files[position].length()];
fis.read(buffer);
byte[] buffer = Exif.getThumbnail(holder.filename);
if (buffer == null) invalidThumb(holder.image.getContext(), holder);
loadThumb(holder, buffer);
holder.isLoaded = true;
} catch (Exception e) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/dev/danielc/fujiapp/Frontend.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void run() {
MainActivity.instance.findViewById(R.id.discoveryProgressBar).setVisibility(View.GONE);
TextView tv = MainActivity.instance.findViewById(R.id.discoveryMessage);
tv.setVisibility(View.VISIBLE);
tv.setText("discovery failed...");
tv.setText(R.string.discovery_failed);
}
});
}
Expand All @@ -55,7 +55,7 @@ public void run() {
MainActivity.instance.findViewById(R.id.discoveryProgressBar).setVisibility(View.GONE);
TextView tv = MainActivity.instance.findViewById(R.id.discoveryMessage);
tv.setVisibility(View.VISIBLE);
tv.setText("waiting on wifi...");
tv.setText(R.string.waiting_on_wifi);
}
});
}
Expand Down
Loading

0 comments on commit 23d6ae3

Please sign in to comment.