2

I'm using Rich edit text library to create HTML in edit-text on android. Here is the GitHub link to the project.

Android-RTEditor

According to the demo, I register the RTApi and RTManager on Activity start but it add a few seconds delay with a black empty screen on start. Code to register that is

RTApi rtApi = new RTApi(this, new RTProxyImpl(this), new RTMediaFactoryImpl(this, true));
RTManager rtManager = new RTManager(rtApi, savedInstanceState);

And here is the logcat on activity start

E/AssetIndex: assets.index
E/AssetIndex: java.io.FileNotFoundException: assets.index
E/AssetIndex:     at android.content.res.AssetManager.openAsset(Native Method)
E/AssetIndex:    at android.content.res.AssetManager.open(AssetManager.java:334)
E/AssetIndex:    at android.content.res.AssetManager.open(AssetManager.java:308)
E/AssetIndex: at com.onegravity.rteditor.fonts.AssetIndex.getAssetIndex(AssetIndex.java:46)
E/AssetIndex: at com.onegravity.rteditor.fonts.FontManager.getAssetFonts(FontManager.java:156)
E/AssetIndex:     at com.onegravity.rteditor.fonts.FontManager.getFonts(FontManager.java:97)
E/AssetIndex:     at com.onegravity.rteditor.toolbar.HorizontalRTToolbar.getFontItems(HorizontalRTToolbar.java:213)
E/AssetIndex:     at com.onegravity.rteditor.toolbar.HorizontalRTToolbar.onFinishInflate(HorizontalRTToolbar.java:177)
E/AssetIndex:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:814)
E/AssetIndex:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
E/AssetIndex:     at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916)
E/AssetIndex:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
 E/AssetIndex:     at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
E/AssetIndex:     at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
E/AssetIndex:     at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
E/AssetIndex:     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
E/AssetIndex:     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
E/AssetIndex:     at com.workmatec.apps.androidapp.UIElements.AppFormActivity.onCreate(AppFormActivity.java:91)
E/AssetIndex:     at android.app.Activity.performCreate(Activity.java:6020)
E/AssetIndex:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
E/AssetIndex:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2259)
E/AssetIndex:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2368)
E/AssetIndex:     at android.app.ActivityThread.access$800(ActivityThread.java:149)
E/AssetIndex:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
E/AssetIndex:     at android.os.Handler.dispatchMessage(Handler.java:102)
E/AssetIndex:     at android.os.Looper.loop(Looper.java:135)
E/AssetIndex:     at android.app.ActivityThread.main(ActivityThread.java:5299)
E/AssetIndex:     at java.lang.reflect.Method.invoke(Native Method)
E/AssetIndex:     at java.lang.reflect.Method.invoke(Method.java:372)
E/AssetIndex:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
E/AssetIndex:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
E/Minikin: addFont failed to create font /system/fonts/jb

Here is my Layout File

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.workmatec.apps.androidapp.UIElements.AppFormActivity">

<include
    android:id="@+id/rte_toolbar_container"
    layout="@layout/rte_toolbar" />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/rte_toolbar_container">

    <LinearLayout
        android:id="@+id/appForm"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/app_background"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin">

    </LinearLayout>
</ScrollView>

XML of RTE_toolbar.xml

    <?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="?attr/actionBarItemBackground"
    android:scrollbarStyle="outsideOverlay" >

    <com.onegravity.rteditor.toolbar.HorizontalRTToolbar
        android:id="@+id/rte_toolbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="?attr/actionBarItemBackground"
        android:orientation="horizontal" >

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_bold"
            style="@style/RTE_ToolbarButton"
            android:background="?attr/rte_icToolbarBold" />

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_italic"
            style="@style/RTE_ToolbarButton"
            android:background="?attr/rte_icToolbarItalic" />

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_underline"
            style="@style/RTE_ToolbarButton"
            android:background="?attr/rte_icToolbarUnderline" />

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_strikethrough"
            style="@style/RTE_ToolbarButton"
            android:background="?attr/rte_icToolbarStrikethrough" />

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_superscript"
            style="@style/RTE_ToolbarButton"
            android:background="?attr/rte_icToolbarSuperscript" />

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_subscript"
            style="@style/RTE_ToolbarButton"
            android:background="?attr/rte_icToolbarSubscript" />

        <include layout="@layout/rte_toolbar_divider"/>

        <Spinner
            android:id="@+id/toolbar_font"
            style="?attr/rte_ToolbarSpinner"
            android:background="?attr/rte_icToolbarFont" />

        <Spinner
            android:id="@+id/toolbar_fontsize"
            style="?attr/rte_ToolbarSpinner"
            android:background="?attr/rte_icToolbarFontSize" />

        <Spinner
            android:id="@+id/toolbar_fontcolor"
            style="?attr/rte_ToolbarSpinner"
            android:background="?attr/rte_icToolbarFontColor" />

        <Spinner
            android:id="@+id/toolbar_bgcolor"
            style="?attr/rte_ToolbarSpinner"
            android:background="?attr/rte_icToolbarBGColor" />

        <include layout="@layout/rte_toolbar_divider"/>

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_number"
            style="@style/RTE_ToolbarButton"
            android:background="?attr/rte_icToolbarNumber" />

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_bullet"
            style="@style/RTE_ToolbarButton"
            android:background="?attr/rte_icToolbarBullet" />

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_inc_indent"
            style="@style/RTE_ToolbarButton"
            android:background="?attr/rte_icToolbarIncIndent" />

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_dec_indent"
            style="@style/RTE_ToolbarButton"
            android:background="?attr/rte_icToolbarDecIntent" />

        <include layout="@layout/rte_toolbar_divider"/>

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_align_left"
            style="@style/RTE_ToolbarButton"
            android:background="?attr/rte_icToolbarAlignLeft" />

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_align_center"
            style="@style/RTE_ToolbarButton"
            android:background="?attr/rte_icToolbarAlignCenter" />

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_align_right"
            style="@style/RTE_ToolbarButton"
            android:background="?attr/rte_icToolbarAlignRight" />

        <include layout="@layout/rte_toolbar_divider"/>

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_link"
            style="@style/RTE_ToolbarButton"
            android:background="?attr/rte_icToolbarLink" />

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_image"
            style="@style/RTE_ToolbarButton"
            android:background="?attr/rte_icToolbarImage" />

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_image_capture"
            style="@style/RTE_ToolbarButton"
            android:background="?attr/rte_icToolbarCapture" />

        <!-- com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_audio"
            style="@style/ToolbarButton"
            android:background="?attr/rte_icToolbarAudio" /-->

        <!-- com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_video"
            style="@style/ToolbarButton"
            android:layout_marginRight="4dip"
            android:background="?attr/rte_icToolbarVideo" /-->

        <include layout="@layout/rte_toolbar_divider"/>

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_undo"
            style="@style/RTE_ToolbarButton"
            android:background="?attr/rte_icToolbarUndo"/>

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_redo"
            style="@style/RTE_ToolbarButton"
            android:background="?attr/rte_icToolbarRedo"/>

        <com.onegravity.rteditor.toolbar.RTToolbarImageButton
            android:id="@+id/toolbar_clear"
            style="@style/RTE_ToolbarButton"
            android:layout_marginRight="4dip"
            android:background="?attr/rte_icToolbarClear"/>

    </com.onegravity.rteditor.toolbar.HorizontalRTToolbar>

</HorizontalScrollView>

RTE Toolbar Button style

<style name="RTE_ToolbarButton" parent="@android:style/Widget.ImageButton">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_gravity">center</item>
    <item name="android:layout_marginTop">4dip</item>
    <item name="android:layout_marginBottom">4dip</item>
    <item name="android:layout_marginLeft">4dip</item>
    <item name="android:gravity">center</item>
    <item name="android:adjustViewBounds">true</item>
</style>
Zeeshan Ahmed
  • 1,179
  • 2
  • 13
  • 30

2 Answers2

2

I had the same problem. I just added assets.index file to the assets folder of my project. The file has followings:

<?xml version="1.0"?>
<project default="createAssetIndex">
    <target name="createAssetIndex">
        <fileset id="assets.fileset" dir="assets/" includes="**"
            excludes="asset.index" />
        <pathconvert pathsep="${line.separator}" property="assets"
            refid="assets.fileset">
            <mapper>
                <globmapper from="${basedir}/assets/*" to="*"
                    handledirsep="yes" />
            </mapper>
        </pathconvert>
        <echo file="assets/assets.index">${assets}</echo>
    </target>
</project>

For more details please follow this link: determine wheteher android asset entry is a file or directory

Community
  • 1
  • 1
mqb
  • 36
  • 4
0

The demo requires you to add this block of code to the build.gardle file of your project so the assest.index file is created during compilation:

task indexAssets {
    description 'Index Build Variant assets for faster lookup by AssetManager'

    ext.assetsSrcDir = file( "${projectDir}/src/main/assets" )

    inputs.dir assetsSrcDir

    doLast {
        android.applicationVariants.each { target ->
            // create index
            def contents = ""
            def tree = fileTree(dir: "${ext.assetsSrcDir}", include: ['**/*.ttf'], exclude: ['**/.svn/**', '*.index'])
            // use this instead if you have assets folders in each flavor:
            // def tree = fileTree(dir: "${ext.variantPath}", exclude: ['**/.svn/**', '*.index'])
            tree.visit { fileDetails ->
                contents += "${fileDetails.relativePath}" + "\n"
            }

            // create index file
            def assetIndexFile = new File("${ext.assetsSrcDir}/assets.index")
            assetIndexFile.write contents
        }
    }
}

indexAssets.dependsOn {
    tasks.matching { task -> task.name.startsWith( 'merge' ) && task.name.endsWith( 'Assets' ) }
}

tasks.withType( JavaCompile ) {
    compileTask -> compileTask.dependsOn indexAssets
}

indexAssets

If you don't have the asset folder, create it like the following in Android Studio :

Select your project, then FILE --> NEW--> FOLDER --> ASSET

I've found that if you have the font folder in the asset, the editor can be launched faster than without.

RedGiant
  • 4,444
  • 11
  • 59
  • 146
  • I've the assets folder on my project directory and also has the index file but still facing the problem. When I click the button to start the activity which contains the RT editor, it hangs for somtime and then start the acticity and display the error message logcat as "E/Minikin: addFont failed to create font /system/fonts/jb" – Zeeshan Ahmed May 17 '16 at 08:06