danielzeller / depth-lib-android- Goto Github PK
View Code? Open in Web Editor NEWA library that gives depth to Views.
License: Other
A library that gives depth to Views.
License: Other
You are just copied from https://github.com/yongjhih/depth ,it's not a good way...
When have your library uses the application terminates with the coordinatorlayout, I said
the application opens everything works fine, but when I change activity and your library is not used, the application stops, I'll have you sent a good video because the explanation is complicated by writing, but I am under a CyanogenMod ROM and the screen is green, I'm not very good in develop-android, but I do fairly well.
I'm sorry for my English.
Hey Daniel,
thanks for this great library! I use it in one of my apps :-)
I've noticed some crashes when switching back to my app. It happens not often, but sometimes. I've noticed the same issue in the sample app.
I haven't found the issue by myself. Maybe you know what's wrong. Thanks!
Best regards,
Sascha
Here is the log I got from my users:
java.lang.IllegalStateException: Matrix can not be modified
at android.graphics.Matrix$1.oops(Matrix.java:40)
at android.graphics.Matrix$1.postTranslate(Matrix.java:154)
at com.saschaha.base.Libs.Depth.DepthLayout.b(Unknown Source)
at com.saschaha.base.Libs.Depth.c.onPreDraw(Unknown Source)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:879)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2129)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1234)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6465)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:573)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
I would cut of part of your lib responsible for noise effect, rewrite it to kotlin, add some features and finally host on my github on MIT license. I will post info in readme that code is based on your library. What do you think? Can I do something like that?
On resume after app is in the background, trying to switch to different fragments app crashes often
Exception java.lang.NullPointerException: Attempt to invoke interface method 'void com.company.sampleapp.MenuAnimation.animateTOMenu()' on a null object reference
Please provide a tutorial on how to use it.
I have never seen such a good open source.
Many Internet information was used for reference, but open source has not been applied.
If you see this issue, please let me know.
my email: [email protected]
Look forward to a long time
Hi,
Application crashes when screen orientation changes.
Regards,
Jay
Hello
I added a new JAVA file that I named "DepthFAB".
It works fine but I tried to put the "StateListAnimator" function on my main XML file but this function is completely ignored. (Although "OnClickListener" works)
My code:
<no.agens.depth.lib.DepthFAB
android:id="@+id/fab_container"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_alignParentRight="true"
android:layout_marginRight="16dp"
android:layout_marginTop="232dp"
android:background="@drawable/circle"
android:src="@drawable/ic_launcher"
android:elevation="9dp"
android:layerType="hardware"
android:stateListAnimator="@animator/raise"
app:custom_elevation="6dp"
app:edge_color="?android:attr/colorAccent"
app:is_circle="true">
</no.agens.depth.lib.DepthFAB>
package no.agens.depth.lib;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewOutlineProvider;
import android.widget.RelativeLayout;
import android.widget.Checkable;
import android.widget.ImageButton;
import no.agens.depth.lib.R;
public class DepthFAB extends ImageButton implements Checkable
{
public static final int DEFAULT_EDGE_COLOR = Color.WHITE;
public static final int DEFAULT_THICKNESS = 2;
private static final int[] CHECKED_STATE_SET = { android.R.attr.state_checked };
private boolean isChecked = false;
private int minOffset;
Paint edgePaint = new Paint();
@Override
public boolean hasOverlappingRendering()
{
return false;
}
public Paint getEdgePaint()
{
return edgePaint;
}
public void setEdgePaint(Paint edgePaint)
{
this.edgePaint = edgePaint;
}
private void initView(AttributeSet attrs)
{
edgePaint.setColor(DEFAULT_EDGE_COLOR);
edgePaint.setAntiAlias(true);
if (attrs != null)
{
TypedArray arr = getContext().obtainStyledAttributes(attrs, R.styleable.DepthView);
edgePaint.setColor(arr.getInt(R.styleable.DepthView_edge_color, DEFAULT_EDGE_COLOR));
setIsCircle(arr.getBoolean(R.styleable.DepthView_is_circle, false));
depth = arr.getDimension(R.styleable.DepthView_depth, DEFAULT_THICKNESS * getResources().getDisplayMetrics().density);
customShadowElevation = arr.getDimension(R.styleable.DepthView_custom_elevation, 0);
}
else
{
edgePaint.setColor(DEFAULT_EDGE_COLOR);
depth = DEFAULT_THICKNESS * getResources().getDisplayMetrics().density;
}
setOutlineProvider(new ViewOutlineProvider()
{
@Override
public void getOutline(View view, Outline outline)
{ }
});
}
public DepthFAB(Context context)
{
super(context);
initView(null);
}
public DepthFAB(Context context, AttributeSet attrs)
{
super(context, attrs);
initView(attrs);
}
public DepthFAB(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
initView(attrs);
}
private float depth;
public float getDepth()
{
return depth;
}
public void setDepth(float depth)
{
this.depth = depth;
((View)getParent()).invalidate();
}
public boolean isCircle()
{
return isCircle;
}
public void setIsCircle(boolean isCircle)
{
this.isCircle = isCircle;
}
private boolean isCircle = false;
float[] prevSrc = new float[8];
public boolean calculateBounds()
{
float[] src = new float[8];
float[] dst = new float[]{0, 0, getWidth(), 0, 0, getHeight(), getWidth(), getHeight()};
Matrix matrix = getMatrix();
matrix.mapPoints(src, dst);
topLeft.x = src[0] + getLeft();
topLeft.y = src[1] + getTop();
topRight.x = src[2] + getLeft();
topRight.y = src[3] + getTop();
bottomLeft.x = src[4] + getLeft();
bottomLeft.y = src[5] + getTop();
bottomRight.x = src[6] + getLeft();
bottomRight.y = src[7] + getTop();
boolean returnValue = hasMatrixChanged(src);
prevSrc = src;
float percentFrom90X = (getRotationX()) / 90f;
float percentFrom90Y = (-getRotationY()) / 90f;
matrix.postTranslate(percentFrom90Y * getDepth(), percentFrom90X * getDepth());
src = new float[8];
dst = new float[]{0, 0, getWidth(), 0, 0, getHeight(), getWidth(), getHeight()};
matrix.mapPoints(src, dst);
topLeftBack.x = src[0] + getLeft();
topLeftBack.y = src[1] + getTop();
topRightBack.x = src[2] + getLeft();
topRightBack.y = src[3] + getTop();
bottomLeftBack.x = src[4] + getLeft();
bottomLeftBack.y = src[5] + getTop();
bottomRightBack.x = src[6] + getLeft();
bottomRightBack.y = src[7] + getTop();
customShadow.calculateBounds(this);
return returnValue;
}
boolean hasMatrixChanged(float[] newSrc)
{
for (int i = 0; i < 8; i++)
{
if (newSrc[i] != prevSrc[i])
return true;
}
return false;
}
public PointF getTopLeft()
{
return topLeft;
}
public PointF getTopRight()
{
return topRight;
}
public PointF getBottomLeft()
{
return bottomLeft;
}
public PointF getBottomRight()
{
return bottomRight;
}
public PointF getTopLeftBack()
{
return topLeftBack;
}
public PointF getTopRightBack()
{
return topRightBack;
}
public PointF getBottomLeftBack()
{
return bottomLeftBack;
}
public PointF getBottomRightBack()
{
return bottomRightBack;
}
PointF topLeft = new PointF(0, 0);
PointF topRight = new PointF(0, 0);
PointF bottomLeft = new PointF(0, 0);
PointF bottomRight = new PointF(0, 0);
PointF topLeftBack = new PointF(0, 0);
PointF topRightBack = new PointF(0, 0);
PointF bottomLeftBack = new PointF(0, 0);
PointF bottomRightBack = new PointF(0, 0);
private CustomShadow customShadow = new CustomShadow();
public CustomShadow getCustomShadow()
{
return customShadow;
}
public void setCustomShadowElevation(float customShadowElevation)
{
this.customShadowElevation = customShadowElevation;
((View)getParent()).invalidate();
}
public float getCustomShadowElevation()
{
return customShadowElevation;
}
float customShadowElevation;
class CustomShadow
{
public static final float DEFAULT_SHADOW_PADDING = 10f;
PointF topLeftBack = new PointF(0, 0);
PointF topRightBack = new PointF(0, 0);
PointF bottomLeftBack = new PointF(0, 0);
PointF bottomRightBack = new PointF(0, 0);
int padding;
public boolean calculateBounds(DepthFAB target)
{
float[] src = new float[8];
float density = getResources().getDisplayMetrics().density;
float offsetY = customShadowElevation;
float offsetX = customShadowElevation / 5;
padding = (int) (customShadowElevation / 4f + DEFAULT_SHADOW_PADDING * density);
float[] dst = new float[]{-padding, -padding, target.getWidth() + padding, -padding, -padding, target.getHeight() + padding, target.getWidth() + padding, target.getHeight() + padding};
Matrix matrix = getMatrix();
matrix.mapPoints(src, dst);
topLeftBack.x = src[0] + target.getLeft() + offsetX;
topLeftBack.y = src[1] + target.getTop() + offsetY;
topRightBack.x = src[2] + target.getLeft() + offsetX;
topRightBack.y = src[3] + target.getTop() + offsetY;
bottomLeftBack.x = src[4] + target.getLeft() + offsetX;
bottomLeftBack.y = src[5] + target.getTop() + offsetY;
bottomRightBack.x = src[6] + target.getLeft() + offsetX;
bottomRightBack.y = src[7] + target.getTop() + offsetY;
return false;
}
Matrix matrix = new Matrix();
public void drawShadow(Canvas canvas, DepthFAB dl, Drawable shadow)
{
shadow.setBounds(-padding, -padding, dl.getWidth() + padding, dl.getHeight() + padding);
float[] src = new float[]{0, 0, dl.getWidth(), 0, dl.getWidth(), dl.getHeight(), 0, dl.getHeight()};
float[] dst = new float[]{topLeftBack.x, topLeftBack.y, topRightBack.x, topRightBack.y, bottomRightBack.x, bottomRightBack.y, bottomLeftBack.x, bottomLeftBack.y};
int count = canvas.save();
matrix.setPolyToPoly(src, 0, dst, 0, src.length >> 1);
canvas.concat(matrix);
shadow.draw(canvas);
canvas.restoreToCount(count);
}
}
public void setOffset(int offset)
{
if (offset != getTranslationY())
{
offset = Math.max(minOffset, offset);
setTranslationY(offset);
}
}
public void setMinOffset(int minOffset)
{
this.minOffset = minOffset;
}
public boolean isChecked()
{
return isChecked;
}
public void setChecked(boolean isChecked)
{
if (this.isChecked != isChecked)
{
this.isChecked = isChecked;
refreshDrawableState();
}
}
public void toggle()
{
setChecked(!isChecked);
}
@Override
public int[] onCreateDrawableState(int extraSpace)
{
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
if (isChecked())
{
mergeDrawableStates(drawableState, CHECKED_STATE_SET);
}
return drawableState;
}
}
This remains in the realm of possible ?
Can you help me please ?
This is so fascinating! I am just amazed how is the entire canvas/Windows is shown in 3D layers? What code is responsible for it?
The demo looks great, but how do I start to use this library?
Can you please put some tutorial? Snippets? Explanation?
Very nice library.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.