Changeset 5017 for pjproject/trunk/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/CallActivity.java
- Timestamp:
- Mar 22, 2015 10:22:44 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/CallActivity.java
r5014 r5017 32 32 33 33 public class CallActivity extends Activity 34 implements Handler.Callback, SurfaceHolder.Callback34 implements Handler.Callback, SurfaceHolder.Callback 35 35 { 36 37 public static Handler handler_; 38 39 private final Handler handler = new Handler(this); 40 private static CallInfo lastCallInfo; 41 42 @Override 43 protected void onCreate(Bundle savedInstanceState) { 44 super.onCreate(savedInstanceState); 45 setContentView(R.layout.activity_call); 46 47 SurfaceView surfaceView = (SurfaceView)findViewById(R.id.surfaceIncomingVideo); 48 if (MainActivity.currentCall == null || 49 MainActivity.currentCall.vidWin == null) 50 { 51 surfaceView.setVisibility(View.GONE); 52 } 53 surfaceView.getHolder().addCallback(this); 54 55 handler_ = handler; 56 if (MainActivity.currentCall != null) { 57 try { 58 lastCallInfo = MainActivity.currentCall.getInfo(); 59 updateCallState(lastCallInfo); 60 } catch (Exception e) { 61 System.out.println(e); 62 } 63 } else { 64 updateCallState(lastCallInfo); 65 } 66 } 36 37 public static Handler handler_; 38 39 private final Handler handler = new Handler(this); 40 private static CallInfo lastCallInfo; 67 41 68 42 @Override 69 protected void onDestroy() { 70 super.onDestroy(); 71 handler_ = null; 72 } 73 74 private void updateVideoWindow(SurfaceHolder holder) { 75 if (MainActivity.currentCall != null && 76 MainActivity.currentCall.vidWin != null) 77 { 78 VideoWindowHandle vidWH = new VideoWindowHandle(); 79 if (holder == null) 80 vidWH.getHandle().setWindow(null); 81 else 82 vidWH.getHandle().setWindow(holder.getSurface()); 83 try { 84 MainActivity.currentCall.vidWin.setWindow(vidWH); 85 } catch (Exception e) {} 86 } 87 } 88 89 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { 90 updateVideoWindow(holder); 91 } 92 93 public void surfaceCreated(SurfaceHolder holder) { 94 } 95 96 public void surfaceDestroyed(SurfaceHolder holder) { 97 updateVideoWindow(null); 98 } 99 100 public void acceptCall(View view) { 101 CallOpParam prm = new CallOpParam(); 102 prm.setStatusCode(pjsip_status_code.PJSIP_SC_OK); 103 try { 104 MainActivity.currentCall.answer(prm); 105 } catch (Exception e) { 106 System.out.println(e); 107 } 108 109 view.setVisibility(View.GONE); 110 } 111 112 public void hangupCall(View view) { 113 handler_ = null; 114 finish(); 115 116 if (MainActivity.currentCall != null) { 117 CallOpParam prm = new CallOpParam(); 118 prm.setStatusCode(pjsip_status_code.PJSIP_SC_DECLINE); 119 try { 120 MainActivity.currentCall.hangup(prm); 121 } catch (Exception e) { 122 System.out.println(e); 123 } 124 } 125 } 126 127 private void setupVideoSurface() { 128 129 SurfaceView surfaceView = (SurfaceView)findViewById(R.id.surfaceIncomingVideo); 130 surfaceView.setVisibility(View.VISIBLE); 131 updateVideoWindow(surfaceView.getHolder()); 132 133 } 134 135 @Override 136 public boolean handleMessage(Message m) { 137 138 if (m.what == MainActivity.MSG_TYPE.CALL_STATE) { 139 140 lastCallInfo = (CallInfo) m.obj; 141 updateCallState(lastCallInfo); 142 143 } else if (m.what == MainActivity.MSG_TYPE.CALL_MEDIA_STATE) { 144 145 if (MainActivity.currentCall.vidWin != null) { 146 /* If there's incoming video, display it. */ 147 setupVideoSurface(); 148 } 149 150 } else { 151 152 /* Message not handled */ 153 return false; 154 155 } 156 157 return true; 158 } 159 160 private void updateCallState(CallInfo ci) { 161 TextView tvPeer = (TextView) findViewById(R.id.textViewPeer); 162 TextView tvState = (TextView) findViewById(R.id.textViewCallState); 163 Button buttonHangup = (Button) findViewById(R.id.buttonHangup); 164 Button buttonAccept = (Button) findViewById(R.id.buttonAccept); 165 String call_state = ""; 166 167 if (ci.getRole() == pjsip_role_e.PJSIP_ROLE_UAC) { 168 buttonAccept.setVisibility(View.GONE); 169 } 170 171 if (ci.getState().swigValue() < pjsip_inv_state.PJSIP_INV_STATE_CONFIRMED.swigValue()) 172 { 173 if (ci.getRole() == pjsip_role_e.PJSIP_ROLE_UAS) { 174 call_state = "Incoming call.."; 175 /* Default button texts are already 'Accept' & 'Reject' */ 176 } else { 177 buttonHangup.setText("Cancel"); 178 call_state = ci.getStateText(); 179 } 180 } 181 else if (ci.getState().swigValue() >= pjsip_inv_state.PJSIP_INV_STATE_CONFIRMED.swigValue()) 182 { 183 buttonAccept.setVisibility(View.GONE); 184 call_state = ci.getStateText(); 185 if (ci.getState() == pjsip_inv_state.PJSIP_INV_STATE_CONFIRMED) { 186 buttonHangup.setText("Hangup"); 187 } else if (ci.getState() == pjsip_inv_state.PJSIP_INV_STATE_DISCONNECTED) { 188 buttonHangup.setText("OK"); 189 call_state = "Call disconnected: " + ci.getLastReason(); 190 } 191 } 192 193 tvPeer.setText(ci.getRemoteUri()); 194 tvState.setText(call_state); 195 } 43 protected void onCreate(Bundle savedInstanceState) 44 { 45 super.onCreate(savedInstanceState); 46 setContentView(R.layout.activity_call); 47 48 SurfaceView surfaceView = (SurfaceView) 49 findViewById(R.id.surfaceIncomingVideo); 50 if (MainActivity.currentCall == null || 51 MainActivity.currentCall.vidWin == null) 52 { 53 surfaceView.setVisibility(View.GONE); 54 } 55 surfaceView.getHolder().addCallback(this); 56 57 handler_ = handler; 58 if (MainActivity.currentCall != null) { 59 try { 60 lastCallInfo = MainActivity.currentCall.getInfo(); 61 updateCallState(lastCallInfo); 62 } catch (Exception e) { 63 System.out.println(e); 64 } 65 } else { 66 updateCallState(lastCallInfo); 67 } 68 } 69 70 @Override 71 protected void onDestroy() 72 { 73 super.onDestroy(); 74 handler_ = null; 75 } 76 77 private void updateVideoWindow(SurfaceHolder holder) 78 { 79 if (MainActivity.currentCall != null && 80 MainActivity.currentCall.vidWin != null) 81 { 82 VideoWindowHandle vidWH = new VideoWindowHandle(); 83 if (holder == null) 84 vidWH.getHandle().setWindow(null); 85 else 86 vidWH.getHandle().setWindow(holder.getSurface()); 87 try { 88 MainActivity.currentCall.vidWin.setWindow(vidWH); 89 } catch (Exception e) {} 90 } 91 } 92 93 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) 94 { 95 updateVideoWindow(holder); 96 } 97 98 public void surfaceCreated(SurfaceHolder holder) 99 { 100 } 101 102 public void surfaceDestroyed(SurfaceHolder holder) 103 { 104 updateVideoWindow(null); 105 } 106 107 public void acceptCall(View view) 108 { 109 CallOpParam prm = new CallOpParam(); 110 prm.setStatusCode(pjsip_status_code.PJSIP_SC_OK); 111 try { 112 MainActivity.currentCall.answer(prm); 113 } catch (Exception e) { 114 System.out.println(e); 115 } 116 117 view.setVisibility(View.GONE); 118 } 119 120 public void hangupCall(View view) 121 { 122 handler_ = null; 123 finish(); 124 125 if (MainActivity.currentCall != null) { 126 CallOpParam prm = new CallOpParam(); 127 prm.setStatusCode(pjsip_status_code.PJSIP_SC_DECLINE); 128 try { 129 MainActivity.currentCall.hangup(prm); 130 } catch (Exception e) { 131 System.out.println(e); 132 } 133 } 134 } 135 136 private void setupVideoSurface() 137 { 138 SurfaceView surfaceView = (SurfaceView) 139 findViewById(R.id.surfaceIncomingVideo); 140 surfaceView.setVisibility(View.VISIBLE); 141 updateVideoWindow(surfaceView.getHolder()); 142 } 143 144 @Override 145 public boolean handleMessage(Message m) 146 { 147 if (m.what == MainActivity.MSG_TYPE.CALL_STATE) { 148 149 lastCallInfo = (CallInfo) m.obj; 150 updateCallState(lastCallInfo); 151 152 } else if (m.what == MainActivity.MSG_TYPE.CALL_MEDIA_STATE) { 153 154 if (MainActivity.currentCall.vidWin != null) { 155 /* If there's incoming video, display it. */ 156 setupVideoSurface(); 157 } 158 159 } else { 160 161 /* Message not handled */ 162 return false; 163 164 } 165 166 return true; 167 } 168 169 private void updateCallState(CallInfo ci) { 170 TextView tvPeer = (TextView) findViewById(R.id.textViewPeer); 171 TextView tvState = (TextView) findViewById(R.id.textViewCallState); 172 Button buttonHangup = (Button) findViewById(R.id.buttonHangup); 173 Button buttonAccept = (Button) findViewById(R.id.buttonAccept); 174 String call_state = ""; 175 176 if (ci.getRole() == pjsip_role_e.PJSIP_ROLE_UAC) { 177 buttonAccept.setVisibility(View.GONE); 178 } 179 180 if (ci.getState().swigValue() < 181 pjsip_inv_state.PJSIP_INV_STATE_CONFIRMED.swigValue()) 182 { 183 if (ci.getRole() == pjsip_role_e.PJSIP_ROLE_UAS) { 184 call_state = "Incoming call.."; 185 /* Default button texts are already 'Accept' & 'Reject' */ 186 } else { 187 buttonHangup.setText("Cancel"); 188 call_state = ci.getStateText(); 189 } 190 } 191 else if (ci.getState().swigValue() >= 192 pjsip_inv_state.PJSIP_INV_STATE_CONFIRMED.swigValue()) 193 { 194 buttonAccept.setVisibility(View.GONE); 195 call_state = ci.getStateText(); 196 if (ci.getState() == pjsip_inv_state.PJSIP_INV_STATE_CONFIRMED) { 197 buttonHangup.setText("Hangup"); 198 } else if (ci.getState() == 199 pjsip_inv_state.PJSIP_INV_STATE_DISCONNECTED) 200 { 201 buttonHangup.setText("OK"); 202 call_state = "Call disconnected: " + ci.getLastReason(); 203 } 204 } 205 206 tvPeer.setText(ci.getRemoteUri()); 207 tvState.setText(call_state); 208 } 196 209 }
Note: See TracChangeset
for help on using the changeset viewer.