-
Notifications
You must be signed in to change notification settings - Fork 395
Floating actions menu #2335
Floating actions menu #2335
Changes from 2 commits
0d48801
b60c6c6
c738e96
8f00609
d5043fc
e965e19
7511580
7a7186b
5f7489d
603e4ef
9a0de73
958e425
d396dd3
e3cb8ae
329a813
1f7310f
b0c1905
b1a038d
dc8a80c
e95b4b4
83e2a85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
import android.content.IntentFilter; | ||
import android.content.SharedPreferences; | ||
import android.content.res.ColorStateList; | ||
import android.graphics.drawable.Drawable; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
|
@@ -38,13 +39,14 @@ | |
import android.support.design.internal.BottomNavigationItemView; | ||
import android.support.design.internal.BottomNavigationMenuView; | ||
import android.support.design.widget.BottomNavigationView; | ||
import android.support.design.widget.FloatingActionButton; | ||
import android.support.design.widget.NavigationView; | ||
import android.support.design.widget.TextInputEditText; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v4.app.FragmentManager; | ||
import android.support.v4.content.ContextCompat; | ||
import android.support.v4.graphics.drawable.DrawableCompat; | ||
import android.support.v4.view.GravityCompat; | ||
import android.support.v4.view.ViewCompat; | ||
import android.support.v4.widget.DrawerLayout; | ||
import android.support.v7.app.ActionBarDrawerToggle; | ||
import android.support.v7.widget.SearchView; | ||
|
@@ -68,6 +70,10 @@ | |
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import com.getbase.floatingactionbutton.AddFloatingActionButton; | ||
import com.getbase.floatingactionbutton.FloatingActionButton; | ||
import com.getbase.floatingactionbutton.FloatingActionsMenu; | ||
|
||
import org.matrix.androidsdk.MXDataHandler; | ||
import org.matrix.androidsdk.MXSession; | ||
import org.matrix.androidsdk.call.IMXCall; | ||
|
@@ -187,8 +193,17 @@ public class VectorHomeActivity extends RiotAppCompatActivity implements SearchV | |
@BindView(R.id.listView_spinner_views) | ||
View waitingView; | ||
|
||
@BindView(R.id.floating_action_button) | ||
FloatingActionButton mFloatingActionButton; | ||
@BindView(R.id.floating_action_menu) | ||
FloatingActionsMenu mFloatingActionsMenu; | ||
|
||
@BindView(R.id.button_start_chat) | ||
FloatingActionButton mFabStartChat; | ||
|
||
@BindView(R.id.button_create_room) | ||
FloatingActionButton mFabCreateRoom; | ||
|
||
@BindView(R.id.button_join_room) | ||
FloatingActionButton mFabJoinRoom; | ||
|
||
// mFloatingActionButton is hidden for 1s when there is scroll | ||
private Timer mFloatingActionButtonTimer; | ||
|
@@ -217,6 +232,9 @@ public class VectorHomeActivity extends RiotAppCompatActivity implements SearchV | |
@BindView(R.id.search_view) | ||
SearchView mSearchView; | ||
|
||
@BindView(R.id.floating_action_menu_touch_guard) | ||
View touchGuard; | ||
|
||
private boolean mStorePermissionCheck = false; | ||
|
||
// a shared files intent is waiting the store init | ||
|
@@ -473,11 +491,14 @@ public void run() { | |
* Display the TAB if it is required | ||
*/ | ||
private void showFloatingActionButton() { | ||
if (null != mFloatingActionButton) { | ||
if (null != mFloatingActionsMenu) { | ||
if ((mCurrentMenuId == R.id.bottom_action_favourites) || (mCurrentMenuId == R.id.bottom_action_groups)) { | ||
mFloatingActionButton.setVisibility(View.GONE); | ||
mFloatingActionsMenu.collapse(); | ||
mFloatingActionsMenu.setVisibility(View.GONE); | ||
} else { | ||
mFloatingActionButton.show(); | ||
mFloatingActionsMenu.collapse(); | ||
mFloatingActionsMenu.setVisibility(View.VISIBLE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implemented animations. |
||
// mFloatingActionButton.show(); | ||
} | ||
} | ||
} | ||
|
@@ -954,7 +975,33 @@ private void updateSelectedFragment(final MenuItem item) { | |
*/ | ||
public void updateTabStyle(final int primaryColor, final int secondaryColor) { | ||
mToolbar.setBackgroundColor(primaryColor); | ||
mFloatingActionButton.setBackgroundTintList(ColorStateList.valueOf(primaryColor)); | ||
|
||
AddFloatingActionButton menuButton = mFloatingActionsMenu.findViewById(com.getbase.floatingactionbutton.R.id.fab_expand_menu_button); | ||
|
||
Class menuClass = FloatingActionsMenu.class; | ||
try { | ||
Field normal = menuClass.getDeclaredField("mAddButtonColorNormal"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you obliged to do that? Isn't it possible using styles? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Styles could be used but only for a one time setup. |
||
normal.setAccessible(true); | ||
Field pressed = menuClass.getDeclaredField("mAddButtonColorPressed"); | ||
pressed.setAccessible(true); | ||
|
||
normal.set(mFloatingActionsMenu, primaryColor); | ||
pressed.set(mFloatingActionsMenu, secondaryColor); | ||
|
||
menuButton.setColorNormal(primaryColor); | ||
menuButton.setColorPressed(secondaryColor); | ||
// mFloatingActionsMenu.invalidate(); | ||
} catch (Exception ignored) { | ||
|
||
} | ||
|
||
mFabJoinRoom.setColorNormal(secondaryColor); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it intended to exchange primary and secondary color for the 3 small FABs (regarding the colors for the main FAB)? It is more visible on the "Contact" tab |
||
mFabJoinRoom.setColorPressed(primaryColor); | ||
mFabCreateRoom.setColorNormal(secondaryColor); | ||
mFabCreateRoom.setColorPressed(primaryColor); | ||
mFabStartChat.setColorNormal(secondaryColor); | ||
mFabStartChat.setColorPressed(primaryColor); | ||
|
||
mVectorPendingCallView.updateBackgroundColor(primaryColor); | ||
mSyncInProgressView.setBackgroundColor(primaryColor); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
|
@@ -963,7 +1010,7 @@ public void updateTabStyle(final int primaryColor, final int secondaryColor) { | |
mSyncInProgressView.getIndeterminateDrawable().setColorFilter( | ||
secondaryColor, android.graphics.PorterDuff.Mode.SRC_IN); | ||
} | ||
mFloatingActionButton.setRippleColor(secondaryColor); | ||
// mFloatingActionButton.setRippleColor(secondaryColor); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
getWindow().setStatusBarColor(secondaryColor); | ||
} | ||
|
@@ -1022,15 +1069,80 @@ public void run() { | |
mSearchView.setIconifiedByDefault(false); | ||
mSearchView.setOnQueryTextListener(this); | ||
|
||
if (null != mFloatingActionButton) { | ||
mFloatingActionButton.setOnClickListener(new View.OnClickListener() { | ||
// if (null != mFloatingActionButton) { | ||
// mFloatingActionButton.setOnClickListener(new View.OnClickListener() { | ||
// @Override | ||
// public void onClick(View v) { | ||
// Fragment fragment = getSelectedFragment(); | ||
// | ||
// if (!(fragment instanceof AbsHomeFragment) || !((AbsHomeFragment) fragment).onFabClick()) { | ||
// onFloatingButtonClick(); | ||
// } | ||
// } | ||
// }); | ||
// } | ||
|
||
Drawable drawable; | ||
|
||
drawable = getResources().getDrawable(R.drawable.ic_person_black_24dp).mutate(); | ||
DrawableCompat.setTint(drawable, getResources().getColor(android.R.color.white)); | ||
mFabStartChat.setIconDrawable(drawable); | ||
|
||
drawable = getResources().getDrawable(R.drawable.ic_add_white).mutate(); | ||
DrawableCompat.setTint(drawable, getResources().getColor(android.R.color.white)); | ||
mFabCreateRoom.setIconDrawable(drawable); | ||
|
||
drawable = getResources().getDrawable(R.drawable.riot_tab_rooms).mutate(); | ||
DrawableCompat.setTint(drawable, getResources().getColor(android.R.color.white)); | ||
mFabJoinRoom.setIconDrawable(drawable); | ||
|
||
// Pre-Lollipop does not support elevation so cannot have touch guard | ||
// above bottomNavigationView. | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The touch guard is not shown on PreLollipop, it is a bit annoying. If there is no elevation before API 21, I think this is not a problem to show the touchguard. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only reason why I've disabled the touch guard pre-lollipop is because the touch guard shows up behind the Bottom Navigation View. No matter the order of views in the constraint layout, the Bottom Navigation View shows up on top of everything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, so it means that the Bottom Navigation View is able to use elevation, maybe by using app: namespace. If it is not possible to do better, yes, I think it is better to have the touch guard in all cases |
||
mFloatingActionsMenu.setOnFloatingActionsMenuUpdateListener(new FloatingActionsMenu.OnFloatingActionsMenuUpdateListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Fragment fragment = getSelectedFragment(); | ||
public void onMenuExpanded() { | ||
touchGuard.setAlpha(0.6f); | ||
|
||
if (!(fragment instanceof AbsHomeFragment) || !((AbsHomeFragment) fragment).onFabClick()) { | ||
onFloatingButtonClick(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
} | ||
touchGuard.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
mFloatingActionsMenu.collapse(); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onMenuCollapsed() { | ||
touchGuard.setAlpha(0); | ||
|
||
touchGuard.setOnClickListener(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will not remove the interception of click event, so the user will be stuck :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is still bugged. You have to call setClickable() AFTER setOnClickListener(). Look in setOnClickListener implementation |
||
} | ||
}); | ||
} | ||
|
||
if (null != mFabStartChat) { | ||
mFabStartChat.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
invitePeopleToNewRoom(); | ||
} | ||
}); | ||
} | ||
if (null != mFabCreateRoom) { | ||
mFabCreateRoom.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
mFloatingActionsMenu.collapse(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The two other cases does not call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added missing calls. |
||
createRoom(); | ||
} | ||
}); | ||
} | ||
if (null != mFabJoinRoom) { | ||
mFabJoinRoom.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
joinARoom(); | ||
} | ||
}); | ||
} | ||
|
@@ -1227,7 +1339,7 @@ private void onFloatingButtonClick() { | |
if (!isWaitingViewVisible()) { | ||
CharSequence items[] = new CharSequence[]{getString(R.string.room_recents_start_chat), getString(R.string.room_recents_create_room), getString(R.string.room_recents_join_room)}; | ||
mFabDialog = new AlertDialog.Builder(this) | ||
.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() { | ||
.setItems(items, new DialogInterface.OnClickListener() { | ||
@Override | ||
public void onClick(DialogInterface d, int n) { | ||
d.cancel(); | ||
|
@@ -1261,9 +1373,10 @@ public void hideFloatingActionButton(String fragmentTag) { | |
mFloatingActionButtonTimer.cancel(); | ||
} | ||
|
||
if (null != mFloatingActionButton) { | ||
mFloatingActionButton.hide(); | ||
|
||
if (null != mFloatingActionsMenu) { | ||
// mFloatingActionButton.hide(); | ||
mFloatingActionsMenu.setVisibility(View.GONE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question about FAB animation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implemented the animation. |
||
mFloatingActionsMenu.collapse(); | ||
try { | ||
mFloatingActionButtonTimer = new Timer(); | ||
mFloatingActionButtonTimer.schedule(new TimerTask() { | ||
|
@@ -1310,7 +1423,7 @@ public void run() { | |
* @return fab view | ||
*/ | ||
public FloatingActionButton getFloatingActionButton() { | ||
return mFloatingActionButton; | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This remove a feature: the FAB is automatically hidden during a few seconds when the user scroll the page. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I gracefully swapped it out for a View. Since only the 'Top' of the button is queried for. |
||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<solid android:color="?attr/multi_selection_background_color"/> | ||
<padding | ||
android:left="16dp" | ||
android:top="4dp" | ||
android:right="16dp" | ||
android:bottom="4dp"/> | ||
<corners | ||
android:radius="3dp"/> | ||
</shape> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you credit this library in the file
open_source_licenses.html
please? There is already a section for Apache 2.0 licenseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have credited the library as requested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks