backward compatible navigation drawer toggle // FREEBIE

This commit is contained in:
Jake McGinty 2014-02-01 19:40:46 -08:00
parent 6157a0df7a
commit ed3151bdb5
2 changed files with 46 additions and 1 deletions

View File

@ -82,7 +82,7 @@
<!-- ConversationListAdapter --> <!-- ConversationListAdapter -->
<string name="ConversationListAdapter_key_exchange_message">Key exchange message...</string> <string name="ConversationListAdapter_key_exchange_message">Key exchange message...</string>
<!-- ConversationListFragment --> <!-- ConversationListFragment -->
<string name="ConversationListFragment_delete_threads_question">Delete threads?</string> <string name="ConversationListFragment_delete_threads_question">Delete threads?</string>
<string name="ConversationListFragment_are_you_sure_you_wish_to_delete_all_selected_conversation_threads">Are you sure you wish to delete ALL selected conversation threads?</string> <string name="ConversationListFragment_are_you_sure_you_wish_to_delete_all_selected_conversation_threads">Are you sure you wish to delete ALL selected conversation threads?</string>
@ -686,6 +686,8 @@
<!-- conversation_list --> <!-- conversation_list -->
<string name="conversation_list__menu_search">Search</string> <string name="conversation_list__menu_search">Search</string>
<string name="conversation_list__drawer_open">Open navigation drawer</string>
<string name="conversation_list__drawer_close">Close navigation drawer</string>
<!-- conversation_secure_verified --> <!-- conversation_secure_verified -->
<string name="conversation_secure_verified__menu_security">Security</string> <string name="conversation_secure_verified__menu_security">Security</string>

View File

@ -1,5 +1,6 @@
package org.thoughtcrime.securesms; package org.thoughtcrime.securesms;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.database.ContentObserver; import android.database.ContentObserver;
@ -8,6 +9,7 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import android.provider.Telephony; import android.provider.Telephony;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat; import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
import android.util.Log; import android.util.Log;
@ -51,6 +53,7 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
private ConversationListFragment fragment; private ConversationListFragment fragment;
private MasterSecret masterSecret; private MasterSecret masterSecret;
private DrawerLayout drawerLayout; private DrawerLayout drawerLayout;
private DrawerToggle drawerToggle;
private ListView drawerList; private ListView drawerList;
@Override @Override
@ -71,6 +74,12 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
DirectoryRefreshListener.schedule(this); DirectoryRefreshListener.schedule(this);
} }
@Override
public void onPostCreate(Bundle bundle) {
super.onPostCreate(bundle);
drawerToggle.syncState();
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
@ -217,6 +226,13 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
} }
DrawerLayout drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout); 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); ListView drawer = (ListView)findViewById(R.id.left_drawer);
SimpleAdapter adapter = new SimpleAdapter(this, items, R.layout.navigation_drawer_item, from, to); SimpleAdapter adapter = new SimpleAdapter(this, items, R.layout.navigation_drawer_item, from, to);
@ -274,4 +290,31 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
startActivity(intent); 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();
}
}
} }