Skip to content
This repository has been archived by the owner on Sep 8, 2019. It is now read-only.

Commit

Permalink
- ui adjustments for Api 19
Browse files Browse the repository at this point in the history
  • Loading branch information
kollerlukas committed Mar 1, 2017
1 parent 8b81995 commit 2fc598c
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package us.koller.cameraroll.adapter.album.ViewHolder;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
Expand All @@ -11,7 +9,6 @@
import us.koller.cameraroll.R;
import us.koller.cameraroll.data.AlbumItem;
import us.koller.cameraroll.util.ColorFade;
import us.koller.cameraroll.util.Util;

public abstract class AlbumItemHolder extends RecyclerView.ViewHolder {

Expand All @@ -28,16 +25,6 @@ public void setAlbumItem(AlbumItem albumItem) {
}

public void loadImage(final ImageView imageView, final AlbumItem albumItem) {

/*final Context context = itemView.getContext();
int screenWidth = Util.getScreenWidth((Activity) context);
int columnCount = Util.getAlbumActivityGridColumnCount(context);
//square image
int[] imageDimens = {
(int) ((float) screenWidth / columnCount),
(int) ((float) screenWidth / columnCount)};*/

Glide.clear(imageView);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package us.koller.cameraroll.adapter.item.ViewHolder;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
Expand Down Expand Up @@ -40,7 +37,7 @@ public void bindView() {
playButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlbumActivity.videoOnClick((Activity) view.getContext(), albumItem);
AlbumActivity.videoOnClick(view.getContext(), albumItem);
}
});
playButton.setAlpha(0.0f);
Expand Down
40 changes: 39 additions & 1 deletion app/src/main/java/us/koller/cameraroll/ui/AboutActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowInsets;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.ImageView;
Expand All @@ -30,6 +31,7 @@
import us.koller.cameraroll.R;
import us.koller.cameraroll.data.Provider.MediaProvider;
import us.koller.cameraroll.ui.widget.SwipeBackCoordinatorLayout;
import us.koller.cameraroll.util.Util;

public class AboutActivity extends AppCompatActivity implements SwipeBackCoordinatorLayout.OnSwipeListener {

Expand Down Expand Up @@ -81,8 +83,8 @@ public boolean onLongClick(View view) {
aboutText.setText(Html.fromHtml(getString(R.string.about_text)));
aboutText.setMovementMethod(new LinkMovementMethod());

final View rootView = findViewById(R.id.root_view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
final View rootView = findViewById(R.id.root_view);
rootView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
@Override
Expand Down Expand Up @@ -114,6 +116,42 @@ public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
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());

aboutText.setPadding(aboutText.getPaddingStart(),
aboutText.getPaddingTop(),
aboutText.getPaddingEnd(),
aboutText.getPaddingBottom() + windowInsets[3]);

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++) {
Expand Down
46 changes: 44 additions & 2 deletions app/src/main/java/us/koller/cameraroll/ui/AlbumActivity.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package us.koller.cameraroll.ui;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.ActivityNotFoundException;
import android.content.ClipData;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
Expand Down Expand Up @@ -295,6 +295,48 @@ public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
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);

ViewGroup.MarginLayoutParams fabParams
= (ViewGroup.MarginLayoutParams) fab.getLayoutParams();
fabParams.rightMargin += windowInsets[2];
fabParams.bottomMargin += windowInsets[3];
fab.setLayoutParams(fabParams);

rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}

toolbar.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
Expand Down Expand Up @@ -729,7 +771,7 @@ public void onItemSelected(int selectedItemCount) {
}
}

public static void videoOnClick(Activity context, AlbumItem albumItem) {
public static void videoOnClick(Context context, AlbumItem albumItem) {
if (!(albumItem instanceof Video)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,47 @@ public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
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]);

ViewGroup.MarginLayoutParams fabParams
= (ViewGroup.MarginLayoutParams) fab.getLayoutParams();
fabParams.rightMargin += windowInsets[2];
fabParams.bottomMargin += windowInsets[3];
fab.setLayoutParams(fabParams);

rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}

//setting recyclerView top padding, so recyclerView starts below the toolbar
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/us/koller/cameraroll/ui/ItemActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,10 @@ public void onGlobalLayout() {
int[] screenSize = Util.getScreenSize(ItemActivity.this);

int[] windowInsets = new int[]{
screenSize[0] - rootView.getLeft(),
screenSize[1] - rootView.getTop(),
screenSize[2] - rootView.getRight(),
rootView.getBottom() - screenSize[3]};
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],
Expand Down
41 changes: 40 additions & 1 deletion app/src/main/java/us/koller/cameraroll/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -27,6 +28,7 @@
import android.view.WindowInsets;

import java.util.ArrayList;
import java.util.Arrays;

import us.koller.cameraroll.R;
import us.koller.cameraroll.adapter.main.RecyclerViewAdapter;
Expand Down Expand Up @@ -147,8 +149,8 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
});

//setting window insets manually
final ViewGroup rootView = (ViewGroup) findViewById(R.id.root_view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
final ViewGroup rootView = (ViewGroup) findViewById(R.id.root_view);
rootView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
@RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
Expand All @@ -174,6 +176,43 @@ public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
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(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())};

Log.d("MainActivity", "windowInsets: " + Arrays.toString(windowInsets));

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]);

rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}

//setting recyclerView top padding, so recyclerView starts below the toolbar
Expand Down
15 changes: 10 additions & 5 deletions app/src/main/java/us/koller/cameraroll/util/ItemViewUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,16 @@ public static ViewGroup bindImageViewForVideo(final ImageView imageView,
Util.getVideoDimensions(albumItem.getPath()) :
Util.getImageDimensions(imageView.getContext(), albumItem.getPath());

int screenWidth = Util.getScreenWidth((Activity) imageView.getContext());
float scale = ((float) screenWidth) / (float) imageDimens[0];
scale = scale > 1.0f ? 1.0f : scale == 0.0f ? 1.0f : scale;
imageDimens[0] = (int) (imageDimens[0] * scale);
imageDimens[1] = (int) (imageDimens[1] * scale);
if (imageView.getContext() instanceof Activity) {
int screenWidth = Util.getScreenWidth((Activity) imageView.getContext());
float scale = ((float) screenWidth) / (float) imageDimens[0];
scale = scale > 1.0f ? 1.0f : scale == 0.0f ? 1.0f : scale;
imageDimens[0] = (int) (imageDimens[0] * scale);
imageDimens[1] = (int) (imageDimens[1] * scale);
} else {
imageDimens[0] = imageDimens[0] / 2;
imageDimens[1] = imageDimens[1] / 2;
}

Glide.with(imageView.getContext())
.load(albumItem.getPath())
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipeBackView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="@bool/belowLollipop">
android:layout_height="match_parent">

<android.support.v4.widget.NestedScrollView
android:id="@+id/scroll_view"
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_album.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
android:id="@+id/root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dark_bg"
android:fitsSystemWindows="@bool/belowLollipop">
android:background="@color/dark_bg">

<include layout="@layout/recycler_view_layout"/>

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_file_explorer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/swipeBackView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="@bool/belowLollipop">
android:layout_height="match_parent">

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="@bool/belowLollipop">
android:layout_height="match_parent">
<!--android:fitsSystemWindows="@bool/belowLollipop"-->

<include layout="@layout/recycler_view_layout"/>
</FrameLayout>
Loading

0 comments on commit 2fc598c

Please sign in to comment.