Skip to content
Snippets Groups Projects
Commit eaf2c491 authored by Emeric Vigier's avatar Emeric Vigier
Browse files

#14652: add android service with test button

parent cf6d51e1
No related branches found
No related tags found
No related merge requests found
......@@ -77,6 +77,12 @@ as that of the covered work.
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<service
android:name=".service.SipService">
<intent-filter>
<action android:name=".service.SipService" />
</intent-filter>
</service>
</application>
</manifest>
......@@ -85,12 +85,20 @@ as that of the covered work.
android:layout_toRightOf="@+id/textTo"
android:layout_below="@+id/editAccountID"
android:ems="10" />
<Button
android:id="@+id/buttonService"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editTo"
android:onClick="onClick"
android:text="enable Service" />
<TextView
android:id="@+id/callVoid_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textTo"
android:layout_below="@+id/buttonService"
android:visibility="invisible"
android:text="callVoidText" />
......
......@@ -57,11 +57,13 @@ import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import com.savoirfairelinux.sflphone.R;
import com.savoirfairelinux.sflphone.service.SipService;
public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
{
......@@ -73,9 +75,11 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC
/* default callID */
static String callID = "007";
static boolean callOnGoing = false;
static boolean serviceIsOn = false;
private String incomingCallID = "";
private static final int REQUEST_CODE_PREFERENCES = 1;
ImageButton buttonCall, buttonHangup;
Button buttonService;
/**
* The {@link ViewPager} that will host the section contents.
......@@ -323,6 +327,8 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC
@Override
public void onClick(View view)
{
buttonService = (Button) findViewById(R.id.buttonService);
switch (view.getId()) {
case R.id.buttonCall:
TextView textView = (TextView) findViewById(R.id.editAccountID);
......@@ -384,6 +390,18 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC
Manager.managerImpl.setPath("");
Manager.managerImpl.init("");
break;
case R.id.buttonService:
if (!serviceIsOn) {
startService(new Intent(this, SipService.class));
serviceIsOn = true;
buttonService.setText("disable Service");
}
else {
stopService(new Intent(this, SipService.class));
serviceIsOn = false;
buttonService.setText("enable Service");
}
break;
case R.id.buttonCallVoid:
Manager.callVoid();
break;
......
package com.savoirfairelinux.sflphone.service;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
import com.savoirfairelinux.sflphone.client.SFLphoneApplication;
public class SipService extends Service {
static final String TAG = "SipService";
static final int DELAY = 5000; /* 5 sec */
private boolean runFlag = false;
private SipServiceThread sipServiceThread;
private SFLphoneApplication sflphone;
private final IBinder mBinder = new LocalBinder();
/* called once by startService() */
@Override
public void onCreate() {
Log.i(TAG, "onCreated");
super.onCreate();
this.sflphone = (SFLphoneApplication) getApplication();
this.sipServiceThread = new SipServiceThread();
Log.i(TAG, "onCreated");
}
/* called for each startService() */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "onStarted");
super.onStartCommand(intent, flags, startId);
// if(intent != null) {
// Parcelable p = intent.getParcelableExtra(ServiceConstants.EXTRA_OUTGOING_ACTIVITY);
// Log.i(TAG, "unmarshalled outgoing_activity");
// }
this.runFlag = true;
this.sipServiceThread.start();
this.sflphone.setServiceRunning(true);
Toast.makeText(this, "Sflphone Service started", Toast.LENGTH_SHORT).show();
Log.i(TAG, "onStarted");
return START_STICKY; /* started and stopped explicitly */
}
@Override
public void onDestroy() {
/* called once by stopService() */
super.onDestroy();
this.runFlag = false;
this.sipServiceThread.interrupt();
this.sipServiceThread = null;
this.sflphone.setServiceRunning(false);
Toast.makeText(this, "Sflphone Service stopped", Toast.LENGTH_SHORT).show();
Log.i(TAG, "onDestroyed");
}
@Override
public IBinder onBind(Intent arg0) {
Log.i(TAG, "onBound");
return mBinder;
}
/**
* Class used for the client Binder. Because we know this service always
* runs in the same process as its clients, we don't need to deal with IPC.
*/
public class LocalBinder extends Binder {
SipService getService() {
// Return this instance of LocalService so clients can call public methods
return SipService.this;
}
}
private class SipServiceThread extends Thread {
public SipServiceThread() {
super("sipServiceThread");
}
@Override
public void run() {
SipService sipService = SipService.this;
while(sipService.runFlag) {
try {
//Log.i(TAG, "SipService thread running...");
Thread.sleep(DELAY);
} catch (InterruptedException e) {
sipService.runFlag = false;
Log.w(TAG, "service thread interrupted!");
}
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment