sharing text

This commit is contained in:
Daniel Gultsch 2014-03-13 21:37:27 +01:00
parent 507cfba6ad
commit 9c811f8fb2
13 changed files with 251 additions and 67 deletions

5
res/drawable/grey.xml Normal file
View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ffdddddd" />
</shape>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:state_pressed="true"
android:drawable="@drawable/grey" />
</selector>

50
res/layout/share_with.xml Normal file
View File

@ -0,0 +1,50 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/conversations_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Active Conversations"
style="@style/sectionHeader"
android:paddingLeft="8dp"
android:paddingTop="8dp"
android:paddingRight="8dp"/>
<LinearLayout
android:id="@+id/conversations"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:divider="?android:dividerHorizontal"
android:showDividers="middle" >
</LinearLayout>
<TextView
android:id="@+id/contacts_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Contacts"
style="@style/sectionHeader"
android:paddingLeft="8dp"
android:paddingTop="8dp"
android:paddingRight="8dp"/>
<LinearLayout
android:id="@+id/contacts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:divider="?android:dividerHorizontal"
android:showDividers="middle" >
</LinearLayout>
</LinearLayout>
</ScrollView>

View File

@ -25,4 +25,5 @@
<string name="untrusted_cert_hint">The server %s presented you with an unstrusted, possible self signed, certificate.</string> <string name="untrusted_cert_hint">The server %s presented you with an unstrusted, possible self signed, certificate.</string>
<string name="account_info">Server Info</string> <string name="account_info">Server Info</string>
<string name="register_account">Register new account on server</string> <string name="register_account">Register new account on server</string>
<string name="share_with">Share with</string>
</resources> </resources>

View File

@ -398,7 +398,7 @@ public class XmppConnectionService extends Service {
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(LOGTAG,"calling start service. caller was:"+intent.getAction()); //Log.d(LOGTAG,"calling start service. caller was:"+intent.getAction());
ConnectivityManager cm = (ConnectivityManager) getApplicationContext() ConnectivityManager cm = (ConnectivityManager) getApplicationContext()
.getSystemService(Context.CONNECTIVITY_SERVICE); .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
@ -670,7 +670,7 @@ public class XmppConnectionService extends Service {
return packet; return packet;
} }
public void getRoster(Account account, private void getRoster(Account account,
final OnRosterFetchedListener listener) { final OnRosterFetchedListener listener) {
List<Contact> contacts = databaseBackend.getContactsByAccount(account); List<Contact> contacts = databaseBackend.getContactsByAccount(account);
for (int i = 0; i < contacts.size(); ++i) { for (int i = 0; i < contacts.size(); ++i) {
@ -681,6 +681,14 @@ public class XmppConnectionService extends Service {
} }
} }
public List<Contact> getRoster(Account account) {
List<Contact> contacts = databaseBackend.getContactsByAccount(account);
for (int i = 0; i < contacts.size(); ++i) {
contacts.get(i).setAccount(account);
}
return contacts;
}
public void updateRoster(final Account account, public void updateRoster(final Account account,
final OnRosterFetchedListener listener) { final OnRosterFetchedListener listener) {
IqPacket iqPacket = new IqPacket(IqPacket.TYPE_GET); IqPacket iqPacket = new IqPacket(IqPacket.TYPE_GET);

View File

@ -11,7 +11,6 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.FragmentTransaction; import android.app.FragmentTransaction;
@ -42,6 +41,7 @@ public class ConversationActivity extends XmppActivity {
public static final String VIEW_CONVERSATION = "viewConversation"; public static final String VIEW_CONVERSATION = "viewConversation";
public static final String CONVERSATION = "conversationUuid"; public static final String CONVERSATION = "conversationUuid";
public static final String TEXT = "text";
public static final int REQUEST_SEND_MESSAGE = 0x75441; public static final int REQUEST_SEND_MESSAGE = 0x75441;
public static final int REQUEST_DECRYPT_PGP = 0x76783; public static final int REQUEST_DECRYPT_PGP = 0x76783;
@ -437,7 +437,8 @@ public class ConversationActivity extends XmppActivity {
} }
} }
paneShouldBeOpen = false; paneShouldBeOpen = false;
swapConversationFragment(); String text = getIntent().getExtras().getString(TEXT, null);
swapConversationFragment().setText(text);
} }
} else { } else {
if (xmppConnectionService.getAccounts().size() == 0) { if (xmppConnectionService.getAccounts().size() == 0) {

View File

@ -1,6 +1,5 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import java.io.FileNotFoundException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
@ -19,7 +18,6 @@ import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.entities.MucOptions.OnRenameListener; import eu.siacs.conversations.entities.MucOptions.OnRenameListener;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.PhoneHelper;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Fragment; import android.app.Fragment;
@ -30,9 +28,7 @@ import android.content.IntentSender;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.IntentSender.SendIntentException; import android.content.IntentSender.SendIntentException;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -63,6 +59,7 @@ public class ConversationFragment extends Fragment {
protected String queuedPqpMessage = null; protected String queuedPqpMessage = null;
private EditText chatMsg; private EditText chatMsg;
private String pastedText = null;
protected Bitmap selfBitmap; protected Bitmap selfBitmap;
@ -153,6 +150,11 @@ public class ConversationFragment extends Fragment {
final View view = inflater.inflate(R.layout.fragment_conversation, final View view = inflater.inflate(R.layout.fragment_conversation,
container, false); container, false);
chatMsg = (EditText) view.findViewById(R.id.textinput); chatMsg = (EditText) view.findViewById(R.id.textinput);
if (pastedText!=null) {
chatMsg.setText(pastedText);
}
ImageButton sendButton = (ImageButton) view ImageButton sendButton = (ImageButton) view
.findViewById(R.id.textSendButton); .findViewById(R.id.textSendButton);
sendButton.setOnClickListener(this.sendMsgListener); sendButton.setOnClickListener(this.sendMsgListener);
@ -640,4 +642,8 @@ public class ConversationFragment extends Fragment {
} }
} }
public void setText(String text) {
this.pastedText = text;
}
} }

View File

@ -289,6 +289,8 @@ public class ManageAccountActivity extends XmppActivity {
XmppConnection xmpp = selectedAccountForActionMode.getXmppConnection(); XmppConnection xmpp = selectedAccountForActionMode.getXmppConnection();
long connectionAge = (SystemClock.elapsedRealtime() - xmpp.lastConnect) / 60000; long connectionAge = (SystemClock.elapsedRealtime() - xmpp.lastConnect) / 60000;
long sessionAge = (SystemClock.elapsedRealtime() - xmpp.lastSessionStarted) / 60000; long sessionAge = (SystemClock.elapsedRealtime() - xmpp.lastSessionStarted) / 60000;
long connectionAgeHours = connectionAge / 60;
long sessionAgeHours = sessionAge / 60;
View view = (View) getLayoutInflater().inflate(R.layout.server_info, null); View view = (View) getLayoutInflater().inflate(R.layout.server_info, null);
TextView connection = (TextView) view.findViewById(R.id.connection); TextView connection = (TextView) view.findViewById(R.id.connection);
TextView session = (TextView) view.findViewById(R.id.session); TextView session = (TextView) view.findViewById(R.id.session);
@ -299,13 +301,21 @@ public class ManageAccountActivity extends XmppActivity {
TextView roster = (TextView) view.findViewById(R.id.roster); TextView roster = (TextView) view.findViewById(R.id.roster);
pcks_received.setText(""+xmpp.getReceivedStanzas()); pcks_received.setText(""+xmpp.getReceivedStanzas());
pcks_sent.setText(""+xmpp.getSentStanzas()); pcks_sent.setText(""+xmpp.getSentStanzas());
if (connectionAgeHours >= 2) {
connection.setText(connectionAgeHours+" hours");
} else {
connection.setText(connectionAge+" mins"); connection.setText(connectionAge+" mins");
}
if (xmpp.hasFeatureStreamManagment()) { if (xmpp.hasFeatureStreamManagment()) {
if (sessionAgeHours >= 2) {
session.setText(sessionAgeHours+" hours");
} else {
session.setText(sessionAge+" mins"); session.setText(sessionAge+" mins");
}
stream.setText("Yes"); stream.setText("Yes");
} else { } else {
stream.setText("No"); stream.setText("No");
session.setText(connectionAge+" mins"); session.setText(connection.getText());
} }
if (xmpp.hasFeaturesCarbon()) { if (xmpp.hasFeaturesCarbon()) {
carbon.setText("Yes"); carbon.setText("Yes");

View File

@ -64,26 +64,6 @@ public class MucDetailsActivity extends XmppActivity {
membersView = (LinearLayout) findViewById(R.id.muc_members); membersView = (LinearLayout) findViewById(R.id.muc_members);
mMoreDetails = (LinearLayout) findViewById(R.id.muc_more_details); mMoreDetails = (LinearLayout) findViewById(R.id.muc_more_details);
mMoreDetails.setVisibility(View.GONE); mMoreDetails.setVisibility(View.GONE);
/*contactsAdapter = new ArrayAdapter<MucOptions.User>(this,
R.layout.contact, users) {
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
User contact = getItem(position);
if (view == null) {
view = (View) inflater.inflate(R.layout.contact, null);
}
((TextView) view.findViewById(R.id.contact_display_name))
.setText(getItem(position).getName());
TextView role = (TextView) view.findViewById(R.id.contact_jid);
role.setText(getReadableRole(contact.getRole()));
ImageView imageView = (ImageView) view
.findViewById(R.id.contact_photo);
imageView.setImageBitmap(UIHelper.getContactPictureByName(contact.getName(), 90));
return view;
}
};*/
getActionBar().setHomeButtonEnabled(true); getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setDisplayHomeAsUpEnabled(true);

View File

@ -6,7 +6,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Locale;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
@ -14,11 +13,9 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.utils.Validator; import eu.siacs.conversations.utils.Validator;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -230,19 +227,7 @@ public class NewConversationActivity extends XmppActivity {
Conversation conversation = xmppConnectionService Conversation conversation = xmppConnectionService
.findOrCreateConversation(account, contact.getJid(), muc); .findOrCreateConversation(account, contact.getJid(), muc);
switchToConversation(conversation); switchToConversation(conversation,null);
}
public void switchToConversation(Conversation conversation) {
Intent viewConversationIntent = new Intent(this,
ConversationActivity.class);
viewConversationIntent.setAction(Intent.ACTION_VIEW);
viewConversationIntent.putExtra(ConversationActivity.CONVERSATION,
conversation.getUuid());
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
viewConversationIntent.setFlags(viewConversationIntent.getFlags()
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(viewConversationIntent);
} }
@Override @Override
@ -265,12 +250,14 @@ public class NewConversationActivity extends XmppActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Conversation conversation = xmppConnectionService.findOrCreateConversation(accounts.get(which), finalJid, false); Conversation conversation = xmppConnectionService.findOrCreateConversation(accounts.get(which), finalJid, false);
switchToConversation(conversation); switchToConversation(conversation,null);
finish();
} }
}).show(); }).show();
} else { } else {
Conversation conversation = xmppConnectionService.findOrCreateConversation(this.accounts.get(0), jid, false); Conversation conversation = xmppConnectionService.findOrCreateConversation(this.accounts.get(0), jid, false);
switchToConversation(conversation); switchToConversation(conversation,null);
finish();
} }
} }
} }
@ -282,24 +269,10 @@ public class NewConversationActivity extends XmppActivity {
} }
this.rosterContacts.clear(); this.rosterContacts.clear();
for (int i = 0; i < accounts.size(); ++i) { for (int i = 0; i < accounts.size(); ++i) {
xmppConnectionService.getRoster(accounts.get(i), rosterContacts.addAll(xmppConnectionService.getRoster(accounts.get(i)));
new OnRosterFetchedListener() { }
@Override
public void onRosterFetched(List<Contact> roster) {
rosterContacts.addAll(roster);
runOnUiThread(new Runnable() {
@Override
public void run() {
updateAggregatedContacts(); updateAggregatedContacts();
} }
});
}
});
}
}
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {

View File

@ -0,0 +1,128 @@
package eu.siacs.conversations.ui;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.utils.UIHelper;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class ShareWithActivity extends XmppActivity {
private LinearLayout conversations;
private LinearLayout contacts;
private OnClickListener click = new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.share_with);
setTitle("Share with Conversation");
contacts = (LinearLayout) findViewById(R.id.contacts);
conversations = (LinearLayout) findViewById(R.id.conversations);
}
public View createContactView(String name, String msgTxt, Bitmap bm) {
View view = (View) getLayoutInflater().inflate(R.layout.contact, null);
view.setBackgroundResource(R.drawable.greybackground);
TextView contactName =(TextView) view.findViewById(R.id.contact_display_name);
contactName.setText(name);
TextView msg = (TextView) view.findViewById(R.id.contact_jid);
msg.setText(msgTxt);
ImageView imageView = (ImageView) view.findViewById(R.id.contact_photo);
imageView.setImageBitmap(bm);
return view;
}
@Override
void onBackendConnected() {
Set<String> displayedContacts = new HashSet<String>();
conversations.removeAllViews();
List<Conversation> convList = xmppConnectionService.getConversations();
Collections.sort(convList, new Comparator<Conversation>() {
@Override
public int compare(Conversation lhs, Conversation rhs) {
return (int) (rhs.getLatestMessage().getTimeSent() - lhs.getLatestMessage().getTimeSent());
}
});
for(final Conversation conversation : convList) {
View view = createContactView(conversation.getName(), conversation.getLatestMessage().getBody().trim(), UIHelper.getContactPicture(conversation.getContact(),conversation.getName(), 90,this.getApplicationContext()));
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String sharedText = getIntent().getStringExtra(Intent.EXTRA_TEXT);
switchToConversation(conversation, sharedText);
finish();
}
});
conversations.addView(view);
if (conversation.getContact() != null) {
displayedContacts.add(conversation.getContact().getUuid());
}
}
contacts.removeAllViews();
final List<Contact> contactsList = new ArrayList<Contact>();
for(Account account : xmppConnectionService.getAccounts()) {
for(final Contact contact : xmppConnectionService.getRoster(account)) {
if (!displayedContacts.contains(contact.getUuid())) {
contactsList.add(contact);
}
}
}
Collections.sort(contactsList, new Comparator<Contact>() {
@Override
public int compare(Contact lhs, Contact rhs) {
return lhs.getDisplayName().compareToIgnoreCase(rhs.getDisplayName());
}
});
for(int i = 0; i < contactsList.size(); ++i) {
final Contact con = contactsList.get(i);
View view = createContactView(con.getDisplayName(), con.getJid(), UIHelper.getContactPicture(con,null, 90,this.getApplicationContext()));
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String sharedText = getIntent().getStringExtra(Intent.EXTRA_TEXT);
Conversation conversation = xmppConnectionService.findOrCreateConversation(con.getAccount(), con.getJid(), false);
switchToConversation(conversation, sharedText);
finish();
}
});
contacts.addView(view);
}
}
}

View File

@ -1,6 +1,7 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder; import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder;
import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.utils.ExceptionHelper;
@ -103,4 +104,19 @@ public abstract class XmppActivity extends Activity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ExceptionHelper.init(getApplicationContext()); ExceptionHelper.init(getApplicationContext());
} }
public void switchToConversation(Conversation conversation, String text) {
Intent viewConversationIntent = new Intent(this,
ConversationActivity.class);
viewConversationIntent.setAction(Intent.ACTION_VIEW);
viewConversationIntent.putExtra(ConversationActivity.CONVERSATION,
conversation.getUuid());
if (text!=null) {
viewConversationIntent.putExtra(ConversationActivity.TEXT, text);
}
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
viewConversationIntent.setFlags(viewConversationIntent.getFlags()
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(viewConversationIntent);
}
} }

View File

@ -720,7 +720,7 @@ public class XmppConnection implements Runnable {
if (this.streamFeatures==null) { if (this.streamFeatures==null) {
return false; return false;
} else { } else {
return this.streamFeatures.hasChild("has"); return this.streamFeatures.hasChild("sm");
} }
} }