Skip to content
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

Xmp header android #37

Merged
merged 7 commits into from
Jan 10, 2024
Merged
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
38 changes: 21 additions & 17 deletions hooks/move_exifInterface.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
var fs = require("fs");
var fs = require("fs").promises;
var path = require("path");

module.exports = function (context) {
var Q = context.requireCordovaModule("q");
var deferral = new Q.defer();
module.exports = async function (context) {
var targetFiles = ["ExifInterfaceFix.java", "ExifInterfaceUtils.java"];

targetFiles.map(fileName => {
for (const fileName of targetFiles) {
var sourceFile = path.join(
context.opts.projectRoot,
`platforms/android/app/src/main/java/jp/co/taisei/construction/fieldmanagement/plugin/${fileName}`
);
var targetFile = path.join(
var targetDir = path.join(
context.opts.projectRoot,
`platforms/android/app/src/main/java/androidx/exifinterface/media/${fileName}`
"platforms/android/app/src/main/java/androidx/exifinterface/media"
);
var targetFile = path.join(targetDir, fileName);

fs.rename(sourceFile, targetFile, function (err) {
if (err) {
deferral.reject("Error moving file: " + err);
} else {
console.log("File moved successfully");
deferral.resolve();
}
});
});
// コピー先ディレクトリが存在するか確認し、存在しない場合は作成する
try {
await fs.access(targetDir, fs.constants.F_OK);
} catch (err) {
await fs.mkdir(targetDir, { recursive: true });
}

return deferral.promise;
// ファイルの移動
try {
await fs.rename(sourceFile, targetFile);
console.log("File moved successfully");
} catch (err) {
console.error("Error moving file: " + err);
throw err; // エラーを外部に伝播させる
}
}
};
4 changes: 4 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
</edit-config> -->

<framework src="com.android.support:exifinterface:27.1.1" />
<framework src="com.adobe.xmp:xmpcore:5.1.3"/>

<source-file src="src/android/BlackboardCamera.kt" target-dir="app/src/main/java/jp/co/taisei/construction/fieldmanagement/plugin"/>
<source-file src="src/android/CameraActivity.kt" target-dir="app/src/main/java/jp/co/taisei/construction/fieldmanagement/plugin"/>
Expand All @@ -110,6 +111,9 @@
<source-file src="src/android/SensorOrientation.kt" target-dir="app/src/main/java/jp/co/taisei/construction/fieldmanagement/plugin"/>
<source-file src="src/android/ElectronicBlackBoardManager.kt" target-dir="app/src/main/java/jp/co/taisei/construction/fieldmanagement/plugin"/>
<source-file src="src/android/PhotoInfo.kt" target-dir="app/src/main/java/jp/co/taisei/construction/fieldmanagement/plugin"/>
<source-file src="src/android/ExifInterfaceFix.java" target-dir="app/src/main/java/jp/co/taisei/construction/fieldmanagement/plugin"/>
<source-file src="src/android/ExifInterfaceUtils.java" target-dir="app/src/main/java/jp/co/taisei/construction/fieldmanagement/plugin"/>
<source-file src="src/android/XmpUtil.java" target-dir="app/src/main/java/jp/co/taisei/construction/fieldmanagement/plugin"/>

<source-file src="src/android/layout/activity_main.xml" target-dir="app/src/main/res/layout"/>
<source-file src="src/android/layout-land/fragment_camera2.xml" target-dir="app/src/main/res/layout-land"/>
Expand Down
10 changes: 6 additions & 4 deletions src/android/ElectronicBlackBoardManager.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package jp.co.taisei.construction.fieldmanagement.plugin

import android.content.Context
import java.io.File
import java.util.*
import android.graphics.BitmapFactory
import android.graphics.Bitmap
import androidx.exifinterface.media.ExifInterfaceFix
import com.adobe.xmp.XMPConst
import java.text.SimpleDateFormat

object ElectronicBlackBoardManager {

fun createImageEmbeddedMetaData(path: String, photoInfo: PhotoInfo?, imageDescription: String, model: String, software: String) {

// http://ns.adobe.com/xap/1.0/情報を先にセットする
val xmpMeta = XmpUtil.extractOrCreateXMPMeta(path)
xmpMeta.setProperty(XMPConst.NS_XMP, "Label", "TPR2");
XmpUtil.writeXMPMeta(path, xmpMeta)

val formatter = SimpleDateFormat("yyyy:MM:dd HH:mm:ss", Locale.US)
val now = Date()
val millisec = (now.time % 1000).toInt()
Expand Down
36 changes: 18 additions & 18 deletions src/android/ExifInterfaceFix.java
Original file line number Diff line number Diff line change
Expand Up @@ -3937,7 +3937,7 @@ boolean isFormatCompatible(int format) {
* @throws IOException if an I/O error occurs while retrieving file descriptor via
* {@link FileInputStream#getFD()}.
*/
public ExifInterface2(@NonNull File file) throws IOException {
public ExifInterfaceFix(@NonNull File file) throws IOException {
if (file == null) {
throw new NullPointerException("file cannot be null");
}
Expand All @@ -3952,7 +3952,7 @@ public ExifInterface2(@NonNull File file) throws IOException {
* @throws IOException if an I/O error occurs while retrieving file descriptor via
* {@link FileInputStream#getFD()}.
*/
public ExifInterface2(@NonNull String filename) throws IOException {
public ExifInterfaceFix(@NonNull String filename) throws IOException {
if (filename == null) {
throw new NullPointerException("filename cannot be null");
}
Expand All @@ -3968,7 +3968,7 @@ public ExifInterface2(@NonNull String filename) throws IOException {
* @throws NullPointerException if file descriptor is null
* @throws IOException if an error occurs while duplicating the file descriptor.
*/
public ExifInterface2(@NonNull FileDescriptor fileDescriptor) throws IOException {
public ExifInterfaceFix(@NonNull FileDescriptor fileDescriptor) throws IOException {
if (fileDescriptor == null) {
throw new NullPointerException("fileDescriptor cannot be null");
}
Expand Down Expand Up @@ -4011,7 +4011,7 @@ public ExifInterface2(@NonNull FileDescriptor fileDescriptor) throws IOException
* @param inputStream the input stream that contains the image data
* @throws NullPointerException if the input stream is null
*/
public ExifInterface2(@NonNull InputStream inputStream) throws IOException {
public ExifInterfaceFix(@NonNull InputStream inputStream) throws IOException {
this(inputStream, STREAM_TYPE_FULL_IMAGE_DATA);
}

Expand All @@ -4027,7 +4027,7 @@ public ExifInterface2(@NonNull InputStream inputStream) throws IOException {
* @throws IOException if an I/O error occurs while retrieving file descriptor via
* {@link FileInputStream#getFD()}.
*/
public ExifInterface2(@NonNull InputStream inputStream, @ExifStreamType int streamType)
public ExifInterfaceFix(@NonNull InputStream inputStream, @ExifStreamType int streamType)
throws IOException {
if (inputStream == null) {
throw new NullPointerException("inputStream cannot be null");
Expand Down Expand Up @@ -5067,7 +5067,7 @@ public void setGpsInfo(Location location) {
if (location == null) {
return;
}
setAttribute(ExifInterface2.TAG_GPS_PROCESSING_METHOD, location.getProvider());
setAttribute(ExifInterfaceFix.TAG_GPS_PROCESSING_METHOD, location.getProvider());
setLatLong(location.getLatitude(), location.getLongitude());
setAltitude(location.getAltitude());
// Location objects store speeds in m/sec. Translates it to km/hr here.
Expand All @@ -5076,8 +5076,8 @@ public void setGpsInfo(Location location) {
* TimeUnit.HOURS.toSeconds(1) / 1000).toString());
String[] dateTime = sFormatterPrimary.format(
new Date(location.getTime())).split("\\s+", -1);
setAttribute(ExifInterface2.TAG_GPS_DATESTAMP, dateTime[0]);
setAttribute(ExifInterface2.TAG_GPS_TIMESTAMP, dateTime[1]);
setAttribute(ExifInterfaceFix.TAG_GPS_DATESTAMP, dateTime[0]);
setAttribute(ExifInterfaceFix.TAG_GPS_TIMESTAMP, dateTime[1]);
}

/**
Expand Down Expand Up @@ -5155,11 +5155,11 @@ public void setDateTime(@NonNull Long timeStamp) {
}

/**
* Returns parsed {@link ExifInterface2#TAG_DATETIME} value as number of milliseconds since
* Returns parsed {@link ExifInterfaceFix#TAG_DATETIME} value as number of milliseconds since
* Jan. 1, 1970, midnight local time.
*
* <p>Note: The return value includes the first three digits (or less depending on the length
* of the string) of {@link ExifInterface2#TAG_SUBSEC_TIME}.
* of the string) of {@link ExifInterfaceFix#TAG_SUBSEC_TIME}.
*
* @return null if date time information is unavailable or invalid.
*
Expand All @@ -5174,11 +5174,11 @@ public Long getDateTime() {
}

/**
* Returns parsed {@link ExifInterface2#TAG_DATETIME_DIGITIZED} value as number of
* Returns parsed {@link ExifInterfaceFix#TAG_DATETIME_DIGITIZED} value as number of
* milliseconds since Jan. 1, 1970, midnight local time.
*
* <p>Note: The return value includes the first three digits (or less depending on the length
* of the string) of {@link ExifInterface2#TAG_SUBSEC_TIME_DIGITIZED}.
* of the string) of {@link ExifInterfaceFix#TAG_SUBSEC_TIME_DIGITIZED}.
*
* @return null if digitized date time information is unavailable or invalid.
*
Expand All @@ -5193,11 +5193,11 @@ public Long getDateTimeDigitized() {
}

/**
* Returns parsed {@link ExifInterface2#TAG_DATETIME_ORIGINAL} value as number of
* Returns parsed {@link ExifInterfaceFix#TAG_DATETIME_ORIGINAL} value as number of
* milliseconds since Jan. 1, 1970, midnight local time.
*
* <p>Note: The return value includes the first three digits (or less depending on the length
* of the string) of {@link ExifInterface2#TAG_SUBSEC_TIME_ORIGINAL}.
* of the string) of {@link ExifInterfaceFix#TAG_SUBSEC_TIME_ORIGINAL}.
*
* @return null if original date time information is unavailable or invalid.
*
Expand Down Expand Up @@ -5920,18 +5920,18 @@ public long getSize() throws IOException {
}

if (rotation != null) {
int orientation = ExifInterface2.ORIENTATION_NORMAL;
int orientation = ExifInterfaceFix.ORIENTATION_NORMAL;

// all rotation angles in CW
switch (Integer.parseInt(rotation)) {
case 90:
orientation = ExifInterface2.ORIENTATION_ROTATE_90;
orientation = ExifInterfaceFix.ORIENTATION_ROTATE_90;
break;
case 180:
orientation = ExifInterface2.ORIENTATION_ROTATE_180;
orientation = ExifInterfaceFix.ORIENTATION_ROTATE_180;
break;
case 270:
orientation = ExifInterface2.ORIENTATION_ROTATE_270;
orientation = ExifInterfaceFix.ORIENTATION_ROTATE_270;
break;
}

Expand Down
Loading