Wizard updated + overview accounts slider

This commit is contained in:
Sylvain Berfini 2012-02-02 17:12:28 +01:00
parent 3a9f1e5e3c
commit caa668604b
6 changed files with 238 additions and 11 deletions

19
res/layout/accounts.xml Normal file
View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:orientation="horizontal"
android:gravity="center" android:layout_height="fill_parent">
<ImageView
android:id="@+id/State"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:id="@+id/Identity"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="4"/>
</LinearLayout>

View file

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:linphone="http://schemas.android.com/apk/res/linphone"
@ -7,17 +8,93 @@
<LinearLayout android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="@+id/Addresslayout">
<org.linphone.ui.AddressText android:id="@+id/SipUri" android:background="@drawable/clavier_bg_grey" android:hint="sip:" android:layout_width="fill_parent"
android:singleLine="true" android:lines="1" android:layout_weight="0.2" android:layout_height="fill_parent" android:padding="10px" android:maxLines="1" android:editable="@bool/allow_edit_in_dialer"/>
<org.linphone.ui.EraseButton android:layout_height="fill_parent" android:background="@drawable/clavier_bg" android:id="@+id/Erase"
android:layout_width="fill_parent" android:layout_weight="0.8" android:textSize="20sp"
android:textStyle="bold" android:text="&lt;" android:layout_gravity="top" android:textColor="@android:color/black"/>
</LinearLayout>
<org.linphone.ui.Numpad android:id="@+id/Dialer" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="4" />
<FrameLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="23sp">
<org.linphone.ui.Numpad
android:id="@+id/Dialer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="4" />
<LinearLayout
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_weight="1">
<org.linphone.ui.CallButton
android:id="@+id/Call"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:src="@drawable/startcall_green"
android:background="@drawable/clavier_bg" />
</LinearLayout>
</LinearLayout>
<SlidingDrawer
android:id="@+id/drawer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:handle="@+id/handle"
android:layout_weight="1"
android:content="@+id/accounts">
<LinearLayout
android:id="@id/handle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#000000"
android:gravity="center_vertical">
<EditText
android:id="@+id/status_label"
android:clickable="false"
android:focusable="false"
android:cursorVisible="false"
android:textSize="12sp"
android:background="#000000"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="4"
android:textColor="@android:color/white" />
<ImageView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="100"
android:src="@drawable/conf_details"/>
</LinearLayout>
<ListView
android:id="@id/accounts"
android:background="#CC000000"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</SlidingDrawer>
</FrameLayout>
<LinearLayout android:layout_height="wrap_content" android:orientation="vertical" android:layout_width="fill_parent">
<org.linphone.ui.CallButton android:id="@+id/Call" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="1" android:src="@drawable/startcall_green" android:background="@drawable/clavier_bg"/>
<EditText android:id="@+id/status_label" android:clickable="false" android:focusable="false" android:cursorVisible="false" android:textSize="12sp" android:height="15sp" android:layout_height="wrap_content" android:layout_width="fill_parent" android:background="@android:color/transparent" android:textColor="@android:color/white" />
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/wizardConfirm"
android:text="@string/wizard_need_activation"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:id="@+id/wizardCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wizard_cancel"/>
<Button
android:id="@+id/wizardCheckAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wizard_verify_account"/>
</LinearLayout>
</LinearLayout>

View file

@ -243,4 +243,6 @@
<string name="wizard_password_incorrect">Your password is not valid (6 characters min).</string>
<string name="wizard_passwords_unmatched">Passwords entered are different.</string>
<string name="wizard_need_activation">You need to activate your account with the link that was send to your email.</string>
<string name="wizard_confirmation">Confirmation</string>
<string name="wizard_verify_account">Check</string>
</resources>

View file

@ -18,10 +18,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone;
import java.util.ArrayList;
import java.util.HashMap;
import org.linphone.LinphoneService.LinphoneGuiListener;
import org.linphone.core.LinphoneCall;
import org.linphone.core.Log;
import org.linphone.core.LinphoneCall.State;
import org.linphone.core.LinphoneCore.RegistrationState;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.Log;
import org.linphone.ui.AddressAware;
import org.linphone.ui.AddressText;
import org.linphone.ui.CallButton;
@ -32,6 +37,12 @@ import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.Adapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.SlidingDrawer;
import android.widget.SlidingDrawer.OnDrawerScrollListener;
import android.widget.TextView;
import android.widget.Toast;
@ -68,6 +79,37 @@ public class DialerActivity extends Activity implements LinphoneGuiListener {
return instance;
}
private String getStatusIcon(RegistrationState state) {
if (state == RegistrationState.RegistrationOk)
return Integer.toString(R.drawable.status_green);
else if (state == RegistrationState.RegistrationNone)
return Integer.toString(R.drawable.status_red);
else if (state == RegistrationState.RegistrationProgress)
return Integer.toString(R.drawable.status_orange);
else
return Integer.toString(R.drawable.status_offline);
}
private void displayRegisterStatus() {
ListView accounts = (ListView) findViewById(R.id.accounts);
accounts.setDividerHeight(0);
ArrayList<HashMap<String,String>> hashMapAccountsStateList = new ArrayList<HashMap<String,String>>();
for (LinphoneProxyConfig lpc : LinphoneManager.getLc().getProxyConfigList()) {
HashMap<String, String> entitiesHashMap = new HashMap<String, String>();
entitiesHashMap.put("Identity", lpc.getIdentity().split("sip:")[1]);
entitiesHashMap.put("State", getStatusIcon(lpc.getState()));
hashMapAccountsStateList.add(entitiesHashMap);
}
Adapter adapterForList = new SimpleAdapter(this, hashMapAccountsStateList, R.layout.accounts,
new String[] {"Identity", "State"},
new int[] { R.id.Identity, R.id.State });
accounts.setAdapter((ListAdapter) adapterForList);
accounts.invalidate();
}
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.dialer);
@ -80,6 +122,17 @@ public class DialerActivity extends Activity implements LinphoneGuiListener {
mStatus = (TextView) findViewById(R.id.status_label);
SlidingDrawer drawer = (SlidingDrawer) findViewById(R.id.drawer);
drawer.setOnDrawerScrollListener(new OnDrawerScrollListener() {
public void onScrollEnded() {
}
public void onScrollStarted() {
displayRegisterStatus();
}
});
AddressAware numpad = (AddressAware) findViewById(R.id.Dialer);
if (numpad != null)
numpad.setAddressWidget(mAddress);
@ -98,6 +151,7 @@ public class DialerActivity extends Activity implements LinphoneGuiListener {
instance = this;
super.onCreate(savedInstanceState);
displayRegisterStatus();
}

View file

@ -69,7 +69,6 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import de.timroes.axmlrpc.XMLRPCCallback;
import de.timroes.axmlrpc.XMLRPCClient;
import de.timroes.axmlrpc.XMLRPCException;
@ -91,9 +90,11 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
private Button createAccount;
private TextView errorMessage;
private PreferenceCategory accounts;
private String username;
private static final int ADD_SIP_ACCOUNT = 0x666;
private static final int WIZARD_ID = 0x667;
private static final int CONFIRM_ID = 0x668;
private SharedPreferences prefs() {
return getPreferenceManager().getSharedPreferences();
@ -253,6 +254,33 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
wizardDialog = builder.create();
return wizardDialog;
}
else if (id == CONFIRM_ID) {
AlertDialog.Builder builder = new AlertDialog.Builder(LinphonePreferencesActivity.this);
builder.setTitle(R.string.wizard_confirmation);
LayoutInflater inflater = LayoutInflater.from(LinphonePreferencesActivity.this);
View v = inflater.inflate(R.layout.wizard_confirm, null);
builder.setView(v);
Button check = (Button) v.findViewById(R.id.wizardCheckAccount);
check.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (isAccountVerified(username)) {
wizardDialog.dismiss();
}
}
});
Button cancel = (Button) v.findViewById(R.id.wizardCancel);
cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
wizardDialog.dismiss();
}
});
wizardDialog = builder.create();
return wizardDialog;
}
return null;
}
@ -260,6 +288,19 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
return username.matches("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{2,}$");
}
private boolean isAccountVerified(String username) {
try {
XMLRPCClient client = new XMLRPCClient(new URL("https://www.linphone.org/wizard.php"));
Object resultO = client.call("check_account_validated", "sip:" + username + "@sip.linphone.org");
Integer result = Integer.parseInt(resultO.toString());
return result == 1;
} catch(Exception ex) {
}
return false;
}
private void isUsernameRegistred(String username, final ImageView icon) {
final Runnable runNotReachable = new Runnable() {
public void run() {
@ -346,12 +387,13 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
Runnable runOk = new Runnable() {
public void run() {
addExtraAccountPreferencesButton(accounts, nbAccounts, true);
LinphonePreferencesActivity.this.username = username;
fillLinphoneAccount(nbAccounts, username, password);
nbAccounts++;
createDynamicAccountsPreferences();
wizardDialog.dismiss();
Toast.makeText(LinphonePreferencesActivity.this, R.string.wizard_need_activation, Toast.LENGTH_LONG).show();
showDialog(CONFIRM_ID);
}
};