Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to use in an activity without statusbar #25

Closed
wants to merge 1 commit into from

Conversation

mbiamont
Copy link

I had an error using this lib in activities which don't have a statusbar (the view is never shown).
What I did is to change the function com.irozon.sneaker.Utils$getStatusBarHeight(Activity activity).

static int getStatusBarHeight(Activity activity) {
        Rect rectangle = new Rect();
        activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rectangle);
        return Math.max(rectangle.top, Utils.convertToDp(activity, 26));
    }

It simply return the statusbar's height, and if it's below 26dp, it returns 26dp.

The other source code modified is just to test.

Please, deploy a new version of your lib with this fix, because I really would like to use it in my projects ❤️

@Hamadakram
Copy link
Owner

Hi,
Sorry i won't be able to accept your request as getStatusBarHeight should return only status bar height. If there is no status bar it should it should return 0. But your code is returning 26dp.

For your issue, i'll have to test again. getStatusBarHeight is only for adding padding on top and adding to height. If its not available, it will not add statusbar height to Sneaker height.

@mbiamont
Copy link
Author

Hi, getStatusBarHeight () return -10000 when there isn't statusbar.
I've put 26dp to simulate the statusbar height (and not 0), otherwise the view is very small.

Two solution here :

  • let 26dp
  • return 0, but add a way to put paddingTop to the view

@Hamadakram
Copy link
Owner

I just checked by removing status bar. Its working fine. Add your code snippet for more understanding.

@mbiamont
Copy link
Author

mbiamont commented Jun 18, 2018

1. With statusbar

No problem.

2. Without statusbar - current code

static int getStatusBarHeight(Activity activity) {
        Rect rectangle = new Rect();
        Window window = activity.getWindow();
        window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
        int statusBarHeight = rectangle.top; // returns -10000
        int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
        int titleBarHeight = contentViewTop - statusBarHeight;

        return statusBarHeight;
    }

Sneaker doesn't appear.

3. Without statusbar - 0px

static int getStatusBarHeight(Activity activity) {
        Rect rectangle = new Rect();
        activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rectangle);
        return Math.max(rectangle.top, 0);
    }

Sneaker a bit small.

4. Without statusbar - 26dp

static int getStatusBarHeight(Activity activity) {
        Rect rectangle = new Rect();
        activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rectangle);
        return Math.max(rectangle.top, Utils.convertToDp(activity, 26));
    }

No problem.

@Hamadakram
Copy link
Owner

That is not a status bar. You are removing Toolbar/ActionBar. Status bar is the bar that is showing battery status on top. Still for both conditions (removing status bar or toolbar), its working for me. Please check your code or give it a fixed height by SetHeight.

@Hamadakram Hamadakram closed this Jun 18, 2018
@mbiamont
Copy link
Author

I'm not talking about Toolbar, if you look on 2nd screen (current behavior), Toolbar is still here.

I'm removing statusbar using this snippet :

protected void onCreate(Bundle savedInstanceState) {
(...)
   Window w = getWindow();
   w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
   w.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants