From: Bartek Przybylski Date: Tue, 15 May 2012 19:52:59 +0000 (+0200) Subject: new icons, new uploader X-Git-Tag: oc-android-1.4.3~421 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/b999f542c0d63e950b64c0caab7baee22073c41c?ds=inline new icons, new uploader --- diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 39d90852..68def42e 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -147,6 +147,8 @@ + + \ No newline at end of file diff --git a/res/drawable-hdpi/ic_action_create_dir.png b/res/drawable-hdpi/ic_action_create_dir.png new file mode 100644 index 00000000..1d1a03e6 Binary files /dev/null and b/res/drawable-hdpi/ic_action_create_dir.png differ diff --git a/res/drawable-hdpi/ic_action_search.png b/res/drawable-hdpi/ic_action_search.png index 720fc9bb..a08722ce 100644 Binary files a/res/drawable-hdpi/ic_action_search.png and b/res/drawable-hdpi/ic_action_search.png differ diff --git a/res/drawable-hdpi/ic_action_upload.png b/res/drawable-hdpi/ic_action_upload.png index 0faf43b0..61b1d71b 100644 Binary files a/res/drawable-hdpi/ic_action_upload.png and b/res/drawable-hdpi/ic_action_upload.png differ diff --git a/res/drawable-ldpi/ic_action_create_dir.png b/res/drawable-ldpi/ic_action_create_dir.png new file mode 100644 index 00000000..49a226e2 Binary files /dev/null and b/res/drawable-ldpi/ic_action_create_dir.png differ diff --git a/res/drawable-ldpi/ic_action_search.png b/res/drawable-ldpi/ic_action_search.png index 9fd8157f..7e4935fb 100644 Binary files a/res/drawable-ldpi/ic_action_search.png and b/res/drawable-ldpi/ic_action_search.png differ diff --git a/res/drawable-ldpi/ic_action_upload.png b/res/drawable-ldpi/ic_action_upload.png index 2369348c..5cc5246e 100644 Binary files a/res/drawable-ldpi/ic_action_upload.png and b/res/drawable-ldpi/ic_action_upload.png differ diff --git a/res/drawable-mdpi/ic_action_create_dir.png b/res/drawable-mdpi/ic_action_create_dir.png new file mode 100644 index 00000000..ce8cdeff Binary files /dev/null and b/res/drawable-mdpi/ic_action_create_dir.png differ diff --git a/res/drawable-mdpi/ic_action_search.png b/res/drawable-mdpi/ic_action_search.png index 90cf3354..7e4935fb 100644 Binary files a/res/drawable-mdpi/ic_action_search.png and b/res/drawable-mdpi/ic_action_search.png differ diff --git a/res/drawable-mdpi/ic_action_upload.png b/res/drawable-mdpi/ic_action_upload.png index 2d4ba56f..b82399bb 100644 Binary files a/res/drawable-mdpi/ic_action_upload.png and b/res/drawable-mdpi/ic_action_upload.png differ diff --git a/res/drawable/main_header_bg.xml b/res/drawable/main_header_bg.xml index ba666218..04bdc465 100644 --- a/res/drawable/main_header_bg.xml +++ b/res/drawable/main_header_bg.xml @@ -1,8 +1,7 @@ diff --git a/res/drawable/split_action_bg.xml b/res/drawable/split_action_bg.xml new file mode 100644 index 00000000..633340c6 --- /dev/null +++ b/res/drawable/split_action_bg.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/res/layout/progressbar_layout.xml b/res/layout/progressbar_layout.xml new file mode 100644 index 00000000..f398d4cb --- /dev/null +++ b/res/layout/progressbar_layout.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/res/menu/menu.xml b/res/menu/menu.xml index f6a7db93..b630c7c9 100644 --- a/res/menu/menu.xml +++ b/res/menu/menu.xml @@ -2,7 +2,7 @@ - + diff --git a/res/values/styles.xml b/res/values/styles.xml index a09945e5..8d5491fb 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -18,10 +18,10 @@ @drawable/main_header_bg @drawable/main_header_bg #ffffff - #222222 1 1 + @drawable/split_action_bg diff --git a/src/eu/alefzero/owncloud/files/services/FileUploader.java b/src/eu/alefzero/owncloud/files/services/FileUploader.java new file mode 100644 index 00000000..323ae73c --- /dev/null +++ b/src/eu/alefzero/owncloud/files/services/FileUploader.java @@ -0,0 +1,153 @@ +package eu.alefzero.owncloud.files.services; + +import java.net.URLEncoder; + +import eu.alefzero.owncloud.AccountUtils; +import eu.alefzero.owncloud.R; +import eu.alefzero.owncloud.authenticator.AccountAuthenticator; +import eu.alefzero.owncloud.utils.OwnCloudVersion; +import eu.alefzero.webdav.WebdavClient; +import android.accounts.Account; +import android.accounts.AccountManager; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.Service; +import android.content.Intent; +import android.net.Uri; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.IBinder; +import android.os.Looper; +import android.os.Message; +import android.os.Process; +import android.util.Log; +import android.webkit.MimeTypeMap; +import android.widget.RemoteViews; +import android.widget.Toast; + +public class FileUploader extends Service { + + public static final String KEY_LOCAL_FILE = "LOCAL_FILE"; + public static final String KEY_REMOTE_FILE = "REMOTE_FILE"; + public static final String KEY_ACCOUNT = "ACCOUNT"; + public static final String KEY_UPLOAD_TYPE = "UPLOAD_TYPE"; + + public static final int UPLOAD_SINGLE_FILE = 0; + public static final int UPLOAD_MULTIPLE_FILES = 1; + + private static final String TAG = "FileUploader"; + private NotificationManager mNotificationManager; + private Looper mServiceLooper; + private ServiceHandler mServiceHandler; + private AccountManager mAccountManager; + private Account mAccount; + private String[] mLocalPaths, mRemotePaths; + private boolean mResult; + private int mUploadType; + + @Override + public IBinder onBind(Intent arg0) { + return null; + } + + private final class ServiceHandler extends Handler { + public ServiceHandler(Looper looper) { + super(looper); + } + @Override + public void handleMessage(Message msg) { + uploadFile(); + stopSelf(msg.arg1); + } + } + + @Override + public void onCreate() { + super.onCreate(); + mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + HandlerThread thread = new HandlerThread("FileUploaderThread", Process.THREAD_PRIORITY_BACKGROUND); + thread.start(); + mServiceLooper = thread.getLooper(); + mServiceHandler = new ServiceHandler(mServiceLooper); + mAccountManager = AccountManager.get(this); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + if (!intent.hasExtra(KEY_ACCOUNT) && !intent.hasExtra(KEY_UPLOAD_TYPE)) { + Log.e(TAG, "Not enought data in intent provided"); + return Service.START_NOT_STICKY; + } + mAccount = intent.getParcelableExtra(KEY_ACCOUNT); + mUploadType = intent.getIntExtra(KEY_UPLOAD_TYPE, -1); + if (mUploadType == -1) { + Log.e(TAG, "Incorrect upload type provided"); + return Service.START_NOT_STICKY; + } + if (mUploadType == UPLOAD_SINGLE_FILE) { + mLocalPaths = new String[] { intent.getStringExtra(KEY_LOCAL_FILE) }; + mRemotePaths = new String[] { intent.getStringExtra(KEY_REMOTE_FILE) }; + } else { // mUploadType == UPLOAD_MULTIPLE_FILES + mLocalPaths = intent.getStringArrayExtra(KEY_LOCAL_FILE); + mRemotePaths = intent.getStringArrayExtra(KEY_REMOTE_FILE); + } + + for (int i = 0; i < mRemotePaths.length; ++i) + mRemotePaths[i] = mRemotePaths[i].replace(' ', '+'); + + if (mLocalPaths.length != mRemotePaths.length) { + Log.e(TAG, "Remote paths and local paths are not equal!"); + return Service.START_NOT_STICKY; + } + + Message msg = mServiceHandler.obtainMessage(); + msg.arg1 = startId; + mServiceHandler.sendMessage(msg); + + return Service.START_NOT_STICKY; + } + + public void run() { + if (mResult) { + Toast.makeText(this, "Upload successfull", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(this, "No i kupa", Toast.LENGTH_SHORT).show(); + } + } + + public void uploadFile() { + String baseUrl = mAccountManager.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL), + ocVerStr = mAccountManager.getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION); + OwnCloudVersion ocVer = new OwnCloudVersion(ocVerStr); + String webdav_path = AccountUtils.getWebdavPath(ocVer); + Uri ocUri = Uri.parse(baseUrl + webdav_path); + String username = mAccount.name.substring(0, mAccount.name.lastIndexOf('@')); + String password = mAccountManager.getPassword(mAccount); + Notification notification = new Notification(eu.alefzero.owncloud.R.drawable.icon, + "Uploading...", System.currentTimeMillis()); + notification.flags |= Notification.FLAG_ONGOING_EVENT; + notification.contentView = new RemoteViews(getApplicationContext().getPackageName(), + R.layout.progressbar_layout); + notification.contentView.setProgressBar(R.id.status_progress, mLocalPaths.length-1, 0, false); + notification.contentView.setImageViewResource(R.id.status_icon, R.drawable.icon); + + mNotificationManager.notify(42, notification); + + WebdavClient wc = new WebdavClient(ocUri); + wc.setCredentials(username, password); + + for (int i = 0; i < mLocalPaths.length; ++i) { + String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(mLocalPaths[i].substring(mLocalPaths[i].lastIndexOf('.')+1)); + mResult = false; + if (wc.putFile(mLocalPaths[i], mRemotePaths[i], mimeType)) { + mResult |= true; + } + notification.contentView.setProgressBar(R.id.status_progress, mLocalPaths.length-1, i+1, false); + + mNotificationManager.notify(42, notification); + } + //notification.contentView.setProgressBar(R.id.status_progress, mLocalPaths.length-1, mLocalPaths.length-1, false); + mNotificationManager.cancel(42); + run(); + } +} diff --git a/src/eu/alefzero/owncloud/files/services/OnUploadCompletedListener.java b/src/eu/alefzero/owncloud/files/services/OnUploadCompletedListener.java new file mode 100644 index 00000000..750e2896 --- /dev/null +++ b/src/eu/alefzero/owncloud/files/services/OnUploadCompletedListener.java @@ -0,0 +1,8 @@ +package eu.alefzero.owncloud.files.services; + +public interface OnUploadCompletedListener extends Runnable { + + public boolean getUploadResult(); + + public void setUploadResult(boolean result); +} diff --git a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java index b87fd1d1..46e9be93 100644 --- a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java @@ -18,6 +18,9 @@ package eu.alefzero.owncloud.ui.activity; +import java.io.File; +import java.net.URLEncoder; + import android.accounts.Account; import android.accounts.AccountManager; import android.app.AlertDialog; @@ -55,8 +58,10 @@ import eu.alefzero.owncloud.authenticator.AccountAuthenticator; import eu.alefzero.owncloud.datamodel.DataStorageManager; import eu.alefzero.owncloud.datamodel.FileDataStorageManager; import eu.alefzero.owncloud.datamodel.OCFile; +import eu.alefzero.owncloud.files.services.FileUploader; import eu.alefzero.owncloud.syncadapter.FileSyncService; import eu.alefzero.owncloud.ui.fragment.FileListFragment; +import eu.alefzero.owncloud.utils.OwnCloudVersion; import eu.alefzero.webdav.WebdavClient; /** @@ -164,6 +169,9 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setProgressBarIndeterminateVisibility(false); + //if (getSupportFragmentManager().findFragmentById(R.id.fileList) == null) + setContentView(R.layout.files); + } @Override @@ -245,8 +253,6 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements IntentFilter f = new IntentFilter(FileSyncService.SYNC_MESSAGE); syncBroadcastRevceiver = new SyncBroadcastReceiver(); registerReceiver(syncBroadcastRevceiver, f); - if (getSupportFragmentManager().findFragmentById(R.id.fileList) == null) - setContentView(R.layout.files); mDirectories = new CustomArrayAdapter(this, R.layout.sherlock_spinner_dropdown_item); @@ -261,28 +267,40 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements } public void onActivityResult(int requestCode, int resultCode, Intent data) { + Log.e("ASD", requestCode + " " + resultCode); if (resultCode == RESULT_OK) { if (requestCode == ACTION_SELECT_FILE) { - Uri selectedImageUri = data.getData(); - - String filemanagerstring = selectedImageUri.getPath(); - - String selectedImagePath = getPath(selectedImageUri); - - //DEBUG PURPOSE - you can delete this if you want - if(selectedImagePath!=null) - System.out.println(selectedImagePath); - else System.out.println("selectedImagePath is null"); - if(filemanagerstring!=null) - System.out.println(filemanagerstring); - else System.out.println("filemanagerstring is null"); - - //NOW WE HAVE OUR WANTED STRING - if(selectedImagePath!=null) - System.out.println("selectedImagePath is the right one for you!"); - else - System.out.println("filemanagerstring is the right one for you!"); + Uri selectedImageUri = data.getData(); + + String filemanagerstring = selectedImageUri.getPath(); + String selectedImagePath = getPath(selectedImageUri); + String filepath; + + if(selectedImagePath!=null) + filepath = selectedImagePath; + else + filepath = filemanagerstring; + + if (filepath == null) { + Log.e("FileDisplay", "Couldnt resolve path to file"); + return; } + + Intent i = new Intent(this, FileUploader.class); + i.putExtra(FileUploader.KEY_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this)); + String remotepath = new String(); + for (int j = mDirectories.getCount() - 2; j >= 0; --j) { + remotepath += "/" + mDirectories.getItem(j); + } + if (!remotepath.endsWith("/")) remotepath += "/"; + remotepath += new File(filepath).getName(); + Log.e("ASD", remotepath+""); + + i.putExtra(FileUploader.KEY_LOCAL_FILE, filepath); + i.putExtra(FileUploader.KEY_REMOTE_FILE, remotepath); + i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE); + startService(i); + } } } @@ -291,8 +309,6 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements Cursor cursor = managedQuery(uri, projection, null, null, null); if(cursor!=null) { - //HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL - //THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); diff --git a/src/eu/alefzero/webdav/WebdavClient.java b/src/eu/alefzero/webdav/WebdavClient.java index 1416d17b..4b719fb6 100644 --- a/src/eu/alefzero/webdav/WebdavClient.java +++ b/src/eu/alefzero/webdav/WebdavClient.java @@ -31,6 +31,7 @@ import org.apache.commons.httpclient.auth.AuthScope; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.HeadMethod; import org.apache.commons.httpclient.methods.PutMethod; +import org.apache.commons.httpclient.methods.RequestEntity; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.commons.httpclient.protocol.Protocol; import org.apache.http.HttpStatus; @@ -102,10 +103,14 @@ public class WebdavClient extends HttpClient { String contentType) { boolean result = true; - try { - FileRequestEntity entity = new FileRequestEntity(new File(localFile), contentType); - PutMethod put = new PutMethod(mUri.toString() + remoteTarget.substring(1)); + try { + Log.e("ASD", contentType+""); + File f = new File(localFile); + RequestEntity entity = new FileRequestEntity(f, contentType); + Log.e("ASD", f.exists()+" " + entity.getContentLength()); + PutMethod put = new PutMethod(mUri.toString() + remoteTarget); put.setRequestEntity(entity); + Log.d(TAG, "" + put.getURI().toString()); int status = executeMethod(put); Log.d(TAG, "PUT method return with status "+status);