Added standard menu to select app used to send the link to share a file
authorDavid A. Velasco <dvelasco@solidgear.es>
Fri, 31 Jan 2014 09:43:25 +0000 (10:43 +0100)
committerDavid A. Velasco <dvelasco@solidgear.es>
Fri, 31 Jan 2014 09:43:25 +0000 (10:43 +0100)
AndroidManifest.xml
owncloud-android-library
src/com/owncloud/android/files/FileHandler.java
src/com/owncloud/android/ui/activity/FileActivity.java
src/com/owncloud/android/ui/activity/FileDisplayActivity.java
src/com/owncloud/android/ui/fragment/FileDetailFragment.java
src/com/owncloud/android/ui/fragment/OCFileListFragment.java
src/com/owncloud/android/ui/preview/PreviewImageActivity.java
src/com/owncloud/android/ui/preview/PreviewImageFragment.java
src/com/owncloud/android/ui/preview/PreviewMediaFragment.java

index c1202e6..8ff6870 100644 (file)
@@ -54,7 +54,6 @@
             >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
             >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
-
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
                 <category android:name="android.intent.category.DEFAULT" >
                 </category>
 
                 <category android:name="android.intent.category.DEFAULT" >
                 </category>
 
-                <data android:mimeType="*/*" >
+                <data android:mimeType="*/*" android:scheme="content">
                 </data>
                 </data>
-            </intent-filter>
+
+                <data android:mimeType="*/*" android:scheme="file">
+                </data>
+                </intent-filter>
         </activity>
         <activity
             android:name=".ui.activity.Preferences"
         </activity>
         <activity
             android:name=".ui.activity.Preferences"
index afb4ae1..974e55a 160000 (submodule)
@@ -1 +1 @@
-Subproject commit afb4ae1c2e15dfc3b3f9a9861b75d375e38f2805
+Subproject commit 974e55a2b95c652b794111254078b806f11fcf31
index 2eb754d..77ff78a 100644 (file)
@@ -27,4 +27,5 @@ public interface FileHandler {
     public void openFile(OCFile file);
 
     
     public void openFile(OCFile file);
 
     
+    public void shareFileWithLink(OCFile file);
 }
 }
index 3a9297e..ae5700f 100644 (file)
 
 package com.owncloud.android.ui.activity;
 
 
 package com.owncloud.android.ui.activity;
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import junit.framework.ComparisonFailure;
+
+import org.apache.http.protocol.HTTP;
+
 import android.accounts.Account;
 import android.accounts.AccountManager;
 import android.accounts.AccountManagerCallback;
 import android.accounts.AccountManagerFuture;
 import android.accounts.OperationCanceledException;
 import android.accounts.Account;
 import android.accounts.AccountManager;
 import android.accounts.AccountManagerCallback;
 import android.accounts.AccountManagerFuture;
 import android.accounts.OperationCanceledException;
+import android.content.Context;
 import android.content.Intent;
 import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
 import android.net.Uri;
 import android.os.Bundle;
 import android.net.Uri;
 import android.os.Bundle;
+import android.os.Parcelable;
 import android.webkit.MimeTypeMap;
 
 import com.actionbarsherlock.app.SherlockFragmentActivity;
 import android.webkit.MimeTypeMap;
 
 import com.actionbarsherlock.app.SherlockFragmentActivity;
@@ -36,6 +47,8 @@ import com.owncloud.android.datamodel.OCFile;
 
 import com.owncloud.android.lib.accounts.OwnCloudAccount;
 import com.owncloud.android.lib.network.webdav.WebdavUtils;
 
 import com.owncloud.android.lib.accounts.OwnCloudAccount;
 import com.owncloud.android.lib.network.webdav.WebdavUtils;
+import com.owncloud.android.lib.operations.common.ShareType;
+import com.owncloud.android.operations.CreateShareOperation;
 
 import com.owncloud.android.utils.Log_OC;
 
 
 import com.owncloud.android.utils.Log_OC;
 
@@ -343,5 +356,77 @@ public abstract class FileActivity extends SherlockFragmentActivity {
             Log_OC.wtf(TAG, "Trying to open a NULL OCFile");
         }
     }
             Log_OC.wtf(TAG, "Trying to open a NULL OCFile");
         }
     }
+
+    /*
+    public void shareFileWithLink(OCFile file) {
+        if (file != null) {
+            
+            Intent intentToShareLink = new Intent(Intent.ACTION_SEND);
+            intentToShareLink.putExtra(Intent.EXTRA_TEXT, "https://fake.url.lolo");
+            intentToShareLink.setType(HTTP.PLAIN_TEXT_TYPE);
+            
+            Intent chooserIntent = Intent.createChooser(intentToShareLink, getString(R.string.action_share_file));
+            startActivity(chooserIntent);
+            
+        } else {
+            Log_OC.wtf(TAG, "Trying to open a NULL OCFile");
+        }
+    }
+    */
+    
+    public void shareFileWithLink(OCFile file) {
+        if (file != null) {
+            
+            //CreateShareOperation createShare = new CreateShareOperation(file.getRemotePath(), ShareType.PUBLIC_LINK, "", false, "", 1);
+            //createShare.execute(getAccount(), this, this, mHandler, this);
+            
+            String link = "https://fake.url.lolo";
+            Intent chooserIntent = null;
+            List<Intent> targetedShareIntents = new ArrayList<Intent>();
+            List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(createShareWithLinkIntent(link), PackageManager.MATCH_DEFAULT_ONLY);
+            String myPackageName = getPackageName();
+            if (!resInfo.isEmpty()) {
+                for (ResolveInfo info : resInfo) {
+                    if (!info.activityInfo.packageName.equalsIgnoreCase(myPackageName)) {
+                        Intent targetedShare = createTargetedShare(link, info.activityInfo.applicationInfo.packageName, info.activityInfo.name);
+                        targetedShareIntents.add(targetedShare);
+                    }
+                }
+            }
+            if (targetedShareIntents.size() > 0) {
+                Intent firstTargeted = targetedShareIntents.remove(0);
+                chooserIntent = Intent.createChooser(firstTargeted, getString(R.string.action_share_file));
+                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[] {}));
+            } else {
+                // to show standard message
+                chooserIntent = Intent.createChooser(null, getString(R.string.action_share_file));
+            }
+            startActivity(chooserIntent);
+            
+        } else {
+            Log_OC.wtf(TAG, "Trying to open a NULL OCFile");
+        }
+    }
+    
+    private Intent createTargetedShare(String link, String packageName, String className) {
+        //Intent targetedShare = createShareWithLinkIntent(link);
+        Intent targetedShare=new Intent(Intent.ACTION_MAIN);
+
+        targetedShare.addCategory(Intent.CATEGORY_LAUNCHER);
+        targetedShare.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
+                    Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);        
+        Log_OC.e("LOLO", "className: " + className + "\npackageName: " + packageName + "\n");
+        targetedShare.setClassName(packageName, className);
+        return targetedShare;
+    }
+
+
+    private Intent createShareWithLinkIntent(String link) {
+        Intent intentToShareLink = new Intent(Intent.ACTION_SEND);
+        intentToShareLink.putExtra(Intent.EXTRA_TEXT, link);
+        intentToShareLink.setType(HTTP.PLAIN_TEXT_TYPE);
+        return intentToShareLink; 
+    }
+    
     
 }
     
 }
index 7f8ad7e..c113029 100644 (file)
@@ -1539,13 +1539,6 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         
     }
 
         
     }
 
-    @Override
-    public void shareFileWithLink(OCFile file) {
-            CreateShareOperation createShare = new CreateShareOperation(file.getRemotePath(), ShareType.PUBLIC_LINK, "", false, "", 1);
-            createShare.execute(getAccount(), this, this, mHandler, this);
-        
-    }
-    
 //    public void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
 //        int childCount = viewGroup.getChildCount();
 //        for (int i = 0; i < childCount; i++) {
 //    public void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
 //        int childCount = viewGroup.getChildCount();
 //        for (int i = 0; i < childCount; i++) {
index 7bf0527..eebbef8 100644 (file)
@@ -339,7 +339,7 @@ public class FileDetailFragment extends FileFragment implements
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
             case R.id.action_share_file: {
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
             case R.id.action_share_file: {
-                    mContainerActivity.shareFileWithLink(getFile());
+                mContainerActivity.shareFileWithLink(getFile());
                 return true;
             }
             case R.id.action_open_file_with: {
                 return true;
             }
             case R.id.action_open_file_with: {
index 326c835..8be9477 100644 (file)
@@ -285,7 +285,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
         mTargetFile = (OCFile) mAdapter.getItem(info.position);
         switch (item.getItemId()) {
             case R.id.action_share_file: {
         mTargetFile = (OCFile) mAdapter.getItem(info.position);
         switch (item.getItemId()) {
             case R.id.action_share_file: {
-                    mContainerActivity.shareFileWithLink(getCurrentFile());
+                mContainerActivity.shareFileWithLink(mTargetFile);
                 return true;
             }
             case R.id.action_rename_file: {
                 return true;
             }
             case R.id.action_rename_file: {
index 7816349..3caa80a 100644 (file)
@@ -481,9 +481,4 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
         }
     }
 
         }
     }
 
-    @Override
-    public void shareFileWithLink(OCFile file) {
-        
-    }
-    
 }
 }
index 8555fa7..d646bd5 100644 (file)
@@ -247,6 +247,10 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
+            case R.id.action_share_file: {
+                //shareFileWithLink(getFile());
+                return true;
+            }
             case R.id.action_open_file_with: {
                 openFile();
                 return true;
             case R.id.action_open_file_with: {
                 openFile();
                 return true;
index 464ea6d..0baed61 100644 (file)
@@ -307,6 +307,10 @@ public class PreviewMediaFragment extends FileFragment implements
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
+            case R.id.action_share_file: {
+                //shareFileWithLink(getFile());
+                return true;
+            }
             case R.id.action_open_file_with: {
                 openFile();
                 return true;
             case R.id.action_open_file_with: {
                 openFile();
                 return true;