Skip to content

Commit

Permalink
Merge pull request #226 from noties/v4.3.1
Browse files Browse the repository at this point in the history
V4.3.1
  • Loading branch information
noties authored Apr 1, 2020
2 parents 8e3d898 + 0f96866 commit a26c13c
Show file tree
Hide file tree
Showing 30 changed files with 1,032 additions and 157 deletions.
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

# 4.3.1
* Fix DexGuard optimization issue ([#216])<br>Thanks [@francescocervone]
* module `images`: `GifSupport` and `SvgSupport` use `Class.forName` instead access to full qualified class name
* `ext-table`: fix links in tables ([#224])
* `ext-table`: proper borders (equal for all sides)
* module `core`: Add `PrecomputedFutureTextSetterCompat`<br>Thanks [@KirkBushman]

[#216]: https://github.com/noties/Markwon/pull/216
[#224]: https://github.com/noties/Markwon/issues/224
[@francescocervone]: https://github.com/francescocervone
[@KirkBushman]: https://github.com/KirkBushman


# 4.3.0
* add `MarkwonInlineParserPlugin` in `inline-parser` module
* `JLatexMathPlugin` now supports inline LaTeX structures via `MarkwonInlineParserPlugin`
Expand All @@ -12,8 +25,7 @@ dependency (must be explicitly added to `Markwon` whilst configuring)
* `LinkResolverDef` defaults to `https` when a link does not have scheme information ([#75])
* add `option` abstraction for `sample` module allowing switching of multiple cases in runtime via menu
* non-empty bounds for `AsyncDrawable` when no dimensions are not yet available ([#189])
* `linkify` - option to use `LinkifyCompat` in `LinkifyPlugin` ([#201])
<br>Thanks to [@drakeet]
* `linkify` - option to use `LinkifyCompat` in `LinkifyPlugin` ([#201])<br>Thanks to [@drakeet]
* `MarkwonVisitor.BlockHandler` and `BlockHandlerDef` implementation to control how blocks insert new lines after them


Expand Down
59 changes: 59 additions & 0 deletions app/src/debug/java/io/noties/markwon/debug/ColorBlendView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.noties.markwon.debug;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

import io.noties.markwon.app.R;
import io.noties.markwon.utils.ColorUtils;

public class ColorBlendView extends View {

private final Rect rect = new Rect();
private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

private int background;
private int foreground;

public ColorBlendView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);

if (attrs != null) {
final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ColorBlendView);
try {
background = array.getColor(R.styleable.ColorBlendView_cbv_background, 0);
foreground = array.getColor(R.styleable.ColorBlendView_cbv_foreground, 0);
} finally {
array.recycle();
}
}

paint.setStyle(Paint.Style.FILL);

setWillNotDraw(false);
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);

final int side = getWidth() / 11;

rect.set(0, 0, side, getHeight());

canvas.translate(getPaddingLeft(), 0F);

for (int i = 0; i < 11; i++) {
final float alpha = i / 10F;
paint.setColor(ColorUtils.blend(foreground, background, alpha));
canvas.drawRect(rect, paint);
canvas.translate(side, 0F);
}
}
}
34 changes: 34 additions & 0 deletions app/src/debug/res/layout/debug_color_blend.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f00">

<io.noties.markwon.debug.ColorBlendView
android:layout_width="match_parent"
android:layout_height="64dip"
app:cbv_background="#fff"
app:cbv_foreground="#f0f"/>

<io.noties.markwon.debug.ColorBlendView
android:layout_width="match_parent"
android:layout_height="64dip"
app:cbv_background="#000"
app:cbv_foreground="#f0f"/>

<io.noties.markwon.debug.ColorBlendView
android:layout_width="match_parent"
android:layout_height="64dip"
app:cbv_background="#fff"
app:cbv_foreground="#00f"/>

<io.noties.markwon.debug.ColorBlendView
android:layout_width="match_parent"
android:layout_height="64dip"
app:cbv_background="#000"
app:cbv_foreground="#00f"/>


</LinearLayout>
5 changes: 5 additions & 0 deletions app/src/debug/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@
<attr name="fcdv_checked" format="boolean" />
</declare-styleable>

<declare-styleable name="ColorBlendView">
<attr name="cbv_foreground" format="color" />
<attr name="cbv_background" format="color" />
</declare-styleable>

</resources>
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ ext {
'x-annotations' : 'androidx.annotation:annotation:1.1.0',
'x-recycler-view' : 'androidx.recyclerview:recyclerview:1.0.0',
'x-core' : 'androidx.core:core:1.0.2',
'x-appcompat' : 'androidx.appcompat:appcompat:1.1.0',
'commonmark' : "com.atlassian.commonmark:commonmark:$commonMarkVersion",
'commonmark-strikethrough': "com.atlassian.commonmark:commonmark-ext-gfm-strikethrough:$commonMarkVersion",
'commonmark-table' : "com.atlassian.commonmark:commonmark-ext-gfm-tables:$commonMarkVersion",
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android.enableJetifier=true
android.enableBuildCache=true
android.buildCacheDir=build/pre-dex-cache

VERSION_NAME=4.3.0
VERSION_NAME=4.3.1

GROUP=io.noties.markwon
POM_DESCRIPTION=Markwon markdown for Android
Expand Down
1 change: 1 addition & 0 deletions markwon-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
// @since 4.1.0 to allow PrecomputedTextSetterCompat
// note that this dependency must be added on a client side explicitly
compileOnly it['x-core']
compileOnly it['x-appcompat']
}

deps['test'].with {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package io.noties.markwon;

import android.text.Spanned;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.core.text.PrecomputedTextCompat;

import java.util.concurrent.Executor;
import java.util.concurrent.Future;

/**
* Please note this class requires `androidx.core:core` artifact being explicitly added to your dependencies.
* This is intended to be used in a RecyclerView.
*
* @see io.noties.markwon.Markwon.TextSetter
* @since 4.3.1
*/
public class PrecomputedFutureTextSetterCompat implements Markwon.TextSetter {

/**
* @param executor for background execution of text pre-computation,
* if not provided the standard, single threaded one will be used.
*/
@NonNull
public static PrecomputedFutureTextSetterCompat create(@Nullable Executor executor) {
return new PrecomputedFutureTextSetterCompat(executor);
}

@NonNull
public static PrecomputedFutureTextSetterCompat create() {
return new PrecomputedFutureTextSetterCompat(null);
}

@Nullable
private final Executor executor;

@SuppressWarnings("WeakerAccess")
PrecomputedFutureTextSetterCompat(@Nullable Executor executor) {
this.executor = executor;
}

@Override
public void setText(
@NonNull TextView textView,
@NonNull Spanned markdown,
@NonNull TextView.BufferType bufferType,
@NonNull Runnable onComplete) {
if (textView instanceof AppCompatTextView) {
final AppCompatTextView appCompatTextView = (AppCompatTextView) textView;
final Future<PrecomputedTextCompat> future = PrecomputedTextCompat.getTextFuture(
markdown,
appCompatTextView.getTextMetricsParamsCompat(),
executor);
appCompatTextView.setTextFuture(future);
// `setTextFuture` is actually a synchronous call, so we should call onComplete now
onComplete.run();
} else {
throw new IllegalStateException("TextView provided is not an instance of AppCompatTextView, " +
"cannot call setTextFuture(), textView: " + textView);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
package io.noties.markwon.utils;

import android.graphics.Color;

import androidx.annotation.ColorInt;
import androidx.annotation.FloatRange;
import androidx.annotation.IntRange;

public abstract class ColorUtils {

public static int applyAlpha(int color, int alpha) {
@ColorInt
public static int applyAlpha(
@ColorInt int color,
@IntRange(from = 0, to = 255) int alpha) {
return (color & 0x00FFFFFF) | (alpha << 24);
}

// blend two colors w/ specified ratio, resulting color won't have alpha channel
@ColorInt
public static int blend(
@ColorInt int foreground,
@ColorInt int background,
@FloatRange(from = 0.0F, to = 1.0F) float ratio) {
return Color.rgb(
(int) (((1F - ratio) * Color.red(foreground)) + (ratio * Color.red(background))),
(int) (((1F - ratio) * Color.green(foreground)) + (ratio * Color.green(background))),
(int) (((1F - ratio) * Color.blue(foreground)) + (ratio * Color.blue(background)))
);
}

private ColorUtils() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,13 @@ public void visit(@NonNull MarkwonVisitor visitor, @NonNull TableBlock tableBloc

visitor.blockStart(tableBlock);

final int length = visitor.length();

visitor.visitChildren(tableBlock);

// if (visitor.hasNext(tableBlock)) {
// visitor.ensureNewLine();
// visitor.forceNewLine();
// }
// @since 4.3.1 apply table span for the full table
visitor.setSpans(length, new TableSpan());

visitor.blockEnd(tableBlock);
}
})
Expand Down
Loading

0 comments on commit a26c13c

Please sign in to comment.