diff --git a/docs-android/app/app.iml b/docs-android/app/app.iml
index 453dc910..22f4bad8 100644
--- a/docs-android/app/app.iml
+++ b/docs-android/app/app.iml
@@ -93,6 +93,7 @@
+
diff --git a/docs-android/app/build.gradle b/docs-android/app/build.gradle
index 3ff97437..ce706bde 100644
--- a/docs-android/app/build.gradle
+++ b/docs-android/app/build.gradle
@@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.0.0-beta2'
+ classpath 'com.android.tools.build:gradle:2.0.0-beta3'
}
}
apply plugin: 'com.android.application'
diff --git a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java
index 2c69a36b..c5e8d12a 100644
--- a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java
+++ b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java
@@ -1,16 +1,13 @@
package com.sismics.docs.activity;
import android.app.AlertDialog;
-import android.app.DownloadManager;
import android.app.ProgressDialog;
import android.content.ClipData;
-import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
-import android.os.Environment;
import android.support.v4.app.DialogFragment;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.ViewPager;
@@ -52,6 +49,7 @@ import com.sismics.docs.resource.CommentResource;
import com.sismics.docs.resource.DocumentResource;
import com.sismics.docs.resource.FileResource;
import com.sismics.docs.service.FileUploadService;
+import com.sismics.docs.util.NetworkUtil;
import com.sismics.docs.util.PreferenceUtil;
import com.sismics.docs.util.TagUtil;
@@ -250,7 +248,8 @@ public class DocumentViewActivity extends AppCompatActivity {
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- DialogFragment dialog = DocExportPdfFragment.newInstance(DocumentViewActivity.this.document.optString("id"));
+ DialogFragment dialog = DocExportPdfFragment.newInstance(
+ DocumentViewActivity.this.document.optString("id"), DocumentViewActivity.this.document.optString("title"));
dialog.show(getSupportFragmentManager(), "DocExportPdfFragment");
}
});
@@ -365,11 +364,11 @@ public class DocumentViewActivity extends AppCompatActivity {
int position = fileViewPager.getCurrentItem();
if (mimeType == null || !mimeType.contains("/")) return;
String ext = mimeType.split("/")[1];
- String fileName = getTitle() + "-" + position + "." + ext;
+ String fileName = document.optString("title") + "-" + position + "." + ext;
// Download the file
String fileUrl = PreferenceUtil.getServerUrl(this) + "/api/file/" + file.optString("id") + "/data";
- downloadFile(fileUrl, fileName, getTitle().toString(), getString(R.string.downloading_file, position + 1));
+ NetworkUtil.downloadFile(this, fileUrl, fileName, document.optString("title"), getString(R.string.download_file_title));
}
private void deleteCurrentFile() {
@@ -428,28 +427,8 @@ public class DocumentViewActivity extends AppCompatActivity {
private void downloadZip() {
if (document == null) return;
String url = PreferenceUtil.getServerUrl(this) + "/api/file/zip?id=" + document.optString("id");
- String fileName = getTitle() + ".zip";
- downloadFile(url, fileName, getTitle().toString(), getString(R.string.downloading_document));
- }
-
- /**
- * Download a file using Android download manager.
- *
- * @param url URL to download
- * @param fileName Destination file name
- * @param title Notification title
- * @param description Notification description
- */
- private void downloadFile(String url, String fileName, String title, String description) {
- String authToken = PreferenceUtil.getAuthToken(this);
- DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
- DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
- request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
- request.addRequestHeader("Cookie", "auth_token=" + authToken);
- request.setTitle(title);
- request.setDescription(description);
- downloadManager.enqueue(request);
+ String fileName = document.optString("title") + ".zip";
+ NetworkUtil.downloadFile(this, url, fileName, document.optString("title"), getString(R.string.download_document_title));
}
/**
diff --git a/docs-android/app/src/main/java/com/sismics/docs/fragment/DocExportPdfFragment.java b/docs-android/app/src/main/java/com/sismics/docs/fragment/DocExportPdfFragment.java
index 0aab910e..3af5480c 100644
--- a/docs-android/app/src/main/java/com/sismics/docs/fragment/DocExportPdfFragment.java
+++ b/docs-android/app/src/main/java/com/sismics/docs/fragment/DocExportPdfFragment.java
@@ -8,8 +8,15 @@ import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
+import android.widget.CheckBox;
+import android.widget.SeekBar;
+import android.widget.TextView;
import com.sismics.docs.R;
+import com.sismics.docs.util.NetworkUtil;
+import com.sismics.docs.util.PreferenceUtil;
+
+import java.util.Locale;
/**
* Export PDF dialog fragment.
@@ -21,11 +28,13 @@ public class DocExportPdfFragment extends DialogFragment {
* Export PDF dialog fragment.
*
* @param id Document ID
+ * @param title Document title
*/
- public static DocExportPdfFragment newInstance(String id) {
+ public static DocExportPdfFragment newInstance(String id, String title) {
DocExportPdfFragment fragment = new DocExportPdfFragment();
Bundle args = new Bundle();
args.putString("id", id);
+ args.putString("title", title);
fragment.setArguments(args);
return fragment;
}
@@ -38,11 +47,41 @@ public class DocExportPdfFragment extends DialogFragment {
// Setup the view
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.document_export_pdf_dialog, null);
+ final SeekBar marginSeekBar = (SeekBar) view.findViewById(R.id.marginSeekBar);
+ final CheckBox exportMetadataCheckbox = (CheckBox) view.findViewById(R.id.exportMetadataCheckbox);
+ final CheckBox exportCommentsCheckbox = (CheckBox) view.findViewById(R.id.exportCommentsCheckbox);
+ final CheckBox fitToPageCheckbox = (CheckBox) view.findViewById(R.id.fitToPageCheckbox);
+ final TextView marginValueText = (TextView) view.findViewById(R.id.marginValueText);
+
+ // Margin label follow seekbar value
+ marginSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ marginValueText.setText(String.format(Locale.ENGLISH, "%d", progress));
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+
+ }
+ });
// Build the dialog
builder.setView(view)
.setPositiveButton(R.string.download, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
+ // Download the PDF
+ String pdfUrl = PreferenceUtil.getServerUrl(getActivity()) + "/api/document/" + getArguments().getString("id") + "/pdf?" +
+ "metadata=" + exportMetadataCheckbox.isChecked() + "&comments=" + exportCommentsCheckbox.isChecked() + "&fitimagetopage=" + fitToPageCheckbox.isChecked() +
+ "&margin=" + marginSeekBar.getProgress();
+ String title = getArguments().getString("title");
+ NetworkUtil.downloadFile(getActivity(), pdfUrl, title + ".pdf", title, getString(R.string.download_pdf_title));
+
getDialog().cancel();
}
})
diff --git a/docs-android/app/src/main/java/com/sismics/docs/util/ApplicationUtil.java b/docs-android/app/src/main/java/com/sismics/docs/util/ApplicationUtil.java
index fba41d56..3c703035 100644
--- a/docs-android/app/src/main/java/com/sismics/docs/util/ApplicationUtil.java
+++ b/docs-android/app/src/main/java/com/sismics/docs/util/ApplicationUtil.java
@@ -10,7 +10,6 @@ import android.content.pm.PackageManager.NameNotFoundException;
* @author bgamard
*/
public class ApplicationUtil {
-
/**
* Returns version name.
*
diff --git a/docs-android/app/src/main/java/com/sismics/docs/util/DialogUtil.java b/docs-android/app/src/main/java/com/sismics/docs/util/DialogUtil.java
index 271977c6..9967a25b 100644
--- a/docs-android/app/src/main/java/com/sismics/docs/util/DialogUtil.java
+++ b/docs-android/app/src/main/java/com/sismics/docs/util/DialogUtil.java
@@ -12,7 +12,6 @@ import com.sismics.docs.R;
* @author bgamard
*/
public class DialogUtil {
-
/**
* Create a dialog with an OK button.
*
diff --git a/docs-android/app/src/main/java/com/sismics/docs/util/NetworkUtil.java b/docs-android/app/src/main/java/com/sismics/docs/util/NetworkUtil.java
new file mode 100644
index 00000000..a81b4862
--- /dev/null
+++ b/docs-android/app/src/main/java/com/sismics/docs/util/NetworkUtil.java
@@ -0,0 +1,33 @@
+package com.sismics.docs.util;
+
+import android.app.DownloadManager;
+import android.content.Context;
+import android.net.Uri;
+import android.os.Environment;
+
+/**
+ * Utility class for network actions.
+ *
+ * @author bgamard.
+ */
+public class NetworkUtil {
+ /**
+ * Download a file using Android download manager.
+ *
+ * @param url URL to download
+ * @param fileName Destination file name
+ * @param title Notification title
+ * @param description Notification description
+ */
+ public static void downloadFile(Context context, String url, String fileName, String title, String description) {
+ String authToken = PreferenceUtil.getAuthToken(context);
+ DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
+ DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
+ request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
+ request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
+ request.addRequestHeader("Cookie", "auth_token=" + authToken);
+ request.setTitle(title);
+ request.setDescription(description);
+ downloadManager.enqueue(request);
+ }
+}
diff --git a/docs-android/app/src/main/res/layout/document_export_pdf_dialog.xml b/docs-android/app/src/main/res/layout/document_export_pdf_dialog.xml
index 2ab84d61..16db3354 100644
--- a/docs-android/app/src/main/res/layout/document_export_pdf_dialog.xml
+++ b/docs-android/app/src/main/res/layout/document_export_pdf_dialog.xml
@@ -8,23 +8,59 @@
+ android:layout_margin="6dp"
+ android:text="@string/export_metadata"
+ android:id="@+id/exportMetadataCheckbox" />
+ android:layout_margin="6dp"
+ android:text="@string/export_comments"
+ android:id="@+id/exportCommentsCheckbox" />
+ android:layout_margin="6dp"
+ android:checked="true"
+ android:text="@string/fit_image_to_page"
+ android:id="@+id/fitToPageCheckbox" />
-
+ android:layout_margin="16dp"
+ android:orientation="horizontal">
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/docs-android/app/src/main/res/values/strings.xml b/docs-android/app/src/main/res/values/strings.xml
index a6e76661..c65eeaec 100644
--- a/docs-android/app/src/main/res/values/strings.xml
+++ b/docs-android/app/src/main/res/values/strings.xml
@@ -28,9 +28,7 @@
A crash occurred, a report has been sent to resolve this problem
Created date
Download current file
- Downloading file number %1s
Download
- Downloading document
Search documents
All documents
Shared documents
@@ -119,6 +117,13 @@
Error deleting comment
Export PDF
Download
-
+ Margin
+ Fit image to page
+ Export comments
+ Export metadata
+ mm
+ Sismics Docs file export
+ Sismics Docs document export
+ Sismics Docs PDF export