android.support.v4.provider.FontRequest Java Examples

The following examples show how to use android.support.v4.provider.FontRequest. 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: MainActivity.java    From user-interface-samples with Apache License 2.0 5 votes vote down vote up
private void requestDownload(String familyName) {
    QueryBuilder queryBuilder = new QueryBuilder(familyName)
            .withWidth(progressToWidth(mWidthSeekBar.getProgress()))
            .withWeight(progressToWeight(mWeightSeekBar.getProgress()))
            .withItalic(progressToItalic(mItalicSeekBar.getProgress()))
            .withBestEffort(mBestEffort.isChecked());
    String query = queryBuilder.build();

    Log.d(TAG, "Requesting a font. Query: " + query);
    FontRequest request = new FontRequest(
            "com.google.android.gms.fonts",
            "com.google.android.gms",
            query,
            R.array.com_google_android_gms_fonts_certs);

    final ProgressBar progressBar = findViewById(R.id.progressBar);
    progressBar.setVisibility(View.VISIBLE);

    FontsContractCompat.FontRequestCallback callback = new FontsContractCompat
            .FontRequestCallback() {
        @Override
        public void onTypefaceRetrieved(Typeface typeface) {
            mDownloadableFontTextView.setTypeface(typeface);
            progressBar.setVisibility(View.GONE);
            mRequestDownloadButton.setEnabled(true);
        }

        @Override
        public void onTypefaceRequestFailed(int reason) {
            Toast.makeText(MainActivity.this,
                    getString(R.string.request_failed, reason), Toast.LENGTH_LONG)
                    .show();
            progressBar.setVisibility(View.GONE);
            mRequestDownloadButton.setEnabled(true);
        }
    };
    FontsContractCompat
            .requestFont(MainActivity.this, request, callback,
                    getHandlerThreadHandler());
}
 
Example #2
Source File: MainActivity.java    From android-DownloadableFonts with Apache License 2.0 5 votes vote down vote up
private void requestDownload(String familyName) {
    QueryBuilder queryBuilder = new QueryBuilder(familyName)
            .withWidth(progressToWidth(mWidthSeekBar.getProgress()))
            .withWeight(progressToWeight(mWeightSeekBar.getProgress()))
            .withItalic(progressToItalic(mItalicSeekBar.getProgress()))
            .withBestEffort(mBestEffort.isChecked());
    String query = queryBuilder.build();

    Log.d(TAG, "Requesting a font. Query: " + query);
    FontRequest request = new FontRequest(
            "com.google.android.gms.fonts",
            "com.google.android.gms",
            query,
            R.array.com_google_android_gms_fonts_certs);

    final ProgressBar progressBar = findViewById(R.id.progressBar);
    progressBar.setVisibility(View.VISIBLE);

    FontsContractCompat.FontRequestCallback callback = new FontsContractCompat
            .FontRequestCallback() {
        @Override
        public void onTypefaceRetrieved(Typeface typeface) {
            mDownloadableFontTextView.setTypeface(typeface);
            progressBar.setVisibility(View.GONE);
            mRequestDownloadButton.setEnabled(true);
        }

        @Override
        public void onTypefaceRequestFailed(int reason) {
            Toast.makeText(MainActivity.this,
                    getString(R.string.request_failed, reason), Toast.LENGTH_LONG)
                    .show();
            progressBar.setVisibility(View.GONE);
            mRequestDownloadButton.setEnabled(true);
        }
    };
    FontsContractCompat
            .requestFont(MainActivity.this, request, callback,
                    getHandlerThreadHandler());
}
 
Example #3
Source File: EmojiService.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
public void init() {
    final FontRequest fontRequest = new FontRequest(
            "com.google.android.gms.fonts",
            "com.google.android.gms",
            "Noto Color Emoji Compat",
            R.array.font_certs);
    FontRequestEmojiCompatConfig fontRequestEmojiCompatConfig = new FontRequestEmojiCompatConfig(context, fontRequest);
    fontRequestEmojiCompatConfig.registerInitCallback(initCallback);
    //On recent Androids we assume to have the latest emojis
    //there are some annoying bugs with emoji compat that make it a safer choice not to use it when possible
    // a) when using the ondemand emoji font (play store) flags don’t work
    // b) the text preview has annoying glitches when the cut of text contains emojis (the emoji will be half visible)
    // c) can trigger a hardware rendering bug https://issuetracker.google.com/issues/67102093
    fontRequestEmojiCompatConfig.setReplaceAll(Build.VERSION.SDK_INT < Build.VERSION_CODES.O);
    EmojiCompat.init(fontRequestEmojiCompatConfig);
}
 
Example #4
Source File: weMessage.java    From weMessage with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    instance = this;

    if (AppLogger.USE_CRASHLYTICS) Fabric.with(this, new Crashlytics());

    updateDatabase();
    generateSharedPreferences();

    File attachmentFolder = new File(getFilesDir(), weMessage.ATTACHMENT_FOLDER_NAME);
    File chatIconsFolder = new File(getFilesDir(), weMessage.CHAT_ICONS_FOLDER_NAME);

    AndroidBase64Wrapper base64Wrapper = new AndroidBase64Wrapper();
    ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter(base64Wrapper);
    EmojiCompat.Config emojiConfig = new FontRequestEmojiCompatConfig(this,
            new FontRequest("com.google.android.gms.fonts", "com.google.android.gms", "Noto Color Emoji Compat", R.array.com_google_android_gms_fonts_certs))
            .registerInitCallback(new EmojiCompat.InitCallback() {
                @Override
                public void onInitialized() {
                    isEmojiInitialized.set(true);
                }
            });

    AESCrypto.setMemoryAvailabilityCheck(true);
    AESCrypto.setBase64Wrapper(base64Wrapper);
    AESCrypto.setPrngHelper(new AesPrngHelper());

    ClientMessage.setByteArrayAdapter(byteArrayAdapter);
    ServerMessage.setByteArrayAdapter(byteArrayAdapter);

    EmojiCompat.init(emojiConfig);
    JobManager.create(this).addJobCreator(new JobsCreator());

    attachmentFolder.mkdir();
    chatIconsFolder.mkdir();

    this.attachmentFolder = attachmentFolder;
    this.chatIconsFolder = chatIconsFolder;
    this.currentSession = new Session();
    this.messageDatabase = new MessageDatabase(this);
    this.messageManager = new MessageManager(this);
    this.notificationManager = new NotificationManager(this);

    if (isSignedIn(true) && !StringUtils.isEmpty(getSharedPreferences().getString(weMessage.SHARED_PREFERENCES_LAST_EMAIL, ""))){
        getCurrentSession().setAccount(getMessageDatabase().getAccountByEmail(getSharedPreferences().getString(weMessage.SHARED_PREFERENCES_LAST_EMAIL, "")));
    }

    getMessageManager().initialize();
    if (MmsManager.isDefaultSmsApp()) enableSmsMode(getMessageDatabase().getSmsChats().isEmpty());
    else disableSmsMode();

    IOUtils.setDeviceName();
}