InteropActivity.java
Go to the documentation of this file.
1 /*
2  * Copyright 2018, gRPC Authors All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package io.grpc.interop.cpp;
18 
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 java.lang.ref.WeakReference;
31 
32 public class InteropActivity extends AppCompatActivity {
33 
34  static {
35  System.loadLibrary("grpc-interop");
36  }
37 
38  private Button sendButton;
39  private EditText hostEdit;
40  private EditText portEdit;
41  private TextView resultText;
42  private GrpcTask grpcTask;
43 
44  @Override
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());
53  }
54 
55  @Override
56  protected void onPause() {
57  super.onPause();
58  if (grpcTask != null) {
59  grpcTask.cancel(true);
60  grpcTask = null;
61  }
62  }
63 
64  public void doPingPong(View view) {
65  ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
66  .hideSoftInputFromWindow(hostEdit.getWindowToken(), 0);
67  sendButton.setEnabled(false);
68  resultText.setText("");
69  grpcTask = new GrpcTask(this);
70  grpcTask.executeOnExecutor(
71  AsyncTask.THREAD_POOL_EXECUTOR,
72  hostEdit.getText().toString(),
73  portEdit.getText().toString());
74  }
75 
76  private static class GrpcTask extends AsyncTask<String, Void, String> {
77  private final WeakReference<InteropActivity> activityReference;
78 
79  private GrpcTask(InteropActivity activity) {
80  this.activityReference = new WeakReference<InteropActivity>(activity);
81  }
82 
83  @Override
84  protected String doInBackground(String... params) {
85  String host = params[0];
86  String portStr = params[1];
87  int port = TextUtils.isEmpty(portStr) ? 50051 : Integer.valueOf(portStr);
88  // TODO(ericgribkoff) Support other test cases in the app UI
89  if (doPingPong(host, port, false)) {
90  return "Success";
91  } else {
92  return "Failure";
93  }
94  }
95 
96  @Override
97  protected void onPostExecute(String result) {
98  InteropActivity activity = activityReference.get();
99  if (activity == null || isCancelled()) {
100  return;
101  }
102  TextView resultText = (TextView) activity.findViewById(R.id.grpc_result_text);
103  Button sendButton = (Button) activity.findViewById(R.id.ping_pong_button);
104  resultText.setText(result);
105  sendButton.setEnabled(true);
106  }
107  }
108 
109  public static native boolean doEmpty(String host, int port, boolean useTls);
110 
111  public static native boolean doLargeUnary(String host, int port, boolean useTls);
112 
113  public static native boolean doEmptyStream(String host, int port, boolean useTls);
114 
115  public static native boolean doRequestStreaming(String host, int port, boolean useTls);
116 
117  public static native boolean doResponseStreaming(String host, int port, boolean useTls);
118 
119  public static native boolean doPingPong(String host, int port, boolean useTls);
120 }
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
java.lang
io.grpc.interop.cpp.InteropActivity.GrpcTask.GrpcTask
GrpcTask(InteropActivity activity)
Definition: InteropActivity.java:79
io.grpc.interop.cpp.InteropActivity.hostEdit
EditText hostEdit
Definition: InteropActivity.java:39
io.grpc.interop.cpp.InteropActivity.portEdit
EditText portEdit
Definition: InteropActivity.java:40
io.grpc.interop.cpp.InteropActivity.onCreate
void onCreate(Bundle savedInstanceState)
Definition: InteropActivity.java:45
io.grpc.interop.cpp.InteropActivity.resultText
TextView resultText
Definition: InteropActivity.java:41
io.grpc.interop.cpp.InteropActivity.doEmptyStream
static native boolean doEmptyStream(String host, int port, boolean useTls)
io.grpc.interop.cpp.InteropActivity.GrpcTask.onPostExecute
void onPostExecute(String result)
Definition: InteropActivity.java:97
io.grpc.interop.cpp.InteropActivity.GrpcTask.activityReference
final WeakReference< InteropActivity > activityReference
Definition: InteropActivity.java:77
io.grpc.interop.cpp.InteropActivity.doEmpty
static native boolean doEmpty(String host, int port, boolean useTls)
io.grpc.interop.cpp.InteropActivity.onPause
void onPause()
Definition: InteropActivity.java:56
io.grpc.interop.cpp.InteropActivity.sendButton
Button sendButton
Definition: InteropActivity.java:38
io.grpc.interop.cpp.InteropActivity.GrpcTask.doInBackground
String doInBackground(String... params)
Definition: InteropActivity.java:84
tests.unit._exit_scenarios.port
port
Definition: _exit_scenarios.py:179
java
io.grpc.interop.cpp.InteropActivity
Definition: InteropActivity.java:32
io.grpc.interop.cpp.InteropActivity.GrpcTask
Definition: InteropActivity.java:76
opencensus.proto.stats.v1.stats_pb2.View
View
Definition: stats_pb2.py:445
io.grpc.interop.cpp.InteropActivity.doResponseStreaming
static native boolean doResponseStreaming(String host, int port, boolean useTls)
io.grpc.interop.cpp.InteropActivity.grpcTask
GrpcTask grpcTask
Definition: InteropActivity.java:42
io.grpc.interop.cpp.InteropActivity.doLargeUnary
static native boolean doLargeUnary(String host, int port, boolean useTls)
io.grpc.interop.cpp.InteropActivity.doRequestStreaming
static native boolean doRequestStreaming(String host, int port, boolean useTls)
io.grpc.interop.cpp.InteropActivity.doPingPong
void doPingPong(View view)
Definition: InteropActivity.java:64


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:22