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.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.DEFAULT"/>
</intent-filter> </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>
<activity <activity
android:name=".LinphoneActivity" android:name=".LinphoneActivity"

View file

@ -198,6 +198,9 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
message = (EditText) view.findViewById(R.id.message); 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); sendImage = (ImageView) view.findViewById(R.id.send_picture);
if (!getResources().getBoolean(R.bool.disable_chat_send_file)) { if (!getResources().getBoolean(R.bool.disable_chat_send_file)) {
sendImage.setOnClickListener(new View.OnClickListener() { 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.sipUri = newSipUri;
this.message.setText(message);
initChatRoom(sipUri); initChatRoom(sipUri);
} }

View file

@ -185,7 +185,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
public void displayFirstChat(){ public void displayFirstChat(){
if (mConversations != null && mConversations.size() > 0) { if (mConversations != null && mConversations.size() > 0) {
LinphoneActivity.instance().displayChat(mConversations.get(0)); LinphoneActivity.instance().displayChat(mConversations.get(0), null);
} else { } else {
LinphoneActivity.instance().displayEmptyFragment(); LinphoneActivity.instance().displayEmptyFragment();
} }
@ -314,7 +314,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
enabledDeleteButton(false); enabledDeleteButton(false);
} }
else if (id == R.id.new_discussion) { else if (id == R.id.new_discussion) {
LinphoneActivity.instance().displayChat(null); LinphoneActivity.instance().displayChat(null, null);
/*String sipUri = fastNewChat.getText().toString(); /*String sipUri = fastNewChat.getText().toString();
if (sipUri.equals("")) { if (sipUri.equals("")) {
LinphoneActivity.instance().displayContacts(true); LinphoneActivity.instance().displayContacts(true);
@ -338,7 +338,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
String sipUri = chatList.getAdapter().getItem(position).toString(); String sipUri = chatList.getAdapter().getItem(position).toString();
if (LinphoneActivity.isInstanciated() && !isEditMode) { if (LinphoneActivity.isInstanciated() && !isEditMode) {
LinphoneActivity.instance().displayChat(sipUri); LinphoneActivity.instance().displayChat(sipUri, null);
} }
} }

View file

@ -56,7 +56,7 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (LinphoneActivity.isInstanciated()) { if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().displayChat(v.getTag().toString()); LinphoneActivity.instance().displayChat(v.getTag().toString(), null);
} }
} }
}; };

View file

@ -161,7 +161,7 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
} if (id == R.id.call) { } if (id == R.id.call) {
LinphoneActivity.instance().setAddresGoToDialerAndCall(sipUri, displayName, pictureUri == null ? null : Uri.parse(pictureUri)); LinphoneActivity.instance().setAddresGoToDialerAndCall(sipUri, displayName, pictureUri == null ? null : Uri.parse(pictureUri));
} else if (id == R.id.chat) { } else if (id == R.id.chat) {
LinphoneActivity.instance().displayChat(sipUri); LinphoneActivity.instance().displayChat(sipUri, null);
} else if (id == R.id.add_contact) { } else if (id == R.id.add_contact) {
String uri = sipUri; String uri = sipUri;
try { try {

View file

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

View file

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