Fixed the warnings in the java code
This commit is contained in:
parent
1b5a3336b9
commit
bc954e9320
9 changed files with 227 additions and 128 deletions
|
@ -21,7 +21,7 @@ import java.util.List;
|
|||
|
||||
import org.linphone.compatibility.Compatibility;
|
||||
import org.linphone.core.LinphoneFriend;
|
||||
import org.linphone.core.OnlineStatus;
|
||||
import org.linphone.core.PresenceActivityType;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
|
@ -278,13 +278,14 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
|||
LinphoneFriend friend = contact.getFriend();
|
||||
if (!LinphoneActivity.instance().isContactPresenceDisabled() && friend != null) {
|
||||
friendStatus.setVisibility(View.VISIBLE);
|
||||
if (friend.getStatus() == OnlineStatus.Online) {
|
||||
PresenceActivityType presenceActivity = friend.getPresenceModel().getActivity().getType();
|
||||
if (presenceActivity == PresenceActivityType.Online) {
|
||||
friendStatus.setImageResource(R.drawable.led_connected);
|
||||
} else if (friend.getStatus() == OnlineStatus.Busy || friend.getStatus() == OnlineStatus.DoNotDisturb) {
|
||||
} else if (presenceActivity == PresenceActivityType.Busy) {
|
||||
friendStatus.setImageResource(R.drawable.led_error);
|
||||
} else if (friend.getStatus() == OnlineStatus.Away || friend.getStatus() == OnlineStatus.BeRightBack) {
|
||||
} else if (presenceActivity == PresenceActivityType.Away) {
|
||||
friendStatus.setImageResource(R.drawable.led_inprogress);
|
||||
} else if (friend.getStatus() == OnlineStatus.Offline) {
|
||||
} else if (presenceActivity == PresenceActivityType.Offline) {
|
||||
friendStatus.setImageResource(R.drawable.led_disconnected);
|
||||
} else {
|
||||
friendStatus.setImageResource(R.drawable.call_quality_indicator_0);
|
||||
|
|
|
@ -43,7 +43,6 @@ import org.linphone.core.LinphoneCore.RegistrationState;
|
|||
import org.linphone.core.LinphoneCoreException;
|
||||
import org.linphone.core.LinphoneCoreFactory;
|
||||
import org.linphone.core.LinphoneFriend;
|
||||
import org.linphone.core.OnlineStatus;
|
||||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.setup.SetupActivity;
|
||||
import org.linphone.ui.AddressText;
|
||||
|
@ -975,12 +974,6 @@ public class LinphoneActivity extends FragmentActivity implements
|
|||
return preferLinphoneContacts;
|
||||
}
|
||||
|
||||
private void refreshStatus(OnlineStatus status) {
|
||||
if (LinphoneManager.isInstanciated()) {
|
||||
LinphoneManager.getLcIfManagerNotDestroyedOrNull().setPresenceInfo(0, "", status);
|
||||
}
|
||||
}
|
||||
|
||||
public void onNewSubscriptionRequestReceived(LinphoneFriend friend,
|
||||
String sipUri) {
|
||||
if (isContactPresenceDisabled) {
|
||||
|
@ -1265,13 +1258,13 @@ public class LinphoneActivity extends FragmentActivity implements
|
|||
}
|
||||
}
|
||||
|
||||
refreshStatus(OnlineStatus.Online);
|
||||
LinphoneManager.getInstance().changeStatusToOnline();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
refreshStatus(OnlineStatus.Away);
|
||||
LinphoneManager.getInstance().changeStatusToAway();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -60,17 +60,19 @@ import org.linphone.core.LinphoneCore.GlobalState;
|
|||
import org.linphone.core.LinphoneCore.RegistrationState;
|
||||
import org.linphone.core.LinphoneCoreException;
|
||||
import org.linphone.core.LinphoneCoreFactory;
|
||||
import org.linphone.core.LinphoneCoreFactoryImpl;
|
||||
import org.linphone.core.LinphoneCoreListener;
|
||||
import org.linphone.core.LinphoneEvent;
|
||||
import org.linphone.core.LinphoneFriend;
|
||||
import org.linphone.core.LinphoneInfoMessage;
|
||||
import org.linphone.core.LinphoneProxyConfig;
|
||||
import org.linphone.core.PayloadType;
|
||||
import org.linphone.core.PresenceActivityType;
|
||||
import org.linphone.core.PresenceModel;
|
||||
import org.linphone.core.PublishState;
|
||||
import org.linphone.core.SubscriptionState;
|
||||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.mediastream.Version;
|
||||
import org.linphone.mediastream.video.capture.AndroidVideoApi5JniWrapper;
|
||||
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
|
||||
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration.AndroidCamera;
|
||||
import org.linphone.mediastream.video.capture.hwconf.Hacks;
|
||||
|
@ -346,9 +348,32 @@ public class LinphoneManager implements LinphoneCoreListener {
|
|||
boolean gsmIdle = tm.getCallState() == TelephonyManager.CALL_STATE_IDLE;
|
||||
setGsmIdle(gsmIdle);
|
||||
|
||||
getInstance().changeStatusToOnline();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void changeStatusToOnline() {
|
||||
if (LinphoneManager.isInstanciated()) {
|
||||
PresenceModel model = LinphoneCoreFactoryImpl.instance().createPresenceModel(PresenceActivityType.Online, null);
|
||||
LinphoneManager.getLcIfManagerNotDestroyedOrNull().setPresenceModel(model);
|
||||
}
|
||||
}
|
||||
|
||||
public void changeStatusToAway() {
|
||||
if (LinphoneManager.isInstanciated()) {
|
||||
PresenceModel model = LinphoneCoreFactoryImpl.instance().createPresenceModel(PresenceActivityType.Away, null);
|
||||
LinphoneManager.getLcIfManagerNotDestroyedOrNull().setPresenceModel(model);
|
||||
}
|
||||
}
|
||||
|
||||
public void changeStatusToOffline() {
|
||||
if (LinphoneManager.isInstanciated()) {
|
||||
PresenceModel model = LinphoneCoreFactoryImpl.instance().createPresenceModel(PresenceActivityType.Offline, null);
|
||||
LinphoneManager.getLcIfManagerNotDestroyedOrNull().setPresenceModel(model);
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized final LinphoneManager getInstance() {
|
||||
if (instance != null) return instance;
|
||||
|
||||
|
@ -734,7 +759,8 @@ public class LinphoneManager implements LinphoneCoreListener {
|
|||
|
||||
public static synchronized void destroy() {
|
||||
if (instance == null) return;
|
||||
sExited=true;
|
||||
getInstance().changeStatusToOffline();
|
||||
sExited = true;
|
||||
instance.doDestroy();
|
||||
}
|
||||
|
||||
|
|
|
@ -33,10 +33,10 @@ import org.linphone.core.LinphoneCore.RegistrationState;
|
|||
import org.linphone.core.LinphoneCoreException;
|
||||
import org.linphone.core.LinphoneCoreFactoryImpl;
|
||||
import org.linphone.core.LinphoneProxyConfig;
|
||||
import org.linphone.core.OnlineStatus;
|
||||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.mediastream.Version;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.Notification;
|
||||
|
@ -156,8 +156,9 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
|
|||
|
||||
LinphoneManager.createAndStart(this, this);
|
||||
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
||||
mWifiLock = mWifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, this.getPackageName()+"-wifi-call-lock");
|
||||
mWifiLock.setReferenceCounted(false);
|
||||
if (Version.sdkAboveOrEqual(Version.API12_HONEYCOMB_MR1_31X)) {
|
||||
startWifiLock();
|
||||
}
|
||||
instance = this; // instance is ready once linphone manager has been created
|
||||
|
||||
|
||||
|
@ -189,7 +190,6 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
|
|||
}, 5000);
|
||||
}
|
||||
|
||||
LinphoneManager.getLc().setPresenceInfo(0, "", OnlineStatus.Online);
|
||||
//make sure the application will at least wakes up every 10 mn
|
||||
Intent intent = new Intent(this, KeepAliveHandler.class);
|
||||
mkeepAlivePendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
|
||||
|
@ -199,6 +199,12 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
|
|||
, mkeepAlivePendingIntent);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
|
||||
private void startWifiLock() {
|
||||
mWifiLock = mWifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, this.getPackageName()+"-wifi-call-lock");
|
||||
mWifiLock.setReferenceCounted(false);
|
||||
}
|
||||
|
||||
private enum IncallIconState {INCALL, PAUSE, VIDEO, IDLE}
|
||||
private IncallIconState mCurrentIncallIconState = IncallIconState.IDLE;
|
||||
private synchronized void setIncallIcon(IncallIconState state) {
|
||||
|
@ -470,7 +476,6 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
|
|||
|
||||
@Override
|
||||
public synchronized void onDestroy() {
|
||||
LinphoneManager.getLc().setPresenceInfo(0, "", OnlineStatus.Offline);
|
||||
instance = null;
|
||||
LinphoneManager.destroy();
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.linphone.mediastream.Log;
|
|||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.view.Display;
|
||||
|
||||
import com.google.android.gcm.GCMRegistrar;
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.linphone.compatibility;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.linphone.R;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
|
@ -7,9 +9,17 @@ import android.app.Notification;
|
|||
import android.app.PendingIntent;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.media.AudioManager;
|
||||
import android.net.Uri;
|
||||
import android.provider.ContactsContract;
|
||||
import android.provider.ContactsContract.Contacts;
|
||||
import android.provider.ContactsContract.CommonDataKinds.SipAddress;
|
||||
import android.provider.ContactsContract.Intents.Insert;
|
||||
|
||||
/*
|
||||
ApiElevenPlus.java
|
||||
|
@ -93,4 +103,38 @@ public class ApiElevenPlus {
|
|||
public static void setAudioManagerInCallMode(AudioManager manager) {
|
||||
manager.setMode(AudioManager.MODE_IN_COMMUNICATION);
|
||||
}
|
||||
|
||||
public static Intent prepareAddContactIntent(String displayName, String sipUri) {
|
||||
Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
|
||||
intent.putExtra(ContactsContract.Intents.Insert.NAME, displayName);
|
||||
|
||||
if (sipUri != null && sipUri.startsWith("sip:")) {
|
||||
sipUri = sipUri.substring(4);
|
||||
}
|
||||
|
||||
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
|
||||
ContentValues sipAddressRow = new ContentValues();
|
||||
sipAddressRow.put(Contacts.Data.MIMETYPE, SipAddress.CONTENT_ITEM_TYPE);
|
||||
sipAddressRow.put(SipAddress.SIP_ADDRESS, sipUri);
|
||||
data.add(sipAddressRow);
|
||||
intent.putParcelableArrayListExtra(Insert.DATA, data);
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
public static Intent prepareEditContactIntentWithSipAddress(int id, String sipUri) {
|
||||
Intent intent = new Intent(Intent.ACTION_EDIT, Contacts.CONTENT_URI);
|
||||
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, id);
|
||||
intent.setData(contactUri);
|
||||
|
||||
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
|
||||
ContentValues sipAddressRow = new ContentValues();
|
||||
sipAddressRow.put(Contacts.Data.MIMETYPE, SipAddress.CONTENT_ITEM_TYPE);
|
||||
sipAddressRow.put(SipAddress.SIP_ADDRESS, sipUri);
|
||||
data.add(sipAddressRow);
|
||||
data.add(sipAddressRow);
|
||||
intent.putParcelableArrayListExtra(Insert.DATA, data);
|
||||
|
||||
return intent;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import java.util.Set;
|
|||
import org.linphone.Contact;
|
||||
import org.linphone.R;
|
||||
import org.linphone.core.LinphoneAddress;
|
||||
import org.linphone.mediastream.Version;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
|
@ -18,7 +17,6 @@ import android.app.PendingIntent;
|
|||
import android.content.ContentProviderOperation;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
|
@ -32,12 +30,9 @@ import android.preference.Preference;
|
|||
import android.provider.ContactsContract;
|
||||
import android.provider.ContactsContract.CommonDataKinds;
|
||||
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
||||
import android.provider.ContactsContract.CommonDataKinds.SipAddress;
|
||||
import android.provider.ContactsContract.Contacts;
|
||||
import android.provider.ContactsContract.Data;
|
||||
import android.provider.ContactsContract.Intents.Insert;
|
||||
import android.text.ClipboardManager;
|
||||
import android.view.Display;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
||||
|
||||
|
@ -73,22 +68,9 @@ public class ApiFivePlus {
|
|||
Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
|
||||
intent.putExtra(ContactsContract.Intents.Insert.NAME, displayName);
|
||||
|
||||
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
||||
if (sipUri != null && sipUri.startsWith("sip:")) {
|
||||
sipUri = sipUri.substring(4);
|
||||
}
|
||||
|
||||
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
|
||||
ContentValues sipAddressRow = new ContentValues();
|
||||
sipAddressRow.put(Contacts.Data.MIMETYPE, SipAddress.CONTENT_ITEM_TYPE);
|
||||
sipAddressRow.put(SipAddress.SIP_ADDRESS, sipUri);
|
||||
data.add(sipAddressRow);
|
||||
intent.putParcelableArrayListExtra(Insert.DATA, data);
|
||||
} else {
|
||||
// VoIP field not available, we store the address in the IM field
|
||||
intent.putExtra(ContactsContract.Intents.Insert.IM_HANDLE, sipUri);
|
||||
intent.putExtra(ContactsContract.Intents.Insert.IM_PROTOCOL, "sip");
|
||||
}
|
||||
// VoIP field not available, we store the address in the IM field
|
||||
intent.putExtra(ContactsContract.Intents.Insert.IM_HANDLE, sipUri);
|
||||
intent.putExtra(ContactsContract.Intents.Insert.IM_PROTOCOL, "sip");
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
@ -106,24 +88,13 @@ public class ApiFivePlus {
|
|||
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, id);
|
||||
intent.setData(contactUri);
|
||||
|
||||
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
||||
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
|
||||
ContentValues sipAddressRow = new ContentValues();
|
||||
sipAddressRow.put(Contacts.Data.MIMETYPE, SipAddress.CONTENT_ITEM_TYPE);
|
||||
sipAddressRow.put(SipAddress.SIP_ADDRESS, sipUri);
|
||||
data.add(sipAddressRow);
|
||||
data.add(sipAddressRow);
|
||||
intent.putParcelableArrayListExtra(Insert.DATA, data);
|
||||
} else {
|
||||
// VoIP field not available, we store the address in the IM field
|
||||
intent.putExtra(ContactsContract.Intents.Insert.IM_HANDLE, sipUri);
|
||||
intent.putExtra(ContactsContract.Intents.Insert.IM_PROTOCOL, "sip");
|
||||
}
|
||||
// VoIP field not available, we store the address in the IM field
|
||||
intent.putExtra(ContactsContract.Intents.Insert.IM_HANDLE, sipUri);
|
||||
intent.putExtra(ContactsContract.Intents.Insert.IM_PROTOCOL, "sip");
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public static List<String> extractContactNumbersAndAddresses(String id, ContentResolver cr) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
|
||||
|
@ -141,41 +112,21 @@ public class ApiFivePlus {
|
|||
}
|
||||
|
||||
// SIP addresses
|
||||
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
||||
String selection = new StringBuilder()
|
||||
.append(Data.CONTACT_ID)
|
||||
.append(" = ? AND ")
|
||||
.append(Data.MIMETYPE)
|
||||
.append(" = '")
|
||||
.append(ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE)
|
||||
.append("'")
|
||||
.toString();
|
||||
projection = new String[] {ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS};
|
||||
c = cr.query(uri, projection, selection, new String[]{id}, null);
|
||||
if (c != null) {
|
||||
int nbId = c.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS);
|
||||
while (c.moveToNext()) {
|
||||
list.add("sip:" + c.getString(nbId));
|
||||
}
|
||||
c.close();
|
||||
}
|
||||
} else {
|
||||
String selection = new StringBuilder()
|
||||
.append(Data.CONTACT_ID).append(" = ? AND ")
|
||||
.append(Data.MIMETYPE).append(" = '")
|
||||
.append(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE)
|
||||
.append("' AND lower(")
|
||||
.append(ContactsContract.CommonDataKinds.Im.CUSTOM_PROTOCOL)
|
||||
.append(") = 'sip'")
|
||||
.toString();
|
||||
c = cr.query(uri, projection, selection, new String[]{id}, null);
|
||||
if (c != null) {
|
||||
int nbId = c.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA);
|
||||
while (c.moveToNext()) {
|
||||
list.add("sip:" + c.getString(nbId));
|
||||
}
|
||||
c.close();
|
||||
String selection = new StringBuilder()
|
||||
.append(Data.CONTACT_ID).append(" = ? AND ")
|
||||
.append(Data.MIMETYPE).append(" = '")
|
||||
.append(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE)
|
||||
.append("' AND lower(")
|
||||
.append(ContactsContract.CommonDataKinds.Im.CUSTOM_PROTOCOL)
|
||||
.append(") = 'sip'")
|
||||
.toString();
|
||||
c = cr.query(uri, projection, selection, new String[]{id}, null);
|
||||
if (c != null) {
|
||||
int nbId = c.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA);
|
||||
while (c.moveToNext()) {
|
||||
list.add("sip:" + c.getString(nbId));
|
||||
}
|
||||
c.close();
|
||||
}
|
||||
|
||||
return list;
|
||||
|
@ -185,45 +136,30 @@ public class ApiFivePlus {
|
|||
String req = Data.MIMETYPE + " = '" + CommonDataKinds.Phone.CONTENT_ITEM_TYPE
|
||||
+ "' AND " + CommonDataKinds.Phone.NUMBER + " IS NOT NULL";
|
||||
|
||||
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
||||
req += " OR (" + Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE
|
||||
+ "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " IS NOT NULL)";
|
||||
} else {
|
||||
req += " OR (" + Contacts.Data.MIMETYPE + " = '" + CommonDataKinds.Im.CONTENT_ITEM_TYPE
|
||||
+ "' AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip')";
|
||||
}
|
||||
req += " OR (" + Contacts.Data.MIMETYPE + " = '" + CommonDataKinds.Im.CONTENT_ITEM_TYPE
|
||||
+ "' AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip')";
|
||||
|
||||
return getGeneralContactCursor(cr, req, true);
|
||||
}
|
||||
|
||||
public static Cursor getSIPContactsCursor(ContentResolver cr) {
|
||||
String req = null;
|
||||
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
||||
req = Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE
|
||||
+ "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " IS NOT NULL";
|
||||
} else {
|
||||
req = Contacts.Data.MIMETYPE + " = '" + CommonDataKinds.Im.CONTENT_ITEM_TYPE
|
||||
+ "' AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip'";
|
||||
}
|
||||
req = Contacts.Data.MIMETYPE + " = '" + CommonDataKinds.Im.CONTENT_ITEM_TYPE
|
||||
+ "' AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip'";
|
||||
|
||||
return getGeneralContactCursor(cr, req, true);
|
||||
}
|
||||
|
||||
private static Cursor getSIPContactCursor(ContentResolver cr, String id) {
|
||||
String req = null;
|
||||
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
||||
req = Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE
|
||||
+ "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " LIKE '" + id + "'";
|
||||
} else {
|
||||
req = Contacts.Data.MIMETYPE + " = '" + CommonDataKinds.Im.CONTENT_ITEM_TYPE
|
||||
+ " AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip' AND "
|
||||
+ android.provider.ContactsContract.CommonDataKinds.Im.DATA + " LIKE '" + id + "'";
|
||||
}
|
||||
req = Contacts.Data.MIMETYPE + " = '" + CommonDataKinds.Im.CONTENT_ITEM_TYPE
|
||||
+ " AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip' AND "
|
||||
+ android.provider.ContactsContract.CommonDataKinds.Im.DATA + " LIKE '" + id + "'";
|
||||
|
||||
return getGeneralContactCursor(cr, req, false);
|
||||
}
|
||||
|
||||
private static Cursor getGeneralContactCursor(ContentResolver cr, String select, boolean shouldGroupBy) {
|
||||
public static Cursor getGeneralContactCursor(ContentResolver cr, String select, boolean shouldGroupBy) {
|
||||
|
||||
String[] projection = new String[] { Data.CONTACT_ID, Data.DISPLAY_NAME };
|
||||
|
||||
|
|
|
@ -1,13 +1,22 @@
|
|||
package org.linphone.compatibility;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.linphone.Contact;
|
||||
import org.linphone.R;
|
||||
import org.linphone.core.LinphoneAddress;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.ContentProviderOperation;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.ContactsContract;
|
||||
import android.provider.ContactsContract.CommonDataKinds;
|
||||
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
||||
import android.provider.ContactsContract.Data;
|
||||
|
||||
/*
|
||||
ApiNinePlus.java
|
||||
|
@ -80,4 +89,85 @@ public class ApiNinePlus {
|
|||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public static List<String> extractContactNumbersAndAddresses(String id, ContentResolver cr) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
|
||||
Uri uri = Data.CONTENT_URI;
|
||||
String[] projection = {ContactsContract.CommonDataKinds.Im.DATA};
|
||||
|
||||
// Phone Numbers
|
||||
Cursor c = cr.query(Phone.CONTENT_URI, new String[] { Phone.NUMBER }, Phone.CONTACT_ID + " = " + id, null, null);
|
||||
if (c != null) {
|
||||
while (c.moveToNext()) {
|
||||
String number = c.getString(c.getColumnIndex(Phone.NUMBER));
|
||||
list.add(number);
|
||||
}
|
||||
c.close();
|
||||
}
|
||||
|
||||
// SIP addresses
|
||||
String selection = new StringBuilder()
|
||||
.append(Data.CONTACT_ID)
|
||||
.append(" = ? AND ")
|
||||
.append(Data.MIMETYPE)
|
||||
.append(" = '")
|
||||
.append(ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE)
|
||||
.append("'")
|
||||
.toString();
|
||||
projection = new String[] {ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS};
|
||||
c = cr.query(uri, projection, selection, new String[]{id}, null);
|
||||
if (c != null) {
|
||||
int nbId = c.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS);
|
||||
while (c.moveToNext()) {
|
||||
list.add("sip:" + c.getString(nbId));
|
||||
}
|
||||
c.close();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public static Cursor getContactsCursor(ContentResolver cr) {
|
||||
String req = Data.MIMETYPE + " = '" + CommonDataKinds.Phone.CONTENT_ITEM_TYPE
|
||||
+ "' AND " + CommonDataKinds.Phone.NUMBER + " IS NOT NULL";
|
||||
|
||||
req += " OR (" + Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE
|
||||
+ "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " IS NOT NULL)";
|
||||
|
||||
return ApiFivePlus.getGeneralContactCursor(cr, req, true);
|
||||
}
|
||||
|
||||
public static Cursor getSIPContactsCursor(ContentResolver cr) {
|
||||
String req = null;
|
||||
req = Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE
|
||||
+ "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " IS NOT NULL";
|
||||
|
||||
return ApiFivePlus.getGeneralContactCursor(cr, req, true);
|
||||
}
|
||||
|
||||
private static Cursor getSIPContactCursor(ContentResolver cr, String id) {
|
||||
String req = null;
|
||||
req = Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE
|
||||
+ "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " LIKE '" + id + "'";
|
||||
|
||||
return ApiFivePlus.getGeneralContactCursor(cr, req, false);
|
||||
}
|
||||
|
||||
public static Uri findUriPictureOfContactAndSetDisplayName(LinphoneAddress address, ContentResolver cr) {
|
||||
String username = address.getUserName();
|
||||
String domain = address.getDomain();
|
||||
String sipUri = username + "@" + domain;
|
||||
|
||||
Cursor cursor = getSIPContactCursor(cr, sipUri);
|
||||
Contact contact = ApiFivePlus.getContact(cr, cursor, 0);
|
||||
if (contact != null && contact.getNumerosOrAddresses().contains(sipUri)) {
|
||||
address.setDisplayName(contact.getName());
|
||||
cursor.close();
|
||||
return contact.getPhotoUri();
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@ import android.graphics.Bitmap;
|
|||
import android.media.AudioManager;
|
||||
import android.net.Uri;
|
||||
import android.preference.Preference;
|
||||
import android.view.Display;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
||||
/**
|
||||
|
@ -51,10 +50,11 @@ public class Compatibility {
|
|||
}
|
||||
|
||||
public static Intent prepareAddContactIntent(String displayName, String sipUri) {
|
||||
if (Version.sdkAboveOrEqual(Version.API05_ECLAIR_20)) {
|
||||
if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) {
|
||||
return ApiElevenPlus.prepareAddContactIntent(displayName, sipUri);
|
||||
} else {
|
||||
return ApiFivePlus.prepareAddContactIntent(displayName, sipUri);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Intent prepareEditContactIntent(int id) {
|
||||
|
@ -65,31 +65,35 @@ public class Compatibility {
|
|||
}
|
||||
|
||||
public static Intent prepareEditContactIntentWithSipAddress(int id, String sipAddress) {
|
||||
if (Version.sdkAboveOrEqual(Version.API05_ECLAIR_20)) {
|
||||
return ApiFivePlus.prepareEditContactIntentWithSipAddress(id, sipAddress);
|
||||
if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) {
|
||||
return ApiElevenPlus.prepareEditContactIntentWithSipAddress(id, sipAddress);
|
||||
} else {
|
||||
return ApiFivePlus.prepareEditContactIntent(id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<String> extractContactNumbersAndAddresses(String id, ContentResolver cr) {
|
||||
if (Version.sdkAboveOrEqual(Version.API05_ECLAIR_20)) {
|
||||
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
||||
return ApiNinePlus.extractContactNumbersAndAddresses(id, cr);
|
||||
} else {
|
||||
return ApiFivePlus.extractContactNumbersAndAddresses(id, cr);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Cursor getContactsCursor(ContentResolver cr) {
|
||||
if (Version.sdkAboveOrEqual(Version.API05_ECLAIR_20)) {
|
||||
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
||||
return ApiNinePlus.getContactsCursor(cr);
|
||||
} else {
|
||||
return ApiFivePlus.getContactsCursor(cr);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Cursor getSIPContactsCursor(ContentResolver cr) {
|
||||
if (Version.sdkAboveOrEqual(Version.API05_ECLAIR_20)) {
|
||||
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
||||
return ApiNinePlus.getSIPContactsCursor(cr);
|
||||
} else {
|
||||
return ApiFivePlus.getSIPContactsCursor(cr);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getCursorDisplayNameColumnIndex(Cursor cursor) {
|
||||
|
@ -114,10 +118,11 @@ public class Compatibility {
|
|||
}
|
||||
|
||||
public static Uri findUriPictureOfContactAndSetDisplayName(LinphoneAddress address, ContentResolver cr) {
|
||||
if (Version.sdkAboveOrEqual(Version.API05_ECLAIR_20)) {
|
||||
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
||||
return ApiNinePlus.findUriPictureOfContactAndSetDisplayName(address, cr);
|
||||
} else {
|
||||
return ApiFivePlus.findUriPictureOfContactAndSetDisplayName(address, cr);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Notification createMessageNotification(Context context, int msgCount, String msgSender, String msg, Bitmap contactIcon, PendingIntent intent) {
|
||||
|
|
Loading…
Reference in a new issue