Android TextView Set manageVisibiltyFieldSpeech(Context context, ImageButton button, AutoCompleteTextView text, int idRightof, int idLeftOf, int idBelow)

Here you can find the source of manageVisibiltyFieldSpeech(Context context, ImageButton button, AutoCompleteTextView text, int idRightof, int idLeftOf, int idBelow)

Description

manage Visibilty Field Speech

License

Open Source License

Declaration

public static void manageVisibiltyFieldSpeech(Context context,
            ImageButton button, AutoCompleteTextView text, int idRightof,
            int idLeftOf, int idBelow) 

Method Source Code

//package com.java2s;
/*//from   w w  w . j  a  v a2 s.  c  o  m
 * Copyright (C) 2011 Binomed (http://blog.binomed.fr)
 *
 * Licensed under the Eclipse Public License - v 1.0;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.eclipse.org/legal/epl-v10.html
 *
 * THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC 
 * LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM 
 * CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
 */

import java.util.List;

import android.content.Context;
import android.content.Intent;

import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Build;

import android.speech.RecognizerIntent;

import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.AutoCompleteTextView;
import android.widget.ImageButton;

import android.widget.RelativeLayout;

public class Main {
    public static void manageVisibiltyFieldSpeech(Context context,
            ImageButton button, AutoCompleteTextView text, int idRightof,
            int idLeftOf, int idBelow) {
        // Manage speech button just if package present on device
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(
                RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
        if (activities.size() == 0) {
            button.setVisibility(View.GONE);

            if ((text != null) && (Integer.valueOf(Build.VERSION.SDK) <= 3)) {
                // Manage specificity for version before 4
                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                        LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
                if (idRightof != -1) {
                    params.addRule(RelativeLayout.RIGHT_OF, idRightof);
                }
                if (idLeftOf != -1) {
                    params.addRule(RelativeLayout.LEFT_OF, idLeftOf);
                }
                if (idBelow != -1) {
                    params.addRule(RelativeLayout.BELOW, idBelow);
                }
                text.setSingleLine(true);
                text.setLayoutParams(params);
            }
        }
    }
}

Related

  1. setText(TextView tv, int str)
  2. setHtml(TextView view, String html)
  3. setHtml(Activity activity, View parent, int elementId, int resId)
  4. initDate(TextView view,int days)
  5. setBold(TextView tv)
  6. setupMarquee(TextView textView, String text)