Project

General

Profile

Feature #245 » history.patch

Vincent Véronis, 11/03/2010 12:12 PM

View differences:

default.properties Tue Oct 26 00:59:27 2010 +0200 → default.properties Wed Nov 03 11:56:15 2010 +0100
8 8
# project structure.
9 9

  
10 10
# Project target.
11
target=android-7
11
target=android-8
res/layout/preferences.xml Tue Oct 26 00:59:27 2010 +0200 → res/layout/preferences.xml Wed Nov 03 11:56:15 2010 +0100
1 1
<?xml version="1.0" encoding="utf-8"?>
2
<!-- 
3
    The format of the preference key is defined in
4
    src/com/beem/project/beem/BeemApplication.java
5
    Basically it is just a simple name like account_username.
6
    TODO: There is still a lot of keys to convert
7
-->
2
	<!--
3
		The format of the preference key is defined in
4
		src/com/beem/project/beem/BeemApplication.java Basically it is just a
5
		simple name like account_username. TODO: There is still a lot of keys
6
		to convert
7
	-->
8 8
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
9 9
	android:shouldDisableView="true" android:selectable="true">
10 10
	<PreferenceCategory android:title="@string/general_preferences">
11
		<CheckBoxPreference android:id="@+id/settings_key_history"
12
			android:title="@string/history" android:defaultValue="false"
13
			android:key="settings_key_history" />
11 14
		<PreferenceScreen android:key="contact_list"
12 15
			android:title="@string/contact_list_preferences" android:summary="@string/contact_list_preferences_sum">
13 16
			<CheckBoxPreference android:title="@string/CLP_hidden_contact"
......
28 31
			<CheckBoxPreference android:title="@string/notification_enable_vibrate_title"
29 32
				android:defaultValue="false" android:summary="@string/notification_enable_vibrate_sum"
30 33
				android:key="notification_vibrate" />
31
			<RingtonePreference
32
				android:title="@string/notification_snd_title" android:key="notification_sound"
33
				android:summary="@string/notification_snd_sum" android:ringtoneType="notification"
34
				android:showDefault="true" />
34
			<RingtonePreference android:title="@string/notification_snd_title"
35
				android:key="notification_sound" android:summary="@string/notification_snd_sum"
36
				android:ringtoneType="notification" android:showDefault="true" />
35 37
		</PreferenceScreen>
36 38
	</PreferenceCategory>
37 39
	<PreferenceCategory android:title="@string/user_preferences">
......
70 72
				<EditTextPreference android:singleLine="true"
71 73
					android:dependency="proxy_use" android:name="port"
72 74
					android:summary="@string/SettingsProxyPort" android:title="@string/settings_proxy_port"
73
					android:key="proxy_port" android:numeric="signed" android:hint="@string/comments_proxy_port" />
75
					android:key="proxy_port" android:numeric="signed"
76
					android:hint="@string/comments_proxy_port" />
74 77
			</PreferenceCategory>
75 78
			<PreferenceCategory android:title="@string/proxy_user_settings">
76 79
				<EditTextPreference android:singleLine="true"
res/values/strings.xml Tue Oct 26 00:59:27 2010 +0200 → res/values/strings.xml Wed Nov 03 11:56:15 2010 +0100
117 117
	<string name="notification_enable_vibrate_sum">Enable vibrate on incoming messages</string>
118 118
	<string name="notification_snd_title">Message ringtone</string>
119 119
	<string name="notification_snd_sum">Set your incoming message ringtone</string>
120

  
120
	<string name="history">History</string>
121
	<string name="history_mount">You need to have SDcard mounted and writable to enable history</string>
122
	<string name="history_on_off">Enable/Disable history messages</string>
121 123
	
122 124
	<!-- Subscription class -->
123 125
	<string name="SubscriptAccept">Subscription accepted</string>
src/com/beem/project/beem/service/BeemChatManager.java Tue Oct 26 00:59:27 2010 +0200 → src/com/beem/project/beem/service/BeemChatManager.java Wed Nov 03 11:56:15 2010 +0100
40 40
    Flavien Astraud, November 26, 2009
41 41
    Head of the EIP Laboratory.
42 42

  
43
*/
43
 */
44 44
package com.beem.project.beem.service;
45 45

  
46 46
import java.util.ArrayList;
......
79 79
    private final ChatManager mAdaptee;
80 80
    private final Map<String, ChatAdapter> mChats = new HashMap<String, ChatAdapter>();
81 81
    private final ChatListener mChatListener = new ChatListener();
82
    private final RemoteCallbackList<IChatManagerListener> mRemoteChatCreationListeners =
83
	new RemoteCallbackList<IChatManagerListener>();
82
    private final RemoteCallbackList<IChatManagerListener> mRemoteChatCreationListeners = new RemoteCallbackList<IChatManagerListener>();
84 83
    private final BeemService mService;
85 84

  
86 85
    /**
......
173 172
	    return mChats.get(key);
174 173
	}
175 174
	ChatAdapter res = new ChatAdapter(chat);
175
	boolean history = PreferenceManager.getDefaultSharedPreferences(mService.getBaseContext()).getBoolean("settings_key_history", false);
176
	res.setHisory(history);
176 177
	Log.d(TAG, "getChat put " + key);
177 178
	mChats.put(key, res);
178 179
	return res;
......
256 257
	private PendingIntent makeChatIntent(IChat chat) {
257 258
	    Intent chatIntent = new Intent(mService, com.beem.project.beem.ui.Chat.class);
258 259
	    chatIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP
259
		    | Intent.FLAG_ACTIVITY_NEW_TASK);
260
		| Intent.FLAG_ACTIVITY_NEW_TASK);
260 261
	    try {
261 262
		chatIntent.setData(chat.getParticipant().toUri());
262 263
	    } catch (RemoteException e) {
......
275 276
	    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mService);
276 277
	    try {
277 278
		CharSequence tickerText = mService.getBind().getRoster().getContact(chat.getParticipant().getJID())
278
		.getName();
279
		    .getName();
279 280
		Notification notification = new Notification(android.R.drawable.stat_notify_chat, tickerText, System
280 281
		    .currentTimeMillis());
281 282
		notification.flags = Notification.FLAG_AUTO_CANCEL;
......
305 306
	}
306 307

  
307 308
	@Override
308
	public void stateChanged(final IChat chat) { }
309
	public void stateChanged(final IChat chat) {
310
	}
309 311
    }
310 312
}
src/com/beem/project/beem/service/ChatAdapter.java Tue Oct 26 00:59:27 2010 +0200 → src/com/beem/project/beem/service/ChatAdapter.java Wed Nov 03 11:56:15 2010 +0100
40 40
    Flavien Astraud, November 26, 2009
41 41
    Head of the EIP Laboratory.
42 42

  
43
*/
43
 */
44 44
package com.beem.project.beem.service;
45 45

  
46
import java.io.File;
47
import java.io.FileWriter;
48
import java.io.IOException;
46 49
import java.util.Collections;
47 50
import java.util.LinkedList;
48 51
import java.util.List;
49 52

  
50 53
import org.jivesoftware.smack.Chat;
51 54
import org.jivesoftware.smack.XMPPException;
55
import org.jivesoftware.smack.util.StringUtils;
56
import org.jivesoftware.smackx.ChatState;
52 57
import org.jivesoftware.smackx.ChatStateListener;
53
import org.jivesoftware.smackx.ChatState;
54 58

  
59
import android.os.Environment;
55 60
import android.os.RemoteCallbackList;
56 61
import android.os.RemoteException;
57 62
import android.util.Log;
......
74 79
    private final List<Message> mMessages;
75 80
    private final RemoteCallbackList<IMessageListener> mRemoteListeners = new RemoteCallbackList<IMessageListener>();
76 81
    private final MsgListener mMsgListener = new MsgListener();
77

  
82
    private boolean mIsHisory;
78 83
    /**
79 84
     * Constructor.
80 85
     * @param chat The chat to adapt
......
115 120
	    // TODO Auto-generated catch block
116 121
	    e.printStackTrace();
117 122
	}
123
	saveSendMessage(message);
118 124
    }
119 125

  
120 126
    /**
......
192 198
	if (mMessages.size() == HISTORY_MAX_SIZE)
193 199
	    mMessages.remove(0);
194 200
	mMessages.add(msg);
201
	if (!"".equals(msg.getBody()) && msg.getBody() != null) {
202
	    saveRecvMessage(msg);
203
	}
204
    }
205

  
206
    /**
207
     * Write message in SDCard
208
     * @param msg the message receive
209
     */
210
    public void saveRecvMessage(Message msg) {
211
	String state = Environment.getExternalStorageState();
212
	if (mIsHisory && Environment.MEDIA_MOUNTED.equals(state)) {
213
	    File path = new File(Environment.getExternalStorageDirectory(), "beem");
214
	    File filepath = new File(path, StringUtils.parseBareAddress(msg.getFrom()));
215
	    path.mkdirs();
216
	    try {
217
		FileWriter file = new FileWriter(filepath, true);
218
		String log = msg.getTimestamp() + " " + msg.getFrom() + " :" + " " + msg.getBody()
219
		    + System.getProperty("line.separator");
220
		file.write(log);
221
		file.close();
222
		Log.i(TAG, log);
223
	    } catch (IOException e) {
224
		e.printStackTrace();
225
	    }
226
	}
227
    }
228

  
229
    public void saveSendMessage(Message msg) {
230
	String state = Environment.getExternalStorageState();
231
	if (mIsHisory && Environment.MEDIA_MOUNTED.equals(state)) {
232
	    File path = new File(Environment.getExternalStorageDirectory(), "beem");
233
	    File filepath = new File(path, StringUtils.parseBareAddress(msg.getTo()));
234
	    path.mkdirs();
235
	    try {
236
		FileWriter file = new FileWriter(filepath, true);
237
		//TODO : getString me
238
		String log = msg.getTimestamp() + " me : " + msg.getBody() + System.getProperty("line.separator");
239
		file.write(log);
240
		file.close();
241
		Log.i(TAG, log);
242
	    } catch (IOException e) {
243
		e.printStackTrace();
244
	    }
245
	}
246
    }
247

  
248
    public void setHisory(boolean mIsHisory) {
249
	this.mIsHisory = mIsHisory;
250
    }
251

  
252
    public boolean getHisory() {
253
	return mIsHisory;
195 254
    }
196 255

  
197 256
    /**
......
201 260
	/**
202 261
	 * Constructor.
203 262
	 */
204
	public MsgListener() { }
263
	public MsgListener() {
264
	}
205 265

  
206 266
	@Override
207 267
	public void processMessage(Chat chat, org.jivesoftware.smack.packet.Message message) {
208
	    Message  msg = new Message(message);
268
	    Message msg = new Message(message);
209 269
	    //TODO add que les message pas de type errors
210 270
	    ChatAdapter.this.addMessage(msg);
211 271
	    final int n = mRemoteListeners.beginBroadcast();
......
241 301
	}
242 302
    }
243 303
}
244

  
src/com/beem/project/beem/ui/Chat.java Tue Oct 26 00:59:27 2010 +0200 → src/com/beem/project/beem/ui/Chat.java Wed Nov 03 11:56:15 2010 +0100
40 40
    Flavien Astraud, November 26, 2009
41 41
    Head of the EIP Laboratory.
42 42

  
43
*/
43
 */
44 44
package com.beem.project.beem.ui;
45 45

  
46 46
import java.text.DateFormat;
......
65 65
import android.os.Handler;
66 66
import android.os.IBinder;
67 67
import android.os.RemoteException;
68
import android.preference.PreferenceManager;
68 69
import android.text.util.Linkify;
69 70
import android.util.Log;
70 71
import android.view.KeyEvent;
......
170 171
		sendMessage();
171 172
	    }
172 173
	});
173

  
174 174
	prepareIconsStatus();
175 175
    }
176 176

  
......
491 491
		    @Override
492 492
		    public void run() {
493 493
			if (msg.getType() == Message.MSG_TYPE_ERROR) {
494
			    mListMessages.add(new MessageText(fromBareJid, mContact.getName(), msg.getBody(), true, msg.getTimestamp()));
494
			    mListMessages.add(new MessageText(fromBareJid, mContact.getName(), msg.getBody(), true, msg
495
				.getTimestamp()));
495 496
			    mMessagesListAdapter.notifyDataSetChanged();
496 497
			} else if (msg.getBody() != null) {
497 498
			    MessageText lastMessage = null;
......
503 504
				lastMessage.setTimestamp(msg.getTimestamp());
504 505
				mListMessages.set(mListMessages.size() - 1, lastMessage);
505 506
			    } else if (msg.getBody() != null)
506
				mListMessages.add(new MessageText(fromBareJid, mContact.getName(), msg.getBody(), false, msg.getTimestamp()));
507
				mListMessages.add(new MessageText(fromBareJid, mContact.getName(), msg.getBody(),
508
				    false, msg.getTimestamp()));
507 509
			    mMessagesListAdapter.notifyDataSetChanged();
508 510
			}
509 511
		    }
......
705 707
	 * @param isError if the message is an error message.
706 708
	 * @param date the time of the message.
707 709
	 */
708
	public MessageText(final String bareJid, final String name, final String message, final boolean isError, Date date) {
710
	public MessageText(final String bareJid, final String name, final String message, final boolean isError,
711
	    Date date) {
709 712
	    mBareJid = bareJid;
710 713
	    mName = name;
711 714
	    mMessage = message;
......
773 776

  
774 777
	/**
775 778
	 * Set the Date of the message.
776
	 *
777 779
	 * @param date date of the message.
778 780
	 */
779 781
	public void setTimestamp(Date date) {
......
782 784

  
783 785
	/**
784 786
	 * Get the Date of the message.
785
	 *
786 787
	 * @return if it is a delayed message get the date the message was sended.
787 788
	 */
788 789
	public Date getTimestamp() {
src/com/beem/project/beem/ui/Settings.java Tue Oct 26 00:59:27 2010 +0200 → src/com/beem/project/beem/ui/Settings.java Wed Nov 03 11:56:15 2010 +0100
40 40
    Flavien Astraud, November 26, 2009
41 41
    Head of the EIP Laboratory.
42 42

  
43
*/
43
 */
44 44
package com.beem.project.beem.ui;
45 45

  
46 46
import android.content.ComponentName;
47 47
import android.content.Intent;
48
import android.content.SharedPreferences;
48 49
import android.os.Bundle;
50
import android.os.Environment;
51
import android.preference.CheckBoxPreference;
49 52
import android.preference.PreferenceActivity;
53
import android.preference.PreferenceManager;
50 54
import android.view.Menu;
51 55
import android.view.MenuInflater;
52 56
import android.view.MenuItem;
57
import android.widget.CheckBox;
53 58

  
54 59
import com.beem.project.beem.R;
55 60

  
......
74 79
    public void onCreate(Bundle savedInstanceState) {
75 80
	super.onCreate(savedInstanceState);
76 81
	addPreferencesFromResource(R.layout.preferences);
82
	CheckBoxPreference history = (CheckBoxPreference) findPreference("settings_key_history");
83
	String state = Environment.getExternalStorageState();
84
	if (!Environment.MEDIA_MOUNTED.equals(state)) {
85
	    history.setSelectable(false);
86
	    history.setSummary(R.string.history_mount);
87
	} else {
88
	    history.setSelectable(true);
89
	    history.setSummary(R.string.history_on_off);
90
	}
91
    }
92
    
93
    @Override
94
    protected void onResume() {
95
        super.onResume();
77 96
    }
78 97

  
79 98
    /**
    (1-1/1)