use of com.ichi2.themes.StyledDialog.Builder in project Anki-Android by Ramblurr.
the class Info method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(AnkiDroidApp.TAG, "Info - onCreate()");
Themes.applyTheme(this);
super.onCreate(savedInstanceState);
Resources res = getResources();
mType = getIntent().getIntExtra(TYPE_EXTRA, TYPE_ABOUT);
setTitle(getTitleString());
setContentView(R.layout.info);
mWebView = (WebView) findViewById(R.id.info);
mWebView.setBackgroundColor(res.getColor(Themes.getBackgroundColor()));
Themes.setWallpaper((View) mWebView.getParent().getParent().getParent());
TextView termsAndConditionsView = (TextView) findViewById(R.id.info_terms_and_conditions);
termsAndConditionsView.setMovementMethod(LinkMovementMethod.getInstance());
Button continueButton = (Button) findViewById(R.id.info_continue);
continueButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (mType == TYPE_ABOUT) {
Info.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.ichi2.anki")));
return;
}
setResult(RESULT_OK);
switch(mType) {
case TYPE_WELCOME:
AnkiDroidApp.getSharedPrefs(Info.this.getBaseContext()).edit().putLong("lastTimeOpened", System.currentTimeMillis()).commit();
break;
case TYPE_NEW_VERSION:
AnkiDroidApp.getSharedPrefs(Info.this.getBaseContext()).edit().putString("lastVersion", AnkiDroidApp.getPkgVersionName()).commit();
break;
case TYPE_UPGRADE_DECKS:
break;
}
finishWithAnimation();
}
});
StringBuilder sb = new StringBuilder();
switch(mType) {
case TYPE_ABOUT:
String[] content = res.getStringArray(R.array.about_content);
sb.append("<html><body text=\"#000000\" link=\"#E37068\" alink=\"#E37068\" vlink=\"#E37068\">");
sb.append(String.format(content[0], res.getString(R.string.app_name), res.getString(R.string.link_anki))).append("<br/><br/>");
sb.append(String.format(content[1], res.getString(R.string.link_issue_tracker), res.getString(R.string.link_wiki), res.getString(R.string.link_forum))).append("<br/><br/>");
sb.append(String.format(content[2], res.getString(R.string.link_wikipedia_open_source), res.getString(R.string.link_contribution), res.getString(R.string.link_contribution_contributors))).append(" ");
sb.append(String.format(content[3], res.getString(R.string.link_translation), res.getString(R.string.link_donation))).append("<br/><br/>");
sb.append(String.format(content[4], res.getString(R.string.licence_wiki), res.getString(R.string.link_source))).append("<br/><br/>");
sb.append("</body></html>");
mWebView.loadDataWithBaseURL("", sb.toString(), "text/html", "utf-8", null);
((Button) findViewById(R.id.info_continue)).setText(res.getString(R.string.info_rate));
break;
case TYPE_WELCOME:
// title
sb.append("<html><body text=\"#000000\" link=\"#E37068\" alink=\"#E37068\" vlink=\"#E37068\">");
sb.append("<big><b>");
sb.append(res.getString(R.string.studyoptions_welcome_title));
sb.append("</big></b><br><br>");
// message
sb.append(res.getString(R.string.welcome_message).replace("\n", "<br>"));
sb.append("</body></html>");
mWebView.loadDataWithBaseURL("", sb.toString(), "text/html", "utf-8", null);
// add tutorial button
Button tutBut = (Button) findViewById(R.id.info_tutorial);
tutBut.setVisibility(View.VISIBLE);
tutBut.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
setResult(RESULT_OK);
Editor edit = AnkiDroidApp.getSharedPrefs(Info.this.getBaseContext()).edit();
edit.putLong("lastTimeOpened", System.currentTimeMillis());
edit.putBoolean("createTutorial", true);
edit.commit();
finishWithAnimation();
}
});
break;
case TYPE_NEW_VERSION:
sb.append(res.getString(R.string.new_version_message));
sb.append("<ul>");
String[] features = res.getStringArray(R.array.new_version_features);
for (int i = 0; i < features.length; i++) {
sb.append("<li>");
sb.append(features[i]);
sb.append("</li>");
}
sb.append("</ul>");
sb.append("</body></html>");
mWebView.loadDataWithBaseURL("", sb.toString(), "text/html", "utf-8", null);
// reactivating ssl check for every new version
AnkiDroidApp.getSharedPrefs(Info.this.getBaseContext()).edit().putBoolean("sslAcceptAll", false).commit();
break;
case TYPE_SHARED_DECKS:
mLoadingLayer = (RelativeLayout) findViewById(R.id.info_loading_layer);
mLoadingLayer.setVisibility(View.VISIBLE);
try {
mShareDecksTemplate = Utils.convertStreamToString(getAssets().open("shared_decks_template.html"));
} catch (IOException e) {
e.printStackTrace();
}
mWebView.setWebViewClient(new MobileAnkiWebview());
mWebView.loadUrl(res.getString(R.string.shared_decks_url));
mWebView.getSettings().setJavaScriptEnabled(true);
termsAndConditionsView.setVisibility(View.VISIBLE);
continueButton.setText(res.getString(R.string.download_button_return));
break;
case TYPE_UPGRADE_DECKS:
setTitle(R.string.deck_upgrade_title);
sb.append("<html><body>");
// add upgrade button
Button but = (Button) findViewById(R.id.info_tutorial);
but.setVisibility(View.VISIBLE);
// add sync button
Button syncButton = (Button) findViewById(R.id.info_sync);
syncButton.setVisibility(View.VISIBLE);
mUpgradeStage = getIntent().getIntExtra(TYPE_UPGRADE_STAGE, -1);
boolean reupgrading = false;
switch(mUpgradeStage) {
case UPGRADE_SCREEN_BASIC1:
sb.append(getString(R.string.deck_upgrade_major_warning));
but.setText(R.string.later);
but.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Themes.showThemedToast(Info.this, getString(R.string.deck_upgrade_start_again_to_upgrade_toast), false);
setResult(RESULT_CANCELED);
finish();
}
});
syncButton.setText(R.string.more_options);
syncButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent result = new Intent();
result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_MORE_OPTIONS);
setResult(RESULT_OK, result);
finishWithAnimation();
}
});
continueButton.setText(R.string.now);
continueButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent result = new Intent();
result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC2);
setResult(RESULT_OK, result);
finishWithAnimation();
}
});
break;
case UPGRADE_SCREEN_BASIC2:
sb.append(getString(R.string.deck_upgrade_recommended_method));
but.setText(R.string.back);
but.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent result = new Intent();
result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC1);
result.putExtra(TYPE_ANIMATION_RIGHT, true);
setResult(RESULT_OK, result);
finishWithAnimation(false);
}
});
syncButton.setEnabled(false);
syncButton.setText("N/A");
syncButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent result = new Intent();
result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_WEB_UPGRADE);
setResult(RESULT_OK, result);
finishWithAnimation();
}
});
continueButton.setText(getString(R.string.pc));
continueButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent result = new Intent();
result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_PC_UPGRADE);
setResult(RESULT_OK, result);
finishWithAnimation();
}
});
break;
case UPGRADE_SCREEN_MORE_OPTIONS:
// If re-upgrading a collection exists already, so don't offer to make a new one
if (new File(AnkiDroidApp.getCollectionPath()).exists()) {
setTitle(getString(R.string.exit_wizard));
reupgrading = true;
sb.append(getString(R.string.deck_upgrade_more_options_exit));
} else {
sb.append(getString(R.string.deck_upgrade_more_options_new_collection));
}
sb.append(getString(R.string.deck_upgrade_more_options_downgrade));
but.setText(R.string.upgrade_decks_button);
but.setText(R.string.back);
but.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent result = new Intent();
result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC1);
result.putExtra(TYPE_ANIMATION_RIGHT, true);
setResult(RESULT_OK, result);
finishWithAnimation(false);
}
});
if (reupgrading) {
syncButton.setText(getString(R.string.upgrade_deck_dont_upgrade));
syncButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent result = new Intent();
result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_CONTINUE);
setResult(RESULT_OK, result);
finishWithAnimation();
}
});
} else {
syncButton.setText(R.string.deck_upgrade_create_new_collection);
syncButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
StyledDialog.Builder builder = new StyledDialog.Builder(Info.this);
builder.setTitle(R.string.deck_upgrade_create_new_collection_title);
builder.setIcon(R.drawable.ic_dialog_alert);
builder.setMessage(R.string.deck_upgrade_not_import_warning);
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent result = new Intent();
result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_CONTINUE);
setResult(RESULT_OK, result);
finishWithAnimation();
}
});
builder.setNegativeButton(R.string.no, null);
builder.show();
}
});
}
continueButton.setVisibility(View.GONE);
break;
case UPGRADE_SCREEN_WEB_UPGRADE:
sb.append(getString(R.string.deck_upgrade_via_web));
but.setText(R.string.back);
but.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent result = new Intent();
result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC2);
result.putExtra(TYPE_ANIMATION_RIGHT, true);
setResult(RESULT_OK, result);
finishWithAnimation(false);
}
});
syncButton.setVisibility(View.GONE);
continueButton.setText(R.string.yes);
continueButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
lockScreenOrientation();
Connection.upgradeDecks(mWebUpgradeListener, new Connection.Payload(new Object[] { AnkiDroidApp.getCurrentAnkiDroidDirectory() }));
}
});
break;
case UPGRADE_SCREEN_PC_UPGRADE:
sb.append(getString(R.string.deck_upgrade_via_anki_desktop));
but.setText(R.string.back);
but.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent result = new Intent();
result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC2);
result.putExtra(TYPE_ANIMATION_RIGHT, true);
setResult(RESULT_OK, result);
finishWithAnimation(false);
}
});
syncButton.setText(R.string.usb);
syncButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent result = new Intent();
result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_MANUAL_UPGRADE);
setResult(RESULT_OK, result);
finishWithAnimation();
}
});
continueButton.setEnabled(false);
continueButton.setText("N/A");
continueButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent result = new Intent();
result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_AUTO_UPGRADE);
setResult(RESULT_OK, result);
finishWithAnimation();
}
});
break;
case UPGRADE_SCREEN_MANUAL_UPGRADE:
sb.append(getString(R.string.deck_upgrade_manual));
but.setText(R.string.back);
but.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent result = new Intent();
result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC2);
result.putExtra(TYPE_ANIMATION_RIGHT, true);
setResult(RESULT_OK, result);
finishWithAnimation(false);
}
});
syncButton.setText(R.string._import);
syncButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
File apkgFile = new File(AnkiDroidApp.getCurrentAnkiDroidDirectory(), DeckPicker.IMPORT_REPLACE_COLLECTION_NAME);
List<File> importables = Utils.getImportableDecks();
if (importables == null || !importables.contains(apkgFile)) {
Themes.showThemedToast(Info.this, getResources().getString(R.string.upgrade_import_no_file_found, DeckPicker.IMPORT_REPLACE_COLLECTION_NAME), false);
} else {
lockScreenOrientation();
DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT_REPLACE, mUpgradeImportListener, new DeckTask.TaskData(AnkiDroidApp.getCol(), apkgFile.getAbsolutePath()));
}
}
});
continueButton.setVisibility(View.GONE);
break;
case UPGRADE_SCREEN_AUTO_UPGRADE:
sb.append(getString(R.string.deck_upgrade_auto_upgrade));
but.setText(R.string.back);
but.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent result = new Intent();
result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_PC_UPGRADE);
result.putExtra(TYPE_ANIMATION_RIGHT, true);
setResult(RESULT_OK, result);
finishWithAnimation(false);
}
});
syncButton.setText(getString(R.string.upgrade_deck_sync_from_ankiweb));
syncButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
StyledDialog.Builder builder = new StyledDialog.Builder(Info.this);
builder.setTitle(R.string.upgrade_deck_sync_from_ankiweb);
builder.setIcon(R.drawable.ic_dialog_alert);
builder.setMessage(getString(R.string.upgrade_deck_have_you_synced));
builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
lockScreenOrientation();
downloadCollection();
}
});
builder.setNegativeButton(R.string.back, null);
builder.show();
}
});
continueButton.setVisibility(View.GONE);
break;
}
// File[] fileList = (new File(AnkiDroidApp.getCurrentAnkiDroidDirectory())).listFiles(new OldAnkiDeckFilter());
// StringBuilder fsb = new StringBuilder();
// fsb.append("<ul>");
// for (File f : fileList) {
// fsb.append("<li>").append(f.getName().replace(".anki", "")).append("</li>");
// }
// fsb.append("</ul>");
// sb.append(res.getString(R.string.upgrade_decks_message, fsb.toString()));
// sb.append("<ul><li>");
// sb.append(res.getString(R.string.upgrade_decks_message_pos1,
// AnkiDroidApp.getCurrentAnkiDroidDirectory()));
// sb.append("</li><li>");
// sb.append(res.getString(R.string.upgrade_decks_message_pos2, res.getString(R.string.link_anki)));
// sb.append("</li><li>");
// sb.append(res.getString(R.string.upgrade_decks_message_pos3));
// sb.append("</li></ul>");
// sb.append(res.getString(R.string.upgrade_decks_message_finish));
sb.append("</body></html>");
mWebView.loadDataWithBaseURL("", sb.toString(), "text/html", "utf-8", null);
StyledDialog.Builder builder2 = new StyledDialog.Builder(this);
builder2.setTitle(res.getString(R.string.connection_error_title));
builder2.setIcon(R.drawable.ic_dialog_alert);
builder2.setMessage(res.getString(R.string.connection_needed));
builder2.setPositiveButton(res.getString(R.string.ok), null);
mNoConnectionAlert = builder2.create();
break;
default:
finish();
break;
}
}
use of com.ichi2.themes.StyledDialog.Builder in project Anki-Android by Ramblurr.
the class CustomFontsReviewerExt method getCustomFontsStyle.
/**
* Returns the CSS used to handle custom fonts.
* <p>
* Custom fonts live in fonts directory in the directory used to store decks.
* <p>
* Each font is mapped to the font family by the same name as the name of the font without the extension.
*/
private static String getCustomFontsStyle(Map<String, AnkiFont> customFontsMap) {
StringBuilder builder = new StringBuilder();
for (AnkiFont font : customFontsMap.values()) {
builder.append(font.getDeclaration());
builder.append('\n');
}
return builder.toString();
}
use of com.ichi2.themes.StyledDialog.Builder in project Anki-Android by Ramblurr.
the class MultimediaCardEditorActivity method showModelSelectDialog.
private Dialog showModelSelectDialog() {
StyledDialog dialog = null;
StyledDialog.Builder builder = new StyledDialog.Builder(this);
ArrayList<CharSequence> dialogItems = new ArrayList<CharSequence>();
// Use this array to know which ID is associated with each
// Item(name)
final ArrayList<Long> dialogIds = new ArrayList<Long>();
ArrayList<JSONObject> models = mCol.getModels().all();
Collections.sort(models, new JSONNameComparator());
builder.setTitle(R.string.note_type);
for (JSONObject m : models) {
try {
dialogItems.add(m.getString("name"));
dialogIds.add(m.getLong("id"));
} catch (JSONException e) {
Log.e("Multimedia Editor", e.getMessage());
}
}
// Convert to Array
String[] items2 = new String[dialogItems.size()];
dialogItems.toArray(items2);
builder.setItems(items2, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
long oldModelId;
try {
oldModelId = mCol.getModels().current().getLong("id");
} catch (JSONException e) {
Log.e("Multimedia Editor", e.getMessage());
return;
}
long newId = dialogIds.get(item);
if (oldModelId != newId) {
changeCurrentModel(newId);
createEditorUI(mNote);
}
}
});
dialog = builder.create();
return dialog;
}
use of com.ichi2.themes.StyledDialog.Builder in project Anki-Android by Ramblurr.
the class ReadText method textToSpeech.
public static void textToSpeech(String text, long did, int ord, int qa) {
mTextToSpeak = text;
mQuestionAnswer = qa;
mDid = did;
mOrd = ord;
String language = getLanguage(mDid, mOrd, mQuestionAnswer);
Locale loc = new Locale(language);
if (language.equals(NO_TTS)) {
return;
}
if (mTts != null) {
if (mTts.isLanguageAvailable(loc) != TextToSpeech.LANG_NOT_SUPPORTED) {
speak(mTextToSpeak, language);
return;
}
}
// Otherwise ask
Resources res = mReviewer.getResources();
StyledDialog.Builder builder = new StyledDialog.Builder(mReviewer);
if (availableTtsLocales.size() == 0) {
builder.setTitle(res.getString(R.string.no_tts_available_title));
builder.setMessage(res.getString(R.string.no_tts_available_message));
builder.setIcon(R.drawable.ic_dialog_alert);
builder.setPositiveButton(res.getString(R.string.ok), null);
} else {
ArrayList<CharSequence> dialogItems = new ArrayList<CharSequence>();
final ArrayList<String> dialogIds = new ArrayList<String>();
builder.setTitle(R.string.select_locale_title);
// Add option: "no tts"
dialogItems.add(res.getString(R.string.tts_no_tts));
dialogIds.add(NO_TTS);
for (int i = 0; i < availableTtsLocales.size(); i++) {
dialogItems.add(availableTtsLocales.get(i)[1]);
dialogIds.add(availableTtsLocales.get(i)[0]);
}
String[] items = new String[dialogItems.size()];
dialogItems.toArray(items);
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
MetaDB.storeLanguage(mReviewer, mDid, mOrd, mQuestionAnswer, dialogIds.get(which));
speak(mTextToSpeak, dialogIds.get(which));
}
});
}
builder.create().show();
}
Aggregations