use of dev.dworks.apps.anexplorer.BaseActivity.State in project AnExplorer by 1hakr.
the class DirectoryFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final Context context = getActivity();
final State state = getDisplayState(DirectoryFragment.this);
root = getArguments().getParcelable(EXTRA_ROOT);
doc = getArguments().getParcelable(EXTRA_DOC);
if (null != root && root.isSecondaryStorage() && state.action == ACTION_BROWSE) {
if (!doc.isWriteSupported()) {
SAFManager.takeCardUriPermission(getActivity(), root, doc);
}
}
isApp = root != null && root.isApp();
isOperationSupported = root != null && (root.isRootedStorage() || root.isUsbStorage());
mAdapter = new DocumentsAdapter();
mType = getArguments().getInt(EXTRA_TYPE);
mStateKey = buildStateKey(root, doc);
if (mType == TYPE_RECENT_OPEN) {
// Hide titles when showing recents for picking images/videos
mHideGridTitles = MimePredicate.mimeMatches(MimePredicate.VISUAL_MIMES, state.acceptMimes);
} else {
mHideGridTitles = (doc != null) && doc.isGridTitlesHidden();
}
mSvelteRecents = Utils.isLowRamDevice(context) && (mType == TYPE_RECENT_OPEN);
mCallbacks = new LoaderCallbacks<DirectoryResult>() {
@Override
public Loader<DirectoryResult> onCreateLoader(int id, Bundle args) {
final String query = getArguments().getString(EXTRA_QUERY);
Uri contentsUri;
switch(mType) {
case TYPE_NORMAL:
contentsUri = DocumentsContract.buildChildDocumentsUri(doc.authority, doc.documentId);
if (state.action == ACTION_MANAGE) {
contentsUri = DocumentsContract.setManageMode(contentsUri);
}
return new DirectoryLoader(context, mType, root, doc, contentsUri, state.userSortOrder);
case TYPE_SEARCH:
contentsUri = DocumentsContract.buildSearchDocumentsUri(root.authority, root.rootId, query);
if (state.action == ACTION_MANAGE) {
contentsUri = DocumentsContract.setManageMode(contentsUri);
}
return new DirectoryLoader(context, mType, root, doc, contentsUri, state.userSortOrder);
case TYPE_RECENT_OPEN:
final RootsCache roots = DocumentsApplication.getRootsCache(context);
return new RecentLoader(context, roots, state);
default:
throw new IllegalStateException("Unknown type " + mType);
}
}
@Override
public void onLoadFinished(Loader<DirectoryResult> loader, DirectoryResult result) {
if (!isAdded())
return;
mAdapter.swapResult(result);
// TODO: if mode change was racing with us, don't overwrite it
if (result.mode != MODE_UNKNOWN) {
state.derivedMode = result.mode;
}
if (result.sortOrder != SORT_ORDER_UNKNOWN) {
state.derivedSortOrder = result.sortOrder;
}
((BaseActivity) context).onStateChanged();
updateDisplayState();
// When launched into empty recents, show drawer
if (mType == TYPE_RECENT_OPEN && mAdapter.isEmpty() && !state.stackTouched) {
((BaseActivity) context).setRootsDrawerOpen(true);
}
if (isResumed()) {
setListShown(true);
} else {
setListShownNoAnimation(true);
}
// Restore any previous instance state
final SparseArray<Parcelable> container = state.dirState.remove(mStateKey);
if (container != null && !getArguments().getBoolean(EXTRA_IGNORE_STATE, false)) {
getView().restoreHierarchyState(container);
} else if (mLastSortOrder != state.derivedSortOrder) {
mListView.smoothScrollToPosition(0);
mGridView.smoothScrollToPosition(0);
}
mLastSortOrder = state.derivedSortOrder;
if (isTelevision()) {
mCurrentView.requestFocus();
}
}
@Override
public void onLoaderReset(Loader<DirectoryResult> loader) {
mAdapter.swapResult(null);
}
};
setListAdapter(mAdapter);
setListShown(false);
// Kick off loader at least once
getLoaderManager().restartLoader(mLoaderId, null, mCallbacks);
updateDisplayState();
}
use of dev.dworks.apps.anexplorer.BaseActivity.State in project AnExplorer by 1hakr.
the class DirectoryFragment method showPopupMenu.
private void showPopupMenu(View view, final int position) {
PopupMenu popup = new PopupMenu(getActivity(), view);
int menuId = R.menu.popup_simple_directory;
if (isApp) {
menuId = R.menu.popup_apps;
} else {
menuId = R.menu.popup_directory;
}
popup.getMenuInflater().inflate(menuId, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
return onPopupMenuItemClick(menuItem, position);
}
});
if (isApp) {
final MenuItem open = popup.getMenu().findItem(R.id.menu_open);
final MenuItem delete = popup.getMenu().findItem(R.id.menu_delete);
final MenuItem save = popup.getMenu().findItem(R.id.menu_save);
open.setVisible(root.isAppPackage());
save.setVisible(root.isAppPackage());
delete.setVisible(root.isUserApp());
} else {
final State state = getDisplayState(DirectoryFragment.this);
final MenuItem share = popup.getMenu().findItem(R.id.menu_share);
final MenuItem delete = popup.getMenu().findItem(R.id.menu_delete);
final MenuItem rename = popup.getMenu().findItem(R.id.menu_rename);
final MenuItem copy = popup.getMenu().findItem(R.id.menu_copy);
final MenuItem cut = popup.getMenu().findItem(R.id.menu_cut);
final MenuItem compress = popup.getMenu().findItem(R.id.menu_compress);
final MenuItem uncompress = popup.getMenu().findItem(R.id.menu_uncompress);
final MenuItem bookmark = popup.getMenu().findItem(R.id.menu_bookmark);
final Cursor cursor = mAdapter.getItem(position);
final DocumentInfo doc = DocumentInfo.fromDirectoryCursor(cursor);
final boolean manageMode = state.action == ACTION_BROWSE;
if (null != doc) {
final boolean isCompressed = doc != null && MimePredicate.mimeMatches(MimePredicate.COMPRESSED_MIMES, doc.mimeType);
if (null != compress)
compress.setVisible(manageMode && doc.isArchiveSupported() && !isCompressed && !isOperationSupported);
if (null != uncompress)
uncompress.setVisible(manageMode && doc.isArchiveSupported() && isCompressed && !isOperationSupported);
if (null != bookmark) {
bookmark.setVisible(manageMode && doc.isBookmarkSupported() && Utils.isDir(doc.mimeType) && !isOperationSupported);
}
share.setVisible(manageMode);
delete.setVisible(manageMode && doc.isDeleteSupported());
rename.setVisible(manageMode && doc.isRenameSupported());
copy.setVisible(manageMode && doc.isCopySupported());
cut.setVisible(manageMode && doc.isMoveSupported());
}
}
popup.show();
}
use of dev.dworks.apps.anexplorer.BaseActivity.State in project AnExplorer by 1hakr.
the class RootsFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (null != savedInstanceState) {
group_size = savedInstanceState.getInt(GROUP_SIZE, 0);
expandedIds = (ArrayList<Long>) savedInstanceState.getSerializable(GROUP_IDS);
}
final Context context = getActivity();
final RootsCache roots = DocumentsApplication.getRootsCache(context);
final State state = ((BaseActivity) context).getDisplayState();
mCallbacks = new LoaderCallbacks<Collection<RootInfo>>() {
@Override
public Loader<Collection<RootInfo>> onCreateLoader(int id, Bundle args) {
return new RootsLoader(context, roots, state);
}
@Override
public void onLoadFinished(Loader<Collection<RootInfo>> loader, Collection<RootInfo> result) {
if (!isAdded())
return;
final Intent includeApps = getArguments().getParcelable(EXTRA_INCLUDE_APPS);
if (mAdapter == null) {
mAdapter = new RootsExpandableAdapter(context, result, includeApps);
Parcelable state = mList.onSaveInstanceState();
mList.setAdapter(mAdapter);
mList.onRestoreInstanceState(state);
} else {
mAdapter.setData(result);
}
int groupCount = mAdapter.getGroupCount();
if (group_size != 0 && group_size == groupCount) {
if (expandedIds != null) {
restoreExpandedState(expandedIds);
}
} else {
group_size = groupCount;
for (int i = 0; i < group_size; i++) {
mList.expandGroup(i);
}
expandedIds = getExpandedIds();
mList.setOnGroupExpandListener(mOnGroupExpandListener);
mList.setOnGroupCollapseListener(mOnGroupCollapseListener);
}
}
@Override
public void onLoaderReset(Loader<Collection<RootInfo>> loader) {
mAdapter = null;
mList.setAdapter((RootsExpandableAdapter) null);
}
};
}
use of dev.dworks.apps.anexplorer.BaseActivity.State in project AnExplorer by 1hakr.
the class RecentsCreateFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final Context context = getActivity();
mAdapter = new DocumentStackAdapter();
mListView.setAdapter(mAdapter);
final RootsCache roots = DocumentsApplication.getRootsCache(context);
final State state = ((BaseActivity) getActivity()).getDisplayState();
mCallbacks = new LoaderCallbacks<List<DocumentStack>>() {
@Override
public Loader<List<DocumentStack>> onCreateLoader(int id, Bundle args) {
return new RecentsCreateLoader(context, roots, state);
}
@Override
public void onLoadFinished(Loader<List<DocumentStack>> loader, List<DocumentStack> data) {
mAdapter.swapStacks(data);
if (isResumed()) {
setListShown(true);
} else {
setListShownNoAnimation(true);
}
// When launched into empty recents, show drawer
if (mAdapter.isEmpty() && !state.stackTouched) {
((BaseActivity) context).setRootsDrawerOpen(true);
}
}
@Override
public void onLoaderReset(Loader<List<DocumentStack>> loader) {
mAdapter.swapStacks(null);
}
};
setListAdapter(mAdapter);
setListShown(false);
getLoaderManager().restartLoader(LOADER_RECENTS, getArguments(), mCallbacks);
}
use of dev.dworks.apps.anexplorer.BaseActivity.State in project AnExplorer by 1hakr.
the class DirectoryFragment method updateDisplayState.
private void updateDisplayState() {
final State state = getDisplayState(this);
mDefaultColor = SettingsActivity.getPrimaryColor(getActivity());
int accentColor = SettingsActivity.getAccentColor();
if (mLastMode == state.derivedMode && mLastSortOrder == state.derivedSortOrder && mLastShowSize == state.showSize && mLastShowFolderSize == state.showFolderSize && mLastShowThumbnail == state.showThumbnail && mLastShowHiddenFiles == state.showHiddenFiles && (mLastShowColor != 0 && mLastShowColor == mDefaultColor) && (mLastShowAccentColor != 0 && mLastShowAccentColor == accentColor))
return;
boolean refreshData = mLastShowHiddenFiles != state.showHiddenFiles;
mLastMode = state.derivedMode;
mLastSortOrder = state.derivedSortOrder;
mLastShowSize = state.showSize;
mLastShowFolderSize = state.showFolderSize;
mLastShowThumbnail = state.showThumbnail;
mLastShowHiddenFiles = state.showHiddenFiles;
mLastShowColor = mDefaultColor;
mProgressBar.setColor(mLastShowColor);
mListView.setVisibility(state.derivedMode == MODE_LIST ? View.VISIBLE : View.GONE);
mGridView.setVisibility(state.derivedMode == MODE_GRID ? View.VISIBLE : View.GONE);
final int choiceMode;
if (state.allowMultiple) {
choiceMode = ListView.CHOICE_MODE_MULTIPLE_MODAL;
} else {
choiceMode = ListView.CHOICE_MODE_NONE;
}
final int thumbSize;
if (state.derivedMode == MODE_GRID) {
thumbSize = getResources().getDimensionPixelSize(R.dimen.grid_width);
mListView.setAdapter(null);
mListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
mGridView.setAdapter(mAdapter);
mGridView.setColumnWidth(thumbSize);
mGridView.setNumColumns(GridView.AUTO_FIT);
mGridView.setChoiceMode(choiceMode);
mCurrentView = mGridView;
} else if (state.derivedMode == MODE_LIST) {
thumbSize = getResources().getDimensionPixelSize(R.dimen.icon_size);
mGridView.setAdapter(null);
mGridView.setChoiceMode(ListView.CHOICE_MODE_NONE);
mListView.setAdapter(mAdapter);
mListView.setChoiceMode(choiceMode);
mCurrentView = mListView;
} else {
throw new IllegalStateException("Unknown state " + state.derivedMode);
}
((BaseActivity) getActivity()).upadateActionItems(mCurrentView);
mThumbSize = new Point(thumbSize, thumbSize);
if (refreshData) {
onUserSortOrderChanged();
}
}
Aggregations