1053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project/* 259aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * Copyright (C) 2008-2012 OMRON SOFTWARE Co., Ltd. 3053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * 4053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 5053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * you may not use this file except in compliance with the License. 6053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * You may obtain a copy of the License at 7053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * 8053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 9053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * 10053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * Unless required by applicable law or agreed to in writing, software 11053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 12053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * See the License for the specific language governing permissions and 14053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * limitations under the License. 15053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project */ 16053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project 17053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Projectpackage jp.co.omronsoft.openwnn; 18053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project 1959aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monmaimport android.app.Dialog; 2059aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monmaimport android.content.res.Resources; 21053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Projectimport android.content.SharedPreferences; 2259aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monmaimport android.view.Gravity; 2359aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monmaimport android.view.View; 2459aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monmaimport android.view.ViewGroup; 2559aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monmaimport android.view.ViewGroup.LayoutParams; 2659aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monmaimport android.widget.HorizontalScrollView; 2759aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monmaimport android.widget.LinearLayout; 2859aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monmaimport android.widget.TextView; 2959aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monmaimport android.util.TypedValue; 3059aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma 3159aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monmaimport java.util.ArrayList; 32053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project 33053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project/** 34d56eddfd5e0f193359f93e7ef665338cace9e2e9Daisuke Miyakawa * The interface of candidates view manager used by {@link OpenWnn}. 35053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * 3659aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * @author Copyright (C) 2008-2011 OMRON SOFTWARE CO., LTD. All Rights Reserved. 37053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project */ 3859aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monmapublic abstract class CandidatesViewManager { 39053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project /** Size of candidates view (normal) */ 40053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project public static final int VIEW_TYPE_NORMAL = 0; 41053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project /** Size of candidates view (full) */ 42053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project public static final int VIEW_TYPE_FULL = 1; 43053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project /** Size of candidates view (close/non-display) */ 44053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project public static final int VIEW_TYPE_CLOSE = 2; 45053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project 46053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project /** 47053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * Attribute of a word (no attribute) 48053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * @see jp.co.omronsoft.openwnn.WnnWord 49053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project */ 50053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project public static final int ATTRIBUTE_NONE = 0; 51053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project /** 52053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * Attribute of a word (a candidate in the history list) 53053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * @see jp.co.omronsoft.openwnn.WnnWord 54053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project */ 55053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project public static final int ATTRIBUTE_HISTORY = 1; 56053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project /** 57053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * Attribute of a word (the best candidate) 58053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * @see jp.co.omronsoft.openwnn.WnnWord 59053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project */ 60053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project public static final int ATTRIBUTE_BEST = 2; 61053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project /** 62053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * Attribute of a word (auto generated/not in the dictionary) 63053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * @see jp.co.omronsoft.openwnn.WnnWord 64053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project */ 65053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project public static final int ATTRIBUTE_AUTO_GENERATED = 4; 66053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project 6759aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma /** The view of the LongPressDialog */ 6859aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma protected View mViewLongPressDialog = null; 6959aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma 7059aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma /** Whether candidates long click enable */ 7159aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma protected Dialog mDialog = null; 7259aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma 7359aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma /** The word pressed */ 7459aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma protected WnnWord mWord; 7559aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma 76053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project /** 77d56eddfd5e0f193359f93e7ef665338cace9e2e9Daisuke Miyakawa * Initialize the candidates view. 78053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * 79053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * @param parent The OpenWnn object 80053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * @param width The width of the display 81053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * @param height The height of the display 82053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * 83d56eddfd5e0f193359f93e7ef665338cace9e2e9Daisuke Miyakawa * @return The candidates view created in the initialize process; {@code null} if cannot create a candidates view. 84053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project */ 8559aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma public abstract View initView(OpenWnn parent, int width, int height); 86053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project 87053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project /** 88d56eddfd5e0f193359f93e7ef665338cace9e2e9Daisuke Miyakawa * Get the candidates view being used currently. 89053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * 90d56eddfd5e0f193359f93e7ef665338cace9e2e9Daisuke Miyakawa * @return The candidates view; {@code null} if no candidates view is used currently. 91053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project */ 9259aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma public abstract View getCurrentView(); 93053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project 94053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project /** 95d56eddfd5e0f193359f93e7ef665338cace9e2e9Daisuke Miyakawa * Set the candidates view type. 96053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * 9759aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * @param type The candidate view type, 9859aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * from {@link CandidatesViewManager#VIEW_TYPE_NORMAL} to 9959aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * {@link CandidatesViewManager#VIEW_TYPE_CLOSE} 100053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project */ 10159aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma public abstract void setViewType(int type); 102053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project 103053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project /** 104d56eddfd5e0f193359f93e7ef665338cace9e2e9Daisuke Miyakawa * Get the candidates view type. 105053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * 10659aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * @return The view type, 10759aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * from {@link CandidatesViewManager#VIEW_TYPE_NORMAL} to 10859aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * {@link CandidatesViewManager#VIEW_TYPE_CLOSE} 109053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project */ 11059aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma public abstract int getViewType(); 111053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project 112053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project /** 113d56eddfd5e0f193359f93e7ef665338cace9e2e9Daisuke Miyakawa * Display candidates. 114053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * 115f96267ad0d85ede52c300ae5456d7e4ecb50915cDaisuke Miyakawa * @param converter The {@link WnnEngine} from which {@link CandidatesViewManager} gets the candidates 116053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * 117053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * @see jp.co.omronsoft.openwnn.WnnEngine#getNextCandidate 118053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project */ 11959aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma public abstract void displayCandidates(WnnEngine converter); 120053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project 121053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project /** 122d56eddfd5e0f193359f93e7ef665338cace9e2e9Daisuke Miyakawa * Clear and hide the candidates view. 123053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project */ 12459aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma public abstract void clearCandidates(); 125053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project 126053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project /** 12759aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * Replace the preferences in the candidates view. 128053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * 129053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project * @param pref The preferences 130053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project */ 13159aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma public abstract void setPreferences(SharedPreferences pref); 13259aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma 13359aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma /** 13459aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * KeyEvent action for soft key board. 13559aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * 13659aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * @param key Key event 13759aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma */ 13859aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma public abstract void processMoveKeyEvent(int key); 13959aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma 14059aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma /** 14159aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * Get candidate is focused now. 14259aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * 14359aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * @return the Candidate is focused of a flag. 14459aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma */ 14559aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma public abstract boolean isFocusCandidate(); 14659aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma 14759aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma /** 14859aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * Select candidate that has focus. 14959aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma */ 15059aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma public abstract void selectFocusCandidate(); 15159aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma 15259aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma /** 15359aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * MSG_SET_CANDIDATES removeMessages. 15459aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma */ 15559aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma public abstract void setCandidateMsgRemove(); 15659aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma 15759aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma /** 15859aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * Display Dialog. 15959aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * 16059aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * @param view View, 16159aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * @param word Display word, 16259aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma */ 16359aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma protected void displayDialog(View view, final WnnWord word) { 16459aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma if ((view instanceof CandidateTextView) && (null != mViewLongPressDialog)) { 16559aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma closeDialog(); 16659aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma mDialog = new Dialog(view.getContext(), R.style.Dialog); 16759aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma 16859aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma TextView text = (TextView)mViewLongPressDialog.findViewById(R.id.candidate_longpress_dialog_text); 16959aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma text.setText(word.candidate); 17059aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma 17159aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma mDialog.setContentView(mViewLongPressDialog); 17259aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma ((CandidateTextView) view).displayCandidateDialog(mDialog); 17359aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma } 17459aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma } 17559aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma 17659aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma /** 17759aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * Close Dialog. 17859aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma * 17959aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma */ 18059aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma public void closeDialog() { 18159aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma if (null != mDialog) { 18259aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma mDialog.dismiss(); 18359aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma mDialog = null; 18459aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma if (null != mViewLongPressDialog) { 18559aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma ViewGroup parent = (ViewGroup)mViewLongPressDialog.getParent(); 18659aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma if (null != parent) { 18759aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma parent.removeView(mViewLongPressDialog); 18859aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma } 18959aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma } 19059aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma } 19159aefa242169b7a51c2381daee58ff22fd1834ceJunichi Monma } 192053d50935e0e311286543bd7c535ae2c863c0deThe Android Open Source Project} 193