Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

android - Using Dynamic Feature Module: Fonts downloaded and installed in Asset folder but is not rendering in PDF-VIEW but renders in APP-UI-VIEW?

I created a dynamic feature module (consists of assets, fonts, and files) which will be downloaded and installed when the user taps onChooseFontClicked(). The dynamic-module is being downloaded and installed, but the fonts are not rendering in the PDF. These fonts can be used to set typeface of the text inside app view but the do they do not render in PDF. Why?

Can anyone help me regarding this issue? It is working perfectly in DEBUG mode.

SomeActivity.java: Unable to render using this code. Assets file is downloaded and saved to the assets folder which again is rendered in App View but not render in PDF view(iTextPDF).

String downloadedAssetsName = "assets/fonts/fontName.ttf";
BaseFont bFont = BaseFont.createFont(downloadedAssetsName, "UTF-8",BaseFont.EMBEDDED);
Font urFontName = new Font(bFont, 12);
Paragraph createdAtparagraph = new Paragraph("Some Data", urFontName);

In release mode, Using above lines PDF is rendering using default font inlace of new downloaded font. But in debit mode this code is working perfectly.

**

@Override
public void onChooseFontClicked(View v) {
    String fontModule = "module_font";
    if (splitInstallManager.getInstalledModules().contains(fontModule)) {

        AppUtils.showToast(this, "Already Installed module.");
        showFontStyleFragment();

    } else {
        requestInstall(fontModule);
    }

}

private void requestInstall(String moduleName) {

    SplitInstallRequest request = SplitInstallRequest.newBuilder()
            .addModule(moduleName)
            .build();
    splitInstallManager.startInstall(request);

}

/**
 * Perform actions on callbacks of state updates for the install session.
 */
private SplitInstallStateUpdatedListener stateListener =
        splitInstallSessionState -> {
            if (splitInstallSessionState.status() == SplitInstallSessionStatus.FAILED &&
                    splitInstallSessionState.sessionId() < 0) {
                AppUtils.showLog(TAG, "Service process died");
                return;
            }
            if (splitInstallSessionState.status() == SplitInstallSessionStatus.DOWNLOADING) {
                long size = splitInstallSessionState.totalBytesToDownload();
                long downloaded = splitInstallSessionState.bytesDownloaded();
                int percentage = (int) ((downloaded * 100) / size);

//                    double completedPercent = Double.parseDouble(downloaded + "") * 100 / Double.parseDouble(size + "");
                AppUtils.showToast(PDFPreviewActivity.this, percentage + "% Completed. Total MB: " + size / 1000000 + " Downloaded: " + downloaded / 1000000 + "MB");
                AppUtils.showLog(TAG, "SplitInstallSessionStatus.DOWNLOADING: " + downloaded);

                // Update progress bar.
            } else if (splitInstallSessionState.status() == SplitInstallSessionStatus.CANCELED) {
                AppUtils.showLog(TAG, "Installation cancelled");
            } else if (splitInstallSessionState.status() == SplitInstallSessionStatus.FAILED) {
                Log.e(TAG, "Install failed");
            } else if (splitInstallSessionState.status() == SplitInstallSessionStatus.INSTALLED) {
                AppUtils.showLog(TAG, "Split successfully installed, launching GreetActivity");
                //Module is downloaded successfully
                AppUtils.showToast(PDFPreviewActivity.this, "SplitInstallSessionStatus.INSTALLED: ");
                SplitInstallHelper.updateAppInfo(PDFPreviewActivity.this);

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                    // Update app context with the code and resources of the installed module.
                    SplitInstallHelper.updateAppInfo(PDFPreviewActivity.this);
                }
                SplitCompat.installActivity(this);
                showFontStyleFragment();
            }

        };

@Override
protected void onResume() {
    super.onResume();
    splitInstallManager.registerListener(stateListener);
}

@Override
protected void onPause() {
    super.onPause();
    splitInstallManager.unregisterListener(stateListener);
}

@Override
 protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(newBase);
    SplitCompat.install(this);
 }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...