Commit 63404961 authored by Grigory Fedorov's avatar Grigory Fedorov

Navigation drawer for main activity. "Settings", "about" and "exit" moved to...

Navigation drawer for main activity. "Settings", "about" and "exit" moved to drawer from options menu. New icons.
parent 8db1474c
......@@ -20,15 +20,19 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
......@@ -60,6 +64,7 @@ import com.xabber.android.ui.dialog.ContactIntegrationDialogFragment;
import com.xabber.android.ui.dialog.StartAtBootDialogFragment;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.preferences.AboutViewer;
import com.xabber.android.ui.preferences.PreferenceEditor;
import com.xabber.androiddev.R;
import com.xabber.xmpp.address.Jid;
......@@ -74,7 +79,7 @@ import java.util.Collection;
* @author alexander.ivanov
*/
public class ContactList extends ManagedActivity implements OnAccountChangedListener,
View.OnClickListener, OnChoosedListener, OnContactClickListener {
View.OnClickListener, OnChoosedListener, OnContactClickListener, ContactListDrawerFragment.ContactListDrawerListener {
/**
* Select contact to be invited to the room was requested.
......@@ -102,6 +107,8 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
private SearchView searchView;
private BarPainter barPainter;
private ActionBarDrawerToggle drawerToggle;
private DrawerLayout drawerLayout;
public static Intent createPersistentIntent(Context context) {
Intent intent = new Intent(context, ContactList.class);
......@@ -149,6 +156,13 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
toolbar.setOnClickListener(this);
setSupportActionBar(toolbar);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.production_title, R.string.production_title);
drawerLayout.setDrawerListener(drawerToggle);
getSupportActionBar().setHomeButtonEnabled(true);
barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
......@@ -381,6 +395,10 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (drawerToggle.onOptionsItemSelected(item)) {
return true;
}
switch (item.getItemId()) {
case R.id.action_search:
searchView.setIconified(false);
......@@ -400,17 +418,32 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
case R.id.action_chat_list:
startActivity(ChatViewer.createRecentChatsIntent(this));
return true;
case R.id.action_settings:
startActivity(PreferenceEditor.createIntent(this));
return true;
case R.id.action_exit:
exit();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
drawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
drawerToggle.onConfigurationChanged(newConfig);
}
@Override
public void onBackPressed() {
if (drawerLayout.isDrawerOpen(Gravity.START | Gravity.LEFT)) {
drawerLayout.closeDrawers();
return;
}
super.onBackPressed();
}
private void exit() {
Application.getInstance().requestToClose();
showDialog(DIALOG_CLOSE_APPLICATION_ID);
......@@ -544,4 +577,20 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
((ContactListFragment)getSupportFragmentManager().findFragmentById(R.id.container)).rebuild();
}
@Override
public void onContactListDrawerListener(int viewId) {
drawerLayout.closeDrawers();
switch (viewId) {
case R.id.drawer_action_settings:
startActivity(PreferenceEditor.createIntent(this));
break;
case R.id.drawer_action_about:
startActivity(AboutViewer.createIntent(this));
break;
case R.id.drawer_action_exit:
exit();
break;
}
}
}
package com.xabber.android.ui;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.xabber.androiddev.R;
public class ContactListDrawerFragment extends Fragment implements View.OnClickListener {
ContactListDrawerListener listener;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.contact_list_drawer, container, false);
view.findViewById(R.id.drawer_action_settings).setOnClickListener(this);
view.findViewById(R.id.drawer_action_about).setOnClickListener(this);
view.findViewById(R.id.drawer_action_exit).setOnClickListener(this);
return view;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
listener = (ContactListDrawerListener) activity;
}
@Override
public void onDetach() {
super.onDetach();
listener = null;
}
@Override
public void onClick(View v) {
listener.onContactListDrawerListener(v.getId());
}
interface ContactListDrawerListener {
void onContactListDrawerListener(int viewId);
}
}
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="?android:colorAccent" />
</shape>
</item>
</ripple>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/grey_300" android:state_pressed="true" />
</selector>
\ No newline at end of file
......@@ -13,28 +13,41 @@
You should have received a copy of the GNU General Public License,
along with this program. If not, see http://www.gnu.org/licenses/.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar_default"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextAppearance="@style/ToolbarTitle" />
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/container"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
android:orientation="vertical">
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar_default"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextAppearance="@style/ToolbarTitle" />
<!-- Main layout -->
<RelativeLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<!-- Nav drawer -->
<fragment
android:id="@+id/fragment_drawer"
android:name="com.xabber.android.ui.ContactListDrawerFragment"
android:layout_width="304dp"
android:layout_height="match_parent"
android:layout_gravity="left|start" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
android:clickable="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="170dp"
android:background="@color/grey_300">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="16dp"
android:src="@drawable/ic_connect" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/drawer_action_settings"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@drawable/drawer_touch"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_settings_grey600_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:text="@string/preference_editor"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/drawer_action_about"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@drawable/drawer_touch"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_help_circle_grey600_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:text="@string/preference_about"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black" />
</LinearLayout>
<LinearLayout
android:id="@+id/drawer_action_exit"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@drawable/drawer_touch"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_exit_grey600_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:text="@string/exit"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
......@@ -2,55 +2,43 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_search"
android:title="@android:string/search_go"
app:showAsAction="always|collapseActionView"
android:orderInCategory="100"
android:icon="@drawable/ic_search_white_24dp"
android:orderInCategory="100"
android:title="@android:string/search_go"
app:actionViewClass="android.widget.SearchView"
app:showAsAction="always|collapseActionView"
/>
<item android:id="@+id/action_add_contact"
android:title="@string/contact_add"
app:showAsAction="never"
android:icon="@drawable/ic_person_add_white_24dp"
android:orderInCategory="110"
android:title="@string/contact_add"
app:showAsAction="never"
/>
<item android:id="@+id/action_join_conference"
android:title="@string/muc_add"
app:showAsAction="never"
android:icon="@drawable/ic_group_white_24dp"
android:orderInCategory="120"
android:title="@string/muc_add"
app:showAsAction="never"
/>
<item android:id="@+id/action_change_status"
android:orderInCategory="130"
android:title="@string/status_editor"
app:showAsAction="never"
android:orderInCategory="130"
/>
<item android:id="@+id/action_chat_list"
android:icon="@drawable/ic_list_white_24dp"
android:orderInCategory="140"
android:title="@string/chat_list"
app:showAsAction="never"
android:orderInCategory="140"
android:icon="@drawable/ic_list_white_24dp"
/>
<item android:id="@+id/action_close_chats"
android:title="@string/close_chats"
app:showAsAction="never"
android:orderInCategory="150"
/>
<item android:id="@+id/action_settings"
android:title="@string/preference_editor"
app:showAsAction="never"
android:orderInCategory="160"
/>
<item android:id="@+id/action_exit"
android:title="@string/exit"
android:title="@string/close_chats"
app:showAsAction="never"
android:orderInCategory="200"
/>
</menu>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment