gt:     if (null != mRecordButton) {
context: /**
   * This file is part of Audioboo, an android program for audio blogging.
   * Copyright (C) 2011 Audioboo Ltd.
   * Copyright (C) 2010,2011 Audioboo Ltd.
   * All rights reserved.
   *
   * Author: Jens Finkhaeuser <jens@finkhaeuser.de>
   *
   * $Id$
   **/
  
  package fm.audioboo.application;
  
  import android.app.Activity;
  
  import android.content.Context;
  import android.content.Intent;
  import android.content.DialogInterface;
  import android.content.res.Configuration;
  
  import android.os.Bundle;
  import android.os.Handler;
  import android.os.Message;
  import android.os.Vibrator;
  
  import android.media.AudioManager;
  import android.media.MediaPlayer;
  
  import android.view.View;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.KeyEvent;
  
  import android.widget.CompoundButton;
  import android.widget.TextView;
  import android.widget.ViewAnimator;
  import android.widget.Toast;
  import android.widget.Button;
  
  import fm.audioboo.widget.RecordButton;
  import fm.audioboo.widget.SpectralView;
  import fm.audioboo.widget.BooPlayerView;
  import fm.audioboo.widget.PieProgressView;
  
  import fm.audioboo.data.BooLocation;
  import fm.audioboo.data.DestinationInfo;
  import fm.audioboo.data.User;
  
  import android.view.animation.Animation;
  import android.view.animation.AnimationUtils;
  
  import android.app.Dialog;
  import android.app.AlertDialog;
  
  import android.location.Location;
  
  import android.net.Uri;
  
  import org.apache.http.NameValuePair;
  
  import java.util.List;
  import java.util.Date;
  
  import java.io.File;
  
  import java.util.List;
  import java.util.LinkedList;
  
  import android.util.Log;
  
  /**
   * The RecordActivity allows for recording (and playing back) of Boos, and
   * launches PublishAcitivity.
   **/
  public class RecordActivity extends Activity
  {
    /***************************************************************************
     * Private constants
     **/
    // Log ID
    private static final String LTAG  = "RecordActivity";
  
    // Dialog IDs.
    private static final int  DIALOG_RECORDING_ERROR        = 0;
    private static final int  DIALOG_DRAFT                  = 1;
  
    // Vibration duration in msec - half a second seems about right.
    private static final long VIBRATE_DURATION              = 500;
  
    // Activity codes
    private static final int  ACTIVITY_PUBLISH              = 0;
  
  
    /***************************************************************************
     * Public constants
     **/
    // Extra names
    public static final String EXTRA_BOO_FILENAME = "fm.audioboo.extras.boo-filename";
  
  
    /***************************************************************************
     * Data members
     **/
    // Recorder instance
    private BooRecorder     mBooRecorder;
    // Temporary place to store mBoo.getDuration()
    private double          mRecordingOffset;
  
    // The record activity essentially represents a Boo, even though it's not
    // filled with all possible bits of information yet. We (re-)create this
    // Boo whenever we reset the recorder.
    private DestinationInfo mDestinationInfo;
    private String          mNewTitle;
    private Boo             mBoo;
  
    // Time limit for recordings; we'll grab that at startup.
    private int             mRecordingTimeLimit;
  
    // Reference to UI elements
    private RecordButton    mRecordButton;
    private SpectralView    mSpectralView;
    private PieProgressView mPieProgress;
    private TextView        mTextProgress;
    private Button          mRestartButton;
    private Button          mPublishButton;
  
    // Last error. Used and cleared in onCreateDialog
    private int             mErrorCode = -1;
  
    // Recording callbacks
    private Handler         mRecordingHandler = new Handler(new Handler.Callback()
    {
      public boolean handleMessage(Message m)
      {
        switch (m.what) {
          case FLACRecorder.MSG_AMPLITUDES:
            FLACRecorder.Amplitudes amp = (FLACRecorder.Amplitudes) m.obj;
            updateRecordingState(amp);
            break;
  
          case FLACRecorder.MSG_OK:
            // Ignore
            break;
  
          case BooRecorder.MSG_END_OF_RECORDING:
            updateButtons();
            break;
  
          default:
            mBooRecorder.stop();
            mErrorCode = m.what;
            showDialog(DIALOG_RECORDING_ERROR);
            break;
        }
  
        return true;
      }
    });
  
  
    /***************************************************************************
     * Implementation
     **/
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.record);
  
      Intent intent = getIntent();
  
      // See if we perhaps are launched via ACTION_VIEW;
      Uri dataUri = intent.getData();
      if (null != dataUri) {
        DestinationInfo info = new DestinationInfo();
  
        List<NameValuePair> params = UriUtils.getQuery(dataUri);
        for (NameValuePair pair : params) {
          String name = pair.getName();
          if (name.equals("destination[stream_id]")) {
            try {
              info.mDestinationId = Integer.valueOf(pair.getValue());
              info.mIsChannel = true;
            } catch (NumberFormatException ex) {
              info.mDestinationId = -1;
            }
          }
  
          else if (name.equals("destination[recipient_id]")) {
            try {
              info.mDestinationId = Integer.valueOf(pair.getValue());
              info.mIsChannel = false;
            } catch (NumberFormatException ex) {
              info.mDestinationId = -1;
            }
          }
  
          else if (name.equals("destination[parent_id]")) {
            try {
              info.mInReplyTo = Integer.valueOf(pair.getValue());
            } catch (NumberFormatException ex) {
              info.mInReplyTo = -1;
            }
          }
  
          else if (name.equals("destination[title]")) {
            mNewTitle = pair.getValue();
          }
  
          else if (name.equals("destination_name")) {
            info.mDestinationName = pair.getValue();
          }
        }
  
        if (-1 == info.mDestinationId || null == info.mDestinationName) {
          Toast.makeText(this, R.string.record_invalid_uri, Toast.LENGTH_LONG).show();
          finish();
          return;
        }
  
        mDestinationInfo = info;
      }
  
      // If we're not getting a data URI, we're not recording a boo with a
      // destination. We might still be recording a fresh boo, or we might be
      // adding to an existing one. We'll know by whether or not the
      // EXTRA_BOO_FILENAME parameter is given.
      Bundle extras = intent.getExtras();
      if (null != extras) {
        String filename = extras.getString(EXTRA_BOO_FILENAME);
        Boo boo = Boo.constructFromFile(filename);
        if (null == boo) {
          throw new IllegalArgumentException("Boo file '" + filename + "' could "
              + "not be loaded.");
        }
        mBoo = boo;
      }
  
      if (null == mBoo) {
        mBoo = Globals.get().getBooManager().createBoo();
        mBoo.mData.mTitle = mNewTitle;
      }
      // Log.d(LTAG, "Boo: " + mBoo);
  
      // Grab recording time limit.
      mRecordingTimeLimit = Globals.get().getRecordingLimit();
    }
  
  
  
    private void writeBoo()
    {
      // We only have destination info if we're creating a new boo anyway.
      if (null != mDestinationInfo) {
        mBoo.mData.mDestinationInfo = mDestinationInfo;
        if (!mDestinationInfo.mIsChannel) {
          mBoo.mData.mIsMessage = true;
        }
      }
  
      // Always overwrite the user. We're dealing with drafts, after all...
      mBoo.mData.mUser = Globals.get().mAccount;
  
      mBoo.writeToFile();
    }
  
  
  
    private void startRecording()
    {
      // Stop playback & hide player.
      Globals.get().mPlayer.stop();
      hidePlayer();
  
      // Force screen to stay on.
      mRecordButton.setKeepScreenOn(true);
  
      mRecordingOffset = mBoo.getDuration();
  
      // Log.d(LTAG, "Resume recording!");
      mBooRecorder.start();
      mSpectralView.startAnimation();
  
      // Update button availability.
      disableSecondaryButtons();
    }
  
  
  
    private void stopRecording()
    {
      // Release the lock if we're holding it.
      mRecordButton.setKeepScreenOn(false);
  
      // Log.d(LTAG, "Stop animating.");
      mSpectralView.stopAnimation();
  
      // Log.d(LTAG, "Pause recording.");
      mBooRecorder.stop();
  
      // Show & initialize player.
      showPlayer();
      Globals.get().mPlayer.play(mBoo, false);
    }
  
  
  
    private void disableSecondaryButtons()
    {
      if (null != mRestartButton) {
        mRestartButton.setEnabled(false);
      }
      if (null != mPublishButton) {
        mPublishButton.setEnabled(false);
      }
    }
  
  
  
    private void updateButtons()
    {
      // Update button availability.
      double duration = mBoo.getDuration();
      if (null != mRestartButton) {
        mRestartButton.setEnabled(duration > 0.0f);
      }
      if (null != mPublishButton) {
        mPublishButton.setEnabled(duration > 0.0f);
      }
  