use of com.ichi2.anki.multimediacard.fields.IField in project Anki-Android by Ramblurr.
the class MultimediaCardEditorActivity method createEditorUI.
/**
* Creates the UI for editor area inside EditorLayout
*
* @param note
*/
private void createEditorUI(IMultimediaEditableNote note) {
try {
if (mNote == null) {
finishCancel();
return;
} else {
for (int i = 0; i < mNote.getNumberOfFields(); ++i) {
IField f = mNote.getField(i);
if (f == null) {
finishCancel();
return;
}
}
}
LinearLayout linearLayout = mEditorLayout;
linearLayout.removeAllViews();
for (int i = 0; i < note.getNumberOfFields(); ++i) {
createNewViewer(linearLayout, note.getField(i), i);
}
mModelButton.setText(gtxt(R.string.multimedia_editor_activity_note_type) + " : " + mEditorNote.model().getString("name"));
mDeckButton.setText(gtxt(R.string.multimedia_editor_activity_deck) + " : " + mCol.getDecks().get(mCurrentDid).getString("name"));
} catch (JSONException e) {
Log.e("Multimedia Editor", e.getMessage());
return;
}
}
use of com.ichi2.anki.multimediacard.fields.IField in project Anki-Android by Ramblurr.
the class NoteService method importMediaToDirectory.
/**
* Considering the field is new, if it has media handle it
*
* @param field
*/
private static void importMediaToDirectory(IField field) {
String tmpMediaPath = null;
switch(field.getType()) {
case AUDIO:
tmpMediaPath = field.getAudioPath();
break;
case IMAGE:
tmpMediaPath = field.getImagePath();
break;
case TEXT:
default:
break;
}
if (tmpMediaPath != null) {
try {
File inFile = new File(tmpMediaPath);
if (inFile.exists()) {
Collection col = AnkiDroidApp.getCol();
String mediaDir = col.getMedia().getDir() + "/";
File mediaDirFile = new File(mediaDir);
File parent = inFile.getParentFile();
// If already there.
if (mediaDirFile.getAbsolutePath().contentEquals(parent.getAbsolutePath())) {
return;
}
File outFile = new File(mediaDir + inFile.getName());
if (!outFile.exists()) {
if (field.hasTemporaryMedia()) {
// Move
inFile.renameTo(outFile);
} else {
// Copy
InputStream in = new FileInputStream(tmpMediaPath);
OutputStream out = new FileOutputStream(outFile.getAbsolutePath());
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
switch(field.getType()) {
case AUDIO:
field.setAudioPath(outFile.getAbsolutePath());
break;
case IMAGE:
field.setImagePath(outFile.getAbsolutePath());
break;
default:
break;
}
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
use of com.ichi2.anki.multimediacard.fields.IField in project Anki-Android by Ramblurr.
the class NoteService method updateMultimediaNoteFromJsonNote.
public static void updateMultimediaNoteFromJsonNote(final Note editorNoteSrc, final IMultimediaEditableNote noteDst) {
if (noteDst instanceof MultimediaEditableNote) {
MultimediaEditableNote mmNote = (MultimediaEditableNote) noteDst;
String[] values = editorNoteSrc.getFields();
for (int i = 0; i < values.length; i++) {
String value = values[i];
IField field = null;
if (value.startsWith("<img")) {
field = new ImageField();
} else if (value.startsWith("[sound:")) {
field = new AudioField();
} else {
field = new TextField();
}
field.setFormattedString(value);
mmNote.setField(i, field);
}
mmNote.setModelId(editorNoteSrc.getMid());
// TODO: set current id of the note as well
}
}
use of com.ichi2.anki.multimediacard.fields.IField in project Anki-Android by Ramblurr.
the class NoteService method saveMedia.
/**
* Saves the multimedia associated with this card to proper path inside anki folder. For each field associated with
* the note it checks for the following condition a. The field content should have changed b. The field content does
* not already point to a media inside anki media path If both condition satisfies then it copies the file inside
* the media path and deletes the file referenced by the note
*
* @param note
*/
public static void saveMedia(final MultimediaEditableNote noteNew) {
// if (noteNew.getModelId() == noteOld.getModelId())
// {
// int fieldCount = noteNew.getNumberOfFields();
// for (int i = 0; i < fieldCount; i++)
// {
// IField newField = noteNew.getField(i);
// IField oldField = noteOld.getField(i);
// if
// (newField.getFormattedValue().equals(oldField.getFormattedValue()))
// {
// continue;
// }
// importMediaToDirectory(newField);
// }
// }
// else
// {
int fieldCount = noteNew.getNumberOfFields();
for (int i = 0; i < fieldCount; i++) {
IField newField = noteNew.getField(i);
importMediaToDirectory(newField);
}
// }
}
use of com.ichi2.anki.multimediacard.fields.IField 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);
}
});
}
Aggregations