com.android.inputmethod.latin.AssetFileAddress Java Examples

The following examples show how to use com.android.inputmethod.latin.AssetFileAddress. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DictionaryInfoUtils.java    From Android-Keyboard with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the information of the dictionary for the given {@link AssetFileAddress}.
 * If the file is corrupted or a pre-fava file, then the file gets deleted and the null
 * value is returned.
 */
@Nullable
private static DictionaryInfo createDictionaryInfoForUnCachedFile(
        @Nonnull final AssetFileAddress fileAddress, final Locale locale) {
    final String id = getMainDictId(locale);
    final int version = DictionaryHeaderUtils.getContentVersion(fileAddress);

    if (version == -1) {
        // Purge the pre-fava/corrupted unused dictionaires.
        fileAddress.deleteUnderlyingFile();
        return null;
    }

    final String description = SubtypeLocaleUtils
            .getSubtypeLocaleDisplayName(locale.toString());

    final File unCachedFile = new File(fileAddress.mFilename);
    // Store just the filename and not the full path.
    final String filenameToStoreOnDb = unCachedFile.getName();
    return new DictionaryInfo(id, locale, description, filenameToStoreOnDb, fileAddress.mLength,
            unCachedFile.lastModified(), version);
}
 
Example #2
Source File: DictionaryInfoUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the information of the dictionary for the given {@link AssetFileAddress}.
 * If the file is corrupted or a pre-fava file, then the file gets deleted and the null
 * value is returned.
 */
@Nullable
private static DictionaryInfo createDictionaryInfoForUnCachedFile(
        @Nonnull final AssetFileAddress fileAddress, final Locale locale) {
    final String id = getMainDictId(locale);
    final int version = DictionaryHeaderUtils.getContentVersion(fileAddress);

    if (version == -1) {
        // Purge the pre-fava/corrupted unused dictionaires.
        fileAddress.deleteUnderlyingFile();
        return null;
    }

    final String description = SubtypeLocaleUtils
            .getSubtypeLocaleDisplayName(locale.toString());

    final File unCachedFile = new File(fileAddress.mFilename);
    // Store just the filename and not the full path.
    final String filenameToStoreOnDb = unCachedFile.getName();
    return new DictionaryInfo(id, locale, description, filenameToStoreOnDb, fileAddress.mLength,
            unCachedFile.lastModified(), version);
}
 
Example #3
Source File: DictionaryInfoUtils.java    From Indic-Keyboard with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the information of the dictionary for the given {@link AssetFileAddress}.
 * If the file is corrupted or a pre-fava file, then the file gets deleted and the null
 * value is returned.
 */
@Nullable
private static DictionaryInfo createDictionaryInfoForUnCachedFile(
        @Nonnull final AssetFileAddress fileAddress, final Locale locale) {
    final String id = getMainDictId(locale);
    final int version = DictionaryHeaderUtils.getContentVersion(fileAddress);

    if (version == -1) {
        // Purge the pre-fava/corrupted unused dictionaires.
        fileAddress.deleteUnderlyingFile();
        return null;
    }

    final String description = SubtypeLocaleUtils
            .getSubtypeLocaleDisplayName(locale.toString());

    final File unCachedFile = new File(fileAddress.mFilename);
    // Store just the filename and not the full path.
    final String filenameToStoreOnDb = unCachedFile.getName();
    return new DictionaryInfo(id, locale, description, filenameToStoreOnDb, fileAddress.mLength,
            unCachedFile.lastModified(), version);
}
 
Example #4
Source File: DictionaryInfoUtils.java    From Android-Keyboard with Apache License 2.0 5 votes vote down vote up
/**
 * Returns information of the dictionary.
 *
 * @param fileAddress the asset dictionary file address.
 * @param locale Locale for this file.
 * @return information of the specified dictionary.
 */
private static DictionaryInfo createDictionaryInfoFromFileAddress(
        @Nonnull final AssetFileAddress fileAddress, final Locale locale) {
    final String id = getMainDictId(locale);
    final int version = DictionaryHeaderUtils.getContentVersion(fileAddress);
    final String description = SubtypeLocaleUtils
            .getSubtypeLocaleDisplayName(locale.toString());
    // Do not store the filename on db as it will try to move the filename from db to the
    // cached directory. If the filename is already in cached directory, this is not
    // necessary.
    final String filenameToStoreOnDb = null;
    return new DictionaryInfo(id, locale, description, filenameToStoreOnDb,
            fileAddress.mLength, new File(fileAddress.mFilename).lastModified(), version);
}
 
Example #5
Source File: DictionaryInfoUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns information of the dictionary.
 *
 * @param fileAddress the asset dictionary file address.
 * @param locale Locale for this file.
 * @return information of the specified dictionary.
 */
private static DictionaryInfo createDictionaryInfoFromFileAddress(
        @Nonnull final AssetFileAddress fileAddress, final Locale locale) {
    final String id = getMainDictId(locale);
    final int version = DictionaryHeaderUtils.getContentVersion(fileAddress);
    final String description = SubtypeLocaleUtils
            .getSubtypeLocaleDisplayName(locale.toString());
    // Do not store the filename on db as it will try to move the filename from db to the
    // cached directory. If the filename is already in cached directory, this is not
    // necessary.
    final String filenameToStoreOnDb = null;
    return new DictionaryInfo(id, locale, description, filenameToStoreOnDb,
            fileAddress.mLength, new File(fileAddress.mFilename).lastModified(), version);
}
 
Example #6
Source File: DictionaryInfoUtils.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
/**
 * Returns information of the dictionary.
 *
 * @param fileAddress the asset dictionary file address.
 * @param locale Locale for this file.
 * @return information of the specified dictionary.
 */
private static DictionaryInfo createDictionaryInfoFromFileAddress(
        @Nonnull final AssetFileAddress fileAddress, final Locale locale) {
    final String id = getMainDictId(locale);
    final int version = DictionaryHeaderUtils.getContentVersion(fileAddress);
    final String description = SubtypeLocaleUtils
            .getSubtypeLocaleDisplayName(locale.toString());
    // Do not store the filename on db as it will try to move the filename from db to the
    // cached directory. If the filename is already in cached directory, this is not
    // necessary.
    final String filenameToStoreOnDb = null;
    return new DictionaryInfo(id, locale, description, filenameToStoreOnDb,
            fileAddress.mLength, new File(fileAddress.mFilename).lastModified(), version);
}
 
Example #7
Source File: DictionaryHeaderUtils.java    From Android-Keyboard with Apache License 2.0 4 votes vote down vote up
public static int getContentVersion(AssetFileAddress fileAddress) {
    final DictionaryHeader header = DictionaryInfoUtils.getDictionaryFileHeaderOrNull(
            new File(fileAddress.mFilename), fileAddress.mOffset, fileAddress.mLength);
    return Integer.parseInt(header.mVersionString);
}
 
Example #8
Source File: DictionaryHeaderUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 4 votes vote down vote up
public static int getContentVersion(AssetFileAddress fileAddress) {
    final DictionaryHeader header = DictionaryInfoUtils.getDictionaryFileHeaderOrNull(
            new File(fileAddress.mFilename), fileAddress.mOffset, fileAddress.mLength);
    return Integer.parseInt(header.mVersionString);
}
 
Example #9
Source File: DictionaryHeaderUtils.java    From Indic-Keyboard with Apache License 2.0 4 votes vote down vote up
public static int getContentVersion(AssetFileAddress fileAddress) {
    final DictionaryHeader header = DictionaryInfoUtils.getDictionaryFileHeaderOrNull(
            new File(fileAddress.mFilename), fileAddress.mOffset, fileAddress.mLength);
    return Integer.parseInt(header.mVersionString);
}