# HG changeset patch # User "Vincent Veronis" # Date 1296936726 -3600 # Node ID d1b0d878eac9452b6702eba60a87791d564d6295 # Parent f0f107c35a07f922a16620c4d8d808b22ad45786 chat menu settings history chat path file setting diff -r f0f107c35a07 -r d1b0d878eac9 res/layout/preferences.xml --- a/res/layout/preferences.xml Tue Feb 01 00:46:43 2011 +0100 +++ b/res/layout/preferences.xml Sat Feb 05 21:12:06 2011 +0100 @@ -8,9 +8,6 @@ - - + + + + + + + + + Chat compact Activer la fenetre Chat compact Historique + Cochez cette option pour enregistrer les discussions sur la SDCard Il vous faut avoir une SDcard utilisable en écriture pour activer l\'historique Activer la l\'historique des messages + Chat + Historique, taille de la fenêtre ... + Répertoire d\'historique + Les conversations sont enregistrées dans un dossier sur la SDCard Activer le debugger XMPP Utiliser le JID entier en tant que login Nécessaire pour certains serveurs (Google Talk) @@ -217,6 +222,9 @@ XMPP edit_settings_tab_proxy Proxy + Historique + Fenêtre de chat + Bienvenue sur BEEM.\n\nVous n\'avez pas encore configuré de compte XMPP (Jabber).\nChoisissez une des options suivantes : diff -r f0f107c35a07 -r d1b0d878eac9 res/values/strings.xml --- a/res/values/strings.xml Tue Feb 01 00:46:43 2011 +0100 +++ b/res/values/strings.xml Sat Feb 05 21:12:06 2011 +0100 @@ -120,8 +120,13 @@ Chat compact Set the chat windows compact History + Check this to save chats on the SDCard You need to have SDcard mounted and writable to enable history Enable history messages + Chat + History, Layout size ... + History path + Chat conversations are saved in a folder on the SDCard Enable XMPP debug Use my full JID as username Need by some server such as Google Talk @@ -200,6 +205,9 @@ Network options Proxy settings Proxy settings + History + Chat layout + edit_settings_tab_account diff -r f0f107c35a07 -r d1b0d878eac9 src/com/beem/project/beem/BeemApplication.java --- a/src/com/beem/project/beem/BeemApplication.java Tue Feb 01 00:46:43 2011 +0100 +++ b/src/com/beem/project/beem/BeemApplication.java Sat Feb 05 21:12:06 2011 +0100 @@ -87,6 +87,8 @@ public static final String SMACK_DEBUG_KEY = "smack_debug"; /** Preference key for full Jid for login. */ public static final String FULL_JID_LOGIN_KEY = "full_jid_login"; + /** Preference key for history path on the SDCard */ + public static final String CHAT_HISTORY_KEY = "settings_chat_history_path"; //TODO add the other one diff -r f0f107c35a07 -r d1b0d878eac9 src/com/beem/project/beem/service/BeemChatManager.java --- a/src/com/beem/project/beem/service/BeemChatManager.java Tue Feb 01 00:46:43 2011 +0100 +++ b/src/com/beem/project/beem/service/BeemChatManager.java Sat Feb 05 21:12:06 2011 +0100 @@ -43,6 +43,7 @@ */ package com.beem.project.beem.service; +import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -56,6 +57,7 @@ import android.app.PendingIntent; import android.content.Intent; import android.content.SharedPreferences; +import android.os.Environment; import android.os.RemoteCallbackList; import android.os.RemoteException; import android.preference.PreferenceManager; @@ -177,8 +179,12 @@ "settings_key_history", false); String accountUser = PreferenceManager.getDefaultSharedPreferences(mService.getBaseContext()).getString( BeemApplication.ACCOUNT_USERNAME_KEY, ""); - res.setHisory(history); + String historyPath = PreferenceManager.getDefaultSharedPreferences(mService.getBaseContext()).getString( + BeemApplication.CHAT_HISTORY_KEY, ""); + if ("".equals(historyPath)) historyPath = "/Android/data/com.beem.project.beem/chat/"; + res.setHistory(history); res.setAccountUser(accountUser); + res.setHistoryPath(new File(Environment.getExternalStorageDirectory(), historyPath)); Log.d(TAG, "getChat put " + key); mChats.put(key, res); return res; diff -r f0f107c35a07 -r d1b0d878eac9 src/com/beem/project/beem/service/ChatAdapter.java --- a/src/com/beem/project/beem/service/ChatAdapter.java Tue Feb 01 00:46:43 2011 +0100 +++ b/src/com/beem/project/beem/service/ChatAdapter.java Sat Feb 05 21:12:06 2011 +0100 @@ -79,7 +79,8 @@ private final List mMessages; private final RemoteCallbackList mRemoteListeners = new RemoteCallbackList(); private final MsgListener mMsgListener = new MsgListener(); - private boolean mIsHisory; + private boolean mIsHistory; + private File mHistoryPath; private String mAccountUser; /** @@ -108,7 +109,6 @@ public void sendMessage(com.beem.project.beem.service.Message message) throws RemoteException { org.jivesoftware.smack.packet.Message send = new org.jivesoftware.smack.packet.Message(); send.setTo(message.getTo()); - Log.w(TAG, "message to " + message.getTo()); send.setBody(message.getBody()); send.setThread(message.getThread()); send.setSubject(message.getSubject()); @@ -119,11 +119,11 @@ mAdaptee.sendMessage(send); mMessages.add(message); } catch (XMPPException e) { - // TODO Auto-generated catch block e.printStackTrace(); } - //TODO replace me - saveHistory(message, mAccountUser); + String state = Environment.getExternalStorageState(); + if (mIsHistory && Environment.MEDIA_MOUNTED.equals(state)) + saveHistory(message, mAccountUser); } /** @@ -202,7 +202,9 @@ mMessages.remove(0); mMessages.add(msg); if (!"".equals(msg.getBody()) && msg.getBody() != null) { - saveHistory(msg, msg.getFrom()); + String state = Environment.getExternalStorageState(); + if (mIsHistory && Environment.MEDIA_MOUNTED.equals(state)) + saveHistory(msg, msg.getFrom()); } } @@ -212,42 +214,38 @@ * @param contactName the name of the contact */ public void saveHistory(Message msg, String contactName) { - String state = Environment.getExternalStorageState(); - if (mIsHisory && Environment.MEDIA_MOUNTED.equals(state)) { - File path = new File(Environment.getExternalStorageDirectory(), "beem"); - File filepath; - if (msg.getFrom() == contactName) - filepath = new File(path, StringUtils.parseBareAddress(contactName)); - else - filepath = new File(path, StringUtils.parseBareAddress(msg.getTo())); - path.mkdirs(); - try { - FileWriter file = new FileWriter(filepath, true); - String log = msg.getTimestamp() + " " + contactName + " " + msg.getBody() - + System.getProperty("line.separator"); - file.write(log); - file.close(); - Log.i(TAG, log); - } catch (IOException e) { - e.printStackTrace(); - } - } + File path = getHistoryPath(); + File filepath; + if (contactName.equals(msg.getFrom())) + filepath = new File(path, StringUtils.parseBareAddress(contactName)); + else + filepath = new File(path, StringUtils.parseBareAddress(msg.getTo())); + path.mkdirs(); + try { + FileWriter file = new FileWriter(filepath, true); + String log = msg.getTimestamp() + " " + contactName + " " + msg.getBody() + + System.getProperty("line.separator"); + file.write(log); + file.close(); + } catch (IOException e) { + Log.e(TAG, "Error writing chat history", e); + } } /** - * set History state. + * set History enable/disable. * @param isHisory history state */ - public void setHisory(boolean isHisory) { - this.mIsHisory = isHisory; + public void setHistory(boolean isHisory) { + this.mIsHistory = isHisory; } /** * get History state. * @return mIsHistory */ - public boolean getHisory() { - return mIsHisory; + public boolean getHistory() { + return mIsHistory; } /** @@ -267,6 +265,22 @@ } /** + * set History path + * @param mHistoryPath history path + */ + public void setHistoryPath(File mHistoryPath) { + this.mHistoryPath = mHistoryPath; + } + + /** + * get History path + * @return mHistoryPath; + */ + public File getHistoryPath() { + return mHistoryPath; + } + + /** * Listener. */ private class MsgListener implements ChatStateListener { diff -r f0f107c35a07 -r d1b0d878eac9 src/com/beem/project/beem/ui/Settings.java --- a/src/com/beem/project/beem/ui/Settings.java Tue Feb 01 00:46:43 2011 +0100 +++ b/src/com/beem/project/beem/ui/Settings.java Sat Feb 05 21:12:06 2011 +0100 @@ -76,15 +76,6 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.layout.preferences); - CheckBoxPreference history = (CheckBoxPreference) findPreference("settings_key_history"); - String state = Environment.getExternalStorageState(); - if (!Environment.MEDIA_MOUNTED.equals(state)) { - history.setSelectable(false); - history.setSummary(R.string.history_mount); - } else { - history.setSelectable(true); - history.setSummary(R.string.history_on_off); - } } /**