require a double Back press to exit the app

This commit is contained in:
tibbi 2016-10-11 23:44:48 +02:00
parent d463ffdb4a
commit 46a20095d8
7 changed files with 22 additions and 1 deletions

View file

@ -5,6 +5,7 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.support.v4.app.ActivityCompat;
import android.view.Menu;
import android.view.MenuItem;
@ -24,8 +25,11 @@ public class MainActivity extends SimpleActivity implements ItemsFragment.ItemIn
@BindView(R.id.breadcrumbs) Breadcrumbs mBreadcrumbs;
private static final int STORAGE_PERMISSION = 1;
private static final int BACK_PRESS_TIMEOUT = 5000;
private static boolean mShowFullPath;
private static Config mConfig;
private static boolean mWasBackJustPressed;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -108,7 +112,18 @@ public class MainActivity extends SimpleActivity implements ItemsFragment.ItemIn
@Override
public void onBackPressed() {
if (mBreadcrumbs.getChildCount() <= 1) {
finish();
if (!mWasBackJustPressed) {
mWasBackJustPressed = true;
Utils.showToast(getApplicationContext(), R.string.press_back_again);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mWasBackJustPressed = false;
}
}, BACK_PRESS_TIMEOUT);
} else {
finish();
}
} else {
mBreadcrumbs.removeBreadcrumb();
final FileDirItem item = (FileDirItem) mBreadcrumbs.getChildAt(mBreadcrumbs.getChildCount() - 1).getTag();

View file

@ -34,6 +34,7 @@
<string name="initial_breadcrumb">home</string>
<string name="ok">OK</string>
<string name="cancel">Abbrechen</string>
<string name="press_back_again">Press back again to exit</string>
<!-- File and directory properties -->
<string name="file_properties">File properties</string>

View file

@ -34,6 +34,7 @@
<string name="initial_breadcrumb">home</string>
<string name="ok">OK</string>
<string name="cancel">Annulla</string>
<string name="press_back_again">Press back again to exit</string>
<!-- File and directory properties -->
<string name="file_properties">Proprietà file</string>

View file

@ -34,6 +34,7 @@
<string name="initial_breadcrumb">ホーム</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="press_back_again">Press back again to exit</string>
<!-- File and directory properties -->
<string name="file_properties">File properties</string>

View file

@ -34,6 +34,7 @@
<string name="initial_breadcrumb">início</string>
<string name="ok">OK</string>
<string name="cancel">Cancelar</string>
<string name="press_back_again">Press back again to exit</string>
<!-- File and directory properties -->
<string name="file_properties">Propriedades do ficheiro</string>

View file

@ -34,6 +34,7 @@
<string name="initial_breadcrumb">home</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="press_back_again">Press back again to exit</string>
<!-- File and directory properties -->
<string name="file_properties">File properties</string>

View file

@ -34,6 +34,7 @@
<string name="initial_breadcrumb">home</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="press_back_again">Press back again to exit</string>
<!-- File and directory properties -->
<string name="file_properties">File properties</string>