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; |
| 13 | |
| 14 | public class Manager { |
| 15 | |
| 16 | private static final String TAG = "Manager"; |
| 17 | private static int sipLogLevel = 6; |
| 18 | static Handler h; |
Alexandre Savard | 398ce1b | 2012-09-12 17:34:41 -0400 | [diff] [blame] | 19 | // private static ButtonSectionFragment buttonSecFragment; |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 20 | static String appPath; |
| 21 | static Animation animation; |
| 22 | static SFLPhoneHome uiThread; |
| 23 | static ImageButton buttonCall; |
| 24 | public static ManagerImpl managerImpl; |
Emeric Vigier | 9380ae5 | 2012-09-14 17:40:39 -0400 | [diff] [blame^] | 25 | public CallManagerJNI callmanagerJNI; |
| 26 | public CallManagerCallBack callManagerCallBack; |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 27 | |
| 28 | static { |
| 29 | // FIXME: this is the 2nd time we call ManagerImpl's constructor. |
| 30 | // First time was at JNI_OnLoad... |
Emeric Vigier | 9380ae5 | 2012-09-14 17:40:39 -0400 | [diff] [blame^] | 31 | // managerImpl = new ManagerImpl(sflphoneserviceJNI.instance(), true); |
| 32 | managerImpl = sflphoneservice.instance(); |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 33 | 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 Vigier | 9380ae5 | 2012-09-14 17:40:39 -0400 | [diff] [blame^] | 51 | callmanagerJNI = new CallManagerJNI(); |
| 52 | callManagerCallBack = new CallManagerCallBack(); |
| 53 | sflphoneservice.setCallbackObject(callManagerCallBack); |
| 54 | Log.i(TAG, "sflphoneservice.setCallbackObject(callManagerCallBack) = " + callManagerCallBack); |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 55 | } |
| 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 Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 69 | |
| 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 Savard | 398ce1b | 2012-09-12 17:34:41 -0400 | [diff] [blame] | 86 | public static void setCallButton(ImageButton b) { |
| 87 | buttonCall = b; |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 88 | } |
| 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 | } |