making file download using progressbar view
authorBartek Przybylski <bart.p.pl@gmail.com>
Sat, 26 May 2012 11:47:26 +0000 (13:47 +0200)
committerBartek Przybylski <bart.p.pl@gmail.com>
Sat, 26 May 2012 11:47:26 +0000 (13:47 +0200)
13 files changed:
AndroidManifest.xml
res/menu/menu.xml
src/eu/alefzero/owncloud/FileDownloader.java [deleted file]
src/eu/alefzero/owncloud/Uploader.java
src/eu/alefzero/owncloud/authenticator/ConnectionCheckerRunnable.java
src/eu/alefzero/owncloud/files/interfaces/OnDatatransferProgressListener.java [new file with mode: 0644]
src/eu/alefzero/owncloud/files/services/FileDownloader.java [new file with mode: 0644]
src/eu/alefzero/owncloud/files/services/FileUploader.java
src/eu/alefzero/owncloud/syncadapter/AbstractOwnCloudSyncAdapter.java
src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java
src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java
src/eu/alefzero/owncloud/ui/fragment/FileListFragment.java
src/eu/alefzero/webdav/WebdavClient.java

index 68def42..47f65c1 100644 (file)
@@ -45,8 +45,7 @@
     <application\r
         android:icon="@drawable/icon"\r
         android:label="@string/app_name"\r
     <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
         <activity\r
             android:name=".ui.activity.FileDisplayActivity"\r
             android:label="@string/app_name">\r
             android:theme="@style/Theme.ownCloud.noActionBar" >\r
         </activity>\r
 \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
         </service>\r
         <service android:name=".location.LocationUpdateService" >\r
             <intent-filter>\r
index 590eabd..5ec8ec0 100644 (file)
@@ -1,10 +1,10 @@
 <?xml version="1.0" encoding="utf-8"?>
 <menu
   xmlns:android="http://schemas.android.com/apk/res/android">
 <?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>
 </menu>
diff --git a/src/eu/alefzero/owncloud/FileDownloader.java b/src/eu/alefzero/owncloud/FileDownloader.java
deleted file mode 100644 (file)
index 1936e8e..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-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
index a63010a..a5d2316 100644 (file)
@@ -358,7 +358,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
 \r
         WebdavClient wdc = new WebdavClient(oc_uri);\r
         wdc.setCredentials(mUsername, mPassword);\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
 \r
         // create last directory in path if nessesary\r
         if (mCreateDir) {\r
index 66c6c3d..bc0ff78 100644 (file)
@@ -95,7 +95,7 @@ public class ConnectionCheckerRunnable implements Runnable {
 
     private boolean tryConnection(Uri uri) {
         WebdavClient wc = new WebdavClient(uri);
 
     private boolean tryConnection(Uri uri) {
         WebdavClient wc = new WebdavClient(uri);
-        wc.allowUnsignedCertificates();
+        wc.allowSelfsignedCertificates();
         GetMethod get = new GetMethod(uri.toString());
         boolean retval = false;
         try {
         GetMethod get = new GetMethod(uri.toString());
         boolean retval = false;
         try {
diff --git a/src/eu/alefzero/owncloud/files/interfaces/OnDatatransferProgressListener.java b/src/eu/alefzero/owncloud/files/interfaces/OnDatatransferProgressListener.java
new file mode 100644 (file)
index 0000000..4a897dd
--- /dev/null
@@ -0,0 +1,6 @@
+package eu.alefzero.owncloud.files.interfaces;
+
+public interface OnDatatransferProgressListener {
+    void transferProgress(long progressRate);
+
+}
diff --git a/src/eu/alefzero/owncloud/files/services/FileDownloader.java b/src/eu/alefzero/owncloud/files/services/FileDownloader.java
new file mode 100644 (file)
index 0000000..087b103
--- /dev/null
@@ -0,0 +1,166 @@
+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
index 30d91e1..f6e1c51 100644 (file)
@@ -147,7 +147,7 @@ public class FileUploader extends Service implements OnUploadProgressListener {
         mNotificationManager.notify(42, mNotification);
 
         WebdavClient wc = new WebdavClient(ocUri);
         mNotificationManager.notify(42, mNotification);
 
         WebdavClient wc = new WebdavClient(ocUri);
-        wc.allowUnsignedCertificates();
+        wc.allowSelfsignedCertificates();
         wc.setUploadListener(this);
         wc.setCredentials(username, password);
 
         wc.setUploadListener(this);
         wc.setCredentials(username, password);
 
index efd4c2b..2b11978 100644 (file)
@@ -160,7 +160,7 @@ public abstract class AbstractOwnCloudSyncAdapter extends
 \r
             mClient = new WebdavClient(uri);\r
             mClient.setCredentials(username, password);\r
 \r
             mClient = new WebdavClient(uri);\r
             mClient.setCredentials(username, password);\r
-            mClient.allowUnsignedCertificates();\r
+            mClient.allowSelfsignedCertificates();\r
             // mHost = mClient.getTargetHost();\r
         }\r
 \r
             // mHost = mClient.getTargetHost();\r
         }\r
 \r
index 2695321..dc564d6 100644 (file)
@@ -104,12 +104,9 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
 \r
     @Override\r
     public boolean onCreateOptionsMenu(Menu menu) {\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
             inflater.inflate(R.menu.menu, menu);\r
             return true;\r
-        }\r
-        return false;\r
     }\r
 \r
     @Override\r
     }\r
 \r
     @Override\r
@@ -206,7 +203,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
 \r
     @Override\r
     public void onBackPressed() {\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
             finish();\r
             return;\r
         }\r
@@ -499,7 +496,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
             String password = mAm.getPassword(mAccount);\r
     \r
             wdc.setCredentials(username, password);\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
             wdc.createDirectory(mTargetPath);\r
         }\r
     \r
index d2f5d10..2241f6f 100644 (file)
@@ -40,10 +40,10 @@ import android.widget.Toast;
 import com.actionbarsherlock.app.SherlockFragment;\r
 \r
 import eu.alefzero.owncloud.DisplayUtils;\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.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
 import eu.alefzero.owncloud.utils.OwnCloudVersion;\r
 \r
 /**\r
@@ -142,6 +142,7 @@ public class FileDetailFragment extends SherlockFragment implements
         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_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
         getActivity().startService(i);\r
     }\r
 \r
index d9ef3da..d5dae1c 100644 (file)
@@ -30,11 +30,11 @@ import android.view.View;
 import android.widget.AdapterView;\r
 import android.widget.Toast;\r
 import eu.alefzero.owncloud.AccountUtils;\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.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 eu.alefzero.owncloud.ui.FragmentListView;\r
 import eu.alefzero.owncloud.ui.activity.FileDetailActivity;\r
 import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;\r
index f7cc060..c4e0a9b 100644 (file)
@@ -38,6 +38,7 @@ import org.apache.http.HttpStatus;
 import org.apache.jackrabbit.webdav.client.methods.MkColMethod;\r
 \r
 import eu.alefzero.owncloud.authenticator.EasySSLSocketFactory;\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
 \r
 import android.net.Uri;\r
 import android.util.Log;\r
@@ -48,6 +49,7 @@ public class WebdavClient extends HttpClient {
     final private static String TAG = "WebdavClient";\r
     private static final String USER_AGENT = "Android-ownCloud";\r
     private OnUploadProgressListener mUploadProgressListener;\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
 \r
     public WebdavClient(Uri uri) {\r
         mUri = uri;\r
@@ -66,7 +68,7 @@ public class WebdavClient extends HttpClient {
         return mCredentials;\r
     }\r
 \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
         // https\r
         Protocol.registerProtocol("https", new Protocol("https",\r
                 new EasySSLSocketFactory(), 443));\r
@@ -99,10 +101,13 @@ public class WebdavClient extends HttpClient {
                     get.getResponseBodyAsStream());\r
             FileOutputStream fos = new FileOutputStream(targetPath);\r
 \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
             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
                 fos.write(bytes, 0, readResult);\r
+            }\r
 \r
         } catch (IOException e) {\r
             e.printStackTrace();\r
 \r
         } catch (IOException e) {\r
             e.printStackTrace();\r
@@ -115,6 +120,10 @@ public class WebdavClient extends HttpClient {
         mUploadProgressListener = listener;\r
     }\r
     \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
     public boolean putFile(String localFile, String remoteTarget,\r
             String contentType) {\r
         boolean result = true;\r