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

* #36666: new PasswordPreference based on CyanogenMod source code

parent f30ff854
Branches
Tags
No related merge requests found
...@@ -70,10 +70,6 @@ as that of the covered work. ...@@ -70,10 +70,6 @@ as that of the covered work.
android:name="android.hardware.screen.portrait" android:name="android.hardware.screen.portrait"
android:required="false" /> android:required="false" />
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@drawable/ic_launcher" android:icon="@drawable/ic_launcher"
...@@ -128,19 +124,24 @@ as that of the covered work. ...@@ -128,19 +124,24 @@ as that of the covered work.
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" /> <data android:scheme="tel" />
<data android:mimeType="vnd.android.cursor.item/phone" />
<data android:mimeType="vnd.android.cursor.item/phone_v2" />
<data android:mimeType="vnd.android.cursor.item/person" />
</intent-filter> </intent-filter>
</activity> <intent-filter>
<action android:name="android.intent.action.CALL" />
<!-- <receiver -->
<!-- android:name="org.sflphone.receivers.ExternalCallReceiver" -->
<!-- android:exported="true" > -->
<!-- <intent-filter> -->
<!-- <action android:name="android.intent.action.NEW_OUTGOING_CALL" /> -->
<category android:name="android.intent.category.DEFAULT" />
<!-- <category android:name="android.intent.category.DEFAULT" /> --> <data android:scheme="tel" />
<!-- </intent-filter> --> <data android:mimeType="vnd.android.cursor.item/phone" />
<!-- </receiver> --> <data android:mimeType="vnd.android.cursor.item/phone_v2" />
<data android:mimeType="vnd.android.cursor.item/person" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</activity>
<service <service
android:name="org.sflphone.service.SipService" android:name="org.sflphone.service.SipService"
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
<string name="account_useragent_label">User-agent</string> <string name="account_useragent_label">User-agent</string>
<string name="account_proxy_field">Proxy</string> <string name="account_proxy_field">Proxy</string>
<string name="account_autoanswer_label">Décroche automatiquement l\'appel</string> <string name="account_autoanswer_label">Décroche automatiquement l\'appel</string>
<string name="show_password">Voir mot de passe</string>
<!-- Audio Details --> <!-- Audio Details -->
<string name="account_preferences_audio_tab">Audio</string> <string name="account_preferences_audio_tab">Audio</string>
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
<string name="account_useragent_label">User Agent</string> <string name="account_useragent_label">User Agent</string>
<string name="account_autoanswer_label">Auto Answer</string> <string name="account_autoanswer_label">Auto Answer</string>
<string name="account_proxy_field">Proxy</string> <string name="account_proxy_field">Proxy</string>
<string name="show_password">Show password</string>
<!-- Audio Details --> <!-- Audio Details -->
<string name="account_preferences_audio_tab">Audio</string> <string name="account_preferences_audio_tab">Audio</string>
......
...@@ -53,7 +53,7 @@ as that of the covered work. ...@@ -53,7 +53,7 @@ as that of the covered work.
android:persistent="false" android:persistent="false"
android:summary="" android:summary=""
android:title="@string/account_username_label" /> android:title="@string/account_username_label" />
<EditTextPreference <org.sflphone.views.PasswordPreference
android:id="@+id/account_password" android:id="@+id/account_password"
android:key="Account.password" android:key="Account.password"
android:persistent="false" android:persistent="false"
......
...@@ -3,6 +3,7 @@ package org.sflphone.fragments; ...@@ -3,6 +3,7 @@ package org.sflphone.fragments;
import org.sflphone.R; import org.sflphone.R;
import org.sflphone.account.AccountDetail; import org.sflphone.account.AccountDetail;
import org.sflphone.model.Account; import org.sflphone.model.Account;
import org.sflphone.views.PasswordPreference;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
...@@ -66,7 +67,16 @@ public class GeneralAccountFragment extends PreferenceFragment { ...@@ -66,7 +67,16 @@ public class GeneralAccountFragment extends PreferenceFragment {
if (pref != null) { if (pref != null) {
if (!p.isTwoState) { if (!p.isTwoState) {
((EditTextPreference) pref).setText(p.mValue); ((EditTextPreference) pref).setText(p.mValue);
if (pref instanceof PasswordPreference) {
String tmp = new String();
for (int i = 0; i < p.mValue.length(); ++i) {
tmp += "*";
}
pref.setSummary(tmp);
} else {
pref.setSummary(p.mValue); pref.setSummary(p.mValue);
}
} else { } else {
((CheckBoxPreference) pref).setChecked(p.isChecked()); ((CheckBoxPreference) pref).setChecked(p.isChecked());
} }
......
...@@ -42,7 +42,7 @@ import android.util.Log; ...@@ -42,7 +42,7 @@ import android.util.Log;
* @author lisional * @author lisional
* *
*/ */
public class ExternalCallReceiver extends BroadcastReceiver public class OutgoingCallReceiver extends BroadcastReceiver
{ {
@Override @Override
......
package org.sflphone.views;
import org.sflphone.R;
import org.sflphone.utils.Compatibility;
import android.content.Context;
import android.view.View.OnClickListener;
import android.preference.EditTextPreference;
import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.CheckBox;
import android.widget.EditText;
public class PasswordPreference extends EditTextPreference implements OnClickListener, TextWatcher {
private static final String THIS_FILE = "PasswordPreference";
private CheckBox showPwdCheckbox;
private boolean canShowPassword = false;
public PasswordPreference(Context context) {
this(context, null);
}
public PasswordPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onAddEditTextToDialogView(View dialogView, EditText editText) {
super.onAddEditTextToDialogView(dialogView, editText);
editText.addTextChangedListener(this);
}
@Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
try {
if (showPwdCheckbox == null) {
showPwdCheckbox = new CheckBox(getContext());
showPwdCheckbox.setText(R.string.show_password);
showPwdCheckbox.setOnClickListener(this);
}
canShowPassword = TextUtils.isEmpty(getText());
getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
updateCanShowPassword();
ViewParent oldParent = showPwdCheckbox.getParent();
if (oldParent != view) {
if (oldParent != null) {
((ViewGroup) oldParent).removeView(showPwdCheckbox);
}
}
ViewGroup container = (ViewGroup) view;
if (Compatibility.isCompatible(8)) {
container = (ViewGroup) container.getChildAt(0);
}
if (container != null) {
container.addView(showPwdCheckbox, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
} catch (Exception e) {
// Just do nothing in case weird ROM in use
Log.w(THIS_FILE, "Unsupported device for enhanced password", e);
}
}
@Override
public void onClick(View view) {
if (!canShowPassword) {
// Even if not shown, be very very sure we never come here
return;
}
getEditText().setInputType(
InputType.TYPE_CLASS_TEXT
| (((CheckBox) view).isChecked() ? InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD : InputType.TYPE_TEXT_VARIATION_PASSWORD));
}
@Override
public void setText(String text) {
super.setText(text);
setCanShowPassword(TextUtils.isEmpty(text));
}
private void updateCanShowPassword() {
if (showPwdCheckbox != null) {
showPwdCheckbox.setVisibility(canShowPassword ? View.VISIBLE : View.GONE);
}
}
private void setCanShowPassword(boolean canShow) {
canShowPassword = canShow;
updateCanShowPassword();
}
@Override
public void afterTextChanged(Editable s) {
if (s.length() == 0) {
setCanShowPassword(true);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Nothing to do
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Nothing to do
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment