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; |
| 25 | |
| 26 | static { |
| 27 | // FIXME: this is the 2nd time we call ManagerImpl's constructor. |
| 28 | // First time was at JNI_OnLoad... |
| 29 | managerImpl = new ManagerImpl(sflphoneserviceJNI.instance(), true); |
| 30 | Log.i(TAG, "ManagerImpl::instance() = " + managerImpl); |
| 31 | } |
| 32 | |
| 33 | public Manager() {} |
| 34 | |
| 35 | public Manager(Handler h) { |
| 36 | // Change alpha from fully visible to invisible |
| 37 | animation = new AlphaAnimation(1, 0); |
| 38 | // duration - half a second |
| 39 | animation.setDuration(500); |
| 40 | // do not alter animation rate |
| 41 | animation.setInterpolator(new LinearInterpolator()); |
| 42 | // Repeat animation infinitely |
| 43 | animation.setRepeatCount(Animation.INFINITE); |
| 44 | // Reverse |
| 45 | animation.setRepeatMode(Animation.REVERSE); |
| 46 | |
| 47 | this.h = h; |
| 48 | } |
| 49 | |
| 50 | public static void callBack(String s) { |
| 51 | Bundle b = new Bundle(); |
| 52 | Log.i(TAG, "callBack: " + s); |
| 53 | b.putString("callback_string", s); |
| 54 | Message m = Message.obtain(); |
| 55 | m.setData(b); |
| 56 | m.setTarget(h); |
| 57 | m.sendToTarget(); |
| 58 | } |
| 59 | |
| 60 | public static void incomingCall(String accountID, String callID, String from) { |
| 61 | Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")"); |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 62 | |
| 63 | // FIXME that's ugly... |
| 64 | uiThread.runOnUiThread(new Runnable() { |
| 65 | public void run() { |
| 66 | try { |
| 67 | buttonCall.startAnimation(animation); |
| 68 | buttonCall.setImageResource(R.drawable.ic_incomingcall); |
| 69 | } catch (Exception e) { |
| 70 | Log.w(TAG, "exception in runOnUiThread ", e); |
| 71 | } |
| 72 | } |
| 73 | }); |
| 74 | |
| 75 | uiThread.setIncomingCallID(callID); |
| 76 | } |
| 77 | |
| 78 | // FIXME |
Alexandre Savard | 398ce1b | 2012-09-12 17:34:41 -0400 | [diff] [blame] | 79 | public static void setCallButton(ImageButton b) { |
| 80 | buttonCall = b; |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | public static void setActivity(SFLPhoneHome a) { |
| 84 | uiThread = a; |
| 85 | } |
| 86 | |
| 87 | public static String getAppPath() { |
| 88 | return appPath; |
| 89 | } |
| 90 | |
| 91 | public static void setAppPath(String path) { |
| 92 | appPath = path; |
| 93 | } |
| 94 | |
| 95 | public static int getSipLogLevel() { |
| 96 | return sipLogLevel; |
| 97 | } |
| 98 | |
| 99 | public static native void callVoid(); |
| 100 | public static native Data getNewData(int i, String s); |
| 101 | public static native String getDataString(Data d); |
| 102 | public static native String getJniString(); |
| 103 | } |