Search in sources :

Example 1 with SwipeBackCoordinatorLayout

use of us.koller.cameraroll.ui.widget.SwipeBackCoordinatorLayout 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 SwipeBackCoordinatorLayout

use of us.koller.cameraroll.ui.widget.SwipeBackCoordinatorLayout 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)

Example 3 with SwipeBackCoordinatorLayout

use of us.koller.cameraroll.ui.widget.SwipeBackCoordinatorLayout in project Camera-Roll-Android-App by kollerlukas.

the class AboutActivity method onSwipeProcess.

@Override
public void onSwipeProcess(float percent) {
    getWindow().getDecorView().setBackgroundColor(SwipeBackCoordinatorLayout.getBackgroundColor(percent));
    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) {
        if (theme.darkStatusBarIcons()) {
            Util.setDarkStatusBarIcons(rootView);
        } else {
            Util.setLightStatusBarIcons(rootView);
        }
    }
}
Also used : SwipeBackCoordinatorLayout(us.koller.cameraroll.ui.widget.SwipeBackCoordinatorLayout) ImageView(android.widget.ImageView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) Toolbar(android.support.v7.widget.Toolbar)

Example 4 with SwipeBackCoordinatorLayout

use of us.koller.cameraroll.ui.widget.SwipeBackCoordinatorLayout in project Camera-Roll-Android-App by kollerlukas.

the class AboutActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_about);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setEnterTransition(new Slide(Gravity.BOTTOM));
        getWindow().setReturnTransition(new Slide(Gravity.BOTTOM));
    }
    SwipeBackCoordinatorLayout swipeBackView = findViewById(R.id.swipeBackView);
    swipeBackView.setOnSwipeListener(this);
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle("");
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    final View header = findViewById(R.id.header);
    header.setBackgroundColor(theme.getAccentColor(this));
    TextView version = findViewById(R.id.version);
    try {
        String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
        final int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
        // noinspection deprecation
        version.setText(Html.fromHtml(versionName));
        version.setTextColor(theme.getAccentTextColor(this));
        version.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) {
                Toast.makeText(view.getContext(), "versionCode: " + String.valueOf(versionCode), Toast.LENGTH_SHORT).show();
                return false;
            }
        });
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    final TextView aboutText = findViewById(R.id.about_text);
    // noinspection deprecation
    aboutText.setText(Html.fromHtml(getString(R.string.about_text)));
    aboutText.setMovementMethod(new LinkMovementMethod());
    final View rootView = findViewById(R.id.root_view);
    final NestedScrollView scrollView = findViewById(R.id.scroll_view);
    scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {

        @Override
        public void onScrollChange(NestedScrollView nestedScrollView, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            int statusBarHeight = toolbar.getPaddingTop();
            if (scrollY > header.getHeight() - statusBarHeight / 2) {
                if (theme.darkStatusBarIcons()) {
                    Util.setDarkStatusBarIcons(rootView);
                } else {
                    Util.setLightStatusBarIcons(rootView);
                }
            } else {
                if (theme.darkStatusBarIconsInSelectorMode()) {
                    Util.setDarkStatusBarIcons(rootView);
                } else {
                    Util.setLightStatusBarIcons(rootView);
                }
            }
        }
    });
    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());
                aboutText.setPadding(aboutText.getPaddingStart(), aboutText.getPaddingTop(), aboutText.getPaddingEnd(), aboutText.getPaddingBottom() + insets.getSystemWindowInsetBottom());
                View viewGroup = findViewById(R.id.swipeBackView);
                ViewGroup.MarginLayoutParams viewGroupParams = (ViewGroup.MarginLayoutParams) viewGroup.getLayoutParams();
                viewGroupParams.leftMargin += insets.getSystemWindowInsetLeft();
                viewGroupParams.rightMargin += insets.getSystemWindowInsetRight();
                viewGroup.setLayoutParams(viewGroupParams);
                // clear this listener so insets aren't re-applied
                rootView.setOnApplyWindowInsetsListener(null);
                return insets.consumeSystemWindowInsets();
            }
        });
        // set status bar icon color
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
    } 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(AboutActivity.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());
                View viewGroup = findViewById(R.id.swipeBackView);
                ViewGroup.MarginLayoutParams viewGroupParams = (ViewGroup.MarginLayoutParams) viewGroup.getLayoutParams();
                viewGroupParams.leftMargin += windowInsets[0];
                viewGroupParams.rightMargin += windowInsets[2];
                viewGroup.setLayoutParams(viewGroupParams);
                rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });
    }
    for (int i = 0; i < toolbar.getChildCount(); i++) {
        if (toolbar.getChildAt(i) instanceof ImageView) {
            ImageView imageView = ((ImageView) toolbar.getChildAt(i));
            int color;
            if (!theme.darkStatusBarIconsInSelectorMode()) {
                color = ContextCompat.getColor(this, R.color.white_translucent1);
            } else {
                color = ContextCompat.getColor(this, R.color.black_translucent2);
            }
            imageView.setColorFilter(color, PorterDuff.Mode.SRC_IN);
            break;
        }
    }
    // needed for transparent statusBar
    setSystemUiFlags();
}
Also used : ViewGroup(android.view.ViewGroup) LinkMovementMethod(android.text.method.LinkMovementMethod) ImageView(android.widget.ImageView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) WindowInsets(android.view.WindowInsets) PackageManager(android.content.pm.PackageManager) Slide(android.transition.Slide) SwipeBackCoordinatorLayout(us.koller.cameraroll.ui.widget.SwipeBackCoordinatorLayout) RequiresApi(android.support.annotation.RequiresApi) TextView(android.widget.TextView) ImageView(android.widget.ImageView) NestedScrollView(android.support.v4.widget.NestedScrollView) ViewTreeObserver(android.view.ViewTreeObserver) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 5 with SwipeBackCoordinatorLayout

use of us.koller.cameraroll.ui.widget.SwipeBackCoordinatorLayout in project Camera-Roll-Android-App by kollerlukas.

the class AlbumActivity method onCreate.

@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_album);
    pick_photos = getIntent().getAction() != null && getIntent().getAction().equals(MainActivity.PICK_PHOTOS);
    allowMultiple = getIntent().getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false);
    MediaProvider.checkPermission(this);
    setExitSharedElementCallback(mCallback);
    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 ViewGroup swipeBackView = findViewById(R.id.swipeBackView);
    if (swipeBackView instanceof SwipeBackCoordinatorLayout) {
        ((SwipeBackCoordinatorLayout) swipeBackView).setOnSwipeListener(this);
    }
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    final ActionBar actionBar = getSupportActionBar();
    if (!pick_photos) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            AnimatedVectorDrawable drawable = (AnimatedVectorDrawable) ContextCompat.getDrawable(AlbumActivity.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);
        }
    } else {
        if (actionBar != null) {
            actionBar.setTitle(allowMultiple ? getString(R.string.pick_photos) : getString(R.string.pick_photo));
        }
        toolbar.setNavigationIcon(R.drawable.ic_clear_white);
        Drawable navIcon = toolbar.getNavigationIcon();
        if (navIcon != null) {
            navIcon = DrawableCompat.wrap(navIcon);
            DrawableCompat.setTint(navIcon.mutate(), accentTextColor);
            toolbar.setNavigationIcon(navIcon);
        }
        Util.setDarkStatusBarIcons(findViewById(R.id.root_view));
        Util.colorToolbarOverflowMenuIcon(toolbar, accentTextColor);
    }
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (recyclerViewAdapter != null && recyclerViewAdapter.isSelectorModeActive()) {
                recyclerViewAdapter.cancelSelectorMode(null);
            } else {
                onBackPressed();
            }
        }
    });
    recyclerView = findViewById(R.id.recyclerView);
    final int columnCount = Settings.getInstance(this).getColumnCount(this);
    GridLayoutManager gridLayoutManager = new GridLayoutManager(this, columnCount);
    recyclerView.setLayoutManager(gridLayoutManager);
    recyclerViewAdapter = new AlbumAdapter(this, recyclerView, album, pick_photos);
    recyclerView.setAdapter(recyclerViewAdapter);
    float albumGridSpacing = getResources().getDimension(R.dimen.album_grid_spacing);
    ((FastScrollerRecyclerView) recyclerView).addOuterGridSpacing((int) (albumGridSpacing / 2));
    recyclerView.addItemDecoration(new GridMarginDecoration((int) albumGridSpacing));
    if (savedInstanceState != null && savedInstanceState.containsKey(RECYCLER_VIEW_SCROLL_STATE)) {
        recyclerView.getLayoutManager().onRestoreInstanceState(savedInstanceState.getParcelable(RECYCLER_VIEW_SCROLL_STATE));
    }
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        // private float scrollY = 0.0f;
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (recyclerViewAdapter.isSelectorModeActive() || pick_photos) {
                return;
            }
            float translationY = toolbar.getTranslationY() - dy;
            if (-translationY > toolbar.getHeight()) {
                translationY = -toolbar.getHeight();
                if (theme.elevatedToolbar()) {
                    toolbar.setActivated(true);
                }
            } else if (translationY > 0) {
                translationY = 0;
                if (theme.elevatedToolbar() && !recyclerView.canScrollVertically(-1)) {
                    toolbar.setActivated(false);
                }
            }
            toolbar.setTranslationY(translationY);
            // animate statusBarIcon color
            if (theme.darkStatusBarIcons()) {
                float animatedValue = (-translationY) / toolbar.getHeight();
                if (animatedValue > 0.9f) {
                    Util.setLightStatusBarIcons(findViewById(R.id.root_view));
                } else {
                    Util.setDarkStatusBarIcons(findViewById(R.id.root_view));
                }
            }
        }
    });
    final FloatingActionButton fab = findViewById(R.id.fab);
    if (!pick_photos) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Drawable d = ContextCompat.getDrawable(this, R.drawable.ic_delete_avd);
            fab.setImageDrawable(d);
        } else {
            fab.setImageResource(R.drawable.ic_delete_white);
        }
    } else {
        fab.setImageResource(R.drawable.ic_send_white);
    }
    Drawable d = fab.getDrawable();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        d.setTint(accentTextColor);
    } else {
        d = DrawableCompat.wrap(d);
        DrawableCompat.setTint(d.mutate(), accentTextColor);
    }
    fab.setImageDrawable(d);
    fab.setScaleX(0.0f);
    fab.setScaleY(0.0f);
    final ViewGroup rootView = findViewById(R.id.root_view);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        rootView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {

            @Override
            @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
            public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
                toolbar.setPadding(toolbar.getPaddingStart(), toolbar.getPaddingTop() + insets.getSystemWindowInsetTop(), toolbar.getPaddingEnd(), 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());
                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(AlbumActivity.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]);
                recyclerView.scrollToPosition(0);
                fab.setTranslationX(-windowInsets[2]);
                fab.setTranslationY(-windowInsets[3]);
                rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });
    }
    // onNewIntent(getIntent());
    // needed for transparent statusBar
    setSystemUiFlags();
    // load album
    String path;
    if (savedInstanceState != null && savedInstanceState.containsKey(ALBUM_PATH)) {
        path = savedInstanceState.getString(ALBUM_PATH);
    } else {
        path = getIntent().getStringExtra(ALBUM_PATH);
    }
    MediaProvider.loadAlbum(this, path, new MediaProvider.OnAlbumLoadedCallback() {

        @Override
        public void onAlbumLoaded(Album album) {
            AlbumActivity.this.album = album;
            AlbumActivity.this.onAlbumLoaded(savedInstanceState);
        }
    });
}
Also used : VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum) Album(us.koller.cameraroll.data.models.Album) WindowInsets(android.view.WindowInsets) TransitionSet(android.transition.TransitionSet) Slide(android.transition.Slide) SwipeBackCoordinatorLayout(us.koller.cameraroll.ui.widget.SwipeBackCoordinatorLayout) GridMarginDecoration(us.koller.cameraroll.ui.widget.GridMarginDecoration) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) FloatingActionButton(android.support.design.widget.FloatingActionButton) FastScrollerRecyclerView(us.koller.cameraroll.ui.widget.FastScrollerRecyclerView) ViewTreeObserver(android.view.ViewTreeObserver) ActionBar(android.support.v7.app.ActionBar) 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) View(android.view.View) FastScrollerRecyclerView(us.koller.cameraroll.ui.widget.FastScrollerRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) GridLayoutManager(android.support.v7.widget.GridLayoutManager) MediaProvider(us.koller.cameraroll.data.provider.MediaProvider) RequiresApi(android.support.annotation.RequiresApi) FastScrollerRecyclerView(us.koller.cameraroll.ui.widget.FastScrollerRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ColorFade(us.koller.cameraroll.util.animators.ColorFade) Fade(android.transition.Fade) AlbumAdapter(us.koller.cameraroll.adapter.album.AlbumAdapter)

Aggregations

Toolbar (android.support.v7.widget.Toolbar)6 View (android.view.View)6 SwipeBackCoordinatorLayout (us.koller.cameraroll.ui.widget.SwipeBackCoordinatorLayout)6 RecyclerView (android.support.v7.widget.RecyclerView)4 TextView (android.widget.TextView)4 RequiresApi (android.support.annotation.RequiresApi)3 ActionBar (android.support.v7.app.ActionBar)3 Slide (android.transition.Slide)3 ViewGroup (android.view.ViewGroup)3 ViewTreeObserver (android.view.ViewTreeObserver)3 WindowInsets (android.view.WindowInsets)3 AnimatedVectorDrawable (android.graphics.drawable.AnimatedVectorDrawable)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Drawable (android.graphics.drawable.Drawable)2 FloatingActionButton (android.support.design.widget.FloatingActionButton)2 NestedScrollView (android.support.v4.widget.NestedScrollView)2 Fade (android.transition.Fade)2 TransitionSet (android.transition.TransitionSet)2 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)2 ImageView (android.widget.ImageView)2