-package com.yuji.ec;\r
-\r
-import android.content.Context;\r
-\r
-import com.yuji.ec.common.CommonUtil;\r
-import com.yuji.ec.db.DatabaseHelper;\r
-import com.yuji.ec.service.NoteUpdatorService;\r
-import com.yuji.ec.utility.EvernoteUtil;\r
-import com.yuji.ec.utility.PasswordUtil;\r
-\r
-public class Initialize {\r
- private static final String EVER_CLIP_ACTIVITY = "EverClipActivity";\r
- private static boolean isInit = true;\r
- private static boolean isInit2 = true;\r
-\r
- public static void initialize(Context context) {\r
- if (!isInit) {\r
- return;\r
- }\r
- \r
- DatabaseHelper.init(context);\r
- NoteUpdatorService.init(context);\r
- \r
- isInit = false;\r
- }\r
-\r
- public static void initialize(Context context, String name) {\r
- if (!isInit2) {\r
- return;\r
- }\r
- if (name.equals(EVER_CLIP_ACTIVITY)){\r
- return;\r
- }\r
- \r
- EvernoteUtil util = EvernoteUtil.getInstance();\r
- String username = PasswordUtil.getUsername(context);\r
- String password = PasswordUtil.getPassword(context);\r
- if (!CommonUtil.isNull(username) && !CommonUtil.isNull(password)) {\r
- util.setConfig(username, password);\r
- }\r
- \r
- isInit2 = false; \r
- }\r
-}\r
+package com.yuji.ec;
+
+import android.content.Context;
+
+import com.yuji.ec.common.CommonUtil;
+import com.yuji.ec.db.DatabaseHelper;
+import com.yuji.ec.service.NoteUpdatorService;
+import com.yuji.ec.utility.EvernoteUtil;
+import com.yuji.ec.utility.PasswordUtil;
+
+public class Initialize {
+ private static final String EVER_CLIP_ACTIVITY = "EverClipActivity";
+ private static boolean isInit = true;
+ private static boolean isInit2 = true;
+
+ public static void initialize(Context context) {
+ if (!isInit) {
+ return;
+ }
+
+ DatabaseHelper.init(context);
+ NoteUpdatorService.init(context);
+
+ isInit = false;
+ }
+
+ public static void initialize(Context context, String name) {
+ if (!isInit2) {
+ return;
+ }
+ if (name.equals(EVER_CLIP_ACTIVITY)){
+ return;
+ }
+
+ EvernoteUtil util = EvernoteUtil.getInstance();
+ String username = PasswordUtil.getUsername(context);
+ String password = PasswordUtil.getPassword(context);
+ if (!CommonUtil.isNull(username) && !CommonUtil.isNull(password)) {
+ util.setConfig(username, password);
+ }
+
+ isInit2 = false;
+ }
+}
-package com.yuji.ec;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import android.content.Intent;\r
-import android.os.Bundle;\r
-import android.view.View;\r
-import android.view.View.OnClickListener;\r
-import android.widget.AdapterView;\r
-import android.widget.AdapterView.OnItemClickListener;\r
-import android.widget.Button;\r
-import android.widget.LinearLayout;\r
-import android.widget.ListView;\r
-import android.widget.TextView;\r
-import android.widget.Toast;\r
-\r
-import com.yuji.ec.common.Constant;\r
-import com.yuji.ec.db.INoteItem;\r
-import com.yuji.ec.db.NoteListItem;\r
-import com.yuji.ec.task.NoteTypeListTask;\r
-import com.yuji.ec.utility.AsyncTaskCommand;\r
-import com.yuji.ec.utility.BaseActivity;\r
-import com.yuji.ec.utility.EditPrefUtil;\r
-import com.yuji.ec.utility.EvernoteUtil;\r
-import com.yuji.ec.utility.EvernoteUtil.Error;\r
-\r
-public class NoteTypeListActivity extends BaseActivity {\r
- private EditPrefUtil pref = new EditPrefUtil(this);\r
-\r
- private static List<NoteListItem> itemList = null;\r
- private LinearLayout layoutView = null;\r
- private TextView messageText = null;\r
- private ListView listView = null;\r
- private Button closeButon = null;\r
-\r
- @Override\r
- public void onCreate(Bundle savedInstanceState) {\r
- super.onCreate(savedInstanceState);\r
- setContentView(R.layout.note_type_list);\r
-\r
- layoutView = (LinearLayout) this.findViewById(R.id.noteTypeLayout);\r
- messageText = (TextView) this\r
- .findViewById(R.id.noteTypeConfirmDeleteMsg);\r
- listView = (ListView) this.findViewById(R.id.noteTypeView);\r
- closeButon = (Button) this.findViewById(R.id.noteTypeCloseButton);\r
-\r
- listView.setOnItemClickListener(new OnItemClickListener() {\r
- public void onItemClick(AdapterView<?> parent, View view,\r
- int position, long id) {\r
- listViewOnItemClickListener(parent, view, position, id);\r
- }\r
- });\r
-\r
- closeButon.setOnClickListener(new OnClickListener(){\r
- public void onClick(View v) {\r
- closeButonOnClick();\r
- }});\r
- closeButon.setEnabled(false);\r
- \r
- // updateList();\r
- if (itemList == null){\r
- int noteItemType = pref.getInt(Constant.PREF_NOTE_ITEM_TYPE_TMP,\r
- Constant.NOTE_ITEM_TYPE_ALL);\r
- NoteTypeListTask task = new NoteTypeListTask(this, noteItemType);\r
- AsyncTaskCommand command = new AsyncTaskCommand(this, task);\r
- command.setTitle(getString(R.string.noteTypeDialogTitle));\r
- command.setButtonTitle(getString(R.string.cancelButton));\r
- command.execute("");\r
- }\r
- else {\r
- setList(itemList); \r
- }\r
- setStatus();\r
- }\r
-\r
- private void listViewOnItemClickListener(AdapterView<?> parent, View view,\r
- int position, long id) {\r
- ListView listView = (ListView) parent;\r
-\r
- NoteListItem selectedItem = (NoteListItem) listView\r
- .getItemAtPosition(position);\r
- INoteItem item = selectedItem.getItem();\r
-\r
- String guid = item.getGuid();\r
- String title = item.getText();\r
-\r
- Intent data = new Intent();\r
- data.putExtra(Constant.EXTRA_GUID, guid);\r
- data.putExtra(Constant.EXTRA_TITLE, title);\r
- setResult(RESULT_OK, data);\r
- finish();\r
- }\r
-\r
- private void closeButonOnClick(){\r
- finish();\r
- }\r
- \r
- public void done(Error errorCode, List<INoteItem> nList) {\r
- if (errorCode != null && !errorCode.equals(Error.NONE)) {\r
- EvernoteUtil util = EvernoteUtil.getInstance();\r
- Toast.makeText(this, util.getErrorMessage(this, errorCode),\r
- Toast.LENGTH_LONG).show();\r
- }\r
-\r
- if (nList == null) {\r
- finish();\r
- return;\r
- }\r
-\r
- List<NoteListItem> itemList = new ArrayList<NoteListItem>();\r
- for (INoteItem iItem : nList) {\r
- NoteListItem item = new NoteListItem(iItem.getText(), iItem);\r
- itemList.add(item);\r
- }\r
- \r
- setList(itemList);\r
-\r
- setStatus();\r
- }\r
-\r
- private void setList(List<NoteListItem> itemList) {\r
- NoteListViewArrayAdapter adapter = new NoteListViewArrayAdapter(this,\r
- R.layout.simple_list_item_1, itemList);\r
- listView.setAdapter(adapter);\r
- \r
- NoteTypeListActivity.itemList = itemList;\r
- }\r
-\r
- private void setStatus() {\r
- closeButon.setEnabled(itemList != null);\r
- layoutView.setVisibility(View.GONE);\r
- }\r
- \r
- public static void init(){\r
- itemList = null;\r
- }\r
-}\r
+package com.yuji.ec;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.yuji.ec.common.Constant;
+import com.yuji.ec.db.INoteItem;
+import com.yuji.ec.db.NoteListItem;
+import com.yuji.ec.task.NoteTypeListTask;
+import com.yuji.ec.utility.AsyncTaskCommand;
+import com.yuji.ec.utility.BaseActivity;
+import com.yuji.ec.utility.EditPrefUtil;
+import com.yuji.ec.utility.EvernoteUtil;
+import com.yuji.ec.utility.EvernoteUtil.Error;
+
+public class NoteTypeListActivity extends BaseActivity {
+ private EditPrefUtil pref = new EditPrefUtil(this);
+
+ private static List<NoteListItem> itemList = null;
+ private LinearLayout layoutView = null;
+ private TextView messageText = null;
+ private ListView listView = null;
+ private Button closeButon = null;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.note_type_list);
+
+ layoutView = (LinearLayout) this.findViewById(R.id.noteTypeLayout);
+ messageText = (TextView) this
+ .findViewById(R.id.noteTypeConfirmDeleteMsg);
+ listView = (ListView) this.findViewById(R.id.noteTypeView);
+ closeButon = (Button) this.findViewById(R.id.noteTypeCloseButton);
+
+ listView.setOnItemClickListener(new OnItemClickListener() {
+ public void onItemClick(AdapterView<?> parent, View view,
+ int position, long id) {
+ listViewOnItemClickListener(parent, view, position, id);
+ }
+ });
+
+ closeButon.setOnClickListener(new OnClickListener(){
+ public void onClick(View v) {
+ closeButonOnClick();
+ }});
+ closeButon.setEnabled(false);
+
+ // updateList();
+ if (itemList == null){
+ int noteItemType = pref.getInt(Constant.PREF_NOTE_ITEM_TYPE_TMP,
+ Constant.NOTE_ITEM_TYPE_ALL);
+ NoteTypeListTask task = new NoteTypeListTask(this, noteItemType);
+ AsyncTaskCommand command = new AsyncTaskCommand(this, task);
+ command.setTitle(getString(R.string.noteTypeDialogTitle));
+ command.setButtonTitle(getString(R.string.cancelButton));
+ command.execute("");
+ }
+ else {
+ setList(itemList);
+ }
+ setStatus();
+ }
+
+ private void listViewOnItemClickListener(AdapterView<?> parent, View view,
+ int position, long id) {
+ ListView listView = (ListView) parent;
+
+ NoteListItem selectedItem = (NoteListItem) listView
+ .getItemAtPosition(position);
+ INoteItem item = selectedItem.getItem();
+
+ String guid = item.getGuid();
+ String title = item.getText();
+
+ Intent data = new Intent();
+ data.putExtra(Constant.EXTRA_GUID, guid);
+ data.putExtra(Constant.EXTRA_TITLE, title);
+ setResult(RESULT_OK, data);
+ finish();
+ }
+
+ private void closeButonOnClick(){
+ finish();
+ }
+
+ public void done(Error errorCode, List<INoteItem> nList) {
+ if (errorCode != null && !errorCode.equals(Error.NONE)) {
+ EvernoteUtil util = EvernoteUtil.getInstance();
+ Toast.makeText(this, util.getErrorMessage(this, errorCode),
+ Toast.LENGTH_LONG).show();
+ }
+
+ if (nList == null) {
+ finish();
+ return;
+ }
+
+ List<NoteListItem> itemList = new ArrayList<NoteListItem>();
+ for (INoteItem iItem : nList) {
+ NoteListItem item = new NoteListItem(iItem.getText(), iItem);
+ itemList.add(item);
+ }
+
+ setList(itemList);
+
+ setStatus();
+ }
+
+ private void setList(List<NoteListItem> itemList) {
+ NoteListViewArrayAdapter adapter = new NoteListViewArrayAdapter(this,
+ R.layout.simple_list_item_1, itemList);
+ listView.setAdapter(adapter);
+
+ NoteTypeListActivity.itemList = itemList;
+ }
+
+ private void setStatus() {
+ closeButon.setEnabled(itemList != null);
+ layoutView.setVisibility(View.GONE);
+ }
+
+ public static void init(){
+ itemList = null;
+ }
+}
: Constant.OFF;
int prevAutoUpdate = pref.getInt(Constant.PREF_AUTO_UPDATE);
long prevUpdateTime = pref.getLong(Constant.PREF_UPDATE_TIME);
- // \8e©\93®\8dX\90V\82ªON\81A\8e\9e\8d\8f\90Ý\92è\8dÏ\82Ý\82È\82ç\82Î
+ // 自動更新がON、時刻設定済みならば
if (autoUpdate == Constant.ON) {
if (updateTime >= 0) {
- // \8e©\93®\8dX\90V\82ªOFF\82©\82çON\81A\82à\82µ\82\82Í\8e\9e\8d\8f\82ª\95Ï\8dX
+ // 自動更新がOFFからON、もしくは時刻が変更
if (prevAutoUpdate == Constant.OFF
|| prevUpdateTime != updateTime) {
pref.put(Constant.PREF_UPDATE_TIME, updateTime);
pref.update();
if (isBind) {
- unbindService(serviceConnection); // \83o\83C\83\93\83h\89ð\8f\9c
+ unbindService(serviceConnection); // バインド解除
isBind = false;
}
if (isRegister) {
- unregisterReceiver(receiver); // \93o\98^\89ð\8f\9c
+ unregisterReceiver(receiver); // 登録解除
isRegister = false;
}
registerReceiver(receiver, filter);
isRegister = true;
- // \83T\81[\83r\83X\82É\83o\83C\83\93\83h
+ // サービスにバインド
bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
isBind = true;
} catch (Exception e) {
-/*\r
- * Java Base64 - A pure Java library for reading and writing Base64\r
- * encoded streams.\r
- * \r
- * Copyright (C) 2007-2009 Carlo Pelliccia (www.sauronsoftware.it)\r
- * \r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License version\r
- * 2.1, as published by the Free Software Foundation.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Lesser General Public\r
- * License version 2.1 along with this program.\r
- * If not, see <http://www.gnu.org/licenses/>.\r
- */\r
-package com.yuji.ec.base64;\r
-\r
-import java.io.ByteArrayInputStream;\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileOutputStream;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.io.OutputStream;\r
-import java.io.UnsupportedEncodingException;\r
-\r
-/**\r
- * <p>\r
- * Base64 encoding and decoding utility methods, both for binary and textual\r
- * informations.\r
- * </p>\r
- * \r
- * @author Carlo Pelliccia\r
- * @since 1.1\r
- * @version 1.3\r
- */\r
-public class Base64 {\r
-\r
- /**\r
- * <p>\r
- * Encodes a string.\r
- * </p>\r
- * <p>\r
- * Before the string is encoded in Base64, it is converted in a binary\r
- * sequence using the system default charset.\r
- * </p>\r
- * \r
- * @param str\r
- * The source string.\r
- * @return The encoded string.\r
- * @throws RuntimeException\r
- * If an unexpected error occurs.\r
- */\r
- public static String encode(String str) throws RuntimeException {\r
- byte[] bytes = str.getBytes();\r
- byte[] encoded = encode(bytes);\r
- try {\r
- return new String(encoded, "ASCII");\r
- } catch (UnsupportedEncodingException e) {\r
- throw new RuntimeException("ASCII is not supported!", e);\r
- }\r
- }\r
-\r
- /**\r
- * <p>\r
- * Encodes a string.\r
- * </p>\r
- * <p>\r
- * Before the string is encoded in Base64, it is converted in a binary\r
- * sequence using the supplied charset.\r
- * </p>\r
- * \r
- * @param str\r
- * The source string\r
- * @param charset\r
- * The charset name.\r
- * @return The encoded string.\r
- * @throws RuntimeException\r
- * If an unexpected error occurs.\r
- * @since 1.2\r
- */\r
- public static String encode(String str, String charset)\r
- throws RuntimeException {\r
- byte[] bytes;\r
- try {\r
- bytes = str.getBytes(charset);\r
- } catch (UnsupportedEncodingException e) {\r
- throw new RuntimeException("Unsupported charset: " + charset, e);\r
- }\r
- byte[] encoded = encode(bytes);\r
- try {\r
- return new String(encoded, "ASCII");\r
- } catch (UnsupportedEncodingException e) {\r
- throw new RuntimeException("ASCII is not supported!", e);\r
- }\r
- }\r
-\r
- /**\r
- * <p>\r
- * Decodes the supplied string.\r
- * </p>\r
- * <p>\r
- * The supplied string is decoded into a binary sequence, and then the\r
- * sequence is encoded with the system default charset and returned.\r
- * </p>\r
- * \r
- * @param str\r
- * The encoded string.\r
- * @return The decoded string.\r
- * @throws RuntimeException\r
- * If an unexpected error occurs.\r
- */\r
- public static String decode(String str) throws RuntimeException {\r
- byte[] bytes;\r
- try {\r
- bytes = str.getBytes("ASCII");\r
- } catch (UnsupportedEncodingException e) {\r
- throw new RuntimeException("ASCII is not supported!", e);\r
- }\r
- byte[] decoded = decode(bytes);\r
- return new String(decoded);\r
- }\r
-\r
- /**\r
- * <p>\r
- * Decodes the supplied string.\r
- * </p>\r
- * <p>\r
- * The supplied string is decoded into a binary sequence, and then the\r
- * sequence is encoded with the supplied charset and returned.\r
- * </p>\r
- * \r
- * @param str\r
- * The encoded string.\r
- * @param charset\r
- * The charset name.\r
- * @return The decoded string.\r
- * @throws RuntimeException\r
- * If an unexpected error occurs.\r
- * @since 1.2\r
- */\r
- public static String decode(String str, String charset)\r
- throws RuntimeException {\r
- byte[] bytes;\r
- try {\r
- bytes = str.getBytes("ASCII");\r
- } catch (UnsupportedEncodingException e) {\r
- throw new RuntimeException("ASCII is not supported!", e);\r
- }\r
- byte[] decoded = decode(bytes);\r
- try {\r
- return new String(decoded, charset);\r
- } catch (UnsupportedEncodingException e) {\r
- throw new RuntimeException("Unsupported charset: " + charset, e);\r
- }\r
- }\r
-\r
- /**\r
- * <p>\r
- * Encodes a binary sequence.\r
- * </p>\r
- * <p>\r
- * If data are large, i.e. if you are working with large binary files,\r
- * consider to use a {@link Base64OutputStream} instead of loading too much\r
- * data in memory.\r
- * </p>\r
- * \r
- * @param bytes\r
- * The source sequence.\r
- * @return The encoded sequence.\r
- * @throws RuntimeException\r
- * If an unexpected error occurs.\r
- * @since 1.2\r
- */\r
- public static byte[] encode(byte[] bytes) throws RuntimeException {\r
- return encode(bytes, 0);\r
- }\r
-\r
- /**\r
- * <p>\r
- * Encodes a binary sequence, wrapping every encoded line every\r
- * <em>wrapAt</em> characters. A <em>wrapAt</em> value less than 1 disables\r
- * wrapping.\r
- * </p>\r
- * <p>\r
- * If data are large, i.e. if you are working with large binary files,\r
- * consider to use a {@link Base64OutputStream} instead of loading too much\r
- * data in memory.\r
- * </p>\r
- * \r
- * @param bytes\r
- * The source sequence.\r
- * @param wrapAt\r
- * The max line length for encoded data. If less than 1 no wrap\r
- * is applied.\r
- * @return The encoded sequence.\r
- * @throws RuntimeException\r
- * If an unexpected error occurs.\r
- * @since 1.2\r
- */\r
- public static byte[] encode(byte[] bytes, int wrapAt)\r
- throws RuntimeException {\r
- ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);\r
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();\r
- try {\r
- encode(inputStream, outputStream, wrapAt);\r
- } catch (IOException e) {\r
- throw new RuntimeException("Unexpected I/O error", e);\r
- } finally {\r
- try {\r
- inputStream.close();\r
- } catch (Throwable t) {\r
- ;\r
- }\r
- try {\r
- outputStream.close();\r
- } catch (Throwable t) {\r
- ;\r
- }\r
- }\r
- return outputStream.toByteArray();\r
- }\r
-\r
- /**\r
- * <p>\r
- * Decodes a binary sequence.\r
- * </p>\r
- * <p>\r
- * If data are large, i.e. if you are working with large binary files,\r
- * consider to use a {@link Base64InputStream} instead of loading too much\r
- * data in memory.\r
- * </p>\r
- * \r
- * @param bytes\r
- * The encoded sequence.\r
- * @return The decoded sequence.\r
- * @throws RuntimeException\r
- * If an unexpected error occurs.\r
- * @since 1.2\r
- */\r
- public static byte[] decode(byte[] bytes) throws RuntimeException {\r
- ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);\r
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();\r
- try {\r
- decode(inputStream, outputStream);\r
- } catch (IOException e) {\r
- throw new RuntimeException("Unexpected I/O error", e);\r
- } finally {\r
- try {\r
- inputStream.close();\r
- } catch (Throwable t) {\r
- ;\r
- }\r
- try {\r
- outputStream.close();\r
- } catch (Throwable t) {\r
- ;\r
- }\r
- }\r
- return outputStream.toByteArray();\r
- }\r
-\r
- /**\r
- * <p>\r
- * Encodes data from the given input stream and writes them in the given\r
- * output stream.\r
- * </p>\r
- * <p>\r
- * The supplied input stream is read until its end is reached, but it's not\r
- * closed by this method.\r
- * </p>\r
- * <p>\r
- * The supplied output stream is nor flushed neither closed by this method.\r
- * </p>\r
- * \r
- * @param inputStream\r
- * The input stream.\r
- * @param outputStream\r
- * The output stream.\r
- * @throws IOException\r
- * If an I/O error occurs.\r
- */\r
- public static void encode(InputStream inputStream, OutputStream outputStream)\r
- throws IOException {\r
- encode(inputStream, outputStream, 0);\r
- }\r
-\r
- /**\r
- * <p>\r
- * Encodes data from the given input stream and writes them in the given\r
- * output stream, wrapping every encoded line every <em>wrapAt</em>\r
- * characters. A <em>wrapAt</em> value less than 1 disables wrapping.\r
- * </p>\r
- * <p>\r
- * The supplied input stream is read until its end is reached, but it's not\r
- * closed by this method.\r
- * </p>\r
- * <p>\r
- * The supplied output stream is nor flushed neither closed by this method.\r
- * </p>\r
- * \r
- * @param inputStream\r
- * The input stream from which clear data are read.\r
- * @param outputStream\r
- * The output stream in which encoded data are written.\r
- * @param wrapAt\r
- * The max line length for encoded data. If less than 1 no wrap\r
- * is applied.\r
- * @throws IOException\r
- * If an I/O error occurs.\r
- */\r
- public static void encode(InputStream inputStream,\r
- OutputStream outputStream, int wrapAt) throws IOException {\r
- Base64OutputStream aux = new Base64OutputStream(outputStream, wrapAt);\r
- copy(inputStream, aux);\r
- aux.commit();\r
- }\r
-\r
- /**\r
- * <p>\r
- * Decodes data from the given input stream and writes them in the given\r
- * output stream.\r
- * </p>\r
- * <p>\r
- * The supplied input stream is read until its end is reached, but it's not\r
- * closed by this method.\r
- * </p>\r
- * <p>\r
- * The supplied output stream is nor flushed neither closed by this method.\r
- * </p>\r
- * \r
- * @param inputStream\r
- * The input stream from which encoded data are read.\r
- * @param outputStream\r
- * The output stream in which decoded data are written.\r
- * @throws IOException\r
- * If an I/O error occurs.\r
- */\r
- public static void decode(InputStream inputStream, OutputStream outputStream)\r
- throws IOException {\r
- copy(new Base64InputStream(inputStream), outputStream);\r
- }\r
-\r
- /**\r
- * <p>\r
- * Encodes data from the given source file contents and writes them in the\r
- * given target file, wrapping every encoded line every <em>wrapAt</em>\r
- * characters. A <em>wrapAt</em> value less than 1 disables wrapping.\r
- * </p>\r
- * \r
- * @param source\r
- * The source file, from which decoded data are read.\r
- * @param target\r
- * The target file, in which encoded data are written.\r
- * @param wrapAt\r
- * The max line length for encoded data. If less than 1 no wrap\r
- * is applied.\r
- * @throws IOException\r
- * If an I/O error occurs.\r
- * @since 1.3\r
- */\r
- public static void encode(File source, File target, int wrapAt)\r
- throws IOException {\r
- InputStream inputStream = null;\r
- OutputStream outputStream = null;\r
- try {\r
- inputStream = new FileInputStream(source);\r
- outputStream = new FileOutputStream(target);\r
- Base64.encode(inputStream, outputStream, wrapAt);\r
- } finally {\r
- if (outputStream != null) {\r
- try {\r
- outputStream.close();\r
- } catch (Throwable t) {\r
- ;\r
- }\r
- }\r
- if (inputStream != null) {\r
- try {\r
- inputStream.close();\r
- } catch (Throwable t) {\r
- ;\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * <p>\r
- * Encodes data from the given source file contents and writes them in the\r
- * given target file.\r
- * </p>\r
- * \r
- * @param source\r
- * The source file, from which decoded data are read.\r
- * @param target\r
- * The target file, in which encoded data are written.\r
- * @throws IOException\r
- * If an I/O error occurs.\r
- * @since 1.3\r
- */\r
- public static void encode(File source, File target) throws IOException {\r
- InputStream inputStream = null;\r
- OutputStream outputStream = null;\r
- try {\r
- inputStream = new FileInputStream(source);\r
- outputStream = new FileOutputStream(target);\r
- Base64.encode(inputStream, outputStream);\r
- } finally {\r
- if (outputStream != null) {\r
- try {\r
- outputStream.close();\r
- } catch (Throwable t) {\r
- ;\r
- }\r
- }\r
- if (inputStream != null) {\r
- try {\r
- inputStream.close();\r
- } catch (Throwable t) {\r
- ;\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * <p>\r
- * Decodes data from the given source file contents and writes them in the\r
- * given target file.\r
- * </p>\r
- * \r
- * @param source\r
- * The source file, from which encoded data are read.\r
- * @param target\r
- * The target file, in which decoded data are written.\r
- * @throws IOException\r
- * If an I/O error occurs.\r
- * @since 1.3\r
- */\r
- public static void decode(File source, File target) throws IOException {\r
- InputStream inputStream = null;\r
- OutputStream outputStream = null;\r
- try {\r
- inputStream = new FileInputStream(source);\r
- outputStream = new FileOutputStream(target);\r
- decode(inputStream, outputStream);\r
- } finally {\r
- if (outputStream != null) {\r
- try {\r
- outputStream.close();\r
- } catch (Throwable t) {\r
- ;\r
- }\r
- }\r
- if (inputStream != null) {\r
- try {\r
- inputStream.close();\r
- } catch (Throwable t) {\r
- ;\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Copies data from a stream to another.\r
- * \r
- * @param inputStream\r
- * The input stream.\r
- * @param outputStream\r
- * The output stream.\r
- * @throws IOException\r
- * If a unexpected I/O error occurs.\r
- */\r
- private static void copy(InputStream inputStream, OutputStream outputStream)\r
- throws IOException {\r
- // 1KB buffer\r
- byte[] b = new byte[1024];\r
- int len;\r
- while ((len = inputStream.read(b)) != -1) {\r
- outputStream.write(b, 0, len);\r
- }\r
- }\r
-\r
-}\r
+/*
+ * Java Base64 - A pure Java library for reading and writing Base64
+ * encoded streams.
+ *
+ * Copyright (C) 2007-2009 Carlo Pelliccia (www.sauronsoftware.it)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version
+ * 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License version 2.1 along with this program.
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.yuji.ec.base64;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * <p>
+ * Base64 encoding and decoding utility methods, both for binary and textual
+ * informations.
+ * </p>
+ *
+ * @author Carlo Pelliccia
+ * @since 1.1
+ * @version 1.3
+ */
+public class Base64 {
+
+ /**
+ * <p>
+ * Encodes a string.
+ * </p>
+ * <p>
+ * Before the string is encoded in Base64, it is converted in a binary
+ * sequence using the system default charset.
+ * </p>
+ *
+ * @param str
+ * The source string.
+ * @return The encoded string.
+ * @throws RuntimeException
+ * If an unexpected error occurs.
+ */
+ public static String encode(String str) throws RuntimeException {
+ byte[] bytes = str.getBytes();
+ byte[] encoded = encode(bytes);
+ try {
+ return new String(encoded, "ASCII");
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException("ASCII is not supported!", e);
+ }
+ }
+
+ /**
+ * <p>
+ * Encodes a string.
+ * </p>
+ * <p>
+ * Before the string is encoded in Base64, it is converted in a binary
+ * sequence using the supplied charset.
+ * </p>
+ *
+ * @param str
+ * The source string
+ * @param charset
+ * The charset name.
+ * @return The encoded string.
+ * @throws RuntimeException
+ * If an unexpected error occurs.
+ * @since 1.2
+ */
+ public static String encode(String str, String charset)
+ throws RuntimeException {
+ byte[] bytes;
+ try {
+ bytes = str.getBytes(charset);
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException("Unsupported charset: " + charset, e);
+ }
+ byte[] encoded = encode(bytes);
+ try {
+ return new String(encoded, "ASCII");
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException("ASCII is not supported!", e);
+ }
+ }
+
+ /**
+ * <p>
+ * Decodes the supplied string.
+ * </p>
+ * <p>
+ * The supplied string is decoded into a binary sequence, and then the
+ * sequence is encoded with the system default charset and returned.
+ * </p>
+ *
+ * @param str
+ * The encoded string.
+ * @return The decoded string.
+ * @throws RuntimeException
+ * If an unexpected error occurs.
+ */
+ public static String decode(String str) throws RuntimeException {
+ byte[] bytes;
+ try {
+ bytes = str.getBytes("ASCII");
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException("ASCII is not supported!", e);
+ }
+ byte[] decoded = decode(bytes);
+ return new String(decoded);
+ }
+
+ /**
+ * <p>
+ * Decodes the supplied string.
+ * </p>
+ * <p>
+ * The supplied string is decoded into a binary sequence, and then the
+ * sequence is encoded with the supplied charset and returned.
+ * </p>
+ *
+ * @param str
+ * The encoded string.
+ * @param charset
+ * The charset name.
+ * @return The decoded string.
+ * @throws RuntimeException
+ * If an unexpected error occurs.
+ * @since 1.2
+ */
+ public static String decode(String str, String charset)
+ throws RuntimeException {
+ byte[] bytes;
+ try {
+ bytes = str.getBytes("ASCII");
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException("ASCII is not supported!", e);
+ }
+ byte[] decoded = decode(bytes);
+ try {
+ return new String(decoded, charset);
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException("Unsupported charset: " + charset, e);
+ }
+ }
+
+ /**
+ * <p>
+ * Encodes a binary sequence.
+ * </p>
+ * <p>
+ * If data are large, i.e. if you are working with large binary files,
+ * consider to use a {@link Base64OutputStream} instead of loading too much
+ * data in memory.
+ * </p>
+ *
+ * @param bytes
+ * The source sequence.
+ * @return The encoded sequence.
+ * @throws RuntimeException
+ * If an unexpected error occurs.
+ * @since 1.2
+ */
+ public static byte[] encode(byte[] bytes) throws RuntimeException {
+ return encode(bytes, 0);
+ }
+
+ /**
+ * <p>
+ * Encodes a binary sequence, wrapping every encoded line every
+ * <em>wrapAt</em> characters. A <em>wrapAt</em> value less than 1 disables
+ * wrapping.
+ * </p>
+ * <p>
+ * If data are large, i.e. if you are working with large binary files,
+ * consider to use a {@link Base64OutputStream} instead of loading too much
+ * data in memory.
+ * </p>
+ *
+ * @param bytes
+ * The source sequence.
+ * @param wrapAt
+ * The max line length for encoded data. If less than 1 no wrap
+ * is applied.
+ * @return The encoded sequence.
+ * @throws RuntimeException
+ * If an unexpected error occurs.
+ * @since 1.2
+ */
+ public static byte[] encode(byte[] bytes, int wrapAt)
+ throws RuntimeException {
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ try {
+ encode(inputStream, outputStream, wrapAt);
+ } catch (IOException e) {
+ throw new RuntimeException("Unexpected I/O error", e);
+ } finally {
+ try {
+ inputStream.close();
+ } catch (Throwable t) {
+ ;
+ }
+ try {
+ outputStream.close();
+ } catch (Throwable t) {
+ ;
+ }
+ }
+ return outputStream.toByteArray();
+ }
+
+ /**
+ * <p>
+ * Decodes a binary sequence.
+ * </p>
+ * <p>
+ * If data are large, i.e. if you are working with large binary files,
+ * consider to use a {@link Base64InputStream} instead of loading too much
+ * data in memory.
+ * </p>
+ *
+ * @param bytes
+ * The encoded sequence.
+ * @return The decoded sequence.
+ * @throws RuntimeException
+ * If an unexpected error occurs.
+ * @since 1.2
+ */
+ public static byte[] decode(byte[] bytes) throws RuntimeException {
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ try {
+ decode(inputStream, outputStream);
+ } catch (IOException e) {
+ throw new RuntimeException("Unexpected I/O error", e);
+ } finally {
+ try {
+ inputStream.close();
+ } catch (Throwable t) {
+ ;
+ }
+ try {
+ outputStream.close();
+ } catch (Throwable t) {
+ ;
+ }
+ }
+ return outputStream.toByteArray();
+ }
+
+ /**
+ * <p>
+ * Encodes data from the given input stream and writes them in the given
+ * output stream.
+ * </p>
+ * <p>
+ * The supplied input stream is read until its end is reached, but it's not
+ * closed by this method.
+ * </p>
+ * <p>
+ * The supplied output stream is nor flushed neither closed by this method.
+ * </p>
+ *
+ * @param inputStream
+ * The input stream.
+ * @param outputStream
+ * The output stream.
+ * @throws IOException
+ * If an I/O error occurs.
+ */
+ public static void encode(InputStream inputStream, OutputStream outputStream)
+ throws IOException {
+ encode(inputStream, outputStream, 0);
+ }
+
+ /**
+ * <p>
+ * Encodes data from the given input stream and writes them in the given
+ * output stream, wrapping every encoded line every <em>wrapAt</em>
+ * characters. A <em>wrapAt</em> value less than 1 disables wrapping.
+ * </p>
+ * <p>
+ * The supplied input stream is read until its end is reached, but it's not
+ * closed by this method.
+ * </p>
+ * <p>
+ * The supplied output stream is nor flushed neither closed by this method.
+ * </p>
+ *
+ * @param inputStream
+ * The input stream from which clear data are read.
+ * @param outputStream
+ * The output stream in which encoded data are written.
+ * @param wrapAt
+ * The max line length for encoded data. If less than 1 no wrap
+ * is applied.
+ * @throws IOException
+ * If an I/O error occurs.
+ */
+ public static void encode(InputStream inputStream,
+ OutputStream outputStream, int wrapAt) throws IOException {
+ Base64OutputStream aux = new Base64OutputStream(outputStream, wrapAt);
+ copy(inputStream, aux);
+ aux.commit();
+ }
+
+ /**
+ * <p>
+ * Decodes data from the given input stream and writes them in the given
+ * output stream.
+ * </p>
+ * <p>
+ * The supplied input stream is read until its end is reached, but it's not
+ * closed by this method.
+ * </p>
+ * <p>
+ * The supplied output stream is nor flushed neither closed by this method.
+ * </p>
+ *
+ * @param inputStream
+ * The input stream from which encoded data are read.
+ * @param outputStream
+ * The output stream in which decoded data are written.
+ * @throws IOException
+ * If an I/O error occurs.
+ */
+ public static void decode(InputStream inputStream, OutputStream outputStream)
+ throws IOException {
+ copy(new Base64InputStream(inputStream), outputStream);
+ }
+
+ /**
+ * <p>
+ * Encodes data from the given source file contents and writes them in the
+ * given target file, wrapping every encoded line every <em>wrapAt</em>
+ * characters. A <em>wrapAt</em> value less than 1 disables wrapping.
+ * </p>
+ *
+ * @param source
+ * The source file, from which decoded data are read.
+ * @param target
+ * The target file, in which encoded data are written.
+ * @param wrapAt
+ * The max line length for encoded data. If less than 1 no wrap
+ * is applied.
+ * @throws IOException
+ * If an I/O error occurs.
+ * @since 1.3
+ */
+ public static void encode(File source, File target, int wrapAt)
+ throws IOException {
+ InputStream inputStream = null;
+ OutputStream outputStream = null;
+ try {
+ inputStream = new FileInputStream(source);
+ outputStream = new FileOutputStream(target);
+ Base64.encode(inputStream, outputStream, wrapAt);
+ } finally {
+ if (outputStream != null) {
+ try {
+ outputStream.close();
+ } catch (Throwable t) {
+ ;
+ }
+ }
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (Throwable t) {
+ ;
+ }
+ }
+ }
+ }
+
+ /**
+ * <p>
+ * Encodes data from the given source file contents and writes them in the
+ * given target file.
+ * </p>
+ *
+ * @param source
+ * The source file, from which decoded data are read.
+ * @param target
+ * The target file, in which encoded data are written.
+ * @throws IOException
+ * If an I/O error occurs.
+ * @since 1.3
+ */
+ public static void encode(File source, File target) throws IOException {
+ InputStream inputStream = null;
+ OutputStream outputStream = null;
+ try {
+ inputStream = new FileInputStream(source);
+ outputStream = new FileOutputStream(target);
+ Base64.encode(inputStream, outputStream);
+ } finally {
+ if (outputStream != null) {
+ try {
+ outputStream.close();
+ } catch (Throwable t) {
+ ;
+ }
+ }
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (Throwable t) {
+ ;
+ }
+ }
+ }
+ }
+
+ /**
+ * <p>
+ * Decodes data from the given source file contents and writes them in the
+ * given target file.
+ * </p>
+ *
+ * @param source
+ * The source file, from which encoded data are read.
+ * @param target
+ * The target file, in which decoded data are written.
+ * @throws IOException
+ * If an I/O error occurs.
+ * @since 1.3
+ */
+ public static void decode(File source, File target) throws IOException {
+ InputStream inputStream = null;
+ OutputStream outputStream = null;
+ try {
+ inputStream = new FileInputStream(source);
+ outputStream = new FileOutputStream(target);
+ decode(inputStream, outputStream);
+ } finally {
+ if (outputStream != null) {
+ try {
+ outputStream.close();
+ } catch (Throwable t) {
+ ;
+ }
+ }
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (Throwable t) {
+ ;
+ }
+ }
+ }
+ }
+
+ /**
+ * Copies data from a stream to another.
+ *
+ * @param inputStream
+ * The input stream.
+ * @param outputStream
+ * The output stream.
+ * @throws IOException
+ * If a unexpected I/O error occurs.
+ */
+ private static void copy(InputStream inputStream, OutputStream outputStream)
+ throws IOException {
+ // 1KB buffer
+ byte[] b = new byte[1024];
+ int len;
+ while ((len = inputStream.read(b)) != -1) {
+ outputStream.write(b, 0, len);
+ }
+ }
+
+}
-/*\r
- * Java Base64 - A pure Java library for reading and writing Base64\r
- * encoded streams.\r
- * \r
- * Copyright (C) 2007-2009 Carlo Pelliccia (www.sauronsoftware.it)\r
- * \r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License version\r
- * 2.1, as published by the Free Software Foundation.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Lesser General Public\r
- * License version 2.1 along with this program.\r
- * If not, see <http://www.gnu.org/licenses/>.\r
- */\r
-package com.yuji.ec.base64;\r
-\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-\r
-/**\r
- * <p>\r
- * A base64 encoding input stream.\r
- * </p>\r
- * \r
- * <p>\r
- * A <em>Base64InputStream</em> reads from an underlying stream which is\r
- * supposed to be a base64 encoded stream. <em>Base64InputStream</em> decodes\r
- * the data read from the underlying stream and returns the decoded bytes to the\r
- * caller.\r
- * </p>\r
- * \r
- * @author Carlo Pelliccia\r
- */\r
-public class Base64InputStream extends InputStream {\r
-\r
- /**\r
- * The underlying stream.\r
- */\r
- private InputStream inputStream;\r
-\r
- /**\r
- * The buffer.\r
- */\r
- private int[] buffer;\r
-\r
- /**\r
- * A counter for values in the buffer.\r
- */\r
- private int bufferCounter = 0;\r
-\r
- /**\r
- * End-of-stream flag.\r
- */\r
- private boolean eof = false;\r
-\r
- /**\r
- * <p>\r
- * It builds a base64 decoding input stream.\r
- * </p>\r
- * \r
- * @param inputStream\r
- * The underlying stream, from which the encoded data is read.\r
- */\r
- public Base64InputStream(InputStream inputStream) {\r
- this.inputStream = inputStream;\r
- }\r
-\r
- public int read() throws IOException {\r
- if (buffer == null || bufferCounter == buffer.length) {\r
- if (eof) {\r
- return -1;\r
- }\r
- acquire();\r
- if (buffer.length == 0) {\r
- buffer = null;\r
- return -1;\r
- }\r
- bufferCounter = 0;\r
- }\r
- return buffer[bufferCounter++];\r
- }\r
-\r
- /**\r
- * Reads from the underlying stream, decodes the data and puts the decoded\r
- * bytes into the buffer.\r
- */\r
- private void acquire() throws IOException {\r
- char[] four = new char[4];\r
- int i = 0;\r
- do {\r
- int b = inputStream.read();\r
- if (b == -1) {\r
- if (i != 0) {\r
- throw new IOException("Bad base64 stream");\r
- } else {\r
- buffer = new int[0];\r
- eof = true;\r
- return;\r
- }\r
- }\r
- char c = (char) b;\r
- if (Shared.chars.indexOf(c) != -1 || c == Shared.pad) {\r
- four[i++] = c;\r
- } else if (c != '\r' && c != '\n') {\r
- throw new IOException("Bad base64 stream");\r
- }\r
- } while (i < 4);\r
- boolean padded = false;\r
- for (i = 0; i < 4; i++) {\r
- if (four[i] != Shared.pad) {\r
- if (padded) {\r
- throw new IOException("Bad base64 stream");\r
- }\r
- } else {\r
- if (!padded) {\r
- padded = true;\r
- }\r
- }\r
- }\r
- int l;\r
- if (four[3] == Shared.pad) {\r
- if (inputStream.read() != -1) {\r
- throw new IOException("Bad base64 stream");\r
- }\r
- eof = true;\r
- if (four[2] == Shared.pad) {\r
- l = 1;\r
- } else {\r
- l = 2;\r
- }\r
- } else {\r
- l = 3;\r
- }\r
- int aux = 0;\r
- for (i = 0; i < 4; i++) {\r
- if (four[i] != Shared.pad) {\r
- aux = aux | (Shared.chars.indexOf(four[i]) << (6 * (3 - i)));\r
- }\r
- }\r
- buffer = new int[l];\r
- for (i = 0; i < l; i++) {\r
- buffer[i] = (aux >>> (8 * (2 - i))) & 0xFF;\r
- }\r
- }\r
-\r
- public void close() throws IOException {\r
- inputStream.close();\r
- }\r
+/*
+ * Java Base64 - A pure Java library for reading and writing Base64
+ * encoded streams.
+ *
+ * Copyright (C) 2007-2009 Carlo Pelliccia (www.sauronsoftware.it)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version
+ * 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License version 2.1 along with this program.
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.yuji.ec.base64;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * <p>
+ * A base64 encoding input stream.
+ * </p>
+ *
+ * <p>
+ * A <em>Base64InputStream</em> reads from an underlying stream which is
+ * supposed to be a base64 encoded stream. <em>Base64InputStream</em> decodes
+ * the data read from the underlying stream and returns the decoded bytes to the
+ * caller.
+ * </p>
+ *
+ * @author Carlo Pelliccia
+ */
+public class Base64InputStream extends InputStream {
+
+ /**
+ * The underlying stream.
+ */
+ private InputStream inputStream;
+
+ /**
+ * The buffer.
+ */
+ private int[] buffer;
+
+ /**
+ * A counter for values in the buffer.
+ */
+ private int bufferCounter = 0;
+
+ /**
+ * End-of-stream flag.
+ */
+ private boolean eof = false;
+
+ /**
+ * <p>
+ * It builds a base64 decoding input stream.
+ * </p>
+ *
+ * @param inputStream
+ * The underlying stream, from which the encoded data is read.
+ */
+ public Base64InputStream(InputStream inputStream) {
+ this.inputStream = inputStream;
+ }
+
+ public int read() throws IOException {
+ if (buffer == null || bufferCounter == buffer.length) {
+ if (eof) {
+ return -1;
+ }
+ acquire();
+ if (buffer.length == 0) {
+ buffer = null;
+ return -1;
+ }
+ bufferCounter = 0;
+ }
+ return buffer[bufferCounter++];
+ }
+
+ /**
+ * Reads from the underlying stream, decodes the data and puts the decoded
+ * bytes into the buffer.
+ */
+ private void acquire() throws IOException {
+ char[] four = new char[4];
+ int i = 0;
+ do {
+ int b = inputStream.read();
+ if (b == -1) {
+ if (i != 0) {
+ throw new IOException("Bad base64 stream");
+ } else {
+ buffer = new int[0];
+ eof = true;
+ return;
+ }
+ }
+ char c = (char) b;
+ if (Shared.chars.indexOf(c) != -1 || c == Shared.pad) {
+ four[i++] = c;
+ } else if (c != '\r' && c != '\n') {
+ throw new IOException("Bad base64 stream");
+ }
+ } while (i < 4);
+ boolean padded = false;
+ for (i = 0; i < 4; i++) {
+ if (four[i] != Shared.pad) {
+ if (padded) {
+ throw new IOException("Bad base64 stream");
+ }
+ } else {
+ if (!padded) {
+ padded = true;
+ }
+ }
+ }
+ int l;
+ if (four[3] == Shared.pad) {
+ if (inputStream.read() != -1) {
+ throw new IOException("Bad base64 stream");
+ }
+ eof = true;
+ if (four[2] == Shared.pad) {
+ l = 1;
+ } else {
+ l = 2;
+ }
+ } else {
+ l = 3;
+ }
+ int aux = 0;
+ for (i = 0; i < 4; i++) {
+ if (four[i] != Shared.pad) {
+ aux = aux | (Shared.chars.indexOf(four[i]) << (6 * (3 - i)));
+ }
+ }
+ buffer = new int[l];
+ for (i = 0; i < l; i++) {
+ buffer[i] = (aux >>> (8 * (2 - i))) & 0xFF;
+ }
+ }
+
+ public void close() throws IOException {
+ inputStream.close();
+ }
}
\ No newline at end of file
-/*\r
- * Java Base64 - A pure Java library for reading and writing Base64\r
- * encoded streams.\r
- * \r
- * Copyright (C) 2007-2009 Carlo Pelliccia (www.sauronsoftware.it)\r
- * \r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License version\r
- * 2.1, as published by the Free Software Foundation.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Lesser General Public\r
- * License version 2.1 along with this program.\r
- * If not, see <http://www.gnu.org/licenses/>.\r
- */\r
-package com.yuji.ec.base64;\r
-\r
-import java.io.IOException;\r
-import java.io.OutputStream;\r
-\r
-/**\r
- * <p>\r
- * A base64 decoding output stream.\r
- * </p>\r
- * \r
- * <p>\r
- * It encodes in base64 everything passed to the stream, and it puts the encoded\r
- * data into the underlying stream.\r
- * </p>\r
- * \r
- * @author Carlo Pelliccia\r
- */\r
-public class Base64OutputStream extends OutputStream {\r
-\r
- /**\r
- * The underlying stream.\r
- */\r
- private OutputStream outputStream = null;\r
-\r
- /**\r
- * A value buffer.\r
- */\r
- private int buffer = 0;\r
-\r
- /**\r
- * How many bytes are currently in the value buffer?\r
- */\r
- private int bytecounter = 0;\r
-\r
- /**\r
- * A counter for the current line length.\r
- */\r
- private int linecounter = 0;\r
-\r
- /**\r
- * The requested line length.\r
- */\r
- private int linelength = 0;\r
-\r
- /**\r
- * <p>\r
- * It builds a base64 encoding output stream writing the encoded data in the\r
- * given underlying stream.\r
- * </p>\r
- * \r
- * <p>\r
- * The encoded data is wrapped to a new line (with a CRLF sequence) every 76\r
- * bytes sent to the underlying stream.\r
- * </p>\r
- * \r
- * @param outputStream\r
- * The underlying stream.\r
- */\r
- public Base64OutputStream(OutputStream outputStream) {\r
- this(outputStream, 76);\r
- }\r
-\r
- /**\r
- * <p>\r
- * It builds a base64 encoding output stream writing the encoded data in the\r
- * given underlying stream.\r
- * </p>\r
- * \r
- * <p>\r
- * The encoded data is wrapped to a new line (with a CRLF sequence) every\r
- * <em>wrapAt</em> bytes sent to the underlying stream. If the\r
- * <em>wrapAt</em> supplied value is less than 1 the encoded data will not\r
- * be wrapped.\r
- * </p>\r
- * \r
- * @param outputStream\r
- * The underlying stream.\r
- * @param wrapAt\r
- * The max line length for encoded data. If less than 1 no wrap\r
- * is applied.\r
- */\r
- public Base64OutputStream(OutputStream outputStream, int wrapAt) {\r
- this.outputStream = outputStream;\r
- this.linelength = wrapAt;\r
- }\r
-\r
- public void write(int b) throws IOException {\r
- int value = (b & 0xFF) << (16 - (bytecounter * 8));\r
- buffer = buffer | value;\r
- bytecounter++;\r
- if (bytecounter == 3) {\r
- commit();\r
- }\r
- }\r
-\r
- public void close() throws IOException {\r
- commit();\r
- outputStream.close();\r
- }\r
-\r
- /**\r
- * <p>\r
- * It commits 4 bytes to the underlying stream.\r
- * </p>\r
- */\r
- protected void commit() throws IOException {\r
- if (bytecounter > 0) {\r
- if (linelength > 0 && linecounter == linelength) {\r
- outputStream.write("\r\n".getBytes());\r
- linecounter = 0;\r
- }\r
- char b1 = Shared.chars.charAt((buffer << 8) >>> 26);\r
- char b2 = Shared.chars.charAt((buffer << 14) >>> 26);\r
- char b3 = (bytecounter < 2) ? Shared.pad : Shared.chars.charAt((buffer << 20) >>> 26);\r
- char b4 = (bytecounter < 3) ? Shared.pad : Shared.chars.charAt((buffer << 26) >>> 26);\r
- outputStream.write(b1);\r
- outputStream.write(b2);\r
- outputStream.write(b3);\r
- outputStream.write(b4);\r
- linecounter += 4;\r
- bytecounter = 0;\r
- buffer = 0;\r
- }\r
- }\r
-\r
+/*
+ * Java Base64 - A pure Java library for reading and writing Base64
+ * encoded streams.
+ *
+ * Copyright (C) 2007-2009 Carlo Pelliccia (www.sauronsoftware.it)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version
+ * 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License version 2.1 along with this program.
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.yuji.ec.base64;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * <p>
+ * A base64 decoding output stream.
+ * </p>
+ *
+ * <p>
+ * It encodes in base64 everything passed to the stream, and it puts the encoded
+ * data into the underlying stream.
+ * </p>
+ *
+ * @author Carlo Pelliccia
+ */
+public class Base64OutputStream extends OutputStream {
+
+ /**
+ * The underlying stream.
+ */
+ private OutputStream outputStream = null;
+
+ /**
+ * A value buffer.
+ */
+ private int buffer = 0;
+
+ /**
+ * How many bytes are currently in the value buffer?
+ */
+ private int bytecounter = 0;
+
+ /**
+ * A counter for the current line length.
+ */
+ private int linecounter = 0;
+
+ /**
+ * The requested line length.
+ */
+ private int linelength = 0;
+
+ /**
+ * <p>
+ * It builds a base64 encoding output stream writing the encoded data in the
+ * given underlying stream.
+ * </p>
+ *
+ * <p>
+ * The encoded data is wrapped to a new line (with a CRLF sequence) every 76
+ * bytes sent to the underlying stream.
+ * </p>
+ *
+ * @param outputStream
+ * The underlying stream.
+ */
+ public Base64OutputStream(OutputStream outputStream) {
+ this(outputStream, 76);
+ }
+
+ /**
+ * <p>
+ * It builds a base64 encoding output stream writing the encoded data in the
+ * given underlying stream.
+ * </p>
+ *
+ * <p>
+ * The encoded data is wrapped to a new line (with a CRLF sequence) every
+ * <em>wrapAt</em> bytes sent to the underlying stream. If the
+ * <em>wrapAt</em> supplied value is less than 1 the encoded data will not
+ * be wrapped.
+ * </p>
+ *
+ * @param outputStream
+ * The underlying stream.
+ * @param wrapAt
+ * The max line length for encoded data. If less than 1 no wrap
+ * is applied.
+ */
+ public Base64OutputStream(OutputStream outputStream, int wrapAt) {
+ this.outputStream = outputStream;
+ this.linelength = wrapAt;
+ }
+
+ public void write(int b) throws IOException {
+ int value = (b & 0xFF) << (16 - (bytecounter * 8));
+ buffer = buffer | value;
+ bytecounter++;
+ if (bytecounter == 3) {
+ commit();
+ }
+ }
+
+ public void close() throws IOException {
+ commit();
+ outputStream.close();
+ }
+
+ /**
+ * <p>
+ * It commits 4 bytes to the underlying stream.
+ * </p>
+ */
+ protected void commit() throws IOException {
+ if (bytecounter > 0) {
+ if (linelength > 0 && linecounter == linelength) {
+ outputStream.write("\r\n".getBytes());
+ linecounter = 0;
+ }
+ char b1 = Shared.chars.charAt((buffer << 8) >>> 26);
+ char b2 = Shared.chars.charAt((buffer << 14) >>> 26);
+ char b3 = (bytecounter < 2) ? Shared.pad : Shared.chars.charAt((buffer << 20) >>> 26);
+ char b4 = (bytecounter < 3) ? Shared.pad : Shared.chars.charAt((buffer << 26) >>> 26);
+ outputStream.write(b1);
+ outputStream.write(b2);
+ outputStream.write(b3);
+ outputStream.write(b4);
+ linecounter += 4;
+ bytecounter = 0;
+ buffer = 0;
+ }
+ }
+
}
\ No newline at end of file
-/*\r
- * Java Base64 - A pure Java library for reading and writing Base64\r
- * encoded streams.\r
- * \r
- * Copyright (C) 2007-2009 Carlo Pelliccia (www.sauronsoftware.it)\r
- * \r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License version\r
- * 2.1, as published by the Free Software Foundation.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Lesser General Public\r
- * License version 2.1 along with this program.\r
- * If not, see <http://www.gnu.org/licenses/>.\r
- */\r
-package com.yuji.ec.base64;\r
-\r
-/**\r
- * Package related utilities.\r
- * \r
- * @author Carlo Pelliccia\r
- */\r
-class Shared {\r
-\r
- static String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";\r
-\r
- static char pad = '=';\r
-\r
+/*
+ * Java Base64 - A pure Java library for reading and writing Base64
+ * encoded streams.
+ *
+ * Copyright (C) 2007-2009 Carlo Pelliccia (www.sauronsoftware.it)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version
+ * 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License version 2.1 along with this program.
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.yuji.ec.base64;
+
+/**
+ * Package related utilities.
+ *
+ * @author Carlo Pelliccia
+ */
+class Shared {
+
+ static String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+ static char pad = '=';
+
}
\ No newline at end of file
-<html>\r
-<body>\r
-<p>Base64 encoders and decoders.</p>\r
-</body>\r
-</html>\r
+<html>
+<body>
+<p>Base64 encoders and decoders.</p>
+</body>
+</html>
-package com.yuji.ec.db;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import android.content.Context;\r
-import android.database.sqlite.SQLiteDatabase;\r
-import android.database.sqlite.SQLiteOpenHelper;\r
-\r
-import com.yuji.ec.utility.Debug;\r
-\r
-public class DatabaseHelper extends SQLiteOpenHelper {\r
- private static DatabaseHelper instance = null;\r
- private static List<IDao<?>> daoList = null;\r
-\r
- public static DatabaseHelper getInstance() {\r
- return instance;\r
- }\r
-\r
- public static void init(Context context) {\r
- if (instance != null) {\r
- return;\r
- }\r
- daoList = new ArrayList<IDao<?>>();\r
- daoList.add(NoteDao.getInstance());\r
-\r
- DatabaseHelper helper = new DatabaseHelper(context);\r
- SQLiteDatabase db = helper.getWritableDatabase();\r
-\r
- for (IDao<?> dao : daoList) {\r
- dao.init(db);\r
- }\r
- }\r
-\r
- public DatabaseHelper(Context context) {\r
- super(context, "EverClip.db", null, 1);\r
- instance = this;\r
- }\r
-\r
- @Override\r
- public void onCreate(SQLiteDatabase db) {\r
- try {\r
- for (IDao<?> dao : daoList) {\r
- dao.onCreate(db);\r
- dao.init(db);\r
- }\r
-\r
- db.beginTransaction();\r
- try {\r
- for (IDao<?> dao : daoList) {\r
- dao.start(db);\r
- }\r
- db.setTransactionSuccessful();\r
- } finally {\r
- db.endTransaction();\r
- }\r
- } catch (Exception e) {\r
- Debug.d(this, null, e);\r
- }\r
- }\r
-\r
- @Override\r
- public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {\r
-\r
- }\r
-\r
-}\r
+package com.yuji.ec.db;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+
+import com.yuji.ec.utility.Debug;
+
+public class DatabaseHelper extends SQLiteOpenHelper {
+ private static DatabaseHelper instance = null;
+ private static List<IDao<?>> daoList = null;
+
+ public static DatabaseHelper getInstance() {
+ return instance;
+ }
+
+ public static void init(Context context) {
+ if (instance != null) {
+ return;
+ }
+ daoList = new ArrayList<IDao<?>>();
+ daoList.add(NoteDao.getInstance());
+
+ DatabaseHelper helper = new DatabaseHelper(context);
+ SQLiteDatabase db = helper.getWritableDatabase();
+
+ for (IDao<?> dao : daoList) {
+ dao.init(db);
+ }
+ }
+
+ public DatabaseHelper(Context context) {
+ super(context, "EverClip.db", null, 1);
+ instance = this;
+ }
+
+ @Override
+ public void onCreate(SQLiteDatabase db) {
+ try {
+ for (IDao<?> dao : daoList) {
+ dao.onCreate(db);
+ dao.init(db);
+ }
+
+ db.beginTransaction();
+ try {
+ for (IDao<?> dao : daoList) {
+ dao.start(db);
+ }
+ db.setTransactionSuccessful();
+ } finally {
+ db.endTransaction();
+ }
+ } catch (Exception e) {
+ Debug.d(this, null, e);
+ }
+ }
+
+ @Override
+ public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
+
+ }
+
+}
-package com.yuji.ec.db;\r
-\r
-import java.util.List;\r
-\r
-import android.database.sqlite.SQLiteDatabase;\r
-\r
-public interface IDao<T> {\r
- public void onCreate(SQLiteDatabase db);\r
- public void init(SQLiteDatabase db);\r
- public void start(SQLiteDatabase db);\r
- public List<Note> search();\r
- public void add(T arg0);\r
+package com.yuji.ec.db;
+
+import java.util.List;
+
+import android.database.sqlite.SQLiteDatabase;
+
+public interface IDao<T> {
+ public void onCreate(SQLiteDatabase db);
+ public void init(SQLiteDatabase db);
+ public void start(SQLiteDatabase db);
+ public List<Note> search();
+ public void add(T arg0);
}
\ No newline at end of file
-package com.yuji.ec.db;\r
-\r
-public interface INoteItem {\r
- String getGuid();\r
- String getText();\r
-}\r
+package com.yuji.ec.db;
+
+public interface INoteItem {
+ String getGuid();
+ String getText();
+}
-package com.yuji.ec.db;\r
-\r
-public class Note implements INoteItem {\r
- private long id = -1;\r
- private String guid;\r
- private String text;\r
- private long created;\r
- private long updated;\r
- \r
- public Note(long id, String guid, String text, long created, long updated){\r
- this.id = id;\r
- this.guid = guid;\r
- this.text = text;\r
- this.created = created;\r
- this.updated = updated;\r
- }\r
-\r
- public Note(String guid, String text, long created, long updated){\r
- this(-1, guid, text, created, updated);\r
- }\r
-\r
- public long getId(){\r
- return id;\r
- }\r
- \r
- public String getGuid() {\r
- return guid;\r
- }\r
-\r
- public String getText() {\r
- return text;\r
- }\r
-\r
- public long getCreated() {\r
- return created;\r
- }\r
-\r
- public long getUpdated() {\r
- return updated;\r
- }\r
-}\r
+package com.yuji.ec.db;
+
+public class Note implements INoteItem {
+ private long id = -1;
+ private String guid;
+ private String text;
+ private long created;
+ private long updated;
+
+ public Note(long id, String guid, String text, long created, long updated){
+ this.id = id;
+ this.guid = guid;
+ this.text = text;
+ this.created = created;
+ this.updated = updated;
+ }
+
+ public Note(String guid, String text, long created, long updated){
+ this(-1, guid, text, created, updated);
+ }
+
+ public long getId(){
+ return id;
+ }
+
+ public String getGuid() {
+ return guid;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public long getCreated() {
+ return created;
+ }
+
+ public long getUpdated() {
+ return updated;
+ }
+}
-package com.yuji.ec.db;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import android.database.Cursor;\r
-import android.database.SQLException;\r
-import android.database.sqlite.SQLiteDatabase;\r
-import android.database.sqlite.SQLiteStatement;\r
-\r
-import com.yuji.ec.utility.Debug;\r
-\r
-public class NoteDao implements IDao<Note> {\r
- private static IDao<Note> instance = null;\r
- private SQLiteStatement insertStmt = null;\r
- private SQLiteStatement deleteStmt = null;\r
-\r
- public static IDao<Note> getInstance(){\r
- if (instance == null){\r
- instance = new NoteDao();\r
- }\r
- return instance;\r
- } \r
- \r
- private NoteDao(){\r
-\r
- }\r
- \r
- public void onCreate(SQLiteDatabase db) {\r
- db.execSQL(\r
- "CREATE TABLE NOTE ("\r
- + android.provider.BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"\r
- + "GUID TEXT,"\r
- + "TEXT TEXT,"\r
- + "CREATED INTEGER,"\r
- + "UPDATED INTEGER"\r
- + ");");\r
- }\r
- \r
- public void init(SQLiteDatabase db) {\r
- insertStmt = db.compileStatement(\r
- "INSERT INTO NOTE ("\r
- + "GUID,"\r
- + "TEXT,"\r
- + "CREATED,"\r
- + "UPDATED"\r
- + ") VALUES ("\r
- + "?,?,?,?"\r
- + ");"); \r
- deleteStmt = db.compileStatement(\r
- "DELETE FROM NOTE");\r
- }\r
- \r
- public void start(SQLiteDatabase db) {\r
-\r
- }\r
-\r
- public List<Note> search(){\r
- return search(null, null, null);\r
- }\r
- \r
- private List<Note> search(String selection, String[] selectionArgs, String orderBy){\r
- List<Note> list = new ArrayList<Note>();\r
- Cursor cursor = null;\r
- try {\r
- DatabaseHelper helper = DatabaseHelper.getInstance();\r
- SQLiteDatabase db = helper.getReadableDatabase();\r
-\r
- cursor = db.query(\r
- "NOTE",\r
- new String[] {\r
- android.provider.BaseColumns._ID, "GUID", "TEXT", "CREATED", "UPDATED"},\r
- selection, selectionArgs, null, null, orderBy);\r
- cursor.moveToFirst();\r
- int size = cursor.getCount();\r
- for (int i = 0; i < size; i++) {\r
- Note note = new Note(\r
- cursor.getLong(0),\r
- cursor.getString(1),\r
- cursor.getString(2),\r
- cursor.getLong(3),\r
- cursor.getLong(4));\r
- list.add(note);\r
- cursor.moveToNext();\r
- }\r
- } catch (SQLException e){\r
- Debug.d(this, null, e);\r
- list = null;\r
- } catch (Exception e){\r
- Debug.d(this, null, e);\r
- list = null;\r
- }\r
- finally {\r
- if (cursor != null){\r
- cursor.close(); \r
- cursor = null; \r
- }\r
- }\r
- return list;\r
- }\r
-\r
- public boolean isEmpty(){\r
- List<Note> list = search();\r
- return list == null || list.size() <= 0;\r
- }\r
- \r
- public void add(Note note) {\r
- DatabaseHelper helper = DatabaseHelper.getInstance();\r
- SQLiteDatabase db = helper.getWritableDatabase();\r
- add(db, note);\r
- }\r
- \r
- private long add(SQLiteDatabase db, Note note) {\r
- long id = -1;\r
- db.beginTransaction();\r
- try {\r
- id = addNT(note);\r
- db.setTransactionSuccessful();\r
- } finally {\r
- db.endTransaction();\r
- }\r
- return id;\r
- }\r
- \r
- public long addNT(Note note) {\r
- long id = -1;\r
- int i = 1;\r
- SQLiteStatement stmt = insertStmt;\r
- stmt.bindString(i++, note.getGuid());\r
- stmt.bindString(i++, note.getText());\r
- stmt.bindLong(i++, note.getCreated());\r
- stmt.bindLong(i++, note.getUpdated());\r
- id = stmt.executeInsert();\r
- return id;\r
- }\r
-\r
- public void deleteNT() {\r
- SQLiteStatement stmt = deleteStmt;\r
- stmt.execute();\r
- }\r
-}\r
+package com.yuji.ec.db;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.database.Cursor;
+import android.database.SQLException;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteStatement;
+
+import com.yuji.ec.utility.Debug;
+
+public class NoteDao implements IDao<Note> {
+ private static IDao<Note> instance = null;
+ private SQLiteStatement insertStmt = null;
+ private SQLiteStatement deleteStmt = null;
+
+ public static IDao<Note> getInstance(){
+ if (instance == null){
+ instance = new NoteDao();
+ }
+ return instance;
+ }
+
+ private NoteDao(){
+
+ }
+
+ public void onCreate(SQLiteDatabase db) {
+ db.execSQL(
+ "CREATE TABLE NOTE ("
+ + android.provider.BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ + "GUID TEXT,"
+ + "TEXT TEXT,"
+ + "CREATED INTEGER,"
+ + "UPDATED INTEGER"
+ + ");");
+ }
+
+ public void init(SQLiteDatabase db) {
+ insertStmt = db.compileStatement(
+ "INSERT INTO NOTE ("
+ + "GUID,"
+ + "TEXT,"
+ + "CREATED,"
+ + "UPDATED"
+ + ") VALUES ("
+ + "?,?,?,?"
+ + ");");
+ deleteStmt = db.compileStatement(
+ "DELETE FROM NOTE");
+ }
+
+ public void start(SQLiteDatabase db) {
+
+ }
+
+ public List<Note> search(){
+ return search(null, null, null);
+ }
+
+ private List<Note> search(String selection, String[] selectionArgs, String orderBy){
+ List<Note> list = new ArrayList<Note>();
+ Cursor cursor = null;
+ try {
+ DatabaseHelper helper = DatabaseHelper.getInstance();
+ SQLiteDatabase db = helper.getReadableDatabase();
+
+ cursor = db.query(
+ "NOTE",
+ new String[] {
+ android.provider.BaseColumns._ID, "GUID", "TEXT", "CREATED", "UPDATED"},
+ selection, selectionArgs, null, null, orderBy);
+ cursor.moveToFirst();
+ int size = cursor.getCount();
+ for (int i = 0; i < size; i++) {
+ Note note = new Note(
+ cursor.getLong(0),
+ cursor.getString(1),
+ cursor.getString(2),
+ cursor.getLong(3),
+ cursor.getLong(4));
+ list.add(note);
+ cursor.moveToNext();
+ }
+ } catch (SQLException e){
+ Debug.d(this, null, e);
+ list = null;
+ } catch (Exception e){
+ Debug.d(this, null, e);
+ list = null;
+ }
+ finally {
+ if (cursor != null){
+ cursor.close();
+ cursor = null;
+ }
+ }
+ return list;
+ }
+
+ public boolean isEmpty(){
+ List<Note> list = search();
+ return list == null || list.size() <= 0;
+ }
+
+ public void add(Note note) {
+ DatabaseHelper helper = DatabaseHelper.getInstance();
+ SQLiteDatabase db = helper.getWritableDatabase();
+ add(db, note);
+ }
+
+ private long add(SQLiteDatabase db, Note note) {
+ long id = -1;
+ db.beginTransaction();
+ try {
+ id = addNT(note);
+ db.setTransactionSuccessful();
+ } finally {
+ db.endTransaction();
+ }
+ return id;
+ }
+
+ public long addNT(Note note) {
+ long id = -1;
+ int i = 1;
+ SQLiteStatement stmt = insertStmt;
+ stmt.bindString(i++, note.getGuid());
+ stmt.bindString(i++, note.getText());
+ stmt.bindLong(i++, note.getCreated());
+ stmt.bindLong(i++, note.getUpdated());
+ id = stmt.executeInsert();
+ return id;
+ }
+
+ public void deleteNT() {
+ SQLiteStatement stmt = deleteStmt;
+ stmt.execute();
+ }
+}
-package com.yuji.ec.service;\r
-\r
-import java.util.Calendar;\r
-\r
-import android.app.AlarmManager;\r
-import android.app.PendingIntent;\r
-import android.app.Service;\r
-import android.content.Context;\r
-import android.content.Intent;\r
-import android.os.Binder;\r
-import android.os.IBinder;\r
-import android.widget.Toast;\r
-\r
-import com.yuji.ec.Initialize;\r
-import com.yuji.ec.common.Constant;\r
-import com.yuji.ec.utility.DateUtil;\r
-import com.yuji.ec.utility.Debug;\r
-import com.yuji.ec.utility.EditPrefUtil;\r
-import com.yuji.ec.utility.NetworkUtil;\r
-import com.yuji.ec.utility.NoteUpdator;\r
-\r
-public class NoteUpdatorService extends Service {\r
- private static final boolean DEBUG = false;\r
-\r
- public class KitchenTimerBinder extends Binder {\r
- public NoteUpdatorService getService() {\r
- return NoteUpdatorService.this;\r
- }\r
- }\r
-\r
- public static final String ACTION = "NoteUpdatorService";\r
- public static final String ACTION_START = "START";\r
- private static final int DS = 60;\r
- private EditPrefUtil pref = new EditPrefUtil(this);\r
- private KitchenTimerBinder binder = new KitchenTimerBinder();\r
- private String action = null;\r
-\r
- @Override\r
- public void onCreate() {\r
- super.onCreate();\r
-\r
- if (DEBUG) {\r
- Toast toast = Toast.makeText(getApplicationContext(), "onCreate()",\r
- Toast.LENGTH_SHORT);\r
- toast.show();\r
- }\r
- }\r
-\r
- private Runnable task = new Runnable() {\r
- public void run() {\r
- try {\r
- if (action.equals(ACTION_START)) {\r
- // \8f\89\8aú\8bN\93®\r
- } else {\r
- // \83^\83C\83}\81[\8bN\93®\r
- synchronized (binder) {\r
- try {\r
- execute();\r
- } catch (Exception e) {\r
- Debug.d(this, null, e);\r
- }\r
- }\r
- }\r
-\r
- setNextTime(NoteUpdatorService.this);\r
- } finally {\r
- NoteUpdatorService.this.stopSelf();\r
- }\r
- }\r
-\r
- private void execute() {\r
- if (!NetworkUtil\r
- .isConnected(NoteUpdatorService.this)){\r
- return;\r
- }\r
- \r
- Initialize.initialize(NoteUpdatorService.this);\r
- Initialize.initialize(NoteUpdatorService.this, "");\r
- \r
- int noteItemType = pref.getInt(Constant.PREF_NOTE_ITEM_TYPE,\r
- Constant.NOTE_ITEM_TYPE_ALL);\r
- String guid = pref.get(Constant.PREF_NOTE_ITEM_GUID);\r
-\r
- NoteUpdator updator = NoteUpdator.getInstance();\r
- updator.update(NoteUpdatorService.this, noteItemType, guid);\r
- \r
- Intent intent = new Intent(Constant.ACTION_UPDATE);\r
- sendBroadcast(intent);\r
- }\r
- };\r
-\r
- @Override\r
- public void onStart(Intent intent, int startId) {\r
- super.onStart(intent, startId);\r
-\r
- action = intent.getAction();\r
- action = (action == null) ? "" : action;\r
-\r
- if (DEBUG) {\r
- Toast toast = Toast.makeText(getApplicationContext(), "onStart() "\r
- + action + " " + startId, Toast.LENGTH_SHORT);\r
- toast.show();\r
- }\r
-\r
- Thread thread = new Thread(null, task, "AlarmService_Service");\r
- thread.start();\r
- }\r
-\r
- @Override\r
- public void onDestroy() {\r
- super.onDestroy();\r
-\r
- if (DEBUG) {\r
- Toast toast = Toast.makeText(getApplicationContext(),\r
- "onDestroy()", Toast.LENGTH_SHORT);\r
- toast.show();\r
- }\r
- }\r
-\r
- @Override\r
- public IBinder onBind(Intent intent) {\r
- if (DEBUG) {\r
- Toast toast = Toast.makeText(getApplicationContext(), "onBind()",\r
- Toast.LENGTH_SHORT);\r
- toast.show();\r
- }\r
-\r
- return binder;\r
- }\r
-\r
- @Override\r
- public void onRebind(Intent intent) {\r
- if (DEBUG) {\r
- Toast toast = Toast.makeText(getApplicationContext(), "onRebind()",\r
- Toast.LENGTH_SHORT);\r
- toast.show();\r
- }\r
- }\r
-\r
- @Override\r
- public boolean onUnbind(Intent intent) {\r
- if (DEBUG) {\r
- Toast toast = Toast.makeText(getApplicationContext(), "onUnbind()",\r
- Toast.LENGTH_SHORT);\r
- toast.show();\r
- }\r
- return true;\r
- }\r
-\r
- public static void setNextTime(Context context) {\r
- EditPrefUtil pref = new EditPrefUtil(context);\r
-\r
- long updateTime = pref.getLong(Constant.PREF_UPDATE_TIME);\r
- Calendar cal = Calendar.getInstance();\r
- cal.setTimeInMillis(updateTime);\r
- int h = cal.get(Calendar.HOUR_OF_DAY);\r
- int m = cal.get(Calendar.MINUTE);\r
- int s = cal.get(Calendar.SECOND);\r
-\r
- s = 0;\r
- long t = DateUtil.next(h, m, s, DS);\r
- PendingIntent alarmSender = PendingIntent.getService(context, 0,\r
- new Intent(context,\r
- NoteUpdatorService.class), 0);\r
- AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);\r
- am.set(AlarmManager.RTC, t, alarmSender);\r
- }\r
- \r
- public static void stopService(Context context) {\r
- PendingIntent alarmSender = PendingIntent.getService(context, 0,\r
- new Intent(context, NoteUpdatorService.class),\r
- PendingIntent.FLAG_CANCEL_CURRENT);\r
- }\r
-\r
- public static boolean isSetAlarmSender(Context context) {\r
- PendingIntent alarmSender = PendingIntent.getService(context, 0,\r
- new Intent(context, NoteUpdatorService.class),\r
- PendingIntent.FLAG_NO_CREATE);\r
- return alarmSender != null;\r
- }\r
- \r
- public static void init(Context context){\r
- EditPrefUtil pref = new EditPrefUtil(context);\r
-\r
- boolean isSet = NoteUpdatorService.isSetAlarmSender(context);\r
- int autoUpdate = pref.getInt(Constant.PREF_AUTO_UPDATE);\r
- long updateTime = pref.getLong(Constant.PREF_UPDATE_TIME);\r
- \r
- if (autoUpdate != 0 && updateTime >= 0){\r
- if (!isSet){\r
- // \8dÄ\8bN\93®\8e\9e\r
- setNextTime(context);\r
- }\r
- }\r
- else {\r
- if (isSet){\r
- // \83f\81[\83^\8dí\8f\9c\8e\9e\r
- // isSet\82Í\83N\83\8a\83A\82³\82ê\82È\82¢\82ª\81A\96â\91è\82È\82Ì\82Å\96\88\89ñ\82æ\82Ô\r
- stopService(context);\r
- }\r
- }\r
- }\r
+package com.yuji.ec.service;
+
+import java.util.Calendar;
+
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Binder;
+import android.os.IBinder;
+import android.widget.Toast;
+
+import com.yuji.ec.Initialize;
+import com.yuji.ec.common.Constant;
+import com.yuji.ec.utility.DateUtil;
+import com.yuji.ec.utility.Debug;
+import com.yuji.ec.utility.EditPrefUtil;
+import com.yuji.ec.utility.NetworkUtil;
+import com.yuji.ec.utility.NoteUpdator;
+
+public class NoteUpdatorService extends Service {
+ private static final boolean DEBUG = false;
+
+ public class KitchenTimerBinder extends Binder {
+ public NoteUpdatorService getService() {
+ return NoteUpdatorService.this;
+ }
+ }
+
+ public static final String ACTION = "NoteUpdatorService";
+ public static final String ACTION_START = "START";
+ private static final int DS = 60;
+ private EditPrefUtil pref = new EditPrefUtil(this);
+ private KitchenTimerBinder binder = new KitchenTimerBinder();
+ private String action = null;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+
+ if (DEBUG) {
+ Toast toast = Toast.makeText(getApplicationContext(), "onCreate()",
+ Toast.LENGTH_SHORT);
+ toast.show();
+ }
+ }
+
+ private Runnable task = new Runnable() {
+ public void run() {
+ try {
+ if (action.equals(ACTION_START)) {
+ // 初期起動
+ } else {
+ // タイマー起動
+ synchronized (binder) {
+ try {
+ execute();
+ } catch (Exception e) {
+ Debug.d(this, null, e);
+ }
+ }
+ }
+
+ setNextTime(NoteUpdatorService.this);
+ } finally {
+ NoteUpdatorService.this.stopSelf();
+ }
+ }
+
+ private void execute() {
+ if (!NetworkUtil
+ .isConnected(NoteUpdatorService.this)){
+ return;
+ }
+
+ Initialize.initialize(NoteUpdatorService.this);
+ Initialize.initialize(NoteUpdatorService.this, "");
+
+ int noteItemType = pref.getInt(Constant.PREF_NOTE_ITEM_TYPE,
+ Constant.NOTE_ITEM_TYPE_ALL);
+ String guid = pref.get(Constant.PREF_NOTE_ITEM_GUID);
+
+ NoteUpdator updator = NoteUpdator.getInstance();
+ updator.update(NoteUpdatorService.this, noteItemType, guid);
+
+ Intent intent = new Intent(Constant.ACTION_UPDATE);
+ sendBroadcast(intent);
+ }
+ };
+
+ @Override
+ public void onStart(Intent intent, int startId) {
+ super.onStart(intent, startId);
+
+ action = intent.getAction();
+ action = (action == null) ? "" : action;
+
+ if (DEBUG) {
+ Toast toast = Toast.makeText(getApplicationContext(), "onStart() "
+ + action + " " + startId, Toast.LENGTH_SHORT);
+ toast.show();
+ }
+
+ Thread thread = new Thread(null, task, "AlarmService_Service");
+ thread.start();
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+
+ if (DEBUG) {
+ Toast toast = Toast.makeText(getApplicationContext(),
+ "onDestroy()", Toast.LENGTH_SHORT);
+ toast.show();
+ }
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ if (DEBUG) {
+ Toast toast = Toast.makeText(getApplicationContext(), "onBind()",
+ Toast.LENGTH_SHORT);
+ toast.show();
+ }
+
+ return binder;
+ }
+
+ @Override
+ public void onRebind(Intent intent) {
+ if (DEBUG) {
+ Toast toast = Toast.makeText(getApplicationContext(), "onRebind()",
+ Toast.LENGTH_SHORT);
+ toast.show();
+ }
+ }
+
+ @Override
+ public boolean onUnbind(Intent intent) {
+ if (DEBUG) {
+ Toast toast = Toast.makeText(getApplicationContext(), "onUnbind()",
+ Toast.LENGTH_SHORT);
+ toast.show();
+ }
+ return true;
+ }
+
+ public static void setNextTime(Context context) {
+ EditPrefUtil pref = new EditPrefUtil(context);
+
+ long updateTime = pref.getLong(Constant.PREF_UPDATE_TIME);
+ Calendar cal = Calendar.getInstance();
+ cal.setTimeInMillis(updateTime);
+ int h = cal.get(Calendar.HOUR_OF_DAY);
+ int m = cal.get(Calendar.MINUTE);
+ int s = cal.get(Calendar.SECOND);
+
+ s = 0;
+ long t = DateUtil.next(h, m, s, DS);
+ PendingIntent alarmSender = PendingIntent.getService(context, 0,
+ new Intent(context,
+ NoteUpdatorService.class), 0);
+ AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+ am.set(AlarmManager.RTC, t, alarmSender);
+ }
+
+ public static void stopService(Context context) {
+ PendingIntent alarmSender = PendingIntent.getService(context, 0,
+ new Intent(context, NoteUpdatorService.class),
+ PendingIntent.FLAG_CANCEL_CURRENT);
+ }
+
+ public static boolean isSetAlarmSender(Context context) {
+ PendingIntent alarmSender = PendingIntent.getService(context, 0,
+ new Intent(context, NoteUpdatorService.class),
+ PendingIntent.FLAG_NO_CREATE);
+ return alarmSender != null;
+ }
+
+ public static void init(Context context){
+ EditPrefUtil pref = new EditPrefUtil(context);
+
+ boolean isSet = NoteUpdatorService.isSetAlarmSender(context);
+ int autoUpdate = pref.getInt(Constant.PREF_AUTO_UPDATE);
+ long updateTime = pref.getLong(Constant.PREF_UPDATE_TIME);
+
+ if (autoUpdate != 0 && updateTime >= 0){
+ if (!isSet){
+ // 再起動時
+ setNextTime(context);
+ }
+ }
+ else {
+ if (isSet){
+ // データ削除時
+ // isSetはクリアされないが、問題なので毎回よぶ
+ stopService(context);
+ }
+ }
+ }
}
\ No newline at end of file
-package com.yuji.ec.utility;\r
-\r
-import java.lang.ref.WeakReference;\r
-\r
-import android.app.Activity;\r
-import android.app.ProgressDialog;\r
-import android.content.DialogInterface;\r
-import android.content.DialogInterface.OnKeyListener;\r
-import android.os.AsyncTask;\r
-import android.view.KeyEvent;\r
-\r
-public class AsyncTaskCommand extends AsyncTask<String, Integer, String> {\r
- private WeakReference<Activity> activityRef;\r
- private AsyncTaskIF command;\r
- private ProgressDialog dialog;\r
- private boolean isCancel = false;\r
- private boolean isDialog = true;\r
- private int status = -1;\r
- \r
- private String title = "";\r
- private String buttonTitle = "";\r
- private boolean cancelable = true;\r
- \r
- @SuppressWarnings({ "rawtypes", "unchecked" })\r
- public AsyncTaskCommand(Activity activity, AsyncTaskIF command) {\r
- this.activityRef = new WeakReference(activity);\r
- this.command = command;\r
- }\r
-\r
- @Override\r
- protected void onPreExecute() {\r
- Debug.d(this, "onPreExecute start");\r
-\r
- Activity activity = activityRef.get();\r
- if (activity == null) {\r
- return;\r
- }\r
- if (isDialog) {\r
- dialog = new ProgressDialog(activity);\r
- dialog.setIndeterminate(true);\r
- dialog.setCancelable(cancelable);\r
- dialog.setTitle(title);\r
- if (cancelable){\r
- dialog.setButton(buttonTitle, new DialogInterface.OnClickListener() {\r
- public void onClick(DialogInterface dialog, int which) {\r
- dialog.cancel();\r
- AsyncTaskCommand.this.cancel(true);\r
- }\r
- });\r
- dialog.setOnKeyListener(new OnKeyListener() {\r
- public boolean onKey(DialogInterface dialog, int keyCode,\r
- KeyEvent event) {\r
- switch (event.getKeyCode()) {\r
- case KeyEvent.KEYCODE_SEARCH:\r
- return true;\r
- }\r
- return false;\r
- }\r
- });\r
- }\r
- dialog.show();\r
- }\r
- Debug.d(this, "onPreExecute end");\r
- }\r
-\r
- @Override\r
- protected String doInBackground(String... arg0) {\r
- try {\r
- Debug.d(this, "doInBackground start");\r
- command.doExecute();\r
- status = command.getStatus();\r
- Debug.d(this, "doInBackground end");\r
- } catch (RuntimeException e) {\r
- Debug.d(this, null, e);\r
- throw e;\r
- }\r
- return null;\r
- }\r
-\r
- @Override\r
- protected void onCancelled() {\r
- Debug.d(this, "onCancelled start");\r
-\r
- isCancel = true;\r
-\r
- if (command != null) {\r
- command.cancel();\r
- }\r
- onPostExecute(null);\r
- Debug.d(this, "onCancelled end");\r
- }\r
-\r
- @Override\r
- protected void onPostExecute(String result) {\r
- Debug.d(this, "onPostExecute start");\r
-\r
- try {\r
- if (command != null) {\r
- command.done(isCancel);\r
- command = null;\r
- }\r
- if (dialog != null) {\r
- try {\r
- dialog.dismiss();\r
- }\r
- catch (IllegalArgumentException e){\r
- ;\r
- }\r
- dialog = null;\r
- }\r
- activityRef = null;\r
- } catch (RuntimeException e) {\r
- Debug.d(this, null, e);\r
- throw e;\r
- }\r
- Debug.d(this, "onPostExecute end");\r
- }\r
-\r
- public void stop() {\r
- Debug.d(this, "stop start");\r
-\r
- if (command != null) {\r
- isCancel = true;\r
- command.cancel();\r
- }\r
- // onPostExecute()\82Ìdialog.dismiss();\82Å\83G\83\89\81[\82Æ\82È\82é\82½\82ß\r
- // \96{\8e¿\93I\82È\89ð\8c\88\8dô\82Å\82Í\82È\82¢\r
- // dialog = null;\r
- if (dialog != null) {\r
- dialog.dismiss();\r
- dialog = null;\r
- }\r
-\r
- Debug.d(this, "stop end");\r
- }\r
-\r
- public void setDialog(boolean b) {\r
- isDialog = b;\r
- }\r
- \r
- public int getResultStatus(){\r
- return status;\r
- }\r
-\r
- public void setTitle(String title) {\r
- this.title = title;\r
- }\r
-\r
- public void setButtonTitle(String buttonTitle) {\r
- this.buttonTitle = buttonTitle;\r
- }\r
- \r
- public void setCancelable(boolean cancelable){\r
- this.cancelable = cancelable;\r
- }\r
-}\r
+package com.yuji.ec.utility;
+
+import java.lang.ref.WeakReference;
+
+import android.app.Activity;
+import android.app.ProgressDialog;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnKeyListener;
+import android.os.AsyncTask;
+import android.view.KeyEvent;
+
+public class AsyncTaskCommand extends AsyncTask<String, Integer, String> {
+ private WeakReference<Activity> activityRef;
+ private AsyncTaskIF command;
+ private ProgressDialog dialog;
+ private boolean isCancel = false;
+ private boolean isDialog = true;
+ private int status = -1;
+
+ private String title = "";
+ private String buttonTitle = "";
+ private boolean cancelable = true;
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public AsyncTaskCommand(Activity activity, AsyncTaskIF command) {
+ this.activityRef = new WeakReference(activity);
+ this.command = command;
+ }
+
+ @Override
+ protected void onPreExecute() {
+ Debug.d(this, "onPreExecute start");
+
+ Activity activity = activityRef.get();
+ if (activity == null) {
+ return;
+ }
+ if (isDialog) {
+ dialog = new ProgressDialog(activity);
+ dialog.setIndeterminate(true);
+ dialog.setCancelable(cancelable);
+ dialog.setTitle(title);
+ if (cancelable){
+ dialog.setButton(buttonTitle, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.cancel();
+ AsyncTaskCommand.this.cancel(true);
+ }
+ });
+ dialog.setOnKeyListener(new OnKeyListener() {
+ public boolean onKey(DialogInterface dialog, int keyCode,
+ KeyEvent event) {
+ switch (event.getKeyCode()) {
+ case KeyEvent.KEYCODE_SEARCH:
+ return true;
+ }
+ return false;
+ }
+ });
+ }
+ dialog.show();
+ }
+ Debug.d(this, "onPreExecute end");
+ }
+
+ @Override
+ protected String doInBackground(String... arg0) {
+ try {
+ Debug.d(this, "doInBackground start");
+ command.doExecute();
+ status = command.getStatus();
+ Debug.d(this, "doInBackground end");
+ } catch (RuntimeException e) {
+ Debug.d(this, null, e);
+ throw e;
+ }
+ return null;
+ }
+
+ @Override
+ protected void onCancelled() {
+ Debug.d(this, "onCancelled start");
+
+ isCancel = true;
+
+ if (command != null) {
+ command.cancel();
+ }
+ onPostExecute(null);
+ Debug.d(this, "onCancelled end");
+ }
+
+ @Override
+ protected void onPostExecute(String result) {
+ Debug.d(this, "onPostExecute start");
+
+ try {
+ if (command != null) {
+ command.done(isCancel);
+ command = null;
+ }
+ if (dialog != null) {
+ try {
+ dialog.dismiss();
+ }
+ catch (IllegalArgumentException e){
+ ;
+ }
+ dialog = null;
+ }
+ activityRef = null;
+ } catch (RuntimeException e) {
+ Debug.d(this, null, e);
+ throw e;
+ }
+ Debug.d(this, "onPostExecute end");
+ }
+
+ public void stop() {
+ Debug.d(this, "stop start");
+
+ if (command != null) {
+ isCancel = true;
+ command.cancel();
+ }
+ // onPostExecute()のdialog.dismiss();でエラーとなるため
+ // 本質的な解決策ではない
+ // dialog = null;
+ if (dialog != null) {
+ dialog.dismiss();
+ dialog = null;
+ }
+
+ Debug.d(this, "stop end");
+ }
+
+ public void setDialog(boolean b) {
+ isDialog = b;
+ }
+
+ public int getResultStatus(){
+ return status;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public void setButtonTitle(String buttonTitle) {
+ this.buttonTitle = buttonTitle;
+ }
+
+ public void setCancelable(boolean cancelable){
+ this.cancelable = cancelable;
+ }
+}
-package com.yuji.ec.utility;\r
-\r
-public interface AsyncTaskIF {\r
- void doExecute();\r
- void cancel();\r
- void done(boolean isCancel);\r
- int getStatus();\r
-}\r
+package com.yuji.ec.utility;
+
+public interface AsyncTaskIF {
+ void doExecute();
+ void cancel();
+ void done(boolean isCancel);
+ int getStatus();
+}
-package com.yuji.ec.utility;\r
-\r
-import android.app.Activity;\r
-import android.app.AlertDialog;\r
-import android.content.Context;\r
-import android.content.DialogInterface;\r
-import android.content.Intent;\r
-import android.os.Bundle;\r
-import android.view.KeyEvent;\r
-import android.view.Window;\r
-import android.view.WindowManager;\r
-import android.widget.Toast;\r
-\r
-import com.yuji.ec.Initialize;\r
-import com.yuji.ec.R;\r
-\r
-public class BaseActivity extends Activity {\r
- @Override\r
- public void onCreate(Bundle savedInstanceState) {\r
- super.onCreate(savedInstanceState);\r
- Debug.d(this, Debug.ON_CREATE);\r
-\r
- try {\r
- String name = this.getLocalClassName();\r
- Context context = getApplicationContext();\r
- Initialize.initialize(context);\r
- Initialize.initialize(context, name);\r
- }\r
- catch (Exception e){\r
- terminate(e);\r
- }\r
- }\r
-\r
- @Override\r
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {\r
- super.onActivityResult(requestCode, resultCode, data);\r
- }\r
-\r
- @Override\r
- protected void onRestart() {\r
- super.onRestart();\r
- Debug.d(this, Debug.ON_RESTART);\r
- }\r
-\r
- @Override\r
- protected void onResume() {\r
- super.onResume();\r
- Debug.d(this, Debug.ON_RESUME);\r
- }\r
-\r
- @Override\r
- protected void onStart() {\r
- super.onStart();\r
- Debug.d(this, Debug.ON_START);\r
- }\r
-\r
- @Override\r
- protected void onPause() {\r
- super.onPause();\r
- Debug.d(this, Debug.ON_PAUSE);\r
- }\r
-\r
- @Override\r
- protected void onStop() {\r
- super.onStop();\r
- Debug.d(this, Debug.ON_STOP);\r
- }\r
-\r
- @Override\r
- protected void onDestroy() {\r
- super.onDestroy();\r
- Debug.d(this, Debug.ON_DESTROY);\r
- }\r
-\r
- // @Override\r
- // public boolean onCreateOptionsMenu(Menu menu) {\r
- // boolean ret = super.onCreateOptionsMenu(menu);\r
- // menu.add(0, Menu.FIRST, Menu.NONE, R.string.help);\r
- // return ret;\r
- // }\r
- //\r
- // @Override\r
- // public boolean onOptionsItemSelected(MenuItem item) {\r
- // try {\r
- // Intent intent = new Intent(this, (Class<?>)Help.class);\r
- // startActivity(intent);\r
- // }\r
- // catch (Exception e){\r
- // terminate(e);\r
- // }\r
- // return super.onOptionsItemSelected(item);\r
- // }\r
-\r
- @Override\r
- public boolean dispatchKeyEvent(KeyEvent event) {\r
- if (event.getAction() == KeyEvent.ACTION_DOWN) {\r
- switch (event.getKeyCode()) {\r
- case KeyEvent.KEYCODE_SEARCH:\r
- return true;\r
- }\r
- }\r
- return super.dispatchKeyEvent(event);\r
- }\r
-\r
- protected void setFullscreen() {\r
- requestWindowFeature(Window.FEATURE_NO_TITLE);\r
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,\r
- WindowManager.LayoutParams.FLAG_FULLSCREEN);\r
- }\r
-\r
- protected void showDialog(String title, String msg, final boolean isFinish) {\r
- new AlertDialog.Builder(this)\r
- .setTitle(title)\r
- .setMessage(msg)\r
- .setNeutralButton(android.R.string.ok,\r
- new DialogInterface.OnClickListener() {\r
- public void onClick(DialogInterface dialog,\r
- int whichButton) {\r
- if (isFinish) {\r
- finish();\r
- }\r
- }\r
- }).show();\r
- }\r
-\r
- protected void showDialog(String title, String msg) {\r
- showDialog(title, msg, false);\r
- }\r
-\r
- protected void showDialog(Object target, Throwable t) {\r
- if (t != null) {\r
- Debug.d(target, null, t);\r
- }\r
- showDialog(getString(R.string.dialogErrorTitle),\r
- getString(R.string.dialogSystemError));\r
- }\r
-\r
- public void terminate(Throwable t) {\r
- if (t != null) {\r
- Debug.d(this, null, t);\r
-\r
- Toast.makeText(\r
- this,\r
- getString(R.string.toastSystem) + ":"\r
- + t.getLocalizedMessage(), Toast.LENGTH_LONG);\r
- }\r
- moveTaskToBack(true);\r
- }\r
-}\r
+package com.yuji.ec.utility;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.KeyEvent;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.Toast;
+
+import com.yuji.ec.Initialize;
+import com.yuji.ec.R;
+
+public class BaseActivity extends Activity {
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Debug.d(this, Debug.ON_CREATE);
+
+ try {
+ String name = this.getLocalClassName();
+ Context context = getApplicationContext();
+ Initialize.initialize(context);
+ Initialize.initialize(context, name);
+ }
+ catch (Exception e){
+ terminate(e);
+ }
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ }
+
+ @Override
+ protected void onRestart() {
+ super.onRestart();
+ Debug.d(this, Debug.ON_RESTART);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ Debug.d(this, Debug.ON_RESUME);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ Debug.d(this, Debug.ON_START);
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ Debug.d(this, Debug.ON_PAUSE);
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ Debug.d(this, Debug.ON_STOP);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ Debug.d(this, Debug.ON_DESTROY);
+ }
+
+ // @Override
+ // public boolean onCreateOptionsMenu(Menu menu) {
+ // boolean ret = super.onCreateOptionsMenu(menu);
+ // menu.add(0, Menu.FIRST, Menu.NONE, R.string.help);
+ // return ret;
+ // }
+ //
+ // @Override
+ // public boolean onOptionsItemSelected(MenuItem item) {
+ // try {
+ // Intent intent = new Intent(this, (Class<?>)Help.class);
+ // startActivity(intent);
+ // }
+ // catch (Exception e){
+ // terminate(e);
+ // }
+ // return super.onOptionsItemSelected(item);
+ // }
+
+ @Override
+ public boolean dispatchKeyEvent(KeyEvent event) {
+ if (event.getAction() == KeyEvent.ACTION_DOWN) {
+ switch (event.getKeyCode()) {
+ case KeyEvent.KEYCODE_SEARCH:
+ return true;
+ }
+ }
+ return super.dispatchKeyEvent(event);
+ }
+
+ protected void setFullscreen() {
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
+ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
+ WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ }
+
+ protected void showDialog(String title, String msg, final boolean isFinish) {
+ new AlertDialog.Builder(this)
+ .setTitle(title)
+ .setMessage(msg)
+ .setNeutralButton(android.R.string.ok,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog,
+ int whichButton) {
+ if (isFinish) {
+ finish();
+ }
+ }
+ }).show();
+ }
+
+ protected void showDialog(String title, String msg) {
+ showDialog(title, msg, false);
+ }
+
+ protected void showDialog(Object target, Throwable t) {
+ if (t != null) {
+ Debug.d(target, null, t);
+ }
+ showDialog(getString(R.string.dialogErrorTitle),
+ getString(R.string.dialogSystemError));
+ }
+
+ public void terminate(Throwable t) {
+ if (t != null) {
+ Debug.d(this, null, t);
+
+ Toast.makeText(
+ this,
+ getString(R.string.toastSystem) + ":"
+ + t.getLocalizedMessage(), Toast.LENGTH_LONG);
+ }
+ moveTaskToBack(true);
+ }
+}
-package com.yuji.ec.utility;\r
-\r
-import android.util.Log;\r
-\r
-public class Debug {\r
- public static final String ON_CREATE = "onCreate";\r
- public static final String ON_DESTROY = "onDestroy";\r
- public static final String ON_START = "onStart";\r
- public static final String ON_STOP = "onStop";\r
- public static final String ON_PAUSE = "onPause";\r
- public static final String ON_RESTART = "onRestart";\r
- public static final String ON_RESUME = "onResume";\r
- public static final String ON_REBIND = "onRebind";\r
- public static final String ON_UNBIND = "onUnbind";\r
-\r
- private static final String FILTER = "com.yuji.ec";\r
-\r
- public static void d(Object target, String msg1, String msg2){\r
- d(target, msg1, msg2, null, null, null);\r
- }\r
- \r
- public static void d(Object target, String msg1, String msg2, String msg3){\r
- d(target, msg1, msg2, msg3, null, null);\r
- }\r
- \r
- public static void d(Object target, String msg1, String msg2, String msg3, String msg4){\r
- d(target, msg1, msg2, msg3, msg4, null);\r
- }\r
- \r
- public static void d(Object target, String msg1, String msg2, String msg3, String msg4, String msg5){\r
- if (!Log.isLoggable(FILTER, Log.DEBUG)){\r
- return;\r
- }\r
- StringBuffer sb = new StringBuffer();\r
- if (msg1 != null){\r
- sb.append(msg1);\r
- }\r
- if (msg2 != null){\r
- sb.append(msg2);\r
- }\r
- if (msg3 != null){\r
- sb.append(msg3);\r
- }\r
- if (msg4 != null){\r
- sb.append(msg4);\r
- }\r
- if (msg5 != null){\r
- sb.append(msg5);\r
- }\r
- d(target, sb.toString(), (Throwable)null);\r
- }\r
- \r
- public static void d(Object target, String msg){\r
- d(target, msg, null, Log.DEBUG);\r
- }\r
-\r
- public static void d(Object target, String msg, Throwable t){\r
-// if (t != null){\r
-// l(t.getMessage());\r
-// }\r
- d(target, msg, t, Log.DEBUG);\r
- }\r
-\r
- public static void i(Object target, String msg){\r
- i(target, msg, null);\r
- }\r
-\r
- public static void i(Object target, String msg, Throwable t){\r
- d(target, msg, t, Log.INFO);\r
- }\r
-\r
- private static void d(Object target, String msg, Throwable t, int level){\r
- if (!Log.isLoggable(FILTER, level)){\r
- return;\r
- }\r
- \r
- String text = target.getClass().getName();\r
- if (msg != null){\r
- text += " " + msg; \r
- }\r
- if (t == null){\r
- Log.d(FILTER, text);\r
- }\r
- else {\r
- Log.d(FILTER, text, t); \r
- }\r
- }\r
- \r
-// public static void t(Context context, String msg){\r
-// if (!Log.isLoggable(FILTER, Log.DEBUG)){\r
-// return;\r
-// }\r
-// if (context == null){\r
-// return;\r
-// }\r
-// Intent intent = new Intent(DelayReceiver.DEBUG);\r
-// intent.putExtra("TEXT", msg);\r
-// context.sendBroadcast(intent);\r
-// }\r
-// \r
-// public static void l(String msg){\r
-// if (!Log.isLoggable(FILTER, Log.DEBUG)){\r
-// return;\r
-// }\r
-// Calendar cal = Calendar.getInstance();\r
-// Date date = cal.getTime();\r
-// int ymd = DateUtil.getYmd(date);\r
-// int hm = DateUtil.getHm(date);\r
-// com.td.db.Log log = new com.td.db.Log(ymd, hm, msg);\r
-// \r
-// LogDao dao = LogDao.getInstance();\r
-// dao.add(log);\r
-// }\r
- \r
- public static boolean isDebug(){\r
- return Log.isLoggable(FILTER, Log.DEBUG);\r
- }\r
-}\r
+package com.yuji.ec.utility;
+
+import android.util.Log;
+
+public class Debug {
+ public static final String ON_CREATE = "onCreate";
+ public static final String ON_DESTROY = "onDestroy";
+ public static final String ON_START = "onStart";
+ public static final String ON_STOP = "onStop";
+ public static final String ON_PAUSE = "onPause";
+ public static final String ON_RESTART = "onRestart";
+ public static final String ON_RESUME = "onResume";
+ public static final String ON_REBIND = "onRebind";
+ public static final String ON_UNBIND = "onUnbind";
+
+ private static final String FILTER = "com.yuji.ec";
+
+ public static void d(Object target, String msg1, String msg2){
+ d(target, msg1, msg2, null, null, null);
+ }
+
+ public static void d(Object target, String msg1, String msg2, String msg3){
+ d(target, msg1, msg2, msg3, null, null);
+ }
+
+ public static void d(Object target, String msg1, String msg2, String msg3, String msg4){
+ d(target, msg1, msg2, msg3, msg4, null);
+ }
+
+ public static void d(Object target, String msg1, String msg2, String msg3, String msg4, String msg5){
+ if (!Log.isLoggable(FILTER, Log.DEBUG)){
+ return;
+ }
+ StringBuffer sb = new StringBuffer();
+ if (msg1 != null){
+ sb.append(msg1);
+ }
+ if (msg2 != null){
+ sb.append(msg2);
+ }
+ if (msg3 != null){
+ sb.append(msg3);
+ }
+ if (msg4 != null){
+ sb.append(msg4);
+ }
+ if (msg5 != null){
+ sb.append(msg5);
+ }
+ d(target, sb.toString(), (Throwable)null);
+ }
+
+ public static void d(Object target, String msg){
+ d(target, msg, null, Log.DEBUG);
+ }
+
+ public static void d(Object target, String msg, Throwable t){
+// if (t != null){
+// l(t.getMessage());
+// }
+ d(target, msg, t, Log.DEBUG);
+ }
+
+ public static void i(Object target, String msg){
+ i(target, msg, null);
+ }
+
+ public static void i(Object target, String msg, Throwable t){
+ d(target, msg, t, Log.INFO);
+ }
+
+ private static void d(Object target, String msg, Throwable t, int level){
+ if (!Log.isLoggable(FILTER, level)){
+ return;
+ }
+
+ String text = target.getClass().getName();
+ if (msg != null){
+ text += " " + msg;
+ }
+ if (t == null){
+ Log.d(FILTER, text);
+ }
+ else {
+ Log.d(FILTER, text, t);
+ }
+ }
+
+// public static void t(Context context, String msg){
+// if (!Log.isLoggable(FILTER, Log.DEBUG)){
+// return;
+// }
+// if (context == null){
+// return;
+// }
+// Intent intent = new Intent(DelayReceiver.DEBUG);
+// intent.putExtra("TEXT", msg);
+// context.sendBroadcast(intent);
+// }
+//
+// public static void l(String msg){
+// if (!Log.isLoggable(FILTER, Log.DEBUG)){
+// return;
+// }
+// Calendar cal = Calendar.getInstance();
+// Date date = cal.getTime();
+// int ymd = DateUtil.getYmd(date);
+// int hm = DateUtil.getHm(date);
+// com.td.db.Log log = new com.td.db.Log(ymd, hm, msg);
+//
+// LogDao dao = LogDao.getInstance();
+// dao.add(log);
+// }
+
+ public static boolean isDebug(){
+ return Log.isLoggable(FILTER, Log.DEBUG);
+ }
+}
-package com.yuji.ec.utility;\r
-\r
-public class ECException extends Exception {\r
-\r
-}\r
+package com.yuji.ec.utility;
+
+public class ECException extends Exception {
+
+}
-package com.yuji.ec.utility;\r
-\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.Map;\r
-import java.util.Map.Entry;\r
-import java.util.Set;\r
-\r
-import android.content.Context;\r
-\r
-public class EditPrefUtil implements PrefUtil {\r
- private static final String DELM = "\t";\r
- private Map<String, String> hash = new HashMap<String, String>();\r
- private PrefUtil pref;\r
- \r
- public EditPrefUtil(Context context){\r
- pref = new PrefUtilImpl(context);\r
- }\r
- \r
- public void put(String key, String value) {\r
- hash.put(key, value);\r
- }\r
-\r
- public void put(String key, int value) {\r
- hash.put(key, String.valueOf(value));\r
- }\r
-\r
- public void put(String key, long value) {\r
- hash.put(key, String.valueOf(value));\r
- }\r
-\r
- public String get(String key) {\r
- String value = hash.get(key);\r
- if (value != null){\r
- return value;\r
- }\r
- value = pref.get(key);\r
- \r
- return value;\r
- }\r
-\r
- public int getInt(String key) {\r
- return Integer.parseInt(get(key));\r
- }\r
-\r
- public long getLong(String key) {\r
- return Long.parseLong(get(key));\r
- }\r
-\r
- public String get(String key, String initValue) {\r
- String value = get(key);\r
- if (value != null){\r
- return value;\r
- }\r
- hash.put(key, initValue);\r
- return initValue;\r
- }\r
-\r
- public int getInt(String key, int initValue) {\r
- return Integer.valueOf(get(key, String.valueOf(initValue)));\r
- }\r
- \r
- public long getLong(String key, long initValue) {\r
- return Long.valueOf(get(key, String.valueOf(initValue)));\r
- }\r
- public void update(){\r
- Set<Entry<String, String>> set = hash.entrySet();\r
- for (Iterator<Entry<String, String>> it = set.iterator(); it.hasNext(); ){\r
- Entry<String, String> entry = it.next();\r
- String key = entry.getKey();\r
- String value = entry.getValue();\r
- pref.put(key, value);\r
- }\r
- hash.clear();\r
- }\r
-\r
- public void copy(String srcKey, String dstKey){\r
- String value = get(srcKey);\r
- put(dstKey, value);\r
- }\r
- \r
- public void remove(String key) {\r
- hash.put(key, null);\r
- }\r
- \r
- public void save(String key){\r
- StringBuffer sb = new StringBuffer();\r
- \r
- Set<Entry<String, String>> set = hash.entrySet();\r
- for (Iterator<Entry<String, String>> it = set.iterator(); it.hasNext(); ){\r
- Entry<String, String> entry = it.next();\r
- String prefKey = entry.getKey();\r
- String prefValue = entry.getValue();\r
- \r
- sb.append(prefKey);\r
- sb.append(DELM);\r
- sb.append(prefValue);\r
- sb.append(DELM);\r
- }\r
- pref.put(key, sb.toString());\r
- }\r
- \r
- public void restore(String key){\r
- hash.clear();\r
-\r
- String data = pref.get(key);\r
- String[] str = data.split(DELM);\r
- for (int i = 0; i < str.length / 2; i++){\r
- String prefKey = str[i * 2];\r
- String prefValue = str[i * 2 + 1];\r
- put(prefKey, prefValue);\r
- }\r
- }\r
-}\r
+package com.yuji.ec.utility;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import android.content.Context;
+
+public class EditPrefUtil implements PrefUtil {
+ private static final String DELM = "\t";
+ private Map<String, String> hash = new HashMap<String, String>();
+ private PrefUtil pref;
+
+ public EditPrefUtil(Context context){
+ pref = new PrefUtilImpl(context);
+ }
+
+ public void put(String key, String value) {
+ hash.put(key, value);
+ }
+
+ public void put(String key, int value) {
+ hash.put(key, String.valueOf(value));
+ }
+
+ public void put(String key, long value) {
+ hash.put(key, String.valueOf(value));
+ }
+
+ public String get(String key) {
+ String value = hash.get(key);
+ if (value != null){
+ return value;
+ }
+ value = pref.get(key);
+
+ return value;
+ }
+
+ public int getInt(String key) {
+ return Integer.parseInt(get(key));
+ }
+
+ public long getLong(String key) {
+ return Long.parseLong(get(key));
+ }
+
+ public String get(String key, String initValue) {
+ String value = get(key);
+ if (value != null){
+ return value;
+ }
+ hash.put(key, initValue);
+ return initValue;
+ }
+
+ public int getInt(String key, int initValue) {
+ return Integer.valueOf(get(key, String.valueOf(initValue)));
+ }
+
+ public long getLong(String key, long initValue) {
+ return Long.valueOf(get(key, String.valueOf(initValue)));
+ }
+ public void update(){
+ Set<Entry<String, String>> set = hash.entrySet();
+ for (Iterator<Entry<String, String>> it = set.iterator(); it.hasNext(); ){
+ Entry<String, String> entry = it.next();
+ String key = entry.getKey();
+ String value = entry.getValue();
+ pref.put(key, value);
+ }
+ hash.clear();
+ }
+
+ public void copy(String srcKey, String dstKey){
+ String value = get(srcKey);
+ put(dstKey, value);
+ }
+
+ public void remove(String key) {
+ hash.put(key, null);
+ }
+
+ public void save(String key){
+ StringBuffer sb = new StringBuffer();
+
+ Set<Entry<String, String>> set = hash.entrySet();
+ for (Iterator<Entry<String, String>> it = set.iterator(); it.hasNext(); ){
+ Entry<String, String> entry = it.next();
+ String prefKey = entry.getKey();
+ String prefValue = entry.getValue();
+
+ sb.append(prefKey);
+ sb.append(DELM);
+ sb.append(prefValue);
+ sb.append(DELM);
+ }
+ pref.put(key, sb.toString());
+ }
+
+ public void restore(String key){
+ hash.clear();
+
+ String data = pref.get(key);
+ String[] str = data.split(DELM);
+ for (int i = 0; i < str.length / 2; i++){
+ String prefKey = str[i * 2];
+ String prefValue = str[i * 2 + 1];
+ put(prefKey, prefValue);
+ }
+ }
+}
-package com.yuji.ec.utility;\r
-\r
-import java.security.InvalidAlgorithmParameterException;\r
-import java.security.InvalidKeyException;\r
-import java.security.Key;\r
-import java.security.NoSuchAlgorithmException;\r
-import java.security.spec.InvalidKeySpecException;\r
-import java.security.spec.KeySpec;\r
-\r
-import javax.crypto.BadPaddingException;\r
-import javax.crypto.Cipher;\r
-import javax.crypto.IllegalBlockSizeException;\r
-import javax.crypto.NoSuchPaddingException;\r
-import javax.crypto.SecretKey;\r
-import javax.crypto.SecretKeyFactory;\r
-import javax.crypto.spec.IvParameterSpec;\r
-import javax.crypto.spec.PBEKeySpec;\r
-\r
-import android.content.Context;\r
-import android.content.pm.PackageInfo;\r
-import android.content.pm.PackageManager;\r
-import android.content.pm.PackageManager.NameNotFoundException;\r
-import android.content.pm.Signature;\r
-\r
-import com.yuji.ec.base64.Base64;\r
-\r
-public class Encryption {\r
- private static Encryption instance = null;\r
- private static final byte[] SALT = new byte[] { -47, 66, 32, -127, 98, -12,\r
- 4, 113, -24, -111, 23, 121, -97 };\r
-\r
- private static final byte[] IV = { 16, 74, 71, -80, 32, 101, -47, 72, 117,\r
- -14, 0, -29, 70, 65, -12, 74 };\r
-\r
- private SecretKey secretKey = null;\r
-\r
- private Encryption(){\r
- \r
- }\r
- \r
- public static Encryption getInstance(){\r
- if (instance == null){\r
- instance = new Encryption();\r
- }\r
- return instance;\r
- }\r
- \r
- public String getEncrypted(Context context, String contents) {\r
- byte[] encoded = null;\r
- try {\r
- if (secretKey == null){\r
- secretKey = generateKey(context);\r
- }\r
-\r
- byte[] encrypted = encrypt(contents.getBytes(), secretKey);\r
-\r
- encoded = Base64.encode(encrypted);\r
- } catch (NoSuchAlgorithmException e) {\r
- ;\r
- } catch (InvalidKeySpecException e) {\r
- ;\r
- } catch (InvalidKeyException e) {\r
- ;\r
- } catch (NoSuchPaddingException e) {\r
- ;\r
- } catch (InvalidAlgorithmParameterException e) {\r
- ;\r
- } catch (IllegalBlockSizeException e) {\r
- ;\r
- } catch (BadPaddingException e) {\r
- ;\r
- }\r
- \r
- return new String(encoded);\r
- }\r
-\r
- public String getDecrypted(Context context, String encoded){\r
- byte[] decrypted = null;\r
- try {\r
- if (secretKey == null){\r
- secretKey = generateKey(context);\r
- }\r
- byte[] crypted = Base64.decode(encoded.getBytes());\r
- \r
- decrypted = decrypt(crypted, secretKey);\r
- } catch (NoSuchAlgorithmException e) {\r
- ;\r
- } catch (InvalidKeySpecException e) {\r
- ;\r
- } catch (InvalidKeyException e) {\r
- ;\r
- } catch (NoSuchPaddingException e) {\r
- ;\r
- } catch (InvalidAlgorithmParameterException e) {\r
- ;\r
- } catch (IllegalBlockSizeException e) {\r
- ;\r
- } catch (BadPaddingException e) {\r
- ;\r
- }\r
- return (decrypted != null)? new String(decrypted) : null;\r
- }\r
- \r
- private byte[] encrypt(byte[] src, Key key) throws NoSuchAlgorithmException,\r
- NoSuchPaddingException, InvalidKeyException,\r
- InvalidAlgorithmParameterException, IllegalBlockSizeException,\r
- BadPaddingException {\r
- Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");\r
-\r
- cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(IV));\r
-\r
- byte[] encrypted = cipher.doFinal(src);\r
-\r
- return encrypted;\r
- }\r
-\r
- private byte[] decrypt(byte[] src, Key key) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException{\r
- Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");\r
-\r
- cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(IV));\r
-\r
- byte[] decrypted = cipher.doFinal(src);\r
-\r
- return decrypted;\r
- }\r
- \r
- private SecretKey generateKey(Context context)\r
- throws NoSuchAlgorithmException, InvalidKeySpecException {\r
- char[] password = generatePassword(context);\r
-\r
- KeySpec keySpec = new PBEKeySpec(password, SALT, 1024, 256);\r
- SecretKeyFactory factory = SecretKeyFactory\r
- .getInstance("PBEWITHSHAAND256BITAES-CBC-BC");\r
- SecretKey secretKey = factory.generateSecret(keySpec);\r
-\r
- return secretKey;\r
- }\r
-\r
- private char[] generatePassword(Context context) {\r
- PackageInfo packageInfo;\r
- StringBuffer sb = new StringBuffer();\r
- try {\r
- packageInfo = context.getPackageManager().getPackageInfo(\r
- context.getPackageName(), PackageManager.GET_SIGNATURES);\r
- Signature[] signatures = packageInfo.signatures;\r
-\r
- for (int i = 0; i < signatures.length; i++) {\r
- Signature signature = packageInfo.signatures[i];\r
- char[] c = signature.toChars();\r
- sb.append(c);\r
- }\r
- } catch (NameNotFoundException e) {\r
- return null;\r
- }\r
- \r
- String s = sb.toString();\r
- if (s.length() > 10){\r
- s = s.substring(0, 10);\r
- }\r
- return s.toCharArray();\r
- }\r
-}\r
+package com.yuji.ec.utility;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.KeySpec;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.PBEKeySpec;
+
+import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.Signature;
+
+import com.yuji.ec.base64.Base64;
+
+public class Encryption {
+ private static Encryption instance = null;
+ private static final byte[] SALT = new byte[] { -47, 66, 32, -127, 98, -12,
+ 4, 113, -24, -111, 23, 121, -97 };
+
+ private static final byte[] IV = { 16, 74, 71, -80, 32, 101, -47, 72, 117,
+ -14, 0, -29, 70, 65, -12, 74 };
+
+ private SecretKey secretKey = null;
+
+ private Encryption(){
+
+ }
+
+ public static Encryption getInstance(){
+ if (instance == null){
+ instance = new Encryption();
+ }
+ return instance;
+ }
+
+ public String getEncrypted(Context context, String contents) {
+ byte[] encoded = null;
+ try {
+ if (secretKey == null){
+ secretKey = generateKey(context);
+ }
+
+ byte[] encrypted = encrypt(contents.getBytes(), secretKey);
+
+ encoded = Base64.encode(encrypted);
+ } catch (NoSuchAlgorithmException e) {
+ ;
+ } catch (InvalidKeySpecException e) {
+ ;
+ } catch (InvalidKeyException e) {
+ ;
+ } catch (NoSuchPaddingException e) {
+ ;
+ } catch (InvalidAlgorithmParameterException e) {
+ ;
+ } catch (IllegalBlockSizeException e) {
+ ;
+ } catch (BadPaddingException e) {
+ ;
+ }
+
+ return new String(encoded);
+ }
+
+ public String getDecrypted(Context context, String encoded){
+ byte[] decrypted = null;
+ try {
+ if (secretKey == null){
+ secretKey = generateKey(context);
+ }
+ byte[] crypted = Base64.decode(encoded.getBytes());
+
+ decrypted = decrypt(crypted, secretKey);
+ } catch (NoSuchAlgorithmException e) {
+ ;
+ } catch (InvalidKeySpecException e) {
+ ;
+ } catch (InvalidKeyException e) {
+ ;
+ } catch (NoSuchPaddingException e) {
+ ;
+ } catch (InvalidAlgorithmParameterException e) {
+ ;
+ } catch (IllegalBlockSizeException e) {
+ ;
+ } catch (BadPaddingException e) {
+ ;
+ }
+ return (decrypted != null)? new String(decrypted) : null;
+ }
+
+ private byte[] encrypt(byte[] src, Key key) throws NoSuchAlgorithmException,
+ NoSuchPaddingException, InvalidKeyException,
+ InvalidAlgorithmParameterException, IllegalBlockSizeException,
+ BadPaddingException {
+ Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+
+ cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(IV));
+
+ byte[] encrypted = cipher.doFinal(src);
+
+ return encrypted;
+ }
+
+ private byte[] decrypt(byte[] src, Key key) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException{
+ Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+
+ cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(IV));
+
+ byte[] decrypted = cipher.doFinal(src);
+
+ return decrypted;
+ }
+
+ private SecretKey generateKey(Context context)
+ throws NoSuchAlgorithmException, InvalidKeySpecException {
+ char[] password = generatePassword(context);
+
+ KeySpec keySpec = new PBEKeySpec(password, SALT, 1024, 256);
+ SecretKeyFactory factory = SecretKeyFactory
+ .getInstance("PBEWITHSHAAND256BITAES-CBC-BC");
+ SecretKey secretKey = factory.generateSecret(keySpec);
+
+ return secretKey;
+ }
+
+ private char[] generatePassword(Context context) {
+ PackageInfo packageInfo;
+ StringBuffer sb = new StringBuffer();
+ try {
+ packageInfo = context.getPackageManager().getPackageInfo(
+ context.getPackageName(), PackageManager.GET_SIGNATURES);
+ Signature[] signatures = packageInfo.signatures;
+
+ for (int i = 0; i < signatures.length; i++) {
+ Signature signature = packageInfo.signatures[i];
+ char[] c = signature.toChars();
+ sb.append(c);
+ }
+ } catch (NameNotFoundException e) {
+ return null;
+ }
+
+ String s = sb.toString();
+ if (s.length() > 10){
+ s = s.substring(0, 10);
+ }
+ return s.toCharArray();
+ }
+}
}
private NoteFilter getDefaultFilter(){
- // \8c\9f\8dõ\8fð\8c\8f\82Æ\82µ\82Ä\81A\8c\9f\8dõ\8cê\82È\82µ\81A\8dX\90V\93ú\8f\87\83\\81[\83g\82ð\8ew\92è
+ // 検索条件として、検索語なし、更新日順ソートを指定
NoteFilter filter = new NoteFilter();
filter.setOrder(NoteSortOrder.UPDATED.getValue());
filter.setAscending(false);
String content = note.getContent();
// #27970
- // \8c©\82Â\82©\82ç\82È\82¢\8fê\8d\87
+ // 見つからない場合
String endTag = "</en-note>";
int pos = content.indexOf(endTag);
if (pos < 0) {
// #27612
// http://www.antun.net/tips/api/evernote.html
// expiredTime=time.time()+(authResult.expiration/1000.0-authResult.currentTime/1000.0)
- // # expiredTime<time.time() \82È\82ç\94F\8fØ\82µ\92¼\82µ\82Ä\81AauthenticationToken
- // \82ð\8eæ\93¾\82µ\92¼\82·\82×\82µ
+ // # expiredTime<time.time() なら認証し直して、authenticationToken
+ // を取得し直すべし
String consumerKey = "yuji_k64613";
String consumerSecret = "d5528b4fdb3a7fee";
-package com.yuji.ec.utility;\r
-\r
-import java.io.IOException;\r
-import java.io.StringReader;\r
-\r
-import org.ccil.cowan.tagsoup.Parser;\r
-import org.xml.sax.Attributes;\r
-import org.xml.sax.ContentHandler;\r
-import org.xml.sax.InputSource;\r
-import org.xml.sax.Locator;\r
-import org.xml.sax.SAXException;\r
-import org.xml.sax.SAXNotRecognizedException;\r
-import org.xml.sax.SAXNotSupportedException;\r
-\r
-import com.yuji.ec.common.CommonUtil;\r
-\r
-public class HtmlParser implements ContentHandler {\r
- // http://java.sun.com/javase/ja/6/docs/ja/api/index.html?org/xml/sax/ContentHandler.html\r
- // http://www35.atwiki.jp/nikoban/pages/23.html\r
- //private final static String NL = System.getProperty("line.separator");\r
- private StringBuffer sb = null;\r
- \r
- public boolean parse(String str){\r
- boolean result = false;\r
- try {\r
- sb = new StringBuffer();\r
- \r
- StringReader sr = new StringReader(str);\r
- InputSource is = new InputSource(sr);\r
- \r
- Parser parser = new Parser();\r
- parser.setContentHandler(this);\r
-\r
- parser.setFeature(Parser.namespacesFeature, false);\r
- parser.parse(is);\r
-\r
- result = true;\r
- } catch (SAXNotRecognizedException e) {\r
- Debug.d(this, null, e);\r
- } catch (SAXNotSupportedException e) {\r
- Debug.d(this, null, e);\r
- } catch (IOException e) {\r
- Debug.d(this, null, e);\r
- } catch (SAXException e) {\r
- Debug.d(this, null, e);\r
- }\r
- return result;\r
- }\r
-\r
- public String getText(){\r
- return (sb != null)? sb.toString() : null;\r
- }\r
- \r
- public void characters(char[] ch, int start, int length) throws SAXException {\r
- if (sb.length() > 0){\r
- //sb.append(NL);\r
- }\r
- String str = new String(ch, start, length);\r
- str = CommonUtil.replaceString(str, "\\n", "");\r
- sb.append(str);\r
- }\r
-\r
- public void endDocument() throws SAXException {\r
- \r
- }\r
-\r
- public void endElement(String uri, String localName, String qName) \r
- throws SAXException {\r
- \r
- }\r
-\r
- public void endPrefixMapping(String prefix) throws SAXException {\r
- \r
- }\r
-\r
- public void ignorableWhitespace(char[] arg0, int arg1, int arg2)\r
- throws SAXException {\r
- \r
- }\r
-\r
- public void processingInstruction(String arg0, String arg1)\r
- throws SAXException {\r
- \r
- }\r
-\r
- public void setDocumentLocator(Locator arg0) {\r
- \r
- }\r
-\r
- public void skippedEntity(String arg0) throws SAXException {\r
- \r
- }\r
-\r
- public void startDocument() throws SAXException {\r
- \r
- }\r
-\r
- public void startElement(String arg0, String arg1, String arg2,\r
- Attributes arg3) throws SAXException {\r
- \r
- }\r
-\r
- public void startPrefixMapping(String arg0, String arg1)\r
- throws SAXException {\r
- \r
- }\r
-}\r
+package com.yuji.ec.utility;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+import org.ccil.cowan.tagsoup.Parser;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+
+import com.yuji.ec.common.CommonUtil;
+
+public class HtmlParser implements ContentHandler {
+ // http://java.sun.com/javase/ja/6/docs/ja/api/index.html?org/xml/sax/ContentHandler.html
+ // http://www35.atwiki.jp/nikoban/pages/23.html
+ //private final static String NL = System.getProperty("line.separator");
+ private StringBuffer sb = null;
+
+ public boolean parse(String str){
+ boolean result = false;
+ try {
+ sb = new StringBuffer();
+
+ StringReader sr = new StringReader(str);
+ InputSource is = new InputSource(sr);
+
+ Parser parser = new Parser();
+ parser.setContentHandler(this);
+
+ parser.setFeature(Parser.namespacesFeature, false);
+ parser.parse(is);
+
+ result = true;
+ } catch (SAXNotRecognizedException e) {
+ Debug.d(this, null, e);
+ } catch (SAXNotSupportedException e) {
+ Debug.d(this, null, e);
+ } catch (IOException e) {
+ Debug.d(this, null, e);
+ } catch (SAXException e) {
+ Debug.d(this, null, e);
+ }
+ return result;
+ }
+
+ public String getText(){
+ return (sb != null)? sb.toString() : null;
+ }
+
+ public void characters(char[] ch, int start, int length) throws SAXException {
+ if (sb.length() > 0){
+ //sb.append(NL);
+ }
+ String str = new String(ch, start, length);
+ str = CommonUtil.replaceString(str, "\\n", "");
+ sb.append(str);
+ }
+
+ public void endDocument() throws SAXException {
+
+ }
+
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException {
+
+ }
+
+ public void endPrefixMapping(String prefix) throws SAXException {
+
+ }
+
+ public void ignorableWhitespace(char[] arg0, int arg1, int arg2)
+ throws SAXException {
+
+ }
+
+ public void processingInstruction(String arg0, String arg1)
+ throws SAXException {
+
+ }
+
+ public void setDocumentLocator(Locator arg0) {
+
+ }
+
+ public void skippedEntity(String arg0) throws SAXException {
+
+ }
+
+ public void startDocument() throws SAXException {
+
+ }
+
+ public void startElement(String arg0, String arg1, String arg2,
+ Attributes arg3) throws SAXException {
+
+ }
+
+ public void startPrefixMapping(String arg0, String arg1)
+ throws SAXException {
+
+ }
+}
-package com.yuji.ec.utility;\r
-\r
-import java.util.List;\r
-\r
-import android.content.Context;\r
-import android.database.sqlite.SQLiteDatabase;\r
-\r
-import com.evernote.edam.notestore.NoteList;\r
-import com.yuji.ec.common.CommonUtil;\r
-import com.yuji.ec.common.Constant;\r
-import com.yuji.ec.db.DatabaseHelper;\r
-import com.yuji.ec.db.Note;\r
-import com.yuji.ec.db.NoteDao;\r
-import com.yuji.ec.utility.EvernoteUtil.Error;\r
-\r
-public class NoteUpdator {\r
- private static NoteUpdator instance = null;\r
- private static Object obj = new Object();\r
-\r
- public static NoteUpdator getInstance() {\r
- if (instance == null) {\r
- synchronized (obj) {\r
- if (instance == null) {\r
- instance = new NoteUpdator();\r
- }\r
- }\r
- }\r
- return instance;\r
- }\r
-\r
- private NoteUpdator() {\r
-\r
- }\r
-\r
- public void update(Context context, int noteItemType, String guid) {\r
- try {\r
- EvernoteUtil util = EvernoteUtil.getInstance();\r
- String username = PasswordUtil.getUsername(context);\r
- String password = PasswordUtil.getPassword(context);\r
- if (!CommonUtil.isNull(username) && !CommonUtil.isNull(password)) {\r
- util.setConfig(username, password);\r
- } else {\r
- return;\r
- }\r
-\r
- List<NoteList> noteListList;\r
- switch (noteItemType) {\r
- case Constant.NOTE_ITEM_TYPE_NOTE_BOOK:\r
- noteListList = util.getNoteListByNotebook(guid);\r
- break;\r
- case Constant.NOTE_ITEM_TYPE_TAG:\r
- noteListList = util.getNoteListByTag(guid);\r
- break;\r
- default:\r
- noteListList = util.getNoteList();\r
- break;\r
- }\r
-\r
- if (util.getErrorCode() != Error.NONE) {\r
- return;\r
- }\r
-\r
- List<Note> list = util.getNoteContentList(noteListList);\r
- if (list == null) {\r
- // NOT_FOUND\r
- return;\r
- }\r
-\r
- DatabaseHelper helper = DatabaseHelper.getInstance();\r
- SQLiteDatabase db = helper.getWritableDatabase();\r
- NoteDao dao = (NoteDao) NoteDao.getInstance();\r
-\r
- synchronized (obj) {\r
- db.beginTransaction();\r
- try {\r
- dao.deleteNT();\r
- for (Note note : list) {\r
- dao.addNT(note);\r
- }\r
- db.setTransactionSuccessful();\r
- } finally {\r
- db.endTransaction();\r
- }\r
- }\r
- } catch (Exception e) {\r
- Debug.d(this, null, e);\r
- }\r
- }\r
-}\r
+package com.yuji.ec.utility;
+
+import java.util.List;
+
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+
+import com.evernote.edam.notestore.NoteList;
+import com.yuji.ec.common.CommonUtil;
+import com.yuji.ec.common.Constant;
+import com.yuji.ec.db.DatabaseHelper;
+import com.yuji.ec.db.Note;
+import com.yuji.ec.db.NoteDao;
+import com.yuji.ec.utility.EvernoteUtil.Error;
+
+public class NoteUpdator {
+ private static NoteUpdator instance = null;
+ private static Object obj = new Object();
+
+ public static NoteUpdator getInstance() {
+ if (instance == null) {
+ synchronized (obj) {
+ if (instance == null) {
+ instance = new NoteUpdator();
+ }
+ }
+ }
+ return instance;
+ }
+
+ private NoteUpdator() {
+
+ }
+
+ public void update(Context context, int noteItemType, String guid) {
+ try {
+ EvernoteUtil util = EvernoteUtil.getInstance();
+ String username = PasswordUtil.getUsername(context);
+ String password = PasswordUtil.getPassword(context);
+ if (!CommonUtil.isNull(username) && !CommonUtil.isNull(password)) {
+ util.setConfig(username, password);
+ } else {
+ return;
+ }
+
+ List<NoteList> noteListList;
+ switch (noteItemType) {
+ case Constant.NOTE_ITEM_TYPE_NOTE_BOOK:
+ noteListList = util.getNoteListByNotebook(guid);
+ break;
+ case Constant.NOTE_ITEM_TYPE_TAG:
+ noteListList = util.getNoteListByTag(guid);
+ break;
+ default:
+ noteListList = util.getNoteList();
+ break;
+ }
+
+ if (util.getErrorCode() != Error.NONE) {
+ return;
+ }
+
+ List<Note> list = util.getNoteContentList(noteListList);
+ if (list == null) {
+ // NOT_FOUND
+ return;
+ }
+
+ DatabaseHelper helper = DatabaseHelper.getInstance();
+ SQLiteDatabase db = helper.getWritableDatabase();
+ NoteDao dao = (NoteDao) NoteDao.getInstance();
+
+ synchronized (obj) {
+ db.beginTransaction();
+ try {
+ dao.deleteNT();
+ for (Note note : list) {
+ dao.addNT(note);
+ }
+ db.setTransactionSuccessful();
+ } finally {
+ db.endTransaction();
+ }
+ }
+ } catch (Exception e) {
+ Debug.d(this, null, e);
+ }
+ }
+}
-package com.yuji.ec.utility;\r
-\r
-import android.content.Context;\r
-\r
-import com.yuji.ec.common.CommonUtil;\r
-import com.yuji.ec.common.Constant;\r
-\r
-public class PasswordUtil {\r
- private static Encryption encryption = Encryption.getInstance();\r
-\r
- public static String getUsername(Context context){\r
- EditPrefUtil pref = new EditPrefUtil(context); \r
- String str = pref.get(Constant.PREF_USER);\r
- if (CommonUtil.isNull(str)){\r
- return null;\r
- }\r
- return encryption.getDecrypted(context, str);\r
- }\r
-\r
- public static String getPassword(Context context){\r
- EditPrefUtil pref = new EditPrefUtil(context); \r
- String str = pref.get(Constant.PREF_PASSWORD);\r
- if (CommonUtil.isNull(str)){\r
- return null;\r
- }\r
- return encryption.getDecrypted(context, str);\r
- }\r
- \r
- public static void setUserAndPassword(Context context, String user, String password){\r
- EditPrefUtil pref = new EditPrefUtil(context); \r
-\r
- String str;\r
- \r
- str = encryption.getEncrypted(context, user);\r
- pref.put(Constant.PREF_USER, str);\r
-\r
- str = encryption.getEncrypted(context, password);\r
- pref.put(Constant.PREF_PASSWORD, str);\r
-\r
- pref.update();\r
- }\r
-}\r
+package com.yuji.ec.utility;
+
+import android.content.Context;
+
+import com.yuji.ec.common.CommonUtil;
+import com.yuji.ec.common.Constant;
+
+public class PasswordUtil {
+ private static Encryption encryption = Encryption.getInstance();
+
+ public static String getUsername(Context context){
+ EditPrefUtil pref = new EditPrefUtil(context);
+ String str = pref.get(Constant.PREF_USER);
+ if (CommonUtil.isNull(str)){
+ return null;
+ }
+ return encryption.getDecrypted(context, str);
+ }
+
+ public static String getPassword(Context context){
+ EditPrefUtil pref = new EditPrefUtil(context);
+ String str = pref.get(Constant.PREF_PASSWORD);
+ if (CommonUtil.isNull(str)){
+ return null;
+ }
+ return encryption.getDecrypted(context, str);
+ }
+
+ public static void setUserAndPassword(Context context, String user, String password){
+ EditPrefUtil pref = new EditPrefUtil(context);
+
+ String str;
+
+ str = encryption.getEncrypted(context, user);
+ pref.put(Constant.PREF_USER, str);
+
+ str = encryption.getEncrypted(context, password);
+ pref.put(Constant.PREF_PASSWORD, str);
+
+ pref.update();
+ }
+}
-package com.yuji.ec.utility;\r
-\r
-public interface PrefUtil {\r
- void put(String key, String value);\r
- void put(String key, int value);\r
- void put(String key, long value);\r
- String get(String key);\r
- int getInt(String key);\r
- long getLong(String key);\r
- String get(String key, String initValue);\r
- int getInt(String key, int initValue);\r
- long getLong(String key, long initValue);\r
- void copy(String srcKey, String dstKey);\r
- void remove(String key);\r
-}\r
+package com.yuji.ec.utility;
+
+public interface PrefUtil {
+ void put(String key, String value);
+ void put(String key, int value);
+ void put(String key, long value);
+ String get(String key);
+ int getInt(String key);
+ long getLong(String key);
+ String get(String key, String initValue);
+ int getInt(String key, int initValue);
+ long getLong(String key, long initValue);
+ void copy(String srcKey, String dstKey);
+ void remove(String key);
+}
-package com.yuji.ec.utility;\r
-\r
-import android.content.Context;\r
-import android.content.SharedPreferences;\r
-import android.content.SharedPreferences.Editor;\r
-import android.content.pm.PackageManager.NameNotFoundException;\r
-\r
-public class PrefUtilImpl implements PrefUtil {\r
- private static final String EVER_CLIP_ACTIVITY = "EverClipActivity";\r
- private static final String PACKAGE_COM_YUJI_EC = "com.yuji.ec";\r
- private Context context;\r
-\r
- public PrefUtilImpl(Context context) {\r
- this.context = context;\r
- }\r
-\r
- public void put(String key, String value) {\r
- synchronized (this) {\r
- SharedPreferences pref = null;\r
- try {\r
- Context ctxt = context.createPackageContext(PACKAGE_COM_YUJI_EC,\r
- Context.CONTEXT_RESTRICTED);\r
- pref = ctxt.getSharedPreferences(EVER_CLIP_ACTIVITY,\r
- Context.MODE_PRIVATE);\r
- } catch (NameNotFoundException e) {\r
- Debug.d(this, null, e);\r
- return;\r
- }\r
-\r
- Editor e = pref.edit();\r
- e.putString(key, value);\r
- e.commit();\r
- }\r
- }\r
-\r
- public void put(String key, int value) {\r
- put(key, String.valueOf(value));\r
- }\r
-\r
- public void put(String key, long value) {\r
- put(key, String.valueOf(value));\r
- }\r
-\r
- public String get(String key) {\r
- String val;\r
- \r
- synchronized (this) {\r
- SharedPreferences pref = null;\r
- try {\r
- Context ctxt = context.createPackageContext(PACKAGE_COM_YUJI_EC,\r
- Context.CONTEXT_RESTRICTED);\r
- pref = ctxt.getSharedPreferences(EVER_CLIP_ACTIVITY,\r
- Context.MODE_WORLD_READABLE);\r
- } catch (NameNotFoundException e) {\r
- Debug.d(this, null, e);\r
- return null;\r
- }\r
- val = pref.getString(key, null);\r
- }\r
-\r
- return val;\r
- }\r
-\r
- public int getInt(String key) {\r
- return Integer.parseInt(get(key));\r
- }\r
-\r
- public long getLong(String key) {\r
- return Long.parseLong(get(key));\r
- }\r
-\r
- public String get(String key, String initValue) {\r
- String value = get(key);\r
- if (value != null) {\r
- return value;\r
- }\r
- put(key, initValue);\r
- return initValue;\r
- }\r
-\r
- public int getInt(String key, int initValue) {\r
- return Integer.valueOf(get(key, String.valueOf(initValue)));\r
- }\r
-\r
- public long getLong(String key, long initValue) {\r
- return Long.valueOf(get(key, String.valueOf(initValue)));\r
- }\r
- \r
- public void copy(String srcKey, String dstKey){\r
- String value = get(srcKey);\r
- put(dstKey, value);\r
- }\r
- \r
- public void remove(String key) {\r
- put(key, null);\r
- }\r
-}\r
+package com.yuji.ec.utility;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.content.pm.PackageManager.NameNotFoundException;
+
+public class PrefUtilImpl implements PrefUtil {
+ private static final String EVER_CLIP_ACTIVITY = "EverClipActivity";
+ private static final String PACKAGE_COM_YUJI_EC = "com.yuji.ec";
+ private Context context;
+
+ public PrefUtilImpl(Context context) {
+ this.context = context;
+ }
+
+ public void put(String key, String value) {
+ synchronized (this) {
+ SharedPreferences pref = null;
+ try {
+ Context ctxt = context.createPackageContext(PACKAGE_COM_YUJI_EC,
+ Context.CONTEXT_RESTRICTED);
+ pref = ctxt.getSharedPreferences(EVER_CLIP_ACTIVITY,
+ Context.MODE_PRIVATE);
+ } catch (NameNotFoundException e) {
+ Debug.d(this, null, e);
+ return;
+ }
+
+ Editor e = pref.edit();
+ e.putString(key, value);
+ e.commit();
+ }
+ }
+
+ public void put(String key, int value) {
+ put(key, String.valueOf(value));
+ }
+
+ public void put(String key, long value) {
+ put(key, String.valueOf(value));
+ }
+
+ public String get(String key) {
+ String val;
+
+ synchronized (this) {
+ SharedPreferences pref = null;
+ try {
+ Context ctxt = context.createPackageContext(PACKAGE_COM_YUJI_EC,
+ Context.CONTEXT_RESTRICTED);
+ pref = ctxt.getSharedPreferences(EVER_CLIP_ACTIVITY,
+ Context.MODE_WORLD_READABLE);
+ } catch (NameNotFoundException e) {
+ Debug.d(this, null, e);
+ return null;
+ }
+ val = pref.getString(key, null);
+ }
+
+ return val;
+ }
+
+ public int getInt(String key) {
+ return Integer.parseInt(get(key));
+ }
+
+ public long getLong(String key) {
+ return Long.parseLong(get(key));
+ }
+
+ public String get(String key, String initValue) {
+ String value = get(key);
+ if (value != null) {
+ return value;
+ }
+ put(key, initValue);
+ return initValue;
+ }
+
+ public int getInt(String key, int initValue) {
+ return Integer.valueOf(get(key, String.valueOf(initValue)));
+ }
+
+ public long getLong(String key, long initValue) {
+ return Long.valueOf(get(key, String.valueOf(initValue)));
+ }
+
+ public void copy(String srcKey, String dstKey){
+ String value = get(srcKey);
+ put(dstKey, value);
+ }
+
+ public void remove(String key) {
+ put(key, null);
+ }
+}