Guest User

Untitled

a guest
May 23rd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.04 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="wrap_content"
  7. tools:context=".MainActivity">
  8.  
  9. <android.support.v7.widget.RecyclerView
  10. android:id="@+id/recycler"
  11. android:layout_width="match_parent"
  12. android:layout_height="wrap_content" />
  13.  
  14. </android.support.constraint.ConstraintLayout>
  15.  
  16. <?xml version="1.0" encoding="utf-8"?>
  17. <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
  18. xmlns:app="http://schemas.android.com/apk/res-auto"
  19. xmlns:tools="http://schemas.android.com/tools"
  20. android:id="@+id/card_parent"
  21. android:layout_width="match_parent"
  22. android:layout_height="wrap_content"
  23. android:layout_margin="8dp"
  24. android:animateLayoutChanges="true"
  25. android:clickable="true"
  26. android:foreground="?android:attr/selectableItemBackground"
  27. app:cardCornerRadius="4dp">
  28.  
  29. <android.support.constraint.ConstraintLayout
  30. android:id="@+id/constraint_card_child"
  31. android:layout_width="match_parent"
  32. android:layout_height="wrap_content"
  33. android:animateLayoutChanges="true">
  34.  
  35. <android.support.constraint.Guideline
  36. android:id="@+id/guideline3"
  37. android:layout_width="wrap_content"
  38. android:layout_height="wrap_content"
  39. android:orientation="vertical"
  40. app:layout_constraintGuide_end="16dp" />
  41.  
  42. <android.support.constraint.Guideline
  43. android:id="@+id/guideline2"
  44. android:layout_width="wrap_content"
  45. android:layout_height="wrap_content"
  46. android:orientation="vertical"
  47. app:layout_constraintGuide_begin="16dp" />
  48.  
  49. <ImageView
  50. android:id="@+id/test_image"
  51. android:layout_width="0dp"
  52. android:layout_height="192dp"
  53. android:layout_marginTop="72dp"
  54. android:scaleType="centerCrop"
  55. app:layout_constraintEnd_toEndOf="parent"
  56. app:layout_constraintStart_toStartOf="parent"
  57. app:layout_constraintTop_toTopOf="parent"
  58. app:srcCompat="@mipmap/ic_launcher" />
  59.  
  60. <TextView
  61. android:id="@+id/params_card_subtitle"
  62. android:layout_width="wrap_content"
  63. android:layout_height="17dp"
  64. android:layout_marginTop="16dp"
  65. android:text="Subtitle goes here"
  66. android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
  67. app:layout_constraintStart_toStartOf="@+id/guideline2"
  68. app:layout_constraintTop_toBottomOf="@+id/test_image" />
  69.  
  70. <TableLayout
  71. android:id="@+id/card_tableLayout"
  72. android:layout_width="0dp"
  73. android:layout_height="wrap_content"
  74. android:layout_marginTop="8dp"
  75. app:layout_constraintEnd_toStartOf="@+id/guideline3"
  76. app:layout_constraintStart_toStartOf="@+id/guideline2"
  77. app:layout_constraintTop_toBottomOf="@+id/params_card_subtitle">
  78.  
  79. <TableRow
  80. android:id="@+id/item1_row"
  81. android:layout_width="match_parent"
  82. android:layout_height="wrap_content">
  83.  
  84. <TextView
  85. android:id="@+id/test_table_item1"
  86. style="@style/TableText"
  87. android:layout_width="0dp"
  88. android:layout_height="wrap_content"
  89. android:layout_weight="3"
  90. android:text="item1" />
  91.  
  92. <LinearLayout
  93. android:layout_width="0dp"
  94. android:layout_height="match_parent"
  95. android:layout_weight="1"
  96. android:gravity="center"
  97. android:orientation="horizontal">
  98.  
  99. <ImageView
  100. android:id="@+id/item1_table_indicator"
  101. android:layout_width="match_parent"
  102. android:layout_height="match_parent"
  103. android:layout_margin="2dp"
  104. app:srcCompat="@mipmap/ic_launcher" />
  105.  
  106. </LinearLayout>
  107.  
  108. <TextView
  109. android:id="@+id/test_table_item1_value_last"
  110. style="@style/TableText"
  111. android:layout_width="0dp"
  112. android:layout_height="wrap_content"
  113. android:layout_weight="1"
  114. android:gravity="right"
  115. android:text="0.722" />
  116.  
  117. <TextView
  118. android:id="@+id/test_table_item1_value_lastest"
  119. style="@style/TableText"
  120. android:layout_width="0dp"
  121. android:layout_height="wrap_content"
  122. android:layout_weight="1"
  123. android:gravity="right"
  124. android:text="0.722" />
  125.  
  126. </TableRow>
  127.  
  128. <TableRow
  129. android:layout_width="match_parent"
  130. android:layout_height="wrap_content"
  131. android:layout_marginTop="4dp">
  132.  
  133. <TextView
  134. android:id="@+id/test_table_item2"
  135. style="@style/TableText"
  136. android:layout_width="0dp"
  137. android:layout_height="wrap_content"
  138. android:layout_weight="3"
  139. android:text="item2" />
  140.  
  141. <LinearLayout
  142. android:layout_width="0dp"
  143. android:layout_height="match_parent"
  144. android:layout_weight="1"
  145. android:gravity="center"
  146. android:orientation="horizontal">
  147.  
  148. <ImageView
  149. android:id="@+id/item2_table_indicator"
  150. android:layout_width="match_parent"
  151. android:layout_height="match_parent"
  152. android:layout_margin="2dp"
  153. app:srcCompat="@mipmap/ic_launcher" />
  154.  
  155. </LinearLayout>
  156.  
  157. <TextView
  158. android:id="@+id/test_table_item2_value_last"
  159. style="@style/TableText"
  160. android:layout_width="0dp"
  161. android:layout_height="wrap_content"
  162. android:layout_weight="1"
  163. android:gravity="right"
  164. android:text="0.001" />
  165.  
  166. <TextView
  167. android:id="@+id/test_table_item2_value_lastest"
  168. style="@style/TableText"
  169. android:layout_width="0dp"
  170. android:layout_height="wrap_content"
  171. android:layout_weight="1"
  172. android:gravity="right"
  173. android:text="0.001" />
  174.  
  175. </TableRow>
  176.  
  177. <TableRow
  178. android:layout_width="match_parent"
  179. android:layout_height="wrap_content"
  180. android:layout_marginTop="4dp">
  181.  
  182. <TextView
  183. android:id="@+id/test_table_item3"
  184. style="@style/TableText"
  185. android:layout_width="0dp"
  186. android:layout_height="wrap_content"
  187. android:layout_weight="3"
  188. android:text="item3" />
  189.  
  190. <LinearLayout
  191. android:layout_width="0dp"
  192. android:layout_height="match_parent"
  193. android:layout_weight="1"
  194. android:gravity="center"
  195. android:orientation="horizontal">
  196.  
  197. <ImageView
  198. android:id="@+id/item3_table_indicator"
  199. android:layout_width="match_parent"
  200. android:layout_height="match_parent"
  201. android:layout_margin="2dp"
  202. app:srcCompat="@mipmap/ic_launcher" />
  203.  
  204. </LinearLayout>
  205.  
  206. <TextView
  207. android:id="@+id/test_table_item3_value_last"
  208. style="@style/TableText"
  209. android:layout_width="0dp"
  210. android:layout_height="wrap_content"
  211. android:layout_weight="1"
  212. android:gravity="right"
  213. android:text="0.000" />
  214.  
  215. <TextView
  216. android:id="@+id/test_table_item3_value_lastest"
  217. style="@style/TableText"
  218. android:layout_width="0dp"
  219. android:layout_height="wrap_content"
  220. android:layout_weight="1"
  221. android:gravity="right"
  222. android:text="0.000" />
  223.  
  224. </TableRow>
  225.  
  226. <TableRow
  227. android:layout_width="match_parent"
  228. android:layout_height="wrap_content"
  229. android:layout_marginTop="4dp">
  230.  
  231. <TextView
  232. android:id="@+id/test_table_item4"
  233. style="@style/TableText"
  234. android:layout_width="0dp"
  235. android:layout_height="wrap_content"
  236. android:layout_weight="3"
  237. android:text="item4" />
  238.  
  239. <LinearLayout
  240. android:layout_width="0dp"
  241. android:layout_height="match_parent"
  242. android:layout_weight="1"
  243. android:gravity="center"
  244. android:orientation="horizontal">
  245.  
  246. <ImageView
  247. android:id="@+id/item4_table_indicator"
  248. android:layout_width="match_parent"
  249. android:layout_height="match_parent"
  250. android:layout_margin="2dp"
  251. app:srcCompat="@mipmap/ic_launcher" />
  252.  
  253. </LinearLayout>
  254.  
  255. <TextView
  256. android:id="@+id/test_table_item4_value_last"
  257. style="@style/TableText"
  258. android:layout_width="0dp"
  259. android:layout_height="wrap_content"
  260. android:layout_weight="1"
  261. android:gravity="right"
  262. android:text="0.000" />
  263.  
  264. <TextView
  265. android:id="@+id/test_table_item4_value_lastest"
  266. style="@style/TableText"
  267. android:layout_width="0dp"
  268. android:layout_height="wrap_content"
  269. android:layout_weight="1"
  270. android:gravity="right"
  271. android:text="0.000" />
  272.  
  273. </TableRow>
  274.  
  275. <TableRow
  276. android:layout_width="match_parent"
  277. android:layout_height="wrap_content"
  278. android:layout_marginTop="4dp">
  279.  
  280. <TextView
  281. android:id="@+id/test_table_item5"
  282. style="@style/TableText"
  283. android:layout_width="0dp"
  284. android:layout_height="wrap_content"
  285. android:layout_weight="3"
  286. android:text="item5" />
  287.  
  288. <LinearLayout
  289. android:layout_width="0dp"
  290. android:layout_height="match_parent"
  291. android:layout_weight="1"
  292. android:gravity="center"
  293. android:orientation="horizontal">
  294.  
  295. <ImageView
  296. android:id="@+id/temp_table_indicator"
  297. android:layout_width="match_parent"
  298. android:layout_height="match_parent"
  299. android:layout_margin="2dp"
  300. app:srcCompat="@mipmap/ic_launcher" />
  301.  
  302. </LinearLayout>
  303.  
  304. <TextView
  305. android:id="@+id/test_table_item5_value_last"
  306. style="@style/TableText"
  307. android:layout_width="0dp"
  308. android:layout_height="wrap_content"
  309. android:layout_weight="1"
  310. android:gravity="right"
  311. android:text="26 °C" />
  312.  
  313. <TextView
  314. android:id="@+id/test_table_item5_value_lastest"
  315. style="@style/TableText"
  316. android:layout_width="0dp"
  317. android:layout_height="wrap_content"
  318. android:layout_weight="1"
  319. android:gravity="right"
  320. android:text="26 °C" />
  321.  
  322. </TableRow>
  323.  
  324. </TableLayout>
  325.  
  326. <View
  327. android:id="@+id/divider3"
  328. android:layout_width="368dp"
  329. android:layout_height="1dp"
  330. android:layout_marginTop="8dp"
  331. android:background="?android:attr/listDivider"
  332. app:layout_constraintBottom_toTopOf="@+id/expand_collapse_button"
  333. app:layout_constraintEnd_toEndOf="parent"
  334. app:layout_constraintStart_toStartOf="parent"
  335. app:layout_constraintTop_toBottomOf="@+id/card_tableLayout"
  336. app:layout_constraintVertical_bias="1.0" />
  337.  
  338. <Button
  339. android:id="@+id/expand_collapse_button"
  340. style="@style/Widget.AppCompat.Button.Borderless"
  341. android:layout_width="wrap_content"
  342. android:layout_height="wrap_content"
  343. android:text="Expand"
  344. android:textColor="@color/colorPrimary"
  345. app:layout_constraintBottom_toBottomOf="parent"
  346. app:layout_constraintStart_toStartOf="parent" />
  347.  
  348. <TextView
  349. android:id="@+id/textView2"
  350. android:layout_width="wrap_content"
  351. android:layout_height="wrap_content"
  352. android:layout_marginStart="72dp"
  353. android:fontFamily="sans-serif"
  354. android:padding="0dp"
  355. android:text="Title"
  356. android:textAllCaps="false"
  357. android:textAppearance="@style/TextAppearance.AppCompat.Title"
  358. android:textSize="20dp"
  359. android:typeface="sans"
  360. app:layout_constraintStart_toStartOf="parent"
  361. app:layout_constraintTop_toTopOf="@+id/guideline4" />
  362.  
  363. <ImageView
  364. android:id="@+id/imageView2"
  365. android:layout_width="40dp"
  366. android:layout_height="40dp"
  367. android:layout_marginTop="16dp"
  368. app:layout_constraintStart_toStartOf="@+id/guideline2"
  369. app:layout_constraintTop_toTopOf="parent"
  370. app:srcCompat="@mipmap/ic_launcher_round" />
  371.  
  372. <TextView
  373. android:id="@+id/textView3"
  374. android:layout_width="wrap_content"
  375. android:layout_height="wrap_content"
  376. android:layout_marginStart="72dp"
  377. android:fontFamily="@font/roboto"
  378. android:padding="0dp"
  379. android:text="Subtitle goes here"
  380. android:textAppearance="@style/TextAppearance.AppCompat.Small"
  381. android:textSize="14dp"
  382. app:layout_constraintStart_toStartOf="parent"
  383. app:layout_constraintTop_toBottomOf="@+id/textView2" />
  384.  
  385. <android.support.constraint.Guideline
  386. android:id="@+id/guideline4"
  387. android:layout_width="wrap_content"
  388. android:layout_height="wrap_content"
  389. android:orientation="horizontal"
  390. app:layout_constraintGuide_begin="16dp" />
  391.  
  392. </android.support.constraint.ConstraintLayout>
  393.  
  394. </android.support.v7.widget.CardView>
  395.  
  396. public class MainActivity extends AppCompatActivity
  397. implements LoaderManager.LoaderCallbacks<Cursor> {
  398.  
  399. private final int LOADER_ID = 0;
  400. private DbHelper helper;
  401. private SQLiteDatabase db;
  402. private RecyclerView recyclerView;
  403. private ListCursorAdapter cursorAdapter;
  404.  
  405. @Override
  406. protected void onCreate(Bundle savedInstanceState) {
  407. super.onCreate(savedInstanceState);
  408. setContentView(R.layout.activity_main);
  409.  
  410. /* Initialize */
  411. cursorAdapter = new ListCursorAdapter(this, null);
  412. helper = new DbHelper(this);
  413.  
  414. /* Setup Recycler */
  415. recyclerView = findViewById(R.id.recycler);
  416. recyclerView.setAdapter(cursorAdapter);
  417. recyclerView.setLayoutManager(new LinearLayoutManager(this));
  418.  
  419. getLoaderManager().initLoader(LOADER_ID, null, this);
  420. }
  421.  
  422. @Override
  423. public Loader<Cursor> onCreateLoader(int id, Bundle args) {
  424. db = helper.getWritableDatabase();
  425.  
  426. /* Create dummy data to test */
  427. int i = 0;
  428. while (i < 10){
  429.  
  430. ContentValues values = new ContentValues();
  431. values.put(NAME_COLUMN, String.valueOf(i));
  432.  
  433. db.insert(TEST_TABLE, null, values);
  434. values.clear();
  435. i++;
  436. }
  437. return new CustomCursorLoader(this);
  438. }
  439.  
  440. @Override
  441. public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
  442. cursorAdapter.swapCursor(cursor);
  443. cursorAdapter = new ListCursorAdapter(this, cursor);
  444. }
  445.  
  446. @Override
  447. public void onLoaderReset(Loader<Cursor> loader) {
  448. cursorAdapter.swapCursor(null);
  449. }
  450. }
Add Comment
Please, Sign In to add comment