Add Linphone for text sharing from other application

This commit is contained in:
Erwan Croze 2017-04-10 17:01:00 +02:00
parent e9e349e76e
commit 9d92ef6b0b
7 changed files with 97 additions and 68 deletions

View file

@ -104,6 +104,11 @@
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity
android:name=".LinphoneActivity"

View file

@ -198,6 +198,9 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
message = (EditText) view.findViewById(R.id.message);
if (getArguments().getString("messageDraft") != null)
message.setText(getArguments().getString("messageDraft"));
sendImage = (ImageView) view.findViewById(R.id.send_picture);
if (!getResources().getBoolean(R.bool.disable_chat_send_file)) {
sendImage.setOnClickListener(new View.OnClickListener() {
@ -404,8 +407,9 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
}
}
public void changeDisplayedChat(String newSipUri, String displayName, String pictureUri) {
public void changeDisplayedChat(String newSipUri, String displayName, String pictureUri, String message) {
this.sipUri = newSipUri;
this.message.setText(message);
initChatRoom(sipUri);
}
@ -1296,7 +1300,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
}
});
chatRoom.markAsRead();
} else {
holder.imdmLayout.setVisibility(View.INVISIBLE);
holder.fileTransferAction.setText(getString(R.string.accept));

View file

@ -64,7 +64,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
private LinearLayout editList, topbar;
private boolean isEditMode = false;
private LinphoneCoreListenerBase mListener;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -74,7 +74,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
chatList = (ListView) view.findViewById(R.id.chatList);
chatList.setOnItemClickListener(this);
registerForContextMenu(chatList);
noChatHistory = (TextView) view.findViewById(R.id.noChatHistory);
editList = (LinearLayout) view.findViewById(R.id.edit_list);
@ -85,10 +85,10 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
edit = (ImageView) view.findViewById(R.id.edit);
edit.setOnClickListener(this);
newDiscussion = (ImageView) view.findViewById(R.id.new_discussion);
newDiscussion.setOnClickListener(this);
selectAll = (ImageView) view.findViewById(R.id.select_all);
selectAll.setOnClickListener(this);
@ -100,7 +100,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
delete = (ImageView) view.findViewById(R.id.delete);
delete.setOnClickListener(this);
mListener = new LinphoneCoreListenerBase() {
@Override
public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
@ -163,7 +163,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
}
}
}
private void hideAndDisplayMessageIfNoChat() {
if (mConversations.size() == 0) {
noChatHistory.setVisibility(View.VISIBLE);
@ -177,7 +177,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
edit.setEnabled(true);
}
}
public void refresh() {
mConversations = LinphoneActivity.instance().getChatList();
hideAndDisplayMessageIfNoChat();
@ -185,7 +185,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
public void displayFirstChat(){
if (mConversations != null && mConversations.size() > 0) {
LinphoneActivity.instance().displayChat(mConversations.get(0));
LinphoneActivity.instance().displayChat(mConversations.get(0), null);
} else {
LinphoneActivity.instance().displayEmptyFragment();
}
@ -201,20 +201,20 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
} else {
backInCall.setVisibility(View.INVISIBLE);
}
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().selectMenu(FragmentsAvailable.CHAT_LIST);
LinphoneActivity.instance().hideTabBar(false);
}
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc != null) {
lc.addListener(mListener);
}
refresh();
}
@Override
public void onPause() {
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
@ -238,7 +238,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, v.getId(), 0, getString(R.string.delete));
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
@ -246,13 +246,13 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
return false;
}
String sipUri = chatList.getAdapter().getItem(info.position).toString();
LinphoneActivity.instance().removeFromChatList(sipUri);
mConversations = LinphoneActivity.instance().getChatList();
hideAndDisplayMessageIfNoChat();
return true;
}
@Override
public void onClick(View v) {
int id = v.getId();
@ -314,7 +314,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
enabledDeleteButton(false);
}
else if (id == R.id.new_discussion) {
LinphoneActivity.instance().displayChat(null);
LinphoneActivity.instance().displayChat(null, null);
/*String sipUri = fastNewChat.getText().toString();
if (sipUri.equals("")) {
LinphoneActivity.instance().displayContacts(true);
@ -338,7 +338,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
String sipUri = chatList.getAdapter().getItem(position).toString();
if (LinphoneActivity.isInstanciated() && !isEditMode) {
LinphoneActivity.instance().displayChat(sipUri);
LinphoneActivity.instance().displayChat(sipUri, null);
}
}
@ -350,7 +350,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
public TextView unreadMessages;
public CheckBox select;
public ImageView contactPicture;
public ViewHolder(View view) {
lastMessageView = (TextView) view.findViewById(R.id.lastMessage);
date = (TextView) view.findViewById(R.id.date);
@ -360,9 +360,9 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
contactPicture = (ImageView) view.findViewById(R.id.contact_picture);
}
}
ChatListAdapter() {}
public int getCount() {
return mConversations.size();
}
@ -379,7 +379,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
View view = null;
ViewHolder holder = null;
String sipUri = mConversations.get(position);
if (convertView != null) {
view = convertView;
holder = (ViewHolder) view.getTag();
@ -388,7 +388,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
holder = new ViewHolder(view);
view.setTag(holder);
}
LinphoneAddress address;
try {
address = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri);

View file

@ -51,32 +51,32 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
}
}
};
private OnClickListener chatListener = new OnClickListener() {
@Override
public void onClick(View v) {
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().displayChat(v.getTag().toString());
LinphoneActivity.instance().displayChat(v.getTag().toString(), null);
}
}
};
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
contact = (LinphoneContact) getArguments().getSerializable("Contact");
this.inflater = inflater;
view = inflater.inflate(R.layout.contact, container, false);
if (getArguments() != null) {
displayChatAddressOnly = getArguments().getBoolean("ChatAddressOnly");
}
editContact = (ImageView) view.findViewById(R.id.editContact);
editContact.setOnClickListener(this);
deleteContact = (ImageView) view.findViewById(R.id.deleteContact);
deleteContact.setOnClickListener(this);
organization = (TextView) view.findViewById(R.id.contactOrganization);
boolean isOrgVisible = getResources().getBoolean(R.bool.display_contact_organization);
String org = contact.getOrganization();
@ -95,12 +95,12 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
return view;
}
public void changeDisplayedContact(LinphoneContact newContact) {
contact = newContact;
displayContact(inflater, view);
}
@SuppressLint("InflateParams")
private void displayContact(LayoutInflater inflater, View view) {
ImageView contactPicture = (ImageView) view.findViewById(R.id.contact_picture);
@ -109,10 +109,10 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
} else {
contactPicture.setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
}
TextView contactName = (TextView) view.findViewById(R.id.contact_name);
contactName.setText(contact.getFullName());
TableLayout controls = (TableLayout) view.findViewById(R.id.controls);
controls.removeAllViews();
for (LinphoneNumberOrAddress noa : contact.getNumbersOrAddresses()) {
@ -130,11 +130,11 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
label.setText(R.string.phone_number);
skip |= getResources().getBoolean(R.bool.hide_contact_phone_numbers);
}
TextView tv = (TextView) v.findViewById(R.id.numeroOrAddress);
tv.setText(displayednumberOrAddress);
tv.setSelected(true);
LinphoneProxyConfig lpc = LinphoneManager.getLc().getDefaultProxyConfig();
if (lpc != null) {
@ -146,7 +146,7 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
if (contactAddress != null) {
v.findViewById(R.id.friendLinphone).setVisibility(View.VISIBLE);
}
if (!displayChatAddressOnly) {
v.findViewById(R.id.contact_call).setOnClickListener(dialListener);
if (contactAddress != null) {
@ -164,17 +164,17 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
} else {
v.findViewById(R.id.contact_chat).setTag(value);
}
if (getResources().getBoolean(R.bool.disable_chat)) {
v.findViewById(R.id.contact_chat).setVisibility(View.GONE);
}
if (!skip) {
controls.addView(v);
}
}
}
@Override
public void onResume() {
super.onResume();
@ -190,7 +190,7 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
@Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.editContact) {
LinphoneActivity.instance().editContact(contact);
}

View file

@ -42,7 +42,7 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
private TextView contactName, contactAddress, time, date;
private String sipUri, displayName, pictureUri;
private LinphoneContact contact;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -54,7 +54,7 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
String callDate = getArguments().getString("CallDate");
view = inflater.inflate(R.layout.history_detail, container, false);
dialBack = (ImageView) view.findViewById(R.id.call);
dialBack.setOnClickListener(this);
@ -64,33 +64,33 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
} else {
back.setOnClickListener(this);
}
chat = (ImageView) view.findViewById(R.id.chat);
chat.setOnClickListener(this);
if (getResources().getBoolean(R.bool.disable_chat))
view.findViewById(R.id.chat).setVisibility(View.GONE);
addToContacts = (ImageView) view.findViewById(R.id.add_contact);
addToContacts.setOnClickListener(this);
goToContact = (ImageView) view.findViewById(R.id.goto_contact);
goToContact.setOnClickListener(this);
contactPicture = (ImageView) view.findViewById(R.id.contact_picture);
contactName = (TextView) view.findViewById(R.id.contact_name);
contactAddress = (TextView) view.findViewById(R.id.contact_address);
callDirection = (ImageView) view.findViewById(R.id.direction);
time = (TextView) view.findViewById(R.id.time);
date = (TextView) view.findViewById(R.id.date);
displayHistory(status, callTime, callDate);
return view;
}
private void displayHistory(String status, String callTime, String callDate) {
if (status.equals(getResources().getString(R.string.missed))) {
callDirection.setImageResource(R.drawable.call_missed);
@ -99,7 +99,7 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
} else if (status.equals(getResources().getString(R.string.outgoing))) {
callDirection.setImageResource(R.drawable.call_outgoing);
}
time.setText(callTime == null ? "" : callTime);
Long longDate = Long.parseLong(callDate);
date.setText(LinphoneUtils.timestampToHumanDate(getActivity(),longDate,getString(R.string.history_detail_date_format)));
@ -130,8 +130,8 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
contactName.setText(displayName == null ? LinphoneUtils.getAddressDisplayName(sipUri) : displayName);
}
}
public void changeDisplayedHistory(String sipUri, String displayName, String pictureUri, String status, String callTime, String callDate) {
public void changeDisplayedHistory(String sipUri, String displayName, String pictureUri, String status, String callTime, String callDate) {
if (displayName == null ) {
displayName = LinphoneUtils.getUsernameFromAddress(sipUri);
}
@ -141,11 +141,11 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
this.pictureUri = pictureUri;
displayHistory(status, callTime, callDate);
}
@Override
public void onResume() {
super.onResume();
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().selectMenu(FragmentsAvailable.HISTORY_DETAIL);
LinphoneActivity.instance().hideTabBar(false);
@ -161,7 +161,7 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
} if (id == R.id.call) {
LinphoneActivity.instance().setAddresGoToDialerAndCall(sipUri, displayName, pictureUri == null ? null : Uri.parse(pictureUri));
} else if (id == R.id.chat) {
LinphoneActivity.instance().displayChat(sipUri);
LinphoneActivity.instance().displayChat(sipUri, null);
} else if (id == R.id.add_contact) {
String uri = sipUri;
try {

View file

@ -639,7 +639,7 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
return count;
}
public void displayChat(String sipUri) {
public void displayChat(String sipUri, String message) {
if (getResources().getBoolean(R.bool.disable_chat)) {
return;
}
@ -670,10 +670,11 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
Fragment fragment2 = getFragmentManager().findFragmentById(R.id.fragmentContainer2);
if (fragment2 != null && fragment2.isVisible() && currentFragment == FragmentsAvailable.CHAT && !emptyFragment) {
ChatFragment chatFragment = (ChatFragment) fragment2;
chatFragment.changeDisplayedChat(sipUri, displayName, pictureUri);
chatFragment.changeDisplayedChat(sipUri, displayName, pictureUri, message);
} else {
Bundle extras = new Bundle();
extras.putString("SipUri", sipUri);
extras.putString("messageDraft", message);
if (sipUri != null && lAddress.getDisplayName() != null) {
extras.putString("DisplayName", displayName);
extras.putString("PictureUri", pictureUri);
@ -684,10 +685,11 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
} else {
if(isTablet()){
changeCurrentFragment(FragmentsAvailable.CHAT_LIST, null);
displayChat(sipUri);
displayChat(sipUri, message);
} else {
Bundle extras = new Bundle();
extras.putString("SipUri", sipUri);
extras.putString("messageDraft", message);
if (sipUri != null && lAddress.getDisplayName() != null) {
extras.putString("DisplayName", displayName);
extras.putString("PictureUri", pictureUri);
@ -1419,7 +1421,7 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
LinphoneService.instance().removeMessageNotification();
String sipUri = extras.getString("ChatContactSipUri");
doNotGoToCallActivity = true;
displayChat(sipUri);
displayChat(sipUri, null);
} else if (extras != null && extras.getBoolean("GoToHistory", false)) {
doNotGoToCallActivity = true;
changeCurrentFragment(FragmentsAvailable.HISTORY_LIST, null);

View file

@ -54,8 +54,10 @@ public class LinphoneLauncherActivity extends Activity {
mHandler = new Handler();
Intent intent = getIntent();
if (LinphoneService.isReady()) {
onServiceReady();
onServiceReady(intent);
} else {
// start linphone as background
startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class));
@ -64,7 +66,7 @@ public class LinphoneLauncherActivity extends Activity {
}
}
protected void onServiceReady() {
protected void onServiceReady(Intent intent) {
final Class<? extends Activity> classToStart;
if (getResources().getBoolean(R.bool.show_tutorials_instead_of_app)) {
classToStart = TutorialLauncherActivity.class;
@ -74,15 +76,31 @@ public class LinphoneLauncherActivity extends Activity {
classToStart = LinphoneActivity.class;
}
String sharedText = null;
if (intent != null) {
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
}
}
}
// We need LinphoneService to start bluetoothManager
if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) {
BluetoothManager.getInstance().initBluetooth();
}
final String finalSharedText = sharedText;
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent().setClass(LinphoneLauncherActivity.this, classToStart).setData(getIntent().getData()));
if (finalSharedText != null) {
LinphoneActivity.instance().displayChat(null, finalSharedText);
}
finish();
}
}, 1000);
@ -100,7 +118,7 @@ public class LinphoneLauncherActivity extends Activity {
mHandler.post(new Runnable() {
@Override
public void run() {
onServiceReady();
onServiceReady(null);
}
});
mThread = null;