From: David A. Velasco Date: Wed, 18 Mar 2015 08:06:12 +0000 (+0100) Subject: Merge pull request #920 from owncloud/fix_crash_in_android_2 X-Git-Tag: oc-android-1.7.1_signed^2~19 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/2a9aae2ed15ba33ace939c71dfdd32322844063f?hp=4fedf76cb0d4248b0ff02d27c187b1584b0b42c8 Merge pull request #920 from owncloud/fix_crash_in_android_2 Fix crash in android 2: gridview --- diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 2537d80f..9fd7efe4 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -30,6 +30,7 @@ import android.accounts.Account; import android.content.Context; import android.content.SharedPreferences; import android.graphics.Bitmap; +import android.os.Build; import android.preference.PreferenceManager; import android.text.format.DateUtils; import android.view.LayoutInflater; @@ -37,7 +38,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.BaseAdapter; -import android.widget.GridView; import android.widget.ImageView; import android.widget.ListAdapter; import android.widget.TextView; @@ -196,15 +196,19 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { if (!file.isFolder()) { AbsListView parentList = (AbsListView)parent; - if (parentList.getChoiceMode() == AbsListView.CHOICE_MODE_NONE) { - checkBoxV.setVisibility(View.GONE); - } else { - if (parentList.isItemChecked(position)) { - checkBoxV.setImageResource(android.R.drawable.checkbox_on_background); + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + if (parentList.getChoiceMode() == AbsListView.CHOICE_MODE_NONE) { + checkBoxV.setVisibility(View.GONE); } else { - checkBoxV.setImageResource(android.R.drawable.checkbox_off_background); + if (parentList.isItemChecked(position)) { + checkBoxV.setImageResource( + android.R.drawable.checkbox_on_background); + } else { + checkBoxV.setImageResource( + android.R.drawable.checkbox_off_background); + } + checkBoxV.setVisibility(View.VISIBLE); } - checkBoxV.setVisibility(View.VISIBLE); } } else { //Folder @@ -230,15 +234,21 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { // local state ImageView localStateView = (ImageView) view.findViewById(R.id.localFileIndicator); localStateView.bringToFront(); - FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder(); - FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder(); - boolean downloading = (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)); - OperationsServiceBinder opsBinder = mTransferServiceGetter.getOperationsServiceBinder(); - downloading |= (opsBinder != null && opsBinder.isSynchronizing(mAccount, file.getRemotePath())); + FileDownloaderBinder downloaderBinder = + mTransferServiceGetter.getFileDownloaderBinder(); + FileUploaderBinder uploaderBinder = + mTransferServiceGetter.getFileUploaderBinder(); + boolean downloading = (downloaderBinder != null && + downloaderBinder.isDownloading(mAccount, file)); + OperationsServiceBinder opsBinder = + mTransferServiceGetter.getOperationsServiceBinder(); + downloading |= (opsBinder != null && + opsBinder.isSynchronizing(mAccount, file.getRemotePath())); if (downloading) { localStateView.setImageResource(R.drawable.downloading_file_indicator); localStateView.setVisibility(View.VISIBLE); - } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) { + } else if (uploaderBinder != null && + uploaderBinder.isUploading(mAccount, file)) { localStateView.setImageResource(R.drawable.uploading_file_indicator); localStateView.setVisibility(View.VISIBLE); } else if (file.isDown()) { @@ -250,7 +260,8 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { // share with me icon if (!file.isFolder()) { - ImageView sharedWithMeIconV = (ImageView) view.findViewById(R.id.sharedWithMeIcon); + ImageView sharedWithMeIconV = (ImageView) + view.findViewById(R.id.sharedWithMeIcon); sharedWithMeIconV.bringToFront(); if (checkIfFileIsSharedWithMe(file)) { sharedWithMeIconV.setVisibility(View.VISIBLE); @@ -302,7 +313,8 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { } } } else { - fileIcon.setImageResource(DisplayUtils.getFileTypeIconId(file.getMimetype(), file.getFileName())); + fileIcon.setImageResource(DisplayUtils.getFileTypeIconId(file.getMimetype(), + file.getFileName())); } } else { // Folder diff --git a/src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java b/src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java index 823abc5c..287c5b9e 100644 --- a/src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java @@ -40,8 +40,6 @@ import com.owncloud.android.datamodel.ThumbnailsCacheManager; import com.owncloud.android.utils.BitmapUtils; import com.owncloud.android.utils.DisplayUtils; -import third_parties.in.srain.cube.GridViewWithHeaderAndFooter; - /** * This Adapter populates a ListView with all files and directories contained * in a local directory diff --git a/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java b/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java index 03289cf9..fb58be3a 100644 --- a/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java +++ b/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java @@ -22,7 +22,7 @@ package com.owncloud.android.ui.fragment; import java.util.ArrayList; -import android.content.Context; +import android.os.Build; import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; import android.view.LayoutInflater; @@ -33,6 +33,7 @@ import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.GridView; import android.widget.ListAdapter; +import android.widget.ListView; import android.widget.TextView; import com.actionbarsherlock.app.SherlockFragment; @@ -80,10 +81,14 @@ implements OnItemClickListener, OnEnforceableRefreshListener { private ListAdapter mAdapter; - protected void setListAdapter(ListAdapter listAdapter) { mAdapter = listAdapter; - mCurrentListView.setAdapter(listAdapter); + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + mCurrentListView.setAdapter(listAdapter); + } else { + ((ListView)mCurrentListView).setAdapter(listAdapter); + } + mCurrentListView.invalidate(); } @@ -216,7 +221,8 @@ implements OnItemClickListener, OnEnforceableRefreshListener { */ protected int getReferencePosition() { if (mCurrentListView != null) { - return (mCurrentListView.getFirstVisiblePosition() + mCurrentListView.getLastVisiblePosition()) / 2; + return (mCurrentListView.getFirstVisiblePosition() + + mCurrentListView.getLastVisiblePosition()) / 2; } else { return 0; } @@ -234,7 +240,8 @@ implements OnItemClickListener, OnEnforceableRefreshListener { final int firstPosition = mFirstPositions.remove(mFirstPositions.size() -1); int top = mTops.remove(mTops.size() - 1); - Log_OC.v(TAG, "Setting selection to position: " + firstPosition + "; top: " + top + "; index: " + index); + Log_OC.v(TAG, "Setting selection to position: " + firstPosition + "; top: " + + top + "; index: " + index); if (mCurrentListView == mListView) { if (mHeightCell*index <= mListView.getHeight()) { @@ -331,8 +338,8 @@ implements OnItemClickListener, OnEnforceableRefreshListener { private void onCreateSwipeToRefresh(SwipeRefreshLayout refreshLayout) { // Colors in animations: background - refreshLayout.setColorScheme(R.color.background_color, R.color.background_color, R.color.background_color, - R.color.background_color); + refreshLayout.setColorScheme(R.color.background_color, R.color.background_color, + R.color.background_color, R.color.background_color); refreshLayout.setOnRefreshListener(this); } @@ -348,10 +355,13 @@ implements OnItemClickListener, OnEnforceableRefreshListener { } } - protected void setChoiceMode(int choiceMode) { - mListView.setChoiceMode(choiceMode); - mGridView.setChoiceMode(choiceMode); + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + mListView.setChoiceMode(choiceMode); + mGridView.setChoiceMode(choiceMode); + } else { + ((ListView)mListView).setChoiceMode(choiceMode); + } } protected void registerForContextMenu() { @@ -386,8 +396,8 @@ implements OnItemClickListener, OnEnforceableRefreshListener { mListFooterView.invalidate(); } else { - mGridView.removeFooterView(mGridFooterView); - mListView.removeFooterView(mListFooterView); +// mGridView.removeFooterView(mGridFooterView); +// mListView.removeFooterView(mListFooterView); } } diff --git a/src/com/owncloud/android/ui/fragment/LocalFileListFragment.java b/src/com/owncloud/android/ui/fragment/LocalFileListFragment.java index b3e40d8d..8a268b75 100644 --- a/src/com/owncloud/android/ui/fragment/LocalFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/LocalFileListFragment.java @@ -64,7 +64,8 @@ public class LocalFileListFragment extends ExtendedListFragment { try { mContainerActivity = (ContainerActivity) activity; } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() + " must implement " + LocalFileListFragment.ContainerActivity.class.getSimpleName()); + throw new ClassCastException(activity.toString() + " must implement " + + LocalFileListFragment.ContainerActivity.class.getSimpleName()); } } @@ -99,7 +100,8 @@ public class LocalFileListFragment extends ExtendedListFragment { } /** - * Checks the file clicked over. Browses inside if it is a directory. Notifies the container activity in any case. + * Checks the file clicked over. Browses inside if it is a directory. + * Notifies the container activity in any case. */ @Override public void onItemClick(AdapterView l, View v, int position, long id) { @@ -117,7 +119,7 @@ public class LocalFileListFragment extends ExtendedListFragment { } else { /// Click on a file ImageView checkBoxV = (ImageView) v.findViewById(R.id.custom_checkbox); if (checkBoxV != null) { - if (getListView().isItemChecked(position)) { + if (((ListView)getListView()).isItemChecked(position)) { checkBoxV.setImageResource(android.R.drawable.checkbox_on_background); } else { checkBoxV.setImageResource(android.R.drawable.checkbox_off_background); @@ -182,7 +184,8 @@ public class LocalFileListFragment extends ExtendedListFragment { if(mDirectory != null){ directory = mDirectory; } else { - directory = Environment.getExternalStorageDirectory(); // TODO be careful with the state of the storage; could not be available + directory = Environment.getExternalStorageDirectory(); + // TODO be careful with the state of the storage; could not be available if (directory == null) return; // no files to show } } @@ -194,7 +197,8 @@ public class LocalFileListFragment extends ExtendedListFragment { directory = directory.getParentFile(); } - mCurrentListView.clearChoices(); // by now, only files in the same directory will be kept as selected + // by now, only files in the same directory will be kept as selected + ((ListView)mCurrentListView).clearChoices(); mAdapter.swapDirectory(directory); if (mDirectory == null || !mDirectory.equals(directory)) { mCurrentListView.setSelection(0); @@ -210,11 +214,12 @@ public class LocalFileListFragment extends ExtendedListFragment { */ public String[] getCheckedFilePaths() { ArrayList result = new ArrayList(); - SparseBooleanArray positions = mCurrentListView.getCheckedItemPositions(); + SparseBooleanArray positions = ((ListView)mCurrentListView).getCheckedItemPositions(); if (positions.size() > 0) { for (int i = 0; i < positions.size(); i++) { if (positions.get(positions.keyAt(i)) == true) { - result.add(((File) mCurrentListView.getItemAtPosition(positions.keyAt(i))).getAbsolutePath()); + result.add(((File) mCurrentListView.getItemAtPosition( + positions.keyAt(i))).getAbsolutePath()); } } @@ -237,7 +242,8 @@ public class LocalFileListFragment extends ExtendedListFragment { public void onDirectoryClick(File directory); /** - * Callback method invoked when a file (non directory) is clicked by the user on the files list + * Callback method invoked when a file (non directory) + * is clicked by the user on the files list * * @param file */ @@ -245,7 +251,8 @@ public class LocalFileListFragment extends ExtendedListFragment { /** - * Callback method invoked when the parent activity is fully created to get the directory to list firstly. + * Callback method invoked when the parent activity + * is fully created to get the directory to list firstly. * * @return Directory to list firstly. Can be NULL. */