Added setting for contacts shortcuts and related improvements
This commit is contained in:
parent
d80891729d
commit
1fb84ad046
10 changed files with 80 additions and 94 deletions
|
@ -32,7 +32,6 @@ import android.provider.ContactsContract;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import org.linphone.call.CallIncomingActivity;
|
import org.linphone.call.CallIncomingActivity;
|
||||||
import org.linphone.call.CallOutgoingActivity;
|
import org.linphone.call.CallOutgoingActivity;
|
||||||
import org.linphone.compatibility.Compatibility;
|
|
||||||
import org.linphone.contacts.ContactsManager;
|
import org.linphone.contacts.ContactsManager;
|
||||||
import org.linphone.core.Call;
|
import org.linphone.core.Call;
|
||||||
import org.linphone.core.Call.State;
|
import org.linphone.core.Call.State;
|
||||||
|
@ -215,8 +214,6 @@ public final class LinphoneService extends Service {
|
||||||
}
|
}
|
||||||
mContactsManager.initializeContactManager();
|
mContactsManager.initializeContactManager();
|
||||||
|
|
||||||
Compatibility.createChatShortcuts(this);
|
|
||||||
|
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,18 +29,22 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import org.linphone.LinphoneManager;
|
import org.linphone.LinphoneManager;
|
||||||
import org.linphone.R;
|
import org.linphone.contacts.ContactsManager;
|
||||||
|
import org.linphone.contacts.LinphoneContact;
|
||||||
|
import org.linphone.core.Address;
|
||||||
import org.linphone.core.ChatRoom;
|
import org.linphone.core.ChatRoom;
|
||||||
import org.linphone.core.ChatRoomCapabilities;
|
import org.linphone.core.ChatRoomCapabilities;
|
||||||
|
import org.linphone.core.tools.Log;
|
||||||
|
import org.linphone.settings.LinphonePreferences;
|
||||||
import org.linphone.utils.LinphoneShortcutManager;
|
import org.linphone.utils.LinphoneShortcutManager;
|
||||||
|
|
||||||
@TargetApi(25)
|
@TargetApi(25)
|
||||||
class ApiTwentyFivePlus {
|
class ApiTwentyFivePlus {
|
||||||
|
|
||||||
public static void createChatShortcuts(Context context) {
|
public static void createChatShortcuts(Context context) {
|
||||||
if (!context.getResources().getBoolean(R.bool.create_most_recent_chat_rooms_shortcuts))
|
if (!LinphonePreferences.instance().shortcutsCreationEnabled()) return;
|
||||||
return;
|
|
||||||
|
|
||||||
|
LinphoneShortcutManager manager = new LinphoneShortcutManager(context);
|
||||||
ShortcutManager shortcutManager =
|
ShortcutManager shortcutManager =
|
||||||
(ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE);
|
(ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE);
|
||||||
ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
|
ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
|
||||||
|
@ -64,37 +68,37 @@ class ApiTwentyFivePlus {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
LinphoneShortcutManager manager = new LinphoneShortcutManager(context);
|
int i = 0;
|
||||||
int maxShortcuts =
|
int maxShortcuts =
|
||||||
min(notEmptyOneToOneRooms.size(), shortcutManager.getMaxShortcutCountPerActivity());
|
min(notEmptyOneToOneRooms.size(), shortcutManager.getMaxShortcutCountPerActivity());
|
||||||
for (int i = 0; i < maxShortcuts; i++) {
|
ArrayList<LinphoneContact> contacts = new ArrayList<>();
|
||||||
|
for (ChatRoom room : notEmptyOneToOneRooms) {
|
||||||
// Android can only have around 4-5 shortcuts at a time
|
// Android can only have around 4-5 shortcuts at a time
|
||||||
ChatRoom room = notEmptyOneToOneRooms.get(i);
|
if (i >= maxShortcuts) break;
|
||||||
ShortcutInfo shortcut = manager.createChatRoomShortcutInfo(room);
|
|
||||||
if (shortcut != null) {
|
Address participantAddress =
|
||||||
shortcuts.add(shortcut);
|
room.hasCapability(ChatRoomCapabilities.Basic.toInt())
|
||||||
|
? room.getPeerAddress()
|
||||||
|
: room.getParticipants()[0].getAddress();
|
||||||
|
LinphoneContact contact =
|
||||||
|
ContactsManager.getInstance().findContactFromAddress(participantAddress);
|
||||||
|
|
||||||
|
if (contact != null && !contacts.contains(contact)) {
|
||||||
|
String peerAddress = room.getPeerAddress().asStringUriOnly();
|
||||||
|
ShortcutInfo shortcut = manager.createChatRoomShortcutInfo(contact, peerAddress);
|
||||||
|
if (shortcut != null) {
|
||||||
|
Log.i(
|
||||||
|
"[Shortcut] Creating launcher shortcut "
|
||||||
|
+ shortcut.getShortLabel()
|
||||||
|
+ " for room "
|
||||||
|
+ shortcut.getId());
|
||||||
|
shortcuts.add(shortcut);
|
||||||
|
contacts.add(contact);
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
shortcutManager.setDynamicShortcuts(shortcuts);
|
shortcutManager.setDynamicShortcuts(shortcuts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateShortcuts(Context context) {
|
|
||||||
if (!context.getResources().getBoolean(R.bool.create_most_recent_chat_rooms_shortcuts))
|
|
||||||
return;
|
|
||||||
|
|
||||||
ShortcutManager shortcutManager =
|
|
||||||
(ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE);
|
|
||||||
ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
|
|
||||||
LinphoneShortcutManager manager = new LinphoneShortcutManager(context);
|
|
||||||
|
|
||||||
for (ShortcutInfo shortcutInfo : shortcutManager.getDynamicShortcuts()) {
|
|
||||||
ShortcutInfo shortcut = manager.updateShortcutInfo(shortcutInfo);
|
|
||||||
if (shortcut != null) {
|
|
||||||
shortcuts.add(shortcut);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
shortcutManager.updateShortcuts(shortcuts);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,12 +251,6 @@ public class Compatibility {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateShortcuts(Context context) {
|
|
||||||
if (Version.sdkAboveOrEqual(Version.API25_NOUGAT_71)) {
|
|
||||||
ApiTwentyFivePlus.updateShortcuts(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void enterPipMode(Activity activity) {
|
public static void enterPipMode(Activity activity) {
|
||||||
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
||||||
ApiTwentySixPlus.enterPipMode(activity);
|
ApiTwentySixPlus.enterPipMode(activity);
|
||||||
|
|
|
@ -31,6 +31,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.linphone.LinphoneManager;
|
import org.linphone.LinphoneManager;
|
||||||
import org.linphone.R;
|
import org.linphone.R;
|
||||||
|
import org.linphone.compatibility.Compatibility;
|
||||||
import org.linphone.core.Core;
|
import org.linphone.core.Core;
|
||||||
import org.linphone.core.Friend;
|
import org.linphone.core.Friend;
|
||||||
import org.linphone.core.FriendList;
|
import org.linphone.core.FriendList;
|
||||||
|
@ -253,6 +254,8 @@ class AsyncContactsLoader extends AsyncTask<Void, Void, AsyncContactsLoader.Asyn
|
||||||
ContactsManager.getInstance().getContactsListeners()) {
|
ContactsManager.getInstance().getContactsListeners()) {
|
||||||
listener.onContactsUpdated();
|
listener.onContactsUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Compatibility.createChatShortcuts(mContext);
|
||||||
Log.i("[Contacts Manager] Synchronization finished");
|
Log.i("[Contacts Manager] Synchronization finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -529,6 +529,6 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
||||||
listener.onContactsUpdated();
|
listener.onContactsUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
Compatibility.updateShortcuts(mContext);
|
Compatibility.createChatShortcuts(mContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,8 @@ public class ContactSettingsFragment extends SettingsFragment {
|
||||||
private View mContactView;
|
private View mContactView;
|
||||||
private SwitchSetting mContactPresenceNativeContact,
|
private SwitchSetting mContactPresenceNativeContact,
|
||||||
mFriendListSubscribe,
|
mFriendListSubscribe,
|
||||||
mDisplayDetailContact;
|
mDisplayDetailContact,
|
||||||
|
mCreateShortcuts;
|
||||||
private LinphonePreferences mPrefs;
|
private LinphonePreferences mPrefs;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,15 +56,20 @@ public class ContactSettingsFragment extends SettingsFragment {
|
||||||
|
|
||||||
private void loadSettings() {
|
private void loadSettings() {
|
||||||
mFriendListSubscribe = mContactView.findViewById(R.id.pref_friendlist_subscribe);
|
mFriendListSubscribe = mContactView.findViewById(R.id.pref_friendlist_subscribe);
|
||||||
|
|
||||||
mContactPresenceNativeContact =
|
mContactPresenceNativeContact =
|
||||||
mContactView.findViewById(R.id.pref_contact_presence_native_contact);
|
mContactView.findViewById(R.id.pref_contact_presence_native_contact);
|
||||||
|
|
||||||
mDisplayDetailContact = mContactView.findViewById(R.id.pref_contact_organization);
|
mDisplayDetailContact = mContactView.findViewById(R.id.pref_contact_organization);
|
||||||
|
|
||||||
|
mCreateShortcuts = mContactView.findViewById(R.id.pref_contact_shortcuts);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateValues() {
|
private void updateValues() {
|
||||||
setListeners();
|
setListeners();
|
||||||
|
|
||||||
mFriendListSubscribe.setChecked(mPrefs.isFriendlistsubscriptionEnabled());
|
mFriendListSubscribe.setChecked(mPrefs.isFriendlistsubscriptionEnabled());
|
||||||
|
|
||||||
mContactPresenceNativeContact.setChecked(
|
mContactPresenceNativeContact.setChecked(
|
||||||
mPrefs.isPresenceStorageInNativeAndroidContactEnabled());
|
mPrefs.isPresenceStorageInNativeAndroidContactEnabled());
|
||||||
|
|
||||||
|
@ -72,6 +78,12 @@ public class ContactSettingsFragment extends SettingsFragment {
|
||||||
} else {
|
} else {
|
||||||
mDisplayDetailContact.setVisibility(View.INVISIBLE);
|
mDisplayDetailContact.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getResources().getBoolean(R.bool.create_most_recent_chat_rooms_shortcuts)) {
|
||||||
|
mCreateShortcuts.setChecked(mPrefs.shortcutsCreationEnabled());
|
||||||
|
} else {
|
||||||
|
mCreateShortcuts.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setListeners() {
|
private void setListeners() {
|
||||||
|
@ -99,6 +111,7 @@ public class ContactSettingsFragment extends SettingsFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mDisplayDetailContact.setListener(
|
mDisplayDetailContact.setListener(
|
||||||
new SettingListenerBase() {
|
new SettingListenerBase() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -106,5 +119,13 @@ public class ContactSettingsFragment extends SettingsFragment {
|
||||||
mPrefs.enabledDisplayContactOrganization(newValue);
|
mPrefs.enabledDisplayContactOrganization(newValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mCreateShortcuts.setListener(
|
||||||
|
new SettingListenerBase() {
|
||||||
|
@Override
|
||||||
|
public void onBoolValueChanged(boolean newValue) {
|
||||||
|
mPrefs.enableChatRoomsShortcuts(newValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1172,4 +1172,12 @@ public class LinphonePreferences {
|
||||||
public void setVideoPreviewEnabled(boolean enabled) {
|
public void setVideoPreviewEnabled(boolean enabled) {
|
||||||
getConfig().setBool("app", "video_preview", enabled);
|
getConfig().setBool("app", "video_preview", enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean shortcutsCreationEnabled() {
|
||||||
|
return getConfig().getBool("app", "shortcuts", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableChatRoomsShortcuts(boolean enable) {
|
||||||
|
getConfig().setBool("app", "shortcuts", enable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,12 +29,7 @@ import android.util.ArraySet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.linphone.R;
|
import org.linphone.R;
|
||||||
import org.linphone.chat.ChatActivity;
|
import org.linphone.chat.ChatActivity;
|
||||||
import org.linphone.contacts.ContactsManager;
|
|
||||||
import org.linphone.contacts.LinphoneContact;
|
import org.linphone.contacts.LinphoneContact;
|
||||||
import org.linphone.core.Address;
|
|
||||||
import org.linphone.core.ChatRoom;
|
|
||||||
import org.linphone.core.ChatRoomCapabilities;
|
|
||||||
import org.linphone.core.Factory;
|
|
||||||
import org.linphone.core.tools.Log;
|
import org.linphone.core.tools.Log;
|
||||||
|
|
||||||
@TargetApi(25)
|
@TargetApi(25)
|
||||||
|
@ -48,16 +43,12 @@ public class LinphoneShortcutManager {
|
||||||
mCategories.add(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION);
|
mCategories.add(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShortcutInfo createChatRoomShortcutInfo(ChatRoom room) {
|
public ShortcutInfo createChatRoomShortcutInfo(
|
||||||
Address peerAddress =
|
LinphoneContact contact, String chatRoomAddress) {
|
||||||
room.hasCapability(ChatRoomCapabilities.Basic.toInt())
|
if (contact == null) return null;
|
||||||
? room.getPeerAddress()
|
|
||||||
: room.getParticipants()[0].getAddress();
|
|
||||||
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(peerAddress);
|
|
||||||
String address = peerAddress.asStringUriOnly();
|
|
||||||
|
|
||||||
Bitmap bm = null;
|
Bitmap bm = null;
|
||||||
if (contact != null && contact.getThumbnailUri() != null) {
|
if (contact.getThumbnailUri() != null) {
|
||||||
bm = ImageUtils.getRoundBitmapFromUri(mContext, contact.getThumbnailUri());
|
bm = ImageUtils.getRoundBitmapFromUri(mContext, contact.getThumbnailUri());
|
||||||
}
|
}
|
||||||
Icon icon =
|
Icon icon =
|
||||||
|
@ -65,20 +56,15 @@ public class LinphoneShortcutManager {
|
||||||
? Icon.createWithResource(mContext, R.drawable.avatar)
|
? Icon.createWithResource(mContext, R.drawable.avatar)
|
||||||
: Icon.createWithBitmap(bm);
|
: Icon.createWithBitmap(bm);
|
||||||
|
|
||||||
String name =
|
|
||||||
contact == null
|
|
||||||
? LinphoneUtils.getAddressDisplayName(peerAddress)
|
|
||||||
: contact.getFullName();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||||
intent.setClass(mContext, ChatActivity.class);
|
intent.setClass(mContext, ChatActivity.class);
|
||||||
intent.addFlags(
|
intent.addFlags(
|
||||||
Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||||
intent.putExtra("RemoteSipUri", room.getPeerAddress().asStringUriOnly());
|
intent.putExtra("RemoteSipUri", chatRoomAddress);
|
||||||
|
|
||||||
return new ShortcutInfo.Builder(mContext, address)
|
return new ShortcutInfo.Builder(mContext, chatRoomAddress)
|
||||||
.setShortLabel(name)
|
.setShortLabel(contact.getFullName())
|
||||||
.setIcon(icon)
|
.setIcon(icon)
|
||||||
.setCategories(mCategories)
|
.setCategories(mCategories)
|
||||||
.setIntent(intent)
|
.setIntent(intent)
|
||||||
|
@ -89,38 +75,4 @@ public class LinphoneShortcutManager {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShortcutInfo updateShortcutInfo(ShortcutInfo shortcutInfo) {
|
|
||||||
String address = shortcutInfo.getId();
|
|
||||||
Address peerAddress = Factory.instance().createAddress(address);
|
|
||||||
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(peerAddress);
|
|
||||||
|
|
||||||
if (contact != null) {
|
|
||||||
Bitmap bm = null;
|
|
||||||
if (contact != null && contact.getThumbnailUri() != null) {
|
|
||||||
bm = ImageUtils.getRoundBitmapFromUri(mContext, contact.getThumbnailUri());
|
|
||||||
}
|
|
||||||
Icon icon =
|
|
||||||
bm == null
|
|
||||||
? Icon.createWithResource(mContext, R.drawable.avatar)
|
|
||||||
: Icon.createWithBitmap(bm);
|
|
||||||
|
|
||||||
String name =
|
|
||||||
contact == null
|
|
||||||
? LinphoneUtils.getAddressDisplayName(peerAddress)
|
|
||||||
: contact.getFullName();
|
|
||||||
|
|
||||||
try {
|
|
||||||
return new ShortcutInfo.Builder(mContext, address)
|
|
||||||
.setShortLabel(name)
|
|
||||||
.setIcon(icon)
|
|
||||||
.setCategories(mCategories)
|
|
||||||
.setIntent(shortcutInfo.getIntent())
|
|
||||||
.build();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e("[Shortcuts Manager] ShortcutInfo.Builder exception: " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return shortcutInfo;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,12 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
linphone:title="@string/pref_contact_display_contact_organization_title" />
|
linphone:title="@string/pref_contact_display_contact_organization_title" />
|
||||||
|
|
||||||
|
<org.linphone.settings.widget.SwitchSetting
|
||||||
|
android:id="@+id/pref_contact_shortcuts"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
linphone:title="@string/pref_create_contact_shortcuts" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
|
@ -435,6 +435,7 @@
|
||||||
<string name="pref_contact_sync_subtitle">Inserting information shortcuts from the Linphone contact into native Android contacts</string>
|
<string name="pref_contact_sync_subtitle">Inserting information shortcuts from the Linphone contact into native Android contacts</string>
|
||||||
<string name="pref_contact_title">Contact</string>
|
<string name="pref_contact_title">Contact</string>
|
||||||
<string name="pref_contact_display_contact_organization_title">Display contact organization</string>
|
<string name="pref_contact_display_contact_organization_title">Display contact organization</string>
|
||||||
|
<string name="pref_create_contact_shortcuts">Create shortcuts in launcher</string>
|
||||||
|
|
||||||
<!-- Call settings -->
|
<!-- Call settings -->
|
||||||
<string name="pref_call_title">Call</string>
|
<string name="pref_call_title">Call</string>
|
||||||
|
|
Loading…
Reference in a new issue