Font.SourceIdentifier Propriedade
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Retorna a ID exclusiva dos dados da fonte de origem.
public int SourceIdentifier { [Android.Runtime.Register("getSourceIdentifier", "()I", "", ApiSince=31)] get; }
[<get: Android.Runtime.Register("getSourceIdentifier", "()I", "", ApiSince=31)>]
member this.SourceIdentifier : int
Valor da propriedade
um identificador exclusivo para os dados da fonte da fonte.
- Atributos
Comentários
Retorna a ID exclusiva dos dados da fonte de origem.
Você pode usar esse identificador como uma chave do cache ou verificar se duas fontes podem ser interpoladas com configurações de variação de fonte.
<code>
// Following three Fonts, fontA, fontB, fontC have the same identifier.
Font fontA = new Font.Builder("/path/to/font").build();
Font fontB = new Font.Builder(fontA).setTtcIndex(1).build();
Font fontC = new Font.Builder(fontB).setFontVariationSettings("'wght' 700).build();
// Following fontD has the different identifier from above three.
Font fontD = new Font.Builder("/path/to/another/font").build();
// Following fontE has different identifier from above four even the font path is the same.
// To get the same identifier, please create new Font instance from existing fonts.
Font fontE = new Font.Builder("/path/to/font").build();
</code>
Aqui está um exemplo de objeto de fonte de cache que tem
<code>
private LongSparseArray<SparseArray<Font>> mCache = new LongSparseArray<>();
private Font getFontWeightVariation(Font font, int weight) {
// Different collection index is treated as different font.
long key = ((long) font.getSourceIdentifier()) << 32 | (long) font.getTtcIndex();
SparseArray<Font> weightCache = mCache.get(key);
if (weightCache == null) {
weightCache = new SparseArray<>();
mCache.put(key, weightCache);
}
Font cachedFont = weightCache.get(weight);
if (cachedFont != null) {
return cachedFont;
}
Font newFont = new Font.Builder(cachedFont)
.setFontVariationSettings("'wght' " + weight);
.build();
weightCache.put(weight, newFont);
return newFont;
}
</code>
Java documentação para android.graphics.fonts.Font.getSourceIdentifier().
Partes desta página são modificações baseadas no trabalho criado e compartilhado pelo Project Open Source do Open Source e usadas de acordo com os termos descritos na Creative Commons 2.5.