1 /* 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 package com.google.media.networktester; 12 13 import android.app.Activity; 14 import android.os.Bundle; 15 import android.os.Handler; 16 import android.view.View; 17 import android.view.View.OnClickListener; 18 import android.view.WindowManager; 19 import android.widget.Button; 20 21 public class MainActivity extends Activity { 22 Button startButton; 23 Button stopButton; 24 NetworkTester networkTester; 25 Handler mainThreadHandler; 26 27 @Override onCreate(Bundle savedInstanceState)28 protected void onCreate(Bundle savedInstanceState) { 29 super.onCreate(savedInstanceState); 30 setContentView(R.layout.activity_main); 31 startButton = (Button) findViewById(R.id.start_button); 32 startButton.setOnClickListener(new OnClickListener() { 33 @Override 34 public void onClick(View v) { 35 startTest(); 36 } 37 }); 38 stopButton = (Button) findViewById(R.id.stop_button); 39 stopButton.setOnClickListener(new OnClickListener() { 40 @Override 41 public void onClick(View v) { 42 stopTest(); 43 } 44 }); 45 mainThreadHandler = new Handler(); 46 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 47 } 48 startTest()49 private void startTest() { 50 if (networkTester == null) { 51 networkTester = new NetworkTester(); 52 networkTester.start(); 53 } 54 } 55 stopTest()56 private void stopTest() { 57 if (networkTester != null) { 58 networkTester.interrupt(); 59 networkTester = null; 60 } 61 } 62 } 63