import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
+import android.graphics.Bitmap;
import android.net.Uri;
import android.support.v4.app.DialogFragment;
import android.webkit.MimeTypeMap;
import android.widget.Toast;
+import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.datamodel.ThumbnailsCacheManager;
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
import com.owncloud.android.lib.common.network.WebdavUtils;
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.services.observer.FileObserverService;
import com.owncloud.android.ui.activity.FileActivity;
+import com.owncloud.android.ui.adapter.DiskLruImageCacheFileProvider;
import com.owncloud.android.ui.dialog.ShareLinkToDialog;
import org.apache.http.protocol.HTTP;
+import java.io.File;
import java.util.List;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import java.util.ArrayList;
+
/**
*
*/
}
public void setPictureAs(OCFile file) {
- if (file != null) {
+ if (file != null){
if (file.isDown()) {
- String storagePath = file.getStoragePath();
- String encodedStoragePath = WebdavUtils.encodePath(storagePath);
- Intent sendIntent = new Intent(Intent.ACTION_ATTACH_DATA);
- // set MimeType
- sendIntent.setType(file.getMimetype());
-// sendIntent.setData(Uri.parse(encodedStoragePath));
- sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(encodedStoragePath));
- // sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + encodedStoragePath));
- // sendIntent.putExtra("jpg", "image/*");
-
- mFileActivity.startActivity(Intent.createChooser(sendIntent,
- mFileActivity.getString(R.string.set_picture_as)));
+ File externalFile = new File(file.getStoragePath());
+ Uri sendUri = Uri.fromFile(externalFile);
+ Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
+ intent.setDataAndType(sendUri, file.getMimetype());
+ intent.putExtra("mimeType", file.getMimetype());
+ mFileActivity.startActivityForResult(Intent.createChooser(intent, "Set As"), 200);
} else {
+ // TODO re-enable after resized images is available
+ Uri sendUri = Uri.parse("content://" + DiskLruImageCacheFileProvider.AUTHORITY + file.getRemotePath());
+ Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
+ intent.setDataAndType(sendUri, file.getMimetype());
+ intent.putExtra("mimeType", file.getMimetype());
+ mFileActivity.startActivityForResult(Intent.createChooser(intent, "Set As"), 200);
+
// Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
// // set MimeType
// sendIntent.setType(file.getMimetype());
}
}
+ public void sendCachedImage(OCFile file) {
+ if (file != null) {
+ Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
+ // set MimeType
+ sendIntent.setType(file.getMimetype());
+// sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://" + DiskLruImageCacheFileProvider.AUTHORITY + "/#" + file.getRemoteId() + "#" + file.getFileName()));
+ sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://" + DiskLruImageCacheFileProvider.AUTHORITY + file.getRemotePath()));
+ sendIntent.putExtra(Intent.ACTION_SEND, true); // Send Action
+
+ // Show dialog, without the own app
+ String[] packagesToExclude = new String[] { mFileActivity.getPackageName() };
+ DialogFragment chooserDialog = ShareLinkToDialog.newInstance(sendIntent, packagesToExclude, file);
+ chooserDialog.show(mFileActivity.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);
+ } else {
+ Log_OC.wtf(TAG, "Trying to send a NULL OCFile");
+ }
+ }
+
+ public void syncFiles(ArrayList<OCFile> files) {
+ for (OCFile file: files) {
+ syncFile(file);
+ }
+ }
+
/**
* Request the synchronization of a file or folder with the OC server, including its contents.
*
intent.putExtra(OperationsService.EXTRA_SYNC_FILE_CONTENTS, true);
mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(intent);
mFileActivity.showLoadingDialog();
-
+
} else {
Intent intent = new Intent(mFileActivity, OperationsService.class);
intent.setAction(OperationsService.ACTION_SYNC_FOLDER);
}
}
+ public void toggleFavorites(ArrayList<OCFile> files, boolean isFavorite){
+ for (OCFile file: files) {
+ toggleFavorite(file, isFavorite);
+ }
+ }
+
public void toggleFavorite(OCFile file, boolean isFavorite) {
file.setFavorite(isFavorite);
mFileActivity.getStorageManager().saveFile(file);
service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
- mFileActivity.showLoadingDialog();
+ // TODO Tobi loading dialog?
+ // mFileActivity.showLoadingDialog();
}
/**