Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 1 | package com.savoirfairelinux.sflphone.client; |
| 2 | |
| 3 | import android.os.Handler; |
| 4 | import android.os.Bundle; |
| 5 | import android.os.Message; |
| 6 | import android.util.Log; |
| 7 | import android.view.animation.AlphaAnimation; |
| 8 | import android.view.animation.Animation; |
| 9 | import android.view.animation.LinearInterpolator; |
| 10 | import android.widget.ImageButton; |
| 11 | |
| 12 | import com.savoirfairelinux.sflphone.R; |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame^] | 13 | import com.savoirfairelinux.sflphone.service.CallManagerCallBack; |
| 14 | import com.savoirfairelinux.sflphone.service.CallManagerJNI; |
| 15 | import com.savoirfairelinux.sflphone.service.ManagerImpl; |
| 16 | import com.savoirfairelinux.sflphone.service.SFLPhoneservice; |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 17 | |
| 18 | public class Manager { |
| 19 | |
| 20 | private static final String TAG = "Manager"; |
| 21 | private static int sipLogLevel = 6; |
| 22 | static Handler h; |
Alexandre Savard | 398ce1b | 2012-09-12 17:34:41 -0400 | [diff] [blame] | 23 | // private static ButtonSectionFragment buttonSecFragment; |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 24 | static String appPath; |
| 25 | static Animation animation; |
| 26 | static SFLPhoneHome uiThread; |
| 27 | static ImageButton buttonCall; |
| 28 | public static ManagerImpl managerImpl; |
Emeric Vigier | 9380ae5 | 2012-09-14 17:40:39 -0400 | [diff] [blame] | 29 | public CallManagerJNI callmanagerJNI; |
| 30 | public CallManagerCallBack callManagerCallBack; |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 31 | |
| 32 | static { |
| 33 | // FIXME: this is the 2nd time we call ManagerImpl's constructor. |
| 34 | // First time was at JNI_OnLoad... |
Emeric Vigier | 9380ae5 | 2012-09-14 17:40:39 -0400 | [diff] [blame] | 35 | // managerImpl = new ManagerImpl(sflphoneserviceJNI.instance(), true); |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame^] | 36 | managerImpl = SFLPhoneservice.instance(); |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 37 | 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 Vigier | 9380ae5 | 2012-09-14 17:40:39 -0400 | [diff] [blame] | 55 | callmanagerJNI = new CallManagerJNI(); |
| 56 | callManagerCallBack = new CallManagerCallBack(); |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame^] | 57 | SFLPhoneservice.setCallbackObject(callManagerCallBack); |
| 58 | Log.i(TAG, "callManagerCallBack = " + callManagerCallBack); |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 59 | } |
| 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 Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 73 | |
| 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 Savard | 398ce1b | 2012-09-12 17:34:41 -0400 | [diff] [blame] | 90 | public static void setCallButton(ImageButton b) { |
| 91 | buttonCall = b; |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 92 | } |
| 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 | } |