diff --git a/README b/README
index 2f989bf7..30a36df1 100644
--- a/README
+++ b/README
@@ -20,6 +20,12 @@ along with Transdroid. If not, see .
---
Some code/libraries are used in the project:
+ ActionBarSherlock
+ Jake Wharton (Apache License, Version 2.0)
+ http://actionbarsherlock.com/
+ AndroidAnnotations
+ Pierre-Yves Ricau (eBusinessInformations) et al.
+ http://androidannotations.org/
Base16Encoder (Apache OpenJPA)
Marc Prud'hommeaux (Apache License, Version 2.0)
MultipartEntity (AOSP)
diff --git a/core/libs/ormlite-android-4.24.jar b/core/libs/ormlite-android-4.24.jar
new file mode 100644
index 00000000..d876135e
Binary files /dev/null and b/core/libs/ormlite-android-4.24.jar differ
diff --git a/core/libs/ormlite-core-4.24.jar b/core/libs/ormlite-core-4.24.jar
new file mode 100644
index 00000000..a9ab582b
Binary files /dev/null and b/core/libs/ormlite-core-4.24.jar differ
diff --git a/core/res/drawable-hdpi/ic_action_website.png b/core/res/drawable-hdpi/ic_action_website.png
new file mode 100644
index 00000000..e154afdb
Binary files /dev/null and b/core/res/drawable-hdpi/ic_action_website.png differ
diff --git a/core/res/drawable-mdpi/ic_action_website.png b/core/res/drawable-mdpi/ic_action_website.png
new file mode 100644
index 00000000..41b56ec9
Binary files /dev/null and b/core/res/drawable-mdpi/ic_action_website.png differ
diff --git a/core/res/drawable-xhdpi/ic_action_website.png b/core/res/drawable-xhdpi/ic_action_website.png
new file mode 100644
index 00000000..9b77be96
Binary files /dev/null and b/core/res/drawable-xhdpi/ic_action_website.png differ
diff --git a/core/res/layout-w600dp/activity_torrents.xml b/core/res/layout-w600dp/activity_torrents.xml
index da228be0..a06281b6 100644
--- a/core/res/layout-w600dp/activity_torrents.xml
+++ b/core/res/layout-w600dp/activity_torrents.xml
@@ -8,7 +8,7 @@
android:baselineAligned="false"
tools:context=".TorrentsActivity" >
-
-
+
+
diff --git a/core/res/layout/fragment_about.xml b/core/res/layout/fragment_about.xml
new file mode 100644
index 00000000..56bf496b
--- /dev/null
+++ b/core/res/layout/fragment_about.xml
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/core/res/layout/fragment_details.xml b/core/res/layout/fragment_details.xml
index d627b53b..1aaefcce 100644
--- a/core/res/layout/fragment_details.xml
+++ b/core/res/layout/fragment_details.xml
@@ -13,6 +13,14 @@
android:dividerHeight="0dip"
android:visibility="gone" />
+
+
+ android:indeterminateDrawable="@drawable/loading_progress"
+ android:visibility="visible" />
+
+
+
+
\ No newline at end of file
diff --git a/core/res/values-sw500dp/bools.xml b/core/res/values-sw500dp/bools.xml
new file mode 100644
index 00000000..4a4c7757
--- /dev/null
+++ b/core/res/values-sw500dp/bools.xml
@@ -0,0 +1,5 @@
+
+
+
+ false
+
\ No newline at end of file
diff --git a/core/res/values/bools.xml b/core/res/values/bools.xml
new file mode 100644
index 00000000..2a472937
--- /dev/null
+++ b/core/res/values/bools.xml
@@ -0,0 +1,5 @@
+
+
+
+ true
+
\ No newline at end of file
diff --git a/core/res/values/strings.xml b/core/res/values/strings.xml
index 734dca59..12b0e1cb 100644
--- a/core/res/values/strings.xml
+++ b/core/res/values/strings.xml
@@ -1,7 +1,5 @@
-
- Transdroid
Add
From file
@@ -40,6 +38,7 @@
Remote play in VLC
Download using (S)FTP
Remove settings
+ Visit transdroid.org
Transdroid allows you to monitor and manage the torrent client you run at home or on your seedbox. Setting things up can be a bit tricky, but we offer step-by-step guides and promise it\'ll be worth it!
Connected, but no torrent are active within the current filter
@@ -179,27 +178,6 @@
View install guides
Recent changes
About
-
- Error during communication; check your connection
- Internal error building request
- Error parsing server response (please check your settings)
- Web interface not connected to a running daemon
- Access denied (please check your settings)
- Can\'t read .torrent file
- Error while parsing the RSS feed
- This URL is not well-formed
- Your web search URL is invalid:
- Input is not a valid IP address or host name
- Port number is always numeric
- Directory paths end with a / or \
- Timeout can not be empty and is a positive number
- The RSS feed item didn\'t provide an URL enclosure or link tag pointing to the .torrent file
- The RSS feed item does not provide a link to browse to
- URL is not a (valid) RSS feed
- SD card not available to read/write
- File does not seem to contain Transdroid settings
- There is no settings file found
-
- BitComet
- Bitflu 1.2+
@@ -258,5 +236,31 @@
- 43200
- 86400
+
+ Error during communication; check your connection
+ Internal error building request
+ Error parsing server response (please check your settings)
+ Web interface not connected to a running daemon
+ Access denied (please check your settings)
+ Can\'t read .torrent file
+ Error while parsing the RSS feed
+ This URL is not well-formed
+ Your web search URL is invalid:
+ Input is not a valid IP address or host name
+ Port number is always numeric
+ Directory paths end with a / or \
+ Timeout can not be empty and is a positive number
+ The RSS feed item didn\'t provide an URL enclosure or link tag pointing to the .torrent file
+ The RSS feed item does not provide a link to browse to
+ URL is not a (valid) RSS feed
+ SD card not available to read/write
+ File does not seem to contain Transdroid settings
+ There is no settings file found
+
+ Transdroid
+ \u00A9 Eric Kok, 2312 development
+ Published under GNU General Public License v3
+ Manage your torrents from your Android device
+ LIBRARIES
\ No newline at end of file
diff --git a/core/src/org/transdroid/core/app/settings/ServerSetting.java b/core/src/org/transdroid/core/app/settings/ServerSetting.java
index 3070c730..f1c47cff 100644
--- a/core/src/org/transdroid/core/app/settings/ServerSetting.java
+++ b/core/src/org/transdroid/core/app/settings/ServerSetting.java
@@ -207,16 +207,23 @@ public class ServerSetting implements SimpleListItem {
// Other objects are never equal to this
return false;
}
-
+
+ /**
+ * Returns the appropriate daemon adapter to which tasks can be executed, in accordance with this server's settings
+ * @return An IDaemonAdapter instance of the specific torrent client daemon type
+ */
public IDaemonAdapter createServerAdapter() {
+ return type.createAdapter(convertToDaemonSettings());
+ }
+
+ private DaemonSettings convertToDaemonSettings() {
// Convert local server settings into an old-style DaemonSetting object
// The local integer key is converted to the idString string
// TODO: Add localaddress and localnetwork to DaemonSettings, or solve properly rework the Connect library
// handling of settings
- DaemonSettings daemonSettings = new DaemonSettings(name, type, address, port, ssl, sslTrustAll, sslTrustKey,
+ return new DaemonSettings(name, type, address, port, ssl, sslTrustAll, sslTrustKey,
folder, useAuthentication, username, password, extraPass, os, downloadDir, ftpUrl, ftpPassword,
timeout, alarmOnFinishedDownload, alarmOnNewTorrent, Integer.toString(key), isAutoGenerated);
- return type.createAdapter(daemonSettings);
}
}
diff --git a/core/src/org/transdroid/core/gui/AboutFragment.java b/core/src/org/transdroid/core/gui/AboutFragment.java
new file mode 100644
index 00000000..6a336bc5
--- /dev/null
+++ b/core/src/org/transdroid/core/gui/AboutFragment.java
@@ -0,0 +1,42 @@
+package org.transdroid.core.gui;
+
+import org.androidannotations.annotations.AfterViews;
+import org.androidannotations.annotations.EFragment;
+import org.androidannotations.annotations.OptionsItem;
+import org.androidannotations.annotations.OptionsMenu;
+
+import android.app.Dialog;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.view.Window;
+
+import com.actionbarsherlock.app.SherlockDialogFragment;
+
+/**
+ * Fragment that shows info about the application developer and used open source libraries.
+ * @author Eric Kok
+ */
+@EFragment(resName="fragment_about")
+@OptionsMenu(resName="fragment_about")
+public class AboutFragment extends SherlockDialogFragment {
+
+ @AfterViews
+ protected void init() {
+ // TODO: Add list of used open source libraries
+ }
+
+ @OptionsItem(resName="action_visitwebsite")
+ protected void visitWebsite() {
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://transdroid.org")));
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ // Allow presenting of this fragment as a dialog
+ Dialog dialog = super.onCreateDialog(savedInstanceState);
+ dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
+ return dialog;
+ }
+
+}
diff --git a/core/src/org/transdroid/core/gui/DetailsActivity.java b/core/src/org/transdroid/core/gui/DetailsActivity.java
index 2e92a39b..bf5974ca 100644
--- a/core/src/org/transdroid/core/gui/DetailsActivity.java
+++ b/core/src/org/transdroid/core/gui/DetailsActivity.java
@@ -103,7 +103,9 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
@Background
protected void refreshTorrent() {
+ fragmentDetails.updateIsLoading(true);
DaemonTaskResult result = RetrieveTask.create(currentConnection).execute();
+ fragmentDetails.updateIsLoading(false);
if (result instanceof RetrieveTaskSuccessResult) {
onTorrentsRetrieved(((RetrieveTaskSuccessResult) result).getTorrents(), ((RetrieveTaskSuccessResult) result).getLabels());
} else {
diff --git a/core/src/org/transdroid/core/gui/DetailsFragment.java b/core/src/org/transdroid/core/gui/DetailsFragment.java
index 1e363ce0..10eaf5f2 100644
--- a/core/src/org/transdroid/core/gui/DetailsFragment.java
+++ b/core/src/org/transdroid/core/gui/DetailsFragment.java
@@ -18,6 +18,7 @@ import org.transdroid.daemon.TorrentDetails;
import org.transdroid.daemon.TorrentFile;
import android.view.View;
+import android.widget.ProgressBar;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
@@ -25,7 +26,7 @@ import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.SherlockListView;
/**
- * Fragment that shown detailed statistics about some torrent. These come from some already fetched {@link Torrent}
+ * Fragment that shows detailed statistics about some torrent. These come from some already fetched {@link Torrent}
* object, but it also retrieves further detailed statistics.
* @author Eric Kok
*/
@@ -40,12 +41,16 @@ public class DetailsFragment extends SherlockFragment {
protected TorrentDetails torrentDetails = null;
@InstanceState
protected ArrayList torrentFiles = null;
+ @InstanceState
+ protected boolean isLoadingTorrent = false;
// Views
@ViewById(resName="details_list")
protected SherlockListView detailsList;
@ViewById
protected TextView emptyText;
+ @ViewById
+ protected ProgressBar loadingProgress;
@AfterViews
protected void init() {
@@ -68,9 +73,10 @@ public class DetailsFragment extends SherlockFragment {
clear();
this.torrent = newTorrent;
((DetailsAdapter) detailsList.getAdapter()).updateTorrent(newTorrent);
- // Make the list (with detials header) visible
+ // Make the list (with details header) visible
detailsList.setVisibility(View.VISIBLE);
- emptyText.setVisibility(View.INVISIBLE);
+ emptyText.setVisibility(isLoadingTorrent? View.INVISIBLE: View.VISIBLE);
+ loadingProgress.setVisibility(!isLoadingTorrent? View.VISIBLE: View.INVISIBLE);
// Also update the available actions in the action bar
getActivity().supportInvalidateOptionsMenu();
}
@@ -122,7 +128,17 @@ public class DetailsFragment extends SherlockFragment {
torrentDetails = null;
torrentFiles = null;
}
-
+
+ /**
+ * Updates the shown screen depending on whether the torrent is loading
+ * @param isLoading True if the torrent is (re)loading, false otherwise
+ */
+ public void updateIsLoading(boolean isLoading) {
+ this.isLoadingTorrent = isLoading;
+ if (isLoadingTorrent)
+ clear();
+ }
+
@Override
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
diff --git a/core/src/org/transdroid/core/gui/TorrentsActivity.java b/core/src/org/transdroid/core/gui/TorrentsActivity.java
index 3c6a5878..dd45f2a1 100644
--- a/core/src/org/transdroid/core/gui/TorrentsActivity.java
+++ b/core/src/org/transdroid/core/gui/TorrentsActivity.java
@@ -19,6 +19,7 @@ import org.transdroid.core.app.settings.ApplicationSettings;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.core.gui.lists.SimpleListItem;
+import org.transdroid.core.gui.log.Log;
import org.transdroid.core.gui.navigation.*;
import org.transdroid.core.gui.navigation.NavigationSelectionView.NavigationFilterManager;
import org.transdroid.core.gui.settings.*;
@@ -323,7 +324,9 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
@Background
protected void refreshTorrents() {
+ fragmentTorrents.updateIsLoading(true);
DaemonTaskResult result = RetrieveTask.create(currentConnection).execute();
+ fragmentTorrents.updateIsLoading(false);
if (result instanceof RetrieveTaskSuccessResult) {
onTorrentsRetrieved(((RetrieveTaskSuccessResult) result).getTorrents(), ((RetrieveTaskSuccessResult) result).getLabels());
} else {
@@ -454,6 +457,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
@UiThread
protected void onCommunicationError(DaemonTaskFailureResult result) {
+ Log.i(this, result.getException().toString());
// TODO: Properly report this error
Toast.makeText(this, getString(LocalTorrent.getResourceForDaemonException(result.getException())),
Toast.LENGTH_LONG).show();
diff --git a/core/src/org/transdroid/core/gui/TorrentsFragment.java b/core/src/org/transdroid/core/gui/TorrentsFragment.java
index 4101c736..0a046aad 100644
--- a/core/src/org/transdroid/core/gui/TorrentsFragment.java
+++ b/core/src/org/transdroid/core/gui/TorrentsFragment.java
@@ -7,6 +7,7 @@ import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.InstanceState;
import org.androidannotations.annotations.ItemClick;
+import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;
import org.transdroid.core.R;
import org.transdroid.core.gui.lists.*;
@@ -172,10 +173,20 @@ public class TorrentsFragment extends SherlockFragment {
this.hasAConnection = hasAConnection;
if (!hasAConnection)
clear();
- updateViewVisibility();
}
-
- private void updateViewVisibility() {
+
+ /**
+ * Updates the shown screen depending on whether the torrents are loading
+ * @param isLoading True if the list of torrents is (re)loading, false otherwise
+ */
+ public void updateIsLoading(boolean isLoading) {
+ this.isLoading = isLoading;
+ if (isLoading)
+ clear();
+ }
+
+ @UiThread
+ protected void updateViewVisibility() {
if (!hasAConnection) {
torrentsList.setVisibility(View.GONE);
emptyText.setVisibility(View.GONE);
diff --git a/core/src/org/transdroid/core/gui/log/DatabaseHelper.java b/core/src/org/transdroid/core/gui/log/DatabaseHelper.java
new file mode 100644
index 00000000..d95cd00a
--- /dev/null
+++ b/core/src/org/transdroid/core/gui/log/DatabaseHelper.java
@@ -0,0 +1,51 @@
+package org.transdroid.core.gui.log;
+
+import java.sql.SQLException;
+
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+import android.util.Log;
+
+import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
+import com.j256.ormlite.support.ConnectionSource;
+import com.j256.ormlite.table.TableUtils;
+
+/**
+ * Helper to access the database to access persisting objects.
+ * @author Eric Kok
+ */
+public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
+
+ private static final String DATABASE_NAME = "transdroid.db";
+ private static final int DATABASE_VERSION = 1;
+
+ public DatabaseHelper(Context context) {
+ super(context, DATABASE_NAME, null, DATABASE_VERSION);
+ }
+
+ @Override
+ public void onCreate(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource) {
+ try {
+ TableUtils.createTable(connectionSource, ErrorLogEntry.class);
+ } catch (SQLException e) {
+ Log.e(org.transdroid.core.gui.log.Log.LOG_NAME, "Could not create new table for ErrorLogEntry", e);
+ }
+ }
+
+ @Override
+ public void onUpgrade(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource, int oldVersion,
+ int newVersion) {
+ try {
+ switch (oldVersion) {
+ case 1:
+ TableUtils.createTable(connectionSource, ErrorLogEntry.class);
+ /*case 1:
+ etc...*/
+ }
+
+ } catch (SQLException e) {
+ Log.e(org.transdroid.core.gui.log.Log.LOG_NAME, "Could not upgrade the table for ErrorLogEntry", e);
+ }
+ }
+
+}
diff --git a/core/src/org/transdroid/core/gui/log/ErrorLogEntry.java b/core/src/org/transdroid/core/gui/log/ErrorLogEntry.java
new file mode 100644
index 00000000..b14656a2
--- /dev/null
+++ b/core/src/org/transdroid/core/gui/log/ErrorLogEntry.java
@@ -0,0 +1,92 @@
+package org.transdroid.core.gui.log;
+
+import java.util.Date;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import com.j256.ormlite.field.DatabaseField;
+import com.j256.ormlite.table.DatabaseTable;
+
+/**
+ * Represents an error log entry to be registered in the database.
+ * @author Eric Kok
+ */
+@DatabaseTable(tableName = "ErrorLogEntry")
+public class ErrorLogEntry implements Parcelable {
+
+ public static final String ID = "logId";
+ public static final String DATEANDTIME = "dateAndTime";
+
+ @DatabaseField(id = true, columnName = ID)
+ private Integer logId;
+ @DatabaseField(columnName = DATEANDTIME)
+ private Date dateAndTime;
+ @DatabaseField
+ private Integer priority;
+ @DatabaseField
+ private String tag;
+ @DatabaseField
+ private String message;
+
+ public ErrorLogEntry() {
+ }
+
+ public ErrorLogEntry(Integer priority, String tag, String message) {
+ this.dateAndTime = new Date();
+ this.priority = priority;
+ this.tag = tag;
+ this.message = message;
+ }
+
+ public Integer getLogId() {
+ return logId;
+ }
+
+ public Date getDateAndTime() {
+ return dateAndTime;
+ }
+
+ public Integer getPriority() {
+ return priority;
+ }
+
+ public String getTag() {
+ return tag;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public int describeContents() {
+ return 0;
+ }
+
+ public void writeToParcel(Parcel out, int flags) {
+ out.writeInt(logId);
+ out.writeLong(dateAndTime.getTime());
+ out.writeInt(priority);
+ out.writeString(tag);
+ out.writeString(message);
+ }
+
+ public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
+ public ErrorLogEntry createFromParcel(Parcel in) {
+ return new ErrorLogEntry(in);
+ }
+
+ public ErrorLogEntry[] newArray(int size) {
+ return new ErrorLogEntry[size];
+ }
+ };
+
+ private ErrorLogEntry(Parcel in) {
+ logId = in.readInt();
+ dateAndTime = new Date(in.readLong());
+ priority = in.readInt();
+ tag = in.readString();
+ message = in.readString();
+ }
+
+}
diff --git a/core/src/org/transdroid/core/gui/log/ErrorLogSender.java b/core/src/org/transdroid/core/gui/log/ErrorLogSender.java
new file mode 100644
index 00000000..26fcc129
--- /dev/null
+++ b/core/src/org/transdroid/core/gui/log/ErrorLogSender.java
@@ -0,0 +1,73 @@
+package org.transdroid.core.gui.log;
+
+import java.sql.SQLException;
+import java.util.List;
+
+import org.androidannotations.annotations.Bean;
+import org.androidannotations.annotations.EBean;
+import org.androidannotations.annotations.OrmLiteDao;
+import org.transdroid.core.R;
+import org.transdroid.core.app.settings.ServerSetting;
+import org.transdroid.core.gui.navigation.NavigationHelper;
+
+import android.app.Activity;
+import android.content.ActivityNotFoundException;
+import android.content.Intent;
+
+import com.j256.ormlite.dao.Dao;
+
+@EBean
+public class ErrorLogSender {
+
+ @Bean
+ protected NavigationHelper navigationHelper;
+ @OrmLiteDao(helper = DatabaseHelper.class, model = ErrorLogEntry.class)
+ protected Dao errorLogDao;
+
+ public void collectAndSendLog(final Activity callingActivity, final ServerSetting serverSetting) {
+
+ try {
+
+ // Prepare an email with error logging information
+ StringBuilder body = new StringBuilder();
+ body.append("Please describe your problem:\n\n\n");
+ body.append("\n");
+ body.append(navigationHelper.getAppNameAndVersion());
+ body.append("\n");
+ body.append(serverSetting.getType().toString());
+ body.append(" settings: ");
+ body.append(serverSetting.getHumanReadableIdentifier());
+ body.append("\n\nConnection and error log:");
+
+ // Print the individual error log messages as stored in the database
+ List all = errorLogDao.queryBuilder().orderBy(ErrorLogEntry.ID, true).query();
+ for (ErrorLogEntry errorLogEntry : all) {
+ body.append("\n");
+ body.append(errorLogEntry.getLogId());
+ body.append(" -- ");
+ body.append(errorLogEntry.getDateAndTime());
+ body.append(" -- ");
+ body.append(errorLogEntry.getPriority());
+ body.append(" -- ");
+ body.append(errorLogEntry.getMessage());
+ }
+
+ Intent target = new Intent(Intent.ACTION_SEND);
+ target.setType("message/rfc822");
+ target.putExtra(Intent.EXTRA_EMAIL, new String[] { "transdroid.org@gmail.com" });
+ target.putExtra(Intent.EXTRA_SUBJECT, "Transdroid error report");
+ target.putExtra(Intent.EXTRA_TEXT, body.toString());
+ try {
+ callingActivity.startActivity(Intent.createChooser(target,
+ callingActivity.getString(R.string.pref_sendlog)).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
+ } catch (ActivityNotFoundException e) {
+ Log.i(callingActivity, "Tried to send error log, but there is no email app installed.");
+ }
+
+ } catch (SQLException e) {
+ Log.e(callingActivity, "Cannot read the error log to build an error report to send: " + e.toString());
+ }
+
+ }
+
+}
diff --git a/core/src/org/transdroid/core/gui/log/Log.java b/core/src/org/transdroid/core/gui/log/Log.java
new file mode 100644
index 00000000..809374ca
--- /dev/null
+++ b/core/src/org/transdroid/core/gui/log/Log.java
@@ -0,0 +1,54 @@
+package org.transdroid.core.gui.log;
+
+import java.sql.SQLException;
+import java.util.Date;
+
+import org.androidannotations.annotations.EBean;
+import org.androidannotations.annotations.EBean.Scope;
+import org.androidannotations.annotations.OrmLiteDao;
+
+import android.content.Context;
+
+import com.j256.ormlite.dao.Dao;
+import com.j256.ormlite.stmt.DeleteBuilder;
+
+/**
+ * Application-wide logging class that registers entries in the database (for a certain time).
+ * @author Eric Kok
+ */
+@EBean(scope = Scope.Singleton)
+public class Log {
+
+ public static final String LOG_NAME = "Transdroid";
+ private static final long MAX_LOG_AGE = 15 * 60 * 1000; // 15 minutes
+
+ @OrmLiteDao(helper = DatabaseHelper.class, model = ErrorLogEntry.class)
+ Dao errorLogDao;
+
+ protected void log(String logName, int priority, String message) {
+ android.util.Log.println(priority, LOG_NAME, message);
+ try {
+ // Store this log message to the database
+ errorLogDao.create(new ErrorLogEntry(priority, logName, message));
+ // Truncate the error log
+ DeleteBuilder db = errorLogDao.deleteBuilder();
+ db.setWhere(db.where().le(ErrorLogEntry.DATEANDTIME, new Date(new Date().getTime() - MAX_LOG_AGE)));
+ errorLogDao.delete(db.prepare());
+ } catch (SQLException e) {
+ android.util.Log.e(LOG_NAME, "Cannot write log message to database: " + e.toString());
+ }
+ }
+
+ public static void e(Context caller, String message) {
+ Log_.getInstance_(caller).log(caller.getClass().toString(), android.util.Log.ERROR, message);
+ }
+
+ public static void i(Context caller, String message) {
+ Log_.getInstance_(caller).log(caller.getClass().toString(), android.util.Log.INFO, message);
+ }
+
+ public static void d(Context caller, String message) {
+ Log_.getInstance_(caller).log(caller.getClass().toString(), android.util.Log.DEBUG, message);
+ }
+
+}
diff --git a/core/src/org/transdroid/core/gui/navigation/DialogHolderActivity.java b/core/src/org/transdroid/core/gui/navigation/DialogHolderActivity.java
new file mode 100644
index 00000000..43451eca
--- /dev/null
+++ b/core/src/org/transdroid/core/gui/navigation/DialogHolderActivity.java
@@ -0,0 +1,53 @@
+package org.transdroid.core.gui.navigation;
+
+import org.androidannotations.annotations.AfterViews;
+import org.androidannotations.annotations.EActivity;
+import org.androidannotations.annotations.Extra;
+import org.transdroid.core.gui.log.Log;
+
+import android.content.Context;
+import android.support.v4.app.DialogFragment;
+import android.support.v4.app.FragmentTransaction;
+
+import com.actionbarsherlock.app.SherlockFragmentActivity;
+
+@EActivity(resName = "activity_dialogholder")
+public class DialogHolderActivity extends SherlockFragmentActivity {
+
+ @Extra
+ protected String dialogType;
+
+ /**
+ * Use this method to show some dialog; it will show the dialog as full screen fragment on smaller devices. Use the
+ * DialogFragment's class here only; a new instance will be created by this holder activity.
+ */
+ public static void showDialog(Context context, Class extends DialogFragment> dialogType) {
+ DialogHolderActivity_.intent(context).start();
+ }
+
+ @AfterViews
+ public void init() {
+ try {
+ // Instantiate an instance of the requested dialog
+ DialogFragment dialog = (DialogFragment) Class.forName(dialogType).newInstance();
+ // Determine if the dialog should be shown as full size screen
+ boolean isSmall = NavigationHelper_.getInstance_(this).isSmallScreen();
+ if (!isSmall) {
+ // Show as normal dialog
+ dialog.show(this.getSupportFragmentManager(), "about_dialog");
+ } else {
+ // Small device, so show the fragment full screen
+ FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
+ // Note: the fragment is not added to the back stack, as this activity already is
+ ft.add(android.R.id.content, dialog).commit();
+ }
+ } catch (InstantiationException e) {
+ Log.e(this, "Tried to show a dialog of type " + dialogType + ", but that cannot be instantiated.");
+ } catch (IllegalAccessException e) {
+ Log.e(this, "Tried to show a dialog of type " + dialogType + ", but it is not accessible.");
+ } catch (ClassNotFoundException e) {
+ Log.e(this, "Tried to show a dialog of type " + dialogType + ", but that class doesn't exist.");
+ }
+ }
+
+}
diff --git a/core/src/org/transdroid/core/gui/navigation/NavigationHelper.java b/core/src/org/transdroid/core/gui/navigation/NavigationHelper.java
index 0d71a040..cb271715 100644
--- a/core/src/org/transdroid/core/gui/navigation/NavigationHelper.java
+++ b/core/src/org/transdroid/core/gui/navigation/NavigationHelper.java
@@ -2,9 +2,12 @@ package org.transdroid.core.gui.navigation;
import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;
+import org.transdroid.core.R;
import android.annotation.TargetApi;
import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
@EBean
@@ -13,6 +16,31 @@ public class NavigationHelper {
@RootContext
protected Context context;
+ /**
+ * Whether any search-related UI components should be shown in the interface. At the moment returns false only if we
+ * run as Transdroid Lite version.
+ * @return True if search is enabled, false otherwise
+ */
+ public String getAppNameAndVersion() {
+ String appName = context.getString(R.string.app_name);
+ try {
+ PackageInfo m = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
+ return appName + " " + m.versionName + " (" + m.versionCode + ")";
+ } catch (NameNotFoundException e) {
+ return appName;
+ }
+ }
+
+ /**
+ * Returns whether the device is considered small (i.e. a phone) rather than large (i.e. a tablet). Can, for example,
+ * be used to determine if a dialog should be shown full screen. Currently is true if the device's smallest
+ * dimension is 500 dip.
+ * @return True if the app runs on a small device, false otherwise
+ */
+ public boolean isSmallScreen() {
+ return context.getResources().getBoolean(R.bool.small_screen);
+ }
+
/**
* Whether any search-related UI components should be shown in the interface. At the moment returns false only if we
* run as Transdroid Lite version.
diff --git a/core/src/org/transdroid/core/gui/settings/SystemSettingsActivity.java b/core/src/org/transdroid/core/gui/settings/SystemSettingsActivity.java
index 7f697f93..bcb29689 100644
--- a/core/src/org/transdroid/core/gui/settings/SystemSettingsActivity.java
+++ b/core/src/org/transdroid/core/gui/settings/SystemSettingsActivity.java
@@ -4,12 +4,16 @@ import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity;
import org.transdroid.core.R;
import org.transdroid.core.app.settings.ApplicationSettings;
+import org.transdroid.core.gui.AboutFragment;
+import org.transdroid.core.gui.log.ErrorLogSender;
+import org.transdroid.core.gui.navigation.DialogHolderActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
+import android.widget.Toast;
import com.actionbarsherlock.app.SherlockPreferenceActivity;
@@ -20,6 +24,8 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity {
@Bean
protected ApplicationSettings applicationSettings;
+ @Bean
+ protected ErrorLogSender errorLogSender;
@SuppressWarnings("deprecation")
@Override
@@ -39,7 +45,7 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity {
private OnPreferenceClickListener onSendLogClick = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
- // TODO: Implement error log collection and sending
+ errorLogSender.collectAndSendLog(SystemSettingsActivity.this, applicationSettings.getLastUsedServer());
return true;
}
};
@@ -55,7 +61,8 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity {
private OnPreferenceClickListener onChangeLogClick = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
- // TODO: Implement about change log screen
+ // TODO: Implement change log screen
+ Toast.makeText(SystemSettingsActivity.this, "TODO: Implement change log screen", Toast.LENGTH_LONG).show();
return true;
}
};
@@ -63,7 +70,7 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity {
private OnPreferenceClickListener onAboutClick = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
- // TODO: Implement about screen with app version, developer name and used open source libraries
+ DialogHolderActivity.showDialog(SystemSettingsActivity.this, AboutFragment.class);
return true;
}
};