* #31001: com.savoirfaire -> org.sflphone
diff --git a/src/org/sflphone/fragments/AboutFragment.java b/src/org/sflphone/fragments/AboutFragment.java
new file mode 100644
index 0000000..32bf957
--- /dev/null
+++ b/src/org/sflphone/fragments/AboutFragment.java
@@ -0,0 +1,34 @@
+package org.sflphone.fragments;
+
+import org.sflphone.R;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.text.Html;
+import android.text.method.LinkMovementMethod;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+public class AboutFragment extends Fragment {
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
+ View inflatedView = inflater.inflate(R.layout.frag_about, parent, false);
+
+
+
+
+ TextView link = (TextView) inflatedView.findViewById(R.id.web_site);
+ String linkText = "<a href='http://sflphone.org/'>"+getResources().getString(R.string.web_site)+"</a>";
+ link.setText(Html.fromHtml(linkText));
+ link.setMovementMethod(LinkMovementMethod.getInstance());
+ getActivity().getActionBar().setTitle(R.string.menu_item_about);
+ return inflatedView;
+ }
+
+
+
+
+}
diff --git a/src/org/sflphone/fragments/AccountCreationFragment.java b/src/org/sflphone/fragments/AccountCreationFragment.java
new file mode 100644
index 0000000..774180d
--- /dev/null
+++ b/src/org/sflphone/fragments/AccountCreationFragment.java
@@ -0,0 +1,220 @@
+package org.sflphone.fragments;
+
+import java.util.HashMap;
+
+import org.sflphone.R;
+import org.sflphone.account.AccountDetail;
+import org.sflphone.account.AccountDetailAdvanced;
+import org.sflphone.account.AccountDetailBasic;
+import org.sflphone.account.AccountDetailSrtp;
+import org.sflphone.account.AccountDetailTls;
+
+import android.app.Activity;
+import android.app.Fragment;
+import android.content.Intent;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.EditText;
+
+public class AccountCreationFragment extends Fragment {
+
+ // Values for email and password at the time of the login attempt.
+ private String mAlias;
+ private String mHostname;
+ private String mUsername;
+ private String mPassword;
+
+ // UI references.
+ private EditText mAliasView;
+ private EditText mHostnameView;
+ private EditText mUsernameView;
+ private EditText mPasswordView;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ // mAdapter = new HistoryAdapter(getActivity(),new ArrayList<HashMap<String, String>>());
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
+ View inflatedView = inflater.inflate(R.layout.frag_account_creation, parent, false);
+
+ mAliasView = (EditText) inflatedView.findViewById(R.id.alias);
+ mHostnameView = (EditText) inflatedView.findViewById(R.id.hostname);
+ mUsernameView = (EditText) inflatedView.findViewById(R.id.username);
+ mPasswordView = (EditText) inflatedView.findViewById(R.id.password);
+ inflatedView.findViewById(R.id.create_button).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ mAlias = mAliasView.getText().toString();
+ mHostname = mHostnameView.getText().toString();
+ mUsername = mUsernameView.getText().toString();
+ mPassword = mPasswordView.getText().toString();
+ attemptCreation();
+ }
+ });
+
+ inflatedView.findViewById(R.id.dev_account).setVisibility(View.GONE); // Hide this button in release apk
+ inflatedView.findViewById(R.id.dev_account).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ createDevAccount();
+ }
+
+ private void createDevAccount() {
+ mUsername = mUsernameView.getText().toString();
+ if (TextUtils.isEmpty(mUsername)) {
+ mUsernameView.setError(getString(R.string.error_field_required));
+ mUsernameView.requestFocus();
+ return;
+ } else {
+ mAlias = mUsername;
+ mHostname = "192.95.9.63";
+ mPassword = "sfl_u"+mUsername;
+ attemptCreation();
+ }
+
+ }
+ });
+
+ return inflatedView;
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+
+ }
+
+ /**
+ * Attempts to sign in or register the account specified by the login form. If there are form errors (invalid email, missing fields, etc.), the
+ * errors are presented and no actual login attempt is made.
+ */
+ public void attemptCreation() {
+
+ // Reset errors.
+ mAliasView.setError(null);
+ mPasswordView.setError(null);
+
+ // Store values at the time of the login attempt.
+
+
+ boolean cancel = false;
+ View focusView = null;
+
+ // Check for a valid password.
+ if (TextUtils.isEmpty(mPassword)) {
+ mPasswordView.setError(getString(R.string.error_field_required));
+ focusView = mPasswordView;
+ cancel = true;
+ }
+
+ if (TextUtils.isEmpty(mUsername)) {
+ mUsernameView.setError(getString(R.string.error_field_required));
+ focusView = mUsernameView;
+ cancel = true;
+ }
+
+ if (TextUtils.isEmpty(mHostname)) {
+ mHostnameView.setError(getString(R.string.error_field_required));
+ focusView = mHostnameView;
+ cancel = true;
+ }
+
+ // Check for a valid email address.
+ if (TextUtils.isEmpty(mAlias)) {
+ mAliasView.setError(getString(R.string.error_field_required));
+ focusView = mAliasView;
+ cancel = true;
+ }
+
+ if (cancel) {
+ // There was an error; don't attempt login and focus the first
+ // form field with an error.
+ focusView.requestFocus();
+ } else {
+ // Show a progress spinner, and kick off a background task to
+ // perform the user login attempt.
+ initCreation();
+
+ }
+ }
+
+ private void initCreation() {
+
+ HashMap<String, String> accountDetails = new HashMap<String, String>();
+
+ accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_TYPE, AccountDetailBasic.CONFIG_ACCOUNT_DEFAULT_TYPE);
+ accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_ALIAS, mAlias);
+ accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_HOSTNAME, mHostname);
+ accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME, mUsername);
+ accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD, mPassword);
+ accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_ROUTESET, "");
+ accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_REALM, AccountDetailBasic.CONFIG_ACCOUNT_DEFAULT_REALM);
+ accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_ENABLE, AccountDetailBasic.CONFIG_ACCOUNT_DEFAULT_ENABLE);
+ accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD, mPassword);
+ accountDetails.put(AccountDetailBasic.CONFIG_ACCOUNT_USERAGENT, AccountDetailBasic.CONFIG_ACCOUNT_DEFAULT_USERAGENT);
+
+ accountDetails.put(AccountDetailAdvanced.CONFIG_LOCAL_PORT, AccountDetailAdvanced.CONFIG_DEFAULT_LOCAL_PORT);
+ accountDetails.put(AccountDetailAdvanced.CONFIG_LOCAL_INTERFACE, AccountDetailAdvanced.CONFIG_DEFAULT_INTERFACE);
+ accountDetails.put(AccountDetailAdvanced.CONFIG_PUBLISHED_PORT, AccountDetailAdvanced.CONFIG_DEFAULT_PUBLISHED_PORT);
+ accountDetails.put(AccountDetailAdvanced.CONFIG_PUBLISHED_ADDRESS, AccountDetailAdvanced.CONFIG_DEFAULT_ADDRESS);
+ accountDetails.put(AccountDetailAdvanced.CONFIG_ACCOUNT_REGISTRATION_EXPIRE, AccountDetailAdvanced.CONFIG_DEFAULT_REGISTRATION_EXPIRE);
+ accountDetails.put(AccountDetailAdvanced.CONFIG_STUN_SERVER, "");
+ accountDetails.put(AccountDetailAdvanced.CONFIG_ACCOUNT_REGISTRATION_STATUS, "");
+ accountDetails.put(AccountDetailAdvanced.CONFIG_ACCOUNT_REGISTRATION_STATE_CODE, "");
+ accountDetails.put(AccountDetailAdvanced.CONFIG_ACCOUNT_REGISTRATION_STATE_DESC, "");
+ accountDetails.put(AccountDetailAdvanced.CONFIG_ACCOUNT_AUTOANSWER, AccountDetailAdvanced.FALSE_STR);
+ accountDetails.put(AccountDetailAdvanced.CONFIG_ACCOUNT_DTMF_TYPE, AccountDetailAdvanced.CONFIG_DEFAULT_DTMF_TYPE);
+ accountDetails.put(AccountDetailAdvanced.CONFIG_KEEP_ALIVE_ENABLED, AccountDetailAdvanced.FALSE_STR);
+ accountDetails.put(AccountDetailAdvanced.CONFIG_STUN_SERVER, "");
+ accountDetails.put(AccountDetailAdvanced.CONFIG_PUBLISHED_SAMEAS_LOCAL, AccountDetailAdvanced.CONFIG_DEFAULT_PUBLISHED_SAMEAS_LOCAL);
+ accountDetails.put(AccountDetailAdvanced.CONFIG_RINGTONE_ENABLED, AccountDetailAdvanced.FALSE_STR);
+ accountDetails.put(AccountDetailAdvanced.CONFIG_RINGTONE_PATH, "");
+ accountDetails.put(AccountDetailAdvanced.CONFIG_STUN_ENABLE, AccountDetailAdvanced.FALSE_STR);
+
+ accountDetails.put(AccountDetailSrtp.CONFIG_SRTP_KEY_EXCHANGE, "");
+ accountDetails.put(AccountDetailSrtp.CONFIG_SRTP_RTP_FALLBACK, "");
+ accountDetails.put(AccountDetailSrtp.CONFIG_SRTP_ENABLE, AccountDetailAdvanced.FALSE_STR);
+ accountDetails.put(AccountDetailSrtp.CONFIG_SRTP_KEY_EXCHANGE, "");
+ accountDetails.put(AccountDetailSrtp.CONFIG_ZRTP_DISPLAY_SAS, "");
+ accountDetails.put(AccountDetailSrtp.CONFIG_ZRTP_DISPLAY_SAS_ONCE, "");
+ accountDetails.put(AccountDetailSrtp.CONFIG_SRTP_KEY_EXCHANGE, "");
+ accountDetails.put(AccountDetailSrtp.CONFIG_ZRTP_HELLO_HASH, "");
+ accountDetails.put(AccountDetailSrtp.CONFIG_ZRTP_NOT_SUPP_WARNING, "");
+
+ accountDetails.put(AccountDetailTls.CONFIG_TLS_CIPHERS, "");
+ accountDetails.put(AccountDetailTls.CONFIG_TLS_LISTENER_PORT, "");
+ accountDetails.put(AccountDetailTls.CONFIG_TLS_METHOD, "");
+ accountDetails.put(AccountDetailTls.CONFIG_TLS_ENABLE, AccountDetailAdvanced.FALSE_STR);
+ accountDetails.put(AccountDetailTls.CONFIG_TLS_PASSWORD, "");
+ accountDetails.put(AccountDetailTls.CONFIG_TLS_PRIVATE_KEY_FILE, "");
+
+ accountDetails.put(AccountDetailTls.CONFIG_TLS_SERVER_NAME, "");
+ accountDetails.put(AccountDetailTls.CONFIG_TLS_REQUIRE_CLIENT_CERTIFICATE, AccountDetailAdvanced.FALSE_STR);
+ accountDetails.put(AccountDetailTls.CONFIG_TLS_LISTENER_PORT, "");
+ accountDetails.put(AccountDetailTls.CONFIG_TLS_VERIFY_CLIENT, "");
+ accountDetails.put(AccountDetailTls.CONFIG_TLS_CERTIFICATE_FILE, "");
+ accountDetails.put(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE, "");
+ accountDetails.put(AccountDetailTls.CONFIG_TLS_VERIFY_SERVER, "");
+
+ Bundle bundle = new Bundle();
+ bundle.putSerializable(AccountDetail.TAG, accountDetails);
+ Intent resultIntent = new Intent();
+ resultIntent.putExtras(bundle);
+
+ getActivity().setResult(Activity.RESULT_OK, resultIntent);
+ getActivity().finish();
+
+ }
+
+}
diff --git a/src/org/sflphone/fragments/AccountManagementFragment.java b/src/org/sflphone/fragments/AccountManagementFragment.java
new file mode 100644
index 0000000..947d1bf
--- /dev/null
+++ b/src/org/sflphone/fragments/AccountManagementFragment.java
@@ -0,0 +1,376 @@
+/*
+ * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
+ *
+ * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
+ * Alexandre Lision <alexandre.lision@savoirfairelinux.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Additional permission under GNU GPL version 3 section 7:
+ *
+ * If you modify this program, or any covered work, by linking or
+ * combining it with the OpenSSL project's OpenSSL library (or a
+ * modified version of that library), containing parts covered by the
+ * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
+ * grants you additional permission to convey the resulting work.
+ * Corresponding Source for a non-source form of such a combination
+ * shall include the source code for the parts of OpenSSL used as well
+ * as that of the covered work.
+ */
+
+package org.sflphone.fragments;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Set;
+
+import org.sflphone.R;
+import org.sflphone.account.AccountDetail;
+import org.sflphone.account.AccountDetailAdvanced;
+import org.sflphone.account.AccountDetailBasic;
+import org.sflphone.account.AccountDetailSrtp;
+import org.sflphone.account.AccountDetailTls;
+import org.sflphone.client.AccountPreferenceActivity;
+import org.sflphone.client.AccountWizard;
+import org.sflphone.client.SFLPhonePreferenceActivity;
+import org.sflphone.client.SFLphoneApplication;
+import org.sflphone.model.Account;
+import org.sflphone.service.ConfigurationManagerCallback;
+import org.sflphone.service.ISipService;
+
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Bundle;
+import android.os.RemoteException;
+import android.preference.Preference;
+import android.preference.PreferenceFragment;
+import android.preference.PreferenceScreen;
+import android.support.v4.content.LocalBroadcastManager;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+
+public class AccountManagementFragment extends PreferenceFragment {
+ static final String TAG = "AccountManagementFragment";
+ static final String DEFAULT_ACCOUNT_ID = "IP2IP";
+ static final int ACCOUNT_CREATE_REQUEST = 1;
+ static final int ACCOUNT_EDIT_REQUEST = 2;
+ private SFLPhonePreferenceActivity sflphonePreferenceActivity;
+ private ISipService service = null;
+
+ // ArrayList<AccountDetail.PreferenceEntry> basicDetailKeys = null;
+ // ArrayList<AccountDetail.PreferenceEntry> advancedDetailKeys = null;
+ // ArrayList<AccountDetail.PreferenceEntry> srtpDetailKeys = null;
+ // ArrayList<AccountDetail.PreferenceEntry> tlsDetailKeys = null;
+ HashMap<String, Preference> accountPreferenceHashMap = null;
+ PreferenceScreen mRoot = null;
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ sflphonePreferenceActivity = (SFLPhonePreferenceActivity) activity;
+ service = sflphonePreferenceActivity.getSipService();
+ Log.w(TAG, "onAttach() service=" + service);
+ }
+
+ public AccountManagementFragment() {
+ // basicDetailKeys = AccountDetailBasic.getPreferenceEntries();
+ // advancedDetailKeys = AccountDetailAdvanced.getPreferenceEntries();
+ // srtpDetailKeys = AccountDetailSrtp.getPreferenceEntries();
+ // tlsDetailKeys = AccountDetailTls.getPreferenceEntries();
+
+ accountPreferenceHashMap = new HashMap<String, Preference>();
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ Log.i(TAG, "Create Account Management Fragment");
+
+ this.setHasOptionsMenu(true);
+
+ /*
+ * FIXME if service cannot be obtained from SFLPhonePreferenceActivity, then get it from Application
+ */
+ service = sflphonePreferenceActivity.getSipService();
+ if (service == null) {
+ service = ((SFLphoneApplication) sflphonePreferenceActivity.getApplication()).getSipService();
+ if (service == null) {
+ Log.e(TAG, "onCreate() service=" + service);
+ }
+ }
+
+ setPreferenceScreen(getAccountListPreferenceScreen());
+
+ LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mMessageReceiver,
+ new IntentFilter(ConfigurationManagerCallback.ACCOUNTS_CHANGED));
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ Log.i(TAG, "onStop");
+ }
+
+ @Override
+ public void onDestroy() {
+ LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mMessageReceiver);
+ super.onDestroy();
+ Log.i(TAG, "onDestroy");
+ }
+
+ @SuppressWarnings("unchecked") // No proper solution with HashMap runtime cast
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ switch (requestCode) {
+ case ACCOUNT_CREATE_REQUEST:
+ if (resultCode == AccountWizard.ACCOUNT_CREATED) {
+ Bundle bundle = data.getExtras();
+ Log.i(TAG, "Create account settings");
+ HashMap<String, String> accountDetails = new HashMap<String, String>();
+ accountDetails = (HashMap<String, String>) bundle.getSerializable(AccountDetail.TAG);
+ // if(accountDetails == null){
+ // Toast.makeText(getActivity(), "NUUUUL", Toast.LENGTH_SHORT).show();
+ // } else
+ // Toast.makeText(getActivity(), "OKKKK", Toast.LENGTH_SHORT).show();
+ createNewAccount(accountDetails);
+ }
+ break;
+ case ACCOUNT_EDIT_REQUEST:
+ if (resultCode == AccountPreferenceActivity.result.ACCOUNT_MODIFIED) {
+ Bundle bundle = data.getExtras();
+ String accountID = bundle.getString("AccountID");
+ Log.i(TAG, "Update account settings for " + accountID);
+
+ HashMap<String, String> accountDetails = new HashMap<String, String>();
+ accountDetails = (HashMap<String, String>) bundle.getSerializable(AccountDetail.TAG);
+
+ Preference accountScreen = accountPreferenceHashMap.get(accountID);
+ mRoot.removePreference(accountScreen);
+ accountPreferenceHashMap.remove(accountID);
+ setAccountDetails(accountID, accountDetails);
+
+ } else if (resultCode == AccountPreferenceActivity.result.ACCOUNT_DELETED) {
+ Bundle bundle = data.getExtras();
+ String accountID = bundle.getString("AccountID");
+
+ Log.i(TAG, "Remove account " + accountID);
+ deleteSelectedAccount(accountID);
+ Preference accountScreen = accountPreferenceHashMap.get(accountID);
+ mRoot.removePreference(accountScreen);
+ accountPreferenceHashMap.remove(accountID);
+ } else {
+ Log.i(TAG, "Edition canceled");
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ private void createNewAccount(HashMap<String, String> accountDetails) {
+ try {
+ Log.i(TAG, "ADD ACCOUNT");
+ service.addAccount(accountDetails);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Cannot call service method", e);
+ }
+ }
+
+ private void setAccountDetails(String accountID, HashMap<String, String> accountDetails) {
+ try {
+ service.setAccountDetails(accountID, accountDetails);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Cannot call service method", e);
+ }
+ }
+
+ private void deleteSelectedAccount(String accountID) {
+ Log.i(TAG, "DeleteSelectedAccount");
+ try {
+ service.removeAccount(accountID);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Cannot call service method", e);
+ }
+ };
+
+ private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ ArrayList<String> newList = (ArrayList<String>) getAccountList();
+ Set<String> currentList = (Set<String>) accountPreferenceHashMap.keySet();
+ if (newList.size() > currentList.size()) {
+ for (String s : newList) {
+ if (!currentList.contains(s)) {
+ Preference accountScreen = createAccountPreferenceScreen(s);
+ mRoot.addPreference(accountScreen);
+ accountPreferenceHashMap.put(s, accountScreen);
+ }
+ }
+ }
+ }
+ };
+
+ Preference.OnPreferenceClickListener launchAccountCreationOnClick = new Preference.OnPreferenceClickListener() {
+ public boolean onPreferenceClick(Preference preference) {
+ launchAccountCreationActivity(preference);
+ return true;
+ }
+ };
+
+ Preference.OnPreferenceClickListener launchAccountEditOnClick = new Preference.OnPreferenceClickListener() {
+ public boolean onPreferenceClick(Preference preference) {
+ launchAccountEditActivity(preference);
+ return true;
+ }
+ };
+
+ Preference.OnPreferenceClickListener removeSelectedAccountOnClick = new Preference.OnPreferenceClickListener() {
+ public boolean onPreferenceClick(Preference preference) {
+ if (preference.getTitle() == "Delete Account") {
+ deleteSelectedAccount(preference.getKey());
+ }
+ return true;
+ }
+ };
+
+ @Override
+ public void onCreateOptionsMenu(Menu m, MenuInflater inf) {
+ super.onCreateOptionsMenu(m, inf);
+ inf.inflate(R.menu.account_creation, m);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ super.onOptionsItemSelected(item);
+ switch (item.getItemId()) {
+ case R.id.menuitem_create:
+ Intent intent = new Intent().setClass(getActivity(), AccountWizard.class);
+ startActivityForResult(intent, ACCOUNT_CREATE_REQUEST);
+ break;
+ }
+
+ return true;
+ }
+
+ private void launchAccountCreationActivity(Preference preference) {
+ Log.i(TAG, "Launch account creation activity");
+ Intent intent = preference.getIntent();
+ startActivityForResult(intent, ACCOUNT_CREATE_REQUEST);
+ }
+
+ private void launchAccountEditActivity(Preference preference) {
+ Log.i(TAG, "Launch account edit activity");
+ Intent intent = preference.getIntent();
+ Bundle bundle = intent.getExtras();
+ String accountID = bundle.getString("AccountID");
+
+ HashMap<String, String> preferenceMap = getAccountDetails(accountID);
+
+ Account d = new Account(accountID, preferenceMap);
+
+ bundle.putStringArrayList(AccountDetailBasic.BUNDLE_TAG, d.getBasicDetails().getValuesOnly());
+ bundle.putStringArrayList(AccountDetailAdvanced.BUNDLE_TAG, d.getAdvancedDetails().getValuesOnly());
+ bundle.putStringArrayList(AccountDetailSrtp.BUNDLE_TAG, d.getSrtpDetails().getValuesOnly());
+ bundle.putStringArrayList(AccountDetailTls.BUNDLE_TAG, d.getTlsDetails().getValuesOnly());
+
+ intent.putExtras(bundle);
+
+ startActivityForResult(intent, ACCOUNT_EDIT_REQUEST);
+ }
+
+ @SuppressWarnings("unchecked") // No proper solution with HashMap runtime cast
+ private ArrayList<String> getAccountList() {
+ ArrayList<String> accountList = null;
+ try {
+ accountList = (ArrayList<String>) service.getAccountList();
+ } catch (RemoteException e) {
+ Log.e(TAG, "Cannot call service method", e);
+ }
+
+ // Remove the default account from list
+ accountList.remove(DEFAULT_ACCOUNT_ID);
+
+ return accountList;
+ }
+
+ @SuppressWarnings("unchecked") // No proper solution with HashMap runtime cast
+ private HashMap<String, String> getAccountDetails(String accountID) {
+ HashMap<String, String> accountDetails = null;
+ try {
+ accountDetails = (HashMap<String, String>) service.getAccountDetails(accountID);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Cannot call service method", e);
+ }
+
+ return accountDetails;
+ }
+
+ public PreferenceScreen getAccountListPreferenceScreen() {
+ Activity currentContext = getActivity();
+
+ mRoot = getPreferenceManager().createPreferenceScreen(currentContext);
+
+ // Default account category
+ // PreferenceCategory defaultAccountCat = new PreferenceCategory(currentContext);
+ // defaultAccountCat.setTitle(R.string.default_account_category);
+ // mRoot.addPreference(defaultAccountCat);
+ //
+ // mRoot.addPreference(createAccountPreferenceScreen(DEFAULT_ACCOUNT_ID));
+
+ // Account list category
+ // PreferenceCategory accountListCat = new PreferenceCategory(currentContext);
+ // accountListCat.setTitle(R.string.default_account_category);
+ // mRoot.addPreference(accountListCat);
+
+ ArrayList<String> accountList = getAccountList();
+
+ for (String s : accountList) {
+ Preference accountScreen = createAccountPreferenceScreen(s);
+ mRoot.addPreference(accountScreen);
+ accountPreferenceHashMap.put(s, accountScreen);
+ }
+
+ return mRoot;
+ }
+
+ Preference createAccountPreferenceScreen(String accountID) {
+
+ HashMap<String, String> details = getAccountDetails(accountID);
+ // Set<String> keys = details.keySet();
+ // Iterator<String> ite = keys.iterator();
+ // while(ite.hasNext()){
+ // Log.i(TAG,"key : "+ ite.next());
+ // }
+ Bundle bundle = new Bundle();
+ bundle.putString("AccountID", accountID);
+
+ Intent intent = new Intent().setClass(getActivity(), AccountPreferenceActivity.class);
+ intent.putExtras(bundle);
+
+ Preference editAccount = new Preference(getActivity());
+ editAccount.setTitle(details.get(AccountDetailBasic.CONFIG_ACCOUNT_ALIAS));
+ editAccount.setSummary(details.get(AccountDetailBasic.CONFIG_ACCOUNT_HOSTNAME));
+ editAccount.setOnPreferenceClickListener(launchAccountEditOnClick);
+ editAccount.setIntent(intent);
+
+ return editAccount;
+ }
+}
diff --git a/src/org/sflphone/fragments/AudioManagementFragment.java b/src/org/sflphone/fragments/AudioManagementFragment.java
new file mode 100644
index 0000000..eb96fea
--- /dev/null
+++ b/src/org/sflphone/fragments/AudioManagementFragment.java
@@ -0,0 +1,256 @@
+/*
+ * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
+ *
+ * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
+ * Alexandre Lision <alexandre.lision@savoirfairelinux.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Additional permission under GNU GPL version 3 section 7:
+ *
+ * If you modify this program, or any covered work, by linking or
+ * combining it with the OpenSSL project's OpenSSL library (or a
+ * modified version of that library), containing parts covered by the
+ * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
+ * grants you additional permission to convey the resulting work.
+ * Corresponding Source for a non-source form of such a combination
+ * shall include the source code for the parts of OpenSSL used as well
+ * as that of the covered work.
+ */
+
+package org.sflphone.fragments;
+
+import org.sflphone.R;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.os.Bundle;
+import android.preference.EditTextPreference;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceCategory;
+import android.preference.PreferenceFragment;
+import android.preference.PreferenceScreen;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.SeekBar;
+import android.widget.SeekBar.OnSeekBarChangeListener;
+import android.widget.TextView;
+
+public class AudioManagementFragment extends PreferenceFragment
+{
+ static final String TAG = "PrefManagementFragment";
+ static final String CURRENT_VALUE = "Current value:: ";
+
+ public AudioManagementFragment()
+ {
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+
+ setPreferenceScreen(getAudioPreferenceScreen());
+ }
+
+ Preference.OnPreferenceChangeListener changePreferenceListener = new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ preference.setSummary(CURRENT_VALUE + (CharSequence)newValue);
+ return true;
+ }
+ };
+
+ public PreferenceScreen getAudioPreferenceScreen()
+ {
+ Activity currentContext = getActivity();
+
+ PreferenceScreen root = getPreferenceManager().createPreferenceScreen(currentContext);
+
+ PreferenceCategory audioPrefCat = new PreferenceCategory(currentContext);
+ audioPrefCat.setTitle(R.string.audio_preferences);
+ root.addPreference(audioPrefCat);
+
+ // Codec List
+ ListPreference codecListPref = new ListPreference(currentContext);
+ codecListPref.setEntries(R.array.audio_codec_list);
+ codecListPref.setEntryValues(R.array.audio_codec_list_value);
+ codecListPref.setDialogTitle(R.string.dialogtitle_audio_codec_list);
+ codecListPref.setPersistent(false);
+ codecListPref.setTitle(R.string.title_audio_codec_list);
+ codecListPref.setSummary(CURRENT_VALUE + "PCMU");
+ codecListPref.setOnPreferenceChangeListener(changePreferenceListener);
+ audioPrefCat.addPreference(codecListPref);
+
+ // Ringtone
+ EditTextPreference audioRingtonePref = new EditTextPreference(currentContext);
+ audioRingtonePref.setDialogTitle(R.string.dialogtitle_audio_ringtone_field);
+ audioRingtonePref.setPersistent(false);
+ audioRingtonePref.setTitle(R.string.title_audio_ringtone_field);
+ audioRingtonePref.setSummary(CURRENT_VALUE + "path/to/ringtone");
+ audioRingtonePref.setOnPreferenceChangeListener(changePreferenceListener);
+ audioPrefCat.addPreference(audioRingtonePref);
+
+ // Speaker volume seekbar
+ SeekBarPreference speakerSeekBarPref = new SeekBarPreference(currentContext);
+ speakerSeekBarPref.setPersistent(false);
+ speakerSeekBarPref.setTitle("Speaker Volume");
+ speakerSeekBarPref.setProgress(50);
+ speakerSeekBarPref.setSummary(CURRENT_VALUE + speakerSeekBarPref.getProgress());
+ audioPrefCat.addPreference(speakerSeekBarPref);
+
+ // Capture volume seekbar
+ SeekBarPreference captureSeekBarPref = new SeekBarPreference(currentContext);
+ captureSeekBarPref.setPersistent(false);
+ captureSeekBarPref.setTitle("Capture Volume");
+ captureSeekBarPref.setProgress(50);
+ captureSeekBarPref.setSummary(CURRENT_VALUE + captureSeekBarPref.getProgress());
+ audioPrefCat.addPreference(captureSeekBarPref);
+
+ // Ringtone volume seekbar
+ SeekBarPreference ringtoneSeekBarPref = new SeekBarPreference(currentContext);
+ ringtoneSeekBarPref.setPersistent(false);
+ ringtoneSeekBarPref.setTitle("Ringtone Volume");
+ ringtoneSeekBarPref.setProgress(50);
+ ringtoneSeekBarPref.setSummary(CURRENT_VALUE + ringtoneSeekBarPref.getProgress());
+ audioPrefCat.addPreference(ringtoneSeekBarPref);
+
+ return root;
+ }
+
+ public class SeekBarPreference extends Preference implements OnSeekBarChangeListener
+ {
+ private SeekBar seekbar;
+ private int progress;
+ private int max = 100;
+ private TextView summary;
+ private boolean discard;
+
+ public SeekBarPreference (Context context)
+ {
+ super( context );
+ }
+
+ public SeekBarPreference (Context context, AttributeSet attrs)
+ {
+ super( context, attrs );
+ }
+
+ public SeekBarPreference (Context context, AttributeSet attrs, int defStyle)
+ {
+ super( context, attrs, defStyle );
+ }
+
+ protected View onCreateView (ViewGroup p)
+ {
+ final Context ctx = getContext();
+
+ LinearLayout layout = new LinearLayout( ctx );
+ layout.setId( android.R.id.widget_frame );
+ layout.setOrientation( LinearLayout.VERTICAL );
+ layout.setPadding(65, 10, 15, 10);
+
+ TextView title = new TextView( ctx );
+ int textColor = title.getCurrentTextColor();
+ title.setId( android.R.id.title );
+ title.setSingleLine();
+ title.setTextAppearance( ctx, android.R.style.TextAppearance_Medium );
+ title.setTextColor( textColor );
+ layout.addView( title );
+
+ summary = new TextView( ctx );
+ summary.setId( android.R.id.summary );
+ summary.setSingleLine();
+ summary.setTextAppearance( ctx, android.R.style.TextAppearance_Small );
+ summary.setTextColor( textColor );
+ layout.addView( summary );
+
+ seekbar = new SeekBar( ctx );
+ seekbar.setId( android.R.id.progress );
+ seekbar.setMax( max );
+ seekbar.setOnSeekBarChangeListener( this );
+ layout.addView( seekbar );
+
+ return layout;
+ }
+
+ @Override
+ protected void onBindView (View view)
+ {
+ super.onBindView( view );
+
+ if (seekbar != null)
+ seekbar.setProgress( progress );
+ }
+
+ public void setProgress (int pcnt) {
+ if (progress != pcnt) {
+ persistInt( progress = pcnt );
+
+ notifyDependencyChange( shouldDisableDependents() );
+ notifyChanged();
+ }
+ }
+
+ public int getProgress () {
+ return progress;
+ }
+
+ public void setMax (int max) {
+ this.max = max;
+ if (seekbar != null)
+ seekbar.setMax( max );
+ }
+
+ @Override
+ protected Object onGetDefaultValue (TypedArray a, int index) {
+ return a.getInt( index, progress );
+ }
+
+ @Override
+ protected void onSetInitialValue (boolean restoreValue, Object defaultValue) {
+ setProgress( restoreValue ? getPersistedInt( progress ) : (Integer)defaultValue );
+ }
+
+ @Override
+ public boolean shouldDisableDependents () {
+ return progress == 0 || super.shouldDisableDependents();
+ }
+
+ public void onProgressChanged (SeekBar seekBar, int progress, boolean fromUser) {
+ discard = !callChangeListener( progress );
+ summary.setText(CURRENT_VALUE + progress);
+ }
+
+ public void onStartTrackingTouch (SeekBar seekBar) {
+ discard = false;
+ }
+
+ public void onStopTrackingTouch (SeekBar seekBar) {
+ if (discard)
+ seekBar.setProgress( progress );
+ else {
+ setProgress( seekBar.getProgress() );
+
+// OnPreferenceChangeListener listener = getOnPreferenceChangeListener();
+ //if (listener instanceof AbstractSeekBarListener)
+ //// setSummary( ((AbstractSeekBarListener)listener).toSummary( seekBar.getProgress() ) );
+ }
+ }
+ }
+}
diff --git a/src/org/sflphone/fragments/CallFragment.java b/src/org/sflphone/fragments/CallFragment.java
new file mode 100644
index 0000000..6c25b15
--- /dev/null
+++ b/src/org/sflphone/fragments/CallFragment.java
@@ -0,0 +1,545 @@
+/*
+ * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
+ *
+ * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Additional permission under GNU GPL version 3 section 7:
+ *
+ * If you modify this program, or any covered work, by linking or
+ * combining it with the OpenSSL project's OpenSSL library (or a
+ * modified version of that library), containing parts covered by the
+ * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
+ * grants you additional permission to convey the resulting work.
+ * Corresponding Source for a non-source form of such a combination
+ * shall include the source code for the parts of OpenSSL used as well
+ * as that of the covered work.
+ */
+
+package org.sflphone.fragments;
+
+import java.util.ArrayList;
+import java.util.Locale;
+
+import org.sflphone.R;
+import org.sflphone.model.Attractor;
+import org.sflphone.model.Bubble;
+import org.sflphone.model.BubbleModel;
+import org.sflphone.model.BubblesView;
+import org.sflphone.model.Conference;
+import org.sflphone.model.SipCall;
+import org.sflphone.service.ISipService;
+
+import android.app.Activity;
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.PointF;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.os.Bundle;
+import android.os.RemoteException;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.LayoutInflater;
+import android.view.SurfaceHolder;
+import android.view.SurfaceHolder.Callback;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.ImageButton;
+import android.widget.TextView;
+
+public class CallFragment extends Fragment implements Callback, SensorEventListener {
+
+ static final String TAG = "CallFragment";
+
+ float BUBBLE_SIZE = 75;
+ static final float ATTRACTOR_SIZE = 40;
+
+ public static final int REQUEST_TRANSFER = 10;
+
+ private Conference conf;
+
+ private TextView callStatusTxt;
+ private BubblesView view;
+ private BubbleModel model;
+
+ private Callbacks mCallbacks = sDummyCallbacks;
+
+ private SipCall myself;
+
+ boolean accepted = false;
+ private Bitmap call_icon;
+
+ private SensorManager mSensorManager;
+
+ private Sensor mSensor;
+
+ TransferDFragment editName;
+
+ @Override
+ public void onCreate(Bundle savedBundle) {
+ super.onCreate(savedBundle);
+ Bundle b = getArguments();
+ conf = new Conference((Conference) b.getParcelable("conference"));
+ model = new BubbleModel(getResources().getDisplayMetrics().density);
+ BUBBLE_SIZE = getResources().getDimension(R.dimen.bubble_size);
+ Log.e(TAG, "BUBBLE_SIZE " + BUBBLE_SIZE);
+ mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
+ mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
+
+ }
+
+ /**
+ * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity.
+ */
+ private static Callbacks sDummyCallbacks = new Callbacks() {
+ @Override
+ public void onSendMessage(SipCall call, String msg) {
+ }
+
+ @Override
+ public void callContact(SipCall call) {
+ }
+
+ @Override
+ public void onCallAccepted(SipCall call) {
+ }
+
+ @Override
+ public void onCallRejected(SipCall call) {
+ }
+
+ @Override
+ public void onCallEnded(SipCall call) {
+ }
+
+ @Override
+ public void onCallSuspended(SipCall call) {
+ }
+
+ @Override
+ public void onCallResumed(SipCall call) {
+ }
+
+ @Override
+ public void onCalltransfered(SipCall call, String to) {
+ }
+
+ @Override
+ public void onRecordCall(SipCall call) {
+ }
+
+ @Override
+ public ISipService getService() {
+ return null;
+ }
+
+ @Override
+ public void replaceCurrentCallDisplayed() {
+ }
+
+ @Override
+ public void startTimer() {
+ }
+ };
+
+ /**
+ * The Activity calling this fragment has to implement this interface
+ *
+ */
+ public interface Callbacks {
+
+ public ISipService getService();
+
+ public void callContact(SipCall call);
+
+ public void onCallAccepted(SipCall call);
+
+ public void onCallRejected(SipCall call);
+
+ public void onCallEnded(SipCall call);
+
+ public void onCallSuspended(SipCall call);
+
+ public void onCallResumed(SipCall call);
+
+ public void onCalltransfered(SipCall call, String to);
+
+ public void onRecordCall(SipCall call);
+
+ public void onSendMessage(SipCall call, String msg);
+
+ public void replaceCurrentCallDisplayed();
+
+ public void startTimer();
+ }
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+
+ if (!(activity instanceof Callbacks)) {
+ throw new IllegalStateException("Activity must implement fragment's callbacks.");
+ }
+
+ // rootView.requestDisallowInterceptTouchEvent(true);
+
+ mCallbacks = (Callbacks) activity;
+ myself = SipCall.SipCallBuilder.buildMyselfCall(activity.getContentResolver(), "Me");
+
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ mCallbacks = sDummyCallbacks;
+ mSensorManager.unregisterListener(this);
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ mSensorManager.unregisterListener(this);
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ SipCall transfer = null;
+ if (requestCode == REQUEST_TRANSFER) {
+ switch (resultCode) {
+ case TransferDFragment.RESULT_TRANSFER_CONF:
+ Conference c = data.getParcelableExtra("target");
+ transfer = data.getParcelableExtra("transfer");
+ try {
+
+ mCallbacks.getService().attendedTransfer(transfer.getCallId(), c.getParticipants().get(0).getCallId());
+
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ // Toast.makeText(getActivity(), "Transfer complete", Toast.LENGTH_LONG).show();
+ break;
+
+ case TransferDFragment.RESULT_TRANSFER_NUMBER:
+ String to = data.getStringExtra("to_number");
+ transfer = data.getParcelableExtra("transfer");
+ try {
+ // Toast.makeText(getActivity(), "Transferring " + transfer.getContact().getmDisplayName() + " to " + to,
+ // Toast.LENGTH_SHORT).show();
+ mCallbacks.getService().transfer(transfer.getCallId(), to);
+ mCallbacks.getService().hangUp(transfer.getCallId());
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ break;
+ case Activity.RESULT_CANCELED:
+ default:
+ model.clear();
+ initNormalStateDisplay();
+ break;
+ }
+ }
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call, container, false);
+
+ view = (BubblesView) rootView.findViewById(R.id.main_view);
+ view.setFragment(this);
+ view.setModel(model);
+ view.getHolder().addCallback(this);
+
+ callStatusTxt = (TextView) rootView.findViewById(R.id.call_status_txt);
+ call_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_call);
+
+ ((ImageButton) rootView.findViewById(R.id.dialpad_btn)).setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ InputMethodManager lManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
+ lManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY);
+ }
+ });
+
+ return rootView;
+ }
+
+ private void initNormalStateDisplay() {
+ Log.i(TAG, "Start normal display");
+
+ mCallbacks.startTimer();
+
+ getBubbleFor(myself, model.width / 2, model.height / 2);
+
+ int angle_part = 360 / conf.getParticipants().size();
+ double dX = 0;
+ double dY = 0;
+ int radiusCalls = (int) (model.width / 2 - BUBBLE_SIZE);
+ for (int i = 0; i < conf.getParticipants().size(); ++i) {
+
+ if (conf.getParticipants().get(i) == null) {
+ Log.i(TAG, i + " null ");
+ continue;
+ }
+ dX = Math.cos(Math.toRadians(angle_part * i - 90)) * radiusCalls;
+ dY = Math.sin(Math.toRadians(angle_part * i - 90)) * radiusCalls;
+ getBubbleFor(conf.getParticipants().get(i), (int) (model.width / 2 + dX), (int) (model.height / 2 + dY));
+ }
+
+ model.clearAttractors();
+ }
+
+ private void initIncomingCallDisplay() {
+ Log.i(TAG, "Start incoming display");
+
+ mCallbacks.startTimer();
+
+ int radiusCalls = (int) (model.width / 2 - BUBBLE_SIZE);
+ getBubbleFor(myself, model.width / 2, model.height / 2 + radiusCalls);
+ getBubbleFor(conf.getParticipants().get(0), model.width / 2, model.height / 2 - radiusCalls);
+
+ model.clearAttractors();
+ model.addAttractor(new Attractor(new PointF(model.width / 2, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() {
+ @Override
+ public boolean onBubbleSucked(Bubble b) {
+
+ if (!accepted) {
+ mCallbacks.onCallAccepted(conf.getParticipants().get(0));
+ accepted = true;
+ }
+ return false;
+ }
+ }, call_icon));
+ }
+
+ private void initOutGoingCallDisplay() {
+ Log.i(TAG, "Start outgoing display");
+
+ mCallbacks.startTimer();
+
+ getBubbleFor(myself, model.width / 2, model.height / 2);
+
+ // TODO off-thread image loading
+ int angle_part = 360 / conf.getParticipants().size();
+ double dX = 0;
+ double dY = 0;
+ int radiusCalls = (int) (model.width / 2 - BUBBLE_SIZE);
+ for (int i = 0; i < conf.getParticipants().size(); ++i) {
+ dX = Math.cos(Math.toRadians(angle_part * i - 90)) * radiusCalls;
+ dY = Math.sin(Math.toRadians(angle_part * i - 90)) * radiusCalls;
+ getBubbleFor(conf.getParticipants().get(i), (int) (model.width / 2 + dX), (int) (model.height / 2 + dY));
+ }
+
+ model.clearAttractors();
+ }
+
+ /**
+ * Retrieves or create a bubble for a given contact. If the bubble exists, it is moved to the new location.
+ *
+ * @param call
+ * The call associated to a contact
+ * @param x
+ * Initial or new x position.
+ * @param y
+ * Initial or new y position.
+ * @return Bubble corresponding to the contact.
+ */
+ private Bubble getBubbleFor(SipCall call, float x, float y) {
+ Bubble contact_bubble = model.getBubble(call);
+ if (contact_bubble != null) {
+ contact_bubble.attractor.set(x, y);
+ return contact_bubble;
+ }
+
+ contact_bubble = new Bubble(getActivity(), call, x, y, BUBBLE_SIZE);
+
+ model.addBubble(contact_bubble);
+ return contact_bubble;
+ }
+
+ /**
+ * Should be called when a bubble is removed from the model
+ */
+ void bubbleRemoved(Bubble b) {
+ if (b.associated_call == null) {
+ return;
+ }
+ }
+
+ public void changeCallState(String callID, String newState) {
+ Log.w(TAG, "Call :" + callID + " " + newState);
+ if (newState.contentEquals("FAILURE")) {
+ try {
+ mCallbacks.getService().hangUp(callID);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+ for (int i = 0; i < conf.getParticipants().size(); ++i) {
+ if (callID.equals(conf.getParticipants().get(i).getCallId())) {
+ if (newState.contentEquals("HUNGUP")) {
+ model.removeBubble(conf.getParticipants().get(i));
+ conf.getParticipants().remove(i);
+ } else {
+ conf.getParticipants().get(i).setCallState(newState);
+ }
+ }
+ }
+
+ if (conf.isOnGoing())
+ initNormalStateDisplay();
+
+ if (conf.getParticipants().size() == 0) {
+ mCallbacks.replaceCurrentCallDisplayed();
+ }
+ }
+
+ public boolean draggingBubble() {
+ return view == null ? false : view.isDraggingBubble();
+ }
+
+ @Override
+ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
+
+ if (conf.getParticipants().size() == 1) {
+ if (conf.getParticipants().get(0).isIncoming() && conf.getParticipants().get(0).isRinging()) {
+ initIncomingCallDisplay();
+ } else {
+ if (conf.getParticipants().get(0).isRinging()) {
+ initOutGoingCallDisplay();
+ }
+ try {
+ if (conf.getParticipants().get(0).isOutGoing()
+ && mCallbacks.getService().getCall(conf.getParticipants().get(0).getCallId()) == null) {
+ mCallbacks.getService().placeCall(conf.getParticipants().get(0));
+ initOutGoingCallDisplay();
+ } else if (conf.getParticipants().get(0).isOutGoing() && conf.getParticipants().get(0).isRinging()) {
+ initOutGoingCallDisplay();
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
+ }
+ if (conf.getParticipants().get(0).isOngoing()) {
+ initNormalStateDisplay();
+ }
+ } else if (conf.getParticipants().size() > 1) {
+ initNormalStateDisplay();
+ }
+ }
+
+ public void makeTransfer(Bubble contact) {
+ FragmentManager fm = getFragmentManager();
+ editName = TransferDFragment.newInstance();
+ Bundle b = new Bundle();
+ try {
+ b.putParcelableArrayList("calls", (ArrayList<Conference>)mCallbacks.getService().getConcurrentCalls());
+ b.putParcelable("call_selected", contact.associated_call);
+ editName.setArguments(b);
+ editName.setTargetFragment(this, REQUEST_TRANSFER);
+ editName.show(fm, "");
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
+
+ }
+
+ @Override
+ public void surfaceCreated(SurfaceHolder holder) {
+
+ }
+
+ @Override
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ // check that soft input is hidden
+ InputMethodManager lManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
+ lManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
+ if(editName != null && editName.isVisible()){
+ editName.dismiss();
+ }
+ }
+
+ public BubblesView getBubbleView() {
+ return view;
+ }
+
+ public void updateTime() {
+ long duration = System.currentTimeMillis() / 1000 - this.conf.getParticipants().get(0).getTimestamp_start();
+ callStatusTxt.setText(String.format("%d:%02d:%02d", duration / 3600, duration % 3600 / 60, duration % 60));
+ }
+
+ @Override
+ public void onAccuracyChanged(Sensor sensor, int accuracy) {
+
+ }
+
+ @Override
+ public void onSensorChanged(SensorEvent event) {
+ if (event.values[0] == 0) {
+ WindowManager.LayoutParams params = getActivity().getWindow().getAttributes();
+ params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
+ params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
+ params.screenBrightness = 0.004f;
+ getActivity().getWindow().setAttributes(params);
+
+ } else {
+ WindowManager.LayoutParams params = getActivity().getWindow().getAttributes();
+ getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
+ params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
+ params.screenBrightness = 1.0f;
+ getActivity().getWindow().setAttributes(params);
+ }
+ }
+
+ public Conference getConference() {
+ return conf;
+ }
+
+ public void onKeyUp(int keyCode, KeyEvent event) {
+ try {
+ String toSend = Character.toString(event.getDisplayLabel());
+ toSend.toUpperCase(Locale.getDefault());
+ Log.d(TAG, "toSend " + toSend);
+ mCallbacks.getService().playDtmf(toSend);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/org/sflphone/fragments/CallListFragment.java b/src/org/sflphone/fragments/CallListFragment.java
new file mode 100644
index 0000000..b4752ba
--- /dev/null
+++ b/src/org/sflphone/fragments/CallListFragment.java
@@ -0,0 +1,574 @@
+/*
+ * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
+ *
+ * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Additional permission under GNU GPL version 3 section 7:
+ *
+ * If you modify this program, or any covered work, by linking or
+ * combining it with the OpenSSL project's OpenSSL library (or a
+ * modified version of that library), containing parts covered by the
+ * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
+ * grants you additional permission to convey the resulting work.
+ * Corresponding Source for a non-source form of such a combination
+ * shall include the source code for the parts of OpenSSL used as well
+ * as that of the covered work.
+ */
+
+package org.sflphone.fragments;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.sflphone.R;
+import org.sflphone.model.Conference;
+import org.sflphone.model.SipCall;
+import org.sflphone.service.ISipService;
+import org.sflphone.views.SwipeListViewTouchListener;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.app.Fragment;
+import android.content.ClipData;
+import android.content.ClipData.Item;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.graphics.Color;
+import android.os.Bundle;
+import android.os.RemoteException;
+import android.os.Vibrator;
+import android.util.Log;
+import android.view.DragEvent;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.View.DragShadowBuilder;
+import android.view.View.OnDragListener;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.AdapterView.OnItemLongClickListener;
+import android.widget.ArrayAdapter;
+import android.widget.BaseAdapter;
+import android.widget.ListAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+public class CallListFragment extends Fragment {
+ static final String TAG = CallListFragment.class.getSimpleName();
+
+ private Callbacks mCallbacks = sDummyCallbacks;
+
+ CallListAdapter mAdapter;
+
+ public static final int REQUEST_TRANSFER = 10;
+ public static final int REQUEST_CONF = 20;
+
+ @Override
+ public void onCreate(Bundle savedBundle) {
+ super.onCreate(savedBundle);
+
+ mAdapter = new CallListAdapter(getActivity());
+
+ }
+
+ /**
+ * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity.
+ */
+ private static Callbacks sDummyCallbacks = new Callbacks() {
+
+ @Override
+ public ISipService getService() {
+ return null;
+ }
+
+ @Override
+ public void onCallSelected(Conference conf) {
+ }
+
+ @Override
+ public void onCallsTerminated() {
+ }
+ };
+
+ /**
+ * The Activity calling this fragment has to implement this interface
+ *
+ */
+ public interface Callbacks {
+ public ISipService getService();
+
+ public void onCallSelected(Conference conf);
+
+ public void onCallsTerminated();
+
+ }
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+
+ if (!(activity instanceof Callbacks)) {
+ throw new IllegalStateException("Activity must implement fragment's callbacks.");
+ }
+
+ mCallbacks = (Callbacks) activity;
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ mCallbacks = sDummyCallbacks;
+ }
+
+ ListView list;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call_list, container, false);
+
+ list = (ListView) rootView.findViewById(R.id.call_list);
+
+ list.setDivider(getResources().getDrawable(android.R.drawable.divider_horizontal_dark));
+ list.setDividerHeight(10);
+ list.setAdapter(mAdapter);
+ list.setOnItemClickListener(mItemClickListener);
+ list.setOnTouchListener(new SwipeListViewTouchListener(list, new SwipeListViewTouchListener.OnSwipeCallback() {
+ @Override
+ public void onSwipeLeft(ListView listView, int[] reverseSortedPositions) {
+ // Log.i(this.getClass().getName(), "swipe left : pos="+reverseSortedPositions[0]);
+ // TODO : YOUR CODE HERE FOR LEFT ACTION
+ Conference tmp = mAdapter.getItem(reverseSortedPositions[0]);
+ try {
+ if (tmp.hasMultipleParticipants()) {
+ mCallbacks.getService().hangUpConference(tmp.getId());
+ } else {
+ mCallbacks.getService().hangUp(tmp.getParticipants().get(0).getCallId());
+ }
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ @Override
+ public void onSwipeRight(ListView listView, int[] reverseSortedPositions) {
+ // Log.i(ProfileMenuActivity.class.getClass().getName(), "swipe right : pos="+reverseSortedPositions[0]);
+ // TODO : YOUR CODE HERE FOR RIGHT ACTION
+
+ Conference tmp = mAdapter.getItem(reverseSortedPositions[0]);
+ try {
+ if (tmp.hasMultipleParticipants()) {
+ if (tmp.isOnHold()) {
+ mCallbacks.getService().unholdConference(tmp.getId());
+ } else {
+ mCallbacks.getService().holdConference(tmp.getId());
+ }
+ } else {
+ if (tmp.isOnHold()) {
+ Toast.makeText(getActivity(), "call is on hold, unholding", Toast.LENGTH_SHORT).show();
+ mCallbacks.getService().unhold(tmp.getParticipants().get(0).getCallId());
+ } else {
+ Toast.makeText(getActivity(), "call is current, holding", Toast.LENGTH_SHORT).show();
+ mCallbacks.getService().hold(tmp.getParticipants().get(0).getCallId());
+ }
+ }
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }, true, // example : left action = dismiss
+ false)); // example : right action without dismiss animation);
+ list.setOnItemLongClickListener(mItemLongClickListener);
+
+ return rootView;
+ }
+
+ OnDragListener dragListener = new OnDragListener() {
+
+ @SuppressWarnings("deprecation") // deprecated in API 16....
+ @Override
+ public boolean onDrag(View v, DragEvent event) {
+ switch (event.getAction()) {
+ case DragEvent.ACTION_DRAG_STARTED:
+ // Do nothing
+ Log.w(TAG, "ACTION_DRAG_STARTED");
+ break;
+ case DragEvent.ACTION_DRAG_ENTERED:
+ Log.w(TAG, "ACTION_DRAG_ENTERED");
+ v.setBackgroundColor(Color.GREEN);
+ break;
+ case DragEvent.ACTION_DRAG_EXITED:
+ Log.w(TAG, "ACTION_DRAG_EXITED");
+ v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_call_selector));
+ break;
+ case DragEvent.ACTION_DROP:
+ Log.w(TAG, "ACTION_DROP");
+ View view = (View) event.getLocalState();
+
+ Item i = event.getClipData().getItemAt(0);
+ Intent intent = i.getIntent();
+ intent.setExtrasClassLoader(Conference.class.getClassLoader());
+
+ Conference initial = (Conference) view.getTag();
+ Conference target = (Conference) v.getTag();
+
+ if (initial == target) {
+ return true;
+ }
+
+ DropActionsChoice dialog = DropActionsChoice.newInstance();
+ Bundle b = new Bundle();
+ b.putParcelable("call_initial", initial);
+ b.putParcelable("call_targeted", target);
+ dialog.setArguments(b);
+ dialog.setTargetFragment(CallListFragment.this, 0);
+ dialog.show(getFragmentManager(), "dialog");
+
+ Toast.makeText(
+ getActivity(),
+ "Dropped " + initial.getParticipants().get(0).getContact().getmDisplayName() + " on "
+ + target.getParticipants().get(0).getContact().getmDisplayName(), Toast.LENGTH_SHORT).show();
+ // view.setBackgroundColor(Color.WHITE);
+ // v.setBackgroundColor(Color.BLACK);
+ break;
+ case DragEvent.ACTION_DRAG_ENDED:
+ Log.w(TAG, "ACTION_DRAG_ENDED");
+ View view1 = (View) event.getLocalState();
+ view1.setVisibility(View.VISIBLE);
+ v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_call_selector));
+ default:
+ break;
+ }
+ return true;
+ }
+
+ };
+
+ private OnItemLongClickListener mItemLongClickListener = new OnItemLongClickListener() {
+
+ @Override
+ public boolean onItemLongClick(AdapterView<?> arg0, View view, int pos, long arg3) {
+ final Vibrator vibe = (Vibrator) view.getContext().getSystemService(Context.VIBRATOR_SERVICE);
+ vibe.vibrate(80);
+ Intent i = new Intent();
+ Bundle b = new Bundle();
+ b.putParcelable("conference", mAdapter.getItem(pos));
+ i.putExtra("bconference", b);
+
+ DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
+ ClipData data = ClipData.newIntent("conference", i);
+ view.startDrag(data, shadowBuilder, view, 0);
+ return false;
+ }
+
+ };
+
+ private OnItemClickListener mItemClickListener = new OnItemClickListener() {
+
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
+ mCallbacks.onCallSelected(mAdapter.getItem(pos));
+
+ }
+ };
+
+ @SuppressWarnings("unchecked") // No proper solution with HashMap runtime cast
+ public void update() {
+ try {
+ HashMap<String, SipCall> list = (HashMap<String, SipCall>) mCallbacks.getService().getCallList();
+
+ // Toast.makeText(getActivity(), "Calls: " + list.size(), Toast.LENGTH_SHORT).show();
+ ArrayList<Conference> conferences = new ArrayList<Conference>();
+ HashMap<String, Conference> tmp = (HashMap<String, Conference>) mCallbacks.getService().getConferenceList();
+ conferences.addAll(tmp.values());
+
+ ArrayList<SipCall> simple_calls = new ArrayList<SipCall>(list.values());
+ for (SipCall call : simple_calls) {
+ Conference confOne = new Conference("-1");
+ confOne.getParticipants().add(call);
+ conferences.add(confOne);
+ }
+
+ if (conferences.isEmpty()) {
+ mCallbacks.onCallsTerminated();
+ }
+
+ mAdapter.update(conferences);
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
+
+ }
+
+ // private void makeTransferDialog(int groupPosition) {
+ // FragmentManager fm = getFragmentManager();
+ // TransferDFragment editNameDialog = new TransferDFragment();
+ //
+ // if (!mAdapter.getItem(groupPosition).hasMultipleParticipants()) {
+ // Bundle b = new Bundle();
+ // b.putParcelableArrayList("calls", mAdapter.getConcurrentCalls(groupPosition));
+ // b.putParcelable("call_selected", mAdapter.getItem(groupPosition));
+ // editNameDialog.setArguments(b);
+ // editNameDialog.setTargetFragment(this, REQUEST_TRANSFER);
+ // editNameDialog.show(fm, "dialog");
+ // } else {
+ // Toast.makeText(getActivity(), "Transfer a Conference ?", Toast.LENGTH_SHORT).show();
+ // }
+ //
+ // }
+ //
+ // private void makeConferenceDialog(int groupPosition) {
+ // FragmentManager fm = getFragmentManager();
+ // ConferenceDFragment confDialog = ConferenceDFragment.newInstance();
+ //
+ // Bundle b = new Bundle();
+ // b.putParcelableArrayList("calls", mAdapter.getConcurrentCalls(groupPosition));
+ // b.putParcelable("call_selected", mAdapter.getItem(groupPosition));
+ // confDialog.setArguments(b);
+ // confDialog.setTargetFragment(this, REQUEST_CONF);
+ // confDialog.show(fm, "dialog");
+ //
+ // }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ Conference transfer = null;
+ if (requestCode == REQUEST_TRANSFER) {
+ switch (resultCode) {
+ case 0:
+ Conference c = data.getParcelableExtra("target");
+ transfer = data.getParcelableExtra("transfer");
+ try {
+
+ mCallbacks.getService().attendedTransfer(transfer.getParticipants().get(0).getCallId(), c.getParticipants().get(0).getCallId());
+ mAdapter.remove(transfer);
+ mAdapter.remove(c);
+ mAdapter.notifyDataSetChanged();
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Toast.makeText(getActivity(), "Transfer complete", Toast.LENGTH_LONG).show();
+ break;
+
+ case 1:
+ String to = data.getStringExtra("to_number");
+ transfer = data.getParcelableExtra("transfer");
+ try {
+ Toast.makeText(getActivity(), "Transferring " + transfer.getParticipants().get(0).getContact().getmDisplayName() + " to " + to,
+ Toast.LENGTH_SHORT).show();
+ mCallbacks.getService().transfer(transfer.getParticipants().get(0).getCallId(), to);
+ mCallbacks.getService().hangUp(transfer.getParticipants().get(0).getCallId());
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ break;
+
+ default:
+ break;
+ }
+ } else if (requestCode == REQUEST_CONF) {
+ switch (resultCode) {
+ case 0:
+ Conference call_to_add = data.getParcelableExtra("transfer");
+ Conference call_target = data.getParcelableExtra("target");
+
+ bindCalls(call_to_add, call_target);
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+
+ private void bindCalls(Conference call_to_add, Conference call_target) {
+ try {
+
+ if (call_target.hasMultipleParticipants() && !call_to_add.hasMultipleParticipants()) {
+
+ mCallbacks.getService().addParticipant(call_to_add.getParticipants().get(0), call_target.getId());
+
+ } else if (call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) {
+
+ // We join two conferences
+ mCallbacks.getService().joinConference(call_to_add.getId(), call_target.getId());
+
+ } else if (!call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) {
+
+ mCallbacks.getService().addParticipant(call_target.getParticipants().get(0), call_to_add.getId());
+
+ } else {
+ // We join two single calls to create a conf
+ mCallbacks.getService().joinParticipant(call_to_add.getParticipants().get(0).getCallId(),
+ call_target.getParticipants().get(0).getCallId());
+ }
+
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public class CallListAdapter extends BaseAdapter {
+
+ private ArrayList<Conference> calls;
+
+ private Context mContext;
+
+ public CallListAdapter(Context act) {
+ super();
+ mContext = act;
+ calls = new ArrayList<Conference>();
+
+ }
+
+ public ArrayList<Conference> getConcurrentCalls(int position) {
+ ArrayList<Conference> toReturn = new ArrayList<Conference>();
+ for (int i = 0; i < calls.size(); ++i) {
+ if (position != i)
+ toReturn.add(calls.get(i));
+ }
+ return toReturn;
+ }
+
+ public void remove(Conference transfer) {
+ calls.remove(transfer);
+ }
+
+ public void update(ArrayList<Conference> list) {
+ calls.clear();
+ calls.addAll(list);
+ notifyDataSetChanged();
+ }
+
+ @Override
+ public int getCount() {
+ return calls.size();
+ }
+
+ @Override
+ public Conference getItem(int position) {
+ return calls.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return 0;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ if (convertView == null)
+ convertView = LayoutInflater.from(mContext).inflate(R.layout.item_calllist, null);
+
+ Conference call = calls.get(position);
+ if (call.getParticipants().size() == 1) {
+ ((TextView) convertView.findViewById(R.id.call_title)).setText(call.getParticipants().get(0).getContact().getmDisplayName());
+
+ long duration = System.currentTimeMillis() / 1000 - (call.getParticipants().get(0).getTimestamp_start());
+
+ ((TextView) convertView.findViewById(R.id.call_time)).setText(String.format("%d:%02d:%02d", duration/3600, (duration%3600)/60, (duration%60)));
+ } else {
+ String tmp = "Conference with " + call.getParticipants().size() + " participants";
+
+ ((TextView) convertView.findViewById(R.id.call_title)).setText(tmp);
+ }
+
+ ((TextView) convertView.findViewById(R.id.call_status)).setText(call.getState());
+ convertView.setOnDragListener(dragListener);
+
+ convertView.setTag(call);
+ return convertView;
+ }
+
+ }
+
+ public static class DropActionsChoice extends DialogFragment {
+
+ ListAdapter mAdapter;
+ private Bundle args;
+
+ /**
+ * Create a new instance of CallActionsDFragment
+ */
+ public static DropActionsChoice newInstance() {
+ DropActionsChoice f = new DropActionsChoice();
+ return f;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // Pick a style based on the num.
+ int style = DialogFragment.STYLE_NORMAL, theme = 0;
+ setStyle(style, theme);
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ ListView rootView = new ListView(getActivity());
+
+ args = getArguments();
+ mAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, getResources().getStringArray(
+ R.array.drop_actions));
+
+ // ListView list = (ListView) rootView.findViewById(R.id.concurrent_calls);
+ rootView.setAdapter(mAdapter);
+ rootView.setOnItemClickListener(new OnItemClickListener() {
+
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
+ Intent in = new Intent();
+
+ in.putExtra("transfer", args.getParcelable("call_initial"));
+ in.putExtra("target", args.getParcelable("call_targeted"));
+
+ switch (pos) {
+ case 0: // Transfer
+ getTargetFragment().onActivityResult(REQUEST_TRANSFER, 0, in);
+ break;
+ case 1: // Conference
+ getTargetFragment().onActivityResult(REQUEST_CONF, 0, in);
+ break;
+ }
+ dismiss();
+
+ }
+ });
+
+ final AlertDialog a = new AlertDialog.Builder(getActivity()).setView(rootView).setTitle("Choose Action")
+ .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+ dismiss();
+ }
+ }).create();
+
+ return a;
+ }
+ }
+
+}
diff --git a/src/org/sflphone/fragments/ConferenceDFragment.java b/src/org/sflphone/fragments/ConferenceDFragment.java
new file mode 100644
index 0000000..c7ebb17
--- /dev/null
+++ b/src/org/sflphone/fragments/ConferenceDFragment.java
@@ -0,0 +1,163 @@
+package org.sflphone.fragments;
+
+import java.util.ArrayList;
+
+import org.sflphone.R;
+import org.sflphone.loaders.ContactsLoader;
+import org.sflphone.model.Conference;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.app.LoaderManager;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.Loader;
+import android.net.Uri;
+import android.os.Bundle;
+import android.provider.ContactsContract.Contacts;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.BaseAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
+
+public class ConferenceDFragment extends DialogFragment implements LoaderManager.LoaderCallbacks<Bundle> {
+
+
+ SimpleCallListAdapter mAdapter;
+
+ /**
+ * Create a new instance of CallActionsDFragment
+ */
+ public static ConferenceDFragment newInstance() {
+ ConferenceDFragment f = new ConferenceDFragment();
+ return f;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // Pick a style based on the num.
+ int style = DialogFragment.STYLE_NORMAL, theme = 0;
+ setStyle(style, theme);
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ View rootView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_conference, null);
+
+ ArrayList<Conference> calls = getArguments().getParcelableArrayList("calls");
+ final Conference call_selected = getArguments().getParcelable("call_selected");
+
+ mAdapter = new SimpleCallListAdapter(getActivity(), calls);
+ ListView list = (ListView) rootView.findViewById(R.id.concurrent_calls);
+ list.setAdapter(mAdapter);
+ list.setOnItemClickListener(new OnItemClickListener() {
+
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
+
+ Intent in = new Intent();
+
+ in.putExtra("transfer", call_selected);
+ in.putExtra("target", mAdapter.getItem(pos));
+ getTargetFragment().onActivityResult(getTargetRequestCode(), 0, in);
+ dismiss();
+ }
+ });
+ list.setEmptyView(rootView.findViewById(R.id.empty_view));
+
+
+
+ final AlertDialog a = new AlertDialog.Builder(getActivity()).setView(rootView).setTitle("Transfer " + call_selected.getParticipants().get(0).getContact())
+ .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+
+ dismiss();
+ }
+ }).create();
+
+ return a;
+ }
+
+ @Override
+ public Loader<Bundle> onCreateLoader(int id, Bundle args) {
+ Uri baseUri;
+
+ if (args != null) {
+ baseUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI, Uri.encode(args.getString("filter")));
+ } else {
+ baseUri = Contacts.CONTENT_URI;
+ }
+ ContactsLoader l = new ContactsLoader(getActivity(), baseUri);
+ l.forceLoad();
+ return l;
+ }
+
+ @Override
+ public void onLoadFinished(Loader<Bundle> loader, Bundle data) {
+
+// ArrayList<CallContact> tmp = data.getParcelableArrayList("Contacts");
+
+ }
+
+ @Override
+ public void onLoaderReset(Loader<Bundle> loader) {
+ // Thi is called when the last Cursor provided to onLoadFinished
+ // mListAdapter.swapCursor(null);
+ }
+
+
+
+ private class SimpleCallListAdapter extends BaseAdapter {
+
+ private LayoutInflater mInflater;
+ ArrayList<Conference> calls;
+
+ public SimpleCallListAdapter(final Context context, ArrayList<Conference> calls2) {
+ super();
+ mInflater = LayoutInflater.from(context);
+ calls = calls2;
+ }
+
+ @Override
+ public View getView(final int position, final View convertView, final ViewGroup parent) {
+ final TextView tv;
+ if (convertView != null) {
+ tv = (TextView) convertView;
+ } else {
+ tv = (TextView) mInflater.inflate(android.R.layout.simple_dropdown_item_1line, parent, false);
+ }
+
+ if(calls.get(position).getParticipants().size() == 1){
+ tv.setText(calls.get(position).getParticipants().get(0).getContact().getmDisplayName());
+ } else {
+ tv.setText("Conference with "+ calls.get(position).getParticipants().size() + " participants");
+ }
+
+ return tv;
+ }
+
+ @Override
+ public int getCount() {
+ return calls.size();
+ }
+
+ @Override
+ public Conference getItem(int pos) {
+ return calls.get(pos);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return 0;
+ }
+ }
+
+}
diff --git a/src/org/sflphone/fragments/ContactListFragment.java b/src/org/sflphone/fragments/ContactListFragment.java
new file mode 100644
index 0000000..3b04166
--- /dev/null
+++ b/src/org/sflphone/fragments/ContactListFragment.java
@@ -0,0 +1,342 @@
+/*
+ * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
+ *
+ * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
+ * Alexandre Lision <alexandre.lision@savoirfairelinux.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Additional permission under GNU GPL version 3 section 7:
+ *
+ * If you modify this program, or any covered work, by linking or
+ * combining it with the OpenSSL project's OpenSSL library (or a
+ * modified version of that library), containing parts covered by the
+ * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
+ * grants you additional permission to convey the resulting work.
+ * Corresponding Source for a non-source form of such a combination
+ * shall include the source code for the parts of OpenSSL used as well
+ * as that of the covered work.
+ */
+package org.sflphone.fragments;
+
+import java.util.ArrayList;
+
+import org.sflphone.R;
+import org.sflphone.adapters.ContactsAdapter;
+import org.sflphone.adapters.StarredContactsAdapter;
+import org.sflphone.loaders.ContactsLoader;
+import org.sflphone.loaders.LoaderConstants;
+import org.sflphone.model.CallContact;
+import org.sflphone.service.ISipService;
+import org.sflphone.views.TACGridView;
+
+import android.animation.LayoutTransition;
+import android.app.Activity;
+import android.app.Fragment;
+import android.app.LoaderManager;
+import android.content.Loader;
+import android.net.Uri;
+import android.os.Bundle;
+import android.provider.ContactsContract.Contacts;
+import android.util.Log;
+import android.view.DragEvent;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.View.DragShadowBuilder;
+import android.view.View.OnClickListener;
+import android.view.View.OnDragListener;
+import android.view.ViewGroup;
+import android.widget.AbsListView;
+import android.widget.AbsListView.OnScrollListener;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.AdapterView.OnItemLongClickListener;
+import android.widget.ImageButton;
+import android.widget.LinearLayout;
+import android.widget.ListView;
+import android.widget.RelativeLayout;
+import android.widget.SearchView;
+import android.widget.SearchView.OnQueryTextListener;
+
+public class ContactListFragment extends Fragment implements OnQueryTextListener, LoaderManager.LoaderCallbacks<Bundle> {
+ private static final String TAG = "ContactListFragment";
+ ContactsAdapter mListAdapter;
+ StarredContactsAdapter mGridAdapter;
+
+ String mCurFilter;
+
+ @Override
+ public void onCreate(Bundle savedInBundle) {
+ super.onCreate(savedInBundle);
+ mListAdapter = new ContactsAdapter(getActivity());
+ mGridAdapter = new StarredContactsAdapter(getActivity());
+ }
+
+ private Callbacks mCallbacks = sDummyCallbacks;
+ /**
+ * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity.
+ */
+ private static Callbacks sDummyCallbacks = new Callbacks() {
+ @Override
+ public void onContactSelected(CallContact c) {
+ }
+
+ @Override
+ public ISipService getService() {
+ Log.i(TAG, "Dummy");
+ return null;
+ }
+
+ @Override
+ public void onContactDragged() {
+ }
+
+ @Override
+ public void openDrawer() {
+ }
+
+ };
+
+ public interface Callbacks {
+ void onContactSelected(CallContact c);
+
+ public ISipService getService();
+
+ void onContactDragged();
+
+ void openDrawer();
+
+ }
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ if (!(activity instanceof Callbacks)) {
+ throw new IllegalStateException("Activity must implement fragment's callbacks.");
+ }
+
+ mCallbacks = (Callbacks) activity;
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ mCallbacks = sDummyCallbacks;
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ // In order to onCreateOptionsMenu be called
+ setHasOptionsMenu(true);
+ getLoaderManager().initLoader(LoaderConstants.CONTACT_LOADER, null, this);
+
+ }
+
+ ListView list;
+
+ private OnItemLongClickListener mItemLongClickListener = new OnItemLongClickListener() {
+ @Override
+ public boolean onItemLongClick(AdapterView<?> av, View view, int pos, long id) {
+ DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view.findViewById(R.id.photo));
+ view.startDrag(null, shadowBuilder, view, 0);
+ // view.setVisibility(View.INVISIBLE);
+ mCallbacks.onContactDragged();
+ // ((SearchView) mHandle.findViewById(R.id.contact_search_text)).setIconified(true);
+ return true;
+ }
+
+ };
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ View inflatedView = inflater.inflate(R.layout.frag_contact_list, container, false);
+ list = (ListView) inflatedView.findViewById(R.id.contacts_list);
+
+ list.setOnDragListener(dragListener);
+ list.setOnItemClickListener(new OnItemClickListener() {
+
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View v, int pos, long arg3) {
+ mCallbacks.onContactSelected(mListAdapter.getItem(pos - 1));
+ // ((SearchView) mHandle.findViewById(R.id.contact_search_text)).setIconified(true);
+
+ }
+ });
+ list.setOnItemLongClickListener(mItemLongClickListener);
+
+ list.setEmptyView(inflatedView.findViewById(R.id.empty_list_contact));
+ View header = inflater.inflate(R.layout.frag_contact_list_header, null);
+ list.addHeaderView(header, null, false);
+ TACGridView grid = (TACGridView) header.findViewById(R.id.favorites_grid);
+
+ list.setAdapter(mListAdapter);
+ grid.setAdapter(mGridAdapter);
+
+ list.setOnScrollListener(new OnScrollListener() {
+
+ @Override
+ public void onScrollStateChanged(AbsListView view, int scrollState) {
+ // TODO Stub de la méthode généré automatiquement
+
+ }
+
+ @Override
+ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
+ if (visibleItemCount > 0 && firstVisibleItem == 0 && view.getChildAt(0).getTop() == 0) {
+ // ListView scrolled at top
+
+ }
+
+ }
+ });
+ grid.setExpanded(true);
+
+ grid.setOnDragListener(dragListener);
+ grid.setOnItemClickListener(new OnItemClickListener() {
+
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View v, int pos, long arg3) {
+ // launchCallActivity(mGridAdapter.getItem(pos));
+ mCallbacks.onContactSelected(mGridAdapter.getItem(pos));
+ // ((SearchView) mHandle.findViewById(R.id.contact_search_text)).setIconified(true);
+ }
+ });
+ grid.setOnItemLongClickListener(mItemLongClickListener);
+
+ return inflatedView;
+ }
+
+ OnDragListener dragListener = new OnDragListener() {
+
+ @Override
+ public boolean onDrag(View v, DragEvent event) {
+ switch (event.getAction()) {
+ case DragEvent.ACTION_DRAG_STARTED:
+ // Do nothing
+ break;
+ case DragEvent.ACTION_DRAG_ENTERED:
+ break;
+ case DragEvent.ACTION_DRAG_EXITED:
+ // v.setBackgroundDrawable(null);
+ break;
+ case DragEvent.ACTION_DROP:
+ break;
+ case DragEvent.ACTION_DRAG_ENDED:
+ View view1 = (View) event.getLocalState();
+ view1.setVisibility(View.VISIBLE);
+ default:
+ break;
+ }
+ return true;
+ }
+
+ };
+
+ @Override
+ public boolean onQueryTextChange(String newText) {
+
+ // Called when the action bar search text has changed. Update
+ // the search filter, and restart the loader to do a new query
+ // with this filter.
+ // String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
+ // Don't do anything if the filter hasn't actually changed.
+ // Prefents restarting the loader when restoring state.
+ // if (mCurFilter == null && newFilter == null) {
+ // return true;
+ // }
+ // if (mCurFilter != null && mCurFilter.equals(newText)) {
+ // return true;
+ // }
+ if (newText.isEmpty()) {
+ getLoaderManager().restartLoader(LoaderConstants.CONTACT_LOADER, null, this);
+ return true;
+ }
+ mCurFilter = newText;
+ Bundle b = new Bundle();
+ b.putString("filter", mCurFilter);
+ getLoaderManager().restartLoader(LoaderConstants.CONTACT_LOADER, b, this);
+ return true;
+ }
+
+ @Override
+ public boolean onQueryTextSubmit(String query) {
+ // Return false to let the SearchView perform the default action
+ return false;
+ }
+
+ @Override
+ public Loader<Bundle> onCreateLoader(int id, Bundle args) {
+ Uri baseUri;
+
+ if (args != null) {
+ baseUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI, Uri.encode(args.getString("filter")));
+ } else {
+ baseUri = Contacts.CONTENT_URI;
+ }
+ ContactsLoader l = new ContactsLoader(getActivity(), baseUri);
+ l.forceLoad();
+ return l;
+ }
+
+ @Override
+ public void onLoadFinished(Loader<Bundle> loader, Bundle data) {
+
+ mListAdapter.removeAll();
+ mGridAdapter.removeAll();
+ ArrayList<CallContact> tmp = data.getParcelableArrayList("Contacts");
+ ArrayList<CallContact> tmp2 = data.getParcelableArrayList("Starred");
+
+ Log.w(TAG, "Contact stareed " + tmp2.size());
+ mListAdapter.addAll(tmp);
+ mGridAdapter.addAll(tmp2);
+
+ }
+
+ @Override
+ public void onLoaderReset(Loader<Bundle> loader) {
+ // Thi is called when the last Cursor provided to onLoadFinished
+ // mListAdapter.swapCursor(null);
+ }
+
+ public void setHandleView(RelativeLayout handle) {
+
+ ((ImageButton) handle.findViewById(R.id.contact_search_button)).setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+
+ SearchView search = new SearchView(getActivity());
+ // Get the ID for the search bar LinearLayout
+ int searchBarId = search.getContext().getResources().getIdentifier("android:id/search_bar", null, null);
+ // Get the search bar Linearlayout
+ LinearLayout searchBar = (LinearLayout) search.findViewById(searchBarId);
+ searchBar.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
+ LinearLayout.LayoutParams.WRAP_CONTENT));
+ // Give the Linearlayout a transition animation.
+ searchBar.setLayoutTransition(new LayoutTransition());
+ search.setOnQueryTextListener(ContactListFragment.this);
+ search.setIconified(false);
+ getActivity().getActionBar().setDisplayShowCustomEnabled(true);
+ getActivity().getActionBar().setCustomView(search);
+ mCallbacks.openDrawer();
+
+ }
+ });
+
+ }
+
+}
diff --git a/src/org/sflphone/fragments/DialingFragment.java b/src/org/sflphone/fragments/DialingFragment.java
new file mode 100644
index 0000000..9994e2a
--- /dev/null
+++ b/src/org/sflphone/fragments/DialingFragment.java
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
+ *
+ * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Additional permission under GNU GPL version 3 section 7:
+ *
+ * If you modify this program, or any covered work, by linking or
+ * combining it with the OpenSSL project's OpenSSL library (or a
+ * modified version of that library), containing parts covered by the
+ * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
+ * grants you additional permission to convey the resulting work.
+ * Corresponding Source for a non-source form of such a combination
+ * shall include the source code for the parts of OpenSSL used as well
+ * as that of the covered work.
+ */
+
+package org.sflphone.fragments;
+
+import java.util.Locale;
+
+import org.sflphone.R;
+import org.sflphone.service.ISipService;
+import org.sflphone.views.ClearableEditText;
+
+import android.app.Activity;
+import android.app.Fragment;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.RemoteException;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.LayoutInflater;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.View.OnTouchListener;
+import android.view.ViewGroup;
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.Button;
+import android.widget.ImageButton;
+
+public class DialingFragment extends Fragment implements OnTouchListener {
+
+ private static final String TAG = DialingFragment.class.getSimpleName();
+
+ ClearableEditText textField;
+ private Callbacks mCallbacks = sDummyCallbacks;
+
+ /**
+ * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity.
+ */
+ private static Callbacks sDummyCallbacks = new Callbacks() {
+ @Override
+ public void onCallDialed(String to) {
+ }
+
+ @Override
+ public ISipService getService() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+
+ /**
+ * The Activity calling this fragment has to implement this interface
+ *
+ */
+ public interface Callbacks {
+ void onCallDialed(String account);
+
+ public ISipService getService();
+
+ }
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+
+ if (!(activity instanceof Callbacks)) {
+ throw new IllegalStateException("Activity must implement fragment's callbacks.");
+ }
+
+ mCallbacks = (Callbacks) activity;
+
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ mCallbacks = sDummyCallbacks;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
+ View inflatedView = inflater.inflate(R.layout.frag_dialing, parent, false);
+
+ textField = (ClearableEditText) inflatedView.findViewById(R.id.textField);
+ ((ImageButton) inflatedView.findViewById(R.id.buttonCall)).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+
+ String to = textField.getText().toString();
+ if (to.contentEquals("")) {
+ textField.setError(getString(R.string.dial_error_no_number_dialed));
+ } else {
+ mCallbacks.onCallDialed(to);
+ }
+ }
+ });
+
+ inflatedView.setOnTouchListener(this);
+
+ ((Button) inflatedView.findViewById(R.id.alphabetic_keyboard)).setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ textField.setInputType(EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
+ InputMethodManager lManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
+ lManager.showSoftInput(textField.getEdit_text(), 0);
+ }
+ });
+
+ ((Button) inflatedView.findViewById(R.id.numeric_keyboard)).setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ textField.setInputType(EditorInfo.TYPE_CLASS_PHONE);
+ InputMethodManager lManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
+ lManager.showSoftInput(textField.getEdit_text(), 0);
+ }
+ });
+ return inflatedView;
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ textField.setTextWatcher(dtmfKeyListener);
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ textField.unsetTextWatcher();
+ }
+
+ TextWatcher dtmfKeyListener = new TextWatcher() {
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ }
+
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ if (count - before > 1 || count == 0)
+ return; // pasted a number (not implemented yet)
+
+ try {
+ String toSend = Character.toString(s.charAt(start));
+ toSend.toUpperCase(Locale.getDefault());
+ mCallbacks.getService().playDtmf(toSend);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+ };
+
+ @Override
+ public void onStart() {
+ super.onStart();
+ }
+
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ InputMethodManager lManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
+ textField.setError(null);
+ lManager.hideSoftInputFromWindow(textField.getWindowToken(), 0);
+ return false;
+ }
+
+}
diff --git a/src/org/sflphone/fragments/HelpGesturesFragment.java b/src/org/sflphone/fragments/HelpGesturesFragment.java
new file mode 100644
index 0000000..81977be
--- /dev/null
+++ b/src/org/sflphone/fragments/HelpGesturesFragment.java
@@ -0,0 +1,20 @@
+package org.sflphone.fragments;
+
+import org.sflphone.R;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class HelpGesturesFragment extends Fragment {
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
+ View inflatedView = inflater.inflate(R.layout.frag_gestures, parent, false);
+
+ return inflatedView;
+ }
+
+}
diff --git a/src/org/sflphone/fragments/HistoryFragment.java b/src/org/sflphone/fragments/HistoryFragment.java
new file mode 100644
index 0000000..0602859
--- /dev/null
+++ b/src/org/sflphone/fragments/HistoryFragment.java
@@ -0,0 +1,301 @@
+/*
+ * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
+ *
+ * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Additional permission under GNU GPL version 3 section 7:
+ *
+ * If you modify this program, or any covered work, by linking or
+ * combining it with the OpenSSL project's OpenSSL library (or a
+ * modified version of that library), containing parts covered by the
+ * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
+ * grants you additional permission to convey the resulting work.
+ * Corresponding Source for a non-source form of such a combination
+ * shall include the source code for the parts of OpenSSL used as well
+ * as that of the covered work.
+ */
+package org.sflphone.fragments;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.sflphone.R;
+import org.sflphone.adapters.ContactPictureTask;
+import org.sflphone.loaders.HistoryLoader;
+import org.sflphone.loaders.LoaderConstants;
+import org.sflphone.model.HistoryEntry;
+import org.sflphone.service.ISipService;
+
+import android.app.Activity;
+import android.app.ListFragment;
+import android.app.LoaderManager.LoaderCallbacks;
+import android.content.Loader;
+import android.os.Bundle;
+import android.os.RemoteException;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.BaseAdapter;
+import android.widget.Button;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.ListView;
+import android.widget.TextView;
+
+public class HistoryFragment extends ListFragment implements LoaderCallbacks<ArrayList<HistoryEntry>> {
+
+ private static final String TAG = HistoryFragment.class.getSimpleName();
+
+ HistoryAdapter mAdapter;
+ private Callbacks mCallbacks = sDummyCallbacks;
+ /**
+ * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity.
+ */
+ private static Callbacks sDummyCallbacks = new Callbacks() {
+ @Override
+ public void onCallDialed(String to) {
+ }
+
+ @Override
+ public ISipService getService() {
+ Log.i(TAG, "Dummy");
+ return null;
+ }
+
+ };
+
+ public interface Callbacks {
+ public void onCallDialed(String to);
+
+ public ISipService getService();
+
+ }
+
+ @Override
+ public void onAttach(Activity activity) {
+ Log.i(TAG, "Attaching HISTORY");
+ super.onAttach(activity);
+
+ if (!(activity instanceof Callbacks)) {
+ throw new IllegalStateException("Activity must implement fragment's callbacks.");
+ }
+
+ mCallbacks = (Callbacks) activity;
+ getLoaderManager().initLoader(LoaderConstants.HISTORY_LOADER, null, this);
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ mCallbacks = sDummyCallbacks;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
+ View inflatedView = inflater.inflate(R.layout.frag_history, parent, false);
+
+ ((ListView) inflatedView.findViewById(android.R.id.list)).setOnItemClickListener(new OnItemClickListener() {
+
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
+ mAdapter.getItem(pos);
+ }
+ });
+ return inflatedView;
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+ Log.w(TAG, "onStart");
+ getLoaderManager().restartLoader(LoaderConstants.HISTORY_LOADER, null, this);
+ }
+
+ public void makeNewCall(int position) {
+ mCallbacks.onCallDialed(mAdapter.getItem(position).getNumber());
+ }
+
+ @Override
+ public Loader<ArrayList<HistoryEntry>> onCreateLoader(int id, Bundle args) {
+
+ HistoryLoader loader = new HistoryLoader(getActivity(), mCallbacks.getService());
+ loader.forceLoad();
+ return loader;
+
+ }
+
+ @Override
+ public void onLoadFinished(Loader<ArrayList<HistoryEntry>> arg0, ArrayList<HistoryEntry> history) {
+ mAdapter = new HistoryAdapter(this, history);
+ getListView().setAdapter(mAdapter);
+ mAdapter.notifyDataSetChanged();
+
+ }
+
+ @Override
+ public void onLoaderReset(Loader<ArrayList<HistoryEntry>> arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public class HistoryAdapter extends BaseAdapter {
+
+ HistoryFragment mContext;
+ ArrayList<HistoryEntry> dataset;
+ private ExecutorService infos_fetcher = Executors.newCachedThreadPool();
+
+ public HistoryAdapter(HistoryFragment activity, ArrayList<HistoryEntry> history) {
+ mContext = activity;
+ dataset = history;
+ }
+
+ @Override
+ public View getView(final int pos, View convertView, ViewGroup arg2) {
+ View rowView = convertView;
+ HistoryView entryView = null;
+
+ if (rowView == null) {
+ // Get a new instance of the row layout view
+ LayoutInflater inflater = LayoutInflater.from(mContext.getActivity());
+ rowView = inflater.inflate(R.layout.item_history, null);
+
+ // Hold the view objects in an object
+ // so they don't need to be re-fetched
+ entryView = new HistoryView();
+ entryView.photo = (ImageView) rowView.findViewById(R.id.photo);
+ entryView.displayName = (TextView) rowView.findViewById(R.id.display_name);
+ entryView.duration = (TextView) rowView.findViewById(R.id.duration);
+ entryView.date = (TextView) rowView.findViewById(R.id.date_start);
+ entryView.missed = (TextView) rowView.findViewById(R.id.missed);
+ entryView.incoming = (TextView) rowView.findViewById(R.id.incomings);
+ entryView.outgoing = (TextView) rowView.findViewById(R.id.outgoings);
+ entryView.replay = (Button) rowView.findViewById(R.id.replay);
+ entryView.call_button = (ImageButton) rowView.findViewById(R.id.action_call);
+ entryView.call_button.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ mContext.makeNewCall(pos);
+
+ }
+ });
+ rowView.setTag(entryView);
+ } else {
+ entryView = (HistoryView) rowView.getTag();
+ }
+
+ // Transfer the stock data from the data object
+ // to the view objects
+
+ // SipCall call = (SipCall) mCallList.values().toArray()[position];
+ entryView.displayName.setText(dataset.get(pos).getContact().getmDisplayName());
+
+ infos_fetcher.execute(new ContactPictureTask(mContext.getActivity(), entryView.photo, dataset.get(pos).getContact().getId()));
+
+
+ entryView.missed.setText(getString(R.string.hist_missed_calls, dataset.get(pos).getMissed_sum()));
+ entryView.incoming.setText(getString(R.string.hist_in_calls, dataset.get(pos).getIncoming_sum()));
+ entryView.outgoing.setText(getString(R.string.hist_out_calls, dataset.get(pos).getOutgoing_sum()));
+
+ if (dataset.get(pos).getCalls().lastEntry().getValue().getRecordPath().length() > 0) {
+ entryView.replay.setVisibility(View.VISIBLE);
+ entryView.replay.setTag(R.id.replay, true);
+ entryView.replay.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ try {
+ if ((Boolean) v.getTag(R.id.replay)) {
+ mCallbacks.getService().startRecordedFilePlayback(dataset.get(pos).getCalls().lastEntry().getValue().getRecordPath());
+ v.setTag(R.id.replay, false);
+ ((Button)v).setText(getString(R.string.hist_replay_button_stop));
+ } else {
+ mCallbacks.getService().stopRecordedFilePlayback(dataset.get(pos).getCalls().lastEntry().getValue().getRecordPath());
+ v.setTag(R.id.replay, true);
+ ((Button)v).setText(getString(R.string.hist_replay_button));
+ }
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+
+ entryView.date.setText(dataset.get(pos).getCalls().lastEntry().getValue().getDate("hh:mm dd/MM/yyyy"));
+ entryView.duration.setText(dataset.get(pos).getTotalDuration());
+
+ return rowView;
+
+ }
+
+ /*********************
+ * ViewHolder Pattern
+ *********************/
+ public class HistoryView {
+ public ImageView photo;
+ protected TextView displayName;
+ protected TextView date;
+ public TextView duration;
+ private ImageButton call_button;
+ private Button replay;
+ private TextView missed;
+ private TextView outgoing;
+ private TextView incoming;
+ }
+
+ @Override
+ public int getCount() {
+
+ return dataset.size();
+ }
+
+ @Override
+ public HistoryEntry getItem(int pos) {
+ return dataset.get(pos);
+ }
+
+ @Override
+ public long getItemId(int arg0) {
+ return 0;
+ }
+
+ public void clear() {
+ dataset.clear();
+
+ }
+
+ public void addAll(ArrayList<HashMap<String, String>> history) {
+ // dataset.addAll(history);
+
+ }
+
+ }
+
+}
diff --git a/src/org/sflphone/fragments/HomeFragment.java b/src/org/sflphone/fragments/HomeFragment.java
new file mode 100644
index 0000000..3a87805
--- /dev/null
+++ b/src/org/sflphone/fragments/HomeFragment.java
@@ -0,0 +1,491 @@
+/*
+ * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
+ *
+ * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Additional permission under GNU GPL version 3 section 7:
+ *
+ * If you modify this program, or any covered work, by linking or
+ * combining it with the OpenSSL project's OpenSSL library (or a
+ * modified version of that library), containing parts covered by the
+ * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
+ * grants you additional permission to convey the resulting work.
+ * Corresponding Source for a non-source form of such a combination
+ * shall include the source code for the parts of OpenSSL used as well
+ * as that of the covered work.
+ */
+package org.sflphone.fragments;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Observable;
+import java.util.Observer;
+
+import org.sflphone.R;
+import org.sflphone.fragments.CallListFragment.DropActionsChoice;
+import org.sflphone.model.CallTimer;
+import org.sflphone.model.Conference;
+import org.sflphone.model.SipCall;
+import org.sflphone.service.ISipService;
+
+import android.app.Activity;
+import android.app.Fragment;
+import android.content.ClipData;
+import android.content.ClipData.Item;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.Color;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.os.Vibrator;
+import android.util.Log;
+import android.view.DragEvent;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.View;
+import android.view.View.DragShadowBuilder;
+import android.view.View.OnDragListener;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.AdapterView.OnItemLongClickListener;
+import android.widget.BaseAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+public class HomeFragment extends Fragment {
+ private static final String TAG = HomeFragment.class.getSimpleName();
+
+ private Callbacks mCallbacks = sDummyCallbacks;
+ private TextView nb_calls, nb_confs;
+ CallListAdapter confs_adapter, calls_adapter;
+ CallTimer timer;
+
+ public static final int REQUEST_TRANSFER = 10;
+ public static final int REQUEST_CONF = 20;
+
+ /**
+ * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity.
+ */
+ private static Callbacks sDummyCallbacks = new Callbacks() {
+
+ @Override
+ public ISipService getService() {
+ Log.i(TAG, "I'm a dummy");
+ return null;
+ }
+
+ @Override
+ public void selectedCall(Conference c) {
+ }
+ };
+
+ /**
+ * The Activity calling this fragment has to implement this interface
+ *
+ */
+ public interface Callbacks {
+
+ public ISipService getService();
+
+ public void selectedCall(Conference c);
+
+ }
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+
+ if (!(activity instanceof Callbacks)) {
+ throw new IllegalStateException("Activity must implement fragment's callbacks.");
+ }
+
+ mCallbacks = (Callbacks) activity;
+
+ }
+
+ private Runnable mUpdateTimeTask = new Runnable() {
+ public void run() {
+ final long start = SystemClock.uptimeMillis();
+ long millis = SystemClock.uptimeMillis() - start;
+ int seconds = (int) (millis / 1000);
+ int minutes = seconds / 60;
+ seconds = seconds % 60;
+
+ calls_adapter.notifyDataSetChanged();
+ confs_adapter.notifyDataSetChanged();
+ mHandler.postAtTime(this, start + (((minutes * 60) + seconds + 1) * 1000));
+ }
+ };
+
+ private Handler mHandler = new Handler();
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ if (mCallbacks.getService() != null) {
+ try {
+ updateLists();
+ if (!calls_adapter.isEmpty() || !confs_adapter.isEmpty()) {
+ mHandler.postDelayed(mUpdateTimeTask, 0);
+ }
+
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ // No proper solution with HashMap runtime cast
+ public void updateLists() throws RemoteException {
+ HashMap<String, SipCall> calls = (HashMap<String, SipCall>) mCallbacks.getService().getCallList();
+ HashMap<String, Conference> confs = (HashMap<String, Conference>) mCallbacks.getService().getConferenceList();
+
+ updateCallList(calls);
+ updateConferenceList(confs);
+ }
+
+ private void updateConferenceList(HashMap<String, Conference> confs) {
+ nb_confs.setText("" + confs.size());
+ confs_adapter.updateDataset(new ArrayList<Conference>(confs.values()));
+ }
+
+ private void updateCallList(HashMap<String, SipCall> calls) {
+ nb_calls.setText("" + calls.size());
+ ArrayList<Conference> conferences = new ArrayList<Conference>();
+ for (SipCall call : calls.values()) {
+ Conference confOne = new Conference("-1");
+ confOne.getParticipants().add(call);
+ conferences.add(confOne);
+ }
+
+ calls_adapter.updateDataset(conferences);
+
+ }
+
+ @Override
+ public void onDetach() {
+
+ super.onDetach();
+ mCallbacks = sDummyCallbacks;
+
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ mHandler.removeCallbacks(mUpdateTimeTask);
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+
+ super.onActivityCreated(savedInstanceState);
+
+ // Give some text to display if there is no data. In a real
+ // application this would come from a resource.
+ // setEmptyText("No phone numbers");
+
+ // We have a menu item to show in action bar.
+ setHasOptionsMenu(true);
+
+ }
+
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+
+ inflater.inflate(R.menu.call_element_menu, menu);
+
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ Log.i(TAG, "onCreateView");
+ View inflatedView = inflater.inflate(R.layout.frag_home, container, false);
+
+ nb_calls = (TextView) inflatedView.findViewById(R.id.calls_counter);
+ nb_confs = (TextView) inflatedView.findViewById(R.id.confs_counter);
+
+ confs_adapter = new CallListAdapter(getActivity());
+ ((ListView) inflatedView.findViewById(R.id.confs_list)).setAdapter(confs_adapter);
+
+ calls_adapter = new CallListAdapter(getActivity());
+ ((ListView) inflatedView.findViewById(R.id.calls_list)).setAdapter(calls_adapter);
+ ((ListView) inflatedView.findViewById(R.id.calls_list)).setOnItemClickListener(callClickListener);
+ ((ListView) inflatedView.findViewById(R.id.confs_list)).setOnItemClickListener(callClickListener);
+
+ ((ListView) inflatedView.findViewById(R.id.calls_list)).setOnItemLongClickListener(mItemLongClickListener);
+ ((ListView) inflatedView.findViewById(R.id.confs_list)).setOnItemLongClickListener(mItemLongClickListener);
+
+ return inflatedView;
+ }
+
+ OnItemClickListener callClickListener = new OnItemClickListener() {
+
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) {
+ mCallbacks.selectedCall((Conference) v.getTag());
+ }
+ };
+
+ private OnItemLongClickListener mItemLongClickListener = new OnItemLongClickListener() {
+
+ @Override
+ public boolean onItemLongClick(AdapterView<?> adptv, View view, int pos, long arg3) {
+ final Vibrator vibe = (Vibrator) view.getContext().getSystemService(Context.VIBRATOR_SERVICE);
+ vibe.vibrate(80);
+ Intent i = new Intent();
+ Bundle b = new Bundle();
+ b.putParcelable("conference", (Conference) adptv.getAdapter().getItem(pos));
+ i.putExtra("bconference", b);
+
+ DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
+ ClipData data = ClipData.newIntent("conference", i);
+ view.startDrag(data, shadowBuilder, view, 0);
+ return false;
+ }
+
+ };
+
+ public class CallListAdapter extends BaseAdapter implements Observer {
+
+ private ArrayList<Conference> calls;
+
+ private Context mContext;
+
+ public CallListAdapter(Context act) {
+ super();
+ mContext = act;
+ calls = new ArrayList<Conference>();
+
+ }
+
+ public ArrayList<Conference> getDataset() {
+ return calls;
+ }
+
+ public void remove(Conference transfer) {
+
+ }
+
+ public void updateDataset(ArrayList<Conference> list) {
+ calls.clear();
+ calls.addAll(list);
+ notifyDataSetChanged();
+ }
+
+ @Override
+ public int getCount() {
+ return calls.size();
+ }
+
+ @Override
+ public Conference getItem(int position) {
+ return calls.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return 0;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ if (convertView == null)
+ convertView = LayoutInflater.from(mContext).inflate(R.layout.item_calllist, null);
+
+ Conference call = calls.get(position);
+ if (call.getParticipants().size() == 1) {
+ ((TextView) convertView.findViewById(R.id.call_title)).setText(call.getParticipants().get(0).getContact().getmDisplayName());
+
+ long duration = System.currentTimeMillis() / 1000 - (call.getParticipants().get(0).getTimestamp_start());
+
+ ((TextView) convertView.findViewById(R.id.call_time)).setText(String.format("%d:%02d:%02d", duration / 3600, (duration % 3600) / 60,
+ (duration % 60)));
+ } else {
+// String tmp = "Conference with " + call.getParticipants().size() + " participants";
+ ((TextView) convertView.findViewById(R.id.call_title)).setText(getString(R.string.home_conf_item, call.getParticipants().size()));
+ }
+ // ((TextView) convertView.findViewById(R.id.num_participants)).setText("" + call.getParticipants().size());
+ ((TextView) convertView.findViewById(R.id.call_status)).setText(call.getState());
+
+ convertView.setOnDragListener(dragListener);
+ convertView.setTag(call);
+
+ return convertView;
+ }
+
+ @Override
+ public void update(Observable observable, Object data) {
+ Log.i(TAG, "Updating views...");
+ notifyDataSetChanged();
+ }
+
+ }
+
+ OnDragListener dragListener = new OnDragListener() {
+
+ @SuppressWarnings("deprecation")
+ // deprecated in API 16....
+ @Override
+ public boolean onDrag(View v, DragEvent event) {
+ switch (event.getAction()) {
+ case DragEvent.ACTION_DRAG_STARTED:
+ // Do nothing
+ // Log.w(TAG, "ACTION_DRAG_STARTED");
+ break;
+ case DragEvent.ACTION_DRAG_ENTERED:
+ // Log.w(TAG, "ACTION_DRAG_ENTERED");
+ v.setBackgroundColor(Color.GREEN);
+ break;
+ case DragEvent.ACTION_DRAG_EXITED:
+ // Log.w(TAG, "ACTION_DRAG_EXITED");
+ v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_call_selector));
+ break;
+ case DragEvent.ACTION_DROP:
+ // Log.w(TAG, "ACTION_DROP");
+ View view = (View) event.getLocalState();
+
+ Item i = event.getClipData().getItemAt(0);
+ Intent intent = i.getIntent();
+ intent.setExtrasClassLoader(Conference.class.getClassLoader());
+
+ Conference initial = (Conference) view.getTag();
+ Conference target = (Conference) v.getTag();
+
+ if (initial == target) {
+ return true;
+ }
+
+ DropActionsChoice dialog = DropActionsChoice.newInstance();
+ Bundle b = new Bundle();
+ b.putParcelable("call_initial", initial);
+ b.putParcelable("call_targeted", target);
+ dialog.setArguments(b);
+ dialog.setTargetFragment(HomeFragment.this, 0);
+ dialog.show(getFragmentManager(), "dialog");
+
+ // view.setBackgroundColor(Color.WHITE);
+ // v.setBackgroundColor(Color.BLACK);
+ break;
+ case DragEvent.ACTION_DRAG_ENDED:
+ // Log.w(TAG, "ACTION_DRAG_ENDED");
+ View view1 = (View) event.getLocalState();
+ view1.setVisibility(View.VISIBLE);
+ v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_call_selector));
+ default:
+ break;
+ }
+ return true;
+ }
+
+ };
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ Conference transfer = null;
+ if (requestCode == REQUEST_TRANSFER) {
+ switch (resultCode) {
+ case 0:
+ Conference c = data.getParcelableExtra("target");
+ transfer = data.getParcelableExtra("transfer");
+ try {
+
+ mCallbacks.getService().attendedTransfer(transfer.getParticipants().get(0).getCallId(), c.getParticipants().get(0).getCallId());
+ calls_adapter.remove(transfer);
+ calls_adapter.remove(c);
+ calls_adapter.notifyDataSetChanged();
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Toast.makeText(getActivity(), getString(R.string.home_transfer_complet), Toast.LENGTH_LONG).show();
+ break;
+
+ case 1:
+ String to = data.getStringExtra("to_number");
+ transfer = data.getParcelableExtra("transfer");
+ try {
+ Toast.makeText(getActivity(), getString(R.string.home_transfering,transfer.getParticipants().get(0).getContact().getmDisplayName(),to),
+ Toast.LENGTH_SHORT).show();
+ mCallbacks.getService().transfer(transfer.getParticipants().get(0).getCallId(), to);
+ mCallbacks.getService().hangUp(transfer.getParticipants().get(0).getCallId());
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ break;
+
+ default:
+ break;
+ }
+ } else if (requestCode == REQUEST_CONF) {
+ switch (resultCode) {
+ case 0:
+ Conference call_to_add = data.getParcelableExtra("transfer");
+ Conference call_target = data.getParcelableExtra("target");
+
+ bindCalls(call_to_add, call_target);
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+
+ private void bindCalls(Conference call_to_add, Conference call_target) {
+ try {
+
+ if (call_target.hasMultipleParticipants() && !call_to_add.hasMultipleParticipants()) {
+
+ mCallbacks.getService().addParticipant(call_to_add.getParticipants().get(0), call_target.getId());
+
+ } else if (call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) {
+
+ // We join two conferences
+ mCallbacks.getService().joinConference(call_to_add.getId(), call_target.getId());
+
+ } else if (!call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) {
+
+ mCallbacks.getService().addParticipant(call_target.getParticipants().get(0), call_to_add.getId());
+
+ } else {
+ // We join two single calls to create a conf
+ mCallbacks.getService().joinParticipant(call_to_add.getParticipants().get(0).getCallId(),
+ call_target.getParticipants().get(0).getCallId());
+ }
+
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/org/sflphone/fragments/MenuFragment.java b/src/org/sflphone/fragments/MenuFragment.java
new file mode 100644
index 0000000..49e8179
--- /dev/null
+++ b/src/org/sflphone/fragments/MenuFragment.java
@@ -0,0 +1,286 @@
+/*
+ * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
+ *
+ * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Additional permission under GNU GPL version 3 section 7:
+ *
+ * If you modify this program, or any covered work, by linking or
+ * combining it with the OpenSSL project's OpenSSL library (or a
+ * modified version of that library), containing parts covered by the
+ * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
+ * grants you additional permission to convey the resulting work.
+ * Corresponding Source for a non-source form of such a combination
+ * shall include the source code for the parts of OpenSSL used as well
+ * as that of the covered work.
+ */
+package org.sflphone.fragments;
+
+import java.util.ArrayList;
+
+import org.sflphone.R;
+import org.sflphone.adapters.AccountSelectionAdapter;
+import org.sflphone.adapters.MenuAdapter;
+import org.sflphone.client.ActivityHolder;
+import org.sflphone.client.SFLPhoneHomeActivity;
+import org.sflphone.client.SFLPhonePreferenceActivity;
+import org.sflphone.interfaces.AccountsInterface;
+import org.sflphone.loaders.AccountsLoader;
+import org.sflphone.loaders.LoaderConstants;
+import org.sflphone.model.Account;
+import org.sflphone.receivers.AccountsReceiver;
+import org.sflphone.service.ConfigurationManagerCallback;
+import org.sflphone.service.ISipService;
+
+import android.app.Activity;
+import android.app.Fragment;
+import android.app.LoaderManager.LoaderCallbacks;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.Loader;
+import android.os.Bundle;
+import android.provider.ContactsContract.Profile;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.AdapterView.OnItemSelectedListener;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+import android.widget.RadioButton;
+import android.widget.Spinner;
+
+public class MenuFragment extends Fragment implements LoaderCallbacks<ArrayList<Account>>, AccountsInterface {
+
+ private static final String TAG = MenuFragment.class.getSimpleName();
+ public static final String ARG_SECTION_NUMBER = "section_number";
+
+ MenuAdapter mAdapter;
+ String[] mProjection = new String[] { Profile._ID, Profile.DISPLAY_NAME_PRIMARY, Profile.LOOKUP_KEY, Profile.PHOTO_THUMBNAIL_URI };
+ AccountSelectionAdapter mAccountAdapter;
+ private Spinner spinnerAccounts;
+ AccountsReceiver accountReceiver;
+ private Callbacks mCallbacks = sDummyCallbacks;
+
+ /**
+ * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity.
+ */
+ private static Callbacks sDummyCallbacks = new Callbacks() {
+
+ @Override
+ public ISipService getService() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+
+ /**
+ * The Activity calling this fragment has to implement this interface
+ *
+ */
+ public interface Callbacks {
+
+ public ISipService getService();
+
+ }
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ if (!(activity instanceof Callbacks)) {
+ throw new IllegalStateException("Activity must implement fragment's callbacks.");
+ }
+
+ mCallbacks = (Callbacks) activity;
+ getLoaderManager().initLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
+
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ mAdapter = new MenuAdapter(getActivity());
+ accountReceiver = new AccountsReceiver(this);
+
+ String[] categories = getResources().getStringArray(R.array.menu_categories);
+ ArrayAdapter<String> paramAdapter = new ArrayAdapter<String>(getActivity(), R.layout.item_menu, getResources().getStringArray(
+ R.array.menu_items_param));
+ ArrayAdapter<String> helpAdapter = new ArrayAdapter<String>(getActivity(), R.layout.item_menu, getResources().getStringArray(
+ R.array.menu_items_help));
+
+ // Add Sections
+ mAdapter.addSection(categories[0], paramAdapter);
+ mAdapter.addSection(categories[1], helpAdapter);
+
+ }
+
+ public void onResume() {
+ super.onResume();
+
+ IntentFilter intentFilter2 = new IntentFilter();
+ intentFilter2.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED);
+ intentFilter2.addAction(ConfigurationManagerCallback.ACCOUNTS_CHANGED);
+ getActivity().registerReceiver(accountReceiver, intentFilter2);
+
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ getActivity().unregisterReceiver(accountReceiver);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
+ View inflatedView = inflater.inflate(R.layout.frag_menu, parent, false);
+
+ ((ListView) inflatedView.findViewById(R.id.listView)).setAdapter(mAdapter);
+ ((ListView) inflatedView.findViewById(R.id.listView)).setOnItemClickListener(new OnItemClickListener() {
+
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
+
+ Intent in = new Intent();
+ switch (pos) {
+ case 1:
+ in.setClass(getActivity(), SFLPhonePreferenceActivity.class);
+ getActivity().startActivityForResult(in, SFLPhoneHomeActivity.REQUEST_CODE_PREFERENCES);
+ break;
+// case 3:
+// in.putExtra("ActivityHolder.args", ActivityHolder.args.FRAG_GESTURES);
+// in.setClass(getActivity(), ActivityHolder.class);
+// getActivity().startActivity(in);
+// break;
+ case 3:
+ in.putExtra("ActivityHolder.args", ActivityHolder.args.FRAG_ABOUT);
+ in.setClass(getActivity(), ActivityHolder.class);
+ getActivity().startActivity(in);
+ break;
+ }
+ }
+ });
+
+ spinnerAccounts = (Spinner) inflatedView.findViewById(R.id.account_selection);
+ mAccountAdapter = new AccountSelectionAdapter(getActivity(), new ArrayList<Account>());
+ spinnerAccounts.setAdapter(mAccountAdapter);
+ spinnerAccounts.setOnItemSelectedListener(new OnItemSelectedListener() {
+
+ @Override
+ public void onItemSelected(AdapterView<?> arg0, View view, int pos, long arg3) {
+ // public void onClick(DialogInterface dialog, int which) {
+
+ Log.i(TAG, "Selected Account: " + mAdapter.getItem(pos));
+ if (null != view) {
+ ((RadioButton) view.findViewById(R.id.account_checked)).toggle();
+ }
+ mAccountAdapter.setSelectedAccount(pos);
+ // accountSelectedNotifyAccountList(mAdapter.getItem(pos));
+ // setSelection(cursor.getPosition(),true);
+
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> arg0) {
+ mAccountAdapter.setSelectedAccount(-1);
+ }
+ });
+
+ // Cursor mProfileCursor = getActivity().getContentResolver().query(Profile.CONTENT_URI, mProjection, null, null, null);
+ //
+ // if (mProfileCursor.getCount() > 0) {
+ // mProfileCursor.moveToFirst();
+ // String photo_uri = mProfileCursor.getString(mProfileCursor.getColumnIndex(Profile.PHOTO_THUMBNAIL_URI));
+ // if (photo_uri != null) {
+ // ((ImageView) inflatedView.findViewById(R.id.user_photo)).setImageURI(Uri.parse(photo_uri));
+ // }
+ // ((TextView) inflatedView.findViewById(R.id.user_name)).setText(mProfileCursor.getString(mProfileCursor
+ // .getColumnIndex(Profile.DISPLAY_NAME_PRIMARY)));
+ // mProfileCursor.close();
+ // }
+ return inflatedView;
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+
+ }
+
+ public Account getSelectedAccount() {
+ return mAccountAdapter.getSelectedAccount();
+ }
+
+ @Override
+ public Loader<ArrayList<Account>> onCreateLoader(int id, Bundle args) {
+ AccountsLoader l = new AccountsLoader(getActivity(), mCallbacks.getService());
+ l.forceLoad();
+ return l;
+ }
+
+ @Override
+ public void onLoadFinished(Loader<ArrayList<Account>> loader, ArrayList<Account> results) {
+ mAccountAdapter.removeAll();
+ mAccountAdapter.addAll(results);
+
+ }
+
+ @Override
+ public void onLoaderReset(Loader<ArrayList<Account>> arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * Called by activity to pass a reference to sipservice to Fragment.
+ *
+ * @param isip
+ */
+ public void onServiceSipBinded(ISipService isip) {
+
+ }
+
+ public void updateAllAccounts() {
+ if (getActivity() != null)
+ getActivity().getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
+ }
+
+ public void updateAccount(Intent accountState) {
+ if (mAccountAdapter != null)
+ mAccountAdapter.updateAccount(accountState);
+ }
+
+ @Override
+ public void accountsChanged() {
+ updateAllAccounts();
+
+ }
+
+ @Override
+ public void accountStateChanged(Intent accountState) {
+ updateAccount(accountState);
+
+ }
+
+}
diff --git a/src/org/sflphone/fragments/TransferDFragment.java b/src/org/sflphone/fragments/TransferDFragment.java
new file mode 100644
index 0000000..a9e73c4
--- /dev/null
+++ b/src/org/sflphone/fragments/TransferDFragment.java
@@ -0,0 +1,303 @@
+/*
+ * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
+ *
+ * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Additional permission under GNU GPL version 3 section 7:
+ *
+ * If you modify this program, or any covered work, by linking or
+ * combining it with the OpenSSL project's OpenSSL library (or a
+ * modified version of that library), containing parts covered by the
+ * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
+ * grants you additional permission to convey the resulting work.
+ * Corresponding Source for a non-source form of such a combination
+ * shall include the source code for the parts of OpenSSL used as well
+ * as that of the covered work.
+ */
+
+package org.sflphone.fragments;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.sflphone.R;
+import org.sflphone.loaders.ContactsLoader;
+import org.sflphone.model.Conference;
+import org.sflphone.model.SipCall;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.app.LoaderManager;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnShowListener;
+import android.content.Intent;
+import android.content.Loader;
+import android.location.Address;
+import android.location.Geocoder;
+import android.net.Uri;
+import android.os.Bundle;
+import android.provider.ContactsContract.Contacts;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ArrayAdapter;
+import android.widget.AutoCompleteTextView;
+import android.widget.BaseAdapter;
+import android.widget.Button;
+import android.widget.Filter;
+import android.widget.Filterable;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+public class TransferDFragment extends DialogFragment implements LoaderManager.LoaderCallbacks<Bundle> {
+ public static final int RESULT_TRANSFER_CONF = Activity.RESULT_FIRST_USER + 1;
+ public static final int RESULT_TRANSFER_NUMBER = Activity.RESULT_FIRST_USER + 2;
+
+ private AutoCompleteTextView mEditText;
+ private AutoCompleteAdapter autoCompleteAdapter;
+ SimpleCallListAdapter mAdapter;
+
+ /**
+ * Create a new instance of CallActionsDFragment
+ */
+ static TransferDFragment newInstance() {
+ TransferDFragment f = new TransferDFragment();
+ return f;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // Pick a style based on the num.
+ int style = DialogFragment.STYLE_NORMAL, theme = 0;
+ setStyle(style, theme);
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ View rootView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_transfer, null);
+
+ ArrayList<Conference> calls = getArguments().getParcelableArrayList("calls");
+ final SipCall call_selected = getArguments().getParcelable("call_selected");
+
+ mAdapter = new SimpleCallListAdapter(getActivity(), calls);
+ ListView list = (ListView) rootView.findViewById(R.id.concurrent_calls);
+ list.setAdapter(mAdapter);
+ list.setOnItemClickListener(new OnItemClickListener() {
+
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
+
+ Intent in = new Intent();
+ in.putExtra("target", mAdapter.getItem(pos));
+ in.putExtra("transfer", call_selected);
+
+ getTargetFragment().onActivityResult(getTargetRequestCode(), RESULT_TRANSFER_CONF, in);
+ dismiss();
+ }
+ });
+ list.setEmptyView(rootView.findViewById(R.id.empty_view));
+
+ mEditText = (AutoCompleteTextView) rootView.findViewById(R.id.external_number);
+ mEditText.setAdapter(autoCompleteAdapter);
+
+ final AlertDialog a = new AlertDialog.Builder(getActivity()).setView(rootView)
+ .setTitle("Transfer " + call_selected.getContact().getmDisplayName())
+ .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int whichButton) {
+
+ }
+ }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int whichButton) {
+ getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_CANCELED, new Intent());
+ dismiss();
+ }
+ }).create();
+
+ a.setOnShowListener(new OnShowListener() {
+
+ @Override
+ public void onShow(DialogInterface dialog) {
+ Button b = a.getButton(AlertDialog.BUTTON_POSITIVE);
+ b.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View view) {
+ if(mEditText.getText().length() == 0){
+ Toast.makeText(getActivity(), "Enter a number to transfer this call", Toast.LENGTH_SHORT).show();
+ } else {
+ Intent in = new Intent();
+ in.putExtra("to_number", mEditText.getText().toString());
+ in.putExtra("transfer", call_selected);
+ getTargetFragment().onActivityResult(getTargetRequestCode(), RESULT_TRANSFER_NUMBER, in);
+ dismiss();
+ }
+ }
+ });
+
+ }
+ });
+ return a;
+ }
+
+ @Override
+ public Loader<Bundle> onCreateLoader(int id, Bundle args) {
+ Uri baseUri;
+
+ if (args != null) {
+ baseUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI, Uri.encode(args.getString("filter")));
+ } else {
+ baseUri = Contacts.CONTENT_URI;
+ }
+ ContactsLoader l = new ContactsLoader(getActivity(), baseUri);
+ l.forceLoad();
+ return l;
+ }
+
+ @Override
+ public void onLoadFinished(Loader<Bundle> loader, Bundle data) {
+
+// ArrayList<CallContact> tmp = data.getParcelableArrayList("Contacts");
+
+ }
+
+ @Override
+ public void onLoaderReset(Loader<Bundle> loader) {
+ // Thi is called when the last Cursor provided to onLoadFinished
+ // mListAdapter.swapCursor(null);
+ }
+
+ private class AutoCompleteAdapter extends ArrayAdapter<Address> implements Filterable {
+
+ private LayoutInflater mInflater;
+ private Geocoder mGeocoder;
+// private StringBuilder mSb = new StringBuilder();
+
+ public AutoCompleteAdapter(final Context context) {
+ super(context, -1);
+ mInflater = LayoutInflater.from(context);
+ mGeocoder = new Geocoder(context);
+ }
+
+ @Override
+ public View getView(final int position, final View convertView, final ViewGroup parent) {
+ final TextView tv;
+ if (convertView != null) {
+ tv = (TextView) convertView;
+ } else {
+ tv = (TextView) mInflater.inflate(android.R.layout.simple_dropdown_item_1line, parent, false);
+ }
+
+ return tv;
+ }
+
+ @Override
+ public Filter getFilter() {
+ Filter myFilter = new Filter() {
+ @Override
+ protected FilterResults performFiltering(final CharSequence constraint) {
+ List<Address> addressList = null;
+ if (constraint != null) {
+ try {
+ addressList = mGeocoder.getFromLocationName((String) constraint, 5);
+ } catch (IOException e) {
+ }
+ }
+ if (addressList == null) {
+ addressList = new ArrayList<Address>();
+ }
+
+ final FilterResults filterResults = new FilterResults();
+ filterResults.values = addressList;
+ filterResults.count = addressList.size();
+
+ return filterResults;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void publishResults(final CharSequence contraint, final FilterResults results) {
+ clear();
+ for (Address address : (List<Address>) results.values) {
+ add(address);
+ }
+ if (results.count > 0) {
+ notifyDataSetChanged();
+ } else {
+ notifyDataSetInvalidated();
+ }
+ }
+
+ @Override
+ public CharSequence convertResultToString(final Object resultValue) {
+ return resultValue == null ? "" : ((Address) resultValue).getAddressLine(0);
+ }
+ };
+ return myFilter;
+ }
+ }
+
+ private class SimpleCallListAdapter extends BaseAdapter {
+
+ private LayoutInflater mInflater;
+ ArrayList<Conference> calls;
+
+ public SimpleCallListAdapter(final Context context, ArrayList<Conference> calls2) {
+ super();
+ mInflater = LayoutInflater.from(context);
+ calls = calls2;
+ }
+
+ @Override
+ public View getView(final int position, final View convertView, final ViewGroup parent) {
+ final TextView tv;
+ if (convertView != null) {
+ tv = (TextView) convertView;
+ } else {
+ tv = (TextView) mInflater.inflate(android.R.layout.simple_dropdown_item_1line, parent, false);
+ }
+
+ tv.setText(calls.get(position).getParticipants().get(0).getContact().getmDisplayName());
+ return tv;
+ }
+
+ @Override
+ public int getCount() {
+ return calls.size();
+ }
+
+ @Override
+ public Conference getItem(int pos) {
+ return calls.get(pos);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return 0;
+ }
+ }
+}