package com.ibm.mil.smartringer;

import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;

public final class NoiseMeter {
    public static final int METER_LIMIT = 32768;

    private static final int SAMPLE_RATE = 8000;
    private static final int MIN_BUFFER_SIZE = AudioRecord.getMinBufferSize(SAMPLE_RATE,
            AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);

    private AudioRecord mAudioRecord;

    public void start() {
        mAudioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, SAMPLE_RATE,
                AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, MIN_BUFFER_SIZE);
        mAudioRecord.startRecording();
    }

    public void stop() {
        if (mAudioRecord != null) {
            mAudioRecord.stop();
            mAudioRecord.release();
        }
    }

    public int getMaxAmplitude() {
        short[] buffer = new short[MIN_BUFFER_SIZE];

        if (mAudioRecord != null) {
            mAudioRecord.read(buffer, 0, MIN_BUFFER_SIZE);
        }

        int max = 0;
        for (short s : buffer) {
            int abs = Math.abs(s);
            if (abs > max) {
                max = abs;
            }
        }

        return max;
    }
}

@@ -1254,10 +1254,706 @@
 ;%0A    %7D%0A
+%0A    public static class Sampler %7B%0A        private NoiseMeter mNoiseMeter;%0A        private int mPollingRate;%0A        private Receiver mReceiver;%0A%0A        public Sampler(NoiseMeter noiseMeter, int pollingRate, Receiver receiver) %7B%0A            mNoiseMeter = noiseMeter;%0A            mPollingRate = pollingRate;%0A            mReceiver = receiver;%0A        %7D%0A%0A        public void startSampling() %7B%0A            // sample from noise meter and notify receiver of result%0A            mReceiver.receiveSample(1000);%0A        %7D%0A%0A        public void stopSampling() %7B%0A            // stop sampling from noise meter%0A        %7D%0A    %7D%0A%0A    public interface Receiver %7B%0A        void receiveSample(int amplitude);%0A    %7D%0A%0A
 %7D%0A

Create a nested Sampler class and Receiver interface inside NoiseMeter