Skip to content

Instantly share code, notes, and snippets.

View sonvp's full-sized avatar

son vo sonvp

  • son.vo@hdwebsoft.com
View GitHub Profile
class _TrianglePainter extends CustomPainter {
final double lineSize;
_TrianglePainter({this.lineSize = 16});
@override
void paint(Canvas canvas, Size size) {
Path path = Path();
path.moveTo(0, 0);
path.lineTo(lineSize, 0);
path.lineTo(lineSize / 2, tan(pi / 3) * lineSize / 2);
@sonvp
sonvp / gist:7873060a99895f483ca48fdc030c71ad
Last active October 25, 2022 11:11
DrawableLeft to top or DrawableRight to top in TextView multiline.
1. Create Custom TextView.
public class TextViewDrawable extends android.support.v7.widget.AppCompatTextView {
public TextViewDrawable(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
/**
In layout
<SearchView
android:id="@+id/searchView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/ReminderTheme"
/>
In Style
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lnContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
@sonvp
sonvp / gist:3d71f0da5c9e80c0cdd753d473e14902
Last active July 5, 2016 08:30
Base on swipeRefreshLayoutRecyclerView.java of Mandhor . I fixed bug SwipeRefreshLayout catches scroll up too early - not on top of the list when use with recyclerview. But in some cases It disable SwipeRefreshLayout I can't scroll up . I fixed it with code below
public class SwipeRefreshLayoutToggleScrollListener extends RecyclerView.OnScrollListener {
private int overallYScroll = 0;
private GeneralSwipeRefreshLayout mSwipeLayout;
public SwipeRefreshLayoutToggleScrollListener(GeneralSwipeRefreshLayout swipeLayout) {
mSwipeLayout = swipeLayout;
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
@sonvp
sonvp / gist:247a5455c768d5f0df6486445ffca0c7
Created July 5, 2016 08:23
Base on swipeRefreshLayoutRecyclerView.java of Mandhor . I fixed bug SwipeRefreshLayout catches scroll up too early - not on top of the list when use with recyclerview. But in some cases It disable SwipeRefreshLayout I can't scroll up . I fixed it with code below
//we have to keep current scroll value somewhere in our fragment
private int overallYScroll = 0;
recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
overallYScroll = overallYScroll + dy;