phonegap.0.9.4

16:50:59.775 INFO  jd.cli.Main - Decompiling phonegap.0.9.4.jar
package com.phonegap;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import com.phonegap.api.PhonegapActivity;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import com.phonegap.api.PluginResult.Status;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class AccelListener
  extends Plugin
  implements SensorEventListener
{
  public static int STOPPED = 0;
  public static int STARTING = 1;
  public static int RUNNING = 2;
  public static int ERROR_FAILED_TO_START = 3;
  public float TIMEOUT = 30000.0F;
  float x;
  float y;
  float z;
  long timestamp;
  int status;
  long lastAccessTime;
  private SensorManager sensorManager;
  Sensor mSensor;
  
  public AccelListener()
  {
    x = 0.0F;
    y = 0.0F;
    z = 0.0F;
    timestamp = 0L;
    setStatus(STOPPED);
  }
  
  public void setContext(PhonegapActivity ctx)
  {
    super.setContext(ctx);
    sensorManager = ((SensorManager)ctx.getSystemService("sensor"));
  }
  
  public PluginResult execute(String action, JSONArray args, String callbackId)
  {
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";
    try
    {
      if (action.equals("getStatus"))
      {
        int i = getStatus();
        return new PluginResult(status, i);
      }
      if (action.equals("start"))
      {
        int i = start();
        return new PluginResult(status, i);
      }
      if (action.equals("stop"))
      {
        stop();
        return new PluginResult(status, 0);
      }
      if (action.equals("getAcceleration"))
      {
        if (this.status != RUNNING)
        {
          int r = start();
          if (r == ERROR_FAILED_TO_START) {
            return new PluginResult(PluginResult.Status.IO_EXCEPTION, ERROR_FAILED_TO_START);
          }
          long timeout = 2000L;
          while ((this.status == STARTING) && (timeout > 0L))
          {
            timeout -= 100L;
            try
            {
              Thread.sleep(100L);
            }
            catch (InterruptedException e)
            {
              e.printStackTrace();
            }
          }
          if (timeout == 0L) {
            return new PluginResult(PluginResult.Status.IO_EXCEPTION, ERROR_FAILED_TO_START);
          }
        }
        lastAccessTime = System.currentTimeMillis();
        JSONObject r = new JSONObject();
        r.put("x", x);
        r.put("y", y);
        r.put("z", z);
        
        r.put("timestamp", timestamp);
        return new PluginResult(status, r);
      }
      if (action.equals("setTimeout"))
      {
        try
        {
          float timeout = Float.parseFloat(args.getString(0));
          setTimeout(timeout);
          return new PluginResult(status, 0);
        }
        catch (NumberFormatException e)
        {
          status = PluginResult.Status.INVALID_ACTION;
          e.printStackTrace();
        }
        catch (JSONException e)
        {
          status = PluginResult.Status.JSON_EXCEPTION;
          e.printStackTrace();
        }
      }
      else if (action.equals("getTimeout"))
      {
        float f = getTimeout();
        return new PluginResult(status, f);
      }
      return new PluginResult(status, result);
    }
    catch (JSONException e) {}
    return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
  }
  
  public boolean isSynch(String action)
  {
    if (action.equals("getStatus")) {
      return true;
    }
    if (action.equals("getAcceleration"))
    {
      if (status == RUNNING) {
        return true;
      }
    }
    else if (action.equals("getTimeout")) {
      return true;
    }
    return false;
  }
  
  public void onDestroy()
  {
    stop();
  }
  
  public int start()
  {
    if ((status == RUNNING) || (status == STARTING)) {
      return status;
    }
    List<Sensor> list = sensorManager.getSensorList(1);
    if ((list != null) && (list.size() > 0))
    {
      mSensor = ((Sensor)list.get(0));
      sensorManager.registerListener(this, mSensor, 0);
      setStatus(STARTING);
      lastAccessTime = System.currentTimeMillis();
    }
    else
    {
      setStatus(ERROR_FAILED_TO_START);
    }
    return status;
  }
  
  public void stop()
  {
    if (status != STOPPED) {
      sensorManager.unregisterListener(this);
    }
    setStatus(STOPPED);
  }
  
  public void onAccuracyChanged(Sensor sensor, int accuracy) {}
  
  public void onSensorChanged(SensorEvent event)
  {
    if (sensor.getType() != 1) {
      return;
    }
    if (status == STOPPED) {
      return;
    }
    timestamp = System.currentTimeMillis();
    x = values[0];
    y = values[1];
    z = values[2];
    
    setStatus(RUNNING);
    if ((float)(timestamp - lastAccessTime) > TIMEOUT) {
      stop();
    }
  }
  
  public int getStatus()
  {
    return status;
  }
  
  public void setTimeout(float timeout)
  {
    TIMEOUT = timeout;
  }
  
  public float getTimeout()
  {
    return TIMEOUT;
  }
  
  private void setStatus(int status)
  {
    this.status = status;
  }
}

/* Location:
 * Qualified Name:     com.phonegap.AccelListener
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.phonegap;

import android.content.Intent;
import com.phonegap.api.PhonegapActivity;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import com.phonegap.api.PluginResult.Status;
import java.io.PrintStream;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class App
  extends Plugin
{
  public PluginResult execute(String action, JSONArray args, String callbackId)
  {
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";
    try
    {
      if (action.equals("clearCache")) {
        clearCache();
      } else if (action.equals("loadUrl")) {
        loadUrl(args.getString(0), args.optJSONObject(1));
      } else if (action.equals("cancelLoadUrl")) {
        cancelLoadUrl();
      } else if (action.equals("clearHistory")) {
        clearHistory();
      } else if (action.equals("addService")) {
        addService(args.getString(0), args.getString(1));
      }
      return new PluginResult(status, result);
    }
    catch (JSONException e) {}
    return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
  }
  
  public void clearCache()
  {
    ((DroidGap)ctx).clearCache();
  }
  
  public void loadUrl(String url, JSONObject props)
    throws JSONException
  {
    System.out.println("App.loadUrl(" + url + "," + props + ")");
    int wait = 0;
    if (props != null)
    {
      JSONArray keys = props.names();
      for (int i = 0; i < keys.length(); i++)
      {
        String key = keys.getString(i);
        if (key.equals("wait"))
        {
          wait = props.getInt(key);
        }
        else
        {
          Object value = props.get(key);
          if (value != null) {
            if (value.getClass().equals(String.class)) {
              ctx.getIntent().putExtra(key, (String)value);
            } else if (value.getClass().equals(Boolean.class)) {
              ctx.getIntent().putExtra(key, (Boolean)value);
            } else if (value.getClass().equals(Integer.class)) {
              ctx.getIntent().putExtra(key, (Integer)value);
            }
          }
        }
      }
    }
    if (wait > 0) {
      ((DroidGap)ctx).loadUrl(url, wait);
    } else {
      ((DroidGap)ctx).loadUrl(url);
    }
  }
  
  public void cancelLoadUrl()
  {
    ((DroidGap)ctx).cancelLoadUrl();
  }
  
  public void clearHistory()
  {
    ((DroidGap)ctx).clearHistory();
  }
  
  public void addService(String serviceType, String className)
  {
    ctx.addService(serviceType, className);
  }
}

/* Location:
 * Qualified Name:     com.phonegap.App
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.phonegap;

import android.media.AudioManager;
import com.phonegap.api.PhonegapActivity;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import com.phonegap.api.PluginResult.Status;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import org.json.JSONArray;
import org.json.JSONException;

public class AudioHandler
  extends Plugin
{
  HashMap<String, AudioPlayer> players;
  
  public AudioHandler()
  {
    players = new HashMap();
  }
  
  public PluginResult execute(String action, JSONArray args, String callbackId)
  {
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";
    try
    {
      if (action.equals("startRecordingAudio"))
      {
        startRecordingAudio(args.getString(0), args.getString(1));
      }
      else if (action.equals("stopRecordingAudio"))
      {
        stopRecordingAudio(args.getString(0));
      }
      else if (action.equals("startPlayingAudio"))
      {
        startPlayingAudio(args.getString(0), args.getString(1));
      }
      else if (action.equals("pausePlayingAudio"))
      {
        pausePlayingAudio(args.getString(0));
      }
      else if (action.equals("stopPlayingAudio"))
      {
        stopPlayingAudio(args.getString(0));
      }
      else
      {
        if (action.equals("getCurrentPositionAudio"))
        {
          long l = getCurrentPositionAudio(args.getString(0));
          return new PluginResult(status, (float)l);
        }
        if (action.equals("getDurationAudio"))
        {
          long l = getDurationAudio(args.getString(0), args.getString(1));
          return new PluginResult(status, (float)l);
        }
        if (action.equals("release"))
        {
          boolean b = release(args.getString(0));
          return new PluginResult(status, b);
        }
      }
      return new PluginResult(status, result);
    }
    catch (JSONException e)
    {
      e.printStackTrace();
    }
    return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
  }
  
  public boolean isSynch(String action)
  {
    if (action.equals("getCurrentPositionAudio")) {
      return true;
    }
    if (action.equals("getDurationAudio")) {
      return true;
    }
    return false;
  }
  
  public void onDestroy()
  {
    Set<Map.Entry<String, AudioPlayer>> s = players.entrySet();
    Iterator<Map.Entry<String, AudioPlayer>> it = s.iterator();
    while (it.hasNext())
    {
      Map.Entry<String, AudioPlayer> entry = (Map.Entry)it.next();
      AudioPlayer audio = (AudioPlayer)entry.getValue();
      audio.destroy();
    }
    players.clear();
  }
  
  private boolean release(String id)
  {
    if (!players.containsKey(id)) {
      return false;
    }
    AudioPlayer audio = (AudioPlayer)players.get(id);
    players.remove(id);
    audio.destroy();
    return true;
  }
  
  public void startRecordingAudio(String id, String file)
  {
    if (players.containsKey(id)) {
      return;
    }
    AudioPlayer audio = new AudioPlayer(this, id);
    players.put(id, audio);
    audio.startRecording(file);
  }
  
  public void stopRecordingAudio(String id)
  {
    AudioPlayer audio = (AudioPlayer)players.get(id);
    if (audio != null)
    {
      audio.stopRecording();
      players.remove(id);
    }
  }
  
  public void startPlayingAudio(String id, String file)
  {
    AudioPlayer audio = (AudioPlayer)players.get(id);
    if (audio == null)
    {
      audio = new AudioPlayer(this, id);
      players.put(id, audio);
    }
    audio.startPlaying(file);
  }
  
  public void pausePlayingAudio(String id)
  {
    AudioPlayer audio = (AudioPlayer)players.get(id);
    if (audio != null) {
      audio.pausePlaying();
    }
  }
  
  public void stopPlayingAudio(String id)
  {
    AudioPlayer audio = (AudioPlayer)players.get(id);
    if (audio != null) {
      audio.stopPlaying();
    }
  }
  
  public long getCurrentPositionAudio(String id)
  {
    AudioPlayer audio = (AudioPlayer)players.get(id);
    if (audio != null) {
      return audio.getCurrentPosition();
    }
    return -1L;
  }
  
  public long getDurationAudio(String id, String file)
  {
    AudioPlayer audio = (AudioPlayer)players.get(id);
    if (audio != null) {
      return audio.getDuration(file);
    }
    audio = new AudioPlayer(this, id);
    players.put(id, audio);
    return audio.getDuration(file);
  }
  
  public void setAudioOutputDevice(int output)
  {
    AudioManager audiMgr = (AudioManager)ctx.getSystemService("audio");
    if (output == 2) {
      audiMgr.setRouting(0, 2, -1);
    } else if (output == 1) {
      audiMgr.setRouting(0, 1, -1);
    } else {
      System.out.println("AudioHandler.setAudioOutputDevice() Error: Unknown output device.");
    }
  }
  
  public int getAudioOutputDevice()
  {
    AudioManager audiMgr = (AudioManager)ctx.getSystemService("audio");
    if (audiMgr.getRouting(0) == 1) {
      return 1;
    }
    if (audiMgr.getRouting(0) == 2) {
      return 2;
    }
    return -1;
  }
}

/* Location:
 * Qualified Name:     com.phonegap.AudioHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.phonegap;

import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.media.MediaRecorder;
import com.phonegap.api.PhonegapActivity;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;

public class AudioPlayer
  implements MediaPlayer.OnCompletionListener, MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener
{
  private static int MEDIA_NONE = 0;
  private static int MEDIA_STARTING = 1;
  private static int MEDIA_RUNNING = 2;
  private static int MEDIA_PAUSED = 3;
  private static int MEDIA_STOPPED = 4;
  private static int MEDIA_STATE = 1;
  private static int MEDIA_DURATION = 2;
  private static int MEDIA_ERROR = 9;
  private static int MEDIA_ERROR_PLAY_MODE_SET = 1;
  private static int MEDIA_ERROR_ALREADY_RECORDING = 2;
  private static int MEDIA_ERROR_STARTING_RECORDING = 3;
  private static int MEDIA_ERROR_RECORD_MODE_SET = 4;
  private static int MEDIA_ERROR_STARTING_PLAYBACK = 5;
  private static int MEDIA_ERROR_RESUME_STATE = 6;
  private static int MEDIA_ERROR_PAUSE_STATE = 7;
  private static int MEDIA_ERROR_STOP_STATE = 8;
  private AudioHandler handler;
  private String id;
  private int state = MEDIA_NONE;
  private String audioFile = null;
  private long duration = -1L;
  private MediaRecorder recorder = null;
  private String tempFile = null;
  private MediaPlayer mPlayer = null;
  private boolean prepareOnly = false;
  
  public AudioPlayer(AudioHandler handler, String id)
  {
    this.handler = handler;
    this.id = id;
    
    tempFile = "/sdcard/tmprecording.mp3";
  }
  
  public void destroy()
  {
    if (mPlayer != null)
    {
      stopPlaying();
      mPlayer.release();
      mPlayer = null;
    }
    if (recorder != null)
    {
      stopRecording();
      recorder.release();
      recorder = null;
    }
  }
  
  public void startRecording(String file)
  {
    if (mPlayer != null)
    {
      System.out.println("AudioPlayer Error: Can't record in play mode.");
      handler.sendJavascript("PhoneGap.Media.onStatus('" + id + "', " + MEDIA_ERROR + ", " + MEDIA_ERROR_PLAY_MODE_SET + ");");
    }
    else if (recorder == null)
    {
      audioFile = file;
      recorder = new MediaRecorder();
      recorder.setAudioSource(1);
      recorder.setOutputFormat(0);
      recorder.setAudioEncoder(0);
      recorder.setOutputFile(tempFile);
      try
      {
        recorder.prepare();
        recorder.start();
        setState(MEDIA_RUNNING);
        return;
      }
      catch (IllegalStateException e)
      {
        e.printStackTrace();
      }
      catch (IOException e)
      {
        e.printStackTrace();
      }
      handler.sendJavascript("PhoneGap.Media.onStatus('" + id + "', " + MEDIA_ERROR + ", " + MEDIA_ERROR_STARTING_RECORDING + ");");
    }
    else
    {
      System.out.println("AudioPlayer Error: Already recording.");
      handler.sendJavascript("PhoneGap.Media.onStatus('" + id + "', " + MEDIA_ERROR + ", " + MEDIA_ERROR_ALREADY_RECORDING + ");");
    }
  }
  
  public void moveFile(String file)
  {
    File f = new File(tempFile);
    f.renameTo(new File("/sdcard/" + file));
  }
  
  public void stopRecording()
  {
    if (recorder != null) {
      try
      {
        if (state == MEDIA_RUNNING)
        {
          recorder.stop();
          setState(MEDIA_STOPPED);
        }
        moveFile(audioFile);
      }
      catch (Exception e)
      {
        e.printStackTrace();
      }
    }
  }
  
  public void startPlaying(String file)
  {
    if (recorder != null)
    {
      System.out.println("AudioPlayer Error: Can't play in record mode.");
      handler.sendJavascript("PhoneGap.Media.onStatus('" + id + "', " + MEDIA_ERROR + ", " + MEDIA_ERROR_RECORD_MODE_SET + ");");
    }
    else if ((mPlayer == null) || (state == MEDIA_STOPPED))
    {
      try
      {
        if (mPlayer != null) {
          mPlayer.reset();
        } else {
          mPlayer = new MediaPlayer();
        }
        audioFile = file;
        if (isStreaming(file))
        {
          mPlayer.setDataSource(file);
          mPlayer.setAudioStreamType(3);
          setState(MEDIA_STARTING);
          mPlayer.setOnPreparedListener(this);
          mPlayer.prepareAsync();
        }
        else
        {
          if (file.startsWith("/android_asset/"))
          {
            String f = file.substring(15);
            AssetFileDescriptor fd = handler.ctx.getBaseContext().getAssets().openFd(f);
            mPlayer.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
          }
          else
          {
            mPlayer.setDataSource("/sdcard/" + file);
          }
          setState(MEDIA_STARTING);
          mPlayer.setOnPreparedListener(this);
          mPlayer.prepare();
          
          duration = mPlayer.getDuration();
        }
      }
      catch (Exception e)
      {
        e.printStackTrace();
        handler.sendJavascript("PhoneGap.Media.onStatus('" + id + "', " + MEDIA_ERROR + ", " + MEDIA_ERROR_STARTING_PLAYBACK + ");");
      }
    }
    else if ((state == MEDIA_PAUSED) || (state == MEDIA_STARTING))
    {
      mPlayer.start();
      setState(MEDIA_RUNNING);
    }
    else
    {
      System.out.println("AudioPlayer Error: startPlaying() called during invalid state: " + state);
      handler.sendJavascript("PhoneGap.Media.onStatus('" + id + "', " + MEDIA_ERROR + ", " + MEDIA_ERROR_RESUME_STATE + ");");
    }
  }
  
  public void pausePlaying()
  {
    if (state == MEDIA_RUNNING)
    {
      mPlayer.pause();
      setState(MEDIA_PAUSED);
    }
    else
    {
      System.out.println("AudioPlayer Error: pausePlaying() called during invalid state: " + state);
      handler.sendJavascript("PhoneGap.Media.onStatus('" + id + "', " + MEDIA_ERROR + ", " + MEDIA_ERROR_PAUSE_STATE + ");");
    }
  }
  
  public void stopPlaying()
  {
    if ((state == MEDIA_RUNNING) || (state == MEDIA_PAUSED))
    {
      mPlayer.stop();
      setState(MEDIA_STOPPED);
    }
    else
    {
      System.out.println("AudioPlayer Error: stopPlaying() called during invalid state: " + state);
      handler.sendJavascript("PhoneGap.Media.onStatus('" + id + "', " + MEDIA_ERROR + ", " + MEDIA_ERROR_STOP_STATE + ");");
    }
  }
  
  public void onCompletion(MediaPlayer mPlayer)
  {
    setState(MEDIA_STOPPED);
  }
  
  public long getCurrentPosition()
  {
    if ((state == MEDIA_RUNNING) || (state == MEDIA_PAUSED)) {
      return mPlayer.getCurrentPosition();
    }
    return -1L;
  }
  
  public boolean isStreaming(String file)
  {
    if (file.contains("http://")) {
      return true;
    }
    return false;
  }
  
  public long getDuration(String file)
  {
    if (recorder != null) {
      return -2L;
    }
    if (mPlayer != null) {
      return duration;
    }
    prepareOnly = true;
    startPlaying(file);
    
    return duration;
  }
  
  public void onPrepared(MediaPlayer mPlayer)
  {
    this.mPlayer.setOnCompletionListener(this);
    if (!prepareOnly)
    {
      this.mPlayer.start();
      
      setState(MEDIA_RUNNING);
    }
    duration = this.mPlayer.getDuration();
    prepareOnly = false;
    
    handler.sendJavascript("PhoneGap.Media.onStatus('" + id + "', " + MEDIA_DURATION + "," + duration + ");");
  }
  
  public boolean onError(MediaPlayer mPlayer, int arg1, int arg2)
  {
    System.out.println("AudioPlayer.onError(" + arg1 + ", " + arg2 + ")");
    
    this.mPlayer.stop();
    this.mPlayer.release();
    
    handler.sendJavascript("PhoneGap.Media.onStatus('" + id + "', " + MEDIA_ERROR + ", " + arg1 + ");");
    return false;
  }
  
  private void setState(int state)
  {
    if (this.state != state) {
      handler.sendJavascript("PhoneGap.Media.onStatus('" + id + "', " + MEDIA_STATE + ", " + state + ");");
    }
    this.state = state;
  }
}

/* Location:
 * Qualified Name:     com.phonegap.AudioPlayer
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.phonegap;

import android.util.Log;
import android.webkit.WebView;

public class BrowserKey
{
  DroidGap mAction;
  boolean bound;
  WebView mView;
  
  BrowserKey(WebView view, DroidGap action)
  {
    bound = false;
    mAction = action;
  }
  
  public void override()
  {
    Log.d("PhoneGap", "WARNING: Back Button Default Behaviour will be overridden.  The backKeyDown event will be fired!");
    bound = true;
  }
  
  public boolean isBound()
  {
    return bound;
  }
  
  public void reset()
  {
    bound = false;
  }
  
  public void exitApp()
  {
    mAction.finish();
  }
}

/* Location:
 * Qualified Name:     com.phonegap.BrowserKey
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.phonegap;

import android.net.Proxy;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.LinkedList;
import java.util.UUID;

public class CallbackServer
  implements Runnable
{
  private LinkedList<String> javascript;
  private int port;
  private Thread serverThread;
  private boolean active;
  private boolean empty;
  private boolean usePolling;
  private String token;
  
  public CallbackServer()
  {
    active = false;
    empty = true;
    port = 0;
    javascript = new LinkedList();
  }
  
  public void init(String url)
  {
    if ((url != null) && (!url.startsWith("file://")))
    {
      usePolling = true;
      stopServer();
    }
    else if (Proxy.getDefaultHost() != null)
    {
      usePolling = true;
      stopServer();
    }
    else
    {
      usePolling = false;
      startServer();
    }
  }
  
  public boolean usePolling()
  {
    return usePolling;
  }
  
  public int getPort()
  {
    return port;
  }
  
  public String getToken()
  {
    return token;
  }
  
  public void startServer()
  {
    active = false;
    
    serverThread = new Thread(this);
    serverThread.start();
  }
  
  public void restartServer()
  {
    stopServer();
    
    startServer();
  }
  
  public void run()
  {
    try
    {
      active = true;
      
      ServerSocket waitSocket = new ServerSocket(0);
      port = waitSocket.getLocalPort();
      
      token = UUID.randomUUID().toString();
      while (active)
      {
        Socket connection = waitSocket.accept();
        BufferedReader xhrReader = new BufferedReader(new InputStreamReader(connection.getInputStream()), 40);
        DataOutputStream output = new DataOutputStream(connection.getOutputStream());
        String request = xhrReader.readLine();
        String response = "";
        if ((active) && (request != null))
        {
          if (request.contains("GET"))
          {
            String[] requestParts = request.split(" ");
            if ((requestParts.length == 3) && (requestParts[1].substring(1).equals(token)))
            {
              synchronized (this)
              {
                while (empty) {
                  try
                  {
                    wait(10000L);
                  }
                  catch (Exception e) {}
                }
              }
              if (active)
              {
                if (empty) {
                  response = "HTTP/1.1 404 NO DATA\r\n\r\n ";
                } else {
                  response = "HTTP/1.1 200 OK\r\n\r\n" + getJavascript();
                }
              }
              else {
                response = "HTTP/1.1 503 Service Unavailable\r\n\r\n ";
              }
            }
            else
            {
              response = "HTTP/1.1 403 Forbidden\r\n\r\n ";
            }
          }
          else
          {
            response = "HTTP/1.1 400 Bad Request\r\n\r\n ";
          }
          output.writeBytes(response);
          output.flush();
        }
        output.close();
        xhrReader.close();
      }
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
    active = false;
  }
  
  public void stopServer()
  {
    if (active)
    {
      active = false;
      synchronized (this)
      {
        notify();
      }
    }
  }
  
  public void destroy()
  {
    stopServer();
  }
  
  public int getSize()
  {
    int size = javascript.size();
    
    return size;
  }
  
  public String getJavascript()
  {
    if (javascript.size() == 0) {
      return null;
    }
    String statement = (String)javascript.remove(0);
    if (javascript.size() == 0) {
      synchronized (this)
      {
        empty = true;
      }
    }
    return statement;
  }
  
  public void sendJavascript(String statement)
  {
    javascript.add(statement);
    synchronized (this)
    {
      empty = false;
      notify();
    }
  }
}

/* Location:
 * Qualified Name:     com.phonegap.CallbackServer
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.phonegap;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore.Images.Media;
import com.phonegap.api.PhonegapActivity;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import com.phonegap.api.PluginResult.Status;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import org.apache.commons.codec.binary.Base64;
import org.json.JSONArray;
import org.json.JSONException;

public class CameraLauncher
  extends Plugin
{
  private static final int DATA_URL = 0;
  private static final int FILE_URI = 1;
  private static final int PHOTOLIBRARY = 0;
  private static final int CAMERA = 1;
  private static final int SAVEDPHOTOALBUM = 2;
  private int mQuality;
  private Uri imageUri;
  public String callbackId;
  
  public PluginResult execute(String action, JSONArray args, String callbackId)
  {
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";
    this.callbackId = callbackId;
    try
    {
      if (action.equals("takePicture"))
      {
        int destType = 0;
        if (args.length() > 1) {
          destType = args.getInt(1);
        }
        int srcType = 1;
        if (args.length() > 2) {
          srcType = args.getInt(2);
        }
        if (srcType == 1) {
          takePicture(args.getInt(0), destType);
        } else if ((srcType == 0) || (srcType == 2)) {
          getImage(args.getInt(0), srcType, destType);
        }
        PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
        r.setKeepCallback(true);
        return r;
      }
      return new PluginResult(status, result);
    }
    catch (JSONException e)
    {
      e.printStackTrace();
    }
    return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
  }
  
  public void takePicture(int quality, int returnType)
  {
    mQuality = quality;
    
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    
    File photo = new File(Environment.getExternalStorageDirectory(), "Pic.jpg");
    intent.putExtra("output", Uri.fromFile(photo));
    imageUri = Uri.fromFile(photo);
    
    ctx.startActivityForResult(this, intent, 32 + returnType + 1);
  }
  
  public void getImage(int quality, int srcType, int returnType)
  {
    mQuality = quality;
    
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction("android.intent.action.GET_CONTENT");
    intent.addCategory("android.intent.category.OPENABLE");
    ctx.startActivityForResult(this, Intent.createChooser(intent, new String("Get Picture")), (srcType + 1) * 16 + returnType + 1);
  }
  
  public void onActivityResult(int requestCode, int resultCode, Intent intent)
  {
    int srcType = requestCode / 16 - 1;
    int destType = requestCode % 16 - 1;
    if (srcType == 1)
    {
      if (resultCode == -1) {
        try
        {
          Bitmap bitmap = MediaStore.Images.Media.getBitmap(ctx.getContentResolver(), imageUri);
          if (destType == 0)
          {
            processPicture(bitmap);
          }
          else if (destType == 1)
          {
            ContentValues values = new ContentValues();
            values.put("mime_type", "image/jpeg");
            Uri uri = null;
            try
            {
              uri = ctx.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
            }
            catch (UnsupportedOperationException e)
            {
              System.out.println("Can't write to external media storage.");
              try
              {
                uri = ctx.getContentResolver().insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
              }
              catch (UnsupportedOperationException ex)
              {
                System.out.println("Can't write to internal media storage.");
                failPicture("Error capturing image - no media storage found.");
                return;
              }
            }
            OutputStream os = ctx.getContentResolver().openOutputStream(uri);
            bitmap.compress(Bitmap.CompressFormat.JPEG, mQuality, os);
            os.close();
            
            success(new PluginResult(PluginResult.Status.OK, uri.toString()), callbackId);
          }
          bitmap.recycle();
          bitmap = null;
          System.gc();
        }
        catch (IOException e)
        {
          e.printStackTrace();
          failPicture("Error capturing image.");
        }
      }
      if (resultCode == 0) {
        failPicture("Camera cancelled.");
      } else {
        failPicture("Did not complete!");
      }
    }
    else if ((srcType == 0) || (srcType == 2))
    {
      if (resultCode == -1)
      {
        Uri uri = intent.getData();
        ContentResolver resolver = ctx.getContentResolver();
        if (destType == 0) {
          try
          {
            Bitmap bitmap = BitmapFactory.decodeStream(resolver.openInputStream(uri));
            processPicture(bitmap);
            bitmap.recycle();
            bitmap = null;
            System.gc();
          }
          catch (FileNotFoundException e)
          {
            e.printStackTrace();
            failPicture("Error retrieving image.");
          }
        } else if (destType == 1) {
          success(new PluginResult(PluginResult.Status.OK, uri.toString()), callbackId);
        }
      }
      else if (resultCode == 0)
      {
        failPicture("Selection cancelled.");
      }
      else
      {
        failPicture("Selection did not complete!");
      }
    }
  }
  
  public void processPicture(Bitmap bitmap)
  {
    ByteArrayOutputStream jpeg_data = new ByteArrayOutputStream();
    try
    {
      if (bitmap.compress(Bitmap.CompressFormat.JPEG, mQuality, jpeg_data))
      {
        byte[] code = jpeg_data.toByteArray();
        byte[] output = Base64.encodeBase64(code);
        String js_out = new String(output);
        success(new PluginResult(PluginResult.Status.OK, js_out), callbackId);
        js_out = null;
        output = null;
        code = null;
      }
    }
    catch (Exception e)
    {
      failPicture("Error compressing image.");
    }
    jpeg_data = null;
  }
  
  public void failPicture(String err)
  {
    error(new PluginResult(PluginResult.Status.ERROR, err), callbackId);
  }
}

/* Location:
 * Qualified Name:     com.phonegap.CameraLauncher
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.phonegap;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import com.phonegap.api.PhonegapActivity;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import com.phonegap.api.PluginResult.Status;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;

public class CompassListener
  extends Plugin
  implements SensorEventListener
{
  public static int STOPPED = 0;
  public static int STARTING = 1;
  public static int RUNNING = 2;
  public static int ERROR_FAILED_TO_START = 3;
  public long TIMEOUT = 30000L;
  int status;
  float heading;
  long timeStamp;
  long lastAccessTime;
  private SensorManager sensorManager;
  Sensor mSensor;
  
  public CompassListener()
  {
    timeStamp = 0L;
    setStatus(STOPPED);
  }
  
  public void setContext(PhonegapActivity ctx)
  {
    super.setContext(ctx);
    sensorManager = ((SensorManager)ctx.getSystemService("sensor"));
  }
  
  public PluginResult execute(String action, JSONArray args, String callbackId)
  {
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";
    try
    {
      if (action.equals("start"))
      {
        start();
      }
      else if (action.equals("stop"))
      {
        stop();
      }
      else
      {
        if (action.equals("getStatus"))
        {
          int i = getStatus();
          return new PluginResult(status, i);
        }
        if (action.equals("getHeading"))
        {
          if (this.status != RUNNING)
          {
            int r = start();
            if (r == ERROR_FAILED_TO_START) {
              return new PluginResult(PluginResult.Status.IO_EXCEPTION, ERROR_FAILED_TO_START);
            }
            long timeout = 2000L;
            while ((this.status == STARTING) && (timeout > 0L))
            {
              timeout -= 100L;
              try
              {
                Thread.sleep(100L);
              }
              catch (InterruptedException e)
              {
                e.printStackTrace();
              }
            }
            if (timeout == 0L) {
              return new PluginResult(PluginResult.Status.IO_EXCEPTION, AccelListener.ERROR_FAILED_TO_START);
            }
          }
          float f = getHeading();
          return new PluginResult(status, f);
        }
        if (action.equals("setTimeout"))
        {
          setTimeout(args.getLong(0));
        }
        else if (action.equals("getTimeout"))
        {
          long l = getTimeout();
          return new PluginResult(status, (float)l);
        }
      }
      return new PluginResult(status, result);
    }
    catch (JSONException e)
    {
      e.printStackTrace();
    }
    return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
  }
  
  public boolean isSynch(String action)
  {
    if (action.equals("getStatus")) {
      return true;
    }
    if (action.equals("getHeading"))
    {
      if (status == RUNNING) {
        return true;
      }
    }
    else if (action.equals("getTimeout")) {
      return true;
    }
    return false;
  }
  
  public void onDestroy()
  {
    stop();
  }
  
  public int start()
  {
    if ((status == RUNNING) || (status == STARTING)) {
      return status;
    }
    List<Sensor> list = sensorManager.getSensorList(3);
    if (list.size() > 0)
    {
      mSensor = ((Sensor)list.get(0));
      sensorManager.registerListener(this, mSensor, 3);
      lastAccessTime = System.currentTimeMillis();
      setStatus(STARTING);
    }
    else
    {
      setStatus(ERROR_FAILED_TO_START);
    }
    return status;
  }
  
  public void stop()
  {
    if (status != STOPPED) {
      sensorManager.unregisterListener(this);
    }
    setStatus(STOPPED);
  }
  
  public void onAccuracyChanged(Sensor sensor, int accuracy) {}
  
  public void onSensorChanged(SensorEvent event)
  {
    float heading = values[0];
    
    timeStamp = System.currentTimeMillis();
    this.heading = heading;
    setStatus(RUNNING);
    if (timeStamp - lastAccessTime > TIMEOUT) {
      stop();
    }
  }
  
  public int getStatus()
  {
    return status;
  }
  
  public float getHeading()
  {
    lastAccessTime = System.currentTimeMillis();
    return heading;
  }
  
  public void setTimeout(long timeout)
  {
    TIMEOUT = timeout;
  }
  
  public long getTimeout()
  {
    return TIMEOUT;
  }
  
  private void setStatus(int status)
  {
    this.status = status;
  }
}

/* Location:
 * Qualified Name:     com.phonegap.CompassListener
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.phonegap;

class ContactAccessor$WhereOptions
{
  private String where;
  private String[] whereArgs;
  
  ContactAccessor$WhereOptions(ContactAccessor paramContactAccessor) {}
  
  public void setWhere(String where)
  {
    this.where = where;
  }
  
  public String getWhere()
  {
    return where;
  }
  
  public void setWhereArgs(String[] whereArgs)
  {
    this.whereArgs = whereArgs;
  }
  
  public String[] getWhereArgs()
  {
    return whereArgs;
  }
}

/* Location:
 * Qualified Name:     com.phonegap.ContactAccessor.WhereOptions
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.phonegap;

import android.app.Activity;
import android.os.Build.VERSION;
import android.util.Log;
import android.webkit.WebView;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public abstract class ContactAccessor
{
  private static ContactAccessor sInstance;
  protected final String LOG_TAG = "ContactsAccessor";
  protected Activity mApp;
  protected WebView mView;
  
  public ContactAccessor()
  {
    LOG_TAG = "ContactsAccessor";
  }
  
  public static ContactAccessor getInstance(WebView view, Activity app)
  {
    if (sInstance == null)
    {
      String className;
      String className;
      if (Build.VERSION.RELEASE.startsWith("1.")) {
        className = "com.phonegap.ContactAccessorSdk3_4";
      } else {
        className = "com.phonegap.ContactAccessorSdk5";
      }
      try
      {
        Class<? extends ContactAccessor> clazz = Class.forName(className).asSubclass(ContactAccessor.class);
        
        Constructor<? extends ContactAccessor> classConstructor = clazz.getConstructor(new Class[] { Class.forName("android.webkit.WebView"), Class.forName("android.app.Activity") });
        sInstance = (ContactAccessor)classConstructor.newInstance(new Object[] { view, app });
      }
      catch (Exception e)
      {
        throw new IllegalStateException(e);
      }
    }
    return sInstance;
  }
  
  protected boolean isRequired(String key, HashMap<String, Boolean> map)
  {
    Boolean retVal = (Boolean)map.get(key);
    return retVal == null ? false : retVal.booleanValue();
  }
  
  protected HashMap<String, Boolean> buildPopulationSet(JSONArray fields)
  {
    HashMap<String,
1 2 3 4 5 6

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd