Search in sources :

Example 31 with AnyMemoDBOpenHelper

use of org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper in project AnyMemo by helloworld1.

the class ShareScreen method onClick.

@Override
public void onClick(View v) {
    try {
        String dbpath = dbnameView.getText().toString();
        Log.v(TAG, dbpath);
        if (v == saveButton || v == savePrevButton) {
            AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(this, dbpath);
            CardDao cardDao = helper.getCardDao();
            try {
                Card card = new Card();
                card.setQuestion(questionView.getText().toString());
                card.setAnswer(answerView.getText().toString());
                card.setNote(noteView.getText().toString());
                card.setCategory(new Category());
                card.setLearningData(new LearningData());
                cardDao.createCard(card);
                if (v == savePrevButton) {
                    Intent myIntent = new Intent(this, PreviewEditActivity.class);
                    /* This should be the newly created id */
                    myIntent.putExtra("id", card.getId());
                    myIntent.putExtra(PreviewEditActivity.EXTRA_DBPATH, dbpath);
                    startActivity(myIntent);
                }
                finish();
            } finally {
                AnyMemoDBOpenHelperManager.releaseHelper(helper);
            }
        } else if (v == cancelButton) {
            finish();
        } else if (v == dbnameView) {
            Intent myIntent = new Intent(this, FileBrowserActivity.class);
            myIntent.putExtra(FileBrowserActivity.EXTRA_FILE_EXTENSIONS, ".db");
            startActivityForResult(myIntent, ACTIVITY_FB);
        }
    } catch (Exception e) {
        AMGUIUtility.displayError(this, getString(R.string.error_text), "", e);
    }
}
Also used : AnyMemoDBOpenHelper(org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper) Category(org.liberty.android.fantastischmemo.entity.Category) Intent(android.content.Intent) LearningData(org.liberty.android.fantastischmemo.entity.LearningData) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Card(org.liberty.android.fantastischmemo.entity.Card)

Example 32 with AnyMemoDBOpenHelper

use of org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper in project AnyMemo by helloworld1.

the class WidgetRemoteViewsFactory method getViewAt.

public RemoteViews getViewAt(int position) {
    RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_item);
    if (position < allPath.length) {
        AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(mContext, allPath[position]);
        CardDao dao = helper.getCardDao();
        String dbName = FilenameUtils.getName(allPath[position]);
        long totalCount = dao.getTotalCount(null);
        long revCount = dao.getScheduledCardCount(null);
        long newCount = dao.getNewCardCount(null);
        String detail = mContext.getString(R.string.stat_total) + totalCount + " " + mContext.getString(R.string.stat_new) + newCount + " " + mContext.getString(R.string.stat_scheduled) + revCount;
        rv.setTextViewText(R.id.widget_db_name, dbName);
        rv.setTextViewText(R.id.widget_db_detail, detail);
        Intent fillInIntent = new Intent();
        fillInIntent.putExtra(StudyActivity.EXTRA_DBPATH, allPath[position]);
        rv.setOnClickFillInIntent(R.id.widget_item, fillInIntent);
    }
    return rv;
}
Also used : RemoteViews(android.widget.RemoteViews) AnyMemoDBOpenHelper(org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper) Intent(android.content.Intent) CardDao(org.liberty.android.fantastischmemo.dao.CardDao)

Aggregations

AnyMemoDBOpenHelper (org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper)32 CardDao (org.liberty.android.fantastischmemo.dao.CardDao)28 Card (org.liberty.android.fantastischmemo.entity.Card)28 File (java.io.File)13 Category (org.liberty.android.fantastischmemo.entity.Category)11 CategoryDao (org.liberty.android.fantastischmemo.dao.CategoryDao)10 LearningDataDao (org.liberty.android.fantastischmemo.dao.LearningDataDao)9 LearningData (org.liberty.android.fantastischmemo.entity.LearningData)9 IOException (java.io.IOException)6 URL (java.net.URL)5 FileWriter (java.io.FileWriter)4 ArrayList (java.util.ArrayList)4 SmallTest (androidx.test.filters.SmallTest)3 BufferedWriter (java.io.BufferedWriter)3 PrintWriter (java.io.PrintWriter)3 SAXParser (javax.xml.parsers.SAXParser)3 SAXParserFactory (javax.xml.parsers.SAXParserFactory)3 Test (org.junit.Test)3 InputSource (org.xml.sax.InputSource)3 XMLReader (org.xml.sax.XMLReader)3