Search in sources :

Example 1 with Settings

use of us.koller.cameraroll.data.Settings in project Camera-Roll-Android-App by kollerlukas.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    pick_photos = getIntent().getAction() != null && getIntent().getAction().equals(PICK_PHOTOS);
    boolean allowMultiple = getIntent().getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false);
    final Settings settings = Settings.getInstance(this);
    hiddenFolders = settings.getHiddenFolders();
    // load media
    albums = MediaProvider.getAlbums();
    if (albums == null) {
        albums = new ArrayList<>();
    }
    if (savedInstanceState == null) {
        refreshPhotos();
    }
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setBackgroundColor(!pick_photos ? toolbarColor : accentColor);
    toolbar.setTitleTextColor(!pick_photos ? textColorPrimary : accentTextColor);
    ActionBar actionBar = getSupportActionBar();
    if (pick_photos) {
        if (actionBar != null) {
            actionBar.setTitle(allowMultiple ? getString(R.string.pick_photos) : getString(R.string.pick_photo));
        }
        toolbar.setActivated(true);
        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);
        }
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                finish();
            }
        });
        Util.colorToolbarOverflowMenuIcon(toolbar, accentTextColor);
        if (theme.darkStatusBarIconsInSelectorMode()) {
            Util.setDarkStatusBarIcons(findViewById(R.id.root_view));
        }
    } else {
        if (actionBar != null) {
            actionBar.setTitle(getString(R.string.toolbar_title));
        }
    }
    recyclerView = findViewById(R.id.recyclerView);
    recyclerView.setTag(ParallaxImageView.RECYCLER_VIEW_TAG);
    SelectorModeManager.Callback callback = new SelectorModeManager.SimpleCallback() {

        @Override
        public void onSelectorModeEnter() {
            super.onSelectorModeEnter();
            showAndHideFab(false);
        }

        @Override
        public void onSelectorModeExit() {
            super.onSelectorModeExit();
            showAndHideFab(true);
        }
    };
    int spanCount, spacing;
    if (settings.noFolderMode()) {
        spanCount = settings.getColumnCount(this);
        spacing = (int) getResources().getDimension(R.dimen.album_grid_spacing) / 2;
        recyclerView.addItemDecoration(new GridMarginDecoration(spacing + spacing));
        recyclerViewAdapter = new NoFolderRecyclerViewAdapter(callback, recyclerView, pick_photos).setData(albums);
    } else {
        spanCount = settings.getStyleColumnCount(this, settings.getStyle(this, pick_photos));
        spacing = settings.getStyleGridSpacing(this, settings.getStyle(this, pick_photos));
        recyclerViewAdapter = new MainAdapter(this, pick_photos).setData(albums);
        recyclerViewAdapter.getSelectorManager().addCallback(callback);
    }
    recyclerView.setAdapter(recyclerViewAdapter);
    recyclerView.setLayoutManager(new GridLayoutManager(this, spanCount));
    if (recyclerView instanceof FastScrollerRecyclerView) {
        ((FastScrollerRecyclerView) recyclerView).addOuterGridSpacing(spacing);
    }
    // disable default change animation
    ((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
    // restore Selector mode, when needed
    if (savedInstanceState != null) {
        SelectorModeManager manager = new SelectorModeManager(savedInstanceState);
        recyclerViewAdapter.setSelectorModeManager(manager);
    }
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (pick_photos) {
                return;
            }
            // hiding toolbar on scroll
            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
            boolean selectorModeActive = recyclerViewAdapter.getSelectorManager().isSelectorModeActive();
            if (!selectorModeActive && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && theme.isBaseLight()) {
                // only animate statusBar icons color, when not in selectorMode
                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);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            fabClicked(view);
        }
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Drawable d = ContextCompat.getDrawable(this, R.drawable.ic_camera_lens_avd);
        fab.setImageDrawable(d);
    } else {
        fab.setImageResource(R.drawable.ic_camera_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);
    if (pick_photos || !settings.getCameraShortcut()) {
        fab.setVisibility(View.GONE);
    }
    // setting window insets manually
    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) {
                // clear this listener so insets aren't re-applied
                rootView.setOnApplyWindowInsetsListener(null);
                Log.d("MainActivity", "onApplyWindowInsets()" + "[" + insets.getSystemWindowInsetLeft() + ", " + insets.getSystemWindowInsetTop() + ", " + insets.getSystemWindowInsetRight() + ", " + insets.getSystemWindowInsetBottom() + "]");
                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());
                return insets.consumeSystemWindowInsets();
            }
        });
    } else {
        rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                // hacky way of getting window insets on pre-Lollipop
                // somewhat works...
                int[] screenSize = Util.getScreenSize(MainActivity.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.setTranslationX(-windowInsets[2]);
                fab.setTranslationY(-windowInsets[3]);
            }
        });
    }
    // needed for transparent statusBar
    setSystemUiFlags();
}
Also used : WindowInsets(android.view.WindowInsets) GridMarginDecoration(us.koller.cameraroll.ui.widget.GridMarginDecoration) NoFolderRecyclerViewAdapter(us.koller.cameraroll.adapter.main.NoFolderRecyclerViewAdapter) FloatingActionButton(android.support.design.widget.FloatingActionButton) FastScrollerRecyclerView(us.koller.cameraroll.ui.widget.FastScrollerRecyclerView) ViewTreeObserver(android.view.ViewTreeObserver) Settings(us.koller.cameraroll.data.Settings) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar) MainAdapter(us.koller.cameraroll.adapter.main.MainAdapter) SimpleItemAnimator(android.support.v7.widget.SimpleItemAnimator) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) View(android.view.View) FastScrollerRecyclerView(us.koller.cameraroll.ui.widget.FastScrollerRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ParallaxImageView(us.koller.cameraroll.ui.widget.ParallaxImageView) GridLayoutManager(android.support.v7.widget.GridLayoutManager) SelectorModeManager(us.koller.cameraroll.adapter.SelectorModeManager) RequiresApi(android.support.annotation.RequiresApi) FastScrollerRecyclerView(us.koller.cameraroll.ui.widget.FastScrollerRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 2 with Settings

use of us.koller.cameraroll.data.Settings in project Camera-Roll-Android-App by kollerlukas.

the class ThemeableActivity method readTheme.

private void readTheme(Context context) {
    Settings s = Settings.getInstance(context);
    theme = s.getThemeInstance(this);
    backgroundColor = theme.getBackgroundColor(this);
    toolbarColor = theme.getToolbarColor(this);
    textColorPrimary = theme.getTextColorPrimary(this);
    textColorSecondary = theme.getTextColorSecondary(this);
    accentColor = theme.getAccentColor(this);
    accentTextColor = theme.getAccentTextColor(this);
}
Also used : Settings(us.koller.cameraroll.data.Settings)

Example 3 with Settings

use of us.koller.cameraroll.data.Settings in project Camera-Roll-Android-App by kollerlukas.

the class Util method tintDrawableWithAccentColor.

private static Drawable tintDrawableWithAccentColor(Context context, Drawable d) {
    Settings s = Settings.getInstance(context);
    Theme theme = s.getThemeInstance(context);
    int tintColor = theme.getAccentColorLight(context);
    d = DrawableCompat.wrap(d);
    DrawableCompat.setTint(d, tintColor);
    return d;
}
Also used : Theme(us.koller.cameraroll.themes.Theme) Settings(us.koller.cameraroll.data.Settings)

Example 4 with Settings

use of us.koller.cameraroll.data.Settings in project Camera-Roll-Android-App by kollerlukas.

the class MediaProvider method getAlbumsWithVirtualDirectories.

public static ArrayList<Album> getAlbumsWithVirtualDirectories(Activity context) {
    Settings s = Settings.getInstance(context);
    boolean virtualDirs = s.getVirtualDirectories();
    if (!virtualDirs) {
        return getAlbums();
    }
    ArrayList<VirtualAlbum> virtualAlbums = getVirtualAlbums(context);
    ArrayList<Album> albums = getAlbums();
    if (albums == null || virtualAlbums == null) {
        return albums;
    }
    // noinspection unchecked
    albums = (ArrayList<Album>) getAlbums().clone();
    ArrayList<Album> albumsWithVirtualDirs = new ArrayList<>();
    for (int i = virtualAlbums.size() - 1; i >= 0; i--) {
        VirtualAlbum virtualAlbum = virtualAlbums.get(i);
        if (virtualAlbum.getDirectories().size() > 0) {
            virtualAlbum.create(context, albums);
            if (virtualAlbum.getAlbumItems().size() > 0) {
                albumsWithVirtualDirs.add(virtualAlbum);
            }
        }
    }
    albumsWithVirtualDirs.addAll(albums);
    for (int i = albumsWithVirtualDirs.size() - 1; i >= 0; i--) {
        Album album = albumsWithVirtualDirs.get(i);
        if (!(album instanceof VirtualAlbum)) {
            for (int k = 0; k < virtualAlbums.size(); k++) {
                if (virtualAlbums.get(k).contains(album.getPath())) {
                    albumsWithVirtualDirs.remove(i);
                    break;
                }
            }
        }
    }
    SortUtil.sortAlbums(context, albumsWithVirtualDirs);
    return albumsWithVirtualDirs;
}
Also used : ArrayList(java.util.ArrayList) VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum) Album(us.koller.cameraroll.data.models.Album) VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum) Settings(us.koller.cameraroll.data.Settings)

Example 5 with Settings

use of us.koller.cameraroll.data.Settings in project Camera-Roll-Android-App by kollerlukas.

the class MediaProvider method loadAlbum.

public static void loadAlbum(final Activity context, final String path, final OnAlbumLoadedCallback callback) {
    if (path == null) {
        context.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                callback.onAlbumLoaded(null);
            }
        });
        return;
    }
    if (albums == null) {
        Settings s = Settings.getInstance(context);
        boolean hiddenFolders = s.getHiddenFolders();
        new MediaProvider(context).loadAlbums(context, hiddenFolders, new OnMediaLoadedCallback() {

            @Override
            public void onMediaLoaded(ArrayList<Album> albums) {
                loadAlbum(context, path, callback);
            }

            @Override
            public void timeout() {
                callback.onAlbumLoaded(getErrorAlbum());
            }

            @Override
            public void needPermission() {
                callback.onAlbumLoaded(getErrorAlbum());
            }
        });
    } else {
        if (path.startsWith(VirtualAlbum.VIRTUAL_ALBUMS_DIR)) {
            ArrayList<VirtualAlbum> virtualDirectories = getVirtualAlbums(context);
            for (int i = 0; i < virtualDirectories.size(); i++) {
                if (virtualDirectories.get(i).getPath().equals(path)) {
                    final VirtualAlbum album = virtualDirectories.get(i);
                    album.create(context, albums);
                    context.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            callback.onAlbumLoaded(album);
                        }
                    });
                    return;
                }
            }
        } else if (path.equals(SINGLE_FOLDER_PATH)) {
            final Album album = new Album().setPath(MediaProvider.SINGLE_FOLDER_PATH);
            for (int i = 0; i < albums.size(); i++) {
                album.getAlbumItems().addAll(albums.get(i).getAlbumItems());
            }
            int sortBy = Settings.getInstance(context).sortAlbumsBy();
            SortUtil.sort(album.getAlbumItems(), sortBy);
            context.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    callback.onAlbumLoaded(album);
                }
            });
        } else {
            for (int i = 0; i < albums.size(); i++) {
                if (albums.get(i).getPath().equals(path)) {
                    final Album album = albums.get(i);
                    context.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            callback.onAlbumLoaded(album);
                        }
                    });
                    return;
                }
            }
        }
    }
}
Also used : VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum) Album(us.koller.cameraroll.data.models.Album) VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum) Settings(us.koller.cameraroll.data.Settings)

Aggregations

Settings (us.koller.cameraroll.data.Settings)10 Album (us.koller.cameraroll.data.models.Album)4 VirtualAlbum (us.koller.cameraroll.data.models.VirtualAlbum)2 Theme (us.koller.cameraroll.themes.Theme)2 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 RequiresApi (android.support.annotation.RequiresApi)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)1 DocumentFile (android.support.v4.provider.DocumentFile)1 ActionBar (android.support.v7.app.ActionBar)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SimpleItemAnimator (android.support.v7.widget.SimpleItemAnimator)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1