Merge branch 'share_link__new_share' into share_link__new_share_menu
authorDavid A. Velasco <dvelasco@solidgear.es>
Mon, 3 Feb 2014 08:46:26 +0000 (09:46 +0100)
committerDavid A. Velasco <dvelasco@solidgear.es>
Mon, 3 Feb 2014 08:46:26 +0000 (09:46 +0100)
AndroidManifest.xml
res/values/strings.xml
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/dialog/ActivityChooserDialog.java [new file with mode: 0644]
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 ca11c81..465dec8 100644 (file)
@@ -54,7 +54,6 @@
             >
             <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.DEFAULT" >
                 </category>
 
-                <data android:mimeType="*/*" >
+                <data android:mimeType="*/*" android:scheme="content">
                 </data>
-            </intent-filter>
+
+                <data android:mimeType="*/*" android:scheme="file">
+                </data>
+                </intent-filter>
         </activity>
         <activity
             android:name=".ui.activity.Preferences"
index 7d941c1..fba0915 100644 (file)
     <string name="wait_a_moment">Wait a moment</string>
     <string name="filedisplay_unexpected_bad_get_content">"Unexpected problem ; please select the file from a different app"</string>
     <string name="filedisplay_no_file_selected">No file was selected</string>
+    <string name="activity_chooser_title">Send link to #8230;</string>
     
     <string name="oauth_check_onoff">Login with oAuth2</string> 
     <string name="oauth_login_connection">Connecting to oAuth2 server…</string>    
index 2eb754d..77ff78a 100644 (file)
@@ -27,4 +27,5 @@ public interface FileHandler {
     public void openFile(OCFile file);
 
     
+    public void shareFileWithLink(OCFile file);
 }
index 3a9297e..4f42597 100644 (file)
 
 package com.owncloud.android.ui.activity;
 
+import java.util.ArrayList;
+import java.util.List;
+
+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.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
 import android.net.Uri;
 import android.os.Bundle;
+import android.os.Parcelable;
 import android.webkit.MimeTypeMap;
+import android.widget.Toast;
 
 import com.actionbarsherlock.app.SherlockFragmentActivity;
 import com.owncloud.android.MainApp;
@@ -343,5 +352,88 @@ public abstract class FileActivity extends SherlockFragmentActivity {
             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 (isSharedSupported()) {
+            if (file != null) {
+                
+                // Create the Share
+                //CreateShareOperation createShare = new CreateShareOperation(file.getRemotePath(), ShareType.PUBLIC_LINK, "", false, "", 1);
+                //createShare.execute(getStorageManager(), this, this, mHandler, this);
+                        
+                // TODO
+                // Get the link --> when the operation is finished
+                        
+                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");
+            }
+            
+        } else {
+            // Show a Message
+            Toast t = Toast.makeText(this, getString(R.string.share_link_no_support_share_api), Toast.LENGTH_LONG);
+            t.show();
+        }
+    }
+    
+    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 9ae9dfe..237113d 100644 (file)
@@ -73,7 +73,6 @@ import com.owncloud.android.operations.CreateFolderOperation;
 import com.owncloud.android.lib.operations.common.OnRemoteOperationListener;
 import com.owncloud.android.lib.operations.common.RemoteOperation;
 import com.owncloud.android.lib.operations.common.RemoteOperationResult;
-import com.owncloud.android.lib.operations.common.ShareType;
 import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;
 import com.owncloud.android.operations.CreateShareOperation;
 import com.owncloud.android.operations.RemoveFileOperation;
@@ -1584,23 +1583,4 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         
     }
 
-
-    public void shareFileWithLink(OCFile file) {
-        
-        if (isSharedSupported()) {
-            // Create the Share
-            CreateShareOperation createShare = new CreateShareOperation(file.getRemotePath(), ShareType.PUBLIC_LINK, "", false, "", 1);
-            createShare.execute(getStorageManager(), this, this, mHandler, this);
-            
-            // TODO
-            // Get the link --> when the operation is finished
-            
-        } else {
-            // Show a Message
-            Toast t = Toast.makeText(this, getString(R.string.share_link_no_support_share_api), Toast.LENGTH_LONG);
-            t.show();
-            
-        }
-    }
-    
 }
diff --git a/src/com/owncloud/android/ui/dialog/ActivityChooserDialog.java b/src/com/owncloud/android/ui/dialog/ActivityChooserDialog.java
new file mode 100644 (file)
index 0000000..fd910b4
--- /dev/null
@@ -0,0 +1,90 @@
+/* ownCloud Android client application
+ *   Copyright (C) 2012-2014 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.ui.dialog;
+
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager.LayoutParams;
+import android.widget.ArrayAdapter;
+import android.widget.EditText;
+import android.widget.ListAdapter;
+
+import com.actionbarsherlock.app.SherlockDialogFragment;
+import com.owncloud.android.R;
+import com.owncloud.android.ui.dialog.ConflictsResolveDialog.Decision;
+import com.owncloud.android.ui.dialog.ConflictsResolveDialog.OnConflictDecisionMadeListener;
+import com.owncloud.android.utils.DisplayUtils;
+import com.owncloud.android.utils.Log_OC;
+
+/**
+ * Dialog showing a list activities able to resolve a given Intent, 
+ * filtering out the activities matching give package names.
+ * 
+ * @author David A. Velasco
+ */
+public class ActivityChooserDialog  extends SherlockDialogFragment {
+    
+    private final static String TAG =  ActivityChooserDialog.class.getSimpleName();
+    private final static String ARG_INTENT =  ActivityChooserDialog.class.getSimpleName() + ".ARG_INTENT";
+    private final static String ARG_PACKAGES_TO_EXCLUDE =  ActivityChooserDialog.class.getSimpleName() + ".ARG_PACKAGES_TO_EXCLUDE";
+    
+    private ListAdapter mAdapter = null; //new ArrayAdapter<Intent>();
+    
+    public static ActivityChooserDialog newInstance(Intent intent, String[] packagesToExclude/*OnConflictDecisionMadeListener listener*/) {
+        ActivityChooserDialog f = new ActivityChooserDialog();
+        Bundle args = new Bundle();
+        args.putParcelable(ARG_INTENT, intent);
+        args.putStringArray(ARG_PACKAGES_TO_EXCLUDE, packagesToExclude);
+        f.setArguments(args);
+        return f;
+    }
+    
+    public ActivityChooserDialog() {
+        super();
+        Log_OC.d(TAG, "constructor");
+    }
+    
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        Intent intent = getArguments().getParcelable(ARG_INTENT);
+        String [] packagesToExclude = getArguments().getStringArray(ARG_PACKAGES_TO_EXCLUDE);
+        
+        // TODO init mAdapter
+        
+        return new AlertDialog.Builder(getSherlockActivity())
+                   .setIcon(DisplayUtils.getSeasonalIconId())
+                   .setTitle(R.string.activity_chooser_title)
+                   .setAdapter(mAdapter, new DialogInterface.OnClickListener() {
+                           @Override
+                           public void onClick(DialogInterface dialog, int which) {
+                               // The 'which' argument contains the index position
+                               // of the selected item                           
+                           }
+                       })
+                   .create();
+    }
+    
+}
index 5925e08..0eacfe4 100644 (file)
@@ -336,7 +336,7 @@ public class FileDetailFragment extends FileFragment implements
     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: {
index ae7b756..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: {
-                    mContainerActivity.shareFileWithLink(mTargetFile);
+                mContainerActivity.shareFileWithLink(mTargetFile);
                 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()) {
+            case R.id.action_share_file: {
+                //shareFileWithLink(getFile());
+                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()) {
+            case R.id.action_share_file: {
+                //shareFileWithLink(getFile());
+                return true;
+            }
             case R.id.action_open_file_with: {
                 openFile();
                 return true;