<application\r
android:icon="@drawable/icon"\r
android:label="@string/app_name"\r
- android:theme="@style/Theme.ownCloud"\r
- android:uiOptions="splitActionBarWhenNarrow"> \r
+ android:theme="@style/Theme.ownCloud"> \r
<activity\r
android:name=".ui.activity.FileDisplayActivity"\r
android:label="@string/app_name">\r
android:theme="@style/Theme.ownCloud.noActionBar" >\r
</activity>\r
\r
- <service android:name=".FileDownloader" >\r
+ <service android:name=".files.services.FileDownloader" >\r
</service>\r
<service android:name=".location.LocationUpdateService" >\r
<intent-filter>\r
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:id="@+id/startSync" android:title="@string/actionbar_sync" android:showAsAction="ifRoom" android:icon="@drawable/ic_action_refresh"></item>
- <item android:id="@+id/createDirectoryItem" android:title="@string/actionbar_mkdir" android:icon="@drawable/ic_action_create_dir" android:showAsAction="ifRoom"></item>
+ <item android:id="@+id/startSync" android:title="@string/actionbar_sync" android:icon="@drawable/ic_action_refresh"></item>
+ <item android:id="@+id/createDirectoryItem" android:title="@string/actionbar_mkdir" android:icon="@drawable/ic_action_create_dir"></item>
- <item android:id="@+id/search" android:title="@string/actionbar_search" android:icon="@drawable/ic_action_search" android:showAsAction="ifRoom"></item>
- <item android:id="@+id/action_upload" android:title="@string/actionbar_upload" android:icon="@drawable/ic_action_upload" android:showAsAction="ifRoom"></item>
- <item android:id="@+id/action_accounts" android:title="@string/actionbar_settings" android:icon="@android:drawable/ic_menu_preferences" android:showAsAction="ifRoom"></item>
+ <item android:id="@+id/search" android:title="@string/actionbar_search" android:icon="@drawable/ic_action_search"></item>
+ <item android:id="@+id/action_upload" android:title="@string/actionbar_upload" android:icon="@drawable/ic_action_upload"></item>
+ <item android:id="@+id/action_accounts" android:title="@string/actionbar_settings" android:icon="@android:drawable/ic_menu_preferences"></item>
</menu>
+++ /dev/null
-package eu.alefzero.owncloud;\r
-\r
-import java.io.File;\r
-\r
-import android.accounts.Account;\r
-import android.accounts.AccountManager;\r
-import android.app.Notification;\r
-import android.app.NotificationManager;\r
-import android.app.PendingIntent;\r
-import android.app.Service;\r
-import android.content.ContentValues;\r
-import android.content.Intent;\r
-import android.net.Uri;\r
-import android.os.Environment;\r
-import android.os.Handler;\r
-import android.os.HandlerThread;\r
-import android.os.IBinder;\r
-import android.os.Looper;\r
-import android.os.Message;\r
-import android.os.Process;\r
-import android.util.Log;\r
-import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
-import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;\r
-import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;\r
-import eu.alefzero.owncloud.utils.OwnCloudVersion;\r
-import eu.alefzero.webdav.WebdavClient;\r
-\r
-public class FileDownloader extends Service {\r
- public static final String DOWNLOAD_FINISH_MESSAGE = "DOWNLOAD_FINISH";\r
- public static final String EXTRA_ACCOUNT = "ACCOUNT";\r
- public static final String EXTRA_FILE_PATH = "FILE_PATH";\r
- private static final String TAG = "FileDownloader";\r
-\r
- private NotificationManager nm;\r
- private Looper mServiceLooper;\r
- private ServiceHandler mServiceHandler;\r
- private Account mAccount;\r
- private String mFilePath;\r
-\r
- private final class ServiceHandler extends Handler {\r
- public ServiceHandler(Looper looper) {\r
- super(looper);\r
- }\r
-\r
- @Override\r
- public void handleMessage(Message msg) {\r
- downloadFile();\r
- stopSelf(msg.arg1);\r
- }\r
- }\r
-\r
- @Override\r
- public void onCreate() {\r
- super.onCreate();\r
- nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);\r
- HandlerThread thread = new HandlerThread("FileDownladerThread",\r
- Process.THREAD_PRIORITY_BACKGROUND);\r
- thread.start();\r
- mServiceLooper = thread.getLooper();\r
- mServiceHandler = new ServiceHandler(mServiceLooper);\r
- }\r
-\r
- @Override\r
- public IBinder onBind(Intent arg0) {\r
- return null;\r
- }\r
-\r
- @Override\r
- public int onStartCommand(Intent intent, int flags, int startId) {\r
- if (!intent.hasExtra(EXTRA_ACCOUNT)\r
- && !intent.hasExtra(EXTRA_FILE_PATH)) {\r
- Log.e(TAG, "Not enough information provided in intent");\r
- return START_STICKY;\r
- }\r
- mAccount = intent.getParcelableExtra(EXTRA_ACCOUNT);\r
- mFilePath = intent.getStringExtra(EXTRA_FILE_PATH);\r
- Message msg = mServiceHandler.obtainMessage();\r
- msg.arg1 = startId;\r
- mServiceHandler.sendMessage(msg);\r
-\r
- return START_NOT_STICKY;\r
- }\r
-\r
- void downloadFile() {\r
- AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE);\r
- String oc_base_url = am.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL);\r
- OwnCloudVersion ocv = new OwnCloudVersion(am\r
- .getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION));\r
- String webdav_path = AccountUtils.getWebdavPath(ocv);\r
- Uri oc_url = Uri.parse(oc_base_url+webdav_path);\r
-\r
- WebdavClient wdc = new WebdavClient(Uri.parse(oc_base_url + webdav_path));\r
-\r
- String username = mAccount.name.split("@")[0];\r
- String password = "";\r
- try {\r
- password = am.blockingGetAuthToken(mAccount,\r
- AccountAuthenticator.AUTH_TOKEN_TYPE, true);\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- return;\r
- }\r
-\r
- wdc.setCredentials(username, password);\r
- wdc.allowUnsignedCertificates();\r
-\r
- Notification n = new Notification(R.drawable.icon, "Downloading file",\r
- System.currentTimeMillis());\r
- PendingIntent pi = PendingIntent.getActivity(this, 1, new Intent(this,\r
- FileDisplayActivity.class), 0);\r
- n.setLatestEventInfo(this, "Downloading file", "Downloading file "\r
- + mFilePath, pi);\r
- nm.notify(1, n);\r
-\r
- File sdCard = Environment.getExternalStorageDirectory();\r
- File dir = new File(sdCard.getAbsolutePath() + "/owncloud");\r
- dir.mkdirs();\r
- File file = new File(dir, mFilePath.replace('/', '.'));\r
-\r
- Log.e(TAG, file.getAbsolutePath() + " " + oc_url.toString());\r
- Log.e(TAG, mFilePath+"");\r
- if (wdc.downloadFile(mFilePath, file)) {\r
- ContentValues cv = new ContentValues();\r
- cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getAbsolutePath());\r
- getContentResolver().update(\r
- ProviderTableMeta.CONTENT_URI,\r
- cv,\r
- ProviderTableMeta.FILE_NAME + "=? AND "\r
- + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",\r
- new String[] {\r
- mFilePath.substring(mFilePath.lastIndexOf('/') + 1),\r
- mAccount.name }); \r
- }\r
- nm.cancel(1);\r
- Intent end = new Intent(DOWNLOAD_FINISH_MESSAGE);\r
- sendBroadcast(end);\r
- }\r
-\r
-}\r
\r
WebdavClient wdc = new WebdavClient(oc_uri);\r
wdc.setCredentials(mUsername, mPassword);\r
- wdc.allowUnsignedCertificates();\r
+ wdc.allowSelfsignedCertificates();\r
\r
// create last directory in path if nessesary\r
if (mCreateDir) {\r
private boolean tryConnection(Uri uri) {
WebdavClient wc = new WebdavClient(uri);
- wc.allowUnsignedCertificates();
+ wc.allowSelfsignedCertificates();
GetMethod get = new GetMethod(uri.toString());
boolean retval = false;
try {
--- /dev/null
+package eu.alefzero.owncloud.files.interfaces;
+
+public interface OnDatatransferProgressListener {
+ void transferProgress(long progressRate);
+
+}
--- /dev/null
+package eu.alefzero.owncloud.files.services;\r
+\r
+import java.io.File;\r
+\r
+import android.accounts.Account;\r
+import android.accounts.AccountManager;\r
+import android.app.Notification;\r
+import android.app.NotificationManager;\r
+import android.app.PendingIntent;\r
+import android.app.Service;\r
+import android.content.ContentValues;\r
+import android.content.Intent;\r
+import android.net.Uri;\r
+import android.os.Environment;\r
+import android.os.Handler;\r
+import android.os.HandlerThread;\r
+import android.os.IBinder;\r
+import android.os.Looper;\r
+import android.os.Message;\r
+import android.os.Process;\r
+import android.util.Log;\r
+import android.widget.RemoteViews;\r
+import eu.alefzero.owncloud.AccountUtils;\r
+import eu.alefzero.owncloud.R;\r
+import eu.alefzero.owncloud.R.drawable;\r
+import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
+import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;\r
+import eu.alefzero.owncloud.files.interfaces.OnDatatransferProgressListener;\r
+import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;\r
+import eu.alefzero.owncloud.utils.OwnCloudVersion;\r
+import eu.alefzero.webdav.WebdavClient;\r
+\r
+public class FileDownloader extends Service implements OnDatatransferProgressListener {\r
+ public static final String DOWNLOAD_FINISH_MESSAGE = "DOWNLOAD_FINISH";\r
+ public static final String EXTRA_ACCOUNT = "ACCOUNT";\r
+ public static final String EXTRA_FILE_PATH = "FILE_PATH";\r
+ public static final String EXTRA_FILE_SIZE = "FILE_SIZE";\r
+ private static final String TAG = "FileDownloader";\r
+\r
+ private NotificationManager mNotificationMngr;\r
+ private Looper mServiceLooper;\r
+ private ServiceHandler mServiceHandler;\r
+ private Account mAccount;\r
+ private String mFilePath;\r
+ private int mLastPercent;\r
+ private long mTotalDownloadSize;\r
+ private long mCurrentDownlodSize;\r
+ private Notification mNotification;\r
+\r
+ private final class ServiceHandler extends Handler {\r
+ public ServiceHandler(Looper looper) {\r
+ super(looper);\r
+ }\r
+\r
+ @Override\r
+ public void handleMessage(Message msg) {\r
+ downloadFile();\r
+ stopSelf(msg.arg1);\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void onCreate() {\r
+ super.onCreate();\r
+ mNotificationMngr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);\r
+ HandlerThread thread = new HandlerThread("FileDownladerThread",\r
+ Process.THREAD_PRIORITY_BACKGROUND);\r
+ thread.start();\r
+ mServiceLooper = thread.getLooper();\r
+ mServiceHandler = new ServiceHandler(mServiceLooper);\r
+ }\r
+\r
+ @Override\r
+ public IBinder onBind(Intent arg0) {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public int onStartCommand(Intent intent, int flags, int startId) {\r
+ if (!intent.hasExtra(EXTRA_ACCOUNT)\r
+ && !intent.hasExtra(EXTRA_FILE_PATH)) {\r
+ Log.e(TAG, "Not enough information provided in intent");\r
+ return START_STICKY;\r
+ }\r
+ mAccount = intent.getParcelableExtra(EXTRA_ACCOUNT);\r
+ mFilePath = intent.getStringExtra(EXTRA_FILE_PATH);\r
+ Message msg = mServiceHandler.obtainMessage();\r
+ msg.arg1 = startId;\r
+ mServiceHandler.sendMessage(msg);\r
+ mCurrentDownlodSize = mLastPercent = 0;\r
+ mTotalDownloadSize = intent.getLongExtra(EXTRA_FILE_SIZE, -1);\r
+\r
+ return START_NOT_STICKY;\r
+ }\r
+\r
+ void downloadFile() {\r
+ AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE);\r
+ String oc_base_url = am.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL);\r
+ OwnCloudVersion ocv = new OwnCloudVersion(am\r
+ .getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION));\r
+ String webdav_path = AccountUtils.getWebdavPath(ocv);\r
+ Uri oc_url = Uri.parse(oc_base_url+webdav_path);\r
+\r
+ WebdavClient wdc = new WebdavClient(Uri.parse(oc_base_url + webdav_path));\r
+ \r
+ String username = mAccount.name.split("@")[0];\r
+ String password = "";\r
+ try {\r
+ password = am.blockingGetAuthToken(mAccount,\r
+ AccountAuthenticator.AUTH_TOKEN_TYPE, true);\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ return;\r
+ }\r
+\r
+ wdc.setCredentials(username, password);\r
+ wdc.allowSelfsignedCertificates();\r
+ wdc.setDataTransferProgressListener(this);\r
+\r
+ mNotification = new Notification(R.drawable.icon, "Downloading file", System.currentTimeMillis());\r
+\r
+ mNotification.flags |= Notification.FLAG_ONGOING_EVENT;\r
+ mNotification.contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.progressbar_layout);\r
+ mNotification.contentView.setProgressBar(R.id.status_progress, 100, 0, mTotalDownloadSize == -1);\r
+ mNotification.contentView.setImageViewResource(R.id.status_icon, R.drawable.icon);\r
+ \r
+ mNotificationMngr.notify(1, mNotification);\r
+\r
+ File sdCard = Environment.getExternalStorageDirectory();\r
+ File dir = new File(sdCard.getAbsolutePath() + "/owncloud");\r
+ dir.mkdirs();\r
+ File file = new File(dir, mFilePath.replace('/', '.'));\r
+\r
+ Log.e(TAG, file.getAbsolutePath() + " " + oc_url.toString());\r
+ Log.e(TAG, mFilePath+"");\r
+ if (wdc.downloadFile(mFilePath, file)) {\r
+ ContentValues cv = new ContentValues();\r
+ cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getAbsolutePath());\r
+ getContentResolver().update(\r
+ ProviderTableMeta.CONTENT_URI,\r
+ cv,\r
+ ProviderTableMeta.FILE_NAME + "=? AND "\r
+ + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",\r
+ new String[] {\r
+ mFilePath.substring(mFilePath.lastIndexOf('/') + 1),\r
+ mAccount.name }); \r
+ }\r
+ mNotificationMngr.cancel(1);\r
+ Intent end = new Intent(DOWNLOAD_FINISH_MESSAGE);\r
+ sendBroadcast(end);\r
+ }\r
+\r
+ @Override\r
+ public void transferProgress(long progressRate) {\r
+ mCurrentDownlodSize += progressRate;\r
+ int percent = (int)(100.0*((double)mCurrentDownlodSize)/((double)mTotalDownloadSize));\r
+ if (percent != mLastPercent) {\r
+ mNotification.contentView.setProgressBar(R.id.status_progress, 100, (int)(100*mCurrentDownlodSize/mTotalDownloadSize), mTotalDownloadSize == -1);\r
+ mNotification.contentView.setTextViewText(R.id.status_text, percent+"%");\r
+ mNotificationMngr.notify(1, mNotification);\r
+ }\r
+ \r
+ mLastPercent = percent;\r
+ }\r
+\r
+}\r
mNotificationManager.notify(42, mNotification);
WebdavClient wc = new WebdavClient(ocUri);
- wc.allowUnsignedCertificates();
+ wc.allowSelfsignedCertificates();
wc.setUploadListener(this);
wc.setCredentials(username, password);
\r
mClient = new WebdavClient(uri);\r
mClient.setCredentials(username, password);\r
- mClient.allowUnsignedCertificates();\r
+ mClient.allowSelfsignedCertificates();\r
// mHost = mClient.getTargetHost();\r
}\r
\r
\r
@Override\r
public boolean onCreateOptionsMenu(Menu menu) {\r
- if (accountsAreSetup()) {\r
- MenuInflater inflater = getSherlock().getMenuInflater();\r
+ MenuInflater inflater = getSherlock().getMenuInflater();\r
inflater.inflate(R.menu.menu, menu);\r
return true;\r
- }\r
- return false;\r
}\r
\r
@Override\r
\r
@Override\r
public void onBackPressed() {\r
- if (mDirectories == null || mDirectories.getCount() == 1) {\r
+ if (mDirectories == null || mDirectories.getCount() <= 1) {\r
finish();\r
return;\r
}\r
String password = mAm.getPassword(mAccount);\r
\r
wdc.setCredentials(username, password);\r
- wdc.allowUnsignedCertificates();\r
+ wdc.allowSelfsignedCertificates();\r
wdc.createDirectory(mTargetPath);\r
}\r
\r
import com.actionbarsherlock.app.SherlockFragment;\r
\r
import eu.alefzero.owncloud.DisplayUtils;\r
-import eu.alefzero.owncloud.FileDownloader;\r
import eu.alefzero.owncloud.R;\r
import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
import eu.alefzero.owncloud.datamodel.OCFile;\r
+import eu.alefzero.owncloud.files.services.FileDownloader;\r
import eu.alefzero.owncloud.utils.OwnCloudVersion;\r
\r
/**\r
i.putExtra(FileDownloader.EXTRA_ACCOUNT,\r
mIntent.getParcelableExtra(FileDownloader.EXTRA_ACCOUNT));\r
i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getRemotePath());\r
+ i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength());\r
getActivity().startService(i);\r
}\r
\r
import android.widget.AdapterView;\r
import android.widget.Toast;\r
import eu.alefzero.owncloud.AccountUtils;\r
-import eu.alefzero.owncloud.FileDownloader;\r
import eu.alefzero.owncloud.R;\r
import eu.alefzero.owncloud.datamodel.DataStorageManager;\r
import eu.alefzero.owncloud.datamodel.FileDataStorageManager;\r
import eu.alefzero.owncloud.datamodel.OCFile;\r
+import eu.alefzero.owncloud.files.services.FileDownloader;\r
import eu.alefzero.owncloud.ui.FragmentListView;\r
import eu.alefzero.owncloud.ui.activity.FileDetailActivity;\r
import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;\r
import org.apache.jackrabbit.webdav.client.methods.MkColMethod;\r
\r
import eu.alefzero.owncloud.authenticator.EasySSLSocketFactory;\r
+import eu.alefzero.owncloud.files.interfaces.OnDatatransferProgressListener;\r
\r
import android.net.Uri;\r
import android.util.Log;\r
final private static String TAG = "WebdavClient";\r
private static final String USER_AGENT = "Android-ownCloud";\r
private OnUploadProgressListener mUploadProgressListener;\r
+ private OnDatatransferProgressListener mDataTransferListener;\r
\r
public WebdavClient(Uri uri) {\r
mUri = uri;\r
return mCredentials;\r
}\r
\r
- public void allowUnsignedCertificates() {\r
+ public void allowSelfsignedCertificates() {\r
// https\r
Protocol.registerProtocol("https", new Protocol("https",\r
new EasySSLSocketFactory(), 443));\r
get.getResponseBodyAsStream());\r
FileOutputStream fos = new FileOutputStream(targetPath);\r
\r
- byte[] bytes = new byte[512];\r
+ byte[] bytes = new byte[4096];\r
int readResult;\r
- while ((readResult = bis.read(bytes)) != -1)\r
+ while ((readResult = bis.read(bytes)) != -1) {\r
+ if (mDataTransferListener != null)\r
+ mDataTransferListener.transferProgress(readResult);\r
fos.write(bytes, 0, readResult);\r
+ }\r
\r
} catch (IOException e) {\r
e.printStackTrace();\r
mUploadProgressListener = listener;\r
}\r
\r
+ public void setDataTransferProgressListener(OnDatatransferProgressListener listener) {\r
+ mDataTransferListener = listener;\r
+ }\r
+ \r
public boolean putFile(String localFile, String remoteTarget,\r
String contentType) {\r
boolean result = true;\r