1/*
2 *  Copyright (c) 2013 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
11package org.webrtc.app;
12
13import android.app.Activity;
14import android.content.Context;
15import android.content.pm.ActivityInfo;
16import android.media.AudioManager;
17import android.os.Bundle;
18import android.util.Log;
19import android.view.View;
20import android.widget.Button;
21
22public class OpenSlDemo extends Activity implements View.OnClickListener {
23  private static final String TAG = "WEBRTC";
24
25  private Button btStartStopCall;
26  private boolean isRunning = false;
27
28  private OpenSlRunner runner;
29
30  // Called when activity is created.
31  @Override
32  public void onCreate(Bundle savedInstanceState) {
33    super.onCreate(savedInstanceState);
34
35    setContentView(R.layout.open_sl_demo);
36
37    // Direct hardware volume controls to affect the voice call audio stream.
38    setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
39
40    btStartStopCall = (Button) findViewById(R.id.btStartStopCall);
41    btStartStopCall.setOnClickListener(this);
42    findViewById(R.id.btExit).setOnClickListener(this);
43
44    runner = new OpenSlRunner();
45    // Native code calls back into JVM to be able to configure OpenSL to low
46    // latency mode. Provide the context needed to do this.
47    OpenSlRunner.RegisterApplicationContext(getApplicationContext());
48  }
49
50  // Called before activity is destroyed.
51  @Override
52  public void onDestroy() {
53    Log.d(TAG, "onDestroy");
54    super.onDestroy();
55  }
56
57  private void startOrStop() {
58    if (isRunning) {
59      OpenSlRunner.Stop();
60      btStartStopCall.setText(R.string.startCall);
61      isRunning = false;
62    } else if (!isRunning){
63      OpenSlRunner.Start();
64      btStartStopCall.setText(R.string.stopCall);
65      isRunning = true;
66    }
67  }
68
69  public void onClick(View arg0) {
70    switch (arg0.getId()) {
71      case R.id.btStartStopCall:
72        startOrStop();
73        break;
74      case R.id.btExit:
75        finish();
76        break;
77    }
78  }
79
80}
81