Moved delete contact button + fix for delete + removed warnings in other code

This commit is contained in:
Sylvain Berfini 2014-11-25 11:03:37 +01:00
parent 129140f945
commit e462133076
9 changed files with 71 additions and 71 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/contact_delete_over" />
<item
android:drawable="@drawable/contact_delete_default" />
</selector>

View file

@ -11,6 +11,20 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView
android:contentDescription="@string/content_description_delete"
android:id="@+id/deleteContact"
android:background="@drawable/contact_delete"
android:text="@string/button_delete_all"
android:gravity="center"
android:paddingTop="20dp"
android:textColor="@drawable/text_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:layout_weight="1"/>
<TextView <TextView
android:contentDescription="@string/content_description_edit" android:contentDescription="@string/content_description_edit"
android:id="@+id/editContact" android:id="@+id/editContact"
@ -25,20 +39,6 @@
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:layout_weight="1"/> android:layout_weight="1"/>
<!-- <TextView
android:contentDescription="@string/content_description_add_contact"
android:id="@+id/newContact"
android:background="@drawable/contact_add_contact"
android:text="@string/button_add_contact"
android:gravity="center"
android:paddingTop="20dp"
android:textColor="@color/text_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:layout_weight="1"/> -->
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout

View file

@ -11,6 +11,20 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView
android:contentDescription="@string/content_description_delete"
android:id="@+id/deleteContact"
android:background="@drawable/contact_delete"
android:text="@string/button_delete_all"
android:gravity="center"
android:paddingTop="20dp"
android:textColor="@drawable/text_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:layout_weight="1"/>
<TextView <TextView
android:contentDescription="@string/content_description_edit" android:contentDescription="@string/content_description_edit"
android:id="@+id/editContact" android:id="@+id/editContact"
@ -21,6 +35,7 @@
android:textColor="@drawable/text_button" android:textColor="@drawable/text_button"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="centerCrop" android:scaleType="centerCrop"
android:adjustViewBounds="true"/> android:adjustViewBounds="true"/>

View file

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/delete_contact"
android:background="@drawable/alert"
android:textColor="@android:color/white"
android:gravity="center"
android:textSize="30dp"
android:textStyle="bold"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_margin="30dp">
</TextView>

View file

@ -18,13 +18,16 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList;
import org.linphone.compatibility.Compatibility; import org.linphone.compatibility.Compatibility;
import org.linphone.core.LinphoneProxyConfig; import org.linphone.core.LinphoneProxyConfig;
import org.linphone.mediastream.Log;
import org.linphone.ui.AvatarWithShadow; import org.linphone.ui.AvatarWithShadow;
import android.annotation.SuppressLint;
import android.content.ContentProviderOperation;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.os.Bundle; import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -39,7 +42,7 @@ import android.widget.TextView;
*/ */
public class ContactFragment extends Fragment implements OnClickListener { public class ContactFragment extends Fragment implements OnClickListener {
private Contact contact; private Contact contact;
private TextView editContact; private TextView editContact, deleteContact;
private LayoutInflater inflater; private LayoutInflater inflater;
private View view; private View view;
private boolean displayChatAddressOnly = false; private boolean displayChatAddressOnly = false;
@ -74,6 +77,9 @@ public class ContactFragment extends Fragment implements OnClickListener {
editContact = (TextView) view.findViewById(R.id.editContact); editContact = (TextView) view.findViewById(R.id.editContact);
editContact.setOnClickListener(this); editContact.setOnClickListener(this);
deleteContact = (TextView) view.findViewById(R.id.deleteContact);
deleteContact.setOnClickListener(this);
return view; return view;
} }
@ -83,6 +89,7 @@ public class ContactFragment extends Fragment implements OnClickListener {
displayContact(inflater, view); displayContact(inflater, view);
} }
@SuppressLint("InflateParams")
private void displayContact(LayoutInflater inflater, View view) { private void displayContact(LayoutInflater inflater, View view) {
AvatarWithShadow contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture); AvatarWithShadow contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);
if (contact.getPhotoUri() != null) { if (contact.getPhotoUri() != null) {
@ -195,6 +202,27 @@ public class ContactFragment extends Fragment implements OnClickListener {
if (id == R.id.editContact) { if (id == R.id.editContact) {
LinphoneActivity.instance().editContact(contact); LinphoneActivity.instance().editContact(contact);
} else if (id == R.id.deleteContact) {
deleteExistingContact();
LinphoneActivity.instance().removeContactFromLists(contact);
LinphoneActivity.instance().displayContacts(false);
} }
} }
private void deleteExistingContact() {
String select = ContactsContract.Data.CONTACT_ID + " = ?";
String[] args = new String[] { contact.getID() };
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
.withSelection(select, args)
.build()
);
try {
getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
} catch (Exception e) {
Log.w(e.getMessage() + ":" + e.getStackTrace());
}
}
} }

View file

@ -3,11 +3,10 @@ package org.linphone;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.linphone.compatibility.Compatibility; import org.linphone.compatibility.Compatibility;
import org.linphone.mediastream.Version; import org.linphone.mediastream.Version;
import org.linphone.ui.AvatarWithShadow; import org.linphone.ui.AvatarWithShadow;
import android.annotation.SuppressLint;
import android.content.ContentProviderOperation; import android.content.ContentProviderOperation;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
@ -34,7 +33,6 @@ public class EditContactFragment extends Fragment {
private TextView ok; private TextView ok;
private EditText firstName, lastName; private EditText firstName, lastName;
private LayoutInflater inflater; private LayoutInflater inflater;
private View deleteContact;
private boolean isNewContact = true; private boolean isNewContact = true;
private Contact contact; private Contact contact;
@ -215,19 +213,6 @@ public class EditContactFragment extends Fragment {
controls.addView(view); controls.addView(view);
} }
if (!isNewContact) {
deleteContact = inflater.inflate(R.layout.contact_delete_button, null);
deleteContact.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
deleteExistingContact();
LinphoneActivity.instance().removeContactFromLists(contact);
LinphoneActivity.instance().displayContacts(false);
}
});
controls.addView(deleteContact, controls.getChildCount());
}
// Add one for phone numbers, one for SIP address // Add one for phone numbers, one for SIP address
if (!getResources().getBoolean(R.bool.hide_phone_numbers_in_editor)) { if (!getResources().getBoolean(R.bool.hide_phone_numbers_in_editor)) {
addEmptyRowToAllowNewNumberOrAddress(controls, false); addEmptyRowToAllowNewNumberOrAddress(controls, false);
@ -243,6 +228,7 @@ public class EditContactFragment extends Fragment {
return displayNumberOrAddress(controls, numberOrAddress, false); return displayNumberOrAddress(controls, numberOrAddress, false);
} }
@SuppressLint("InflateParams")
private View displayNumberOrAddress(final TableLayout controls, String numberOrAddress, boolean forceAddNumber) { private View displayNumberOrAddress(final TableLayout controls, String numberOrAddress, boolean forceAddNumber) {
boolean isSip = LinphoneUtils.isStrictSipAddress(numberOrAddress) || !LinphoneUtils.isNumberAddress(numberOrAddress); boolean isSip = LinphoneUtils.isStrictSipAddress(numberOrAddress) || !LinphoneUtils.isNumberAddress(numberOrAddress);
@ -307,6 +293,7 @@ public class EditContactFragment extends Fragment {
return view; return view;
} }
@SuppressLint("InflateParams")
private void addEmptyRowToAllowNewNumberOrAddress(final TableLayout controls, final boolean isSip) { private void addEmptyRowToAllowNewNumberOrAddress(final TableLayout controls, final boolean isSip) {
final View view = inflater.inflate(R.layout.contact_add_row, null); final View view = inflater.inflate(R.layout.contact_add_row, null);
@ -365,11 +352,6 @@ public class EditContactFragment extends Fragment {
controls.addView(view); controls.addView(view);
} }
} }
if (deleteContact != null) {
// Move to the bottom the remove contact button
controls.removeView(deleteContact);
controls.addView(deleteContact, controls.getChildCount());
}
} }
private void createNewContact() { private void createNewContact() {
@ -405,22 +387,6 @@ public class EditContactFragment extends Fragment {
} }
} }
private void deleteExistingContact() {
String select = ContactsContract.Data.CONTACT_ID + "=?";
String[] args = new String[] { String.valueOf(contactID) };
ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
.withSelection(select, args)
.build()
);
try {
getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
} catch (Exception e) {
e.printStackTrace();
}
}
private String getDisplayName() { private String getDisplayName() {
String displayName = null; String displayName = null;
if (firstName.getText().length() > 0 && lastName.getText().length() > 0) if (firstName.getText().length() > 0 && lastName.getText().length() > 0)

View file

@ -32,7 +32,6 @@ import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreFactory; import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneProxyConfig; import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.PayloadType; import org.linphone.core.PayloadType;
import org.linphone.core.TunnelConfig;
import org.linphone.mediastream.Log; import org.linphone.mediastream.Log;
import org.linphone.mediastream.Version; import org.linphone.mediastream.Version;
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration; import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
@ -59,7 +58,6 @@ public class SettingsFragment extends PreferencesListFragment implements EcCalib
private static final int WIZARD_INTENT = 1; private static final int WIZARD_INTENT = 1;
private LinphonePreferences mPrefs; private LinphonePreferences mPrefs;
private Handler mHandler = new Handler(); private Handler mHandler = new Handler();
private TunnelConfig tunnelConfig;
public SettingsFragment() { public SettingsFragment() {
super(R.xml.preferences); super(R.xml.preferences);
@ -503,7 +501,6 @@ public class SettingsFragment extends PreferencesListFragment implements EcCalib
findPreference(getString(R.string.pref_adaptive_rate_algorithm_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() { findPreference(getString(R.string.pref_adaptive_rate_algorithm_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
ListPreference listPreference = (ListPreference) preference;
mPrefs.setAdaptiveRateAlgorithm(AdaptiveRateAlgorithm.fromString((String)newValue)); mPrefs.setAdaptiveRateAlgorithm(AdaptiveRateAlgorithm.fromString((String)newValue));
preference.setSummary(String.valueOf(mPrefs.getAdaptiveRateAlgorithm())); preference.setSummary(String.valueOf(mPrefs.getAdaptiveRateAlgorithm()));
return true; return true;