Skip to content

Instantly share code, notes, and snippets.

@duynhm
duynhm / viewpager.java
Created December 16, 2016 03:45
Các note lien quan đến ViewPager
//viewPager
/*FragmentPagerAdapter
This version of the pager is best for use when there are a handful of typically more static fragments to be paged through, such as a set of tabs. The fragment of each page the user visits will be kept in memory, though its view hierarchy may be destroyed when not visible. This can result in using a significant amount of memory since fragment instances can hold on to an arbitrary amount of state. For larger sets of pages, consider FragmentStatePagerAdapter.
*/
/*FragmentStatePagerAdapter:
This version of the pager is more useful when there are a large number of pages, working more like a list view. When pages are not visible to the user, their entire fragment may be destroyed, only keeping the saved state of that fragment. This allows the pager to hold on to much less memory associated with each visited page as compared to FragmentPagerAdapter at the cost of potentially more overhead when switching between pages.*/
/*setOffscreenPageLimit(int limit)
Set the number of pages
@duynhm
duynhm / style.xml
Created December 13, 2016 07:23
các style xml cần nhớ
<!--Đổi màu item option menu trên toolbar-->
<item name="android:actionMenuTextColor">@color/primary</item>
<!--animation ripple when click cardview-->
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="0dp"
android:id="@+id/edt1"
style="@style/edt_otp"
/>
<!--style-->
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to": "/topics/foo-bar",
"data": {
"message": "This is a Firebase Cloud Messaging Topic Message!",
}
}
@duynhm
duynhm / Click_word.java
Last active September 10, 2019 06:02
Spannable Click TextView Android
//click từng kí tự
private SpannableStringBuilder addClickablePart1(String str) {
SpannableStringBuilder ssb = new SpannableStringBuilder(str);
String[] array = str.split(" ");
int next = 0;
int start = 0;
for (final String s : array) {
start = str.indexOf(s, next);
ssb.setSpan(new NonUnderlinedClickableSpan() {
@Override
@duynhm
duynhm / DaggerApi.java
Last active December 27, 2018 03:47
Code minh họa cho bài viết Dagger 2 — Part 1 — Các Annotation trong dagger 2
public @interface Component {
Class<?>[] modules() default {};
Class<?>[] dependencies() default {};
}
public @interface Subcomponent {
Class<?>[] modules() default {};
}
public @interface Module {