-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Moves media player related functionalities to Media Widget class #2817
Changes from 9 commits
5920f83
dae5f5c
7e47345
85d7d43
199e169
ed8f245
1312e2e
064dc34
facfe12
e5c59b2
f67b2dc
9997ccd
27dba1b
44f5479
5d91481
2dec895
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.odk.collect.android.widgets; | ||
|
||
import android.content.Context; | ||
import android.graphics.Color; | ||
import android.media.MediaPlayer; | ||
import android.support.annotation.CallSuper; | ||
|
||
import org.javarosa.form.api.FormEntryPrompt; | ||
|
||
import timber.log.Timber; | ||
|
||
public abstract class MediaWidget extends QuestionWidget { | ||
|
||
private int playColor; | ||
|
||
public MediaWidget(Context context, FormEntryPrompt prompt) { | ||
super(context, prompt); | ||
|
||
String imageURI = this instanceof SelectImageMapWidget ? null : prompt.getImageText(); | ||
String audioURI = prompt.getAudioText(); | ||
String videoURI = prompt.getSpecialFormQuestionText("video"); | ||
|
||
// shown when image is clicked | ||
String bigImageURI = prompt.getSpecialFormQuestionText("big-image"); | ||
|
||
getQuestionMediaLayout().setAVT(audioURI, imageURI, videoURI, bigImageURI, player); | ||
getQuestionMediaLayout().setAudioListener(this); | ||
|
||
initPlayColor(); | ||
} | ||
|
||
private void initPlayColor() { | ||
playColor = themeUtils.getAccentColor(); | ||
|
||
String playColorString = getFormEntryPrompt().getFormElement().getAdditionalAttribute(null, "playColor"); | ||
if (playColorString != null) { | ||
try { | ||
playColor = Color.parseColor(playColorString); | ||
} catch (IllegalArgumentException e) { | ||
Timber.e(e, "Argument %s is incorrect", playColorString); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see you didn’t create, but just moved this code, so disregard the above if you like. |
||
} | ||
} | ||
|
||
getQuestionMediaLayout().setPlayTextColor(playColor); | ||
} | ||
|
||
@Override | ||
public void release() { | ||
super.release(); | ||
|
||
if (player != null) { | ||
player.release(); | ||
player = null; | ||
} | ||
} | ||
|
||
@Override | ||
protected void onWindowVisibilityChanged(int visibility) { | ||
if (visibility == INVISIBLE || visibility == GONE) { | ||
stopAudio(); | ||
} | ||
} | ||
|
||
/* | ||
* Prompts with items must override this | ||
*/ | ||
@CallSuper | ||
public void playAllPromptText(String playOption) { | ||
if (playOption.equalsIgnoreCase("audio")) { | ||
getQuestionMediaLayout().playAudio(); | ||
} else if (playOption.equalsIgnoreCase("video")) { | ||
getQuestionMediaLayout().playVideo(); | ||
} | ||
} | ||
|
||
public void stopAudio() { | ||
if (player != null && player.isPlaying()) { | ||
player.stop(); | ||
player.reset(); | ||
} | ||
} | ||
|
||
public MediaPlayer getPlayer() { | ||
return player; | ||
} | ||
|
||
public int getPlayColor() { | ||
return playColor; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but I think we’re using the convention that initialisms (like URI) are capitalized like uri or imageUri. I have an audio clip of Josh Bloch himself recommending this.