Add SonarDiagnosticActivity to android

Summary:
Open the screen by running adb shell
am start -n com.facebook.wakizashi/com.facebook.sonar.android.diagnostics.SonarDiagnosticActivity

Reviewed By: passy

Differential Revision: D8954095

fbshipit-source-id: b4a638bc0ba2f69a69c121c7c1c00fbe47476ee3
This commit is contained in:
John Knox
2018-08-03 07:34:36 -07:00
committed by Facebook Github Bot
parent c791a108f1
commit 3237b60ff1
2 changed files with 66 additions and 1 deletions

View File

@@ -24,7 +24,8 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.facebook.sonar.android.diagnostics.SonarDiagnosticActivity"
android:exported="true"/>
</application>
</manifest>

View File

@@ -0,0 +1,64 @@
package com.facebook.sonar.android.diagnostics;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.Toast;
import com.facebook.sonar.android.AndroidSonarClient;
import com.facebook.sonar.core.SonarClient;
import com.facebook.sonar.core.SonarStateUpdateListener;
import android.widget.LinearLayout;
import android.view.View;
import android.widget.TextView;
import android.widget.ScrollView;
public class SonarDiagnosticActivity extends Activity implements SonarStateUpdateListener {
private TextView textView;
private ScrollView scrollView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout root = new LinearLayout(this);
textView = new TextView(this);
scrollView = new ScrollView(this);
scrollView.addView(textView);
root.addView(scrollView);
setContentView(root);
}
protected void onStart() {
super.onStart();
SonarClient client = AndroidSonarClient.getInstance(this);
client.subscribeForUpdates(this);
textView.setText(client.getState());
}
protected void onResume() {
super.onResume();
scrollView.fullScroll(View.FOCUS_DOWN);
}
@Override
public void onUpdate() {
final Context context = this;
final String state = AndroidSonarClient.getInstance(context).getState();
runOnUiThread(new Runnable() {
@Override
public void run() {
textView.setText(state);
scrollView.fullScroll(View.FOCUS_DOWN);
}
});
}
protected void onStop() {
super.onStop();
SonarClient client = AndroidSonarClient.getInstance(this);
client.unsubscribe();
}
}