use of ee.ioc.phon.android.speak.model.Combo in project K6nele by Kaljurand.
the class SpeechInputView method updateComboSelector.
private void updateComboSelector(ServiceLanguageChooser slc) {
Combo combo = new Combo(getContext(), slc.getCombo());
mBComboSelector.setText(combo.getLongLabel());
}
use of ee.ioc.phon.android.speak.model.Combo in project K6nele by Kaljurand.
the class Utils method publishShortcuts.
/**
* Constructs and publishes the list of app shortcuts, one for each combo that is selected for the
* search panel. The intent behind the shortcut sets AUTO_START=true and sets RESULTS_REWRITES
* to the list of default rewrites (at creation time), and PROMPT to the list of rewrite names.
* All other settings (e.g. MAX_RESULTS) depend on the settings at execution time.
*/
@TargetApi(Build.VERSION_CODES.N_MR1)
public static void publishShortcuts(Context context, List<Combo> selectedCombos, Set<String> rewriteTables) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
List<ShortcutInfo> shortcuts = new ArrayList<>();
int maxShortcutCountPerActivity = shortcutManager.getMaxShortcutCountPerActivity();
int counter = 0;
// TODO: rewriteTables should be a list (not a set that needs to be sorted)
String[] names = rewriteTables.toArray(new String[rewriteTables.size()]);
Arrays.sort(names);
String rewritesId = TextUtils.join(", ", names);
String rewritesIdSuffix = "";
if (!rewritesId.isEmpty()) {
rewritesIdSuffix = "; " + rewritesId;
}
for (Combo combo : selectedCombos) {
Intent intent = new Intent(context, SpeechActionActivity.class);
intent.setAction(RecognizerIntent.ACTION_WEB_SEARCH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, combo.getLocaleAsStr());
intent.putExtra(Extras.EXTRA_SERVICE_COMPONENT, combo.getServiceComponent().flattenToShortString());
if (names.length > 0) {
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, rewritesId);
}
intent.putExtra(Extras.EXTRA_RESULT_REWRITES, names);
intent.putExtra(Extras.EXTRA_AUTO_START, true);
// Launch the activity so that the existing Kõnele activities are not in the background stack.
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
shortcuts.add(new ShortcutInfo.Builder(context, combo.getId() + rewritesId).setIntent(intent).setShortLabel(combo.getShortLabel() + rewritesIdSuffix).setLongLabel(combo.getLongLabel() + rewritesIdSuffix).setIcon(Icon.createWithBitmap(drawableToBitmap(combo.getIcon(context)))).build());
counter++;
// We are only allowed a certain number (5) of shortcuts
if (counter >= maxShortcutCountPerActivity) {
break;
}
}
shortcutManager.setDynamicShortcuts(shortcuts);
}
use of ee.ioc.phon.android.speak.model.Combo in project K6nele by Kaljurand.
the class ComboAdapter method getView.
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
View view;
if (convertView == null) {
view = context.getLayoutInflater().inflate(R.layout.list_item_combo, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.icon = view.findViewById(R.id.serviceIcon);
viewHolder.language = view.findViewById(R.id.language);
viewHolder.service = view.findViewById(R.id.service);
viewHolder.checkbox = view.findViewById(R.id.check);
viewHolder.checkbox.setOnCheckedChangeListener((buttonView, isChecked) -> {
Combo item = (Combo) viewHolder.checkbox.getTag();
item.setSelected(isChecked);
});
view.setTag(viewHolder);
viewHolder.checkbox.setTag(list.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
Combo item = list.get(position);
holder.icon.setImageDrawable(item.getIcon(this.context));
String language = item.getLanguage();
if (language == null || language.isEmpty()) {
holder.language.setText(R.string.dash);
} else {
holder.language.setText(language);
}
holder.service.setText(item.getService());
holder.checkbox.setChecked(item.isSelected());
return view;
}
Aggregations