Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Fix: Add Exit Toast #375

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand Down Expand Up @@ -61,6 +62,8 @@ public class MainActivity extends FormListActivity implements LoaderManager.Load
private static final String COLLECT_PACKAGE = "org.odk.collect.android";
private static final int STORAGE_PERMISSION_REQUEST_CODE = 101;
private static final int FORM_LOADER = 2;
public static final int BACK_TIME = 2000;
public static boolean BACK_FLAG = false;

@BindView(R.id.toolbar)
Toolbar toolbar;
Expand Down Expand Up @@ -300,4 +303,21 @@ private void setUpLoader() {
}
}
}

@Override
public void onBackPressed() {
if(BACK_FLAG){
super.onBackPressed();
return;
}
BACK_FLAG = true;
Toast.makeText(getApplicationContext(),getString(R.string.exit_toast),Toast.LENGTH_SHORT).show();

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
BACK_FLAG = false;
}
},BACK_TIME);
}
}
2 changes: 2 additions & 0 deletions skunkworks_crow/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,6 @@
<string name="finalized_on_date_at_time">\'Finalized on\' EEE, MMM dd, yyyy \'at\' HH:mm</string> <!-- http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html -->
<string name="sent_on_date_at_time">\'Sent on\' EEE, MMM dd, yyyy \'at\' HH:mm</string> <!-- http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html -->
<string name="sending_failed_on_date_at_time">\'Sending failed on\' EEE, MMM dd, yyyy \'at\' HH:mm</string> <!-- http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html -->

<string name="exit_toast">Press BACK again to exit program</string>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of program please give app

</resources>