Created
February 6, 2019 22:35
-
-
Save rsheeter/46c0a50cb9ba1d036a1467b08c383cdd to your computer and use it in GitHub Desktop.
Fonts ContentProvider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Notes on ContentProvider to fulfil requests for fonts, such as from FontsContractCompat. | |
// Not all imports shown | |
import android.provider.FontsContract.Columns; | |
public abstract class MyFontProvider extends ContentProvider { | |
@Override | |
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { | |
String query = selectionArgs[0]; // change based on your input pattern | |
// Prepare a response cursor | |
// Columns from https://android.googlesource.com/platform/frameworks/support/+/androidx-master-release/compat/src/main/java/androidx/core/provider/FontsContractCompat.java | |
// Set up response cursor. | |
MatrixCursor cursor = | |
new MatrixCursor( | |
new String[] { | |
Columns._ID, | |
Columns.FILE_ID, | |
Columns.TTC_INDEX, | |
Columns.VARIATION_SETTINGS, | |
Columns.WEIGHT, | |
Columns.ITALIC, | |
Columns.RESULT_CODE | |
}); | |
// Figure out if you understand the query | |
if (weUnderstandQuery()) { | |
cursor.addRow( | |
new Object[] { | |
an_identifier_you_generated, | |
0, | |
null, | |
400, | |
0.0, | |
RESULT_CODE_OK | |
}); | |
} else { | |
writeErrorToCursor(cursor, error code, perhaps RESULT_CODE_FONT_UNAVAILABLE); | |
} | |
} | |
@Override | |
public ParcelFileDescriptor openFile(Uri uri, String mode) { | |
// Uri is based on what you sent back from query | |
// See FontsContractCompat for details | |
// Extract identifier from uri | |
// Build and return a ParcelFileDescriptor for the font | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment