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);
}

View file

@ -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();
}
@ -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);
}
}

View file

@ -56,7 +56,7 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
@Override
public void onClick(View v) {
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) {
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;