Search in sources :

Example 6 with IField

use of com.ichi2.anki.multimediacard.fields.IField in project Anki-Android by Ramblurr.

the class MultimediaCardEditorActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE_EDIT_FIELD) {
        if (resultCode == RESULT_OK) {
            IField field = (IField) data.getSerializableExtra(EditFieldActivity.EXTRA_RESULT_FIELD);
            int index = data.getIntExtra(EditFieldActivity.EXTRA_RESULT_FIELD_INDEX, -1);
            // Failed editing activity
            if (index == -1) {
                return;
            }
            mNote.setField(index, field);
            createEditorUI(mNote);
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}
Also used : IField(com.ichi2.anki.multimediacard.fields.IField) SuppressLint(android.annotation.SuppressLint)

Example 7 with IField

use of com.ichi2.anki.multimediacard.fields.IField in project Anki-Android by Ramblurr.

the class BasicTextFieldController method createCloneButton.

/**
     * @param activity
     * @param layoutTools This creates a button, which will call a dialog, allowing to pick from another note's fields
     *            one, and use it's value in the current one.
     * @param p
     */
private void createCloneButton(LinearLayout layoutTools, LayoutParams p) {
    // Makes sense only for two and more fields
    if (mNote.getNumberOfFields() > 1) {
        // Should be more than one text not empty fields for clone to make
        // sense
        mPossibleClones = new ArrayList<String>();
        int numTextFields = 0;
        for (int i = 0; i < mNote.getNumberOfFields(); ++i) {
            // Sort out non text and empty fields
            IField curField = mNote.getField(i);
            if (curField == null) {
                continue;
            }
            if (curField.getType() != EFieldType.TEXT) {
                continue;
            }
            if (curField.getText() == null) {
                continue;
            }
            if (curField.getText().length() == 0) {
                continue;
            }
            // as well as the same field
            if (curField.getText().contentEquals(mField.getText())) {
                continue;
            }
            // collect clone sources
            mPossibleClones.add(curField.getText());
            ++numTextFields;
        }
        // Nothing to clone from
        if (numTextFields < 1) {
            return;
        }
        Button btnOtherField = new Button(mActivity);
        btnOtherField.setText(gtxt(R.string.multimedia_editor_text_field_editing_clone));
        layoutTools.addView(btnOtherField, p);
        final BasicTextFieldController controller = this;
        btnOtherField.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                PickStringDialogFragment fragment = new PickStringDialogFragment();
                fragment.setChoices(mPossibleClones);
                fragment.setOnclickListener(controller);
                fragment.setTitle(gtxt(R.string.multimedia_editor_text_field_editing_clone_source));
                fragment.show(mActivity.getSupportFragmentManager(), "pick.clone");
            // flow continues in the onClick function
            }
        });
    }
}
Also used : Button(android.widget.Button) PickStringDialogFragment(com.ichi2.anki.multimediacard.activity.PickStringDialogFragment) OnClickListener(android.view.View.OnClickListener) View(android.view.View)

Aggregations

IField (com.ichi2.anki.multimediacard.fields.IField)4 SuppressLint (android.annotation.SuppressLint)3 View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 Button (android.widget.Button)2 LinearLayout (android.widget.LinearLayout)2 File (java.io.File)2 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 DisplayMetrics (android.util.DisplayMetrics)1 ImageView (android.widget.ImageView)1 LayoutParams (android.widget.LinearLayout.LayoutParams)1 TextView (android.widget.TextView)1 AudioView (com.ichi2.anki.multimediacard.AudioView)1 IMultimediaEditableNote (com.ichi2.anki.multimediacard.IMultimediaEditableNote)1 PickStringDialogFragment (com.ichi2.anki.multimediacard.activity.PickStringDialogFragment)1 AudioField (com.ichi2.anki.multimediacard.fields.AudioField)1 ImageField (com.ichi2.anki.multimediacard.fields.ImageField)1 TextField (com.ichi2.anki.multimediacard.fields.TextField)1 MultimediaEditableNote (com.ichi2.anki.multimediacard.impl.MultimediaEditableNote)1