use of org.liberty.android.fantastischmemo.entity.Setting in project AnyMemo by helloworld1.
the class SettingTest method testAnswerFontSize.
@SmallTest
@Test
public void testAnswerFontSize() throws Exception {
Setting setting = getCurrentSetting();
setting.setAnswerFontSize(60);
Setting savedSetting = setSetting(setting);
assertEquals(60, (int) savedSetting.getAnswerFontSize());
}
use of org.liberty.android.fantastischmemo.entity.Setting in project AnyMemo by helloworld1.
the class AnyMemoDBOpenHelper method onCreate.
@Override
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
Log.v(TAG, "Now we are creating a new database!");
Log.i(TAG, "Newly created db version: " + database.getVersion());
try {
TableUtils.createTable(connectionSource, Card.class);
TableUtils.createTable(connectionSource, Deck.class);
TableUtils.createTable(connectionSource, Setting.class);
TableUtils.createTable(connectionSource, Filter.class);
TableUtils.createTable(connectionSource, Category.class);
TableUtils.createTable(connectionSource, LearningData.class);
getSettingDao().create(new Setting());
getCategoryDao().create(new Category());
if (database.getVersion() == 0) {
convertOldDatabase(database);
}
} catch (SQLException e) {
throw new RuntimeException("Database creation error: " + e.toString());
}
}
use of org.liberty.android.fantastischmemo.entity.Setting in project AnyMemo by helloworld1.
the class QACardActivity method displayCard.
// Important class that display the card using fragment
// the showAnswer parameter is handled differently on single
// sided card and double sided card.
protected void displayCard(boolean showAnswer) {
// First prepare the text to display
String questionTypeface = setting.getQuestionFont();
String answerTypeface = setting.getAnswerFont();
Setting.Align questionAlign = setting.getQuestionTextAlign();
Setting.Align answerAlign = setting.getAnswerTextAlign();
String questionTypefaceValue = null;
String answerTypefaceValue = null;
/* Set the typeface of question and answer */
if (!Strings.isNullOrEmpty(questionTypeface)) {
questionTypefaceValue = questionTypeface;
}
if (!Strings.isNullOrEmpty(answerTypeface)) {
answerTypefaceValue = answerTypeface;
}
final String[] imageSearchPaths = { /* Relative path */
"", /* Relative path with db name */
"" + FilenameUtils.getName(dbPath), /* Try the image in /sdcard/anymemo/images/dbname/ */
AMEnv.DEFAULT_IMAGE_PATH + FilenameUtils.getName(dbPath), /* Try the image in /sdcard/anymemo/images/ */
AMEnv.DEFAULT_IMAGE_PATH };
// Buttons view can be null if it is not decleared in the layout XML
View buttonsView = findViewById(R.id.buttons_root);
if (buttonsView != null) {
// Make sure the buttons view are also handling the event for the answer view
// e. g. clicking on the blank area of the buttons layout to reveal the answer
// or flip the card.
buttonsView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
onQuestionViewClickListener.onClick(v);
}
});
// or answer view's color.
if (!setting.isDefaultColor()) {
if (setting.getCardStyle() == Setting.CardStyle.DOUBLE_SIDED && !showAnswer && setting.getQuestionBackgroundColor() != null) {
buttonsView.setBackgroundColor(setting.getQuestionBackgroundColor());
} else if (setting.getAnswerBackgroundColor() != null) {
buttonsView.setBackgroundColor(setting.getAnswerBackgroundColor());
}
}
}
CardFragment.Builder questionFragmentBuilder = new CardFragment.Builder(getCurrentCard().getQuestion()).setTextAlignment(questionAlign).setTypefaceFromFile(questionTypefaceValue).setTextOnClickListener(onQuestionTextClickListener).setCardOnClickListener(onQuestionViewClickListener).setTextFontSize(setting.getQuestionFontSize()).setTypefaceFromFile(setting.getQuestionFont()).setDisplayInHtml(setting.getDisplayInHTMLEnum().contains(Setting.CardField.QUESTION)).setHtmlLinebreakConversion(setting.getHtmlLineBreakConversion()).setImageSearchPaths(imageSearchPaths);
CardFragment.Builder answerFragmentBuilder = new CardFragment.Builder(getCurrentCard().getAnswer()).setTextAlignment(answerAlign).setTypefaceFromFile(answerTypefaceValue).setTextOnClickListener(onAnswerTextClickListener).setCardOnClickListener(onAnswerViewClickListener).setTextFontSize(setting.getAnswerFontSize()).setTypefaceFromFile(setting.getAnswerFont()).setDisplayInHtml(setting.getDisplayInHTMLEnum().contains(Setting.CardField.ANSWER)).setHtmlLinebreakConversion(setting.getHtmlLineBreakConversion()).setImageSearchPaths(imageSearchPaths);
CardFragment.Builder showAnswerFragmentBuilder = new CardFragment.Builder("?\n" + getString(R.string.memo_show_answer)).setTextAlignment(Setting.Align.CENTER).setTypefaceFromFile(answerTypefaceValue).setTextOnClickListener(onAnswerTextClickListener).setCardOnClickListener(onAnswerViewClickListener).setTextFontSize(setting.getAnswerFontSize()).setTypefaceFromFile(setting.getAnswerFont());
questionFragmentBuilder.setTextColor(setting.getQuestionTextColor()).setBackgroundColor(setting.getQuestionBackgroundColor());
answerFragmentBuilder.setBackgroundColor(setting.getAnswerBackgroundColor()).setTextColor(setting.getAnswerTextColor());
showAnswerFragmentBuilder.setTextColor(setting.getAnswerTextColor()).setBackgroundColor(setting.getAnswerBackgroundColor());
// Note is currently shared some settings with Answer
CardFragment.Builder noteFragmentBuilder = new CardFragment.Builder(getCurrentCard().getNote()).setTextAlignment(answerAlign).setTypefaceFromFile(answerTypefaceValue).setCardOnClickListener(onAnswerViewClickListener).setTextFontSize(setting.getAnswerFontSize()).setTypefaceFromFile(setting.getAnswerFont()).setDisplayInHtml(setting.getDisplayInHTMLEnum().contains(Setting.CardField.ANSWER)).setHtmlLinebreakConversion(setting.getHtmlLineBreakConversion()).setImageSearchPaths(imageSearchPaths);
// Long click to launch image viewer if the card has an image
questionFragmentBuilder.setTextOnLongClickListener(generateImageOnLongClickListener(getCurrentCard().getQuestion(), imageSearchPaths));
answerFragmentBuilder.setTextOnLongClickListener(generateImageOnLongClickListener(getCurrentCard().getAnswer(), imageSearchPaths));
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (setting.getCardStyle() == Setting.CardStyle.SINGLE_SIDED) {
TwoFieldsCardFragment fragment = new TwoFieldsCardFragment();
Bundle b = new Bundle();
// Handle card field setting.
List<CardFragment.Builder> builders1List = new ArrayList<CardFragment.Builder>(4);
if (setting.getQuestionFieldEnum().contains(Setting.CardField.QUESTION)) {
builders1List.add(questionFragmentBuilder);
}
if (setting.getQuestionFieldEnum().contains(Setting.CardField.ANSWER)) {
builders1List.add(answerFragmentBuilder);
}
if (setting.getQuestionFieldEnum().contains(Setting.CardField.NOTE)) {
builders1List.add(noteFragmentBuilder);
}
List<CardFragment.Builder> builders2List = new ArrayList<CardFragment.Builder>(4);
if (!showAnswer) {
builders2List.add(showAnswerFragmentBuilder);
}
if (setting.getAnswerFieldEnum().contains(Setting.CardField.QUESTION)) {
builders2List.add(questionFragmentBuilder);
}
if (setting.getAnswerFieldEnum().contains(Setting.CardField.ANSWER)) {
builders2List.add(answerFragmentBuilder);
}
if (setting.getAnswerFieldEnum().contains(Setting.CardField.NOTE)) {
builders2List.add(noteFragmentBuilder);
}
CardFragment.Builder[] builders1 = new CardFragment.Builder[builders1List.size()];
builders1List.toArray(builders1);
CardFragment.Builder[] builders2 = new CardFragment.Builder[builders2List.size()];
builders2List.toArray(builders2);
b.putSerializable(TwoFieldsCardFragment.EXTRA_FIELD1_CARD_FRAGMENT_BUILDERS, builders1);
b.putSerializable(TwoFieldsCardFragment.EXTRA_FIELD2_CARD_FRAGMENT_BUILDERS, builders2);
if (showAnswer) {
b.putInt(TwoFieldsCardFragment.EXTRA_FIELD2_INITIAL_POSITION, 0);
} else {
b.putInt(TwoFieldsCardFragment.EXTRA_FIELD2_INITIAL_POSITION, 0);
}
b.putInt(TwoFieldsCardFragment.EXTRA_QA_RATIO, setting.getQaRatio());
b.putInt(TwoFieldsCardFragment.EXTRA_SEPARATOR_COLOR, setting.getSeparatorColor());
fragment.setArguments(b);
configCardFragmentTransitionAnimation(ft);
ft.replace(R.id.card_root, fragment);
ft.commit();
} else if (setting.getCardStyle() == Setting.CardStyle.DOUBLE_SIDED) {
FlipableCardFragment fragment = new FlipableCardFragment();
Bundle b = new Bundle(1);
CardFragment.Builder[] builders = { questionFragmentBuilder, answerFragmentBuilder, noteFragmentBuilder };
b.putSerializable(FlipableCardFragment.EXTRA_CARD_FRAGMENT_BUILDERS, builders);
if (showAnswer) {
b.putInt(FlipableCardFragment.EXTRA_INITIAL_POSITION, 1);
} else {
b.putInt(FlipableCardFragment.EXTRA_INITIAL_POSITION, 0);
}
fragment.setArguments(b);
configCardFragmentTransitionAnimation(ft);
ft.replace(R.id.card_root, fragment);
ft.commit();
} else {
assert false : "Card logic not implemented for style: " + setting.getCardStyle();
}
isAnswerShown = showAnswer;
// Set up the small title bar
// It is defualt "GONE" so it won't take any space
// if there is no text
smallTitleBar = (TextView) findViewById(R.id.small_title_bar);
// http://code.google.com/p/anymemo/issues/detail?id=239
if (showAnswer == true) {
copyToClipboard();
}
currentDisplayedCard = getCurrentCard();
onPostDisplayCard();
}
Aggregations