Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I have updated AlphaArray which is used to create path that mimics shadow #97

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .idea/caches/build_file_checksums.ser
Binary file not shown.
Binary file added .idea/caches/gradle_models.ser
Binary file not shown.
3 changes: 3 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Sample/src/main/res/layout/activity_badge.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
app:centre_part_linear="false"
app:space_background_color="@color/space_white"
app:layout_behavior="com.luseen.spacenavigation.SpaceNavigationViewBehavior" />
</RelativeLayout>
</LinearLayout>
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.novoda:bintray-release:0.8.0'
}
}

allprojects {
repositories {
jcenter()
google()
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Mar 14 18:44:51 IST 2018
#Wed Feb 20 14:48:23 KST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.luseen.spacenavigation;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.v4.content.ContextCompat;
import android.widget.RelativeLayout;

@SuppressLint("ViewConstructor")
public class NavigationViewShadow extends RelativeLayout {
private final int spaceNavigationShadowHeight = (int) Math.ceil(getResources().getDimension(R.dimen.space_navigation_shadow_width));

private Paint paint;

private int bezierWidth, bezierHeight, navigationWidth;

private Context context;

private boolean isLinear=false;

int [] alphaArray = new int[]{11, 9, 7, 6, 5, 4, 3, 2, 1, 0};

NavigationViewShadow(Context context) {
super(context);
this.context = context;
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStrokeWidth(2);
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.STROKE);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setBackgroundColor(ContextCompat.getColor(context, R.color.space_transparent));
}

@Override
protected void onDraw(Canvas canvas) {
// translate canvas by shadow width. Otherwise canvas clips top part bezier curve
canvas.translate(0, spaceNavigationShadowHeight);

// Should draw paths "spaceNavigationShadowHeight" times
for (int i = 0; i<spaceNavigationShadowHeight; i++){
/**
* Draw shadow
*/
// If path count exceeds alpha array size then assign alpha level of zero to the rest of paths
if (i >= alphaArray.length){
canvas.drawPath(drawPathWithOffset(0, i), paint);
}else {
canvas.drawPath(drawPathWithOffset(alphaArray[i], i), paint);
}

}
}

private Path drawPathWithOffset(int alpha, int offset){

int offsettedBeizerHeight = bezierHeight - offset;

Path path = new Path();
/**
* Reset path before drawing
*/
path.reset();

/**
* Set paint color to draw the path with
*/
paint.setColor(Color.BLACK);


/**
* Set alpha to change opacity of path
*/
paint.setAlpha(alpha);

/**
* Start point for drawing
*/
path.moveTo(0, offsettedBeizerHeight);

/**
* Draw line over left main-content
*/
path.lineTo((navigationWidth-bezierWidth)/2, offsettedBeizerHeight);

if(!isLinear){
/**
* Seth half path of bezier view
*/
path.cubicTo(bezierWidth / 4+(navigationWidth-bezierWidth)/2, offsettedBeizerHeight, bezierWidth / 4+(navigationWidth-bezierWidth)/2, -offset, bezierWidth / 2+(navigationWidth-bezierWidth)/2, -offset);
/**
* Seth second part of bezier view
*/
path.cubicTo((bezierWidth / 4) * 3 +(navigationWidth-bezierWidth)/2, -offset, (bezierWidth / 4) * 3 +(navigationWidth-bezierWidth)/2, offsettedBeizerHeight, bezierWidth+(navigationWidth-bezierWidth)/2, offsettedBeizerHeight);
}

/**
* Draw line over right main-content
*/
path.lineTo(navigationWidth, offsettedBeizerHeight);

return path;
}

/**
* Build bezier view with given width and height
*
* @param bezierWidth Given width
* @param bezierHeight Given height
* @param isLinear True, if curves are not needed
*/
void build(int navigationWidth, int bezierWidth, int bezierHeight,boolean isLinear) {
this.navigationWidth = navigationWidth;
this.bezierWidth = bezierWidth;
this.bezierHeight = bezierHeight;
this.isLinear=isLinear;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ public class SpaceNavigationView extends RelativeLayout {

private static final int MIN_SPACE_ITEM_SIZE = 2;
private final int spaceNavigationHeight = (int) getResources().getDimension(com.luseen.spacenavigation.R.dimen.space_navigation_height);
private final int spaceNavigationShadowHeight = (int) Math.ceil(getResources().getDimension(R.dimen.space_navigation_shadow_width));
private final int mainContentHeight = (int) getResources().getDimension(com.luseen.spacenavigation.R.dimen.main_content_height);
private final int centreContentWight = (int) getResources().getDimension(com.luseen.spacenavigation.R.dimen.centre_content_width);
private final int itemContentWight = (int) getResources().getDimension(com.luseen.spacenavigation.R.dimen.item_content_width);
private final int centreButtonSize = (int) getResources().getDimension(com.luseen.spacenavigation.R.dimen.space_centre_button_default_size);
private int spaceNavigationWidth;
private List<SpaceItem> spaceItems = new ArrayList<>();
private List<View> spaceItemList = new ArrayList<>();
private List<RelativeLayout> badgeList = new ArrayList<>();
Expand All @@ -85,6 +87,7 @@ public class SpaceNavigationView extends RelativeLayout {
private RelativeLayout centreBackgroundView;
private LinearLayout leftContent, rightContent;
private BezierView centreContent;
private NavigationViewShadow navigationViewBorderLine;
private Typeface customFont;
private Context context;
private int spaceItemIconSize = NOT_DEFINED;
Expand Down Expand Up @@ -221,7 +224,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
*/
ViewGroup.LayoutParams params = getLayoutParams();
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
params.height = spaceNavigationHeight;
// width increase by shadow width to allow shadow be visible, otherwise shadow will be clipped
params.height = spaceNavigationHeight+spaceNavigationShadowHeight;
setBackgroundColor(ContextCompat.getColor(context, R.color.space_transparent));
setLayoutParams(params);
}
Expand All @@ -230,6 +234,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
super.onSizeChanged(width, height, oldWidth, oldHeight);

spaceNavigationWidth = width;

/**
* Restore current item index from savedInstance
*/
Expand Down Expand Up @@ -289,6 +295,7 @@ private void initAndAddViewsToMainView() {
rightContent = new LinearLayout(context);

centreContent = buildBezierView();
navigationViewBorderLine = buildBezierBorderline();

centreButton = new CentreButton(context);

Expand Down Expand Up @@ -343,6 +350,13 @@ public boolean onLongClick(View v) {
centreContentParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
centreContentParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

/**
* Borderline params
*/
LayoutParams borderLineParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, spaceNavigationHeight);
borderLineParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
borderLineParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);

/**
* Centre Background View content size and position
*/
Expand Down Expand Up @@ -371,6 +385,11 @@ public boolean onLongClick(View v) {
*/
setBackgroundColors();

/**
* Adding shadow first, so it appears under all views
*/
addView(navigationViewBorderLine, borderLineParams);

/**
* Adding view to centreContent
*/
Expand Down Expand Up @@ -438,7 +457,7 @@ private void addSpaceItems(LinearLayout leftContent, LinearLayout rightContent)
targetWidth = contentWidth;
}

RelativeLayout.LayoutParams textAndIconContainerParams = new RelativeLayout.LayoutParams(
LayoutParams textAndIconContainerParams = new LayoutParams(
targetWidth, mainContentHeight);
RelativeLayout textAndIconContainer = (RelativeLayout) inflater.inflate(R.layout.space_item_view, this, false);
textAndIconContainer.setLayoutParams(textAndIconContainerParams);
Expand Down Expand Up @@ -716,6 +735,17 @@ private BezierView buildBezierView() {
return bezierView;
}

/**
* Creating borderline with params
*
* @return created borderline view
*/
private NavigationViewShadow buildBezierBorderline() {
NavigationViewShadow borderline = new NavigationViewShadow(context);
borderline.build(spaceNavigationWidth, centreContentWight, spaceNavigationHeight - mainContentHeight,isCentrePartLinear);
return borderline;
}

/**
* Throw Array Index Out Of Bounds Exception
*
Expand Down
1 change: 1 addition & 0 deletions spacelib/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<dimen name="space_item_text_default_size">14sp</dimen>
<dimen name="badge_left_margin">5dp</dimen>
<dimen name="view_bottom_margin">50dp</dimen>
<dimen name="space_navigation_shadow_width">4dp</dimen>
</resources>