소스 검색

on click on item in upload list: open with default app

Luke Owncloud 10 년 전
부모
커밋
64c07f6a30
1개의 변경된 파일44개의 추가작업 그리고 11개의 파일을 삭제
  1. 44 11
      src/com/owncloud/android/ui/activity/UploadListActivity.java

+ 44 - 11
src/com/owncloud/android/ui/activity/UploadListActivity.java

@@ -2,9 +2,11 @@ package com.owncloud.android.ui.activity;
 
 import java.io.File;
 
+import android.content.ActivityNotFoundException;
 import android.content.ComponentName;
 import android.content.Intent;
 import android.content.ServiceConnection;
+import android.net.Uri;
 import android.os.Bundle;
 import android.os.IBinder;
 import android.os.Parcelable;
@@ -52,22 +54,53 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
         File f = new File(file.getLocalPath());
         if(!f.exists()) {
             Toast.makeText(this, "Cannot open. Local file does not exist.", Toast.LENGTH_SHORT).show();
-            return true;
-        }
-        
-        if (PreviewImageFragment.canBePreviewed(file.getOCFile())) {
-            // preview image
-            Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
-            showDetailsIntent.putExtra(EXTRA_FILE, (Parcelable)file.getOCFile());
-            showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
-            startActivity(showDetailsIntent);            
         } else {
-            //open file
-            getFileOperationsHelper().openFile(file.getOCFile());
+            openFileWithDefault(file.getLocalPath());
         }
         return true;
     }
 
+    /**
+     * Open file with app associates with its mimetype. If mimetype unknown, show list with all apps.  
+     */
+    private void openFileWithDefault(String localPath) {
+        Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW);
+        File file = new File(localPath);
+        String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString());
+        String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
+        if (mimetype == null)
+            mimetype = "*/*";
+        myIntent.setDataAndType(Uri.fromFile(file), mimetype);
+        try {
+            startActivity(myIntent);
+        } catch (ActivityNotFoundException e) {
+            Toast.makeText(this, "Found no app to open this file.", Toast.LENGTH_LONG).show();
+            Log_OC.i(TAG, "Could not find app for sending log history.");
+
+        }        
+    }
+    
+    /**
+     * Same as openFileWithDefault() but user cannot save default app.
+     * @param localPath
+     */
+    @SuppressWarnings("unused")
+    private void openFileWithDefaultNoDefault(OCFile ocFile) {
+        getFileOperationsHelper().openFile(ocFile);
+    }
+
+    /**
+     * WARNING! This opens the local copy inside owncloud directory. If file not uploaded yet, there is none.
+     */
+    @SuppressWarnings("unused")
+    private void openPreview(UploadDbObject file) {
+     // preview image
+        Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
+        showDetailsIntent.putExtra(EXTRA_FILE, (Parcelable)file.getOCFile());
+        showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
+        startActivity(showDetailsIntent);  
+    }
+    
     @SuppressWarnings("unused")
     private void openDetails(UploadDbObject file) {
         OCFile ocFile = file.getOCFile();