Skip to content

Commit

Permalink
add new preference to let the implementor decide if they want to draw…
Browse files Browse the repository at this point in the history
… under the status bar, or if they want to let the library manage the content padding
  • Loading branch information
klinker24 committed Sep 23, 2017
1 parent db153e1 commit 8d57b44
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

### v1.5.0

* Don't assume 24dp for the status bar size (Essential Ph-1)
* Add DragDismissIntentBuilder preference for whether or not you want to draw under the status bar.
* If not, the library will handle the content margin at the top, to take the status bar into account
* This is off by default, so the library is handling the status bar size, for you

### v1.4.4

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To include it in your project, add this to your module's `build.gradle` file:
```groovy
dependencies {
...
compile 'com.klinkerapps:drag-dismiss-activity:1.4.4'
compile 'com.klinkerapps:drag-dismiss-activity:1.5.0'
}
```

Expand Down Expand Up @@ -88,6 +88,7 @@ new DragDismissBundleBuilder(context)
.setShouldScrollToolbar(true) // defaults to true
.setFullscreenOnTablets(false) // defaults to false, tablets will have padding on each side
.setDragElasticity(DragDismissIntentBuilder.DragElasticity.NORMAL) // Larger elasticities will make it easier to dismiss.
.setDrawUnderStatusBar(false) // defaults to false. Change to true if you don't want me to handle the content margin for the Activity. Does not apply to the RecyclerView Activities
.build(dragDismissActivity);

// do anything else that you want to set up the Intent
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ MIN_SDK=15
TARGET_SDK=26
COMPILE_SDK=26

VERSION_NAME=1.4.4
VERSION_NAME=1.5.0
VERSION_CODE=1
GROUP=com.klinkerapps

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class DragDismissIntentBuilder {
public static final String EXTRA_SHOULD_SHOW_TOOLBAR = "extra_show_toolbar";
public static final String EXTRA_SHOULD_SCROLL_TOOLBAR = "extra_scroll_toolbar";
public static final String EXTRA_FULLSCREEN_FOR_TABLETS = "extra_fullscreen_tablets";
public static final String EXTRA_DRAW_UNDER_STATUS_BAR = "extra_draw_under_status_bar";

public static final int DEFAULT_TOOLBAR_RESOURCE = R.color.dragdismiss_toolbarBackground;

Expand All @@ -49,6 +50,7 @@ public enum DragElasticity {
private boolean shouldShowToolbar = true;
private boolean shouldScrollToolbar = true;
private boolean fullscreen = false;
private boolean drawUnderStatusBar = false;

private Context context;

Expand All @@ -73,6 +75,7 @@ public Intent build(Intent intentToBuildOn) {
intentToBuildOn.putExtra(EXTRA_SHOULD_SHOW_TOOLBAR, shouldShowToolbar);
intentToBuildOn.putExtra(EXTRA_SHOULD_SCROLL_TOOLBAR, shouldScrollToolbar);
intentToBuildOn.putExtra(EXTRA_FULLSCREEN_FOR_TABLETS, fullscreen);
intentToBuildOn.putExtra(EXTRA_DRAW_UNDER_STATUS_BAR, drawUnderStatusBar);

return intentToBuildOn;
}
Expand Down Expand Up @@ -164,4 +167,19 @@ public DragDismissIntentBuilder setFullscreenOnTablets(boolean fullscreen) {
this.fullscreen = fullscreen;
return this;
}

/**
* Set whether or not you want to place content under the status bar manually, in your layout. If not,
* this library will handle the content margins to account for the status bar. Remember that not all
* phones have the same size status bar. This will only apply for the {@link xyz.klinker.android.drag_dismiss.delegate.DragDismissDelegate}, not
* the {@link xyz.klinker.android.drag_dismiss.delegate.DragDismissRecyclerViewDelegate}.
* You will need to always handle the RecyclerView yourself. A header View is a great way to do that.
*
* @param drawUnderStatusBar
* @return the builder.
*/
public DragDismissIntentBuilder setDrawUnderStatusBar(boolean drawUnderStatusBar) {
this.drawUnderStatusBar = drawUnderStatusBar;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public abstract class AbstractDragDismissDelegate {
private int primaryColor;
private boolean shouldShowToolbar;
private boolean shouldScrollToolbar;
protected boolean drawUnderStatusBar;

AbstractDragDismissDelegate(AppCompatActivity activity) {
this.activity = activity;
Expand Down Expand Up @@ -101,6 +102,7 @@ private void getIntentExtras() {
activity.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
}

this.drawUnderStatusBar = activity.getIntent().getBooleanExtra(DragDismissIntentBuilder.EXTRA_DRAW_UNDER_STATUS_BAR, false);
this.fullscreenForTablets = activity.getIntent().getBooleanExtra(DragDismissIntentBuilder.EXTRA_FULLSCREEN_FOR_TABLETS, false);
this.shouldScrollToolbar = activity.getIntent().getBooleanExtra(DragDismissIntentBuilder.EXTRA_SHOULD_SCROLL_TOOLBAR, true);
this.shouldShowToolbar = activity.getIntent().getBooleanExtra(DragDismissIntentBuilder.EXTRA_SHOULD_SHOW_TOOLBAR, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ public void onDrag(float elasticOffset, float elasticOffsetPixels, float rawOffs
FrameLayout elasticContent = (FrameLayout) activity.findViewById(R.id.dragdismiss_content);
elasticContent.addView(callback.onCreateContent(activity.getLayoutInflater(), elasticContent, savedInstanceState));

((NestedScrollView.LayoutParams) elasticContent.getLayoutParams()).topMargin = StatusBarHelper.getStatusBarHeight(activity);
if (!drawUnderStatusBar) {
((NestedScrollView.LayoutParams) elasticContent.getLayoutParams()).topMargin = StatusBarHelper.getStatusBarHeight(activity);
}
}

@Override
Expand Down

0 comments on commit 8d57b44

Please sign in to comment.