{"id":19891124,"url":"https://github.com/xenv/jinrishici-sdk-android","last_synced_at":"2025-05-02T18:31:11.927Z","repository":{"id":47790111,"uuid":"166800774","full_name":"xenv/jinrishici-sdk-android","owner":"xenv","description":"今日诗词安卓 SDK","archived":false,"fork":false,"pushed_at":"2021-06-06T06:18:54.000Z","size":201,"stargazers_count":27,"open_issues_count":1,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-07T04:35:34.451Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xenv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-21T11:13:07.000Z","updated_at":"2024-12-10T01:42:36.000Z","dependencies_parsed_at":"2022-08-30T00:00:32.463Z","dependency_job_id":null,"html_url":"https://github.com/xenv/jinrishici-sdk-android","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xenv%2Fjinrishici-sdk-android","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xenv%2Fjinrishici-sdk-android/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xenv%2Fjinrishici-sdk-android/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xenv%2Fjinrishici-sdk-android/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xenv","download_url":"https://codeload.github.com/xenv/jinrishici-sdk-android/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252088369,"owners_count":21692783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T18:17:11.044Z","updated_at":"2025-05-02T18:31:10.991Z","avatar_url":"https://github.com/xenv.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 今日诗词安卓 SDK\n\nREADME: [English](https://github.com/xenv/jinrishici-sdk-android/blob/master/README_EN.md \"English\") | [中文](https://github.com/xenv/jinrishici-sdk-android/blob/master/README.md \"中文\")\n\n![](https://img.shields.io/github/last-commit/xenv/jinrishici-sdk-android.svg) ![](https://img.shields.io/github/release-date/xenv/jinrishici-sdk-android.svg) ![](https://img.shields.io/github/license/xenv/jinrishici-sdk-android.svg) ![](https://img.shields.io/github/stars/xenv/jinrishici-sdk-android.svg?label=Stars\u0026style=social) ![](https://img.shields.io/github/forks/xenv/jinrishici-sdk-android.svg?label=Fork\u0026style=social)\n\n## 安装\n![](https://img.shields.io/github/release/xenv/jinrishici-sdk-android.svg)\n\n通过Gradle集成：\n\n\timplementation 'com.jinrishici:android-sdk:{release-version}'\n通过Maven集成：\n\n\t\u003cdependency\u003e\n\t\t\u003cgroupId\u003ecom.jinrishici\u003c/groupId\u003e\n\t\t\u003cartifactId\u003eandroid-sdk\u003c/artifactId\u003e\n\t\t\u003cversion\u003e{release-version}\u003c/version\u003e\n\t\t\u003ctype\u003epom\u003c/type\u003e\n\t\u003c/dependency\u003e\n\n## 如何使用\n\n### 初始化\n\n在调用获取今日诗词的接口之前任何地方调用初始化方法：\n```java\n//以下两种初始化方式任选一种即可\nJinrishiciFactory.init(getContext());\nJinrishiciClient.getInstance().init(getContext());\n```\n**这一步为了初始化 `SharedPreference` 的存储，让今日诗词的 `token` 能够存储到设备上，避免重复请求 `token` 给服务端带来不必要的开销。**\n\n### 使用\n在任何你想要的地方调用函数进行请求：\n```java\n//异步方法\nJinrishiciClient client = JinrishiciClient.getInstance();\nclient.getOneSentenceBackground(new JinrishiciCallback() {\n\t@Override\n\tpublic void done(PoetySentence poetySentence) {\n\t\t//TODO do something\n\t\t//在这里进行你的逻辑处理\n\t}\n\n\t@Override\n\tpublic void error(JinrishiciRuntimeException e) {\n\t\tLog.w(TAG, \"error: code = \" + e.getCode() + \" message = \" + e.getMessage());\n\t\t//TODO do something else\n\t}\n});\n\n//同步方法，当请求出现错误时会抛出 JinrishiciRuntimeException ，请自行捕获进行处理\nPoetySentence poetySentence = JinrishiciClient.getInstance().getOneSentence();\n```\n\n### 使用项目中的HTTP请求框架发起请求（1.5版本以后提供）\n\n如果不喜欢使用 `HttpsURLConnection` 发起请求，或者希望使用项目中统一的HTTP请求框架，可以通过以下方法指定请求的具体实现。\n\n默认使用 `HttpsURLConnection` 实现。\n\n```java\nclient.setRequestClient(new RequestClient() {\n            @Override\n            public PoetyToken generateToken(String httpMethod, String httpUrl) {\n              \t//使用项目中使用的Http框架发起请求，例如OkHttp或者Retrofit\n              \t//向给定的httpUrl发送指定httpMethod的请求，然后将返回结果反序列化成PoetyToken返回即可\n              \t//该方法为同步调用，无需在此处以异步方式返回结果\n                return null;\n            }\n\n            @Override\n            public PoetySentence getPoetySentence(String httpMethod, String httpUrl, String httpHeaderName, String httpHeaderValue) {\n              \t//使用项目中使用的Http框架发起请求，例如OkHttp或者Retrofit\n              \t//向给定的httpUrl发送指定httpMethod的请求，添加指定的HttpHeaderName和HttpHeaderValue到请求Header中，然后将返回结果反序列化成PoetySentence返回即可\n              \t//该方法为同步调用，无需在此处以异步方式返回结果\n                return null;\n            }\n        });\n```\n\n\n\n### 自定义控件\n\n同样，sdk也提供自定义控件，你只需要将控件添加进布局中，无需处理相关逻辑，控件会自动请求数据并展示到控件上\n**如果使用自定义控件的方式，那么不用手动调用初始化的方法，控件会自动调用**\n```xml\n\u003ccom.jinrishici.sdk.android.view.JinrishiciTextView\n\tandroid:id=\"@+id/jinrisiciTextView\"\n\tandroid:layout_width=\"wrap_content\"\n\tandroid:layout_height=\"wrap_content\"\n\tandroid:textColor=\"@color/colorAccent\"\n\tandroid:textSize=\"18sp\" /\u003e\n\u003c!--你可以像使用TextView那样对JinrishiciTextView进行设置--\u003e\n\u003c!--如示例代码中的textColor和textSize属性--\u003e\n```\n#### 自定义控件支持的自定义属性\n\n|属性名|支持数据类型|备注|\n| :------------ | :------------ | :------------ |\n|jrsc_refresh_on_click|boolean|点击TextView时是否刷新|\n|jrsc_show_error|boolean|当请求出现错误时，是否直接将错误信息显示到TextView上|\n|jrsc_show_loading_text|boolean|是否在加载数据时显示加载文本|\n|jrsc_text_loading|string|加载数据时显示的文本|\n|jrsc_text_error|string|加载失败时显示的文本，当jrsc_show_error为false时有效|\n\n#### 自定义显示数据格式\n```java\nJinrishiciTextView jinrishiciTextView = findViewById(R.id.jinrisiciTextView);\njinrishiciTextView.setDataFormat(new JinrishiciTextView.DataFormatListener() {\n\t@Override\n\tpublic String set(PoetySentence poetySentence) {\n\t\t//TODO return String by yourself\n\t\treturn \"ip:\" + poetySentence.getIpAddress() + \"content:\" + poetySentence.getData().getContent();\n\t}\n});\n```\n**设置新的格式后会自动刷新当前显示的格式，数据不会改变**\n\n## 参考代码\n[Sample](https://github.com/xenv/jinrishici-sdk-android/blob/master/app/src/main/java/com/jinrishici/sdk/android/demo/MainActivity.java \"Sample\")\n\n\n## 混淆配置\n**1.3版本之后已经在sdk中自动添加了混淆代码，不用再手动添加混淆配置**\n**如果存在问题请手动添加以下配置**\n\n```\n# Gson uses generic type information stored in a class file when working with fields. Proguard\n# removes such information by default, so configure it to keep all of it.\n-keepattributes Signature\n# For using GSON @Expose annotation\n-keepattributes *Annotation*\n# Gson specific classes\n-keep class sun.misc.Unsafe { *; }\n-keep class com.google.gson.stream.** { *; }\n# Application classes that will be serialized/deserialized over Gson\n-keep class com.jinrishici.sdk.android.model.** { *; }\n```\n\n## License\n\nBSD 3-Clause \"New\" or \"Revised\" License\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxenv%2Fjinrishici-sdk-android","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxenv%2Fjinrishici-sdk-android","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxenv%2Fjinrishici-sdk-android/lists"}