Initial commit 🎉
fbshipit-source-id: b6fc29740c6875d2e78953b8a7123890a67930f2 Co-authored-by: Sebastian McKenzie <sebmck@fb.com> Co-authored-by: John Knox <jknox@fb.com> Co-authored-by: Emil Sjölander <emilsj@fb.com> Co-authored-by: Pritesh Nandgaonkar <prit91@fb.com>
This commit is contained in:
29
android/sample/AndroidManifest.xml
Normal file
29
android/sample/AndroidManifest.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.facebook.sonar.sample">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="15"
|
||||
android:targetSdkVersion="24"
|
||||
/>
|
||||
|
||||
<application
|
||||
android:name=".SonarSampleApplication"
|
||||
android:label="@string/app_name"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:allowBackup="false"
|
||||
android:theme="@style/NoTitleBarWhiteBG">
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
|
||||
</manifest>
|
||||
63
android/sample/build.gradle
Normal file
63
android/sample/build.gradle
Normal file
@@ -0,0 +1,63 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
|
||||
compileSdkVersion rootProject.compileSdkVersion
|
||||
buildToolsVersion rootProject.buildToolsVersion
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.minSdkVersion
|
||||
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
|
||||
applicationId "com.facebook.sonar.sample"
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
sourceSets {
|
||||
main {
|
||||
manifest.srcFile './AndroidManifest.xml'
|
||||
java {
|
||||
srcDir 'src'
|
||||
}
|
||||
res {
|
||||
srcDir 'res'
|
||||
}
|
||||
}
|
||||
}
|
||||
packagingOptions {
|
||||
pickFirst 'lib/armeabi-v7a/libfb.so'
|
||||
pickFirst 'lib/x86/libfb.so'
|
||||
pickFirst 'lib/x86_64/libfb.so'
|
||||
pickFirst 'lib/arm64-v8a/libfb.so'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation 'com.android.support:appcompat-v7:26.1.0'
|
||||
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
|
||||
implementation 'com.android.support:design:26.1.0'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
// ...
|
||||
// Litho
|
||||
implementation 'com.facebook.litho:litho-core:0.15.0'
|
||||
implementation 'com.facebook.litho:litho-widget:0.15.0'
|
||||
compileOnly 'com.facebook.litho:litho-annotations:0.15.0'
|
||||
|
||||
annotationProcessor 'com.facebook.litho:litho-processor:0.15.0'
|
||||
|
||||
// SoLoader
|
||||
implementation 'com.facebook.soloader:soloader:0.4.1'
|
||||
|
||||
// For integration with Fresco
|
||||
implementation 'com.facebook.litho:litho-fresco:0.15.0'
|
||||
|
||||
// For testing
|
||||
testImplementation 'com.facebook.litho:litho-testing:0.15.0'
|
||||
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
|
||||
implementation project(':android')
|
||||
//implementation project(':sonar')
|
||||
}
|
||||
BIN
android/sample/debug.keystore
Normal file
BIN
android/sample/debug.keystore
Normal file
Binary file not shown.
3
android/sample/debug.keystore.properties
Normal file
3
android/sample/debug.keystore.properties
Normal file
@@ -0,0 +1,3 @@
|
||||
key.alias=androiddebugkey
|
||||
key.store.password=android
|
||||
key.alias.password=android
|
||||
BIN
android/sample/res/drawable-hdpi/ic_launcher.png
Normal file
BIN
android/sample/res/drawable-hdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
BIN
android/sample/res/drawable-mdpi/ic_launcher.png
Normal file
BIN
android/sample/res/drawable-mdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
BIN
android/sample/res/drawable-xhdpi/ic_launcher.png
Normal file
BIN
android/sample/res/drawable-xhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
BIN
android/sample/res/drawable-xxhdpi/ic_launcher.png
Normal file
BIN
android/sample/res/drawable-xxhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
BIN
android/sample/res/drawable-xxxhdpi/ic_launcher.png
Normal file
BIN
android/sample/res/drawable-xxxhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.8 KiB |
5
android/sample/res/values/strings.xml
Normal file
5
android/sample/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/res/values/styles.xml
Normal file
7
android/sample/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>
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.sonar.sample;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import com.facebook.litho.ComponentContext;
|
||||
import com.facebook.litho.LithoView;
|
||||
|
||||
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,105 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.sonar.sample;
|
||||
|
||||
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.widget.Text;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.FormBody.Builder;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import com.facebook.litho.ClickEvent;
|
||||
import android.util.Log;
|
||||
import java.io.IOException;
|
||||
import com.facebook.litho.annotations.OnEvent;
|
||||
|
||||
@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,50 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.sonar.sample;
|
||||
|
||||
import android.app.Application;
|
||||
import android.net.Network;
|
||||
import android.support.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.facebook.litho.sonar.LithoSonarDescriptors;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
import com.facebook.sonar.android.utils.SonarUtils;
|
||||
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.network.NetworkResponseFormatter;
|
||||
import okhttp3.OkHttpClient;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SonarSampleApplication extends Application {
|
||||
|
||||
static public 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.start();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user