Example usage for android.content Intent getFloatArrayExtra

List of usage examples for android.content Intent getFloatArrayExtra

Introduction

In this page you can find the example usage for android.content Intent getFloatArrayExtra.

Prototype

public float[] getFloatArrayExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:Main.java

public static float[] getFloatArrayExtra(Intent intent, String name) {
    if (!hasIntent(intent) || !hasExtra(intent, name))
        return null;
    return intent.getFloatArrayExtra(name);
}

From source file:gidaibero.android.matsol.MatrixDisplayActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    target = R.id.matrix_button;/*  w w w . j av  a 2  s  .c o m*/

    int currentIndex;
    TableRow tableRow;
    // Define the layout. 
    setContentView(R.layout.matrix_display_view);

    // Parse the values from the parent 
    Intent intent = getIntent();
    this.height = intent.getIntExtra(MatrixInputActivity.MATRIX_SIZE, 5);
    this.matrix = new float[this.height][];
    for (int i = 0; i < this.height; i++) {
        this.matrix[i] = intent.getFloatArrayExtra(MatrixInputActivity.MATRIX_VALUES + i);
    }
    this.results = intent.getFloatArrayExtra(MatrixInputActivity.MATRIX_RESULTS);
    // the we are always a linear equation 
    this.width = this.height + 1;

    // initialize the array
    this.textViewArray = new TextView[this.width * this.height];

    // get the table view to draw in it
    matrixTable = (TableLayout) findViewById(R.id.matrix_display_table);

    // traverse rows
    for (int i = 0; i < this.height; i++) {
        //traverse each element of the row
        tableRow = new TableRow(this);
        for (int j = 0; j < this.width; j++) {
            currentIndex = i * this.width + j; // this points to the location of t                                                                      // editText in the matrix
            this.textViewArray[currentIndex] = new TextView(this);
            this.textViewArray[currentIndex]
                    .setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
            this.textViewArray[currentIndex].setPadding(5, 5, 5, 5);
            if (j == this.width - 1) {
                this.textViewArray[currentIndex].setText(" " + this.results[i]);
            } else {
                this.textViewArray[currentIndex].setText(" " + this.matrix[i][j]);
            }
            tableRow.addView(this.textViewArray[currentIndex]);
        }
        textViewArray[0].measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
        // this will add target and position-specific views to hint the
        // user of what we are doing
        tableRow = decorateTableRow(tableRow, textViewArray[0].getMeasuredHeight(),
                textViewArray[0].getMeasuredWidth(), i);

        matrixTable.addView(tableRow,
                new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    }

}

From source file:com.ipo.wiimote.SpeechRecognizer.java

/**
 * Handle the results from the recognition activity.
 *//* w w w  .  j a v  a2  s . c o  m*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        // Fill the list view with the strings the recognizer thought it could have heard
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        float[] confidence = data.getFloatArrayExtra(RecognizerIntent.EXTRA_CONFIDENCE_SCORES);

        if (confidence != null) {
            Log.d(LOG_TAG, "confidence length " + confidence.length);
            Iterator<String> iterator = matches.iterator();
            int i = 0;
            while (iterator.hasNext()) {
                Log.d(LOG_TAG, "Match = " + iterator.next() + " confidence = " + confidence[i]);
                i++;
            }
        } else {
            Log.d(LOG_TAG, "No confidence" + "");
        }

        ReturnSpeechResults(requestCode, matches);
    } else {
        // Failure - Let the caller know
        ReturnSpeechFailure(resultCode);
    }

    super.onActivityResult(requestCode, resultCode, data);
}

From source file:conversandroid.SimpleASR.java

/**
 *  Shows the formatted best of N best recognition results (N-best list) from
 *  best to worst in the <code>ListView</code>. 
 *  For each match, it will render the recognized phrase and the confidence with 
 *  which it was recognized./*  w ww. j  av  a2  s.c om*/
 */
@SuppressLint("InlinedApi")
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ASR_CODE) {
        if (resultCode == RESULT_OK) {
            if (data != null) {
                //Retrieves the N-best list and the confidences from the ASR result
                ArrayList<String> nBestList = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                float[] nBestConfidences = null;

                if (Build.VERSION.SDK_INT >= 14) //Checks the API level because the confidence scores are supported only from API level 14
                    nBestConfidences = data.getFloatArrayExtra(RecognizerIntent.EXTRA_CONFIDENCE_SCORES);

                //Creates a collection of strings, each one with a recognition result and its confidence
                //following the structure "Phrase matched (conf: 0.5)"
                ArrayList<String> nBestView = new ArrayList<String>();

                for (int i = 0; i < nBestList.size(); i++) {
                    if (nBestConfidences != null) {
                        if (nBestConfidences[i] >= 0)
                            nBestView.add(nBestList.get(i) + " (conf: "
                                    + String.format("%.2f", nBestConfidences[i]) + ")");
                        else
                            nBestView.add(nBestList.get(i) + " (no confidence value available)");
                    } else
                        nBestView.add(nBestList.get(i) + " (no confidence value available)");
                }

                //Includes the collection in the ListView of the GUI
                setListView(nBestView);

                Log.i(LOGTAG, "There were : " + nBestView.size() + " recognition results");
            }
        } else {
            //Reports error in recognition error in log
            Log.e(LOGTAG, "Recognition was not successful");
        }

        //Enable button
        Button speak = (Button) findViewById(R.id.speech_btn);
        speak.setEnabled(true);
    }
}

From source file:com.yanzhenjie.durban.DurbanActivity.java

private void initArgument(Intent intent) {
    mStatusColor = ContextCompat.getColor(this, R.color.durban_ColorPrimaryDark);
    mToolbarColor = ContextCompat.getColor(this, R.color.durban_ColorPrimary);
    mNavigationColor = ContextCompat.getColor(this, R.color.durban_ColorPrimaryBlack);

    mStatusColor = intent.getIntExtra(Durban.KEY_INPUT_STATUS_COLOR, mStatusColor);
    mToolbarColor = intent.getIntExtra(Durban.KEY_INPUT_TOOLBAR_COLOR, mToolbarColor);
    mNavigationColor = intent.getIntExtra(Durban.KEY_INPUT_NAVIGATION_COLOR, mNavigationColor);
    mTitle = intent.getStringExtra(Durban.KEY_INPUT_TITLE);
    if (TextUtils.isEmpty(mTitle))
        mTitle = getString(R.string.durban_title_crop);

    mGesture = intent.getIntExtra(Durban.KEY_INPUT_GESTURE, Durban.GESTURE_ALL);
    mAspectRatio = intent.getFloatArrayExtra(Durban.KEY_INPUT_ASPECT_RATIO);
    if (mAspectRatio == null)
        mAspectRatio = new float[] { 0, 0 };
    mMaxWidthHeight = intent.getIntArrayExtra(Durban.KEY_INPUT_MAX_WIDTH_HEIGHT);
    if (mMaxWidthHeight == null)
        mMaxWidthHeight = new int[] { 500, 500 };

    //noinspection JavacQuirks
    int compressFormat = intent.getIntExtra(Durban.KEY_INPUT_COMPRESS_FORMAT, 0);
    mCompressFormat = compressFormat == Durban.COMPRESS_PNG ? Bitmap.CompressFormat.PNG
            : Bitmap.CompressFormat.JPEG;
    mCompressQuality = intent.getIntExtra(Durban.KEY_INPUT_COMPRESS_QUALITY, 90);

    mOutputDirectory = intent.getStringExtra(Durban.KEY_INPUT_DIRECTORY);
    if (TextUtils.isEmpty(mOutputDirectory))
        mOutputDirectory = getFilesDir().getAbsolutePath();
    mInputPathList = intent.getStringArrayListExtra(Durban.KEY_INPUT_PATH_ARRAY);

    mController = intent.getParcelableExtra(Durban.KEY_INPUT_CONTROLLER);
    if (mController == null)
        mController = Controller.newBuilder().build();

    mOutputPathList = new ArrayList<>();
}

From source file:com.fenlisproject.elf.core.framework.ElfBinder.java

public static void bindIntentExtra(Object receiver) {
    Field[] fields = receiver.getClass().getDeclaredFields();
    for (Field field : fields) {
        field.setAccessible(true);/*ww w . j a  v a2 s . c  o m*/
        IntentExtra intentExtra = field.getAnnotation(IntentExtra.class);
        if (intentExtra != null) {
            try {
                Intent intent = null;
                if (receiver instanceof Activity) {
                    intent = ((Activity) receiver).getIntent();
                } else if (receiver instanceof Fragment) {
                    intent = ((Fragment) receiver).getActivity().getIntent();
                }
                if (intent != null) {
                    Class<?> type = field.getType();
                    if (type == Boolean.class || type == boolean.class) {
                        field.set(receiver, intent.getBooleanExtra(intentExtra.value(), false));
                    } else if (type == Byte.class || type == byte.class) {
                        field.set(receiver, intent.getByteExtra(intentExtra.value(), (byte) 0));
                    } else if (type == Character.class || type == char.class) {
                        field.set(receiver, intent.getCharExtra(intentExtra.value(), '\u0000'));
                    } else if (type == Double.class || type == double.class) {
                        field.set(receiver, intent.getDoubleExtra(intentExtra.value(), 0.0d));
                    } else if (type == Float.class || type == float.class) {
                        field.set(receiver, intent.getFloatExtra(intentExtra.value(), 0.0f));
                    } else if (type == Integer.class || type == int.class) {
                        field.set(receiver, intent.getIntExtra(intentExtra.value(), 0));
                    } else if (type == Long.class || type == long.class) {
                        field.set(receiver, intent.getLongExtra(intentExtra.value(), 0L));
                    } else if (type == Short.class || type == short.class) {
                        field.set(receiver, intent.getShortExtra(intentExtra.value(), (short) 0));
                    } else if (type == String.class) {
                        field.set(receiver, intent.getStringExtra(intentExtra.value()));
                    } else if (type == Boolean[].class || type == boolean[].class) {
                        field.set(receiver, intent.getBooleanArrayExtra(intentExtra.value()));
                    } else if (type == Byte[].class || type == byte[].class) {
                        field.set(receiver, intent.getByteArrayExtra(intentExtra.value()));
                    } else if (type == Character[].class || type == char[].class) {
                        field.set(receiver, intent.getCharArrayExtra(intentExtra.value()));
                    } else if (type == Double[].class || type == double[].class) {
                        field.set(receiver, intent.getDoubleArrayExtra(intentExtra.value()));
                    } else if (type == Float[].class || type == float[].class) {
                        field.set(receiver, intent.getFloatArrayExtra(intentExtra.value()));
                    } else if (type == Integer[].class || type == int[].class) {
                        field.set(receiver, intent.getIntArrayExtra(intentExtra.value()));
                    } else if (type == Long[].class || type == long[].class) {
                        field.set(receiver, intent.getLongArrayExtra(intentExtra.value()));
                    } else if (type == Short[].class || type == short[].class) {
                        field.set(receiver, intent.getShortArrayExtra(intentExtra.value()));
                    } else if (type == String[].class) {
                        field.set(receiver, intent.getStringArrayExtra(intentExtra.value()));
                    } else if (Serializable.class.isAssignableFrom(type)) {
                        field.set(receiver, intent.getSerializableExtra(intentExtra.value()));
                    } else if (type == Bundle.class) {
                        field.set(receiver, intent.getBundleExtra(intentExtra.value()));
                    }
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}