From ed3151bdb5c6e1bc0a58247dcde01ab26d9eff6f Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Sat, 1 Feb 2014 19:40:46 -0800 Subject: [PATCH] backward compatible navigation drawer toggle // FREEBIE --- res/values/strings.xml | 4 +- .../securesms/ConversationListActivity.java | 43 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index c467194aec..6feb71736f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -82,7 +82,7 @@ Key exchange message... - + Delete threads? Are you sure you wish to delete ALL selected conversation threads? @@ -686,6 +686,8 @@ Search + Open navigation drawer + Close navigation drawer Security diff --git a/src/org/thoughtcrime/securesms/ConversationListActivity.java b/src/org/thoughtcrime/securesms/ConversationListActivity.java index 4661b0bdb5..eb8bf3c4d1 100644 --- a/src/org/thoughtcrime/securesms/ConversationListActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationListActivity.java @@ -1,5 +1,6 @@ package org.thoughtcrime.securesms; +import android.app.Activity; import android.content.Intent; import android.content.res.TypedArray; import android.database.ContentObserver; @@ -8,6 +9,7 @@ import android.os.Build; import android.os.Bundle; import android.provider.ContactsContract; import android.provider.Telephony; +import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.util.Log; @@ -51,6 +53,7 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment private ConversationListFragment fragment; private MasterSecret masterSecret; private DrawerLayout drawerLayout; + private DrawerToggle drawerToggle; private ListView drawerList; @Override @@ -71,6 +74,12 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment DirectoryRefreshListener.schedule(this); } + @Override + public void onPostCreate(Bundle bundle) { + super.onPostCreate(bundle); + drawerToggle.syncState(); + } + @Override public void onResume() { super.onResume(); @@ -217,6 +226,13 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment } DrawerLayout drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout); + drawerToggle = new DrawerToggle(this, drawerLayout, + R.drawable.ic_drawer, + R.string.conversation_list__drawer_open, + R.string.conversation_list__drawer_close); + + drawerLayout.setDrawerListener(drawerToggle); + ListView drawer = (ListView)findViewById(R.id.left_drawer); SimpleAdapter adapter = new SimpleAdapter(this, items, R.layout.navigation_drawer_item, from, to); @@ -274,4 +290,31 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment startActivity(intent); } } + + class DrawerToggle extends ActionBarDrawerToggle { + + public DrawerToggle(Activity activity, DrawerLayout drawerLayout, + int drawerImageRes, int openDrawerContentDescRes, + int closeDrawerContentDescRes) { + + super(activity, drawerLayout, drawerImageRes, + openDrawerContentDescRes, closeDrawerContentDescRes); + } + + @Override + public void onDrawerClosed(View drawerView) { + + super.onDrawerClosed(drawerView); + + invalidateOptionsMenu(); + } + + @Override + public void onDrawerOpened(View drawerView) { + + super.onDrawerOpened(drawerView); + + invalidateOptionsMenu(); + } + } }