diff --git a/src/org/linphone/BluetoothManager.java b/src/org/linphone/BluetoothManager.java index 34982c4e0..b908a4359 100644 --- a/src/org/linphone/BluetoothManager.java +++ b/src/org/linphone/BluetoothManager.java @@ -19,7 +19,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import java.util.List; -import org.linphone.compatibility.Compatibility; import org.linphone.mediastream.Log; import android.annotation.TargetApi; @@ -81,7 +80,7 @@ public class BluetoothManager extends BroadcastReceiver { IntentFilter filter = new IntentFilter(); filter.addCategory(BluetoothHeadset.VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY + "." + BluetoothAssignedNumbers.PLANTRONICS); - filter.addAction(Compatibility.getAudioManagerEventForBluetoothConnectionStateChangedEvent()); + filter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED); filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT); mContext.registerReceiver(this, filter); @@ -278,7 +277,7 @@ public class BluetoothManager extends BroadcastReceiver { return; String action = intent.getAction(); - if (Compatibility.getAudioManagerEventForBluetoothConnectionStateChangedEvent().equals(action)) { + if (AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED.equals(action)) { int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, 0); if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) { Log.d("Bluetooth sco state => connected"); diff --git a/src/org/linphone/ChatFragment.java b/src/org/linphone/ChatFragment.java index 24604d69e..42e404914 100644 --- a/src/org/linphone/ChatFragment.java +++ b/src/org/linphone/ChatFragment.java @@ -44,6 +44,8 @@ import android.app.Activity; import android.app.Dialog; import android.app.Fragment; import android.app.ProgressDialog; +import android.content.ClipData; +import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.content.res.Configuration; @@ -827,7 +829,9 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC txt = message.getText(); } if (txt != null) { - Compatibility.copyTextToClipboard(getActivity(), txt); + ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = android.content.ClipData.newPlainText("Message", txt); + clipboard.setPrimaryClip(clip); LinphoneActivity.instance().displayCustomToast(getString(R.string.text_copied_to_clipboard), Toast.LENGTH_SHORT); } } diff --git a/src/org/linphone/ContactsManager.java b/src/org/linphone/ContactsManager.java index 4cbcdd7eb..b67f1453d 100644 --- a/src/org/linphone/ContactsManager.java +++ b/src/org/linphone/ContactsManager.java @@ -21,10 +21,11 @@ package org.linphone; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.Set; -import org.linphone.compatibility.Compatibility; import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneFriend; @@ -38,11 +39,13 @@ import android.content.ContentResolver; import android.content.Context; import android.database.ContentObserver; import android.database.Cursor; +import android.database.MatrixCursor; import android.net.Uri; import android.os.AsyncTask; import android.os.Handler; import android.os.Message; import android.provider.ContactsContract; +import android.provider.ContactsContract.CommonDataKinds; import android.provider.ContactsContract.Data; interface ContactsUpdatedListener { @@ -228,14 +231,13 @@ public class ContactsManager extends ContentObserver { contactsFetchTask.execute(); } - private class ContactsFetchTask extends AsyncTask, List> { @SuppressWarnings("unchecked") protected List doInBackground(Void... params) { List contacts = new ArrayList(); if (hasContactsAccess()) { - Cursor c = Compatibility.getContactsCursor(contentResolver, null); + Cursor c = getContactsCursor(contentResolver); if (c != null) { while (c.moveToNext()) { String id = c.getString(c.getColumnIndex(Data.CONTACT_ID)); @@ -367,4 +369,38 @@ public class ContactsManager extends ContentObserver { public String getString(int resourceID) { return context.getString(resourceID); } + + private Cursor getContactsCursor(ContentResolver cr) { + String req = "(" + Data.MIMETYPE + " = '" + CommonDataKinds.Phone.CONTENT_ITEM_TYPE + + "' AND " + CommonDataKinds.Phone.NUMBER + " IS NOT NULL " + + " OR (" + Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE + + "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " IS NOT NULL))"; + String[] projection = new String[] { Data.CONTACT_ID, Data.DISPLAY_NAME }; + String query = Data.DISPLAY_NAME + " IS NOT NULL AND (" + req + ")"; + + Cursor cursor = cr.query(Data.CONTENT_URI, projection, query, null, " lower(" + Data.DISPLAY_NAME + ") COLLATE UNICODE ASC"); + if (cursor == null) { + return cursor; + } + + MatrixCursor result = new MatrixCursor(cursor.getColumnNames()); + Set groupBy = new HashSet(); + while (cursor.moveToNext()) { + String name = cursor.getString(cursor.getColumnIndex(Data.DISPLAY_NAME)); + if (!groupBy.contains(name)) { + groupBy.add(name); + Object[] newRow = new Object[cursor.getColumnCount()]; + + int contactID = cursor.getColumnIndex(Data.CONTACT_ID); + int displayName = cursor.getColumnIndex(Data.DISPLAY_NAME); + + newRow[contactID] = cursor.getString(contactID); + newRow[displayName] = cursor.getString(displayName); + + result.addRow(newRow); + } + } + cursor.close(); + return result; + } } diff --git a/src/org/linphone/LinphoneManager.java b/src/org/linphone/LinphoneManager.java index 232e1b4d9..d09a88545 100644 --- a/src/org/linphone/LinphoneManager.java +++ b/src/org/linphone/LinphoneManager.java @@ -36,7 +36,6 @@ import java.util.Set; import java.util.Timer; import java.util.TimerTask; -import org.linphone.compatibility.Compatibility; import org.linphone.core.CallDirection; import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneBuffer; @@ -1046,7 +1045,16 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag } return null; } - + + public void setAudioManagerInCallMode() { + if (mAudioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION) { + Log.w("---AudioManager: already in MODE_IN_COMMUNICATION, skipping..."); + return; + } + Log.d("---AudioManager: set mode to MODE_IN_COMMUNICATION"); + mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); + } + @SuppressLint("Wakelock") public void callState(final LinphoneCore lc,final LinphoneCall call, final State state, final String message) { Log.i("New call state [",state,"]"); @@ -1082,7 +1090,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag if (state == State.Connected) { if (mLc.getCallsNb() == 1) { requestAudioFocus(); - Compatibility.setAudioManagerInCallMode(mAudioManager); + setAudioManagerInCallMode(); } if (Hacks.needSoftvolume()) { @@ -1092,7 +1100,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag } if (state == State.OutgoingEarlyMedia) { - Compatibility.setAudioManagerInCallMode(mAudioManager); + setAudioManagerInCallMode(); } if (state == State.CallReleased || state == State.Error) { @@ -1172,7 +1180,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag public void startEcCalibration(LinphoneCoreListener l) throws LinphoneCoreException { routeAudioToSpeaker(); - Compatibility.setAudioManagerInCallMode((AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE)); + setAudioManagerInCallMode(); Log.i("Set audio mode on 'Voice Communication'"); int oldVolume = mAudioManager.getStreamVolume(STREAM_VOICE_CALL); int maxVolume = mAudioManager.getStreamMaxVolume(STREAM_VOICE_CALL); @@ -1390,11 +1398,11 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag if (nearby) { params.screenBrightness = 0.1f; view.setVisibility(View.INVISIBLE); - Compatibility.hideNavigationBar(activity); + activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); } else { params.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE; view.setVisibility(View.VISIBLE); - Compatibility.showNavigationBar(activity); + activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); } window.setAttributes(params); } diff --git a/src/org/linphone/compatibility/ApiEightPlus.java b/src/org/linphone/compatibility/ApiEightPlus.java deleted file mode 100644 index 295e3bf9c..000000000 --- a/src/org/linphone/compatibility/ApiEightPlus.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.linphone.compatibility; - -import android.annotation.TargetApi; -import android.media.AudioManager; - -/* -ApiEightPlus.java -Copyright (C) 2012 Belledonne Communications, Grenoble, France - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -/** - * @author Sylvain Berfini - */ - -@TargetApi(8) -public class ApiEightPlus { - - @SuppressWarnings("deprecation") - public static String getAudioManagerEventForBluetoothConnectionStateChangedEvent() { - return AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED; - } -} \ No newline at end of file diff --git a/src/org/linphone/compatibility/ApiElevenPlus.java b/src/org/linphone/compatibility/ApiElevenPlus.java index d763c5221..7b30e5581 100644 --- a/src/org/linphone/compatibility/ApiElevenPlus.java +++ b/src/org/linphone/compatibility/ApiElevenPlus.java @@ -3,19 +3,15 @@ package org.linphone.compatibility; import java.util.ArrayList; import org.linphone.R; -import org.linphone.mediastream.Log; import android.annotation.TargetApi; 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.CommonDataKinds.SipAddress; @@ -119,21 +115,6 @@ public class ApiElevenPlus { return notif; } - - public static void copyTextToClipboard(Context context, String msg) { - ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip = android.content.ClipData.newPlainText("Message", msg); - clipboard.setPrimaryClip(clip); - } - - public static void setAudioManagerInCallMode(AudioManager manager) { - if (manager.getMode() == AudioManager.MODE_IN_COMMUNICATION) { - Log.w("---AudioManager: already in MODE_IN_COMMUNICATION, skipping..."); - return; - } - Log.d("---AudioManager: set mode to MODE_IN_COMMUNICATION"); - manager.setMode(AudioManager.MODE_IN_COMMUNICATION); - } public static Intent prepareAddContactIntent(String displayName, String sipUri) { Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI); diff --git a/src/org/linphone/compatibility/ApiFivePlus.java b/src/org/linphone/compatibility/ApiFivePlus.java deleted file mode 100644 index 7adc28c1e..000000000 --- a/src/org/linphone/compatibility/ApiFivePlus.java +++ /dev/null @@ -1,406 +0,0 @@ -package org.linphone.compatibility; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.linphone.LinphoneContact; -import org.linphone.R; -import org.linphone.core.LinphoneAddress; - -import android.annotation.TargetApi; -import android.app.Activity; -import android.app.Notification; -import android.app.PendingIntent; -import android.content.ContentProviderOperation; -import android.content.ContentResolver; -import android.content.ContentUris; -import android.content.Context; -import android.content.Intent; -import android.database.Cursor; -import android.database.MatrixCursor; -import android.media.AudioManager; -import android.net.Uri; -import android.preference.CheckBoxPreference; -import android.preference.Preference; -import android.provider.ContactsContract; -import android.provider.ContactsContract.CommonDataKinds; -import android.provider.ContactsContract.CommonDataKinds.Phone; -import android.provider.ContactsContract.Contacts; -import android.provider.ContactsContract.Data; -import android.support.v4.app.NotificationCompat; -import android.text.ClipboardManager; -import android.text.TextUtils; -import android.view.ViewTreeObserver; -import android.view.ViewTreeObserver.OnGlobalLayoutListener; - -/* -ApiFivePlus.java -Copyright (C) 2012 Belledonne Communications, Grenoble, France - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -/** - * @author Sylvain Berfini - */ -@SuppressWarnings("deprecation") -@TargetApi(5) -public class ApiFivePlus { - public static void overridePendingTransition(Activity activity, int idAnimIn, int idAnimOut) { - activity.overridePendingTransition(idAnimIn, idAnimOut); - } - - 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); - - // 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; - } - - public static Intent prepareEditContactIntent(int id) { - Intent intent = new Intent(Intent.ACTION_EDIT, Contacts.CONTENT_URI); - Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, id); - intent.setData(contactUri); - - 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); - - // 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; - } - - public static List extractContactNumbersAndAddresses(String id, ContentResolver cr) { - List list = new ArrayList(); - - Uri uri = Data.CONTENT_URI; - String[] projection = {ContactsContract.CommonDataKinds.Im.DATA}; - - // IM addresses - 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(); - Cursor 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(); - } - - // Phone Numbers - 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(); - } - - return list; - } - - public static Cursor getContactsCursor(ContentResolver cr, List ids) { - String req = Data.MIMETYPE + " = '" + CommonDataKinds.Phone.CONTENT_ITEM_TYPE - + "' AND " + CommonDataKinds.Phone.NUMBER + " IS NOT NULL"; - - req += " OR (" + Contacts.Data.MIMETYPE + " = '" + CommonDataKinds.Im.CONTENT_ITEM_TYPE - + "' AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip')"; - - if(ids != null){ - String s = TextUtils.join(",", ids); - req += " OR (" + Data.CONTACT_ID + " IN (" + s + "))"; - } - - return getGeneralContactCursor(cr, req, true); - } - - public static Cursor getSIPContactsCursor(ContentResolver cr, List ids) { - String req = null; - req = Contacts.Data.MIMETYPE + " = '" + CommonDataKinds.Im.CONTENT_ITEM_TYPE - + "' AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip'"; - - if(ids != null){ - String s = TextUtils.join(",", ids); - req += " OR (" + Data.CONTACT_ID + " IN (" + s + "))"; - } - - return getGeneralContactCursor(cr, req, true); - } - - private static Cursor getSIPContactCursor(ContentResolver cr, String id) { - String req = null; - 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); - } - - public static Cursor getGeneralContactCursor(ContentResolver cr, String select, boolean shouldGroupBy) { - String[] projection = new String[] { Data.CONTACT_ID, Data.DISPLAY_NAME }; - String query; - - query = Data.DISPLAY_NAME + " IS NOT NULL AND (" + select + ")"; - - Cursor cursor = cr.query(Data.CONTENT_URI, projection, query, null, " lower(" + Data.DISPLAY_NAME + ") COLLATE UNICODE ASC"); - - if (!shouldGroupBy || cursor == null) { - return cursor; - } - - MatrixCursor result = new MatrixCursor(cursor.getColumnNames()); - Set groupBy = new HashSet(); - while (cursor.moveToNext()) { - String name = cursor.getString(getCursorDisplayNameColumnIndex(cursor)); - if (!groupBy.contains(name)) { - groupBy.add(name); - Object[] newRow = new Object[cursor.getColumnCount()]; - - int contactID = cursor.getColumnIndex(Data.CONTACT_ID); - int displayName = cursor.getColumnIndex(Data.DISPLAY_NAME); - - newRow[contactID] = cursor.getString(contactID); - newRow[displayName] = cursor.getString(displayName); - - result.addRow(newRow); - } - } - cursor.close(); - return result; - } - - public static int getCursorDisplayNameColumnIndex(Cursor cursor) { - return cursor.getColumnIndex(Data.DISPLAY_NAME); - } - - public static LinphoneContact getContact(ContentResolver cr, Cursor cursor, int position) { - try { - if(cursor != null) { - cursor.moveToFirst(); - boolean success = cursor.move(position); - if (!success) - return null; - - String id = cursor.getString(cursor.getColumnIndex(Data.CONTACT_ID)); - String name = getContactDisplayName(cursor); - Uri thumbnail = getContactPictureUri(id); - Uri photo = getContactPhotoUri(id); - InputStream input = getContactPictureInputStream(cr, id); - - LinphoneContact contact = new LinphoneContact(); - contact.setAndroidId(id); - contact.setFullName(name); - if (input != null) { - contact.setPhotoUri(photo); - contact.setThumbnailUri(thumbnail); - } - - return contact; - } else { - return null; - } - } catch (Exception e) { - - } - return null; - } - - public static InputStream getContactPictureInputStream(ContentResolver cr, String id) { - Uri person = ContentUris.withAppendedId(Contacts.CONTENT_URI, Long.parseLong(id)); - return Contacts.openContactPhotoInputStream(cr, person); - } - - private static String getContactDisplayName(Cursor cursor) { - return cursor.getString(cursor.getColumnIndex(Data.DISPLAY_NAME)); - } - - private static Uri getContactPictureUri(String id) { - Uri person = ContentUris.withAppendedId(Contacts.CONTENT_URI, Long.parseLong(id)); - return Uri.withAppendedPath(person, Contacts.Photo.CONTENT_DIRECTORY); - } - - private static Uri getContactPhotoUri(String id) { - Uri person = ContentUris.withAppendedId(Contacts.CONTENT_URI, Long.parseLong(id)); - return Uri.withAppendedPath(person, Contacts.Photo.DISPLAY_PHOTO); - } - - 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); - if(cursor != null) { - LinphoneContact contact = getContact(cr, cursor, 0); - if (contact != null && contact.getNumbersOrAddresses().contains(sipUri)) { - address.setDisplayName(contact.getFullName()); - cursor.close(); - return contact.getPhotoUri(); - } - cursor.close(); - } - return null; - } - - public static String refreshContactName(ContentResolver cr, String id) { - Cursor cursor = getGeneralContactCursor(cr, Data.CONTACT_ID + " = '" + id + "'", false); - if (cursor != null && cursor.moveToFirst()) { - String contactDisplayName = getContactDisplayName(cursor); - cursor.close(); - return contactDisplayName; - } - return null; - } - - public static Notification createMessageNotification(Context context, String title, String msg, PendingIntent intent) { - Notification notif = new Notification(); - notif.icon = R.drawable.topbar_chat_notification; - notif.iconLevel = 0; - notif.when = System.currentTimeMillis(); - notif.flags &= Notification.FLAG_ONGOING_EVENT; - - notif.defaults |= Notification.DEFAULT_VIBRATE; - notif.defaults |= Notification.DEFAULT_SOUND; - notif.defaults |= Notification.DEFAULT_LIGHTS; - - return notif; - } - - public static Notification createInCallNotification(Context context, String title, String msg, int iconID, PendingIntent intent) { - NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context) - .setSmallIcon(iconID) - .setContentTitle(title) - .setContentText(msg) - .setContentIntent(intent); - - return notifBuilder.build(); - } - - public static void setPreferenceChecked(Preference preference, boolean checked) { - ((CheckBoxPreference) preference).setChecked(checked); - } - - public static boolean isPreferenceChecked(Preference preference) { - return ((CheckBoxPreference) preference).isChecked(); - } - - public static void copyTextToClipboard(Context context, String msg) { - ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - clipboard.setText(msg); - } - - public static void addSipAddressToContact(Context context, ArrayList ops, String sipAddress) { - ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) - .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) - .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE) - .withValue(ContactsContract.CommonDataKinds.Im.DATA, sipAddress) - .withValue(ContactsContract.CommonDataKinds.Im.TYPE, ContactsContract.CommonDataKinds.Im.TYPE_CUSTOM) - .withValue(ContactsContract.CommonDataKinds.Im.LABEL, context.getString(R.string.addressbook_label)) - .build() - ); - } - - public static void addSipAddressToContact(Context context, ArrayList ops, String sipAddress, String rawContactID) { - ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) - .withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactID) - .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE) - .withValue(ContactsContract.CommonDataKinds.Im.DATA, sipAddress) - .withValue(ContactsContract.CommonDataKinds.Im.TYPE, ContactsContract.CommonDataKinds.Im.TYPE_CUSTOM) - .withValue(ContactsContract.CommonDataKinds.Im.LABEL, context.getString(R.string.addressbook_label)) - .build() - ); - } - - public static void updateSipAddressForContact(ArrayList ops, String oldSipAddress, String newSipAddress, String contactID) { - String select = ContactsContract.Data.CONTACT_ID + "=? AND " - + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE + "' AND " - + ContactsContract.CommonDataKinds.Im.DATA + "=?"; - String[] args = new String[] { String.valueOf(contactID), oldSipAddress }; - - ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI) - .withSelection(select, args) - .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE) - .withValue(ContactsContract.CommonDataKinds.Im.DATA, newSipAddress) - .build() - ); - } - - public static void deleteSipAddressFromContact(ArrayList ops, String oldSipAddress, String contactID) { - String select = ContactsContract.Data.CONTACT_ID + "=? AND " - + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE + "' AND " - + ContactsContract.CommonDataKinds.Im.DATA + "=?"; - String[] args = new String[] { String.valueOf(contactID), oldSipAddress }; - - ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI) - .withSelection(select, args) - .build() - ); - } - - public static void removeGlobalLayoutListener(ViewTreeObserver viewTreeObserver, OnGlobalLayoutListener keyboardListener) { - viewTreeObserver.removeGlobalOnLayoutListener(keyboardListener); - } - - public static void setAudioManagerInCallMode(AudioManager manager) { - /* Do not use MODE_IN_CALL, because it is reserved to GSM. This is causing conflicts on audio system resulting in silenced audio.*/ - //manager.setMode(AudioManager.MODE_IN_CALL); - } - - public static Notification createNotification(Context context, String title, String message, int icon, int level, PendingIntent intent, boolean isOngoingEvent) { - NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context) - .setSmallIcon(icon, level) - .setContentTitle(title) - .setContentText(message) - .setContentIntent(intent); - - return notifBuilder.build(); - } - - public static Notification createSimpleNotification(Context context, String title, String text, PendingIntent intent) { - NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context) - .setSmallIcon(R.drawable.linphone_logo) - .setContentTitle(title) - .setContentText(text) - .setContentIntent(intent); - - Notification notif = notifBuilder.build(); - notif.defaults |= Notification.DEFAULT_VIBRATE; - notif.defaults |= Notification.DEFAULT_SOUND; - notif.defaults |= Notification.DEFAULT_LIGHTS; - - return notif; - } -} diff --git a/src/org/linphone/compatibility/ApiFourteenPlus.java b/src/org/linphone/compatibility/ApiFourteenPlus.java deleted file mode 100644 index df480ad78..000000000 --- a/src/org/linphone/compatibility/ApiFourteenPlus.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.linphone.compatibility; - -import android.annotation.TargetApi; -import android.app.Activity; -import android.media.AudioManager; -import android.preference.Preference; -import android.preference.TwoStatePreference; -import android.view.View; - -/* -ApiFourteenPlus.java -Copyright (C) 2012 Belledonne Communications, Grenoble, France - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -/** - * @author Sylvain Berfini - */ -@TargetApi(14) -public class ApiFourteenPlus { - - public static void setPreferenceChecked(Preference preference, boolean checked) { - ((TwoStatePreference) preference).setChecked(checked); - } - - public static boolean isPreferenceChecked(Preference preference) { - return ((TwoStatePreference) preference).isChecked(); - } - - public static void hideNavigationBar(Activity activity) { - activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); - } - - public static void showNavigationBar(Activity activity) { - activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); - } - - public static String getAudioManagerEventForBluetoothConnectionStateChangedEvent() { - return AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED; - } -} diff --git a/src/org/linphone/compatibility/ApiNinePlus.java b/src/org/linphone/compatibility/ApiNinePlus.java deleted file mode 100644 index 313ee4d1a..000000000 --- a/src/org/linphone/compatibility/ApiNinePlus.java +++ /dev/null @@ -1,195 +0,0 @@ -package org.linphone.compatibility; - -import java.util.ArrayList; -import java.util.List; - -import org.linphone.LinphoneContact; -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.Contacts; -import android.provider.ContactsContract.Data; -import android.text.TextUtils; - -/* -ApiNinePlus.java -Copyright (C) 2012 Belledonne Communications, Grenoble, France - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -/** - * @author Sylvain Berfini - */ -@TargetApi(9) -public class ApiNinePlus { - - public static void addSipAddressToContact(Context context, ArrayList ops, String sipAddress) { - ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) - .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) - .withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE) - .withValue(ContactsContract.CommonDataKinds.SipAddress.DATA, sipAddress) - .withValue(CommonDataKinds.SipAddress.TYPE, CommonDataKinds.SipAddress.TYPE_CUSTOM) - .withValue(CommonDataKinds.SipAddress.LABEL, context.getString(R.string.addressbook_label)) - .build() - ); - } - - public static void addSipAddressToContact(Context context, ArrayList ops, String sipAddress, String rawContactID) { - ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) - .withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactID) - .withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE) - .withValue(ContactsContract.CommonDataKinds.SipAddress.DATA, sipAddress) - .withValue(CommonDataKinds.SipAddress.TYPE, CommonDataKinds.SipAddress.TYPE_CUSTOM) - .withValue(CommonDataKinds.SipAddress.LABEL, context.getString(R.string.addressbook_label)) - .build() - ); - } - - public static void updateSipAddressForContact(ArrayList ops, String oldSipAddress, String newSipAddress, String contactID) { - String select = ContactsContract.Data.CONTACT_ID + "=? AND " - + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE + "' AND " - + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + "=?"; - String[] args = new String[] { String.valueOf(contactID), oldSipAddress }; - - ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI) - .withSelection(select, args) - .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE) - .withValue(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS, newSipAddress) - .build() - ); - } - - public static void deleteSipAddressFromContact(ArrayList ops, String oldSipAddress, String contactID) { - String select = ContactsContract.Data.CONTACT_ID + "=? AND " - + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE + "' AND " - + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + "=? "; - String[] args = new String[] { String.valueOf(contactID), oldSipAddress }; - - ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI) - .withSelection(select, args) - .build() - ); - } - - public static List extractContactNumbersAndAddresses(String id, ContentResolver cr) { - List list = new ArrayList(); - - Uri uri = Data.CONTENT_URI; - String[] projection; - - // SIP addresses - String selection2 = 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}; - Cursor c = cr.query(uri, projection, selection2, 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(); - } - - // Phone Numbers - 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(); - } - - return list; - } - - public static Cursor getContactsCursor(ContentResolver cr, String search, List ids) { - String req; - if(ids != null && ids.size() > 0) { - req = "(" + Data.MIMETYPE + " = '" + CommonDataKinds.Phone.CONTENT_ITEM_TYPE - + "' AND " + CommonDataKinds.Phone.NUMBER + " IS NOT NULL " - + " OR (" + Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE - + "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " IS NOT NULL)" - + " OR (" + Data.CONTACT_ID + " IN (" + TextUtils.join(" , ", ids) + ")))"; - } else { - req = "(" + Data.MIMETYPE + " = '" + CommonDataKinds.Phone.CONTENT_ITEM_TYPE - + "' AND " + CommonDataKinds.Phone.NUMBER + " IS NOT NULL " - + " OR (" + Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE - + "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " IS NOT NULL))"; - } - - if (search != null) { - req += " AND " + Data.DISPLAY_NAME + " LIKE '%" + search + "%'"; - } - - return ApiFivePlus.getGeneralContactCursor(cr, req, true); - } - - public static Cursor getSIPContactsCursor(ContentResolver cr, String search, List ids) { - - String req = "(" + Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE - + "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " IS NOT NULL) "; - - if(ids != null && ids.size() > 0) { - req += " OR (" + Data.CONTACT_ID + " IN (" + TextUtils.join(" , ", ids) + "))"; - } - - if (search != null) { - req += " AND " + Data.DISPLAY_NAME + " LIKE '%" + search + "%'"; - } - - return ApiFivePlus.getGeneralContactCursor(cr, req, true); - } - - private static Cursor getSIPContactCursor(ContentResolver cr, String id) { - String req = null; - req = Contacts.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); - LinphoneContact contact = ApiFivePlus.getContact(cr, cursor, 0); - if (contact != null && contact.getNumbersOrAddresses().contains(sipUri)) { - address.setDisplayName(contact.getFullName()); - cursor.close(); - return contact.getPhotoUri(); - } - - cursor.close(); - return null; - } -} diff --git a/src/org/linphone/compatibility/Compatibility.java b/src/org/linphone/compatibility/Compatibility.java index 556498c6d..b37e784b4 100644 --- a/src/org/linphone/compatibility/Compatibility.java +++ b/src/org/linphone/compatibility/Compatibility.java @@ -17,18 +17,12 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import java.util.List; - import org.linphone.mediastream.Version; -import android.app.Activity; import android.app.Notification; import android.app.PendingIntent; -import android.content.ContentResolver; import android.content.Context; -import android.database.Cursor; import android.graphics.Bitmap; -import android.media.AudioManager; import android.os.PowerManager; import android.provider.Settings; import android.text.Html; @@ -39,61 +33,38 @@ import android.view.ViewTreeObserver.OnGlobalLayoutListener; * @author Sylvain Berfini */ public class Compatibility { - public static Cursor getContactsCursor(ContentResolver cr, List contactsId) { - if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) { - return ApiNinePlus.getContactsCursor(cr, null, contactsId); - } else { - return ApiFivePlus.getContactsCursor(cr, contactsId); - } - } - public static Notification createSimpleNotification(Context context, String title, String text, PendingIntent intent) { Notification notif = null; - if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) { return ApiTwentyOnePlus.createSimpleNotification(context, title, text, intent); } else if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) { notif = ApiSixteenPlus.createSimpleNotification(context, title, text, intent); - } else if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) { - notif = ApiElevenPlus.createSimpleNotification(context, title, text, intent); } else { - notif = ApiFivePlus.createSimpleNotification(context, title, text, intent); + notif = ApiElevenPlus.createSimpleNotification(context, title, text, intent); } return notif; } public static Notification createMessageNotification(Context context, int msgCount, String msgSender, String msg, Bitmap contactIcon, PendingIntent intent) { - Notification notif = null; - String title; - if (msgCount == 1) { - title = "Unread message from %s".replace("%s", msgSender); - } else { - title = "%i unread messages".replace("%i", String.valueOf(msgCount)); - } - + Notification notif = null; if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) { return ApiTwentyOnePlus.createMessageNotification(context, msgCount, msgSender, msg, contactIcon, intent); } else if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) { notif = ApiSixteenPlus.createMessageNotification(context, msgCount, msgSender, msg, contactIcon, intent); - } else if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) { - notif = ApiElevenPlus.createMessageNotification(context, msgCount, msgSender, msg, contactIcon, intent); } else { - notif = ApiFivePlus.createMessageNotification(context, title, msg, intent); + notif = ApiElevenPlus.createMessageNotification(context, msgCount, msgSender, msg, contactIcon, intent); } return notif; } public static Notification createInCallNotification(Context context, String title, String msg, int iconID, Bitmap contactIcon, String contactName, PendingIntent intent) { Notification notif = null; - if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) { return ApiTwentyOnePlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent); } else if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) { notif = ApiSixteenPlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent); - } else if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) { - notif = ApiElevenPlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent); } else { - notif = ApiFivePlus.createInCallNotification(context, title, msg, iconID, intent); + notif = ApiElevenPlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent); } return notif; } @@ -103,10 +74,8 @@ public class Compatibility { return ApiTwentyOnePlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent, isOngoingEvent,priority); } else if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) { return ApiSixteenPlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent, isOngoingEvent,priority); - } else if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) { - return ApiElevenPlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent, isOngoingEvent); } else { - return ApiFivePlus.createNotification(context, title, message, icon, iconLevel, intent, isOngoingEvent); + return ApiElevenPlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent, isOngoingEvent); } } @@ -119,47 +88,12 @@ public class Compatibility { return null; } - public static void copyTextToClipboard(Context context, String msg) { - if(Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) { - ApiElevenPlus.copyTextToClipboard(context, msg); - } else { - ApiFivePlus.copyTextToClipboard(context, msg); - } - } - + @SuppressWarnings("deprecation") public static void removeGlobalLayoutListener(ViewTreeObserver viewTreeObserver, OnGlobalLayoutListener keyboardListener) { if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) { ApiSixteenPlus.removeGlobalLayoutListener(viewTreeObserver, keyboardListener); } else { - ApiFivePlus.removeGlobalLayoutListener(viewTreeObserver, keyboardListener); - } - } - - public static void hideNavigationBar(Activity activity) { - if (Version.sdkAboveOrEqual(Version.API14_ICE_CREAM_SANDWICH_40)) { - ApiFourteenPlus.hideNavigationBar(activity); - } - } - - public static void showNavigationBar(Activity activity) { - if (Version.sdkAboveOrEqual(Version.API14_ICE_CREAM_SANDWICH_40)) { - ApiFourteenPlus.showNavigationBar(activity); - } - } - - public static void setAudioManagerInCallMode(AudioManager manager) { - if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) { - ApiElevenPlus.setAudioManagerInCallMode(manager); - } else { - ApiFivePlus.setAudioManagerInCallMode(manager); - } - } - - public static String getAudioManagerEventForBluetoothConnectionStateChangedEvent() { - if (Version.sdkAboveOrEqual(Version.API14_ICE_CREAM_SANDWICH_40)) { - return ApiFourteenPlus.getAudioManagerEventForBluetoothConnectionStateChangedEvent(); - } else { - return ApiEightPlus.getAudioManagerEventForBluetoothConnectionStateChangedEvent(); + viewTreeObserver.removeGlobalOnLayoutListener(keyboardListener); } } diff --git a/src/org/linphone/gcm/GCMService.java b/src/org/linphone/gcm/GCMService.java index ebeb8f7f6..ebfc1273f 100644 --- a/src/org/linphone/gcm/GCMService.java +++ b/src/org/linphone/gcm/GCMService.java @@ -53,13 +53,13 @@ public class GCMService extends GCMBaseIntentService { @Override protected void onError(Context context, String errorId) { initLogger(context); - Log.e("Error while registering push notification : " + errorId); + Log.e("[Push Notification] Error while registering: " + errorId); } @Override protected void onMessage(Context context, Intent intent) { initLogger(context); - Log.d("Push notification received"); + Log.d("[Push Notification] Received"); if (!LinphoneService.isReady()) { startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class)); @@ -79,7 +79,7 @@ public class GCMService extends GCMBaseIntentService { @Override protected void onRegistered(Context context, String regId) { initLogger(context); - Log.d("Registered push notification : " + regId); + Log.d("[Push Notification] Registered: " + regId); LinphonePreferences.instance().setPushNotificationRegistrationID(regId); } @@ -87,7 +87,7 @@ public class GCMService extends GCMBaseIntentService { @Override protected void onUnregistered(Context context, String regId) { initLogger(context); - Log.w("Unregistered push notification : " + regId); + Log.w("[Push Notification] Unregistered: " + regId); LinphonePreferences.instance().setPushNotificationRegistrationID(null); }