{"id":2555,"date":"2024-08-26T11:29:48","date_gmt":"2024-08-26T03:29:48","guid":{"rendered":"https:\/\/support.foxitsoftware.cn\/?p=2555"},"modified":"2024-08-26T11:35:23","modified_gmt":"2024-08-26T03:35:23","slug":"%e5%8a%a8%e6%80%81%e8%ae%be%e7%bd%ae%e5%b7%a5%e5%85%b7%e6%a0%8f","status":"publish","type":"post","link":"https:\/\/support.fuxinsoft.cn\/?p=2555","title":{"rendered":"\u52a8\u6001\u8bbe\u7f6e\u5de5\u5177\u680f"},"content":{"rendered":"\n<p class=\"has-body-font-family has-medium-font-size\">Foxit PDF for Android\u4fdd\u5b58getCenterItems()\u83b7\u53d6\u5230\u7684\u6570\u636e\u683c\u5f0f\uff0c\u901a\u8fc7setCenterItems\u6062\u590d\u8bbe\u7f6e\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u652f\u6301\u901a\u8fc7\u8bfb\u53d6json\u6765\u8bbe\u7f6e<\/li>\n\n\n\n<li>\u6301\u4e45\u5316\u4fdd\u5b58\u5de5\u5177\u680f\u914d\u7f6e<\/li>\n\n\n\n<li>\u6062\u590d\u5de5\u5177\u680f\u914d\u7f6e<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-contrast-color has-base-2-background-color has-text-color has-background has-link-color has-body-font-family has-medium-font-size wp-elements-e343a954a28da44ba4bf742906c2eba2\"><code>package com.foxit.pdfreader.fragment;\n\nimport static com.foxit.uiextensions.utils.AppUtil.getApplicationContext;\n\nimport android.content.Context;\nimport android.content.res.AssetManager;\nimport android.util.Log;\n\nimport com.foxit.uiextensions.UIExtensionsManager;\nimport com.foxit.uiextensions.controls.toolbar.ToolItemBean;\nimport com.foxit.uiextensions.controls.toolbar.ToolProperty;\nimport com.foxit.uiextensions.pdfreader.MainCenterItemBean;\nimport com.foxit.uiextensions.utils.AppSharedPreferences;\nimport com.foxit.uiextensions.utils.AppUtil;\n\nimport org.json.JSONArray;\nimport org.json.JSONObject;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigDecimal;\nimport java.util.ArrayList;\nimport java.util.List;\n\npublic class CenterItemsManager {\n\n    public static final String SP_NAME = \"Foxit_Plugin_SP\";\n    public static final String TAB_ITEMS_KEY = \"KEY_TAB_ITEMS\";\n\n\n    \/**\n     * \u8bfb\u53d6assets\u76ee\u5f55\u4e0b\u7684json\u6587\u4ef6\n     *\n     * @param fileName json\u6587\u4ef6Name\n     * @param context  \u7cfb\u7edf\u4e0a\u4e0b\u6587\n     * @return json\u5b57\u7b26\u4e32\n     *\/\n    public static String getJson(String fileName, Context context) {\n        \/\/\u5c06json\u6570\u636e\u53d8\u6210\u5b57\u7b26\u4e32\n        StringBuilder stringBuilder = new StringBuilder();\n        try {\n            \/\/\u83b7\u53d6assets\u8d44\u6e90\u7ba1\u7406\u5668\n            AssetManager assetManager = context.getAssets();\n            \/\/\u901a\u8fc7\u7ba1\u7406\u5668\u6253\u5f00\u6587\u4ef6\u5e76\u8bfb\u53d6\n            BufferedReader bf = new BufferedReader(new InputStreamReader(\n                    assetManager.open(fileName)));\n            String line;\n            while ((line = bf.readLine()) != null) {\n                stringBuilder.append(line);\n            }\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n        return stringBuilder.toString();\n    }\n\n    \/**\n     * \u4fdd\u5b58TabItems\n     *\n     * @param items getMainFrame().getCenterItems() \u914d\u7f6e\n     *\/\n    public static void saveTabItems(List&lt;MainCenterItemBean&gt; items) {\n        try {\n            JSONObject rootObj = new JSONObject();\n            JSONArray centerItemsObj = new JSONArray();\n            rootObj.put(\"centerItems\", centerItemsObj);\n\n            for (MainCenterItemBean centerItem : items) {\n                JSONObject centerObj = new JSONObject();\n                centerObj.put(\"type\", centerItem.type);\n                centerObj.put(\"position\", centerItem.position);\n\n                if (centerItem.toolItems != null) {\n                    JSONArray toolItemsObj = new JSONArray();\n                    centerObj.put(\"toolItems\", toolItemsObj);\n                    for (ToolItemBean toolItem : centerItem.toolItems) {\n                        JSONObject toolObj = new JSONObject();\n                        toolObj.put(\"itemStyle\", toolItem.itemStyle);\n                        toolObj.put(\"type\", toolItem.type);\n                        {\n                            ToolProperty property = toolItem.property;\n                            JSONObject propObj = new JSONObject();\n\n                            if (property != null) {\n                                setToolPropObjVal(propObj, property);\n                            }\n                            toolObj.put(\"property\", propObj);\n                        }\n                        toolItemsObj.put(toolObj);\n                    }\n                }\n                centerItemsObj.put(centerObj);\n            }\n            Log.d(\"ddd\", rootObj.toString());\n            AppSharedPreferences.getInstance(getApplicationContext()).setString(SP_NAME, TAB_ITEMS_KEY, rootObj.toString());\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n\n    \/**\n     * \u6062\u590d\u8bbe\u7f6e\u597d\u7684tabItems\n     *\n     * @param mUiExtensionsManager UiExtensionsManager\n     *\/\n    public static void restoreItems(UIExtensionsManager mUiExtensionsManager, String tabItems) {\n        if (!AppUtil.isEmpty(tabItems)) {\n            try {\n                JSONObject rootObj = new JSONObject(tabItems);\n                JSONArray centerItemsObj = rootObj.getJSONArray(\"centerItems\");\n\n                ArrayList&lt;MainCenterItemBean&gt; items = new ArrayList&lt;&gt;();\n                for (int i = 0; i &lt; centerItemsObj.length(); i++) {\n                    JSONObject centerObj = centerItemsObj.getJSONObject(i);\n\n                    MainCenterItemBean centerItem = new MainCenterItemBean();\n                    centerItem.type = centerObj.getInt(\"type\");\n                    centerItem.position = centerObj.getInt(\"position\");\n                    if (!centerObj.has(\"toolItems\")) {\n                        items.add(centerItem);\n                        continue;\n                    }\n\n                    centerItem.toolItems = new ArrayList&lt;&gt;();\n                    JSONArray toolItemsObj = centerObj.getJSONArray(\"toolItems\");\n                    for (int toolIndex = 0; toolIndex &lt; toolItemsObj.length(); toolIndex++) {\n                        JSONObject toolObj = toolItemsObj.getJSONObject(toolIndex);\n\n                        ToolItemBean toolItem = new ToolItemBean();\n                        toolItem.itemStyle = toolObj.getInt(\"itemStyle\");\n                        toolItem.type = toolObj.getInt(\"type\");\n                        toolItem.property = new ToolProperty();\n                        {\n                            ToolProperty property = toolItem.property;\n                            JSONObject propObj = toolObj.getJSONObject(\"property\");\n\n                            if (!setToolPropVal(property, propObj)) {\n                                toolItem.property = null;\n                            }\n                        }\n                        centerItem.toolItems.add(toolItem);\n                    }\n                    items.add(centerItem);\n                }\n                mUiExtensionsManager.getMainFrame().setCenterItems(items);\n            } catch (Exception e) {\n                e.printStackTrace();\n            }\n        }\n    }\n\n\n    \/**\n     * \u8bbe\u7f6e\u5de5\u5177\u5c5e\u6027\u503c\n     *\n     * @param property \u5de5\u5177\u5c5e\u6027\n     * @param propObj  JSON\u5bf9\u8c61\n     * @return \u662f\u5426\u8bbe\u7f6e\u4e86\u5c5e\u6027\n     *\/\n    static boolean setToolPropVal(ToolProperty property, JSONObject propObj) {\n        try {\n            boolean haveProp = false;\n            if (propObj.has(\"type\")) {\n                property.type = propObj.getInt(\"type\");\n                haveProp = true;\n            }\n            if (propObj.has(\"color\")) {\n                property.color = propObj.getInt(\"color\");\n                haveProp = true;\n            }\n            if (propObj.has(\"fillColor\")) {\n                property.fillColor = propObj.getInt(\"fillColor\");\n                haveProp = true;\n            }\n            if (propObj.has(\"opacity\")) {\n                property.opacity = propObj.getInt(\"opacity\");\n                haveProp = true;\n            }\n            if (propObj.has(\"style\")) {\n                property.style = propObj.getInt(\"style\");\n                haveProp = true;\n            }\n            if (propObj.has(\"rotation\")) {\n                property.rotation = propObj.getInt(\"rotation\");\n                haveProp = true;\n            }\n            if (propObj.has(\"lineWidth\")) {\n                property.lineWidth = (float) propObj.getDouble(\"lineWidth\");\n                haveProp = true;\n            }\n            if (propObj.has(\"fontSize\")) {\n                property.fontSize = (float) propObj.getDouble(\"fontSize\");\n                haveProp = true;\n            }\n            if (propObj.has(\"fontName\")) {\n                property.fontName = propObj.getString(\"fontName\");\n                haveProp = true;\n            }\n            if (propObj.has(\"scaleFromUnitIndex\")) {\n                property.scaleFromUnitIndex = propObj.getInt(\"scaleFromUnitIndex\");\n                haveProp = true;\n            }\n            if (propObj.has(\"scaleToUnitIndex\")) {\n                property.scaleToUnitIndex = propObj.getInt(\"scaleToUnitIndex\");\n                haveProp = true;\n            }\n            if (propObj.has(\"scaleFromValue\")) {\n                property.scaleFromValue = BigDecimal.valueOf(propObj.getDouble(\"scaleFromValue\")).floatValue();\n                haveProp = true;\n            }\n            if (propObj.has(\"scaleToValue\")) {\n                property.scaleToValue = BigDecimal.valueOf(propObj.getDouble(\"scaleToValue\")).floatValue();\n                haveProp = true;\n            }\n            if (propObj.has(\"eraserShape\")) {\n                property.eraserShape = propObj.getInt(\"eraserShape\");\n                haveProp = true;\n            }\n            if (propObj.has(\"tag\")) {\n                property.mTag = propObj.get(\"tag\");\n                haveProp = true;\n            }\n            return haveProp;\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n        return false;\n    }\n\n    \/**\n     * \u8bbe\u7f6e\u5de5\u5177\u5c5e\u6027\u5bf9\u8c61\u503c\n     *\n     * @param propObj  \u5de5\u5177\u5c5e\u6027\u5bf9\u8c61\n     * @param property \u5de5\u5177\u5c5e\u6027\n     *\/\n    static void setToolPropObjVal(JSONObject propObj, ToolProperty property) {\n        try {\n            propObj.put(\"type\", property.type);\n            propObj.put(\"color\", property.color);\n            propObj.put(\"fillColor\", property.fillColor);\n            propObj.put(\"opacity\", property.opacity);\n            propObj.put(\"style\", property.style);\n            propObj.put(\"rotation\", property.rotation);\n            propObj.put(\"lineWidth\", property.lineWidth);\n            propObj.put(\"fontSize\", property.fontSize);\n            propObj.put(\"fontName\", property.fontName);\n            propObj.put(\"scaleFromUnitIndex\", property.scaleFromUnitIndex);\n            propObj.put(\"scaleToUnitIndex\", property.scaleToUnitIndex);\n            propObj.put(\"scaleFromValue\", property.scaleFromValue);\n            propObj.put(\"scaleToValue\", property.scaleToValue);\n            propObj.put(\"eraserShape\", property.eraserShape);\n            if (property.mTag != null)\n                propObj.put(\"tag\", property.mTag);\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Foxit PDF for Android\u4fdd\u5b58getCenterItems()\u83b7\u53d6\u5230\u7684\u6570\u636e\u683c\u5f0f\uff0c\u901a\u8fc7setCe [&hellip;]<\/p>\n","protected":false},"author":28,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[85],"tags":[],"class_list":["post-2555","post","type-post","status-publish","format-standard","hentry","category-rdk-android"],"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","_links":{"self":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/2555","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2555"}],"version-history":[{"count":2,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/2555\/revisions"}],"predecessor-version":[{"id":2597,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/2555\/revisions\/2597"}],"wp:attachment":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2555"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}