long press for exit

Support for Android version of Total Commander

Moderators: white, Hacker, petermad, Stefan2

Post Reply
kamerunka
Junior Member
Junior Member
Posts: 29
Joined: 2009-11-01, 00:03 UTC

long press for exit

Post by *kamerunka »

currently it is a little bit problematic, you hold and hold, and hold ... and nothing happens until you release your finger.
i think it will be better if it exits if you hold it for a while, regardles if you lft you finger or not
User avatar
Number99
Junior Member
Junior Member
Posts: 27
Joined: 2009-04-11, 13:56 UTC
Location: Sweden

Post by *Number99 »

I'd like to see some kind of confirmation that TC is going to exit when I longpress the back button. A short vibration for example.
#202310
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48083
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Unfortunately TC does not receive any notification from Android when the press is long enough. All it gets is either a notification OnClicked, or OnLongClicked, but only when the button is released.
Author of Total Commander
https://www.ghisler.com
kamerunka
Junior Member
Junior Member
Posts: 29
Joined: 2009-11-01, 00:03 UTC

Post by *kamerunka »

both dolphin & cool reader have such functionality and provide some feedback
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48083
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

On a long press of the back button???

All I have seen is when you press the back button shortly, you get a message "press again to exit".
Author of Total Commander
https://www.ghisler.com
siealex
Senior Member
Senior Member
Posts: 278
Joined: 2009-03-22, 16:36 UTC

Post by *siealex »

It is a system function on HTC devices.
We are not so S.M.A.R.T. as we imagine...
User avatar
za222
Member
Member
Posts: 146
Joined: 2003-03-11, 17:19 UTC
Location: Germany

Post by *za222 »

It does work, you need to implement it like this:

Code: Select all

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)  {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        // track for long presses
        event.startTracking();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        // long press event
        // end activity by calling finish() for example or show confirmation dialog
        // return true will cause the CANCELED flag to be set in the event
        // which can be checked in the onKeyUp() method to make sure
        // that the short-press-action isn't performed additionally.
        return true;
    }
    return super.onKeyLongPress(keyCode, event);
}

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_CALL) {
        if (!event.isCanceled()) { // check if the user performed a long-press
            // if not, perform normal (short press) action
            /* ... */
        }
        return true;
    }
    return super.onKeyUp(keyCode, event);
}
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48083
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Hmm, the only difference to my code seems to be the call

Code: Select all

event.startTracking();
I have added this now, but don't see any difference at all. There is no clue (like a shake as when holding down the finger on the display) when the time limit for the long click is reached.
Author of Total Commander
https://www.ghisler.com
User avatar
za222
Member
Member
Posts: 146
Joined: 2003-03-11, 17:19 UTC
Location: Germany

Post by *za222 »

that is very weird.
I'm using that exact implementation in an app and it works fine.
As soon as the time is reached, onKeyLongPress() is called.

But I just went through the sources of the android 2.3.7 stock browser, they are using a slightly different approach.

Maybe that works:

Code: Select all

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
                if (event.getRepeatCount() == 0) { // actual "down" event
                    event.startTracking();
                    return true;
                } else if (event.isLongPress()) {
                    // key was held until long press is recognized, causing the FLAG_LONG_PRESS flag to be set
                    /* long press action here */
                    return true;
                }
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK)) {
                if (event.isTracking() && !event.isCanceled()) {
                    // long press didnt fire, so this is a regular short press
                    /* short press action */
                    return true;
                }
        }
        return super.onKeyUp(keyCode, event);
    }
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48083
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

that is very weird.
I'm using that exact implementation in an app and it works fine.
As soon as the time is reached, onKeyLongPress() is called.
Not here (Android 2.2)
Maybe that works:
Yes it does, thanks a lot!
Author of Total Commander
https://www.ghisler.com
User avatar
gewone
Junior Member
Junior Member
Posts: 66
Joined: 2008-03-06, 17:37 UTC

Post by *gewone »

The long-press-to-exit has worked a charm on all my previous phones (Samsung Galaxy series), but on my new Oneplus 3T the function doesn't have any effect at all. Any clue?
User avatar
Hacker
Moderator
Moderator
Posts: 13065
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

gewone,
Works fine here. What is your setting under Settings - Buttons - Back button - Long press action? Mine is No action.

Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48083
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Some Android versions contain manufacturer-specific changes, e.g. long tap on home shows task list etc. I guess that long tap on back has been redefined system-wide on your phone...
Author of Total Commander
https://www.ghisler.com
Post Reply