Search in sources :

Example 1 with AudioView

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

the class BasicAudioFieldController method createUI.

@Override
public void createUI(LinearLayout layout) {
    origAudioPath = mField.getAudioPath();
    boolean bExist = false;
    if (origAudioPath != null) {
        File f = new File(origAudioPath);
        if (f.exists()) {
            tempAudioPath = f.getAbsolutePath();
            bExist = true;
        }
    }
    if (!bExist) {
        File file = null;
        try {
            file = File.createTempFile("ankidroid_audiorec", ".3gp", DiskUtil.getStoringDirectory());
            tempAudioPath = file.getAbsolutePath();
        } catch (IOException e) {
            Log.e(AnkiDroidApp.TAG, "Could not create temporary audio file. " + e.getMessage());
            tempAudioPath = null;
        }
    }
    AudioView audioView = AudioView.createRecorderInstance(mActivity, R.drawable.av_play, R.drawable.av_pause, R.drawable.av_stop, R.drawable.av_rec, R.drawable.av_rec_stop, tempAudioPath);
    audioView.setOnRecordingFinishEventListener(new AudioView.OnRecordingFinishEventListener() {

        @Override
        public void onRecordingFinish(View v) {
            // currentFilePath.setText("Recording done, you can preview it. Hit save after finish");
            mField.setAudioPath(tempAudioPath);
            mField.setHasTemporaryMedia(true);
        }
    });
    layout.addView(audioView, LinearLayout.LayoutParams.FILL_PARENT);
}
Also used : AudioView(com.ichi2.anki.multimediacard.AudioView) IOException(java.io.IOException) File(java.io.File) View(android.view.View) AudioView(com.ichi2.anki.multimediacard.AudioView)

Example 2 with AudioView

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

the class MultimediaCardEditorActivity method createNewViewer.

private void createNewViewer(LinearLayout linearLayout, final IField field, final int index) {
    final MultimediaCardEditorActivity context = this;
    switch(field.getType()) {
        case TEXT:
            // Create a text field and an edit button, opening editing for
            // the
            // text field
            TextView textView = new TextView(this);
            textView.setText(field.getText());
            linearLayout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT);
            break;
        case IMAGE:
            ImageView imgView = new ImageView(this);
            //
            // BitmapFactory.Options options = new BitmapFactory.Options();
            // options.inSampleSize = 2;
            // Bitmap bm = BitmapFactory.decodeFile(myJpgPath, options);
            // jpgView.setImageBitmap(bm);
            LinearLayout.LayoutParams p = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            File f = new File(field.getImagePath());
            Bitmap b = BitmapUtil.decodeFile(f, getMaxImageSize());
            int currentapiVersion = android.os.Build.VERSION.SDK_INT;
            if (currentapiVersion >= android.os.Build.VERSION_CODES.ECLAIR) {
                b = ExifUtil.rotateFromCamera(f, b);
            }
            imgView.setImageBitmap(b);
            imgView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            imgView.setAdjustViewBounds(true);
            DisplayMetrics metrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(metrics);
            int height = metrics.heightPixels;
            int width = metrics.widthPixels;
            imgView.setMaxHeight((int) Math.round(height * 0.6));
            imgView.setMaxWidth((int) Math.round(width * 0.7));
            linearLayout.addView(imgView, p);
            break;
        case AUDIO:
            AudioView audioView = AudioView.createPlayerInstance(this, R.drawable.av_play, R.drawable.av_pause, R.drawable.av_stop, field.getAudioPath());
            linearLayout.addView(audioView);
            break;
        default:
            Log.e("multimedia editor", "Unsupported field type found");
            break;
    }
    Button editButtonText = new Button(this);
    editButtonText.setText(gtxt(R.string.multimedia_editor_activity_edit_button));
    linearLayout.addView(editButtonText, LinearLayout.LayoutParams.MATCH_PARENT);
    editButtonText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(context, EditFieldActivity.class);
            putExtrasAndStartEditActivity(field, index, i);
        }
    });
}
Also used : LayoutParams(android.widget.LinearLayout.LayoutParams) OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) DisplayMetrics(android.util.DisplayMetrics) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AudioView(com.ichi2.anki.multimediacard.AudioView) SuppressLint(android.annotation.SuppressLint) LayoutParams(android.widget.LinearLayout.LayoutParams) AudioView(com.ichi2.anki.multimediacard.AudioView) Bitmap(android.graphics.Bitmap) Button(android.widget.Button) TextView(android.widget.TextView) ImageView(android.widget.ImageView) File(java.io.File) LinearLayout(android.widget.LinearLayout)

Aggregations

View (android.view.View)2 AudioView (com.ichi2.anki.multimediacard.AudioView)2 File (java.io.File)2 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 DisplayMetrics (android.util.DisplayMetrics)1 OnClickListener (android.view.View.OnClickListener)1 Button (android.widget.Button)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 LayoutParams (android.widget.LinearLayout.LayoutParams)1 TextView (android.widget.TextView)1 IOException (java.io.IOException)1