ISpy Android Source Code

iSpy
ConfigEditor.java
package com.jcarx.ispy;

/*
 * netsolvers.net (c) 2012
 *
 * @author Ravi Manthena
 */

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;

import com.google.ads.AdRequest;
import com.google.ads.AdView;
import com.jcarx.ispy.R;

import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
//import android.widget.EditText;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.Toast;

public class ConfigEditor extends Activity{
	
	private static final String TAG = "ConfigEditor";
	private Button backB = null;
	private Button saveB = null;
	private SeekBar sensativityB = null;
	private EditText phonenumber = null;
	private EditText interval = null;
	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.config);
        
        Location targetlocation = new Location("FIXED");
	    targetlocation.setLatitude(Double.parseDouble(getString(R.string.targetlocation_us_latitude)));
	    targetlocation.setLongitude(Double.parseDouble(getString(R.string.targetlocation_us_longitude)));
    
        AdView mAdView = (AdView) findViewById(R.id.adViewconfig);
        		AdRequest adRequest = new AdRequest();
        	    
        	    adRequest.addKeyword("sporting");
        	    adRequest.addKeyword("security");
        	    adRequest.addKeyword("jeans");
        	    adRequest.addKeyword("hunting");
        	    adRequest.addKeyword("motorcycle");
        	    adRequest.addKeyword("motorcycles");
        	    adRequest.addKeyword("yamaha");
        	    adRequest.addKeyword("honda");
        	    adRequest.addKeyword("bmw");
        	    adRequest.addKeyword("suzuki");
        	    
        	    adRequest.setLocation(targetlocation);
        	    
        	    //adRequest.setLocation();
        	    
        	    
        	    mAdView.loadAd(adRequest);
                
        
        // cop,lion,tiger,wolf
        
        // see what the user alreadys has 
        SharedPreferences soloPrefs = this.getSharedPreferences("ispyPrefs", MODE_WORLD_READABLE);
		String sensitivityleveluserpref = soloPrefs.getString("sensitivityleveluserpref", "7");
		String phonenumbertouseuserpref = soloPrefs.getString("phonenumbertouseuserpref", "");
		String callintervaluserpref = soloPrefs.getString("callintervaluserpref", "30");
		
		String debuguserpref = 
		"\nsensitivityleveluserpref="+sensitivityleveluserpref   +
		"\ncallintervaluserpref="+callintervaluserpref +
		"\nphonenumbertouseuserpref="+phonenumbertouseuserpref
		;
		
		Log.e(TAG, " Config Called");
    	
		//Toast.makeText(getApplicationContext(),
		//		"Saving your configurations"+debuguserpref,
		//		Toast.LENGTH_LONG).show();
			
		sensativityB = (SeekBar) findViewById(R.id.sensitivityB);
        sensativityB.setMax(10);
        sensativityB.setProgress(Integer.parseInt(sensitivityleveluserpref));
        
         
        phonenumber = (EditText)findViewById(R.id.phonenumber);
    	phonenumber.setText(phonenumbertouseuserpref);
    	
    	interval = (EditText)findViewById(R.id.interval);
    	interval.setText(callintervaluserpref);
    	
        backB = (Button) findViewById(R.id.backB);
        backB.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				try{
		    		Intent intent = new Intent();
		    		intent.setClass( ConfigEditor.this, MainActivity.class);
		    		//intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		    		startActivity(intent);
					finish();
		    	}catch(Exception x){
		    			x.printStackTrace();
		    	}
			}
       });
       
       saveB = (Button) findViewById(R.id.saveB);
       saveB.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				try{
					saveuserpref();
				}catch(Exception x){
		    			x.printStackTrace();
		    	}
			}
       });
    }
    
    public void saveuserpref(){
		try{
			String sensitivitylevel = Integer.toString(sensativityB.getProgress());
			String phonenumbertouse = phonenumber.getText().toString();
			String callintervaluser = interval.getText().toString();
			
			String debug = 
					"\nsensitivitylevel="+sensitivitylevel   +
					"\ncallintervaluser="+callintervaluser +
					"\nphonenumbertouse="+phonenumbertouse
					;
			
			// save pref
			SharedPreferences myPrefs = this.getSharedPreferences("ispyPrefs", MODE_WORLD_READABLE);
			SharedPreferences.Editor prefsEditor = myPrefs.edit();
			prefsEditor.putString("sensitivityleveluserpref", sensitivitylevel);
			prefsEditor.putString("callintervaluserpref", callintervaluser);
			prefsEditor.putString("phonenumbertouseuserpref", phonenumbertouse);
			prefsEditor.commit();
			
			Log.d(TAG, debug);
	    	
			Toast.makeText(getApplicationContext(),
					"Saving your configurations"+debug,
					Toast.LENGTH_LONG).show();
			
		}catch(Exception x){
    			x.printStackTrace();
    	}
    }
}
MainActivity.java
package com.jcarx.ispy;

/*
 * netsolvers.net (c) 2012
 *
 * @author Ravi Manthena
 */

import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.Location;
import android.location.LocationManager;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.SystemClock;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ProgressBar;

// admods
import com.google.ads.AdRequest;
import com.google.ads.AdView;
import com.jcarx.ispy.R;

public class MainActivity extends Activity implements Runnable {

	final Context context = this;
	private ImageButton spyb;
	private ImageButton nospyb;
	private ImageButton configb;
	private ImageButton exitb;
	
	private EditText statuset;

	private ProgressBar ampP = null;

	private MediaRecorder mRecorder = null;

	private AudioManager audiomanager = null;

	private boolean spyinprogress = false;

	private TelephonyManager telephonyManager = null;
	
	private PhoneCallListener phoneListener = null;

	StringBuffer statusbuf = new StringBuffer();

	double amp = 0.0;
	
	long callbreaktime = 1; //let's say 1 minutes
	
	boolean callbreaktimeb = false; 
	
	/*
	 * MediaRecorder recorder = new MediaRecorder();
	 * recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
	 * recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
	 * recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
	 * recorder.setOutputFile(PATH_NAME); recorder.prepare(); recorder.start();
	 * // Recording is now started ... recorder.stop(); recorder.reset(); // You
	 * can reuse the object by going back to setAudioSource() step
	 * recorder.release(); // Now the object cannot be reused
	 */

	private double mEMA = 0.0;
	boolean runner = true;

	String sensitivityleveluserpref = "";
	String phonenumbertouseuserpref = "";
	String chklastcallmadeat ="0";
	String callintervaluserpref = "30";

	private Thread solothelistner = null;

	String TAG = "MainActivity";

	PowerManager pm = null;
	PowerManager.WakeLock wl = null;

	int incrementx = 0;
	int incrementj = 0;

	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		// old pic look
		// setContentView(R.layout.mainoldpicture);

		// modern one
		setContentView(R.layout.modernlookone);

		// modern two
		// setContentView(R.layout.modernlooktwo);
		
		//String location_context = Context.LOCATION_SERVICE;
		//LocationManager locationmanager = (LocationManager) getSystemService(location_context);
	    //List<String> providers = locationmanager.getProviders(true);
		
	    //Log.e(TAG,"Provider Start");
	    //for(int io = 0; io < providers.size(); io++){
	    //	Log.e(TAG,providers.get(io));
	    //}
	    //Log.e(TAG,"Provider End");
	    
	    Location targetlocation = new Location("FIXED");
	    targetlocation.setLatitude(Double.parseDouble(getString(R.string.targetlocation_sf_latitude)));
	    targetlocation.setLongitude(Double.parseDouble(getString(R.string.targetlocation_sf_longitude)));
        
	    AdView mAdView = (AdView) findViewById(R.id.adViewmain);
		AdRequest adRequest = new AdRequest();
	    
	    adRequest.addKeyword("sporting");
	    adRequest.addKeyword("security");
	    adRequest.addKeyword("jeans");
	    adRequest.addKeyword("bikes");
	    adRequest.addKeyword("bike");
	    adRequest.addKeyword("motorcycle");
	    adRequest.addKeyword("motorcycles");
	    adRequest.addKeyword("yamaha");
	    adRequest.addKeyword("honda");
	    adRequest.addKeyword("ford");
	    adRequest.addKeyword("suzuki");
	    
	    adRequest.setLocation(targetlocation);
	    
	    //adRequest.setLocation();
	    
	    
	    mAdView.loadAd(adRequest);

		pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
		wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, TAG);
		wl.acquire();

		loadthePref();
		
		// set the timer between calls
		try{
			callbreaktime = Long.parseLong(callintervaluserpref);
		}catch(Exception x){
			Log.d(TAG,"Exception parsing long");
			callbreaktime = 30;
		}
		
		
		// see if the app is already running in spy mode.
		SharedPreferences soloPrefs = this.getSharedPreferences(
				"ispyPrefs", MODE_WORLD_READABLE);
		
		String spyinprogressStr = soloPrefs.getString(
				"spyinprogress", "false");
		if(spyinprogressStr.equals("true")){
			spyinprogress = true;
			Log.d(TAG,"Already in Spying mode so setting spy on");
		}else{
			Log.d(TAG,"Spying mode off either starting a new one or clicked stop spying");
		}
		

		ampP = (ProgressBar) findViewById(R.id.noiselevelseekbar);
		ampP.setVisibility(ProgressBar.VISIBLE);
		ampP.setProgress(0);
		ampP.setMax(15);

		// add PhoneStateListener
		phoneListener = new PhoneCallListener();
		telephonyManager = (TelephonyManager) this
				.getSystemService(Context.TELEPHONY_SERVICE);
		telephonyManager.listen(phoneListener,
				PhoneStateListener.LISTEN_CALL_STATE);

		spyb = (ImageButton) findViewById(R.id.spyb);
		//AnimateRotateImageButton(spyb);

		// add button listener
		spyb.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {

				if (phonenumbertouseuserpref == "") {
					try {
						debug("No Configured Phone# \nPlease Use Config Button \nand set a phone number to call");
					} catch (Exception x) {
						x.printStackTrace();
					}
				}else{
				
					Log.d(TAG, "Spy Call in Process");
					debug("Spying in Progress");
					spyinprogress = true;
					
					// set the spying mode
					  SharedPreferences myPrefs = getSharedPreferences("ispyPrefs", MODE_WORLD_READABLE);
						SharedPreferences.Editor prefsEditor = myPrefs.edit();
						prefsEditor.putString("spyinprogress", "true");
						prefsEditor.commit();
						Log.d(TAG,"Set spyinprogress to true in userPref");
					
				}
			}

		});

		nospyb = (ImageButton) findViewById(R.id.nospyb);
		//AnimateRotateImageButton(nospyb);

		// add button listener
		nospyb.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Log.d(TAG, "Stop Calling No Spy in Process");
				debug("Stoping Spy Activitys");
				spyinprogress = false;
				
				// set the spying mode
				  SharedPreferences myPrefs = getSharedPreferences("ispyPrefs", MODE_WORLD_READABLE);
					SharedPreferences.Editor prefsEditor = myPrefs.edit();
					prefsEditor.putString("spyinprogress", "false");
					prefsEditor.commit();
					Log.d(TAG,"Set spyinprogress to true in userPref");
	
			}

		});

		exitb = (ImageButton) findViewById(R.id.exitb);
		//AnimateRotateImageButton(nospyb);

		// add button listener
		exitb.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Log.d(TAG, "Exiting ISpy");

			    SharedPreferences myPrefs = getSharedPreferences("ispyPrefs", MODE_WORLD_READABLE);
				SharedPreferences.Editor prefsEditor = myPrefs.edit();
				prefsEditor.putString("spyinprogress", "false");
				prefsEditor.commit();
				Log.d(TAG,"Set spyinprogress to false in userPref");
				
				if (telephonyManager != null) {
					telephonyManager = null;
					Log.d(TAG, "telephonyManager = null");
				}

				if (mRecorder != null) {
					//mRecorder.stop();
					mRecorder.reset();
					mRecorder.release();
					mRecorder = null;
					Log.d(TAG,
							" mRecorder = null");
				}

				if (audiomanager != null) {
					audiomanager = null;
					Log.d(TAG,
					"audiomanager = null");
				}else{
					Log.d(TAG,
					" audiomanager = was already null");
				}
				
				
				if(phoneListener != null){
					phoneListener = null;
					Log.d(TAG, "set phoneListener=null");
				}else{
					Log.d(TAG, "phoneListener was already null");
				}
				
				// power
				Log.d(TAG, "Releasing power now");
				wl.release();
				
				System.exit(0);
			    
			    // back button pressed so killing the process
				int currpid = android.os.Process.myPid();
				Log.d(TAG, "Killing Process Pid ="+currpid);
				android.os.Process.killProcess(currpid);
				
				System.exit(0);
				
			}
		});

		configb = (ImageButton) findViewById(R.id.configb);
		AnimateRotateImageButton(configb);

		// add button listener 
		configb.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Log.d(TAG, "Invoke Config");
				Intent intent = new Intent();
				intent.setClass(MainActivity.this, ConfigEditor.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent);
				//finish();
			}

		});

		statuset = (EditText) findViewById(R.id.statuset);
		// AnimateRotateEditText(statuset);

		setAudioManager();
		
		if(solothelistner != null){
			Log.d(TAG, "solothelistner was not null so not creating a new one");
		}else{
			solothelistner = new Thread(this);
			solothelistner.start();
			solothelistner.setName("SoloThread");
			Log.d(TAG, "solothelistner was null so creating a new one");
		}

		
		if(this.phonenumbertouseuserpref == ""){
			
			AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setMessage("     Warning....\n\n"+
				"We are not responsible \n"+
				"for how this App is used.\n"+
				"Please read the App's\n"+
				"description before use.\n"+
				"Use it at your own Risk.\n\n"+
				"Please Configure a phone#\n"+
				"Before you start Spying"
		
			)
		    .setCancelable(false)
		    .setPositiveButton("I Agree", new DialogInterface.OnClickListener() {
		    	public void onClick(DialogInterface dialog, int id) {
		        	   //MainActivity.this.finish();
		    		dialog.cancel();
		           }
		       })	
		    .setNegativeButton("No I do not Agree", new DialogInterface.OnClickListener() {
		           public void onClick(DialogInterface dialog, int id) {
		                dialog.cancel();
		                MainActivity.this.onBackPressed();
		           }
		       });
			AlertDialog alert = builder.create();
			alert.show();
		}
		
		int currpid = android.os.Process.myPid();
		Log.w(TAG, this.toString()+" Current Pid ="+currpid);
		
		// save all the pids
		//int currpid = android.os.Process.myPid();
		//android.os.Process.
	}
	
	private void setAudioManager(){
		try{
			
			Log.d(TAG, "Initilized AudioManager");
			
			/* original 
			audiomanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
			audiomanager.setMode(AudioManager.MODE_IN_CALL);
			audiomanager.setStreamMute(AudioManager.MODE_IN_CALL, true);
			audiomanager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, 10,
					AudioManager.FLAG_PLAY_SOUND);
			audiomanager.setSpeakerphoneOn(true);
			*/

			audiomanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
			
			// this cause's bugs since we do not want to explicily set the mode....
			//audiomanager.setMode(AudioManager.MODE_IN_CALL);
			
			audiomanager.setStreamMute(AudioManager.MODE_IN_CALL, true);
			
			audiomanager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, 10,
					AudioManager.FLAG_PLAY_SOUND);
			
			audiomanager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
			
			// test this one
			//audiomanager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
			
			audiomanager.setSpeakerphoneOn(true);
			
			Log.d(TAG, "Done Initilizing AudioManager");
		
		}catch(Exception x){
			x.printStackTrace();
		}
	}

	protected void onPause() {
		super.onPause();

		Log.d(TAG, "onPause");
		
		runner = false;
		
		if(solothelistner != null){
			Log.d(TAG, "onPause "+"solothread is not null");
			try{
				//solothelistner.destroy();
				solothelistner = null;
			}catch(Exception xxx){
				Log.e(TAG, "OnPause while closing thread ", xxx);
			}
		} else{
			Log.d(TAG, "onPause "+"solothread is null");
		}
		
		try {
			if (mRecorder != null) {
				try{
					//mRecorder.stop();
					mRecorder.reset();
					mRecorder.release();
					mRecorder = null;
					Log.d(TAG,
						" mRecorder stopped onPause ");
				}catch(Exception xx){
					Log.e(TAG, " Exception so will null again", xx);
					try{
						//mRecorder.stop();
						mRecorder.reset();
						mRecorder.release();
						mRecorder = null;
					}catch(Exception xx2){
						Log.e(TAG, " Exception in Exception so nulling again", xx2);
					}
					Log.d(TAG, " Exception in onPause ");
				}
			} else {
				Log.d(TAG,
						" mRecorder was already null so nothing to do in onPause");
			}
		} catch (Exception xx) {
			Log.d(TAG, " Exception in onPause ");
		}
	}

	protected void onResume() {
		super.onResume();
		Log.d(TAG, "onResume");
	}

	protected void onDestroy() {
		super.onDestroy();
		Log.d(TAG, "onDestroy");

		if (telephonyManager != null) {
			telephonyManager = null;
			Log.d(TAG, "telephonyManager = null");
		}
		
		if (mRecorder != null) {
			//mRecorder.stop();
			mRecorder.reset();
			mRecorder.release();
			mRecorder = null;
			Log.d(TAG,
					" mRecorder = stoped");
		}

		if (audiomanager != null) {
			audiomanager = null;
			Log.d(TAG,
			"audiomanager = null");
		}else{
			Log.d(TAG,
			" audiomanager = was already null");
		}
		
		// back button pressed so killing the process
		//int currpid = android.os.Process.myPid();
		//Log.d(TAG, "Killing Process Pid ="+currpid);
		//android.os.Process.killProcess(currpid);
		
		if(phoneListener != null){
			phoneListener = null;
			Log.d(TAG, "set phoneListener=null");
		}else{
			Log.d(TAG, "phoneListener was already null");
		}
		
		// power
		wl.release();
		
		
	}
	

	
	public void onBackPressed() {

	    super.onBackPressed();
	    
	    Log.d(TAG, "onBackPressed");

	    SharedPreferences myPrefs = this.getSharedPreferences("ispyPrefs", MODE_WORLD_READABLE);
		SharedPreferences.Editor prefsEditor = myPrefs.edit();
		prefsEditor.putString("spyinprogress", "false");
		prefsEditor.commit();
		Log.d(TAG,"Set spyinprogress to false in userPref");
		
		if (telephonyManager != null) {
			telephonyManager = null;
			Log.d(TAG, "telephonyManager = null");
		}

		if (mRecorder != null) {
			//mRecorder.stop();
			mRecorder.reset();
			mRecorder.release();
			mRecorder = null;
			Log.d(TAG,
					" mRecorder = null");
		}

		if (audiomanager != null) {
			audiomanager = null;
			Log.d(TAG,
			"audiomanager = null");
		}else{
			Log.d(TAG,
			" audiomanager = was already null");
		}
		
		
		if(phoneListener != null){
			phoneListener = null;
			Log.d(TAG, "set phoneListener=null");
		}else{
			Log.d(TAG, "phoneListener was already null");
		}
		
		// power
		Log.d(TAG, "Releasing power now");
		wl.release();
		
		System.exit(0);
	    
	    // back button pressed so killing the process
		int currpid = android.os.Process.myPid();
		Log.d(TAG, "Killing Process Pid ="+currpid);
		android.os.Process.killProcess(currpid);
		
		System.exit(0);
	
	}

	public void createamRecorder(){
		if(mRecorder == null){
			try{
				mRecorder = new MediaRecorder();
				
				mRecorder.reset();
			
				mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
				mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
			
				mRecorder.setOutputFile("/dev/null");
			
				//mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
			
				mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
				
				//mRecorder.setAudioEncodingBitRate(16);
				//mRecorder.setAudioSamplingRate(44100);
			
				try {
					mRecorder.prepare();
				} catch (Exception x) {
					x.printStackTrace();
					Log.d(TAG, "Exception in Preparing a mRecorder ", x);
				}
			}catch(Exception x){
				x.printStackTrace();
				Log.d(TAG," Exception while creating a new mRecorder ",x);
			}
		}		
	}

	public void run() {
		Log.d(TAG, "Solothelister Thread started running now " + this.solothelistner.toString() );

		if(mRecorder == null){
		try {
				
			// sleep her for few seconds so that the mRecorder has time to setu it self up
			try{
				createamRecorder();
				
				Log.d(TAG, "Right before calling start on mRecorder");
				
				Log.d(TAG, "mRecorder ="+mRecorder+"-----------");
				
				if(mRecorder == null){
					createamRecorder();
				}
				
				//mRecorder.wait(50);
				
				mRecorder.start();
				
				mEMA = 0.0;
			
			}catch(Exception x){
				// debug("Stoped Spying");
				x.printStackTrace();
				Log.d(TAG, "Exception in Starting mRecorder="+mRecorder, x);
			}

		} catch (Exception x) {
			Log.d(TAG, "Exception in Creating a mRecorder ", x);
		}
		}else{
			try{
				//mRecorder.wait(50);
				
				mRecorder.start();
				mEMA = 0.0;
			}catch(Exception x){
				Log.d(TAG, "Exception in Starting the mRecorder", x);
			}
		}

		Log.d(TAG, "Runner is = " + runner);
		
		
		callbreaktime = callbreaktime * 60 * 1000;
		
		Log.d(TAG, "callbreaktime " + Long.toString(callbreaktime));
		
		
		while (runner) {
			try {

				amp = 0.0;
				// ravi need to chk to make sure it is not null
				// if not we will keep getting NullPointer
				if (mRecorder != null) {
					amp = mRecorder.getMaxAmplitude() / 2700.0;
				}

				int progressamp = getAmpProgress(amp);
				ampP.setProgress(progressamp);

				// just for debug to see noise levels
				/*
				 * if(incrementx == incrementj){ Log.d("mRecorder",
				 * Double.toString(progressamp)); incrementj = incrementj + 10+
				 * incrementj; incrementx++; }else{ incrementx++; }
				 */

				Thread.sleep(130);
				//Log.d(TAG, solothelistner.getName()+" "+solothelistner.toString());
				
				if(chklastcallmadeat != null){
					
					//Log.d(TAG, " chklastcallmadeat ="+chklastcallmadeat);
							
					long startTime = Long.parseLong(chklastcallmadeat);
					
					long endTime   = System.currentTimeMillis();

					long totalTime = endTime - startTime;
					
					if(totalTime > callbreaktime){
						//Log.d(TAG, " totalTime is greater than callbreaktime");
						callbreaktimeb = true;
					}else{
						//Log.d(TAG, " totalTime > callbreaktime "+ totalTime +" > "+ callbreaktime);
					} 
					
					//Log.d(TAG, "Current = "+endTime + " totalTime = "+Long.toString(totalTime));
					
				}
			
					
				//Log.d(TAG, solothelistner.getName()+" "+solothelistner.toString());
				
				
				
				// Reset the Progress
				ampP.setProgress(0);

				if (progressamp > Integer.parseInt(sensitivityleveluserpref)) {

					//debug("spyinprogress = " + spyinprogress);

					if (phonenumbertouseuserpref == "") {
						/*debug("No Phone# Configured\n"
								+ "Please press Config Button\n"
								+ "To Configurte a Phone# to call ");
						*/
					} else if(spyinprogress == true){
						/*debug("Meets the noise level "
								+ "\nwill call the preconfigured" + "\nphone# "
								+ phonenumbertouseuserpref
								+ "\nso that the spyer can listen");
						 */
						// not sure we want to sleep here test

						// Thread.sleep(2000);
				
						//debug(" Calling in progress .."+ phonenumbertouseuserpref);
						
						if(callbreaktimeb){
							String lastcallmadeat = Long.toString(System.currentTimeMillis());
							SharedPreferences myPrefs = this.getSharedPreferences("ispyPrefs", MODE_WORLD_READABLE);
							SharedPreferences.Editor prefsEditor = myPrefs.edit();
							prefsEditor.putString("lastcallmadeat", lastcallmadeat);
							prefsEditor.commit();
						
							Log.d(TAG, "saved the timestamp "+lastcallmadeat);
							
							Intent callIntent = new Intent(Intent.ACTION_CALL);
							// callIntent.setData(Uri.parse("tel:5556"));
							// callIntent.setData(Uri.parse("tel:9160765199"));
							callIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
							callIntent.setData(Uri.parse("tel:"
								+ phonenumbertouseuserpref));

							startActivity(callIntent);
						
						
							//int currpid = android.os.Process.myPid();
							//Log.d(TAG, "Killing Current Process Pid="+currpid);
							//android.os.Process.killProcess(currpid);
						
						
						
						
						}else{
							Log.d(TAG, " Does not meet the time interval before another call");
						}

					}
				} else {
					// don;t do anything other than listen
				}

				Thread.sleep(100);

			} catch (Exception x) {
				Log.d(TAG, " Exception in Run Method " + x.toString());
				Log.d(TAG, " Exception Details \n", x);
			}
		}
	}

	public int getAmpProgress(double amp) {
		if ((amp > .02 && amp < .05)) {
			return 1;
		} else if (amp > .05 && amp < .08) {
			return 3;
		} else if (amp > .08 && amp < .1) {
			return 4;
		} else if (amp > .1 && amp < 1.2) {
			return 5;
		} else if (amp > 1.2 && amp < 1.5) {
			return 6;
		} else if (amp > 1.5 && amp < 2.5) {
			return 7;
		} else if (amp > 2.5 && amp < 3.0) {
			return 8;
		} else if (amp > 3.0 && amp < 3.5) {
			return 9;
		} else if (amp > 3.5 && amp < 4.0) {
			return 10;
		} else if (amp > 4.0 && amp < 4.5) {
			return 11;
		} else if (amp > 4.5 && amp < 5.0) {
			return 12;
		} else if (amp > 5.0 && amp < 5.5) {
			return 13;
		} else if (amp > 5.5 && amp < 6.) {
			return 14;
		} else if (amp > 6.0 && amp < 6.5) {
			return 15;
		} else {
			return 0;
		}
	}

	private class PhoneCallListener extends PhoneStateListener {

		private boolean isPhoneCalling = false;

		@Override
		public void onCallStateChanged(int state, String incomingNumber) {

			if (TelephonyManager.CALL_STATE_RINGING == state) {
				// phone ringing
				Log.i(TAG, "RINGING, number: " + incomingNumber);
				debug("RINGING the Spyer's phone now \nCalling "
						+ incomingNumber);
			}

			if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
				// active
				Log.i(TAG, "OFFHOOK");
				debug("Spyer picked up the phone \nand is listening now");

				isPhoneCalling = true;
			}

			if (TelephonyManager.CALL_STATE_IDLE == state) {
				// run when class initial and phone call ended, need detect flag
				// from CALL_STATE_OFFHOOK
				Log.i(TAG, "IDLE");
				if (isPhoneCalling || spyinprogress ) {
					debug("Spying In Progress ..");
				} else {
					debug("No Spying in Process \n Click on the Start Spying \n Button to Spy");
				}

				if (isPhoneCalling) {

					//debug("Spyer is done listening \nBack to Spying mode");

					Log.w(TAG, " Calling Main Spyer back");

					// bug where it runs only twice
					/*
					Intent i = getBaseContext().getPackageManager()
							.getLaunchIntentForPackage(
									getBaseContext().getPackageName());
					 i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
					 Intent.FLAG_ACTIVITY_NEW_TASK );

					i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					startActivity(i);
					*/
					
					// bug where the back buttons needs to be pressed multiple times
					/*
					Intent intent = new Intent();
					intent.setClass(MainActivity.this, SpyInProgress.class);
					intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
					 Intent.FLAG_ACTIVITY_NEW_TASK );
					startActivity(intent);
					*/
					
					Intent intent = new Intent();
					intent.setClass(MainActivity.this, SpyInProgress.class);
					intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
					 Intent.FLAG_ACTIVITY_NEW_TASK );
					startActivity(intent);
					finish();
					isPhoneCalling = false;
				}

			}
		}
	}

	public void loadthePref() {
		try {
			SharedPreferences soloPrefs = this.getSharedPreferences(
					"ispyPrefs", MODE_WORLD_READABLE);
			phonenumbertouseuserpref = soloPrefs.getString(
					"phonenumbertouseuserpref", "");
			sensitivityleveluserpref = soloPrefs.getString(
					"sensitivityleveluserpref", "6");
			callintervaluserpref = soloPrefs.getString(
					"callintervaluserpref", "30");
			
			chklastcallmadeat = soloPrefs.getString(
					"lastcallmadeat", "0");

		} catch (Exception x) {
			Log.d(TAG, "Exception in loadthePref method =" + x.toString());
		}
	}

	public void AnimateFadeInFadeOutImageButton(ImageButton ib) {

		AnimationSet set = new AnimationSet(true);
		ib.startAnimation(set);

		Animation fadeIn = new AlphaAnimation(0, 1);
		fadeIn.setInterpolator(new DecelerateInterpolator()); // add this
		fadeIn.setDuration(1000);
		fadeIn.setRepeatCount(1);

		Animation fadeOut = new AlphaAnimation(1, 0);
		fadeOut.setInterpolator(new AccelerateInterpolator()); // and this
		fadeOut.setStartOffset(1000);
		fadeOut.setDuration(1000);
		fadeOut.setRepeatCount(1);

		AnimationSet animation = new AnimationSet(true); // change to false
		animation.addAnimation(fadeIn);
		animation.addAnimation(fadeOut);

		set.addAnimation(animation);

		ib.startAnimation(set);
	}

	public void AnimateRotateImageButton(ImageButton ib) {

		int animationDuration = 1000;

		AnimationSet set = new AnimationSet(true);
		ib.startAnimation(set);

		RotateAnimation r = new RotateAnimation(0f, 359f, 40, 40); // HERE
		r.setStartOffset(1000);

		r.setDuration(animationDuration);

		set.addAnimation(r);

		ib.startAnimation(set);
		try {
			// Thread.sleep(animationDuration);
		} catch (Exception x) {
			x.printStackTrace();
		}
	}

	public void AnimateRotateEditText(EditText ib) {

		int animationDuration = 1000;

		AnimationSet set = new AnimationSet(true);
		ib.startAnimation(set);

		RotateAnimation r = new RotateAnimation(0f, 359f, 40, 40); // HERE
		r.setStartOffset(1000);

		r.setDuration(animationDuration);

		set.addAnimation(r);

		ib.startAnimation(set);
		try {
			// Thread.sleep(animationDuration);
		} catch (Exception x) {
			x.printStackTrace();
		}
	}

	public void debug(String debug) {
		Log.d(TAG, debug);
		statuset.setText("    " + debug);
		// statusbuf.append("\n"+debug);
		// statuset.setText(statusbuf.toString());
	}

}
SpyInProgress.java
package com.jcarx.ispy;

/*
 * netsolvers.net (c) 2012
 *
 * @author Ravi Manthena
 */

import com.google.ads.AdRequest;
import com.google.ads.AdView;

import android.app.Activity;
import android.content.Intent;

import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import android.widget.ProgressBar;

public class SpyInProgress extends Activity implements Runnable{
	
	private static final String TAG = "SpyInProgress";
	
	Thread spythread = null;
	ProgressBar ampP = null;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.reset);
        
        Location targetlocation = new Location("FIXED");
	    targetlocation.setLatitude(Double.parseDouble(getString(R.string.targetlocation_us_latitude)));
	    targetlocation.setLongitude(Double.parseDouble(getString(R.string.targetlocation_us_longitude)));
        
	    //AdView mAdView = (AdView) findViewById(R.id.adView);
	    AdView mAdView = (AdView) findViewById(R.id.adViewreset);
		AdRequest adRequest = new AdRequest();
	    
	    adRequest.addKeyword("sporting");
	    adRequest.addKeyword("security");
	    adRequest.addKeyword("jeans");
	    adRequest.addKeyword("bikes");
	    adRequest.addKeyword("bike");
	    adRequest.addKeyword("motorcycle");
	    adRequest.addKeyword("motorcycles");
	    adRequest.addKeyword("yamaha");
	    adRequest.addKeyword("honda");
	    adRequest.addKeyword("ford");
	    adRequest.addKeyword("suzuki");
	    
	    adRequest.setLocation(targetlocation);
	    
	    //adRequest.setLocation();
	    
	    
	    mAdView.loadAd(adRequest);
        
        ampP = (ProgressBar) findViewById(R.id.resetinprogressbar);
		ampP.setVisibility(ProgressBar.VISIBLE);
		ampP.setMax(10);
		ampP.setProgress(10);
		
        spythread  = new Thread(this);
        spythread .start();
    }
    
    public void run(){
    	try{
    		long timerval = 1000;
    		Thread.sleep(timerval);
    		ampP.setProgress(10);
    		Thread.sleep(timerval);
    		ampP.setProgress(9);
    		Thread.sleep(timerval);
    		ampP.setProgress(8);
    		Thread.sleep(timerval);
    		ampP.setProgress(7);
    		Thread.sleep(timerval);
    		ampP.setProgress(6);
    		Thread.sleep(timerval);
    		ampP.setProgress(5);
    		Thread.sleep(timerval);
    		ampP.setProgress(4);
    		Thread.sleep(timerval);
    		ampP.setProgress(3);
    		Thread.sleep(timerval);
    		ampP.setProgress(2);
    		Thread.sleep(timerval);
    		ampP.setProgress(1);
    		
    		Log.e(TAG, "SpyInProgress");
            Intent intent = new Intent();
            intent.setClass( SpyInProgress.this, MainActivity.class);
            //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            finish();
    	}catch(Exception x){
    		x.printStackTrace();
    	}
    }
}

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.