Feature to auto fill email filed in wizard using google account email

This commit is contained in:
Sylvain Berfini 2013-06-18 15:24:39 +02:00
parent ae9dcdfc65
commit 1b638b780d
4 changed files with 23 additions and 2 deletions

View file

@ -34,6 +34,8 @@
<!-- Needed to route the audio to the bluetooth headset if available -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<!-- Needed to pre fill the wizard email field (only if enabled in custom settings) -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true"/>

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/topLayout"
xmlns:linphone="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -68,6 +69,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="80dip" />
android:layout_marginBottom="80dp" />
</RelativeLayout>

View file

@ -51,6 +51,7 @@
<bool name="disable_options_in_call">false</bool>
<!-- Behavior Settings -->
<bool name="pre_fill_email_in_wizard">true</bool> <!-- Set the email field of the wizard with one of the gmail account registered on the device -->
<bool name="allow_chat_multiline">false</bool>
<bool name="call_last_log_if_adress_is_empty">true</bool>
<bool name="allow_ringing_while_early_media">true</bool>

View file

@ -18,17 +18,21 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
import java.net.URL;
import java.util.regex.Pattern;
import org.linphone.LinphoneManager;
import org.linphone.LinphoneService;
import org.linphone.R;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Patterns;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@ -86,6 +90,18 @@ public class WizardFragment extends Fragment {
}
});
if (getResources().getBoolean(R.bool.pre_fill_email_in_wizard)) {
Account[] accounts = AccountManager.get(getActivity()).getAccountsByType("com.google");
for (Account account: accounts) {
if (isEmailCorrect(account.name)) {
String possibleEmail = account.name;
email.setText(possibleEmail);
break;
}
}
}
return view;
}
@ -152,7 +168,8 @@ public class WizardFragment extends Fragment {
}
private boolean isEmailCorrect(String email) {
return email.matches("^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,}$");
Pattern emailPattern = Patterns.EMAIL_ADDRESS;
return emailPattern.matcher(email).matches();
}
private boolean isPasswordCorrect(String password) {