├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── lizhengxian
│ │ └── top
│ │ └── bigbang
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── lizhengxian
│ │ │ └── top
│ │ │ └── bigbang
│ │ │ ├── BigBangService.java
│ │ │ ├── activity
│ │ │ ├── BigBangActivity.java
│ │ │ └── SettingActivity.java
│ │ │ ├── tool
│ │ │ ├── Constant.java
│ │ │ ├── HTTPRequest.java
│ │ │ └── IResponse.java
│ │ │ └── widget
│ │ │ ├── AutoExpandLinearLayout.java
│ │ │ └── BangWordView.java
│ └── res
│ │ ├── drawable
│ │ ├── checkbox_normal_shape.xml
│ │ ├── checkbox_pressed_shape.xml
│ │ └── checkbox_selector.xml
│ │ ├── layout
│ │ ├── activity_bigbang.xml
│ │ ├── activity_main.xml
│ │ └── divide.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── lizhengxian
│ └── top
│ └── bigbang
│ └── ExampleUnitTest.java
├── build.gradle
├── config
└── gradle-wrapper.properties
├── debug_apk
└── app-debug.apk
├── gradle.properties
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 | *.mp4
11 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BigBang
2 | ## 说明
3 | 受锤子M1发布会功能演示的启发,正好看讯飞SDK时发现他们有和哈工大合作的[分词的SDK](http://www.ltp-cloud.com/),何不借来一用,直接在普通手机上实现BigBang呢?
4 |
5 | ## 应用形态
6 | 模仿锤子M1新出的BigBang功能,利用Android Service在后台监听剪切板,当用户在系统任一地方长按文本点击复制的时候,后台自动弹出界面,把词炸开,选中想要的分词,可以复制成一句话。
7 |
8 | ## 开发进度
9 | 2016/10/22 23:27 init commit
10 |
11 | 2016/10/23 01:00 分词接口请求通过
12 |
13 | 2016/10/23 05:40 基本功能完成,主路径测试通过
14 |
15 | ## 最终效果
16 | 
17 |
18 | (如果效果gif图裂请刷新)
19 |
20 | ## 测试包
21 | 测试包[下载链接](http://www.lizhengxian.top/BigBang/debug_apk/app-debug.apk)
22 |
23 | ## 注意
24 | 云服务的免费接口有每日流量限制,如果遇服务器返回错误503,说明今日流量已用尽。希望大家仅做学习使用。
25 | 项目正在完善当中,如有疑问和bug欢迎交流,作者博客:[https://juejin.im/user/57e32a8dc4c971005f4b4daa](https://juejin.im/user/57e32a8dc4c971005f4b4daa)
26 |
27 | ## License
28 |
29 | Copyright (C) 2016 The Android Open Source Project
30 |
31 | Licensed under the Apache License, Version 2.0 (the "License");
32 | you may not use this file except in compliance with the License.
33 | You may obtain a copy of the License at
34 |
35 | http://www.apache.org/licenses/LICENSE-2.0
36 |
37 | Unless required by applicable law or agreed to in writing, software
38 | distributed under the License is distributed on an "AS IS" BASIS,
39 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40 | See the License for the specific language governing permissions and
41 | limitations under the License.
42 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "24.0.1"
6 | defaultConfig {
7 | applicationId "lizhengxian.top.bigbang"
8 | minSdkVersion 16
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | testCompile 'junit:junit:4.12'
28 | compile 'com.android.support:appcompat-v7:25.0.0'
29 | }
30 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/jsonlee/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/lizhengxian/top/bigbang/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package lizhengxian.top.bigbang;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("lizhengxian.top.bigbang", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
12 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
25 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/java/lizhengxian/top/bigbang/BigBangService.java:
--------------------------------------------------------------------------------
1 | package lizhengxian.top.bigbang;
2 |
3 | import android.app.Notification;
4 | import android.app.PendingIntent;
5 | import android.app.Service;
6 | import android.content.ClipboardManager;
7 | import android.content.Context;
8 | import android.content.Intent;
9 | import android.graphics.BitmapFactory;
10 | import android.os.IBinder;
11 |
12 | import lizhengxian.top.bigbang.activity.BigBangActivity;
13 | import lizhengxian.top.bigbang.activity.SettingActivity;
14 | import lizhengxian.top.bigbang.tool.Constant;
15 |
16 | import static android.app.PendingIntent.getActivity;
17 |
18 | /**
19 | * 后台监听剪切板事件,有复制就BigBang一下
20 | */
21 | public class BigBangService extends Service {
22 |
23 | public static final int NOTIFICATION_ID = 110;
24 |
25 | public BigBangService() {
26 | }
27 |
28 | @Override
29 | public IBinder onBind(Intent intent) {
30 | // TODO: Return the communication channel to the service.
31 | throw new UnsupportedOperationException("Not yet implemented");
32 | }
33 |
34 | @Override
35 | public int onStartCommand(Intent intent, int flags, int startId) {
36 | startForeService();
37 | listenClipboard();
38 | return super.onStartCommand(intent, flags, startId);
39 | }
40 |
41 | /**
42 | * 通知栏常驻,提醒用户BigBang正在后台提供服务
43 | */
44 | private void startForeService() {
45 | Notification.Builder builder = new Notification.Builder(this.getApplicationContext()); //获取一个Notification构造器
46 | Intent nfIntent = new Intent(this, SettingActivity.class);
47 | builder.setContentIntent(PendingIntent.getActivity(this, 0, nfIntent, PendingIntent.FLAG_UPDATE_CURRENT)) // 设置PendingIntent
48 | .setLargeIcon(BitmapFactory.decodeResource(this.getResources(),
49 | R.mipmap.ic_launcher)) // 设置下拉列表中的图标(大图标)
50 | .setContentTitle("BigBang正在后台运行") // 设置下拉列表里的标题
51 | .setSmallIcon(R.mipmap.ic_launcher) // 设置状态栏内的小图标
52 | .setContentText("复制想要bang的内容到剪切板, BigBang帮你处理") // 设置上下文内容
53 | .setWhen(System.currentTimeMillis()); // 设置该通知发生的时间
54 | Notification notification = builder.build(); // 获取构建好的Notification
55 |
56 | startForeground(NOTIFICATION_ID, notification);// 开始前台服务
57 | }
58 |
59 | /**
60 | * 监听剪切板
61 | */
62 | private void listenClipboard() {
63 | final ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
64 | clipboard.addPrimaryClipChangedListener(new ClipboardManager.OnPrimaryClipChangedListener() {
65 | @Override
66 | public void onPrimaryClipChanged() {
67 | if (BigBangActivity.isShowing) {
68 | //是BigBang复制的,复制结束了就发广播关闭
69 | sendBroadcast(new Intent(Constant.FINISH_BIGBANG_ACTIVITY));
70 | } else {
71 | Intent intent = new Intent(getApplication(), BigBangActivity.class);
72 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
73 | intent.putExtra(Constant.CLIPBOARD_TEXT, clipboard.getText().toString());
74 | startActivity(intent);
75 | }
76 | }
77 | });
78 | }
79 |
80 | @Override
81 | public void onDestroy() {
82 | stopForeground(true);// 停止前台服务--参数:表示是否移除之前的通知
83 | super.onDestroy();
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/app/src/main/java/lizhengxian/top/bigbang/activity/BigBangActivity.java:
--------------------------------------------------------------------------------
1 | package lizhengxian.top.bigbang.activity;
2 |
3 | import android.app.Activity;
4 | import android.content.BroadcastReceiver;
5 | import android.content.ClipboardManager;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.content.IntentFilter;
9 | import android.os.Bundle;
10 | import android.text.TextUtils;
11 | import android.view.View;
12 | import android.widget.Button;
13 | import android.widget.CheckBox;
14 | import android.widget.Toast;
15 |
16 | import lizhengxian.top.bigbang.R;
17 | import lizhengxian.top.bigbang.tool.Constant;
18 | import lizhengxian.top.bigbang.tool.HTTPRequest;
19 | import lizhengxian.top.bigbang.tool.IResponse;
20 | import lizhengxian.top.bigbang.widget.AutoExpandLinearLayout;
21 | import lizhengxian.top.bigbang.widget.BangWordView;
22 |
23 | /**
24 | * Created by lizhengxian on 2016/10/23.
25 | * 浮窗Activity,用来展示BigBang结果
26 | */
27 |
28 | public class BigBangActivity extends Activity implements View.OnClickListener {
29 | AutoExpandLinearLayout mAutoLayout;
30 | Button mCopyBtn;
31 | Button mCancelBtn;
32 | public static boolean isShowing = false;
33 |
34 | @Override
35 | protected void onStart() {
36 | super.onStart();
37 | isShowing = true;
38 | }
39 |
40 | @Override
41 | protected void onStop() {
42 | isShowing = false;
43 | super.onStop();
44 | }
45 |
46 | @Override
47 | protected void onCreate(Bundle savedInstanceState) {
48 | super.onCreate(savedInstanceState);
49 | setContentView(R.layout.activity_bigbang);
50 | registerReceiver(receiver,new IntentFilter(Constant.FINISH_BIGBANG_ACTIVITY));
51 | mAutoLayout = (AutoExpandLinearLayout) findViewById(R.id.auto_layout);
52 | mCopyBtn = (Button) findViewById(R.id.btn_copy);
53 | mCancelBtn = (Button)findViewById(R.id.btn_cancel);
54 | mCopyBtn.setOnClickListener(this);
55 | mCancelBtn.setOnClickListener(this);
56 | String text = getIntent().getStringExtra(Constant.CLIPBOARD_TEXT);
57 | requestServe(text);
58 | }
59 |
60 | protected void requestServe(String text) {
61 | HTTPRequest.getSplitChar(text, new IResponse() {
62 | @Override
63 | public void finish(final String[] words) {
64 | if (words != null) {
65 | runOnUiThread(new Runnable() {
66 | @Override
67 | public void run() {
68 | for (String word : words) {
69 | BangWordView bangWordView = new BangWordView(getApplication(),word);
70 | mAutoLayout.addView(bangWordView);
71 | }
72 | }
73 | });
74 | }
75 | }
76 |
77 | @Override
78 | public void failure(final String errorMsg) {
79 | runOnUiThread(new Runnable() {
80 | @Override
81 | public void run() {
82 | Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_SHORT).show();
83 | }
84 | });
85 | }
86 | });
87 | }
88 |
89 | @Override
90 | public void onClick(View view) {
91 | switch (view.getId()){
92 | case R.id.btn_cancel:
93 | finish();
94 | break;
95 | case R.id.btn_copy:
96 | int count = mAutoLayout.getChildCount();
97 | StringBuilder builder = new StringBuilder();
98 | for (int i = 0; i < count; i++) {
99 | CheckBox checkBox = (CheckBox) mAutoLayout.getChildAt(i);
100 | if (checkBox.isChecked()){
101 | builder.append(checkBox.getText());
102 | }
103 | }
104 | String str = builder.toString();
105 | if(TextUtils.isEmpty(str)){
106 | Toast.makeText(getApplicationContext(),"没有选中词组",Toast.LENGTH_SHORT).show();
107 | }else{
108 | Toast.makeText(getApplicationContext(),"["+str+"] 已经复制到剪切板",Toast.LENGTH_SHORT).show();
109 | ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
110 | clipboardManager.setText(str);
111 | }
112 | break;
113 | }
114 | }
115 |
116 | @Override
117 | protected void onDestroy() {
118 | unregisterReceiver(receiver);
119 | super.onDestroy();
120 | }
121 |
122 | BroadcastReceiver receiver = new BroadcastReceiver() {
123 | @Override
124 | public void onReceive(Context context, Intent intent) {
125 | finish();
126 | }
127 | };
128 | }
129 |
--------------------------------------------------------------------------------
/app/src/main/java/lizhengxian/top/bigbang/activity/SettingActivity.java:
--------------------------------------------------------------------------------
1 | package lizhengxian.top.bigbang.activity;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.Button;
9 | import android.widget.CompoundButton;
10 | import android.widget.EditText;
11 | import android.widget.Switch;
12 | import android.widget.Toast;
13 |
14 | import lizhengxian.top.bigbang.BigBangService;
15 | import lizhengxian.top.bigbang.tool.Constant;
16 | import lizhengxian.top.bigbang.tool.HTTPRequest;
17 | import lizhengxian.top.bigbang.tool.IResponse;
18 | import lizhengxian.top.bigbang.R;
19 |
20 | public class SettingActivity extends Activity implements CompoundButton.OnCheckedChangeListener,View.OnClickListener {
21 | String TAG = getClass().getName();
22 |
23 | ViewGroup mRootView ;
24 | Switch mRunSwitch;
25 | Button mTestBtn;
26 | EditText mTestText;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_main);
32 | mRootView = (ViewGroup) findViewById(R.id.root_view);
33 | mRunSwitch = (Switch) findViewById(R.id.sw_run);
34 | mRunSwitch.setOnCheckedChangeListener(this);
35 | mRunSwitch.setChecked(true);
36 | mTestBtn = (Button)findViewById(R.id.test_ws);
37 | mTestBtn.setOnClickListener(this);
38 | mTestText = (EditText) findViewById(R.id.test_text);
39 | }
40 |
41 | @Override
42 | public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
43 | if (b){
44 | startService(new Intent(this,BigBangService.class));
45 | }else{
46 | stopService(new Intent(this,BigBangService.class));
47 | }
48 | }
49 |
50 | @Override
51 | public void onClick(View view) {
52 | String text = mTestText.getText().toString();
53 | Intent intent = new Intent(getApplication(), BigBangActivity.class);
54 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
55 | intent.putExtra(Constant.CLIPBOARD_TEXT,text);
56 | startActivity(intent);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/java/lizhengxian/top/bigbang/tool/Constant.java:
--------------------------------------------------------------------------------
1 | package lizhengxian.top.bigbang.tool;
2 |
3 | /**
4 | * Created by lizhengxian on 2016/10/23.
5 | */
6 |
7 | public class Constant {
8 | public static final String CLIPBOARD_TEXT = "clipboard_text";
9 | public static final String FINISH_BIGBANG_ACTIVITY = "top.lizhengxian.bigbang.finish_bigbang_activity";
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/lizhengxian/top/bigbang/tool/HTTPRequest.java:
--------------------------------------------------------------------------------
1 | package lizhengxian.top.bigbang.tool;
2 |
3 | import java.io.ByteArrayOutputStream;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.io.UnsupportedEncodingException;
7 | import java.net.HttpURLConnection;
8 | import java.net.URL;
9 | import java.net.URLEncoder;
10 | import java.util.concurrent.ExecutorService;
11 | import java.util.concurrent.Executors;
12 |
13 | /**
14 | * Created by lizhengxian on 2016/10/22.
15 | */
16 |
17 | public class HTTPRequest {
18 | private static final String SPLIT_CHAR = " ";
19 | private static final ExecutorService executor = Executors.newSingleThreadExecutor();
20 | /**
21 | * 使用get方式请求分词服务
22 | *
23 | * @param text 原始中文字符串
24 | * @return 分词词组
25 | */
26 | public static void getSplitChar(final String text,final IResponse response) {
27 | executor.submit(new Runnable() {
28 | @Override
29 | public void run() {
30 | String result = null;
31 | HttpURLConnection conn = null;
32 | String utf8string = "";
33 | try {
34 | utf8string = URLEncoder.encode(text,"UTF-8");
35 | } catch (UnsupportedEncodingException e) {
36 | e.printStackTrace();
37 | }
38 | StringBuilder urlBuilder = new StringBuilder("http://api.ltp-cloud.com/analysis")
39 | .append('?').append("api_key").append('=').append("D8W3a5b4fvVngvMYrx0cfHOj5bKlrXlx6iiwsGNn")
40 | .append('&').append("text").append('=').append(utf8string)
41 | .append('&').append("pattern").append('=').append("ws")
42 | .append('&').append("format").append('=').append("plain");
43 | String url = urlBuilder.toString();
44 | try {
45 | // 利用string url构建URL对象
46 | URL mURL = new URL(url);
47 | conn = (HttpURLConnection) mURL.openConnection();
48 |
49 | conn.setRequestMethod("GET");
50 | conn.setReadTimeout(5000);
51 | conn.setConnectTimeout(10000);
52 |
53 | int responseCode = conn.getResponseCode();
54 | if (responseCode == 200) {
55 | InputStream is = conn.getInputStream();
56 | result = getStringFromInputStream(is);
57 | if (response != null) {
58 | response.finish(result == null ? null : result.split(SPLIT_CHAR));
59 | }
60 | } else {
61 | if (response != null){
62 | response.failure("访问失败" + responseCode + ':' + conn.getResponseMessage());
63 | }
64 | }
65 | } catch (Exception e) {
66 | if (response != null){
67 | response.failure(e.toString());
68 | }
69 | e.printStackTrace();
70 | } finally {
71 | if (conn != null) {
72 | conn.disconnect();
73 | }
74 | }
75 | }
76 | });
77 | }
78 |
79 | /**
80 | * 读取流,返回字符串
81 | * @param is
82 | * @return
83 | * @throws IOException
84 | */
85 | private static String getStringFromInputStream(InputStream is)
86 | throws IOException {
87 | ByteArrayOutputStream os = new ByteArrayOutputStream();
88 | byte[] buffer = new byte[1024];
89 | int len;
90 | while ((len = is.read(buffer)) != -1) {
91 | os.write(buffer, 0, len);
92 | }
93 | is.close();
94 | String state = os.toString();// 把流中的数据转换成字符串,采用的编码是utf-8(模拟器默认编码)
95 | os.close();
96 | return state;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/app/src/main/java/lizhengxian/top/bigbang/tool/IResponse.java:
--------------------------------------------------------------------------------
1 | package lizhengxian.top.bigbang.tool;
2 |
3 | /**
4 | * Created by lizhengxian on 2016/10/23.
5 | */
6 |
7 | public interface IResponse {
8 | void finish(String[] words);
9 | void failure(String errorMsg);
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/lizhengxian/top/bigbang/widget/AutoExpandLinearLayout.java:
--------------------------------------------------------------------------------
1 | package lizhengxian.top.bigbang.widget;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | /**
9 | * 根据按钮多少自动换行的ViewGroup
10 | */
11 | public class AutoExpandLinearLayout extends ViewGroup {
12 | private static final int MARGIN = 5;
13 | private int maxWidth;// 可使用的最大宽度
14 | public AutoExpandLinearLayout(Context context) {
15 | super(context);
16 | }
17 | public AutoExpandLinearLayout(Context context, AttributeSet attrs) {
18 | super(context, attrs);
19 | }
20 | public AutoExpandLinearLayout(Context context, AttributeSet attrs,
21 | int defStyle) {
22 | super(context, attrs, defStyle);
23 | }
24 | @Override
25 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
26 | maxWidth = MeasureSpec.getSize(widthMeasureSpec);
27 | int containorHeight = 0;// 容器的高度,也就是本布局的高度。初始化赋值为0.
28 | int count = getChildCount();// 获取该布局内子组件的个数
29 | for (int i = 0; i < count; i++) {
30 | View view = getChildAt(i);
31 | /**
32 | * measure(int widthMeasureSpec,int
33 | * heightMeasureSpec)用于设置子组件显示模式.有三个值:
34 | * MeasureSpec.AT_MOST 该组件可以设置自己的大小,但是最大不能超过其父组件的限定
35 | * MeasureSpec.EXACTLY 无论该组件设置大小是多少,都只能按照父组件限制的大小来显示
36 | * MeasureSpec.UNSPECIFIED 该组件不受父组件的限制,可以设置任意大小
37 | */
38 | view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
39 | // 把每个子组件的高度相加就是该组件要显示的高度。
40 | containorHeight += view.getMeasuredHeight();
41 | }
42 | setMeasuredDimension(maxWidth, containorHeight);// onMeasure方法的关键代码,该句设置父容器的大小。
43 | }
44 | @Override
45 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
46 | int childCount = getChildCount();// 获取子组件数
47 | int row = 1;// 子组件行数,初始化赋值为1
48 | int left = 0;// 子组件的左边“坐标”
49 | int right = 0;// 子组件的右边“坐标”
50 | int top = 0;// 子组件的顶部“坐标”
51 | int bottom = 0;// 子组件的底部“坐标”
52 | int p = getPaddingLeft();// 在父组件中设置的padding属性的值,该值显然也会影响到子组件在屏幕的显示位置
53 | for (int i = 0; i < childCount; i++) {
54 | View view = getChildAt(i);
55 | int width = view.getMeasuredWidth();// 测量子组件的宽
56 | int height = view.getMeasuredHeight();// 测量子组件的高
57 | left = p + right;// ---------------------------------------------------备注1
58 | right = left + width;// -----------------------------------------------备注2
59 | top = p * row + height * (row - 1);// ---------------------------------备注3
60 | bottom = top + height;// ----------------------------------------------备注4
61 | if (right > maxWidth) {
62 | row++;
63 | left = 0;//每次换行后要将子组件左边“坐标”与右边“坐标”重新初始化
64 | right = 0;
65 | left = p + right ;
66 | right = left + width;
67 | top = p * row + height * (row - 1);
68 | bottom = top + height;
69 | }
70 | view.layout(left, top, right, bottom);// 最后按照计算出来的“坐标”将子组件放在父容器内
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/lizhengxian/top/bigbang/widget/BangWordView.java:
--------------------------------------------------------------------------------
1 | package lizhengxian.top.bigbang.widget;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.os.Build;
6 | import android.support.annotation.RequiresApi;
7 | import android.util.AttributeSet;
8 | import android.view.ViewGroup;
9 | import android.widget.CheckBox;
10 |
11 | import lizhengxian.top.bigbang.R;
12 |
13 | /**
14 | * Created by lizhengxian on 2016/10/23.
15 | * 显示分割后的词语的控件
16 | */
17 |
18 | public class BangWordView extends CheckBox {
19 | public BangWordView(Context context,String text) {
20 | super(context);
21 | ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
22 | setBackgroundResource(R.drawable.checkbox_selector);
23 | setButtonDrawable(null);
24 | setLayoutParams(params);
25 | setText(text);
26 | setTextColor(Color.BLACK);
27 | setTextSize(18);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/checkbox_normal_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
21 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/checkbox_pressed_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
21 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/checkbox_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_bigbang.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
33 |
38 |
39 |
45 |
51 |
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
20 |
21 |
24 |
28 |
33 |
34 |
35 |
41 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/divide.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Levi-Ackerman/BigBang/a591a29ffd234cbed25605665dfcd788344e2397/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Levi-Ackerman/BigBang/a591a29ffd234cbed25605665dfcd788344e2397/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Levi-Ackerman/BigBang/a591a29ffd234cbed25605665dfcd788344e2397/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Levi-Ackerman/BigBang/a591a29ffd234cbed25605665dfcd788344e2397/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Levi-Ackerman/BigBang/a591a29ffd234cbed25605665dfcd788344e2397/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BigBang
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/test/java/lizhengxian/top/bigbang/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package lizhengxian.top.bigbang;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/config/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/debug_apk/app-debug.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Levi-Ackerman/BigBang/a591a29ffd234cbed25605665dfcd788344e2397/debug_apk/app-debug.apk
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------