Skip to content

Commit 75eec83

Browse files
committed
Merge pull request #22 from cookpad/v2.0.0
[Proposal] New interfaces to configure Puree
2 parents 661f46f + 398c8e4 commit 75eec83

25 files changed

+475
-234
lines changed

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public class DemoApplication extends Application {
3030
public static PureeConfiguration buildConfiguration(Context context) {
3131
PureeFilter addEventTimeFilter = new AddEventTimeFilter();
3232
return new PureeConfiguration.Builder(context)
33-
.registerOutput(new OutLogcat())
34-
.registerOutput(new OutBufferedLogcat(), addEventTimeFilter)
33+
.source(ClickLog.class).to(new OutLogcat())
34+
.source(ClickLog.class).filter(addEventTimeListener).to(new OutBufferedLogcat())
3535
.build();
3636
}
3737
}
@@ -58,7 +58,7 @@ public class ClickLog extends JsonConvertible {
5858
Call `Puree.send` in an arbitrary timing.
5959

6060
```java
61-
Puree.send(new ClickLog("MainActivity", "Hello"), OutLogcat.TYPE);
61+
Puree.send(new ClickLog("MainActivity", "Hello"));
6262
// => {"page":"MainActivity","label":"Hello"}
6363
```
6464

@@ -73,7 +73,7 @@ If you don't need buffering, you can use PureeOutput.
7373

7474
```java
7575
public class OutLogcat extends PureeOutput {
76-
public static final String TYPE = "out_logcat";
76+
private static final String TYPE = "out_logcat";
7777

7878
@Override
7979
public String type() {
@@ -96,7 +96,7 @@ If you need beffering, you can use PureeBufferedOutput.
9696

9797
```java
9898
public class OutFakeApi extends PureeBufferedOutput {
99-
public static final String TYPE = "out_fake_api";
99+
private static final String TYPE = "out_fake_api";
100100

101101
private static final FakeApiClient CLIENT = new FakeApiClient();
102102

@@ -170,8 +170,8 @@ Register filters when initializing Puree.
170170

171171
```java
172172
new PureeConfiguration.Builder(context)
173-
.registerOutput(new OutLogcat(), addEventTimeFilter)
174-
.registerOutput(new OutFakeApi(), addEventTimeFilter, samplingFilter)
173+
.source(ClickLog.class).to(new OutLogcat())
174+
.source(ClickLog.class).filters(addEventTimeFilter).filter(samplingFilter).to(new OutFakeApi())
175175
.build();
176176
```
177177

@@ -188,5 +188,5 @@ buildscript {
188188
...
189189
190190
// app/build.gradle
191-
compile 'com.cookpad:puree:1.2.0'
191+
compile 'com.cookpad:puree:2.0.0'
192192
```

demo/src/main/java/com/example/puree/MainActivity.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package com.example.puree;
22

3-
import android.support.v7.app.ActionBarActivity;
43
import android.os.Bundle;
4+
import android.support.v7.app.ActionBarActivity;
55
import android.view.Menu;
66
import android.view.MenuItem;
77
import android.view.View;
88
import android.widget.Button;
99
import android.widget.TextView;
1010

1111
import com.cookpad.puree.Puree;
12-
import com.cookpad.puree.plugins.OutLogcat;
1312
import com.example.puree.logs.ClickLog;
1413
import com.example.puree.logs.PvLog;
1514
import com.example.puree.logs.plugins.OutBufferedDisplay;
@@ -20,8 +19,8 @@
2019

2120
public class MainActivity extends ActionBarActivity {
2221
private TextView logDisplayTextView;
23-
private Button logDisplayButton;
24-
private Button logBufferedDisplayButton;
22+
private Button button1;
23+
private Button button2;
2524

2625
private final OutDisplay.Callback outDisplayCallback = new OutDisplay.Callback() {
2726
@Override
@@ -57,7 +56,7 @@ protected void onCreate(Bundle savedInstanceState) {
5756
findViews();
5857
OutDisplay.register(outDisplayCallback);
5958
OutBufferedDisplay.register(outBufferedDisplayCallback);
60-
Puree.send(new PvLog(this), OutLogcat.TYPE);
59+
Puree.send(new PvLog(this));
6160
setupViews();
6261
}
6362

@@ -70,21 +69,21 @@ protected void onDestroy() {
7069

7170
private void findViews() {
7271
logDisplayTextView = (TextView) findViewById(R.id.log_display);
73-
logDisplayButton = (Button) findViewById(R.id.display_button);
74-
logBufferedDisplayButton = (Button) findViewById(R.id.buffered_display_button);
72+
button1 = (Button) findViewById(R.id.button1);
73+
button2 = (Button) findViewById(R.id.button2);
7574
}
7675

7776
private void setupViews() {
78-
logDisplayButton.setOnClickListener(new View.OnClickListener() {
77+
button1.setOnClickListener(new View.OnClickListener() {
7978
@Override
8079
public void onClick(View view) {
81-
Puree.send(new ClickLog("MainActivity", "track"), OutDisplay.TYPE);
80+
Puree.send(new ClickLog("MainActivity", "BUTTON 1"));
8281
}
8382
});
84-
logBufferedDisplayButton.setOnClickListener(new View.OnClickListener() {
83+
button2.setOnClickListener(new View.OnClickListener() {
8584
@Override
8685
public void onClick(View view) {
87-
Puree.send(new ClickLog("MainActivity", "track"), OutBufferedDisplay.TYPE);
86+
Puree.send(new ClickLog("MainActivity", "BUTTON 2"));
8887
}
8988
});
9089
}

demo/src/main/java/com/example/puree/logs/PureeConfigurator.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.cookpad.puree.plugins.OutBufferedLogcat;
99
import com.cookpad.puree.plugins.OutLogcat;
1010
import com.example.puree.AddEventTimeFilter;
11-
import com.example.puree.logs.plugins.OutBufferedDisplay;
1211
import com.example.puree.logs.plugins.OutDisplay;
1312

1413
public class PureeConfigurator {
@@ -18,12 +17,13 @@ public static void configure(Context context) {
1817

1918
public static PureeConfiguration buildConf(Context context) {
2019
PureeFilter addEventTimeFilter = new AddEventTimeFilter();
21-
return new PureeConfiguration.Builder(context)
22-
.registerOutput(new OutLogcat(), addEventTimeFilter)
23-
.registerOutput(new OutBufferedLogcat(), addEventTimeFilter)
24-
.registerOutput(new OutDisplay())
20+
PureeConfiguration conf = new PureeConfiguration.Builder(context)
21+
.source(ClickLog.class).to(new OutDisplay())
22+
.source(ClickLog.class).filter(addEventTimeFilter).to(new OutBufferedLogcat())
23+
.source(PvLog.class).filter(addEventTimeFilter).to(new OutLogcat())
2524
// .registerOutput(new OutDisplay(), new SamplingFilter(0.5F)) // you can sampling logs
26-
.registerOutput(new OutBufferedDisplay())
2725
.build();
26+
conf.printMapping();
27+
return conf;
2828
}
2929
}

demo/src/main/java/com/example/puree/logs/plugins/OutBufferedDisplay.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import java.lang.ref.WeakReference;
1313

1414
public class OutBufferedDisplay extends PureeBufferedOutput {
15-
public static final String TYPE = "buffered_display";
16-
1715
private static WeakReference<Callback> callbackRef = new WeakReference<>(null);
1816

1917
public static void register(Callback callback) {
@@ -26,7 +24,7 @@ public static void unregister() {
2624

2725
@Override
2826
public String type() {
29-
return TYPE;
27+
return "out_buffered_display";
3028
}
3129

3230
@Override

demo/src/main/java/com/example/puree/logs/plugins/OutFakeApi.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
import org.json.JSONArray;
99

1010
public class OutFakeApi extends PureeBufferedOutput {
11-
public static final String TYPE = "out_fake_api";
12-
1311
private static final FakeApiClient CLIENT = new FakeApiClient();
1412

1513
@Override
1614
public String type() {
17-
return TYPE;
15+
return "out_fake_api";
1816
}
1917

2018
@Override

demo/src/main/res/layout/activity_main.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@
1111
android:orientation="horizontal">
1212

1313
<Button
14-
android:id="@+id/display_button"
14+
android:id="@+id/button1"
1515
android:layout_width="match_parent"
1616
android:layout_height="wrap_content"
1717
android:layout_weight="1"
1818
android:background="@drawable/clickable_button_background"
19-
android:text="display"
19+
android:text="BUTTON 1"
2020
android:textColor="@android:color/white" />
2121

2222
<Button
23-
android:id="@+id/buffered_display_button"
23+
android:id="@+id/button2"
2424
android:layout_width="match_parent"
2525
android:layout_height="wrap_content"
2626
android:layout_marginLeft="8dp"
2727
android:layout_weight="1"
2828
android:background="@drawable/clickable_button_background"
29-
android:text="buffered display"
29+
android:text="BUTTON 2"
3030
android:textColor="@android:color/white" />
3131
</LinearLayout>
3232

plugins/src/main/java/com/cookpad/puree/plugins/OutLogcat.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
import org.json.JSONObject;
99

1010
public class OutLogcat extends PureeOutput {
11-
public static final String TYPE = "out_logcat";
12-
1311
@Override
1412
public String type() {
15-
return TYPE;
13+
return "out_logcat";
1614
}
1715

1816
@Override
@@ -22,6 +20,6 @@ public OutputConfiguration configure(OutputConfiguration conf) {
2220

2321
@Override
2422
public void emit(JSONObject jsonLog) {
25-
Log.d(TYPE, jsonLog.toString());
23+
Log.d("out_logcat", jsonLog.toString());
2624
}
2725
}

puree/build.gradle

+11-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ android {
1111
targetSdkVersion 21
1212
versionCode 1
1313
versionName "1.0"
14+
15+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1416
}
1517
buildTypes {
1618
release {
@@ -20,9 +22,14 @@ android {
2022
}
2123

2224
compileOptions {
25+
encoding = 'UTF-8'
2326
sourceCompatibility JavaVersion.VERSION_1_7
2427
targetCompatibility JavaVersion.VERSION_1_7
2528
}
29+
packagingOptions {
30+
exclude 'META-INF/services/javax.annotation.processing.Processor'
31+
exclude 'LICENSE.txt'
32+
}
2633
}
2734

2835
android.libraryVariants.all { variant ->
@@ -47,6 +54,9 @@ dependencies {
4754
compile fileTree(dir: 'libs', include: ['*.jar'])
4855
compile 'com.android.support:appcompat-v7:21.0.2'
4956
compile 'com.google.code.gson:gson:2.3'
57+
58+
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
59+
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
5060
}
5161

5262
task androidJar(type: Jar) {
@@ -63,7 +73,7 @@ artifacts {
6373
archives androidSourcesJar
6474
}
6575

66-
version = "1.2.0"
76+
version = "2.0.0"
6777

6878
publishing {
6979
publications {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.cookpad.puree;
2+
3+
import android.support.test.runner.AndroidJUnit4;
4+
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
8+
import static org.hamcrest.Matchers.is;
9+
import static org.junit.Assert.assertThat;
10+
11+
@RunWith(AndroidJUnit4.class)
12+
public class KeyTest {
13+
@Test
14+
public void getId() {
15+
{
16+
Key key = Key.from(FooLog.class);
17+
assertThat(key.getId(), is("com.cookpad.puree.KeyTest$FooLog"));
18+
}
19+
{
20+
Key key = Key.from(BarLog.class);
21+
assertThat(key.getId(), is("com.cookpad.puree.KeyTest$BarLog"));
22+
}
23+
}
24+
25+
@Test
26+
public void equals() {
27+
{
28+
Key key1 = Key.from(FooLog.class);
29+
Key key2 = Key.from(BarLog.class);
30+
assertThat(key1.equals(key2), is(false));
31+
}
32+
{
33+
Key key1 = Key.from(FooLog.class);
34+
Key key2 = Key.from(FooLog.class);
35+
assertThat(key1.equals(key2), is(true));
36+
}
37+
}
38+
39+
private static class FooLog extends JsonConvertible {
40+
}
41+
42+
private static class BarLog extends JsonConvertible {
43+
}
44+
}

0 commit comments

Comments
 (0)