");
178 | message.setText(body, "utf-8", "html");
179 | message.setFlag(Flags.Flag.SEEN,true);
180 | }
181 | message.setSubject(note.GetTitle());
182 | MailDateFormat mailDateFormat = new MailDateFormat();
183 | // Remove (CET) or (GMT+1) part as asked in github issue #13
184 | String headerDate = (mailDateFormat.format(new Date())).replaceAll("\\(.*$", "");
185 | message.addHeader("Date", headerDate);
186 | //déterminer l'uid temporaire
187 | String uid = Integer.toString(Math.abs(Integer.parseInt(note.GetUid())));
188 | File directory = new File ((ImapNotes2.getAppContext()).getFilesDir() + "/" +
189 | Listactivity.imapNotes2Account.GetAccountname() + "/new");
190 | //message.setFrom(new InternetAddress("ImapNotes2", Listactivity.imapNotes2Account.GetAccountname()));
191 | message.setFrom(Listactivity.imapNotes2Account.GetAccountname());
192 | File outfile = new File (directory, uid);
193 | OutputStream str = new FileOutputStream(outfile);
194 | message.writeTo(str);
195 |
196 | }
197 |
198 | }
199 |
--------------------------------------------------------------------------------
/ImapNote2/src/main/java/com/Pau/ImapNotes2/NewNoteActivity.java:
--------------------------------------------------------------------------------
1 | package com.Pau.ImapNotes2;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.graphics.Color;
6 | import android.os.Bundle;
7 | import android.support.v4.app.NavUtils;
8 | import android.text.Html;
9 | import android.view.Menu;
10 | import android.view.MenuItem;
11 | import android.widget.EditText;
12 |
13 | public class NewNoteActivity extends Activity{
14 |
15 | private static final int SAVE_BUTTON = 5;
16 | private static final String TAG = "IN_NewNoteActivity";
17 | private String sticky;
18 | private String color = "NONE";
19 |
20 | public void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.new_note);
23 | getActionBar().setDisplayHomeAsUpEnabled(true);
24 | this.ResetColors();
25 | this.sticky = (String)getIntent().getExtras().get("usesSticky");
26 | }
27 |
28 | private void ResetColors(){
29 | ((EditText)findViewById(R.id.editNote)).setBackgroundColor(Color.TRANSPARENT);
30 | ((EditText)findViewById(R.id.editNote)).setTextColor(Color.BLACK);
31 | }
32 |
33 | public boolean onCreateOptionsMenu(Menu menu){
34 | getMenuInflater().inflate(R.menu.newnote, menu);
35 | return true;
36 | }
37 |
38 | public boolean onOptionsItemSelected (MenuItem item){
39 | switch (item.getItemId()){
40 | case R.id.save:
41 | Intent intent=new Intent();
42 | intent.putExtra("SAVE_ITEM",Html.toHtml(((EditText)findViewById(R.id.editNote)).getText()));
43 | if (this.sticky.equals("true")) {
44 | this.color="YELLOW";
45 | }
46 | intent.putExtra("SAVE_ITEM_COLOR",this.color);
47 | setResult(SAVE_BUTTON, intent);
48 | finish();//finishing activity
49 | return true;
50 | case android.R.id.home:
51 | NavUtils.navigateUpFromSameTask(this);
52 | return true;
53 | default:
54 | return super.onOptionsItemSelected(item);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/ImapNote2/src/main/java/com/Pau/ImapNotes2/NoteDetailActivity.java:
--------------------------------------------------------------------------------
1 | package com.Pau.ImapNotes2;
2 |
3 | import java.util.HashMap;
4 | import javax.mail.Message;
5 | import javax.mail.MessagingException;
6 | import javax.mail.Multipart;
7 | import javax.mail.Part;
8 | import javax.mail.internet.ContentType;
9 | import javax.mail.internet.MimeMessage;
10 |
11 | import org.apache.commons.io.IOUtils;
12 |
13 | import com.Pau.ImapNotes2.Miscs.OneNote;
14 | import com.Pau.ImapNotes2.Miscs.Sticky;
15 | import com.Pau.ImapNotes2.Sync.SyncUtils;
16 |
17 | import java.io.File;
18 | import java.io.FileOutputStream;
19 | import java.io.IOException;
20 | import java.io.InputStream;
21 | import java.io.OutputStream;
22 |
23 | import android.app.Activity;
24 | import android.content.Intent;
25 | import android.graphics.Color;
26 | import android.os.Bundle;
27 | import android.support.v4.app.NavUtils;
28 | import android.text.Html;
29 | import android.text.Spanned;
30 | import android.util.Log;
31 | import android.view.Menu;
32 | import android.view.MenuItem;
33 | import android.view.View;
34 | import android.view.WindowManager;
35 | import android.widget.EditText;
36 |
37 | public class NoteDetailActivity extends Activity {
38 |
39 | private static final int DELETE_BUTTON = 3;
40 | private static final int EDIT_BUTTON = 6;
41 | private HashMap hm;
42 | private String usesticky;
43 | private Sticky sticky;
44 | private String stringres;
45 | private String color;
46 | private String position;
47 | private int realColor = R.id.yellow;
48 | private Boolean isClicked = false;
49 | private Message message;
50 | private String suid; // uid as string
51 | private final static int ROOT_AND_NEW = 3;
52 | private static final String TAG = "IN_NoteDetailActivity";
53 |
54 | public void onCreate(Bundle savedInstanceState) {
55 | super.onCreate(savedInstanceState);
56 | setContentView(R.layout.note_detail);
57 | getActionBar().setDisplayHomeAsUpEnabled(true);
58 | // Don't display keyboard when on note detail, only if user touches the screen
59 | getWindow().setSoftInputMode(
60 | WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
61 | );
62 |
63 | this.hm = (HashMap)getIntent().getExtras().get("selectedNote");
64 | this.usesticky = (String)getIntent().getExtras().get("useSticky");
65 |
66 | suid = this.hm.get("uid").toString();
67 | String rootDir = (ImapNotes2.getAppContext()).getFilesDir() + "/" +
68 | Listactivity.imapNotes2Account.GetAccountname();
69 | message = SyncUtils.ReadMailFromFile(suid, ROOT_AND_NEW, true, rootDir);
70 | sticky = GetInfoFromMessage(message);
71 | stringres = sticky.GetText();
72 | position = sticky.GetPosition();
73 | color = sticky.GetColor();
74 | Spanned plainText = Html.fromHtml(stringres);
75 | ((EditText)findViewById(R.id.bodyView)).setText(plainText);
76 | this.ResetColors();
77 | //invalidateOptionsMenu();
78 | }
79 |
80 | public void onClick(View v){
81 | this.isClicked = true;
82 | }
83 |
84 | private void ResetColors(){
85 | ((EditText)findViewById(R.id.bodyView)).setBackgroundColor(Color.TRANSPARENT);
86 | ((EditText)findViewById(R.id.bodyView)).setTextColor(Color.BLACK);
87 | Colors currentColor = Colors.valueOf(color);
88 | switch (currentColor) {
89 | case BLUE:
90 | (findViewById(R.id.scrollView)).setBackgroundColor(0xFFA6CAFD);
91 | this.realColor = R.id.blue;
92 | break;
93 | case WHITE:
94 | (findViewById(R.id.scrollView)).setBackgroundColor(0xFFFFFFFF);
95 | this.realColor = R.id.white;
96 | break;
97 | case YELLOW:
98 | (findViewById(R.id.scrollView)).setBackgroundColor(0xFFFFFFCC);
99 | this.realColor = R.id.yellow;
100 | break;
101 | case PINK:
102 | (findViewById(R.id.scrollView)).setBackgroundColor(0xFFFFCCCC);
103 | this.realColor = R.id.pink;
104 | break;
105 | case GREEN:
106 | (findViewById(R.id.scrollView)).setBackgroundColor(0xFFCCFFCC);
107 | this.realColor = R.id.green;
108 | break;
109 | default:
110 | (findViewById(R.id.scrollView)).setBackgroundColor(Color.TRANSPARENT);
111 | }
112 | invalidateOptionsMenu();
113 | }
114 |
115 | public boolean onCreateOptionsMenu(Menu menu){
116 | getMenuInflater().inflate(R.menu.detail, menu);
117 | return true;
118 | }
119 |
120 | @Override
121 | public boolean onPrepareOptionsMenu(Menu menu) {
122 | MenuItem item= menu.findItem(R.id.color);
123 | super.onPrepareOptionsMenu(menu);
124 | //depending on your conditions, either enable/disable
125 | if (this.usesticky.equals("true")) {
126 | item.setVisible(true);
127 | } else {
128 | item.setVisible(false);
129 | }
130 | menu.findItem(this.realColor).setChecked(true);
131 | return true;
132 | }
133 |
134 | public boolean onOptionsItemSelected (MenuItem item){
135 | Intent intent=new Intent();
136 | switch (item.getItemId()){
137 | case R.id.delete:
138 | //Log.d(TAG,"We ask to delete Message #"+this.currentNote.get("number"));
139 | intent.putExtra("DELETE_ITEM_NUM_IMAP",suid);
140 | setResult(NoteDetailActivity.DELETE_BUTTON, intent);
141 | finish();//finishing activity
142 | return true;
143 | case R.id.save:
144 | //Log.d(TAG,"We ask to modify Message #"+this.currentNote.get("number"));
145 | intent.putExtra("EDIT_ITEM_NUM_IMAP",suid);
146 | intent.putExtra("EDIT_ITEM_TXT",
147 | Html.toHtml(((EditText)findViewById(R.id.bodyView)).getText()));
148 | if (!this.usesticky.equals("true")) {
149 | this.color="NONE";
150 | }
151 | intent.putExtra("EDIT_ITEM_COLOR",this.color);
152 | setResult(NoteDetailActivity.EDIT_BUTTON, intent);
153 | finish();//finishing activity
154 | return true;
155 | case android.R.id.home:
156 | NavUtils.navigateUpFromSameTask(this);
157 | return true;
158 | case R.id.blue:
159 | item.setChecked(true);
160 | this.color = "BLUE";
161 | (findViewById(R.id.scrollView)).setBackgroundColor(0xFFA6CAFD);
162 | return true;
163 | case R.id.white:
164 | item.setChecked(true);
165 | this.color = "WHITE";
166 | (findViewById(R.id.scrollView)).setBackgroundColor(0xFFFFFFFF);
167 | return true;
168 | case R.id.yellow:
169 | item.setChecked(true);
170 | this.color = "YELLOW";
171 | (findViewById(R.id.scrollView)).setBackgroundColor(0xFFFFFFCC);
172 | return true;
173 | case R.id.pink:
174 | item.setChecked(true);
175 | this.color = "PINK";
176 | (findViewById(R.id.scrollView)).setBackgroundColor(0xFFFFCCCC);
177 | return true;
178 | case R.id.green:
179 | item.setChecked(true);
180 | this.color = "GREEN";
181 | (findViewById(R.id.scrollView)).setBackgroundColor(0xFFCCFFCC);
182 | return true;
183 | default:
184 | return super.onOptionsItemSelected(item);
185 | }
186 | }
187 |
188 | public enum Colors {
189 | BLUE,
190 | WHITE,
191 | YELLOW,
192 | PINK,
193 | GREEN,
194 | NONE
195 | }
196 |
197 | private Sticky GetInfoFromMessage (Message message) {
198 | ContentType contentType = null;
199 | String stringres = null;
200 | InputStream iis = null;
201 | String color = "NONE";
202 | String charset;
203 | Sticky sticky = null;
204 | try {
205 | //Log.d(TAG, "Contenttype as string:"+message.getContentType());
206 | contentType = new ContentType(message.getContentType() );
207 | charset = contentType.getParameter("charset");
208 | iis = (InputStream)message.getContent();
209 | stringres = IOUtils.toString(iis, charset);
210 | } catch (Exception e) {
211 | // TODO Auto-generated catch block
212 | e.printStackTrace();
213 | }
214 |
215 | //Log.d(TAG,"contentType:"+contentType);
216 | if (contentType.match("text/x-stickynote")) {
217 | sticky = SyncUtils.ReadStickynote(stringres);
218 | } else if (contentType.match("TEXT/HTML")) {
219 | sticky = ReadHtmlnote(stringres);
220 | } else if (contentType.match("TEXT/PLAIN")) {
221 | sticky = ReadPlainnote(stringres);
222 | } else if (contentType.match("multipart/related")) {
223 | // All next is a workaround
224 | // All function need to be rewritten to handle correctly multipart and images
225 | if (contentType.getParameter("type").equalsIgnoreCase("TEXT/HTML")) {
226 | sticky = ReadHtmlnote(stringres);
227 | } else if (contentType.getParameter("type").equalsIgnoreCase("TEXT/PLAIN")) {
228 | sticky = ReadPlainnote(stringres);
229 | }
230 | } else if (contentType.getParameter("BOUNDARY") != null) {
231 | sticky = ReadHtmlnote(stringres);
232 | }
233 | return sticky;
234 | }
235 |
236 | private void GetPart(Part message) throws Exception {
237 | if (message.isMimeType("text/plain")) {
238 | Log.d(TAG,"+++ isMimeType text/plain (contentType):"+message.getContentType());
239 | } else if (message.isMimeType("multipart/*")) {
240 | Log.d(TAG,"+++ isMimeType multipart/* (contentType):"+message.getContentType());
241 | Object content = message.getContent();
242 | Multipart mp = (Multipart) content;
243 | int count = mp.getCount();
244 | for (int i = 0; i < count; i++) GetPart(mp.getBodyPart(i));
245 | } else if (message.isMimeType("message/rfc822")) {
246 | Log.d(TAG,"+++ isMimeType message/rfc822/* (contentType):"+message.getContentType());
247 | GetPart((Part) message.getContent());
248 | } else if (message.isMimeType("image/jpeg")) {
249 | Log.d(TAG,"+++ isMimeType image/jpeg (contentType):"+message.getContentType());
250 | } else if (message.getContentType().contains("image/")) {
251 | Log.d(TAG,"+++ isMimeType image/jpeg (contentType):"+message.getContentType());
252 | } else {
253 | Object o = message.getContent();
254 | if (o instanceof String) {
255 | Log.d(TAG,"+++ instanceof String");
256 | } else if (o instanceof InputStream) {
257 | Log.d(TAG,"+++ instanceof InputStream");
258 | } else Log.d(TAG,"+++ instanceof ???");
259 | }
260 | }
261 |
262 | private Sticky ReadHtmlnote(String stringres) {
263 | // Log.d(TAG,"From server (html):"+stringres);
264 | Spanned spanres = Html.fromHtml(stringres);
265 | stringres = Html.toHtml(spanres);
266 | stringres = stringres.replaceFirst("
", "");
267 | stringres = stringres.replaceFirst("
", "");
268 | stringres = stringres.replaceAll("
", "
");
269 | stringres = stringres.replaceAll("
", "
");
270 | stringres = stringres.replaceAll("
", "");
271 |
272 | return new Sticky(stringres, "", "NONE");
273 | }
274 |
275 | private Sticky ReadPlainnote(String stringres) {
276 | // Log.d(TAG,"From server (plain):"+stringres);
277 | stringres = stringres.replaceAll("\n", "
");
278 |
279 | return new Sticky(stringres, "", "NONE");
280 | }
281 |
282 | private void WriteMailToFile (String suid, Message message) {
283 | String directory = (ImapNotes2.getAppContext()).getFilesDir() + "/" +
284 | Listactivity.imapNotes2Account.GetAccountname();
285 | try {
286 | File outfile = new File (directory, suid);
287 | OutputStream str = new FileOutputStream(outfile);
288 | message.writeTo(str);
289 | } catch (Exception e) {
290 | // TODO Auto-generated catch block
291 | e.printStackTrace();
292 | }
293 | }
294 |
295 |
296 |
297 | }
298 |
--------------------------------------------------------------------------------
/ImapNote2/src/main/java/com/Pau/ImapNotes2/NotesListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.Pau.ImapNotes2;
2 |
3 | /*
4 | * Copyright (C) 2006 The Android Open Source Project
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import android.content.Context;
20 | import android.view.View;
21 | import android.view.ViewGroup;
22 | import android.widget.BaseAdapter;
23 | import android.widget.Checkable;
24 | import android.widget.Filter;
25 | import android.widget.Filterable;
26 | import android.widget.ImageView;
27 | import android.widget.TextView;
28 | import android.view.LayoutInflater;
29 | import android.net.Uri;
30 |
31 | import java.util.ArrayList;
32 | import java.util.List;
33 | import java.util.Map;
34 |
35 | /**
36 | * An easy adapter to map static data to views defined in an XML file. You can specify the data
37 | * backing the list as an ArrayList of Maps. Each entry in the ArrayList corresponds to one row
38 | * in the list. The Maps contain the data for each row. You also specify an XML file that
39 | * defines the views used to display the row, and a mapping from keys in the Map to specific
40 | * views.
41 | *
42 | * Binding data to views occurs in two phases. First, if a
43 | * {@link android.widget.SimpleAdapter.ViewBinder} is available,
44 | * {@link ViewBinder#setViewValue(android.view.View, Object, String)}
45 | * is invoked. If the returned value is true, binding has occurred.
46 | * If the returned value is false, the following views are then tried in order:
47 | *
48 | * - A view that implements Checkable (e.g. CheckBox). The expected bind value is a boolean.
49 | *
- TextView. The expected bind value is a string and {@link #setViewText(TextView, String)}
50 | * is invoked.
51 | *
- ImageView. The expected bind value is a resource id or a string and
52 | * {@link #setViewImage(ImageView, int)} or {@link #setViewImage(ImageView, String)} is invoked.
53 | *
54 | * If no appropriate binding can be found, an {@link IllegalStateException} is thrown.
55 | */
56 | public class NotesListAdapter extends BaseAdapter implements Filterable {
57 | private int[] mTo;
58 | private String[] mFrom;
59 | private ViewBinder mViewBinder;
60 |
61 | private List extends Map
> mData;
62 |
63 | private int mResource;
64 | private int mDropDownResource;
65 | private LayoutInflater mInflater;
66 |
67 | private SimpleFilter mFilter;
68 | private ArrayList