mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-12-27 22:18:58 +00:00
Added option menu to navigation bar
This commit is contained in:
parent
52512b2343
commit
3923e2b704
@ -8,17 +8,13 @@ import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.SubMenu;
|
||||
import android.widget.TextView;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.communiquons.android.comunic.client.BuildConfig;
|
||||
@ -29,8 +25,6 @@ import org.communiquons.android.comunic.client.data.helpers.AccountHelper;
|
||||
import org.communiquons.android.comunic.client.data.helpers.ConversationsListHelper;
|
||||
import org.communiquons.android.comunic.client.data.helpers.DatabaseHelper;
|
||||
import org.communiquons.android.comunic.client.data.helpers.DebugHelper;
|
||||
import org.communiquons.android.comunic.client.data.helpers.GetUsersHelper;
|
||||
import org.communiquons.android.comunic.client.data.models.UserInfo;
|
||||
import org.communiquons.android.comunic.client.data.runnables.FriendRefreshLoopRunnable;
|
||||
import org.communiquons.android.comunic.client.data.services.NotificationsService;
|
||||
import org.communiquons.android.comunic.client.data.utils.AccountUtils;
|
||||
@ -50,7 +44,6 @@ import org.communiquons.android.comunic.client.ui.listeners.openConversationList
|
||||
import org.communiquons.android.comunic.client.ui.listeners.updateConversationListener;
|
||||
import org.communiquons.android.comunic.client.ui.utils.UiUtils;
|
||||
import org.communiquons.android.comunic.client.ui.views.NavigationBar;
|
||||
import org.communiquons.android.comunic.client.ui.views.WebUserAccountImage;
|
||||
|
||||
|
||||
/**
|
||||
@ -178,7 +171,7 @@ public class MainActivity extends AppCompatActivity implements
|
||||
|
||||
|
||||
/**
|
||||
* Top menu creation
|
||||
* Activity context menu
|
||||
*/
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
@ -230,6 +223,12 @@ public class MainActivity extends AppCompatActivity implements
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Navigation bar options
|
||||
*
|
||||
* @param menuItem Selected item
|
||||
* @return TRUE if the event is consumed / FALSE else
|
||||
*/
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
|
||||
int id = menuItem.getItemId();
|
||||
@ -259,6 +258,25 @@ public class MainActivity extends AppCompatActivity implements
|
||||
openConversationsListFragment();
|
||||
}
|
||||
|
||||
//More options
|
||||
else if(id == R.id.action_more){
|
||||
PopupMenu popupMenu = new PopupMenu(this,
|
||||
mNavBar.getItemIdentifierView(R.id.action_more));
|
||||
onCreateOptionsMenu(popupMenu.getMenu());
|
||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
return onOptionsItemSelected(item);
|
||||
}
|
||||
});
|
||||
popupMenu.show();
|
||||
return false;
|
||||
}
|
||||
|
||||
else
|
||||
//Option not found
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,29 @@
|
||||
package org.communiquons.android.comunic.client.ui.utils;
|
||||
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
/**
|
||||
* Menu utilities
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
public class MenuUtils {
|
||||
|
||||
/**
|
||||
* Find and return the index of an identifier in a menu
|
||||
*
|
||||
* @param menu Target menu
|
||||
* @param identifier Queried identifier
|
||||
* @return Matching index
|
||||
*/
|
||||
public static int MenuIdentifierToIndex(Menu menu, int identifier){
|
||||
MenuItem item = menu.findItem(identifier);
|
||||
|
||||
for(int i = 0; i < menu.size(); i++)
|
||||
if(menu.getItem(i).equals(item))
|
||||
return i;
|
||||
|
||||
throw new RuntimeException("Identifier not found in menu!");
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ import android.widget.LinearLayout;
|
||||
import android.widget.PopupMenu;
|
||||
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
import org.communiquons.android.comunic.client.ui.utils.MenuUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -110,6 +111,27 @@ public class NavigationBar extends BaseFrameLayoutView implements NavigationBarI
|
||||
this.mOnNavigationItemSelectedListener = onNavigationItemSelectedListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view associated to an index
|
||||
*
|
||||
* @param index The index of the item to get
|
||||
* @return Related view
|
||||
*/
|
||||
public View getItemIndexView(int index){
|
||||
return mItems.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view associated to an identifier
|
||||
*
|
||||
* @param id The identifier of the item to get
|
||||
* @return Related view
|
||||
*/
|
||||
public View getItemIdentifierView(int id){
|
||||
return getItemIndexView(MenuUtils.MenuIdentifierToIndex(mMenu, id));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onItemClick(int index) {
|
||||
if(mOnNavigationItemSelectedListener == null)
|
||||
|
9
app/src/main/res/drawable/ic_more.xml
Normal file
9
app/src/main/res/drawable/ic_more.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="@color/default_drawable_color"
|
||||
android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
|
||||
</vector>
|
@ -26,4 +26,9 @@
|
||||
android:id="@+id/action_conversations"
|
||||
android:title="@string/navigation_bottom_conversations_item"
|
||||
android:icon="@drawable/ic_menu_conversations" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_more"
|
||||
android:title="@string/action_more"
|
||||
android:icon="@drawable/ic_more"/>
|
||||
</menu>
|
@ -236,4 +236,5 @@
|
||||
<string name="activity_login_too_many_request">Trop de tentative de connexion ont échouées. Veuillez réessayer ultérieurement.</string>
|
||||
<string name="err_create_account_existing_email">Cette adresse est déjà associée à un compte Comunic existant !</string>
|
||||
<string name="err_create_account_too_many_requests">Trop de création de compte. Veuillez réessayer ultérieurement.</string>
|
||||
<string name="action_more">Plus</string>
|
||||
</resources>
|
@ -234,5 +234,6 @@
|
||||
<string name="account_created_sign_in">Sign in</string>
|
||||
<string name="activity_login_too_many_request">Too many failed login requests. Please try again later…</string>
|
||||
<string name="err_create_account_existing_email">This email address is already associated with an account!</string>
|
||||
<string name="err_create_account_too_many_requests">Too many account creation requests. Please try again later...</string>
|
||||
<string name="err_create_account_too_many_requests">Too many account creation requests. Please try again later…</string>
|
||||
<string name="action_more">More</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user