Skip to content

Commit

Permalink
Close Navigation Drawer when pressing back key
Browse files Browse the repository at this point in the history
  • Loading branch information
javiersantos committed Jun 13, 2015
1 parent 860ee07 commit 6de9036
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.javiersantos.mlmanager.utils.AppPreferences;
import com.javiersantos.mlmanager.utils.UtilsApp;
import com.javiersantos.mlmanager.utils.UtilsUI;
import com.mikepenz.materialdrawer.Drawer;
import com.pnikosis.materialishprogress.ProgressWheel;

import java.io.File;
Expand Down Expand Up @@ -61,6 +62,7 @@ public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private VerticalRecyclerViewFastScroller fastScroller;
private ProgressWheel progressWheel;
private Drawer drawer;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -108,7 +110,7 @@ private void setInitialConfiguration() {
}

private void setNavigationDrawer(AppAdapter appAdapter, AppAdapter appSystemAdapter, RecyclerView recyclerView) {
UtilsUI.setNavigationDrawer(this, getApplicationContext(), toolbar, appAdapter, appSystemAdapter, recyclerView);
drawer = UtilsUI.setNavigationDrawer(this, getApplicationContext(), toolbar, appAdapter, appSystemAdapter, recyclerView);
}

class getInstalledApps extends AsyncTask<Void, PackageInfo, Void> {
Expand Down Expand Up @@ -234,18 +236,22 @@ private List<AppInfo> createList(List<String> apps, List<String> apks, List<Stri

@Override
public void onBackPressed() {
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, R.string.tap_exit, Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce = false;
if (drawer.isDrawerOpen()) {
drawer.closeDrawer();
} else {
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
}, 2000);
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, R.string.tap_exit, Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce = false;
}
}, 2000);
}
}

}

0 comments on commit 6de9036

Please # to comment.