예제 #1
0
  @LargeTest
  public void testSaveFontSize() throws Exception {
    solo.pressSpinnerItem(0 /* Question font size spinner*/, 4 /* 48 */);
    // solo.sleep(300);
    solo.pressSpinnerItem(2 /* Answer font size spinner*/, 6 /* 72 */);
    // solo.sleep(300);

    assertTrue(solo.searchText("48"));
    assertTrue(solo.searchText("72"));

    // solo.sleep(500);
    solo.clickOnActionBarItem(R.id.save);
    // solo.sleep(2000);

    AnyMemoDBOpenHelper helper =
        AnyMemoDBOpenHelperManager.getHelper(mActivity, TestHelper.SAMPLE_DB_PATH);
    try {
      SettingDao settingDao = helper.getSettingDao();
      Setting setting = settingDao.queryForId(1);
      assertEquals(48, (int) setting.getQuestionFontSize());
      assertEquals(72, (int) setting.getAnswerFontSize());
    } finally {
      AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }
  }
예제 #2
0
  @LargeTest
  public void testTTSAudioLocale() throws Exception {
    solo.pressSpinnerItem(6 /* Question audio spinner */, 3 /* German */);
    // solo.sleep(300);

    solo.pressSpinnerItem(7 /* Answer audio spinner */, 2 /* Italian */);
    // solo.sleep(300);

    solo.clickOnActionBarItem(R.id.save);
    // solo.sleep(2000);

    AnyMemoDBOpenHelper helper =
        AnyMemoDBOpenHelperManager.getHelper(mActivity, TestHelper.SAMPLE_DB_PATH);
    try {
      SettingDao settingDao = helper.getSettingDao();
      Setting setting = settingDao.queryForId(1);
      assertEquals("DE", setting.getQuestionAudio());
      assertEquals("IT", setting.getAnswerAudio());
      assertTrue(Strings.isNullOrEmpty(setting.getQuestionAudioLocation()));
      assertTrue(Strings.isNullOrEmpty(setting.getAnswerAudioLocation()));

    } finally {
      AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }
  }
예제 #3
0
  @SmallTest
  @Test
  public void testMergeCsvIntoDb() throws Exception {
    srcFilePath = AMEnv.DEFAULT_ROOT_PATH + "/" + "csv-test.csv";
    destFilePath = AMEnv.DEFAULT_ROOT_PATH + "/" + "csv-test.db";
    new File(srcFilePath).delete();
    new File(destFilePath).delete();

    AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(getContext(), destFilePath);
    try {
      // Create an new db with some contents
      helper.getCardDao().createCards(newDbCardList);
    } finally {
      AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }

    // Now convert the csv-test.csv into csv-test.db which will be merged
    // into existing csv-test.db
    amFileUtil.copyFileFromAsset("csv-test.csv", new File(srcFilePath));
    Converter converter = new CSVImporter(amFileUtil);
    converter.convert(srcFilePath, destFilePath);

    // verify the content of csv-test has merged cards
    helper = AnyMemoDBOpenHelperManager.getHelper(getContext(), destFilePath);
    try {
      List<Card> cards = helper.getCardDao().getAllCards(null);
      assertEquals(6, cards.size());

      assertEquals(1, (int) cards.get(0).getId());
      assertEquals(1, (int) cards.get(0).getOrdinal());
      assertEquals("old question 1", cards.get(0).getQuestion());
      assertEquals("old answer 1", cards.get(0).getAnswer());

      assertEquals(2, (int) cards.get(1).getId());
      assertEquals(2, (int) cards.get(1).getOrdinal());
      assertEquals("old question 2", cards.get(1).getQuestion());
      assertEquals("old answer 2", cards.get(1).getAnswer());

      assertEquals(3, (int) cards.get(2).getId());
      assertEquals(3, (int) cards.get(2).getOrdinal());
      assertEquals("Question1", cards.get(2).getQuestion());
      assertEquals("Answer1", cards.get(2).getAnswer());
      assertEquals("Category1", cards.get(2).getCategory().getName());
      assertEquals("Note1", cards.get(2).getNote());

      assertEquals(4, (int) cards.get(3).getId());
      assertEquals(4, (int) cards.get(3).getOrdinal());
      assertEquals("Question2", cards.get(3).getQuestion());
      assertEquals("Answer2", cards.get(3).getAnswer());
      assertEquals("Category1", cards.get(3).getCategory().getName());
      assertEquals("Note2", cards.get(3).getNote());
    } finally {
      AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }
  }
예제 #4
0
  @dk.au.cs.thor.robotium2espresso.UnstableTest
  public void testGoBackWithNoSettingChangedShouldQuit() throws Exception {
    solo.goBack();
    // solo.sleep(2000);

    AnyMemoDBOpenHelper helper =
        AnyMemoDBOpenHelperManager.getHelper(mActivity, TestHelper.SAMPLE_DB_PATH);
    try {
      SettingDao settingDao = helper.getSettingDao();
      Setting setting = settingDao.queryForId(1);
      assertEquals(50, (int) setting.getQaRatio());
    } finally {
      AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }
  }
예제 #5
0
  @SmallTest
  @Test
  public void testMergeQATxtIntoDb() throws Exception {
    srcFilePath = AMEnv.DEFAULT_ROOT_PATH + "/" + "qa-text-test.txt";
    destFilePath = AMEnv.DEFAULT_ROOT_PATH + "/" + "qa-text-test.db";
    new File(srcFilePath).delete();
    new File(destFilePath).delete();

    AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(getContext(), destFilePath);
    try {
      // Create an new db with some contents
      helper.getCardDao().createCards(newDbCardList);
    } finally {
      AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }

    amFileUtil.copyFileFromAsset("qa-text-test.txt", new File(srcFilePath));
    Converter converter = new QATxtImporter(amFileUtil);
    converter.convert(srcFilePath, destFilePath);

    helper = AnyMemoDBOpenHelperManager.getHelper(getContext(), destFilePath);
    try {
      List<Card> cards = helper.getCardDao().getAllCards(null);
      assertEquals(4, cards.size());

      assertEquals(1, (int) cards.get(0).getId());
      assertEquals(1, (int) cards.get(0).getOrdinal());
      assertEquals("old question 1", cards.get(0).getQuestion());
      assertEquals("old answer 1", cards.get(0).getAnswer());

      assertEquals(2, (int) cards.get(1).getId());
      assertEquals(2, (int) cards.get(1).getOrdinal());
      assertEquals("old question 2", cards.get(1).getQuestion());
      assertEquals("old answer 2", cards.get(1).getAnswer());

      assertEquals(3, (int) cards.get(2).getId());
      assertEquals(3, (int) cards.get(2).getOrdinal());
      assertEquals("This is question1", cards.get(2).getQuestion());
      assertEquals("Answer1", cards.get(2).getAnswer());

      assertEquals(4, (int) cards.get(3).getId());
      assertEquals(4, (int) cards.get(3).getOrdinal());
      assertEquals("Question2", cards.get(3).getQuestion());
      assertEquals("Answer2", cards.get(3).getAnswer());
    } finally {
      AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }
  }
예제 #6
0
 public static void deleteDbSafe(String filepath) {
   if (!new File(filepath).exists()) {
     return;
   }
   AnyMemoDBOpenHelperManager.forceRelease(filepath);
   new File(filepath).delete();
 }
예제 #7
0
  @LargeTest
  public void testSaveCardStyle() throws Exception {
    solo.pressSpinnerItem(4 /* Card style */, 1 /* Double sided */);

    // solo.sleep(500);
    solo.clickOnActionBarItem(R.id.save);
    // solo.sleep(2000);
    AnyMemoDBOpenHelper helper =
        AnyMemoDBOpenHelperManager.getHelper(mActivity, TestHelper.SAMPLE_DB_PATH);
    try {
      SettingDao settingDao = helper.getSettingDao();
      Setting setting = settingDao.queryForId(1);
      assertEquals(Setting.CardStyle.DOUBLE_SIDED, setting.getCardStyle());
    } finally {
      AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }
  }
예제 #8
0
  @LargeTest
  public void testSaveDisplayRatio() throws Exception {
    solo.pressSpinnerItem(5 /* Q/A ratio */, 1 /* 60% */);
    // solo.sleep(500);

    solo.clickOnActionBarItem(R.id.save);
    // solo.sleep(2000);

    AnyMemoDBOpenHelper helper =
        AnyMemoDBOpenHelperManager.getHelper(mActivity, TestHelper.SAMPLE_DB_PATH);
    try {
      SettingDao settingDao = helper.getSettingDao();
      Setting setting = settingDao.queryForId(1);
      assertEquals(60, (int) setting.getQaRatio());
    } finally {
      AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }
  }
예제 #9
0
  @LargeTest
  public void testGoBackWithSettingChangedPressYesButtonShouldSaveSettings() throws Exception {
    solo.pressSpinnerItem(5 /* Q/A ratio */, 1 /* 60% */);
    // solo.sleep(500);
    solo.goBack();

    // solo.sleep(500);
    solo.clickOnButton(solo.getString(R.string.yes_text));
    // solo.sleep(2000);

    AnyMemoDBOpenHelper helper =
        AnyMemoDBOpenHelperManager.getHelper(mActivity, TestHelper.SAMPLE_DB_PATH);
    try {
      SettingDao settingDao = helper.getSettingDao();
      Setting setting = settingDao.queryForId(1);
      assertEquals(60, (int) setting.getQaRatio());
    } finally {
      AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }
  }
예제 #10
0
 public void convert(String src, String dest) throws Exception {
   new File(dest).delete();
   AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(src);
   try {
     final CardDao cardDao = helper.getCardDao();
     PrintWriter outtxt = new PrintWriter(new BufferedWriter(new FileWriter(dest)));
     if (outtxt.checkError()) {
       throw new IOException("Can't open: " + dest + " for writting");
     }
     List<Card> cardList = cardDao.queryForAll();
     if (cardList == null || cardList.size() == 0) {
       throw new IOException("Can't retrieve items for database: " + src);
     }
     for (Card card : cardList) {
       outtxt.print("Q: " + card.getQuestion() + "\n");
       outtxt.print("A: " + card.getAnswer() + "\n\n");
     }
     outtxt.close();
   } finally {
     AnyMemoDBOpenHelperManager.releaseHelper(helper);
   }
 }
예제 #11
0
  private void uploadDB(String dbPath) throws Exception {
    final String dbName = AMUtil.getFilenameFromPath(dbPath);
    int cardId = addCardSet(dbName, "Import from AnyMemo");
    AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(this, dbPath);
    CardDao cardDao = helper.getCardDao();
    List<Card> cards = cardDao.queryForAll();

    for (Card card : cards) {
      String question = card.getQuestion();
      String answer = card.getAnswer();
      addCard(cardId, question, answer);
    }
  }
예제 #12
0
  @LargeTest
  public void testSaveAlignments() throws Exception {
    // 1st spinner
    solo.pressSpinnerItem(1 /* Question text alignment */, -1 /* Left */);
    // solo.sleep(300);
    solo.pressSpinnerItem(3 /* Question text alignment */, 1 /* Right */);
    // solo.sleep(300);

    solo.clickOnActionBarItem(R.id.save);
    // solo.sleep(2000);

    AnyMemoDBOpenHelper helper =
        AnyMemoDBOpenHelperManager.getHelper(mActivity, TestHelper.SAMPLE_DB_PATH);
    try {
      SettingDao settingDao = helper.getSettingDao();
      Setting setting = settingDao.queryForId(1);
      assertEquals(Setting.Align.LEFT, setting.getQuestionTextAlign());
      assertEquals(Setting.Align.RIGHT, setting.getAnswerTextAlign());
    } finally {
      AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }
  }
예제 #13
0
  @LargeTest
  public void testGoBackWithSettingChangedPressCancelButtonShouldStayInCurrentActivity()
      throws Exception {
    solo.pressSpinnerItem(5 /* Q/A ratio */, 1 /* 60% */);
    // solo.sleep(500);

    solo.goBack();
    // solo.sleep(500);
    solo.clickOnButton(solo.getString(R.string.cancel_text));
    // solo.sleep(2000);

    AnyMemoDBOpenHelper helper =
        AnyMemoDBOpenHelperManager.getHelper(mActivity, TestHelper.SAMPLE_DB_PATH);
    try {
      SettingDao settingDao = helper.getSettingDao();
      Setting setting = settingDao.queryForId(1);
      assertEquals(50, (int) setting.getQaRatio());
    } finally {
      AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }

    // Is current activity SettingsScreen
    solo.assertCurrentActivity("Stay", SettingsScreen.class);
  }
예제 #14
0
  @Override
  public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    activityComponents().inject(this);
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      dbPath = extras.getString(EXTRA_DBPATH);
    }
    dbOpenHelper = AnyMemoDBOpenHelperManager.getHelper(SettingsScreen.this, dbPath);

    assert dbPath != null : "dbPath shouldn't be null";
    settingsChanged = false;

    multipleLoaderManager.registerLoaderCallbacks(1, new SettingLoaderCallbacks(), false);
    multipleLoaderManager.setOnAllLoaderCompletedRunnable(onPostInitRunnable);
    multipleLoaderManager.startLoading();
  }
예제 #15
0
 @Override
 public void onDestroy() {
   super.onDestroy();
   AnyMemoDBOpenHelperManager.releaseHelper(dbOpenHelper);
 }
예제 #16
0
  public void convert(String src, String dest) throws Exception {
    new File(dest).delete();
    AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(mContext, dest);
    try {
      final CardDao cardDao = helper.getCardDao();
      BufferedReader txtfile = new BufferedReader(new FileReader(src));
      String line;
      int count = 0;
      List<Card> cardList = new LinkedList<Card>();
      boolean isQ = false;
      StringBuffer qBuf = null;
      StringBuffer aBuf = null;
      while ((line = txtfile.readLine()) != null) {
        /* remove BOM */
        line = line.replace("\uFEFF", "");

        String head = "";
        if (line.length() >= 2) {
          head = line.substring(0, 2);
        }
        if (line.equals("")) {
          continue;
        } else if (head.equals("Q:")) {
          if (isQ == true) {
            /* next line */
            qBuf.append("<br />" + line.replaceAll("Q:\\s*", ""));
          } else {
            isQ = true;
            /* Save item when the Q is after A
             * because it is a new item */
            if (count != 0) {
              Card card = new Card();
              card.setQuestion(qBuf.toString());
              card.setAnswer(aBuf.toString());
              card.setOrdinal(count);
              card.setCategory(new Category());
              card.setLearningData(new LearningData());
              cardList.add(card);
            }
            count += 1;
            qBuf = new StringBuffer();
            qBuf.append(line.replaceAll("Q:\\s*", ""));
          }
        } else if (head.equals("A:")) {
          if (isQ == true) {
            isQ = false;
            aBuf = new StringBuffer();
            aBuf.append(line.replaceAll("A:\\s*", ""));
          } else {
            aBuf.append("<br />" + line.replaceAll("A:\\s*", ""));
          }
        } else {
          if (isQ) {
            qBuf.append("<br />" + line);
          } else {
            aBuf.append("<br />" + line);
          }
        }
      }
      /* Last item need to be added manually */
      count += 1;
      Card card = new Card();
      card.setQuestion(qBuf.toString());
      card.setAnswer(aBuf.toString());
      card.setOrdinal(count);
      card.setCategory(new Category());
      card.setLearningData(new LearningData());
      cardList.add(card);

      txtfile.close();
      cardDao.createCards(cardList);
    } finally {
      AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }
  }