use of android.support.annotation.RequiresApi 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();
}
use of android.support.annotation.RequiresApi in project Camera-Roll-Android-App by kollerlukas.
the class MainActivity method onActivityReenter.
@Override
public void onActivityReenter(final int resultCode, Intent intent) {
super.onActivityReenter(resultCode, intent);
int nestedRecyclerViewValue = getResources().getInteger(R.integer.STYLE_NESTED_RECYCLER_VIEW_VALUE);
if (intent.getAction() != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && intent.getAction().equals(ItemActivity.SHARED_ELEMENT_RETURN_TRANSITION) && Settings.getInstance(this).getStyle(this, pick_photos) == nestedRecyclerViewValue) {
// handle shared-element transition, for nested nestedRecyclerView style
Bundle tmpReenterState = new Bundle(intent.getExtras());
if (tmpReenterState.containsKey(AlbumActivity.ALBUM_PATH) && tmpReenterState.containsKey(AlbumActivity.EXTRA_CURRENT_ALBUM_POSITION)) {
String albumPath = tmpReenterState.getString(AlbumActivity.ALBUM_PATH);
final int sharedElementReturnPosition = tmpReenterState.getInt(AlbumActivity.EXTRA_CURRENT_ALBUM_POSITION);
int index = -1;
ArrayList<Album> albums = MediaProvider.getAlbumsWithVirtualDirectories(this);
for (int i = 0; i < albums.size(); i++) {
if (albums.get(i).getPath().equals(albumPath)) {
index = i;
break;
}
}
if (index == -1) {
return;
}
// postponing transition until sharedElement is laid out
postponeEnterTransition();
setExitSharedElementCallback(mCallback);
final NestedRecyclerViewAlbumHolder.StartSharedElementTransitionCallback callback = new NestedRecyclerViewAlbumHolder.StartSharedElementTransitionCallback() {
@Override
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public void startPostponedEnterTransition() {
// sharedElement is laid out --> start transition
MainActivity.this.startPostponedEnterTransition();
}
};
final int finalIndex = index;
recyclerView.scrollToPosition(index);
// wait until ViewHolder is laid out
recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onLayoutChange(View v, int l, int t, int r, int b, int oL, int oT, int oR, int oB) {
RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(finalIndex);
if (viewHolder != null) {
recyclerView.removeOnLayoutChangeListener(this);
} else {
// viewHolder hasn't been laid out yet --> wait
recyclerView.scrollToPosition(finalIndex);
}
if (viewHolder instanceof NestedRecyclerViewAlbumHolder) {
// found ViewHolder
sharedElementViewHolder = (NestedRecyclerViewAlbumHolder) viewHolder;
((NestedRecyclerViewAlbumHolder) viewHolder).onSharedElement(sharedElementReturnPosition, callback);
}
}
});
}
}
}
use of android.support.annotation.RequiresApi in project Camera-Roll-Android-App by kollerlukas.
the class EditImageActivity method onCreate.
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_image);
Intent intent = getIntent();
if (intent == null) {
return;
}
final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle("");
actionBar.setDisplayHomeAsUpEnabled(true);
}
Uri uri = intent.getData();
if (uri == null) {
finish();
return;
}
String mimeType = MediaType.getMimeType(this, uri);
if (!(MediaType.checkImageMimeType(mimeType) || MediaType.checkRAWMimeType(mimeType))) {
Toast.makeText(this, R.string.editing_file_format_not_supported, Toast.LENGTH_SHORT).show();
finish();
}
imagePath = intent.getStringExtra(IMAGE_PATH);
final CropImageView imageView = findViewById(R.id.cropImageView);
CropImageView.State state = null;
if (savedInstanceState != null) {
state = (CropImageView.State) savedInstanceState.getSerializable(IMAGE_VIEW_STATE);
}
imageView.loadImage(uri, state);
final Button doneButton = findViewById(R.id.done_button);
doneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
done(view);
}
});
// setting window insets manually
final ViewGroup rootView = findViewById(R.id.root_view);
final View actionArea = findViewById(R.id.action_area);
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);
toolbar.setPadding(toolbar.getPaddingStart() + insets.getSystemWindowInsetLeft(), toolbar.getPaddingTop() + insets.getSystemWindowInsetTop(), toolbar.getPaddingEnd() + insets.getSystemWindowInsetRight(), toolbar.getPaddingBottom());
actionArea.setPadding(actionArea.getPaddingStart() + insets.getSystemWindowInsetLeft(), actionArea.getPaddingTop(), actionArea.getPaddingEnd() + insets.getSystemWindowInsetRight(), actionArea.getPaddingBottom() + insets.getSystemWindowInsetBottom());
imageView.setPadding(imageView.getPaddingStart() + insets.getSystemWindowInsetLeft(), imageView.getPaddingTop(), /* + insets.getSystemWindowInsetTop()*/
imageView.getPaddingEnd() + insets.getSystemWindowInsetRight(), imageView.getPaddingBottom());
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(EditImageActivity.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() + windowInsets[0], toolbar.getPaddingTop() + windowInsets[1], toolbar.getPaddingEnd() + windowInsets[2], toolbar.getPaddingBottom());
actionArea.setPadding(actionArea.getPaddingStart() + windowInsets[0], actionArea.getPaddingTop(), actionArea.getPaddingEnd() + windowInsets[2], actionArea.getPaddingBottom() + windowInsets[3]);
imageView.setPadding(imageView.getPaddingStart() + windowInsets[0], imageView.getPaddingTop(), /* + windowInsets[1]*/
imageView.getPaddingEnd() + windowInsets[2], imageView.getPaddingBottom());
}
});
}
imageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
imageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
imageView.setPadding(imageView.getPaddingStart(), imageView.getPaddingTop() + toolbar.getHeight(), imageView.getPaddingEnd(), imageView.getPaddingBottom() + actionArea.getHeight());
}
});
// needed to achieve transparent navBar
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE);
}
use of android.support.annotation.RequiresApi in project Camera-Roll-Android-App by kollerlukas.
the class VirtualAlbumsActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_virtual_albums);
final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
virtualAlbums = Provider.getVirtualAlbums(this);
final TextView emptyStateText = findViewById(R.id.empty_state_text);
if (virtualAlbums.size() == 0) {
emptyStateText.setText(R.string.no_virtual_albums);
emptyStateText.setVisibility(View.VISIBLE);
}
final int accentColor = theme.getAccentColor(this);
final int toolbarTitleColor = theme.getTextColorPrimary(this);
final String toolbarTitle = String.valueOf(toolbar.getTitle());
final RecyclerView recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter = new RecyclerViewAdapter(virtualAlbums);
onVirtualAlbumChangedListener = new RecyclerViewAdapter.OnVirtualAlbumChangedListener() {
@Override
public void onVirtualAlbumChanged(VirtualAlbum album) {
menu.findItem(R.id.add_virtual_album).setVisible(album == null);
if (album != null) {
toolbar.setTitle(album.getName());
toolbar.setTitleTextColor(accentColor);
} else {
toolbar.setTitle(toolbarTitle);
toolbar.setTitleTextColor(toolbarTitleColor);
}
if (album == null) {
if (virtualAlbums.size() == 0) {
emptyStateText.setText(R.string.no_virtual_albums);
emptyStateText.setVisibility(View.VISIBLE);
} else {
emptyStateText.setVisibility(View.GONE);
}
} else {
if (album.getDirectories().size() == 0) {
emptyStateText.setText(R.string.no_paths);
emptyStateText.setVisibility(View.VISIBLE);
} else {
emptyStateText.setVisibility(View.GONE);
}
}
}
};
adapter.setOnVirtualAlbumChangedListener(onVirtualAlbumChangedListener);
recyclerView.setAdapter(adapter);
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() + insets.getSystemWindowInsetLeft(), toolbar.getPaddingTop() + insets.getSystemWindowInsetTop(), toolbar.getPaddingEnd() + insets.getSystemWindowInsetRight(), toolbar.getPaddingBottom());
recyclerView.setPadding(recyclerView.getPaddingStart() + insets.getSystemWindowInsetLeft(), recyclerView.getPaddingTop(), recyclerView.getPaddingEnd() + insets.getSystemWindowInsetRight(), recyclerView.getPaddingBottom() + insets.getSystemWindowInsetBottom());
// 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
int[] screenSize = Util.getScreenSize(VirtualAlbumsActivity.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() + windowInsets[0], toolbar.getPaddingTop() + windowInsets[1], toolbar.getPaddingEnd() + windowInsets[2], toolbar.getPaddingBottom());
recyclerView.setPadding(recyclerView.getPaddingStart() + windowInsets[0], recyclerView.getPaddingTop(), recyclerView.getPaddingEnd() + windowInsets[2], recyclerView.getPaddingBottom() + windowInsets[3]);
rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
// needed to achieve transparent statusBar in landscape; don't ask me why, but its working
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
use of android.support.annotation.RequiresApi in project Camera-Roll-Android-App by kollerlukas.
the class ItemViewUtil method bindTransitionView.
public static void bindTransitionView(final ImageView imageView, final AlbumItem albumItem) {
// handle timeOut
if (albumItem.isSharedElement && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
new Handler().postDelayed(new Runnable() {
@Override
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public void run() {
albumItem.isSharedElement = false;
((AppCompatActivity) imageView.getContext()).startPostponedEnterTransition();
}
}, 100);
}
ViewCompat.setTransitionName(imageView, albumItem.getPath());
Context context = imageView.getContext();
Glide.with(context).asBitmap().load(albumItem.getUri(context)).listener(new RequestListener<Bitmap>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
albumItem.error = true;
if (albumItem.isSharedElement && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
albumItem.isSharedElement = false;
((AppCompatActivity) imageView.getContext()).startPostponedEnterTransition();
}
return false;
}
@Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
if (albumItem.isSharedElement && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
albumItem.isSharedElement = false;
((AppCompatActivity) imageView.getContext()).startPostponedEnterTransition();
}
return false;
}
}).apply(albumItem.getGlideRequestOptions(imageView.getContext())).into(imageView);
}
Aggregations