| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fdc9b98 commit b26a227
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,19 +1,32 @@ | |||
| 1 | 1 | package com.morihacky.android.rxjava; | |
| 2 | 2 | ||
| 3 | + import android.content.Context; | ||
| 3 | 4 | import android.os.Bundle; | |
| 4 | 5 | import android.support.annotation.Nullable; | |
| 5 | 6 | import android.support.v4.app.Fragment; | |
| 6 | 7 | import android.view.LayoutInflater; | |
| 7 | 8 | import android.view.View; | |
| 8 | 9 | import android.view.ViewGroup; | |
| 10 | + import android.widget.ArrayAdapter; | ||
| 11 | + import android.widget.ListView; | ||
| 9 | 12 | ||
| 10 | 13 | import com.morihacky.android.rxjava.app.R; | |
| 11 | 14 | ||
| 15 | + import java.util.ArrayList; | ||
| 16 | + import java.util.List; | ||
| 17 | + | ||
| 12 | 18 | import butterknife.ButterKnife; | |
| 19 | + import butterknife.InjectView; | ||
| 20 | + import butterknife.OnClick; | ||
| 13 | 21 | ||
| 14 | 22 | public class DemoAccumulateEventFragment | |
| 15 | 23 | extends Fragment { | |
| 16 | 24 | ||
| 25 | + @InjectView(R.id.accumulated_event_list) ListView _logsListView; | ||
| 26 | + | ||
| 27 | + private LogAdapter _adapter; | ||
| 28 | + private List<String> _logs; | ||
| 29 | + | ||
| 17 | 30 | @Override | |
| 18 | 31 | public View onCreateView(LayoutInflater inflater, | |
| 19 | 32 | @Nullable ViewGroup container, | |
@@ -22,4 +35,39 @@ public View onCreateView(LayoutInflater inflater, | |||
| 22 | 35 | ButterKnife.inject(this, layout); | |
| 23 | 36 | return layout; | |
| 24 | 37 | } | |
| 38 | + | ||
| 39 | + @Override | ||
| 40 | + public void onActivityCreated(@Nullable Bundle savedInstanceState) { | ||
| 41 | + super.onActivityCreated(savedInstanceState); | ||
| 42 | + _setupLogAdapter(); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + @OnClick(R.id.accumulated_event_btn) | ||
| 46 | + public void onButtonTapped() { | ||
| 47 | + | ||
| 48 | + _addLogToAdapter("Tapped"); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + // ----------------------------------------------------------------------------------- | ||
| 52 | + // Method that help wiring up the example (irrelevant to RxJava) | ||
| 53 | + | ||
| 54 | + private void _setupLogAdapter() { | ||
| 55 | + _logs = new ArrayList<String>(); | ||
| 56 | + _adapter = new LogAdapter(getActivity(), new ArrayList<String>()); | ||
| 57 | + _logsListView.setAdapter(_adapter); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + private void _addLogToAdapter(String logMsg) { | ||
| 61 | + _logs.add(0, logMsg); | ||
| 62 | + _adapter.clear(); | ||
| 63 | + _adapter.addAll(_logs); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + private class LogAdapter | ||
| 67 | + extends ArrayAdapter<String> { | ||
| 68 | + | ||
| 69 | + public LogAdapter(Context context, List<String> logs) { | ||
| 70 | + super(context, R.layout.item_log, R.id.item_log, logs); | ||
| 71 | + } | ||
| 72 | + } | ||
| 25 | 73 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,8 +7,24 @@ | |||
| 7 | 7 | xmlns:android="http://schemas.android.com/apk/res/android"> | |
| 8 | 8 | ||
| 9 | 9 | <TextView | |
| 10 | - android:layout_width="wrap_content" | ||
| 11 | 10 | android:layout_height="wrap_content" | |
| 12 | - android:text="Accumulate events test" /> | ||
| 11 | + android:layout_width="match_parent" | ||
| 12 | + android:padding="10dp" | ||
| 13 | + android:gravity="center" | ||
| 14 | + android:text="@string/demo_accumulate_msg"/> | ||
| 15 | + | ||
| 16 | + <Button | ||
| 17 | + android:id="@+id/accumulated_event_btn" | ||
| 18 | + android:layout_height="wrap_content" | ||
| 19 | + android:layout_width="match_parent" | ||
| 20 | + android:layout_marginLeft="90dp" | ||
| 21 | + android:layout_marginRight="90dp" | ||
| 22 | + android:textSize="16dp" | ||
| 23 | + android:text="tap me"/> | ||
| 24 | + | ||
| 25 | + <ListView | ||
| 26 | + android:id="@+id/accumulated_event_list" | ||
| 27 | + android:layout_height="match_parent" | ||
| 28 | + android:layout_width="match_parent"/> | ||
| 13 | 29 | ||
| 14 | 30 | </LinearLayout> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,8 @@ | |||
| 1 | + <?xml version="1.0" encoding="utf-8"?> | ||
| 2 | + | ||
| 3 | + <TextView | ||
| 4 | + android:id="@+id/item_log" | ||
| 5 | + android:layout_height="match_parent" | ||
| 6 | + android:layout_width="match_parent" | ||
| 7 | + android:text="Item Log goes here" | ||
| 8 | + xmlns:android="http://schemas.android.com/apk/res/android"/> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,5 +6,6 @@ | |||
| 6 | 6 | <string name="action_settings">Settings</string> | |
| 7 | 7 | <string name="demo_type_long_bg">long operation in bg (schedulers)</string> | |
| 8 | 8 | <string name="demo_type_accumulate">accumulate events (instant search)</string> | |
| 9 | + <string name="demo_accumulate_msg">This is a demonstration of how events are accumulated. Tap the button below repetitively and you will notice in the logs that button taps are collected over a span of 2s and printed below.</string> | ||
| 9 | 10 | ||
| 10 | 11 | </resources> | |
| Back | FazBrowse Home | New Git URL |
0 commit comments