Android Open Source - teluguvelugu Dictionary






From Project

Back to project page teluguvelugu.

License

The source code is released under:

MIT License

If you think the Android project teluguvelugu listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ehc.teluguvelugu;
/*from   w w w. ja v  a2 s.  c  o m*/
import java.util.LinkedHashSet;
import java.util.Set;

import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class Dictionary {
    public SQLiteDatabase database;

    public Dictionary(SQLiteDatabase database) {
        this.database = database;
    }

    // Generating Random query from Database
    public String getRandomWord() {
        Cursor records = database.rawQuery(
                "select * from eng2te where rowid = (abs(random()) % (select max(rowid)+1 from eng2te))", null);
        records.moveToFirst();
        int word_index = records.getColumnIndex("eng_word");
        String word = records.getString(word_index);
        return word;
    }

    // Getting Meaning for Input query
    public String getMeaning(String query) {
        try {
            Cursor meaningOfWordComponentQuery = database.rawQuery("Select * from eng2te where eng_word='" + query + "'"
                    + "COLLATE NOCASE", null);
            boolean recordsExist = meaningOfWordComponentQuery.moveToFirst();
            if (recordsExist) {
                int index = meaningOfWordComponentQuery.getColumnIndex("meaning");
                String meaning = meaningOfWordComponentQuery.getString(index);
                return meaning;
            } else {
                return null;
            }
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
    }

    public void storeRecentWord(SharedPreferences recentQueries, String word) {
        String meaning = getMeaning(word);
        if (meaning != null) {
            Set recents = recentQueries.getStringSet("recentValues", new LinkedHashSet<String>());
            recents.add(word);
            SharedPreferences.Editor recentEditor = recentQueries.edit();
            recentEditor.putStringSet("recentValues", recents);
            recentEditor.commit();
        }
    }
}




Java Source Code List

com.ehc.teluguvelugu.DataBaseHelper.java
com.ehc.teluguvelugu.DictionaryActivity.java
com.ehc.teluguvelugu.Dictionary.java
com.ehc.teluguvelugu.SplashActivity.java