Fix contact edit
This commit is contained in:
parent
660642a71c
commit
12b4d76831
2 changed files with 38 additions and 39 deletions
|
@ -64,10 +64,10 @@ public class ContactEditorFragment extends Fragment {
|
||||||
private LinearLayout phoneNumbersSection, sipAddressesSection;
|
private LinearLayout phoneNumbersSection, sipAddressesSection;
|
||||||
private EditText firstName, lastName, organization;
|
private EditText firstName, lastName, organization;
|
||||||
private LayoutInflater inflater;
|
private LayoutInflater inflater;
|
||||||
|
|
||||||
private static final int ADD_PHOTO = 1337;
|
private static final int ADD_PHOTO = 1337;
|
||||||
private static final int PHOTO_SIZE = 128;
|
private static final int PHOTO_SIZE = 128;
|
||||||
|
|
||||||
private boolean isNewContact;
|
private boolean isNewContact;
|
||||||
private LinphoneContact contact;
|
private LinphoneContact contact;
|
||||||
private List<LinphoneNumberOrAddress> numbersAndAddresses;
|
private List<LinphoneNumberOrAddress> numbersAndAddresses;
|
||||||
|
@ -79,10 +79,10 @@ public class ContactEditorFragment extends Fragment {
|
||||||
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
this.inflater = inflater;
|
this.inflater = inflater;
|
||||||
|
|
||||||
contact = null;
|
contact = null;
|
||||||
isNewContact = true;
|
isNewContact = true;
|
||||||
|
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
Serializable obj = getArguments().getSerializable("Contact");
|
Serializable obj = getArguments().getSerializable("Contact");
|
||||||
if (obj != null) {
|
if (obj != null) {
|
||||||
|
@ -97,18 +97,18 @@ public class ContactEditorFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
view = inflater.inflate(R.layout.contact_edit, container, false);
|
view = inflater.inflate(R.layout.contact_edit, container, false);
|
||||||
|
|
||||||
phoneNumbersSection = (LinearLayout) view.findViewById(R.id.phone_numbers);
|
phoneNumbersSection = (LinearLayout) view.findViewById(R.id.phone_numbers);
|
||||||
if (getResources().getBoolean(R.bool.hide_phone_numbers_in_editor) || !ContactsManager.getInstance().hasContactsAccess()) {
|
if (getResources().getBoolean(R.bool.hide_phone_numbers_in_editor) || !ContactsManager.getInstance().hasContactsAccess()) {
|
||||||
//Currently linphone friends don't support phone numbers, so hide them
|
//Currently linphone friends don't support phone numbers, so hide them
|
||||||
phoneNumbersSection.setVisibility(View.GONE);
|
phoneNumbersSection.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
sipAddressesSection = (LinearLayout) view.findViewById(R.id.sip_addresses);
|
sipAddressesSection = (LinearLayout) view.findViewById(R.id.sip_addresses);
|
||||||
if (getResources().getBoolean(R.bool.hide_sip_addresses_in_editor)) {
|
if (getResources().getBoolean(R.bool.hide_sip_addresses_in_editor)) {
|
||||||
sipAddressesSection.setVisibility(View.GONE);
|
sipAddressesSection.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
deleteContact = (ImageView) view.findViewById(R.id.delete_contact);
|
deleteContact = (ImageView) view.findViewById(R.id.delete_contact);
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
getFragmentManager().popBackStackImmediate();
|
getFragmentManager().popBackStackImmediate();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
lastName = (EditText) view.findViewById(R.id.contactLastName);
|
lastName = (EditText) view.findViewById(R.id.contactLastName);
|
||||||
// Hack to display keyboard when touching focused edittext on Nexus One
|
// Hack to display keyboard when touching focused edittext on Nexus One
|
||||||
if (Version.sdkStrictlyBelow(Version.API11_HONEYCOMB_30)) {
|
if (Version.sdkStrictlyBelow(Version.API11_HONEYCOMB_30)) {
|
||||||
|
@ -174,16 +174,16 @@ public class ContactEditorFragment extends Fragment {
|
||||||
ok.setEnabled(false);
|
ok.setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
firstName = (EditText) view.findViewById(R.id.contactFirstName);
|
firstName = (EditText) view.findViewById(R.id.contactFirstName);
|
||||||
firstName.addTextChangedListener(new TextWatcher() {
|
firstName.addTextChangedListener(new TextWatcher() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -194,16 +194,16 @@ public class ContactEditorFragment extends Fragment {
|
||||||
ok.setEnabled(false);
|
ok.setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
organization = (EditText) view.findViewById(R.id.contactOrganization);
|
organization = (EditText) view.findViewById(R.id.contactOrganization);
|
||||||
boolean isOrgVisible = getResources().getBoolean(R.bool.display_contact_organization);
|
boolean isOrgVisible = getResources().getBoolean(R.bool.display_contact_organization);
|
||||||
|
@ -226,7 +226,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
lastName.setText(contact.getFullName());
|
lastName.setText(contact.getFullName());
|
||||||
firstName.setText("");
|
firstName.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteContact.setOnClickListener(new OnClickListener() {
|
deleteContact.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
@ -299,10 +299,10 @@ public class ContactEditorFragment extends Fragment {
|
||||||
});
|
});
|
||||||
|
|
||||||
lastName.requestFocus();
|
lastName.requestFocus();
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
@ -388,7 +388,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
image = BitmapFactory.decodeFile(filePath);
|
image = BitmapFactory.decodeFile(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap scaledPhoto;
|
Bitmap scaledPhoto;
|
||||||
int size = getThumbnailSize();
|
int size = getThumbnailSize();
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
|
@ -397,13 +397,13 @@ public class ContactEditorFragment extends Fragment {
|
||||||
scaledPhoto = Bitmap.createBitmap(image);
|
scaledPhoto = Bitmap.createBitmap(image);
|
||||||
}
|
}
|
||||||
image.recycle();
|
image.recycle();
|
||||||
|
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
scaledPhoto.compress(Bitmap.CompressFormat.PNG , 0, stream);
|
scaledPhoto.compress(Bitmap.CompressFormat.PNG , 0, stream);
|
||||||
contactPicture.setImageBitmap(scaledPhoto);
|
contactPicture.setImageBitmap(scaledPhoto);
|
||||||
photoToAdd = stream.toByteArray();
|
photoToAdd = stream.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getThumbnailSize() {
|
private int getThumbnailSize() {
|
||||||
int value = -1;
|
int value = -1;
|
||||||
Cursor c = LinphoneActivity.instance().getContentResolver().query(DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI, new String[] { DisplayPhoto.THUMBNAIL_MAX_DIM }, null, null, null);
|
Cursor c = LinphoneActivity.instance().getContentResolver().query(DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI, new String[] { DisplayPhoto.THUMBNAIL_MAX_DIM }, null, null, null);
|
||||||
|
@ -415,11 +415,11 @@ public class ContactEditorFragment extends Fragment {
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private LinearLayout initNumbersFields(final LinphoneContact contact) {
|
private LinearLayout initNumbersFields(final LinphoneContact contact) {
|
||||||
LinearLayout controls = (LinearLayout) view.findViewById(R.id.controls_numbers);
|
LinearLayout controls = (LinearLayout) view.findViewById(R.id.controls_numbers);
|
||||||
controls.removeAllViews();
|
controls.removeAllViews();
|
||||||
|
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
for (LinphoneNumberOrAddress numberOrAddress : contact.getNumbersOrAddresses()) {
|
for (LinphoneNumberOrAddress numberOrAddress : contact.getNumbersOrAddresses()) {
|
||||||
if (!numberOrAddress.isSIPAddress()) {
|
if (!numberOrAddress.isSIPAddress()) {
|
||||||
|
@ -475,18 +475,19 @@ public class ContactEditorFragment extends Fragment {
|
||||||
|
|
||||||
return controls;
|
return controls;
|
||||||
}
|
}
|
||||||
|
|
||||||
private View displayNumberOrAddress(final LinearLayout controls, String numberOrAddress, boolean isSIP) {
|
private View displayNumberOrAddress(final LinearLayout controls, String numberOrAddress, boolean isSIP) {
|
||||||
return displayNumberOrAddress(controls, numberOrAddress, isSIP, false);
|
return displayNumberOrAddress(controls, numberOrAddress, isSIP, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
private View displayNumberOrAddress(final LinearLayout controls, String numberOrAddress, boolean isSIP, boolean forceAddNumber) {
|
private View displayNumberOrAddress(final LinearLayout controls, String numberOrAddress, boolean isSIP, boolean forceAddNumber) {
|
||||||
|
String displayNumberOrAddress = numberOrAddress;
|
||||||
if (isSIP) {
|
if (isSIP) {
|
||||||
if (firstSipAddressIndex == -1) {
|
if (firstSipAddressIndex == -1) {
|
||||||
firstSipAddressIndex = controls.getChildCount();
|
firstSipAddressIndex = controls.getChildCount();
|
||||||
}
|
}
|
||||||
numberOrAddress = LinphoneUtils.getDisplayableUsernameFromAddress(numberOrAddress);
|
displayNumberOrAddress = LinphoneUtils.getDisplayableUsernameFromAddress(numberOrAddress);
|
||||||
}
|
}
|
||||||
if ((getResources().getBoolean(R.bool.hide_phone_numbers_in_editor) && !isSIP) || (getResources().getBoolean(R.bool.hide_sip_addresses_in_editor) && isSIP)) {
|
if ((getResources().getBoolean(R.bool.hide_phone_numbers_in_editor) && !isSIP) || (getResources().getBoolean(R.bool.hide_sip_addresses_in_editor) && isSIP)) {
|
||||||
if (forceAddNumber)
|
if (forceAddNumber)
|
||||||
|
@ -494,7 +495,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
LinphoneNumberOrAddress tempNounoa;
|
LinphoneNumberOrAddress tempNounoa;
|
||||||
if (forceAddNumber) {
|
if (forceAddNumber) {
|
||||||
tempNounoa = new LinphoneNumberOrAddress(null, isSIP);
|
tempNounoa = new LinphoneNumberOrAddress(null, isSIP);
|
||||||
|
@ -507,24 +508,24 @@ public class ContactEditorFragment extends Fragment {
|
||||||
}
|
}
|
||||||
final LinphoneNumberOrAddress nounoa = tempNounoa;
|
final LinphoneNumberOrAddress nounoa = tempNounoa;
|
||||||
numbersAndAddresses.add(nounoa);
|
numbersAndAddresses.add(nounoa);
|
||||||
|
|
||||||
final View view = inflater.inflate(R.layout.contact_edit_row, null);
|
final View view = inflater.inflate(R.layout.contact_edit_row, null);
|
||||||
|
|
||||||
final EditText noa = (EditText) view.findViewById(R.id.numoraddr);
|
final EditText noa = (EditText) view.findViewById(R.id.numoraddr);
|
||||||
if (!isSIP) {
|
if (!isSIP) {
|
||||||
noa.setInputType(InputType.TYPE_CLASS_PHONE);
|
noa.setInputType(InputType.TYPE_CLASS_PHONE);
|
||||||
}
|
}
|
||||||
noa.setText(numberOrAddress);
|
noa.setText(displayNumberOrAddress);
|
||||||
noa.addTextChangedListener(new TextWatcher() {
|
noa.addTextChangedListener(new TextWatcher() {
|
||||||
@Override
|
@Override
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
nounoa.setValue(noa.getText().toString());
|
nounoa.setValue(noa.getText().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
}
|
}
|
||||||
|
@ -532,7 +533,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
if (forceAddNumber) {
|
if (forceAddNumber) {
|
||||||
nounoa.setValue(noa.getText().toString());
|
nounoa.setValue(noa.getText().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageView delete = (ImageView) view.findViewById(R.id.delete_field);
|
ImageView delete = (ImageView) view.findViewById(R.id.delete_field);
|
||||||
if ((getResources().getBoolean(R.bool.allow_only_one_phone_number) && !isSIP) || (getResources().getBoolean(R.bool.allow_only_one_sip_address) && isSIP)) {
|
if ((getResources().getBoolean(R.bool.allow_only_one_phone_number) && !isSIP) || (getResources().getBoolean(R.bool.allow_only_one_sip_address) && isSIP)) {
|
||||||
delete.setVisibility(View.GONE);
|
delete.setVisibility(View.GONE);
|
||||||
|
@ -550,12 +551,12 @@ public class ContactEditorFragment extends Fragment {
|
||||||
});
|
});
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
private void addEmptyRowToAllowNewNumberOrAddress(final LinearLayout controls, final boolean isSip) {
|
private void addEmptyRowToAllowNewNumberOrAddress(final LinearLayout controls, final boolean isSip) {
|
||||||
final View view = inflater.inflate(R.layout.contact_edit_row, null);
|
final View view = inflater.inflate(R.layout.contact_edit_row, null);
|
||||||
final LinphoneNumberOrAddress nounoa = new LinphoneNumberOrAddress(null, isSip);
|
final LinphoneNumberOrAddress nounoa = new LinphoneNumberOrAddress(null, isSip);
|
||||||
|
|
||||||
final EditText noa = (EditText) view.findViewById(R.id.numoraddr);
|
final EditText noa = (EditText) view.findViewById(R.id.numoraddr);
|
||||||
numbersAndAddresses.add(nounoa);
|
numbersAndAddresses.add(nounoa);
|
||||||
noa.setHint(isSip ? getString(R.string.sip_address) : getString(R.string.phone_number));
|
noa.setHint(isSip ? getString(R.string.sip_address) : getString(R.string.phone_number));
|
||||||
|
@ -568,16 +569,16 @@ public class ContactEditorFragment extends Fragment {
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
nounoa.setValue(noa.getText().toString());
|
nounoa.setValue(noa.getText().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
final ImageView delete = (ImageView) view.findViewById(R.id.delete_field);
|
final ImageView delete = (ImageView) view.findViewById(R.id.delete_field);
|
||||||
if ((getResources().getBoolean(R.bool.allow_only_one_phone_number) && !isSip) || (getResources().getBoolean(R.bool.allow_only_one_sip_address) && isSip)) {
|
if ((getResources().getBoolean(R.bool.allow_only_one_phone_number) && !isSip) || (getResources().getBoolean(R.bool.allow_only_one_sip_address) && isSip)) {
|
||||||
delete.setVisibility(View.GONE);
|
delete.setVisibility(View.GONE);
|
||||||
|
|
|
@ -1253,8 +1253,6 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
if (readContactsI >= 0 && grantResults[readContactsI] == PackageManager.PERMISSION_GRANTED) {
|
if (readContactsI >= 0 && grantResults[readContactsI] == PackageManager.PERMISSION_GRANTED) {
|
||||||
ContactsManager.getInstance().enableContactsAccess();
|
ContactsManager.getInstance().enableContactsAccess();
|
||||||
}
|
}
|
||||||
ContactsManager.getInstance().fetchContactsAsync();
|
|
||||||
ContactsManager.getInstance().enableContactsAccess();
|
|
||||||
if (!fetchedContactsOnce) {
|
if (!fetchedContactsOnce) {
|
||||||
ContactsManager.getInstance().enableContactsAccess();
|
ContactsManager.getInstance().enableContactsAccess();
|
||||||
ContactsManager.getInstance().fetchContactsAsync();
|
ContactsManager.getInstance().fetchContactsAsync();
|
||||||
|
|
Loading…
Reference in a new issue