From: Bartek Przybylski Date: Sun, 13 May 2012 14:19:22 +0000 (+0200) Subject: merge fix X-Git-Tag: oc-android-1.4.3~426 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/390949b8323633b26d56b3a837e83941cbc24b4b?hp=-c merge fix --- 390949b8323633b26d56b3a837e83941cbc24b4b diff --combined src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java index cec268bd,294dbfa6..1db5246e --- a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java @@@ -23,17 -23,15 +23,17 @@@ import android.accounts.AccountManager import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.Dialog; + import android.content.BroadcastReceiver; + import android.content.ContentResolver; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; - import android.content.BroadcastReceiver; - import android.content.ContentResolver; import android.content.Intent; import android.content.IntentFilter; +import android.database.Cursor; import android.net.Uri; import android.os.Bundle; +import android.provider.MediaStore; import android.util.Log; import android.view.View; import android.view.ViewGroup; @@@ -71,13 -69,10 +71,13 @@@ public class FileDisplayActivity extend private ArrayAdapter mDirectories; private DataStorageManager mStorageManager; - private BR b; + private SyncBroadcastReceiver syncBroadcastRevceiver; private static final int DIALOG_SETUP_ACCOUNT = 0; private static final int DIALOG_CREATE_DIR = 1; + + private static final int REQUEST_ACCOUNT_SETUP = 0; + private static final int ACTION_SELECT_FILE = 1; public void pushPath(String path) { mDirectories.insert(path, 0); @@@ -98,8 -93,8 +98,8 @@@ builder.setTitle(R.string.main_tit_accsetup); builder.setMessage(R.string.main_wrn_accsetup); builder.setCancelable(false); - builder.setPositiveButton(R.string.common_ok, this); - builder.setNegativeButton(R.string.common_cancel, this); + builder.setPositiveButton(android.R.string.ok, this); + builder.setNegativeButton(android.R.string.cancel, this); dialog = builder.create(); break; case DIALOG_CREATE_DIR: @@@ -109,13 -104,12 +109,13 @@@ final Account a = AccountUtils.getCurrentOwnCloudAccount(this); builder.setView(dirName); builder.setTitle(R.string.uploader_info_dirname); - dirName.setTextColor(R.color.setup_text_typed); + int typed_color = getResources().getColor(R.color.setup_text_typed); + dirName.setTextColor(typed_color); - builder.setPositiveButton(R.string.common_ok, new OnClickListener() { + builder.setPositiveButton(android.R.string.ok, new OnClickListener() { public void onClick(DialogInterface dialog, int which) { String s = dirName.getText().toString(); - if (s.trim().isEmpty()) { + if (s.trim().length() == 0) { dialog.cancel(); return; } @@@ -143,8 -137,6 +143,8 @@@ dialog.cancel(); } }); + dialog = builder.create(); + break; } default: dialog = null; @@@ -156,19 -148,27 +156,19 @@@ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + if(!accountsAreSetup()){ showDialog(DIALOG_SETUP_ACCOUNT); return; } - - requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); - - mDirectories = new CustomArrayAdapter(this, - R.layout.sherlock_spinner_dropdown_item); - mDirectories.add("/"); - setContentView(R.layout.files); - mStorageManager = new FileDataStorageManager(AccountUtils.getCurrentOwnCloudAccount(this), getContentResolver()); - ActionBar action_bar = getSupportActionBar(); - action_bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); - action_bar.setDisplayShowTitleEnabled(false); - action_bar.setListNavigationCallbacks(mDirectories, this); - action_bar.setDisplayHomeAsUpEnabled(true); + + requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); + setProgressBarIndeterminateVisibility(false); } @Override public boolean onOptionsItemSelected(MenuItem item) { + boolean retval = true; switch (item.getItemId()) { case R.id.settingsItem: { Intent i = new Intent(this, Preferences.class); @@@ -187,23 -187,13 +187,23 @@@ bundle); break; } + case R.id.action_upload: { + Intent action = new Intent(Intent.ACTION_GET_CONTENT); + action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE); + startActivityForResult(Intent.createChooser(action, "Upload file from..."), ACTION_SELECT_FILE); + break; + } + case android.R.id.home: { - onBackPressed(); + Intent i = new Intent(this, AccountSelectActivity.class); + startActivity(i); + finish(); break; } - + default: + retval = false; } - return true; + return retval; } @Override @@@ -232,7 -222,15 +232,7 @@@ showDialog(DIALOG_SETUP_ACCOUNT); } } - - @Override - protected void onStart() { - super.onStart(); - // Check, if there are ownCloud accounts - if(!accountsAreSetup()){ - showDialog(DIALOG_SETUP_ACCOUNT); - } - } + @Override protected void onResume() { @@@ -241,74 -239,18 +241,74 @@@ showDialog(DIALOG_SETUP_ACCOUNT); return; } - IntentFilter syncMessageIntentFilter = new IntentFilter(FileSyncService.SYNC_MESSAGE); - syncBroadcastRevceiver = new SyncBroadcastReceiver(); - registerReceiver(syncBroadcastRevceiver, syncMessageIntentFilter); - setProgressBarIndeterminateVisibility(false); + + IntentFilter f = new IntentFilter(FileSyncService.SYNC_MESSAGE); + b = new BR(); + registerReceiver(b, f); + if (getSupportFragmentManager().findFragmentById(R.id.fileList) == null) + setContentView(R.layout.files); + + mDirectories = new CustomArrayAdapter(this, + R.layout.sherlock_spinner_dropdown_item); + mDirectories.add("/"); + + mStorageManager = new FileDataStorageManager(AccountUtils.getCurrentOwnCloudAccount(this), getContentResolver()); + ActionBar action_bar = getSupportActionBar(); + action_bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); + action_bar.setDisplayShowTitleEnabled(false); + action_bar.setListNavigationCallbacks(mDirectories, this); + action_bar.setDisplayHomeAsUpEnabled(true); } + public void onActivityResult(int requestCode, int resultCode, Intent data) { + 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!"); + } + } + } + + public String getPath(Uri uri) { + String[] projection = { MediaStore.Images.Media.DATA }; + 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(); + return cursor.getString(column_index); + } + else return null; + } + @Override protected void onPause() { super.onPause(); - if(syncBroadcastRevceiver != null){ - unregisterReceiver(syncBroadcastRevceiver); + if (b != null) { + unregisterReceiver(b); + b = null; } + } @Override @@@ -379,7 -321,7 +379,7 @@@ } - + public void onClick(DialogInterface dialog, int which) { // In any case - we won't need it anymore dialog.dismiss(); @@@ -409,17 -351,20 +409,20 @@@ return accounts.length > 0; } - private class BR extends BroadcastReceiver { + private class SyncBroadcastReceiver extends BroadcastReceiver { + /** + * {@link BroadcastReceiver} to enable syncing feedback in UI + */ @Override public void onReceive(Context context, Intent intent) { - boolean in_progress = intent.getBooleanExtra(FileSyncService.IN_PROGRESS, false); + boolean inProgress = intent.getBooleanExtra(FileSyncService.IN_PROGRESS, false); String account_name = intent.getStringExtra(FileSyncService.ACCOUNT_NAME); - Log.d("FileDisplay", "sync of account " + account_name + " is in_progress: " + in_progress); - setProgressBarIndeterminateVisibility(in_progress); - if (!in_progress) { - FileListFragment f = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); - if (f != null) - f.populateFileList(); + Log.d("FileDisplay", "sync of account " + account_name + " is in_progress: " + inProgress); + setProgressBarIndeterminateVisibility(inProgress); + if (!inProgress) { + FileListFragment fileListFramgent = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList); + if (fileListFramgent != null) + fileListFramgent.populateFileList(); } }