Change variables which never should change to 'final'
This commit is contained in:
@@ -82,9 +82,9 @@ public class DiscoverActivity extends Activity
|
|||||||
public void onItemClick(AdapterView<?> parent, View view,
|
public void onItemClick(AdapterView<?> parent, View view,
|
||||||
int position, long id)
|
int position, long id)
|
||||||
{
|
{
|
||||||
ServiceInfoWrapper info = (ServiceInfoWrapper) parent.getItemAtPosition(position);
|
final ServiceInfoWrapper info = (ServiceInfoWrapper) parent.getItemAtPosition(position);
|
||||||
Intent i = new Intent(getApplicationContext(), ListenActivity.class);
|
final Intent i = new Intent(getApplicationContext(), ListenActivity.class);
|
||||||
Bundle b = new Bundle();
|
final Bundle b = new Bundle();
|
||||||
b.putString("address", info.getAddress());
|
b.putString("address", info.getAddress());
|
||||||
b.putInt("port", info.getPort());
|
b.putInt("port", info.getPort());
|
||||||
b.putString("name", info.getName());
|
b.putString("name", info.getName());
|
||||||
|
|||||||
@@ -39,14 +39,14 @@ public class ListenActivity extends Activity
|
|||||||
String _name;
|
String _name;
|
||||||
|
|
||||||
Thread _listenThread;
|
Thread _listenThread;
|
||||||
private void streamAudio(Socket socket) throws IllegalArgumentException, IllegalStateException, IOException
|
private void streamAudio(final Socket socket) throws IllegalArgumentException, IllegalStateException, IOException
|
||||||
{
|
{
|
||||||
Log.i(TAG, "Setting up stream");
|
Log.i(TAG, "Setting up stream");
|
||||||
|
|
||||||
int frequency = 11025;
|
final int frequency = 11025;
|
||||||
int channelConfiguration = AudioFormat.CHANNEL_OUT_MONO;
|
final int channelConfiguration = AudioFormat.CHANNEL_OUT_MONO;
|
||||||
int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
|
final int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
|
||||||
int bufferSize = AudioTrack.getMinBufferSize(frequency, channelConfiguration, audioEncoding);
|
final int bufferSize = AudioTrack.getMinBufferSize(frequency, channelConfiguration, audioEncoding);
|
||||||
|
|
||||||
final AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
|
final AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
|
||||||
frequency,
|
frequency,
|
||||||
@@ -57,14 +57,14 @@ public class ListenActivity extends Activity
|
|||||||
|
|
||||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||||
|
|
||||||
InputStream is = socket.getInputStream();
|
final InputStream is = socket.getInputStream();
|
||||||
int read = 0;
|
int read = 0;
|
||||||
|
|
||||||
audioTrack.play();
|
audioTrack.play();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
byte [] buffer = new byte[bufferSize*2];
|
final byte [] buffer = new byte[bufferSize*2];
|
||||||
|
|
||||||
while(socket.isConnected() && read != -1 && Thread.currentThread().isInterrupted() == false)
|
while(socket.isConnected() && read != -1 && Thread.currentThread().isInterrupted() == false)
|
||||||
{
|
{
|
||||||
@@ -88,7 +88,7 @@ public class ListenActivity extends Activity
|
|||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
Bundle b = getIntent().getExtras();
|
final Bundle b = getIntent().getExtras();
|
||||||
_address = b.getString("address");
|
_address = b.getString("address");
|
||||||
_port = b.getInt("port");
|
_port = b.getInt("port");
|
||||||
_name = b.getString("name");
|
_name = b.getString("name");
|
||||||
@@ -115,7 +115,7 @@ public class ListenActivity extends Activity
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Socket socket = new Socket(_address, _port);
|
final Socket socket = new Socket(_address, _port);
|
||||||
streamAudio(socket);
|
streamAudio(socket);
|
||||||
}
|
}
|
||||||
catch (UnknownHostException e)
|
catch (UnknownHostException e)
|
||||||
|
|||||||
@@ -56,30 +56,30 @@ public class MonitorActivity extends Activity
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
int frequency = 11025;
|
final int frequency = 11025;
|
||||||
int channelConfiguration = AudioFormat.CHANNEL_IN_MONO;
|
final int channelConfiguration = AudioFormat.CHANNEL_IN_MONO;
|
||||||
int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
|
final int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
|
||||||
|
|
||||||
int bufferSize = AudioRecord.getMinBufferSize(frequency, channelConfiguration, audioEncoding);
|
final int bufferSize = AudioRecord.getMinBufferSize(frequency, channelConfiguration, audioEncoding);
|
||||||
AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
|
final AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
|
||||||
frequency, channelConfiguration,
|
frequency, channelConfiguration,
|
||||||
audioEncoding, bufferSize);
|
audioEncoding, bufferSize);
|
||||||
|
|
||||||
final int byteBufferSize = bufferSize*2;
|
final int byteBufferSize = bufferSize*2;
|
||||||
byte[] buffer = new byte[bufferSize*2];
|
final byte[] buffer = new byte[bufferSize*2];
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
audioRecord.startRecording();
|
audioRecord.startRecording();
|
||||||
|
|
||||||
OutputStream out = socket.getOutputStream();
|
final OutputStream out = socket.getOutputStream();
|
||||||
|
|
||||||
socket.setSendBufferSize(byteBufferSize);
|
socket.setSendBufferSize(byteBufferSize);
|
||||||
Log.d(TAG, "Socket send buffer size: " + socket.getSendBufferSize());
|
Log.d(TAG, "Socket send buffer size: " + socket.getSendBufferSize());
|
||||||
|
|
||||||
while (socket.isConnected() && Thread.currentThread().isInterrupted() == false)
|
while (socket.isConnected() && Thread.currentThread().isInterrupted() == false)
|
||||||
{
|
{
|
||||||
int read = audioRecord.read(buffer, 0, bufferSize);
|
final int read = audioRecord.read(buffer, 0, bufferSize);
|
||||||
out.write(buffer, 0, read);
|
out.write(buffer, 0, read);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ public class MonitorActivity extends Activity
|
|||||||
serverSocket = new ServerSocket(0);
|
serverSocket = new ServerSocket(0);
|
||||||
|
|
||||||
// Store the chosen port.
|
// Store the chosen port.
|
||||||
int localPort = serverSocket.getLocalPort();
|
final int localPort = serverSocket.getLocalPort();
|
||||||
|
|
||||||
// Register the service so that parent devices can
|
// Register the service so that parent devices can
|
||||||
// locate the child device
|
// locate the child device
|
||||||
@@ -202,9 +202,9 @@ public class MonitorActivity extends Activity
|
|||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerService(int port)
|
private void registerService(final int port)
|
||||||
{
|
{
|
||||||
NsdServiceInfo serviceInfo = new NsdServiceInfo();
|
final NsdServiceInfo serviceInfo = new NsdServiceInfo();
|
||||||
serviceInfo.setServiceName("ProtectBabyMonitor");
|
serviceInfo.setServiceName("ProtectBabyMonitor");
|
||||||
serviceInfo.setServiceType("_babymonitor._tcp.");
|
serviceInfo.setServiceType("_babymonitor._tcp.");
|
||||||
serviceInfo.setPort(port);
|
serviceInfo.setPort(port);
|
||||||
|
|||||||
Reference in New Issue
Block a user