• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Simple Notepad Application for Android OS


Commit MetaInfo

Revisión91d9ea4f4f7c493fff5661f38b8fa551c3f82358 (tree)
Tiempo2016-05-03 16:44:28
AutorMasahiko, SAWAI <say@user...>
CommiterMasahiko, SAWAI

Log Message

Added copy to clipboard function

Cambiar Resumen

Diferencia incremental

--- a/notepad-app-level-11/AndroidManifest.xml
+++ b/notepad-app-level-11/AndroidManifest.xml
@@ -6,7 +6,7 @@
66 android:versionName="1.0.8"
77 android:installLocation="auto"
88 >
9- <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="11" />
9+ <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="23" />
1010
1111 <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
1212 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
--- a/notepad-app-level-11/pom.xml
+++ b/notepad-app-level-11/pom.xml
@@ -20,9 +20,9 @@
2020 <dependencies>
2121
2222 <dependency>
23- <groupId>android</groupId>
23+ <groupId>com.google.android</groupId>
2424 <artifactId>android</artifactId>
25- <version>3.0_r2</version>
25+ <version>4.1.1.4</version>
2626 <!--
2727 <version>1.5_r3</version>
2828 <version>1.5_r4</version>
@@ -60,7 +60,7 @@
6060 <sdk>
6161 <path>${env.ANDROID_HOME}</path>
6262 <!-- <path>C:/Java/android-sdk</path> -->
63- <platform>11</platform>
63+ <platform>23</platform>
6464 </sdk>
6565 <release>false</release>
6666 <proguard>
--- a/notepad-app-level-11/res/menu/note_list_context_menu.xml
+++ b/notepad-app-level-11/res/menu/note_list_context_menu.xml
@@ -21,4 +21,16 @@
2121 android:numericShortcut="3"
2222 android:alphabeticShortcut="s"
2323 />
24+ <item
25+ android:id="@+id/copy_note_title_menuitem"
26+ android:title="@string/copy_note_title"
27+ android:numericShortcut="4"
28+ android:alphabeticShortcut="t"
29+ />
30+ <item
31+ android:id="@+id/copy_note_content_menuitem"
32+ android:title="@string/copy_note_content"
33+ android:numericShortcut="5"
34+ android:alphabeticShortcut="c"
35+ />
2436 </menu>
\ No newline at end of file
--- a/notepad-app-level-11/res/menu/note_title_context_menu.xml
+++ b/notepad-app-level-11/res/menu/note_title_context_menu.xml
@@ -4,7 +4,7 @@
44 android:id="@+id/copy_note_title_menuitem"
55 android:title="@string/copy_note_title"
66 android:numericShortcut="1"
7- android:alphabeticShortcut="c"
7+ android:alphabeticShortcut="t"
88 />
99 <item
1010 android:id="@+id/edit_note_menuitem"
--- a/notepad-app-level-11/res/values-ja/strings.xml
+++ b/notepad-app-level-11/res/values-ja/strings.xml
@@ -60,6 +60,8 @@
6060
6161 <string name="copy_note_title">タイトルをコピー</string>
6262 <string name="copy_note_content">本文をコピー</string>
63+ <string name="copy_note_title_done">タイトルをコピーしました。</string>
64+ <string name="copy_note_content_done">本文をコピーしました。</string>
6365
6466 <string name="templates">テンプレート</string>
6567 <string name="add_new_note_template">追加</string>
--- a/notepad-app-level-11/res/values/strings.xml
+++ b/notepad-app-level-11/res/values/strings.xml
@@ -60,6 +60,8 @@
6060
6161 <string name="copy_note_title">Copy Title</string>
6262 <string name="copy_note_content">Copy Text</string>
63+ <string name="copy_note_title_done">The title has copied.</string>
64+ <string name="copy_note_content_done">The text has copied.</string>
6365
6466 <string name="templates">Templates</string>
6567 <string name="add_new_note_template">Add</string>
--- a/notepad-app-level-11/src/org/routine_work/notepad/fragment/NoteListFragment.java
+++ b/notepad-app-level-11/src/org/routine_work/notepad/fragment/NoteListFragment.java
@@ -45,6 +45,7 @@ import android.view.ViewGroup;
4545 import android.widget.AbsListView;
4646 import android.widget.AdapterView.AdapterContextMenuInfo;
4747 import android.widget.ListView;
48+import android.widget.Toast;
4849 import java.util.Arrays;
4950 import org.routine_work.notepad.R;
5051 import org.routine_work.notepad.prefs.NotepadPreferenceUtils;
@@ -54,37 +55,32 @@ import org.routine_work.notepad.utils.NotepadConstants;
5455 import org.routine_work.utils.Log;
5556
5657 public class NoteListFragment extends ListFragment
57- implements NotepadConstants,
58- LoaderManager.LoaderCallbacks<Cursor>,
59- AbsListView.MultiChoiceModeListener
60-{
58+ implements NotepadConstants,
59+ LoaderManager.LoaderCallbacks<Cursor>,
60+ AbsListView.MultiChoiceModeListener {
6161
6262 private static final String LOG_TAG = "simple-notepad";
6363 private NoteCursorAdapter listAdapter;
6464 private Uri contentUri;
6565 private NoteControlCallback noteControlCallback;
6666
67- public NoteListFragment()
68- {
67+ public NoteListFragment() {
6968 this.contentUri = NoteStore.Note.CONTENT_URI;
7069 }
7170
7271 @Override
73- public void onAttach(Activity activity)
74- {
72+ public void onAttach(Activity activity) {
7573 Log.v(LOG_TAG, "Hello");
7674 super.onAttach(activity);
7775
78- if (activity instanceof NoteControlCallback)
79- {
76+ if (activity instanceof NoteControlCallback) {
8077 noteControlCallback = (NoteControlCallback) activity;
8178 }
8279 Log.v(LOG_TAG, "Bye");
8380 }
8481
8582 @Override
86- public void onCreate(Bundle savedInstanceState)
87- {
83+ public void onCreate(Bundle savedInstanceState) {
8884 Log.v(LOG_TAG, "Hello");
8985
9086 super.onCreate(savedInstanceState);
@@ -95,8 +91,7 @@ public class NoteListFragment extends ListFragment
9591
9692 @Override
9793 public View onCreateView(LayoutInflater inflater, ViewGroup container,
98- Bundle savedInstanceState)
99- {
94+ Bundle savedInstanceState) {
10095 Log.v(LOG_TAG, "Hello");
10196
10297 View v = inflater.inflate(R.layout.note_list_fragment, container, false);
@@ -106,8 +101,7 @@ public class NoteListFragment extends ListFragment
106101 }
107102
108103 @Override
109- public void onActivityCreated(Bundle savedInstanceState)
110- {
104+ public void onActivityCreated(Bundle savedInstanceState) {
111105 Log.v(LOG_TAG, "Hello");
112106 super.onActivityCreated(savedInstanceState);
113107
@@ -127,8 +121,7 @@ public class NoteListFragment extends ListFragment
127121 }
128122
129123 @Override
130- public void onDestroy()
131- {
124+ public void onDestroy() {
132125 Log.v(LOG_TAG, "Hello");
133126
134127 super.onDestroy();
@@ -138,13 +131,11 @@ public class NoteListFragment extends ListFragment
138131
139132 @Override
140133 public void onCreateContextMenu(ContextMenu menu, View v,
141- ContextMenuInfo menuInfo)
142- {
134+ ContextMenuInfo menuInfo) {
143135 Log.v(LOG_TAG, "Hello");
144136
145137 super.onCreateContextMenu(menu, v, menuInfo);
146- if (v == getListView())
147- {
138+ if (v == getListView()) {
148139 MenuInflater menuInflater = getActivity().getMenuInflater();
149140 menuInflater.inflate(R.menu.note_list_context_menu, menu);
150141 }
@@ -153,16 +144,13 @@ public class NoteListFragment extends ListFragment
153144 }
154145
155146 @Override
156- public boolean onContextItemSelected(MenuItem item)
157- {
147+ public boolean onContextItemSelected(MenuItem item) {
158148 boolean result = false;
159149 Log.v(LOG_TAG, "Hello");
160150
161151 AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
162- if (menuInfo != null)
163- {
164- switch (item.getItemId())
165- {
152+ if (menuInfo != null) {
153+ switch (item.getItemId()) {
166154 case R.id.delete_note_menuitem:
167155 deleteNote(menuInfo.id);
168156 result = true;
@@ -173,12 +161,18 @@ public class NoteListFragment extends ListFragment
173161 case R.id.share_note_menuitem:
174162 NoteUtils.shareNote(getActivity(), menuInfo.id);
175163 break;
164+ case R.id.copy_note_title_menuitem:
165+ NoteUtils.copyNoteTitleToClipboard(getActivity(), menuInfo.id);
166+ Toast.makeText(getActivity(), R.string.copy_note_title_done, Toast.LENGTH_SHORT).show();
167+ break;
168+ case R.id.copy_note_content_menuitem:
169+ NoteUtils.copyNoteContentToClipboard(getActivity(), menuInfo.id);
170+ Toast.makeText(getActivity(), R.string.copy_note_content_done, Toast.LENGTH_SHORT).show();
171+ break;
176172 default:
177173 result = super.onContextItemSelected(item);
178174 }
179- }
180- else
181- {
175+ } else {
182176 result = super.onContextItemSelected(item);
183177 }
184178
@@ -187,8 +181,7 @@ public class NoteListFragment extends ListFragment
187181 }
188182
189183 @Override
190- public void onListItemClick(ListView l, View v, int position, long id)
191- {
184+ public void onListItemClick(ListView l, View v, int position, long id) {
192185 Log.v(LOG_TAG, "Hello");
193186
194187 super.onListItemClick(l, v, position, id);
@@ -199,35 +192,32 @@ public class NoteListFragment extends ListFragment
199192 }
200193
201194 // BEGIN ---------- LoaderManager.LoaderCallbacks<Cursor> ----------
202- public Loader<Cursor> onCreateLoader(int id, Bundle bundle)
203- {
195+ public Loader<Cursor> onCreateLoader(int id, Bundle bundle) {
204196 Log.v(LOG_TAG, "Hello");
205197 Log.d(LOG_TAG, "this.contentUri => " + this.contentUri);
206198
207199 String where = NoteStore.Note.Columns.ENABLED + " = ?";
208- String[] whereArgs =
209- {
210- "1"
211- };
200+ String[] whereArgs
201+ = {
202+ "1"
203+ };
212204 String sortOrder = NotepadPreferenceUtils.getNoteListSortOrder(getActivity());
213205 Log.d(LOG_TAG, String.format("where => %s, whereArgs => %s, sortOrder => %s", where, Arrays.toString(whereArgs), sortOrder));
214206 CursorLoader cursorLoader = new CursorLoader(getActivity(),
215- contentUri, null, where, whereArgs, sortOrder);
207+ contentUri, null, where, whereArgs, sortOrder);
216208
217209 Log.v(LOG_TAG, "Bye");
218210 return cursorLoader;
219211 }
220212
221- public void onLoadFinished(Loader<Cursor> loader, Cursor cursor)
222- {
213+ public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
223214 Log.v(LOG_TAG, "Hello");
224215 Log.d(LOG_TAG, "cursor => " + cursor);
225216 listAdapter.swapCursor(cursor);
226217 Log.v(LOG_TAG, "Bye");
227218 }
228219
229- public void onLoaderReset(Loader<Cursor> loader)
230- {
220+ public void onLoaderReset(Loader<Cursor> loader) {
231221 Log.v(LOG_TAG, "Hello");
232222 listAdapter.swapCursor(null);
233223 Log.v(LOG_TAG, "Bye");
@@ -235,14 +225,12 @@ public class NoteListFragment extends ListFragment
235225 // END ---------- LoaderManager.LoaderCallbacks<Cursor> ----------
236226
237227 // BEGIN ---------- AbsListView.MultiChoiceModeListener
238- public void onItemCheckedStateChanged(ActionMode actionMode, int position, long id, boolean checked)
239- {
228+ public void onItemCheckedStateChanged(ActionMode actionMode, int position, long id, boolean checked) {
240229 Log.v(LOG_TAG, "Hello");
241230 Log.v(LOG_TAG, "Bye");
242231 }
243232
244- public boolean onCreateActionMode(ActionMode actionMode, Menu menu)
245- {
233+ public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
246234 Log.v(LOG_TAG, "Hello");
247235
248236 MenuInflater menuInflater = getActivity().getMenuInflater();
@@ -253,8 +241,7 @@ public class NoteListFragment extends ListFragment
253241 return true;
254242 }
255243
256- public boolean onPrepareActionMode(ActionMode actionMode, Menu menu)
257- {
244+ public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
258245 boolean result = false;
259246 Log.v(LOG_TAG, "Hello");
260247 listAdapter.setCheckable(true);
@@ -262,13 +249,11 @@ public class NoteListFragment extends ListFragment
262249 return result;
263250 }
264251
265- public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem)
266- {
252+ public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
267253 boolean result = true;
268254 Log.v(LOG_TAG, "Hello");
269255
270- switch (menuItem.getItemId())
271- {
256+ switch (menuItem.getItemId()) {
272257 case R.id.delete_note_menuitem:
273258 deleteCheckedNotes();
274259 actionMode.finish();
@@ -282,16 +267,14 @@ public class NoteListFragment extends ListFragment
282267 return result;
283268 }
284269
285- public void onDestroyActionMode(ActionMode actionMode)
286- {
270+ public void onDestroyActionMode(ActionMode actionMode) {
287271 Log.v(LOG_TAG, "Hello");
288272 listAdapter.setCheckable(false);
289273 Log.v(LOG_TAG, "Bye");
290274 }
291275 // END ---------- AbsListView.MultiChoiceModeListener
292276
293- public void setContentUri(Uri contentUri)
294- {
277+ public void setContentUri(Uri contentUri) {
295278 Log.v(LOG_TAG, "Hello");
296279 Log.d(LOG_TAG, "contentUri => " + contentUri);
297280
@@ -301,8 +284,7 @@ public class NoteListFragment extends ListFragment
301284 Log.v(LOG_TAG, "Bye");
302285 }
303286
304- public void reload()
305- {
287+ public void reload() {
306288 Log.v(LOG_TAG, "Hello");
307289
308290 getLoaderManager().restartLoader(NOTE_LOADER_ID, null, this);
@@ -310,25 +292,21 @@ public class NoteListFragment extends ListFragment
310292 Log.v(LOG_TAG, "Bye");
311293 }
312294
313- private void deleteNote(long id)
314- {
295+ private void deleteNote(long id) {
315296 Log.v(LOG_TAG, "Hello");
316297
317298 Uri noteUri = ContentUris.withAppendedId(NoteStore.Note.CONTENT_URI, id);
318- if (noteControlCallback != null)
319- {
299+ if (noteControlCallback != null) {
320300 noteControlCallback.startDeleteNote(noteUri);
321301 }
322302
323303 Log.v(LOG_TAG, "Bye");
324304 }
325305
326- private void showNoteDetail(long id)
327- {
306+ private void showNoteDetail(long id) {
328307 Log.v(LOG_TAG, "Hello");
329308
330- if (noteControlCallback != null)
331- {
309+ if (noteControlCallback != null) {
332310 Uri noteUri = ContentUris.withAppendedId(NoteStore.Note.CONTENT_URI, id);
333311 noteControlCallback.startViewNote(noteUri);
334312 }
@@ -336,28 +314,24 @@ public class NoteListFragment extends ListFragment
336314 Log.v(LOG_TAG, "Bye");
337315 }
338316
339- private void editNote(long id)
340- {
317+ private void editNote(long id) {
341318 Log.v(LOG_TAG, "Hello");
342319
343320 Uri noteUri = ContentUris.withAppendedId(NoteStore.Note.CONTENT_URI, id);
344- if (noteControlCallback != null)
345- {
321+ if (noteControlCallback != null) {
346322 noteControlCallback.startEditNote(noteUri);
347323 }
348324
349325 Log.v(LOG_TAG, "Bye");
350326 }
351327
352- private void deleteCheckedNotes()
353- {
328+ private void deleteCheckedNotes() {
354329 Log.v(LOG_TAG, "Hello");
355330
356331 ContentResolver cr = getActivity().getContentResolver();
357332 ListView listView = getListView();
358333 long[] checkItemIds = listView.getCheckItemIds();
359- for (int i = checkItemIds.length - 1; i >= 0; i--)
360- {
334+ for (int i = checkItemIds.length - 1; i >= 0; i--) {
361335 long id = checkItemIds[i];
362336 Log.d(LOG_TAG, "delete note. i => " + i + ", id => " + id);
363337 Uri noteUri = ContentUris.withAppendedId(NoteStore.Note.CONTENT_URI, id);
--- a/notepad-app/pom.xml
+++ b/notepad-app/pom.xml
@@ -61,7 +61,7 @@
6161 <sdk>
6262 <path>${env.ANDROID_HOME}</path>
6363 <!-- <path>C:/Java/android-sdk</path> -->
64- <platform>10</platform>
64+ <platform>23</platform>
6565 </sdk>
6666 <release>false</release>
6767 <proguard>
--- a/notepad-app/res/menu/note_list_context_menu.xml
+++ b/notepad-app/res/menu/note_list_context_menu.xml
@@ -28,4 +28,16 @@
2828 android:numericShortcut="4"
2929 android:alphabeticShortcut="s"
3030 />
31+ <item
32+ android:id="@+id/copy_note_title_menuitem"
33+ android:title="@string/copy_note_title"
34+ android:numericShortcut="5"
35+ android:alphabeticShortcut="t"
36+ />
37+ <item
38+ android:id="@+id/copy_note_content_menuitem"
39+ android:title="@string/copy_note_content"
40+ android:numericShortcut="5"
41+ android:alphabeticShortcut="c"
42+ />
3143 </menu>
\ No newline at end of file
--- a/notepad-app/res/menu/note_title_context_menu.xml
+++ b/notepad-app/res/menu/note_title_context_menu.xml
@@ -4,7 +4,7 @@
44 android:id="@+id/copy_note_title_menuitem"
55 android:title="@string/copy_note_title"
66 android:numericShortcut="1"
7- android:alphabeticShortcut="c"
7+ android:alphabeticShortcut="t"
88 />
99 <item
1010 android:id="@+id/edit_note_menuitem"
--- a/notepad-app/res/values-ja/strings.xml
+++ b/notepad-app/res/values-ja/strings.xml
@@ -65,6 +65,8 @@
6565
6666 <string name="copy_note_title">タイトルをコピー</string>
6767 <string name="copy_note_content">本文をコピー</string>
68+ <string name="copy_note_title_done">タイトルをコピーしました。</string>
69+ <string name="copy_note_content_done">本文をコピーしました。</string>
6870
6971 <string name="templates">テンプレート</string>
7072 <string name="add_new_note_template">追加</string>
--- a/notepad-app/res/values/strings.xml
+++ b/notepad-app/res/values/strings.xml
@@ -65,6 +65,8 @@
6565
6666 <string name="copy_note_title">Copy Title</string>
6767 <string name="copy_note_content">Copy Text</string>
68+ <string name="copy_note_title_done">The title has copied.</string>
69+ <string name="copy_note_content_done">The text has copied.</string>
6870
6971 <string name="templates">Templates</string>
7072 <string name="add_new_note_template">Add</string>
--- a/notepad-app/src/org/routine_work/notepad/NotepadActivity.java
+++ b/notepad-app/src/org/routine_work/notepad/NotepadActivity.java
@@ -62,11 +62,10 @@ import org.routine_work.utils.Log;
6262 * @author Masahiko, SAWAI <masahiko.sawai@gmail.com>
6363 */
6464 public class NotepadActivity extends ListActivity
65- implements View.OnClickListener, OnItemClickListener,
66- TextView.OnEditorActionListener, OnFocusChangeListener,
67- SharedPreferences.OnSharedPreferenceChangeListener,
68- NotepadConstants
69-{
65+ implements View.OnClickListener, OnItemClickListener,
66+ TextView.OnEditorActionListener, OnFocusChangeListener,
67+ SharedPreferences.OnSharedPreferenceChangeListener,
68+ NotepadConstants {
7069
7170 private static final String LOG_TAG = "simple-notepad";
7271 private static final String ACTION_QUIT = NotepadConstants.class.getPackage().getName() + ".QUIT";
@@ -74,31 +73,24 @@ public class NotepadActivity extends ListActivity
7473 private static final int ACTION_MODE_NORMAL = 0;
7574 private static final int ACTION_MODE_SEARCH = 1;
7675 private static final int DIALOG_ID_NOTE_TEMPLATE_PICKER = 0;
77- private static final int[][][] ACTION_ITEM_VISIBILITY =
78- {
79- { // ACTION_MODE_NORMAL
80- { // GONE
81- R.id.search_edittext,
82- R.id.cancel_search_button,
83- },
84- { // VISIBLE
85- R.id.title_textview,
86- R.id.add_new_note_button,
87- R.id.search_button,
88- },
89- },
90- { // ACTION_MODE_SEARCH
91- { // GONE
92- R.id.title_textview,
93- R.id.add_new_note_button,
94- R.id.search_button,
95- },
96- { // VISIBLE
97- R.id.search_edittext,
98- R.id.cancel_search_button,
99- },
100- },
101- };
76+ private static final int[][][] ACTION_ITEM_VISIBILITY
77+ = {
78+ { // ACTION_MODE_NORMAL
79+ { // GONE
80+ R.id.search_edittext,
81+ R.id.cancel_search_button,},
82+ { // VISIBLE
83+ R.id.title_textview,
84+ R.id.add_new_note_button,
85+ R.id.search_button,},},
86+ { // ACTION_MODE_SEARCH
87+ { // GONE
88+ R.id.title_textview,
89+ R.id.add_new_note_button,
90+ R.id.search_button,},
91+ { // VISIBLE
92+ R.id.search_edittext,
93+ R.id.cancel_search_button,},},};
10294 // instances
10395 private int actionMode = -1;
10496 private NoteCursorAdapter listAdapter;
@@ -106,22 +98,19 @@ public class NotepadActivity extends ListActivity
10698 private EditText searchEditText;
10799 private NoteTemplatePickerDialog noteTemplatePickerDialog;
108100
109- static
110- {
101+ static {
111102 Log.setOutputLevel(Log.VERBOSE);
112103 Log.setTraceMode(true);
113104 Log.setIndentMode(true);
114105 }
115106
116- public static void goHomeActivity(Context context)
117- {
107+ public static void goHomeActivity(Context context) {
118108 Intent homeIntent = new Intent(Intent.ACTION_VIEW, NoteStore.Note.CONTENT_URI);
119109 homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
120110 context.startActivity(homeIntent);
121111 }
122112
123- public static void quitApplication(Context context)
124- {
113+ public static void quitApplication(Context context) {
125114 Intent quitIntent = new Intent(context, NotepadActivity.class);
126115 quitIntent.setAction(ACTION_QUIT);
127116 quitIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
@@ -129,8 +118,7 @@ public class NotepadActivity extends ListActivity
129118 }
130119
131120 @Override
132- protected void onCreate(Bundle savedInstanceState)
133- {
121+ protected void onCreate(Bundle savedInstanceState) {
134122 Log.v(LOG_TAG, "Hello");
135123
136124 setTheme(NotepadPreferenceUtils.getTheme(this));
@@ -155,17 +143,13 @@ public class NotepadActivity extends ListActivity
155143 listView.setOnItemClickListener(this);
156144 registerForContextMenu(listView);
157145
158- if (savedInstanceState == null)
159- {
146+ if (savedInstanceState == null) {
160147 initializeWithIntent(getIntent());
161- }
162- else
163- {
148+ } else {
164149 initializeWithSavedInstance(savedInstanceState);
165150 }
166151
167- if (isFinishing() == false)
168- {
152+ if (isFinishing() == false) {
169153 ImageButton homeImageButton = (ImageButton) findViewById(R.id.home_button);
170154 homeImageButton.setOnClickListener(this);
171155 ImageButton addImageButton = (ImageButton) findViewById(R.id.add_new_note_button);
@@ -183,8 +167,7 @@ public class NotepadActivity extends ListActivity
183167 }
184168
185169 @Override
186- protected void onNewIntent(Intent intent)
187- {
170+ protected void onNewIntent(Intent intent) {
188171 Log.v(LOG_TAG, "Hello");
189172
190173 super.onNewIntent(intent);
@@ -194,35 +177,30 @@ public class NotepadActivity extends ListActivity
194177 }
195178
196179 @Override
197- protected void onResume()
198- {
180+ protected void onResume() {
199181 Log.v(LOG_TAG, "Hello");
200182 super.onResume();
201183 Log.v(LOG_TAG, "Bye");
202184 }
203185
204186 @Override
205- protected void onPause()
206- {
187+ protected void onPause() {
207188 Log.v(LOG_TAG, "Hello");
208189 super.onPause();
209190 Log.v(LOG_TAG, "Bye");
210191 }
211192
212193 @Override
213- protected void onDestroy()
214- {
194+ protected void onDestroy() {
215195 Log.v(LOG_TAG, "Hello");
216196
217- if (cursor != null)
218- {
197+ if (cursor != null) {
219198 cursor.close();
220199 cursor = null;
221200 }
222201
223202 int quitCount = NotepadPreferenceUtils.incrementQuitCount(this);
224- if (quitCount % 64 == 0)
225- {
203+ if (quitCount % 64 == 0) {
226204 Intent noteDBOptimizerIntent = new Intent(this, NoteDBOptimizer.class);
227205 startService(noteDBOptimizerIntent);
228206 }
@@ -233,8 +211,7 @@ public class NotepadActivity extends ListActivity
233211 }
234212
235213 @Override
236- protected void onSaveInstanceState(Bundle outState)
237- {
214+ protected void onSaveInstanceState(Bundle outState) {
238215 Log.v(LOG_TAG, "Hello");
239216
240217 super.onSaveInstanceState(outState);
@@ -287,8 +264,7 @@ public class NotepadActivity extends ListActivity
287264 }
288265 */
289266 @Override
290- public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
291- {
267+ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
292268 Log.v(LOG_TAG, "Hello");
293269 super.onCreateContextMenu(menu, v, menuInfo);
294270
@@ -299,39 +275,45 @@ public class NotepadActivity extends ListActivity
299275 }
300276
301277 @Override
302- public boolean onContextItemSelected(MenuItem item)
303- {
278+ public boolean onContextItemSelected(MenuItem item) {
304279 boolean result = true;
280+ Log.v(LOG_TAG, "Hello");
281+ Log.v(LOG_TAG, "Bye");
305282
306283 AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
307- Log.v(LOG_TAG, "list item position => " + menuInfo.position);
308- Log.v(LOG_TAG, "list item id => " + menuInfo.id);
309- Log.v(LOG_TAG, "list item targetView => " + menuInfo.targetView);
310-
311- int itemId = item.getItemId();
312- switch (itemId)
313- {
314- case R.id.view_note_menuitem:
315- startViewNoteActivityById(menuInfo.id);
316- break;
317- case R.id.edit_note_menuitem:
318- startEditNoteActivityById(menuInfo.id);
319- break;
320- case R.id.delete_note_menuitem:
321- startDeleteNoteActivityById(menuInfo.id);
322- break;
323- case R.id.share_note_menuitem:
324- NoteUtils.shareNote(this, menuInfo.id);
325- break;
326- default:
327- result = super.onContextItemSelected(item);
284+ if (menuInfo != null) {
285+ switch (item.getItemId()) {
286+ case R.id.view_note_menuitem:
287+ startViewNoteActivityById(menuInfo.id);
288+ break;
289+ case R.id.edit_note_menuitem:
290+ startEditNoteActivityById(menuInfo.id);
291+ break;
292+ case R.id.delete_note_menuitem:
293+ startDeleteNoteActivityById(menuInfo.id);
294+ break;
295+ case R.id.share_note_menuitem:
296+ NoteUtils.shareNote(this, menuInfo.id);
297+ break;
298+ case R.id.copy_note_title_menuitem:
299+ NoteUtils.copyNoteTitleToClipboard(this, menuInfo.id);
300+ Toast.makeText(this, R.string.copy_note_title_done, Toast.LENGTH_SHORT).show();
301+ break;
302+ case R.id.copy_note_content_menuitem:
303+ NoteUtils.copyNoteContentToClipboard(this, menuInfo.id);
304+ Toast.makeText(this, R.string.copy_note_content_done, Toast.LENGTH_SHORT).show();
305+ break;
306+ default:
307+ result = super.onContextItemSelected(item);
308+ }
309+ } else {
310+ result = super.onContextItemSelected(item);
328311 }
329312
330313 return result;
331314 }
332315
333- public void onItemClick(AdapterView<?> parentView, View view, int position, long id)
334- {
316+ public void onItemClick(AdapterView<?> parentView, View view, int position, long id) {
335317 Log.v(LOG_TAG, "Hello");
336318
337319 Log.d(LOG_TAG, "clicked item position => " + position);
@@ -343,8 +325,7 @@ public class NotepadActivity extends ListActivity
343325 }
344326
345327 @Override
346- public boolean onCreateOptionsMenu(Menu menu)
347- {
328+ public boolean onCreateOptionsMenu(Menu menu) {
348329 Log.v(LOG_TAG, "Hello");
349330
350331 MenuInflater menuInflater = getMenuInflater();
@@ -360,14 +341,12 @@ public class NotepadActivity extends ListActivity
360341 }
361342
362343 @Override
363- public boolean onOptionsItemSelected(MenuItem item)
364- {
344+ public boolean onOptionsItemSelected(MenuItem item) {
365345 boolean result = true;
366346 Log.v(LOG_TAG, "Hello");
367347
368348 int itemId = item.getItemId();
369- switch (itemId)
370- {
349+ switch (itemId) {
371350 case R.id.add_new_note_menuitem:
372351 Log.d(LOG_TAG, "add_new_note_menuitem is selected.");
373352 addNewNote();
@@ -400,13 +379,11 @@ public class NotepadActivity extends ListActivity
400379 return result;
401380 }
402381
403- public void onClick(View view)
404- {
382+ public void onClick(View view) {
405383 Log.v(LOG_TAG, "Hello");
406384
407385 int viewId = view.getId();
408- switch (viewId)
409- {
386+ switch (viewId) {
410387 case R.id.home_button:
411388 Log.d(LOG_TAG, "home_button is clicked.");
412389 cancelSearchMode();
@@ -429,19 +406,15 @@ public class NotepadActivity extends ListActivity
429406 }
430407
431408 @Override
432- public boolean onKeyDown(int keyCode, KeyEvent event)
433- {
409+ public boolean onKeyDown(int keyCode, KeyEvent event) {
434410 boolean result;
435411 Log.v(LOG_TAG, "Hello");
436412
437413 if ((keyCode == KeyEvent.KEYCODE_BACK)
438- && (actionMode != ACTION_MODE_NORMAL))
439- {
414+ && (actionMode != ACTION_MODE_NORMAL)) {
440415 cancelSearchMode();
441416 result = true;
442- }
443- else
444- {
417+ } else {
445418 result = super.onKeyDown(keyCode, event);
446419 }
447420
@@ -450,13 +423,11 @@ public class NotepadActivity extends ListActivity
450423 }
451424
452425 @Override
453- protected Dialog onCreateDialog(int id)
454- {
426+ protected Dialog onCreateDialog(int id) {
455427 Dialog dialog = null;
456428 Log.v(LOG_TAG, "Hello");
457429
458- switch (id)
459- {
430+ switch (id) {
460431 case DIALOG_ID_NOTE_TEMPLATE_PICKER:
461432 dialog = getNoteTemplatePickerDialog();
462433 break;
@@ -468,28 +439,21 @@ public class NotepadActivity extends ListActivity
468439 }
469440
470441 // TextView.OnEditorActionListener
471- public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
472- {
473- if (actionId == EditorInfo.IME_ACTION_SEARCH)
474- {
442+ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
443+ if (actionId == EditorInfo.IME_ACTION_SEARCH) {
475444 IMEUtils.hideSoftKeyboardWindow(this, v);
476445 }
477446 return true;
478447 }
479448
480- public void onFocusChange(View v, boolean hasFocus)
481- {
449+ public void onFocusChange(View v, boolean hasFocus) {
482450 Log.v(LOG_TAG, "Hello");
483451
484- if (v.getId() == R.id.search_edittext)
485- {
486- if (hasFocus)
487- {
452+ if (v.getId() == R.id.search_edittext) {
453+ if (hasFocus) {
488454 Log.d(LOG_TAG, "search_edittext has focus.");
489455 IMEUtils.showSoftKeyboardWindow(this, v);
490- }
491- else
492- {
456+ } else {
493457 Log.d(LOG_TAG, "search_edittext has focus.");
494458 IMEUtils.hideSoftKeyboardWindow(this, v);
495459 }
@@ -498,14 +462,12 @@ public class NotepadActivity extends ListActivity
498462 Log.v(LOG_TAG, "Bye");
499463 }
500464
501- public void onSharedPreferenceChanged(SharedPreferences prefs, String key)
502- {
465+ public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
503466 Log.v(LOG_TAG, "Hello");
504467 Log.d(LOG_TAG, "shared preference " + key + " is changed.");
505468
506469 String noteListSortOrderKey = getString(R.string.note_list_sort_order_key);
507- if (noteListSortOrderKey.equals(key))
508- {
470+ if (noteListSortOrderKey.equals(key)) {
509471 Log.d(LOG_TAG, "sort order is changed, update note list with new sort order.");
510472 String queryString = searchEditText.getText().toString();
511473 updateContentWithQuery(queryString);
@@ -514,8 +476,7 @@ public class NotepadActivity extends ListActivity
514476 Log.v(LOG_TAG, "Bye");
515477 }
516478
517- private void initializeWithIntent(Intent intent)
518- {
479+ private void initializeWithIntent(Intent intent) {
519480 Log.v(LOG_TAG, "Hello");
520481
521482 Log.d(LOG_TAG, "------------------------------");
@@ -527,31 +488,23 @@ public class NotepadActivity extends ListActivity
527488
528489 String queryString = null;
529490 String action = intent.getAction();
530- if (ACTION_QUIT.equals(action))
531- {
491+ if (ACTION_QUIT.equals(action)) {
532492 finish();
533- }
534- else if (Intent.ACTION_SEARCH.equals(action))
535- {
493+ } else if (Intent.ACTION_SEARCH.equals(action)) {
536494 queryString = intent.getStringExtra(SearchManager.QUERY);
537- }
538- else if (Intent.ACTION_VIEW.equals(action))
539- {
495+ } else if (Intent.ACTION_VIEW.equals(action)) {
540496 int flags = intent.getFlags();
541497 Log.v(LOG_TAG, "flags => 0x" + Integer.toHexString(flags));
542498
543- if ((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0)
544- {
499+ if ((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
545500 Log.d(LOG_TAG, "flags includes FLAG_ACTIVITY_NEW_TASK");
546501
547502 boolean processed = false;
548503 Uri data = intent.getData();
549- if (data != null)
550- {
504+ if (data != null) {
551505 ContentResolver contentResolver = getContentResolver();
552506 String type = contentResolver.getType(data);
553- if (NoteStore.Note.NOTE_ITEM_CONTENT_TYPE.equals(type))
554- {
507+ if (NoteStore.Note.NOTE_ITEM_CONTENT_TYPE.equals(type)) {
555508 Log.d(LOG_TAG, "open note : data => " + data);
556509 String idString = data.getLastPathSegment();
557510 queryString = "id:" + idString;
@@ -559,27 +512,20 @@ public class NotepadActivity extends ListActivity
559512 }
560513 }
561514
562- if (!processed)
563- {
515+ if (!processed) {
564516 queryString = intent.getStringExtra(SearchManager.QUERY);
565517 }
566518 }
567519 }
568520
569- if (queryString != null)
570- {
521+ if (queryString != null) {
571522 enterSearchMode();
572- if (TextUtils.isEmpty(queryString.trim()))
573- {
523+ if (TextUtils.isEmpty(queryString.trim())) {
574524 searchEditText.setText(null);
575- }
576- else
577- {
525+ } else {
578526 searchEditText.setText(queryString);
579527 }
580- }
581- else
582- {
528+ } else {
583529 setActionMode(ACTION_MODE_NORMAL);
584530 searchEditText.setText(null);
585531 }
@@ -587,8 +533,7 @@ public class NotepadActivity extends ListActivity
587533 Log.v(LOG_TAG, "Bye");
588534 }
589535
590- private void initializeWithSavedInstance(Bundle savedInstanceState)
591- {
536+ private void initializeWithSavedInstance(Bundle savedInstanceState) {
592537 Log.v(LOG_TAG, "Hello");
593538
594539 int savedActionMode = savedInstanceState.getInt(SAVE_KEY_ACTION_MODE);
@@ -597,29 +542,22 @@ public class NotepadActivity extends ListActivity
597542 Log.v(LOG_TAG, "Bye");
598543 }
599544
600- private void addNewNote()
601- {
545+ private void addNewNote() {
602546 Log.v(LOG_TAG, "Hello");
603547
604548 int noteTemplateCount = NoteStore.getNoteTemplateCount(getContentResolver());
605- if (noteTemplateCount >= 2)
606- {
549+ if (noteTemplateCount >= 2) {
607550 showDialog(DIALOG_ID_NOTE_TEMPLATE_PICKER);
608- }
609- else if (noteTemplateCount == 1)
610- {
551+ } else if (noteTemplateCount == 1) {
611552 NoteUtils.startActivityToAddNewNoteWithFirstTemplate(this);
612- }
613- else if (noteTemplateCount == 0)
614- {
553+ } else if (noteTemplateCount == 0) {
615554 NoteUtils.startActivityToAddNewBlankNote(this);
616555 }
617556
618557 Log.v(LOG_TAG, "Bye");
619558 }
620559
621- private void startViewNoteActivityById(long id)
622- {
560+ private void startViewNoteActivityById(long id) {
623561 Log.v(LOG_TAG, "Hello");
624562
625563 Uri uri = ContentUris.withAppendedId(NoteStore.Note.CONTENT_URI, id);
@@ -629,8 +567,7 @@ public class NotepadActivity extends ListActivity
629567 Log.v(LOG_TAG, "Bye");
630568 }
631569
632- private void startEditNoteActivityById(long id)
633- {
570+ private void startEditNoteActivityById(long id) {
634571 Log.v(LOG_TAG, "Hello");
635572
636573 Uri uri = ContentUris.withAppendedId(NoteStore.Note.CONTENT_URI, id);
@@ -640,8 +577,7 @@ public class NotepadActivity extends ListActivity
640577 Log.v(LOG_TAG, "Bye");
641578 }
642579
643- private void startDeleteNoteActivityById(long id)
644- {
580+ private void startDeleteNoteActivityById(long id) {
645581 Log.v(LOG_TAG, "Hello");
646582
647583 Uri uri = ContentUris.withAppendedId(NoteStore.Note.CONTENT_URI, id);
@@ -651,8 +587,7 @@ public class NotepadActivity extends ListActivity
651587 Log.v(LOG_TAG, "Bye");
652588 }
653589
654- private void startDeleteNotesActivity()
655- {
590+ private void startDeleteNotesActivity() {
656591 Log.v(LOG_TAG, "Hello");
657592
658593 Intent intent = new Intent(this, DeleteNotesActivity.class);
@@ -661,8 +596,7 @@ public class NotepadActivity extends ListActivity
661596 Log.v(LOG_TAG, "Bye");
662597 }
663598
664- private void startPreferencesActivity()
665- {
599+ private void startPreferencesActivity() {
666600 Log.v(LOG_TAG, "Hello");
667601
668602 Intent intent = new Intent(this, NotepadPreferenceActivity.class);
@@ -671,8 +605,7 @@ public class NotepadActivity extends ListActivity
671605 Log.v(LOG_TAG, "Bye");
672606 }
673607
674- private void startTemplateListActivity()
675- {
608+ private void startTemplateListActivity() {
676609 Log.v(LOG_TAG, "Hello");
677610
678611 Intent intent = new Intent(Intent.ACTION_VIEW, NoteStore.NoteTemplate.CONTENT_URI);
@@ -681,29 +614,23 @@ public class NotepadActivity extends ListActivity
681614 Log.v(LOG_TAG, "Bye");
682615 }
683616
684- private void setActionMode(int newActionMode)
685- {
617+ private void setActionMode(int newActionMode) {
686618 Log.v(LOG_TAG, "Hello");
687619
688- if (actionMode != newActionMode)
689- {
620+ if (actionMode != newActionMode) {
690621 actionMode = newActionMode;
691622 Log.d(LOG_TAG, "update actionMode => " + actionMode);
692623 int[] goneViewIds = ACTION_ITEM_VISIBILITY[actionMode][0];
693- for (int i = 0; i < goneViewIds.length; i++)
694- {
624+ for (int i = 0; i < goneViewIds.length; i++) {
695625 View view = findViewById(goneViewIds[i]);
696- if (view != null)
697- {
626+ if (view != null) {
698627 view.setVisibility(View.GONE);
699628 }
700629 }
701630 int[] visibleViewIds = ACTION_ITEM_VISIBILITY[actionMode][1];
702- for (int i = 0; i < visibleViewIds.length; i++)
703- {
631+ for (int i = 0; i < visibleViewIds.length; i++) {
704632 View view = findViewById(visibleViewIds[i]);
705- if (view != null)
706- {
633+ if (view != null) {
707634 view.setVisibility(View.VISIBLE);
708635 }
709636 }
@@ -713,40 +640,35 @@ public class NotepadActivity extends ListActivity
713640 Log.v(LOG_TAG, "Bye");
714641 }
715642
716- private void updateContentWithQuery(String queryString)
717- {
643+ private void updateContentWithQuery(String queryString) {
718644 Log.v(LOG_TAG, "Hello");
719645 Log.v(LOG_TAG, "queryString => " + queryString);
720646
721647 Uri contentUri = NoteSearchQueryParser.parseQuery(queryString);
722648 Log.v(LOG_TAG, "contentUri => " + contentUri);
723649
724- if (contentUri != null)
725- {
650+ if (contentUri != null) {
726651 updateContentWithUri(contentUri);
727652 }
728653
729654 Log.v(LOG_TAG, "Bye");
730655 }
731656
732- private void updateContentWithUri(Uri contentUri)
733- {
657+ private void updateContentWithUri(Uri contentUri) {
734658 Log.v(LOG_TAG, "Hello");
735659 Log.v(LOG_TAG, "contentUri => " + contentUri);
736660
737661 String where = NoteStore.Note.Columns.ENABLED + " = ?";
738- String[] whereArgs =
739- {
740- "1",
741- };
662+ String[] whereArgs
663+ = {
664+ "1",};
742665 String sortOrder = NotepadPreferenceUtils.getNoteListSortOrder(this);
743666 Log.d(LOG_TAG, String.format("where => %s, whereArgs => %s, sortOrder => %s", where, Arrays.toString(whereArgs), sortOrder));
744667 ContentResolver cr = getContentResolver();
745668 Cursor newCursor = cr.query(contentUri, null, where, whereArgs, sortOrder);
746669 listAdapter.changeCursor(newCursor);
747670
748- if (cursor != null)
749- {
671+ if (cursor != null) {
750672 cursor.close();
751673 }
752674 cursor = newCursor;
@@ -754,44 +676,35 @@ public class NotepadActivity extends ListActivity
754676 Log.v(LOG_TAG, "Bye");
755677 }
756678
757- private void cancelSearchMode()
758- {
759- if (actionMode != ACTION_MODE_NORMAL)
760- {
679+ private void cancelSearchMode() {
680+ if (actionMode != ACTION_MODE_NORMAL) {
761681 searchEditText.setText(null);
762682 getListView().requestFocus();
763683 setActionMode(ACTION_MODE_NORMAL);
764684 }
765685 }
766686
767- private void enterSearchMode()
768- {
769- if (actionMode != ACTION_MODE_SEARCH)
770- {
687+ private void enterSearchMode() {
688+ if (actionMode != ACTION_MODE_SEARCH) {
771689 setActionMode(ACTION_MODE_SEARCH);
772690 IMEUtils.requestKeyboardFocus(searchEditText);
773691 // searchEditText.requestFocus();
774692 }
775693 }
776694
777- private Dialog getNoteTemplatePickerDialog()
778- {
779- if (noteTemplatePickerDialog == null)
780- {
695+ private Dialog getNoteTemplatePickerDialog() {
696+ if (noteTemplatePickerDialog == null) {
781697 noteTemplatePickerDialog = new NoteTemplatePickerDialog(this);
782698 }
783699 return noteTemplatePickerDialog;
784700 }
785701
786- private void initializeNoteTemplateData()
787- {
788- if (NotepadPreferenceUtils.isTemplateDataInitialized(this) == false)
789- {
702+ private void initializeNoteTemplateData() {
703+ if (NotepadPreferenceUtils.isTemplateDataInitialized(this) == false) {
790704 NotepadPreferenceUtils.setTemplateDataInitialized(this, true);
791705 int noteTemplateCount = NoteStore.getNoteTemplateCount(getContentResolver());
792706 Log.d(LOG_TAG, "noteTemplateCount => " + noteTemplateCount);
793- if (noteTemplateCount == 0)
794- {
707+ if (noteTemplateCount == 0) {
795708 Log.d(LOG_TAG, "start NoteTemplateInitializer");
796709 Intent noteTeplateInitializerIntent = new Intent(this, NoteTemplateInitializer.class);
797710 startService(noteTeplateInitializerIntent);
@@ -799,17 +712,14 @@ public class NotepadActivity extends ListActivity
799712 }
800713 }
801714
802- class SearchEditTextWatcher implements TextWatcher
803- {
715+ class SearchEditTextWatcher implements TextWatcher {
804716
805- public void beforeTextChanged(CharSequence s, int start, int count, int after)
806- {
717+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
807718 Log.v(LOG_TAG, "Hello");
808719 Log.v(LOG_TAG, "Bye");
809720 }
810721
811- public void onTextChanged(CharSequence s, int start, int before, int count)
812- {
722+ public void onTextChanged(CharSequence s, int start, int before, int count) {
813723 Log.v(LOG_TAG, "Hello");
814724
815725 updateContentWithQuery(s.toString());
@@ -817,8 +727,7 @@ public class NotepadActivity extends ListActivity
817727 Log.v(LOG_TAG, "Bye");
818728 }
819729
820- public void afterTextChanged(Editable s)
821- {
730+ public void afterTextChanged(Editable s) {
822731 Log.v(LOG_TAG, "Hello");
823732 Log.v(LOG_TAG, "Bye");
824733 }
--- a/notepad-common/src/org/routine_work/notepad/utils/NoteUtils.java
+++ b/notepad-common/src/org/routine_work/notepad/utils/NoteUtils.java
@@ -11,11 +11,13 @@ import android.content.Context;
1111 import android.content.Intent;
1212 import android.database.Cursor;
1313 import android.net.Uri;
14+import android.text.ClipboardManager;
1415 import android.text.TextUtils;
1516 import android.text.format.DateFormat;
1617 import java.util.Date;
1718 import java.util.HashMap;
1819 import java.util.Map;
20+import org.routine_work.notepad.model.Note;
1921 import org.routine_work.notepad.provider.NoteStore;
2022 import org.routine_work.utils.Log;
2123
@@ -23,13 +25,11 @@ import org.routine_work.utils.Log;
2325 *
2426 * @author sawai
2527 */
26-public class NoteUtils implements NotepadConstants
27-{
28+public class NoteUtils implements NotepadConstants {
2829
2930 private static final String LOG_TAG = "simple-notepad";
3031
31- public static void shareNote(Context context, long noteId)
32- {
32+ public static void shareNote(Context context, long noteId) {
3333 Log.v(LOG_TAG, "Hello");
3434 Log.d(LOG_TAG, "noteId");
3535
@@ -39,40 +39,19 @@ public class NoteUtils implements NotepadConstants
3939 Log.v(LOG_TAG, "Bye");
4040 }
4141
42- public static void shareNote(Context context, Uri noteUri)
43- {
42+ public static void shareNote(Context context, Uri noteUri) {
4443 Log.v(LOG_TAG, "Hello");
4544 Log.d(LOG_TAG, "noteUri => " + noteUri);
4645
47- if (NoteStore.isNoteItemUri(context, noteUri))
48- {
49- ContentResolver contentResolver = context.getContentResolver();
50- Cursor cursor = contentResolver.query(noteUri, null, null, null, null);
51- if (cursor != null)
52- {
53- try
54- {
55- if (cursor.moveToFirst())
56- {
57- int titleIndex = cursor.getColumnIndex(NoteStore.Note.Columns.TITLE);
58- int contentIndex = cursor.getColumnIndex(NoteStore.Note.Columns.CONTENT);
59- String noteTitle = cursor.getString(titleIndex);
60- String noteContent = cursor.getString(contentIndex);
61- shareNote(context, noteTitle, noteContent);
62- }
63- }
64- finally
65- {
66- cursor.close();
67- }
68- }
46+ Note note = loadNoteData(context, noteUri);
47+ if (note != null) {
48+ shareNote(context, note.getTitle(), note.getContent());
6949 }
7050
7151 Log.v(LOG_TAG, "Bye");
7252 }
7353
74- public static void shareNote(Context context, String noteTitle, String noteContent)
75- {
54+ public static void shareNote(Context context, String noteTitle, String noteContent) {
7655 Log.v(LOG_TAG, "Hello");
7756 Log.d(LOG_TAG, "titile => " + noteTitle);
7857 Log.d(LOG_TAG, "content => " + noteContent);
@@ -87,6 +66,50 @@ public class NoteUtils implements NotepadConstants
8766 Log.v(LOG_TAG, "Bye");
8867 }
8968
69+ public static void copyNoteTitleToClipboard(Context context, long id) {
70+ Log.v(LOG_TAG, "Hello");
71+
72+ Uri noteUri = ContentUris.withAppendedId(NoteStore.Note.CONTENT_URI, id);
73+ copyNoteTitleToClipboard(context, noteUri);
74+
75+ Log.v(LOG_TAG, "Bye");
76+ }
77+
78+ public static void copyNoteTitleToClipboard(Context context, Uri noteUri) {
79+ Log.v(LOG_TAG, "Hello");
80+ Log.d(LOG_TAG, "noteUri => " + noteUri);
81+
82+ Note note = loadNoteData(context, noteUri);
83+ if (note != null) {
84+ ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
85+ clipboardManager.setText(note.getTitle());
86+ }
87+
88+ Log.v(LOG_TAG, "Bye");
89+ }
90+
91+ public static void copyNoteContentToClipboard(Context context, long id) {
92+ Log.v(LOG_TAG, "Hello");
93+
94+ Uri noteUri = ContentUris.withAppendedId(NoteStore.Note.CONTENT_URI, id);
95+ copyNoteContentToClipboard(context, noteUri);
96+
97+ Log.v(LOG_TAG, "Bye");
98+ }
99+
100+ public static void copyNoteContentToClipboard(Context context, Uri noteUri) {
101+ Log.v(LOG_TAG, "Hello");
102+ Log.d(LOG_TAG, "noteUri => " + noteUri);
103+
104+ Note note = loadNoteData(context, noteUri);
105+ if (note != null) {
106+ ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
107+ clipboardManager.setText(note.getContent());
108+ }
109+
110+ Log.v(LOG_TAG, "Bye");
111+ }
112+
90113 /**
91114 * Start NoteDetailActivity without note template
92115 *
@@ -94,8 +117,7 @@ public class NoteUtils implements NotepadConstants
94117 *
95118 * @param activity
96119 */
97- public static void startActivityToAddNewBlankNote(Activity activity)
98- {
120+ public static void startActivityToAddNewBlankNote(Activity activity) {
99121 Log.v(LOG_TAG, "Hello");
100122
101123 Intent intent = new Intent(Intent.ACTION_INSERT, NoteStore.Note.CONTENT_URI);
@@ -105,33 +127,27 @@ public class NoteUtils implements NotepadConstants
105127 Log.v(LOG_TAG, "Bye");
106128 }
107129
108- public static void startActivityToAddNewNoteWithTemplate(Activity activity, long noteTemplateId)
109- {
130+ public static void startActivityToAddNewNoteWithTemplate(Activity activity, long noteTemplateId) {
110131 Uri noteTemplateUri = ContentUris.withAppendedId(NoteStore.NoteTemplate.CONTENT_URI, noteTemplateId);
111132 NoteUtils.startActivityToAddNewNoteWithTemplate(activity, noteTemplateUri);
112133 }
113134
114- public static void startActivityToAddNewNoteWithTemplate(Activity activity, Uri noteTemplateUri)
115- {
135+ public static void startActivityToAddNewNoteWithTemplate(Activity activity, Uri noteTemplateUri) {
116136 Log.v(LOG_TAG, "Hello");
117137
118138 String where = null;
119139 String[] whereArgs = null;
120- if (NoteStore.NoteTemplate.CONTENT_URI.equals(noteTemplateUri))
121- {
140+ if (NoteStore.NoteTemplate.CONTENT_URI.equals(noteTemplateUri)) {
122141 where = NoteStore.Note.Columns.ENABLED + " = ?";
123- whereArgs = new String[]
124- {
142+ whereArgs = new String[]{
125143 "1"
126144 };
127145 }
128146
129147 Cursor cursor = activity.getContentResolver().query(noteTemplateUri,
130- null, where, whereArgs, null);
131- try
132- {
133- if (cursor != null && cursor.moveToFirst())
134- {
148+ null, where, whereArgs, null);
149+ try {
150+ if (cursor != null && cursor.moveToFirst()) {
135151 int titleIndex = cursor.getColumnIndex(NoteStore.NoteTemplate.Columns.TITLE);
136152 int contentIndex = cursor.getColumnIndex(NoteStore.NoteTemplate.Columns.CONTENT);
137153 int titleLockedIndex = cursor.getColumnIndex(NoteStore.NoteTemplate.Columns.TITLE_LOCKED);
@@ -151,23 +167,19 @@ public class NoteUtils implements NotepadConstants
151167 String content = expandTemplate(contentTemplate, templateContextMap);
152168
153169 Uri noteUri = null;
154- if (editSameTitle)
155- {
170+ if (editSameTitle) {
156171 noteUri = searchNoteByTitle(activity, title);
157172 }
158173 Log.d(LOG_TAG, "noteUri => " + noteUri);
159174
160- if (noteUri != null)
161- {
175+ if (noteUri != null) {
162176 Log.d(LOG_TAG, "note is already exist.");
163177 // if note is already exist
164178 Intent intent = new Intent(Intent.ACTION_EDIT, noteUri);
165179 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
166180 intent.putExtra(EXTRA_TEXT, content);
167181 activity.startActivityForResult(intent, REQUEST_CODE_EDIT_NOTE);
168- }
169- else
170- {
182+ } else {
171183 Log.d(LOG_TAG, "note is not found.");
172184 // if not found, insert new note
173185 Intent intent = new Intent(Intent.ACTION_INSERT, NoteStore.Note.CONTENT_URI);
@@ -178,54 +190,42 @@ public class NoteUtils implements NotepadConstants
178190 activity.startActivityForResult(intent, REQUEST_CODE_ADD_NOTE);
179191 }
180192 }
181- }
182- finally
183- {
184- if (cursor != null)
185- {
193+ } finally {
194+ if (cursor != null) {
186195 cursor.close();
187196 }
188197 }
189198 Log.v(LOG_TAG, "Bye");
190199 }
191200
192- public static void startActivityToAddNewNoteWithFirstTemplate(Activity activity)
193- {
201+ public static void startActivityToAddNewNoteWithFirstTemplate(Activity activity) {
194202 NoteUtils.startActivityToAddNewNoteWithTemplate(activity, NoteStore.NoteTemplate.CONTENT_URI);
195203 }
196204
197- public static Uri searchNoteByTitle(Context context, String title)
198- {
205+ public static Uri searchNoteByTitle(Context context, String title) {
199206 Uri result = null;
200207 Log.v(LOG_TAG, "Hello");
201208 Log.d(LOG_TAG, "title => " + title);
202209
203- if (!TextUtils.isEmpty(title))
204- {
210+ if (!TextUtils.isEmpty(title)) {
205211 ContentResolver contentResolver = context.getContentResolver();
206212 final String selection = NoteStore.Note.Columns.TITLE + " = ? "
207- + " AND "
208- + NoteStore.Note.Columns.ENABLED + " = ? ";
209- final String[] selectionArgs = new String[]
210- {
213+ + " AND "
214+ + NoteStore.Note.Columns.ENABLED + " = ? ";
215+ final String[] selectionArgs = new String[]{
211216 title,
212217 "1"
213218 };
214219 Cursor cursor = contentResolver.query(NoteStore.Note.CONTENT_URI, null,
215- selection, selectionArgs, null);
216- if (cursor != null)
217- {
218- try
219- {
220- if (cursor.moveToFirst())
221- {
220+ selection, selectionArgs, null);
221+ if (cursor != null) {
222+ try {
223+ if (cursor.moveToFirst()) {
222224 int idColumnIndex = cursor.getColumnIndex(NoteStore.Note.Columns._ID);
223225 long noteId = cursor.getLong(idColumnIndex);
224226 result = ContentUris.withAppendedId(NoteStore.Note.CONTENT_URI, noteId);
225227 }
226- }
227- finally
228- {
228+ } finally {
229229 cursor.close();
230230 }
231231 }
@@ -235,12 +235,10 @@ public class NoteUtils implements NotepadConstants
235235 return result;
236236 }
237237
238- public static String expandTemplate(String template, Map<String, String> templateContextMap)
239- {
238+ public static String expandTemplate(String template, Map<String, String> templateContextMap) {
240239 String text = template;
241240
242- for (String key : templateContextMap.keySet())
243- {
241+ for (String key : templateContextMap.keySet()) {
244242 String value = templateContextMap.get(key);
245243 Log.d(LOG_TAG, "key => " + key);
246244 Log.d(LOG_TAG, "value => " + value);
@@ -251,4 +249,34 @@ public class NoteUtils implements NotepadConstants
251249
252250 return text;
253251 }
252+
253+ private static Note loadNoteData(Context context, Uri noteUri) {
254+ Note note = null;
255+
256+ Log.v(LOG_TAG, "Hello");
257+ Log.d(LOG_TAG, "noteUri => " + noteUri);
258+
259+ if (NoteStore.isNoteItemUri(context, noteUri)) {
260+ ContentResolver contentResolver = context.getContentResolver();
261+ Cursor cursor = contentResolver.query(noteUri, null, null, null, null);
262+ if (cursor != null) {
263+ try {
264+ if (cursor.moveToFirst()) {
265+ int titleIndex = cursor.getColumnIndex(NoteStore.Note.Columns.TITLE);
266+ int contentIndex = cursor.getColumnIndex(NoteStore.Note.Columns.CONTENT);
267+ String noteTitle = cursor.getString(titleIndex);
268+ String noteContent = cursor.getString(contentIndex);
269+ note = new Note();
270+ note.setTitle(noteTitle);
271+ note.setContent(noteContent);
272+ }
273+ } finally {
274+ cursor.close();
275+ }
276+ }
277+ }
278+
279+ Log.v(LOG_TAG, "Bye");
280+ return note;
281+ }
254282 }
--- a/pom.xml
+++ b/pom.xml
@@ -32,17 +32,24 @@
3232 <pluginManagement>
3333 <plugins>
3434 <plugin>
35+ <!--
3536 <groupId>com.jayway.maven.plugins.android.generation2</groupId>
3637 <artifactId>android-maven-plugin</artifactId>
37- <version>3.8.2</version>
38+ <version>3.9.0-rc.3</version>
39+ -->
40+ <groupId>com.simpligility.maven.plugins</groupId>
41+ <artifactId>android-maven-plugin</artifactId>
42+ <version>4.4.1</version> <!-- use latest release -->
43+ <extensions>true</extensions>
3844 <dependencies>
3945 <dependency>
4046 <groupId>net.sf.proguard</groupId>
4147 <artifactId>proguard-base</artifactId>
42- <version>4.11</version>
48+ <version>5.2.1</version>
4349 </dependency>
4450 </dependencies>
4551 </plugin>
52+
4653
4754 <!-- mvn compile -->
4855 <plugin>