blob: 0da5c1a402e6097626cf9c5a658dcec9b52c15fd [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;
13
14public class Manager {
15
16 private static final String TAG = "Manager";
17 private static int sipLogLevel = 6;
18 static Handler h;
Alexandre Savard398ce1b2012-09-12 17:34:41 -040019 // private static ButtonSectionFragment buttonSecFragment;
Emeric Vigier9701e032012-09-12 12:38:01 -040020 static String appPath;
21 static Animation animation;
22 static SFLPhoneHome uiThread;
23 static ImageButton buttonCall;
24 public static ManagerImpl managerImpl;
Emeric Vigier9380ae52012-09-14 17:40:39 -040025 public CallManagerJNI callmanagerJNI;
26 public CallManagerCallBack callManagerCallBack;
Emeric Vigier9701e032012-09-12 12:38:01 -040027
28 static {
29 // FIXME: this is the 2nd time we call ManagerImpl's constructor.
30 // First time was at JNI_OnLoad...
Emeric Vigier9380ae52012-09-14 17:40:39 -040031// managerImpl = new ManagerImpl(sflphoneserviceJNI.instance(), true);
32 managerImpl = sflphoneservice.instance();
Emeric Vigier9701e032012-09-12 12:38:01 -040033 Log.i(TAG, "ManagerImpl::instance() = " + managerImpl);
34 }
35
36 public Manager() {}
37
38 public Manager(Handler h) {
39 // Change alpha from fully visible to invisible
40 animation = new AlphaAnimation(1, 0);
41 // duration - half a second
42 animation.setDuration(500);
43 // do not alter animation rate
44 animation.setInterpolator(new LinearInterpolator());
45 // Repeat animation infinitely
46 animation.setRepeatCount(Animation.INFINITE);
47 // Reverse
48 animation.setRepeatMode(Animation.REVERSE);
49
50 this.h = h;
Emeric Vigier9380ae52012-09-14 17:40:39 -040051 callmanagerJNI = new CallManagerJNI();
52 callManagerCallBack = new CallManagerCallBack();
53 sflphoneservice.setCallbackObject(callManagerCallBack);
54 Log.i(TAG, "sflphoneservice.setCallbackObject(callManagerCallBack) = " + callManagerCallBack);
Emeric Vigier9701e032012-09-12 12:38:01 -040055 }
56
57 public static void callBack(String s) {
58 Bundle b = new Bundle();
59 Log.i(TAG, "callBack: " + s);
60 b.putString("callback_string", s);
61 Message m = Message.obtain();
62 m.setData(b);
63 m.setTarget(h);
64 m.sendToTarget();
65 }
66
67 public static void incomingCall(String accountID, String callID, String from) {
68 Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")");
Emeric Vigier9701e032012-09-12 12:38:01 -040069
70 // FIXME that's ugly...
71 uiThread.runOnUiThread(new Runnable() {
72 public void run() {
73 try {
74 buttonCall.startAnimation(animation);
75 buttonCall.setImageResource(R.drawable.ic_incomingcall);
76 } catch (Exception e) {
77 Log.w(TAG, "exception in runOnUiThread ", e);
78 }
79 }
80 });
81
82 uiThread.setIncomingCallID(callID);
83 }
84
85 // FIXME
Alexandre Savard398ce1b2012-09-12 17:34:41 -040086 public static void setCallButton(ImageButton b) {
87 buttonCall = b;
Emeric Vigier9701e032012-09-12 12:38:01 -040088 }
89
90 public static void setActivity(SFLPhoneHome a) {
91 uiThread = a;
92 }
93
94 public static String getAppPath() {
95 return appPath;
96 }
97
98 public static void setAppPath(String path) {
99 appPath = path;
100 }
101
102 public static int getSipLogLevel() {
103 return sipLogLevel;
104 }
105
106 public static native void callVoid();
107 public static native Data getNewData(int i, String s);
108 public static native String getDataString(Data d);
109 public static native String getJniString();
110}