Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Examples/restcomm-olympus/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Examples/restcomm-olympus/app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,83 +26,89 @@
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatDialogFragment;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.util.ArrayList;
import java.util.Map;

import static org.restcomm.android.olympus.ContactsController.CONTACT_KEY;
import static org.restcomm.android.olympus.ContactsController.CONTACT_VALUE;

public class AddUserDialogFragment extends AppCompatDialogFragment {
public static final int DIALOG_TYPE_ADD_CONTACT = 0;
public static final int DIALOG_TYPE_UPDATE_CONTACT = 1;
EditText txtUsername;
EditText txtSipuri;
// Use this instance of the interface to deliver action events
ContactDialogListener listener;


/* The activity that creates an instance of this dialog fragment must
* implement this interface in order to receive event callbacks.
* Each method passes the DialogFragment in case the host needs to query it. */
public interface ContactDialogListener {
public void onDialogPositiveClick(int type, String username, String sipuri);

public void onDialogNegativeClick();
}

/**
* Create a new instance of MyDialogFragment, providing "num"
* as an argument.
*/
public static AddUserDialogFragment newInstance(int type, String username, String sipuri)
{
AddUserDialogFragment f = new AddUserDialogFragment();

// Supply num input as an argument.
Bundle args = new Bundle();
args.putInt("type", type);
if (type == DIALOG_TYPE_UPDATE_CONTACT) {
args.putString(CONTACT_KEY, username);
args.putString(CONTACT_VALUE, sipuri);
}
f.setArguments(args);

return f;
}

// Override the Fragment.onAttach() method to instantiate the NoticeDialogListener
@Override
public void onAttach(Activity activity)
{
super.onAttach(activity);
// Verify that the host activity implements the callback interface
try {
// Instantiate the NoticeDialogListener so we can send events to the host
listener = (ContactDialogListener) activity;
}
catch (ClassCastException e) {
// The activity doesn't implement the interface, throw exception
throw new ClassCastException(activity.toString()
+ " must implement ContactDialogListener");
}
}

@Override
public void onDetach()
{
super.onDetach();
listener = null;
}

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

}
public static final int DIALOG_TYPE_ADD_CONTACT = 0;
public static final int DIALOG_TYPE_UPDATE_CONTACT = 1;
EditText txtUsername;
EditText txtSipuri;
private ArrayList<Map<String, String>> contactList;
// Use this instance of the interface to deliver action events
ContactDialogListener listener;

public Button buttonImportUsers;


/* The activity that creates an instance of this dialog fragment must
* implement this interface in order to receive event callbacks.
* Each method passes the DialogFragment in case the host needs to query it. */
public interface ContactDialogListener {
public void onDialogPositiveClick(int type, String username, String sipuri);

public void onDialogNegativeClick();
}

/**
* Create a new instance of MyDialogFragment, providing "num"
* as an argument.
*/
public static AddUserDialogFragment newInstance(int type, String username, String sipuri) {
AddUserDialogFragment f = new AddUserDialogFragment();

// Supply num input as an argument.
Bundle args = new Bundle();
args.putInt("type", type);
if (type == DIALOG_TYPE_UPDATE_CONTACT) {
args.putString(CONTACT_KEY, username);
args.putString(CONTACT_VALUE, sipuri);
}
f.setArguments(args);

return f;
}

// Override the Fragment.onAttach() method to instantiate the NoticeDialogListener
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// Verify that the host activity implements the callback interface
try {
// Instantiate the NoticeDialogListener so we can send events to the host
listener = (ContactDialogListener) activity;
} catch (ClassCastException e) {
// The activity doesn't implement the interface, throw exception
throw new ClassCastException(activity.toString()
+ " must implement ContactDialogListener");
}
}

@Override
public void onDetach() {
super.onDetach();
listener = null;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

}

/* Not to be used when onCreateDialog is overriden (it is for non-alert dialog fragments
@Override
Expand All @@ -116,51 +122,90 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
}
*/

// Notice that for this doesn't work if onCreateView has been overriden as described above. To add
// custom view when using alert we need to use builder.setView() as seen below
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
// Get the layout inflater
View view = getActivity().getLayoutInflater().inflate(R.layout.fragment_dialog_add_contact, null);
txtUsername = (EditText) view.findViewById(R.id.editText_username);
txtSipuri = (EditText) view.findViewById(R.id.editText_sipuri);

String title = "Add Contact";
String positiveText = "Add";
if (getArguments().getInt("type") == DIALOG_TYPE_UPDATE_CONTACT) {
title = "Update Contact";
positiveText = "Update";

txtUsername.setText(getArguments().getString(CONTACT_KEY, ""));
txtSipuri.setText(getArguments().getString(CONTACT_VALUE, ""));
// username is not modifiable
txtUsername.setEnabled(false);
}

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle);

// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
builder.setView(view)
.setTitle(title)
.setPositiveButton(positiveText,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton)
{
listener.onDialogPositiveClick(getArguments().getInt("type"), txtUsername.getText().toString(),
txtSipuri.getText().toString());
}
}
)
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton)
{
listener.onDialogNegativeClick();
}
}
);
return builder.create();
}
// Notice that for this doesn't work if onCreateView has been overriden as described above. To add
// custom view when using alert we need to use builder.setView() as seen below
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Get the layout inflater
View view = getActivity().getLayoutInflater().inflate(R.layout.fragment_dialog_add_contact, null);
txtUsername = (EditText) view.findViewById(R.id.editText_username);
txtSipuri = (EditText) view.findViewById(R.id.editText_sipuri);
buttonImportUsers = (Button) view.findViewById(R.id.button_contactFromPhone);

String title = "Add Contact";
String positiveText = "Add";
if (getArguments().getInt("type") == DIALOG_TYPE_UPDATE_CONTACT) {
title = "Update Contact";
positiveText = "Update";

txtUsername.setText(getArguments().getString(CONTACT_KEY, ""));
txtSipuri.setText(getArguments().getString(CONTACT_VALUE, ""));
// username is not modifiable
txtUsername.setEnabled(false);
}

buttonImportUsers.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
importContacts();
}
});

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle);

// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
builder.setView(view)
.setTitle(title)
.setPositiveButton(positiveText,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
listener.onDialogPositiveClick(getArguments().getInt("type"), txtUsername.getText().toString(),
txtSipuri.getText().toString());
}
}
)
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
listener.onDialogNegativeClick();
}
}
);
return builder.create();
}

private void importContacts() {

final MainFragment.ContactAdapter contactAdapter = new MainFragment.ContactAdapter(getContext(), contactList);
final Cursor phones = getContext().getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
final ContactsController contactsController = new ContactsController(getContext());
contactList = contactsController.retrieveContacts();

final ProgressDialog progressDialog = ProgressDialog.show(getContext(), "Loading", "Importing the contacts", true);
AsyncTask.execute(new Runnable() {
@Override
public void run() {

while (phones.moveToNext()) {

String name = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

try {
contactsController.addContact(contactList, name, phoneNumber);
} catch (Exception e) {
e.printStackTrace();
}


}

contactAdapter.notifyDataSetChanged();
progressDialog.dismiss();
}
});


}
}
Loading