Skip to content

Commit

Permalink
Added static map in notification, balloon, send location by google maps
Browse files Browse the repository at this point in the history
fragment. (#51)

Signed-off-by: Andrea Cappelli <[email protected]>
  • Loading branch information
sw1ftc0d3r committed Mar 19, 2014
1 parent 83bede3 commit 771122a
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 16 deletions.
6 changes: 6 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
Expand All @@ -47,8 +48,10 @@

<!-- internal permissions -->
<permission android:name="org.kontalk.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<permission android:name="org.kontalk.xmpp.maps.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>

<uses-permission android:name="org.kontalk.permission.C2D_MESSAGE" />
<uses-permission android:name="org.kontalk.xmpp.maps.permission.MAPS_RECEIVE"/>

<!-- do not make telephony and touchscreen mandatory -->
<uses-feature android:name="android.hardware.telephony" android:required="false"/>
Expand All @@ -60,6 +63,9 @@
android:theme="@style/Theme.Light"
android:allowBackup="true">

<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="TE_LO_STO_PE_DI" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

<!-- Services -->
<service android:name=".service.MessageCenterService"
android:label="@string/service_name"/>
Expand Down
3 changes: 2 additions & 1 deletion project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
# project structure.

# Project target.
target=android-19
target=Google Inc.:Google APIs:19
android.library.reference.1=../android-support-v7-appcompat
android.library.reference.2=../../../android-sdk-macosx/extras/google/google_play_services/libproject/google-play-services_lib
4 changes: 4 additions & 0 deletions res/layout/compose_message.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@

<include layout="@layout/composer_bar"/>

<FrameLayout android:id="@+id/drawer"
android:layout_width="fill_parent"
android:layout_height="0dp"/>

</LinearLayout>
4 changes: 3 additions & 1 deletion src/org/kontalk/message/CompositeMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ else if (VCardComponent.supportsMimeType(attMime)) {
if (!c.isNull(COLUMN_GEO_LATITUDE)) {
double lat = c.getDouble(COLUMN_GEO_LATITUDE);
double lon = c.getDouble(COLUMN_GEO_LONGITUDE);
LocationComponent location = new LocationComponent(lat, lon);
String attPreview = c.getString(COLUMN_ATTACHMENT_PREVIEW_PATH);
File previewFile = (attPreview != null) ? new File(attPreview) : null;
LocationComponent location = new LocationComponent(lat, lon, previewFile);
addComponent(location);
}

Expand Down
14 changes: 12 additions & 2 deletions src/org/kontalk/message/LocationComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@

package org.kontalk.message;

import java.io.File;

import org.kontalk.crypto.Coder;

import android.util.Log;



/**
Expand All @@ -28,9 +32,10 @@
* @author Andrea Cappelli
*/
public class LocationComponent extends MessageComponent <Location> {

public LocationComponent(double lat, double lon) {
private File mCachedMap;
public LocationComponent(double lat, double lon, File cachedMap) {
super(new Location(lat,lon), 0, false, Coder.SECURITY_CLEARTEXT);
mCachedMap = cachedMap;
}

public double getLatitude() {
Expand All @@ -40,4 +45,9 @@ public double getLatitude() {
public double getLongitude() {
return mContent.getLongitude();
}

public File getCachedMap () {
Log.w ("PATH",""+mCachedMap.getAbsolutePath());
return mCachedMap;
}
}
13 changes: 12 additions & 1 deletion src/org/kontalk/service/MessageCenterService.java
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,8 @@ private void resendPendingMessages(boolean retrying) {
Messages.ATTACHMENT_PREVIEW_PATH,
Messages.ATTACHMENT_LENGTH,
// TODO Messages.ATTACHMENT_SECURITY_FLAGS,
Messages.GEO_LATITUDE,
Messages.GEO_LONGITUDE,
},
filter.toString(),
null, Messages._ID);
Expand Down Expand Up @@ -985,6 +987,13 @@ else if (attFileUri != null) {
b.putLong("org.kontalk.message.length", attLength);
}

if (!c.isNull(9)){
double lat = c.getDouble(9);
double lon = c.getDouble(10);
b.putDouble("org.kontalk.message.geo_lat", lat);
b.putDouble("org.kontalk.message.geo_lon", lon);
}

Log.v(TAG, "resending pending message " + id);
sendMessage(b);
}
Expand Down Expand Up @@ -1399,6 +1408,8 @@ public void run() {
v.put(Messages.ATTACHMENT_PREVIEW_PATH, dest.toString());
Log.w ("Percorso: ",""+v.get(Messages.ATTACHMENT_PREVIEW_PATH));
getContentResolver().update(_uri, v, null, null);

MessagingNotification.delayedUpdateMessagesNotification(getApplicationContext(), false);
}
},

Expand Down Expand Up @@ -2601,7 +2612,7 @@ else if (VCardComponent.supportsMimeType(mime)) {
UserLocation location = (UserLocation) _location;
msg.addComponent(new LocationComponent
(location.getLatitude(),
location.getLongitude()));
location.getLongitude(), null));
}

if (msg != null) {
Expand Down
12 changes: 11 additions & 1 deletion src/org/kontalk/ui/ComposeMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.ImageView;
Expand All @@ -58,7 +60,7 @@
* @author Daniele Ricci
* @version 1.0
*/
public class ComposeMessage extends ActionBarActivity {
public class ComposeMessage extends ActionBarActivity implements FragmentParent {
private static final String TAG = ComposeMessage.class.getSimpleName();

private static final int REQUEST_CONTACT_PICKER = 9721;
Expand Down Expand Up @@ -101,6 +103,14 @@ protected void onCreate(Bundle savedInstanceState) {
processIntent(savedInstanceState);
}

@Override
public void onChildClose(Fragment fragment) {
View v = mFragment.getView().findViewById(R.id.drawer);
LayoutParams p=v.getLayoutParams();
p.height=0;
v.setLayoutParams(p);
}

@TargetApi(android.os.Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
ActionBar bar = getSupportActionBar();
Expand Down
59 changes: 51 additions & 8 deletions src/org/kontalk/ui/ComposeMessageFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.spongycastle.openpgp.PGPPublicKey;
import org.spongycastle.openpgp.PGPPublicKeyRing;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.AsyncQueryHandler;
Expand All @@ -81,14 +82,13 @@
import android.database.sqlite.SQLiteException;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.location.Criteria;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.ContactsContract.Contacts;
import android.provider.MediaStore;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.ListFragment;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.MenuItemCompat;
Expand All @@ -106,6 +106,8 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
Expand Down Expand Up @@ -183,6 +185,9 @@ public class ComposeMessageFragment extends ListFragment implements
private TextWatcher mChatStateListener;
private AdapterView.OnItemClickListener mSmileySelectListener;

private MyMapFragment mLocationFragment;


private static final class PresenceData {
public String status;
public int priority;
Expand Down Expand Up @@ -330,6 +335,20 @@ public void onClick(View v) {
}
});

final View root=getActivity().getWindow().getDecorView().findViewById(android.R.id.content);
root.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(){
public void onGlobalLayout(){
int heightDiff = root.getRootView().getHeight()-
(root.getHeight()+getActivity().getWindow().getDecorView().findViewById(android.R.id.content).getTop());
Log.d(TAG,root.getRootView().getHeight()+" - "
+(root.getHeight()+getActivity().getWindow().getDecorView().findViewById(android.R.id.content).getTop())
+" = "+heightDiff);

if (heightDiff > 0)
MessagingPreferences.setDrawerHeight(getActivity(), heightDiff);
}
});

Configuration config = getResources().getConfiguration();
onKeyboardStateChanged(config.keyboardHidden == KEYBOARDHIDDEN_NO);

Expand Down Expand Up @@ -552,7 +571,7 @@ public void run() {
}
else {
MessageCenterService.sendLocationMessage(getActivity(),
userId, "Location", mLatitude, mLongitude, MessagingPreferences
userId, mText, mLatitude, mLongitude, MessagingPreferences
.getEncryptionEnabled(getActivity()),
ContentUris.parseId(newMsg));
}
Expand Down Expand Up @@ -588,8 +607,15 @@ public void sendTextMessage(String text, boolean fromTextEntry) {

offlineModeWarning();

// start thread
new TextMessageThread(text).start();
if (mLocationFragment != null) {
Location l = mLocationFragment.getMap().getMyLocation();
new TextMessageThread(text, l.getLatitude(), l.getLongitude()).start();
}

else {
// start thread
new TextMessageThread(text).start();
}

if (fromTextEntry) {
// empty text
Expand Down Expand Up @@ -822,8 +848,25 @@ private void selectContactAttachment() {
startActivityForResult(i, SELECT_ATTACHMENT_CONTACT);
}

@SuppressLint("NewApi")
private void selectLocationAttachment() {
final LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
/*InputMethodManager input = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
input.hideSoftInputFromWindow(getView().getWindowToken(), 0);*/

View v=getActivity().findViewById(R.id.drawer);
LayoutParams p=v.getLayoutParams();
p.height=MessagingPreferences.getDrawerHeight(getActivity());
v.setLayoutParams(p);

mLocationFragment= new MyMapFragment();
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.replace(R.id.drawer, mLocationFragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.addToBackStack(null);
ft.commit();
mSendButton.setEnabled(true);

/*final LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
// TODO i18n
Expand Down Expand Up @@ -868,7 +911,7 @@ public void onLocationChanged(android.location.Location location) {
};
locationManager.requestLocationUpdates(provider, 0, 0, l);
}
}*/
}

private void showSmileysPopup(View anchor) {
Expand Down
7 changes: 7 additions & 0 deletions src/org/kontalk/ui/FragmentParent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.kontalk.ui;

import android.support.v4.app.Fragment;

public interface FragmentParent {
public void onChildClose (Fragment fragment);
}
20 changes: 20 additions & 0 deletions src/org/kontalk/ui/MessageListItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.kontalk.ui;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -27,13 +28,15 @@
import org.kontalk.message.AttachmentComponent;
import org.kontalk.message.CompositeMessage;
import org.kontalk.message.ImageComponent;
import org.kontalk.message.LocationComponent;
import org.kontalk.message.TextComponent;
import org.kontalk.provider.MyMessages.Messages;
import org.kontalk.util.MessageUtils;
import org.kontalk.util.MessageUtils.SmileyImageSpan;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
Expand Down Expand Up @@ -363,6 +366,23 @@ private SpannableStringBuilder formatMessage(final Contact contact, final Patter
}

}
else {
LocationComponent loc = (LocationComponent) mMessage.getComponent(LocationComponent.class);
if (loc != null) {
String placeholder = "Map";
buf.insert(0, placeholder);
try {
File preview = loc.getCachedMap();
Bitmap bitmap = BitmapFactory.decodeFile(preview.getAbsolutePath() /*"/data/data/org.kontalk/cache/41.771848_12.303395.png"*/);
if (bitmap != null) {
ImageSpan imgSpan = new MaxSizeImageSpan(getContext(), bitmap);
buf.setSpan(imgSpan, 0, placeholder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
} catch (Exception e) {

}
}
}

}

Expand Down
1 change: 0 additions & 1 deletion src/org/kontalk/ui/MessagingNotification.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ else if (content == null && attMime != null) {
CharSequence last = convs.get(peer)[1];

if (unread == 1 && previewPath != null) {
Log.d ("PATH",previewPath);
Bitmap b=BitmapFactory.decodeFile(previewPath);
style = new BigPictureStyle();
((BigPictureStyle) style).bigPicture(b);
Expand Down
13 changes: 13 additions & 0 deletions src/org/kontalk/ui/MessagingPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
public final class MessagingPreferences extends PreferenceActivity {
private static final String TAG = MessagingPreferences.class.getSimpleName();

private static final float DEFAULT_DRAWER_HEIGHT = 200;

private static final int REQUEST_PICK_BACKGROUND = Activity.RESULT_FIRST_USER + 1;

private static Drawable customBackground;
Expand Down Expand Up @@ -561,6 +563,17 @@ public static String getPushSenderId(Context context) {
return getString(context, "pref_push_sender", null);
}

public static int getDrawerHeight (Context context) {
return getInt(context, "pref_drawer_height", MessageUtils.getDensityPixel(context, DEFAULT_DRAWER_HEIGHT));
}

public static boolean setDrawerHeight (Context context, int height) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.edit()
.putInt("pref_drawer_height", height)
.commit();
}

public static boolean setPushSenderId(Context context, String senderId) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.edit()
Expand Down
Loading

0 comments on commit 771122a

Please sign in to comment.