From: Bartek Przybylski Date: Sat, 19 May 2012 19:05:53 +0000 (+0200) Subject: adding open file button X-Git-Tag: oc-android-1.4.3~408 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/576e2923ccbb2175b7177b26aca90b4b4c0253d0?ds=inline;hp=--cc adding open file button --- 576e2923ccbb2175b7177b26aca90b4b4c0253d0 diff --git a/src/eu/alefzero/owncloud/FileDownloader.java b/src/eu/alefzero/owncloud/FileDownloader.java index b8fffbcf..3b5f198b 100644 --- a/src/eu/alefzero/owncloud/FileDownloader.java +++ b/src/eu/alefzero/owncloud/FileDownloader.java @@ -1,6 +1,7 @@ package eu.alefzero.owncloud; import java.io.File; +import java.net.URLEncoder; import android.accounts.Account; import android.accounts.AccountManager; @@ -22,6 +23,7 @@ import android.util.Log; import eu.alefzero.owncloud.authenticator.AccountAuthenticator; import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta; import eu.alefzero.owncloud.ui.activity.FileDisplayActivity; +import eu.alefzero.owncloud.utils.OwnCloudVersion; import eu.alefzero.webdav.WebdavClient; public class FileDownloader extends Service { @@ -82,10 +84,13 @@ public class FileDownloader extends Service { void downloadFile() { AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE); - Uri oc_url = Uri.parse(am.getUserData(mAccount, - AccountAuthenticator.KEY_OC_URL)); + String oc_base_url = am.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL); + OwnCloudVersion ocv = new OwnCloudVersion(am + .getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION)); + String webdav_path = AccountUtils.getWebdavPath(ocv); + Uri oc_url = Uri.parse(oc_base_url+webdav_path); - WebdavClient wdc = new WebdavClient(oc_url); + WebdavClient wdc = new WebdavClient(Uri.parse(oc_base_url + webdav_path)); String username = mAccount.name.split("@")[0]; String password = ""; @@ -94,6 +99,7 @@ public class FileDownloader extends Service { AccountAuthenticator.AUTH_TOKEN_TYPE, true); } catch (Exception e) { e.printStackTrace(); + return; } wdc.setCredentials(username, password); @@ -113,17 +119,19 @@ public class FileDownloader extends Service { File file = new File(dir, mFilePath.replace('/', '.')); Log.e(TAG, file.getAbsolutePath() + " " + oc_url.toString()); - wdc.downloadFile(mFilePath, file); - ContentValues cv = new ContentValues(); - cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getAbsolutePath()); - getContentResolver().update( - ProviderTableMeta.CONTENT_URI, - cv, - ProviderTableMeta.FILE_NAME + "=? AND " - + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?", - new String[] { - mFilePath.substring(mFilePath.lastIndexOf('/') + 1), - mAccount.name }); + Log.e(TAG, mFilePath+""); + if (wdc.downloadFile(mFilePath, file)) { + ContentValues cv = new ContentValues(); + cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getAbsolutePath()); + getContentResolver().update( + ProviderTableMeta.CONTENT_URI, + cv, + ProviderTableMeta.FILE_NAME + "=? AND " + + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?", + new String[] { + mFilePath.substring(mFilePath.lastIndexOf('/') + 1), + mAccount.name }); + } nm.cancel(1); Intent end = new Intent(DOWNLOAD_FINISH_MESSAGE); sendBroadcast(end); diff --git a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java index 1e1a5e37..8bd0a575 100644 --- a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java +++ b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java @@ -47,6 +47,8 @@ import eu.alefzero.webdav.WebdavEntry; */ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { + private final static String TAG = "FileSyncAdapter"; + private long mCurrentSyncTime; public FileSyncAdapter(Context context, boolean autoInitialize) { @@ -63,7 +65,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { this.setStorageManager(new FileDataStorageManager(account, getContentProvider())); - Log.d("ASD", "syncing owncloud account " + account.name); + Log.d(TAG, "syncing owncloud account " + account.name); Intent i = new Intent(FileSyncService.SYNC_MESSAGE); i.putExtra(FileSyncService.IN_PROGRESS, true); diff --git a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java index 4ca240dd..e7ee4cc1 100644 --- a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java @@ -19,6 +19,7 @@ package eu.alefzero.owncloud.ui.activity; import java.io.File; +import java.net.URLDecoder; import java.net.URLEncoder; import android.accounts.Account; @@ -298,7 +299,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements AccountUtils.getCurrentOwnCloudAccount(this)); String remotepath = new String(); for (int j = mDirectories.getCount() - 2; j >= 0; --j) { - remotepath += "/" + mDirectories.getItem(j); + remotepath += "/" + URLDecoder.decode(mDirectories.getItem(j)); } if (!remotepath.endsWith("/")) remotepath += "/"; diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java index 5fd4003a..7d10ebac 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java @@ -23,7 +23,9 @@ import android.content.Intent; import android.content.IntentFilter; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.net.Uri; import android.os.Bundle; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -56,6 +58,7 @@ public class FileDetailFragment extends SherlockFragment implements private int mLayout; private View mView; private OCFile mFile; + private static final String TAG = "FileDetailFragment"; /** * Default constructor - contains real layout @@ -124,6 +127,7 @@ public class FileDetailFragment extends SherlockFragment implements private void updateFileDetails() { mFile = mIntent.getParcelableExtra(FILE); + Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn); if (mFile != null) { // set file details @@ -131,20 +135,31 @@ public class FileDetailFragment extends SherlockFragment implements setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mFile .getMimetype())); setFilesize(mFile.getFileLength()); - // Update preview if (mFile.getStoragePath() != null) { - if (mFile.getMimetype().startsWith("image/")) { - ImageView preview = (ImageView) getView().findViewById( - R.id.fdPreview); - Bitmap bmp = BitmapFactory.decodeFile(mFile.getStoragePath()); - preview.setImageBitmap(bmp); + try { + if (mFile.getMimetype().startsWith("image/")) { + ImageView preview = (ImageView) getView().findViewById( + R.id.fdPreview); + Bitmap bmp = BitmapFactory.decodeFile(mFile.getStoragePath()); + preview.setImageBitmap(bmp); + } + } catch (OutOfMemoryError e) { + Log.e(TAG, "Out of memory occured for file with size " + mFile.getFileLength()); } + downloadButton.setText("Open file"); + downloadButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setDataAndType(Uri.parse("file://"+mFile.getStoragePath()), mFile.getMimetype()); + startActivity(i); + } + }); + } else { + // Make download button effective + downloadButton.setOnClickListener(this); } - - // Make download button effective - Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn); - downloadButton.setOnClickListener(this); } } diff --git a/src/eu/alefzero/webdav/WebdavClient.java b/src/eu/alefzero/webdav/WebdavClient.java index 6e1d287b..3338f01f 100644 --- a/src/eu/alefzero/webdav/WebdavClient.java +++ b/src/eu/alefzero/webdav/WebdavClient.java @@ -75,16 +75,16 @@ public class WebdavClient extends HttpClient { // HttpGet get = new HttpGet(mUri.toString() + filepath.replace(" ", // "%20")); - Log.e("ASD", mUri.toString() + URLDecoder.decode(filepath) + ""); + Log.e("ASD", mUri.toString() + filepath.replace(" ", "%20") + ""); GetMethod get = new GetMethod(mUri.toString() - + URLEncoder.encode(filepath)); + + filepath.replace(" ", "%20")); // get.setHeader("Host", mUri.getHost()); // get.setHeader("User-Agent", "Android-ownCloud"); try { - Log.e("ASD", get.toString()); int status = executeMethod(get); + Log.e(TAG, "status return: " + status); if (status != HttpStatus.SC_OK) { return false; }