diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 7415658d7..35f81fffe 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -29,6 +29,8 @@ + + diff --git a/res/drawable-xhdpi/contact_cancel_default.9.png b/res/drawable-xhdpi/contact_cancel_default.9.png new file mode 100644 index 000000000..16d416922 Binary files /dev/null and b/res/drawable-xhdpi/contact_cancel_default.9.png differ diff --git a/res/drawable-xhdpi/contact_cancel_over.9.png b/res/drawable-xhdpi/contact_cancel_over.9.png new file mode 100644 index 000000000..6f4b52aba Binary files /dev/null and b/res/drawable-xhdpi/contact_cancel_over.9.png differ diff --git a/res/drawable-xhdpi/contact_ok_default.9.png b/res/drawable-xhdpi/contact_ok_default.9.png new file mode 100644 index 000000000..3d5c1bd66 Binary files /dev/null and b/res/drawable-xhdpi/contact_ok_default.9.png differ diff --git a/res/drawable-xhdpi/contact_ok_disabled.9.png b/res/drawable-xhdpi/contact_ok_disabled.9.png new file mode 100644 index 000000000..c2b480881 Binary files /dev/null and b/res/drawable-xhdpi/contact_ok_disabled.9.png differ diff --git a/res/drawable-xhdpi/contact_ok_over.9.png b/res/drawable-xhdpi/contact_ok_over.9.png new file mode 100644 index 000000000..173a68908 Binary files /dev/null and b/res/drawable-xhdpi/contact_ok_over.9.png differ diff --git a/res/drawable/contact_cancel.xml b/res/drawable/contact_cancel.xml new file mode 100644 index 000000000..c69e447ed --- /dev/null +++ b/res/drawable/contact_cancel.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/res/drawable/contact_ok.xml b/res/drawable/contact_ok.xml new file mode 100644 index 000000000..5c3b8eebb --- /dev/null +++ b/res/drawable/contact_ok.xml @@ -0,0 +1,10 @@ + + + + + + + diff --git a/res/drawable/text_button.xml b/res/drawable/text_button.xml new file mode 100644 index 000000000..982f2f896 --- /dev/null +++ b/res/drawable/text_button.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/res/layout/chatlist.xml b/res/layout/chatlist.xml index f5dbbcd7b..608ebdaa2 100644 --- a/res/layout/chatlist.xml +++ b/res/layout/chatlist.xml @@ -17,7 +17,7 @@ android:text="@string/button_new_chat" android:gravity="center" android:paddingTop="25dp" - android:textColor="@color/text_button" + android:textColor="@drawable/text_button" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" @@ -31,7 +31,7 @@ android:text="@string/button_edit" android:gravity="center" android:paddingTop="20dp" - android:textColor="@color/text_button" + android:textColor="@drawable/text_button" android:layout_width="match_parent" android:layout_height="match_parent" android:adjustViewBounds="true" @@ -44,7 +44,7 @@ android:text="@string/button_ok" android:gravity="center" android:paddingTop="20dp" - android:textColor="@color/text_button" + android:textColor="@drawable/text_button" android:visibility="gone" android:layout_width="match_parent" android:layout_height="match_parent" diff --git a/res/layout/contact.xml b/res/layout/contact.xml index 6a5ae1400..627bef0f7 100644 --- a/res/layout/contact.xml +++ b/res/layout/contact.xml @@ -18,7 +18,7 @@ android:text="@string/button_edit" android:gravity="center" android:paddingTop="20dp" - android:textColor="@color/text_button" + android:textColor="@drawable/text_button" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" @@ -32,7 +32,7 @@ android:text="@string/button_add_contact" android:gravity="center" android:paddingTop="20dp" - android:textColor="@color/text_button" + android:textColor="@drawable/text_button" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" diff --git a/res/layout/contacts_list.xml b/res/layout/contacts_list.xml index 003e00c74..9181c5b5e 100644 --- a/res/layout/contacts_list.xml +++ b/res/layout/contacts_list.xml @@ -58,7 +58,7 @@ android:gravity="center" android:paddingTop="20dp" android:textSize="13dp" - android:textColor="@color/text_button" + android:textColor="@drawable/text_button" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" diff --git a/res/layout/edit_contact.xml b/res/layout/edit_contact.xml new file mode 100644 index 000000000..ac8f68cc2 --- /dev/null +++ b/res/layout/edit_contact.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/history.xml b/res/layout/history.xml index 032e097bc..df3f24b62 100644 --- a/res/layout/history.xml +++ b/res/layout/history.xml @@ -18,7 +18,7 @@ android:text="@string/button_delete_all" android:gravity="center" android:paddingTop="20dp" - android:textColor="@color/text_button" + android:textColor="@drawable/text_button" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" @@ -60,7 +60,7 @@ android:text="@string/button_edit" android:gravity="center" android:paddingTop="20dp" - android:textColor="@color/text_button" + android:textColor="@drawable/text_button" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" @@ -74,7 +74,7 @@ android:text="@string/button_ok" android:gravity="center" android:paddingTop="20dp" - android:textColor="@color/text_button" + android:textColor="@drawable/text_button" android:visibility="gone" android:layout_width="match_parent" android:layout_height="match_parent" diff --git a/res/layout/history_simple.xml b/res/layout/history_simple.xml index 73302d992..6d7a969be 100644 --- a/res/layout/history_simple.xml +++ b/res/layout/history_simple.xml @@ -19,7 +19,7 @@ android:gravity="center" android:paddingTop="20dp" android:textSize="13dp" - android:textColor="@color/text_button" + android:textColor="@drawable/text_button" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" @@ -64,7 +64,7 @@ android:gravity="center" android:paddingTop="20dp" android:textSize="13dp" - android:textColor="@color/text_button" + android:textColor="@drawable/text_button" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" @@ -79,7 +79,7 @@ android:gravity="center" android:paddingTop="20dp" android:textSize="13dp" - android:textColor="@color/text_button" + android:textColor="@drawable/text_button" android:visibility="gone" android:layout_width="match_parent" android:layout_height="match_parent" diff --git a/res/values-FR/strings.xml b/res/values-FR/strings.xml index b18769406..332623aae 100644 --- a/res/values-FR/strings.xml +++ b/res/values-FR/strings.xml @@ -297,6 +297,7 @@ + Chat Modifier + Annuler Valider Tous SIP diff --git a/res/values/non_localizable_custom.xml b/res/values/non_localizable_custom.xml index a46f22ef7..605deaddf 100644 --- a/res/values/non_localizable_custom.xml +++ b/res/values/non_localizable_custom.xml @@ -21,7 +21,9 @@ false false false - true + true + + false false true diff --git a/res/values/strings.xml b/res/values/strings.xml index 6a17c7152..4cdbb60a6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -345,6 +345,7 @@ New conversation Edit + Cancel Okay All SIP diff --git a/src/org/linphone/ContactFragment.java b/src/org/linphone/ContactFragment.java index c91f82e63..a623423b0 100644 --- a/src/org/linphone/ContactFragment.java +++ b/src/org/linphone/ContactFragment.java @@ -23,7 +23,6 @@ import org.linphone.compatibility.Compatibility; import org.linphone.core.LinphoneProxyConfig; import org.linphone.ui.AvatarWithShadow; -import android.content.Intent; import android.graphics.BitmapFactory; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -59,8 +58,7 @@ public class ContactFragment extends Fragment implements OnClickListener { } }; - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { contact = (Contact) getArguments().getSerializable("Contact"); this.inflater = inflater; @@ -183,17 +181,14 @@ public class ContactFragment extends Fragment implements OnClickListener { @Override public void onClick(View v) { int id = v.getId(); - Intent intent; switch (id) { case R.id.editContact: - intent = Compatibility.prepareEditContactIntent(Integer.parseInt(contact.getID())); - startActivity(intent); + LinphoneActivity.instance().editContact(contact); break; case R.id.newContact: - intent = Compatibility.prepareAddContactIntent("", ""); - startActivity(intent); + LinphoneActivity.instance().addContact("", ""); break; } } diff --git a/src/org/linphone/ContactHelper.java b/src/org/linphone/ContactHelper.java index 454650f16..0f43a4aec 100644 --- a/src/org/linphone/ContactHelper.java +++ b/src/org/linphone/ContactHelper.java @@ -18,10 +18,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package org.linphone; -import org.linphone.compatibility.Compatibility; import org.linphone.core.LinphoneAddress; import org.linphone.mediastream.Version; -import org.linphone.ui.AddressText; import android.content.ContentResolver; import android.content.ContentUris; @@ -68,10 +66,6 @@ public final class ContactHelper { } return succeeded; } - - public static Intent prepareAddContactIntent(AddressText address) { - return Compatibility.prepareAddContactIntent(address.getDisplayedName(), address.getText().toString()); - } public static Intent prepareEditContactIntent(int id) { Intent intent = new Intent(Intent.ACTION_EDIT, Contacts.CONTENT_URI); diff --git a/src/org/linphone/ContactsFragment.java b/src/org/linphone/ContactsFragment.java index 1e9c2cedc..b20d3a6ef 100644 --- a/src/org/linphone/ContactsFragment.java +++ b/src/org/linphone/ContactsFragment.java @@ -23,7 +23,6 @@ import org.linphone.compatibility.Compatibility; import org.linphone.core.LinphoneFriend; import org.linphone.core.OnlineStatus; -import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -109,8 +108,7 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte } else if (id == R.id.newContact) { editConsumed = true; - Intent intent = Compatibility.prepareAddContactIntent(null, sipAddressToAdd); - startActivity(intent); + LinphoneActivity.instance().addContact(null, sipAddressToAdd); } } @@ -159,8 +157,7 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte Contact contact = (Contact) adapter.getItemAtPosition(position); if (editOnClick) { editConsumed = true; - Intent intent = Compatibility.prepareEditContactIntentWithSipAddress(Integer.parseInt(contact.getID()), sipAddressToAdd); - startActivity(intent); + LinphoneActivity.instance().editContact(contact, sipAddressToAdd); } else { lastKnownPosition = contactsList.getFirstVisiblePosition(); LinphoneActivity.instance().displayContact(contact, onlyDisplayChatAddress); diff --git a/src/org/linphone/EditContactFragment.java b/src/org/linphone/EditContactFragment.java new file mode 100644 index 000000000..2e93bd5f4 --- /dev/null +++ b/src/org/linphone/EditContactFragment.java @@ -0,0 +1,100 @@ +package org.linphone; + +import java.util.ArrayList; + +import android.content.ContentProviderOperation; +import android.os.Bundle; +import android.provider.ContactsContract; +import android.provider.ContactsContract.RawContacts; +import android.support.v4.app.Fragment; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.EditText; +import android.widget.TextView; + +public class EditContactFragment extends Fragment { + private View view; + private boolean isNewContact = true; + private TextView ok; + private EditText displayName; + + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + Contact contact = null; + if (getArguments() != null && getArguments().getSerializable("Contact") != null) { + contact = (Contact) getArguments().getSerializable("Contact"); + isNewContact = false; + } + + view = inflater.inflate(R.layout.edit_contact, container, false); + + TextView cancel = (TextView) view.findViewById(R.id.cancel); + cancel.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + getFragmentManager().popBackStackImmediate(); + } + }); + + ok = (TextView) view.findViewById(R.id.ok); + ok.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + if (isNewContact) { + createNewContact(); + } + } + }); + + displayName = (EditText) view.findViewById(R.id.contactName); + displayName.addTextChangedListener(new TextWatcher() { + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + if (displayName.getText().length() > 0) { + ok.setEnabled(true); + } else { + ok.setEnabled(false); + } + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void afterTextChanged(Editable s) { + } + }); + if (!isNewContact) { + displayName.setText(contact.getName()); + } + + return view; + } + + private void createNewContact() { + ArrayList ops = new ArrayList(); + int contactID = ops.size(); + + ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI) + .withValue(RawContacts.ACCOUNT_TYPE, null) + .withValue(RawContacts.ACCOUNT_NAME, null).build()); + + if (displayName.getText().length() > 0) { + ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) + .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, contactID) + .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE) + .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, displayName.getText().toString()).build() + ); + } + + try { + getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); + } catch (Exception e) { + + } + } +} diff --git a/src/org/linphone/FragmentsAvailable.java b/src/org/linphone/FragmentsAvailable.java index 8ee3c8eca..bb88fd71b 100644 --- a/src/org/linphone/FragmentsAvailable.java +++ b/src/org/linphone/FragmentsAvailable.java @@ -27,6 +27,7 @@ public enum FragmentsAvailable { HISTORY_DETAIL, CONTACTS, CONTACT, + EDIT_CONTACT, ABOUT, ABOUT_INSTEAD_OF_SETTINGS, ABOUT_INSTEAD_OF_CHAT, @@ -57,8 +58,11 @@ public enum FragmentsAvailable { case CONTACT: return CONTACTS.isRightOf(fragment) || fragment == CONTACTS; + case EDIT_CONTACT: + return CONTACT.isRightOf(fragment) || fragment == CONTACT; + case DIALER: - return CONTACTS.isRightOf(fragment) || fragment == CONTACT || fragment == CONTACTS; + return EDIT_CONTACT.isRightOf(fragment) || fragment == EDIT_CONTACT; case ABOUT_INSTEAD_OF_CHAT: case CHATLIST: @@ -88,6 +92,9 @@ public enum FragmentsAvailable { case CONTACT: return fragment == CONTACTS; + case EDIT_CONTACT: + return fragment == CONTACT; + case CHAT: return fragment == CHATLIST; diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java index ac5f59311..f9ebd4860 100644 --- a/src/org/linphone/LinphoneActivity.java +++ b/src/org/linphone/LinphoneActivity.java @@ -100,15 +100,12 @@ public class LinphoneActivity extends FragmentActivity implements private TextView missedCalls, missedChats; private ImageView dialer; private LinearLayout menu, mark; - private RelativeLayout contacts, history, settings, chat, aboutChat, - aboutSettings; + private RelativeLayout contacts, history, settings, chat, aboutChat, aboutSettings; private FragmentsAvailable currentFragment, nextFragment; - private Fragment dialerFragment, messageListenerFragment, - messageListFragment, friendStatusListenerFragment; + private Fragment dialerFragment, messageListenerFragment, messageListFragment, friendStatusListenerFragment; private SavedState dialerSavedState; private ChatStorage chatStorage; - private boolean preferLinphoneContacts = false, - isAnimationDisabled = false, isContactPresenceDisabled = true; + private boolean preferLinphoneContacts = false, isAnimationDisabled = false, isContactPresenceDisabled = true; private Handler mHandler = new Handler(); private List contactList, sipContactList; private Cursor contactCursor, sipContactCursor; @@ -129,8 +126,7 @@ public class LinphoneActivity extends FragmentActivity implements super.onCreate(savedInstanceState); if (!LinphoneManager.isInstanciated()) { - Log.e("No service running: avoid crash by starting the launcher", - this.getClass().getName()); + Log.e("No service running: avoid crash by starting the launcher", this.getClass().getName()); // super.onCreate called earlier finish(); startActivity(getIntent().setClass(this, @@ -138,17 +134,10 @@ public class LinphoneActivity extends FragmentActivity implements return; } - boolean useFirstLoginActivity = getResources().getBoolean( - R.bool.useFirstLoginActivity); - SharedPreferences pref = PreferenceManager - .getDefaultSharedPreferences(this); - if (useFirstLoginActivity - && !pref.getBoolean( - getString(R.string.first_launch_suceeded_once_key), - false)) { - startActivityForResult( - new Intent().setClass(this, SetupActivity.class), - FIRST_LOGIN_ACTIVITY); + boolean useFirstLoginActivity = getResources().getBoolean(R.bool.use_first_login_activity); + SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); + if (useFirstLoginActivity && !pref.getBoolean(getString(R.string.first_launch_suceeded_once_key), false)) { + startActivityForResult(new Intent().setClass(this, SetupActivity.class), FIRST_LOGIN_ACTIVITY); } setContentView(R.layout.main); @@ -160,8 +149,7 @@ public class LinphoneActivity extends FragmentActivity implements if (findViewById(R.id.fragmentContainer) != null) { dialerFragment = new DialerFragment(); dialerFragment.setArguments(getIntent().getExtras()); - getSupportFragmentManager().beginTransaction() - .add(R.id.fragmentContainer, dialerFragment).commit(); + getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainer, dialerFragment).commit(); selectMenu(FragmentsAvailable.DIALER); } } @@ -169,8 +157,7 @@ public class LinphoneActivity extends FragmentActivity implements int missedCalls = LinphoneManager.getLc().getMissedCallsCount(); displayMissedCalls(missedCalls); - int rotation = Compatibility.getRotation(getWindowManager() - .getDefaultDisplay()); + int rotation = Compatibility.getRotation(getWindowManager().getDefaultDisplay()); // Inverse landscape rotation to initiate linphoneCore correctly if (rotation == 270) rotation = 90; @@ -238,28 +225,23 @@ public class LinphoneActivity extends FragmentActivity implements // dialer from chat statusFragment.getView().setVisibility(View.VISIBLE); } - findViewById(R.id.fragmentContainer).setPadding(0, - LinphoneUtils.pixelsToDpi(getResources(), 40), 0, 0); + findViewById(R.id.fragmentContainer).setPadding(0, LinphoneUtils.pixelsToDpi(getResources(), 40), 0, 0); } - private void changeCurrentFragment(FragmentsAvailable newFragmentType, - Bundle extras) { + private void changeCurrentFragment(FragmentsAvailable newFragmentType, Bundle extras) { changeCurrentFragment(newFragmentType, extras, false); } @SuppressWarnings("incomplete-switch") - private void changeCurrentFragment(FragmentsAvailable newFragmentType, - Bundle extras, boolean withoutAnimation) { - if (newFragmentType == currentFragment - && newFragmentType != FragmentsAvailable.CHAT) { + private void changeCurrentFragment(FragmentsAvailable newFragmentType, Bundle extras, boolean withoutAnimation) { + if (newFragmentType == currentFragment && newFragmentType != FragmentsAvailable.CHAT) { return; } nextFragment = newFragmentType; if (currentFragment == FragmentsAvailable.DIALER) { try { - dialerSavedState = getSupportFragmentManager() - .saveFragmentInstanceState(dialerFragment); + dialerSavedState = getSupportFragmentManager().saveFragmentInstanceState(dialerFragment); } catch (Exception e) { } } @@ -284,6 +266,9 @@ public class LinphoneActivity extends FragmentActivity implements case CONTACT: newFragment = new ContactFragment(); break; + case EDIT_CONTACT: + newFragment = new EditContactFragment(); + break; case DIALER: newFragment = new DialerFragment(); if (extras == null) { @@ -315,8 +300,7 @@ public class LinphoneActivity extends FragmentActivity implements if (newFragment != null) { newFragment.setArguments(extras); if (Version.isXLargeScreen(this)) { - changeFragmentForTablets(newFragment, newFragmentType, - withoutAnimation); + changeFragmentForTablets(newFragment, newFragmentType, withoutAnimation); } else { changeFragment(newFragment, newFragmentType, withoutAnimation); } @@ -324,14 +308,9 @@ public class LinphoneActivity extends FragmentActivity implements } private void updateAnimationsState() { - SharedPreferences prefs = PreferenceManager - .getDefaultSharedPreferences(this); - isAnimationDisabled = getResources().getBoolean( - R.bool.disable_animations) - || !prefs.getBoolean( - getString(R.string.pref_animation_enable_key), false); - isContactPresenceDisabled = !getResources().getBoolean( - R.bool.enable_linphone_friends); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + isAnimationDisabled = getResources().getBoolean(R.bool.disable_animations) || !prefs.getBoolean(getString(R.string.pref_animation_enable_key), false); + isContactPresenceDisabled = !getResources().getBoolean(R.bool.enable_linphone_friends); } public boolean isAnimationDisabled() { @@ -354,11 +333,9 @@ public class LinphoneActivity extends FragmentActivity implements statusFragment.closeStatusBar(); } - FragmentTransaction transaction = getSupportFragmentManager() - .beginTransaction(); + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); - if (!withoutAnimation && !isAnimationDisabled - && currentFragment.shouldAnimate()) { + if (!withoutAnimation && !isAnimationDisabled && currentFragment.shouldAnimate()) { if (newFragmentType.isRightOf(currentFragment)) { transaction.setCustomAnimations(R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left, @@ -372,9 +349,7 @@ public class LinphoneActivity extends FragmentActivity implements } } try { - getSupportFragmentManager().popBackStackImmediate( - newFragmentType.toString(), - FragmentManager.POP_BACK_STACK_INCLUSIVE); + getSupportFragmentManager().popBackStackImmediate(newFragmentType.toString(), FragmentManager.POP_BACK_STACK_INCLUSIVE); } catch (java.lang.IllegalStateException e) { } @@ -409,7 +384,9 @@ public class LinphoneActivity extends FragmentActivity implements transaction.replace(R.id.fragmentContainer2, newFragment); } else { if (newFragmentType == FragmentsAvailable.DIALER - || newFragmentType == FragmentsAvailable.ABOUT || newFragmentType == FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT || newFragmentType == FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS + || newFragmentType == FragmentsAvailable.ABOUT + || newFragmentType == FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT + || newFragmentType == FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS || newFragmentType == FragmentsAvailable.SETTINGS || newFragmentType == FragmentsAvailable.ACCOUNT_SETTINGS) { ll.setVisibility(View.GONE); @@ -441,10 +418,8 @@ public class LinphoneActivity extends FragmentActivity implements } public void displayHistoryDetail(String sipUri, LinphoneCallLog log) { - LinphoneAddress lAddress = LinphoneCoreFactory.instance() - .createLinphoneAddress(sipUri); - Uri uri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName( - lAddress, getContentResolver()); + LinphoneAddress lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri); + Uri uri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(lAddress, getContentResolver()); String displayName = lAddress.getDisplayName(); String pictureUri = uri == null ? null : uri.toString(); @@ -463,13 +438,10 @@ public class LinphoneActivity extends FragmentActivity implements String callTime = secondsToDisplayableString(log.getCallDuration()); String callDate = log.getStartDate(); - Fragment fragment2 = getSupportFragmentManager().findFragmentById( - R.id.fragmentContainer2); - if (fragment2 != null && fragment2.isVisible() - && currentFragment == FragmentsAvailable.HISTORY_DETAIL) { + Fragment fragment2 = getSupportFragmentManager().findFragmentById(R.id.fragmentContainer2); + if (fragment2 != null && fragment2.isVisible() && currentFragment == FragmentsAvailable.HISTORY_DETAIL) { HistoryDetailFragment historyDetailFragment = (HistoryDetailFragment) fragment2; - historyDetailFragment.changeDisplayedHistory(sipUri, displayName, - pictureUri, status, callTime, callDate); + historyDetailFragment.changeDisplayedHistory(sipUri, displayName, pictureUri, status, callTime, callDate); } else { Bundle extras = new Bundle(); extras.putString("SipUri", sipUri); @@ -493,10 +465,8 @@ public class LinphoneActivity extends FragmentActivity implements } public void displayContact(Contact contact, boolean chatOnly) { - Fragment fragment2 = getSupportFragmentManager().findFragmentById( - R.id.fragmentContainer2); - if (fragment2 != null && fragment2.isVisible() - && currentFragment == FragmentsAvailable.CONTACT) { + Fragment fragment2 = getSupportFragmentManager().findFragmentById(R.id.fragmentContainer2); + if (fragment2 != null && fragment2.isVisible() && currentFragment == FragmentsAvailable.CONTACT) { ContactFragment contactFragment = (ContactFragment) fragment2; contactFragment.changeDisplayedContact(contact); } else { @@ -588,10 +558,8 @@ public class LinphoneActivity extends FragmentActivity implements aboutChat.setSelected(true); } else if (id == R.id.about_settings) { Bundle b = new Bundle(); - b.putSerializable("About", - FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS); - changeCurrentFragment(FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS, - b); + b.putSerializable("About", FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS); + changeCurrentFragment(FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS, b); aboutSettings.setSelected(true); } else if (id == R.id.chat) { changeCurrentFragment(FragmentsAvailable.CHATLIST, null); @@ -621,6 +589,7 @@ public class LinphoneActivity extends FragmentActivity implements break; case CONTACTS: case CONTACT: + case EDIT_CONTACT: contacts.setSelected(true); break; case DIALER: @@ -646,17 +615,13 @@ public class LinphoneActivity extends FragmentActivity implements public void updateDialerFragment(DialerFragment fragment) { dialerFragment = fragment; // Hack to maintain soft input flags - getWindow().setSoftInputMode( - WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN - | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); + getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); } public void updateChatFragment(ChatFragment fragment) { messageListenerFragment = fragment; // Hack to maintain soft input flags - getWindow().setSoftInputMode( - WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE - | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); + getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); } public void updateChatListFragment(ChatListFragment fragment) { @@ -672,8 +637,7 @@ public class LinphoneActivity extends FragmentActivity implements statusFragment = fragment; if (LinphoneManager.getLc().getDefaultProxyConfig() != null) { - statusFragment.registrationStateChanged(LinphoneManager.getLc() - .getDefaultProxyConfig().getState()); + statusFragment.registrationStateChanged(LinphoneManager.getLc().getDefaultProxyConfig().getState()); } } @@ -683,8 +647,7 @@ public class LinphoneActivity extends FragmentActivity implements } public void applyConfigChangesIfNeeded() { - if (nextFragment != FragmentsAvailable.SETTINGS - && nextFragment != FragmentsAvailable.ACCOUNT_SETTINGS) { + if (nextFragment != FragmentsAvailable.SETTINGS && nextFragment != FragmentsAvailable.ACCOUNT_SETTINGS) { reloadConfig(); updateAnimationsState(); } @@ -700,17 +663,14 @@ public class LinphoneActivity extends FragmentActivity implements try { LinphoneManager.getInstance().initFromConf(); - lc.setVideoPolicy(LinphoneManager.getInstance() - .isAutoInitiateVideoCalls(), LinphoneManager.getInstance() - .isAutoAcceptCamera()); + lc.setVideoPolicy(LinphoneManager.getInstance().isAutoInitiateVideoCalls(), LinphoneManager.getInstance().isAutoAcceptCamera()); } catch (LinphoneException e) { if (!(e instanceof LinphoneConfigException)) { Log.e(e, "Cannot update config"); return; } - LinphoneActivity.instance().showPreferenceErrorDialog( - e.getMessage()); + LinphoneActivity.instance().showPreferenceErrorDialog(e.getMessage()); } } @@ -757,8 +717,7 @@ public class LinphoneActivity extends FragmentActivity implements String notificationText = null; int id = -1; if (textMessage != null && textMessage.length() > 0) { - id = getChatStorage().saveMessage(from.asStringUriOnly(), "", - textMessage); + id = getChatStorage().saveMessage(from.asStringUriOnly(), "", textMessage); notificationText = textMessage; } else if (url != null && url.length() > 0) { Bitmap bm = ChatFragment.downloadImage(url); @@ -767,9 +726,7 @@ public class LinphoneActivity extends FragmentActivity implements } ChatFragment chatFragment = ((ChatFragment) messageListenerFragment); - if (messageListenerFragment != null - && messageListenerFragment.isVisible() - && chatFragment.getSipUri().equals(from.asStringUriOnly())) { + if (messageListenerFragment != null && messageListenerFragment.isVisible() && chatFragment.getSipUri().equals(from.asStringUriOnly())) { chatFragment.onMessageReceived(id, from, message); getChatStorage().markMessageAsRead(id); } else if (LinphoneService.isReady()) { @@ -778,11 +735,8 @@ public class LinphoneActivity extends FragmentActivity implements ((ChatListFragment) messageListFragment).refresh(); } } - LinphoneUtils.findUriPictureOfContactAndSetDisplayName(from, - getContentResolver()); - LinphoneService.instance() - .displayMessageNotification(from.asStringUriOnly(), - from.getDisplayName(), notificationText); + LinphoneUtils.findUriPictureOfContactAndSetDisplayName(from, getContentResolver()); + LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getDisplayName(), notificationText); } public void updateMissedChatCount() { @@ -822,9 +776,7 @@ public class LinphoneActivity extends FragmentActivity implements missedCalls.setText(missedCallsCount + ""); missedCalls.setVisibility(View.VISIBLE); if (!isAnimationDisabled) { - missedCalls.startAnimation(AnimationUtils - .loadAnimation(LinphoneActivity.this, - R.anim.bounce)); + missedCalls.startAnimation(AnimationUtils.loadAnimation(LinphoneActivity.this, R.anim.bounce)); } } else { missedCalls.clearAnimation(); @@ -847,9 +799,7 @@ public class LinphoneActivity extends FragmentActivity implements } missedChats.setVisibility(View.VISIBLE); if (!isAnimationDisabled) { - missedChats.startAnimation(AnimationUtils - .loadAnimation(LinphoneActivity.this, - R.anim.bounce)); + missedChats.startAnimation(AnimationUtils.loadAnimation(LinphoneActivity.this, R.anim.bounce)); } } else { missedChats.clearAnimation(); @@ -874,8 +824,7 @@ public class LinphoneActivity extends FragmentActivity implements } else { startIncallActivity(call); } - } else if (state == State.CallEnd || state == State.Error - || state == State.CallReleased) { + } else if (state == State.CallEnd || state == State.Error || state == State.CallReleased) { resetClassicMenuLayoutAndGoBackToCallIfStillRunning(); } @@ -888,11 +837,9 @@ public class LinphoneActivity extends FragmentActivity implements @Override public void run() { LayoutInflater inflater = getLayoutInflater(); - View layout = inflater.inflate(R.layout.toast, - (ViewGroup) findViewById(R.id.toastRoot)); + View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toastRoot)); - TextView toastText = (TextView) layout - .findViewById(R.id.toastMessage); + TextView toastText = (TextView) layout.findViewById(R.id.toastMessage); toastText.setText(message); final Toast toast = new Toast(getApplicationContext()); @@ -958,8 +905,7 @@ public class LinphoneActivity extends FragmentActivity implements private int mAlwaysChangingPhoneAngle = -1; private AcceptNewFriendDialog acceptNewFriendDialog; - private class LocalOrientationEventListener extends - OrientationEventListener { + private class LocalOrientationEventListener extends OrientationEventListener { public LocalOrientationEventListener(Context context) { super(context); } @@ -985,13 +931,11 @@ public class LinphoneActivity extends FragmentActivity implements Log.d("Phone orientation changed to ", degrees); int rotation = (360 - degrees) % 360; - LinphoneCore lc = LinphoneManager - .getLcIfManagerNotDestroyedOrNull(); + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); if (lc != null) { lc.setDeviceRotation(rotation); LinphoneCall currentCall = lc.getCurrentCall(); - if (currentCall != null && currentCall.cameraEnabled() - && currentCall.getCurrentParamsCopy().getVideoEnabled()) { + if (currentCall != null && currentCall.cameraEnabled() && currentCall.getCurrentParamsCopy().getVideoEnabled()) { lc.updateCall(currentCall, null); } } @@ -1028,8 +972,7 @@ public class LinphoneActivity extends FragmentActivity implements private void refreshStatus(OnlineStatus status) { if (LinphoneManager.isInstanciated()) { - LinphoneManager.getLcIfManagerNotDestroyedOrNull().setPresenceInfo( - 0, "", status); + LinphoneManager.getLcIfManagerNotDestroyedOrNull().setPresenceInfo(0, "", status); } } @@ -1040,10 +983,8 @@ public class LinphoneActivity extends FragmentActivity implements } sipUri = sipUri.replace("<", "").replace(">", ""); - SharedPreferences prefs = PreferenceManager - .getDefaultSharedPreferences(this); - if (prefs.getBoolean(getString(R.string.pref_auto_accept_friends_key), - false)) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + if (prefs.getBoolean(getString(R.string.pref_auto_accept_friends_key), false)) { Contact contact = findContactWithSipAddress(sipUri); if (contact != null) { friend.enableSubscribes(true); @@ -1058,8 +999,7 @@ public class LinphoneActivity extends FragmentActivity implements Contact contact = findContactWithSipAddress(sipUri); if (contact != null) { FragmentManager fm = getSupportFragmentManager(); - acceptNewFriendDialog = new AcceptNewFriendDialog(contact, - sipUri); + acceptNewFriendDialog = new AcceptNewFriendDialog(contact, sipUri); acceptNewFriendDialog.show(fm, "New Friend Request Dialog"); } } @@ -1081,16 +1021,13 @@ public class LinphoneActivity extends FragmentActivity implements } public void onNotifyPresenceReceived(LinphoneFriend friend) { - if (!isContactPresenceDisabled - && currentFragment == FragmentsAvailable.CONTACTS - && friendStatusListenerFragment != null) { + if (!isContactPresenceDisabled && currentFragment == FragmentsAvailable.CONTACTS && friendStatusListenerFragment != null) { ((ContactsFragment) friendStatusListenerFragment).invalidate(); } } public boolean newFriend(Contact contact, String sipUri) { - LinphoneFriend friend = LinphoneCoreFactory.instance() - .createLinphoneFriend(sipUri); + LinphoneFriend friend = LinphoneCoreFactory.instance().createLinphoneFriend(sipUri); friend.enableSubscribes(true); friend.setIncSubscribePolicy(LinphoneFriend.SubscribePolicy.SPAccept); try { @@ -1103,8 +1040,7 @@ public class LinphoneActivity extends FragmentActivity implements return false; } - private void acceptNewFriend(Contact contact, String sipUri, - boolean accepted) { + private void acceptNewFriend(Contact contact, String sipUri, boolean accepted) { acceptNewFriendDialog.dismissAllowingStateLoss(); if (accepted) { newFriend(contact, sipUri); @@ -1112,8 +1048,7 @@ public class LinphoneActivity extends FragmentActivity implements } public boolean removeFriend(Contact contact, String sipUri) { - LinphoneFriend friend = LinphoneManager.getLc().findFriendByAddress( - sipUri); + LinphoneFriend friend = LinphoneManager.getLc().findFriendByAddress(sipUri); if (friend != null) { friend.enableSubscribes(false); LinphoneManager.getLc().removeFriend(friend); @@ -1130,8 +1065,7 @@ public class LinphoneActivity extends FragmentActivity implements for (String sipUri : contact.getNumerosOrAddresses()) { if (LinphoneUtils.isSipAddress(sipUri)) { - LinphoneFriend friend = LinphoneManager.getLc() - .findFriendByAddress(sipUri); + LinphoneFriend friend = LinphoneManager.getLc().findFriendByAddress(sipUri); if (friend != null) { friend.enableSubscribes(true); friend.setIncSubscribePolicy(LinphoneFriend.SubscribePolicy.SPAccept); @@ -1151,15 +1085,13 @@ public class LinphoneActivity extends FragmentActivity implements } contactCursor = Compatibility.getContactsCursor(getContentResolver()); - sipContactCursor = Compatibility - .getSIPContactsCursor(getContentResolver()); + sipContactCursor = Compatibility.getSIPContactsCursor(getContentResolver()); Thread sipContactsHandler = new Thread(new Runnable() { @Override public void run() { for (int i = 0; i < sipContactCursor.getCount(); i++) { - Contact contact = Compatibility.getContact( - getContentResolver(), sipContactCursor, i); + Contact contact = Compatibility.getContact(getContentResolver(), sipContactCursor, i); contact.refresh(getContentResolver()); if (!isContactPresenceDisabled) { searchFriendAndAddToContact(contact); @@ -1167,8 +1099,7 @@ public class LinphoneActivity extends FragmentActivity implements sipContactList.add(contact); } for (int i = 0; i < contactCursor.getCount(); i++) { - Contact contact = Compatibility.getContact( - getContentResolver(), contactCursor, i); + Contact contact = Compatibility.getContact(getContentResolver(), contactCursor, i); for (Contact c : sipContactList) { if (c.getID().equals(contact.getID())) { contact = c; @@ -1200,8 +1131,7 @@ public class LinphoneActivity extends FragmentActivity implements ((DialerFragment) dialerFragment).resetLayout(false); } - if (LinphoneManager.isInstanciated() - && LinphoneManager.getLc().getCallsNb() > 0) { + if (LinphoneManager.isInstanciated() && LinphoneManager.getLc().getCallsNb() > 0) { LinphoneCall call = LinphoneManager.getLc().getCalls()[0]; if (call.getCurrentParamsCopy().getVideoEnabled()) { startVideoActivity(call); @@ -1223,29 +1153,60 @@ public class LinphoneActivity extends FragmentActivity implements } return chatStorage; } + + public void addContact(String displayName, String sipUri) + { + if (getResources().getBoolean(R.bool.use_android_native_contact_edit_interface)) { + Intent intent = Compatibility.prepareAddContactIntent(displayName, sipUri); + startActivity(intent); + } else { + changeCurrentFragment(FragmentsAvailable.EDIT_CONTACT, null); + } + } + + public void editContact(Contact contact) + { + if (getResources().getBoolean(R.bool.use_android_native_contact_edit_interface)) { + Intent intent = Compatibility.prepareEditContactIntent(Integer.parseInt(contact.getID())); + startActivity(intent); + } else { + Bundle extras = new Bundle(); + extras.putSerializable("Contact", contact); + changeCurrentFragment(FragmentsAvailable.EDIT_CONTACT, extras); + } + } + + public void editContact(Contact contact, String sipAddress) + { + if (getResources().getBoolean(R.bool.use_android_native_contact_edit_interface)) { + Intent intent = Compatibility.prepareEditContactIntentWithSipAddress(Integer.parseInt(contact.getID()), sipAddress); + startActivity(intent); + } else { + Bundle extras = new Bundle(); + extras.putSerializable("Contact", contact); + extras.putSerializable("NewSipAdress", sipAddress); + changeCurrentFragment(FragmentsAvailable.EDIT_CONTACT, extras); + } + } public void exit() { refreshStatus(OnlineStatus.Offline); finish(); - stopService(new Intent(ACTION_MAIN).setClass(this, - LinphoneService.class)); + stopService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class)); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (resultCode == Activity.RESULT_FIRST_USER - && requestCode == SETTINGS_ACTIVITY) { + if (resultCode == Activity.RESULT_FIRST_USER && requestCode == SETTINGS_ACTIVITY) { if (data.getExtras().getBoolean("Exit", false)) { exit(); } else { - FragmentsAvailable newFragment = (FragmentsAvailable) data - .getExtras().getSerializable("FragmentToDisplay"); + FragmentsAvailable newFragment = (FragmentsAvailable) data.getExtras().getSerializable("FragmentToDisplay"); changeCurrentFragment(newFragment, null, true); selectMenu(newFragment); } } else if (requestCode == callActivity) { - boolean callTransfer = data == null ? false : data.getBooleanExtra( - "Transfer", false); + boolean callTransfer = data == null ? false : data.getBooleanExtra("Transfer", false); if (LinphoneManager.getLc().getCallsNb() > 0) { initInCallMenuLayout(callTransfer); } else { @@ -1346,8 +1307,7 @@ public class LinphoneActivity extends FragmentActivity implements } if (LinphoneManager.getLc().getCalls().length > 0) { LinphoneCall call = LinphoneManager.getLc().getCalls()[0]; - if (call != null - && call.getState() != LinphoneCall.State.IncomingReceived) { + if (call != null && call.getState() != LinphoneCall.State.IncomingReceived) { if (call.getCurrentParamsCopy().getVideoEnabled()) { startVideoActivity(call); } else { @@ -1398,10 +1358,8 @@ public class LinphoneActivity extends FragmentActivity implements } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.new_friend_request_dialog, - container); + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.new_friend_request_dialog, container); getDialog().setTitle(R.string.linphone_friend_new_request_title);