added call hold also for incoming calls

This commit is contained in:
Juha Heinanen
2018-03-05 09:10:14 +13:00
parent fe785622ce
commit 6aa4435569
3 changed files with 76 additions and 9 deletions
@@ -3,6 +3,7 @@ package com.tutpro.baresip;
public class Call { public class Call {
private String ua, call, peer_uri, status; private String ua, call, peer_uri, status;
Boolean hold;
public Call(String ua, String call, String peer_uri, String status) { public Call(String ua, String call, String peer_uri, String status) {
this.ua = ua; this.ua = ua;
@@ -29,4 +30,11 @@ public class Call {
public String getStatus() { public String getStatus() {
return status; return status;
} }
public void setHold(Boolean hold) {
this.hold = hold;
}
public Boolean getHold() {
return hold;
}
} }
@@ -28,6 +28,7 @@ public class MainActivity extends AppCompatActivity {
static AutoCompleteTextView callee; static AutoCompleteTextView callee;
static RelativeLayout layout; static RelativeLayout layout;
static Button callButton; static Button callButton;
static Button holdButton;
static ArrayList<Account> Accounts = new ArrayList<>(); static ArrayList<Account> Accounts = new ArrayList<>();
static ArrayList<String> AoRs = new ArrayList<>(); static ArrayList<String> AoRs = new ArrayList<>();
static ArrayList<Integer> Images = new ArrayList<>(); static ArrayList<Integer> Images = new ArrayList<>();
@@ -58,17 +59,28 @@ public class MainActivity extends AppCompatActivity {
ua_current_set(aor); ua_current_set(aor);
ArrayList<Call> out = uaCalls(Out, ua_current()); ArrayList<Call> out = uaCalls(Out, ua_current());
if (out.size() == 0) { if (out.size() == 0) {
callee.setText(""); callee.setHint("Callee");
callButton.setText("Call"); callButton.setText("Call");
holdButton.setVisibility(View.INVISIBLE);
} else { } else {
callee.setText(out.get(0).getPeerURI()); callee.setText(out.get(0).getPeerURI());
callButton.setText(out.get(0).getStatus()); callButton.setText(out.get(0).getStatus());
if (out.get(0).getStatus() == "Hangup") {
if (out.get(0).getHold()) {
holdButton.setText("Unhold");
} else {
holdButton.setText("Hold");
}
holdButton.setVisibility(View.VISIBLE);
} else {
holdButton.setVisibility(View.INVISIBLE);
}
} }
ArrayList<Call> in = uaCalls(In, ua_current()); ArrayList<Call> in = uaCalls(In, ua_current());
int view_count = layout.getChildCount(); int view_count = layout.getChildCount();
Log.d("Baresip", "View count is " + view_count); Log.d("Baresip", "View count is " + view_count);
if (view_count > 4) { if (view_count > 5) {
layout.removeViews(4, view_count - 4); layout.removeViews(5, view_count - 5);
} }
for (Call c: in) { for (Call c: in) {
for (int call_index = 0; call_index < In.size(); call_index++) { for (int call_index = 0; call_index < In.size(); call_index++) {
@@ -164,6 +176,27 @@ public class MainActivity extends AppCompatActivity {
} }
} }
}); });
holdButton = (Button)findViewById(R.id.holdButton);
holdButton.setVisibility(View.INVISIBLE);
holdButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (holdButton.getText().toString().equals("Hold")) {
Log.i("Baresip", "Holding up " +
((EditText) findViewById(R.id.callee)).getText());
call_hold(Out.get(0).getCall());
Out.get(0).setHold(true);
holdButton.setText("Unhold");
} else {
Log.i("Baresip", "Unholding " +
((EditText) findViewById(R.id.callee)).getText());
call_unhold(Out.get(0).getCall());
Out.get(0).setHold(false);
holdButton.setText("Hold");
}
}
});
} }
@Override @Override
@@ -330,7 +363,7 @@ public class MainActivity extends AppCompatActivity {
layout.addView(caller_uri); layout.addView(caller_uri);
Button answer_button = new Button(mainActivityContext); Button answer_button = new Button(mainActivityContext);
answer_button.setText("Answer"); answer_button.setText(call.getStatus());
answer_button.setBackgroundResource(android.R.drawable.btn_default); answer_button.setBackgroundResource(android.R.drawable.btn_default);
answer_button.setTextColor(Color.BLACK); answer_button.setTextColor(Color.BLACK);
Log.d("Baresip", "Creating new answer button at " + (id + 2)); Log.d("Baresip", "Creating new answer button at " + (id + 2));
@@ -347,7 +380,9 @@ public class MainActivity extends AppCompatActivity {
ua_answer(call_ua, call_call); ua_answer(call_ua, call_call);
final int final_in_index = callIndex(In, call_ua, call_call); final int final_in_index = callIndex(In, call_ua, call_call);
if (final_in_index >= 0) { if (final_in_index >= 0) {
Log.d("Baresip", "Changing answer button text to Hangup"); Log.d("Baresip", "Updating Hangup and Hold");
In.get(final_in_index).setStatus("Hangup");
In.get(final_in_index).setHold(false);
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -380,7 +415,15 @@ public class MainActivity extends AppCompatActivity {
layout.addView(answer_button); layout.addView(answer_button);
Button reject_button = new Button(mainActivityContext); Button reject_button = new Button(mainActivityContext);
if (call.getStatus() == "Answer") {
reject_button.setText("Reject"); reject_button.setText("Reject");
} else {
if (call.getHold()) {
reject_button.setText("Unhold");
} else {
reject_button.setText("Hold");
}
}
reject_button.setBackgroundResource(android.R.drawable.btn_default); reject_button.setBackgroundResource(android.R.drawable.btn_default);
reject_button.setTextColor(Color.BLACK); reject_button.setTextColor(Color.BLACK);
Log.d("Baresip", "Creating new reject button at " + (id + 3)); Log.d("Baresip", "Creating new reject button at " + (id + 3));
@@ -397,10 +440,12 @@ public class MainActivity extends AppCompatActivity {
case "Hold": case "Hold":
call_hold(call.getCall()); call_hold(call.getCall());
((Button)v).setText("Unhold"); ((Button)v).setText("Unhold");
call.setHold(true);
break; break;
case "Unhold": case "Unhold":
call_unhold(call.getCall()); call_unhold(call.getCall());
((Button)v).setText("Hold"); ((Button)v).setText("Hold");
call.setHold(false);
break; break;
} }
} }
@@ -470,16 +515,19 @@ public class MainActivity extends AppCompatActivity {
case "call ringing": case "call ringing":
break; break;
case "call established": case "call established":
Log.d("Baresip", "Out call number is " + Out.size()); Log.d("Baresip", "Out call index is " + (Out.size() - 1));
int out_index = callIndex(Out, ua, call); int out_index = callIndex(Out, ua, call);
if (out_index >= 0) { if (out_index >= 0) {
Log.d("Baresip", "Changing call button text to Hangup"); Log.d("Baresip", "Update Hangup and Hold");
Out.get(out_index).setStatus("Hangup"); Out.get(out_index).setStatus("Hangup");
Out.get(out_index).setHold(false);
if (ua.equals(ua_current())) { if (ua.equals(ua_current())) {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
callButton.setText("Hangup"); callButton.setText("Hangup");
holdButton.setText("Hold");
holdButton.setVisibility(View.VISIBLE);
} }
}); });
} }
@@ -543,6 +591,7 @@ public class MainActivity extends AppCompatActivity {
public void run() { public void run() {
callButton.setText("Call"); callButton.setText("Call");
callButton.setEnabled(true); callButton.setEnabled(true);
holdButton.setVisibility(View.INVISIBLE);
} }
}); });
} }
+11 -1
View File
@@ -53,8 +53,18 @@
android:layout_width="96dp" android:layout_width="96dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@android:drawable/btn_default" android:background="@android:drawable/btn_default"
android:layout_below="@id/callee" >
</Button>
<Button
android:id="@+id/holdButton"
android:layout_width="96dp"
android:layout_height="wrap_content"
android:background="@android:drawable/btn_default"
android:text="Hold"
android:layout_below="@id/callee" android:layout_below="@id/callee"
android:text="@id/callee" > android:layout_marginLeft="106dp"
android:visibility="invisible" >
</Button> </Button>
</RelativeLayout> </RelativeLayout>