aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/cyanogenmod/filemanager
diff options
context:
space:
mode:
authorJorge Ruesga <jorge@ruesga.com>2013-11-29 01:38:05 +0100
committerJorge Ruesga <jorge@ruesga.com>2013-11-29 01:38:05 +0100
commit299d5e31b4ec15dc5a01afd9d1b7034ef4603a8f (patch)
treee364e788655bd4c08e12dd99bd2453e83b0fe4c1 /src/com/cyanogenmod/filemanager
parent92a87e30b4358fc107a48438cfa06f2a7eda3347 (diff)
downloadandroid_packages_apps_CMFileManager-299d5e31b4ec15dc5a01afd9d1b7034ef4603a8f.tar.gz
android_packages_apps_CMFileManager-299d5e31b4ec15dc5a01afd9d1b7034ef4603a8f.tar.bz2
android_packages_apps_CMFileManager-299d5e31b4ec15dc5a01afd9d1b7034ef4603a8f.zip
CMFM: Fix more deadlocks
Change-Id: Iad7042126436c26f93f384358082d4fb0e780352 Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Diffstat (limited to 'src/com/cyanogenmod/filemanager')
-rw-r--r--src/com/cyanogenmod/filemanager/activities/preferences/ThemesPreferenceFragment.java12
-rw-r--r--src/com/cyanogenmod/filemanager/adapters/FileSystemObjectAdapter.java24
-rw-r--r--src/com/cyanogenmod/filemanager/ui/widgets/NavigationView.java582
3 files changed, 287 insertions, 331 deletions
diff --git a/src/com/cyanogenmod/filemanager/activities/preferences/ThemesPreferenceFragment.java b/src/com/cyanogenmod/filemanager/activities/preferences/ThemesPreferenceFragment.java
index ad0a99fc..ac70a6b5 100644
--- a/src/com/cyanogenmod/filemanager/activities/preferences/ThemesPreferenceFragment.java
+++ b/src/com/cyanogenmod/filemanager/activities/preferences/ThemesPreferenceFragment.java
@@ -17,7 +17,6 @@
package com.cyanogenmod.filemanager.activities.preferences;
import android.content.Context;
-import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
@@ -50,17 +49,6 @@ public class ThemesPreferenceFragment extends TitlePreferenceFragment {
key,
String.valueOf(newValue)));
}
-
- // Notify to all activities that the theme has changed
- Intent intent = new Intent(FileManagerSettings.INTENT_THEME_CHANGED);
- intent.putExtra(FileManagerSettings.EXTRA_THEME_ID, (String)newValue);
- getActivity().sendBroadcast(intent);
-
- //Wait for allow activities to apply the theme, prior to finish settings
- try {
- Thread.sleep(250L);
- } catch (Throwable e) {/**NON BLOCK**/}
- getActivity().finish();
return true;
}
};
diff --git a/src/com/cyanogenmod/filemanager/adapters/FileSystemObjectAdapter.java b/src/com/cyanogenmod/filemanager/adapters/FileSystemObjectAdapter.java
index 1f64e2a5..2c8d802e 100644
--- a/src/com/cyanogenmod/filemanager/adapters/FileSystemObjectAdapter.java
+++ b/src/com/cyanogenmod/filemanager/adapters/FileSystemObjectAdapter.java
@@ -275,23 +275,6 @@ public class FileSystemObjectAdapter
viewHolder.mBtCheck = (ImageButton)v.findViewById(RESOURCE_ITEM_CHECK);
viewHolder.mBtCheck.setVisibility(View.GONE);
}
-
- // Apply the current theme
- if (this.mPickable) {
- theme.setBackgroundDrawable(
- getContext(), v, "background_drawable"); //$NON-NLS-1$
- }
- theme.setTextColor(
- getContext(), viewHolder.mTvName, "text_color"); //$NON-NLS-1$
- if (viewHolder.mTvSummary != null) {
- theme.setTextColor(
- getContext(), viewHolder.mTvSummary, "text_color"); //$NON-NLS-1$
- }
- if (viewHolder.mTvSize != null) {
- theme.setTextColor(
- getContext(), viewHolder.mTvSize, "text_color"); //$NON-NLS-1$
- }
-
v.setTag(viewHolder);
}
@@ -300,9 +283,11 @@ public class FileSystemObjectAdapter
//Retrieve the view holder
ViewHolder viewHolder = (ViewHolder)v.getTag();
+ if (this.mPickable) {
+ theme.setBackgroundDrawable(getContext(), v, "background_drawable"); //$NON-NLS-1$
+ }
//Set the data
-
if (convertView != null) {
// Cancel load for previous usage
mIconHolder.cancelLoad(viewHolder.mIvIcon);
@@ -310,11 +295,14 @@ public class FileSystemObjectAdapter
mIconHolder.loadDrawable(viewHolder.mIvIcon, getItem(position), dataHolder.mDwIcon);
viewHolder.mTvName.setText(dataHolder.mName);
+ theme.setTextColor(getContext(), viewHolder.mTvName, "text_color"); //$NON-NLS-1$
if (viewHolder.mTvSummary != null) {
viewHolder.mTvSummary.setText(dataHolder.mSummary);
+ theme.setTextColor(getContext(), viewHolder.mTvSummary, "text_color"); //$NON-NLS-1$
}
if (viewHolder.mTvSize != null) {
viewHolder.mTvSize.setText(dataHolder.mSize);
+ theme.setTextColor(getContext(), viewHolder.mTvSize, "text_color"); //$NON-NLS-1$
}
if (!this.mPickable) {
viewHolder.mBtCheck.setVisibility(
diff --git a/src/com/cyanogenmod/filemanager/ui/widgets/NavigationView.java b/src/com/cyanogenmod/filemanager/ui/widgets/NavigationView.java
index 61aa09e5..1563d922 100644
--- a/src/com/cyanogenmod/filemanager/ui/widgets/NavigationView.java
+++ b/src/com/cyanogenmod/filemanager/ui/widgets/NavigationView.java
@@ -203,6 +203,198 @@ public class NavigationView extends RelativeLayout implements
}
};
+ private class NavigationTask extends AsyncTask<String, Integer, List<FileSystemObject>> {
+ private final boolean mUseCurrent;
+ private final boolean mAddToHistory;
+ private final boolean mReload;
+ private boolean mHasChanged;
+ private boolean mIsNewHistory;
+ private String mNewDirChecked;
+ private final SearchInfoParcelable mSearchInfo;
+ private final FileSystemObject mScrollTo;
+
+ public NavigationTask(boolean useCurrent, boolean addToHistory, boolean reload,
+ SearchInfoParcelable searchInfo, FileSystemObject scrollTo) {
+ super();
+ this.mUseCurrent = useCurrent;
+ this.mAddToHistory = addToHistory;
+ this.mSearchInfo = searchInfo;
+ this.mReload = reload;
+ this.mScrollTo = scrollTo;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected List<FileSystemObject> doInBackground(String... params) {
+ // Check navigation security (don't allow to go outside the ChRooted environment if one
+ // is created)
+ mNewDirChecked = checkChRootedNavigation(params[0]);
+
+ //Check that it is really necessary change the directory
+ if (!mReload && NavigationView.this.mCurrentDir != null &&
+ NavigationView.this.mCurrentDir.compareTo(mNewDirChecked) == 0) {
+ return null;
+ }
+
+ mHasChanged = !(NavigationView.this.mCurrentDir != null &&
+ NavigationView.this.mCurrentDir.compareTo(mNewDirChecked) == 0);
+ mIsNewHistory = (NavigationView.this.mCurrentDir != null);
+
+ try {
+ //Reset the custom title view and returns to breadcrumb
+ if (NavigationView.this.mTitle != null) {
+ NavigationView.this.mTitle.post(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ NavigationView.this.mTitle.restoreView();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+
+
+ //Start of loading data
+ if (NavigationView.this.mBreadcrumb != null) {
+ try {
+ NavigationView.this.mBreadcrumb.startLoading();
+ } catch (Throwable ex) {
+ /**NON BLOCK**/
+ }
+ }
+
+ //Get the files, resolve links and apply configuration
+ //(sort, hidden, ...)
+ List<FileSystemObject> files = NavigationView.this.mFiles;
+ if (!mUseCurrent) {
+ files = CommandHelper.listFiles(getContext(), mNewDirChecked, null);
+ }
+ return files;
+
+ } catch (final ConsoleAllocException e) {
+ //Show exception and exists
+ NavigationView.this.post(new Runnable() {
+ @Override
+ public void run() {
+ Context ctx = getContext();
+ Log.e(TAG, ctx.getString(
+ R.string.msgs_cant_create_console), e);
+ DialogHelper.showToast(ctx,
+ R.string.msgs_cant_create_console,
+ Toast.LENGTH_LONG);
+ ((Activity)ctx).finish();
+ }
+ });
+
+ } catch (Exception ex) {
+ //End of loading data
+ if (NavigationView.this.mBreadcrumb != null) {
+ try {
+ NavigationView.this.mBreadcrumb.endLoading();
+ } catch (Throwable ex2) {
+ /**NON BLOCK**/
+ }
+ }
+
+ //Capture exception (attach task, and use listener to do the anim)
+ ExceptionUtil.attachAsyncTask(
+ ex,
+ new AsyncTask<Object, Integer, Boolean>() {
+ private List<FileSystemObject> mTaskFiles = null;
+ @Override
+ @SuppressWarnings({
+ "unchecked", "unqualified-field-access"
+ })
+ protected Boolean doInBackground(Object... taskParams) {
+ mTaskFiles = (List<FileSystemObject>)taskParams[0];
+ return Boolean.TRUE;
+ }
+
+ @Override
+ @SuppressWarnings("unqualified-field-access")
+ protected void onPostExecute(Boolean result) {
+ if (!result.booleanValue()) {
+ return;
+ }
+ onPostExecuteTask(
+ mTaskFiles, mAddToHistory, mIsNewHistory, mHasChanged,
+ mSearchInfo, mNewDirChecked, mScrollTo);
+ }
+ });
+ final OnRelaunchCommandResult exListener =
+ new OnRelaunchCommandResult() {
+ @Override
+ public void onSuccess() {
+ done();
+ }
+ @Override
+ public void onFailed(Throwable cause) {
+ done();
+ }
+ @Override
+ public void onCancelled() {
+ done();
+ }
+ private void done() {
+ // Do animation
+ fadeEfect(false);
+ }
+ };
+ ExceptionUtil.translateException(
+ getContext(), ex, false, true, exListener);
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onCancelled(List<FileSystemObject> result) {
+ onCancelled();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onPostExecute(List<FileSystemObject> files) {
+ // This means an exception. This method will be recalled then
+ if (files != null) {
+ onPostExecuteTask(files, mAddToHistory, mIsNewHistory, mHasChanged,
+ mSearchInfo, mNewDirChecked, mScrollTo);
+
+ // Do animation
+ fadeEfect(false);
+ }
+ }
+
+ /**
+ * Method that performs a fade animation.
+ *
+ * @param out Fade out (true); Fade in (false)
+ */
+ void fadeEfect(final boolean out) {
+ Activity activity = (Activity)getContext();
+ activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Animation fadeAnim = out ?
+ new AlphaAnimation(1, 0) :
+ new AlphaAnimation(0, 1);
+ fadeAnim.setDuration(50L);
+ fadeAnim.setFillAfter(true);
+ fadeAnim.setInterpolator(new AccelerateInterpolator());
+ NavigationView.this.startAnimation(fadeAnim);
+ }
+ });
+ }
+ };
+
private int mId;
private String mCurrentDir;
private NavigationLayoutMode mCurrentMode;
@@ -212,9 +404,6 @@ public class NavigationView extends RelativeLayout implements
List<FileSystemObject> mFiles;
private FileSystemObjectAdapter mAdapter;
- private boolean mChangingDir;
- private final Object mSync = new Object();
-
private OnHistoryListener mOnHistoryListener;
private OnNavigationSelectionChangedListener mOnNavigationSelectionChangedListener;
private OnNavigationRequestMenuListener mOnNavigationRequestMenuListener;
@@ -314,12 +503,6 @@ public class NavigationView extends RelativeLayout implements
* @return boolean If can restore
*/
public boolean onRestoreState(NavigationViewInfoParcelable info) {
- synchronized (mSync) {
- if (mChangingDir) {
- return false;
- }
- }
-
//Restore the data
this.mId = info.getId();
this.mCurrentDir = info.getCurrentDir();
@@ -609,106 +792,104 @@ public class NavigationView extends RelativeLayout implements
*/
@SuppressWarnings("unchecked")
public void changeViewMode(final NavigationLayoutMode newMode) {
- synchronized (this.mSync) {
- //Check that it is really necessary change the mode
- if (this.mCurrentMode != null && this.mCurrentMode.compareTo(newMode) == 0) {
- return;
- }
+ //Check that it is really necessary change the mode
+ if (this.mCurrentMode != null && this.mCurrentMode.compareTo(newMode) == 0) {
+ return;
+ }
- // If we should set the listview to response to flinger gesture detection
- boolean useFlinger =
- Preferences.getSharedPreferences().getBoolean(
- FileManagerSettings.SETTINGS_USE_FLINGER.getId(),
- ((Boolean)FileManagerSettings.
- SETTINGS_USE_FLINGER.
- getDefaultValue()).booleanValue());
-
- //Creates the new layout
- AdapterView<ListAdapter> newView = null;
- int itemResourceId = -1;
- if (newMode.compareTo(NavigationLayoutMode.ICONS) == 0) {
- newView = (AdapterView<ListAdapter>)inflate(
- getContext(), RESOURCE_MODE_ICONS_LAYOUT, null);
- itemResourceId = RESOURCE_MODE_ICONS_ITEM;
-
- } else if (newMode.compareTo(NavigationLayoutMode.SIMPLE) == 0) {
- newView = (AdapterView<ListAdapter>)inflate(
- getContext(), RESOURCE_MODE_SIMPLE_LAYOUT, null);
- itemResourceId = RESOURCE_MODE_SIMPLE_ITEM;
-
- // Set the flinger listener (only when navigate)
- if (this.mNavigationMode.compareTo(NAVIGATION_MODE.BROWSABLE) == 0) {
- if (useFlinger && newView instanceof FlingerListView) {
- ((FlingerListView)newView).
- setOnItemFlingerListener(this.mOnItemFlingerListener);
- }
+ // If we should set the listview to response to flinger gesture detection
+ boolean useFlinger =
+ Preferences.getSharedPreferences().getBoolean(
+ FileManagerSettings.SETTINGS_USE_FLINGER.getId(),
+ ((Boolean)FileManagerSettings.
+ SETTINGS_USE_FLINGER.
+ getDefaultValue()).booleanValue());
+
+ //Creates the new layout
+ AdapterView<ListAdapter> newView = null;
+ int itemResourceId = -1;
+ if (newMode.compareTo(NavigationLayoutMode.ICONS) == 0) {
+ newView = (AdapterView<ListAdapter>)inflate(
+ getContext(), RESOURCE_MODE_ICONS_LAYOUT, null);
+ itemResourceId = RESOURCE_MODE_ICONS_ITEM;
+
+ } else if (newMode.compareTo(NavigationLayoutMode.SIMPLE) == 0) {
+ newView = (AdapterView<ListAdapter>)inflate(
+ getContext(), RESOURCE_MODE_SIMPLE_LAYOUT, null);
+ itemResourceId = RESOURCE_MODE_SIMPLE_ITEM;
+
+ // Set the flinger listener (only when navigate)
+ if (this.mNavigationMode.compareTo(NAVIGATION_MODE.BROWSABLE) == 0) {
+ if (useFlinger && newView instanceof FlingerListView) {
+ ((FlingerListView)newView).
+ setOnItemFlingerListener(this.mOnItemFlingerListener);
}
+ }
- } else if (newMode.compareTo(NavigationLayoutMode.DETAILS) == 0) {
- newView = (AdapterView<ListAdapter>)inflate(
- getContext(), RESOURCE_MODE_DETAILS_LAYOUT, null);
- itemResourceId = RESOURCE_MODE_DETAILS_ITEM;
+ } else if (newMode.compareTo(NavigationLayoutMode.DETAILS) == 0) {
+ newView = (AdapterView<ListAdapter>)inflate(
+ getContext(), RESOURCE_MODE_DETAILS_LAYOUT, null);
+ itemResourceId = RESOURCE_MODE_DETAILS_ITEM;
- // Set the flinger listener (only when navigate)
- if (this.mNavigationMode.compareTo(NAVIGATION_MODE.BROWSABLE) == 0) {
- if (useFlinger && newView instanceof FlingerListView) {
- ((FlingerListView)newView).
- setOnItemFlingerListener(this.mOnItemFlingerListener);
- }
+ // Set the flinger listener (only when navigate)
+ if (this.mNavigationMode.compareTo(NAVIGATION_MODE.BROWSABLE) == 0) {
+ if (useFlinger && newView instanceof FlingerListView) {
+ ((FlingerListView)newView).
+ setOnItemFlingerListener(this.mOnItemFlingerListener);
}
}
+ }
- //Get the current adapter and its adapter list
- List<FileSystemObject> files = new ArrayList<FileSystemObject>(this.mFiles);
- final AdapterView<ListAdapter> current =
- (AdapterView<ListAdapter>)findViewById(RESOURCE_CURRENT_LAYOUT);
- FileSystemObjectAdapter adapter =
- new FileSystemObjectAdapter(
- getContext(),
- new ArrayList<FileSystemObject>(),
- itemResourceId,
- this.mNavigationMode.compareTo(NAVIGATION_MODE.PICKABLE) == 0);
- adapter.setOnSelectionChangedListener(this);
-
- //Remove current layout
- if (current != null) {
- if (current.getAdapter() != null) {
- //Save selected items before dispose adapter
- FileSystemObjectAdapter currentAdapter =
- ((FileSystemObjectAdapter)current.getAdapter());
- adapter.setSelectedItems(currentAdapter.getSelectedItems());
- currentAdapter.dispose();
- }
- removeView(current);
+ //Get the current adapter and its adapter list
+ List<FileSystemObject> files = new ArrayList<FileSystemObject>(this.mFiles);
+ final AdapterView<ListAdapter> current =
+ (AdapterView<ListAdapter>)findViewById(RESOURCE_CURRENT_LAYOUT);
+ FileSystemObjectAdapter adapter =
+ new FileSystemObjectAdapter(
+ getContext(),
+ new ArrayList<FileSystemObject>(),
+ itemResourceId,
+ this.mNavigationMode.compareTo(NAVIGATION_MODE.PICKABLE) == 0);
+ adapter.setOnSelectionChangedListener(this);
+
+ //Remove current layout
+ if (current != null) {
+ if (current.getAdapter() != null) {
+ //Save selected items before dispose adapter
+ FileSystemObjectAdapter currentAdapter =
+ ((FileSystemObjectAdapter)current.getAdapter());
+ adapter.setSelectedItems(currentAdapter.getSelectedItems());
+ currentAdapter.dispose();
}
- this.mFiles = files;
- adapter.addAll(files);
+ removeView(current);
+ }
+ this.mFiles = files;
+ adapter.addAll(files);
- //Set the adapter
- this.mAdapter = adapter;
- newView.setAdapter(this.mAdapter);
- newView.setOnItemClickListener(NavigationView.this);
+ //Set the adapter
+ this.mAdapter = adapter;
+ newView.setAdapter(this.mAdapter);
+ newView.setOnItemClickListener(NavigationView.this);
- //Add the new layout
- this.mAdapterView = newView;
- addView(newView, 0);
- this.mCurrentMode = newMode;
+ //Add the new layout
+ this.mAdapterView = newView;
+ addView(newView, 0);
+ this.mCurrentMode = newMode;
- // Pick mode doesn't implements the onlongclick
- if (this.mNavigationMode.compareTo(NAVIGATION_MODE.BROWSABLE) == 0) {
- this.mAdapterView.setOnItemLongClickListener(this);
- } else {
- this.mAdapterView.setOnItemLongClickListener(null);
- }
+ // Pick mode doesn't implements the onlongclick
+ if (this.mNavigationMode.compareTo(NAVIGATION_MODE.BROWSABLE) == 0) {
+ this.mAdapterView.setOnItemLongClickListener(this);
+ } else {
+ this.mAdapterView.setOnItemLongClickListener(null);
+ }
- //Save the preference (only in navigation browse mode)
- if (this.mNavigationMode.compareTo(NAVIGATION_MODE.BROWSABLE) == 0) {
- try {
- Preferences.savePreference(
- FileManagerSettings.SETTINGS_LAYOUT_MODE, newMode, true);
- } catch (Exception ex) {
- Log.e(TAG, "Save of view mode preference fails", ex); //$NON-NLS-1$
- }
+ //Save the preference (only in navigation browse mode)
+ if (this.mNavigationMode.compareTo(NAVIGATION_MODE.BROWSABLE) == 0) {
+ try {
+ Preferences.savePreference(
+ FileManagerSettings.SETTINGS_LAYOUT_MODE, newMode, true);
+ } catch (Exception ex) {
+ Log.e(TAG, "Save of view mode preference fails", ex); //$NON-NLS-1$
}
}
}
@@ -787,210 +968,9 @@ public class NavigationView extends RelativeLayout implements
final String newDir, final boolean addToHistory,
final boolean reload, final boolean useCurrent,
final SearchInfoParcelable searchInfo, final FileSystemObject scrollTo) {
-
- // Check navigation security (don't allow to go outside the ChRooted environment if one
- // is created)
- final String fNewDir = checkChRootedNavigation(newDir);
-
- // Wait to finalization
- synchronized (this.mSync) {
- if (mChangingDir) {
- try {
- mSync.wait();
- } catch (InterruptedException iex) {
- // Ignore
- }
- }
- mChangingDir = true;
- }
-
- //Check that it is really necessary change the directory
- if (!reload && this.mCurrentDir != null && this.mCurrentDir.compareTo(fNewDir) == 0) {
- synchronized (this.mSync) {
- mChangingDir = false;
- mSync.notify();
- }
- return;
- }
-
- final boolean hasChanged =
- !(this.mCurrentDir != null && this.mCurrentDir.compareTo(fNewDir) == 0);
- final boolean isNewHistory = (this.mCurrentDir != null);
-
- //Execute the listing in a background process
- AsyncTask<String, Integer, List<FileSystemObject>> task =
- new AsyncTask<String, Integer, List<FileSystemObject>>() {
- /**
- * {@inheritDoc}
- */
- @Override
- protected List<FileSystemObject> doInBackground(String... params) {
- try {
- //Reset the custom title view and returns to breadcrumb
- if (NavigationView.this.mTitle != null) {
- NavigationView.this.mTitle.post(new Runnable() {
- @Override
- public void run() {
- try {
- NavigationView.this.mTitle.restoreView();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
-
-
- //Start of loading data
- if (NavigationView.this.mBreadcrumb != null) {
- try {
- NavigationView.this.mBreadcrumb.startLoading();
- } catch (Throwable ex) {
- /**NON BLOCK**/
- }
- }
-
- //Get the files, resolve links and apply configuration
- //(sort, hidden, ...)
- List<FileSystemObject> files = NavigationView.this.mFiles;
- if (!useCurrent) {
- files = CommandHelper.listFiles(getContext(), fNewDir, null);
- }
- return files;
-
- } catch (final ConsoleAllocException e) {
- //Show exception and exists
- NavigationView.this.post(new Runnable() {
- @Override
- public void run() {
- Context ctx = getContext();
- Log.e(TAG, ctx.getString(
- R.string.msgs_cant_create_console), e);
- DialogHelper.showToast(ctx,
- R.string.msgs_cant_create_console,
- Toast.LENGTH_LONG);
- ((Activity)ctx).finish();
- }
- });
- return null;
-
- } catch (Exception ex) {
- //End of loading data
- if (NavigationView.this.mBreadcrumb != null) {
- try {
- NavigationView.this.mBreadcrumb.endLoading();
- } catch (Throwable ex2) {
- /**NON BLOCK**/
- }
- }
-
- //Capture exception (attach task, and use listener to do the anim)
- ExceptionUtil.attachAsyncTask(
- ex,
- new AsyncTask<Object, Integer, Boolean>() {
- private List<FileSystemObject> mTaskFiles = null;
- @Override
- @SuppressWarnings({
- "unchecked", "unqualified-field-access"
- })
- protected Boolean doInBackground(Object... taskParams) {
- mTaskFiles = (List<FileSystemObject>)taskParams[0];
- return Boolean.TRUE;
- }
-
- @Override
- @SuppressWarnings("unqualified-field-access")
- protected void onPostExecute(Boolean result) {
- if (!result.booleanValue()) {
- return;
- }
- onPostExecuteTask(
- mTaskFiles, addToHistory,
- isNewHistory, hasChanged,
- searchInfo, fNewDir, scrollTo);
- }
- });
- final OnRelaunchCommandResult exListener =
- new OnRelaunchCommandResult() {
- @Override
- public void onSuccess() {
- done();
- }
- @Override
- public void onFailed(Throwable cause) {
- done();
- }
- @Override
- public void onCancelled() {
- done();
- }
- private void done() {
- // Do animation
- fadeEfect(false);
- synchronized (mSync) {
- mChangingDir = false;
- mSync.notify();
- }
- }
- };
- ExceptionUtil.translateException(
- getContext(), ex, false, true, exListener);
- }
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onPreExecute() {
- // Do animation
- fadeEfect(true);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onPostExecute(List<FileSystemObject> files) {
- // This means an exception. This method will be recalled then
- if (files != null) {
- onPostExecuteTask(
- files, addToHistory, isNewHistory,
- hasChanged, searchInfo, fNewDir, scrollTo);
-
- // Do animation
- fadeEfect(false);
-
- synchronized (mSync) {
- mChangingDir = false;
- mSync.notify();
- }
- }
- }
-
- /**
- * Method that performs a fade animation.
- *
- * @param out Fade out (true); Fade in (false)
- */
- void fadeEfect(final boolean out) {
- Activity activity = (Activity)getContext();
- activity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- Animation fadeAnim = out ?
- new AlphaAnimation(1, 0) :
- new AlphaAnimation(0, 1);
- fadeAnim.setDuration(50L);
- fadeAnim.setFillAfter(true);
- fadeAnim.setInterpolator(new AccelerateInterpolator());
- NavigationView.this.startAnimation(fadeAnim);
- }
- });
- }
- };
- task.execute(fNewDir);
+ NavigationTask task = new NavigationTask(useCurrent, addToHistory, reload,
+ searchInfo, scrollTo);
+ task.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, newDir);
}