Thunderbottom / UltimateBrowserProject

android browser based on webview
http://bit.ly/XDAUBP
162 stars 59 forks source link

Weird Bug pls help #53

Closed Thunderbottom closed 8 years ago

Thunderbottom commented 8 years ago

Well, so now, the top part of the page is not shown in the view until I zoom in.

Here's the unzoomed page -

Unzoomed

And here's the page zoomed in -

zoom

As you can see the top part of the page is not shown in the unzoomed view, and I haven't touched anything in the WebView. @takahirom @james9909 pls help ;-;

Thunderbottom commented 8 years ago

@takahirom pls help

takahirom commented 8 years ago

I want to help you. But, I'm so busy.. Probably I can look this in weekend.

Thunderbottom commented 8 years ago

okay thanks :)

xdevs23 commented 8 years ago

Will also look into it

xdevs23 commented 8 years ago

Seems to work now... after my commits screenshot_2015-11-12-15-49-53

I have generated an apk from latest source code (including my latest commits today) and it is working. All times prior that apk did also have the bug.

Seems that the missing german arrays.xml was causing it, after adding it, it is working.

EDIT:

Ok, I checked it out again, and somehow the bug persists.

EDIT 2:

@balzathor found what is causing it: the webview has to be moved under the omnibox because it is overlapping the webview, or when using bottom, the status bar overlaps it. I will try to fix it, already playing around. Not overlapping: screenshot_2015-11-12-16-46-17 Overlapping: screenshot_2015-11-12-16-46-24

To reproduce this, set the omnibox position to top and scroll down a bit the page. After scrolling down, scroll back to the top but without letting the omnibox appear again.

Thunderbottom commented 8 years ago

But the top positioned omnibox also wasn't meant to overlap some portion, I don't know why but this is happening since last release, need to check past commits

xdevs23 commented 8 years ago

I found it!

It is in UltimateBrowserProjectWebView.java on "initWebView" where you define the OnTouchListener.

I tried this:

               if (action == MotionEvent.ACTION_DOWN) {
                    y2 = y1;
                } else if (action == MotionEvent.ACTION_UP) {
                    if ((y1 - y2) > UP_SCROLL_THRESHOLD) {
                        browserController.showOmnibox();
                        int l = view.getLeft(), t = view.getTop() + 48,
                            b = view.getBottom(), r = view.getRight();
                        view.layout(l, t, r, b);
                    } else if ((y1 - y2) < -DOWN_SCROLL_THRESHOLD) {
                        browserController.hideOmnibox();
                        int l = view.getLeft(), t = view.getTop() - 48,
                            b = view.getBottom(), r = view.getRight();
                        view.layout(l, t, r, b);
                    }
                    y2 = 0;
                }

And it works in some way... It is buggy, but if you overscroll 2 times after reaching the top of the page, it doesn't overlap anymore.

I will commit now and you just have to improve my solution...

But don't forget to do that in initWebView also, so that it is immediately correct.

screenshot_2015-11-12-17-15-37

xdevs23 commented 8 years ago

See https://github.com/balzathor/UltimateBrowserProject/commit/f2fd65b9f8a253dc4d640948d8a1afb8495ed8ae

Thunderbottom commented 8 years ago

The bug is, if you drag it more downwards, the webview shifts down, I guess you should revert the changes

xdevs23 commented 8 years ago

You have to pull down webview when omnibox is visible, so it doesn't overlap. And when omnibox disappears, just pull it up again.

And if the omnibox is at the bottom you have to pull it down although because the status bar is overlapping it. (Let me analyze the situation please and I will try to fix it)

Thunderbottom commented 8 years ago

No, what I'm saying is if you pull it down twice, it comes back into view, but if you keep pulling, then the webview gets dragged along with it and a white padding appears above. I'm pretty sure some old commit broke it.... I'm checking it too

xdevs23 commented 8 years ago

Yes, I know, I have seen that, just a few if statements would fix that, too. But it is a step into the right direction.

xdevs23 commented 8 years ago

Great news: It is almost finished

Thunderbottom commented 8 years ago

:+1:

xdevs23 commented 8 years ago

Didn't finish today, but will do later.

Please tell me if you solved it yourself in the meantime.

I need to know what changes the height and what changes the 'top offset' in your code...

It is working but somehow immediately after the webview is positioned correctly, it restores the previous wrong position.

Tell me where you did something like "view.layout()" on the webview.

Thanks

Thunderbottom commented 8 years ago

This and this is where I think the problem might be..

Thunderbottom commented 8 years ago

@james9909 any idea on where this might be?

james9909 commented 8 years ago

Unfortunately, I don't have enough time to look into the situation, and am very sorry about my unavailability for the past few months.

Thunderbottom commented 8 years ago

Well, that's fine. I'll go through it myself :)

xdevs23 commented 8 years ago

What you've marked were my tries to get the webview under the omnibox when it shows up.

I have uncommented the part here but didn't come to commit it: https://github.com/balzathor/UltimateBrowserProject/blob/83f21a387e1b4b5243edd0eadcbaba17c2434e9c/app/src/main/java/io/github/UltimateBrowserProject/Unit/ViewUnit.java#L48v

I had success doing it, but it was buggy, I have to think more about it and do something better, but basically the fix/workaround I am doing works.

xdevs23 commented 8 years ago

Also you did not handle the navigation bar size. For example, on my device, there is 50px of adjustHeight and 1200 of window height but the screen has 1280 height, so there's 30px missing... And this could also be what is missing

Thunderbottom commented 8 years ago

Can you explain the last part a bit more?

xdevs23 commented 8 years ago

See here

My screen resolution is 720x1280 Width is 720, Height is 1280 The window height is 1200, window width is 720, adjustHeight is 50, so status bar height is also 50.

1200 + 50 = 1250 but not 1280, so there are 30 pixels missing.

See here:

    public static boolean respectAdjustHeight = true;
    private static int adjustHeightMultiplier = 1;
    public static void bound(Context context, View view, boolean isFullScreen) {
        int windowWidth = getWindowWidth(context);    // gives 720, which is correct
        int windowHeight = getWindowHeight(context); // gives 1200
        int adjustHeight = 0;
        if (!isFullScreen && respectAdjustHeight)
            adjustHeight += getStatusBarHeight(context) * adjustHeightMultiplier;  // gives 50
      ...

The log here (from logcat):

Window height: 1200; Window width: 720; Adjust height: 50; status bar height: 50;widthSpec: 1073742544; heightSpec: 1073742974

is the result of

        Logging.logt(String.format(
                "Window height: %s; Window width: %s; "
              + "Adjust height: %s; status bar height: %s;"
              + "widthSpec: %s; heightSpec: %s",
                windowHeight, windowWidth,
                adjustHeight, getStatusBarHeight(context),
                widthSpec, heightSpec
        ));

The status bar has 50 pixels in height but the navbar has 80 pixels in height and not 30... So where do the 30 belong to?

(Navbar - status bar = 30; 80 - 50 = 30, but I don't think that has anything to do with...)

We are not talking about dp (Density Pixels), these are real pixels....

See the screenshot: scr13

Thunderbottom commented 8 years ago

Alright I get what you're saying, but that isn't the problem I guess. The screen size is set to 1250x720 just because the status bar/navbar takes up 30px. And in fullscreen mode if you see, it is totally hidden, where it works fine. I think there's some thing wrong in WebView...

xdevs23 commented 8 years ago

Yes, check out this. There is something missing, I guess.

xdevs23 commented 8 years ago

The problem is basically that the webview has to be pulln down when omnibox is visible, because it is overlaying the webview.

And with the bottom option, I think, the webview is under the status bar. You simply have to pull down the webview 96px (what is the height of the omnibox?) when it is shown. Doesn't matter if top or bottom, just do it and it works.

Thunderbottom commented 8 years ago

You were working on some fix right? how is it going?

xdevs23 commented 8 years ago

Well, it seems to work but the webview restores the previous position.

I have to look what is blocking

Don't know...

xdevs23 commented 8 years ago

Look here, I have this code now:

    @Override
    public void hideOmnibox(View view) {
        if (omnibox.getVisibility() != View.GONE) {
            Animation hide;
            if (anchor == 0) {
                if (contentFrame.findViewById(R.id.main_omnibox) == null) {
                    ((ViewGroup)omnibox.getParent()).removeView(omnibox);
                    contentFrame.addView(omnibox);
                    omnibox.bringToFront();
                }
                hide = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_top_up);

                int     l = view.getLeft(),
                        t = view.getTop(),
                        b = view.getBottom(),
                        r = view.getRight(),

                        sbOffset = getResources().getDimensionPixelSize(getResources()
                                .getIdentifier("status_bar_height", "dimen", "android")),

                        nbOffset = getResources().getDimensionPixelSize(getResources()
                                .getIdentifier("navigation_bar_height", "dimen", "android"))

                                ;
                view.layout(
                        l,
                        t - 96,
                        r,
                        b
                );
            } else {
                return;
            }
            hide.setAnimationListener(new Animation.AnimationListener() {

                @Override
                public void onAnimationStart(Animation animation) {}

                @Override
                public void onAnimationEnd(Animation animation) {
                    omnibox.setVisibility(View.GONE);
                    setBound((View) currentAlbumController);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {}
            });
            omnibox.startAnimation(hide);
        }
    }

    @Override
    public void showOmnibox(View view) {
        if (omnibox.getVisibility() != View.VISIBLE) {
            Animation show;
            if (anchor == 0) {
                if (contentFrame.findViewById(R.id.main_omnibox) == null) {
                    ((ViewGroup)omnibox.getParent()).removeView(omnibox);
                    contentFrame.addView(omnibox);
                    omnibox.bringToFront();
                }
                show = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_top_down);
            } else {
                return;
            }

            show.setAnimationListener(new Animation.AnimationListener() {

                @Override
                public void onAnimationStart(Animation animation) {
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    omnibox.setVisibility(View.VISIBLE);
                    setBound((View) currentAlbumController);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }
            });

            omnibox.startAnimation(show);

            int     l = view.getLeft(),
                    t = view.getTop(),
                    b = view.getBottom(),
                    r = view.getRight(),

                    sbOffset = getResources().getDimensionPixelSize(getResources()
                            .getIdentifier("status_bar_height", "dimen", "android")),

                    nbOffset = getResources().getDimensionPixelSize(getResources()
                            .getIdentifier("navigation_bar_height", "dimen", "android"))

                            ;

            view.layout(
                    l,
                    t + 96,
                    r,
                    b
            );
        }
    }

In this (50% slower) video you can see that it gets pulln down but when the omnibox appears, it goes up again. ezgif-4267518258

EDIT: You can see that the webview is behind the omnibox by swiping the omnibox to the right and holding it

xdevs23 commented 8 years ago

Ok, so now I am getting it fixed, the code is just wasted up and many things are blocking other things... I am finishing. For now it is working very good, just have to finish, and I hope it works...

xdevs23 commented 8 years ago

Sorry, I accidentally clicked on Close and comment

xdevs23 commented 8 years ago

It is working!

But without animation, I think we could add that later... Will commit now

Thunderbottom commented 8 years ago

I've seen that thing happen before, not sure where...

Thunderbottom commented 8 years ago

Sorry, I would've fixed this myself but I have exams coming up in 5 days so I can't do much at this moment. Thanks for helping though :)

xdevs23 commented 8 years ago

I already fixed it... I just wrote some things from scratch, and used my own ideas for it, now it works perfectly fine, just the slide in/out animation is missing but that we can do later.

Nothing is cropped at the top: scrw1

Nothing is cropped at the top: scrw2

And when using omnibox at the top, it is not overlaying: scrw3

Thunderbottom commented 8 years ago

That's awesome, although the animation was very much needed there..

Thunderbottom commented 8 years ago

Well, I'll just remove the "Hide omnibox" for now, I'm facing some glitches..

xdevs23 commented 8 years ago

Well, I have a better idea for an animation, but I'm glad that the bug is at least fixed, so we could just leave it how it is now and I will make the animation, I am sure that it will be awesome :smiley:

Thunderbottom commented 8 years ago

Can you try to reproduce the glitch so that I can make sure it's not happening only for me?

Thunderbottom commented 8 years ago

Try to load a page and hide the omnibox, then try to bring up the omnibox again, the omnibox shifts to the center of the display for a second or so and then comes back to normal.

xdevs23 commented 8 years ago

No, I don't have this glitch, it is working perfectly fine on my device...

Thunderbottom commented 8 years ago

Can you do this while the page is loading?

xdevs23 commented 8 years ago

Oh I see, that is not a glitch, it has something to do with the layout, we have to set a fixed size for the omnibox, because while the webview is loading a page, the omnibox just stretches up to the whole height. But that's not hard to do...

xdevs23 commented 8 years ago

Fixing it and creating an animation...

xdevs23 commented 8 years ago

@balzathor would be nice if you let me do the job, so the omnibox is working correctly with the webview

Thunderbottom commented 8 years ago

As I said, do anything just don't break it lol

xdevs23 commented 8 years ago

Ok, will do the work

xdevs23 commented 8 years ago

@balzathor It's fixed now :D

Maybe there's a tiny lag but that is a minor thing which we can ignore for now and fix it later.

Thunderbottom commented 8 years ago

Check this out - checkthisout

Thunderbottom commented 8 years ago

The gif is slow, but if you can test it, you'll see that the omnibox has a glitch when it appears, slowly pulling the WebView down with it for a split second, then getting back to normal. Also, sometimes when you swipe it up and down pretty fast, the omnibox appears before it actually should