Search in sources :

Example 1 with Category

use of com.alphago.alphago.model.Category in project Alphago by Onedelay.

the class WordLearningActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_word_learning);
    learnImage = (ImageView) findViewById(R.id.learn_image);
    learnLabel = (TextView) findViewById(R.id.learn_label);
    tts = new TTSHelper(this);
    findViewById(btn_learn_exit).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    findViewById(R.id.btn_learn_pre).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (index > 0) {
                index--;
                setWord(index);
            } else {
                Toast.makeText(WordLearningActivity.this, "First card.", Toast.LENGTH_SHORT).show();
            }
        }
    });
    findViewById(R.id.btn_learn_next).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (index < cards.size() - 1) {
                index++;
                setWord(index);
            } else {
                Toast.makeText(WordLearningActivity.this, "Last card.", Toast.LENGTH_SHORT).show();
            }
        }
    });
    findViewById(R.id.btn_pronounce).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (learnLabel.getText().toString().equals("usb"))
                tts.speak("U.S.B");
            else
                tts.speak(learnLabel.getText().toString());
        }
    });
    DbHelper dbHelper = new DbHelper(getBaseContext());
    int type = getIntent().getIntExtra("learning_type", 0);
    if (type == TYPE_ALL) {
        List<Category> categories = dbHelper.categorySelect();
        List<CardBook> cardBooks;
        // 현재 카드북으로 되어있지만, 카드에서 중복 제거 후 구현해야함.
        for (Category category : categories) {
            cardBooks = dbHelper.cardbookSelect(category.getId());
            cards.addAll(cardBooks);
        }
    } else if (type == TYPE_ALBUM) {
        ArrayList<Long> list = (ArrayList<Long>) getIntent().getSerializableExtra("category_select_list");
        for (Long id : list) {
            List<CardBook> cardBooks = dbHelper.cardbookSelect(id);
            cards.addAll(cardBooks);
        }
    } else {
        Toast.makeText(this, "TYPE ERROR", Toast.LENGTH_SHORT).show();
        finish();
    }
    if (!cards.isEmpty()) {
        Collections.shuffle(cards);
        setWord(index);
    } else {
        Toast.makeText(WordLearningActivity.this, "학습할 목록이 없습니다.", Toast.LENGTH_SHORT).show();
    }
}
Also used : Category(com.alphago.alphago.model.Category) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) CardBook(com.alphago.alphago.model.CardBook) TTSHelper(com.alphago.alphago.util.TTSHelper) ArrayList(java.util.ArrayList) List(java.util.List) DbHelper(com.alphago.alphago.database.DbHelper)

Example 2 with Category

use of com.alphago.alphago.model.Category in project Alphago by Onedelay.

the class CardBookActivity method onCardClick.

@Override
public void onCardClick(Object data) {
    if (data instanceof Category) {
        long catId = ((Category) data).getId();
        if (!isSelectMode) {
            Intent intent = new Intent(getBaseContext(), CardBookListActivity.class);
            intent.putExtra("categoryId", catId);
            intent.putExtra("category", ((Category) data).getLabel());
            startActivity(intent);
        } else {
            if (!selectList.contains(catId)) {
                selectList.add(catId);
                ((Category) data).setSelect(true);
            } else {
                selectList.remove(catId);
                ((Category) data).setSelect(false);
            }
            adapter.notifyDataSetChanged();
        }
    }
}
Also used : Category(com.alphago.alphago.model.Category) Intent(android.content.Intent)

Example 3 with Category

use of com.alphago.alphago.model.Category in project Alphago by Onedelay.

the class DbHelper method categorySelect.

public List<Category> categorySelect() {
    SQLiteDatabase db = getReadableDatabase();
    String[] projection = { "*" };
    Cursor c = db.query(CategoryEntry.TABLE_NAME, projection, null, null, null, null, null);
    String selection = CardBookEntry.COLUMN_NAME_CATEGORY + " = ?";
    List<Category> categoryList = new ArrayList<>();
    while (c.moveToNext()) {
        long categoryId = c.getLong(c.getColumnIndexOrThrow(CategoryEntry._ID));
        String category = c.getString(c.getColumnIndexOrThrow(CategoryEntry.COLUMN_NAME_LABEL));
        String filePath = c.getString(c.getColumnIndexOrThrow(CategoryEntry.COLUMN_NAME_PATH));
        String[] selectionArgs = { String.valueOf(categoryId) };
        Cursor cards = db.query(CardBookEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, null);
        if (cards.moveToNext())
            categoryList.add(new Category(categoryId, category, filePath));
        cards.close();
    }
    c.close();
    return categoryList;
}
Also used : CollectCategory(com.alphago.alphago.model.CollectCategory) Category(com.alphago.alphago.model.Category) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Aggregations

Category (com.alphago.alphago.model.Category)3 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 DbHelper (com.alphago.alphago.database.DbHelper)1 CardBook (com.alphago.alphago.model.CardBook)1 CollectCategory (com.alphago.alphago.model.CollectCategory)1 TTSHelper (com.alphago.alphago.util.TTSHelper)1 List (java.util.List)1