├── .gitignore ├── FastCheckList.iml ├── README.md ├── app ├── app.iml ├── build.gradle └── src │ ├── androidTest │ ├── AndroidManifest.xml │ ├── java │ │ └── net │ │ │ └── cattaka │ │ │ └── android │ │ │ └── fastchecklist │ │ │ ├── CheckListCheckActivityTest.java │ │ │ ├── CheckListEntryActivityTest.java │ │ │ ├── FastCheckListActivity2Test.java │ │ │ ├── FastCheckListActivityTest.java │ │ │ ├── adapter │ │ │ └── MyAdapterTest.java │ │ │ ├── core │ │ │ └── ContextLogicFactoryTest.java │ │ │ ├── db │ │ │ └── OpenHelperTest.java │ │ │ ├── exception │ │ │ └── DbExceptionTest.java │ │ │ └── test │ │ │ ├── BaseTestCase.java │ │ │ ├── TestContextLogic.java │ │ │ ├── TestUtil.java │ │ │ └── UnlockKeyguardActivity.java │ └── res │ │ ├── drawable-hdpi │ │ └── ic_launcher.png │ │ ├── drawable-ldpi │ │ └── ic_launcher.png │ │ ├── drawable-mdpi │ │ └── ic_launcher.png │ │ ├── layout │ │ ├── activity_unlock_keyguard.xml │ │ └── main.xml │ │ └── values │ │ └── strings.xml │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── net │ │ └── cattaka │ │ └── android │ │ └── fastchecklist │ │ ├── CheckListCheckActivity.java │ │ ├── CheckListEntryActivity.java │ │ ├── FastCheckListActivity.java │ │ ├── FastCheckListConstants.java │ │ ├── MyAppliction.java │ │ ├── adapter │ │ └── MyAdapter.java │ │ ├── core │ │ ├── ContextLogic.java │ │ └── ContextLogicFactory.java │ │ ├── db │ │ └── OpenHelper.java │ │ ├── exception │ │ └── DbException.java │ │ ├── model │ │ ├── CheckListEntry.java │ │ ├── CheckListHistory.java │ │ └── CheckListItem.java │ │ ├── util │ │ └── ContextUtil.java │ │ └── view │ │ ├── CheckableLinearLayout.java │ │ └── ItemEntryDialog.java │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-ldpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable │ └── bgcolor_highlighted.xml │ ├── layout │ ├── dialog_item_entry.xml │ ├── layout_check.xml │ ├── layout_check_item.xml │ ├── layout_entry.xml │ ├── layout_entry_item.xml │ ├── layout_main.xml │ └── layout_main_item.xml │ ├── menu │ └── menu.xml │ ├── values-ja │ └── strings.xml │ └── values │ ├── colors.xml │ ├── strings.xml │ └── style.xml ├── build.gradle ├── circle.yml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── misc ├── btn_add.svg ├── btn_check.svg ├── icon.svg ├── icon512.png ├── icon_big_banner.png ├── icon_big_banner.svg └── icon_big_banner2.svg ├── settings.gradle └── wercker.yml /.gitignore: -------------------------------------------------------------------------------- 1 | #built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Windows thumbnail db 19 | Thumbs.db 20 | 21 | # OSX files 22 | .DS_Store 23 | 24 | # Eclipse project files 25 | .classpath 26 | .project 27 | 28 | # Android Studio 29 | .idea 30 | #.idea/workspace.xml - remove # and delete .idea if it better suit your needs. 31 | .gradle 32 | build/ 33 | 34 | -------------------------------------------------------------------------------- /FastCheckList.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | FastCheckList 2 | ============= 3 | 4 | # Summary 5 | Simple check list application. 6 | Despite carry on a daily basis, 7 | I think you forget What things. 8 | You can easily check them with a checklist to use this app, 9 | you can eliminate the lost item. 10 | 11 | # For developer 12 | This application is an example of [CatHandsGendroid](https://github.com/cattaka/CatHandsGendroid). 13 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.neenbedankt.android-apt' 3 | 4 | android { 5 | compileSdkVersion 21 6 | buildToolsVersion "21.1.2" 7 | 8 | defaultConfig { 9 | applicationId "net.cattaka.android.fastchecklist" 10 | minSdkVersion 8 11 | targetSdkVersion 21 12 | 13 | testApplicationId "net.cattaka.android.fastchecklist.test" 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | } 16 | 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 21 | } 22 | debug { 23 | testCoverageEnabled true 24 | } 25 | } 26 | 27 | packagingOptions { 28 | exclude 'LICENSE.txt' 29 | } 30 | } 31 | 32 | apt { 33 | arguments { 34 | resourcePackageName android.defaultConfig.applicationId 35 | androidManifestFile variant.outputs[0]?.processResources?.manifestFile 36 | } 37 | } 38 | 39 | dependencies { 40 | apt 'net.cattaka:cathandsgendroid-apt:0.4.1' 41 | compile 'net.cattaka:cathandsgendroid-core:0.4.1' 42 | debugCompile 'net.cattaka:telnetsqlite:1.0.0' 43 | androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' 44 | androidTestCompile 'com.android.support.test:runner:0.3' 45 | androidTestCompile 'org.mockito:mockito-core:1.10.19' 46 | androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2' 47 | } 48 | -------------------------------------------------------------------------------- /app/src/androidTest/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/androidTest/java/net/cattaka/android/fastchecklist/CheckListCheckActivityTest.java: -------------------------------------------------------------------------------- 1 | 2 | package net.cattaka.android.fastchecklist; 3 | 4 | import android.content.Intent; 5 | import android.view.KeyEvent; 6 | import android.widget.ListView; 7 | 8 | import net.cattaka.android.fastchecklist.db.OpenHelper; 9 | import net.cattaka.android.fastchecklist.model.CheckListEntry; 10 | import net.cattaka.android.fastchecklist.model.CheckListHistory; 11 | import net.cattaka.android.fastchecklist.test.BaseTestCase; 12 | import net.cattaka.android.fastchecklist.test.TestUtil; 13 | 14 | import org.hamcrest.Matchers; 15 | 16 | import java.util.List; 17 | 18 | import static android.support.test.espresso.Espresso.onData; 19 | import static android.support.test.espresso.Espresso.onView; 20 | import static android.support.test.espresso.action.ViewActions.click; 21 | import static android.support.test.espresso.matcher.ViewMatchers.withId; 22 | 23 | public class CheckListCheckActivityTest extends BaseTestCase { 24 | public CheckListCheckActivityTest() { 25 | super(CheckListCheckActivity.class); 26 | } 27 | 28 | /** 29 | * Test start and exit. 30 | */ 31 | public void testStartAndExitActivity() { 32 | final CheckListCheckActivity activity = getActivity(); 33 | assertFalse(activity.isFinishing()); 34 | { // Test finish by back key 35 | getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_BACK); 36 | TestUtil.waitForBoolean(new TestUtil.BooleanFunc() { 37 | @Override 38 | public boolean run() { 39 | return activity.isFinishing(); 40 | } 41 | }, 3000); 42 | assertTrue(activity.isFinishing()); 43 | } 44 | } 45 | 46 | /** 47 | * Test start and exit. 48 | */ 49 | public void testStartAndCancelActivity() throws Throwable { 50 | final CheckListCheckActivity activity = getActivity(); 51 | assertFalse(activity.isFinishing()); 52 | { // Test finish by click button_ok 53 | onView(withId(R.id.button_cancel)) 54 | .perform(click()); 55 | assertTrue(activity.isFinishing()); 56 | } 57 | } 58 | 59 | /** 60 | * Test screen transition to the edit screen. 61 | */ 62 | public void testCheckAndRegister() throws Throwable{ 63 | List entries; 64 | { // Creating dummy data. 65 | clearData(); 66 | entries = createTestData(3, 4); 67 | } 68 | CheckListEntry testTarget = entries.get(1); 69 | { // Check history is empty 70 | OpenHelper openHelper = mContextLogic.createOpenHelper(); 71 | List histories = openHelper.findHistory(testTarget.getId()); 72 | assertEquals(0, histories.size()); 73 | } 74 | { // set activity intent 75 | Intent intent = new Intent(); 76 | intent.putExtra(CheckListCheckActivity.EXTRA_TARGET_ENTRY_ID, testTarget.getId()); 77 | setActivityIntent(intent); 78 | } 79 | final CheckListCheckActivity activity = getActivity(); 80 | assertFalse(activity.isFinishing()); 81 | final ListView listView = (ListView) activity.findViewById(R.id.list_items); 82 | { // Test number of entries 83 | assertEquals(4, listView.getCount()); 84 | } 85 | { 86 | for (int i=0;i histories = openHelper.findHistory(testTarget.getId()); 111 | assertEquals(1, histories.size()); 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /app/src/androidTest/java/net/cattaka/android/fastchecklist/CheckListEntryActivityTest.java: -------------------------------------------------------------------------------- 1 | 2 | package net.cattaka.android.fastchecklist; 3 | 4 | import android.content.Intent; 5 | import android.view.KeyEvent; 6 | import android.widget.EditText; 7 | import android.widget.ListView; 8 | 9 | import net.cattaka.android.fastchecklist.db.OpenHelper; 10 | import net.cattaka.android.fastchecklist.model.CheckListEntry; 11 | import net.cattaka.android.fastchecklist.model.CheckListHistory; 12 | import net.cattaka.android.fastchecklist.test.BaseTestCase; 13 | 14 | import java.util.List; 15 | 16 | import static android.support.test.espresso.Espresso.onView; 17 | import static android.support.test.espresso.action.ViewActions.click; 18 | import static android.support.test.espresso.action.ViewActions.typeText; 19 | import static android.support.test.espresso.matcher.ViewMatchers.withId; 20 | 21 | public class CheckListEntryActivityTest extends BaseTestCase { 22 | public CheckListEntryActivityTest() { 23 | super(CheckListEntryActivity.class); 24 | } 25 | 26 | /** 27 | * Test start and exit. 28 | */ 29 | public void testStartAndExitActivity_new() throws Throwable { 30 | final CheckListEntryActivity activity = getActivity(); 31 | assertFalse(activity.isFinishing()); 32 | { // Test finish by button_cancel 33 | onView(withId(R.id.button_cancel)) 34 | .perform(click()); 35 | assertTrue(activity.isFinishing()); 36 | } 37 | } 38 | 39 | /** 40 | * Test start and exit. 41 | */ 42 | public void testStartAndExitActivity() throws Throwable { 43 | List entries; 44 | { // Creating dummy data. 45 | clearData(); 46 | entries = createTestData(3, 4); 47 | } 48 | CheckListEntry testTarget = entries.get(1); 49 | { // set activity intent 50 | Intent intent = new Intent(); 51 | intent.putExtra(CheckListEntryActivity.EXTRA_TARGET_ENTRY_ID, testTarget.getId()); 52 | setActivityIntent(intent); 53 | } 54 | final CheckListEntryActivity activity = getActivity(); 55 | assertFalse(activity.isFinishing()); 56 | { // Test finish by button_cancel 57 | onView(withId(R.id.button_cancel)) 58 | .perform(click()); 59 | assertTrue(activity.isFinishing()); 60 | } 61 | } 62 | 63 | /** 64 | * Test start and exit. 65 | */ 66 | public void testStartAndCancelActivity() throws Throwable { 67 | List entries; 68 | { // Creating dummy data. 69 | clearData(); 70 | entries = createTestData(3, 4); 71 | } 72 | CheckListEntry testTarget = entries.get(1); 73 | { // set activity intent 74 | Intent intent = new Intent(); 75 | intent.putExtra(CheckListEntryActivity.EXTRA_TARGET_ENTRY_ID, testTarget.getId()); 76 | setActivityIntent(intent); 77 | } 78 | final CheckListEntryActivity activity = getActivity(); 79 | assertFalse(activity.isFinishing()); 80 | { // Test finish by click button_ok 81 | onView(withId(R.id.button_cancel)) 82 | .perform(click()); 83 | assertTrue(activity.isFinishing()); 84 | } 85 | } 86 | 87 | /** 88 | * Test create new item. 89 | */ 90 | public void testCreateNewItem() throws Throwable { 91 | { // clear all data. 92 | clearData(); 93 | } 94 | final CheckListEntryActivity activity = getActivity(); 95 | assertFalse(activity.isFinishing()); 96 | { // Input title to EditText 97 | onView(withId(R.id.edit_title)) 98 | .perform(typeText("Test Title")); 99 | } 100 | { // Test finish by button_ok 101 | onView(withId(R.id.button_ok)) 102 | .perform(click()); 103 | assertTrue(activity.isFinishing()); 104 | } 105 | { // Check new item is added on the tail. 106 | OpenHelper openHelper = mContextLogic.createOpenHelper(); 107 | List entries = openHelper.findEntry(); 108 | CheckListEntry entry = entries.get(entries.size() - 1); 109 | assertEquals("Test Title", entry.getTitle()); 110 | } 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /app/src/androidTest/java/net/cattaka/android/fastchecklist/FastCheckListActivity2Test.java: -------------------------------------------------------------------------------- 1 | 2 | package net.cattaka.android.fastchecklist; 3 | 4 | import android.app.Instrumentation; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.os.SystemClock; 8 | import android.test.ActivityInstrumentationTestCase2; 9 | import android.test.ActivityUnitTestCase; 10 | import android.test.RenamingDelegatingContext; 11 | import android.view.KeyEvent; 12 | import android.view.View; 13 | import android.widget.ListView; 14 | 15 | import net.cattaka.android.fastchecklist.core.ContextLogic; 16 | import net.cattaka.android.fastchecklist.core.ContextLogicFactory; 17 | import net.cattaka.android.fastchecklist.db.OpenHelper; 18 | import net.cattaka.android.fastchecklist.model.CheckListEntry; 19 | import net.cattaka.android.fastchecklist.model.CheckListItem; 20 | import net.cattaka.android.fastchecklist.test.BaseTestCase; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | import static android.support.test.espresso.Espresso.onData; 26 | import static android.support.test.espresso.Espresso.onView; 27 | import static android.support.test.espresso.action.ViewActions.click; 28 | import static android.support.test.espresso.action.ViewActions.scrollTo; 29 | import static android.support.test.espresso.matcher.ViewMatchers.hasSibling; 30 | import static android.support.test.espresso.matcher.ViewMatchers.withId; 31 | import static android.support.test.espresso.matcher.ViewMatchers.withText; 32 | import static org.hamcrest.Matchers.allOf; 33 | import static org.hamcrest.Matchers.is; 34 | 35 | public class FastCheckListActivity2Test extends BaseTestCase { 36 | public FastCheckListActivity2Test() { 37 | super(FastCheckListActivity.class); 38 | } 39 | 40 | /** 41 | * Test start and exit. 42 | */ 43 | public void testStartAndExitActivity() { 44 | FastCheckListActivity activity = getActivity(); 45 | assertFalse(activity.isFinishing()); 46 | { // Test finish by back key 47 | getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_BACK); 48 | assertTrue(activity.isFinishing()); 49 | } 50 | } 51 | 52 | /** 53 | * Test screen transition to the edit screen. 54 | */ 55 | public void testScreenTransition() throws Throwable{ 56 | { // Creating dummy data. 57 | clearData(); 58 | createTestData(3, 4); 59 | } 60 | FastCheckListActivity activity = getActivity(); 61 | assertFalse(activity.isFinishing()); 62 | final ListView listView = (ListView) activity.findViewById(R.id.list_entries); 63 | { // Test number of entries 64 | assertEquals(3,listView.getCount()); 65 | } 66 | { // Test screen transition. on press R.id.button_check. 67 | Instrumentation.ActivityMonitor monitor = new Instrumentation.ActivityMonitor(CheckListCheckActivity.class.getName(), null, true); 68 | getInstrumentation().addMonitor(monitor); 69 | try { 70 | setSelection(listView, 0); 71 | CheckListEntry entry = ((CheckListEntry)listView.getItemAtPosition(0)); 72 | onView(allOf(withId(R.id.button_check), hasSibling(withText(entry.getTitle())))) 73 | .perform(click()); 74 | assertEquals(1, monitor.getHits()); 75 | } finally { 76 | getInstrumentation().removeMonitor(monitor); 77 | } 78 | } 79 | { // Test finish by back key 80 | getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_BACK); 81 | assertTrue(activity.isFinishing()); 82 | } 83 | } 84 | 85 | /** 86 | * Test switch to edit mode and back to normal mode. 87 | * This checks visibilities of views. 88 | */ 89 | public void testSwitchEditMode() throws Throwable{ 90 | { // Creating dummy data. 91 | clearData(); 92 | createTestData(3, 4); 93 | } 94 | final FastCheckListActivity activity = getActivity(); 95 | assertFalse(activity.isFinishing()); 96 | final ListView listView = (ListView) activity.findViewById(R.id.list_entries); 97 | { // Test number of entries 98 | assertEquals(3, listView.getCount()); 99 | } 100 | { 101 | { // Check visiblity 102 | assertEquals(View.VISIBLE, activity.findViewById(R.id.button_enter_edit_mode).getVisibility()); 103 | assertEquals(View.GONE, activity.findViewById(R.id.button_exit_edit_mode).getVisibility()); 104 | assertEquals(View.GONE, listView.getChildAt(0).findViewById(R.id.button_up).getVisibility()); 105 | assertEquals(View.GONE, listView.getChildAt(0).findViewById(R.id.button_down).getVisibility()); 106 | assertEquals(View.GONE, listView.getChildAt(0).findViewById(R.id.button_edit).getVisibility()); 107 | assertEquals(View.VISIBLE, listView.getChildAt(0).findViewById(R.id.button_check).getVisibility()); 108 | } 109 | { 110 | onView(withId(R.id.button_enter_edit_mode)) 111 | .perform(click()); 112 | } 113 | { // Check visiblity 114 | assertEquals(View.GONE, activity.findViewById(R.id.button_enter_edit_mode).getVisibility()); 115 | assertEquals(View.VISIBLE, activity.findViewById(R.id.button_exit_edit_mode).getVisibility()); 116 | assertEquals(View.VISIBLE, listView.getChildAt(0).findViewById(R.id.button_up).getVisibility()); 117 | assertEquals(View.VISIBLE, listView.getChildAt(0).findViewById(R.id.button_down).getVisibility()); 118 | assertEquals(View.VISIBLE, listView.getChildAt(0).findViewById(R.id.button_edit).getVisibility()); 119 | assertEquals(View.GONE, listView.getChildAt(0).findViewById(R.id.button_check).getVisibility()); 120 | } 121 | { 122 | onView(withId(R.id.button_exit_edit_mode)) 123 | .perform(click()); 124 | } 125 | { // Check visiblity 126 | assertEquals(View.VISIBLE, activity.findViewById(R.id.button_enter_edit_mode).getVisibility()); 127 | assertEquals(View.GONE, activity.findViewById(R.id.button_exit_edit_mode).getVisibility()); 128 | assertEquals(View.GONE, listView.getChildAt(0).findViewById(R.id.button_up).getVisibility()); 129 | assertEquals(View.GONE, listView.getChildAt(0).findViewById(R.id.button_down).getVisibility()); 130 | assertEquals(View.GONE, listView.getChildAt(0).findViewById(R.id.button_edit).getVisibility()); 131 | assertEquals(View.VISIBLE, listView.getChildAt(0).findViewById(R.id.button_check).getVisibility()); 132 | } 133 | } 134 | } 135 | 136 | /** 137 | * Test change order of items. [0,1,2] -> [1,2,0] 138 | */ 139 | public void testChangeOrder() throws Throwable{ 140 | List entries; 141 | { // Creating dummy data. 142 | clearData(); 143 | entries = createTestData(3, 4); 144 | } 145 | final FastCheckListActivity activity = getActivity(); 146 | assertFalse(activity.isFinishing()); 147 | final ListView listView = (ListView) activity.findViewById(R.id.list_entries); 148 | { // Check number of entries 149 | assertEquals(3,listView.getCount()); 150 | } 151 | { // Check items have correct order after sort. 152 | assertEquals(entries.get(0).getTitle(), ((CheckListEntry)listView.getItemAtPosition(0)).getTitle()); 153 | assertEquals(entries.get(1).getTitle(), ((CheckListEntry)listView.getItemAtPosition(1)).getTitle()); 154 | assertEquals(entries.get(2).getTitle(), ((CheckListEntry)listView.getItemAtPosition(2)).getTitle()); 155 | } 156 | { 157 | { // Enter edit mode 158 | onView(withId(R.id.button_enter_edit_mode)) 159 | .perform(click()); 160 | } 161 | { // Sort up 162 | setSelection(listView, 1); 163 | CheckListEntry entry = ((CheckListEntry)listView.getItemAtPosition(1)); 164 | onView(allOf(withId(R.id.button_up), hasSibling(withText(entry.getTitle())))) 165 | .perform(click()); 166 | } 167 | { // Sort down 168 | setSelection(listView, 1); 169 | CheckListEntry entry = ((CheckListEntry)listView.getItemAtPosition(1)); 170 | onView(allOf(withId(R.id.button_down), hasSibling(withText(entry.getTitle())))) 171 | .perform(click()); 172 | } 173 | { // Exit edit mode 174 | onView(withId(R.id.button_exit_edit_mode)) 175 | .perform(click()); 176 | } 177 | } 178 | { // Check items have correct order after sort. 179 | assertEquals(entries.get(1).getTitle(), ((CheckListEntry)listView.getItemAtPosition(0)).getTitle()); 180 | assertEquals(entries.get(2).getTitle(), ((CheckListEntry)listView.getItemAtPosition(1)).getTitle()); 181 | assertEquals(entries.get(0).getTitle(), ((CheckListEntry)listView.getItemAtPosition(2)).getTitle()); 182 | } 183 | } 184 | 185 | private void setSelection(final ListView listView, final int position) throws Throwable { 186 | runTestOnUiThread(new Runnable() { 187 | @Override 188 | public void run() { 189 | listView.setSelection(position); 190 | } 191 | }); 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /app/src/androidTest/java/net/cattaka/android/fastchecklist/FastCheckListActivityTest.java: -------------------------------------------------------------------------------- 1 | 2 | package net.cattaka.android.fastchecklist; 3 | 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.test.ActivityInstrumentationTestCase2; 7 | import android.test.ActivityUnitTestCase; 8 | import android.test.RenamingDelegatingContext; 9 | 10 | import net.cattaka.android.fastchecklist.core.ContextLogic; 11 | import net.cattaka.android.fastchecklist.core.ContextLogicFactory; 12 | import net.cattaka.android.fastchecklist.test.BaseTestCase; 13 | 14 | public class FastCheckListActivityTest extends BaseTestCase { 15 | public FastCheckListActivityTest() { 16 | super(FastCheckListActivity.class); 17 | } 18 | 19 | public void testStartActivity() { 20 | FastCheckListActivity activity = getActivity(); 21 | activity.finish(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/androidTest/java/net/cattaka/android/fastchecklist/adapter/MyAdapterTest.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist.adapter; 2 | 3 | import android.content.Context; 4 | import android.test.InstrumentationTestCase; 5 | import android.view.View; 6 | import android.widget.CheckedTextView; 7 | 8 | import net.cattaka.android.fastchecklist.model.CheckListItem; 9 | 10 | import org.hamcrest.Matchers; 11 | import org.junit.Test; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | import static android.support.test.espresso.matcher.ViewMatchers.assertThat; 17 | import static org.hamcrest.Matchers.is; 18 | 19 | public class MyAdapterTest extends InstrumentationTestCase { 20 | public void testGetView() { 21 | List dummys = new ArrayList<>(); 22 | { // ダミーデータを作る 23 | dummys.add(new CheckListItem(1L, 1L, 1L, "Label1")); 24 | dummys.add(new CheckListItem(2L, 2L, 2L, "Label2")); 25 | } 26 | 27 | Context context = getInstrumentation().getTargetContext(); 28 | MyAdapter sup = new MyAdapter(context, dummys); 29 | 30 | { // 1つめのViewの表示内容を確認する 31 | View view = sup.getView(0, null, null); 32 | assertThat(view, is(Matchers.instanceOf(CheckedTextView.class))); 33 | assertThat(((CheckedTextView)view).getText().toString(), is("Label1")); 34 | } 35 | { // 2つめのViewの表示内容を確認する 36 | View view = sup.getView(1, null, null); 37 | assertThat(view, is(Matchers.instanceOf(CheckedTextView.class))); 38 | assertThat(((CheckedTextView)view).getText().toString(), is("Label2")); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/net/cattaka/android/fastchecklist/core/ContextLogicFactoryTest.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist.core; 2 | 3 | import android.content.Context; 4 | import android.test.InstrumentationTestCase; 5 | 6 | public class ContextLogicFactoryTest extends InstrumentationTestCase { 7 | @Override 8 | protected void setUp() throws Exception { 9 | super.setUp(); 10 | ContextLogicFactory.replaceInstance(new ContextLogicFactory()); 11 | } 12 | 13 | public void testNewInstance() { 14 | Context context = getInstrumentation().getTargetContext(); 15 | ContextLogicFactory sup = new ContextLogicFactory(); 16 | 17 | ContextLogic logic = sup.newInstance(context); 18 | assertEquals(ContextLogic.class, logic.getClass()); 19 | } 20 | 21 | public void testReplaceInstance() { 22 | 23 | Context context = getInstrumentation().getTargetContext(); 24 | ContextLogicFactory sup = new DummyContextLogicFactory(); 25 | 26 | ContextLogic logic = sup.newInstance(context); 27 | assertEquals(DummyContextLogic.class, logic.getClass()); 28 | } 29 | 30 | public static class DummyContextLogic extends ContextLogic { 31 | public DummyContextLogic(Context context) { 32 | super(context); 33 | } 34 | } 35 | 36 | public static class DummyContextLogicFactory extends ContextLogicFactory { 37 | @Override 38 | public ContextLogic newInstance(Context context) { 39 | return new DummyContextLogic(context); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/net/cattaka/android/fastchecklist/db/OpenHelperTest.java: -------------------------------------------------------------------------------- 1 | 2 | package net.cattaka.android.fastchecklist.db; 3 | 4 | import net.cattaka.android.fastchecklist.model.CheckListEntry; 5 | import android.content.Context; 6 | import android.test.InstrumentationTestCase; 7 | import android.test.RenamingDelegatingContext; 8 | 9 | import org.junit.Test; 10 | 11 | import static android.support.test.espresso.matcher.ViewMatchers.*; 12 | import static org.hamcrest.Matchers.is; 13 | 14 | public class OpenHelperTest extends InstrumentationTestCase { 15 | private OpenHelper mOpenHelper; 16 | 17 | @Override 18 | protected void setUp() throws Exception { 19 | super.setUp(); 20 | Context context = new RenamingDelegatingContext(getInstrumentation().getTargetContext(), "test_"); 21 | mOpenHelper = new OpenHelper(context); 22 | } 23 | 24 | @Override 25 | protected void tearDown() throws Exception { 26 | super.tearDown(); 27 | mOpenHelper.close(); 28 | mOpenHelper = null; 29 | } 30 | 31 | public void testInsertSelect() { 32 | assertEquals(1, mOpenHelper.findEntry().size()); 33 | 34 | CheckListEntry orig = new CheckListEntry(); 35 | { // INSERTする 36 | orig.setTitle("hoge"); 37 | mOpenHelper.registerEntry(orig); 38 | } 39 | CheckListEntry dest; 40 | { // SELECTする 41 | Long id = orig.getId(); 42 | dest = mOpenHelper.findEntry(id, false); 43 | } 44 | { // 確認する 45 | assertThat(dest.getTitle(), is("hoge")); 46 | } 47 | } 48 | 49 | public void testFind() { 50 | assertEquals(1, mOpenHelper.findEntry().size()); 51 | 52 | CheckListEntry entry = new CheckListEntry(); 53 | entry.setTitle("title"); 54 | mOpenHelper.registerEntry(entry); 55 | assertEquals(2, mOpenHelper.findEntry().size()); 56 | } 57 | 58 | public void testRegister() { 59 | assertEquals(1, mOpenHelper.findEntry().size()); 60 | 61 | for (int i = 0; i < 10; i++) { 62 | CheckListEntry entry = new CheckListEntry(); 63 | entry.setTitle("title" + i); 64 | mOpenHelper.registerEntry(entry); 65 | } 66 | assertEquals(11, mOpenHelper.findEntry().size()); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /app/src/androidTest/java/net/cattaka/android/fastchecklist/exception/DbExceptionTest.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist.exception; 2 | 3 | import junit.framework.TestCase; 4 | 5 | public class DbExceptionTest extends TestCase { 6 | public void testConstructor_1() { 7 | DbException sup = new DbException(); 8 | assertNotNull(sup); 9 | assertNull(sup.getMessage()); 10 | assertNull(sup.getCause()); 11 | } 12 | public void testConstructor_2() { 13 | Throwable t = new Throwable(); 14 | DbException sup = new DbException("detailMessage", t); 15 | assertNotNull(sup); 16 | assertEquals("detailMessage", sup.getMessage()); 17 | assertEquals(t, sup.getCause()); 18 | } 19 | public void testConstructor_3() { 20 | Throwable t = new Throwable(); 21 | DbException sup = new DbException("detailMessage"); 22 | assertNotNull(sup); 23 | assertEquals("detailMessage", sup.getMessage()); 24 | assertNull(sup.getCause()); 25 | } 26 | public void testConstructor_4() { 27 | Throwable t = new Throwable(); 28 | DbException sup = new DbException(t); 29 | assertNotNull(sup); 30 | assertEquals(t.getClass().getCanonicalName(), sup.getMessage()); 31 | assertEquals(t, sup.getCause()); 32 | } 33 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/net/cattaka/android/fastchecklist/test/BaseTestCase.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist.test; 2 | 3 | import android.app.Activity; 4 | import android.app.KeyguardManager; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.os.Build; 8 | import android.os.PowerManager; 9 | import android.os.SystemClock; 10 | import android.test.ActivityInstrumentationTestCase2; 11 | import android.test.RenamingDelegatingContext; 12 | 13 | import net.cattaka.android.fastchecklist.core.ContextLogic; 14 | import net.cattaka.android.fastchecklist.core.ContextLogicFactory; 15 | import net.cattaka.android.fastchecklist.db.OpenHelper; 16 | import net.cattaka.android.fastchecklist.model.CheckListEntry; 17 | import net.cattaka.android.fastchecklist.model.CheckListItem; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | /** 23 | * Created by cattaka on 14/11/28. 24 | */ 25 | public class BaseTestCase extends ActivityInstrumentationTestCase2 { 26 | protected ContextLogic mContextLogic; 27 | 28 | public BaseTestCase(Class tClass) { 29 | super(tClass); 30 | } 31 | 32 | protected void setUp() throws Exception { 33 | super.setUp(); 34 | Context context = getInstrumentation().getTargetContext(); 35 | mContextLogic = new TestContextLogic(context); 36 | { // Replace ContextLogicFactory to use RenamingDelegatingContext. 37 | ContextLogicFactory.replaceInstance(new ContextLogicFactory() { 38 | @Override 39 | public ContextLogic newInstance(Context context) { 40 | return mContextLogic; 41 | } 42 | }); 43 | } 44 | { // Unlock keyguard and screen on 45 | KeyguardManager km = (KeyguardManager) getInstrumentation().getTargetContext().getSystemService(Context.KEYGUARD_SERVICE); 46 | PowerManager pm = (PowerManager) getInstrumentation().getTargetContext().getSystemService(Context.POWER_SERVICE); 47 | boolean locked = false; 48 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 49 | locked = km.isKeyguardLocked(); 50 | } 51 | if (locked || km.inKeyguardRestrictedInputMode() || !pm.isScreenOn()) { 52 | Intent intent = new Intent(getInstrumentation().getContext(), UnlockKeyguardActivity.class); 53 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 54 | getInstrumentation().getTargetContext().startActivity(intent); 55 | while (km.inKeyguardRestrictedInputMode()) { 56 | SystemClock.sleep(100); 57 | } 58 | } 59 | } 60 | } 61 | 62 | public void clearData() { 63 | OpenHelper openHelper = mContextLogic.createOpenHelper(); 64 | for (CheckListEntry entry : openHelper.findEntry()) { 65 | openHelper.deleteEntry(entry.getId()); 66 | } 67 | } 68 | 69 | public List createTestData(int entriesNum, int itemsNum) { 70 | List entries = new ArrayList(); 71 | // Creating dummy data. 72 | OpenHelper openHelper = mContextLogic.createOpenHelper(); 73 | for (int i = 0; i < entriesNum; i++) { 74 | CheckListEntry entry = new CheckListEntry(); 75 | entry.setTitle("Entry " + i); 76 | entry.setSort((long) i); 77 | entry.setItems(new ArrayList()); 78 | for (int j = 0; j < itemsNum; j++) { 79 | CheckListItem item = new CheckListItem(); 80 | item.setLabel("Item " + j); 81 | item.setSort((long)j); 82 | entry.getItems().add(item); 83 | } 84 | openHelper.registerEntry(entry); 85 | entries.add(entry); 86 | } 87 | return entries; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /app/src/androidTest/java/net/cattaka/android/fastchecklist/test/TestContextLogic.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist.test; 2 | 3 | import android.content.Context; 4 | import android.test.RenamingDelegatingContext; 5 | 6 | import net.cattaka.android.fastchecklist.core.ContextLogic; 7 | import net.cattaka.android.fastchecklist.db.OpenHelper; 8 | 9 | /** 10 | * Created by takao on 2015/04/24. 11 | */ 12 | public class TestContextLogic extends ContextLogic { 13 | private RenamingDelegatingContext mRdContext; 14 | public TestContextLogic(Context context) { 15 | super(context); 16 | mRdContext = new RenamingDelegatingContext(context, "test_"); 17 | } 18 | 19 | @Override 20 | public OpenHelper createOpenHelper() { 21 | return new OpenHelper(mRdContext); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/androidTest/java/net/cattaka/android/fastchecklist/test/TestUtil.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist.test; 2 | 3 | import android.os.SystemClock; 4 | 5 | /** 6 | * Created by cattaka on 15/07/05. 7 | */ 8 | public class TestUtil { 9 | public static void waitForBoolean(BooleanFunc func, int timeout) { 10 | long time = SystemClock.elapsedRealtime(); 11 | do { 12 | if (func.run()) { 13 | break; 14 | } 15 | SystemClock.sleep(50); 16 | } while (SystemClock.elapsedRealtime() - time <= time); 17 | } 18 | 19 | public interface BooleanFunc { 20 | public boolean run(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/androidTest/java/net/cattaka/android/fastchecklist/test/UnlockKeyguardActivity.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist.test; 2 | 3 | import android.app.Activity; 4 | import android.app.KeyguardManager; 5 | import android.content.Context; 6 | import android.os.Bundle; 7 | import android.os.Handler; 8 | import android.os.PowerManager; 9 | import android.view.Window; 10 | import android.view.WindowManager; 11 | 12 | import net.cattaka.android.fastchecklist.test.R; 13 | 14 | /** 15 | * Created by cattaka on 14/11/29. 16 | */ 17 | public class UnlockKeyguardActivity extends Activity { 18 | private static Handler sHandler = new Handler(); 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_unlock_keyguard); 24 | 25 | Window window = this.getWindow(); 26 | window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); 27 | window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); 28 | window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); 29 | } 30 | 31 | @Override 32 | protected void onResume() { 33 | super.onResume(); 34 | sHandler.postDelayed(new Runnable() { 35 | @Override 36 | public void run() { 37 | checkUnlocked(); 38 | } 39 | }, 100); 40 | } 41 | 42 | private void checkUnlocked() { 43 | KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); 44 | PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); 45 | if (!km.inKeyguardRestrictedInputMode() && pm.isScreenOn()) { 46 | finish(); 47 | } else { 48 | sHandler.postDelayed(new Runnable() { 49 | @Override 50 | public void run() { 51 | checkUnlocked(); 52 | } 53 | }, 100); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/androidTest/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cattaka/FastCheckList/705b71093fa24d2b0b6c715ca117221a05738311/app/src/androidTest/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/androidTest/res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cattaka/FastCheckList/705b71093fa24d2b0b6c715ca117221a05738311/app/src/androidTest/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/androidTest/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cattaka/FastCheckList/705b71093fa24d2b0b6c715ca117221a05738311/app/src/androidTest/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/androidTest/res/layout/activity_unlock_keyguard.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/androidTest/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/androidTest/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | EasyCheckListTest 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/java/net/cattaka/android/fastchecklist/CheckListCheckActivity.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Date; 5 | 6 | import net.cattaka.android.fastchecklist.adapter.MyAdapter; 7 | import net.cattaka.android.fastchecklist.core.ContextLogic; 8 | import net.cattaka.android.fastchecklist.core.ContextLogicFactory; 9 | import net.cattaka.android.fastchecklist.db.OpenHelper; 10 | import net.cattaka.android.fastchecklist.model.CheckListEntry; 11 | import net.cattaka.android.fastchecklist.model.CheckListHistory; 12 | import net.cattaka.android.fastchecklist.model.CheckListItem; 13 | import android.app.Activity; 14 | import android.content.Intent; 15 | import android.os.Bundle; 16 | import android.util.SparseBooleanArray; 17 | import android.view.View; 18 | import android.widget.AdapterView; 19 | import android.widget.ListView; 20 | import android.widget.TextView; 21 | 22 | public class CheckListCheckActivity extends Activity implements View.OnClickListener { 23 | public static final String EXTRA_TARGET_ENTRY_ID = "TARGET_ENTRY_ID"; 24 | 25 | private ContextLogic mContextLogic = ContextLogicFactory.createContextLogic(this); 26 | 27 | private CheckListEntry mEntry; 28 | private MyAdapter mItemsAdapter; 29 | private OpenHelper mOpenHelper; 30 | 31 | /** Called when the activity is first created. */ 32 | @Override 33 | public void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.layout_check); 36 | 37 | mOpenHelper = mContextLogic.createOpenHelper(); 38 | { 39 | Intent intent = getIntent(); 40 | Long entryId = intent.getLongExtra(EXTRA_TARGET_ENTRY_ID, -1L); 41 | if (entryId != null && entryId >= 0L) { 42 | mEntry = mOpenHelper.findEntry(entryId, true); 43 | } 44 | } 45 | 46 | if (mEntry == null) { 47 | mEntry = new CheckListEntry(); 48 | mEntry.setItems(new ArrayList()); 49 | mEntry.setTitle(""); 50 | } 51 | 52 | findViewById(R.id.button_ok).setOnClickListener(this); 53 | findViewById(R.id.button_cancel).setOnClickListener(this); 54 | 55 | TextView textTitle = (TextView) findViewById(R.id.text_title); 56 | textTitle.setText(mEntry.getTitle()); 57 | mItemsAdapter = new MyAdapter(this, new ArrayList(mEntry.getItems())); 58 | ListView listView = (ListView) findViewById(R.id.list_items); 59 | listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 60 | listView.setAdapter(mItemsAdapter); 61 | 62 | listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 63 | @Override 64 | public void onItemClick(AdapterView parent, View view, int position, long id) { 65 | updateOkButton(); 66 | } 67 | }); 68 | 69 | updateOkButton(); 70 | } 71 | 72 | @Override 73 | public void onClick(View v) { 74 | if (v.getId() == R.id.button_ok) { 75 | CheckListHistory checkListHistory = new CheckListHistory(); 76 | { // 登録データの作成 77 | checkListHistory.setEntryId(mEntry.getId()); 78 | checkListHistory.setDate(new Date()); 79 | } 80 | { // DBへの書き込みの実施 81 | mOpenHelper.registerHistory(checkListHistory); 82 | } 83 | finish(); 84 | } else if (v.getId() == R.id.button_cancel) { 85 | finish(); 86 | } 87 | } 88 | private void updateOkButton() { 89 | boolean okFlag = true; 90 | ListView listView = (ListView) findViewById(R.id.list_items); 91 | SparseBooleanArray sba = listView.getCheckedItemPositions(); 92 | for (int i=0;i { 34 | public AdapterEx(List items) { 35 | super(CheckListEntryActivity.this, R.layout.layout_entry_item, 36 | items); 37 | } 38 | 39 | @Override 40 | public View getView(int position, View convertView, ViewGroup parent) { 41 | CheckListItem item = getItem(position); 42 | if (convertView == null) { 43 | LayoutInflater inflater = LayoutInflater 44 | .from(CheckListEntryActivity.this); 45 | convertView = inflater 46 | .inflate(R.layout.layout_entry_item, null); 47 | convertView.setOnClickListener(onClickListenerForItems); 48 | convertView.findViewById(R.id.button_up).setOnClickListener( 49 | onClickListenerForItems); 50 | convertView.findViewById(R.id.button_down).setOnClickListener( 51 | onClickListenerForItems); 52 | convertView.findViewById(R.id.button_trash).setOnClickListener( 53 | onClickListenerForItems); 54 | } 55 | convertView.setTag(position); 56 | convertView.findViewById(R.id.button_up).setTag(position); 57 | convertView.findViewById(R.id.button_down).setTag(position); 58 | convertView.findViewById(R.id.button_trash).setTag(position); 59 | 60 | TextView textLabel = (TextView) convertView 61 | .findViewById(R.id.text_label); 62 | textLabel.setText(item.getLabel()); 63 | return convertView; 64 | } 65 | } 66 | 67 | private ContextLogic mContextLogic = ContextLogicFactory.createContextLogic(this); 68 | 69 | private CheckListEntry mEntry; 70 | private AdapterEx mItemsAdapter; 71 | private int mTargetEntryIndex; 72 | private View.OnClickListener onClickListenerForItems = new View.OnClickListener() { 73 | public void onClick(View v) { 74 | int position; 75 | { 76 | if (!(v.getTag() instanceof Integer)) { 77 | return; 78 | } 79 | position = (Integer) v.getTag(); 80 | if (position < 0 || mItemsAdapter.getCount() <= position) { 81 | return; 82 | } 83 | } 84 | onClickItem(v.getId(), position); 85 | }; 86 | }; 87 | 88 | void onClickItem(int viewId, int position) { 89 | mTargetEntryIndex = position; 90 | 91 | if (viewId == R.id.button_up) { 92 | if (position > 0) { 93 | CheckListItem item = mItemsAdapter.getItem(position); 94 | mItemsAdapter.remove(item); 95 | mItemsAdapter.insert(item, position - 1); 96 | } 97 | } else if (viewId == R.id.button_down) { 98 | if (position < mItemsAdapter.getCount() - 1) { 99 | CheckListItem item = mItemsAdapter.getItem(position); 100 | mItemsAdapter.remove(item); 101 | mItemsAdapter.insert(item, position + 1); 102 | } 103 | } else if (viewId == R.id.button_trash) { 104 | showDialog(DIALOG_TRASH); 105 | } else { 106 | CheckListItem item = mItemsAdapter.getItem(position); 107 | ItemEntryDialog dialog = new ItemEntryDialog( 108 | this); 109 | dialog.setTitle(R.string.dialog_title_change_label); 110 | dialog.setup(new ItemEntryDialog.OnItemEntryListener() { 111 | @Override 112 | public void onOk(CheckListItem item) { 113 | mItemsAdapter.notifyDataSetChanged(); 114 | } 115 | 116 | @Override 117 | public void onCancel() { 118 | } 119 | }, item); 120 | dialog.show(); 121 | } 122 | } 123 | 124 | private OpenHelper mOpenHelper; 125 | 126 | /** Called when the activity is first created. */ 127 | @Override 128 | public void onCreate(Bundle savedInstanceState) { 129 | super.onCreate(savedInstanceState); 130 | setContentView(R.layout.layout_entry); 131 | 132 | mOpenHelper = mContextLogic.createOpenHelper(); 133 | { 134 | Intent intent = getIntent(); 135 | Long entryId = intent.getLongExtra(EXTRA_TARGET_ENTRY_ID, -1L); 136 | if (entryId != null && entryId >= 0L) { 137 | mEntry = mOpenHelper.findEntry(entryId, true); 138 | } 139 | } 140 | 141 | if (mEntry == null) { 142 | mEntry = new CheckListEntry(); 143 | mEntry.setItems(new ArrayList()); 144 | mEntry.setTitle(""); 145 | } 146 | 147 | findViewById(R.id.button_add_item).setOnClickListener(this); 148 | findViewById(R.id.button_ok).setOnClickListener(this); 149 | findViewById(R.id.button_cancel).setOnClickListener(this); 150 | 151 | EditText editTitle = (EditText) findViewById(R.id.edit_title); 152 | editTitle.setText(mEntry.getTitle()); 153 | mItemsAdapter = new AdapterEx(new ArrayList( 154 | mEntry.getItems())); 155 | ListView listView = (ListView) findViewById(R.id.list_items); 156 | listView.setAdapter(mItemsAdapter); 157 | } 158 | 159 | private void deleteItem(int pos) { 160 | if (pos < 0 || mItemsAdapter.getCount() <= pos) { 161 | return; 162 | } 163 | CheckListItem item = mItemsAdapter.getItem(pos); 164 | mItemsAdapter.remove(item); 165 | } 166 | 167 | @Override 168 | public void onClick(View v) { 169 | if (v.getId() == R.id.button_add_item) { 170 | ItemEntryDialog dialog = new ItemEntryDialog(this); 171 | dialog.setTitle(R.string.dialog_title_input_label); 172 | dialog.setup(new ItemEntryDialog.OnItemEntryListener() { 173 | @Override 174 | public void onOk(CheckListItem item) { 175 | mItemsAdapter.add(item); 176 | mItemsAdapter.notifyDataSetChanged(); 177 | } 178 | 179 | @Override 180 | public void onCancel() { 181 | } 182 | }, new CheckListItem()); 183 | dialog.show(); 184 | } else if (v.getId() == R.id.button_ok) { 185 | { 186 | EditText editTitle = (EditText) findViewById(R.id.edit_title); 187 | String title = String.valueOf(editTitle.getText()); 188 | mEntry.setTitle(title); 189 | } 190 | { // 登録用itemデータの作成 191 | mEntry.getItems().clear(); 192 | for (int i = 0; i < mItemsAdapter.getCount(); i++) { 193 | CheckListItem item = mItemsAdapter.getItem(i); 194 | mEntry.getItems().add(item); 195 | } 196 | } 197 | { // DBへの書き込みの実施 198 | mOpenHelper.registerEntry(mEntry); 199 | } 200 | finish(); 201 | } else if (v.getId() == R.id.button_cancel) { 202 | finish(); 203 | } 204 | } 205 | @Override 206 | protected Dialog onCreateDialog(int id) { 207 | switch (id) { 208 | case DIALOG_TRASH: { 209 | String title = getResources().getString(R.string.dialog_title_confirm); 210 | String message = getResources().getString(R.string.msg_delete_confirm); 211 | CharSequence messageSec = Html.fromHtml(message); 212 | 213 | DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { 214 | @Override 215 | public void onClick(DialogInterface dialog, int which) { 216 | if (which == DialogInterface.BUTTON_POSITIVE) { 217 | if (mTargetEntryIndex >= 0) { 218 | deleteItem(mTargetEntryIndex); 219 | mTargetEntryIndex = -1; 220 | dialog.dismiss(); 221 | } 222 | } else if (which == DialogInterface.BUTTON_NEGATIVE) { 223 | dialog.dismiss(); 224 | } 225 | } 226 | }; 227 | return new AlertDialog.Builder(this) 228 | .setIcon(android.R.drawable.ic_dialog_alert) 229 | .setTitle(title) 230 | .setMessage(messageSec) 231 | .setPositiveButton(android.R.string.ok,listener) 232 | .setNegativeButton(android.R.string.cancel,listener) 233 | .create(); 234 | } 235 | } 236 | return super.onCreateDialog(id); 237 | } 238 | } -------------------------------------------------------------------------------- /app/src/main/java/net/cattaka/android/fastchecklist/FastCheckListActivity.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import android.app.Activity; 7 | import android.app.AlertDialog; 8 | import android.app.Dialog; 9 | import android.content.DialogInterface; 10 | import android.content.Intent; 11 | import android.os.Bundle; 12 | import android.text.Html; 13 | import android.view.LayoutInflater; 14 | import android.view.Menu; 15 | import android.view.MenuItem; 16 | import android.view.View; 17 | import android.view.ViewGroup; 18 | import android.widget.ArrayAdapter; 19 | import android.widget.ListView; 20 | import android.widget.TextView; 21 | import net.cattaka.android.fastchecklist.R; 22 | import net.cattaka.android.fastchecklist.core.ContextLogic; 23 | import net.cattaka.android.fastchecklist.core.ContextLogicFactory; 24 | import net.cattaka.android.fastchecklist.db.OpenHelper; 25 | import net.cattaka.android.fastchecklist.model.CheckListEntry; 26 | import net.cattaka.android.fastchecklist.util.ContextUtil; 27 | 28 | public class FastCheckListActivity extends Activity 29 | implements View.OnClickListener 30 | { 31 | private static final int DIALOG_ABOUT = 2; 32 | private static final int DIALOG_TRASH = 3; 33 | 34 | private ContextLogic mContextLogic = ContextLogicFactory.createContextLogic(this); 35 | 36 | private AdapterEx mEntriesAdapter; 37 | private boolean mEditModeFlag = false; 38 | 39 | // UI系 40 | private int mTargetEntryIndex; 41 | 42 | private OpenHelper mOpenHelper; 43 | 44 | class AdapterEx extends ArrayAdapter { 45 | public AdapterEx(List entries) { 46 | super(FastCheckListActivity.this, R.layout.layout_main_item, entries); 47 | } 48 | @Override 49 | public View getView(int position, View convertView, ViewGroup parent) { 50 | CheckListEntry entry = getItem(position); 51 | if (convertView == null) { 52 | LayoutInflater inflater = LayoutInflater.from(FastCheckListActivity.this); 53 | convertView = inflater.inflate(R.layout.layout_main_item, null); 54 | convertView.setOnClickListener(mOnClickListenerForEntries); 55 | convertView.findViewById(R.id.button_trash).setOnClickListener(mOnClickListenerForEntries); 56 | convertView.findViewById(R.id.button_up).setOnClickListener(mOnClickListenerForEntries); 57 | convertView.findViewById(R.id.button_down).setOnClickListener(mOnClickListenerForEntries); 58 | convertView.findViewById(R.id.button_edit).setOnClickListener(mOnClickListenerForEntries); 59 | convertView.findViewById(R.id.button_check).setOnClickListener(mOnClickListenerForEntries); 60 | } 61 | convertView.setTag(position); 62 | convertView.findViewById(R.id.button_trash).setTag(position); 63 | convertView.findViewById(R.id.button_up).setTag(position); 64 | convertView.findViewById(R.id.button_down).setTag(position); 65 | convertView.findViewById(R.id.button_edit).setTag(position); 66 | convertView.findViewById(R.id.button_check).setTag(position); 67 | 68 | convertView.findViewById(R.id.button_trash).setVisibility((mEditModeFlag) ? View.VISIBLE : View.GONE); 69 | convertView.findViewById(R.id.button_up).setVisibility((mEditModeFlag) ? View.VISIBLE : View.GONE); 70 | convertView.findViewById(R.id.button_down).setVisibility((mEditModeFlag) ? View.VISIBLE : View.GONE); 71 | convertView.findViewById(R.id.button_edit).setVisibility((mEditModeFlag) ? View.VISIBLE : View.GONE); 72 | convertView.findViewById(R.id.button_check).setVisibility((!mEditModeFlag) ? View.VISIBLE : View.GONE); 73 | 74 | TextView textLabel = (TextView) convertView.findViewById(R.id.text_label); 75 | textLabel.setText(entry.getTitle()); 76 | return convertView; 77 | } 78 | } 79 | 80 | private View.OnClickListener mOnClickListenerForEntries = new View.OnClickListener() { 81 | @Override 82 | public void onClick(View v) { 83 | int position; 84 | { 85 | if (!(v.getTag() instanceof Integer)) { 86 | return; 87 | } 88 | position = (Integer) v.getTag(); 89 | if (position < 0 || mEntriesAdapter.getCount() <= position) { 90 | return; 91 | } 92 | } 93 | mTargetEntryIndex = position; 94 | if (v.getId() == R.id.button_up) { 95 | swapEntries(position, position - 1); 96 | } else if (v.getId() == R.id.button_down) { 97 | swapEntries(position, position + 1); 98 | } else if (v.getId() == R.id.button_check) { 99 | CheckListEntry entry = mEntriesAdapter.getItem(position); 100 | Intent intent = new Intent(FastCheckListActivity.this, CheckListCheckActivity.class); 101 | intent.putExtra(CheckListCheckActivity.EXTRA_TARGET_ENTRY_ID, entry.getId()); 102 | startActivity(intent); 103 | } else if (v.getId() == R.id.button_edit) { 104 | CheckListEntry entry = mEntriesAdapter.getItem(position); 105 | Intent intent = new Intent(FastCheckListActivity.this, CheckListEntryActivity.class); 106 | intent.putExtra(CheckListEntryActivity.EXTRA_TARGET_ENTRY_ID, entry.getId()); 107 | startActivity(intent); 108 | } else if (v.getId() == R.id.button_trash) { 109 | showDialog(DIALOG_TRASH); 110 | } 111 | } 112 | }; 113 | 114 | /** Called when the activity is first created. */ 115 | @Override 116 | public void onCreate(Bundle savedInstanceState) { 117 | super.onCreate(savedInstanceState); 118 | setContentView(R.layout.layout_main); 119 | 120 | mOpenHelper = mContextLogic.createOpenHelper(); 121 | 122 | findViewById(R.id.button_add_entry).setOnClickListener(this); 123 | findViewById(R.id.button_enter_edit_mode).setOnClickListener(this); 124 | findViewById(R.id.button_exit_edit_mode).setOnClickListener(this); 125 | 126 | changeEditMode(false); 127 | } 128 | @Override 129 | protected void onResume() { 130 | super.onResume(); 131 | { 132 | // Intent intent = new Intent(this, TelnetSqliteService.class); 133 | // startService(intent); 134 | } 135 | List entries; 136 | { 137 | entries = mOpenHelper.findEntry(); 138 | if (entries == null) { 139 | entries = new ArrayList(); 140 | } 141 | } 142 | { 143 | mEntriesAdapter = new AdapterEx(entries); 144 | ListView listView = (ListView) findViewById(R.id.list_entries); 145 | listView.setAdapter(mEntriesAdapter); 146 | } 147 | } 148 | 149 | private void deleteEntries(int pos) { 150 | if (pos < 0 || mEntriesAdapter.getCount() <= pos) { 151 | return; 152 | } 153 | CheckListEntry entry = mEntriesAdapter.getItem(pos); 154 | mOpenHelper.deleteEntry(entry.getId()); 155 | mEntriesAdapter.remove(entry); 156 | } 157 | private void swapEntries(int pos1, int pos2) { 158 | if (pos1 < 0 || mEntriesAdapter.getCount() <= pos1 || pos2 < 0 || mEntriesAdapter.getCount() <= pos2) { 159 | return; 160 | } 161 | CheckListEntry entry1 = mEntriesAdapter.getItem(pos1); 162 | CheckListEntry entry2 = mEntriesAdapter.getItem(pos2); 163 | mOpenHelper.swapEntriesSort(entry1.getId(), entry2.getId()); 164 | 165 | mEntriesAdapter.remove(entry1); 166 | mEntriesAdapter.remove(entry2); 167 | if (pos1 < pos2) { 168 | mEntriesAdapter.insert(entry2, pos1); 169 | mEntriesAdapter.insert(entry1, pos2); 170 | } else { 171 | mEntriesAdapter.insert(entry1, pos2); 172 | mEntriesAdapter.insert(entry2, pos1); 173 | } 174 | } 175 | @Override 176 | public boolean onCreateOptionsMenu(Menu menu) { 177 | getMenuInflater().inflate(R.menu.menu, menu); 178 | return true; 179 | } 180 | 181 | @Override 182 | public boolean onMenuItemSelected(int featureId, MenuItem item) { 183 | if (item.getItemId() == R.id.menu_about) { 184 | showDialog(DIALOG_ABOUT); 185 | return true; 186 | } 187 | return super.onMenuItemSelected(featureId, item); 188 | } 189 | 190 | @Override 191 | protected Dialog onCreateDialog(int id) { 192 | switch (id) { 193 | case DIALOG_ABOUT: { 194 | String title = getResources().getString(R.string.app_name) + " " 195 | + ContextUtil.getVersion(this); 196 | String message = getResources().getString(R.string.msg_about); 197 | CharSequence messageSec = Html.fromHtml(message); 198 | 199 | return new AlertDialog.Builder(this) 200 | .setIcon(R.drawable.ic_launcher) 201 | .setTitle(title) 202 | .setMessage(messageSec) 203 | .setNeutralButton(android.R.string.ok, 204 | new DialogInterface.OnClickListener() { 205 | public void onClick(DialogInterface dialog, 206 | int whichButton) { 207 | /* User clicked Something so do some stuff */ 208 | } 209 | }).create(); 210 | } 211 | case DIALOG_TRASH: { 212 | String title = getResources().getString(R.string.dialog_title_confirm); 213 | String message = getResources().getString(R.string.msg_delete_confirm); 214 | CharSequence messageSec = Html.fromHtml(message); 215 | 216 | DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { 217 | @Override 218 | public void onClick(DialogInterface dialog, int which) { 219 | if (which == DialogInterface.BUTTON_POSITIVE) { 220 | if (mTargetEntryIndex >= 0) { 221 | deleteEntries(mTargetEntryIndex); 222 | mTargetEntryIndex = -1; 223 | dialog.dismiss(); 224 | } 225 | } else if (which == DialogInterface.BUTTON_NEGATIVE) { 226 | dialog.dismiss(); 227 | } 228 | } 229 | }; 230 | return new AlertDialog.Builder(this) 231 | .setIcon(android.R.drawable.ic_dialog_alert) 232 | .setTitle(title) 233 | .setMessage(messageSec) 234 | .setPositiveButton(android.R.string.ok,listener) 235 | .setNegativeButton(android.R.string.cancel,listener) 236 | .create(); 237 | } 238 | } 239 | return super.onCreateDialog(id); 240 | } 241 | @Override 242 | public void onClick(View v) { 243 | if (v.getId() == R.id.button_add_entry) { 244 | Intent intent = new Intent(this, CheckListEntryActivity.class); 245 | startActivity(intent); 246 | } else if (v.getId() == R.id.button_enter_edit_mode) { 247 | changeEditMode(true); 248 | } else if (v.getId() == R.id.button_exit_edit_mode) { 249 | changeEditMode(false); 250 | } 251 | } 252 | private void changeEditMode(boolean editModeFlag) { 253 | if (editModeFlag) { 254 | mEditModeFlag = editModeFlag; 255 | findViewById(R.id.button_enter_edit_mode).setVisibility(View.GONE); 256 | findViewById(R.id.button_exit_edit_mode).setVisibility(View.VISIBLE); 257 | if (mEntriesAdapter != null) { 258 | mEntriesAdapter.notifyDataSetChanged(); 259 | } 260 | } else { 261 | mEditModeFlag = editModeFlag; 262 | findViewById(R.id.button_enter_edit_mode).setVisibility(View.VISIBLE); 263 | findViewById(R.id.button_exit_edit_mode).setVisibility(View.GONE); 264 | if (mEntriesAdapter != null) { 265 | mEntriesAdapter.notifyDataSetChanged(); 266 | } 267 | } 268 | } 269 | } -------------------------------------------------------------------------------- /app/src/main/java/net/cattaka/android/fastchecklist/FastCheckListConstants.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist; 2 | 3 | public class FastCheckListConstants { 4 | public static final String DB_NAME = "data.db"; 5 | } 6 | -------------------------------------------------------------------------------- /app/src/main/java/net/cattaka/android/fastchecklist/MyAppliction.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | 6 | /** 7 | * Created by cattaka on 14/09/27. 8 | */ 9 | public class MyAppliction extends Application { 10 | @Override 11 | public void onCreate() { 12 | super.onCreate(); 13 | // SQLiteにアクセするためのサーバーを起動する(開発時専用) 14 | try { 15 | Class clazz = Class.forName("net.cattaka.telnetsqlite.TelnetSqliteService"); 16 | Thread serverThread = (Thread)clazz.getMethod("createTelnetSqliteServer", Context.class, int.class).invoke(null, this, 12080); 17 | serverThread.start(); 18 | } catch (Exception e) { 19 | // ignore 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/net/cattaka/android/fastchecklist/adapter/MyAdapter.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.ArrayAdapter; 8 | import android.widget.CheckedTextView; 9 | 10 | import net.cattaka.android.fastchecklist.R; 11 | import net.cattaka.android.fastchecklist.model.CheckListItem; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * Created by takao on 2015/04/24. 17 | */ 18 | public class MyAdapter extends ArrayAdapter { 19 | public MyAdapter(Context context, List items) { 20 | super(context, R.layout.layout_check_item, items); 21 | } 22 | @Override 23 | public View getView(int position, View convertView, ViewGroup parent) { 24 | CheckListItem item = getItem(position); 25 | if (convertView == null) { 26 | LayoutInflater inflater = LayoutInflater.from(getContext()); 27 | convertView = inflater.inflate(R.layout.layout_check_item, null); 28 | } 29 | convertView.setTag(position); 30 | 31 | CheckedTextView textLabel = (CheckedTextView) convertView; 32 | textLabel.setText(item.getLabel()); 33 | return convertView; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/net/cattaka/android/fastchecklist/core/ContextLogic.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist.core; 2 | 3 | import android.content.Context; 4 | 5 | import net.cattaka.android.fastchecklist.db.OpenHelper; 6 | 7 | /** 8 | * Created by cattaka on 14/11/28. 9 | */ 10 | public class ContextLogic { 11 | protected Context mContext; 12 | 13 | public ContextLogic(Context context) { 14 | mContext = context; 15 | } 16 | 17 | public OpenHelper createOpenHelper() { 18 | return new OpenHelper(mContext); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/net/cattaka/android/fastchecklist/core/ContextLogicFactory.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist.core; 2 | 3 | import android.content.Context; 4 | 5 | /** 6 | * Created by cattaka on 14/11/28. 7 | */ 8 | public class ContextLogicFactory { 9 | static ContextLogicFactory INSTANCE = new ContextLogicFactory(); 10 | public ContextLogic newInstance(Context context) { 11 | return new ContextLogic(context); 12 | } 13 | 14 | public static ContextLogic createContextLogic(Context context) { 15 | return INSTANCE.newInstance(context); 16 | } 17 | 18 | public static void replaceInstance(ContextLogicFactory INSTANCE) { 19 | ContextLogicFactory.INSTANCE = INSTANCE; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/net/cattaka/android/fastchecklist/db/OpenHelper.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist.db; 2 | 3 | import android.content.ContentValues; 4 | import android.content.Context; 5 | import android.content.res.Resources; 6 | import android.database.Cursor; 7 | import android.database.sqlite.SQLiteDatabase; 8 | import android.database.sqlite.SQLiteOpenHelper; 9 | 10 | import net.cattaka.android.fastchecklist.FastCheckListConstants; 11 | import net.cattaka.android.fastchecklist.R; 12 | import net.cattaka.android.fastchecklist.exception.DbException; 13 | import net.cattaka.android.fastchecklist.model.CheckListEntry; 14 | import net.cattaka.android.fastchecklist.model.CheckListEntryCatHands; 15 | import net.cattaka.android.fastchecklist.model.CheckListHistory; 16 | import net.cattaka.android.fastchecklist.model.CheckListHistoryCatHands; 17 | import net.cattaka.android.fastchecklist.model.CheckListItem; 18 | import net.cattaka.android.fastchecklist.model.CheckListItemCatHands; 19 | 20 | import java.util.ArrayList; 21 | import java.util.HashSet; 22 | import java.util.List; 23 | import java.util.Set; 24 | 25 | public class OpenHelper extends SQLiteOpenHelper { 26 | public static final int VERSION = 1; 27 | private Context mContext; 28 | 29 | public OpenHelper(Context context) { 30 | this(context, FastCheckListConstants.DB_NAME); 31 | } 32 | 33 | public OpenHelper(Context context, String name) { 34 | super(context, name, null, VERSION); 35 | mContext = context; 36 | } 37 | 38 | @Override 39 | public void onCreate(SQLiteDatabase db) { 40 | db.execSQL(CheckListEntryCatHands.SQL_CREATE_TABLE); 41 | db.execSQL(CheckListItemCatHands.SQL_CREATE_TABLE); 42 | db.execSQL(CheckListHistoryCatHands.SQL_CREATE_TABLE); 43 | { 44 | Resources resources = mContext.getResources(); 45 | CheckListEntry entry = new CheckListEntry(); 46 | entry.setTitle(resources.getString(R.string.sample_title)); 47 | entry.setItems(new ArrayList()); 48 | String[] sampleItems = resources.getStringArray(R.array.sample_items); 49 | for (String sampleItem : sampleItems) { 50 | CheckListItem item = new CheckListItem(); 51 | item.setLabel(sampleItem); 52 | entry.getItems().add(item); 53 | } 54 | registerEntry(db, entry); 55 | } 56 | } 57 | 58 | @Override 59 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 60 | CheckListEntryCatHands.upgrade(db, oldVersion, newVersion); 61 | CheckListItemCatHands.upgrade(db, oldVersion, newVersion); 62 | CheckListHistoryCatHands.upgrade(db, oldVersion, newVersion); 63 | } 64 | 65 | public List findEntry() throws DbException { 66 | SQLiteDatabase db = getReadableDatabase(); 67 | try { 68 | return CheckListEntryCatHands.findOrderBySortAsc(db, 0); 69 | } finally { 70 | db.close(); 71 | } 72 | } 73 | 74 | public CheckListEntry findEntry(Long id, boolean withItems) 75 | throws DbException { 76 | SQLiteDatabase db = getReadableDatabase(); 77 | try { 78 | CheckListEntry entry = CheckListEntryCatHands.findById(db, id); 79 | if (entry != null && withItems) { 80 | List items = CheckListItemCatHands 81 | .findByEntryIdOrderBySortAsc(db, 0, id); 82 | entry.setItems(items); 83 | } 84 | return entry; 85 | } finally { 86 | db.close(); 87 | } 88 | } 89 | 90 | public List findHistory(Long id) 91 | throws DbException { 92 | SQLiteDatabase db = getReadableDatabase(); 93 | try { 94 | return CheckListHistoryCatHands.findByEntryIdOrderByIdDesc(db, -1, id); 95 | } finally { 96 | db.close(); 97 | } 98 | } 99 | 100 | public boolean deleteEntry(Long id) { 101 | SQLiteDatabase db = getWritableDatabase(); 102 | boolean flag = false; 103 | try { 104 | db.beginTransaction(); 105 | db.delete(CheckListItemCatHands.TABLE_NAME, "entryId=?", new String[]{String.valueOf(id)}); 106 | flag = (CheckListEntryCatHands.delete(db, id) == 1); 107 | db.setTransactionSuccessful(); 108 | } finally { 109 | db.endTransaction(); 110 | db.close(); 111 | } 112 | return flag; 113 | } 114 | 115 | private long getMaxSortNo(SQLiteDatabase db) { 116 | Long maxSort = 0L; 117 | List entries = CheckListEntryCatHands.findByMaxSortNo(db); 118 | CheckListEntry entry = (entries.size() > 0) ? entries.get(0) : null; 119 | maxSort = (entry.getSort() != null) ? entry.getSort() : 0; 120 | return maxSort; 121 | } 122 | 123 | public void registerEntry(CheckListEntry entry) { 124 | SQLiteDatabase db = getWritableDatabase(); 125 | try { 126 | registerEntry(db, entry); 127 | } finally { 128 | db.close(); 129 | } 130 | } 131 | public void registerEntry(SQLiteDatabase db, CheckListEntry entry) { 132 | try { 133 | db.beginTransaction(); 134 | { // entryのinsert/update 135 | if (entry.getId() != null) { 136 | CheckListEntryCatHands.update(db, entry); 137 | } else { 138 | entry.setSort(getMaxSortNo(db) + 1); 139 | CheckListEntryCatHands.insert(db, entry); 140 | } 141 | } 142 | { // 削除されたitemのdelete 143 | Set deletedIds = new HashSet(); 144 | List oldItems = CheckListItemCatHands 145 | .findByEntryIdOrderBySortAsc(db, 0, entry.getId()); 146 | for (CheckListItem item : oldItems) { 147 | deletedIds.add(item.getId()); 148 | } 149 | if (entry.getItems() != null) { 150 | for (CheckListItem item : entry.getItems()) { 151 | if (item.getId() != null) { 152 | deletedIds.remove(item.getId()); 153 | } 154 | } 155 | } 156 | for (Long id : deletedIds) { 157 | CheckListItemCatHands.delete(db, id); 158 | } 159 | } 160 | { // itemのinsert/update 161 | if (entry.getItems() != null) { 162 | long sort = 1; 163 | for (CheckListItem item : entry.getItems()) { 164 | item.setEntryId(entry.getId()); 165 | item.setSort(sort); 166 | if (item.getId() != null) { 167 | CheckListItemCatHands.update(db, item); 168 | } else { 169 | CheckListItemCatHands.insert(db, item); 170 | } 171 | sort++; 172 | } 173 | } 174 | } 175 | db.setTransactionSuccessful(); 176 | } finally { 177 | db.endTransaction(); 178 | } 179 | } 180 | 181 | public void registerHistory(CheckListHistory history) { 182 | SQLiteDatabase db = getWritableDatabase(); 183 | try { 184 | db.beginTransaction(); 185 | { // historyのinsert/update 186 | if (history.getId() != null) { 187 | CheckListHistoryCatHands.update(db, history); 188 | } else { 189 | CheckListHistoryCatHands.insert(db, history); 190 | } 191 | } 192 | db.setTransactionSuccessful(); 193 | } finally { 194 | db.endTransaction(); 195 | db.close(); 196 | } 197 | } 198 | public void swapEntriesSort(Long id1, Long id2) { 199 | SQLiteDatabase db = getWritableDatabase(); 200 | try { 201 | db.beginTransaction(); 202 | CheckListEntry entry1 = CheckListEntryCatHands.findById(db, id1); 203 | CheckListEntry entry2 = CheckListEntryCatHands.findById(db, id2); 204 | { 205 | ContentValues values = new ContentValues(); 206 | values.put("sort", entry2.getSort()); 207 | db.update(CheckListEntryCatHands.TABLE_NAME, values, "id=?", new String[]{String.valueOf(id1)}); 208 | } 209 | { 210 | ContentValues values = new ContentValues(); 211 | values.put("sort", entry1.getSort()); 212 | db.update(CheckListEntryCatHands.TABLE_NAME, values, "id=?", new String[]{String.valueOf(id2)}); 213 | } 214 | db.setTransactionSuccessful(); 215 | } finally { 216 | db.endTransaction(); 217 | db.close(); 218 | } 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /app/src/main/java/net/cattaka/android/fastchecklist/exception/DbException.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist.exception; 2 | 3 | public class DbException extends RuntimeException { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public DbException() { 7 | super(); 8 | } 9 | 10 | public DbException(String detailMessage, Throwable throwable) { 11 | super(detailMessage, throwable); 12 | } 13 | 14 | public DbException(String detailMessage) { 15 | super(detailMessage); 16 | } 17 | 18 | public DbException(Throwable throwable) { 19 | super(throwable); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/net/cattaka/android/fastchecklist/model/CheckListEntry.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist.model; 2 | 3 | import net.cattaka.util.cathandsgendroid.annotation.DataModel; 4 | import net.cattaka.util.cathandsgendroid.annotation.DataModelAttrs; 5 | 6 | import java.util.List; 7 | 8 | @DataModel( 9 | find={"id",":sort+"}, 10 | unique={"title"}, 11 | query={"MaxSortNo:select max(sort) as sort from checkListEntry"} 12 | ) 13 | public class CheckListEntry { 14 | @DataModelAttrs(primaryKey=true) 15 | private Long id; 16 | private String title; 17 | private Long sort; 18 | private Long starFlag; 19 | @DataModelAttrs(ignore=true) 20 | private List items; 21 | 22 | public Long getId() { 23 | return id; 24 | } 25 | public void setId(Long id) { 26 | this.id = id; 27 | } 28 | public String getTitle() { 29 | return title; 30 | } 31 | public void setTitle(String title) { 32 | this.title = title; 33 | } 34 | public List getItems() { 35 | return items; 36 | } 37 | public void setItems(List items) { 38 | this.items = items; 39 | } 40 | public Long getSort() { 41 | return sort; 42 | } 43 | public void setSort(Long sort) { 44 | this.sort = sort; 45 | } 46 | public Long getStarFlag() { 47 | return starFlag; 48 | } 49 | public void setStarFlag(Long starFlag) { 50 | this.starFlag = starFlag; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/net/cattaka/android/fastchecklist/model/CheckListHistory.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist.model; 2 | 3 | import java.util.Date; 4 | 5 | import net.cattaka.util.cathandsgendroid.annotation.DataModel; 6 | import net.cattaka.util.cathandsgendroid.annotation.DataModelAttrs; 7 | 8 | @DataModel( 9 | find={"id:id-","entryId:id-"} 10 | ) 11 | public class CheckListHistory { 12 | @DataModelAttrs(primaryKey=true) 13 | private Long id; 14 | private Long entryId; 15 | private Date date; 16 | 17 | public Long getId() { 18 | return id; 19 | } 20 | public void setId(Long id) { 21 | this.id = id; 22 | } 23 | public Long getEntryId() { 24 | return entryId; 25 | } 26 | public void setEntryId(Long entryId) { 27 | this.entryId = entryId; 28 | } 29 | public Date getDate() { 30 | return date; 31 | } 32 | public void setDate(Date date) { 33 | this.date = date; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/net/cattaka/android/fastchecklist/model/CheckListItem.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist.model; 2 | 3 | import net.cattaka.util.cathandsgendroid.annotation.DataModel; 4 | import net.cattaka.util.cathandsgendroid.annotation.DataModelAttrs; 5 | 6 | @DataModel( 7 | find={"id","entryId:sort+"}, 8 | query={"MaxSort:select max(sort) as sort from checkListItem where entryId=?"} 9 | ) 10 | public class CheckListItem { 11 | @DataModelAttrs(primaryKey=true) 12 | private Long id; 13 | private Long entryId; 14 | private Long sort; 15 | private String label; 16 | 17 | public CheckListItem() { 18 | } 19 | 20 | public CheckListItem(Long id, Long entryId, Long sort, String label) { 21 | this.id = id; 22 | this.entryId = entryId; 23 | this.sort = sort; 24 | this.label = label; 25 | } 26 | 27 | public Long getId() { 28 | return id; 29 | } 30 | public void setId(Long id) { 31 | this.id = id; 32 | } 33 | public Long getEntryId() { 34 | return entryId; 35 | } 36 | public void setEntryId(Long entryId) { 37 | this.entryId = entryId; 38 | } 39 | public String getLabel() { 40 | return label; 41 | } 42 | public void setLabel(String label) { 43 | this.label = label; 44 | } 45 | public Long getSort() { 46 | return sort; 47 | } 48 | public void setSort(Long sort) { 49 | this.sort = sort; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/net/cattaka/android/fastchecklist/util/ContextUtil.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist.util; 2 | 3 | import android.content.Context; 4 | import android.content.pm.PackageInfo; 5 | import android.content.pm.PackageManager; 6 | import android.content.pm.PackageManager.NameNotFoundException; 7 | 8 | public class ContextUtil { 9 | public static String getVersion(Context context) { 10 | String versionName = ""; 11 | String packageName = context.getClass().getPackage().getName(); 12 | PackageManager pm = context.getPackageManager(); 13 | try { 14 | PackageInfo info = null; 15 | info = pm.getPackageInfo(packageName, 0); 16 | versionName = info.versionName; 17 | } catch (NameNotFoundException e) { 18 | } 19 | return versionName; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/net/cattaka/android/fastchecklist/view/CheckableLinearLayout.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.widget.Checkable; 6 | import android.widget.LinearLayout; 7 | 8 | public class CheckableLinearLayout extends LinearLayout implements Checkable { 9 | private boolean checked; 10 | private static final int[] CHECKED_STATE_SET = { 11 | android.R.attr.state_checked 12 | }; 13 | 14 | public CheckableLinearLayout(Context context, AttributeSet attrs) { 15 | super(context, attrs); 16 | } 17 | 18 | public CheckableLinearLayout(Context context) { 19 | super(context); 20 | } 21 | 22 | @Override 23 | public boolean isChecked() { 24 | return checked; 25 | } 26 | 27 | @Override 28 | public void setChecked(boolean checked) { 29 | if (this.checked != checked) { 30 | this.checked = checked; 31 | refreshDrawableState(); 32 | } 33 | } 34 | 35 | @Override 36 | public void toggle() { 37 | this.checked = !this.checked; 38 | refreshDrawableState(); 39 | } 40 | 41 | @Override 42 | protected int[] onCreateDrawableState(int extraSpace) { 43 | final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); 44 | if (isChecked()) { 45 | mergeDrawableStates(drawableState, CHECKED_STATE_SET); 46 | } 47 | return drawableState; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/net/cattaka/android/fastchecklist/view/ItemEntryDialog.java: -------------------------------------------------------------------------------- 1 | package net.cattaka.android.fastchecklist.view; 2 | 3 | import net.cattaka.android.fastchecklist.R; 4 | import net.cattaka.android.fastchecklist.model.CheckListItem; 5 | import android.app.Dialog; 6 | import android.content.Context; 7 | import android.os.Bundle; 8 | import android.view.View; 9 | import android.widget.EditText; 10 | 11 | public class ItemEntryDialog extends Dialog implements View.OnClickListener { 12 | public interface OnItemEntryListener { 13 | public void onOk(CheckListItem item); 14 | public void onCancel(); 15 | } 16 | 17 | private CheckListItem mItem; 18 | private OnItemEntryListener mOnItemEntryListener; 19 | 20 | public ItemEntryDialog(Context context) { 21 | super(context); 22 | } 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.dialog_item_entry); 27 | findViewById(R.id.button_ok).setOnClickListener(this); 28 | findViewById(R.id.button_cancel).setOnClickListener(this); 29 | 30 | EditText editLabel = (EditText) findViewById(R.id.edit_label); 31 | editLabel.setText((mItem.getLabel() != null) ? mItem.getLabel() : ""); 32 | } 33 | 34 | @Override 35 | public void onClick(View v) { 36 | if (v.getId() == R.id.button_ok) { 37 | EditText editLabel = (EditText) findViewById(R.id.edit_label); 38 | mItem.setLabel(String.valueOf(editLabel.getText())); 39 | dismiss(); 40 | if (mOnItemEntryListener != null) { 41 | mOnItemEntryListener.onOk(mItem); 42 | } 43 | } else if (v.getId() == R.id.button_cancel) { 44 | dismiss(); 45 | if (mOnItemEntryListener != null) { 46 | mOnItemEntryListener.onCancel(); 47 | } 48 | } 49 | } 50 | public void setup(OnItemEntryListener onItemEntryListener, CheckListItem item) { 51 | this.mOnItemEntryListener = onItemEntryListener; 52 | this.mItem = item; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cattaka/FastCheckList/705b71093fa24d2b0b6c715ca117221a05738311/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cattaka/FastCheckList/705b71093fa24d2b0b6c715ca117221a05738311/app/src/main/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cattaka/FastCheckList/705b71093fa24d2b0b6c715ca117221a05738311/app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/bgcolor_highlighted.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_item_entry.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 9 | 13 |