InApp contact editor started

This commit is contained in:
Sylvain Berfini 2012-11-06 15:26:05 +01:00
parent 9a9011f15a
commit 9c1b86dc3f
24 changed files with 343 additions and 186 deletions

View file

@ -29,6 +29,8 @@
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- Needed to store received images if the user wants to -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- Needed to use our own Contact editor -->
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true"/>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,023 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 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_cancel_over" />
<item
android:drawable="@drawable/contact_cancel_default" />
</selector>

View file

@ -0,0 +1,10 @@
<?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_ok_over" />
<item android:state_enabled="false"
android:drawable="@drawable/contact_ok_disabled" />
<item
android:drawable="@drawable/contact_ok_default" />
</selector>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="@color/text_button_over" />
<item android:state_selected="true"
android:color="@color/text_button_selected" />
<item android:state_enabled="false"
android:color="@color/text_button_disabled" />
<item android:color="@color/text_button" />
</selector>

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:linphone="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:contentDescription="@string/content_description_cancel"
android:id="@+id/cancel"
android:background="@drawable/contact_cancel"
android:text="@string/button_cancel"
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
android:contentDescription="@string/content_description_validate"
android:id="@+id/ok"
android:background="@drawable/contact_ok"
android:text="@string/button_ok"
android:gravity="center"
android:enabled="false"
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"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<org.linphone.ui.AvatarWithShadow
android:id="@+id/contactPicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
linphone:picture="@drawable/unknown_small" />
<EditText
android:id="@+id/contactName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:background="@drawable/chat_fast_address_background"
android:gravity="center"
android:paddingRight="5dp"
android:inputType="textPersonName|textCapWords"/>
</LinearLayout>
</LinearLayout>

View file

@ -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"

View file

@ -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"

View file

@ -297,6 +297,7 @@
<string name="button_new_chat">+ Chat</string>
<string name="button_edit">Modifier</string>
<string name="button_cancel">Annuler</string>
<string name="button_ok">Valider</string>
<string name="button_all_contacts">Tous</string>
<string name="button_sip_contacts">SIP</string>

View file

@ -21,7 +21,9 @@
<bool name="hide_linphone_accounts_wizard">false</bool>
<bool name="hide_generic_accounts_wizard">false</bool>
<bool name="hide_accounts">false</bool>
<bool name="useFirstLoginActivity">true</bool>
<bool name="use_first_login_activity">true</bool>
<bool name="use_android_native_contact_edit_interface">false</bool>
<bool name="disable_animations">false</bool>
<bool name="show_statusbar_only_on_dialer">true</bool>

View file

@ -345,6 +345,7 @@
<string name="button_new_chat">New conversation</string>
<string name="button_edit">Edit</string>
<string name="button_cancel">Cancel</string>
<string name="button_ok">Okay</string>
<string name="button_all_contacts">All</string>
<string name="button_sip_contacts">SIP</string>

View file

@ -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;
}
}

View file

@ -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);

View file

@ -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);

View file

@ -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<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
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) {
}
}
}

View file

@ -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;

View file

@ -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<Contact> 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);