Skip to content

Commit

Permalink
ToolBar UI Update #1
Browse files Browse the repository at this point in the history
*Update UI to allow RecyclerView to scroll underneath search box.
  • Loading branch information
rayliverified committed Mar 12, 2018
1 parent 84ade48 commit e5fafd4
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 80 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<meta-data
android:name="CustomAds"
android:value="http://apprewards.org/crosspromotion/"/>
android:value="https://apprewards.org/crosspromotion/"/>

<activity
android:name=".MainActivity"
Expand Down
47 changes: 35 additions & 12 deletions app/src/main/java/stream/rocketnotes/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package stream.rocketnotes;

import android.*;
import android.Manifest;
import android.app.Dialog;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
Expand All @@ -8,6 +10,7 @@
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.speech.RecognizerIntent;
Expand All @@ -19,6 +22,7 @@
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.Log;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.widget.ImageView;
Expand Down Expand Up @@ -48,13 +52,17 @@
import eu.davidea.flexibleadapter.items.IFlexible;
import io.github.yavski.fabspeeddial.FabSpeedDial;
import io.github.yavski.fabspeeddial.SimpleMenuListenerAdapter;
import stream.crosspromotion.Utils;
import stream.custompermissionsdialogue.PermissionsDialogue;
import stream.custompermissionsdialogue.utils.PermissionUtils;
import stream.rocketnotes.filter.FilterMaterialSearchView;
import stream.rocketnotes.filter.model.Filter;
import stream.rocketnotes.ui.HideViewOnScrollListener;
import stream.rocketnotes.ui.MoveViewOnScrollListener;
import stream.rocketnotes.utils.AnalyticsUtils;
import stream.rocketnotes.utils.Units;

public class MainActivity extends AppCompatActivity implements AppBarLayout.OnOffsetChangedListener {
public class MainActivity extends AppCompatActivity {

private Integer mNoteCount;
private Integer mImageCount;
Expand Down Expand Up @@ -82,7 +90,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);

mContext = getApplicationContext();
if (!PermissionUtils.IsPermissionEnabled(mContext, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
if (!PermissionUtils.IsPermissionEnabled(mContext, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
PermissionsDialogue.Builder alertPermissions = new PermissionsDialogue.Builder(MainActivity.this)
.setCancelable(false)
.setMessage(getString(R.string.app_name) + " requires the following permissions to save notes: ")
Expand Down Expand Up @@ -111,14 +119,11 @@ public void OnClick(View view, Dialog dialog) {
// editor.apply();
// }

mAppBar = findViewById(R.id.app_bar);
mAppBar.addOnOffsetChangedListener(this);

InitializeRecyclerView();

// checkVoiceRecognition();
mAppBar = findViewById(R.id.app_bar);
mFilterView = findViewById(R.id.sv);
SetupSearchBar();
InitializeRecyclerView();
SetupFAB();
if (getIntent().getAction() != null && getIntent().getAction() != Intent.ACTION_MAIN) {
Log.d("MainActivity", getIntent().getAction());
Expand Down Expand Up @@ -186,6 +191,29 @@ public void onFastScrollerStateChange(boolean scrolling) {
});
mAdapter.setFastScroller(fastScroller);
}

// mRecyclerView.setY(Units.dpToPx(mContext, 56));
// mRecyclerView.setOnTouchListener(new View.OnTouchListener() {
// @Override
// public boolean onTouch(View view, MotionEvent motionEvent) {
// switch (motionEvent.getAction()) {
// case MotionEvent.ACTION_DOWN:
// break;
// case MotionEvent.ACTION_UP:
// break;
// case MotionEvent.ACTION_POINTER_DOWN:
// break;
// case MotionEvent.ACTION_POINTER_UP:
// break;
// case MotionEvent.ACTION_MOVE:
// mRecyclerView.get()
// break;
// }
// ret
// urn false;
// }
// });
// mRecyclerView.addOnScrollListener(new MoveViewOnScrollListener(mRecyclerView));
}

private void SetupSearchBar() {
Expand Down Expand Up @@ -594,11 +622,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}

@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
mSearchView.setTranslationY(verticalOffset);
}

protected StaggeredGridLayoutManager createNewStaggeredGridLayoutManager() {
return new SmoothScrollStaggeredLayoutManager(this, 2);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package stream.rocketnotes.ui;

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;

public class HideViewOnScrollListener extends RecyclerView.OnScrollListener {

private float alpha = 1.f;
private float scrolly = 0.f;

private int heightViewToHide;
private final View viewToHide;

public HideViewOnScrollListener(final View viewToHide) {
this.viewToHide = viewToHide;

heightViewToHide = viewToHide.getHeight();
if (heightViewToHide == 0) {

ViewTreeObserver viewTreeObserver = viewToHide.getViewTreeObserver();
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {

heightViewToHide = viewToHide.getHeight();

if (heightViewToHide > 0)
viewToHide.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}

}

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);

scrolly += dy;

Log.d("ScrollY", String.valueOf(scrolly));
Log.d("Scroll", String.valueOf(dy));

alpha = (heightViewToHide - scrolly) / heightViewToHide;

if (alpha < 0.f) alpha = 0.f;
if (alpha > 1.0f) alpha = 1.f;

if (dy < 0 && scrolly > heightViewToHide) {
alpha = 0.f;
}

viewToHide.setAlpha(alpha);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package stream.rocketnotes.ui;

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

public class MoveViewOnScrollListener extends RecyclerView.OnScrollListener {

private float alpha = 1f;
private float scrollY = 0f;
private float scrollThreshold;

private int heightViewToHide;
private final View mView;

public MoveViewOnScrollListener(final View view) {
this.mView = view;

scrollThreshold = view.getY();
Log.d("Threshhold", String.valueOf(scrollThreshold));
}

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);

scrollY += dy;

if (scrollY < scrollThreshold)
{
mView.setTranslationY(dy);
}
}
}
22 changes: 12 additions & 10 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,14 @@
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Light">
android:theme="@style/TransparentActionBar"
app:elevation="0dp">

<View
android:layout_width="match_parent"
android:layout_height="62dp"
android:background="@color/colorPrimary"
android:background="@color/transparent"
app:layout_scrollFlags="scroll|enterAlways"/>

<stream.rocketnotes.filter.FilterMaterialSearchView
android:id="@+id/sv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:msvIsContainEnabled="false"
android:elevation="4dp"/>
</android.support.design.widget.AppBarLayout>

<android.support.v7.widget.RecyclerView
Expand Down Expand Up @@ -71,4 +64,13 @@
app:floatingSearch_menu="@menu/menu_search_view"
app:floatingSearch_close_search_on_keyboard_dismiss="true"
app:floatingSearch_dimBackground="false"/>

<stream.rocketnotes.filter.FilterMaterialSearchView
android:id="@+id/sv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="62dp"
android:visibility="gone"
app:msvIsContainEnabled="false"
android:elevation="4dp"/>
</RelativeLayout>
52 changes: 24 additions & 28 deletions app/src/main/res/layout/msv_filter.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:id="@+id/search_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<android.support.v7.widget.RecyclerView
android:id="@+id/rv_filter"
android:layout_width="match_parent"
android:layout_height="@dimen/msv_filter_rv_height"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:paddingBottom="6dp"
android:background="@color/colorPrimary"/>

<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_gravity="bottom"
android:background="#FFFFFF"
android:backgroundTint="#10000000"/>
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/search_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false">

<android.support.v7.widget.RecyclerView
android:id="@+id/rv_filter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:paddingBottom="6dp"
android:background="@color/transparent"
android:clipChildren="false"/>

<!--<View-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="1dip"-->
<!--android:layout_gravity="bottom"-->
<!--android:background="#FFFFFF"-->
<!--android:backgroundTint="#10000000"/>-->
</FrameLayout>
59 changes: 30 additions & 29 deletions app/src/main/res/layout/msv_filter_civ.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_margin="@dimen/msv_filter_margin"
android:layout_width="wrap_content"
android:layout_height="@dimen/msv_filter_height"
android:background="@drawable/msv_filter_background"
android:gravity="center">

<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/civ_icon"
android:layout_width="@dimen/msv_filter_height"
android:layout_height="@dimen/msv_filter_height"/>

<TextView
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/msv_horizontal_margin"
tools:text="Prova"
android:theme="@style/MSV_FilterTextName"/>

<ImageView
android:id="@android:id/closeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/msv_filter_close_button_horizontal_margin"
android:layout_marginLeft="@dimen/msv_filter_close_button_horizontal_margin"
android:src="@drawable/ic_close_circle_grey600_24dp"/>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="@dimen/msv_filter_height"
android:layout_margin="@dimen/msv_filter_margin"
android:background="@drawable/msv_filter_background"
android:gravity="center"
android:elevation="4dp">

<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/civ_icon"
android:layout_width="@dimen/msv_filter_height"
android:layout_height="@dimen/msv_filter_height"/>

<TextView
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/msv_horizontal_margin"
tools:text="Prova"
android:theme="@style/MSV_FilterTextName"/>

<ImageView
android:id="@android:id/closeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/msv_filter_close_button_horizontal_margin"
android:layout_marginLeft="@dimen/msv_filter_close_button_horizontal_margin"
android:src="@drawable/ic_close_circle_grey600_24dp"/>
</LinearLayout>
5 changes: 5 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
<item name="colorControlNormal">@color/white</item>
</style>

<style name="TransparentActionBar" parent="AppTheme">
<item name="colorPrimary">@color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
</style>

<style name="AdTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
Expand Down

0 comments on commit e5fafd4

Please sign in to comment.