Move sample source and resources to gradle dirs
Summary: Follow standard Gradle paths. Reviewed By: priteshrnandgaonkar Differential Revision: D8890133 fbshipit-source-id: 062331b6b3d5f118f07cb5ca14cdec871f75867b
This commit is contained in:
committed by
Facebook Github Bot
parent
50affb0a25
commit
07b083e570
@@ -0,0 +1,26 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.sonar.sample;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import java.util.List;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import com.facebook.litho.ComponentContext;
|
||||
import com.facebook.litho.LithoView;
|
||||
import android.util.Log;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
final ComponentContext c = new ComponentContext(this);
|
||||
setContentView(
|
||||
LithoView.create(
|
||||
c,
|
||||
RootComponent.create(c).build()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.sonar.sample;
|
||||
|
||||
import android.util.Log;
|
||||
import com.facebook.litho.ClickEvent;
|
||||
import com.facebook.litho.Column;
|
||||
import com.facebook.litho.Component;
|
||||
import com.facebook.litho.ComponentContext;
|
||||
import com.facebook.litho.annotations.LayoutSpec;
|
||||
import com.facebook.litho.annotations.OnCreateLayout;
|
||||
import com.facebook.litho.annotations.OnEvent;
|
||||
import com.facebook.litho.widget.Text;
|
||||
import java.io.IOException;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
@LayoutSpec
|
||||
public class RootComponentSpec {
|
||||
|
||||
@OnCreateLayout
|
||||
static Component onCreateLayout(ComponentContext c) {
|
||||
return Column.create(c)
|
||||
.child(
|
||||
Text.create(c)
|
||||
.text("Tap to hit get request")
|
||||
.key("1")
|
||||
.textSizeSp(20)
|
||||
.clickHandler(RootComponent.hitGetRequest(c)))
|
||||
.child(
|
||||
Text.create(c)
|
||||
.text("Tap to hit post request")
|
||||
.key("2")
|
||||
.textSizeSp(20)
|
||||
.clickHandler(RootComponent.hitPostRequest(c)))
|
||||
.child(
|
||||
Text.create(c)
|
||||
.text("I m just a text")
|
||||
.key("3")
|
||||
.textSizeSp(20))
|
||||
.build();
|
||||
}
|
||||
|
||||
@OnEvent(ClickEvent.class)
|
||||
static void hitGetRequest(ComponentContext c) {
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url("https://api.github.com/repos/facebook/yoga")
|
||||
.get()
|
||||
.build();
|
||||
SonarSampleApplication.okhttpClient.newCall(request).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.d("Sonar", e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
if (response.isSuccessful()) {
|
||||
Log.d("Sonar", response.body().string());
|
||||
} else {
|
||||
Log.d("Sonar", "not successful");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@OnEvent(ClickEvent.class)
|
||||
static void hitPostRequest(ComponentContext c) {
|
||||
|
||||
RequestBody formBody = new FormBody.Builder()
|
||||
.add("app", "Sonar")
|
||||
.add("remarks", "Its awesome")
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url("https://demo9512366.mockable.io/SonarPost")
|
||||
.post(formBody)
|
||||
.build();
|
||||
|
||||
SonarSampleApplication.okhttpClient.newCall(request).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.d("Sonar", e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
if (response.isSuccessful()) {
|
||||
Log.d("Sonar", response.body().string());
|
||||
} else {
|
||||
Log.d("Sonar", "not successful");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.sonar.sample;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import com.facebook.litho.sonar.LithoSonarDescriptors;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
import com.facebook.sonar.android.AndroidSonarClient;
|
||||
import com.facebook.sonar.core.SonarClient;
|
||||
import com.facebook.sonar.plugins.inspector.DescriptorMapping;
|
||||
import com.facebook.sonar.plugins.inspector.InspectorSonarPlugin;
|
||||
import com.facebook.sonar.plugins.network.NetworkSonarPlugin;
|
||||
import com.facebook.sonar.plugins.network.SonarOkhttpInterceptor;
|
||||
import com.facebook.sonar.plugins.sharedpreferences.SharedPreferencesSonarPlugin;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public class SonarSampleApplication extends Application {
|
||||
|
||||
public static OkHttpClient okhttpClient;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
SoLoader.init(this, false);
|
||||
|
||||
final SonarClient client = AndroidSonarClient.getInstance(this);
|
||||
final DescriptorMapping descriptorMapping = DescriptorMapping.withDefaults();
|
||||
|
||||
NetworkSonarPlugin networkPlugin = new NetworkSonarPlugin();
|
||||
SonarOkhttpInterceptor interceptor = new SonarOkhttpInterceptor(networkPlugin);
|
||||
|
||||
okhttpClient = new OkHttpClient.Builder()
|
||||
.addNetworkInterceptor(interceptor)
|
||||
.connectTimeout(60, TimeUnit.SECONDS)
|
||||
.readTimeout(60, TimeUnit.SECONDS)
|
||||
.writeTimeout(10, TimeUnit.MINUTES)
|
||||
.build();
|
||||
|
||||
LithoSonarDescriptors.add(descriptorMapping);
|
||||
client.addPlugin(new InspectorSonarPlugin(this, descriptorMapping));
|
||||
client.addPlugin(networkPlugin);
|
||||
client.addPlugin(new SharedPreferencesSonarPlugin(this, "sample"));
|
||||
client.start();
|
||||
|
||||
getSharedPreferences("sample", Context.MODE_PRIVATE).edit().putString("Hello", "world").apply();
|
||||
}
|
||||
}
|
||||
BIN
android/sample/src/main/res/drawable-hdpi/ic_launcher.png
Normal file
BIN
android/sample/src/main/res/drawable-hdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
BIN
android/sample/src/main/res/drawable-mdpi/ic_launcher.png
Normal file
BIN
android/sample/src/main/res/drawable-mdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
BIN
android/sample/src/main/res/drawable-xhdpi/ic_launcher.png
Normal file
BIN
android/sample/src/main/res/drawable-xhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
BIN
android/sample/src/main/res/drawable-xxhdpi/ic_launcher.png
Normal file
BIN
android/sample/src/main/res/drawable-xxhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
BIN
android/sample/src/main/res/drawable-xxxhdpi/ic_launcher.png
Normal file
BIN
android/sample/src/main/res/drawable-xxxhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.8 KiB |
5
android/sample/src/main/res/values/strings.xml
Normal file
5
android/sample/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<resources>
|
||||
<string name="app_name">Sonar</string>
|
||||
</resources>
|
||||
7
android/sample/src/main/res/values/styles.xml
Normal file
7
android/sample/src/main/res/values/styles.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<resources>
|
||||
<style name="NoTitleBarWhiteBG" parent="Theme.AppCompat.Light">
|
||||
<item name="android:textColor">#000000</item>
|
||||
</style>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user