17 package io.grpc.interop.cpp;
19 import android.content.Context;
20 import android.os.AsyncTask;
21 import android.os.Bundle;
22 import android.support.v7.app.AppCompatActivity;
23 import android.text.TextUtils;
24 import android.text.method.ScrollingMovementMethod;
25 import android.view.View;
26 import android.view.inputmethod.InputMethodManager;
27 import android.widget.Button;
28 import android.widget.EditText;
29 import android.widget.TextView;
35 System.loadLibrary(
"grpc-interop");
45 protected void onCreate(Bundle savedInstanceState) {
46 super.onCreate(savedInstanceState);
47 setContentView(R.layout.activity_interop);
48 sendButton = (Button) findViewById(R.id.ping_pong_button);
49 hostEdit = (EditText) findViewById(R.id.host_edit_text);
50 portEdit = (EditText) findViewById(R.id.port_edit_text);
51 resultText = (TextView) findViewById(R.id.grpc_result_text);
52 resultText.setMovementMethod(
new ScrollingMovementMethod());
65 ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
66 .hideSoftInputFromWindow(
hostEdit.getWindowToken(), 0);
71 AsyncTask.THREAD_POOL_EXECUTOR,
76 private static class GrpcTask extends AsyncTask<String, Void, String> {
80 this.activityReference =
new WeakReference<InteropActivity>(activity);
85 String host = params[0];
86 String portStr = params[1];
87 int port = TextUtils.isEmpty(portStr) ? 50051 : Integer.valueOf(portStr);
99 if (activity ==
null || isCancelled()) {
102 TextView
resultText = (TextView) activity.findViewById(R.id.grpc_result_text);
103 Button
sendButton = (Button) activity.findViewById(R.id.ping_pong_button);
109 public static native
boolean doEmpty(String host,
int port,
boolean useTls);
111 public static native
boolean doLargeUnary(String host,
int port,
boolean useTls);
113 public static native
boolean doEmptyStream(String host,
int port,
boolean useTls);
119 public static native
boolean doPingPong(String host,
int port,
boolean useTls);