Skip to content
Snippets Groups Projects
Commit 3cefec24 authored by Alexandre Lision's avatar Alexandre Lision
Browse files

* #34699: working multi credential setting

parent 12f22dcf
Branches
Tags
No related merge requests found
Showing
with 471 additions and 304 deletions
...@@ -15,12 +15,11 @@ APP_MODULES += libccrtp1 ...@@ -15,12 +15,11 @@ APP_MODULES += libccrtp1
APP_MODULES += libsndfile APP_MODULES += libsndfile
# APP_MODULES += libconfig APP_MODULES += libpcre
APP_MODULES += libcrypto APP_MODULES += libcrypto
#APP_MODULES += openssl #APP_MODULES += openssl
#APP_MODULES += libspeex
APP_MODULES += libspeexresampler APP_MODULES += libspeexresampler
APP_MODULES += libcodec_ulaw APP_MODULES += libcodec_ulaw
APP_MODULES += libcodec_alaw APP_MODULES += libcodec_alaw
......
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
Author: Alexandre Lision <alexandre.lision@gmail.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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="vertical" >
<EditText
android:id="@+id/credentials_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="textNoSuggestions"
android:hint="Username..." >
<requestFocus />
</EditText>
<EditText
android:id="@+id/credentials_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:hint="Password..."
android:inputType="textVisiblePassword" />
<EditText
android:id="@+id/credentials_realm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
android:imeOptions="actionGo"
android:hint="Realm..." />
</LinearLayout>
\ No newline at end of file
...@@ -3,13 +3,8 @@ ...@@ -3,13 +3,8 @@
<item <item
android:id="@+id/menuitem_delete" android:id="@+id/menuitem_delete"
android:title="@string/ab_account_edition_1" android:icon="@drawable/ic_action_discard"
android:showAsAction="ifRoom" android:showAsAction="ifRoom"
android:icon="@drawable/ic_action_discard"/> android:title="@string/ab_account_edition_1"/>
<item
android:id="@+id/menuitem_edit"
android:title="@string/ab_account_edition_2"
android:showAsAction="ifRoom"
android:icon="@drawable/ic_action_accept"/>
</menu> </menu>
\ No newline at end of file
...@@ -32,11 +32,11 @@ as that of the covered work. ...@@ -32,11 +32,11 @@ as that of the covered work.
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<Preference <org.sflphone.views.CredentialsPreference
android:id="@+id/account_credential_number" android:id="@+id/account_credential_number"
android:key="Add.credentials" android:key="Add.credentials"
android:title="Add Credentials" android:title="Add Credentials"
android:icon="@drawable/ic_action_new_dark" > android:icon="@drawable/ic_action_new_dark" >
</Preference> </org.sflphone.views.CredentialsPreference>
</PreferenceScreen> </PreferenceScreen>
\ No newline at end of file
...@@ -15,7 +15,6 @@ public class AccountCredentials implements AccountDetail { ...@@ -15,7 +15,6 @@ public class AccountCredentials implements AccountDetail {
public static final String CONFIG_ACCOUNT_PASSWORD = "Account.password"; public static final String CONFIG_ACCOUNT_PASSWORD = "Account.password";
public static final String CONFIG_ACCOUNT_REALM = "Account.realm"; public static final String CONFIG_ACCOUNT_REALM = "Account.realm";
private ArrayList<AccountDetail.PreferenceEntry> privateArray; private ArrayList<AccountDetail.PreferenceEntry> privateArray;
public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() { public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() {
...@@ -37,7 +36,10 @@ public class AccountCredentials implements AccountDetail { ...@@ -37,7 +36,10 @@ public class AccountCredentials implements AccountDetail {
for (AccountDetail.PreferenceEntry p : privateArray) { for (AccountDetail.PreferenceEntry p : privateArray) {
p.mValue = pref.get(p.mKey); p.mValue = pref.get(p.mKey);
Log.i(TAG, "Creating "+pref.get(p.mKey));
} }
} }
public AccountCredentials(ArrayList<String> pref) { public AccountCredentials(ArrayList<String> pref) {
...@@ -101,4 +103,14 @@ public class AccountCredentials implements AccountDetail { ...@@ -101,4 +103,14 @@ public class AccountCredentials implements AccountDetail {
} }
@Override
public boolean equals(Object other){
if(other instanceof AccountCredentials)
return ((AccountCredentials)other).getDetailsHashMap().get(CONFIG_ACCOUNT_USERNAME).contentEquals(getDetailString(CONFIG_ACCOUNT_USERNAME)) &&
((AccountCredentials)other).getDetailsHashMap().get(CONFIG_ACCOUNT_PASSWORD).contentEquals(getDetailString(CONFIG_ACCOUNT_PASSWORD)) &&
((AccountCredentials)other).getDetailsHashMap().get(CONFIG_ACCOUNT_REALM).contentEquals(getDetailString(CONFIG_ACCOUNT_REALM));
return false;
}
} }
\ No newline at end of file
...@@ -249,9 +249,10 @@ public class AccountDetailsHandler { ...@@ -249,9 +249,10 @@ public class AccountDetailsHandler {
public static ArrayList<HashMap<String, String>> convertCredentialsToNative(VectMap map) { public static ArrayList<HashMap<String, String>> convertCredentialsToNative(VectMap map) {
ArrayList<HashMap<String, String>> toReturn = new ArrayList<HashMap<String, String>>(); ArrayList<HashMap<String, String>> toReturn = new ArrayList<HashMap<String, String>>();
StringMap entry;
HashMap<String, String> nativeEntry = new HashMap<String, String>();
for (int i = 0; i < map.size(); ++i) { for (int i = 0; i < map.size(); ++i) {
StringMap entry = new StringMap();
HashMap<String, String> nativeEntry = new HashMap<String, String>();
entry = map.get(i); entry = map.get(i);
nativeEntry.put(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD, entry.get(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD)); nativeEntry.put(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD, entry.get(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD));
nativeEntry.put(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME, entry.get(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME)); nativeEntry.put(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME, entry.get(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME));
...@@ -264,10 +265,11 @@ public class AccountDetailsHandler { ...@@ -264,10 +265,11 @@ public class AccountDetailsHandler {
public static VectMap convertCredentialsToSwig(List creds) { public static VectMap convertCredentialsToSwig(List creds) {
ArrayList<HashMap<String, String>> todecode = (ArrayList<HashMap<String, String>>) creds; ArrayList<HashMap<String, String>> todecode = (ArrayList<HashMap<String, String>>) creds;
VectMap toReturn = new VectMap(); VectMap toReturn = new VectMap();
StringMap entry = new StringMap();
HashMap<String, String> nativeEntry; HashMap<String, String> nativeEntry;
for (int i = 0; i < todecode.size(); ++i) { for (int i = 0; i < todecode.size(); ++i) {
nativeEntry = todecode.get(i); nativeEntry = todecode.get(i);
StringMap entry = new StringMap();
entry.set(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD, nativeEntry.get(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD)); entry.set(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD, nativeEntry.get(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD));
entry.set(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME, nativeEntry.get(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME)); entry.set(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME, nativeEntry.get(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME));
entry.set(AccountDetailBasic.CONFIG_ACCOUNT_REALM, nativeEntry.get(AccountDetailBasic.CONFIG_ACCOUNT_REALM)); entry.set(AccountDetailBasic.CONFIG_ACCOUNT_REALM, nativeEntry.get(AccountDetailBasic.CONFIG_ACCOUNT_REALM));
......
/*
* Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
*
* Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
* Alexandre Savard <alexandre.savard@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.account;
import java.util.ArrayList;
import java.util.HashMap;
import org.sflphone.fragments.NestedSettingsFragment.Callbacks;
import org.sflphone.model.Account;
import org.sflphone.views.CredentialsPreference;
import android.content.Context;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceScreen;
public class CredentialsManager {
PreferenceScreen mScreen;
public static final String CURRENT_CRED = "current_cred";
public static final String NEW_CRED = "new_cred";
private Context mContext;
private Account mAccount;
public void onCreate(Context cont, PreferenceScreen preferenceScreen, Account acc) {
mContext = cont;
mScreen = preferenceScreen;
mAccount = acc;
}
public void reloadCredentials() {
removeAllCredentials();
addAllCredentials();
}
public void setAddCredentialListener() {
mScreen.findPreference("Add.credentials").setOnPreferenceChangeListener(addCredentialListener);
}
public void setEditCredentialListener() {
mScreen.findPreference("Add.credentials").setOnPreferenceChangeListener(addCredentialListener);
}
private void addAllCredentials() {
ArrayList<AccountCredentials> credentials = mAccount.getCredentials();
for (AccountCredentials cred : credentials) {
CredentialsPreference toAdd = new CredentialsPreference(mContext, null);
toAdd.setKey("credential");
toAdd.setTitle(cred.getDetailString(AccountCredentials.CONFIG_ACCOUNT_USERNAME));
toAdd.setSummary(cred.getDetailString(AccountCredentials.CONFIG_ACCOUNT_REALM));
toAdd.getExtras().putSerializable(CURRENT_CRED, cred.getDetailsHashMap());
toAdd.setOnPreferenceChangeListener(editCredentialListener);
toAdd.setIcon(null);
mScreen.addPreference(toAdd);
}
}
private void removeAllCredentials() {
Preference toRemove = mScreen.findPreference("credential");
while (mScreen.findPreference("credential") != null) {
mScreen.removePreference(toRemove);
toRemove = mScreen.findPreference("credential");
}
}
private OnPreferenceChangeListener editCredentialListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// We need the old and new value to correctly edit the list of credentials
Bundle result = (Bundle) newValue;
mAccount.removeCredential(new AccountCredentials((HashMap<String, String>) result.get(CURRENT_CRED)));
if(result.get(NEW_CRED) != null){
// There is a new value for this credentials it means it has been edited (otherwise deleted)
mAccount.addCredential(new AccountCredentials((HashMap<String, String>) result.get(NEW_CRED)));
}
mAccount.notifyObservers();
reloadCredentials();
return false;
}
};
private OnPreferenceChangeListener addCredentialListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mAccount.addCredential((AccountCredentials) newValue);
mAccount.notifyObservers();
reloadCredentials();
return false;
}
};
}
...@@ -34,6 +34,8 @@ package org.sflphone.client; ...@@ -34,6 +34,8 @@ package org.sflphone.client;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
import java.util.Observable;
import java.util.Observer;
import org.sflphone.R; import org.sflphone.R;
import org.sflphone.account.AccountDetailBasic; import org.sflphone.account.AccountDetailBasic;
...@@ -51,7 +53,6 @@ import android.app.ActionBar.Tab; ...@@ -51,7 +53,6 @@ import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener; import android.app.ActionBar.TabListener;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog;
import android.app.Fragment; import android.app.Fragment;
import android.app.FragmentManager; import android.app.FragmentManager;
import android.app.FragmentTransaction; import android.app.FragmentTransaction;
...@@ -69,18 +70,16 @@ import android.util.Log; ...@@ -69,18 +70,16 @@ import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.widget.Toast;
public class AccountEditionActivity extends Activity implements TabListener, GeneralAccountFragment.Callbacks, AudioManagementFragment.Callbacks, public class AccountEditionActivity extends Activity implements TabListener, GeneralAccountFragment.Callbacks, AudioManagementFragment.Callbacks,
AdvancedAccountFragment.Callbacks, SecurityAccountFragment.Callbacks, NestedSettingsFragment.Callbacks { AdvancedAccountFragment.Callbacks, SecurityAccountFragment.Callbacks, NestedSettingsFragment.Callbacks {
private static final String TAG = "AccoutPreferenceActivity"; private static final String TAG = AccountEditionActivity.class.getSimpleName();
public static final String KEY_MODE = "mode"; public static final String KEY_MODE = "mode";
private boolean mBound = false; private boolean mBound = false;
private ISipService service; private ISipService service;
private View mOverlayContainer;
private Account acc_selected; private Account acc_selected;
PreferencesPagerAdapter mPreferencesPagerAdapter; PreferencesPagerAdapter mPreferencesPagerAdapter;
...@@ -107,14 +106,8 @@ public class AccountEditionActivity extends Activity implements TabListener, Gen ...@@ -107,14 +106,8 @@ public class AccountEditionActivity extends Activity implements TabListener, Gen
final PagerSlidingTabStrip strip = PagerSlidingTabStrip.class.cast(findViewById(R.id.pager_sliding_strip)); final PagerSlidingTabStrip strip = PagerSlidingTabStrip.class.cast(findViewById(R.id.pager_sliding_strip));
// strip.setBackgroundColor(getResources().getColor(R.color.sfl_blue_0));
strip.setViewPager(mViewPager); strip.setViewPager(mViewPager);
// getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// for (int i = 0; i < mPreferencesPagerAdapter.getCount(); i++) {
// getActionBar().addTab(
// getActionBar().newTab().setText(mPreferencesPagerAdapter.getPageTitle(i)).setTabListener(AccountEditionActivity.this));
//
// }
} }
@Override @Override
...@@ -125,6 +118,16 @@ public class AccountEditionActivity extends Activity implements TabListener, Gen ...@@ -125,6 +118,16 @@ public class AccountEditionActivity extends Activity implements TabListener, Gen
private ViewPager mViewPager; private ViewPager mViewPager;
private NestedSettingsFragment toDisplay;
private Observer mAccountObserver = new Observer() {
@Override
public void update(Observable observable, Object data) {
processAccount();
}
};
// private ArrayList<String> requiredFields = null; // private ArrayList<String> requiredFields = null;
// EditionFragment mEditionFragment; // EditionFragment mEditionFragment;
...@@ -143,9 +146,10 @@ public class AccountEditionActivity extends Activity implements TabListener, Gen ...@@ -143,9 +146,10 @@ public class AccountEditionActivity extends Activity implements TabListener, Gen
} }
}); });
mOverlayContainer = findViewById(R.id.hidden_container);
acc_selected = getIntent().getExtras().getParcelable("account"); acc_selected = getIntent().getExtras().getParcelable("account");
acc_selected.addObserver(mAccountObserver);
if (!mBound) { if (!mBound) {
Log.i(TAG, "onCreate: Binding service..."); Log.i(TAG, "onCreate: Binding service...");
Intent intent = new Intent(this, SipService.class); Intent intent = new Intent(this, SipService.class);
...@@ -167,17 +171,19 @@ public class AccountEditionActivity extends Activity implements TabListener, Gen ...@@ -167,17 +171,19 @@ public class AccountEditionActivity extends Activity implements TabListener, Gen
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (toDisplay != null) {
getFragmentManager().beginTransaction().remove(toDisplay).commit();
toDisplay = null;
return;
}
if (acc_selected.isIP2IP()) { if (acc_selected.isIP2IP()) {
super.onBackPressed(); super.onBackPressed();
return; return;
} }
if (mPreferencesPagerAdapter.getItem(0) != null && ((GeneralAccountFragment) mPreferencesPagerAdapter.getItem(0)).isDifferent()) {
AlertDialog dialog = createCancelDialog();
dialog.show();
} else {
super.onBackPressed(); super.onBackPressed();
}
} }
@Override @Override
...@@ -198,36 +204,28 @@ public class AccountEditionActivity extends Activity implements TabListener, Gen ...@@ -198,36 +204,28 @@ public class AccountEditionActivity extends Activity implements TabListener, Gen
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: case android.R.id.home:
if (toDisplay != null) {
getFragmentManager().beginTransaction().remove(toDisplay).commit();
toDisplay = null;
} else
finish(); finish();
return true; return true;
case R.id.menuitem_delete: case R.id.menuitem_delete:
AlertDialog dialog = createDeleteDialog(); AlertDialog dialog = createDeleteDialog();
dialog.show(); dialog.show();
break; break;
case R.id.menuitem_edit:
processAccount();
break;
} }
return true; return true;
} }
private void processAccount() { private void processAccount() {
AlertDialog dialog;
ArrayList<String> missingValue = new ArrayList<String>();
if (validateAccountCreation(missingValue)) {
try { try {
service.setCredentials(acc_selected.getAccountID(), acc_selected.getCredentialsHashMapList());
service.setAccountDetails(acc_selected.getAccountID(), acc_selected.getDetails()); service.setAccountDetails(acc_selected.getAccountID(), acc_selected.getDetails());
} catch (RemoteException e) { } catch (RemoteException e) {
e.printStackTrace(); e.printStackTrace();
} }
finish();
} else {
dialog = createCouldNotValidateDialog(missingValue);
dialog.show();
}
} }
...@@ -249,54 +247,6 @@ public class AccountEditionActivity extends Activity implements TabListener, Gen ...@@ -249,54 +247,6 @@ public class AccountEditionActivity extends Activity implements TabListener, Gen
return valid; return valid;
} }
/******************************************
*
* AlertDialogs
*
******************************************/
private AlertDialog createCouldNotValidateDialog(ArrayList<String> missingValue) {
String message = "The following parameters are missing:";
for (String s : missingValue)
message += "\n - " + s;
Activity ownerActivity = this;
AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity);
builder.setMessage(message).setTitle("Missing Parameters").setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
/* Nothing to be done */
}
});
AlertDialog alertDialog = builder.create();
return alertDialog;
}
private AlertDialog createCancelDialog() {
Activity ownerActivity = this;
AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity);
builder.setMessage("Modifications will be lost").setTitle("Account Edition")
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
Activity activity = ((Dialog) dialog).getOwnerActivity();
activity.finish();
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
/* Terminate with no action */
}
});
AlertDialog alertDialog = builder.create();
alertDialog.setOwnerActivity(ownerActivity);
return alertDialog;
}
private AlertDialog createDeleteDialog() { private AlertDialog createDeleteDialog() {
Activity ownerActivity = this; Activity ownerActivity = this;
AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity); AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity);
...@@ -407,7 +357,7 @@ public class AccountEditionActivity extends Activity implements TabListener, Gen ...@@ -407,7 +357,7 @@ public class AccountEditionActivity extends Activity implements TabListener, Gen
@Override @Override
public void displayCredentialsScreen() { public void displayCredentialsScreen() {
Fragment toDisplay = new NestedSettingsFragment(); toDisplay = new NestedSettingsFragment();
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putInt("MODE", 0); b.putInt("MODE", 0);
toDisplay.setArguments(b); toDisplay.setArguments(b);
......
...@@ -132,7 +132,7 @@ public class AdvancedAccountFragment extends PreferenceFragment { ...@@ -132,7 +132,7 @@ public class AdvancedAccountFragment extends PreferenceFragment {
Preference.OnPreferenceChangeListener changeAdvancedPreferenceListener = new Preference.OnPreferenceChangeListener() { Preference.OnPreferenceChangeListener changeAdvancedPreferenceListener = new Preference.OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
setDifferent(true);
if (preference instanceof CheckBoxPreference) { if (preference instanceof CheckBoxPreference) {
mCallbacks.getAccount().getAdvancedDetails().setDetailString(preference.getKey(), ((Boolean) newValue).toString()); mCallbacks.getAccount().getAdvancedDetails().setDetailString(preference.getKey(), ((Boolean) newValue).toString());
if (preference.getKey().contentEquals("STUN.enable")) { if (preference.getKey().contentEquals("STUN.enable")) {
...@@ -141,22 +141,15 @@ public class AdvancedAccountFragment extends PreferenceFragment { ...@@ -141,22 +141,15 @@ public class AdvancedAccountFragment extends PreferenceFragment {
findPreference("Account.publishedPort").setEnabled(!(Boolean) newValue); findPreference("Account.publishedPort").setEnabled(!(Boolean) newValue);
findPreference("Account.publishedAddress").setEnabled(!(Boolean) newValue); findPreference("Account.publishedAddress").setEnabled(!(Boolean) newValue);
} }
mCallbacks.getAccount().notifyObservers();
} else { } else {
preference.setSummary((CharSequence) newValue); preference.setSummary((CharSequence) newValue);
Log.i(TAG, "Changing" + preference.getKey() + " value:" + newValue); Log.i(TAG, "Changing" + preference.getKey() + " value:" + newValue);
mCallbacks.getAccount().getAdvancedDetails().setDetailString(preference.getKey(), ((CharSequence) newValue).toString()); mCallbacks.getAccount().getAdvancedDetails().setDetailString(preference.getKey(), ((CharSequence) newValue).toString());
mCallbacks.getAccount().notifyObservers();
} }
return true; return true;
} }
}; };
public boolean isDifferent() {
return isDifferent;
}
public void setDifferent(boolean isDifferent) {
this.isDifferent = isDifferent;
}
} }
...@@ -16,9 +16,6 @@ import android.util.Log; ...@@ -16,9 +16,6 @@ import android.util.Log;
public class GeneralAccountFragment extends PreferenceFragment { public class GeneralAccountFragment extends PreferenceFragment {
private static final String TAG = GeneralAccountFragment.class.getSimpleName(); private static final String TAG = GeneralAccountFragment.class.getSimpleName();
private boolean isDifferent = false;
private Callbacks mCallbacks = sDummyCallbacks; private Callbacks mCallbacks = sDummyCallbacks;
private static Callbacks sDummyCallbacks = new Callbacks() { private static Callbacks sDummyCallbacks = new Callbacks() {
...@@ -94,55 +91,22 @@ public class GeneralAccountFragment extends PreferenceFragment { ...@@ -94,55 +91,22 @@ public class GeneralAccountFragment extends PreferenceFragment {
Preference.OnPreferenceChangeListener changeBasicPreferenceListener = new Preference.OnPreferenceChangeListener() { Preference.OnPreferenceChangeListener changeBasicPreferenceListener = new Preference.OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
setDifferent(true);
if (preference instanceof CheckBoxPreference) { if (preference instanceof CheckBoxPreference) {
Log.i(TAG, "Changing preference value:" + newValue); Log.i(TAG, "Changing preference value:" + newValue);
mCallbacks.getAccount().getBasicDetails().setDetailString(preference.getKey(), ((Boolean) newValue).toString()); mCallbacks.getAccount().getBasicDetails().setDetailString(preference.getKey(), ((Boolean) newValue).toString());
mCallbacks.getAccount().notifyObservers();
} else { } else {
preference.setSummary((CharSequence) newValue); preference.setSummary((CharSequence) newValue);
Log.i(TAG, "Changing preference value:" + newValue); Log.i(TAG, "Changing preference value:" + newValue);
mCallbacks.getAccount().getBasicDetails().setDetailString(preference.getKey(), ((CharSequence) newValue).toString()); mCallbacks.getAccount().getBasicDetails().setDetailString(preference.getKey(), ((CharSequence) newValue).toString());
} mCallbacks.getAccount().notifyObservers();
return true;
}
};
Preference.OnPreferenceChangeListener changeAdvancedPreferenceListener = new Preference.OnPreferenceChangeListener() { Log.i(TAG, "Observer count:" + mCallbacks.getAccount().countObservers());
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
preference.setSummary((CharSequence) newValue);
mCallbacks.getAccount().getAdvancedDetails().setDetailString(preference.getKey(), ((CharSequence) newValue).toString());
return true;
} }
};
Preference.OnPreferenceChangeListener changeTlsPreferenceListener = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
preference.setSummary((CharSequence) newValue);
mCallbacks.getAccount().getTlsDetails().setDetailString(preference.getKey(), ((CharSequence) newValue).toString());
return true; return true;
} }
}; };
Preference.OnPreferenceChangeListener changeSrtpPreferenceListener = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
preference.setSummary((CharSequence) newValue);
mCallbacks.getAccount().getSrtpDetails().setDetailString(preference.getKey(), ((CharSequence) newValue).toString());
return true;
}
};
public boolean isDifferent() {
return isDifferent;
}
public void setDifferent(boolean isDifferent) {
this.isDifferent = isDifferent;
}
} }
package org.sflphone.fragments; package org.sflphone.fragments;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import org.sflphone.R; import org.sflphone.R;
import org.sflphone.account.AccountCredentials; import org.sflphone.account.CredentialsManager;
import org.sflphone.account.AccountDetail;
import org.sflphone.account.AccountDetailAdvanced;
import org.sflphone.model.Account; import org.sflphone.model.Account;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -27,9 +17,11 @@ public class NestedSettingsFragment extends PreferenceFragment { ...@@ -27,9 +17,11 @@ public class NestedSettingsFragment extends PreferenceFragment {
private static final String TAG = AdvancedAccountFragment.class.getSimpleName(); private static final String TAG = AdvancedAccountFragment.class.getSimpleName();
private boolean isDifferent = false;
private Callbacks mCallbacks = sDummyCallbacks; private Callbacks mCallbacks = sDummyCallbacks;
CredentialsManager mCredsManager;
private static Callbacks sDummyCallbacks = new Callbacks() { private static Callbacks sDummyCallbacks = new Callbacks() {
@Override @Override
...@@ -51,8 +43,6 @@ public class NestedSettingsFragment extends PreferenceFragment { ...@@ -51,8 +43,6 @@ public class NestedSettingsFragment extends PreferenceFragment {
if (!(activity instanceof Callbacks)) { if (!(activity instanceof Callbacks)) {
throw new IllegalStateException("Activity must implement fragment's callbacks."); throw new IllegalStateException("Activity must implement fragment's callbacks.");
} }
Log.e(TAG, "Attaching Adavnced");
mCallbacks = (Callbacks) activity; mCallbacks = (Callbacks) activity;
} }
...@@ -66,122 +56,36 @@ public class NestedSettingsFragment extends PreferenceFragment { ...@@ -66,122 +56,36 @@ public class NestedSettingsFragment extends PreferenceFragment {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
// Load the preferences from an XML resource // Load the preferences from an XML resource
switch (getArguments().getInt("MODE")) { switch (getArguments().getInt("MODE")) {
case 0: case 0:
addPreferencesFromResource(R.xml.account_credentials); addPreferencesFromResource(R.xml.account_credentials);
addAllCredentials(); mCredsManager = new CredentialsManager();
mCredsManager.onCreate(getActivity(), getPreferenceScreen(), mCallbacks.getAccount());
mCredsManager.reloadCredentials();
mCredsManager.setAddCredentialListener();
break; break;
case 1: case 1:
break; break;
case 2: case 2:
break; break;
} }
// setPreferenceDetails(mCallbacks.getAccount().getAdvancedDetails());
// addPreferenceListener(mCallbacks.getAccount().getAdvancedDetails(), changeAdvancedPreferenceListener);
}
private void addAllCredentials() {
ArrayList<AccountCredentials> credentials = mCallbacks.getAccount().getCredentials();
for (AccountCredentials cred : credentials) {
Preference toAdd = new Preference(getActivity());
toAdd.setTitle(cred.getDetailString(AccountCredentials.CONFIG_ACCOUNT_USERNAME));
toAdd.setSummary(cred.getDetailString(AccountCredentials.CONFIG_ACCOUNT_PASSWORD));
getPreferenceScreen().addPreference(toAdd);
} }
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState); View view = super.onCreateView(inflater, container, savedInstanceState);
view.setBackgroundColor(getResources().getColor(android.R.color.white)); view.setBackgroundColor(getResources().getColor(android.R.color.white));
return view; return view;
} }
private void setPreferenceDetails(AccountDetail details) {
for (AccountDetail.PreferenceEntry p : details.getDetailValues()) {
Log.i(TAG, "setPreferenceDetails: pref " + p.mKey + " value " + p.mValue);
Preference pref = findPreference(p.mKey);
if (pref != null) {
if (p.mKey == AccountDetailAdvanced.CONFIG_LOCAL_INTERFACE) {
ArrayList<CharSequence> entries = new ArrayList<CharSequence>();
try {
for (Enumeration<NetworkInterface> list = NetworkInterface.getNetworkInterfaces(); list.hasMoreElements();) {
NetworkInterface i = list.nextElement();
Log.e("network_interfaces", "display name " + i.getDisplayName());
if (i.isUp())
entries.add(i.getDisplayName());
}
} catch (SocketException e) {
Log.e(TAG, e.toString());
}
CharSequence[] display = new CharSequence[entries.size()];
entries.toArray(display);
((ListPreference) pref).setEntries(display);
((ListPreference) pref).setEntryValues(display);
pref.setSummary(p.mValue);
continue;
}
if (!p.isTwoState) {
pref.setSummary(p.mValue);
}
} else {
Log.w(TAG, "pref not found");
}
}
}
private void addPreferenceListener(AccountDetail details, OnPreferenceChangeListener listener) {
for (AccountDetail.PreferenceEntry p : details.getDetailValues()) {
Log.i(TAG, "addPreferenceListener: pref " + p.mKey + p.mValue);
Preference pref = findPreference(p.mKey);
if (pref != null) {
pref.setOnPreferenceChangeListener(listener);
} else {
Log.w(TAG, "addPreferenceListener: pref not found");
}
}
}
Preference.OnPreferenceChangeListener changeAdvancedPreferenceListener = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
setDifferent(true);
if (preference instanceof CheckBoxPreference) {
mCallbacks.getAccount().getAdvancedDetails().setDetailString(preference.getKey(), ((Boolean) newValue).toString());
if (preference.getKey().contentEquals("STUN.enable")) {
findPreference("STUN.server").setEnabled((Boolean) newValue);
} else if (preference.getKey().contentEquals("Account.publishedSameAsLocal")) {
findPreference("Account.publishedPort").setEnabled((Boolean) newValue);
findPreference("Account.publishedAddress").setEnabled((Boolean) newValue);
}
} else {
preference.setSummary((CharSequence) newValue);
Log.i(TAG, "Changing preference value:" + newValue);
mCallbacks.getAccount().getAdvancedDetails().setDetailString(preference.getKey(), ((CharSequence) newValue).toString());
}
return true;
}
};
public boolean isDifferent() {
return isDifferent;
}
public void setDifferent(boolean isDifferent) {
this.isDifferent = isDifferent;
}
} }
\ No newline at end of file
...@@ -80,18 +80,6 @@ public class SecurityAccountFragment extends PreferenceFragment { ...@@ -80,18 +80,6 @@ public class SecurityAccountFragment extends PreferenceFragment {
} }
}); });
// for (AccountDetail.PreferenceEntry p : details.getDetailValues()) {
// Log.i(TAG, "setPreferenceDetails: pref " + p.mKey + " value " + p.mValue);
// Preference pref = findPreference(p.mKey);
// if (pref != null) {
// if (!p.isTwoState) {
// ((EditTextPreference) pref).setText(p.mValue);
// pref.setSummary(p.mValue);
// }
// } else {
// Log.w(TAG, "pref not found");
// }
// }
} }
private void addPreferenceListener(AccountDetail details, OnPreferenceChangeListener listener) { private void addPreferenceListener(AccountDetail details, OnPreferenceChangeListener listener) {
......
...@@ -33,6 +33,7 @@ package org.sflphone.model; ...@@ -33,6 +33,7 @@ package org.sflphone.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import org.sflphone.account.AccountCredentials; import org.sflphone.account.AccountCredentials;
import org.sflphone.account.AccountDetailAdvanced; import org.sflphone.account.AccountDetailAdvanced;
...@@ -42,8 +43,9 @@ import org.sflphone.account.AccountDetailTls; ...@@ -42,8 +43,9 @@ import org.sflphone.account.AccountDetailTls;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.util.Log;
public class Account implements Parcelable { public class Account extends java.util.Observable implements Parcelable {
String accountID; String accountID;
private AccountDetailBasic basicDetails = null; private AccountDetailBasic basicDetails = null;
...@@ -213,4 +215,25 @@ public class Account implements Parcelable { ...@@ -213,4 +215,25 @@ public class Account implements Parcelable {
return credentialsDetails; return credentialsDetails;
} }
public void addCredential(AccountCredentials newValue) {
credentialsDetails.add(newValue);
}
public void removeCredential(AccountCredentials accountCredentials) {
credentialsDetails.remove(accountCredentials);
}
@Override
public boolean hasChanged() {
return true;
}
public List getCredentialsHashMapList() {
ArrayList<HashMap<String, String>> result = new ArrayList<HashMap<String, String>>();
for (AccountCredentials cred : credentialsDetails) {
result.add(cred.getDetailsHashMap());
}
return result;
}
} }
...@@ -34,8 +34,7 @@ import java.util.Map.Entry; ...@@ -34,8 +34,7 @@ import java.util.Map.Entry;
import java.util.Random; import java.util.Random;
import org.sflphone.R; import org.sflphone.R;
import org.sflphone.account.AccountDetailAdvanced; import org.sflphone.account.AccountCredentials;
import org.sflphone.account.AccountDetailBasic;
import org.sflphone.account.AccountDetailsHandler; import org.sflphone.account.AccountDetailsHandler;
import org.sflphone.account.CallDetailsHandler; import org.sflphone.account.CallDetailsHandler;
import org.sflphone.account.HistoryHandler; import org.sflphone.account.HistoryHandler;
...@@ -232,6 +231,7 @@ public class SipService extends Service { ...@@ -232,6 +231,7 @@ public class SipService extends Service {
System.loadLibrary("ssl"); System.loadLibrary("ssl");
System.loadLibrary("sndfile"); System.loadLibrary("sndfile");
System.loadLibrary("ccrtp1"); System.loadLibrary("ccrtp1");
System.loadLibrary("pcre");
System.loadLibrary("samplerate"); System.loadLibrary("samplerate");
System.loadLibrary("codec_ulaw"); System.loadLibrary("codec_ulaw");
System.loadLibrary("codec_alaw"); System.loadLibrary("codec_alaw");
...@@ -556,26 +556,10 @@ public class SipService extends Service { ...@@ -556,26 +556,10 @@ public class SipService extends Service {
@Override @Override
protected void doRun() throws SameThreadException { protected void doRun() throws SameThreadException {
configurationManagerJNI.setCredentials(accountId, extractCredentials(map));
configurationManagerJNI.setAccountDetails(accountId, swigmap); configurationManagerJNI.setAccountDetails(accountId, swigmap);
// convertSwigToNative(configurationManagerJNI.getCredentials(accountId));
Log.i(TAG, "SipService.setAccountDetails() thread running..."); Log.i(TAG, "SipService.setAccountDetails() thread running...");
} }
private VectMap extractCredentials(Map map) {
VectMap swigmap = new VectMap();
StringMap entry = new StringMap();
entry.set(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME, (String) map.get(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME));
if ((String) map.get(AccountDetailBasic.CONFIG_ACCOUNT_REALM) != null)
entry.set(AccountDetailBasic.CONFIG_ACCOUNT_REALM, (String) map.get(AccountDetailBasic.CONFIG_ACCOUNT_REALM));
else
entry.set(AccountDetailBasic.CONFIG_ACCOUNT_REALM, "*");
entry.set(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD, (String) map.get(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD));
swigmap.add(entry);
return swigmap;
}
}); });
} }
...@@ -1309,6 +1293,12 @@ public class SipService extends Service { ...@@ -1309,6 +1293,12 @@ public class SipService extends Service {
Log.i(TAG, "SipService.getCredentials() thread running..."); Log.i(TAG, "SipService.getCredentials() thread running...");
VectMap map = configurationManagerJNI.getCredentials(accountID); VectMap map = configurationManagerJNI.getCredentials(accountID);
ArrayList<HashMap<String, String>> result = AccountDetailsHandler.convertCredentialsToNative(map); ArrayList<HashMap<String, String>> result = AccountDetailsHandler.convertCredentialsToNative(map);
Log.i("CREDS","----------------- GET CREDENTIALS:");
for (HashMap<String, String> test : result) {
Log.i("CREDS","CONFIG_ACCOUNT_USERNAME:"+ test.get(AccountCredentials.CONFIG_ACCOUNT_USERNAME));
Log.i("CREDS","CONFIG_ACCOUNT_PASSWORD:"+ test.get(AccountCredentials.CONFIG_ACCOUNT_PASSWORD));
Log.i("CREDS","CONFIG_ACCOUNT_REALM:"+ test.get(AccountCredentials.CONFIG_ACCOUNT_REALM));
}
return result; return result;
} }
} }
...@@ -1326,6 +1316,13 @@ public class SipService extends Service { ...@@ -1326,6 +1316,13 @@ public class SipService extends Service {
@Override @Override
protected void doRun() throws SameThreadException, RemoteException { protected void doRun() throws SameThreadException, RemoteException {
Log.i(TAG, "SipService.setCredentials() thread running..."); Log.i(TAG, "SipService.setCredentials() thread running...");
Log.i("CREDS","----------------- GET CREDENTIALS:");
ArrayList<HashMap<String, String>> list = (ArrayList<HashMap<String, String>>) creds;
for (HashMap<String, String> test : list) {
Log.i("CREDS","CONFIG_ACCOUNT_USERNAME:"+ test.get(AccountCredentials.CONFIG_ACCOUNT_USERNAME));
Log.i("CREDS","CONFIG_ACCOUNT_PASSWORD:"+ test.get(AccountCredentials.CONFIG_ACCOUNT_PASSWORD));
Log.i("CREDS","CONFIG_ACCOUNT_REALM:"+ test.get(AccountCredentials.CONFIG_ACCOUNT_REALM));
}
configurationManagerJNI.setCredentials(accountID, AccountDetailsHandler.convertCredentialsToSwig(creds));; configurationManagerJNI.setCredentials(accountID, AccountDetailsHandler.convertCredentialsToSwig(creds));;
} }
}); });
......
package org.sflphone.views;
import java.util.HashMap;
import org.sflphone.R;
import org.sflphone.account.AccountCredentials;
import org.sflphone.account.CredentialsManager;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;
public class CredentialsPreference extends DialogPreference {
EditText mUsernameField, mPasswordField, mRealmField;
public CredentialsPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected View onCreateDialogView() {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.credentials_pref, null);
mUsernameField = (EditText) view.findViewById(R.id.credentials_username);
mPasswordField = (EditText) view.findViewById(R.id.credentials_password);
mRealmField = (EditText) view.findViewById(R.id.credentials_realm);
if (getExtras().getSerializable(CredentialsManager.CURRENT_CRED) != null) {
HashMap<String, String> details = (HashMap<String, String>) getExtras().getSerializable(CredentialsManager.CURRENT_CRED);
mUsernameField.setText(details.get(AccountCredentials.CONFIG_ACCOUNT_USERNAME));
mPasswordField.setText(details.get(AccountCredentials.CONFIG_ACCOUNT_PASSWORD));
mRealmField.setText(details.get(AccountCredentials.CONFIG_ACCOUNT_REALM));
}
mRealmField.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
String to = mRealmField.getText().toString();
if (to.contentEquals("")) {
mRealmField.setError(getContext().getString(R.string.dial_error_no_number_dialed));
}
return true;
}
});
return view;
}
private boolean isValid() {
return mUsernameField.getText().length() > 0 && mPasswordField.getText().length() > 0 && mRealmField.getText().length() > 0;
}
@Override
protected void showDialog(Bundle state) {
super.showDialog(state);
final AlertDialog d = (AlertDialog) getDialog();
// Prevent dismissing the dialog if they are any empty field
d.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isValid()) {
d.dismiss();
onDialogClosed(true);
} else {
Toast t = Toast.makeText(getContext(), "All fields are mandatory!", Toast.LENGTH_LONG);
t.setGravity(Gravity.CENTER, 0, 0);
t.show();
}
}
});
d.setButton(DialogInterface.BUTTON_NEUTRAL, "Delete", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Bundle toReturn = getExtras();
getOnPreferenceChangeListener().onPreferenceChange(CredentialsPreference.this, toReturn);
}
});
}
@Override
public void onPrepareDialogBuilder(Builder builder) {
if (getExtras().getSerializable(CredentialsManager.CURRENT_CRED) != null) {
// If the user is editing an entry, he can delete it, otherwise don't show this button
builder.setNeutralButton("Delete", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Bundle toReturn = getExtras();
getOnPreferenceChangeListener().onPreferenceChange(CredentialsPreference.this, toReturn);
}
});
}
super.onPrepareDialogBuilder(builder);
}
@Override
protected void onDialogClosed(boolean positiveResult) {
if (positiveResult) {
if (getExtras().getSerializable(CredentialsManager.CURRENT_CRED) != null) {
Bundle toReturn = getExtras();
HashMap<String, String> fields = new HashMap<String, String>();
fields.put(AccountCredentials.CONFIG_ACCOUNT_USERNAME, mUsernameField.getText().toString());
fields.put(AccountCredentials.CONFIG_ACCOUNT_PASSWORD, mPasswordField.getText().toString());
fields.put(AccountCredentials.CONFIG_ACCOUNT_REALM, mRealmField.getText().toString());
toReturn.putSerializable(CredentialsManager.NEW_CRED, fields);
getOnPreferenceChangeListener().onPreferenceChange(this, toReturn);
} else {
HashMap<String, String> fields = new HashMap<String, String>();
fields.put(AccountCredentials.CONFIG_ACCOUNT_USERNAME, mUsernameField.getText().toString());
fields.put(AccountCredentials.CONFIG_ACCOUNT_PASSWORD, mPasswordField.getText().toString());
fields.put(AccountCredentials.CONFIG_ACCOUNT_REALM, mRealmField.getText().toString());
getOnPreferenceChangeListener().onPreferenceChange(this, new AccountCredentials(fields));
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment