mirror of
https://github.com/ankidroid/Anki-Android.git
synced 2024-09-20 12:02:16 +02:00
De-lint / Codacy-clean multimediacard hierarchy
This commit is contained in:
parent
aafa5155ae
commit
d21954ee8f
@ -22,7 +22,6 @@ package com.ichi2.anki.multimediacard;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.media.MediaPlayer;
|
||||
import android.media.MediaPlayer.OnCompletionListener;
|
||||
import android.media.MediaRecorder;
|
||||
|
||||
import androidx.appcompat.widget.AppCompatImageButton;
|
||||
@ -45,15 +44,15 @@ public class AudioView extends LinearLayout {
|
||||
private MediaRecorder mRecorder = null;
|
||||
private MediaPlayer mPlayer = null;
|
||||
|
||||
OnRecordingFinishEventListener mOnRecordingFinishEventListener = null;
|
||||
private OnRecordingFinishEventListener mOnRecordingFinishEventListener = null;
|
||||
|
||||
private Status mStatus = Status.IDLE;
|
||||
|
||||
int mResPlayImage;
|
||||
int mResPauseImage;
|
||||
int mResStopImage;
|
||||
int mResRecordImage;
|
||||
int mResRecordStopImage;
|
||||
private int mResPlayImage;
|
||||
private int mResPauseImage;
|
||||
private int mResStopImage;
|
||||
private int mResRecordImage;
|
||||
private int mResRecordStopImage;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@ -66,20 +65,6 @@ public class AudioView extends LinearLayout {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param context Resources for images
|
||||
* @param resPlay
|
||||
* @param resPause
|
||||
* @param resStop
|
||||
* @param audioPath
|
||||
* @return
|
||||
*/
|
||||
public static AudioView createPlayerInstance(Context context, int resPlay, int resPause, int resStop,
|
||||
String audioPath) {
|
||||
return new AudioView(context, resPlay, resPause, resStop, audioPath);
|
||||
}
|
||||
|
||||
|
||||
public static AudioView createRecorderInstance(Context context, int resPlay, int resPause, int resStop,
|
||||
int resRecord, int resRecordStop, String audioPath) {
|
||||
return new AudioView(context, resPlay, resPause, resStop, resRecord, resRecordStop, audioPath);
|
||||
@ -136,15 +121,6 @@ public class AudioView extends LinearLayout {
|
||||
}
|
||||
|
||||
|
||||
public void setRecordButtonVisible(boolean isVisible) {
|
||||
if (isVisible) {
|
||||
mRecord.setVisibility(VISIBLE);
|
||||
} else {
|
||||
mRecord.setVisibility(INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setOnRecordingFinishEventListener(OnRecordingFinishEventListener listener) {
|
||||
mOnRecordingFinishEventListener = listener;
|
||||
}
|
||||
@ -209,7 +185,7 @@ public class AudioView extends LinearLayout {
|
||||
}
|
||||
|
||||
protected class PlayPauseButton extends AppCompatImageButton {
|
||||
OnClickListener onClickListener = new View.OnClickListener() {
|
||||
private OnClickListener onClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mAudioPath == null) {
|
||||
@ -221,13 +197,10 @@ public class AudioView extends LinearLayout {
|
||||
try {
|
||||
mPlayer = new MediaPlayer();
|
||||
mPlayer.setDataSource(getAudioPath());
|
||||
mPlayer.setOnCompletionListener(new OnCompletionListener() {
|
||||
@Override
|
||||
public void onCompletion(MediaPlayer mp) {
|
||||
mStatus = Status.STOPPED;
|
||||
mPlayer.stop();
|
||||
notifyStop();
|
||||
}
|
||||
mPlayer.setOnCompletionListener(mp -> {
|
||||
mStatus = Status.STOPPED;
|
||||
mPlayer.stop();
|
||||
notifyStop();
|
||||
});
|
||||
mPlayer.prepare();
|
||||
mPlayer.start();
|
||||
@ -236,7 +209,7 @@ public class AudioView extends LinearLayout {
|
||||
mStatus = Status.PLAYING;
|
||||
notifyPlay();
|
||||
} catch (Exception e) {
|
||||
Timber.e(e.getMessage());
|
||||
Timber.e(e);
|
||||
showToast(gtxt(R.string.multimedia_editor_audio_view_playing_failed));
|
||||
mStatus = Status.IDLE;
|
||||
}
|
||||
@ -258,7 +231,7 @@ public class AudioView extends LinearLayout {
|
||||
mPlayer.prepare();
|
||||
mPlayer.seekTo(0);
|
||||
} catch (Exception e) {
|
||||
Timber.e(e.getMessage());
|
||||
Timber.e(e);
|
||||
}
|
||||
mPlayer.start();
|
||||
notifyPlay();
|
||||
@ -309,22 +282,21 @@ public class AudioView extends LinearLayout {
|
||||
}
|
||||
|
||||
protected class StopButton extends AppCompatImageButton {
|
||||
OnClickListener onClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (mStatus) {
|
||||
case PAUSED:
|
||||
case PLAYING:
|
||||
mPlayer.stop();
|
||||
mStatus = Status.STOPPED;
|
||||
notifyStop();
|
||||
break;
|
||||
private OnClickListener onClickListener = v -> {
|
||||
switch (mStatus) {
|
||||
case PAUSED:
|
||||
case PLAYING:
|
||||
mPlayer.stop();
|
||||
mStatus = Status.STOPPED;
|
||||
notifyStop();
|
||||
break;
|
||||
|
||||
case IDLE:
|
||||
case STOPPED:
|
||||
case RECORDING:
|
||||
case INITIALIZED:
|
||||
}
|
||||
case IDLE:
|
||||
case STOPPED:
|
||||
case RECORDING:
|
||||
case INITIALIZED:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
@ -345,6 +317,7 @@ public class AudioView extends LinearLayout {
|
||||
|
||||
default:
|
||||
setEnabled(true);
|
||||
break;
|
||||
}
|
||||
// It doesn't need to update itself on any other state changes
|
||||
}
|
||||
@ -352,7 +325,7 @@ public class AudioView extends LinearLayout {
|
||||
}
|
||||
|
||||
protected class RecordButton extends AppCompatImageButton {
|
||||
OnClickListener onClickListener = new View.OnClickListener() {
|
||||
private OnClickListener onClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// Since mAudioPath is not compulsory, we check if it exists
|
||||
@ -412,7 +385,7 @@ public class AudioView extends LinearLayout {
|
||||
break;
|
||||
|
||||
default:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -452,6 +425,6 @@ public class AudioView extends LinearLayout {
|
||||
}
|
||||
|
||||
public interface OnRecordingFinishEventListener {
|
||||
public void onRecordingFinish(View v);
|
||||
void onRecordingFinish(View v);
|
||||
}
|
||||
}
|
||||
|
@ -38,8 +38,4 @@ public interface IMultimediaEditableNote extends Serializable {
|
||||
|
||||
|
||||
boolean isModified();
|
||||
|
||||
|
||||
public void circularSwap();
|
||||
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
@ -52,6 +51,7 @@ import java.util.Locale;
|
||||
* User picks a source language and the source is passed as extra.
|
||||
* <p>
|
||||
* When activity finished, it passes the filepath as another extra to the caller.
|
||||
* FIXME why isn't this extending AnkiActivity?
|
||||
*/
|
||||
public class LoadPronounciationActivity extends Activity implements OnCancelListener {
|
||||
|
||||
@ -67,18 +67,13 @@ public class LoadPronounciationActivity extends Activity implements OnCancelList
|
||||
|
||||
private ProgressDialog progressDialog = null;
|
||||
|
||||
private String mTranslation;
|
||||
|
||||
private String mPronunciationAddress;
|
||||
|
||||
private String mPronunciationPage;
|
||||
|
||||
private String mMp3Address;
|
||||
|
||||
private LoadPronounciationActivity mActivity;
|
||||
private LanguageListerBeolingus mLanguageLister;
|
||||
private Spinner mSpinnerFrom;
|
||||
private Button mSaveButton;
|
||||
|
||||
private BackgroundPost mPostTranslation = null;
|
||||
private BackgroundPost mPostPronunciation = null;
|
||||
@ -102,9 +97,9 @@ public class LoadPronounciationActivity extends Activity implements OnCancelList
|
||||
setContentView(R.layout.activity_load_pronounciation);
|
||||
mSource = getIntent().getExtras().getString(EXTRA_SOURCE);
|
||||
|
||||
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.layoutInLoadPronActivity);
|
||||
LinearLayout linearLayout = findViewById(R.id.layoutInLoadPronActivity);
|
||||
|
||||
mLanguageLister = new LanguageListerBeolingus(this);
|
||||
mLanguageLister = new LanguageListerBeolingus();
|
||||
|
||||
mSpinnerFrom = new Spinner(this);
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
|
||||
@ -116,27 +111,12 @@ public class LoadPronounciationActivity extends Activity implements OnCancelList
|
||||
Button buttonLoadPronunciation = new Button(this);
|
||||
buttonLoadPronunciation.setText(gtxt(R.string.multimedia_editor_pron_load));
|
||||
linearLayout.addView(buttonLoadPronunciation);
|
||||
buttonLoadPronunciation.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onLoadPronunciation(v);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
mSaveButton = new Button(this);
|
||||
buttonLoadPronunciation.setOnClickListener(v -> onLoadPronunciation(v));
|
||||
Button mSaveButton = new Button(this);
|
||||
mSaveButton.setText("Save");
|
||||
mSaveButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
});
|
||||
mSaveButton.setOnClickListener(v -> { });
|
||||
mActivity = this;
|
||||
|
||||
mStopped = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -276,19 +256,15 @@ public class LoadPronounciationActivity extends Activity implements OnCancelList
|
||||
// Means we get the page with the word translation,
|
||||
// And we have to start fetching the page with pronunciation
|
||||
if (post.getAddress().contentEquals(mTranslationAddress)) {
|
||||
mTranslation = result;
|
||||
|
||||
if (mTranslation.startsWith("FAILED")) {
|
||||
|
||||
if (result.startsWith("FAILED")) {
|
||||
failNoPronunciation();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
mPronunciationAddress = BeolingusParser.getPronunciationAddressFromTranslation(mTranslation, mSource);
|
||||
mPronunciationAddress = BeolingusParser.getPronunciationAddressFromTranslation(result, mSource);
|
||||
|
||||
if (mPronunciationAddress.contentEquals("no")) {
|
||||
|
||||
failNoPronunciation();
|
||||
|
||||
if (!mSource.toLowerCase(Locale.getDefault()).contentEquals(mSource)) {
|
||||
@ -318,9 +294,7 @@ public class LoadPronounciationActivity extends Activity implements OnCancelList
|
||||
if (post.getAddress().contentEquals(mPronunciationAddress)) {
|
||||
// else here = pronunciation post returned;
|
||||
|
||||
mPronunciationPage = result;
|
||||
|
||||
mMp3Address = BeolingusParser.getMp3AddressFromPronounciation(mPronunciationPage);
|
||||
mMp3Address = BeolingusParser.getMp3AddressFromPronounciation(result);
|
||||
|
||||
if (mMp3Address.contentEquals("no")) {
|
||||
failNoPronunciation();
|
||||
@ -337,11 +311,7 @@ public class LoadPronounciationActivity extends Activity implements OnCancelList
|
||||
progressDialog.dismiss();
|
||||
showToast(gtxt(R.string.multimedia_editor_something_wrong));
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -362,17 +332,11 @@ public class LoadPronounciationActivity extends Activity implements OnCancelList
|
||||
}
|
||||
|
||||
progressDialog.dismiss();
|
||||
|
||||
showToast(gtxt(R.string.multimedia_editor_general_done));
|
||||
|
||||
Intent resultData = new Intent();
|
||||
|
||||
resultData.putExtra(EXTRA_PRONUNCIATION_FILE_PATH, result);
|
||||
|
||||
setResult(RESULT_OK, resultData);
|
||||
|
||||
finish();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -442,25 +406,18 @@ public class LoadPronounciationActivity extends Activity implements OnCancelList
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
mStopped = true;
|
||||
|
||||
dismissCarefullyProgressDialog();
|
||||
|
||||
stopAllTasks();
|
||||
|
||||
Intent resultData = new Intent();
|
||||
|
||||
setResult(RESULT_CANCELED, resultData);
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
private void dismissCarefullyProgressDialog() {
|
||||
try {
|
||||
if (progressDialog != null) {
|
||||
if (progressDialog.isShowing()) {
|
||||
if ((progressDialog != null) && progressDialog.isShowing()) {
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// nothing is done intentionally
|
||||
|
@ -30,9 +30,7 @@ import androidx.appcompat.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
|
||||
import com.ichi2.anki.AnkiActivity;
|
||||
import com.ichi2.anki.R;
|
||||
@ -64,9 +62,9 @@ public class MultimediaEditFieldActivity extends AnkiActivity
|
||||
private static final int REQUEST_AUDIO_PERMISSION = 0;
|
||||
private static final int REQUEST_CAMERA_PERMISSION = 1;
|
||||
|
||||
IField mField;
|
||||
IMultimediaEditableNote mNote;
|
||||
int mFieldIndex;
|
||||
private IField mField;
|
||||
private IMultimediaEditableNote mNote;
|
||||
private int mFieldIndex;
|
||||
|
||||
private IFieldController mFieldController;
|
||||
|
||||
@ -85,7 +83,7 @@ public class MultimediaEditFieldActivity extends AnkiActivity
|
||||
|
||||
setContentView(R.layout.multimedia_edit_field_activity);
|
||||
View mainView = findViewById(android.R.id.content);
|
||||
Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.toolbar);
|
||||
Toolbar toolbar = mainView.findViewById(R.id.toolbar);
|
||||
if (toolbar != null) {
|
||||
setSupportActionBar(toolbar);
|
||||
}
|
||||
@ -108,6 +106,7 @@ public class MultimediaEditFieldActivity extends AnkiActivity
|
||||
|
||||
|
||||
private void recreateEditingUi() {
|
||||
Timber.d("recreateEditingUi()");
|
||||
|
||||
IControllerFactory controllerFactory = BasicControllerFactory.getInstance();
|
||||
|
||||
@ -138,7 +137,7 @@ public class MultimediaEditFieldActivity extends AnkiActivity
|
||||
mFieldController.setNote(mNote);
|
||||
mFieldController.setEditingActivity(this);
|
||||
|
||||
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.LinearLayoutInScrollViewFieldEdit);
|
||||
LinearLayout linearLayout = findViewById(R.id.LinearLayoutInScrollViewFieldEdit);
|
||||
|
||||
linearLayout.removeAllViews();
|
||||
|
||||
@ -149,6 +148,7 @@ public class MultimediaEditFieldActivity extends AnkiActivity
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
Timber.d("onCreateOptionsMenu() - mField.getType() = %s", mField.getType());
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.activity_edit_text, menu);
|
||||
menu.findItem(R.id.multimedia_edit_field_to_text).setVisible(mField.getType() != EFieldType.TEXT);
|
||||
@ -193,53 +193,6 @@ public class MultimediaEditFieldActivity extends AnkiActivity
|
||||
}
|
||||
|
||||
|
||||
private void createSpareMenu(LinearLayout linearLayout) {
|
||||
|
||||
LayoutParams pars = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1);
|
||||
|
||||
Button toTextButton = new Button(this);
|
||||
toTextButton.setText(gtxt(R.string.multimedia_editor_field_editing_text));
|
||||
toTextButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
toTextField();
|
||||
}
|
||||
|
||||
});
|
||||
linearLayout.addView(toTextButton, pars);
|
||||
|
||||
Button toImageButton = new Button(this);
|
||||
toImageButton.setText(gtxt(R.string.multimedia_editor_field_editing_image));
|
||||
toImageButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
toImageField();
|
||||
}
|
||||
|
||||
});
|
||||
linearLayout.addView(toImageButton, pars);
|
||||
|
||||
Button toAudioButton = new Button(this);
|
||||
toAudioButton.setText(gtxt(R.string.multimedia_editor_field_editing_audio));
|
||||
toAudioButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
toAudioField();
|
||||
}
|
||||
|
||||
});
|
||||
linearLayout.addView(toAudioButton, pars);
|
||||
|
||||
Button doneButton = new Button(this);
|
||||
doneButton.setText(gtxt(R.string.multimedia_editor_field_editing_done));
|
||||
doneButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
done();
|
||||
}
|
||||
|
||||
});
|
||||
linearLayout.addView(doneButton, pars);
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void done() {
|
||||
|
||||
mFieldController.onDone();
|
||||
@ -281,7 +234,7 @@ public class MultimediaEditFieldActivity extends AnkiActivity
|
||||
|
||||
setResult(RESULT_OK, resultData);
|
||||
|
||||
finish();
|
||||
finishWithoutAnimation();
|
||||
}
|
||||
|
||||
|
||||
@ -312,6 +265,7 @@ public class MultimediaEditFieldActivity extends AnkiActivity
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
Timber.d("onActivityResult()");
|
||||
if (mFieldController != null) {
|
||||
mFieldController.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
@ -349,11 +303,6 @@ public class MultimediaEditFieldActivity extends AnkiActivity
|
||||
}
|
||||
|
||||
|
||||
private String gtxt(int id) {
|
||||
return getText(id).toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
@ -28,8 +28,6 @@ import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import android.view.Menu;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
@ -58,6 +56,7 @@ import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Activity used now with Glosbe.com to enable translation of words.
|
||||
* FIXME why isn't this extending from our base classes?
|
||||
*/
|
||||
public class TranslationActivity extends FragmentActivity implements DialogInterface.OnClickListener, OnCancelListener {
|
||||
|
||||
@ -68,8 +67,8 @@ public class TranslationActivity extends FragmentActivity implements DialogInter
|
||||
// Translated result
|
||||
public static final String EXTRA_TRANSLATION = "translation.activity.extra.translation";
|
||||
|
||||
String mSource;
|
||||
String mTranslation;
|
||||
private String mSource;
|
||||
private String mTranslation;
|
||||
private LanguagesListerGlosbe mLanguageLister;
|
||||
private Spinner mSpinnerFrom;
|
||||
private Spinner mSpinnerTo;
|
||||
@ -110,7 +109,7 @@ public class TranslationActivity extends FragmentActivity implements DialogInter
|
||||
// If translation fails this is a default - source will be returned.
|
||||
mTranslation = mSource;
|
||||
|
||||
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.MainLayoutInTranslationActivity);
|
||||
LinearLayout linearLayout = findViewById(R.id.MainLayoutInTranslationActivity);
|
||||
|
||||
TextView tv = new TextView(this);
|
||||
tv.setText(getText(R.string.multimedia_editor_trans_poweredglosbe));
|
||||
@ -120,7 +119,7 @@ public class TranslationActivity extends FragmentActivity implements DialogInter
|
||||
tvFrom.setText(getText(R.string.multimedia_editor_trans_from));
|
||||
linearLayout.addView(tvFrom);
|
||||
|
||||
mLanguageLister = new LanguagesListerGlosbe(this);
|
||||
mLanguageLister = new LanguagesListerGlosbe();
|
||||
|
||||
mSpinnerFrom = new Spinner(this);
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
|
||||
@ -150,17 +149,14 @@ public class TranslationActivity extends FragmentActivity implements DialogInter
|
||||
// Setup button
|
||||
Button btnDone = new Button(this);
|
||||
btnDone.setText(getText(R.string.multimedia_editor_trans_translate));
|
||||
btnDone.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// Remember currently selected language
|
||||
String fromLang = mSpinnerFrom.getSelectedItem().toString();
|
||||
String toLang = mSpinnerTo.getSelectedItem().toString();
|
||||
preferences.edit().putString("translatorLastLanguageFrom", fromLang).commit();
|
||||
preferences.edit().putString("translatorLastLanguageTo", toLang).commit();
|
||||
// Get translation
|
||||
translate();
|
||||
}
|
||||
btnDone.setOnClickListener(v -> {
|
||||
// Remember currently selected language
|
||||
String fromLang1 = mSpinnerFrom.getSelectedItem().toString();
|
||||
String toLang1 = mSpinnerTo.getSelectedItem().toString();
|
||||
preferences.edit().putString("translatorLastLanguageFrom", fromLang1).apply();
|
||||
preferences.edit().putString("translatorLastLanguageTo", toLang1).apply();
|
||||
// Get translation
|
||||
translate();
|
||||
});
|
||||
|
||||
linearLayout.addView(btnDone);
|
||||
@ -416,10 +412,8 @@ public class TranslationActivity extends FragmentActivity implements DialogInter
|
||||
|
||||
private void dismissCarefullyProgressDialog() {
|
||||
try {
|
||||
if (progressDialog != null) {
|
||||
if (progressDialog.isShowing()) {
|
||||
if ((progressDialog != null) && progressDialog.isShowing()) {
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// nothing is done intentionally
|
||||
|
@ -42,7 +42,7 @@ public class BeolingusParser {
|
||||
Matcher m = PRONUNC_PATTERN.matcher(html);
|
||||
while (m.find()) {
|
||||
if (m.group(2).equals(wordToSearchFor)) {
|
||||
Timber.d("pronunciation URL is https://dict.tu-chemnitz.de" + m.group(1));
|
||||
Timber.d("pronunciation URL is https://dict.tu-chemnitz.de%s", m.group(1));
|
||||
return "https://dict.tu-chemnitz.de" + m.group(1);
|
||||
}
|
||||
}
|
||||
@ -58,7 +58,7 @@ public class BeolingusParser {
|
||||
// Timber.d("pronunciationPageHtml is " + pronunciationPageHtml);
|
||||
Matcher m = MP3_PATTERN.matcher(pronunciationPageHtml);
|
||||
if (m.find()) {
|
||||
Timber.d("MP3 address is https://dict.tu-chemnitz.de" + m.group(1));
|
||||
Timber.d("MP3 address is https://dict.tu-chemnitz.de%s", m.group(1));
|
||||
return "https://dict.tu-chemnitz.de" + m.group(1);
|
||||
}
|
||||
return "no";
|
||||
|
@ -22,7 +22,6 @@ package com.ichi2.anki.multimediacard.fields;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.ichi2.anki.CollectionHelper;
|
||||
@ -37,19 +36,16 @@ import timber.log.Timber;
|
||||
|
||||
public class BasicAudioFieldController extends FieldControllerBase implements IFieldController {
|
||||
|
||||
protected static final int ACTIVITY_RECORD_AUDIO = 1;
|
||||
|
||||
/**
|
||||
* This controller always return a temporary path where it writes the audio
|
||||
*/
|
||||
private String tempAudioPath;
|
||||
private String origAudioPath;
|
||||
private AudioView mAudioView;
|
||||
|
||||
|
||||
@Override
|
||||
public void createUI(Context context, LinearLayout layout) {
|
||||
origAudioPath = mField.getAudioPath();
|
||||
String origAudioPath = mField.getAudioPath();
|
||||
|
||||
boolean bExist = false;
|
||||
|
||||
@ -63,27 +59,23 @@ public class BasicAudioFieldController extends FieldControllerBase implements IF
|
||||
}
|
||||
|
||||
if (!bExist) {
|
||||
File file = null;
|
||||
try {
|
||||
Collection col = CollectionHelper.getInstance().getCol(context);
|
||||
File storingDirectory = new File(col.getMedia().dir());
|
||||
file = File.createTempFile("ankidroid_audiorec", ".3gp", storingDirectory);
|
||||
File file = File.createTempFile("ankidroid_audiorec", ".3gp", storingDirectory);
|
||||
tempAudioPath = file.getAbsolutePath();
|
||||
} catch (IOException e) {
|
||||
Timber.e("Could not create temporary audio file. " + e.getMessage());
|
||||
Timber.e(e, "Could not create temporary audio file.");
|
||||
tempAudioPath = null;
|
||||
}
|
||||
}
|
||||
|
||||
mAudioView = 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);
|
||||
mAudioView.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);
|
||||
}
|
||||
mAudioView.setOnRecordingFinishEventListener(v -> {
|
||||
// currentFilePath.setText("Recording done, you can preview it. Hit save after finish");
|
||||
mField.setAudioPath(tempAudioPath);
|
||||
mField.setHasTemporaryMedia(true);
|
||||
});
|
||||
layout.addView(mAudioView, LinearLayout.LayoutParams.FILL_PARENT);
|
||||
}
|
||||
@ -96,6 +88,7 @@ public class BasicAudioFieldController extends FieldControllerBase implements IF
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,8 +20,6 @@
|
||||
package com.ichi2.anki.multimediacard.fields;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
@ -55,16 +53,13 @@ import timber.log.Timber;
|
||||
|
||||
public class BasicImageFieldController extends FieldControllerBase implements IFieldController {
|
||||
|
||||
protected static final int ACTIVITY_SELECT_IMAGE = 1;
|
||||
protected static final int ACTIVITY_TAKE_PICTURE = 2;
|
||||
protected static final int IMAGE_PREVIEW_MAX_WIDTH = 100;
|
||||
private static final int ACTIVITY_SELECT_IMAGE = 1;
|
||||
private static final int ACTIVITY_TAKE_PICTURE = 2;
|
||||
private static final int IMAGE_SAVE_MAX_WIDTH = 1920;
|
||||
|
||||
protected Button mBtnGallery;
|
||||
protected Button mBtnCamera;
|
||||
protected ImageView mImagePreview;
|
||||
private ImageView mImagePreview;
|
||||
|
||||
protected String mTempCameraImagePath;
|
||||
private String mTempCameraImagePath;
|
||||
private DisplayMetrics mMetrics = null;
|
||||
|
||||
|
||||
@ -96,44 +91,37 @@ public class BasicImageFieldController extends FieldControllerBase implements IF
|
||||
mImagePreview.setMaxHeight((int) Math.round(height * 0.4));
|
||||
mImagePreview.setMaxWidth((int) Math.round(width * 0.6));
|
||||
|
||||
mBtnGallery = new Button(mActivity);
|
||||
Button mBtnGallery = new Button(mActivity);
|
||||
mBtnGallery.setText(gtxt(R.string.multimedia_editor_image_field_editing_galery));
|
||||
mBtnGallery.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
mActivity.startActivityForResult(i, ACTIVITY_SELECT_IMAGE);
|
||||
}
|
||||
mBtnGallery.setOnClickListener(v -> {
|
||||
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
mActivity.startActivityForResultWithoutAnimation(i, ACTIVITY_SELECT_IMAGE);
|
||||
});
|
||||
|
||||
mBtnCamera = new Button(mActivity);
|
||||
Button mBtnCamera = new Button(mActivity);
|
||||
mBtnCamera.setText(gtxt(R.string.multimedia_editor_image_field_editing_photo));
|
||||
mBtnCamera.setOnClickListener(new View.OnClickListener() {
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
|
||||
File image;
|
||||
File storageDir;
|
||||
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US).format(new Date());
|
||||
try {
|
||||
storageDir = mActivity.getCacheDir();
|
||||
image = File.createTempFile("img_" + timeStamp, ".jpg", storageDir);
|
||||
mTempCameraImagePath = image.getPath();
|
||||
Uri uriSavedImage = FileProvider.getUriForFile(mActivity,
|
||||
mActivity.getApplicationContext().getPackageName() + ".apkgfileprovider",
|
||||
image);
|
||||
mBtnCamera.setOnClickListener(v -> {
|
||||
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||
File image;
|
||||
File storageDir;
|
||||
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US).format(new Date());
|
||||
try {
|
||||
storageDir = mActivity.getCacheDir();
|
||||
image = File.createTempFile("img_" + timeStamp, ".jpg", storageDir);
|
||||
mTempCameraImagePath = image.getPath();
|
||||
Uri uriSavedImage = FileProvider.getUriForFile(mActivity,
|
||||
mActivity.getApplicationContext().getPackageName() + ".apkgfileprovider",
|
||||
image);
|
||||
|
||||
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
|
||||
if (cameraIntent.resolveActivity(context.getPackageManager()) != null) {
|
||||
mActivity.startActivityForResult(cameraIntent, ACTIVITY_TAKE_PICTURE);
|
||||
}
|
||||
else {
|
||||
Timber.w("Device has a camera, but no app to handle ACTION_IMAGE_CAPTURE Intent");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
|
||||
if (cameraIntent.resolveActivity(context.getPackageManager()) != null) {
|
||||
mActivity.startActivityForResultWithoutAnimation(cameraIntent, ACTIVITY_TAKE_PICTURE);
|
||||
}
|
||||
else {
|
||||
Timber.w("Device has a camera, but no app to handle ACTION_IMAGE_CAPTURE Intent");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
@ -159,7 +147,7 @@ public class BasicImageFieldController extends FieldControllerBase implements IF
|
||||
}
|
||||
|
||||
|
||||
protected DisplayMetrics getDisplayMetrics() {
|
||||
private DisplayMetrics getDisplayMetrics() {
|
||||
if (mMetrics == null) {
|
||||
mMetrics = new DisplayMetrics();
|
||||
mActivity.getWindowManager().getDefaultDisplay().getMetrics(mMetrics);
|
||||
@ -170,9 +158,8 @@ public class BasicImageFieldController extends FieldControllerBase implements IF
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode == Activity.RESULT_CANCELED) {
|
||||
// Do Nothing.
|
||||
} else if (requestCode == ACTIVITY_SELECT_IMAGE) {
|
||||
// ignore RESULT_CANCELED but handle image select and take
|
||||
if (requestCode == ACTIVITY_SELECT_IMAGE) {
|
||||
Uri selectedImage = data.getData();
|
||||
// Timber.d(selectedImage.toString());
|
||||
String[] filePathColumn = { MediaColumns.DATA };
|
||||
@ -195,13 +182,14 @@ public class BasicImageFieldController extends FieldControllerBase implements IF
|
||||
|
||||
@Override
|
||||
public void onFocusLost() {
|
||||
// do nothing
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDone() {
|
||||
//
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
@ -220,7 +208,7 @@ public class BasicImageFieldController extends FieldControllerBase implements IF
|
||||
f.delete();
|
||||
return outPath;
|
||||
} catch (FileNotFoundException e) {
|
||||
Timber.e("Error in BasicImageFieldController.rotateAndCompress() : " + e.getMessage());
|
||||
Timber.e(e, "Error in BasicImageFieldController.rotateAndCompress()");
|
||||
return inPath;
|
||||
} finally {
|
||||
try {
|
||||
@ -234,7 +222,7 @@ public class BasicImageFieldController extends FieldControllerBase implements IF
|
||||
}
|
||||
|
||||
|
||||
protected void setPreviewImage(String imagePath, int maxsize) {
|
||||
private void setPreviewImage(String imagePath, int maxsize) {
|
||||
if (imagePath != null && !imagePath.equals("")) {
|
||||
File f = new File(imagePath);
|
||||
Bitmap b = BitmapUtil.decodeFile(f, maxsize);
|
||||
@ -249,5 +237,4 @@ public class BasicImageFieldController extends FieldControllerBase implements IF
|
||||
ImageView imageView = mImagePreview;
|
||||
BitmapUtil.freeImageView(imageView);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,8 +25,6 @@ import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
@ -57,9 +55,7 @@ public class BasicTextFieldController extends FieldControllerBase implements IFi
|
||||
private static final int REQUEST_CODE_TRANSLATE_GLOSBE = 101;
|
||||
private static final int REQUEST_CODE_PRONOUNCIATION = 102;
|
||||
private static final int REQUEST_CODE_TRANSLATE_COLORDICT = 103;
|
||||
private static final int REQUEST_CODE_IMAGE_SEARCH = 104;
|
||||
|
||||
private TextView mSearchLabel;
|
||||
private EditText mEditText;
|
||||
|
||||
// This is used to copy from another field value to this field
|
||||
@ -82,7 +78,7 @@ public class BasicTextFieldController extends FieldControllerBase implements IFi
|
||||
createCloneButton(layoutTools, p);
|
||||
createClearButton(layoutTools, p);
|
||||
// search label
|
||||
mSearchLabel = new TextView(mActivity);
|
||||
TextView mSearchLabel = new TextView(mActivity);
|
||||
mSearchLabel.setText(R.string.multimedia_editor_text_field_editing_search_label);
|
||||
layout.addView(mSearchLabel);
|
||||
// search buttons
|
||||
@ -105,38 +101,28 @@ public class BasicTextFieldController extends FieldControllerBase implements IFi
|
||||
clearButton.setText(gtxt(R.string.multimedia_editor_text_field_editing_clear));
|
||||
layoutTools.addView(clearButton, p);
|
||||
|
||||
clearButton.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mEditText.setText("");
|
||||
|
||||
}
|
||||
});
|
||||
clearButton.setOnClickListener(v -> mEditText.setText(""));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param layoutTools
|
||||
* @param layoutTools to create the button
|
||||
* @param p Button to load pronunciation from Beolingus
|
||||
*/
|
||||
private void createPronounceButton(LinearLayout layoutTools, LayoutParams p) {
|
||||
Button btnPronounce = new Button(mActivity);
|
||||
btnPronounce.setText(gtxt(R.string.multimedia_editor_text_field_editing_say));
|
||||
btnPronounce.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String source = mEditText.getText().toString();
|
||||
btnPronounce.setOnClickListener(v -> {
|
||||
String source = mEditText.getText().toString();
|
||||
|
||||
if (source.length() == 0) {
|
||||
showToast(gtxt(R.string.multimedia_editor_text_field_editing_no_text));
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(mActivity, LoadPronounciationActivity.class);
|
||||
intent.putExtra(LoadPronounciationActivity.EXTRA_SOURCE, source);
|
||||
mActivity.startActivityForResult(intent, REQUEST_CODE_PRONOUNCIATION);
|
||||
if (source.length() == 0) {
|
||||
showToast(gtxt(R.string.multimedia_editor_text_field_editing_no_text));
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(mActivity, LoadPronounciationActivity.class);
|
||||
intent.putExtra(LoadPronounciationActivity.EXTRA_SOURCE, source);
|
||||
mActivity.startActivityForResultWithoutAnimation(intent, REQUEST_CODE_PRONOUNCIATION);
|
||||
});
|
||||
|
||||
layoutTools.addView(btnPronounce, p);
|
||||
@ -147,49 +133,42 @@ public class BasicTextFieldController extends FieldControllerBase implements IFi
|
||||
private void createTranslateButton(LinearLayout layoutTool, LayoutParams ps) {
|
||||
Button btnTranslate = new Button(mActivity);
|
||||
btnTranslate.setText(gtxt(R.string.multimedia_editor_text_field_editing_translate));
|
||||
btnTranslate.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String source = mEditText.getText().toString();
|
||||
btnTranslate.setOnClickListener(v -> {
|
||||
String source = mEditText.getText().toString();
|
||||
|
||||
// Checks and warnings
|
||||
if (source.length() == 0) {
|
||||
showToast(gtxt(R.string.multimedia_editor_text_field_editing_no_text));
|
||||
return;
|
||||
}
|
||||
|
||||
if (source.contains(" ")) {
|
||||
showToast(gtxt(R.string.multimedia_editor_text_field_editing_many_words));
|
||||
}
|
||||
|
||||
// Pick from two translation sources
|
||||
PickStringDialogFragment fragment = new PickStringDialogFragment();
|
||||
|
||||
final ArrayList<String> translationSources = new ArrayList<>();
|
||||
translationSources.add("Glosbe.com");
|
||||
// Chromebooks do not support dependent apps yet.
|
||||
if (!CompatHelper.isChromebook()) {
|
||||
translationSources.add("ColorDict");
|
||||
}
|
||||
|
||||
fragment.setChoices(translationSources);
|
||||
fragment.setOnclickListener(new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String translationSource = translationSources.get(which);
|
||||
if (translationSource.equals("Glosbe.com")) {
|
||||
startTranslationWithGlosbe();
|
||||
} else if (translationSource.equals("ColorDict")) {
|
||||
startTranslationWithColorDict();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fragment.setTitle(gtxt(R.string.multimedia_editor_trans_pick_translation_source));
|
||||
|
||||
fragment.show(mActivity.getSupportFragmentManager(), "pick.translation.source");
|
||||
// Checks and warnings
|
||||
if (source.length() == 0) {
|
||||
showToast(gtxt(R.string.multimedia_editor_text_field_editing_no_text));
|
||||
return;
|
||||
}
|
||||
|
||||
if (source.contains(" ")) {
|
||||
showToast(gtxt(R.string.multimedia_editor_text_field_editing_many_words));
|
||||
}
|
||||
|
||||
// Pick from two translation sources
|
||||
PickStringDialogFragment fragment = new PickStringDialogFragment();
|
||||
|
||||
final ArrayList<String> translationSources = new ArrayList<>();
|
||||
translationSources.add("Glosbe.com");
|
||||
// Chromebooks do not support dependent apps yet.
|
||||
if (!CompatHelper.isChromebook()) {
|
||||
translationSources.add("ColorDict");
|
||||
}
|
||||
|
||||
fragment.setChoices(translationSources);
|
||||
fragment.setOnclickListener((dialog, which) -> {
|
||||
String translationSource = translationSources.get(which);
|
||||
if ("Glosbe.com".equals(translationSource)) {
|
||||
startTranslationWithGlosbe();
|
||||
} else if ("ColorDict".equals(translationSource)) {
|
||||
startTranslationWithColorDict();
|
||||
}
|
||||
});
|
||||
|
||||
fragment.setTitle(gtxt(R.string.multimedia_editor_trans_pick_translation_source));
|
||||
|
||||
fragment.show(mActivity.getSupportFragmentManager(), "pick.translation.source");
|
||||
});
|
||||
|
||||
layoutTool.addView(btnTranslate, ps);
|
||||
@ -202,7 +181,7 @@ public class BasicTextFieldController extends FieldControllerBase implements IFi
|
||||
/**
|
||||
* @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
|
||||
* @param p layout params
|
||||
*/
|
||||
private void createCloneButton(LinearLayout layoutTools, LayoutParams p) {
|
||||
// Makes sense only for two and more fields
|
||||
@ -253,21 +232,17 @@ public class BasicTextFieldController extends FieldControllerBase implements IFi
|
||||
|
||||
final BasicTextFieldController controller = this;
|
||||
|
||||
btnOtherField.setOnClickListener(new OnClickListener() {
|
||||
btnOtherField.setOnClickListener(v -> {
|
||||
PickStringDialogFragment fragment = new PickStringDialogFragment();
|
||||
|
||||
@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.setChoices(mPossibleClones);
|
||||
fragment.setOnclickListener(controller);
|
||||
fragment.setTitle(gtxt(R.string.multimedia_editor_text_field_editing_clone_source));
|
||||
fragment.show(mActivity.getSupportFragmentManager(), "pick.clone");
|
||||
|
||||
fragment.show(mActivity.getSupportFragmentManager(), "pick.clone");
|
||||
// flow continues in the onClick function
|
||||
|
||||
// flow continues in the onClick function
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
@ -319,16 +294,16 @@ public class BasicTextFieldController extends FieldControllerBase implements IFi
|
||||
|
||||
@Override
|
||||
public void onFocusLost() {
|
||||
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param context
|
||||
* @param intent
|
||||
* @param context context with the PackageManager
|
||||
* @param intent intent for state data
|
||||
* @return Needed to check, if the Color Dict is installed
|
||||
*/
|
||||
public static boolean isIntentAvailable(Context context, Intent intent) {
|
||||
private static boolean isIntentAvailable(Context context, Intent intent) {
|
||||
final PackageManager packageManager = context.getPackageManager();
|
||||
List<?> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
|
||||
return list.size() > 0;
|
||||
@ -361,7 +336,7 @@ public class BasicTextFieldController extends FieldControllerBase implements IFi
|
||||
|
||||
// Only now not all APIs are used, may be later, they will be.
|
||||
@SuppressWarnings("unused")
|
||||
protected void startTranslationWithColorDict() {
|
||||
private void startTranslationWithColorDict() {
|
||||
final String PICK_RESULT_ACTION = "colordict.intent.action.PICK_RESULT";
|
||||
final String SEARCH_ACTION = "colordict.intent.action.SEARCH";
|
||||
final String EXTRA_QUERY = "EXTRA_QUERY";
|
||||
@ -386,16 +361,16 @@ public class BasicTextFieldController extends FieldControllerBase implements IFi
|
||||
showToast(gtxt(R.string.multimedia_editor_trans_install_color_dict));
|
||||
return;
|
||||
}
|
||||
mActivity.startActivityForResult(intent, REQUEST_CODE_TRANSLATE_COLORDICT);
|
||||
mActivity.startActivityForResultWithoutAnimation(intent, REQUEST_CODE_TRANSLATE_COLORDICT);
|
||||
}
|
||||
|
||||
|
||||
protected void startTranslationWithGlosbe() {
|
||||
private void startTranslationWithGlosbe() {
|
||||
String source = mEditText.getText().toString();
|
||||
|
||||
Intent intent = new Intent(mActivity, TranslationActivity.class);
|
||||
intent.putExtra(TranslationActivity.EXTRA_SOURCE, source);
|
||||
mActivity.startActivityForResult(intent, REQUEST_CODE_TRANSLATE_GLOSBE);
|
||||
mActivity.startActivityForResultWithoutAnimation(intent, REQUEST_CODE_TRANSLATE_GLOSBE);
|
||||
}
|
||||
|
||||
|
||||
@ -404,5 +379,4 @@ public class BasicTextFieldController extends FieldControllerBase implements IFi
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ package com.ichi2.anki.multimediacard.fields;
|
||||
* Controls modifications. This is done to not to save anything, if the field has not been modified.
|
||||
*/
|
||||
public class FieldBase {
|
||||
boolean mIsModified = false;
|
||||
private boolean mIsModified = false;
|
||||
|
||||
|
||||
void setThisModified() {
|
||||
|
@ -32,31 +32,12 @@ import java.util.ArrayList;
|
||||
|
||||
public class MultimediaEditableNote implements IMultimediaEditableNote {
|
||||
private static final long serialVersionUID = -6161821367135636659L;
|
||||
boolean mIsModified = false;
|
||||
|
||||
ArrayList<IField> mFields;
|
||||
private boolean mIsModified = false;
|
||||
private ArrayList<IField> mFields;
|
||||
private long mModelId;
|
||||
|
||||
|
||||
public void circularSwap() {
|
||||
if (mFields == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mFields.size() <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<IField> newFields = new ArrayList<>();
|
||||
newFields.add(mFields.get(mFields.size() - 1));
|
||||
newFields.addAll(mFields);
|
||||
newFields.remove(mFields.size());
|
||||
|
||||
mFields = newFields;
|
||||
}
|
||||
|
||||
|
||||
void setThisModified() {
|
||||
private void setThisModified() {
|
||||
mIsModified = true;
|
||||
}
|
||||
|
||||
|
@ -1,38 +0,0 @@
|
||||
/**
|
||||
* @author Zaur
|
||||
*/
|
||||
|
||||
package com.ichi2.anki.multimediacard.impl;
|
||||
|
||||
import com.ichi2.anki.multimediacard.IMultimediaEditableNote;
|
||||
import com.ichi2.anki.multimediacard.fields.ImageField;
|
||||
import com.ichi2.anki.multimediacard.fields.TextField;
|
||||
|
||||
/**
|
||||
* Creates IMultimediaEditableNotes according to various parameters.
|
||||
*/
|
||||
public class NoteFactory {
|
||||
public static IMultimediaEditableNote createNote() {
|
||||
MultimediaEditableNote note = new MultimediaEditableNote();
|
||||
note.setNumFields(4);
|
||||
|
||||
TextField tf = new TextField();
|
||||
tf.setText("world");
|
||||
note.setField(0, tf);
|
||||
|
||||
TextField tf2 = new TextField();
|
||||
tf2.setText("Welt");
|
||||
note.setField(1, tf2);
|
||||
|
||||
TextField tf3 = new TextField();
|
||||
tf3.setText("Übung");
|
||||
note.setField(2, tf3);
|
||||
|
||||
ImageField imageField = new ImageField();
|
||||
imageField.setImagePath("/mnt/sdcard/img/1.jpg");
|
||||
note.setField(3, imageField);
|
||||
|
||||
return note;
|
||||
}
|
||||
|
||||
}
|
@ -21,7 +21,6 @@ package com.ichi2.anki.multimediacard.language;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
@ -32,7 +31,7 @@ import java.util.HashMap;
|
||||
*/
|
||||
public class LanguageListerBase {
|
||||
|
||||
protected HashMap<String, String> mLanguageMap;
|
||||
private HashMap<String, String> mLanguageMap;
|
||||
|
||||
|
||||
public LanguageListerBase() {
|
||||
@ -59,14 +58,8 @@ public class LanguageListerBase {
|
||||
|
||||
|
||||
public ArrayList<String> getLanguages() {
|
||||
ArrayList<String> res = new ArrayList<>();
|
||||
res.addAll(mLanguageMap.keySet());
|
||||
Collections.sort(res, new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String text1, String text2) {
|
||||
return text1.compareToIgnoreCase(text2);
|
||||
}
|
||||
});
|
||||
ArrayList<String> res = new ArrayList<>(mLanguageMap.keySet());
|
||||
Collections.sort(res, String::compareToIgnoreCase);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -19,25 +19,22 @@
|
||||
|
||||
package com.ichi2.anki.multimediacard.language;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* This one listers services in beolingus.
|
||||
* This one lister services in beolingus.
|
||||
* <p>
|
||||
* It is used to load pronunciation.
|
||||
*/
|
||||
public class LanguageListerBeolingus extends LanguageListerBase {
|
||||
|
||||
public LanguageListerBeolingus(Context context) {
|
||||
public LanguageListerBeolingus() {
|
||||
super();
|
||||
|
||||
addLanguage((new Locale("eng")).getDisplayLanguage() , "en-de");
|
||||
addLanguage((new Locale("deu")).getDisplayLanguage(), "deen");
|
||||
addLanguage((new Locale("spa")).getDisplayLanguage(), "es-de");
|
||||
// Seems to have no pronunciation yet
|
||||
// addLanguage(context.getString(R.string.multimedia_editor_languages_portuguese), "pt-de");
|
||||
addLanguage((new Locale("por")).getDisplayLanguage(), "pt-de");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,66 +0,0 @@
|
||||
/****************************************************************************************
|
||||
* Copyright (c) 2013 Bibek Shrestha <bibekshrestha@gmail.com> *
|
||||
* Copyright (c) 2013 Zaur Molotnikov <qutorial@gmail.com> *
|
||||
* Copyright (c) 2013 Nicolas Raoul <nicolas.raoul@gmail.com> *
|
||||
* Copyright (c) 2013 Flavio Lerda <flerda@gmail.com> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify it under *
|
||||
* the terms of the GNU General Public License as published by the Free Software *
|
||||
* Foundation; either version 3 of the License, or (at your option) any later *
|
||||
* version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License along with *
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
|
||||
package com.ichi2.anki.multimediacard.language;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class LanguagesLister {
|
||||
HashMap<String, String> mLanguageMap;
|
||||
|
||||
|
||||
LanguagesLister() {
|
||||
mLanguageMap = new HashMap<>();
|
||||
|
||||
mLanguageMap.put("Mandarin", "cmn");
|
||||
mLanguageMap.put("Spanish", "spa");
|
||||
mLanguageMap.put("English", "eng");
|
||||
mLanguageMap.put("Nepali", "nep");
|
||||
mLanguageMap.put("Russian", "rus");
|
||||
mLanguageMap.put("German", "deu");
|
||||
mLanguageMap.put("Slovak", "slk");
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String getCodeFor(String Language) {
|
||||
if (mLanguageMap.containsKey(Language)) {
|
||||
return mLanguageMap.get(Language);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<String> getLanguages() {
|
||||
ArrayList<String> res = new ArrayList<>();
|
||||
res.addAll(mLanguageMap.keySet());
|
||||
Collections.sort(res, new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String text1, String text2) {
|
||||
return text1.compareToIgnoreCase(text2);
|
||||
}
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
@ -23,8 +23,6 @@ package com.ichi2.anki.multimediacard.language;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* This language lister is used to call glosbe.com translation services.
|
||||
* <p>
|
||||
@ -33,7 +31,10 @@ import android.content.Context;
|
||||
* It can be extended freely here, to support more languages.
|
||||
*/
|
||||
public class LanguagesListerGlosbe extends LanguageListerBase {
|
||||
public LanguagesListerGlosbe(Context context) {
|
||||
|
||||
private static HashMap<String, Locale> locale_map = null;
|
||||
|
||||
public LanguagesListerGlosbe() {
|
||||
final String [] languages ={"eng", "deu", "jpn", "fra", "spa", "pol", "ita", "rus",
|
||||
"ces", "zho", "nld", "por", "swe", "hrv", "hin", "hun", "vie", "ara", "tur"};
|
||||
// Java Locale uses ISO 639-2 rather than 639-3 so we currently only support the subset of
|
||||
@ -45,8 +46,6 @@ public class LanguagesListerGlosbe extends LanguageListerBase {
|
||||
}
|
||||
}
|
||||
|
||||
private static HashMap<String, Locale> locale_map = null;
|
||||
|
||||
/**
|
||||
* Convert from 3 letter ISO 639-2 language code to ISO 639-1
|
||||
* @param req 3 letter language code
|
||||
|
@ -1,53 +0,0 @@
|
||||
/****************************************************************************************
|
||||
* Copyright (c) 2013 Bibek Shrestha <bibekshrestha@gmail.com> *
|
||||
* Copyright (c) 2013 Zaur Molotnikov <qutorial@gmail.com> *
|
||||
* Copyright (c) 2013 Nicolas Raoul <nicolas.raoul@gmail.com> *
|
||||
* Copyright (c) 2013 Flavio Lerda <flerda@gmail.com> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify it under *
|
||||
* the terms of the GNU General Public License as published by the Free Software *
|
||||
* Foundation; either version 3 of the License, or (at your option) any later *
|
||||
* version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License along with *
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
|
||||
package com.ichi2.anki.multimediacard.test;
|
||||
|
||||
import com.ichi2.anki.multimediacard.IMultimediaEditableNote;
|
||||
import com.ichi2.anki.multimediacard.fields.ImageField;
|
||||
import com.ichi2.anki.multimediacard.fields.TextField;
|
||||
import com.ichi2.anki.multimediacard.impl.MultimediaEditableNote;
|
||||
|
||||
/**
|
||||
* Made for tests
|
||||
*/
|
||||
public class MockNoteFactory {
|
||||
public static IMultimediaEditableNote makeNote() {
|
||||
MultimediaEditableNote note = new MultimediaEditableNote();
|
||||
note.setNumFields(4);
|
||||
|
||||
TextField tf = new TextField();
|
||||
tf.setText("world");
|
||||
note.setField(0, tf);
|
||||
|
||||
TextField tf2 = new TextField();
|
||||
tf2.setText("Welt");
|
||||
note.setField(1, tf2);
|
||||
|
||||
TextField tf3 = new TextField();
|
||||
tf3.setText("Übung");
|
||||
note.setField(2, tf3);
|
||||
|
||||
ImageField imageField = new ImageField();
|
||||
imageField.setImagePath("/mnt/sdcard/img/1.jpg");
|
||||
note.setField(3, imageField);
|
||||
|
||||
return note;
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/****************************************************************************************
|
||||
* Copyright (c) 2013 Bibek Shrestha <bibekshrestha@gmail.com> *
|
||||
* Copyright (c) 2013 Zaur Molotnikov <qutorial@gmail.com> *
|
||||
* Copyright (c) 2013 Nicolas Raoul <nicolas.raoul@gmail.com> *
|
||||
* Copyright (c) 2013 Flavio Lerda <flerda@gmail.com> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify it under *
|
||||
* the terms of the GNU General Public License as published by the Free Software *
|
||||
* Foundation; either version 3 of the License, or (at your option) any later *
|
||||
* version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License along with *
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
|
||||
package com.ichi2.anki.multimediacard.test;
|
||||
|
||||
/**
|
||||
* This is a class used for tests actually
|
||||
*/
|
||||
public class MockPronounciationPageFetcher {
|
||||
|
||||
public static String get() {
|
||||
return " <param name=\"BGCOLOR\" value=\"#FFFFFF\" />"
|
||||
+ " <embed src=\"wimpy_button.swf?theFile=/speak-de/4/0/yNuwm9F0njM.mp3&autoplay=yes&loopMe=no\""
|
||||
+ " width=\"30\" height=\"30\" quality=\"high\" bgcolor=\"#FFFFFF\""
|
||||
+ " pluginspage=\"http://www.macromedia.com/go/getflashplayer\""
|
||||
+ " type=\"application/x-shockwave-flash\""
|
||||
+ " /></object>"
|
||||
+ " <strong></strong></td>"
|
||||
+ " <td style=\"vertical-align: middle;\"><strong>Welt</strong></td>"
|
||||
+ " </tr>"
|
||||
+ " <tr class=\"air\"><td> </td><td><div> </div></td>"
|
||||
+ " </tr>"
|
||||
+ " <tr>"
|
||||
+ " <td> </td>"
|
||||
+ " <td><a href=\"/speak-de/4/0/yNuwm9F0njM.mp3\">Listen with your<br />default MP3 player</a></td>"
|
||||
+ " </tr>" + " </tbody>" + " </table>" + " </td>"
|
||||
+ " </tr>" + " <tr>" + " <td> </td>"
|
||||
+ " <td style=\"text-align:center";
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/****************************************************************************************
|
||||
* Copyright (c) 2013 Bibek Shrestha <bibekshrestha@gmail.com> *
|
||||
* Copyright (c) 2013 Zaur Molotnikov <qutorial@gmail.com> *
|
||||
* Copyright (c) 2013 Nicolas Raoul <nicolas.raoul@gmail.com> *
|
||||
* Copyright (c) 2013 Flavio Lerda <flerda@gmail.com> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify it under *
|
||||
* the terms of the GNU General Public License as published by the Free Software *
|
||||
* Foundation; either version 3 of the License, or (at your option) any later *
|
||||
* version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License along with *
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
|
||||
package com.ichi2.anki.multimediacard.test;
|
||||
|
||||
/**
|
||||
* class for tests
|
||||
*/
|
||||
public class MockTranslationFetcher {
|
||||
public static String get() {
|
||||
return
|
||||
|
||||
"<td class=\"r\"><a href=\"/deutsch-englisch/Welt.html\" onclick=\"return m('Welt',this,'l1');\" ondblclick=\"return d(this);\"><b>Welt</b></a> <span title=\"noun, feminine (die)\">{f}</span> <a href=\"/dings.cgi?speak=de/4/0/yNuwm9F0njM;text=Welt\" onclick=\"return s(this)\" onmouseover=\"return u('Welt')\"><img src=\"/pics/s1.png\" width=\"16\" height=\"16\" alt=\"[listen]\" title=\"Welt\" border=\"0\" align=\"top\" /></a></td>"
|
||||
+ " <td class=\"r\"><a href=\"/english-german/world.html\" onclick=\"return m('world',this,'l2');\" ondblclick=\"return d(this);\">world</a> <a href=\"/dings.cgi?speak=en/8/5/emUMgGzviSg;text=world\" onclick=\"return s(this)\" onmouseover=\"return u('world')\"><img src=\"/pics/s1.png\" width=\"16\" height=\"16\" alt=\"[listen]\" title=\"world\" border=\"0\" align=\"top\" /></a></td><td><a href=\"#\" onclick=\"return vi('Welt {f}','world','Welt','de','en',this);\"><img src=\"/pics/v.png\" /></a></td>"
|
||||
+ ""
|
||||
+ " </tr>"
|
||||
+ " </tbody>"
|
||||
+ " <tbody id=\"b1\" class=\"n\">"
|
||||
+ " <tr class=\"s1 c\">"
|
||||
+ " <td align=\"right\"><br /></td>"
|
||||
+ " <td class=\"f\"> <a href=\"/deutsch-englisch/Welten.html\" onclick=\"return m('Welten',this,'l1');\" ondblclick=\"return d(this);\"><b>Welt</b>en</a> <span title=\"noun, plural (die)\">{pl}</span> </td>"
|
||||
+ " <td class=\"f\"> <a href=\"/english-german/worlds.html\" onclick=\"return m('worlds',this,'l2');\" ondblclick=\"return d(this);\">worlds</a> </td><td><a href=\"#\" onclick=\"return vi('Welten {pl}','worlds','Welt','de','en',this);\"><img src=\"/pics/v.png\" /></a></td>"
|
||||
+ "" + " </tr>";
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user