Implemented option to copy shared link in clipboard instead of trusting in external...
authorDavid A. Velasco <dvelasco@solidgear.es>
Wed, 19 Feb 2014 17:00:49 +0000 (18:00 +0100)
committerDavid A. Velasco <dvelasco@solidgear.es>
Wed, 19 Feb 2014 17:00:49 +0000 (18:00 +0100)
AndroidManifest.xml
res/drawable-hdpi/copy_link.png [new file with mode: 0644]
res/drawable-ldpi/copy_link.png [new file with mode: 0644]
res/drawable-mdpi/copy_link.png [new file with mode: 0644]
res/drawable-xhdpi/copy_link.png [new file with mode: 0644]
res/values/strings.xml
src/com/owncloud/android/files/FileOperationsHelper.java
src/com/owncloud/android/ui/activity/CopyToClipboardActivity.java [new file with mode: 0644]
src/com/owncloud/android/ui/dialog/ActivityChooserDialog.java [deleted file]
src/com/owncloud/android/ui/dialog/ShareLinkToDialog.java [new file with mode: 0644]

index 141d56a..c92af06 100644 (file)
                 <category android:name="android.intent.category.DEFAULT" >
                 </category>
 
-                <data android:mimeType="*/*" android:scheme="content">
+                <data android:mimeType="*/*" >
                 </data>
 
-                <data android:mimeType="*/*" android:scheme="file">
-                </data>
-                </intent-filter>
+                       </intent-filter>
         </activity>
         <activity
             android:name=".ui.activity.Preferences"
         </receiver>
         <service android:name=".files.services.FileObserverService"/>
         
+        <activity 
+            android:name=".ui.activity.CopyToClipboardActivity" 
+               android:label="@string/copy_link"
+               android:icon="@drawable/copy_link" />
+        
     </application>
 
 </manifest>
diff --git a/res/drawable-hdpi/copy_link.png b/res/drawable-hdpi/copy_link.png
new file mode 100644 (file)
index 0000000..35df55f
Binary files /dev/null and b/res/drawable-hdpi/copy_link.png differ
diff --git a/res/drawable-ldpi/copy_link.png b/res/drawable-ldpi/copy_link.png
new file mode 100644 (file)
index 0000000..b3caf52
Binary files /dev/null and b/res/drawable-ldpi/copy_link.png differ
diff --git a/res/drawable-mdpi/copy_link.png b/res/drawable-mdpi/copy_link.png
new file mode 100644 (file)
index 0000000..4e2af28
Binary files /dev/null and b/res/drawable-mdpi/copy_link.png differ
diff --git a/res/drawable-xhdpi/copy_link.png b/res/drawable-xhdpi/copy_link.png
new file mode 100644 (file)
index 0000000..c69eb05
Binary files /dev/null and b/res/drawable-xhdpi/copy_link.png differ
index f6871a6..6b58ea8 100644 (file)
     <string name="sync_fail_in_favourites_content">Contents of %1$d files could not be sync\'ed (%2$d conflicts)</string>
     <string name="sync_foreign_files_forgotten_ticker">Some local files were forgotten</string>
     <string name="sync_foreign_files_forgotten_content">%1$d files out of the %2$s directory could not be copied into</string>
-    <string name="sync_foreign_files_forgotten_explanation">As of version 1.3.16, files uploaded from this device are copied into the local %1$s folder to prevent data loss when a single file is synced with multiple accounts.\n\nDue to this change, all files uploaded in previous versions of this app were copied into the %2$s folder. However, an error prevented the completion of this operation during account synchronization. You may either leave the file(s) as is and remove the link to %3$s, or move the file(s) into the %1$s directory and retain the link to %4$s.\n\nListed below are the local file(s), and the the remote file(s) in %5$s they were linked to.</string>
+    <string name="sync_foreign_files_forgotten_explanation">As of version 1.3.16, files uploaded from this device are copied into the local %1$s folder to prevent data loss when a single file is synced with multiple accounts.\n\nDue to this change, all files uploaded in previous versions of this app were copied into the %2$s folder. However, an error prevented the completion of this operation during account synchronization. You may either leave the file(s) as is and remove the link to %3$s, or move the file(s) into the %1$s directory and retain the link to %4$s.\n\nListed below are the local file(s), and the remote file(s) in %5$s they were linked to.</string>
        <string name="sync_current_folder_was_removed">Folder %1$s does not exist anymore</string>    
     <string name="foreign_files_move">"Move all"</string>
     <string name="foreign_files_success">"All files were moved"</string>
        <string name="share_link_file_error">An error occurred while trying to share this file or folder</string>
        <string name="unshare_link_file_no_exist">Unable to unshare this file or folder. It does not exist.</string>
        <string name="unshare_link_file_error">An error occurred while trying to unshare this file or folder</string>
+
+       <string name="copy_link">Copy link</string>     
+       <string name="clipboard_text_copied">Copied to clipboard</string>
 </resources>
index 61fde2d..c14d84d 100644 (file)
@@ -33,7 +33,7 @@ import com.owncloud.android.lib.network.webdav.WebdavUtils;
 import com.owncloud.android.lib.utils.OwnCloudVersion;
 import com.owncloud.android.services.OperationsService;
 import com.owncloud.android.ui.activity.FileActivity;
-import com.owncloud.android.ui.dialog.ActivityChooserDialog;
+import com.owncloud.android.ui.dialog.ShareLinkToDialog;
 import com.owncloud.android.utils.Log_OC;
 
 /**
@@ -89,7 +89,7 @@ public class FileOperationsHelper {
                 String link = "https://fake.url";
                 Intent intent = createShareWithLinkIntent(link);
                 String[] packagesToExclude = new String[] { callerActivity.getPackageName() };
-                DialogFragment chooserDialog = ActivityChooserDialog.newInstance(intent, packagesToExclude, file);
+                DialogFragment chooserDialog = ShareLinkToDialog.newInstance(intent, packagesToExclude, file);
                 chooserDialog.show(callerActivity.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);
                 
             } else {
diff --git a/src/com/owncloud/android/ui/activity/CopyToClipboardActivity.java b/src/com/owncloud/android/ui/activity/CopyToClipboardActivity.java
new file mode 100644 (file)
index 0000000..7c54641
--- /dev/null
@@ -0,0 +1,66 @@
+/* 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.activity;
+
+import com.owncloud.android.R;
+
+import android.app.Activity;
+import android.content.ClipData;
+import android.content.Intent;
+import android.os.Build;
+import android.os.Bundle;
+import android.text.ClipboardManager;
+import android.widget.Toast;
+
+/**
+ * Activity copying the text of the received Intent into the system clibpoard.
+ * 
+ * @author David A. Velasco
+ */
+@SuppressWarnings("deprecation")
+public class CopyToClipboardActivity extends Activity {
+    
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        
+        // get the clipboard system service
+        ClipboardManager clipboardManager = (ClipboardManager) this.getSystemService(CLIPBOARD_SERVICE);
+        
+        // get the text to copy into the clipboard 
+        Intent intent = getIntent();
+        CharSequence text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
+        
+        // and put the text the clipboard
+        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
+            // API level >= 11 -> modern Clipboard
+            ClipData clip = ClipData.newPlainText("ownCloud was here", text);
+            ((android.content.ClipboardManager)clipboardManager).setPrimaryClip(clip);
+            
+        } else {
+            // API level >= 11 -> legacy Clipboard
+            clipboardManager.setText(text);    
+        }
+        
+        // alert the user that the text is in the clipboard and we're done
+        Toast.makeText(this, R.string.clipboard_text_copied, Toast.LENGTH_SHORT).show();
+        
+        finish();
+    }    
+
+}
diff --git a/src/com/owncloud/android/ui/dialog/ActivityChooserDialog.java b/src/com/owncloud/android/ui/dialog/ActivityChooserDialog.java
deleted file mode 100644 (file)
index dc15f69..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-/* 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 java.util.Arrays;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
-import android.widget.ImageView;
-import android.widget.TextView;
-
-import com.actionbarsherlock.app.SherlockDialogFragment;
-import com.owncloud.android.R;
-import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.files.FileOperationsHelper;
-import com.owncloud.android.ui.activity.FileActivity;
-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 final static String ARG_FILE_TO_SHARE = ActivityChooserDialog.class.getSimpleName() + ".FILE_TO_SHARE";
-    
-    private ActivityAdapter mAdapter;
-    private OCFile mFile;
-    private Intent mIntent;
-    
-    public static ActivityChooserDialog newInstance(Intent intent, String[] packagesToExclude, OCFile fileToShare) {
-        ActivityChooserDialog f = new ActivityChooserDialog();
-        Bundle args = new Bundle();
-        args.putParcelable(ARG_INTENT, intent);
-        args.putStringArray(ARG_PACKAGES_TO_EXCLUDE, packagesToExclude);
-        args.putParcelable(ARG_FILE_TO_SHARE, fileToShare);
-        f.setArguments(args);
-        return f;
-    }
-    
-    public ActivityChooserDialog() {
-        super();
-        Log_OC.d(TAG, "constructor");
-    }
-    
-    @Override
-    public Dialog onCreateDialog(Bundle savedInstanceState) {
-        mIntent = getArguments().getParcelable(ARG_INTENT);
-        String[] packagesToExclude = getArguments().getStringArray(ARG_PACKAGES_TO_EXCLUDE);
-        List<String> packagesToExcludeList = Arrays.asList(packagesToExclude != null ? packagesToExclude : new String[0]);
-        mFile = getArguments().getParcelable(ARG_FILE_TO_SHARE);
-        
-        PackageManager pm= getSherlockActivity().getPackageManager();
-        List<ResolveInfo> activities = pm.queryIntentActivities(mIntent, PackageManager.MATCH_DEFAULT_ONLY);
-        Iterator<ResolveInfo> it = activities.iterator();
-        ResolveInfo resolveInfo;
-        while (it.hasNext()) {
-            resolveInfo = it.next();
-            if (packagesToExcludeList.contains(resolveInfo.activityInfo.packageName.toLowerCase())) {
-                it.remove();
-            }
-        }
-        Collections.sort(activities, new ResolveInfo.DisplayNameComparator(pm)); 
-        mAdapter = new ActivityAdapter(getSherlockActivity(), pm, activities);
-        
-        return new AlertDialog.Builder(getSherlockActivity())
-                   .setTitle(R.string.activity_chooser_title)
-                   .setAdapter(mAdapter, new DialogInterface.OnClickListener() {
-                           @Override
-                           public void onClick(DialogInterface dialog, int which) {
-                               // Add the information of the chosen activity to the intent to send 
-                               ResolveInfo chosen = mAdapter.getItem(which);
-                               ActivityInfo actInfo = chosen.activityInfo;
-                               ComponentName name=new ComponentName(actInfo.applicationInfo.packageName, actInfo.name);
-                               mIntent.setComponent(name);                               
-                               
-                               // Create a new share resource
-                               FileOperationsHelper foh = new FileOperationsHelper();
-                               foh.shareFileWithLinkToApp(mFile, mIntent, (FileActivity)getSherlockActivity()); 
-                           }
-                       })
-                   .create();
-    }
-
-    
-    class ActivityAdapter extends ArrayAdapter<ResolveInfo> {
-        
-        private PackageManager mPackageManager;
-        
-        ActivityAdapter(Context context, PackageManager pm, List<ResolveInfo> apps) {
-            super(context, R.layout.activity_row, apps);
-            this.mPackageManager = pm;
-        }
-        
-        @Override
-        public View getView(int position, View convertView, ViewGroup parent) {
-            if (convertView == null) {
-                convertView = newView(parent);
-            }
-            bindView(position, convertView);
-            return convertView;
-        }
-        
-        private View newView(ViewGroup parent) {
-            return(((LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.activity_row, parent, false));
-        }
-        
-        private void bindView(int position, View row) {
-            TextView label = (TextView) row.findViewById(R.id.title);
-            label.setText(getItem(position).loadLabel(mPackageManager));
-            ImageView icon = (ImageView) row.findViewById(R.id.icon);
-            icon.setImageDrawable(getItem(position).loadIcon(mPackageManager));
-        }
-    }
-    
-}
diff --git a/src/com/owncloud/android/ui/dialog/ShareLinkToDialog.java b/src/com/owncloud/android/ui/dialog/ShareLinkToDialog.java
new file mode 100644 (file)
index 0000000..e0e76d1
--- /dev/null
@@ -0,0 +1,160 @@
+/* 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 java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.actionbarsherlock.app.SherlockDialogFragment;
+import com.owncloud.android.R;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.files.FileOperationsHelper;
+import com.owncloud.android.ui.activity.CopyToClipboardActivity;
+import com.owncloud.android.ui.activity.FileActivity;
+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 ShareLinkToDialog  extends SherlockDialogFragment {
+    
+    private final static String TAG =  ShareLinkToDialog.class.getSimpleName();
+    private final static String ARG_INTENT =  ShareLinkToDialog.class.getSimpleName() + ".ARG_INTENT";
+    private final static String ARG_PACKAGES_TO_EXCLUDE =  ShareLinkToDialog.class.getSimpleName() + ".ARG_PACKAGES_TO_EXCLUDE";
+    private final static String ARG_FILE_TO_SHARE = ShareLinkToDialog.class.getSimpleName() + ".FILE_TO_SHARE";
+    
+    private ActivityAdapter mAdapter;
+    private OCFile mFile;
+    private Intent mIntent;
+    
+    public static ShareLinkToDialog newInstance(Intent intent, String[] packagesToExclude, OCFile fileToShare) {
+        ShareLinkToDialog f = new ShareLinkToDialog();
+        Bundle args = new Bundle();
+        args.putParcelable(ARG_INTENT, intent);
+        args.putStringArray(ARG_PACKAGES_TO_EXCLUDE, packagesToExclude);
+        args.putParcelable(ARG_FILE_TO_SHARE, fileToShare);
+        f.setArguments(args);
+        return f;
+    }
+    
+    public ShareLinkToDialog() {
+        super();
+        Log_OC.d(TAG, "constructor");
+    }
+    
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        mIntent = getArguments().getParcelable(ARG_INTENT);
+        String[] packagesToExclude = getArguments().getStringArray(ARG_PACKAGES_TO_EXCLUDE);
+        List<String> packagesToExcludeList = Arrays.asList(packagesToExclude != null ? packagesToExclude : new String[0]);
+        mFile = getArguments().getParcelable(ARG_FILE_TO_SHARE);
+        
+        PackageManager pm= getSherlockActivity().getPackageManager();
+        List<ResolveInfo> activities = pm.queryIntentActivities(mIntent, PackageManager.MATCH_DEFAULT_ONLY);
+        Iterator<ResolveInfo> it = activities.iterator();
+        ResolveInfo resolveInfo;
+        while (it.hasNext()) {
+            resolveInfo = it.next();
+            if (packagesToExcludeList.contains(resolveInfo.activityInfo.packageName.toLowerCase())) {
+                it.remove();
+            }
+        }
+        
+        // add activity for copy to clipboard
+        Intent copyToClipboardIntent = new Intent(getSherlockActivity(), CopyToClipboardActivity.class);
+        List<ResolveInfo> copyToClipboard = pm.queryIntentActivities(copyToClipboardIntent, 0);
+        if (!copyToClipboard.isEmpty()) {
+            activities.add(copyToClipboard.get(0));
+        }
+        
+        Collections.sort(activities, new ResolveInfo.DisplayNameComparator(pm)); 
+        mAdapter = new ActivityAdapter(getSherlockActivity(), pm, activities);
+        
+        return new AlertDialog.Builder(getSherlockActivity())
+                   .setTitle(R.string.activity_chooser_title)
+                   .setAdapter(mAdapter, new DialogInterface.OnClickListener() {
+                           @Override
+                           public void onClick(DialogInterface dialog, int which) {
+                               // Add the information of the chosen activity to the intent to send 
+                               ResolveInfo chosen = mAdapter.getItem(which);
+                               ActivityInfo actInfo = chosen.activityInfo;
+                               ComponentName name=new ComponentName(actInfo.applicationInfo.packageName, actInfo.name);
+                               mIntent.setComponent(name);                               
+                               
+                               // Create a new share resource
+                               FileOperationsHelper foh = new FileOperationsHelper();
+                               foh.shareFileWithLinkToApp(mFile, mIntent, (FileActivity)getSherlockActivity()); 
+                           }
+                       })
+                   .create();
+    }
+
+    
+    class ActivityAdapter extends ArrayAdapter<ResolveInfo> {
+        
+        private PackageManager mPackageManager;
+        
+        ActivityAdapter(Context context, PackageManager pm, List<ResolveInfo> apps) {
+            super(context, R.layout.activity_row, apps);
+            this.mPackageManager = pm;
+        }
+        
+        @Override
+        public View getView(int position, View convertView, ViewGroup parent) {
+            if (convertView == null) {
+                convertView = newView(parent);
+            }
+            bindView(position, convertView);
+            return convertView;
+        }
+        
+        private View newView(ViewGroup parent) {
+            return(((LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.activity_row, parent, false));
+        }
+        
+        private void bindView(int position, View row) {
+            TextView label = (TextView) row.findViewById(R.id.title);
+            label.setText(getItem(position).loadLabel(mPackageManager));
+            ImageView icon = (ImageView) row.findViewById(R.id.icon);
+            icon.setImageDrawable(getItem(position).loadIcon(mPackageManager));
+        }
+    }
+    
+}