Back to project page LearnByHeart.
The source code is released under:
Apache License
If you think the Android project LearnByHeart listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.mps.learn.pb; /*from ww w.j a va 2s . c o m*/ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.util.Log; import com.mps.learn.pb.db.DataSourcePhrase; import com.mps.learn.pb.model.PhraseModel; import com.mps.learn.pb.util.Debugger; public class PhraseManager { private static PhraseManager INSTANCE; private DataSourcePhrase mPhraseDataSource; private List<PhraseModel> mPhraseList; public static Map<String, Integer> PHRASE_IMAGES_MAP = new HashMap<String, Integer>(); public static final int CARD_COLOR_CODES[] = new int[]{ R.drawable.card_blueborder, R.drawable.card_goldborder, R.drawable.card_greenborder, R.drawable.card_navyborder, R.drawable.card_purpleborder, R.drawable.card_redborder, R.drawable.card_tealborder, R.drawable.card_yellowborder }; private PhraseManager() { init(); // Empty private constructor this.setPhraseList(new ArrayList<PhraseModel>()); // create a datasource this.mPhraseDataSource = new DataSourcePhrase(App.INSTANCE); } public static synchronized PhraseManager getInstance() { if (INSTANCE == null) INSTANCE = new PhraseManager(); return INSTANCE; } public List<PhraseModel> getPhraseList() { return mPhraseList; } public void setPhraseList(List<PhraseModel> mPhraseList) { this.mPhraseList = mPhraseList; } /* * Manage Call for Phrases */ public List<PhraseModel> getAllPhrases(){ this.mPhraseDataSource.open(); List<PhraseModel> dbPhraseList = this.mPhraseDataSource.getAllSavedPhrases(); Log.i(Debugger.TAG, "Size of DB : " + dbPhraseList.size()); if(dbPhraseList.size() > 0 ){ for( PhraseModel model : dbPhraseList) mPhraseList.add(0, model); } this.mPhraseDataSource.close(); return this.mPhraseList; } public void addPhrase(int location, PhraseModel model){ this.mPhraseList.add(location, model); } public PhraseModel createAndSavePhraseModel(String title, String usagePb, String usageEn, String resUrl ) { this.mPhraseDataSource.open(); PhraseModel model = this.mPhraseDataSource.createPhrase( title, usagePb, usageEn, resUrl ); this.mPhraseDataSource.close(); return model; } public void removePhraseModel(int location){ this.mPhraseDataSource.open(); this.mPhraseDataSource.close(); long id = this.mPhraseList.get(location).getId(); if(mPhraseDataSource != null){ mPhraseDataSource.delete(id); } this.mPhraseList.remove(location); } ///////////////////////////////////////////////////// /** * initialize phrase list with initial set of phrases */ public void init() { PHRASE_IMAGES_MAP.put("roti", R.drawable.roti); PHRASE_IMAGES_MAP.put("thali", R.drawable.thali); PHRASE_IMAGES_MAP.put("water", R.drawable.water); PHRASE_IMAGES_MAP.put("name", R.drawable.name); PHRASE_IMAGES_MAP.put("yes", R.drawable.yes); PHRASE_IMAGES_MAP.put("thankyou", R.drawable.thankyou); PHRASE_IMAGES_MAP.put("ok", R.drawable.ok); PHRASE_IMAGES_MAP.put("pleasetomeetyou", R.drawable.pleasetomeetyou); PHRASE_IMAGES_MAP.put("doesntmatter", R.drawable.doesntmatter); // // Populate the List // PhraseModel item = new PhraseModel( "Roti", // Title // "Roti davi", // Punjabi // "Give me Chapaati", // English // PhraseModel.TYPE_LOCAL_URL); // URL Type // this.mPhraseList.add(item); // // PhraseModel item2 = new PhraseModel("Roti", // Title // "Roti davi", // Punjabi // "Give me Food", // English // PhraseModel.TYPE_LOCAL_URL); // URL Type // this.mPhraseList.add(item2); // // PhraseModel item3 = new PhraseModel("Paani", // Title // "Paani davi", // Punjabi // "Give me Water", // English // PhraseModel.TYPE_LOCAL_URL); // URL Type // this.mPhraseList.add(item3); // // item = new PhraseModel("Dhanwaad / Meharbani / Shukriya ", // Title // "Dhanwaad ji", // Punjabi // "Thank you", // English // PhraseModel.TYPE_LOCAL_URL); // URL Type // this.mPhraseList.add(item); // // item = new PhraseModel("Haanji", // Title // "Haanji", // Punjabi // "Yes", // English // PhraseModel.TYPE_LOCAL_URL); // URL Type // this.mPhraseList.add(item); // // item = new PhraseModel("Haanji", // Title // "Haanji, mein aayi", // Punjabi // "Yes, I am coming", // English // PhraseModel.TYPE_LOCAL_URL); // URL Type // this.mPhraseList.add(item); // // item = new PhraseModel("Naa", // Title // "Mera naa ... hai", // Punjabi // "My name is ...", // English // PhraseModel.TYPE_LOCAL_URL); // URL Type // this.mPhraseList.add(item); // // item = new PhraseModel("Chunga / Acchaa", // Title // "Use when we agree or reply", // Punjabi // "Well / good / OK", // English // PhraseModel.TYPE_LOCAL_URL); // URL Type // this.mPhraseList.add(item); // // item = new PhraseModel( "Khushi", // Title // "Tuhanu mil ke khushi hoi", // Punjabi // "Pleased to meet you", // English // PhraseModel.TYPE_LOCAL_URL); // URL Type // this.mPhraseList.add(item); // // item = new PhraseModel("Koi gal nahi", // Title // "Koi gal nahi", // Punjabi // "You're welcome / doesn't matter / no worries", // English // PhraseModel.TYPE_LOCAL_URL); // URL Type // this.mPhraseList.add(item); } }