{"id":13645528,"url":"https://github.com/barryhappy/TContributionsView","last_synced_at":"2025-04-21T14:31:31.102Z","repository":{"id":45906736,"uuid":"74770697","full_name":"barryhappy/TContributionsView","owner":"barryhappy","description":"TContributionsView can be use for a Contributions View, like in one personal homepage of Github, and more than that. ","archived":false,"fork":false,"pushed_at":"2016-12-20T14:07:06.000Z","size":2713,"stargazers_count":510,"open_issues_count":1,"forks_count":43,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-16T12:51:34.377Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/barryhappy.png","metadata":{"files":{"readme":"README.cn.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-25T15:46:59.000Z","updated_at":"2024-11-02T04:48:59.000Z","dependencies_parsed_at":"2022-08-27T23:21:45.571Z","dependency_job_id":null,"html_url":"https://github.com/barryhappy/TContributionsView","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barryhappy%2FTContributionsView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barryhappy%2FTContributionsView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barryhappy%2FTContributionsView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barryhappy%2FTContributionsView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/barryhappy","download_url":"https://codeload.github.com/barryhappy/TContributionsView/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250070173,"owners_count":21369839,"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-08-02T01:02:36.616Z","updated_at":"2025-04-21T14:31:30.756Z","avatar_url":"https://github.com/barryhappy.png","language":"Java","funding_links":[],"categories":["其他"],"sub_categories":[],"readme":"**[【English Version Click Here】](./README.md)**\n\nTContributionsView可以用以显示类似github贡献度的View，当然，也绝不仅限于此~\n\n\u003e 👻一开始，我只是想用它来显示 Github 贡献图，所以才给它起名字叫TContributionsView，后来，我发现它似乎还有很多更有意思的玩法……\n目前想到的可以发展的应用场景有： github 贡献图、像素画、电影院选座？棋盘？……\n\n# 1. 效果图\n\n点击[这里](https://raw.githubusercontent.com/barryhappy/TContributionsView/master/apk/app-v0.2.apk)下载Demo，或者扫描二维码:  \n![QRCode](apk/qrcode.png)   \n\n![overview.png](images/overview.png)￼\n# 2. 快速开始：\n\n**引入：**\n\n```java\ncompile 'com.barryzhang:tcontributionsview:0.2'\n``` \n \n想显示这样：  \n![fast](images/14801274783930.jpg)￼  \n只需要这么写：\n\n```java\nIntArraysContributionsViewAdapter adapter = new IntArraysContributionsViewAdapter();\nInteger arrays[][] = {\n        {0, 0, 0, 1, 0, 0, 0, 0},\n        {0, 0, 1, 3, 1, 0, 0},\n        {0, 1, 2, 4, 2, 1, 0},\n        {0, 0, 1, 3, 1, 0, 0},\n        {0, 0, 0, 1, 0, 0, 0},\n};\nadapter.setArrays(arrays);\ncontributionsView.setAdapter(adapter);\n```\n😀是不是超简单？\n\n# 3. 属性\u0026Level说明\n\n![QQ20161126-1](images/QQ20161126-1.png)￼  \n每个格子都是用一个int值来表示它的Level属性。目前支持0-4五个Level的格子、以及一个用-1表示的空状态。 \n只需给不同的格子设置不同的Level，即可控制它的显示。\n\n在xml中设置颜色、尺寸、是否显示圆形等：\n```xml\n\u003ccom.barryzhang.tcontributionsview.TContributionsView\n    android:id=\"@+id/contributionsView1s\"\n    android:layout_width=\"wrap_content\"\n    android:layout_height=\"wrap_content\"\u2028    \n    app:contributions_use_circle=\"true\"\n    app:contributions_color_0=\"#E1DFCE\"\n    app:contributions_color_1=\"#FFED3B\"\n    app:contributions_color_2=\"#F4C42E\"\n    app:contributions_color_3=\"#FB8308\"\n    app:contributions_color_4=\"#040015\"\n    app:contributions_item_height=\"10dp\"\n    app:contributions_item_space=\"1dp\"\n    app:contributions_item_width=\"10dp\"/\u003e\n```  \n\n# 4. Adapter\n使用setAdapter进行数据设置：\n\n**基本用法:**\n```java\nBaseContributionsViewAdapter adapter;\n// config adapter \ncontributionsView.setAdapter(adapter);\n```\n已经内置了几种常用的Adapter，你也可以很方便地自定义自己的Adapter。 \n\n**内置的几种Adapter**\n\n* `PositionContributionsViewAdapter` ：基于(x,y)坐标\n* `AbstractArraysContributionsViewAdapter`：使用一个二维数组进行标识，用起来特别方便\n* `IntArraysContributionsViewAdapter`：继承AbstractArraysContributionsViewAdapter，使用int[][]表示数据\n* `DateContributionsAdapter`：基于日期的表示，用这个Adapter可以很方便地实现类似github个人主页的贡献度图的效果\n* `TestContributionAdapter`：一个随机level的adapter~ 一般用以演示 :-D\n\n\n## 4.1 ArraysContributionsViewAdapter\n前面的\"快速开始\"已经是一个例子，这个adapter其实还可以很方便地做一些其他的效果，比如这样：\n```java\nIntArraysContributionsViewAdapter adapter = new IntArraysContributionsViewAdapter();\nInteger arrays[][] = {\n        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},\n        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 0,},\n        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 2, 3, 4, 0,},\n        {0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 2, 3, 2, 4, 0,},\n        {0, 0, 0, 0, 0, 0, 0, 0, 4, 2, 3, 2, 4, 0, 0,},\n        {0, 0, 4, 4, 0, 0, 0, 4, 2, 3, 2, 4, 0, 0, 0,},\n        {0, 0, 4, 3, 4, 0, 4, 2, 3, 2, 4, 0, 0, 0, 0,},\n        {0, 0, 0, 4, 3, 4, 2, 3, 2, 4, 0, 0, 0, 0, 0,},\n        {0, 0, 0, 4, 3, 4, 3, 2, 4, 0, 0, 0, 0, 0, 0,},\n        {0, 0, 0, 0, 4, 3, 4, 4, 0, 0, 0, 0, 0, 0, 0,},\n        {0, 0, 0, 1, 1, 4, 3, 3, 4, 0, 0, 0, 0, 0, 0,},\n        {0, 0, 1, 1, 1, 0, 4, 4, 3, 4, 0, 0, 0, 0, 0,},\n        {4, 4, 1, 1, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0,},\n        {4, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},\n        {4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},\n};\nadapter.setArrays(arrays);\ncontributionsView.setAdapter(adapter);\n```\n\n![](images/14802568958601.jpg)￼  \n恭喜你获得成就：  \n『出击时间到！』 😁\n\n通过`AbstractArraysContributionsViewAdapter`，可以使用任意数据类型T表示等级，只需要重写它的`int mapLevel(T from)`方法即可。\n\n## 4.2 PositionContributionsViewAdapter\n\n基于(x,y)坐标，给每个格子设置显示等级，未设置的格子默认为0.\n例子：\n\n```java\nPositionContributionsViewAdapter adapter =\n        new PositionContributionsViewAdapter(8, 17);\nadapter.put(0, 4, 4);\nadapter.put(1, 4, 4);\nadapter.put(1, 5, 4);\nadapter.put(2, 5, 4);\nadapter.put(0, 10, 4);\nadapter.put(1, 10, 4);\nadapter.put(1, 9, 4);\nadapter.put(2, 9, 4);\nadapter.put(4, 7, 4);\nadapter.put(4, 3, 1);\nadapter.put(5, 4, 2);\nadapter.put(6, 5, 3);\nadapter.put(6, 6, 4);\nadapter.put(6, 7, 4);\nadapter.put(6, 8, 4);\nadapter.put(6, 9, 3);\nadapter.put(5, 10, 2);\nadapter.put(4, 11, 1);\ncontributionsView.setAdapter(adapter);\n```\n![](images/14801287752777.jpg)￼\n\n\n## 4.3 DateContributionsAdapter\n使用`DateContributionsAdapter`可以快速制作出类似github个人主页的贡献度显示效果。\n这里的row被固定为7（一周）。\n```java\nDateContributionsAdapter adapter = new DateContributionsAdapter() ;\nadapter.setWeekCount(10);\nadapter.setEndDay(\"2016-11-20\");\nadapter.put(\"2016-10-17\", 1);\nadapter.put(\"2016-10-18\", 2);\nadapter.put(\"2016-10-19\", 3);\nadapter.put(\"2016-10-20\", 4);\nadapter.put(\"2016-10-21\", 3);\nadapter.put(\"2016-10-22\", 3);\nadapter.put(\"2016-10-27\", 1);\nadapter.put(\"2016-10-28\", 1);\nadapter.put(\"2016-10-20\", 1);\nadapter.put(\"2016-11-19\", 2);\nadapter.put(\"2016-11-18\", 4);\ncontributionsView.setAdapter(adapter);\n```\n![](images/14801292366055.jpg)￼\n\n## 4.4 自定义Adapter\n\n可以很方便地进行自定义Adapter，只需要继承BaseContributionsViewAdapter，然后重写其中几个方法即可。\n```java\n// 获取行数\npublic abstract int getRowCount();\n// 获取列数\npublic abstract int getColumnCount();\n// 获取指定行列所对应的level值（-1~4）\npublic abstract int getLevel(int row, int column);\n```\n\n内置的`TestContributionAdapter`是一个很简单的示例：\n```java\n\npublic class TestContributionAdapter extends BaseContributionsViewAdapter {\n    private int row;\n    private int column;\n\n    public TestContributionAdapter() { this(7,20); }\n\n    public TestContributionAdapter(int row, int column) {\n        super();\n        this.row = row;\n        this.column = column;\n    }\n\n    @Override\n    public int getRowCount() { return this.row; }\n\n    @Override\n    public int getColumnCount() { return this.column; }\n\n    @Override\n    public int getLevel(int row, int column) {\n        return (int) (Math.random() * 100) % 10;\n    }\n}\n```\n\n\n# 5. 自定义Item样式（Canvas）\n[0.2版本添加]  \n可以通过Canvas进行绘制自定义样式的格子，Demo：  \n![CustomDra](images/CustomDraw.png)￼  \n\n```java\nTestContributionAdapter adapter = new TestContributionAdapter(5, 5);\nadapter.setOnDrawItemListener(new TContributionsView.OnDrawItemListener() {\n    // called before the default drawItem method\n    @Override\n    public boolean beforeDrawItem(RectF rect, Canvas canvas, Paint paintByLevel, int level) {\n        // True will not called default drawItem method, false otherwise.\n        return true;\n    }\n    //called after the default drawItem method\n    @Override\n    public void afterDrawItem(RectF rect, Canvas canvas, Paint paintByLevel, int level) {\n        // Draw a Regular polygon inside the giving Rect area\n        CanvasUtil.drawPolygon(rect,canvas,paintByLevel,level+3);\n    }\n});\ncontributionsView.setAdapter(adapter);\n```\n\n# 6. 更新记录\n\n## V 0.2\n添加自定义item样式的方法: `adapter.setOnDrawItemListener`\n\n## V 0.1\n基础功能\n\n \n# 7. 关于作者\n \"barryhappy2010#gmail.com\".replace(\"#\",\"@\") \n\n***\n# 8. License \n\n    Copyright 2016 Barry Zhang\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarryhappy%2FTContributionsView","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbarryhappy%2FTContributionsView","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarryhappy%2FTContributionsView/lists"}