Skip to content
This repository has been archived by the owner on May 30, 2020. It is now read-only.

fix notifications, drawable avatars, unique resource #54

Merged
merged 1 commit into from
Nov 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added res/drawable-hdpi/avatar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/avatar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xhdpi/avatar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxhdpi/avatar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxxhdpi/avatar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 3 additions & 6 deletions src/protocol/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ public final void addMessage(Message message, boolean silent) {
isMention = isHighlight;
}
if (message.isOffline()) {
} else if (isPersonal) {
} else if (isPersonal || isMention) {
isWakeUp = contact.isAuth() && !contact.isTemp()
&& message.isWakeUp() && Options.getBoolean(JLocale.getString(R.string.pref_alarm));
if (isWakeUp) {
Expand All @@ -890,13 +890,10 @@ public final void addMessage(Message message, boolean silent) {
}
}
if (!isWakeUp) {
boolean isNewMessageIcon = (chat.typeNewMessageIcon != chat.getNewMessageIcon()
&& !contact.getUserId().equals(ChatHistory.instance.getLastChatNick()))
|| Message.ICON_IN_MSG_HI == chat.typeNewMessageIcon;
if (isNewMessageIcon && !chat.isVisibleChat()) {
if (!chat.isVisibleChat()) {
chat.typeNewMessageIcon = chat.getNewMessageIcon();
RosterHelper.getInstance().updateRoster(contact);
SawimApplication.getInstance().sendNotify(contact.getUserId(), message.getProcessedText(), notifyMessage && !chat.isVisibleChat());
SawimApplication.getInstance().sendNotify(contact.getUserId(), message.getProcessedText(), notifyMessage && !chat.isVisibleChat(), message.getName());
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/protocol/xmpp/Xmpp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.provider.Settings;
import android.widget.Toast;
import protocol.*;
import ru.sawim.R;
Expand Down Expand Up @@ -445,7 +446,8 @@ String getDefaultServer(String domain) {
}

protected String processUin(String uin) {
resource = Jid.getResource(uin, "Sawim");
String android_id = Settings.Secure.getString(SawimApplication.getContext().getContentResolver(),Settings.Secure.ANDROID_ID);
resource = Jid.getResource(uin, "Sawim"+" ("+android_id+")");
return Jid.getBareJid(uin);
}

Expand Down
6 changes: 5 additions & 1 deletion src/protocol/xmpp/XmppConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import ru.sawim.modules.search.UserInfo;
import ru.sawim.roster.RosterHelper;

import java.io.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.NoSuchAlgorithmException;
Expand Down Expand Up @@ -871,6 +874,7 @@ private void parseIq(XmlNode iq) throws SawimException {
+ "'/></iq>");
}
if (IQ_TYPE_RESULT == iqType) {
String jid = Jid.isConference(from) ? from : Jid.getBareJid(from);
String time = iqQuery.getAttribute("seconds");
time = Util.secDiffToDate(Integer.parseInt(time));
getXmpp().addMessage(new SystemNotice(getXmpp(), (byte) -1, Jid.getBareJid(from), time));
Expand Down
17 changes: 11 additions & 6 deletions src/protocol/xmpp/XmppServiceContact.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

public class XmppServiceContact extends XmppContact {

public static final byte STATUS_ONLINE = (byte) 1;
public static final byte STATUS_AWAY = (byte) 2;
public static final byte STATUS_DND = (byte) 3;
public static final byte STATUS_OFFLINE = (byte) 0;
public static final byte AFFILIATION_NONE = (byte) 0;
public static final byte AFFILIATION_MEMBER = (byte) 1;
public static final byte AFFILIATION_ADMIN = (byte) 2;
Expand Down Expand Up @@ -62,18 +66,19 @@ public XmppServiceContact(String jid, String name) {
}
}

public static final int getAffiliationName(byte index) {

public static final int getStatusName(byte index) {
switch (index) {
case AFFILIATION_OWNER:
case STATUS_AWAY:
return 0;
case AFFILIATION_ADMIN:
case STATUS_DND:
return 1;
case AFFILIATION_MEMBER:
case STATUS_ONLINE:
return 2;
case AFFILIATION_NONE:
case STATUS_OFFLINE:
return 3;
}
return 0;
return 1;
};

public boolean isAutoJoin() {
Expand Down
8 changes: 5 additions & 3 deletions src/ru/sawim/SawimApplication.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ru.sawim;

import android.app.*;
import android.app.ActivityManager;
import android.app.Application;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
Expand Down Expand Up @@ -189,8 +191,8 @@ public void setStatus(Protocol p, int statusIndex, String statusMsg) {
serviceConnection.send(Message.obtain(null, SawimService.SET_STATUS, objects));
}

public void sendNotify(String title, String text, boolean silent) {
Object[] parameters = new Object[]{title, text, silent};
public void sendNotify(String title, String text, boolean silent, String nick) {
Object[] parameters = new Object[]{ title, text, silent, nick};
serviceConnection.send(Message.obtain(null, SawimService.SEND_NOTIFY, parameters));
}

Expand Down
11 changes: 8 additions & 3 deletions src/ru/sawim/SawimNotification.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ public class SawimNotification {
public static final int ALARM_NOTIFY_ID = 2;
private static final HashMap<String, Integer> idsMap = new HashMap<String, Integer>();
private static final HashMap<Integer, NotificationCompat.Builder> notifiBuildersMap = new HashMap<Integer, NotificationCompat.Builder>();

public static Notification get(Context context, String nick, boolean silent) {
private static String lastNotifyContact;
public static Notification get(Context context, String nick, boolean silent, String senderName) {
int unread = ChatHistory.instance.getPersonalUnreadMessageCount(false);
int allUnread = ChatHistory.instance.getPersonalUnreadMessageCount(true);
CharSequence stateMsg = "";
lastNotifyContact = nick;
final int icon;
if (0 < allUnread) {
icon = R.drawable.ic_tray_msg;
Expand Down Expand Up @@ -84,7 +85,7 @@ public static Notification get(Context context, String nick, boolean silent) {
.setContentText(stateMsg)
.setSmallIcon(icon)
.setContentTitle(nick == null ? context.getString(R.string.app_name)
: context.getString(R.string.message_from) + " " + nick);
: context.getString(R.string.message_from) + " " + (senderName == null ? nick : senderName+"/"+nick));
return notification.build();
}

Expand Down Expand Up @@ -225,4 +226,8 @@ public static void clear(String id) {
((NotificationManager) SawimApplication.getContext().getSystemService(Context.NOTIFICATION_SERVICE)).cancel(idsMap.get(id));
idsMap.remove(id);
}

public static String getLastNotifyContact() {
return lastNotifyContact;
}
}
18 changes: 12 additions & 6 deletions src/ru/sawim/activities/SawimActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
import protocol.icq.Icq;
import protocol.mrim.Mrim;
import protocol.xmpp.Xmpp;
import ru.sawim.*;
import ru.sawim.Options;
import ru.sawim.R;
import ru.sawim.SawimApplication;
import ru.sawim.Scheme;
import ru.sawim.chat.Chat;
import ru.sawim.chat.ChatHistory;
import ru.sawim.modules.DebugLog;
Expand Down Expand Up @@ -91,12 +94,15 @@ private void handleIntent() {
rosterView.setMode(getIntent().getType().equals("text/plain") ? RosterView.MODE_SHARE_TEXT : RosterView.MODE_SHARE);
return;
}
Chat current = ChatHistory.instance.getChat(ChatHistory.instance.getLastChatNick());
if (NOTIFY.equals(getIntent().getAction()) || NOTIFY_REPLY.equals(getIntent().getAction())) {
if (current != null) {
if (NOTIFY.equals(getIntent().getAction())) {
Chat current = ChatHistory.instance.chatAt(ChatHistory.instance.getPreferredItem());
if (current != null)
isOpenNewChat = openChat(current.getProtocol(), current.getContact(), true);
}
if (NOTIFY_REPLY.equals(getIntent().getAction())) {
Chat current = ChatHistory.instance.chatAt(ChatHistory.instance.getPreferredItem());
if (current != null)
isOpenNewChat = openChat(current.getProtocol(), current.getContact(), true);
ChatHistory.instance.nicksTable.remove(ChatHistory.instance.nicksTable.size() - 1);
}
}
if (NOTIFY_CAPTCHA.equals(getIntent().getAction())) {
FormView.showWindows(this, getIntent().getStringExtra(NOTIFY_CAPTCHA));
Expand Down
4 changes: 3 additions & 1 deletion src/ru/sawim/icons/ImageCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@


import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.TextUtils;
import ru.sawim.R;
import ru.sawim.SawimApplication;
import ru.sawim.comm.LruCache;
import ru.sawim.widget.Util;
Expand Down Expand Up @@ -86,7 +88,7 @@ public void run() {
});
}
} else {
bitmap = RoundedAvatars.getRoundedBitmapNotExsist(AVATAR_SIZE);
bitmap = BitmapFactory.decodeResource(SawimApplication.getContext().getResources(), R.drawable.avatar);
}
return bitmap;
}
Expand Down
33 changes: 0 additions & 33 deletions src/ru/sawim/icons/RoundedAvatars.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,4 @@ public static Bitmap getRoundedBitmap(Bitmap bitmap) {
}
return output;
}

public static Bitmap getRoundedBitmapNotExsist(int AVATAR_SIZE) {
Bitmap output = null;
try {
output = Bitmap.createBitmap(AVATAR_SIZE,AVATAR_SIZE, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff33B5E5;
final Paint paint_main = new Paint(Paint.ANTI_ALIAS_FLAG);
Paint paint_s = new Paint();
final Rect rect = new Rect(0, 0, AVATAR_SIZE,AVATAR_SIZE);
paint_main.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint_main.setColor(color);
paint_s.setColor(Color.WHITE);
float target = (float)rect.height()*.6f;
paint_s.setTextSize(target);
paint_s.setAntiAlias(true);
paint_s.setTextAlign(Paint.Align.CENTER);
Rect bounds = new Rect();
paint_s.setTextAlign(Paint.Align.CENTER);
String gText = "S";
paint_s.getTextBounds(gText, 0, gText.length(), bounds);
int y = (output.getHeight() + bounds.height())/2;
canvas.drawCircle(AVATAR_SIZE / 2, AVATAR_SIZE / 2, AVATAR_SIZE / 2, paint_main);
canvas.drawText("S", rect.width() / 2, y, paint_s);
paint_main.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(output, rect, rect, paint_main);
} catch (Exception ex) {
ex.printStackTrace();
}
return output;
}

}
2 changes: 1 addition & 1 deletion src/ru/sawim/models/MucUsersAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,6 @@ public void run() {
if (ic != null && !Options.getBoolean(JLocale.getString(R.string.pref_hide_icons_clients))) {
rosterItemView.itemFifthImage = ic.getImage().getBitmap();
}
rosterItemView.itemSixthImage = SawimResources.affiliationIcons.iconAt(XmppServiceContact.getAffiliationName(c.status)).getImage().getBitmap();
rosterItemView.itemSixthImage = SawimResources.affiliationIcons.iconAt(XmppServiceContact.getStatusName(c.status)).getImage().getBitmap();
}
}
13 changes: 6 additions & 7 deletions src/ru/sawim/models/RosterAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import protocol.*;
import protocol.xmpp.XmppServiceContact;
import ru.sawim.SawimApplication;
import ru.sawim.SawimResources;
import ru.sawim.Scheme;
Expand All @@ -26,7 +27,6 @@
import ru.sawim.roster.RosterHelper;
import ru.sawim.roster.TreeNode;
import ru.sawim.widget.MyImageButton;
import ru.sawim.widget.Util;
import ru.sawim.widget.roster.RosterItemView;

import java.util.ArrayList;
Expand Down Expand Up @@ -229,9 +229,11 @@ public void run() {
}
});
rosterItemView.itemFirstImage = avatar;
Icon icStatus = item.getLeftIcon(p);
if (icStatus != null)
rosterItemView.itemSecondImage = icStatus.getImage().getBitmap();
rosterItemView.itemSixthImage = SawimResources.affiliationIcons.iconAt(XmppServiceContact.getStatusName(item.getStatusIndex())).getImage().getBitmap();

Icon icClient = (null != p.clientInfo) ? p.clientInfo.getIcon(item.clientIndex) : null;
if (icClient != null && !SawimApplication.hideIconsClient)
rosterItemView.itemSecondImage = icClient.getImage().getBitmap();
if (item.isTyping()) {
rosterItemView.itemSecondImage = Message.getIcon(Message.ICON_TYPE).getBitmap();
} else {
Expand Down Expand Up @@ -263,9 +265,6 @@ public void run() {
}
}

Icon icClient = (null != p.clientInfo) ? p.clientInfo.getIcon(item.clientIndex) : null;
if (icClient != null && !SawimApplication.hideIconsClient)
rosterItemView.itemSixthImage = icClient.getImage().getBitmap();
}

public BitmapDrawable getImageChat(Chat chat, boolean showMess) {
Expand Down
6 changes: 3 additions & 3 deletions src/ru/sawim/service/SawimService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class SawimService extends Service {
@Override
public void onCreate() {
super.onCreate();
SawimService.this.startForeground(R.string.app_name, SawimNotification.get(SawimService.this, null, false));
SawimService.this.startForeground(R.string.app_name, SawimNotification.get(SawimService.this, null, false, null));
Log.i(LOG_TAG, "onStart();");
}

Expand Down Expand Up @@ -88,11 +88,11 @@ public void handleMessage(final Message msg) {
updateLock();
break;
case UPDATE_APP_ICON:
SawimService.this.startForeground(R.string.app_name, SawimNotification.get(SawimService.this, null, false));
SawimService.this.startForeground(R.string.app_name, SawimNotification.get(SawimService.this, null, false, null));
break;
case SEND_NOTIFY:
//SawimNotification.sendNotify(SawimService.this, (String)((Object[])msg.obj)[0], (String)((Object[])msg.obj)[1]);
SawimService.this.startForeground(R.string.app_name, SawimNotification.get(SawimService.this, (String)((Object[])msg.obj)[0], (boolean)((Object[])msg.obj)[2]));
SawimService.this.startForeground(R.string.app_name, SawimNotification.get(SawimService.this, (String)((Object[])msg.obj)[0], (boolean)((Object[])msg.obj)[2], (String)((Object[])msg.obj)[3]));
break;
case SET_STATUS:
final Protocol protocol = (Protocol) ((Object[]) msg.obj)[0];
Expand Down
2 changes: 1 addition & 1 deletion src/ru/sawim/widget/roster/RosterItemView.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private void computeCoordinates(int ascent, int descent, int viewWidth, int view
}
sixthImageX = fifthImageX;
if (itemSixthImage != null) {
sixthImageX = secondImageX - leftPadding - 3;
sixthImageX = secondImageX - itemSixthImage.getWidth();
sixthImageY = firstImageY;
}
}
Expand Down