use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START in project Anki-Android by ankidroid.
the class AnkiDroidApp method onCreate.
/**
* On application creation.
*/
@Override
public void onCreate() {
super.onCreate();
if (sInstance != null) {
Timber.i("onCreate() called multiple times");
// 5887 - fix crash.
if (sInstance.getResources() == null) {
Timber.w("Skipping re-initialisation - no resources. Maybe uninstalling app?");
return;
}
}
sInstance = this;
// Get preferences
SharedPreferences preferences = getSharedPrefs(this);
// Setup logging and crash reporting
mAcraCoreConfigBuilder = new CoreConfigurationBuilder(this);
if (BuildConfig.DEBUG) {
// Enable verbose error logging and do method tracing to put the Class name as log tag
Timber.plant(new DebugTree());
setDebugACRAConfig(preferences);
List<ReferenceMatcher> referenceMatchers = new ArrayList<>();
// Add known memory leaks to 'referenceMatchers'
matchKnownMemoryLeaks(referenceMatchers);
// AppWatcher manual install if not already installed
if (!AppWatcher.INSTANCE.isInstalled()) {
AppWatcher.INSTANCE.manualInstall(this);
}
// Show 'Leaks' app launcher. It has been removed by default via constants.xml.
LeakCanary.INSTANCE.showLeakDisplayActivityLauncherIcon(true);
} else {
Timber.plant(new ProductionCrashReportingTree());
setProductionACRAConfig(preferences);
disableLeakCanary();
}
Timber.tag(TAG);
Timber.d("Startup - Application Start");
// Analytics falls back to a sensible default if this is not set.
if (ACRA.isACRASenderServiceProcess() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
try {
WebViewDebugging.setDataDirectorySuffix("acra");
} catch (Exception e) {
Timber.w(e, "Failed to set WebView data directory");
}
}
// analytics after ACRA, they both install UncaughtExceptionHandlers but Analytics chains while ACRA does not
UsageAnalytics.initialize(this);
if (BuildConfig.DEBUG) {
UsageAnalytics.setDryRun(true);
}
// Stop after analytics and logging are initialised.
if (ACRA.isACRASenderServiceProcess()) {
Timber.d("Skipping AnkiDroidApp.onCreate from ACRA sender process");
return;
}
if (AdaptionUtil.isUserATestClient()) {
UIUtils.showThemedToast(this.getApplicationContext(), getString(R.string.user_is_a_robot), false);
}
// make default HTML / JS debugging true for debug build and disable for unit/android tests
if (BuildConfig.DEBUG && !AdaptionUtil.isRunningAsUnitTest()) {
preferences.edit().putBoolean("html_javascript_debugging", true).apply();
}
CardBrowserContextMenu.ensureConsistentStateWithSharedPreferences(this);
AnkiCardContextMenu.ensureConsistentStateWithSharedPreferences(this);
NotificationChannels.setup(getApplicationContext());
// Configure WebView to allow file scheme pages to access cookies.
if (!acceptFileSchemeCookies()) {
return;
}
// Forget the last deck that was used in the CardBrowser
CardBrowser.clearLastDeckId();
// Create the AnkiDroid directory if missing. Send exception report if inaccessible.
if (Permissions.hasStorageAccessPermission(this)) {
try {
String dir = CollectionHelper.getCurrentAnkiDroidDirectory(this);
CollectionHelper.initializeAnkiDroidDirectory(dir);
} catch (StorageAccessException e) {
Timber.e(e, "Could not initialize AnkiDroid directory");
String defaultDir = CollectionHelper.getDefaultAnkiDroidDirectory(this);
if (isSdCardMounted() && CollectionHelper.getCurrentAnkiDroidDirectory(this).equals(defaultDir)) {
// Don't send report if the user is using a custom directory as SD cards trip up here a lot
sendExceptionReport(e, "AnkiDroidApp.onCreate");
}
}
}
Timber.i("AnkiDroidApp: Starting Services");
new BootService().onReceive(this, new Intent(this, BootService.class));
// Register BroadcastReceiver NotificationService
NotificationService ns = new NotificationService();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.registerReceiver(ns, new IntentFilter(NotificationService.INTENT_ACTION));
}
use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START in project Anki-Android by ankidroid.
the class DeckPicker method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Resources res = getResources();
if (getDrawerToggle().onOptionsItemSelected(item)) {
return true;
}
int itemId = item.getItemId();
if (itemId == R.id.action_undo) {
Timber.i("DeckPicker:: Undo button pressed");
undo();
return true;
} else if (itemId == R.id.action_sync) {
Timber.i("DeckPicker:: Sync button pressed");
sync();
return true;
} else if (itemId == R.id.action_import) {
Timber.i("DeckPicker:: Import button pressed");
showDialogFragment(ImportFileSelectionFragment.createInstance(this));
return true;
} else if (itemId == R.id.action_new_filtered_deck) {
CreateDeckDialog createFilteredDeckDialog = new CreateDeckDialog(DeckPicker.this, R.string.new_deck, CreateDeckDialog.DeckDialogType.FILTERED_DECK, null);
createFilteredDeckDialog.setOnNewDeckCreated((id) -> {
// a filtered deck was created
openStudyOptions(true);
});
createFilteredDeckDialog.showFilteredDeckDialog();
return true;
} else if (itemId == R.id.action_check_database) {
Timber.i("DeckPicker:: Check database button pressed");
showDatabaseErrorDialog(DatabaseErrorDialog.DIALOG_CONFIRM_DATABASE_CHECK);
return true;
} else if (itemId == R.id.action_check_media) {
Timber.i("DeckPicker:: Check media button pressed");
showMediaCheckDialog(MediaCheckDialog.DIALOG_CONFIRM_MEDIA_CHECK);
return true;
} else if (itemId == R.id.action_empty_cards) {
Timber.i("DeckPicker:: Empty cards button pressed");
handleEmptyCards();
return true;
} else if (itemId == R.id.action_model_browser_open) {
Timber.i("DeckPicker:: Model browser button pressed");
Intent noteTypeBrowser = new Intent(this, ModelBrowser.class);
startActivityForResultWithAnimation(noteTypeBrowser, 0, START);
return true;
} else if (itemId == R.id.action_restore_backup) {
Timber.i("DeckPicker:: Restore from backup button pressed");
showDatabaseErrorDialog(DatabaseErrorDialog.DIALOG_CONFIRM_RESTORE_BACKUP);
return true;
} else if (itemId == R.id.action_export) {
Timber.i("DeckPicker:: Export collection button pressed");
String msg = getResources().getString(R.string.confirm_apkg_export);
mExportingDelegate.showExportDialog(msg);
return true;
}
return super.onOptionsItemSelected(item);
}
use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START in project Anki-Android by ankidroid.
the class CardTemplatePreviewerTest method testPreviewUnsavedTemplate_Basic.
@Test
public void testPreviewUnsavedTemplate_Basic() {
String modelName = "Basic";
Model collectionBasicModelOriginal = getCurrentDatabaseModelCopy(modelName);
List<String> fields = collectionBasicModelOriginal.getFieldsNames();
JSONObject template = collectionBasicModelOriginal.getJSONArray("tmpls").getJSONObject(0);
template.put("qfmt", template.getString("qfmt") + "PREVIEWER_TEST");
String tempModelPath = TemporaryModel.saveTempModel(getTargetContext(), collectionBasicModelOriginal);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra(TemporaryModel.INTENT_MODEL_FILENAME, tempModelPath);
intent.putExtra("index", 0);
ActivityController<TestCardTemplatePreviewer> previewerController = Robolectric.buildActivity(TestCardTemplatePreviewer.class, intent).create().start().resume().visible();
saveControllerForCleanup((previewerController));
TestCardTemplatePreviewer testCardTemplatePreviewer = previewerController.get();
String[] arr = testCardTemplatePreviewer.getDummyCard(collectionBasicModelOriginal, 0).note().getFields();
assertThat(arr[0], is("(" + fields.get(0) + ")"));
assertThat(arr[1], is("(" + fields.get(1) + ")"));
}
use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START in project Anki-Android by ankidroid.
the class NoteEditor method setMMButtonListener.
private void setMMButtonListener(ImageButton mediaButton, final int index) {
mediaButton.setOnClickListener(v -> {
Timber.i("NoteEditor:: Multimedia button pressed for field %d", index);
if (mEditorNote.items()[index][1].length() > 0) {
final Collection col = CollectionHelper.getInstance().getCol(NoteEditor.this);
// If the field already exists then we start the field editor, which figures out the type
// automatically
IMultimediaEditableNote note = getCurrentMultimediaEditableNote(col);
startMultimediaFieldEditor(index, note);
} else {
// Otherwise we make a popup menu allowing the user to choose between audio/image/text field
// TODO: Update the icons for dark material theme, then can set 3rd argument to true
PopupMenuWithIcons popup = new PopupMenuWithIcons(NoteEditor.this, v, true);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.popupmenu_multimedia_options, popup.getMenu());
popup.setOnMenuItemClickListener(item -> {
int itemId = item.getItemId();
if (itemId == R.id.menu_multimedia_audio) {
Timber.i("NoteEditor:: Record audio button pressed");
startMultimediaFieldEditorForField(index, new AudioRecordingField());
return true;
} else if (itemId == R.id.menu_multimedia_audio_clip || itemId == R.id.menu_multimedia_video_clip) {
Timber.i("NoteEditor:: Add audio clip button pressed");
startMultimediaFieldEditorForField(index, new MediaClipField());
return true;
} else if (itemId == R.id.menu_multimedia_photo) {
Timber.i("NoteEditor:: Add image button pressed");
startMultimediaFieldEditorForField(index, new ImageField());
return true;
} else if (itemId == R.id.menu_multimedia_text) {
Timber.i("NoteEditor:: Advanced editor button pressed");
startAdvancedTextEditor(index);
return true;
} else if (itemId == R.id.menu_multimedia_clear_field) {
Timber.i("NoteEditor:: Clear field button pressed");
clearField(index);
}
return false;
});
if (AdaptionUtil.isRestrictedLearningDevice()) {
popup.getMenu().findItem(R.id.menu_multimedia_photo).setVisible(false);
popup.getMenu().findItem(R.id.menu_multimedia_text).setVisible(false);
}
popup.show();
}
});
}
use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START in project Anki-Android by ankidroid.
the class Media method mediaChangesZip.
/*
* Media syncing: zips
* ***********************************************************
*/
/**
* Unlike python, our temp zip file will be on disk instead of in memory. This avoids storing
* potentially large files in memory which is not feasible with Android's limited heap space.
* <p>
* Notes:
* <p>
* - The maximum size of the changes zip is decided by the constant SYNC_ZIP_SIZE. If a media file exceeds this
* limit, only that file (in full) will be zipped to be sent to the server.
* <p>
* - This method will be repeatedly called from MediaSyncer until there are no more files (marked "dirty" in the DB)
* to send.
* <p>
* - Since AnkiDroid avoids scanning the media directory on every sync, it is possible for a file to be marked as a
* new addition but actually have been deleted (e.g., with a file manager). In this case we skip over the file
* and mark it as removed in the database. (This behaviour differs from the desktop client).
* <p>
*/
public Pair<File, List<String>> mediaChangesZip() {
File f = new File(mCol.getPath().replaceFirst("collection\\.anki2$", "tmpSyncToServer.zip"));
List<String> fnames = new ArrayList<>();
try (ZipOutputStream z = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(f)));
Cursor cur = mDb.query("select fname, csum from media where dirty=1 limit " + Consts.SYNC_MAX_FILES)) {
z.setMethod(ZipOutputStream.DEFLATED);
// meta is a list of (fname, zipname), where zipname of null is a deleted file
// NOTE: In python, meta is a list of tuples that then gets serialized into json and added
// to the zip as a string. In our version, we use JSON objects from the start to avoid the
// serialization step. Instead of a list of tuples, we use JSONArrays of JSONArrays.
JSONArray meta = new JSONArray();
int sz = 0;
byte[] buffer = new byte[2048];
for (int c = 0; cur.moveToNext(); c++) {
String fname = cur.getString(0);
String csum = cur.getString(1);
fnames.add(fname);
String normname = Utils.nfcNormalized(fname);
if (!TextUtils.isEmpty(csum)) {
try {
mCol.log("+media zip " + fname);
File file = new File(dir(), fname);
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file), 2048);
z.putNextEntry(new ZipEntry(Integer.toString(c)));
int count = 0;
while ((count = bis.read(buffer, 0, 2048)) != -1) {
z.write(buffer, 0, count);
}
z.closeEntry();
bis.close();
meta.put(new JSONArray().put(normname).put(Integer.toString(c)));
sz += file.length();
} catch (FileNotFoundException e) {
Timber.w(e);
// A file has been marked as added but no longer exists in the media directory.
// Skip over it and mark it as removed in the db.
removeFile(fname);
}
} else {
mCol.log("-media zip " + fname);
meta.put(new JSONArray().put(normname).put(""));
}
if (sz >= Consts.SYNC_MAX_BYTES) {
break;
}
}
z.putNextEntry(new ZipEntry("_meta"));
z.write(Utils.jsonToString(meta).getBytes());
z.closeEntry();
// Don't leave lingering temp files if the VM terminates.
f.deleteOnExit();
return new Pair<>(f, fnames);
} catch (IOException e) {
Timber.e(e, "Failed to create media changes zip: ");
throw new RuntimeException(e);
}
}
Aggregations