Skip to content

Commit db153e1

Browse files
committed
don't assume 24dp for the status bar size
1 parent e14d346 commit db153e1

File tree

8 files changed

+74
-3
lines changed

8 files changed

+74
-3
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515
#
1616

17-
GRADLE_PLUGIN_VERSION=3.0.0-beta5
17+
GRADLE_PLUGIN_VERSION=3.0.0-beta6
1818
BUILD_TOOLS_VERSION=26.0.1
1919

2020
ANDROID_SUPPORT_VERSION=26.0.1

library/src/main/java/xyz/klinker/android/drag_dismiss/delegate/AbstractDragDismissDelegate.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@
2020
import android.graphics.Color;
2121
import android.os.Bundle;
2222
import android.support.annotation.CallSuper;
23+
import android.support.design.widget.AppBarLayout;
24+
import android.support.design.widget.CoordinatorLayout;
2325
import android.support.v7.app.AppCompatActivity;
2426
import android.support.v7.app.AppCompatDelegate;
2527
import android.support.v7.widget.Toolbar;
2628
import android.view.View;
2729
import android.view.ViewGroup;
30+
import android.widget.FrameLayout;
2831
import android.widget.ProgressBar;
2932

3033
import xyz.klinker.android.drag_dismiss.DragDismissIntentBuilder;
3134
import xyz.klinker.android.drag_dismiss.R;
3235
import xyz.klinker.android.drag_dismiss.util.ColorUtils;
36+
import xyz.klinker.android.drag_dismiss.util.StatusBarHelper;
3337
import xyz.klinker.android.drag_dismiss.view.ElasticDragDismissFrameLayout;
3438

3539
public abstract class AbstractDragDismissDelegate {
@@ -40,6 +44,7 @@ public abstract class AbstractDragDismissDelegate {
4044

4145
private ProgressBar progressBar;
4246
private Toolbar toolbar;
47+
private AppBarLayout appBarLayout;
4348
private View statusBar;
4449

4550
private String dragElasticity;
@@ -61,6 +66,7 @@ public void onCreate(Bundle savedInstanceState) {
6166

6267
progressBar = (ProgressBar) activity.findViewById(R.id.dragdismiss_loading);
6368
toolbar = (Toolbar) activity.findViewById(R.id.dragdismiss_toolbar);
69+
appBarLayout = (AppBarLayout) activity.findViewById(R.id.dragdismiss_app_bar);
6470
statusBar = activity.findViewById(R.id.dragdismiss_status_bar);
6571

6672
setupToolbar();
@@ -114,6 +120,15 @@ private void setupToolbar() {
114120
if (!shouldShowToolbar) {
115121
toolbar.setVisibility(View.GONE);
116122
}
123+
124+
int statusBarHeight = StatusBarHelper.getStatusBarHeight(activity);
125+
statusBar.getLayoutParams().height = statusBarHeight;
126+
127+
if (appBarLayout == null) {
128+
((CoordinatorLayout.LayoutParams) toolbar.getLayoutParams()).topMargin = statusBarHeight;
129+
} else {
130+
((CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams()).topMargin = statusBarHeight;
131+
}
117132
}
118133

119134
private void setupDragDismiss() {

library/src/main/java/xyz/klinker/android/drag_dismiss/delegate/DragDismissDelegate.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.widget.FrameLayout;
2626

2727
import xyz.klinker.android.drag_dismiss.R;
28+
import xyz.klinker.android.drag_dismiss.util.StatusBarHelper;
2829
import xyz.klinker.android.drag_dismiss.view.ElasticDragDismissFrameLayout;
2930
import xyz.klinker.android.drag_dismiss.view.ToolbarScrollListener;
3031

@@ -67,6 +68,8 @@ public void onDrag(float elasticOffset, float elasticOffsetPixels, float rawOffs
6768

6869
FrameLayout elasticContent = (FrameLayout) activity.findViewById(R.id.dragdismiss_content);
6970
elasticContent.addView(callback.onCreateContent(activity.getLayoutInflater(), elasticContent, savedInstanceState));
71+
72+
((NestedScrollView.LayoutParams) elasticContent.getLayoutParams()).topMargin = StatusBarHelper.getStatusBarHeight(activity);
7073
}
7174

7275
@Override

library/src/main/java/xyz/klinker/android/drag_dismiss/util/ColorUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (C) 2017 Luke Klinker
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package xyz.klinker.android.drag_dismiss.util;
218

319
import android.annotation.TargetApi;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (C) 2017 Luke Klinker
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package xyz.klinker.android.drag_dismiss.util;
18+
19+
import android.content.Context;
20+
import android.util.TypedValue;
21+
22+
public class StatusBarHelper {
23+
24+
public static int getStatusBarHeight(Context context) {
25+
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
26+
if (resourceId > 0) {
27+
return context.getResources().getDimensionPixelSize(resourceId);
28+
} else {
29+
return toDp(24, context);
30+
}
31+
}
32+
33+
private static int toDp(int px, Context context) {
34+
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, px, context.getResources().getDisplayMetrics());
35+
}
36+
}

library/src/main/res/layout/dragdismiss_activity_recycler.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
android:background="@color/dragdismiss_toolbarBackground"/>
6565

6666
<android.support.design.widget.AppBarLayout
67+
android:id="@+id/dragdismiss_app_bar"
6768
android:layout_width="match_parent"
6869
android:layout_height="wrap_content"
6970
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

sample/src/main/java/xyz/klinker/drag_dismiss/DismissableActivityNormalContent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import xyz.klinker.android.drag_dismiss.DragDismissIntentBuilder;
2626
import xyz.klinker.android.drag_dismiss.activity.DragDismissActivity;
27+
import xyz.klinker.android.drag_dismiss.util.StatusBarHelper;
2728

2829
public class DismissableActivityNormalContent extends DragDismissActivity {
2930

@@ -36,7 +37,7 @@ public View onCreateContent(LayoutInflater inflater, ViewGroup parent, Bundle sa
3637

3738
if (!getDragDismissDelegate().shouldShowToolbar()) {
3839
// don't need the padding that pushes it below the toolbar
39-
tv.setPadding(0,0,0,0);
40+
tv.setPadding(0, 0,0,0);
4041
}
4142

4243
if (getIntent().getBooleanExtra(EXTRA_SHOW_PROGRESS, false)) {

sample/src/main/res/layout/activity_scrollable.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
android:orientation="vertical"
2121
android:layout_width="wrap_content"
2222
android:layout_height="wrap_content"
23-
android:layout_marginTop="24dp"
2423
android:padding="16dp" >
2524

2625
<TextView

0 commit comments

Comments
 (0)