Search in sources :

Example 1 with FileExplorerAdapter

use of us.koller.cameraroll.adapter.fileExplorer.FileExplorerAdapter 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();*/
    }
}
Also used : LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) WindowInsets(android.view.WindowInsets) TransitionSet(android.transition.TransitionSet) Slide(android.transition.Slide) SwipeBackCoordinatorLayout(us.koller.cameraroll.ui.widget.SwipeBackCoordinatorLayout) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) FloatingActionButton(android.support.design.widget.FloatingActionButton) TextView(android.widget.TextView) ViewTreeObserver(android.view.ViewTreeObserver) ActionBar(android.support.v7.app.ActionBar) FileExplorerAdapter(us.koller.cameraroll.adapter.fileExplorer.FileExplorerAdapter) Toolbar(android.support.v7.widget.Toolbar) ViewGroup(android.view.ViewGroup) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) Handler(android.os.Handler) File_POJO(us.koller.cameraroll.data.models.File_POJO) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) RequiresApi(android.support.annotation.RequiresApi) ColorFade(us.koller.cameraroll.util.animators.ColorFade) Fade(android.transition.Fade)

Example 2 with FileExplorerAdapter

use of us.koller.cameraroll.adapter.fileExplorer.FileExplorerAdapter in project Camera-Roll-Android-App by kollerlukas.

the class FileExplorerActivity method onSwipeProcess.

@Override
public void onSwipeProcess(float percent) {
    getWindow().getDecorView().setBackgroundColor(SwipeBackCoordinatorLayout.getBackgroundColor(percent));
    boolean selectorModeActive = ((FileExplorerAdapter) recyclerView.getAdapter()).isModeActive();
    if (!theme.darkStatusBarIcons() && selectorModeActive) {
        SwipeBackCoordinatorLayout layout = findViewById(R.id.swipeBackView);
        Toolbar toolbar = findViewById(R.id.toolbar);
        View rootView = findViewById(R.id.root_view);
        int translationY = (int) layout.getTranslationY();
        int statusBarHeight = toolbar.getPaddingTop();
        if (translationY > statusBarHeight * 0.5) {
            Util.setLightStatusBarIcons(rootView);
        } else {
            Util.setDarkStatusBarIcons(rootView);
        }
    }
}
Also used : SwipeBackCoordinatorLayout(us.koller.cameraroll.ui.widget.SwipeBackCoordinatorLayout) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) FileExplorerAdapter(us.koller.cameraroll.adapter.fileExplorer.FileExplorerAdapter) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)2 Toolbar (android.support.v7.widget.Toolbar)2 View (android.view.View)2 TextView (android.widget.TextView)2 FileExplorerAdapter (us.koller.cameraroll.adapter.fileExplorer.FileExplorerAdapter)2 SwipeBackCoordinatorLayout (us.koller.cameraroll.ui.widget.SwipeBackCoordinatorLayout)2 AnimatedVectorDrawable (android.graphics.drawable.AnimatedVectorDrawable)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 Handler (android.os.Handler)1 RequiresApi (android.support.annotation.RequiresApi)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 ActionBar (android.support.v7.app.ActionBar)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 Fade (android.transition.Fade)1 Slide (android.transition.Slide)1 TransitionSet (android.transition.TransitionSet)1 ViewGroup (android.view.ViewGroup)1 ViewTreeObserver (android.view.ViewTreeObserver)1 WindowInsets (android.view.WindowInsets)1