-
Notifications
You must be signed in to change notification settings - Fork 138
/
ExampleMaterialAboutFragment.java
83 lines (67 loc) · 2.83 KB
/
ExampleMaterialAboutFragment.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.danielstone.materialaboutlibrarydemo;
import android.content.Context;
import android.os.Handler;
import androidx.core.content.ContextCompat;
import android.util.Log;
import com.danielstone.materialaboutlibrary.MaterialAboutFragment;
import com.danielstone.materialaboutlibrary.items.MaterialAboutActionItem;
import com.danielstone.materialaboutlibrary.items.MaterialAboutItemOnClickAction;
import com.danielstone.materialaboutlibrary.model.MaterialAboutList;
import com.mikepenz.community_material_typeface_library.CommunityMaterial;
import com.mikepenz.iconics.IconicsDrawable;
import static com.danielstone.materialaboutlibrarydemo.ExampleMaterialAboutActivity.THEME_LIGHT;
public class ExampleMaterialAboutFragment extends MaterialAboutFragment {
private MaterialAboutActionItem createDynamicItem(String subText, final Context c) {
final MaterialAboutActionItem item = new MaterialAboutActionItem.Builder()
.text("Dynamic UI")
.subText(subText)
.icon(new IconicsDrawable(c)
.icon(CommunityMaterial.Icon.cmd_refresh)
.sizeDp(18))
.build();
item.setOnClickAction(new MaterialAboutItemOnClickAction() {
@Override
public void onClick() {
item.setSubText("Random number: " + ((int) (Math.random() * 10)));
refreshMaterialAboutList();
}
});
return item;
}
@Override
protected MaterialAboutList getMaterialAboutList(final Context c) {
MaterialAboutList list = Demo.createMaterialAboutList(c, THEME_LIGHT);
list.getCards().get(2).getItems().add(createDynamicItem("Tap for a random number", c));
final MaterialAboutActionItem time = new MaterialAboutActionItem.Builder()
.text("Unix Time In Millis")
.subText("Time")
.icon(new IconicsDrawable(c)
.icon(CommunityMaterial.Icon.cmd_clock)
.sizeDp(18))
.build();
list.getCards().get(2).getItems().add(time);
return list;
}
final Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
Log.i("MaterialAboutFragment", "Updating with time");
if (getList().getCards().size() > 0) {
((MaterialAboutActionItem) getList().getCards().get(2).getItems().get(7)).setSubText("" + System.currentTimeMillis());
refreshMaterialAboutList();
}
handler.postDelayed(this, 1000);
}
};
@Override
public void onResume() {
super.onResume();
runnable.run();
}
@Override
public void onPause() {
super.onPause();
handler.removeCallbacks(runnable);
}
}