Translate

Monday, September 26, 2016

Android: Blocking swipe-to-refresh on minimized AppBar

If you are designing an User-Interface that is using a CollapsingToolbarLayout and SwipeReshLayout, you may notice discomfort when flipping down the content, seen in CollapsingToolbarLayout that immediately trigger swipe-to-refresh.

Here I'm sharing a code below.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
 * Block SwipeRefreshLayout in collapsed and idle state.
 */
public class AppBarRefreshAdjustListener implements AppBarLayout.OnOffsetChangedListener {

    private static final long BLOCK_DELAY = 1000L;

    private final SwipeRefreshLayout mSwipeRefreshLayout;
    private int mVerticalOffset;
    private Handler mHandler = new Handler();

    public AppBarRefreshAdjustListener(SwipeRefreshLayout refreshLayout) {
        mSwipeRefreshLayout = refreshLayout;
        handleOffsetChanged(mVerticalOffset);
    }

    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
        handleOffsetChanged(verticalOffset);
    }

    private void handleOffsetChanged(int verticalOffset) {
        if (verticalOffset == 0) {
            mHandler.removeCallbacksAndMessages(null);
            mHandler.postDelayed(() -> {
                mSwipeRefreshLayout.setEnabled(mVerticalOffset == 0);
            }, BLOCK_DELAY);
        } else {
            mSwipeRefreshLayout.setEnabled(false);
        }
        mVerticalOffset = verticalOffset;
    }
}

This class solves the problem - blocking SwipeRefreshLayout on clotting time / AppBar deployment:

1
appBarLayout addOnOffsetChangedListener (new AppBarRefreshAdjustListener (swipeRefreshLayout) );

Update Vodafone HG553 Router to OpenWRT – Barrier Breaker 14.07

Upgrade your Vodafone HG553 to OpenWRT – Barrier Breaker 14.07:
Why OpenWrt? We can do a lot of things with OpenWRT, Like Share your Hardisk via wifi, torrent downloader, EasyHotSpot Login, etc…
Here are the Step you need to do:
1. Download the Firmware from this link:
2. Do a Clear Update with 30 second Reset procedure, here is the step:
-Turn Off the Router by pressing the switch behind the Router.
-Stick the little hole which containing a button, behind the Router under the Reset label. Keep Stick it then turn on the Router.
-Release the Stick after 30 seconds from the Router being turn on. The Indicator lamp will remain blue.
-Connect the Lan Cable Port 1 to the PC.
-Now, Open your pc and go to the network settings, set your IP address for the Lan card to: 192.168.1.2, subnet mask: 255.255.255.0, and Default Gateway: 192.168.1.1
-Open Internet Browser (Firefox, Chrome or IE), type in the address bar: //192.168.1.1
-Click “CHOOSE FILE”, and choose the firmware that we already download in step 1.
-Click “Upgrade”. Wait until the process done, it is about 2 minutes.
3. After the process done, there will be 2 indicator lamps in blue appear in the Router. And when you type //192.168.1.1, you will get the Login page of OpenWRT
4. Login with user: root and password: admin
Congratulation, your Router upgraded to OpenWRT – Barrier Breaker 14.07