Git Product home page Git Product logo

Comments (5)

guaishouN avatar guaishouN commented on May 14, 2024

可以增加完整导图截图功能和导出文本功能

文本功能如下:

地球
    海洋
         北冰洋
         大西洋
         太平洋
    陆地
         亚洲
         欧洲

如果作为一个通用的结构图控件,这方面你有具体的方案没有?比如json、xml...,一般用法有哪些?
因为我之前项目没有做复杂功能,编辑功能都是应别人请求做的

from android-thinkmap-treeview.

onexuan avatar onexuan commented on May 14, 2024

我是试了序列化对象再转成hex string,这样app容易序列化与反序列化,但如果离开app,就只能导致出文本格式了,方便用户看文本。试过NodeModel导成Gson,会FC
编辑功能是有必要的

from android-thinkmap-treeview.

onexuan avatar onexuan commented on May 14, 2024

我试过截view图,但文字比较小还有只有某个区域,得做区域截图并做全域滚动,再把图拼接。导出图片也是一种格式导出

from android-thinkmap-treeview.

hardlove avatar hardlove commented on May 14, 2024

生成截图的功能我这边已经实现,可以参考:

 /**
     * 加载静态xml布局资源生成Bitmap
     *
     * @param context
     * @param layoutRes xml 布局资源ID
     * @param onInitCallBack 数据初始化回调
     */
    fun convertViewToBitmap(
        context: Context,
        @LayoutRes layoutRes: Int,
        onInitCallBack: (View)-> Unit
    ): Bitmap {
        val root = LayoutInflater.from(context).inflate(layoutRes, null)
        onInitCallBack(root)
        //测量
        val width = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
        val height = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
        root.measure(width, height)
        val measuredWidth = root.measuredWidth
        val measuredHeight = root.measuredHeight

        //再次测量(避免子View无法正常显示)
        root.measure(View.MeasureSpec.makeMeasureSpec(measuredWidth, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(measuredHeight, View.MeasureSpec.EXACTLY))

        //布局
        root.layout(0, 0, measuredWidth, measuredHeight)
        val bitmap = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888)
        val canvas = Canvas(bitmap)
        root.draw(canvas)
        return bitmap
    }
val bitmap =
                                                BitmapUtils.convertViewToBitmap(activity,
                                                        R.layout.save_xmind_layout) { rootView ->
                                                    val gysoTreeView =
                                                            rootView.findViewById<GysoTreeView>(
                                                                    R.id.tree_view)

                                                    val saveAdapter =
                                                            XMindTreeViewAdapter()
                                                    gysoTreeView.adapter = saveAdapter

                                                    gysoTreeView.setTreeLayoutManager(
                                                            getTreeLayoutManager())

                                                    saveAdapter.treeModel =
                                                            adapter.treeModel
                                                    saveAdapter.bindBaseTreeView(
                                                            gysoTreeView)
                                                    saveAdapter.getTreeViewEditor()
                                                            .focusMidLocation(false)
                                                }

目前还有给棘手的问题就是,如何把数据存储起来,序列化会直接报错,这比较麻烦,不知道大家有什么好办法没?

from android-thinkmap-treeview.

onexuan avatar onexuan commented on May 14, 2024

@hardlove

public static String writeTreeObject(Object object) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(out);
oos.writeObject(object);
oos.close();
ByteString byteString = ByteString.of(out.toByteArray(),0,out.size());
return byteString.hex();
}

public static Object readTreeObject(String hex) throws Exception {
    ByteArrayInputStream in=new ByteArrayInputStream(ByteString.decodeHex(hex).toByteArray());
    ObjectInputStream oin = new ObjectInputStream(in);
    Object obj = oin.readObject();
    oin.close();
    return obj;
}

from android-thinkmap-treeview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.