blob: 6ee701b42b942b4164fd2dc8926a292566432adf [file] [log] [blame]
Emeric Vigier9701e032012-09-12 12:38:01 -04001package com.savoirfairelinux.sflphone.client;
2
3import android.os.Handler;
4import android.os.Bundle;
5import android.os.Message;
6import android.util.Log;
7import android.view.animation.AlphaAnimation;
8import android.view.animation.Animation;
9import android.view.animation.LinearInterpolator;
10import android.widget.ImageButton;
11
12import com.savoirfairelinux.sflphone.R;
Emeric Vigier12d61d82012-09-19 15:08:18 -040013import com.savoirfairelinux.sflphone.service.CallManagerCallBack;
14import com.savoirfairelinux.sflphone.service.CallManagerJNI;
15import com.savoirfairelinux.sflphone.service.ManagerImpl;
16import com.savoirfairelinux.sflphone.service.SFLPhoneservice;
Emeric Vigier9701e032012-09-12 12:38:01 -040017
18public class Manager {
19
20 private static final String TAG = "Manager";
21 private static int sipLogLevel = 6;
22 static Handler h;
Alexandre Savard398ce1b2012-09-12 17:34:41 -040023 // private static ButtonSectionFragment buttonSecFragment;
Emeric Vigier9701e032012-09-12 12:38:01 -040024 static String appPath;
25 static Animation animation;
26 static SFLPhoneHome uiThread;
27 static ImageButton buttonCall;
28 public static ManagerImpl managerImpl;
Emeric Vigier9380ae52012-09-14 17:40:39 -040029 public CallManagerJNI callmanagerJNI;
30 public CallManagerCallBack callManagerCallBack;
Emeric Vigier9701e032012-09-12 12:38:01 -040031
32 static {
33 // FIXME: this is the 2nd time we call ManagerImpl's constructor.
34 // First time was at JNI_OnLoad...
Emeric Vigier9380ae52012-09-14 17:40:39 -040035// managerImpl = new ManagerImpl(sflphoneserviceJNI.instance(), true);
Emeric Vigier12d61d82012-09-19 15:08:18 -040036 managerImpl = SFLPhoneservice.instance();
Emeric Vigier9701e032012-09-12 12:38:01 -040037 Log.i(TAG, "ManagerImpl::instance() = " + managerImpl);
38 }
39
40 public Manager() {}
41
42 public Manager(Handler h) {
43 // Change alpha from fully visible to invisible
44 animation = new AlphaAnimation(1, 0);
45 // duration - half a second
46 animation.setDuration(500);
47 // do not alter animation rate
48 animation.setInterpolator(new LinearInterpolator());
49 // Repeat animation infinitely
50 animation.setRepeatCount(Animation.INFINITE);
51 // Reverse
52 animation.setRepeatMode(Animation.REVERSE);
53
54 this.h = h;
Emeric Vigier9380ae52012-09-14 17:40:39 -040055 callmanagerJNI = new CallManagerJNI();
56 callManagerCallBack = new CallManagerCallBack();
Emeric Vigier12d61d82012-09-19 15:08:18 -040057 SFLPhoneservice.setCallbackObject(callManagerCallBack);
58 Log.i(TAG, "callManagerCallBack = " + callManagerCallBack);
Emeric Vigier9701e032012-09-12 12:38:01 -040059 }
60
61 public static void callBack(String s) {
62 Bundle b = new Bundle();
63 Log.i(TAG, "callBack: " + s);
64 b.putString("callback_string", s);
65 Message m = Message.obtain();
66 m.setData(b);
67 m.setTarget(h);
68 m.sendToTarget();
69 }
70
71 public static void incomingCall(String accountID, String callID, String from) {
72 Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")");
Emeric Vigier9701e032012-09-12 12:38:01 -040073
74 // FIXME that's ugly...
75 uiThread.runOnUiThread(new Runnable() {
76 public void run() {
77 try {
78 buttonCall.startAnimation(animation);
79 buttonCall.setImageResource(R.drawable.ic_incomingcall);
80 } catch (Exception e) {
81 Log.w(TAG, "exception in runOnUiThread ", e);
82 }
83 }
84 });
85
86 uiThread.setIncomingCallID(callID);
87 }
88
89 // FIXME
Alexandre Savard398ce1b2012-09-12 17:34:41 -040090 public static void setCallButton(ImageButton b) {
91 buttonCall = b;
Emeric Vigier9701e032012-09-12 12:38:01 -040092 }
93
94 public static void setActivity(SFLPhoneHome a) {
95 uiThread = a;
96 }
97
98 public static String getAppPath() {
99 return appPath;
100 }
101
102 public static void setAppPath(String path) {
103 appPath = path;
104 }
105
106 public static int getSipLogLevel() {
107 return sipLogLevel;
108 }
109
110 public static native void callVoid();
111 public static native Data getNewData(int i, String s);
112 public static native String getDataString(Data d);
113 public static native String getJniString();
114}