Skip to content

Commit

Permalink
exports moved to plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
moovida committed Feb 10, 2017
1 parent fd7d804 commit f7059ad
Show file tree
Hide file tree
Showing 22 changed files with 486 additions and 188 deletions.
1 change: 1 addition & 0 deletions geopaparazzi.app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ dependencies {
compile project(':geopaparazzi_default_import_plugins')
compile project(':geopaparazzi_projects_import_plugins')
compile project(':geopaparazzi_projects_export_plugins')
compile project(':geopaparazzi_default_export_plugins')
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public class ExportActivity extends AppCompatActivity implements
// List of URIs to provide to Android Beam
private Uri[] mFileUris = new Uri[1];
private PendingIntent pendingIntent;
private StringAsyncTask exportImagesTask;

private SparseArray<IMenuEntry> menuEntriesMap = new SparseArray<>();

Expand All @@ -107,27 +106,6 @@ public void onCreate(Bundle icicle) {
GPLog.error(this, e.getLocalizedMessage(), e);
}

Button kmzExportButton = (Button) findViewById(R.id.kmzExportButton);
kmzExportButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
KmzExportDialogFragment kmzExportDialogFragment = KmzExportDialogFragment.newInstance(null);
kmzExportDialogFragment.show(getSupportFragmentManager(), "kmz export");
}
});
Button gpxExportButton = (Button) findViewById(R.id.gpxExportButton);
gpxExportButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
GpxExportDialogFragment gpxExportDialogFragment = GpxExportDialogFragment.newInstance(null);
gpxExportDialogFragment.show(getSupportFragmentManager(), "gpx export");
}
});
Button bookmarksExportButton = (Button) findViewById(R.id.bookmarksExportButton);
bookmarksExportButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
exportBookmarks();
}
});

// Button cloudDataExportButton = (Button) findViewById(R.id.cloudDataExportButton);
// cloudDataExportButton.setOnClickListener(new Button.OnClickListener() {
// public void onClick(View v) {
Expand Down Expand Up @@ -163,14 +141,6 @@ public void onClick(View v) {
// }
// });

Button imagesExportButton = (Button) findViewById(R.id.imagesExportButton);
imagesExportButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
exportImages();
}
});


MenuLoader menuLoader = new MenuLoader(this, IMenuLoader.MENU_EXPORT_PROVIDER);
menuLoader.addListener(new PluginLoaderListener<MenuLoader>() {
@Override
Expand Down Expand Up @@ -227,133 +197,6 @@ protected void onPause() {
}


@SuppressWarnings("nls")
private void exportBookmarks() {

try {
List<Bookmark> allBookmarks = DaoBookmarks.getAllBookmarks();
TreeSet<String> bookmarksNames = new TreeSet<>();
for (Bookmark bookmark : allBookmarks) {
String tmpName = bookmark.getName();
bookmarksNames.add(tmpName.trim());
}

List<String> namesToNOTAdd = new ArrayList<>();
ResourcesManager resourcesManager = ResourcesManager.getInstance(this);
File sdcardDir = resourcesManager.getSdcardDir();
File bookmarksfile = new File(sdcardDir, "bookmarks.csv"); //$NON-NLS-1$
StringBuilder sb = new StringBuilder();
if (bookmarksfile.exists()) {
List<String> bookmarksList = FileUtilities.readfileToList(bookmarksfile);
for (String bookmarkLine : bookmarksList) {
String[] split = bookmarkLine.split(","); //$NON-NLS-1$
// bookmarks are of type: Agritur BeB In Valle, 45.46564, 11.58969, 12
if (split.length < 3) {
continue;
}
String name = split[0].trim();
if (bookmarksNames.contains(name)) {
namesToNOTAdd.add(name);
}
}
for (String string : bookmarksList) {
sb.append(string).append("\n");
}
}
int exported = 0;
for (Bookmark bookmark : allBookmarks) {
String name = bookmark.getName().trim();
if (!namesToNOTAdd.contains(name)) {
sb.append(name);
sb.append(",");
sb.append(bookmark.getLat());
sb.append(",");
sb.append(bookmark.getLon());
sb.append(",");
sb.append(bookmark.getZoom());
sb.append("\n");
exported++;
}
}

FileUtilities.writefile(sb.toString(), bookmarksfile);
if (bookmarksfile.exists()) {
GPDialogs.infoDialog(this, getString(R.string.bookmarks_exported) + exported, null);
} else {
GPDialogs.infoDialog(this, getString(R.string.bookmarks_exported_newfile) + exported, null);
}
} catch (Exception e) {
GPLog.error(this, null, e);
GPDialogs.warningDialog(this, getString(R.string.bookmarks_exported_error), null);
}

}

private void exportImages() {
try {
File sdcardDir = ResourcesManager.getInstance(GeopaparazziApplication.getInstance()).getSdcardDir();
final File outFolder = new File(sdcardDir, "geopaparazzi_images_" + TimeUtilities.INSTANCE.TIMESTAMPFORMATTER_LOCAL.format(new Date()));
if (!outFolder.mkdir()) {
GPDialogs.warningDialog(this, getString(R.string.export_img_unable_to_create_folder) + outFolder, null);
return;
}
final List<Image> imagesList = DaoImages.getImagesList(false, false);
if (imagesList.size() == 0) {
GPDialogs.infoDialog(this, getString(R.string.no_images_in_project), null);
return;
}


final DaoImages imageHelper = new DaoImages();
exportImagesTask = new StringAsyncTask(this) {
protected String doBackgroundWork() {
try {
for (int i = 0; i < imagesList.size(); i++) {
Image image = imagesList.get(i);
try {
byte[] imageData = imageHelper.getImageData(image.getId());
File imageFile = new File(outFolder, image.getName());

FileOutputStream fos = new FileOutputStream(imageFile);
fos.write(imageData);
fos.close();
} catch (IOException e) {
GPLog.error(this, "For file: " + image.getName(), e);
} finally {
publishProgress(i);
}
}
} catch (Exception e) {
return "ERROR: " + e.getLocalizedMessage();
}
return "";
}

protected void doUiPostWork(String response) {
if (response == null) response = "";
if (response.length() != 0) {
GPDialogs.warningDialog(ExportActivity.this, response, null);
} else {
GPDialogs.infoDialog(ExportActivity.this, getString(R.string.export_img_ok_exported) + outFolder, null);
}
}
};
exportImagesTask.setProgressDialog(getString(R.string.export_uc), getString(R.string.export_img_processing), false, imagesList.size());
exportImagesTask.execute();


} catch (Exception e) {
GPLog.error(this, null, e);
GPDialogs.errorDialog(this, e, null);
}
}

@Override
protected void onDestroy() {
if (exportImagesTask != null) exportImagesTask.dispose();
super.onDestroy();
}

@Override
public Uri[] createBeamUris(NfcEvent nfcEvent) {
GPLog.addLogEntry(this, "URI SENT: " + mFileUris[0]);
Expand Down
23 changes: 0 additions & 23 deletions geopaparazzi_core/src/main/res/layout/activity_export.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,6 @@
android:layout_marginTop="15dp"
android:orientation="vertical">

<Button
android:id="@+id/kmzExportButton"
style="@style/GPMediumButton"
android:layout_width="match_parent"
android:text="@string/kmz" />

<Button
android:id="@+id/gpxExportButton"
style="@style/GPMediumButton"
android:layout_width="match_parent"
android:text="@string/gpx" />

<Button
android:id="@+id/bookmarksExportButton"
style="@style/GPMediumButton"
android:layout_width="match_parent"
android:text="@string/bookmarks" />

<Button
android:id="@+id/imagesExportButton"
style="@style/GPMediumButton"
android:layout_width="match_parent"
android:text="@string/export_images" />
</LinearLayout>
</ScrollView>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void removeListener(PluginLoaderListener listener) {
public void connect() {
PackageManager packageManager = context.getPackageManager();
Intent intent = new Intent(this.serviceName);
List<ResolveInfo> menuProviders = packageManager.queryIntentServices(intent, PackageManager.MATCH_ALL);
List<ResolveInfo> menuProviders = packageManager.queryIntentServices(intent, PackageManager.GET_RESOLVED_FILTER);
numberOfPlugins = menuProviders.size();
for (int i = 0; i < menuProviders.size(); ++i) {
ResolveInfo info = menuProviders.get(i);
Expand Down
1 change: 1 addition & 0 deletions plugins/geopaparazzi_default_export_plugins/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
32 changes: 32 additions & 0 deletions plugins/geopaparazzi_default_export_plugins/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "24.0.3"

defaultConfig {
minSdkVersion 18
targetSdkVersion 25
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.1'
testCompile 'junit:junit:4.12'
compile project(':geopaparazzi_core')
}
17 changes: 17 additions & 0 deletions plugins/geopaparazzi_default_export_plugins/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/cesar/Android/Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.geopaparazzi.plugins.defaultexports">

<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">
<service android:name="eu.geopaparazzi.plugins.defaultexports.DefaultExportsMenuProvider"
android:exported="false">
<intent-filter>
<action android:name="eu.geopaparazzi.core.extension.ep.exporter.MENU_PROVIDER" />
<category android:name="androidsrc.intent.category.MENU_PROVIDER" />
</intent-filter>
</service>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Geopaparazzi - Digital field mapping on Android based devices
* Copyright (C) 2016 HydroloGIS (www.hydrologis.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.geopaparazzi.plugins.defaultexports;

import android.content.Intent;
import android.os.IBinder;

import eu.geopaparazzi.library.plugin.PluginService;
import eu.geopaparazzi.library.plugin.types.MenuEntryList;


/**
* Menu provider for all default exports.
*
* @author Andrea Antonello (www.hydrologis.com)
*/
public class DefaultExportsMenuProvider extends PluginService {
private static final String NAME = "DefaultExportsMenuProvider";
private MenuEntryList list = null;

public DefaultExportsMenuProvider() {
super(NAME);
}

public IBinder onBind(Intent intent) {
if (list == null) {
list = new MenuEntryList();
list.addEntry(new ExportKmzMenuEntry(getApplicationContext()));
list.addEntry(new ExportGpxMenuEntry(getApplicationContext()));
list.addEntry(new ExportBookmarksMenuEntry(getApplicationContext()));
list.addEntry(new ExportImagesMenuEntry(getApplicationContext()));
}
return list;
}


}
Loading

0 comments on commit f7059ad

Please sign in to comment.