From 6dd309f78bdc7300030f09ea1e8b78ee4d347bb9 Mon Sep 17 00:00:00 2001 From: Sagar Vakkala Date: Tue, 6 Jun 2017 16:41:23 +0530 Subject: [PATCH 1/2] Implementing all phone contacts Added a feature to import all contacts in the phone to Olympus app --- Examples/restcomm-olympus/.idea/misc.xml | 2 +- Examples/restcomm-olympus/app/app.iml | 14 +- .../olympus/AddUserDialogFragment.java | 273 +++--- .../android/olympus/MainActivity.java | 845 +++++++++--------- .../android/olympus/MainFragment.java | 2 +- .../drawable-xhdpi/custom_orange_button.xml | 10 + .../layout/fragment_dialog_add_contact.xml | 12 + 7 files changed, 612 insertions(+), 546 deletions(-) create mode 100644 Examples/restcomm-olympus/app/src/main/res/drawable-xhdpi/custom_orange_button.xml diff --git a/Examples/restcomm-olympus/.idea/misc.xml b/Examples/restcomm-olympus/.idea/misc.xml index fbb68289..5d199810 100644 --- a/Examples/restcomm-olympus/.idea/misc.xml +++ b/Examples/restcomm-olympus/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/Examples/restcomm-olympus/app/app.iml b/Examples/restcomm-olympus/app/app.iml index 2d848d21..ee5e2512 100644 --- a/Examples/restcomm-olympus/app/app.iml +++ b/Examples/restcomm-olympus/app/app.iml @@ -62,13 +62,6 @@ - - - - - - - @@ -76,6 +69,13 @@ + + + + + + + diff --git a/Examples/restcomm-olympus/app/src/main/java/org/restcomm/android/olympus/AddUserDialogFragment.java b/Examples/restcomm-olympus/app/src/main/java/org/restcomm/android/olympus/AddUserDialogFragment.java index d06265a0..9f347edb 100644 --- a/Examples/restcomm-olympus/app/src/main/java/org/restcomm/android/olympus/AddUserDialogFragment.java +++ b/Examples/restcomm-olympus/app/src/main/java/org/restcomm/android/olympus/AddUserDialogFragment.java @@ -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> 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 @@ -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(); + } + }); + + + } } \ No newline at end of file diff --git a/Examples/restcomm-olympus/app/src/main/java/org/restcomm/android/olympus/MainActivity.java b/Examples/restcomm-olympus/app/src/main/java/org/restcomm/android/olympus/MainActivity.java index e58fa7a5..622b1b7a 100644 --- a/Examples/restcomm-olympus/app/src/main/java/org/restcomm/android/olympus/MainActivity.java +++ b/Examples/restcomm-olympus/app/src/main/java/org/restcomm/android/olympus/MainActivity.java @@ -22,6 +22,7 @@ package org.restcomm.android.olympus; +import android.Manifest; import android.app.AlertDialog; import android.app.DialogFragment; import android.content.ComponentCallbacks; @@ -31,6 +32,7 @@ import android.content.Intent; import android.content.ServiceConnection; import android.content.SharedPreferences; +import android.content.pm.PackageManager; import android.content.res.Configuration; import android.graphics.drawable.ColorDrawable; import android.net.Uri; @@ -38,6 +40,8 @@ import android.os.IBinder; import android.preference.PreferenceManager; import android.support.design.widget.FloatingActionButton; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; @@ -45,6 +49,7 @@ import android.view.MenuItem; import android.view.View; import android.widget.Toast; + import com.testfairy.TestFairy; //import net.hockeyapp.android.CrashManager; //import net.hockeyapp.android.UpdateManager; @@ -60,125 +65,148 @@ import static org.restcomm.android.olympus.ContactsController.CONTACT_VALUE; public class MainActivity extends AppCompatActivity - implements MainFragment.Callbacks, RCDeviceListener, - View.OnClickListener, SharedPreferences.OnSharedPreferenceChangeListener, - AddUserDialogFragment.ContactDialogListener, ServiceConnection, ComponentCallbacks, - ComponentCallbacks2 { - - private RCDevice device = null; - boolean serviceBound = false; - - // DEBUG - //ArrayList list = new ArrayList<>(); - - private static final String TAG = "MainActivity"; - SharedPreferences prefs; - private HashMap params; - private MainFragment listFragment; - private AlertDialog alertDialog; - private RCConnectivityStatus previousConnectivityStatus = RCConnectivityStatus.RCConnectivityStatusNone; - private static final String APP_VERSION = "Restcomm Android Olympus Client " + BuildConfig.VERSION_NAME + "#" + BuildConfig.VERSION_CODE; //"Restcomm Android Olympus Client 1.0.0-BETA4#20"; - FloatingActionButton btnAdd; - public static String ACTION_DISCONNECTED_BACKGROUND = "org.restcomm.android.olympus.ACTION_DISCONNECTED_BACKGROUND"; - - private static final int CONNECTION_REQUEST = 1; - - @Override - protected void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - Log.i(TAG, "%% onCreate"); - Log.i(TAG, "Olympus Version: " + APP_VERSION); - - // For TestFairy troubleshooting. IMPORTANT: remove for production apps, as TestFairy sends logs, screenshots, etc to their servers - //TestFairy.begin(this, "#TESTFAIRY_APP_TOKEN"); - TestFairy.begin(this, "52d3ee1de1b7681d1fcbbc3295b2b86a0aa43fcc"); - - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - // TODO set proper image at xhdpi with 48x48 - toolbar.setNavigationIcon(R.drawable.bar_icon_24dp); - toolbar.setTitle(getTitle()); + implements MainFragment.Callbacks, RCDeviceListener, + View.OnClickListener, SharedPreferences.OnSharedPreferenceChangeListener, + AddUserDialogFragment.ContactDialogListener, ServiceConnection, ComponentCallbacks, + ComponentCallbacks2 { - listFragment = (MainFragment) getSupportFragmentManager().findFragmentById(R.id.item_list); + private RCDevice device = null; + boolean serviceBound = false; + private static final int MY_PERMISSIONS_REQUEST_READ_CONTACTS = 56; - btnAdd = (FloatingActionButton) findViewById(R.id.imageButton_add); - btnAdd.setOnClickListener(this); + // DEBUG + //ArrayList list = new ArrayList<>(); - alertDialog = new AlertDialog.Builder(MainActivity.this, R.style.SimpleAlertStyle).create(); + private static final String TAG = "MainActivity"; + SharedPreferences prefs; + private HashMap params; + private MainFragment listFragment; + private AlertDialog alertDialog; + private RCConnectivityStatus previousConnectivityStatus = RCConnectivityStatus.RCConnectivityStatusNone; + private static final String APP_VERSION = "Restcomm Android Olympus Client " + BuildConfig.VERSION_NAME + "#" + BuildConfig.VERSION_CODE; //"Restcomm Android Olympus Client 1.0.0-BETA4#20"; + FloatingActionButton btnAdd; + public static String ACTION_DISCONNECTED_BACKGROUND = "org.restcomm.android.olympus.ACTION_DISCONNECTED_BACKGROUND"; - PreferenceManager.setDefaultValues(this, R.xml.preferences, false); - prefs = PreferenceManager.getDefaultSharedPreferences(this); + private static final int CONNECTION_REQUEST = 1; - // preferences - prefs.registerOnSharedPreferenceChangeListener(this); - - // No longer needed, we'll change with toast - // set it to wifi by default to avoid the status message when starting with wifi - //previousConnectivityStatus = RCConnectivityStatus.RCConnectivityStatusWiFi; - } - - @Override - protected void onStart() - { - super.onStart(); - // The activity is about to become visible. - Log.i(TAG, "%% onStart"); + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); - bindService(new Intent(this, RCDevice.class), this, Context.BIND_AUTO_CREATE); - } + Log.i(TAG, "%% onCreate"); + Log.i(TAG, "Olympus Version: " + APP_VERSION); - @Override - protected void onResume() - { - super.onResume(); + // For TestFairy troubleshooting. IMPORTANT: remove for production apps, as TestFairy sends logs, screenshots, etc to their servers + //TestFairy.begin(this, "#TESTFAIRY_APP_TOKEN"); + TestFairy.begin(this, "52d3ee1de1b7681d1fcbbc3295b2b86a0aa43fcc"); + + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + // TODO set proper image at xhdpi with 48x48 + toolbar.setNavigationIcon(R.drawable.bar_icon_24dp); + toolbar.setTitle(getTitle()); + + listFragment = (MainFragment) getSupportFragmentManager().findFragmentById(R.id.item_list); + + btnAdd = (FloatingActionButton) findViewById(R.id.imageButton_add); + btnAdd.setOnClickListener(this); + + alertDialog = new AlertDialog.Builder(MainActivity.this, R.style.SimpleAlertStyle).create(); + + PreferenceManager.setDefaultValues(this, R.xml.preferences, false); + prefs = PreferenceManager.getDefaultSharedPreferences(this); + + // preferences + prefs.registerOnSharedPreferenceChangeListener(this); + + checkPermissions(); + // No longer needed, we'll change with toast + // set it to wifi by default to avoid the status message when starting with wifi + //previousConnectivityStatus = RCConnectivityStatus.RCConnectivityStatusWiFi; + } + + public void checkPermissions() { + + if (ContextCompat.checkSelfPermission(getApplicationContext(), + Manifest.permission.READ_CONTACTS) + != PackageManager.PERMISSION_GRANTED) { + + // Should we show an explanation? + if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, + Manifest.permission.READ_CONTACTS)) { + + //Don't need to add anything over here for now --Sagar Vakkala + + } else { + + //Didn't add any explanation right now --Sagar Vakkala + + ActivityCompat.requestPermissions(MainActivity.this, + new String[]{Manifest.permission.READ_CONTACTS}, + MY_PERMISSIONS_REQUEST_READ_CONTACTS); + + //Requesting permissions for reading contacts + + + } + } + } + + @Override + protected void onStart() { + super.onStart(); + // The activity is about to become visible. + Log.i(TAG, "%% onStart"); + + bindService(new Intent(this, RCDevice.class), this, Context.BIND_AUTO_CREATE); + } + + @Override + protected void onResume() { + super.onResume(); + + // The activity has become visible (it is now "resumed"). + Log.i(TAG, "%% onResume"); - // The activity has become visible (it is now "resumed"). - Log.i(TAG, "%% onResume"); + if (device != null) { + // needed if we are returning from Message screen that becomes the Device listener + device.setDeviceListener(this); + } + } - if (device != null) { - // needed if we are returning from Message screen that becomes the Device listener - device.setDeviceListener(this); - } - } + @Override + protected void onPause() { + super.onPause(); + // Another activity is taking focus (this activity is about to be "paused"). + Log.i(TAG, "%% onPause"); + } - @Override - protected void onPause() - { - super.onPause(); - // Another activity is taking focus (this activity is about to be "paused"). - Log.i(TAG, "%% onPause"); - } + @Override + protected void onStop() { + super.onStop(); + // The activity is no longer visible (it is now "stopped") + Log.i(TAG, "%% onStop"); - @Override - protected void onStop() - { - super.onStop(); - // The activity is no longer visible (it is now "stopped") - Log.i(TAG, "%% onStop"); - - // Unbind from the service - if (serviceBound) { - //device.detach(); - unbindService(this); - serviceBound = false; - } - } + // Unbind from the service + if (serviceBound) { + //device.detach(); + unbindService(this); + serviceBound = false; + } + } - @Override - protected void onDestroy() - { - super.onDestroy(); - // The activity is about to be destroyed. - Log.i(TAG, "%% onDestroy"); + @Override + protected void onDestroy() { + super.onDestroy(); + // The activity is about to be destroyed. + Log.i(TAG, "%% onDestroy"); /* RCClient.shutdown(); device = null; */ - prefs.unregisterOnSharedPreferenceChangeListener(this); - } + prefs.unregisterOnSharedPreferenceChangeListener(this); + } /* private void checkForCrashes() { @@ -195,107 +223,103 @@ private void unregisterManagers() { } */ - public void onLowMemory() - { - Log.e(TAG, "onLowMemory"); - } - - @Override - public void onTrimMemory(int level) - { - super.onTrimMemory(level); - Log.e(TAG, "onTrimMemory: " + level); - } - - @Override - public void onNewIntent(Intent intent) - { - super.onNewIntent(intent); - - // We get this intent from CallActivity, when the App is in the background and the user has requested hangup via notification - // In that case we don't wont to interrupt the user from what they are currently doing in the foreground, so we just finish() - if (intent.getAction() != null && intent.getAction().equals(ACTION_DISCONNECTED_BACKGROUND)) { - finish(); - } - } - - // Callbacks for service binding, passed to bindService() - @Override - public void onServiceConnected(ComponentName className, IBinder service) - { - Log.i(TAG, "%% onServiceConnected"); - // We've bound to LocalService, cast the IBinder and get LocalService instance - RCDevice.RCDeviceBinder binder = (RCDevice.RCDeviceBinder) service; - device = binder.getService(); - - if (!device.isInitialized()) { - HashMap params = new HashMap(); - params.put(RCDevice.ParameterKeys.INTENT_INCOMING_CALL, new Intent(RCDevice.ACTION_INCOMING_CALL, null, getApplicationContext(), CallActivity.class)); - params.put(RCDevice.ParameterKeys.INTENT_INCOMING_MESSAGE, new Intent(RCDevice.ACTION_INCOMING_MESSAGE, null, getApplicationContext(), MessageActivity.class)); - params.put(RCDevice.ParameterKeys.SIGNALING_DOMAIN, prefs.getString(RCDevice.ParameterKeys.SIGNALING_DOMAIN, "")); - params.put(RCDevice.ParameterKeys.SIGNALING_USERNAME, prefs.getString(RCDevice.ParameterKeys.SIGNALING_USERNAME, "android-sdk")); - params.put(RCDevice.ParameterKeys.SIGNALING_PASSWORD, prefs.getString(RCDevice.ParameterKeys.SIGNALING_PASSWORD, "1234")); - params.put(RCDevice.ParameterKeys.MEDIA_ICE_URL, prefs.getString(RCDevice.ParameterKeys.MEDIA_ICE_URL, "")); - params.put(RCDevice.ParameterKeys.MEDIA_ICE_USERNAME, prefs.getString(RCDevice.ParameterKeys.MEDIA_ICE_USERNAME, "")); - params.put(RCDevice.ParameterKeys.MEDIA_ICE_PASSWORD, prefs.getString(RCDevice.ParameterKeys.MEDIA_ICE_PASSWORD, "")); - params.put(RCDevice.ParameterKeys.MEDIA_ICE_DOMAIN, prefs.getString(RCDevice.ParameterKeys.MEDIA_ICE_DOMAIN, "")); - params.put(RCDevice.ParameterKeys.MEDIA_TURN_ENABLED, prefs.getBoolean(RCDevice.ParameterKeys.MEDIA_TURN_ENABLED, true)); - params.put(RCDevice.ParameterKeys.SIGNALING_SECURE_ENABLED, prefs.getBoolean(RCDevice.ParameterKeys.SIGNALING_SECURE_ENABLED, true)); - // The SDK provides the user with default sounds for calling, ringing, busy (declined) and message, but the user can override them - // by providing their own resource files (i.e. .wav, .mp3, etc) at res/raw passing them with Resource IDs like R.raw.user_provided_calling_sound - //params.put(RCDevice.ParameterKeys.RESOURCE_SOUND_CALLING, R.raw.user_provided_calling_sound); - //params.put(RCDevice.ParameterKeys.RESOURCE_SOUND_RINGING, R.raw.user_provided_ringing_sound); - //params.put(RCDevice.ParameterKeys.RESOURCE_SOUND_DECLINED, R.raw.user_provided_declined_sound); - //params.put(RCDevice.ParameterKeys.RESOURCE_SOUND_MESSAGE, R.raw.user_provided_message_sound); - - // These are for debugging purposes, NOT for release builds! - //params.put(RCDevice.ParameterKeys.DEBUG_JAIN_SIP_LOGGING_ENABLED, prefs.getBoolean(RCDevice.ParameterKeys.DEBUG_JAIN_SIP_LOGGING_ENABLED, true)); - //params.put(RCDevice.ParameterKeys.DEBUG_JAIN_DISABLE_CERTIFICATE_VERIFICATION, prefs.getBoolean(RCDevice.ParameterKeys.DEBUG_JAIN_DISABLE_CERTIFICATE_VERIFICATION, true)); - - device.setLogLevel(Log.VERBOSE); - device.initialize(getApplicationContext(), params, this); - } - - if (device.getState() == RCDevice.DeviceState.OFFLINE) { - getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorTextSecondary))); - } - else { - getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary))); - handleExternalCall(); - } - - serviceBound = true; - } - - @Override - public void onServiceDisconnected(ComponentName arg0) - { - Log.i(TAG, "%% onServiceDisconnected"); - serviceBound = false; - } - - /** - * MainFragment Callbacks - */ - @Override - public void onItemSelected(HashMap contact, MainFragment.ContactSelectionType type) - { - Intent intent = new Intent(this, MessageActivity.class); - intent.setAction(MessageActivity.ACTION_OPEN_MESSAGE_SCREEN); - intent.putExtra(MessageActivity.EXTRA_CONTACT_NAME, contact.get(CONTACT_KEY)); - intent.putExtra(RCDevice.EXTRA_DID, contact.get(CONTACT_VALUE)); - startActivity(intent); - - // forward to onActionClicked - //onActionClicked(ActionFragment.ActionType.ACTION_TYPE_VIDEO_CALL, contact.get(CONTACT_KEY), contact.get(CONTACT_VALUE)); - } - - public void onContactUpdate(HashMap contact, int type) - { - AddUserDialogFragment newFragment = AddUserDialogFragment.newInstance(AddUserDialogFragment.DIALOG_TYPE_UPDATE_CONTACT, contact.get(CONTACT_KEY), contact.get(CONTACT_VALUE)); - newFragment.show(getSupportFragmentManager(), "dialog"); - //newFragment.show(getFragmentManager(), "dialog"); - } + public void onLowMemory() { + Log.e(TAG, "onLowMemory"); + } + + + + @Override + public void onTrimMemory(int level) { + super.onTrimMemory(level); + Log.e(TAG, "onTrimMemory: " + level); + } + + + + @Override + public void onNewIntent(Intent intent) { + super.onNewIntent(intent); + + // We get this intent from CallActivity, when the App is in the background and the user has requested hangup via notification + // In that case we don't wont to interrupt the user from what they are currently doing in the foreground, so we just finish() + if (intent.getAction() != null && intent.getAction().equals(ACTION_DISCONNECTED_BACKGROUND)) { + finish(); + } + } + + // Callbacks for service binding, passed to bindService() + @Override + public void onServiceConnected(ComponentName className, IBinder service) { + Log.i(TAG, "%% onServiceConnected"); + // We've bound to LocalService, cast the IBinder and get LocalService instance + RCDevice.RCDeviceBinder binder = (RCDevice.RCDeviceBinder) service; + device = binder.getService(); + + if (!device.isInitialized()) { + HashMap params = new HashMap(); + params.put(RCDevice.ParameterKeys.INTENT_INCOMING_CALL, new Intent(RCDevice.ACTION_INCOMING_CALL, null, getApplicationContext(), CallActivity.class)); + params.put(RCDevice.ParameterKeys.INTENT_INCOMING_MESSAGE, new Intent(RCDevice.ACTION_INCOMING_MESSAGE, null, getApplicationContext(), MessageActivity.class)); + params.put(RCDevice.ParameterKeys.SIGNALING_DOMAIN, prefs.getString(RCDevice.ParameterKeys.SIGNALING_DOMAIN, "")); + params.put(RCDevice.ParameterKeys.SIGNALING_USERNAME, prefs.getString(RCDevice.ParameterKeys.SIGNALING_USERNAME, "android-sdk")); + params.put(RCDevice.ParameterKeys.SIGNALING_PASSWORD, prefs.getString(RCDevice.ParameterKeys.SIGNALING_PASSWORD, "1234")); + params.put(RCDevice.ParameterKeys.MEDIA_ICE_URL, prefs.getString(RCDevice.ParameterKeys.MEDIA_ICE_URL, "")); + params.put(RCDevice.ParameterKeys.MEDIA_ICE_USERNAME, prefs.getString(RCDevice.ParameterKeys.MEDIA_ICE_USERNAME, "")); + params.put(RCDevice.ParameterKeys.MEDIA_ICE_PASSWORD, prefs.getString(RCDevice.ParameterKeys.MEDIA_ICE_PASSWORD, "")); + params.put(RCDevice.ParameterKeys.MEDIA_ICE_DOMAIN, prefs.getString(RCDevice.ParameterKeys.MEDIA_ICE_DOMAIN, "")); + params.put(RCDevice.ParameterKeys.MEDIA_TURN_ENABLED, prefs.getBoolean(RCDevice.ParameterKeys.MEDIA_TURN_ENABLED, true)); + params.put(RCDevice.ParameterKeys.SIGNALING_SECURE_ENABLED, prefs.getBoolean(RCDevice.ParameterKeys.SIGNALING_SECURE_ENABLED, true)); + // The SDK provides the user with default sounds for calling, ringing, busy (declined) and message, but the user can override them + // by providing their own resource files (i.e. .wav, .mp3, etc) at res/raw passing them with Resource IDs like R.raw.user_provided_calling_sound + //params.put(RCDevice.ParameterKeys.RESOURCE_SOUND_CALLING, R.raw.user_provided_calling_sound); + //params.put(RCDevice.ParameterKeys.RESOURCE_SOUND_RINGING, R.raw.user_provided_ringing_sound); + //params.put(RCDevice.ParameterKeys.RESOURCE_SOUND_DECLINED, R.raw.user_provided_declined_sound); + //params.put(RCDevice.ParameterKeys.RESOURCE_SOUND_MESSAGE, R.raw.user_provided_message_sound); + + // These are for debugging purposes, NOT for release builds! + //params.put(RCDevice.ParameterKeys.DEBUG_JAIN_SIP_LOGGING_ENABLED, prefs.getBoolean(RCDevice.ParameterKeys.DEBUG_JAIN_SIP_LOGGING_ENABLED, true)); + //params.put(RCDevice.ParameterKeys.DEBUG_JAIN_DISABLE_CERTIFICATE_VERIFICATION, prefs.getBoolean(RCDevice.ParameterKeys.DEBUG_JAIN_DISABLE_CERTIFICATE_VERIFICATION, true)); + + device.setLogLevel(Log.VERBOSE); + device.initialize(getApplicationContext(), params, this); + } + + if (device.getState() == RCDevice.DeviceState.OFFLINE) { + getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorTextSecondary))); + } else { + getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary))); + handleExternalCall(); + } + + serviceBound = true; + } + + @Override + public void onServiceDisconnected(ComponentName arg0) { + Log.i(TAG, "%% onServiceDisconnected"); + serviceBound = false; + } + + /** + * MainFragment Callbacks + */ + @Override + public void onItemSelected(HashMap contact, MainFragment.ContactSelectionType type) { + Intent intent = new Intent(this, MessageActivity.class); + intent.setAction(MessageActivity.ACTION_OPEN_MESSAGE_SCREEN); + intent.putExtra(MessageActivity.EXTRA_CONTACT_NAME, contact.get(CONTACT_KEY)); + intent.putExtra(RCDevice.EXTRA_DID, contact.get(CONTACT_VALUE)); + startActivity(intent); + + // forward to onActionClicked + //onActionClicked(ActionFragment.ActionType.ACTION_TYPE_VIDEO_CALL, contact.get(CONTACT_KEY), contact.get(CONTACT_VALUE)); + } + + public void onContactUpdate(HashMap contact, int type) { + AddUserDialogFragment newFragment = AddUserDialogFragment.newInstance(AddUserDialogFragment.DIALOG_TYPE_UPDATE_CONTACT, contact.get(CONTACT_KEY), contact.get(CONTACT_VALUE)); + newFragment.show(getSupportFragmentManager(), "dialog"); + //newFragment.show(getFragmentManager(), "dialog"); + } /* public void onAccessoryClicked(HashMap contact) @@ -305,22 +329,20 @@ public void onAccessoryClicked(HashMap contact) } */ - /** - * Callbacks for AddUserDialogFragment - */ - public void onDialogPositiveClick(int type, String username, String sipuri) - { - listFragment.updateContact(type, username, sipuri); - } + /** + * Callbacks for AddUserDialogFragment + */ + public void onDialogPositiveClick(int type, String username, String sipuri) { + listFragment.updateContact(type, username, sipuri); + } - public void onDialogNegativeClick() - { + public void onDialogNegativeClick() { - } + } - /** - * Callbacks for ActionFragment - */ + /** + * Callbacks for ActionFragment + */ /* public void onActionClicked(ActionFragment.ActionType action, String username, String sipuri) { @@ -347,225 +369,202 @@ public void onActionClicked(ActionFragment.ActionType action, String username, S } */ - /** - * Main Activity onClick - */ - public void onClick(View view) - { - if (view.getId() == R.id.imageButton_add) { + /** + * Main Activity onClick + */ + public void onClick(View view) { + if (view.getId() == R.id.imageButton_add) { /* TODO: Issue #380: once we figure out the issue with the backgrounding we need to uncomment this, but also place it to a suitable place Intent intent = new Intent(this, CallActivity.class); intent.setAction(RCDevice.LIVE_CALL); startActivityForResult(intent, CONNECTION_REQUEST); */ - //DialogFragment newFragment = AddUserDialogFragment.newInstance(AddUserDialogFragment.DIALOG_TYPE_ADD_CONTACT, "", ""); - //newFragment.show(getFragmentManager(), "dialog"); + //DialogFragment newFragment = AddUserDialogFragment.newInstance(AddUserDialogFragment.DIALOG_TYPE_ADD_CONTACT, "", ""); + //newFragment.show(getFragmentManager(), "dialog"); - AddUserDialogFragment newFragment = AddUserDialogFragment.newInstance(AddUserDialogFragment.DIALOG_TYPE_ADD_CONTACT, "", ""); - newFragment.show(getSupportFragmentManager(), "dialog"); + AddUserDialogFragment newFragment = AddUserDialogFragment.newInstance(AddUserDialogFragment.DIALOG_TYPE_ADD_CONTACT, "", ""); + newFragment.show(getSupportFragmentManager(), "dialog"); - // DEBUG: for adding memory pressure to the App + // DEBUG: for adding memory pressure to the App /* for (int i = 0; i < 200; i++) { list.add(new String[100000]); } Log.i(TAG, "List size: " + list.size()); */ - } - } - - /** - * RCDeviceListener callbacks - */ - public void onStartListening(RCDevice device, RCDeviceListener.RCConnectivityStatus connectivityStatus) - { - handleConnectivityUpdate(connectivityStatus, null); - } - - public void onStopListening(RCDevice device) - { - - } - - public void onStopListening(RCDevice device, int errorCode, String errorText) - { - if (errorCode == RCClient.ErrorCodes.SUCCESS.ordinal()) { - handleConnectivityUpdate(RCConnectivityStatus.RCConnectivityStatusNone, "RCDevice: " + errorText); - } - else { - handleConnectivityUpdate(RCConnectivityStatus.RCConnectivityStatusNone, "RCDevice Error: " + errorText); - } - } - - public void onInitialized(RCDevice device, RCDeviceListener.RCConnectivityStatus connectivityStatus, int statusCode, String statusText) - { - if (statusCode == RCClient.ErrorCodes.SUCCESS.ordinal()) { - handleConnectivityUpdate(connectivityStatus, "RCDevice successfully initialized, using: " + connectivityStatus); - } - else if (statusCode == RCClient.ErrorCodes.ERROR_DEVICE_NO_CONNECTIVITY.ordinal()) { - // This is not really an error, since if connectivity comes back the RCDevice will resume automatically - handleConnectivityUpdate(connectivityStatus, null); - } - else { - //Toast.makeText(getApplicationContext(), "RCDevice Initialization Error: " + statusText, Toast.LENGTH_LONG).show(); - //showOkAlert("RCDevice Initialization Error", statusText); - //handleConnectivityUpdate(connectivityStatus, "RCDevice Initialization Error: " + statusText); - Toast.makeText(getApplicationContext(), "RCDevice Initialization Error: " + statusText, Toast.LENGTH_LONG).show(); - } - - } - - public void onInitializationError(int errorCode, String errorText) - { - Toast.makeText(getApplicationContext(), "RCDevice Initialization Error: " + errorText, Toast.LENGTH_LONG).show(); - } - - public void onReleased(RCDevice device, int statusCode, String statusText) - { - if (statusCode != RCClient.ErrorCodes.SUCCESS.ordinal()) { - //showOkAlert("RCDevice Release Error", statusText); - Toast.makeText(getApplicationContext(), "RCDevice Release Error: " + statusText, Toast.LENGTH_LONG).show(); - } - else { - handleConnectivityUpdate(RCConnectivityStatus.RCConnectivityStatusNone, "RCDevice Released: " + statusText); - } - } - - public void onConnectivityUpdate(RCDevice device, RCConnectivityStatus connectivityStatus) - { - handleConnectivityUpdate(connectivityStatus, null); - } - - public void handleConnectivityUpdate(RCConnectivityStatus connectivityStatus, String text) - { - if (text == null) { - if (connectivityStatus == RCConnectivityStatus.RCConnectivityStatusNone) { - text = "RCDevice connectivity change: Lost connectivity"; - } - if (connectivityStatus == RCConnectivityStatus.RCConnectivityStatusWiFi) { - text = "RCDevice connectivity change: Reestablished connectivity (Wifi)"; - } - if (connectivityStatus == RCConnectivityStatus.RCConnectivityStatusCellular) { - text = "RCDevice connectivity change: Reestablished connectivity (Cellular)"; - } - if (connectivityStatus == RCConnectivityStatus.RCConnectivityStatusEthernet) { - text = "RCDevice connectivity change: Reestablished connectivity (Ethernet)"; - } - } - - if (connectivityStatus == RCConnectivityStatus.RCConnectivityStatusNone) { - getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorTextSecondary))); - } - else { - getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary))); - handleExternalCall(); - } - - Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG).show(); - this.previousConnectivityStatus = connectivityStatus; - } - - // Handle call issued by external App via CALL intent - private void handleExternalCall() - { - // We have connectivity (either wifi or cellular), check if we have any external call requests and service it - GlobalPreferences globalPreferences = new GlobalPreferences(getApplicationContext()); - String externalCallUriString = globalPreferences.getExternalCallUri(); - if (!externalCallUriString.isEmpty()) { - Uri externalCallUri = Uri.parse(externalCallUriString); - - String parsedUriString = ""; - if (externalCallUri.getScheme().contains("sip")) { - // either 'sip' or 'restcomm-sip' - // normalize 'restcomm-sip' and replace with 'sip' - //String normalized = externalCallUriString.replace("restcomm-sip", "sip"); - // also replace '://' with ':' so that the SIP stack can understand it - //parsedUriString = normalized.replace("://", ":"); - parsedUriString = externalCallUriString.replace("restcomm-sip", "sip"); - } - else { - // either 'tel', 'restcomm-tel', 'client' or 'restcomm-client'. Return just the host part, like 'bob' or '1235' that the Restcomm SDK can handle - parsedUriString = externalCallUri.getSchemeSpecificPart(); - } - - Intent intent = new Intent(this, CallActivity.class); - intent.setAction(RCDevice.ACTION_OUTGOING_CALL); - intent.putExtra(RCDevice.EXTRA_DID, parsedUriString); - intent.putExtra(RCDevice.EXTRA_VIDEO_ENABLED, true); - startActivityForResult(intent, CONNECTION_REQUEST); - - globalPreferences.setExternalCallUri(""); - } - } - - public void onMessageSent(RCDevice device, int statusCode, String statusText, String jobId) - { - - } - - public boolean receivePresenceEvents(RCDevice device) - { - return false; - } - - public void onPresenceChanged(RCDevice device, RCPresenceEvent presenceEvent) - { - - } - - /** - * Settings Menu callbacks - */ - @Override - public void onConfigurationChanged(Configuration newConfig) - { - super.onConfigurationChanged(newConfig); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) - { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_main, menu); - return true; - } - - - @Override - public boolean onOptionsItemSelected(MenuItem item) - { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - if (id == R.id.action_settings) { - Intent i = new Intent(this, SettingsActivity.class); - startActivity(i); - } - if (id == R.id.action_submit_logs) { - Intent intent = new Intent(this, BugReportActivity.class); - //intent.setAction(RCDevice.ACTION_OUTGOING_CALL); - //intent.putExtra(RCDevice.EXTRA_DID, parsedUriString); - //intent.putExtra(RCDevice.EXTRA_VIDEO_ENABLED, true); - startActivity(intent); - } - if (id == R.id.action_about) { - DialogFragment newFragment = AboutFragment.newInstance(); - newFragment.show(getFragmentManager(), "dialog-about"); - } - return super.onOptionsItemSelected(item); - } - - @Override - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, - String key) - { - - } - - /** - * Helpers - */ + } + } + + /** + * RCDeviceListener callbacks + */ + public void onStartListening(RCDevice device, RCDeviceListener.RCConnectivityStatus connectivityStatus) { + handleConnectivityUpdate(connectivityStatus, null); + } + + public void onStopListening(RCDevice device) { + + } + + public void onStopListening(RCDevice device, int errorCode, String errorText) { + if (errorCode == RCClient.ErrorCodes.SUCCESS.ordinal()) { + handleConnectivityUpdate(RCConnectivityStatus.RCConnectivityStatusNone, "RCDevice: " + errorText); + } else { + handleConnectivityUpdate(RCConnectivityStatus.RCConnectivityStatusNone, "RCDevice Error: " + errorText); + } + } + + public void onInitialized(RCDevice device, RCDeviceListener.RCConnectivityStatus connectivityStatus, int statusCode, String statusText) { + if (statusCode == RCClient.ErrorCodes.SUCCESS.ordinal()) { + handleConnectivityUpdate(connectivityStatus, "RCDevice successfully initialized, using: " + connectivityStatus); + } else if (statusCode == RCClient.ErrorCodes.ERROR_DEVICE_NO_CONNECTIVITY.ordinal()) { + // This is not really an error, since if connectivity comes back the RCDevice will resume automatically + handleConnectivityUpdate(connectivityStatus, null); + } else { + //Toast.makeText(getApplicationContext(), "RCDevice Initialization Error: " + statusText, Toast.LENGTH_LONG).show(); + //showOkAlert("RCDevice Initialization Error", statusText); + //handleConnectivityUpdate(connectivityStatus, "RCDevice Initialization Error: " + statusText); + Toast.makeText(getApplicationContext(), "RCDevice Initialization Error: " + statusText, Toast.LENGTH_LONG).show(); + } + + } + + public void onInitializationError(int errorCode, String errorText) { + Toast.makeText(getApplicationContext(), "RCDevice Initialization Error: " + errorText, Toast.LENGTH_LONG).show(); + } + + public void onReleased(RCDevice device, int statusCode, String statusText) { + if (statusCode != RCClient.ErrorCodes.SUCCESS.ordinal()) { + //showOkAlert("RCDevice Release Error", statusText); + Toast.makeText(getApplicationContext(), "RCDevice Release Error: " + statusText, Toast.LENGTH_LONG).show(); + } else { + handleConnectivityUpdate(RCConnectivityStatus.RCConnectivityStatusNone, "RCDevice Released: " + statusText); + } + } + + public void onConnectivityUpdate(RCDevice device, RCConnectivityStatus connectivityStatus) { + handleConnectivityUpdate(connectivityStatus, null); + } + + public void handleConnectivityUpdate(RCConnectivityStatus connectivityStatus, String text) { + if (text == null) { + if (connectivityStatus == RCConnectivityStatus.RCConnectivityStatusNone) { + text = "RCDevice connectivity change: Lost connectivity"; + } + if (connectivityStatus == RCConnectivityStatus.RCConnectivityStatusWiFi) { + text = "RCDevice connectivity change: Reestablished connectivity (Wifi)"; + } + if (connectivityStatus == RCConnectivityStatus.RCConnectivityStatusCellular) { + text = "RCDevice connectivity change: Reestablished connectivity (Cellular)"; + } + if (connectivityStatus == RCConnectivityStatus.RCConnectivityStatusEthernet) { + text = "RCDevice connectivity change: Reestablished connectivity (Ethernet)"; + } + } + + if (connectivityStatus == RCConnectivityStatus.RCConnectivityStatusNone) { + getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorTextSecondary))); + } else { + getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary))); + handleExternalCall(); + } + + Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG).show(); + this.previousConnectivityStatus = connectivityStatus; + } + + // Handle call issued by external App via CALL intent + private void handleExternalCall() { + // We have connectivity (either wifi or cellular), check if we have any external call requests and service it + GlobalPreferences globalPreferences = new GlobalPreferences(getApplicationContext()); + String externalCallUriString = globalPreferences.getExternalCallUri(); + if (!externalCallUriString.isEmpty()) { + Uri externalCallUri = Uri.parse(externalCallUriString); + + String parsedUriString = ""; + if (externalCallUri.getScheme().contains("sip")) { + // either 'sip' or 'restcomm-sip' + // normalize 'restcomm-sip' and replace with 'sip' + //String normalized = externalCallUriString.replace("restcomm-sip", "sip"); + // also replace '://' with ':' so that the SIP stack can understand it + //parsedUriString = normalized.replace("://", ":"); + parsedUriString = externalCallUriString.replace("restcomm-sip", "sip"); + } else { + // either 'tel', 'restcomm-tel', 'client' or 'restcomm-client'. Return just the host part, like 'bob' or '1235' that the Restcomm SDK can handle + parsedUriString = externalCallUri.getSchemeSpecificPart(); + } + + Intent intent = new Intent(this, CallActivity.class); + intent.setAction(RCDevice.ACTION_OUTGOING_CALL); + intent.putExtra(RCDevice.EXTRA_DID, parsedUriString); + intent.putExtra(RCDevice.EXTRA_VIDEO_ENABLED, true); + startActivityForResult(intent, CONNECTION_REQUEST); + + globalPreferences.setExternalCallUri(""); + } + } + + public void onMessageSent(RCDevice device, int statusCode, String statusText, String jobId) { + + } + + public boolean receivePresenceEvents(RCDevice device) { + return false; + } + + public void onPresenceChanged(RCDevice device, RCPresenceEvent presenceEvent) { + + } + + /** + * Settings Menu callbacks + */ + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_main, menu); + return true; + } + + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + if (id == R.id.action_settings) { + Intent i = new Intent(this, SettingsActivity.class); + startActivity(i); + } + if (id == R.id.action_submit_logs) { + Intent intent = new Intent(this, BugReportActivity.class); + //intent.setAction(RCDevice.ACTION_OUTGOING_CALL); + //intent.putExtra(RCDevice.EXTRA_DID, parsedUriString); + //intent.putExtra(RCDevice.EXTRA_VIDEO_ENABLED, true); + startActivity(intent); + } + if (id == R.id.action_about) { + DialogFragment newFragment = AboutFragment.newInstance(); + newFragment.show(getFragmentManager(), "dialog-about"); + } + return super.onOptionsItemSelected(item); + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, + String key) { + + } + + /** + * Helpers + */ /* private void showOkAlert(final String title, final String detail) { diff --git a/Examples/restcomm-olympus/app/src/main/java/org/restcomm/android/olympus/MainFragment.java b/Examples/restcomm-olympus/app/src/main/java/org/restcomm/android/olympus/MainFragment.java index a2aa07af..539495e1 100644 --- a/Examples/restcomm-olympus/app/src/main/java/org/restcomm/android/olympus/MainFragment.java +++ b/Examples/restcomm-olympus/app/src/main/java/org/restcomm/android/olympus/MainFragment.java @@ -309,7 +309,7 @@ public void onClick(DialogInterface dialog, int which) alertDialog.show(); } - public class ContactAdapter extends BaseAdapter { + public static class ContactAdapter extends BaseAdapter { private LayoutInflater mInflater; private ArrayList> contactList; private ContactAdapterListener listener; diff --git a/Examples/restcomm-olympus/app/src/main/res/drawable-xhdpi/custom_orange_button.xml b/Examples/restcomm-olympus/app/src/main/res/drawable-xhdpi/custom_orange_button.xml new file mode 100644 index 00000000..f663cbcd --- /dev/null +++ b/Examples/restcomm-olympus/app/src/main/res/drawable-xhdpi/custom_orange_button.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/Examples/restcomm-olympus/app/src/main/res/layout/fragment_dialog_add_contact.xml b/Examples/restcomm-olympus/app/src/main/res/layout/fragment_dialog_add_contact.xml index 4a3013d1..86a1b7c6 100644 --- a/Examples/restcomm-olympus/app/src/main/res/layout/fragment_dialog_add_contact.xml +++ b/Examples/restcomm-olympus/app/src/main/res/layout/fragment_dialog_add_contact.xml @@ -73,4 +73,16 @@ android:id="@+id/textView_sipuri" android:layout_gravity="center_horizontal" /> +