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)
1  2 
AndroidManifest.xml
res/values/strings.xml
src/com/owncloud/android/ui/activity/FileActivity.java
src/com/owncloud/android/ui/activity/FileDisplayActivity.java
src/com/owncloud/android/ui/fragment/FileDetailFragment.java

Simple merge
Simple merge
@@@ -29,12 -24,9 +29,13 @@@ import android.accounts.AccountManagerC
  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;
@@@ -351,77 -343,5 +352,88 @@@ public abstract class FileActivity exte
              Log_OC.wtf(TAG, "Trying to open a NULL OCFile");
          }
      }
-         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);
 +
 +    /*
 +    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 (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[] {}));
++        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);
++                        }
 +                    }
 +                }
-                 // to show standard message
-                 chooserIntent = Intent.createChooser(null, getString(R.string.action_share_file));
++                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 {
-             startActivity(chooserIntent);
++                Log_OC.wtf(TAG, "Trying to open a NULL OCFile");
 +            }
-             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; 
 +    }
 +    
      
  }
@@@ -72,10 -73,9 +73,8 @@@ import com.owncloud.android.operations.
  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;
  import com.owncloud.android.operations.RenameFileOperation;
  import com.owncloud.android.operations.SynchronizeFileOperation;
@@@ -1537,15 -1584,23 +1583,4 @@@ OCFileListFragment.ContainerActivity, F
          
      }
  
- //    public void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
- //        int childCount = viewGroup.getChildCount();
- //        for (int i = 0; i < childCount; i++) {
- //          View view = viewGroup.getChildAt(i);
- //          view.setEnabled(enabled);
- //          view.setClickable(!enabled);
- //          if (view instanceof ViewGroup) {
- //            enableDisableViewGroup((ViewGroup) view, enabled);
- //          }
- //        }
- //      }
 -
 -    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();
 -            
 -        }
 -    }
 -    
  }