2011-08-24 05:44:46 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-12-16 02:26:14 +00:00
|
|
|
package com.android.inputmethod.latin.suggestions;
|
2011-08-24 05:44:46 +00:00
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.util.AttributeSet;
|
2013-05-01 08:02:27 +00:00
|
|
|
import android.util.Log;
|
2011-08-24 05:44:46 +00:00
|
|
|
|
2013-05-01 08:02:27 +00:00
|
|
|
import com.android.inputmethod.keyboard.Keyboard;
|
2012-12-03 02:47:52 +00:00
|
|
|
import com.android.inputmethod.keyboard.MoreKeysKeyboardView;
|
2011-12-16 02:26:14 +00:00
|
|
|
import com.android.inputmethod.latin.R;
|
2013-05-01 08:02:27 +00:00
|
|
|
import com.android.inputmethod.latin.SuggestedWords;
|
|
|
|
import com.android.inputmethod.latin.suggestions.MoreSuggestions.MoreSuggestionsListener;
|
2011-08-24 05:44:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A view that renders a virtual {@link MoreSuggestions}. It handles rendering of keys and detecting
|
|
|
|
* key presses and touch movements.
|
|
|
|
*/
|
2012-12-03 02:47:52 +00:00
|
|
|
public final class MoreSuggestionsView extends MoreKeysKeyboardView {
|
2013-05-01 08:02:27 +00:00
|
|
|
private static final String TAG = MoreSuggestionsView.class.getSimpleName();
|
|
|
|
|
2012-10-03 05:46:47 +00:00
|
|
|
public MoreSuggestionsView(final Context context, final AttributeSet attrs) {
|
2013-08-27 06:15:44 +00:00
|
|
|
this(context, attrs, R.attr.moreKeysKeyboardViewStyle);
|
2011-08-24 05:44:46 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 05:46:47 +00:00
|
|
|
public MoreSuggestionsView(final Context context, final AttributeSet attrs,
|
|
|
|
final int defStyle) {
|
2011-08-24 05:44:46 +00:00
|
|
|
super(context, attrs, defStyle);
|
2012-12-03 02:47:52 +00:00
|
|
|
}
|
2011-08-24 05:44:46 +00:00
|
|
|
|
2012-12-03 02:47:52 +00:00
|
|
|
@Override
|
|
|
|
protected int getDefaultCoordX() {
|
|
|
|
final MoreSuggestions pane = (MoreSuggestions)getKeyboard();
|
|
|
|
return pane.mOccupiedWidth / 2;
|
2011-08-24 05:44:46 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 20:26:45 +00:00
|
|
|
public void updateKeyboardGeometry(final int keyHeight) {
|
2013-04-11 03:08:36 +00:00
|
|
|
updateKeyDrawParams(keyHeight);
|
2012-10-16 20:26:45 +00:00
|
|
|
}
|
|
|
|
|
2013-04-15 03:57:10 +00:00
|
|
|
public void adjustVerticalCorrectionForModalMode() {
|
|
|
|
// Set vertical correction to zero (Reset more keys keyboard sliding allowance
|
2013-12-13 08:09:16 +00:00
|
|
|
// {@link R#dimen.config_more_keys_keyboard_slide_allowance}).
|
2013-04-15 03:57:10 +00:00
|
|
|
mKeyDetector.setKeyboard(getKeyboard(), -getPaddingLeft(), -getPaddingTop());
|
|
|
|
}
|
|
|
|
|
2011-08-24 05:44:46 +00:00
|
|
|
@Override
|
2013-01-22 05:32:47 +00:00
|
|
|
public void onCodeInput(final int code, final int x, final int y) {
|
2013-05-01 08:02:27 +00:00
|
|
|
final Keyboard keyboard = getKeyboard();
|
|
|
|
if (!(keyboard instanceof MoreSuggestions)) {
|
|
|
|
Log.e(TAG, "Expected keyboard is MoreSuggestions, but found "
|
|
|
|
+ keyboard.getClass().getName());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final SuggestedWords suggestedWords = ((MoreSuggestions)keyboard).mSuggestedWords;
|
2013-01-22 05:32:47 +00:00
|
|
|
final int index = code - MoreSuggestions.SUGGESTION_CODE_BASE;
|
2013-05-01 08:02:27 +00:00
|
|
|
if (index < 0 || index >= suggestedWords.size()) {
|
|
|
|
Log.e(TAG, "Selected suggestion has an illegal index: " + index);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(mListener instanceof MoreSuggestionsListener)) {
|
|
|
|
Log.e(TAG, "Expected mListener is MoreSuggestionsListener, but found "
|
|
|
|
+ mListener.getClass().getName());
|
|
|
|
return;
|
2011-09-06 02:37:51 +00:00
|
|
|
}
|
2013-05-01 08:02:27 +00:00
|
|
|
((MoreSuggestionsListener)mListener).onSuggestionSelected(
|
|
|
|
index, suggestedWords.getInfo(index));
|
2012-12-03 06:49:10 +00:00
|
|
|
}
|
2011-08-24 05:44:46 +00:00
|
|
|
}
|