use of com.ichi2.anki.R in project Anki-Android by Ramblurr.
the class DeckPicker method onOptionsItemSelected.
/**
* Handles item selections
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Resources res = getResources();
switch(item.getItemId()) {
case MENU_HELP:
showDialog(DIALOG_SELECT_HELP);
return true;
case MENU_SYNC:
sync();
return true;
case MENU_ADD_NOTE:
addNote();
return true;
case MENU_STATISTICS:
showDialog(DIALOG_SELECT_STATISTICS_TYPE);
return true;
case MENU_CARDBROWSER:
openCardBrowser();
return true;
case MENU_CREATE_DECK:
StyledDialog.Builder builder2 = new StyledDialog.Builder(DeckPicker.this);
builder2.setTitle(res.getString(R.string.new_deck));
mDialogEditText = (EditText) new EditText(DeckPicker.this);
// mDialogEditText.setFilters(new InputFilter[] { mDeckNameFilter });
builder2.setView(mDialogEditText, false, false);
builder2.setPositiveButton(res.getString(R.string.create), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String deckName = mDialogEditText.getText().toString().replaceAll("[\'\"\\n\\r\\[\\]\\(\\)]", "");
// Log.i(AnkiDroidApp.TAG, "Creating deck: " + deckName);
AnkiDroidApp.getCol().getDecks().id(deckName, true);
loadCounts();
}
});
builder2.setNegativeButton(res.getString(R.string.cancel), null);
builder2.create().show();
return true;
case MENU_CREATE_DYNAMIC_DECK:
StyledDialog.Builder builder3 = new StyledDialog.Builder(DeckPicker.this);
builder3.setTitle(res.getString(R.string.new_deck));
mDialogEditText = (EditText) new EditText(DeckPicker.this);
ArrayList<String> names = AnkiDroidApp.getCol().getDecks().allNames();
int n = 1;
String cramDeckName = "Cram 1";
while (names.contains(cramDeckName)) {
n++;
cramDeckName = "Cram " + n;
}
mDialogEditText.setText(cramDeckName);
// mDialogEditText.setFilters(new InputFilter[] { mDeckNameFilter });
builder3.setView(mDialogEditText, false, false);
builder3.setPositiveButton(res.getString(R.string.create), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
long id = AnkiDroidApp.getCol().getDecks().newDyn(mDialogEditText.getText().toString());
openStudyOptions(id, new Bundle());
}
});
builder3.setNegativeButton(res.getString(R.string.cancel), null);
builder3.create().show();
return true;
case MENU_ABOUT:
startActivity(new Intent(DeckPicker.this, Info.class));
if (AnkiDroidApp.SDK_VERSION > 4) {
ActivityTransitionAnimation.slide(DeckPicker.this, ActivityTransitionAnimation.RIGHT);
}
return true;
case MENU_ADD_SHARED_DECK:
if (AnkiDroidApp.getCol() != null) {
SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
String hkey = preferences.getString("hkey", "");
if (hkey.length() == 0) {
showDialog(DIALOG_USER_NOT_LOGGED_IN_ADD_SHARED_DECK);
} else {
addSharedDeck();
}
}
return true;
case MENU_IMPORT:
showDialog(DIALOG_IMPORT_HINT);
return true;
case MENU_PREFERENCES:
startActivityForResult(new Intent(DeckPicker.this, Preferences.class), PREFERENCES_UPDATE);
return true;
case MENU_FEEDBACK:
Intent i = new Intent(DeckPicker.this, Feedback.class);
i.putExtra("request", REPORT_FEEDBACK);
startActivityForResult(i, REPORT_FEEDBACK);
if (AnkiDroidApp.SDK_VERSION > 4) {
ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.RIGHT);
}
return true;
case CHECK_DATABASE:
integrityCheck();
return true;
case StudyOptionsActivity.MENU_ROTATE:
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
return true;
case StudyOptionsActivity.MENU_NIGHT:
SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(this);
if (preferences.getBoolean("invertedColors", false)) {
preferences.edit().putBoolean("invertedColors", false).commit();
item.setIcon(R.drawable.ic_menu_night);
} else {
preferences.edit().putBoolean("invertedColors", true).commit();
item.setIcon(R.drawable.ic_menu_night_checked);
}
return true;
case MENU_REUPGRADE:
restartUpgradeProcess();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
use of com.ichi2.anki.R in project AnkiChinaAndroid by ankichinateam.
the class ModelBrowser method renameModelDialog.
/*
* Displays a confirmation box asking if you want to rename the note type and then renames it if confirmed
*/
private void renameModelDialog() {
mModelNameInput = new EditText(this);
mModelNameInput.setSingleLine(true);
mModelNameInput.setText(mModels.get(mModelListPosition).getString("name"));
mModelNameInput.setSelection(mModelNameInput.getText().length());
new MaterialDialog.Builder(this).title(R.string.rename_model).positiveText(R.string.rename).negativeText(R.string.dialog_cancel).customView(mModelNameInput, true).onPositive((dialog, which) -> {
Model model = mModels.get(mModelListPosition);
String deckName = mModelNameInput.getText().toString().replaceAll("[\"\\n\\r]", "");
getCol().getDecks().id(deckName, false);
if (deckName.length() > 0) {
model.put("name", deckName);
col.getModels().update(model);
mModels.get(mModelListPosition).put("name", deckName);
mModelDisplayList.set(mModelListPosition, new DisplayPair(mModels.get(mModelListPosition).getString("name"), mCardCounts.get(mModelListPosition)));
refreshList();
} else {
showToast(getResources().getString(R.string.toast_empty_name));
}
}).show();
}
use of com.ichi2.anki.R in project AnkiChinaAndroid by ankichinateam.
the class ModelFieldEditor method renameFieldDialog.
/*
* Creates a dialog to rename the currently selected field
* Processing time is constant
*/
private void renameFieldDialog() {
mFieldNameInput = new EditText(this);
mFieldNameInput.setSingleLine(true);
mFieldNameInput.setText(mFieldLabels.get(mCurrentPos));
mFieldNameInput.setSelection(mFieldNameInput.getText().length());
new MaterialDialog.Builder(this).title(R.string.rename_model).positiveText(R.string.rename).customView(mFieldNameInput, true).onPositive((dialog, which) -> {
String fieldLabel = mFieldNameInput.getText().toString().replaceAll("[\\n\\r]", "");
if (fieldLabel.length() == 0) {
UIUtils.showThemedToast(this, getResources().getString(R.string.toast_empty_name), true);
} else if (containsField(fieldLabel)) {
UIUtils.showThemedToast(this, getResources().getString(R.string.toast_duplicate_field), true);
} else {
// Field is valid, now rename
try {
renameField();
} catch (ConfirmModSchemaException e) {
// Handler mod schema confirmation
ConfirmationDialog c = new ConfirmationDialog();
c.setArgs(getResources().getString(R.string.full_sync_confirmation));
Runnable confirm = () -> {
mCol.modSchemaNoCheck();
try {
renameField();
} catch (ConfirmModSchemaException e1) {
// This should never be thrown
}
dismissContextMenu();
};
c.setConfirm(confirm);
c.setCancel(mConfirmDialogCancel);
ModelFieldEditor.this.showDialogFragment(c);
}
}
}).negativeText(R.string.dialog_cancel).show();
}
use of com.ichi2.anki.R in project AnkiChinaAndroid by ankichinateam.
the class ModelFieldEditor method renameField.
/*
* Renames the current field
*/
private void renameField() throws ConfirmModSchemaException {
String fieldLabel = mFieldNameInput.getText().toString().replaceAll("[\\n\\r]", "");
JSONObject field = mNoteFields.getJSONObject(mCurrentPos);
mCol.getModels().renameField(mMod, field, fieldLabel);
mCol.getModels().save();
fullRefreshList();
}
use of com.ichi2.anki.R in project AnkiChinaAndroid by ankichinateam.
the class HttpTest method testLogin.
@Test
public void testLogin() {
String username = "AnkiDroidInstrumentedTestUser";
String password = "AnkiDroidInstrumentedTestInvalidPass";
Connection.Payload invalidPayload = new Connection.Payload(new Object[] { username, password, new HostNum(null) });
TestTaskListener testListener = new TestTaskListener(invalidPayload);
// We have to carefully run things on the main thread here or the threading protections in BaseAsyncTask throw
// The first one is just to run the static initializer, really
Runnable onlineRunnable = () -> {
try {
Class.forName("com.ichi2.async.Connection");
} catch (Exception e) {
Assert.fail("Unable to load Connection class: " + e.getMessage());
}
};
InstrumentationRegistry.getInstrumentation().runOnMainSync(onlineRunnable);
// TODO simulate offline programmatically - currently exercised by manually toggling an emulator offline pre-test
if (!Connection.isOnline()) {
Connection.login(testListener, invalidPayload);
Assert.assertFalse("Successful login despite being offline", testListener.getPayload().success);
Assert.assertTrue("onDisconnected not called despite being offline", testListener.mDisconnectedCalled);
return;
}
Runnable r = () -> {
Connection conn = Connection.login(testListener, invalidPayload);
try {
// This forces us to synchronously wait for the AsyncTask to do it's work
conn.get();
} catch (Exception e) {
Assert.fail("Caught exception while trying to login: " + e.getMessage());
}
};
InstrumentationRegistry.getInstrumentation().runOnMainSync(r);
Assert.assertFalse("Successful login despite invalid credentials", testListener.getPayload().success);
}
Aggregations