forked from ekibun/Bangumi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
44 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
app/src/main/java/soko/ekibun/bangumi/util/span/BaseLineImageSpan.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package soko.ekibun.bangumi.util.span | ||
|
||
import android.graphics.Paint | ||
import android.text.style.ImageSpan | ||
|
||
class BaseLineImageSpan(drawable: UrlDrawable, private val source: String? = null) : | ||
ImageSpan(drawable, ALIGN_BASELINE) { | ||
override fun getSource(): String? = source | ||
override fun getDrawable(): UrlDrawable = super.getDrawable() as UrlDrawable | ||
override fun getSize(paint: Paint, text: CharSequence?, start: Int, end: Int, fm: Paint.FontMetricsInt?): Int { | ||
val ascent = fm?.ascent | ||
val top = fm?.top | ||
val descent = fm?.descent | ||
val bottom = fm?.bottom | ||
val width = super.getSize(paint, text, start, end, fm) | ||
fm?.descent = descent | ||
fm?.bottom = bottom | ||
fm?.top = Math.min(fm?.top ?: 0, top ?: 0) | ||
fm?.ascent = Math.min(fm?.ascent ?: 0, ascent ?: 0) | ||
return width | ||
} | ||
} |
11 changes: 4 additions & 7 deletions
11
app/src/main/java/soko/ekibun/bangumi/util/span/ClickableImageSpan.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,21 @@ | ||
package soko.ekibun.bangumi.util.span | ||
|
||
import android.text.style.ClickableSpan | ||
import android.text.style.ImageSpan | ||
import android.util.Log | ||
import android.view.View | ||
|
||
/** | ||
* | ||
*/ | ||
class ClickableImageSpan( | ||
var image: ImageSpan, | ||
private val onClick: (View, ImageSpan) -> Unit | ||
var image: BaseLineImageSpan, | ||
private val onClick: (View, BaseLineImageSpan) -> Unit | ||
) : ClickableSpan() { | ||
override fun onClick(widget: View) { | ||
Log.v("click", image.drawable.toString()) | ||
val drawable = image.drawable | ||
if (drawable is UrlDrawable) { | ||
if (drawable.error == true) drawable.loadImage() | ||
else if (drawable.error == false) onClick(widget, image) | ||
} else onClick(widget, image) | ||
if (drawable.error == true) drawable.loadImage() | ||
else if (drawable.error == false) onClick(widget, image) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters