-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement code and pre blocks support on Android
- Loading branch information
Showing
13 changed files
with
492 additions
and
107 deletions.
There are no files selected for viewing
11 changes: 0 additions & 11 deletions
11
android/src/main/java/com/expensify/livemarkdown/MarkdownBackgroundColorSpan.java
This file was deleted.
Oops, something went wrong.
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
13 changes: 13 additions & 0 deletions
13
android/src/main/java/com/expensify/livemarkdown/MarkdownCodeSpan.java
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,13 @@ | ||
package com.expensify.livemarkdown; | ||
|
||
import android.content.res.AssetManager; | ||
|
||
import androidx.annotation.ColorInt; | ||
import androidx.annotation.NonNull; | ||
|
||
public class MarkdownCodeSpan extends MarkdownBlockSpan { | ||
public MarkdownCodeSpan(@NonNull AssetManager assetManager, @NonNull String fontFamily, float fontSize, @ColorInt int color) { | ||
super(assetManager, fontFamily, fontSize, color); | ||
} | ||
} | ||
|
11 changes: 0 additions & 11 deletions
11
android/src/main/java/com/expensify/livemarkdown/MarkdownFontSizeSpan.java
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
android/src/main/java/com/expensify/livemarkdown/MarkdownH1Span.java
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,47 @@ | ||
package com.expensify.livemarkdown; | ||
|
||
import android.graphics.Paint; | ||
import android.graphics.Typeface; | ||
import android.text.TextPaint; | ||
import android.text.style.LineHeightSpan; | ||
import android.text.style.StyleSpan; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.facebook.react.uimanager.PixelUtil; | ||
|
||
public class MarkdownH1Span extends StyleSpan implements LineHeightSpan, MarkdownSpan { | ||
|
||
private final float mFontSize; | ||
private final Integer mLineHeight; | ||
|
||
public MarkdownH1Span(float fontSize, Integer lineHeight) { | ||
super(Typeface.BOLD); | ||
mFontSize = PixelUtil.toPixelFromDIP(fontSize); | ||
mLineHeight = lineHeight; | ||
} | ||
|
||
@Override | ||
public void updateMeasureState(@NonNull TextPaint textPaint) { | ||
super.updateMeasureState(textPaint); | ||
apply(textPaint); | ||
} | ||
|
||
@Override | ||
public void updateDrawState(TextPaint tp) { | ||
super.updateDrawState(tp); | ||
apply(tp); | ||
} | ||
|
||
private void apply(@NonNull TextPaint textPaint) { | ||
textPaint.setTextSize(mFontSize); | ||
} | ||
|
||
@Override | ||
public void chooseHeight(CharSequence text, int start, int end, int spanstartv, int lineHeight, Paint.FontMetricsInt fm) { | ||
if (mLineHeight != null) { | ||
fm.top -= mLineHeight / 4; | ||
fm.ascent -= mLineHeight / 4; | ||
} | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
android/src/main/java/com/expensify/livemarkdown/MarkdownLineHeightSpan.java
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
android/src/main/java/com/expensify/livemarkdown/MarkdownLinkSpan.java
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,30 @@ | ||
package com.expensify.livemarkdown; | ||
|
||
import android.text.TextPaint; | ||
import android.text.style.MetricAffectingSpan; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
public class MarkdownLinkSpan extends MetricAffectingSpan implements MarkdownSpan { | ||
|
||
private final int mForegroundColor; | ||
|
||
public MarkdownLinkSpan(int foregroundColor) { | ||
mForegroundColor = foregroundColor; | ||
} | ||
|
||
@Override | ||
public void updateMeasureState(@NonNull TextPaint textPaint) { | ||
apply(textPaint); | ||
} | ||
|
||
@Override | ||
public void updateDrawState(TextPaint tp) { | ||
apply(tp); | ||
} | ||
|
||
private void apply(@NonNull TextPaint textPaint) { | ||
textPaint.setUnderlineText(true); | ||
textPaint.setColor(mForegroundColor); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
android/src/main/java/com/expensify/livemarkdown/MarkdownMentionSpan.java
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,32 @@ | ||
package com.expensify.livemarkdown; | ||
|
||
import android.text.TextPaint; | ||
import android.text.style.MetricAffectingSpan; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
public class MarkdownMentionSpan extends MetricAffectingSpan implements MarkdownSpan { | ||
|
||
private final int mBackgroundColor; | ||
private final int mForegroundColor; | ||
|
||
public MarkdownMentionSpan(int backgroundColor, int foregroundColor) { | ||
mBackgroundColor = backgroundColor; | ||
mForegroundColor = foregroundColor; | ||
} | ||
|
||
@Override | ||
public void updateMeasureState(@NonNull TextPaint textPaint) { | ||
apply(textPaint); | ||
} | ||
|
||
@Override | ||
public void updateDrawState(TextPaint tp) { | ||
apply(tp); | ||
} | ||
|
||
private void apply(@NonNull TextPaint textPaint) { | ||
textPaint.bgColor = mBackgroundColor; | ||
textPaint.setColor(mForegroundColor); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
android/src/main/java/com/expensify/livemarkdown/MarkdownPreSpan.java
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,28 @@ | ||
package com.expensify.livemarkdown; | ||
|
||
import android.content.res.AssetManager; | ||
import android.graphics.Canvas; | ||
import android.graphics.Paint; | ||
import android.text.Layout; | ||
import android.text.style.LeadingMarginSpan; | ||
|
||
import androidx.annotation.ColorInt; | ||
import androidx.annotation.NonNull; | ||
|
||
public class MarkdownPreSpan extends MarkdownBlockSpan implements LeadingMarginSpan { | ||
|
||
private final int mLeadingMargin; | ||
|
||
public MarkdownPreSpan(@NonNull AssetManager assetManager, @NonNull String fontFamily, float fontSize, @ColorInt int color, int leadingMargin) { | ||
super(assetManager, fontFamily, fontSize, color); | ||
mLeadingMargin = leadingMargin; | ||
} | ||
|
||
@Override | ||
public int getLeadingMargin(boolean first) { | ||
return mLeadingMargin; | ||
} | ||
|
||
@Override | ||
public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom, CharSequence text, int start, int end, boolean first, Layout layout) {} | ||
} |
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
Oops, something went wrong.