Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Press Back Again Toast in Simulator #415

Open
wants to merge 1 commit into
base: bug-fixes
Choose a base branch
from
Open
Changes from all commits
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
@@ -1,6 +1,7 @@
package org.buildmlearn.toolkit.simulator;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
Expand All @@ -25,6 +26,7 @@ public class Simulator extends AppCompatActivity {
private static final String TAG = "SIMULATOR";
private int templateId;
private TemplateInterface selectedTemplate;
private boolean isBackPressed = false;

/**
* {@inheritDoc}
Expand Down Expand Up @@ -117,20 +119,31 @@ protected void onSaveInstanceState(Bundle outState) {

@Override
public void onBackPressed() {

int count = getSupportFragmentManager().getBackStackEntryCount();
if (count == 1) {
finish();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer != null) {
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
if (drawer != null && drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
int count = getSupportFragmentManager().getBackStackEntryCount();
if (count <= 1) {
if (isBackPressed){
finish();
super.onBackPressed();
}
else{
Toast.makeText(this, "Tap back once more to exit.", Toast.LENGTH_SHORT).show();
isBackPressed=true;
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
isBackPressed= false;
}
}, 3000);
}}
else {
super.onBackPressed();
}
} else {
super.onBackPressed();
}
}

Expand Down