Search in sources :

Example 1 with DictionaryDB

use of com.zhan_dui.dictionary.db.DictionaryDB in project little-bear-dictionary by daimajia.

the class SimpleWordsFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mDictionaryDB = new DictionaryDB(getActivity(), DictionaryDB.DB_NAME, null, DictionaryDB.DB_VERSION);
    SQLiteDatabase sqLiteDatabase = mDictionaryDB.getReadableDatabase();
    Cursor cursor = sqLiteDatabase.rawQuery("select * from `word` order by `_id` desc", null);
    getListView().setAdapter(new SimpleWordAdapter(getActivity(), cursor));
    sqLiteDatabase.close();
}
Also used : DictionaryDB(com.zhan_dui.dictionary.db.DictionaryDB) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) SimpleWordAdapter(com.zhan_dui.dictionary.cursoradapters.SimpleWordAdapter)

Example 2 with DictionaryDB

use of com.zhan_dui.dictionary.db.DictionaryDB in project little-bear-dictionary by daimajia.

the class WordsFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    StickyListHeadersListView stickyList = (StickyListHeadersListView) view.findViewById(R.id.list);
    stickyList.setDivider(new ColorDrawable(0xffffffff));
    stickyList.setDividerHeight(1);
    stickyList.setOnScrollListener(this);
    stickyList.setOnItemClickListener(this);
    stickyList.setOnHeaderClickListener(this);
    if (savedInstanceState != null) {
        firstVisible = savedInstanceState.getInt(KEY_LIST_POSITION);
    }
    DictionaryDB dictionaryDB = new DictionaryDB(getActivity(), DictionaryDB.DB_NAME, null, DictionaryDB.DB_VERSION);
    SQLiteDatabase sqLiteDatabase = dictionaryDB.getReadableDatabase();
    Cursor cursor = sqLiteDatabase.rawQuery("select * from word order by word", null);
    WordAdapter wordAdapter = new WordAdapter(getActivity(), cursor);
    stickyList.setAdapter(wordAdapter);
    stickyList.setSelection(firstVisible);
}
Also used : WordAdapter(com.zhan_dui.dictionary.cursoradapters.WordAdapter) DictionaryDB(com.zhan_dui.dictionary.db.DictionaryDB) ColorDrawable(android.graphics.drawable.ColorDrawable) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) StickyListHeadersListView(com.emilsjolander.components.stickylistheaders.StickyListHeadersListView) Cursor(android.database.Cursor)

Example 3 with DictionaryDB

use of com.zhan_dui.dictionary.db.DictionaryDB in project little-bear-dictionary by daimajia.

the class DictionaryManageFragment method onDestroyView.

@Override
public void onDestroyView() {
    super.onDestroyView();
    QueryProcessor.updateCacheDictionaryList(getActivity().getApplicationContext());
    if (mDictionaryManageFragment.mOfflineDictionaryManageView == null) {
        return;
    }
    DragSortListView dragSortListView = (DragSortListView) mDictionaryManageFragment.mOfflineDictionaryManageView.findViewById(android.R.id.list);
    OfflineListCursorAdapter dragSortCursorAdapter = (OfflineListCursorAdapter) dragSortListView.getInputAdapter();
    ArrayList<Integer> SortedResult = dragSortCursorAdapter.getCursorPositions();
    if (SortedResult == null || SortedResult.size() == 0) {
        return;
    }
    Cursor cursor = dragSortCursorAdapter.getCursor();
    cursor.moveToPosition(-1);
    int i = 0;
    DictionaryDB dictionaryDB = new DictionaryDB(getActivity(), DictionaryDB.DB_NAME, null, DictionaryDB.DB_VERSION);
    SQLiteDatabase sqLiteDatabase = dictionaryDB.getWritableDatabase();
    while (cursor.moveToNext()) {
        String[] args = { SortedResult.get(i).toString(), cursor.getString(cursor.getColumnIndex("_id")) };
        sqLiteDatabase.execSQL("update `dictionary_list` set `dictionary_order`= ? where `_id`= ?", args);
        i++;
    }
}
Also used : DictionaryDB(com.zhan_dui.dictionary.db.DictionaryDB) OfflineListCursorAdapter(com.zhan_dui.dictionary.cursoradapters.OfflineListCursorAdapter) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) DragSortListView(com.mobeta.android.dslv.DragSortListView) Cursor(android.database.Cursor)

Example 4 with DictionaryDB

use of com.zhan_dui.dictionary.db.DictionaryDB in project little-bear-dictionary by daimajia.

the class QueryProcessor method updateCacheDictionaryList.

public static void updateCacheDictionaryList(Context context) {
    mCacheUsingDictionaries.clear();
    DictionaryDB dictionaryDB = new DictionaryDB(context, DictionaryDB.DB_NAME, null, DictionaryDB.DB_VERSION);
    SQLiteDatabase sqLiteDatabase = dictionaryDB.getReadableDatabase();
    Cursor cursor = sqLiteDatabase.rawQuery("select * from `dictionary_list` where `dictionary_show`='1' and `dictionary_downloaded`='1' order by `dictionary_order` asc", null);
    while (cursor.moveToNext()) {
        String dicname = cursor.getString(cursor.getColumnIndex("dictionary_name"));
        String filename = cursor.getString(cursor.getColumnIndex("dictionary_save_name")).replace("zip", "dic");
        String dirname = filename.substring(0, filename.length() - 4);
        String configFileName = "config-" + filename;
        DictionaryInfo dictionaryInfo = new DictionaryInfo(dicname, filename, configFileName, dirname);
        mCacheUsingDictionaries.add(dictionaryInfo);
    }
    sqLiteDatabase.close();
}
Also used : DictionaryDB(com.zhan_dui.dictionary.db.DictionaryDB) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SpannableString(android.text.SpannableString) Cursor(android.database.Cursor)

Example 5 with DictionaryDB

use of com.zhan_dui.dictionary.db.DictionaryDB in project little-bear-dictionary by daimajia.

the class GetOnlineDictionaryAsyncTask method ParseJson.

public void ParseJson(String json) throws JSONException {
    JSONArray jsonArray = new JSONArray(json);
    String name, size, url, save_name;
    JSONObject jsonObject;
    DictionaryDB dictionaryDB = new DictionaryDB(mContext, DictionaryDB.DB_NAME, null, DictionaryDB.DB_VERSION);
    SQLiteDatabase sqLiteDatabase = dictionaryDB.getWritableDatabase();
    Cursor cursor = sqLiteDatabase.rawQuery("select count(*) from dictionary_list", null);
    cursor.moveToFirst();
    int dictionaryCount = cursor.getInt(cursor.getColumnIndex("count(*)"));
    for (int i = 0; i < jsonArray.length(); i++) {
        jsonObject = jsonArray.getJSONObject(i);
        name = jsonObject.getString("dictionary_name");
        size = jsonObject.getString("dictionary_size");
        url = jsonObject.getString("dictionary_url");
        save_name = jsonObject.getString("dictionary_save_name");
        DictionaryManager.getInstance(mContext).addAnDictionaryToDB(name, save_name, url, size, true, ++dictionaryCount);
    }
    sqLiteDatabase.close();
}
Also used : DictionaryDB(com.zhan_dui.dictionary.db.DictionaryDB) JSONObject(org.json.JSONObject) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) JSONArray(org.json.JSONArray) Cursor(android.database.Cursor)

Aggregations

SQLiteDatabase (android.database.sqlite.SQLiteDatabase)7 DictionaryDB (com.zhan_dui.dictionary.db.DictionaryDB)7 Cursor (android.database.Cursor)6 SuppressLint (android.annotation.SuppressLint)1 ContentValues (android.content.ContentValues)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 SpannableString (android.text.SpannableString)1 StickyListHeadersListView (com.emilsjolander.components.stickylistheaders.StickyListHeadersListView)1 DragSortListView (com.mobeta.android.dslv.DragSortListView)1 OfflineListCursorAdapter (com.zhan_dui.dictionary.cursoradapters.OfflineListCursorAdapter)1 SimpleWordAdapter (com.zhan_dui.dictionary.cursoradapters.SimpleWordAdapter)1 WordAdapter (com.zhan_dui.dictionary.cursoradapters.WordAdapter)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1