コード例 #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
ファイル: FEUpload.java プロジェクト: Neetik92/AnyMemo
  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);
    }
  }
コード例 #5
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);
    }
  }
コード例 #6
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);
    }
  }
コード例 #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
  @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);
    }
  }
コード例 #12
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);
  }
コード例 #13
0
        @Override
        public void run() {
          // Dismiss the progress dialog

          settingDao = dbOpenHelper.getSettingDao();

          setContentView(R.layout.settings_screen);

          questionFontSizeSpinner = (AMSpinner) findViewById(R.id.question_font_size_spinner);

          answerFontSizeSpinner = (AMSpinner) findViewById(R.id.answer_font_size_spinner);

          questionAlignSpinner = (AMSpinner) findViewById(R.id.question_align_spinner);

          answerAlignSpinner = (AMSpinner) findViewById(R.id.answer_align_spinner);

          styleSpinner = (AMSpinner) findViewById(R.id.card_style_spinner);

          qaRatioSpinner = (AMSpinner) findViewById(R.id.ratio_spinner);

          questionLocaleSpinner = (AMSpinner) findViewById(R.id.question_locale_spinner);

          answerLocaleSpinner = (AMSpinner) findViewById(R.id.answer_locale_spinner);

          audioLocationEdit = (EditText) findViewById(R.id.settings_audio_location);

          // If we got no text, we will use the default location.
          if (!Strings.isNullOrEmpty(setting.getQuestionAudio())) {
            audioLocationEdit.setText(setting.getQuestionAudioLocation());
          }

          if (!Strings.isNullOrEmpty(setting.getAnswerAudio())) {
            audioLocationEdit.setText(setting.getAnswerAudioLocation());
          }

          if (Strings.isNullOrEmpty(audioLocationEdit.getText().toString())) {
            audioLocationEdit.setText(AMEnv.DEFAULT_AUDIO_PATH);
          }

          colorCheckbox = (CheckBox) findViewById(R.id.checkbox_customize_color);
          colorCheckbox.setOnClickListener(settingFieldOnClickListener);
          colorRow = (TableRow) findViewById(R.id.color_row);

          colorSpinner = (AMSpinner) findViewById(R.id.color_item_spinner);
          colorButton = (Button) findViewById(R.id.settings_color_button);
          colorButton.setOnClickListener(settingFieldOnClickListener);
          colors = new ArrayList<Integer>(5);
          colors.add(setting.getQuestionTextColor());
          colors.add(setting.getAnswerTextColor());
          colors.add(setting.getQuestionBackgroundColor());
          colors.add(setting.getAnswerBackgroundColor());
          colors.add(setting.getSeparatorColor());

          qTypefaceCheckbox = (CheckBox) findViewById(R.id.checkbox_typeface_question);
          qTypefaceCheckbox.setOnClickListener(settingFieldOnClickListener);
          aTypefaceCheckbox = (CheckBox) findViewById(R.id.checkbox_typeface_answer);
          aTypefaceCheckbox.setOnClickListener(settingFieldOnClickListener);

          qTypefaceEdit = (EditText) findViewById(R.id.edit_typeface_question);
          qTypefaceEdit.setOnClickListener(settingFieldOnClickListener);

          aTypefaceEdit = (EditText) findViewById(R.id.edit_typeface_answer);
          aTypefaceEdit.setOnClickListener(settingFieldOnClickListener);

          displayInHTMLCheckbox = (CheckBox) findViewById(R.id.display_html);
          displayInHTMLCheckbox.setOnClickListener(settingFieldOnClickListener);
          fieldsDisplayedInHTML = setting.getDisplayInHTMLEnum();

          linebreakCheckbox = (CheckBox) findViewById(R.id.linebreak_conversion);
          linebreakCheckbox.setOnClickListener(settingFieldOnClickListener);

          field1Checkbox = (CheckBox) findViewById(R.id.checkbox_field1);
          field1Checkbox.setOnClickListener(settingFieldOnClickListener);
          questionFields = setting.getQuestionFieldEnum();

          field2Checkbox = (CheckBox) findViewById(R.id.checkbox_field2);
          field2Checkbox.setOnClickListener(settingFieldOnClickListener);
          answerFields = setting.getAnswerFieldEnum();

          updateViews();

          setSpinnerListeners();
        }
コード例 #14
0
ファイル: QATxtImporter.java プロジェクト: piotrbazan/AnyMemo
  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);
    }
  }