Skip to content

Commit

Permalink
don't assume 24dp for the status bar size
Browse files Browse the repository at this point in the history
  • Loading branch information
klinker24 committed Sep 22, 2017
1 parent e14d346 commit db153e1
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#

GRADLE_PLUGIN_VERSION=3.0.0-beta5
GRADLE_PLUGIN_VERSION=3.0.0-beta6
BUILD_TOOLS_VERSION=26.0.1

ANDROID_SUPPORT_VERSION=26.0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.CallSuper;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ProgressBar;

import xyz.klinker.android.drag_dismiss.DragDismissIntentBuilder;
import xyz.klinker.android.drag_dismiss.R;
import xyz.klinker.android.drag_dismiss.util.ColorUtils;
import xyz.klinker.android.drag_dismiss.util.StatusBarHelper;
import xyz.klinker.android.drag_dismiss.view.ElasticDragDismissFrameLayout;

public abstract class AbstractDragDismissDelegate {
Expand All @@ -40,6 +44,7 @@ public abstract class AbstractDragDismissDelegate {

private ProgressBar progressBar;
private Toolbar toolbar;
private AppBarLayout appBarLayout;
private View statusBar;

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

progressBar = (ProgressBar) activity.findViewById(R.id.dragdismiss_loading);
toolbar = (Toolbar) activity.findViewById(R.id.dragdismiss_toolbar);
appBarLayout = (AppBarLayout) activity.findViewById(R.id.dragdismiss_app_bar);
statusBar = activity.findViewById(R.id.dragdismiss_status_bar);

setupToolbar();
Expand Down Expand Up @@ -114,6 +120,15 @@ private void setupToolbar() {
if (!shouldShowToolbar) {
toolbar.setVisibility(View.GONE);
}

int statusBarHeight = StatusBarHelper.getStatusBarHeight(activity);
statusBar.getLayoutParams().height = statusBarHeight;

if (appBarLayout == null) {
((CoordinatorLayout.LayoutParams) toolbar.getLayoutParams()).topMargin = statusBarHeight;
} else {
((CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams()).topMargin = statusBarHeight;
}
}

private void setupDragDismiss() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.widget.FrameLayout;

import xyz.klinker.android.drag_dismiss.R;
import xyz.klinker.android.drag_dismiss.util.StatusBarHelper;
import xyz.klinker.android.drag_dismiss.view.ElasticDragDismissFrameLayout;
import xyz.klinker.android.drag_dismiss.view.ToolbarScrollListener;

Expand Down Expand Up @@ -67,6 +68,8 @@ 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);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (C) 2017 Luke Klinker
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package xyz.klinker.android.drag_dismiss.util;

import android.annotation.TargetApi;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2017 Luke Klinker
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package xyz.klinker.android.drag_dismiss.util;

import android.content.Context;
import android.util.TypedValue;

public class StatusBarHelper {

public static int getStatusBarHeight(Context context) {
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
return context.getResources().getDimensionPixelSize(resourceId);
} else {
return toDp(24, context);
}
}

private static int toDp(int px, Context context) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, px, context.getResources().getDisplayMetrics());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
android:background="@color/dragdismiss_toolbarBackground"/>

<android.support.design.widget.AppBarLayout
android:id="@+id/dragdismiss_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import xyz.klinker.android.drag_dismiss.DragDismissIntentBuilder;
import xyz.klinker.android.drag_dismiss.activity.DragDismissActivity;
import xyz.klinker.android.drag_dismiss.util.StatusBarHelper;

public class DismissableActivityNormalContent extends DragDismissActivity {

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

if (!getDragDismissDelegate().shouldShowToolbar()) {
// don't need the padding that pushes it below the toolbar
tv.setPadding(0,0,0,0);
tv.setPadding(0, 0,0,0);
}

if (getIntent().getBooleanExtra(EXTRA_SHOW_PROGRESS, false)) {
Expand Down
1 change: 0 additions & 1 deletion sample/src/main/res/layout/activity_scrollable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:padding="16dp" >

<TextView
Expand Down

0 comments on commit db153e1

Please sign in to comment.