17 package io.grpc.helloworldexample.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;
30 import android.widget.Toast;
36 System.loadLibrary(
"grpc-helloworld");
50 protected void onCreate(Bundle savedInstanceState) {
51 super.onCreate(savedInstanceState);
52 setContentView(R.layout.activity_helloworld);
53 sendButton = (Button) findViewById(R.id.send_button);
54 serverButton = (Button) findViewById(R.id.server_button);
55 hostEdit = (EditText) findViewById(R.id.host_edit_text);
56 portEdit = (EditText) findViewById(R.id.port_edit_text);
57 messageEdit = (EditText) findViewById(R.id.message_edit_text);
58 serverPortEdit = (EditText) findViewById(R.id.server_port_edit_text);
59 resultText = (TextView) findViewById(R.id.grpc_response_text);
60 resultText.setMovementMethod(
new ScrollingMovementMethod());
78 ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
79 .hideSoftInputFromWindow(
hostEdit.getWindowToken(), 0);
84 AsyncTask.THREAD_POOL_EXECUTOR,
95 Toast.makeText(
this,
"Server stopped", Toast.LENGTH_SHORT).show();
99 int port = TextUtils.isEmpty(portStr) ? 50051 : Integer.valueOf(portStr);
102 Toast.makeText(
this,
"Server started on port " +
port, Toast.LENGTH_SHORT).show();
110 this.activityReference =
new WeakReference<HelloworldActivity>(activity);
115 int port = params[0];
117 if (activity !=
null) {
124 private static class GrpcTask extends AsyncTask<String, Void, String> {
128 this.activityReference =
new WeakReference<HelloworldActivity>(activity);
133 String host = params[0];
135 String portStr = params[2];
136 int port = TextUtils.isEmpty(portStr) ? 50051 : Integer.valueOf(portStr);
143 if (activity ==
null || isCancelled()) {
146 TextView
resultText = (TextView) activity.findViewById(R.id.grpc_response_text);
147 Button
sendButton = (Button) activity.findViewById(R.id.send_button);