* #31542: correct screen flow
diff --git a/src/org/sflphone/client/AccountEditionActivity.java b/src/org/sflphone/client/AccountEditionActivity.java
index 592ea96..72ee750 100644
--- a/src/org/sflphone/client/AccountEditionActivity.java
+++ b/src/org/sflphone/client/AccountEditionActivity.java
@@ -44,13 +44,20 @@
import org.sflphone.account.AccountDetailBasic;
import org.sflphone.account.AccountDetailSrtp;
import org.sflphone.account.AccountDetailTls;
+import org.sflphone.service.ISipService;
+import org.sflphone.service.SipService;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
+import android.content.ComponentName;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.ServiceConnection;
import android.os.Bundle;
+import android.os.IBinder;
+import android.os.RemoteException;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
@@ -66,6 +73,22 @@
private static final String TAG = "AccoutPreferenceActivity";
public static final String KEY_MODE = "mode";
+ private boolean mBound = false;
+ private ISipService service;
+
+ private ServiceConnection mConnection = new ServiceConnection() {
+
+ @Override
+ public void onServiceConnected(ComponentName className, IBinder binder) {
+ service = ISipService.Stub.asInterface(binder);
+ mBound = true;
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName arg0) {
+
+ }
+ };
public interface result {
static final int ACCOUNT_MODIFIED = Activity.RESULT_FIRST_USER + 1;
@@ -78,13 +101,19 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
+
setContentView(R.layout.activity_holder);
getActionBar().setDisplayHomeAsUpEnabled(true);
mEditionFragment = new EditionFragment();
mEditionFragment.setArguments(getIntent().getExtras());
getFragmentManager().beginTransaction().replace(R.id.frag_container, mEditionFragment).commit();
+
+ if (!mBound) {
+ Log.i(TAG, "onCreate: Binding service...");
+ Intent intent = new Intent(this, SipService.class);
+ bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
+ }
}
@@ -108,6 +137,19 @@
}
@Override
+ protected void onDestroy() {
+
+ if (mBound) {
+ unbindService(mConnection);
+ mBound = false;
+ }
+
+ // stopService(new Intent(this, SipService.class));
+ // serviceIsOn = false;
+ super.onDestroy();
+ }
+
+ @Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@@ -132,8 +174,6 @@
ArrayList<String> missingValue = new ArrayList<String>();
if (mEditionFragment.validateAccountCreation(missingValue)) {
- Bundle bundle = new Bundle();
- bundle.putString("AccountID", mEditionFragment.mAccountID);
HashMap<String, String> accountDetails = new HashMap<String, String>();
updateAccountDetails(accountDetails, mEditionFragment.basicDetails);
@@ -142,11 +182,11 @@
updateAccountDetails(accountDetails, mEditionFragment.tlsDetails);
accountDetails.put("Account.type", "SIP");
- bundle.putSerializable(AccountDetail.TAG, accountDetails);
- Intent resultIntent = new Intent();
- resultIntent.putExtras(bundle);
-
- setResult(resultCode, resultIntent);
+ try {
+ service.setAccountDetails(mEditionFragment.mAccountID, accountDetails);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
finish();
} else {
dialog = createCouldNotValidateDialog(missingValue);
@@ -224,12 +264,12 @@
Bundle bundle = new Bundle();
bundle.putString("AccountID", mEditionFragment.mAccountID);
- Intent resultIntent = new Intent();
- resultIntent.putExtras(bundle);
-
- Activity activity = ((Dialog) dialog).getOwnerActivity();
- activity.setResult(result.ACCOUNT_DELETED, resultIntent);
- activity.finish();
+ try {
+ service.removeAccount(mEditionFragment.mAccountID);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ finish();
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
@@ -253,12 +293,11 @@
private String mAccountID;
private boolean isDifferent = false;
private ArrayList<String> requiredFields = null;
-
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.account_creation_preferences);
initEdition();
@@ -269,7 +308,7 @@
requiredFields.add(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD);
}
-
+
private void initEdition() {
Bundle b = getArguments();
diff --git a/src/org/sflphone/client/AccountWizard.java b/src/org/sflphone/client/AccountWizard.java
index 1987541..960d614 100644
--- a/src/org/sflphone/client/AccountWizard.java
+++ b/src/org/sflphone/client/AccountWizard.java
@@ -36,27 +36,47 @@
import org.sflphone.R;
import org.sflphone.fragments.AccountCreationFragment;
+import org.sflphone.fragments.AccountCreationFragment.Callbacks;
import org.sflphone.interfaces.AccountsInterface;
+import org.sflphone.service.ISipService;
+import org.sflphone.service.SipService;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.content.ServiceConnection;
import android.os.Bundle;
+import android.os.IBinder;
import android.support.v13.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.MenuItem;
-public class AccountWizard extends Activity implements AccountsInterface {
+public class AccountWizard extends Activity implements AccountsInterface, Callbacks {
static final String TAG = "AccountWizard";
-
+ private boolean mBound = false;
public static final int ACCOUNT_CREATED = Activity.RESULT_OK;
-
+ private ISipService service;
ViewPager mViewPager;
private SectionsPagerAdapter mSectionsPagerAdapter;
+ private ServiceConnection mConnection = new ServiceConnection() {
+
+ @Override
+ public void onServiceConnected(ComponentName className, IBinder binder) {
+ service = ISipService.Stub.asInterface(binder);
+ mBound = true;
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName arg0) {
+
+ }
+ };
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -69,12 +89,22 @@
mSectionsPagerAdapter = new SectionsPagerAdapter(AccountWizard.this, getFragmentManager());
mViewPager.setAdapter(mSectionsPagerAdapter);
+ if (!mBound) {
+ Log.i(TAG, "onCreate: Binding service...");
+ Intent intent = new Intent(this, SipService.class);
+ bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
+ }
+
}
/* activity finishes itself or is being killed by the system */
@Override
protected void onDestroy() {
super.onDestroy();
+ if (mBound) {
+ unbindService(mConnection);
+ mBound = false;
+ }
}
@Override
@@ -154,4 +184,9 @@
}
}
+ @Override
+ public ISipService getService() {
+ return service;
+ }
+
}
diff --git a/src/org/sflphone/client/SFLPhoneHomeActivity.java b/src/org/sflphone/client/SFLPhoneHomeActivity.java
index 8378b1f..c4784ba 100644
--- a/src/org/sflphone/client/SFLPhoneHomeActivity.java
+++ b/src/org/sflphone/client/SFLPhoneHomeActivity.java
@@ -253,6 +253,9 @@
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
+ if(mDrawer.isOpened()){
+ getActionBar().hide();
+ }
}
@Override
@@ -283,6 +286,7 @@
intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT);
intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED);
registerReceiver(callReceiver, intentFilter);
+
}
@@ -484,9 +488,7 @@
@Override
public void onCallContact(final CallContact c) {
- getActionBar().show(); // in case the contact drawer is open
if (fMenu.getSelectedAccount() == null) {
- // Toast.makeText(this, "No Account Selected", Toast.LENGTH_SHORT).show();
createAccountDialog().show();
return;
}
@@ -496,6 +498,7 @@
return;
}
+ getActionBar().show();
Thread launcher = new Thread(new Runnable() {
final String[] CONTACTS_PHONES_PROJECTION = new String[] { Phone.NUMBER, Phone.TYPE };
@@ -540,7 +543,6 @@
public void onCallDialed(String to) {
if (fMenu.getSelectedAccount() == null) {
- // Toast.makeText(this, "No Account Selected", Toast.LENGTH_SHORT).show();
createAccountDialog().show();
return;
}
@@ -605,10 +607,7 @@
@Override
public void onContactDragged() {
-
mDrawer.close();
- // mTabHost.setCurrentTab(1);
-
}
@Override
diff --git a/src/org/sflphone/client/SFLPhonePreferenceActivity.java b/src/org/sflphone/client/SFLPhonePreferenceActivity.java
index 549873e..3172a34 100644
--- a/src/org/sflphone/client/SFLPhonePreferenceActivity.java
+++ b/src/org/sflphone/client/SFLPhonePreferenceActivity.java
@@ -38,11 +38,9 @@
import org.sflphone.service.ISipService;
import org.sflphone.service.SipService;
-import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
-import android.app.FragmentTransaction;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -55,11 +53,10 @@
import android.view.MenuItem;
public class SFLPhonePreferenceActivity extends Activity implements AccountManagementFragment.Callbacks{
- static final int NUM_PAGES = 1;
+
static final String TAG = SFLPhonePreferenceActivity.class.getSimpleName();
PreferencesPagerAdapter mPreferencesPagerAdapter;
private boolean mBound = false;
- static boolean serviceIsOn = false;
private ISipService service;
ViewPager mViewPager;
@@ -150,6 +147,8 @@
public class PreferencesPagerAdapter extends FragmentStatePagerAdapter {
+ static final int NUM_PAGES = 1;
+
public PreferencesPagerAdapter(FragmentManager fm) {
super(fm);
}
diff --git a/src/org/sflphone/fragments/AccountCreationFragment.java b/src/org/sflphone/fragments/AccountCreationFragment.java
index 9d68a83..388f2a1 100644
--- a/src/org/sflphone/fragments/AccountCreationFragment.java
+++ b/src/org/sflphone/fragments/AccountCreationFragment.java
@@ -8,12 +8,21 @@
import org.sflphone.account.AccountDetailBasic;
import org.sflphone.account.AccountDetailSrtp;
import org.sflphone.account.AccountDetailTls;
+import org.sflphone.client.SFLPhonePreferenceActivity;
+import org.sflphone.client.SFLPhonePreferenceActivity.PreferencesPagerAdapter;
+import org.sflphone.fragments.AccountManagementFragment.Callbacks;
+import org.sflphone.service.ISipService;
import android.app.Activity;
import android.app.Fragment;
+import android.content.ComponentName;
import android.content.Intent;
+import android.content.ServiceConnection;
import android.os.Bundle;
+import android.os.IBinder;
+import android.os.RemoteException;
import android.text.TextUtils;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -32,6 +41,23 @@
private EditText mHostnameView;
private EditText mUsernameView;
private EditText mPasswordView;
+
+ private Callbacks mCallbacks = sDummyCallbacks;
+ private static Callbacks sDummyCallbacks = new Callbacks() {
+
+ @Override
+ public ISipService getService() {
+ return null;
+ }
+ };
+
+ public interface Callbacks {
+
+ public ISipService getService();
+
+ }
+
+
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -94,6 +120,16 @@
super.onStart();
}
+
+ @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;
+ }
/**
* Attempts to sign in or register the account specified by the login form. If there are form errors (invalid email, missing fields, etc.), the
@@ -208,13 +244,25 @@
accountDetails.put(AccountDetailTls.CONFIG_TLS_VERIFY_SERVER, "");
Bundle bundle = new Bundle();
- bundle.putSerializable(AccountDetail.TAG, accountDetails);
- Intent resultIntent = new Intent();
- resultIntent.putExtras(bundle);
-
+
+
+ createNewAccount(accountDetails);
+
+ Intent resultIntent = new Intent(getActivity(), SFLPhonePreferenceActivity.class);
getActivity().setResult(Activity.RESULT_OK, resultIntent);
+ resultIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
+ startActivity(resultIntent);
getActivity().finish();
}
+
+ private void createNewAccount(HashMap<String, String> accountDetails) {
+ try {
+
+ mCallbacks.getService().addAccount(accountDetails);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
}
diff --git a/src/org/sflphone/fragments/AccountManagementFragment.java b/src/org/sflphone/fragments/AccountManagementFragment.java
index 60a5920..4b19b7e 100644
--- a/src/org/sflphone/fragments/AccountManagementFragment.java
+++ b/src/org/sflphone/fragments/AccountManagementFragment.java
@@ -33,10 +33,8 @@
package org.sflphone.fragments;
import java.util.ArrayList;
-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;
@@ -58,18 +56,15 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.Loader;
-import android.graphics.Color;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;
-import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
-import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
@@ -109,6 +104,7 @@
}
mCallbacks = (Callbacks) activity;
+ getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
}
@Override
@@ -125,7 +121,7 @@
mAdapter = new AccountsAdapter(getActivity(), new ArrayList<Account>());
this.setHasOptionsMenu(true);
accountReceiver = new AccountsReceiver(this);
- getLoaderManager().initLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
+
}
@Override
@@ -161,65 +157,9 @@
intentFilter2.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED);
intentFilter2.addAction(ConfigurationManagerCallback.ACCOUNTS_CHANGED);
getActivity().registerReceiver(accountReceiver, intentFilter2);
- }
-
- @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();
- HashMap<String, String> accountDetails = new HashMap<String, String>();
- accountDetails = (HashMap<String, String>) bundle.getSerializable(AccountDetail.TAG);
-
- createNewAccount(accountDetails);
- }
- break;
- case ACCOUNT_EDIT_REQUEST:
- if (resultCode == AccountEditionActivity.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);
- setAccountDetails(accountID, accountDetails);
-
- } else if (resultCode == AccountEditionActivity.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");
- mCallbacks.getService().addAccount(accountDetails);
- } catch (RemoteException e) {
- Log.e(TAG, "Cannot call service method", e);
- }
- }
-
- private void setAccountDetails(String accountID, HashMap<String, String> accountDetails) {
- try {
- mCallbacks.getService().setAccountDetails(accountID, accountDetails);
- } catch (RemoteException e) {
- Log.e(TAG, "Cannot call service method", e);
- }
+
+ getActivity().getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
+
}
@Override
@@ -241,15 +181,6 @@
}
- private void deleteSelectedAccount(String accountID) {
- Log.i(TAG, "DeleteSelectedAccount");
- try {
- mCallbacks.getService().removeAccount(accountID);
- } catch (RemoteException e) {
- Log.e(TAG, "Cannot call service method", e);
- }
- };
-
@Override
public void onCreateOptionsMenu(Menu m, MenuInflater inf) {
super.onCreateOptionsMenu(m, inf);