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();
}
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);
}
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++;
}
}
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();
}
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();
}
Aggregations