Java Code Examples for com.android.inputmethod.latin.AssetFileAddress

The following examples show how to use com.android.inputmethod.latin.AssetFileAddress. These examples are extracted from open source projects. 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 Project: Android-Keyboard   Source File: DictionaryInfoUtils.java    License: 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 Project: AOSP-Kayboard-7.1.2   Source File: DictionaryInfoUtils.java    License: 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 Project: Indic-Keyboard   Source File: DictionaryInfoUtils.java    License: 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 Project: Android-Keyboard   Source File: DictionaryInfoUtils.java    License: 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 Project: AOSP-Kayboard-7.1.2   Source File: DictionaryInfoUtils.java    License: 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 Project: Indic-Keyboard   Source File: DictionaryInfoUtils.java    License: 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 Project: Android-Keyboard   Source File: DictionaryHeaderUtils.java    License: 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 Project: AOSP-Kayboard-7.1.2   Source File: DictionaryHeaderUtils.java    License: 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 Project: Indic-Keyboard   Source File: DictionaryHeaderUtils.java    License: 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);
}