Skip to content

Commit

Permalink
Send location message without text (#51)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Cappelli <[email protected]>
  • Loading branch information
sw1ftc0d3r committed Mar 23, 2014
1 parent a57cce6 commit 794172f
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 10 deletions.
Binary file added res/drawable-hdpi/ic_send_holo_location.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 19 additions & 10 deletions src/org/kontalk/ui/ComposeMessageFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,25 @@
import java.io.IOException;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.regex.Pattern;

import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smackx.ChatState;
import org.kontalk.Kontalk;
import org.kontalk.R;
import org.kontalk.authenticator.Authenticator;
import org.kontalk.client.EndpointServer;
import org.kontalk.crypto.Coder;
import org.kontalk.crypto.DecryptException;
import org.kontalk.crypto.PGP;
import org.kontalk.crypto.PersonalKey;
import org.kontalk.data.Contact;
import org.kontalk.data.Conversation;
import org.kontalk.message.AttachmentComponent;
import org.kontalk.message.CompositeMessage;
import org.kontalk.message.ImageComponent;
import org.kontalk.message.LocationComponent;
import org.kontalk.message.MessageComponent;
import org.kontalk.message.RawComponent;
import org.kontalk.message.TextComponent;
import org.kontalk.message.VCardComponent;
import org.kontalk.provider.MessagesProvider;
Expand All @@ -63,7 +58,6 @@
import org.kontalk.ui.IconContextMenu.IconContextMenuOnClickListener;
import org.kontalk.util.MediaStorage;
import org.kontalk.util.MessageUtils;
import org.kontalk.util.XMPPUtils;
import org.kontalk.util.MessageUtils.SmileyImageSpan;
import org.spongycastle.openpgp.PGPPublicKey;
import org.spongycastle.openpgp.PGPPublicKeyRing;
Expand Down Expand Up @@ -526,7 +520,7 @@ public void run() {
v.bind(getActivity(), msg, contact, null);
getListView().addFooterView(v);
*/
byte[] bytes = mText.getBytes();
byte[] bytes = mText != null ? mText.getBytes() : null;

// save to local storage
ContentValues values = new ContentValues();
Expand All @@ -535,7 +529,7 @@ public void run() {
values.put(Messages.PEER, userId);
values.put(Messages.BODY_MIME, TextComponent.MIME_TYPE);
values.put(Messages.BODY_CONTENT, bytes);
values.put(Messages.BODY_LENGTH, bytes.length);
values.put(Messages.BODY_LENGTH, bytes != null ? bytes.length : 0);
values.put(Messages.UNREAD, false);
values.put(Messages.DIRECTION, Messages.DIRECTION_OUT);
values.put(Messages.TIMESTAMP, System.currentTimeMillis());
Expand Down Expand Up @@ -605,7 +599,9 @@ public void sendTextMessage(String text, boolean fromTextEntry) {
if (fromTextEntry)
text = mTextEntry.getText().toString();

if (!TextUtils.isEmpty(text)) {
boolean empty = TextUtils.isEmpty(text);

if (!empty || mLocationFragment != null) {
/*
* TODO show an animation to warn the user that the message
* is being sent (actually stored).
Expand All @@ -615,7 +611,15 @@ public void sendTextMessage(String text, boolean fromTextEntry) {

if (mLocationFragment != null) {
Location l = mLocationFragment.getMap().getMyLocation();
new TextMessageThread(text, l.getLatitude(), l.getLongitude()).start();
// location not available yet
if (l == null) {
// TODO i18n
Toast.makeText(getActivity(), "Location not available. Please try later.", Toast.LENGTH_SHORT)
.show();
return;
}

new TextMessageThread(empty ? null : text, l.getLatitude(), l.getLongitude()).start();
}

else {
Expand Down Expand Up @@ -870,6 +874,11 @@ private void selectLocationAttachment() {
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.addToBackStack(null);
ft.commit();

if (mSendButton instanceof ImageButton) {
((ImageButton) mSendButton).setImageResource(R.drawable.ic_send_holo_location);
}

mSendButton.setEnabled(true);

/*final LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
Expand Down
18 changes: 18 additions & 0 deletions src/org/kontalk/ui/FragmentParent.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Kontalk Android client
* Copyright (C) 2014 Kontalk Devteam <[email protected]>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.kontalk.ui;

import android.support.v4.app.Fragment;
Expand Down
18 changes: 18 additions & 0 deletions src/org/kontalk/ui/MyMapFragment.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Kontalk Android client
* Copyright (C) 2014 Kontalk Devteam <[email protected]>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.kontalk.ui;

import com.google.android.gms.maps.GoogleMap;
Expand Down
23 changes: 23 additions & 0 deletions src/org/kontalk/util/GMStaticMap.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Kontalk Android client
* Copyright (C) 2014 Kontalk Devteam <[email protected]>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.kontalk.util;

import java.io.File;
Expand All @@ -11,6 +29,11 @@

import android.content.Context;

/**
* Download Google Static Map
* @author Daniele Ricci
* @author Andrea Cappelli
*/

public class GMStaticMap {

Expand Down
24 changes: 24 additions & 0 deletions src/org/kontalk/util/GMStaticUrlBuilder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
/*
* Kontalk Android client
* Copyright (C) 2014 Kontalk Devteam <[email protected]>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.kontalk.util;

/**
* Download Google Static Map
* @author Daniele Ricci
* @author Andrea Cappelli
*/

public class GMStaticUrlBuilder {
private static final String URL="http://maps.googleapis.com/maps/api/staticmap";

Expand Down

0 comments on commit 794172f

Please sign in to comment.