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
package lt.linecounter | |
import java.awt.Font | |
import java.awt.FontMetrics | |
import java.awt.Insets | |
import java.awt.font.LineBreakMeasurer | |
import java.awt.font.TextAttribute | |
import java.text.AttributedString | |
import java.text.BreakIterator | |
import javax.swing.JTextArea |
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
package lt.linecounter | |
import org.slf4j.Logger | |
import org.slf4j.LoggerFactory | |
import java.awt.* | |
import java.awt.event.ComponentAdapter | |
import java.awt.event.ComponentEvent | |
import javax.swing.JFrame | |
import javax.swing.JPanel | |
import javax.swing.JTextArea |
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
/** | |
* Parses text to fit in [TextProvider.formatWidth] and wraps whenever needed | |
*/ | |
class TextAreaLineCounter( | |
private val textProvider: TextProvider | |
) { | |
private val formatWidth: Float | |
get() = textProvider.formatWidth |
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
import lt.ito.export.TextAreaLineCounter | |
import sun.font.FontDesignMetrics | |
import java.awt.Font | |
import java.awt.FontMetrics | |
import java.awt.Graphics | |
/** | |
* Scales font into bounding [boxWidth], [boxHeight] to fit in and draws it using word wrap | |
*/ | |
class TextAreaScaleDrawer( |
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
/** | |
* Inspiration and main resource taken from [com.google.android.material.divider.MaterialDividerItemDecoration] | |
* | |
* Divider is solving only vertical scrolling use case. | |
* It divides items that are vertically scrolled + "divides" the first item (paints divider on top) | |
* | |
* Will not paint a full rectangle if the [RecyclerView] scrolls only in one direction, because | |
* the dividers are pointed on top. So the dividers "stays on top" whenever scrolling. | |
*/ | |
class MaterialDividerVerticalOnlyWithFirstItem( |
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
import androidx.annotation.NonNull; | |
import androidx.annotation.Nullable; | |
public class LogUtils { | |
@NonNull public static String objPrefix(@Nullable Object obj) { | |
if (obj != null) { | |
return String.format( | |
"[%s@%s]", | |
obj.getClass().getSimpleName(), |
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
/** | |
* Debugging utils | |
*/ | |
object LogUtils { | |
/** | |
* Converts [obj] to instance signature | |
* Easier to figure out different object instance usage in combination to logging | |
*/ | |
@JvmStatic |
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
package lt.markmerkk | |
import android.content.Context | |
import android.graphics.Rect | |
import android.view.View | |
import androidx.recyclerview.widget.RecyclerView | |
import androidx.recyclerview.widget.RecyclerView.ItemDecoration | |
import lt.ermitazas.base.dpToPx | |
/** |
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
data class ItemDecoratorOffset private constructor( | |
val top: Int, | |
val bottom: Int, | |
val start: Int, | |
val end: Int, | |
) { | |
companion object { | |
fun asEmpty(): ItemDecoratorOffset { | |
return ItemDecoratorOffset( | |
top = 0, |
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
class DividerItemWithoutLastDecoration( | |
val divider: Drawable, | |
val dividerOffset: ItemDecoratorOffset = ItemDecoratorOffset.asEmpty(), | |
) : RecyclerView.ItemDecoration() { | |
override fun onDrawOver(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) { | |
val dividerLeft = parent.paddingLeft + dividerOffset.start | |
val dividerRight = parent.width - parent.paddingRight - dividerOffset.end | |
val childCount = parent.childCount | |
for (i in 0..childCount - 2) { |
OlderNewer