use of us.koller.cameraroll.data.models.File_POJO in project Camera-Roll-Android-App by kollerlukas.
the class FileExplorerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_file_explorer);
currentDir = new File_POJO("", false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setEnterTransition(new TransitionSet().setOrdering(TransitionSet.ORDERING_TOGETHER).addTransition(new Slide(Gravity.BOTTOM)).addTransition(new Fade()).setInterpolator(new AccelerateDecelerateInterpolator()));
getWindow().setReturnTransition(new TransitionSet().setOrdering(TransitionSet.ORDERING_TOGETHER).addTransition(new Slide(Gravity.BOTTOM)).addTransition(new Fade()).setInterpolator(new AccelerateDecelerateInterpolator()));
}
final Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setBackgroundColor(toolbarColor);
toolbar.setTitleTextColor(textColorPrimary);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && showAnimations()) {
AnimatedVectorDrawable drawable = (AnimatedVectorDrawable) ContextCompat.getDrawable(FileExplorerActivity.this, R.drawable.back_to_cancel_avd);
// mutating avd to reset it
drawable.mutate();
toolbar.setNavigationIcon(drawable);
} else {
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white);
}
Drawable navIcon = toolbar.getNavigationIcon();
if (navIcon != null) {
navIcon = DrawableCompat.wrap(navIcon);
DrawableCompat.setTint(navIcon.mutate(), textColorSecondary);
toolbar.setNavigationIcon(navIcon);
}
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(getString(R.string.file_explorer));
actionBar.setDisplayHomeAsUpEnabled(true);
}
Util.colorToolbarOverflowMenuIcon(toolbar, textColorSecondary);
// need to be called after setTitle(), to ensure, that mTitleTextView exists
final TextView titleTextView = Util.setToolbarTypeface(toolbar);
if (titleTextView != null) {
titleTextView.setEllipsize(TextUtils.TruncateAt.START);
}
final ViewGroup rootView = findViewById(R.id.swipeBackView);
if (rootView instanceof SwipeBackCoordinatorLayout) {
((SwipeBackCoordinatorLayout) rootView).setOnSwipeListener(this);
}
recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerViewAdapter = new FileExplorerAdapter(new OnDirectoryChangeCallback() {
@Override
public void changeDir(String path) {
loadDirectory(path);
}
}, this);
if (savedInstanceState != null && savedInstanceState.containsKey(CURRENT_DIR)) {
recyclerViewAdapter.setFiles(currentDir);
}
recyclerViewAdapter.notifyDataSetChanged();
recyclerView.setAdapter(recyclerViewAdapter);
// setup fab
final FloatingActionButton fab = findViewById(R.id.fab);
fab.setImageResource(R.drawable.ic_create_new_folder_white);
Drawable d = fab.getDrawable();
d = DrawableCompat.wrap(d);
DrawableCompat.setTint(d.mutate(), accentTextColor);
fab.setImageDrawable(d);
fab.setScaleX(0.0f);
fab.setScaleY(0.0f);
// setting window insets manually
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
rootView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
@Override
public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
toolbar.setPadding(toolbar.getPaddingStart(), /*+ insets.getSystemWindowInsetLeft()*/
toolbar.getPaddingTop() + insets.getSystemWindowInsetTop(), toolbar.getPaddingEnd(), /*+ insets.getSystemWindowInsetRight()*/
toolbar.getPaddingBottom());
ViewGroup.MarginLayoutParams toolbarParams = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
toolbarParams.leftMargin += insets.getSystemWindowInsetLeft();
toolbarParams.rightMargin += insets.getSystemWindowInsetRight();
toolbar.setLayoutParams(toolbarParams);
recyclerView.setPadding(recyclerView.getPaddingStart() + insets.getSystemWindowInsetLeft(), recyclerView.getPaddingTop() + insets.getSystemWindowInsetTop(), recyclerView.getPaddingEnd() + insets.getSystemWindowInsetRight(), recyclerView.getPaddingBottom() + insets.getSystemWindowInsetBottom());
fab.setTranslationY(-insets.getSystemWindowInsetBottom());
fab.setTranslationX(-insets.getSystemWindowInsetRight());
// clear this listener so insets aren't re-applied
rootView.setOnApplyWindowInsetsListener(null);
return insets.consumeSystemWindowInsets();
}
});
} else {
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// hacky way of getting window insets on pre-Lollipop
// somewhat works...
int[] screenSize = Util.getScreenSize(FileExplorerActivity.this);
int[] windowInsets = new int[] { Math.abs(screenSize[0] - rootView.getLeft()), Math.abs(screenSize[1] - rootView.getTop()), Math.abs(screenSize[2] - rootView.getRight()), Math.abs(screenSize[3] - rootView.getBottom()) };
toolbar.setPadding(toolbar.getPaddingStart(), toolbar.getPaddingTop() + windowInsets[1], toolbar.getPaddingEnd(), toolbar.getPaddingBottom());
ViewGroup.MarginLayoutParams toolbarParams = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
toolbarParams.leftMargin += windowInsets[0];
toolbarParams.rightMargin += windowInsets[2];
toolbar.setLayoutParams(toolbarParams);
recyclerView.setPadding(recyclerView.getPaddingStart() + windowInsets[0], recyclerView.getPaddingTop() + windowInsets[1], recyclerView.getPaddingEnd() + windowInsets[2], recyclerView.getPaddingBottom() + windowInsets[3]);
fab.setTranslationY(-windowInsets[2]);
fab.setTranslationX(-windowInsets[3]);
rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
// needed to achieve transparent navBar
setSystemUiFlags();
// load files
if (savedInstanceState != null && savedInstanceState.containsKey(CURRENT_DIR) && savedInstanceState.containsKey(ROOTS)) {
roots = savedInstanceState.getParcelable(ROOTS);
currentDir = savedInstanceState.getParcelable(CURRENT_DIR);
recyclerViewAdapter.setFiles(currentDir);
recyclerViewAdapter.notifyDataSetChanged();
onDataChanged();
if (savedInstanceState.containsKey(MODE)) {
int mode = savedInstanceState.getInt(MODE);
if (mode == FileExplorerAdapter.SELECTOR_MODE) {
if (savedInstanceState.containsKey(SELECTED_ITEMS)) {
final File_POJO[] selectedItems = (File_POJO[]) savedInstanceState.getParcelableArray(SELECTED_ITEMS);
if (selectedItems != null) {
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
recyclerViewAdapter.enterSelectorMode(selectedItems);
}
});
}
}
} else if (mode == FileExplorerAdapter.PICK_TARGET_MODE && savedInstanceState.containsKey(FILE_OPERATION)) {
onSelectorModeEnter();
// fileOp = savedInstanceState.getParcelable(FILE_OPERATION);
/*FileOperation.operation = fileOp != null ?
fileOp.getType() : FileOperation.EMPTY;*/
// need to call pick target after onSelectorModeEnter animation are done
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
recyclerViewAdapter.pickTarget();
}
}, (int) (500 * Util.getAnimatorSpeed(this)));
}
}
} else {
loadRoots();
// show warning dialog
/*new AlertDialog.Builder(this, getDialogThemeRes())
.setTitle(R.string.warning)
.setMessage(Html.fromHtml(getString(R.string.file_explorer_warning_message)))
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
finish();
}
})
.show();*/
}
}
use of us.koller.cameraroll.data.models.File_POJO in project Camera-Roll-Android-App by kollerlukas.
the class FileExplorerActivity method fabClicked.
public void fabClicked(View v) {
if (showAnimations()) {
animateFab(false);
}
View dialogLayout = LayoutInflater.from(this).inflate(R.layout.input_dialog_layout, (ViewGroup) findViewById(R.id.root_view), false);
final EditText editText = dialogLayout.findViewById(R.id.edit_text);
AlertDialog dialog = new AlertDialog.Builder(this, theme.getDialogThemeRes()).setTitle(R.string.new_folder).setView(dialogLayout).setPositiveButton(R.string.create, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String filename = editText.getText().toString();
File_POJO newFolder = new File_POJO(currentDir.getPath() + "/" + filename, false);
File_POJO[] files = new File_POJO[] { newFolder };
Intent intent = FileOperation.getDefaultIntent(FileExplorerActivity.this, FileOperation.NEW_DIR, files);
startService(intent);
}
}).setNegativeButton(getString(R.string.cancel), null).setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
animateFab(true);
}
}).create();
// noinspection ConstantConditions
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
dialog.show();
}
use of us.koller.cameraroll.data.models.File_POJO in project Camera-Roll-Android-App by kollerlukas.
the class FileOperationDialogActivity method createNewFolderDialog.
public void createNewFolderDialog(final NewFolderCallback callback) {
View dialogLayout = LayoutInflater.from(this).inflate(R.layout.input_dialog_layout, (ViewGroup) findViewById(R.id.root_view), false);
final EditText editText = dialogLayout.findViewById(R.id.edit_text);
dialog = new AlertDialog.Builder(this, theme.getDialogThemeRes()).setTitle(R.string.new_folder).setView(dialogLayout).setPositiveButton(R.string.create, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String filename = editText.getText().toString();
String picturesDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath();
final File_POJO newFolder = new File_POJO(picturesDir + "/" + filename, false);
registerLocalBroadcastReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
unregisterLocalBroadcastReceiver(this);
switch(intent.getAction()) {
case FileOperation.RESULT_DONE:
creatingNewFolder = false;
callback.newFolderCreated(newFolder.getPath());
break;
case FileOperation.FAILED:
creatingNewFolder = false;
callback.failed();
break;
default:
break;
}
}
});
Intent intent = FileOperation.getDefaultIntent(FileOperationDialogActivity.this, FileOperation.NEW_DIR, new File_POJO[] { newFolder });
startService(intent);
}
}).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// showFolderSelectorDialog();
}
}).setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
creatingNewFolder = false;
onDialogDismiss();
}
}).create();
// noinspection ConstantConditions
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
dialog.show();
}
use of us.koller.cameraroll.data.models.File_POJO in project Camera-Roll-Android-App by kollerlukas.
the class FileOperationDialogActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_file_operation_dialog);
Intent intent = getIntent();
if (intent == null) {
this.finish();
return;
}
action = intent.getAction();
String[] filePaths = intent.getStringArrayExtra(FILES);
final File_POJO[] files = new File_POJO[filePaths.length];
for (int i = 0; i < filePaths.length; i++) {
files[i] = new File_POJO(filePaths[i], MediaType.isMedia(filePaths[i]));
}
if (savedInstanceState != null && savedInstanceState.containsKey(CREATE_NEW_FOLDER) && Objects.equals(savedInstanceState.getString(CREATE_NEW_FOLDER), "true")) {
creatingNewFolder = true;
createNewFolder(files);
return;
}
showFolderSelectorDialog(files);
}
use of us.koller.cameraroll.data.models.File_POJO in project Camera-Roll-Android-App by kollerlukas.
the class AlbumActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
final String[] selected_items_paths;
Intent intent;
switch(item.getItemId()) {
case R.id.select_all:
SelectorModeManager manager = recyclerViewAdapter.getSelectorManager();
String[] paths = new String[album.getAlbumItems().size()];
for (int i = 0; i < album.getAlbumItems().size(); i++) {
paths[i] = album.getAlbumItems().get(i).getPath();
}
manager.selectAll(paths);
recyclerViewAdapter.notifyItemRangeChanged(0, paths.length);
break;
case R.id.share:
// share multiple items
selected_items_paths = recyclerViewAdapter.cancelSelectorMode(this);
ArrayList<Uri> uris = new ArrayList<>();
for (int i = 0; i < selected_items_paths.length; i++) {
uris.add(StorageUtil.getContentUri(this, selected_items_paths[i]));
}
intent = new Intent().setAction(Intent.ACTION_SEND_MULTIPLE).setType(MediaType.getMimeType(this, uris.get(0))).putExtra(Intent.EXTRA_STREAM, uris);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(Intent.createChooser(intent, getString(R.string.share)));
}
break;
case R.id.copy:
case R.id.move:
selected_items_paths = recyclerViewAdapter.cancelSelectorMode(this);
intent = new Intent(this, FileOperationDialogActivity.class);
intent.setAction(item.getItemId() == R.id.copy ? FileOperationDialogActivity.ACTION_COPY : FileOperationDialogActivity.ACTION_MOVE);
intent.putExtra(FileOperationDialogActivity.FILES, selected_items_paths);
startActivityForResult(intent, FILE_OP_DIALOG_REQUEST);
break;
case R.id.exclude:
Provider.loadExcludedPaths(this);
if (!album.excluded) {
Provider.addExcludedPath(this, album.getPath());
album.excluded = true;
} else {
Provider.removeExcludedPath(this, album.getPath());
album.excluded = false;
}
item.setChecked(album.excluded);
break;
case R.id.pin:
Provider.loadPinnedPaths(this);
if (!album.pinned) {
Provider.pinPath(this, album.getPath());
album.pinned = true;
} else {
Provider.unpinPath(this, album.getPath());
album.pinned = false;
}
item.setChecked(album.pinned);
break;
case R.id.rename:
File_POJO file = new File_POJO(album.getPath(), false).setName(album.getName());
Rename.Util.getRenameDialog(this, file, new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final Activity activity = AlbumActivity.this;
final String newFilePath = intent.getStringExtra(Rename.NEW_FILE_PATH);
getIntent().putExtra(ALBUM_PATH, newFilePath);
boolean hiddenFolders = Settings.getInstance(activity).getHiddenFolders();
new MediaProvider(activity).loadAlbums(activity, hiddenFolders, new MediaProvider.OnMediaLoadedCallback() {
@Override
public void onMediaLoaded(ArrayList<Album> albums) {
// reload activity
MediaProvider.loadAlbum(activity, newFilePath, new MediaProvider.OnAlbumLoadedCallback() {
@Override
public void onAlbumLoaded(Album album) {
AlbumActivity.this.album = album;
AlbumActivity.this.onAlbumLoaded(null);
}
});
}
@Override
public void timeout() {
finish();
}
@Override
public void needPermission() {
finish();
}
});
}
}).show();
break;
case R.id.sort_by_date:
case R.id.sort_by_name:
item.setChecked(true);
int sort_by = item.getItemId() == R.id.sort_by_date ? SortUtil.BY_DATE : SortUtil.BY_NAME;
Settings.getInstance(this).sortAlbumBy(this, sort_by);
SortUtil.sort(album.getAlbumItems(), sort_by);
recyclerViewAdapter.notifyDataSetChanged();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
Aggregations