Shadow works not well
codingCavalier opened this issue · comments
Hi, Zielony, I am luckly to use the Carbon project, but I missing the problem that the shadow was works not very well, below is my ui, that page is maked by copy your sample app's activity_shadow.xml file and I delete the last line to avoid some issues (it's not important).
Looking forward to your help~
Thank you very much~
Which version of Android and Carbon are you using? Carbon 0.16 draws shadows using Material Component's Drawable, so it should work just like all shadows provided by Google.
My phone is Pixel 2 XL and the version is Android P, Carbon is 0.15.3
So, this may be a couple of things:
-
On Android P Carbon reuses native colored shadows, so these should look the best. If you're getting inconsistent results on Android P, then there may be a bug in Carbon.
-
The sample app on DropBox is pretty old. I'm not sure, which version is that. I would compile and run the code from master to be sure.
-
Since 0.16 Carbon uses compat shadows implemented by Google. These should work faster and more consistent that the previous. Also, the setup is lighter and easier. Personally I think that Google's implementation is not as pleasing, but it's much easier for me to rely on their code, than to build that from scratch.
I'll check the most recent master code on Pixel tomorrow.
Thanks very much, the sample I used is compiled from the Carbon's Github project by my self. So I look forward to your good news, you can test it by create a new project and adding dependencies of Carbon lib, best don't just testing it in your sample project that writed in Carbon project, I don't know if I said was meaningful. ^-^
Well, it seems like gray shadows on P are a bug in the emulator image or something, so I'm not going to spend more time on that. I checked a couple of different configurations and everything seems to be working.
Could you please prepare a simple application showing your issue and share it with me? That would be very useful. I would like to check your exact code.
This project is already compiled. To be able to play with it I need sources and build.gradle
.
Decompile apk and below is gradle config:
Module's gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.example.shadowdemo"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dataBinding {
enabled = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
api 'tk.zielony:carbon:0.16.0.1'
}
Project's gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.41'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Decompiling your apk is missing the point. Your apk contains tons of needless stuff obfuscating the meaningful part of the app. I don't want to guess, what is the issue, but to debug it. Android has so many quirks and bugs that the reason can be pretty much anything.
For example, your AppTheme seems to be not extending any base theme, but that wouldn't work, so I guess that this part was removed.
Another example would be your code being written in Kotlin. I don't know about any Kotlin decompiler, so all I can get is Java or Smali, which I am not interested in.
I tried to build an app using your description and your build.gradle
, but it's working fine for me. I also run your app-debug.apk
on the same device and the shadows are really small, but I don't know why and I have no way to debug it.
For the moment, it's my failure that I removed the Theme that in style.xml, so when I added it back, Carbon works well, but below exception occured :
java.lang.IllegalArgumentException: radius must be > 0
at android.graphics.RadialGradient.<init>(RadialGradient.java:59)
at carbon.shadow.ShadowRenderer.drawCornerShadow(ShadowRenderer.java:158)
at carbon.shadow.ShapePath$ArcShadowOperation.draw(ShapePath.java:289)
at carbon.shadow.ShapePath$1.draw(ShapePath.java:179)
at carbon.shadow.ShapePath$ShadowCompatOperation.draw(ShapePath.java:229)
at carbon.shadow.MaterialShapeDrawable.drawCompatShadow(MaterialShapeDrawable.java:383)
at carbon.shadow.MaterialShapeDrawable.draw(MaterialShapeDrawable.java:344)
at carbon.widget.ImageView.drawShadow(ImageView.java:619)
at carbon.widget.ConstraintLayout.drawChild(ConstraintLayout.java:313)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:2023)
at carbon.widget.ConstraintLayout.dispatchDrawInternal(ConstraintLayout.java:290)
at carbon.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:282)
at android.view.View.draw(View.java:17308)
at carbon.widget.ConstraintLayout.drawInternal(ConstraintLayout.java:420)
at carbon.widget.ConstraintLayout.draw(ConstraintLayout.java:482)
at android.view.View.updateDisplayListIfDirty(View.java:16282)
at android.view.View.draw(View.java:17066)
at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
at android.view.View.updateDisplayListIfDirty(View.java:16277)
at android.view.View.draw(View.java:17066)
at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
at android.view.View.updateDisplayListIfDirty(View.java:16277)
at android.view.View.draw(View.java:17066)
at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
at android.view.View.draw(View.java:17308)
at com.android.internal.policy.DecorView.draw(DecorView.java:786)
at android.view.View.updateDisplayListIfDirty(View.java:16282)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:661)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:667)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:775)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2829)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2637)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2239)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1270)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6464)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:888)
at android.view.Choreographer.doCallbacks(Choreographer.java:700)
at android.view.Choreographer.doFrame(Choreographer.java:635)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:874)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6405)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1003)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:893)
Is there has any problem?
PathArcOperation pathArcOperation = new PathArcOperation(endX, endY, endX, endY);
pathArcOperation.startAngle = currentShadowAngle;
pathArcOperation.sweepAngle = shadowSweep;
shadowCompatOperations.add(new ArcShadowOperation(pathArcOperation));
currentShadowAngle = nextShadowAngle;