use of com.ichi2.anki.CardBrowser.Column.CREATED in project Anki-Android by ankidroid.
the class DeckOptionsTest method changeHardFactor.
@Test
public void changeHardFactor() {
Collection col = getCol();
// Verify that for newly created deck hardFactor is default.
double hardFactor = col.get_config("hardFactor", 1.2);
Assert.assertEquals(1.2, hardFactor, 0.01);
// Modify hard factor.
col.set_config("hardFactor", 1.0);
// Verify that hardFactor value has changed.
hardFactor = col.get_config("hardFactor", 1.2);
Assert.assertEquals(1.0, hardFactor, 0.01);
}
use of com.ichi2.anki.CardBrowser.Column.CREATED in project Anki-Android by ankidroid.
the class CardContentProvider method insertMediaFile.
private Uri insertMediaFile(ContentValues values, Collection col) {
// Insert media file using libanki.Media.addFile and return Uri for the inserted file.
Uri fileUri = Uri.parse(values.getAsString(FlashCardsContract.AnkiMedia.FILE_URI));
String preferredName = values.getAsString(FlashCardsContract.AnkiMedia.PREFERRED_NAME);
try {
ContentResolver cR = mContext.getContentResolver();
Media media = col.getMedia();
// idea, open input stream and save to cache directory, then
// pass this (hopefully temporary) file to the media.addFile function.
// return eg "jpeg"
String fileMimeType = MimeTypeMap.getSingleton().getExtensionFromMimeType(cR.getType(fileUri));
// should we be enforcing strict mimetypes? which types?
File tempFile;
File externalCacheDir = mContext.getExternalCacheDir();
if (externalCacheDir == null) {
Timber.e("createUI() unable to get external cache directory");
return null;
}
File tempMediaDir = new File(externalCacheDir.getAbsolutePath() + "/temp-media");
if (!tempMediaDir.exists() && !tempMediaDir.mkdir()) {
Timber.e("temp-media dir did not exist and could not be created");
return null;
}
try {
tempFile = File.createTempFile(// the beginning of the filename.
preferredName + "_", // this is the extension, if null, '.tmp' is used, need to get the extension from MIME type?
"." + fileMimeType, tempMediaDir);
tempFile.deleteOnExit();
} catch (Exception e) {
Timber.w(e, "Could not create temporary media file. ");
return null;
}
FileUtil.internalizeUri(fileUri, tempFile, cR);
String fname = media.addFile(tempFile);
Timber.d("insert -> MEDIA: fname = %s", fname);
File f = new File(fname);
Timber.d("insert -> MEDIA: f = %s", f);
Uri uriFromF = Uri.fromFile(f);
Timber.d("insert -> MEDIA: uriFromF = %s", uriFromF);
return Uri.fromFile(new File(fname));
} catch (IOException | EmptyMediaException e) {
Timber.w(e, "insert failed from %s", fileUri);
return null;
}
}
use of com.ichi2.anki.CardBrowser.Column.CREATED in project Anki-Android by ankidroid.
the class BasicImageFieldController method createUI.
@Override
public void createUI(Context context, LinearLayout layout) {
Timber.d("createUI()");
mViewModel = mViewModel.replaceNullValues(mField, mActivity);
mImagePreview = new ImageView(mActivity);
File externalCacheDirRoot = context.getExternalCacheDir();
if (externalCacheDirRoot == null) {
Timber.e("createUI() unable to get external cache directory");
showSomethingWentWrong();
return;
}
File externalCacheDir = new File(externalCacheDirRoot.getAbsolutePath() + "/temp-photos");
if (!externalCacheDir.exists() && !externalCacheDir.mkdir()) {
Timber.e("createUI() externalCacheDir did not exist and could not be created");
showSomethingWentWrong();
return;
}
mAnkiCacheDirectory = externalCacheDir.getAbsolutePath();
LinearLayout.LayoutParams p = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
drawUIComponents(context);
mCropButton = new Button(mActivity);
mCropButton.setText(gtxt(R.string.crop_button));
mCropButton.setOnClickListener(v -> mViewModel = requestCrop(mViewModel));
mCropButton.setVisibility(View.INVISIBLE);
Button btnGallery = new Button(mActivity);
btnGallery.setText(gtxt(R.string.multimedia_editor_image_field_editing_galery));
btnGallery.setOnClickListener(v -> {
Intent i = new Intent(Intent.ACTION_PICK);
i.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
mActivity.startActivityForResultWithoutAnimation(i, ACTIVITY_SELECT_IMAGE);
});
Button btnDraw = new Button(mActivity);
btnDraw.setText(gtxt(R.string.drawing));
btnDraw.setOnClickListener(v -> {
mActivity.startActivityForResultWithoutAnimation(new Intent(mActivity, DrawingActivity.class), ACTIVITY_DRAWING);
});
Button btnCamera = new Button(mActivity);
btnCamera.setText(gtxt(R.string.multimedia_editor_image_field_editing_photo));
btnCamera.setOnClickListener(v -> mViewModel = captureImage(context));
if (!canUseCamera(context)) {
btnCamera.setVisibility(View.INVISIBLE);
}
setPreviewImage(mViewModel.mImagePath, getMaxImageSize());
layout.addView(mImagePreview, ViewGroup.LayoutParams.MATCH_PARENT, p);
layout.addView(mImageFileSize, ViewGroup.LayoutParams.MATCH_PARENT);
layout.addView(mImageFileSizeWarning, ViewGroup.LayoutParams.MATCH_PARENT);
layout.addView(btnGallery, ViewGroup.LayoutParams.MATCH_PARENT);
// drew image appear far larger in preview in devices API < 24 #9439
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
layout.addView(btnDraw, ViewGroup.LayoutParams.MATCH_PARENT);
}
if (com.ichi2.utils.CheckCameraPermission.manifestContainsPermission(context)) {
layout.addView(btnCamera, ViewGroup.LayoutParams.MATCH_PARENT);
}
layout.addView(mCropButton, ViewGroup.LayoutParams.MATCH_PARENT);
}
use of com.ichi2.anki.CardBrowser.Column.CREATED in project Anki-Android by ankidroid.
the class DeckPicker method showStartupScreensAndDialogs.
private void showStartupScreensAndDialogs(SharedPreferences preferences, int skip) {
// For Android 8/8.1 we want to use software rendering by default or the Reviewer UI is broken #7369
if (CompatHelper.getSdkVersion() == Build.VERSION_CODES.O || CompatHelper.getSdkVersion() == Build.VERSION_CODES.O_MR1) {
if (!preferences.contains("softwareRender")) {
Timber.i("Android 8/8.1 detected with no render preference. Turning on software render.");
preferences.edit().putBoolean("softwareRender", true).apply();
} else {
Timber.i("Android 8/8.1 detected, software render preference already exists.");
}
}
if (!BackupManager.enoughDiscSpace(CollectionHelper.getCurrentAnkiDroidDirectory(this))) {
Timber.i("Not enough space to do backup");
showDialogFragment(DeckPickerNoSpaceLeftDialog.newInstance());
} else if (preferences.getBoolean("noSpaceLeft", false)) {
Timber.i("No space left");
showDialogFragment(DeckPickerBackupNoSpaceLeftDialog.newInstance());
preferences.edit().remove("noSpaceLeft").apply();
} else if (InitialActivity.performSetupFromFreshInstallOrClearedPreferences(preferences)) {
onFinishedStartup();
} else if (skip < 2 && !InitialActivity.isLatestVersion(preferences)) {
Timber.i("AnkiDroid is being updated and a collection already exists.");
// The user might appreciate us now, see if they will help us get better?
if (!preferences.contains(UsageAnalytics.ANALYTICS_OPTIN_KEY)) {
displayAnalyticsOptInDialog();
}
// For upgrades, we check if we are upgrading
// to a version that contains additions to the database integrity check routine that we would
// like to run on all collections. A missing version number is assumed to be a fresh
// installation of AnkiDroid and we don't run the check.
long current = VersionUtils.getPkgVersionCode();
Timber.i("Current AnkiDroid version: %s", current);
long previous;
if (preferences.contains(UPGRADE_VERSION_KEY)) {
// Upgrading currently installed app
previous = getPreviousVersion(preferences, current);
} else {
// Fresh install
previous = current;
}
preferences.edit().putLong(UPGRADE_VERSION_KEY, current).apply();
// It is rebuilt on the next sync or media check
if (previous < 20300200) {
Timber.i("Deleting media database");
File mediaDb = new File(CollectionHelper.getCurrentAnkiDroidDirectory(this), "collection.media.ad.db2");
if (mediaDb.exists()) {
mediaDb.delete();
}
}
// Recommend the user to do a full-sync if they're upgrading from before 2.3.1beta8
if (previous < 20301208) {
Timber.i("Recommend the user to do a full-sync");
mRecommendFullSync = true;
}
// Fix "font-family" definition in templates created by AnkiDroid before 2.6alhpa23
if (previous < 20600123) {
Timber.i("Fixing font-family definition in templates");
try {
ModelManager models = getCol().getModels();
for (Model m : models.all()) {
String css = m.getString("css");
if (css.contains("font-familiy")) {
m.put("css", css.replace("font-familiy", "font-family"));
models.save(m);
}
}
models.flush();
} catch (JSONException e) {
Timber.e(e, "Failed to upgrade css definitions.");
}
}
// Check if preference upgrade or database check required, otherwise go to new feature screen
int upgradeDbVersion = AnkiDroidApp.CHECK_DB_AT_VERSION;
// Specifying a checkpoint in the future is not supported, please don't do it!
if (current < upgradeDbVersion) {
Timber.e("Invalid value for CHECK_DB_AT_VERSION");
UIUtils.showSimpleSnackbar(this, "Invalid value for CHECK_DB_AT_VERSION", false);
onFinishedStartup();
return;
}
// Skip full DB check if the basic check is OK
// TODO: remove this variable if we really want to do the full db check on every user
boolean skipDbCheck = false;
// if (previous < upgradeDbVersion && getCol().basicCheck()) {
// skipDbCheck = true;
// }
boolean upgradedPreferences = InitialActivity.upgradePreferences(this, previous);
// noinspection ConstantConditions
if (!skipDbCheck && previous < upgradeDbVersion) {
Timber.i("showStartupScreensAndDialogs() running integrityCheck()");
// #5852 - since we may have a warning about disk space, we don't want to force a check database
// and show a warning before the user knows what is happening.
new MaterialDialog.Builder(this).title(R.string.integrity_check_startup_title).content(R.string.integrity_check_startup_content).positiveText(R.string.check_db).negativeText(R.string.close).onPositive((materialDialog, dialogAction) -> integrityCheck()).onNeutral((materialDialog, dialogAction) -> restartActivity()).onNegative((materialDialog, dialogAction) -> restartActivity()).canceledOnTouchOutside(false).cancelable(false).build().show();
return;
}
if (upgradedPreferences) {
Timber.i("Updated preferences with no integrity check - restarting activity");
// If integrityCheck() doesn't occur, but we did update preferences we should restart DeckPicker to
// proceed
restartActivity();
return;
}
// There the "lastVersion" is set, so that this code is not reached again
if (VersionUtils.isReleaseVersion()) {
Timber.i("Displaying new features");
Intent infoIntent = new Intent(this, Info.class);
infoIntent.putExtra(Info.TYPE_EXTRA, Info.TYPE_NEW_VERSION);
if (skip != 0) {
startActivityForResultWithAnimation(infoIntent, SHOW_INFO_NEW_VERSION, START);
} else {
startActivityForResultWithoutAnimation(infoIntent, SHOW_INFO_NEW_VERSION);
}
} else {
Timber.i("Dev Build - not showing 'new features'");
// Don't show new features dialog for development builds
InitialActivity.setUpgradedToLatestVersion(preferences);
String ver = getResources().getString(R.string.updated_version, VersionUtils.getPkgVersionName());
UIUtils.showSnackbar(this, ver, true, -1, null, findViewById(R.id.root_layout), null);
showStartupScreensAndDialogs(preferences, 2);
}
} else {
// This is the main call when there is nothing special required
Timber.i("No startup screens required");
onFinishedStartup();
}
}
use of com.ichi2.anki.CardBrowser.Column.CREATED in project Anki-Android by ankidroid.
the class DeckPicker method createSubDeckDialog.
public void createSubDeckDialog(long did) {
CreateDeckDialog createDeckDialog = new CreateDeckDialog(DeckPicker.this, R.string.create_subdeck, CreateDeckDialog.DeckDialogType.SUB_DECK, did);
createDeckDialog.setOnNewDeckCreated((i) -> {
// a deck was created
mDeckListAdapter.notifyDataSetChanged();
updateDeckList();
if (mFragmented) {
loadStudyOptionsFragment(false);
}
});
createDeckDialog.showDialog();
}
Aggregations