mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 07:05:49 +03:00
Fixed preview of images in Android 2.x ; fixed synchronization progress indicator in Android <4.0
This commit is contained in:
parent
91225458c1
commit
3ce234e6c7
5 changed files with 93 additions and 65 deletions
|
@ -18,7 +18,7 @@
|
|||
-->
|
||||
<manifest package="eu.alefzero.owncloud"
|
||||
android:versionCode="1"
|
||||
android:versionName="0.1.134B" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
android:versionName="0.1.135B" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
||||
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
|
||||
|
|
|
@ -68,6 +68,21 @@ public class AccountUtils {
|
|||
return defaultAccount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks, whether or not there are any ownCloud accounts setup.
|
||||
*
|
||||
* @return true, if there is at least one account.
|
||||
*/
|
||||
public static boolean accountsAreSetup(Context context) {
|
||||
AccountManager accMan = AccountManager.get(context);
|
||||
Account[] accounts = accMan
|
||||
.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE);
|
||||
return accounts.length > 0;
|
||||
}
|
||||
|
||||
|
||||
public static void setCurrentOwnCloudAccount(Context context, String name) {
|
||||
SharedPreferences.Editor appPrefs = PreferenceManager
|
||||
.getDefaultSharedPreferences(context).edit();
|
||||
|
|
|
@ -18,10 +18,7 @@
|
|||
|
||||
package eu.alefzero.owncloud.ui.activity;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.accounts.Account;
|
||||
|
@ -37,18 +34,15 @@ import android.content.DialogInterface.OnClickListener;
|
|||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckedTextView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -82,15 +76,16 @@ import eu.alefzero.webdav.WebdavClient;
|
|||
|
||||
public class FileDisplayActivity extends SherlockFragmentActivity implements
|
||||
OnNavigationListener, OnClickListener, android.view.View.OnClickListener {
|
||||
|
||||
private ArrayAdapter<String> mDirectories;
|
||||
private DataStorageManager mStorageManager;
|
||||
private FileListFragment mFileList;
|
||||
private OCFile mCurrentDir;
|
||||
private String[] mDirs = null;
|
||||
|
||||
private SyncBroadcastReceiver syncBroadcastRevceiver;
|
||||
private DataStorageManager mStorageManager;
|
||||
private SyncBroadcastReceiver syncBroadcastReceiver;
|
||||
|
||||
private View mLayoutView = null;
|
||||
private FileListFragment mFileList;
|
||||
|
||||
private static final String KEY_DIR_ARRAY = "DIR_ARRAY";
|
||||
private static final String KEY_CURRENT_DIR = "DIR";
|
||||
|
@ -98,39 +93,37 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
|
|||
private static final int DIALOG_SETUP_ACCOUNT = 0;
|
||||
private static final int DIALOG_CREATE_DIR = 1;
|
||||
private static final int DIALOG_ABOUT_APP = 2;
|
||||
|
||||
private static final int ACTION_SELECT_FILE = 1;
|
||||
//private static final int ACTION_CREATE_FIRST_ACCOUNT = 2; dvelasco: WIP
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(getClass().toString(), "onCreate() start");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// TODO: fix hack: workaround for bug in actionbar sherlock
|
||||
// it always shows indeterminate progress bar
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
|
||||
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
||||
setProgressBarIndeterminateVisibility(false);
|
||||
}
|
||||
setSupportProgressBarIndeterminateVisibility(false);
|
||||
|
||||
Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(getApplicationContext()));
|
||||
|
||||
if(savedInstanceState != null){
|
||||
mCurrentDir = (OCFile) savedInstanceState.getParcelable(KEY_CURRENT_DIR);
|
||||
mCurrentDir = (OCFile) savedInstanceState.getParcelable(KEY_CURRENT_DIR); // this is never saved with this key :S
|
||||
}
|
||||
|
||||
if (findViewById(R.id.file_list_view) == null)
|
||||
mLayoutView = getLayoutInflater().inflate(R.layout.files, null); // always inflate this at onCreate() ; just once!
|
||||
|
||||
//TODO: Dialog useless -> get rid of this
|
||||
if (!accountsAreSetup()) {
|
||||
if (AccountUtils.accountsAreSetup(this)) {
|
||||
setContentView(mLayoutView);
|
||||
|
||||
} else {
|
||||
setContentView(R.layout.no_account_available);
|
||||
setProgressBarIndeterminateVisibility(false);
|
||||
getSupportActionBar().setNavigationMode(ActionBar.DISPLAY_SHOW_TITLE);
|
||||
findViewById(R.id.setup_account).setOnClickListener(this);
|
||||
|
||||
} else if (findViewById(R.id.file_list_view) == null) {
|
||||
setContentView(mLayoutView);
|
||||
}
|
||||
|
||||
Log.i(getClass().toString(), "onCreate() end");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -199,8 +192,8 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
|
|||
* Called, when the user selected something for uploading
|
||||
*/
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (requestCode == ACTION_SELECT_FILE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
Uri selectedImageUri = data.getData();
|
||||
|
||||
String filemanagerstring = selectedImageUri.getPath();
|
||||
|
@ -234,7 +227,13 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
|
|||
i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
|
||||
startService(i);
|
||||
}
|
||||
|
||||
}/* dvelasco: WIP - not working as expected ... yet :)
|
||||
else if (requestCode == ACTION_CREATE_FIRST_ACCOUNT) {
|
||||
if (resultCode != RESULT_OK) {
|
||||
finish(); // the user cancelled the AuthenticatorActivity
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -255,6 +254,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
|
|||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
Log.i(getClass().toString(), "onRestoreInstanceState() start");
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
mDirs = savedInstanceState.getStringArray(KEY_DIR_ARRAY);
|
||||
mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);
|
||||
|
@ -263,10 +263,12 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
|
|||
for (String s : mDirs)
|
||||
mDirectories.insert(s, 0);
|
||||
mCurrentDir = savedInstanceState.getParcelable(FileDetailFragment.EXTRA_FILE);
|
||||
Log.i(getClass().toString(), "onRestoreInstanceState() end");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
Log.i(getClass().toString(), "onSaveInstanceState() start");
|
||||
super.onSaveInstanceState(outState);
|
||||
if(mDirectories != null && mDirectories.getCount() != 0){
|
||||
mDirs = new String[mDirectories.getCount()-1];
|
||||
|
@ -276,20 +278,30 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
|
|||
}
|
||||
outState.putStringArray(KEY_DIR_ARRAY, mDirs);
|
||||
outState.putParcelable(FileDetailFragment.EXTRA_FILE, mCurrentDir);
|
||||
Log.i(getClass().toString(), "onSaveInstanceState() end");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
Log.i(getClass().toString(), "onResume() start");
|
||||
super.onResume();
|
||||
|
||||
if (accountsAreSetup()) {
|
||||
if (!AccountUtils.accountsAreSetup(this)) {
|
||||
/*Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
|
||||
intent.putExtra(android.provider.Settings.EXTRA_AUTHORITIES, new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE });
|
||||
//startActivity(intent);
|
||||
startActivityForResult(intent, ACTION_CREATE_FIRST_ACCOUNT);*/
|
||||
|
||||
setContentView(mLayoutView); // this should solve the crash by repeated inflating in big screens (DROIDCLOUD-27)
|
||||
} else { // at least an account exist: normal operation
|
||||
|
||||
// set the layout only if it couldn't be set in onCreate
|
||||
if (findViewById(R.id.file_list_view) == null)
|
||||
setContentView(mLayoutView);
|
||||
|
||||
// Listen for sync messages
|
||||
IntentFilter syncIntentFilter = new IntentFilter(FileSyncService.SYNC_MESSAGE);
|
||||
syncBroadcastRevceiver = new SyncBroadcastReceiver();
|
||||
registerReceiver(syncBroadcastRevceiver, syncIntentFilter);
|
||||
syncBroadcastReceiver = new SyncBroadcastReceiver();
|
||||
registerReceiver(syncBroadcastReceiver, syncIntentFilter);
|
||||
|
||||
// Storage manager initialization
|
||||
mStorageManager = new FileDataStorageManager(
|
||||
|
@ -355,16 +367,19 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
|
|||
// List dir here
|
||||
mFileList.listDirectory(mCurrentDir);
|
||||
}
|
||||
Log.i(getClass().toString(), "onResume() end");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
Log.i(getClass().toString(), "onPause() start");
|
||||
super.onPause();
|
||||
if (syncBroadcastRevceiver != null) {
|
||||
unregisterReceiver(syncBroadcastRevceiver);
|
||||
syncBroadcastRevceiver = null;
|
||||
if (syncBroadcastReceiver != null) {
|
||||
unregisterReceiver(syncBroadcastReceiver);
|
||||
syncBroadcastReceiver = null;
|
||||
}
|
||||
getIntent().putExtra(FileDetailFragment.EXTRA_FILE, mCurrentDir);
|
||||
Log.i(getClass().toString(), "onPause() end");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -520,18 +535,6 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
|
|||
return !mDirectories.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks, whether or not there are any ownCloud accounts setup.
|
||||
*
|
||||
* @return true, if there is at least one account.
|
||||
*/
|
||||
private boolean accountsAreSetup() {
|
||||
AccountManager accMan = AccountManager.get(this);
|
||||
Account[] accounts = accMan
|
||||
.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE);
|
||||
return accounts.length > 0;
|
||||
}
|
||||
|
||||
private class DirectoryCreator implements Runnable {
|
||||
private String mTargetPath;
|
||||
private Account mAccount;
|
||||
|
@ -598,12 +601,12 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
|
|||
.getStringExtra(FileSyncService.ACCOUNT_NAME);
|
||||
Log.d("FileDisplay", "sync of account " + account_name
|
||||
+ " is in_progress: " + inProgress);
|
||||
setProgressBarIndeterminateVisibility(inProgress);
|
||||
setSupportProgressBarIndeterminateVisibility(inProgress);
|
||||
if (!inProgress) {
|
||||
FileListFragment fileListFramgent = (FileListFragment) getSupportFragmentManager()
|
||||
FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager()
|
||||
.findFragmentById(R.id.fileList);
|
||||
if (fileListFramgent != null)
|
||||
fileListFramgent.listDirectory();
|
||||
if (fileListFragment != null)
|
||||
fileListFragment.listDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -203,9 +203,13 @@ public class FileDetailFragment extends SherlockFragment implements
|
|||
if (mFile.getMimetype().startsWith("image/")) {
|
||||
BitmapFactory.Options options = new Options();
|
||||
options.inScaled = true;
|
||||
options.inMutable = false;
|
||||
options.inPreferQualityOverSpeed = false;
|
||||
options.inPurgeable = true;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
options.inPreferQualityOverSpeed = false;
|
||||
}
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
|
||||
options.inMutable = false;
|
||||
}
|
||||
|
||||
Bitmap bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options);
|
||||
|
||||
|
@ -224,6 +228,14 @@ public class FileDetailFragment extends SherlockFragment implements
|
|||
} catch (OutOfMemoryError e) {
|
||||
preview.setVisibility(View.INVISIBLE);
|
||||
Log.e(TAG, "Out of memory occured for file with size " + mFile.getFileLength());
|
||||
|
||||
} catch (NoSuchFieldError e) {
|
||||
preview.setVisibility(View.INVISIBLE);
|
||||
Log.e(TAG, "Error from access to unexisting field despite protection " + mFile.getFileLength());
|
||||
|
||||
} catch (Throwable t) {
|
||||
preview.setVisibility(View.INVISIBLE);
|
||||
Log.e(TAG, "Unexpected error while creating image preview " + mFile.getFileLength());
|
||||
}
|
||||
downloadButton.setText(R.string.filedetails_open);
|
||||
downloadButton.setOnClickListener(new OnClickListener() {
|
||||
|
|
|
@ -50,36 +50,40 @@ import eu.alefzero.owncloud.ui.adapter.FileListListAdapter;
|
|||
*/
|
||||
public class FileListFragment extends FragmentListView {
|
||||
private static final String TAG = "FileListFragment";
|
||||
//private Account mAccount; // dvelasco : the fragment is not recreated when other account is selected; keep as an attribute is dangerous
|
||||
|
||||
private Vector<OCFile> mFiles;
|
||||
//private DataStorageManager mStorageManager; // dvelasco : just the same; it depends upon the current account ; it's updated in FileDisplayActivity!!
|
||||
private OCFile mFile;
|
||||
private boolean mIsLargeDevice = false;
|
||||
private boolean mIsLargeDevice;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(getClass().toString(), "onCreate() start");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Intent intent = getActivity().getIntent();
|
||||
OCFile directory = intent.getParcelableExtra(FileDetailFragment.EXTRA_FILE);
|
||||
mFile = directory;
|
||||
mIsLargeDevice = false;
|
||||
|
||||
Log.i(getClass().toString(), "onCreate() stop");
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
Log.i(getClass().toString(), "onCreateView() start");
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
getListView().setDivider(getResources().getDrawable(R.drawable.uploader_list_separator));
|
||||
getListView().setDividerHeight(1);
|
||||
|
||||
//listDirectory(mFile);
|
||||
|
||||
Log.i(getClass().toString(), "onCreateView() end");
|
||||
return getListView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
Log.i(getClass().toString(), "onStart() start");
|
||||
super.onStart();
|
||||
// Create a placeholder upon launch
|
||||
View fragmentContainer = getActivity().findViewById(R.id.file_details_container);
|
||||
if (fragmentContainer != null) {
|
||||
|
@ -88,7 +92,7 @@ public class FileListFragment extends FragmentListView {
|
|||
transaction.replace(R.id.file_details_container, new FileDetailFragment(true));
|
||||
transaction.commit();
|
||||
}
|
||||
super.onStart();
|
||||
Log.i(getClass().toString(), "onStart() end");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -212,10 +216,4 @@ public class FileListFragment extends FragmentListView {
|
|||
setListAdapter(new FileListListAdapter(directory, storageManager, getActivity()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable("ACCOUNT", AccountUtils.getCurrentOwnCloudAccount(getActivity()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue