4 |
5 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language:
2 | - java
3 |
4 | jdk:
5 | - openjdk6
6 |
7 | before_install:
8 | - if [ `uname -m` = x86_64 ]; then sudo apt-get update; fi
9 | - if [ `uname -m` = x86_64 ]; then sudo apt-get install -qq --force-yes libgd2-xpm ia32-libs ia32-libs-multiarch; fi
10 | - wget http://services.gradle.org/distributions/gradle-1.9-bin.zip
11 | - unzip -qq gradle-1.9-bin.zip
12 | - export GRADLE_HOME=`pwd`/gradle-1.9
13 | - export PATH=$GRADLE_HOME/bin:$PATH
14 | - wget http://dl.google.com/android/android-sdk_r22.3-linux.tgz
15 | - tar -zxf android-sdk_r22.3-linux.tgz
16 | - export ANDROID_HOME=`pwd`/android-sdk-linux
17 | - export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools
18 | - echo "sdk.dir=$ANDROID_HOME" > local.properties
19 | - echo yes | android update sdk -t tools,platform-tools,extra-android-support,extra-android-m2repository,android-18 --force --no-ui
20 | - wget http://dl.google.com/android/repository/build-tools_r19.0.1-linux.zip
21 | - mkdir -p $ANDROID_HOME/build-tools
22 | - unzip -qq build-tools_r19.0.1-linux.zip -d $ANDROID_HOME/build-tools/
23 | - mv $ANDROID_HOME/build-tools/android-4.4.2 $ANDROID_HOME/build-tools/19.0.1
24 |
25 | script:
26 | - "./gradlew"
27 | - "./gradlew test"
28 |
29 | install: true
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014, importre
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification,
5 | are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright notice, this
11 | list of conditions and the following disclaimer in the documentation and/or
12 | other materials provided with the distribution.
13 |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ChromeADB for Android
2 | =====================
3 |
4 | [](https://travis-ci.org/importre/chromeadb_for_android)
5 |
6 | ChromeADB for Android is helper of [ChromeADB][chromeadb_github] on [Chrome Web Store][chromeadb_store].
7 |
8 | This app is for Android Developers.
9 | Currently, this app only shows a mouse cursor.
10 |
11 |
12 | License
13 | -------
14 |
15 | See `LICENSE` file
16 |
17 |
18 |
19 | [chromeadb_github]: https://github.com/importre/chromeadb
20 | [chromeadb_store]: https://chrome.google.com/webstore/detail/chrome-adb/fhdoijgfljahinnpbolfdimpcfoicmnm
21 |
--------------------------------------------------------------------------------
/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 | mavenCentral()
6 | maven {
7 | url 'https://oss.sonatype.org/content/repositories/snapshots/'
8 | }
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:0.7.+'
12 | classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.1-SNAPSHOT'
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | mavenCentral()
19 | mavenLocal()
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/chromeadb/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/chromeadb/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'android'
2 | apply plugin: 'android-test'
3 |
4 | android {
5 | compileSdkVersion 18
6 | buildToolsVersion "19.0.1"
7 |
8 | defaultConfig {
9 | minSdkVersion 7
10 | targetSdkVersion 18
11 | versionCode 17
12 | versionName "0.1.1"
13 | }
14 |
15 | buildTypes {
16 | release {
17 | runProguard false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
19 | }
20 | }
21 |
22 | sourceSets {
23 | instrumentTest.setRoot('src/test')
24 | }
25 | }
26 |
27 | dependencies {
28 | compile 'com.android.support:support-v4:19.0.1'
29 | compile 'com.android.support:appcompat-v7:19.0.1'
30 | compile files('libs/commons-io-2.4.jar')
31 |
32 | testCompile 'junit:junit:4.10'
33 | testCompile files('libs/robolectric-2.3-SNAPSHOT.jar')
34 | testCompile 'com.squareup:fest-android:1.0.+'
35 |
36 | instrumentTestCompile 'junit:junit:4.10'
37 | instrumentTestCompile files('libs/robolectric-2.3-SNAPSHOT.jar')
38 | instrumentTestCompile 'com.squareup:fest-android:1.0.+'
39 | }
40 |
--------------------------------------------------------------------------------
/chromeadb/chromeadb.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/chromeadb/libs/commons-io-2.4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/importre/chromeadb_for_android/586311206eb7173f84d94dd39cd8584c57259982/chromeadb/libs/commons-io-2.4.jar
--------------------------------------------------------------------------------
/chromeadb/libs/robolectric-2.3-SNAPSHOT.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/importre/chromeadb_for_android/586311206eb7173f84d94dd39cd8584c57259982/chromeadb/libs/robolectric-2.3-SNAPSHOT.jar
--------------------------------------------------------------------------------
/chromeadb/proguard-rules.txt:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the ProGuard
5 | # include property in project.properties.
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 | #}
--------------------------------------------------------------------------------
/chromeadb/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
28 |
29 |
32 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/chromeadb/src/main/assets/LICENSE-2.0.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/chromeadb/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/importre/chromeadb_for_android/586311206eb7173f84d94dd39cd8584c57259982/chromeadb/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/chromeadb/src/main/java/io/github/importre/android/chromeadb/ChromeAdbService.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014, importre. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package io.github.importre.android.chromeadb;
6 |
7 | import android.annotation.SuppressLint;
8 | import android.app.Service;
9 | import android.content.Intent;
10 | import android.graphics.PixelFormat;
11 | import android.graphics.Point;
12 | import android.os.Build;
13 | import android.os.Bundle;
14 | import android.os.Handler;
15 | import android.os.IBinder;
16 | import android.os.Message;
17 | import android.view.Display;
18 | import android.view.Gravity;
19 | import android.view.WindowManager;
20 | import android.widget.ImageView;
21 | import android.widget.Toast;
22 |
23 | import org.apache.commons.io.input.Tailer;
24 | import org.apache.commons.io.input.TailerListener;
25 |
26 | import java.io.File;
27 | import java.io.IOException;
28 |
29 | public class ChromeAdbService extends Service implements TailerListener {
30 |
31 | private File mEventFile = new File("/sdcard/chromeadb.event");
32 | private ImageView mCursorImage;
33 | private String mPrevLine;
34 | private Tailer mTailer;
35 | private WindowManager mWindowManager;
36 | private WindowManager.LayoutParams mLayoutParam;
37 |
38 | @Override
39 | public int onStartCommand(Intent intent, int flags, int startId) {
40 | startTailer();
41 | addMouseCursor();
42 | setCursorPosToCenter();
43 | return super.onStartCommand(intent, flags, startId);
44 | }
45 |
46 | @Override
47 | public void onDestroy() {
48 | super.onDestroy();
49 | stopTailer();
50 | removeMouseCursor();
51 | }
52 |
53 | @Override
54 | public IBinder onBind(Intent intent) {
55 | return null;
56 | }
57 |
58 | private void addMouseCursor() {
59 | if (mCursorImage == null) {
60 | mCursorImage = new ImageView(this);
61 | mCursorImage.setImageResource(R.drawable.cursor);
62 | }
63 |
64 | if (mLayoutParam == null) {
65 | mLayoutParam = new WindowManager.LayoutParams(
66 | WindowManager.LayoutParams.WRAP_CONTENT,
67 | WindowManager.LayoutParams.WRAP_CONTENT,
68 | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
69 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
70 | | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
71 | PixelFormat.TRANSLUCENT);
72 | mLayoutParam.gravity = Gravity.LEFT | Gravity.TOP;
73 | mLayoutParam.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
74 | }
75 |
76 | if (mWindowManager == null) {
77 | mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
78 | mWindowManager.addView(mCursorImage, mLayoutParam);
79 | }
80 | }
81 |
82 | @SuppressLint("NewApi")
83 | private void setCursorPosToCenter() {
84 | if (mWindowManager == null || mCursorImage == null) {
85 | return;
86 | }
87 |
88 | Display display = mWindowManager.getDefaultDisplay();
89 | int x, y;
90 |
91 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
92 | Point size = new Point();
93 | display.getSize(size);
94 | x = size.x;
95 | y = size.y;
96 | } else {
97 | x = display.getWidth();
98 | y = display.getHeight();
99 | }
100 |
101 | move(x >> 1, y >> 1);
102 | }
103 |
104 | private void removeMouseCursor() {
105 | if (mCursorImage != null && mWindowManager != null) {
106 | mWindowManager.removeView(mCursorImage);
107 | mCursorImage = null;
108 | }
109 | }
110 |
111 | public void move(int touchX, int touchY) {
112 | if (mLayoutParam == null || mWindowManager == null || mCursorImage == null) {
113 | return;
114 | }
115 |
116 | mLayoutParam.x = touchX;
117 | mLayoutParam.y = touchY;
118 | mWindowManager.updateViewLayout(mCursorImage, mLayoutParam);
119 | }
120 |
121 | private void startTailer() {
122 | try {
123 | if (mEventFile.exists()) {
124 | mEventFile.delete();
125 | }
126 | mEventFile.createNewFile();
127 | } catch (IOException e) {
128 | Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
129 | return;
130 | }
131 |
132 | if (mTailer != null) {
133 | mTailer.stop();
134 | }
135 |
136 | mTailer = new Tailer(mEventFile, this, 10, true);
137 | Thread thread = new Thread(mTailer);
138 | thread.start();
139 | }
140 |
141 | private void stopTailer() {
142 | if (mTailer != null) {
143 | mTailer.stop();
144 | mTailer = null;
145 | }
146 |
147 | if (mEventFile != null && mEventFile.exists()) {
148 | mEventFile.delete();
149 | }
150 | }
151 |
152 | @Override
153 | public void init(Tailer tailer) {
154 | }
155 |
156 | @Override
157 | public void fileNotFound() {
158 | mTailer.stop();
159 | }
160 |
161 | @Override
162 | public void fileRotated() {
163 | }
164 |
165 | @Override
166 | public void handle(String s) {
167 | if (mPrevLine != null && mPrevLine.equals(s)) {
168 | return;
169 | }
170 |
171 | String coords = Command.getCoordinates(s);
172 | if (coords != null) {
173 | moveCursor(coords);
174 | }
175 |
176 | mPrevLine = s;
177 | }
178 |
179 | private void moveCursor(String coords) {
180 | try {
181 | final String[] points = coords.split(",");
182 | for (int i = 0; i < points.length; i += 2) {
183 | int x = Integer.parseInt(points[i]);
184 | int y = Integer.parseInt(points[i + 1]);
185 | Message msg = mHandler.obtainMessage();
186 | Bundle data = new Bundle();
187 | data.putInt("x", x);
188 | data.putInt("y", y);
189 | msg.setData(data);
190 | mHandler.sendMessage(msg);
191 | }
192 | } catch (Exception e) {
193 | }
194 | }
195 |
196 | private final Handler mHandler = new Handler() {
197 |
198 | @Override
199 | public void handleMessage(Message msg) {
200 | Bundle data = msg.getData();
201 | if (data != null) {
202 | int x = data.getInt("x", 0);
203 | int y = data.getInt("y", 0);
204 | move(x, y);
205 | }
206 | }
207 | };
208 |
209 | @Override
210 | public void handle(Exception e) {
211 | }
212 | }
213 |
--------------------------------------------------------------------------------
/chromeadb/src/main/java/io/github/importre/android/chromeadb/Command.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014, importre. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package io.github.importre.android.chromeadb;
6 |
7 | import android.text.TextUtils;
8 |
9 | import java.util.regex.Pattern;
10 |
11 | public class Command {
12 | public static final String sCmdMove = "move ";
13 |
14 | private static final Pattern sCoordPattern = Pattern.compile("\\d+,\\d+(,\\d+,\\d+)*");
15 |
16 | /**
17 | * Returns coordinate list
18 | *
19 | * @param s line
20 | * @return returns coordinate list if command is move, otherwise returns null
21 | */
22 | public static String getCoordinates(String s) {
23 | if (!TextUtils.isEmpty(s)) {
24 | s = s.trim();
25 | if (s.startsWith(Command.sCmdMove)) {
26 | s = s.substring(Command.sCmdMove.length());
27 | if (Command.sCoordPattern.matcher(s).matches()) {
28 | return s;
29 | }
30 | }
31 | }
32 | return null;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/chromeadb/src/main/java/io/github/importre/android/chromeadb/HelpFragment.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014, importre. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package io.github.importre.android.chromeadb;
6 |
7 | import android.os.Bundle;
8 | import android.support.v4.app.Fragment;
9 | import android.text.Html;
10 | import android.text.method.LinkMovementMethod;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.widget.TextView;
15 |
16 | public class HelpFragment extends Fragment {
17 |
18 | public static HelpFragment newInstance() {
19 | return new HelpFragment();
20 | }
21 |
22 | @Override
23 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
24 | View view = inflater.inflate(R.layout.fragment_help, container, false);
25 | setContents(view);
26 | return view;
27 | }
28 |
29 | private void setContents(View view) {
30 | TextView see = (TextView) view.findViewById(R.id.see_chromeadb);
31 | see.setText(Html.fromHtml(getActivity().getString(R.string.help_desc2)));
32 | see.setMovementMethod(LinkMovementMethod.getInstance());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/chromeadb/src/main/java/io/github/importre/android/chromeadb/InfoFragment.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014, importre. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package io.github.importre.android.chromeadb;
6 |
7 | import android.content.Intent;
8 | import android.content.pm.PackageInfo;
9 | import android.content.pm.PackageManager;
10 | import android.os.Bundle;
11 | import android.support.v4.app.Fragment;
12 | import android.support.v4.app.FragmentActivity;
13 | import android.view.LayoutInflater;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 | import android.widget.Button;
17 | import android.widget.Toast;
18 |
19 | import java.util.Locale;
20 |
21 | public class InfoFragment extends Fragment implements View.OnClickListener {
22 |
23 | private Button mBtnVersion;
24 | private Button mBtnFeedback;
25 | private Button mBtnLicense;
26 |
27 | public static InfoFragment newInstance() {
28 | return new InfoFragment();
29 | }
30 |
31 | @Override
32 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
33 | View view = inflater.inflate(R.layout.fragment_info, container, false);
34 | initButtons(view);
35 | setVersion();
36 | return view;
37 | }
38 |
39 | private void initButtons(View view) {
40 | mBtnVersion = (Button) view.findViewById(R.id.version);
41 | mBtnVersion.setOnClickListener(this);
42 | mBtnFeedback = (Button) view.findViewById(R.id.feedback);
43 | mBtnFeedback.setOnClickListener(this);
44 | mBtnLicense = (Button) view.findViewById(R.id.license);
45 | mBtnLicense.setOnClickListener(this);
46 | }
47 |
48 | private void setVersion() {
49 | try {
50 | FragmentActivity activity = getActivity();
51 | PackageManager pm = activity.getPackageManager();
52 | PackageInfo info = pm.getPackageInfo(activity.getPackageName(), PackageManager.GET_ACTIVITIES);
53 | String ver = String.format(Locale.US, "%s (Build %d)", info.versionName, info.versionCode);
54 | mBtnVersion.setText(ver);
55 | } catch (Exception e) {
56 | }
57 | }
58 |
59 | @Override
60 | public void onClick(View v) {
61 | switch (v.getId()) {
62 | case R.id.version:
63 | break;
64 | case R.id.feedback:
65 | sendFeedback();
66 | break;
67 | case R.id.license:
68 | showOssLicenses();
69 | break;
70 | default:
71 | // do nothing
72 | break;
73 | }
74 | }
75 |
76 | private void sendFeedback() {
77 | FragmentActivity activity = getActivity();
78 | Intent intent = new Intent(Intent.ACTION_SEND);
79 | intent.setType(activity.getString(R.string.feedback_type));
80 | intent.putExtra(Intent.EXTRA_EMAIL, new String[]{activity.getString(R.string.chromeadb_gmail)});
81 | intent.putExtra(Intent.EXTRA_SUBJECT, activity.getString(R.string.feedback_subject));
82 |
83 | try {
84 | startActivity(Intent.createChooser(intent, activity.getString(R.string.send_feedback)));
85 | } catch (Exception e) {
86 | Toast.makeText(activity, activity.getString(R.string.feedback_error_msg), Toast.LENGTH_SHORT).show();
87 | }
88 | }
89 |
90 | private void showOssLicenses() {
91 | FragmentActivity activity = getActivity();
92 | Intent intent = new Intent(activity, OssLicenseActivity.class);
93 | activity.startActivity(intent);
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/chromeadb/src/main/java/io/github/importre/android/chromeadb/MainActivity.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014, importre. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package io.github.importre.android.chromeadb;
6 |
7 | import android.os.Bundle;
8 | import android.support.v7.app.ActionBarActivity;
9 |
10 | public class MainActivity extends ActionBarActivity {
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_main);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/chromeadb/src/main/java/io/github/importre/android/chromeadb/MainFragment.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014, importre. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package io.github.importre.android.chromeadb;
6 |
7 | import android.os.Bundle;
8 | import android.support.v4.app.Fragment;
9 | import android.support.v4.app.FragmentTransaction;
10 | import android.support.v4.view.PagerAdapter;
11 | import android.support.v4.view.ViewPager;
12 | import android.support.v7.app.ActionBar;
13 | import android.view.LayoutInflater;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 |
17 | public class MainFragment extends Fragment
18 | implements ViewPager.OnPageChangeListener, ActionBar.TabListener {
19 |
20 | private ActionBar mActionBar;
21 | private PagerAdapter mViewPagerAdapter;
22 | private ViewPager mViewPager;
23 |
24 | @Override
25 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
26 | View view = inflater.inflate(R.layout.fragment_main, container, false);
27 | initView(view);
28 | return view;
29 | }
30 |
31 | private void initView(View view) {
32 | mViewPagerAdapter = new MainViewPagerAdapter(getFragmentManager());
33 |
34 | mViewPager = (ViewPager) view.findViewById(R.id.viewpager);
35 | mViewPager.setAdapter(mViewPagerAdapter);
36 | mViewPager.setOnPageChangeListener(this);
37 |
38 | String[] titles = getResources().getStringArray(R.array.main_titles);
39 | mActionBar = ((MainActivity) getActivity()).getSupportActionBar();
40 | mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
41 | for (int i = 0; i < MainViewPagerAdapter.COUNTS; i++) {
42 | mActionBar.addTab(mActionBar.newTab().setText(titles[i]).setTabListener(this));
43 | }
44 | }
45 |
46 | @Override
47 | public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
48 | mViewPager.setCurrentItem(tab.getPosition());
49 | }
50 |
51 | @Override
52 | public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
53 | }
54 |
55 | @Override
56 | public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
57 | }
58 |
59 | @Override
60 | public void onPageScrolled(int i, float v, int i2) {
61 | }
62 |
63 | @Override
64 | public void onPageSelected(int i) {
65 | mActionBar.setSelectedNavigationItem(i);
66 | }
67 |
68 | @Override
69 | public void onPageScrollStateChanged(int i) {
70 | }
71 | }
72 |
73 |
--------------------------------------------------------------------------------
/chromeadb/src/main/java/io/github/importre/android/chromeadb/MainViewPagerAdapter.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014, importre. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package io.github.importre.android.chromeadb;
6 |
7 | import android.support.v4.app.Fragment;
8 | import android.support.v4.app.FragmentManager;
9 | import android.support.v4.app.FragmentStatePagerAdapter;
10 |
11 | public class MainViewPagerAdapter extends FragmentStatePagerAdapter {
12 |
13 | public static final int COUNTS = 2;
14 |
15 | public MainViewPagerAdapter(FragmentManager fm) {
16 | super(fm);
17 | }
18 |
19 | @Override
20 | public Fragment getItem(int i) {
21 | switch (i) {
22 | case 0:
23 | return HelpFragment.newInstance();
24 | case 1:
25 | return InfoFragment.newInstance();
26 | default:
27 | throw new RuntimeException("unexpected position");
28 | }
29 | }
30 |
31 | @Override
32 | public int getCount() {
33 | return MainViewPagerAdapter.COUNTS;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/chromeadb/src/main/java/io/github/importre/android/chromeadb/OssLicenseActivity.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014, importre. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package io.github.importre.android.chromeadb;
6 |
7 | import android.os.Bundle;
8 | import android.support.v4.app.NavUtils;
9 | import android.support.v7.app.ActionBar;
10 | import android.support.v7.app.ActionBarActivity;
11 | import android.view.MenuItem;
12 |
13 | public class OssLicenseActivity extends ActionBarActivity {
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_oss_license);
19 |
20 | if (savedInstanceState == null) {
21 | getSupportFragmentManager().beginTransaction()
22 | .add(R.id.container, new OssLicenseFragment())
23 | .commit();
24 | }
25 |
26 | ActionBar actionBar = getSupportActionBar();
27 | actionBar.setDisplayHomeAsUpEnabled(true);
28 | }
29 |
30 | @Override
31 | public boolean onOptionsItemSelected(MenuItem item) {
32 | switch (item.getItemId()) {
33 | case android.R.id.home:
34 | NavUtils.navigateUpFromSameTask(this);
35 | return true;
36 | default:
37 | return super.onOptionsItemSelected(item);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/chromeadb/src/main/java/io/github/importre/android/chromeadb/OssLicenseFragment.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014, importre. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package io.github.importre.android.chromeadb;
6 |
7 | import android.os.Bundle;
8 | import android.support.v4.app.Fragment;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.webkit.WebSettings;
13 | import android.webkit.WebView;
14 |
15 | import java.io.BufferedReader;
16 | import java.io.IOException;
17 | import java.io.InputStream;
18 | import java.io.InputStreamReader;
19 |
20 | public class OssLicenseFragment extends Fragment {
21 |
22 | @Override
23 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
24 | View rootView = inflater.inflate(R.layout.fragment_oss_license, container, false);
25 | setContents(rootView);
26 | return rootView;
27 | }
28 |
29 | private void setContents(View rootView) {
30 | String str;
31 | StringBuilder buf = new StringBuilder("