├── .gitignore
├── LICENSE.txt
├── README.md
├── build.gradle
├── cooper
├── .gitignore
├── build.gradle
└── src
│ ├── instrumentTest
│ └── java
│ │ └── com
│ │ └── dconstructing
│ │ └── cooper
│ │ └── test
│ │ └── BasicTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── dconstructing
│ │ └── cooper
│ │ ├── ConnectionActivity.java
│ │ ├── MainActivity.java
│ │ ├── adapters
│ │ └── ConnectionAdapter.java
│ │ ├── contentproviders
│ │ └── ConnectionsContentProvider.java
│ │ ├── database
│ │ └── CooperOpenHelper.java
│ │ ├── fragments
│ │ ├── ConnectedDirectoryFragment.java
│ │ ├── ConnectedFileFragment.java
│ │ ├── ConnectionsFragment.java
│ │ ├── NewConnectionFragment.java
│ │ └── PasswordDialogFragment.java
│ │ ├── objects
│ │ ├── Address.java
│ │ ├── Connection.java
│ │ └── FilePath.java
│ │ └── services
│ │ └── ConnectionService.java
│ └── res
│ ├── layout
│ ├── connection_list_item.xml
│ ├── dialog_password.xml
│ ├── fragment_connections.xml
│ ├── fragment_directory.xml
│ ├── fragment_file.xml
│ └── fragment_new_connection.xml
│ ├── menu
│ ├── connections.xml
│ └── new_connection.xml
│ ├── values-sw600dp
│ └── dimens.xml
│ ├── values-sw720dp-land
│ └── dimens.xml
│ ├── values-v11
│ └── styles.xml
│ ├── values-v14
│ └── styles.xml
│ └── values
│ ├── dimens.xml
│ ├── ids.xml
│ ├── strings.xml
│ └── styles.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.apk
2 | *.ap_
3 |
4 | # files for the dex VM
5 | *.dex
6 |
7 | # Java class files
8 | *.class
9 |
10 | # generated files
11 | bin/
12 | gen/
13 |
14 | # Local configuration file (sdk path, etc)
15 | local.properties
16 |
17 | # Eclipse project files
18 | .classpath
19 | .project
20 | .settings/
21 |
22 | # Android Studio
23 | .idea/
24 | .gradle
25 | /*/local.properties
26 | /*/out
27 | /*/*/build
28 | /*/*/production
29 | *.iml
30 | *.iws
31 | *.ipr
32 | *~
33 | *.swp
34 |
35 | # Mac
36 | .DS_Store
37 |
38 | #files
39 | *.png
40 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | This project is licensed under the GNU GPLv3 license. License text found below.
2 |
3 | This project incorporates JSch 0.1.49, which is covered by the following
4 | copyright and permission notice:
5 |
6 | Copyright (c) 2002-2012 Atsuhiko Yamanaka, JCraft,Inc.
7 | All rights reserved.
8 |
9 | Redistribution and use in source and binary forms, with or without
10 | modification, are permitted provided that the following conditions are met:
11 |
12 | 1. Redistributions of source code must retain the above copyright notice,
13 | this list of conditions and the following disclaimer.
14 |
15 | 2. Redistributions in binary form must reproduce the above copyright
16 | notice, this list of conditions and the following disclaimer in
17 | the documentation and/or other materials provided with the distribution.
18 |
19 | 3. The names of the authors may not be used to endorse or promote products
20 | derived from this software without specific prior written permission.
21 |
22 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
23 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
24 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
25 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
26 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 |
33 | --------------------------------------------------------------------------------
34 |
35 | GNU GENERAL PUBLIC LICENSE
36 | Version 3, 29 June 2007
37 |
38 | Copyright (C) 2007 Free Software Foundation, Inc.
39 | Everyone is permitted to copy and distribute verbatim copies
40 | of this license document, but changing it is not allowed.
41 |
42 | Preamble
43 |
44 | The GNU General Public License is a free, copyleft license for
45 | software and other kinds of works.
46 |
47 | The licenses for most software and other practical works are designed
48 | to take away your freedom to share and change the works. By contrast,
49 | the GNU General Public License is intended to guarantee your freedom to
50 | share and change all versions of a program--to make sure it remains free
51 | software for all its users. We, the Free Software Foundation, use the
52 | GNU General Public License for most of our software; it applies also to
53 | any other work released this way by its authors. You can apply it to
54 | your programs, too.
55 |
56 | When we speak of free software, we are referring to freedom, not
57 | price. Our General Public Licenses are designed to make sure that you
58 | have the freedom to distribute copies of free software (and charge for
59 | them if you wish), that you receive source code or can get it if you
60 | want it, that you can change the software or use pieces of it in new
61 | free programs, and that you know you can do these things.
62 |
63 | To protect your rights, we need to prevent others from denying you
64 | these rights or asking you to surrender the rights. Therefore, you have
65 | certain responsibilities if you distribute copies of the software, or if
66 | you modify it: responsibilities to respect the freedom of others.
67 |
68 | For example, if you distribute copies of such a program, whether
69 | gratis or for a fee, you must pass on to the recipients the same
70 | freedoms that you received. You must make sure that they, too, receive
71 | or can get the source code. And you must show them these terms so they
72 | know their rights.
73 |
74 | Developers that use the GNU GPL protect your rights with two steps:
75 | (1) assert copyright on the software, and (2) offer you this License
76 | giving you legal permission to copy, distribute and/or modify it.
77 |
78 | For the developers' and authors' protection, the GPL clearly explains
79 | that there is no warranty for this free software. For both users' and
80 | authors' sake, the GPL requires that modified versions be marked as
81 | changed, so that their problems will not be attributed erroneously to
82 | authors of previous versions.
83 |
84 | Some devices are designed to deny users access to install or run
85 | modified versions of the software inside them, although the manufacturer
86 | can do so. This is fundamentally incompatible with the aim of
87 | protecting users' freedom to change the software. The systematic
88 | pattern of such abuse occurs in the area of products for individuals to
89 | use, which is precisely where it is most unacceptable. Therefore, we
90 | have designed this version of the GPL to prohibit the practice for those
91 | products. If such problems arise substantially in other domains, we
92 | stand ready to extend this provision to those domains in future versions
93 | of the GPL, as needed to protect the freedom of users.
94 |
95 | Finally, every program is threatened constantly by software patents.
96 | States should not allow patents to restrict development and use of
97 | software on general-purpose computers, but in those that do, we wish to
98 | avoid the special danger that patents applied to a free program could
99 | make it effectively proprietary. To prevent this, the GPL assures that
100 | patents cannot be used to render the program non-free.
101 |
102 | The precise terms and conditions for copying, distribution and
103 | modification follow.
104 |
105 | TERMS AND CONDITIONS
106 |
107 | 0. Definitions.
108 |
109 | "This License" refers to version 3 of the GNU General Public License.
110 |
111 | "Copyright" also means copyright-like laws that apply to other kinds of
112 | works, such as semiconductor masks.
113 |
114 | "The Program" refers to any copyrightable work licensed under this
115 | License. Each licensee is addressed as "you". "Licensees" and
116 | "recipients" may be individuals or organizations.
117 |
118 | To "modify" a work means to copy from or adapt all or part of the work
119 | in a fashion requiring copyright permission, other than the making of an
120 | exact copy. The resulting work is called a "modified version" of the
121 | earlier work or a work "based on" the earlier work.
122 |
123 | A "covered work" means either the unmodified Program or a work based
124 | on the Program.
125 |
126 | To "propagate" a work means to do anything with it that, without
127 | permission, would make you directly or secondarily liable for
128 | infringement under applicable copyright law, except executing it on a
129 | computer or modifying a private copy. Propagation includes copying,
130 | distribution (with or without modification), making available to the
131 | public, and in some countries other activities as well.
132 |
133 | To "convey" a work means any kind of propagation that enables other
134 | parties to make or receive copies. Mere interaction with a user through
135 | a computer network, with no transfer of a copy, is not conveying.
136 |
137 | An interactive user interface displays "Appropriate Legal Notices"
138 | to the extent that it includes a convenient and prominently visible
139 | feature that (1) displays an appropriate copyright notice, and (2)
140 | tells the user that there is no warranty for the work (except to the
141 | extent that warranties are provided), that licensees may convey the
142 | work under this License, and how to view a copy of this License. If
143 | the interface presents a list of user commands or options, such as a
144 | menu, a prominent item in the list meets this criterion.
145 |
146 | 1. Source Code.
147 |
148 | The "source code" for a work means the preferred form of the work
149 | for making modifications to it. "Object code" means any non-source
150 | form of a work.
151 |
152 | A "Standard Interface" means an interface that either is an official
153 | standard defined by a recognized standards body, or, in the case of
154 | interfaces specified for a particular programming language, one that
155 | is widely used among developers working in that language.
156 |
157 | The "System Libraries" of an executable work include anything, other
158 | than the work as a whole, that (a) is included in the normal form of
159 | packaging a Major Component, but which is not part of that Major
160 | Component, and (b) serves only to enable use of the work with that
161 | Major Component, or to implement a Standard Interface for which an
162 | implementation is available to the public in source code form. A
163 | "Major Component", in this context, means a major essential component
164 | (kernel, window system, and so on) of the specific operating system
165 | (if any) on which the executable work runs, or a compiler used to
166 | produce the work, or an object code interpreter used to run it.
167 |
168 | The "Corresponding Source" for a work in object code form means all
169 | the source code needed to generate, install, and (for an executable
170 | work) run the object code and to modify the work, including scripts to
171 | control those activities. However, it does not include the work's
172 | System Libraries, or general-purpose tools or generally available free
173 | programs which are used unmodified in performing those activities but
174 | which are not part of the work. For example, Corresponding Source
175 | includes interface definition files associated with source files for
176 | the work, and the source code for shared libraries and dynamically
177 | linked subprograms that the work is specifically designed to require,
178 | such as by intimate data communication or control flow between those
179 | subprograms and other parts of the work.
180 |
181 | The Corresponding Source need not include anything that users
182 | can regenerate automatically from other parts of the Corresponding
183 | Source.
184 |
185 | The Corresponding Source for a work in source code form is that
186 | same work.
187 |
188 | 2. Basic Permissions.
189 |
190 | All rights granted under this License are granted for the term of
191 | copyright on the Program, and are irrevocable provided the stated
192 | conditions are met. This License explicitly affirms your unlimited
193 | permission to run the unmodified Program. The output from running a
194 | covered work is covered by this License only if the output, given its
195 | content, constitutes a covered work. This License acknowledges your
196 | rights of fair use or other equivalent, as provided by copyright law.
197 |
198 | You may make, run and propagate covered works that you do not
199 | convey, without conditions so long as your license otherwise remains
200 | in force. You may convey covered works to others for the sole purpose
201 | of having them make modifications exclusively for you, or provide you
202 | with facilities for running those works, provided that you comply with
203 | the terms of this License in conveying all material for which you do
204 | not control copyright. Those thus making or running the covered works
205 | for you must do so exclusively on your behalf, under your direction
206 | and control, on terms that prohibit them from making any copies of
207 | your copyrighted material outside their relationship with you.
208 |
209 | Conveying under any other circumstances is permitted solely under
210 | the conditions stated below. Sublicensing is not allowed; section 10
211 | makes it unnecessary.
212 |
213 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
214 |
215 | No covered work shall be deemed part of an effective technological
216 | measure under any applicable law fulfilling obligations under article
217 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
218 | similar laws prohibiting or restricting circumvention of such
219 | measures.
220 |
221 | When you convey a covered work, you waive any legal power to forbid
222 | circumvention of technological measures to the extent such circumvention
223 | is effected by exercising rights under this License with respect to
224 | the covered work, and you disclaim any intention to limit operation or
225 | modification of the work as a means of enforcing, against the work's
226 | users, your or third parties' legal rights to forbid circumvention of
227 | technological measures.
228 |
229 | 4. Conveying Verbatim Copies.
230 |
231 | You may convey verbatim copies of the Program's source code as you
232 | receive it, in any medium, provided that you conspicuously and
233 | appropriately publish on each copy an appropriate copyright notice;
234 | keep intact all notices stating that this License and any
235 | non-permissive terms added in accord with section 7 apply to the code;
236 | keep intact all notices of the absence of any warranty; and give all
237 | recipients a copy of this License along with the Program.
238 |
239 | You may charge any price or no price for each copy that you convey,
240 | and you may offer support or warranty protection for a fee.
241 |
242 | 5. Conveying Modified Source Versions.
243 |
244 | You may convey a work based on the Program, or the modifications to
245 | produce it from the Program, in the form of source code under the
246 | terms of section 4, provided that you also meet all of these conditions:
247 |
248 | a) The work must carry prominent notices stating that you modified
249 | it, and giving a relevant date.
250 |
251 | b) The work must carry prominent notices stating that it is
252 | released under this License and any conditions added under section
253 | 7. This requirement modifies the requirement in section 4 to
254 | "keep intact all notices".
255 |
256 | c) You must license the entire work, as a whole, under this
257 | License to anyone who comes into possession of a copy. This
258 | License will therefore apply, along with any applicable section 7
259 | additional terms, to the whole of the work, and all its parts,
260 | regardless of how they are packaged. This License gives no
261 | permission to license the work in any other way, but it does not
262 | invalidate such permission if you have separately received it.
263 |
264 | d) If the work has interactive user interfaces, each must display
265 | Appropriate Legal Notices; however, if the Program has interactive
266 | interfaces that do not display Appropriate Legal Notices, your
267 | work need not make them do so.
268 |
269 | A compilation of a covered work with other separate and independent
270 | works, which are not by their nature extensions of the covered work,
271 | and which are not combined with it such as to form a larger program,
272 | in or on a volume of a storage or distribution medium, is called an
273 | "aggregate" if the compilation and its resulting copyright are not
274 | used to limit the access or legal rights of the compilation's users
275 | beyond what the individual works permit. Inclusion of a covered work
276 | in an aggregate does not cause this License to apply to the other
277 | parts of the aggregate.
278 |
279 | 6. Conveying Non-Source Forms.
280 |
281 | You may convey a covered work in object code form under the terms
282 | of sections 4 and 5, provided that you also convey the
283 | machine-readable Corresponding Source under the terms of this License,
284 | in one of these ways:
285 |
286 | a) Convey the object code in, or embodied in, a physical product
287 | (including a physical distribution medium), accompanied by the
288 | Corresponding Source fixed on a durable physical medium
289 | customarily used for software interchange.
290 |
291 | b) Convey the object code in, or embodied in, a physical product
292 | (including a physical distribution medium), accompanied by a
293 | written offer, valid for at least three years and valid for as
294 | long as you offer spare parts or customer support for that product
295 | model, to give anyone who possesses the object code either (1) a
296 | copy of the Corresponding Source for all the software in the
297 | product that is covered by this License, on a durable physical
298 | medium customarily used for software interchange, for a price no
299 | more than your reasonable cost of physically performing this
300 | conveying of source, or (2) access to copy the
301 | Corresponding Source from a network server at no charge.
302 |
303 | c) Convey individual copies of the object code with a copy of the
304 | written offer to provide the Corresponding Source. This
305 | alternative is allowed only occasionally and noncommercially, and
306 | only if you received the object code with such an offer, in accord
307 | with subsection 6b.
308 |
309 | d) Convey the object code by offering access from a designated
310 | place (gratis or for a charge), and offer equivalent access to the
311 | Corresponding Source in the same way through the same place at no
312 | further charge. You need not require recipients to copy the
313 | Corresponding Source along with the object code. If the place to
314 | copy the object code is a network server, the Corresponding Source
315 | may be on a different server (operated by you or a third party)
316 | that supports equivalent copying facilities, provided you maintain
317 | clear directions next to the object code saying where to find the
318 | Corresponding Source. Regardless of what server hosts the
319 | Corresponding Source, you remain obligated to ensure that it is
320 | available for as long as needed to satisfy these requirements.
321 |
322 | e) Convey the object code using peer-to-peer transmission, provided
323 | you inform other peers where the object code and Corresponding
324 | Source of the work are being offered to the general public at no
325 | charge under subsection 6d.
326 |
327 | A separable portion of the object code, whose source code is excluded
328 | from the Corresponding Source as a System Library, need not be
329 | included in conveying the object code work.
330 |
331 | A "User Product" is either (1) a "consumer product", which means any
332 | tangible personal property which is normally used for personal, family,
333 | or household purposes, or (2) anything designed or sold for incorporation
334 | into a dwelling. In determining whether a product is a consumer product,
335 | doubtful cases shall be resolved in favor of coverage. For a particular
336 | product received by a particular user, "normally used" refers to a
337 | typical or common use of that class of product, regardless of the status
338 | of the particular user or of the way in which the particular user
339 | actually uses, or expects or is expected to use, the product. A product
340 | is a consumer product regardless of whether the product has substantial
341 | commercial, industrial or non-consumer uses, unless such uses represent
342 | the only significant mode of use of the product.
343 |
344 | "Installation Information" for a User Product means any methods,
345 | procedures, authorization keys, or other information required to install
346 | and execute modified versions of a covered work in that User Product from
347 | a modified version of its Corresponding Source. The information must
348 | suffice to ensure that the continued functioning of the modified object
349 | code is in no case prevented or interfered with solely because
350 | modification has been made.
351 |
352 | If you convey an object code work under this section in, or with, or
353 | specifically for use in, a User Product, and the conveying occurs as
354 | part of a transaction in which the right of possession and use of the
355 | User Product is transferred to the recipient in perpetuity or for a
356 | fixed term (regardless of how the transaction is characterized), the
357 | Corresponding Source conveyed under this section must be accompanied
358 | by the Installation Information. But this requirement does not apply
359 | if neither you nor any third party retains the ability to install
360 | modified object code on the User Product (for example, the work has
361 | been installed in ROM).
362 |
363 | The requirement to provide Installation Information does not include a
364 | requirement to continue to provide support service, warranty, or updates
365 | for a work that has been modified or installed by the recipient, or for
366 | the User Product in which it has been modified or installed. Access to a
367 | network may be denied when the modification itself materially and
368 | adversely affects the operation of the network or violates the rules and
369 | protocols for communication across the network.
370 |
371 | Corresponding Source conveyed, and Installation Information provided,
372 | in accord with this section must be in a format that is publicly
373 | documented (and with an implementation available to the public in
374 | source code form), and must require no special password or key for
375 | unpacking, reading or copying.
376 |
377 | 7. Additional Terms.
378 |
379 | "Additional permissions" are terms that supplement the terms of this
380 | License by making exceptions from one or more of its conditions.
381 | Additional permissions that are applicable to the entire Program shall
382 | be treated as though they were included in this License, to the extent
383 | that they are valid under applicable law. If additional permissions
384 | apply only to part of the Program, that part may be used separately
385 | under those permissions, but the entire Program remains governed by
386 | this License without regard to the additional permissions.
387 |
388 | When you convey a copy of a covered work, you may at your option
389 | remove any additional permissions from that copy, or from any part of
390 | it. (Additional permissions may be written to require their own
391 | removal in certain cases when you modify the work.) You may place
392 | additional permissions on material, added by you to a covered work,
393 | for which you have or can give appropriate copyright permission.
394 |
395 | Notwithstanding any other provision of this License, for material you
396 | add to a covered work, you may (if authorized by the copyright holders of
397 | that material) supplement the terms of this License with terms:
398 |
399 | a) Disclaiming warranty or limiting liability differently from the
400 | terms of sections 15 and 16 of this License; or
401 |
402 | b) Requiring preservation of specified reasonable legal notices or
403 | author attributions in that material or in the Appropriate Legal
404 | Notices displayed by works containing it; or
405 |
406 | c) Prohibiting misrepresentation of the origin of that material, or
407 | requiring that modified versions of such material be marked in
408 | reasonable ways as different from the original version; or
409 |
410 | d) Limiting the use for publicity purposes of names of licensors or
411 | authors of the material; or
412 |
413 | e) Declining to grant rights under trademark law for use of some
414 | trade names, trademarks, or service marks; or
415 |
416 | f) Requiring indemnification of licensors and authors of that
417 | material by anyone who conveys the material (or modified versions of
418 | it) with contractual assumptions of liability to the recipient, for
419 | any liability that these contractual assumptions directly impose on
420 | those licensors and authors.
421 |
422 | All other non-permissive additional terms are considered "further
423 | restrictions" within the meaning of section 10. If the Program as you
424 | received it, or any part of it, contains a notice stating that it is
425 | governed by this License along with a term that is a further
426 | restriction, you may remove that term. If a license document contains
427 | a further restriction but permits relicensing or conveying under this
428 | License, you may add to a covered work material governed by the terms
429 | of that license document, provided that the further restriction does
430 | not survive such relicensing or conveying.
431 |
432 | If you add terms to a covered work in accord with this section, you
433 | must place, in the relevant source files, a statement of the
434 | additional terms that apply to those files, or a notice indicating
435 | where to find the applicable terms.
436 |
437 | Additional terms, permissive or non-permissive, may be stated in the
438 | form of a separately written license, or stated as exceptions;
439 | the above requirements apply either way.
440 |
441 | 8. Termination.
442 |
443 | You may not propagate or modify a covered work except as expressly
444 | provided under this License. Any attempt otherwise to propagate or
445 | modify it is void, and will automatically terminate your rights under
446 | this License (including any patent licenses granted under the third
447 | paragraph of section 11).
448 |
449 | However, if you cease all violation of this License, then your
450 | license from a particular copyright holder is reinstated (a)
451 | provisionally, unless and until the copyright holder explicitly and
452 | finally terminates your license, and (b) permanently, if the copyright
453 | holder fails to notify you of the violation by some reasonable means
454 | prior to 60 days after the cessation.
455 |
456 | Moreover, your license from a particular copyright holder is
457 | reinstated permanently if the copyright holder notifies you of the
458 | violation by some reasonable means, this is the first time you have
459 | received notice of violation of this License (for any work) from that
460 | copyright holder, and you cure the violation prior to 30 days after
461 | your receipt of the notice.
462 |
463 | Termination of your rights under this section does not terminate the
464 | licenses of parties who have received copies or rights from you under
465 | this License. If your rights have been terminated and not permanently
466 | reinstated, you do not qualify to receive new licenses for the same
467 | material under section 10.
468 |
469 | 9. Acceptance Not Required for Having Copies.
470 |
471 | You are not required to accept this License in order to receive or
472 | run a copy of the Program. Ancillary propagation of a covered work
473 | occurring solely as a consequence of using peer-to-peer transmission
474 | to receive a copy likewise does not require acceptance. However,
475 | nothing other than this License grants you permission to propagate or
476 | modify any covered work. These actions infringe copyright if you do
477 | not accept this License. Therefore, by modifying or propagating a
478 | covered work, you indicate your acceptance of this License to do so.
479 |
480 | 10. Automatic Licensing of Downstream Recipients.
481 |
482 | Each time you convey a covered work, the recipient automatically
483 | receives a license from the original licensors, to run, modify and
484 | propagate that work, subject to this License. You are not responsible
485 | for enforcing compliance by third parties with this License.
486 |
487 | An "entity transaction" is a transaction transferring control of an
488 | organization, or substantially all assets of one, or subdividing an
489 | organization, or merging organizations. If propagation of a covered
490 | work results from an entity transaction, each party to that
491 | transaction who receives a copy of the work also receives whatever
492 | licenses to the work the party's predecessor in interest had or could
493 | give under the previous paragraph, plus a right to possession of the
494 | Corresponding Source of the work from the predecessor in interest, if
495 | the predecessor has it or can get it with reasonable efforts.
496 |
497 | You may not impose any further restrictions on the exercise of the
498 | rights granted or affirmed under this License. For example, you may
499 | not impose a license fee, royalty, or other charge for exercise of
500 | rights granted under this License, and you may not initiate litigation
501 | (including a cross-claim or counterclaim in a lawsuit) alleging that
502 | any patent claim is infringed by making, using, selling, offering for
503 | sale, or importing the Program or any portion of it.
504 |
505 | 11. Patents.
506 |
507 | A "contributor" is a copyright holder who authorizes use under this
508 | License of the Program or a work on which the Program is based. The
509 | work thus licensed is called the contributor's "contributor version".
510 |
511 | A contributor's "essential patent claims" are all patent claims
512 | owned or controlled by the contributor, whether already acquired or
513 | hereafter acquired, that would be infringed by some manner, permitted
514 | by this License, of making, using, or selling its contributor version,
515 | but do not include claims that would be infringed only as a
516 | consequence of further modification of the contributor version. For
517 | purposes of this definition, "control" includes the right to grant
518 | patent sublicenses in a manner consistent with the requirements of
519 | this License.
520 |
521 | Each contributor grants you a non-exclusive, worldwide, royalty-free
522 | patent license under the contributor's essential patent claims, to
523 | make, use, sell, offer for sale, import and otherwise run, modify and
524 | propagate the contents of its contributor version.
525 |
526 | In the following three paragraphs, a "patent license" is any express
527 | agreement or commitment, however denominated, not to enforce a patent
528 | (such as an express permission to practice a patent or covenant not to
529 | sue for patent infringement). To "grant" such a patent license to a
530 | party means to make such an agreement or commitment not to enforce a
531 | patent against the party.
532 |
533 | If you convey a covered work, knowingly relying on a patent license,
534 | and the Corresponding Source of the work is not available for anyone
535 | to copy, free of charge and under the terms of this License, through a
536 | publicly available network server or other readily accessible means,
537 | then you must either (1) cause the Corresponding Source to be so
538 | available, or (2) arrange to deprive yourself of the benefit of the
539 | patent license for this particular work, or (3) arrange, in a manner
540 | consistent with the requirements of this License, to extend the patent
541 | license to downstream recipients. "Knowingly relying" means you have
542 | actual knowledge that, but for the patent license, your conveying the
543 | covered work in a country, or your recipient's use of the covered work
544 | in a country, would infringe one or more identifiable patents in that
545 | country that you have reason to believe are valid.
546 |
547 | If, pursuant to or in connection with a single transaction or
548 | arrangement, you convey, or propagate by procuring conveyance of, a
549 | covered work, and grant a patent license to some of the parties
550 | receiving the covered work authorizing them to use, propagate, modify
551 | or convey a specific copy of the covered work, then the patent license
552 | you grant is automatically extended to all recipients of the covered
553 | work and works based on it.
554 |
555 | A patent license is "discriminatory" if it does not include within
556 | the scope of its coverage, prohibits the exercise of, or is
557 | conditioned on the non-exercise of one or more of the rights that are
558 | specifically granted under this License. You may not convey a covered
559 | work if you are a party to an arrangement with a third party that is
560 | in the business of distributing software, under which you make payment
561 | to the third party based on the extent of your activity of conveying
562 | the work, and under which the third party grants, to any of the
563 | parties who would receive the covered work from you, a discriminatory
564 | patent license (a) in connection with copies of the covered work
565 | conveyed by you (or copies made from those copies), or (b) primarily
566 | for and in connection with specific products or compilations that
567 | contain the covered work, unless you entered into that arrangement,
568 | or that patent license was granted, prior to 28 March 2007.
569 |
570 | Nothing in this License shall be construed as excluding or limiting
571 | any implied license or other defenses to infringement that may
572 | otherwise be available to you under applicable patent law.
573 |
574 | 12. No Surrender of Others' Freedom.
575 |
576 | If conditions are imposed on you (whether by court order, agreement or
577 | otherwise) that contradict the conditions of this License, they do not
578 | excuse you from the conditions of this License. If you cannot convey a
579 | covered work so as to satisfy simultaneously your obligations under this
580 | License and any other pertinent obligations, then as a consequence you may
581 | not convey it at all. For example, if you agree to terms that obligate you
582 | to collect a royalty for further conveying from those to whom you convey
583 | the Program, the only way you could satisfy both those terms and this
584 | License would be to refrain entirely from conveying the Program.
585 |
586 | 13. Use with the GNU Affero General Public License.
587 |
588 | Notwithstanding any other provision of this License, you have
589 | permission to link or combine any covered work with a work licensed
590 | under version 3 of the GNU Affero General Public License into a single
591 | combined work, and to convey the resulting work. The terms of this
592 | License will continue to apply to the part which is the covered work,
593 | but the special requirements of the GNU Affero General Public License,
594 | section 13, concerning interaction through a network will apply to the
595 | combination as such.
596 |
597 | 14. Revised Versions of this License.
598 |
599 | The Free Software Foundation may publish revised and/or new versions of
600 | the GNU General Public License from time to time. Such new versions will
601 | be similar in spirit to the present version, but may differ in detail to
602 | address new problems or concerns.
603 |
604 | Each version is given a distinguishing version number. If the
605 | Program specifies that a certain numbered version of the GNU General
606 | Public License "or any later version" applies to it, you have the
607 | option of following the terms and conditions either of that numbered
608 | version or of any later version published by the Free Software
609 | Foundation. If the Program does not specify a version number of the
610 | GNU General Public License, you may choose any version ever published
611 | by the Free Software Foundation.
612 |
613 | If the Program specifies that a proxy can decide which future
614 | versions of the GNU General Public License can be used, that proxy's
615 | public statement of acceptance of a version permanently authorizes you
616 | to choose that version for the Program.
617 |
618 | Later license versions may give you additional or different
619 | permissions. However, no additional obligations are imposed on any
620 | author or copyright holder as a result of your choosing to follow a
621 | later version.
622 |
623 | 15. Disclaimer of Warranty.
624 |
625 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
626 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
627 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
628 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
629 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
630 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
631 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
632 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
633 |
634 | 16. Limitation of Liability.
635 |
636 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
637 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
638 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
639 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
640 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
641 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
642 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
643 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
644 | SUCH DAMAGES.
645 |
646 | 17. Interpretation of Sections 15 and 16.
647 |
648 | If the disclaimer of warranty and limitation of liability provided
649 | above cannot be given local legal effect according to their terms,
650 | reviewing courts shall apply local law that most closely approximates
651 | an absolute waiver of all civil liability in connection with the
652 | Program, unless a warranty or assumption of liability accompanies a
653 | copy of the Program in return for a fee.
654 |
655 | END OF TERMS AND CONDITIONS
656 |
657 | How to Apply These Terms to Your New Programs
658 |
659 | If you develop a new program, and you want it to be of the greatest
660 | possible use to the public, the best way to achieve this is to make it
661 | free software which everyone can redistribute and change under these terms.
662 |
663 | To do so, attach the following notices to the program. It is safest
664 | to attach them to the start of each source file to most effectively
665 | state the exclusion of warranty; and each file should have at least
666 | the "copyright" line and a pointer to where the full notice is found.
667 |
668 |
669 | Copyright (C)
670 |
671 | This program is free software: you can redistribute it and/or modify
672 | it under the terms of the GNU General Public License as published by
673 | the Free Software Foundation, either version 3 of the License, or
674 | (at your option) any later version.
675 |
676 | This program is distributed in the hope that it will be useful,
677 | but WITHOUT ANY WARRANTY; without even the implied warranty of
678 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
679 | GNU General Public License for more details.
680 |
681 | You should have received a copy of the GNU General Public License
682 | along with this program. If not, see .
683 |
684 | Also add information on how to contact you by electronic and paper mail.
685 |
686 | If the program does terminal interaction, make it output a short
687 | notice like this when it starts in an interactive mode:
688 |
689 | Copyright (C)
690 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
691 | This is free software, and you are welcome to redistribute it
692 | under certain conditions; type `show c' for details.
693 |
694 | The hypothetical commands `show w' and `show c' should show the appropriate
695 | parts of the General Public License. Of course, your program's commands
696 | might be different; for a GUI interface, you would use an "about box".
697 |
698 | You should also get your employer (if you work as a programmer) or school,
699 | if any, to sign a "copyright disclaimer" for the program, if necessary.
700 | For more information on this, and how to apply and follow the GNU GPL, see
701 | .
702 |
703 | The GNU General Public License does not permit incorporating your program
704 | into proprietary programs. If your program is a subroutine library, you
705 | may consider it more useful to permit linking proprietary applications with
706 | the library. If this is what you want to do, use the GNU Lesser General
707 | Public License instead of this License. But first, please read
708 | .
709 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Cooper
2 | ======
3 |
4 | Lightweight SSH client optimized for touch devices.
5 |
6 | This app is being developed to make remote software/web-app development easier, so future improvements will include tablet optimized layouts, a touch optimized command execution interface (menu based with support for custom commands), and a mechanism for jumping between open files.
7 |
8 | ### License
9 | Cooper is distributed subject to the GNU GPLv3 license. Accordingly, you are free to use and modify this source code. Any derivative works must also be distributed according to the GNU GPLv3 license (or greater).
10 |
11 | ### Get Cooper
12 | The most recent stable build of Cooper is available for sale on [Google Play](https://play.google.com/store/apps/details?id=com.dconstructing.cooper). Proceeds support its continued development.
13 |
14 | [](https://play.google.com/store/apps/details?id=com.dconstructing.cooper)
15 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
--------------------------------------------------------------------------------
/cooper/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/cooper/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:0.6.+'
7 | }
8 | }
9 | apply plugin: 'android'
10 |
11 | repositories {
12 | mavenCentral()
13 | }
14 |
15 | android {
16 | compileSdkVersion 18
17 | buildToolsVersion "18.1.1"
18 |
19 | defaultConfig {
20 | minSdkVersion 16
21 | targetSdkVersion 17
22 | }
23 | }
24 |
25 | dependencies {
26 | compile 'com.android.support:appcompat-v7:18.0.0'
27 | compile 'com.jcraft:jsch:0.1.50'
28 | instrumentTestCompile 'junit:junit:3.8'
29 | }
30 |
--------------------------------------------------------------------------------
/cooper/src/instrumentTest/java/com/dconstructing/cooper/test/BasicTest.java:
--------------------------------------------------------------------------------
1 | package com.dconstructing.cooper.test;
2 |
3 | import android.test.ActivityInstrumentationTestCase2;
4 |
5 | import com.dconstructing.cooper.MainActivity;
6 |
7 | /**
8 | * Created by dcox on 10/10/13.
9 | */
10 | public class BasicTest extends ActivityInstrumentationTestCase2 {
11 |
12 | public BasicTest() {
13 | super(MainActivity.class);
14 | }
15 |
16 | @Override
17 | protected void setUp() throws Exception {
18 | super.setUp();
19 | setActivityInitialTouchMode(false);
20 | }
21 |
22 | @Override
23 | protected void tearDown() throws Exception {
24 | super.tearDown();
25 | }
26 |
27 | public void testStartFirstActivity() {
28 | assertNotNull(getActivity());
29 | }
30 |
31 | // public void testStartSecondActivity() throws Exception {
32 | //
33 | // // add monitor to check for the second activity
34 | // Instrumentation.ActivityMonitor monitor = getInstrumentation().addMonitor(MainActivity.class.getName(), null, false);
35 | //
36 | // // find button and click it
37 | // Button view = (Button) activity.findViewById(R.id.button1);
38 | // TouchUtils.clickView(this, view);
39 | //
40 | // // To click on a click, e.g. in a listview
41 | // // listView.getChildAt(0);
42 | //
43 | // // Wait 2 seconds for the start of the activity
44 | // MainActivity startedActivity = (MainActivity) monitor
45 | // .waitForActivityWithTimeout(2000);
46 | // assertNotNull(startedActivity);
47 | //
48 | // // Search for the textView
49 | // TextView textView = (TextView) startedActivity.findViewById(R.id.resultText);
50 | //
51 | // // check that the TextView is on the screen
52 | // ViewAsserts.assertOnScreen(startedActivity.getWindow().getDecorView(),
53 | // textView);
54 | // // Validate the text on the TextView
55 | // assertEquals("Text incorrect", "Started", textView.getText().toString());
56 | //
57 | // // Press back and click again
58 | // this.sendKeys(KeyEvent.KEYCODE_BACK);
59 | // TouchUtils.clickView(this, view);
60 | //
61 | // }
62 | }
63 |
--------------------------------------------------------------------------------
/cooper/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
13 |
18 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
30 |
33 |
34 |
35 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/cooper/src/main/java/com/dconstructing/cooper/ConnectionActivity.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Cooper, a touch-friendly SSH client for Android devices
3 | * Copyright (C) 2013 David Cox
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.dconstructing.cooper;
19 |
20 | import java.lang.ref.WeakReference;
21 | import java.util.ArrayList;
22 | import java.util.Iterator;
23 |
24 | import android.app.ActionBar;
25 | import android.app.Activity;
26 | import android.app.FragmentManager;
27 | import android.app.FragmentTransaction;
28 | import android.content.ComponentName;
29 | import android.content.Context;
30 | import android.content.Intent;
31 | import android.content.ServiceConnection;
32 | import android.os.Bundle;
33 | import android.os.Handler;
34 | import android.os.IBinder;
35 | import android.os.Message;
36 | import android.os.Messenger;
37 | import android.os.RemoteException;
38 | import android.util.Log;
39 |
40 | import com.dconstructing.cooper.fragments.ConnectedDirectoryFragment;
41 | import com.dconstructing.cooper.fragments.ConnectedDirectoryFragment.DirectoryListener;
42 | import com.dconstructing.cooper.fragments.ConnectedFileFragment;
43 | import com.dconstructing.cooper.fragments.ConnectedFileFragment.FileListener;
44 | import com.dconstructing.cooper.objects.FilePath;
45 | import com.dconstructing.cooper.services.ConnectionService;
46 |
47 | public class ConnectionActivity extends Activity implements DirectoryListener, FileListener {
48 |
49 | public final String TAG = getClass().getSimpleName();
50 |
51 | Messenger mService = null;
52 | ArrayList mConnectionQueue = new ArrayList();
53 | ArrayList mMessageQueue = new ArrayList();
54 |
55 | final Messenger mMessenger = new Messenger(new IncomingHandler(this));
56 |
57 | @Override
58 | protected void onCreate(Bundle savedInstanceState) {
59 | super.onCreate(savedInstanceState);
60 | if (MainActivity.isDebuggable) Log.i(TAG, "onCreate");
61 |
62 | ActionBar actionBar = getActionBar();
63 | actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
64 | actionBar.setDisplayHomeAsUpEnabled(true);
65 |
66 | if (savedInstanceState == null) {
67 | // During initial setup
68 | Intent intent = getIntent();
69 | long uuid = intent.getLongExtra("uuid", 0);
70 | showConnection(uuid);
71 | }
72 |
73 | }
74 |
75 | @Override
76 | public void onDirectoryItemSelected(String tag, FilePath filePath) {
77 | if (filePath.isDirectory) {
78 | changeDirectory(Long.parseLong(tag), filePath.name);
79 | //loadDirectoryContent(Long.parseLong(tag), filePath.name);
80 | } else {
81 | openSelectedItem(Long.parseLong(tag), filePath.name);
82 | }
83 | }
84 |
85 | @Override
86 | public void onFileSaved(Long uuid, FilePath filePath, String content) {
87 | if (MainActivity.isDebuggable) Log.i(TAG, "Constructing File Save Command");
88 | Bundle bundle = new Bundle();
89 | bundle.putLong("uuid", uuid);
90 | bundle.putString("parameter", filePath.toString());
91 | bundle.putString("content", content);
92 | Message msg = Message.obtain(null, ConnectionService.MSG_FILE_SAVE);
93 | msg.setData(bundle);
94 | msg.replyTo = mMessenger;
95 |
96 | sendMessage(msg);
97 | }
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 | public void bindToService() {
109 | if (MainActivity.isDebuggable) Log.i(TAG, "Gotta start the Connection Service");
110 | try {
111 | getApplicationContext().bindService(new Intent(this, ConnectionService.class), mConnection, Context.BIND_AUTO_CREATE);
112 | } catch (SecurityException e) {
113 | if (MainActivity.isDebuggable) Log.e(TAG, "Could not bind to service", e);
114 | }
115 | }
116 |
117 | public void sendMessage(Message message) {
118 | if (mService == null) {
119 | this.queueMessage(message);
120 | bindToService();
121 | } else {
122 | transmitMessage(message);
123 | }
124 | }
125 |
126 | public void transmitMessage(Message message) {
127 | try {
128 | mService.send(message);
129 | } catch (RemoteException e) {
130 | e.printStackTrace();
131 | }
132 | }
133 |
134 | public void showConnection(long uuid) {
135 | if (mService == null) {
136 | this.queueConnection(uuid);
137 | bindToService();
138 | } else {
139 | loadDirectoryContent(uuid, null);
140 | }
141 | }
142 |
143 | public void queueConnection(long uuid) {
144 | if (MainActivity.isDebuggable) Log.i(TAG, "Queuing connection " + Long.toString(uuid));
145 | mConnectionQueue.add(uuid);
146 | }
147 |
148 | public void showQueuedConnections() {
149 | if (MainActivity.isDebuggable) Log.i(TAG, "Working through the queue");
150 |
151 | Iterator it = mConnectionQueue.iterator();
152 | while (it.hasNext()) {
153 | long uuid = (Long) it.next();
154 | showConnection(uuid);
155 | it.remove();
156 | }
157 | }
158 |
159 | public void queueMessage(Message message) {
160 | if (MainActivity.isDebuggable) Log.i(TAG, "Queuing message ");
161 | mMessageQueue.add(message);
162 | }
163 |
164 | public void sendQueuedMessagess() {
165 | if (MainActivity.isDebuggable) Log.i(TAG, "Working through the message queue");
166 |
167 | Iterator it = mMessageQueue.iterator();
168 | while (it.hasNext()) {
169 | Message message = (Message) it.next();
170 | sendMessage(message);
171 | it.remove();
172 | }
173 | }
174 |
175 | /*
176 | public void bringToFront(long uuid) {
177 | if (MainActivity.isDebuggable) Log.i(TAG, "Looking for fragment with tag: " + Long.toString(uuid));
178 | FragmentManager fm = getFragmentManager();
179 | ConnectedDirectoryFragment fragment = (ConnectedDirectoryFragment)fm.findFragmentByTag(Long.toString(uuid));
180 | if (fragment == null) {
181 | if (MainActivity.isDebuggable) Log.i(TAG, "Fragment is null");
182 | } else {
183 | if (MainActivity.isDebuggable) Log.i(TAG, "Fragment is found");
184 | }
185 |
186 | }
187 | */
188 |
189 | public void loadDirectoryContent(long uuid, String itemName) {
190 | if (MainActivity.isDebuggable) Log.i(TAG, "Loading Directory content");
191 | Bundle bundle = new Bundle();
192 | bundle.putLong("uuid", uuid);
193 | bundle.putInt("command", ConnectionService.CMD_DIR_READ);
194 | bundle.putString("parameter", itemName);
195 | Message msg = Message.obtain(null, ConnectionService.MSG_COMMAND_DISPATCH);
196 | msg.setData(bundle);
197 | msg.replyTo = mMessenger;
198 |
199 | sendMessage(msg);
200 | }
201 |
202 | public void changeDirectory(long uuid, String itemName) {
203 | if (MainActivity.isDebuggable) Log.i(TAG, "Changing Directory");
204 | Bundle bundle = new Bundle();
205 | bundle.putLong("uuid", uuid);
206 | bundle.putInt("command", ConnectionService.CMD_CHANGE_LOCATION);
207 | bundle.putString("parameter", itemName);
208 | Message msg = Message.obtain(null, ConnectionService.MSG_COMMAND_DISPATCH);
209 | msg.setData(bundle);
210 | msg.replyTo = mMessenger;
211 |
212 | sendMessage(msg);
213 | }
214 |
215 | public void openSelectedItem(long uuid, String itemName) {
216 | if (MainActivity.isDebuggable) Log.i(TAG, "Loading Directory content");
217 | Bundle bundle = new Bundle();
218 | bundle.putLong("uuid", uuid);
219 | bundle.putInt("command", ConnectionService.CMD_FILE_READ);
220 | bundle.putString("parameter", itemName);
221 | Message msg = Message.obtain(null, ConnectionService.MSG_COMMAND_DISPATCH);
222 | msg.setData(bundle);
223 | msg.replyTo = mMessenger;
224 |
225 | sendMessage(msg);
226 | }
227 |
228 | public void handleResponse(long uuid, ArrayList files, ArrayList directories) {
229 | sendResponseToDirectoryFragment(uuid, files, directories);
230 | }
231 |
232 | public void handleResponse(long uuid, int command, String path, String response) {
233 | if (command == ConnectionService.CMD_FILE_READ) {
234 | // display file fragment
235 | if (MainActivity.isDebuggable) Log.i(TAG, "Displaying file: " + response);
236 | if (MainActivity.isDebuggable) Log.i(TAG, "Looking for fragment with tag: " + Long.toString(uuid));
237 | sendResponseToFileFragment(uuid, path, response);
238 | } else if (command == ConnectionService.CMD_FILE_WRITE) {
239 | // TODO: Should I do anything here?
240 | }
241 | }
242 |
243 | public void sendResponseToDirectoryFragment(long uuid, ArrayList files, ArrayList directories) {
244 | if (MainActivity.isDebuggable) Log.i(TAG, "Looking for directory fragment with tag: " + Long.toString(uuid));
245 | FragmentManager fm = getFragmentManager();
246 | ConnectedDirectoryFragment fragment = (ConnectedDirectoryFragment)fm.findFragmentByTag(Long.toString(uuid));
247 | if (fragment == null) {
248 | if (MainActivity.isDebuggable) Log.i(TAG, "Fragment is null");
249 | // create fragment with response
250 | Bundle bundle = new Bundle();
251 | bundle.putStringArrayList("files", files);
252 | bundle.putStringArrayList("directories", directories);
253 | ConnectedDirectoryFragment newDirectory = new ConnectedDirectoryFragment();
254 | newDirectory.setArguments(bundle);
255 | FragmentTransaction transaction = fm.beginTransaction();
256 | transaction.replace(android.R.id.content, newDirectory, Long.toString(uuid));
257 | transaction.addToBackStack(null);
258 | transaction.commit();
259 | } else {
260 | if (MainActivity.isDebuggable) Log.i(TAG, "Found the fragment with tag: " + Long.toString(uuid));
261 | fragment.processResponse(files, directories);
262 | }
263 | }
264 |
265 | public void sendResponseToFileFragment(long uuid, String path, String response) {
266 | if (MainActivity.isDebuggable) Log.i(TAG, "Looking for fragment with tag: " + Long.toString(uuid) + ":" + path);
267 | FragmentManager fm = getFragmentManager();
268 | ConnectedFileFragment fragment = (ConnectedFileFragment)fm.findFragmentByTag(Long.toString(uuid) + ":" + path);
269 | if (fragment == null) {
270 | if (MainActivity.isDebuggable) Log.i(TAG, "Fragment is null");
271 | // create fragment with response
272 | Bundle bundle = new Bundle();
273 | bundle.putLong("uuid", uuid);
274 | bundle.putString("path", path);
275 | bundle.putString("content", response);
276 | ConnectedFileFragment newDirectory = new ConnectedFileFragment();
277 | newDirectory.setArguments(bundle);
278 | FragmentTransaction transaction = fm.beginTransaction();
279 | transaction.replace(android.R.id.content, newDirectory, Long.toString(uuid) + ":" + path);
280 | transaction.addToBackStack(null);
281 | transaction.commit();
282 | } else {
283 | fragment.processResponse(response);
284 | }
285 | }
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 | static class IncomingHandler extends Handler {
297 | public final String TAG = "ConnectionActivity";
298 |
299 | private final WeakReference mActivity;
300 |
301 | IncomingHandler(ConnectionActivity activity) {
302 | mActivity = new WeakReference(activity);
303 | }
304 |
305 | @Override
306 | public void handleMessage(Message msg) {
307 | ConnectionActivity activity = mActivity.get();
308 | switch (msg.what) {
309 | case ConnectionService.MSG_COMMAND_RETURN:
310 | if (MainActivity.isDebuggable) Log.i(TAG, "Command returned to Activity");
311 | Bundle cmdBundle = msg.getData();
312 | String response = cmdBundle.getString("response");
313 | if (response == null) {
314 | if (MainActivity.isDebuggable) Log.i(TAG, "Opening a directory");
315 | ArrayList files = cmdBundle.getStringArrayList("files");
316 | ArrayList directories = cmdBundle.getStringArrayList("directories");
317 | activity.handleResponse(cmdBundle.getLong("uuid"), files, directories);
318 | } else {
319 | if (MainActivity.isDebuggable) Log.i(TAG, "Opening a file");
320 | activity.handleResponse(cmdBundle.getLong("uuid"), cmdBundle.getInt("command"), cmdBundle.getString("parameter"), response);
321 | }
322 | default:
323 | super.handleMessage(msg);
324 | }
325 | }
326 | }
327 |
328 | private ServiceConnection mConnection = new ServiceConnection() {
329 | public void onServiceConnected(ComponentName className, IBinder service) {
330 | if (MainActivity.isDebuggable) Log.i(TAG, "Bound to service - confirmed");
331 |
332 | // This is called when the connection with the service has been
333 | // established, giving us the service object we can use to
334 | // interact with the service. We are communicating with our
335 | // service through an IDL interface, so get a client-side
336 | // representation of that from the raw service object.
337 | mService = new Messenger(service);
338 |
339 | showQueuedConnections();
340 | sendQueuedMessagess();
341 | }
342 |
343 | public void onServiceDisconnected(ComponentName className) {
344 | // This is called when the connection with the service has been
345 | // unexpectedly disconnected -- that is, its process crashed.
346 | mService = null;
347 |
348 | // As part of the sample, tell the user what happened.
349 | if (MainActivity.isDebuggable) Log.e(TAG, "Disconnected from service unintentionally - confirmed");
350 | }
351 | };
352 |
353 | }
354 |
--------------------------------------------------------------------------------
/cooper/src/main/java/com/dconstructing/cooper/MainActivity.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Cooper, a touch-friendly SSH client for Android devices
3 | * Copyright (C) 2013 David Cox
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.dconstructing.cooper;
19 |
20 | import java.lang.ref.WeakReference;
21 | import java.util.ArrayList;
22 | import java.util.HashMap;
23 | import java.util.Iterator;
24 | import java.util.Map;
25 |
26 | import android.app.Activity;
27 | import android.app.FragmentManager;
28 | import android.app.FragmentTransaction;
29 | import android.content.ComponentName;
30 | import android.content.Context;
31 | import android.content.Intent;
32 | import android.content.ServiceConnection;
33 | import android.content.pm.ApplicationInfo;
34 | import android.os.Bundle;
35 | import android.os.Handler;
36 | import android.os.IBinder;
37 | import android.os.Message;
38 | import android.os.Messenger;
39 | import android.os.RemoteException;
40 | import android.util.Log;
41 |
42 | import com.dconstructing.cooper.fragments.ConnectionsFragment;
43 | import com.dconstructing.cooper.fragments.ConnectionsFragment.OnAddConnectionOptionListener;
44 | import com.dconstructing.cooper.fragments.NewConnectionFragment;
45 | import com.dconstructing.cooper.fragments.PasswordDialogFragment;
46 | import com.dconstructing.cooper.fragments.PasswordDialogFragment.PasswordDialogListener;
47 | import com.dconstructing.cooper.objects.Address;
48 | import com.dconstructing.cooper.objects.Connection;
49 | import com.dconstructing.cooper.services.ConnectionService;
50 |
51 |
52 | public class MainActivity extends Activity implements OnAddConnectionOptionListener, PasswordDialogListener {
53 |
54 | public final String TAG = ((Object) this).getClass().getSimpleName();
55 | public static boolean isDebuggable = false;
56 |
57 | public final static String EXTRA_MESSAGE = "com.dconstructing.cooper.MESSAGE";
58 |
59 | Messenger mService = null;
60 | ArrayList mConnectionQueue = new ArrayList();
61 | ArrayList mDisconnectionQueue = new ArrayList();
62 | public Map mConnectionsStatus = new HashMap();
63 |
64 | final Messenger mMessenger = new Messenger(new IncomingHandler(this));
65 |
66 | @Override
67 | public void onCreate(Bundle savedInstanceState) {
68 | super.onCreate(savedInstanceState);
69 | MainActivity.isDebuggable = (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE));
70 |
71 | if (MainActivity.isDebuggable) {
72 | Log.i(TAG, "Debuggable");
73 | } else {
74 | Log.i(TAG, "Not Debuggable");
75 | }
76 |
77 | if (savedInstanceState == null) {
78 | // During initial setup
79 |
80 | // plug in the connections fragment.
81 | // TODO: Add a secondary fragment for large/wide screens for two-pane view
82 | ConnectionsFragment connections = new ConnectionsFragment();
83 | connections.setArguments(getIntent().getExtras());
84 | getFragmentManager().beginTransaction().add(android.R.id.content, connections, "connections").commit();
85 | }
86 |
87 | }
88 |
89 | @Override
90 | public void onAddConnectionSelected() {
91 | // TODO: Adjust the function for a two-paned view (instead of replacing the primary fragment, replace the secondary).
92 | NewConnectionFragment newConnection = new NewConnectionFragment();
93 | FragmentTransaction transaction = getFragmentManager().beginTransaction();
94 | transaction.replace(android.R.id.content, newConnection, "addConnection");
95 | transaction.addToBackStack(null);
96 | transaction.commit();
97 | }
98 |
99 | @Override
100 | public void connectToServer(long uuid, String host, String username, boolean recycle) {
101 | if (MainActivity.isDebuggable) Log.i(TAG, "Connecting to host " + host + " with username " + username);
102 |
103 | if (mService == null) {
104 | this.queueConnection(uuid, host, username);
105 |
106 | if (MainActivity.isDebuggable) Log.i(TAG, "Gotta start the Connection Service");
107 | try {
108 | getApplicationContext().bindService(new Intent(this, ConnectionService.class), mConnection, Context.BIND_AUTO_CREATE);
109 | } catch (SecurityException e) {
110 | if (MainActivity.isDebuggable) Log.e(TAG, "Could not bind to service", e);
111 | }
112 | } else if (recycle) {
113 | if (MainActivity.isDebuggable) Log.i(TAG, "Trying to recycle connection");
114 | checkForRunningConnection(uuid, host, username);
115 | } else {
116 | if (MainActivity.isDebuggable) Log.i(TAG, "Start a new connection, requiring password");
117 | promptForPassword(uuid, host, username);
118 | }
119 | }
120 |
121 | @Override
122 | public void disconnectFromServer(long uuid) {
123 | if (MainActivity.isDebuggable) Log.i(TAG, "Disconnecting to from server " + Long.toString(uuid));
124 |
125 | if (mService == null) {
126 | this.queueDisconnection(uuid);
127 |
128 | if (MainActivity.isDebuggable) Log.i(TAG, "Gotta start the Connection Service");
129 | try {
130 | getApplicationContext().bindService(new Intent(this, ConnectionService.class), mConnection, Context.BIND_AUTO_CREATE);
131 | } catch (SecurityException e) {
132 | if (MainActivity.isDebuggable) Log.e(TAG, "Could not bind to service", e);
133 | }
134 | } else {
135 | if (MainActivity.isDebuggable) Log.i(TAG, "Trying to recycle connection");
136 | initiateDisconnection(uuid);
137 | }
138 | }
139 |
140 | @Override
141 | public void onPasswordEntered(long uuid, String host, String username, String password) {
142 | if (MainActivity.isDebuggable) Log.i(TAG, "Got password");
143 | this.initiateConnection(uuid, host, username, password);
144 | }
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 | public void updateConnections(long uuid, int status) {
155 | mConnectionsStatus.put(uuid, status);
156 | if (MainActivity.isDebuggable) Log.i(TAG, "Map:" + mConnectionsStatus.toString());
157 |
158 | ConnectionsFragment fragment = (ConnectionsFragment) getFragmentManager().findFragmentByTag("connections");
159 | if (fragment != null) {
160 | fragment.updateConnectionStatus(uuid, status);
161 | }
162 | }
163 |
164 | public void queueConnection(long uuid, String host, String username) {
165 | if (MainActivity.isDebuggable) Log.i(TAG, "Queuing host " + host + " with username " + username);
166 | Address connection = new Address();
167 | connection.id = uuid;
168 | connection.host = host;
169 | connection.username = username;
170 | mConnectionQueue.add(connection);
171 | }
172 |
173 | public void queueDisconnection(long uuid) {
174 | if (MainActivity.isDebuggable) Log.i(TAG, "Queuing host #" + Long.toString(uuid));
175 | mDisconnectionQueue.add(uuid);
176 | }
177 |
178 | public void initiateQueuedConnections() {
179 | if (MainActivity.isDebuggable) Log.i(TAG, "Working through the queue");
180 |
181 | Iterator it = mConnectionQueue.iterator();
182 | while (it.hasNext()) {
183 | Address connection = (Address) it.next();
184 | connectToServer(connection.id, connection.host, connection.username, true);
185 | it.remove();
186 | }
187 | }
188 |
189 | public void initiateQueuedDisconnections() {
190 | if (MainActivity.isDebuggable) Log.i(TAG, "Working through the disconnect queue");
191 |
192 | Iterator it = mDisconnectionQueue.iterator();
193 | while (it.hasNext()) {
194 | Long uuid = (Long) it.next();
195 | disconnectFromServer(uuid);
196 | it.remove();
197 | }
198 | }
199 |
200 | public void checkForRunningConnection(long uuid, String host, String username) {
201 | if (MainActivity.isDebuggable) Log.i(TAG, "Checking for connection");
202 | try {
203 | Bundle bundle = new Bundle();
204 | bundle.putLong("uuid",uuid);
205 | bundle.putString("host", host);
206 | bundle.putString("username", username);
207 | Message msg = Message.obtain(null, ConnectionService.MSG_CONNECTION_CHECK);
208 | if (msg != null) {
209 | msg.setData(bundle);
210 | msg.replyTo = mMessenger;
211 | mService.send(msg);
212 | }
213 | } catch (RemoteException e) {
214 | // In this case the service has crashed before we could even
215 | // do anything with it; we can count on soon being
216 | // disconnected (and then reconnected if it can be restarted)
217 | // so there is no need to do anything here.
218 | }
219 | }
220 |
221 | public void handleConnectionCheck(long uuid, String host, String username, boolean hasConnection) {
222 | if (MainActivity.isDebuggable) Log.i(TAG, "Connection check results");
223 | if (hasConnection) {
224 | if (MainActivity.isDebuggable) Log.i(TAG, "Already has connection");
225 | // open activity without starting new connection
226 | Intent intent = new Intent(this, ConnectionActivity.class);
227 | intent.putExtra("uuid", uuid);
228 | startActivity(intent);
229 | } else {
230 | if (MainActivity.isDebuggable) Log.i(TAG, "Must start new connection");
231 | // start a new connection
232 | connectToServer(uuid, host, username, false);
233 | }
234 | }
235 |
236 | public void promptForPassword(long uuid, String host, String username) {
237 | if (MainActivity.isDebuggable) Log.i(TAG, "Show password prompt");
238 | FragmentManager fm = getFragmentManager();
239 | PasswordDialogFragment passwordDialog = PasswordDialogFragment.create(uuid, host, username);
240 | passwordDialog.show(fm, "fragment_password");
241 | }
242 |
243 | public void initiateConnection(long uuid, String host, String username, String password) {
244 | if (MainActivity.isDebuggable) Log.i(TAG, "Attempting the connection with " + host + " and " + username);
245 |
246 | updateConnections(uuid, Connection.CONNECTING);
247 |
248 | try {
249 | Bundle bundle = new Bundle();
250 | bundle.putLong("uuid",uuid);
251 | bundle.putString("host",host);
252 | bundle.putInt("port",22);
253 | bundle.putString("username",username);
254 | bundle.putString("password",password);
255 | Message msg = Message.obtain(null, ConnectionService.MSG_CONNECTION_INITIATE);
256 | if (msg != null) {
257 | msg.setData(bundle);
258 | msg.replyTo = mMessenger;
259 | mService.send(msg);
260 | }
261 | } catch (RemoteException e) {
262 | // In this case the service has crashed before we could even
263 | // do anything with it; we can count on soon being
264 | // disconnected (and then reconnected if it can be restarted)
265 | // so there is no need to do anything here.
266 | }
267 | }
268 |
269 | public void initiateDisconnection(long uuid) {
270 | if (MainActivity.isDebuggable) Log.i(TAG, "Attempting to diconnect from " + Long.toString(uuid));
271 |
272 | updateConnections(uuid, Connection.DISCONNECTING);
273 |
274 | try {
275 | Bundle bundle = new Bundle();
276 | bundle.putLong("uuid", uuid);
277 | Message msg = Message.obtain(null, ConnectionService.MSG_CONNECTION_TERMINATE);
278 | if (msg != null) {
279 | msg.setData(bundle);
280 | msg.replyTo = mMessenger;
281 | mService.send(msg);
282 | }
283 | } catch (RemoteException e) {
284 | // In this case the service has crashed before we could even
285 | // do anything with it; we can count on soon being
286 | // disconnected (and then reconnected if it can be restarted)
287 | // so there is no need to do anything here.
288 | }
289 | }
290 |
291 | public void connectionEstablished(long uuid) {
292 | if (MainActivity.isDebuggable) Log.i(TAG, "Creating a new fragment for this connection with tag (" + Long.toString(uuid) + ")");
293 |
294 | updateConnections(uuid, Connection.CONNECTED);
295 |
296 | // Open the Connection Activity
297 | Intent intent = new Intent(this, ConnectionActivity.class);
298 | intent.putExtra("uuid", uuid);
299 | startActivity(intent);
300 | }
301 |
302 | public void connectionDestroyed(long uuid) {
303 | if (MainActivity.isDebuggable) Log.i(TAG, "Destroying a fragment for this connection with tag (" + Long.toString(uuid) + ")");
304 |
305 | updateConnections(uuid, Connection.NOT_CONNECTED);
306 |
307 | // TODO: Make sure the fragment for this connection is cleared away.
308 | // Open the Connection Activity
309 | // Intent intent = new Intent(this, ConnectionActivity.class);
310 | // intent.putExtra("uuid", uuid);
311 | // startActivity(intent);
312 | }
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 | static class IncomingHandler extends Handler {
321 | private final WeakReference mActivity;
322 |
323 | IncomingHandler(MainActivity activity) {
324 | mActivity = new WeakReference(activity);
325 | }
326 |
327 | @Override
328 | public void handleMessage(Message msg) {
329 | MainActivity activity = mActivity.get();
330 | if (activity != null) {
331 | switch (msg.what) {
332 | case ConnectionService.MSG_CONNECTION_ESTABLISHED:
333 | // Do something become the connection was complete
334 | if (MainActivity.isDebuggable) Log.i(activity.TAG, "Service connection to server - confirmed");
335 | Bundle bundle = msg.getData();
336 | if (bundle != null) {
337 | activity.connectionEstablished(bundle.getLong("uuid"));
338 | }
339 | break;
340 | case ConnectionService.MSG_CONNECTION_DESTROYED:
341 | // Do something become the connection was cut off
342 | if (MainActivity.isDebuggable) Log.i(activity.TAG, "Service connection to server - closed");
343 | Bundle destroyedBundle = msg.getData();
344 | if (destroyedBundle != null) {
345 | activity.connectionDestroyed(destroyedBundle.getLong("uuid"));
346 | }
347 | break;
348 | case ConnectionService.MSG_CONNECTION_CHECKED:
349 | Bundle checkedBundle = msg.getData();
350 | if (checkedBundle != null) {
351 | boolean hasConnection = checkedBundle.getBoolean("hasConnection");
352 | long uuid = checkedBundle.getLong("uuid");
353 | activity.handleConnectionCheck(uuid, checkedBundle.getString("host"), checkedBundle.getString("username"), hasConnection);
354 | }
355 | break;
356 | default:
357 | super.handleMessage(msg);
358 | }
359 | }
360 | }
361 | }
362 |
363 | private ServiceConnection mConnection = new ServiceConnection() {
364 | public void onServiceConnected(ComponentName className, IBinder service) {
365 | if (MainActivity.isDebuggable) Log.i(TAG, "Bound to service - confirmed");
366 |
367 | // This is called when the connection with the service has been
368 | // established, giving us the service object we can use to
369 | // interact with the service. We are communicating with our
370 | // service through an IDL interface, so get a client-side
371 | // representation of that from the raw service object.
372 | mService = new Messenger(service);
373 |
374 | initiateQueuedConnections();
375 | initiateQueuedDisconnections();
376 | }
377 |
378 | public void onServiceDisconnected(ComponentName className) {
379 | // This is called when the connection with the service has been
380 | // unexpectedly disconnected -- that is, its process crashed.
381 | mService = null;
382 |
383 | // As part of the sample, tell the user what happened.
384 | if (MainActivity.isDebuggable) Log.e(TAG, "Disconnected from service unintentionally - confirmed");
385 | }
386 | };
387 |
388 | }
--------------------------------------------------------------------------------
/cooper/src/main/java/com/dconstructing/cooper/adapters/ConnectionAdapter.java:
--------------------------------------------------------------------------------
1 | package com.dconstructing.cooper.adapters;
2 |
3 | import android.content.Context;
4 | import android.database.Cursor;
5 | import android.graphics.Color;
6 | import android.provider.BaseColumns;
7 | import android.util.Log;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.CursorAdapter;
12 | import android.widget.ProgressBar;
13 | import android.widget.RelativeLayout;
14 | import android.widget.TextView;
15 |
16 | import com.dconstructing.cooper.MainActivity;
17 | import com.dconstructing.cooper.R;
18 | import com.dconstructing.cooper.database.CooperOpenHelper;
19 | import com.dconstructing.cooper.objects.Connection;
20 |
21 | /**
22 | * Created by dcox on 10/10/13.
23 | */
24 | public class ConnectionAdapter extends CursorAdapter {
25 |
26 | public final String TAG = getClass().getSimpleName();
27 |
28 | private Cursor mCursor;
29 | private Context mContext;
30 | private final LayoutInflater mInflater;
31 |
32 |
33 | public ConnectionAdapter(Context context, Cursor cursor) {
34 | super(context, cursor, 0);
35 | mInflater = LayoutInflater.from(context);
36 | mContext = context;
37 | }
38 |
39 | @Override
40 | public void bindView(View view, Context context, Cursor cursor) {
41 | long entryId = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID));
42 | if (MainActivity.isDebuggable) Log.i(TAG, "Item created:" + Long.toString(entryId));
43 |
44 | TextView mainText = (TextView)view.findViewById(android.R.id.text1);
45 | mainText.setText(cursor.getString(cursor.getColumnIndex(CooperOpenHelper.USERNAME_FIELD_NAME)));
46 |
47 | TextView secondaryText = (TextView)view.findViewById(android.R.id.text2);
48 | secondaryText.setText(cursor.getString(cursor.getColumnIndex(CooperOpenHelper.HOST_FIELD_NAME)));
49 |
50 | RelativeLayout indicatorContainer = (RelativeLayout)view.findViewById(R.id.connection_status);
51 | ProgressBar progressBar = (ProgressBar)indicatorContainer.findViewById(R.id.progressBar);
52 |
53 | MainActivity activity = (MainActivity) context;
54 | if (MainActivity.isDebuggable) Log.i(TAG, "Map:" + activity.mConnectionsStatus.toString());
55 | if (activity.mConnectionsStatus.containsKey(entryId)) {
56 | if (MainActivity.isDebuggable) Log.i(TAG, "Map contains:" + Long.toString(entryId));
57 | switch(activity.mConnectionsStatus.get(entryId)) {
58 | case Connection.CONNECTING:
59 | indicatorContainer.setBackgroundColor(Color.argb(32,255,255,0));
60 | progressBar.setVisibility(View.VISIBLE);
61 | break;
62 | case Connection.CONNECTED:
63 | indicatorContainer.setBackgroundColor(Color.argb(32,0,255,0));
64 | progressBar.setVisibility(View.INVISIBLE);
65 | break;
66 | case Connection.DISCONNECTING:
67 | indicatorContainer.setBackgroundColor(Color.argb(32,255,255,0));
68 | progressBar.setVisibility(View.VISIBLE);
69 | break;
70 | default:
71 | indicatorContainer.setBackgroundColor(Color.argb(32,255,0,0));
72 | progressBar.setVisibility(View.INVISIBLE);
73 | break;
74 | }
75 | } else {
76 | if (MainActivity.isDebuggable) Log.i(TAG, "Map does not contain:" + Long.toString(entryId));
77 | indicatorContainer.setBackgroundColor(Color.argb(32,255,0,0));
78 | progressBar.setVisibility(View.INVISIBLE);
79 | }
80 | }
81 |
82 | @Override
83 | public View newView(Context context, Cursor cursor, ViewGroup parent) {
84 | final View view = mInflater.inflate(R.layout.connection_list_item, parent, false);
85 | return view;
86 | }
87 |
88 | }
--------------------------------------------------------------------------------
/cooper/src/main/java/com/dconstructing/cooper/contentproviders/ConnectionsContentProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Cooper, a touch-friendly SSH client for Android devices
3 | * Copyright (C) 2013 David Cox
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.dconstructing.cooper.contentproviders;
19 |
20 | import android.content.ContentProvider;
21 | import android.content.ContentResolver;
22 | import android.content.ContentValues;
23 | import android.content.UriMatcher;
24 | import android.database.Cursor;
25 | import android.database.SQLException;
26 | import android.database.sqlite.SQLiteQueryBuilder;
27 | import android.net.Uri;
28 | import android.util.Log;
29 |
30 | import com.dconstructing.cooper.MainActivity;
31 | import com.dconstructing.cooper.database.CooperOpenHelper;
32 |
33 | public class ConnectionsContentProvider extends ContentProvider {
34 |
35 | public final String TAG = getClass().getSimpleName();
36 |
37 | public static final int ALL_CONNECTIONS = 1;
38 |
39 | private static final int CONNECTIONS = 10;
40 | private static final int CONNECTION_ID = 20;
41 |
42 | private static final String AUTHORITY = "com.dconstructing.cooper.contentproviders";
43 | private static final String BASE_PATH = "connections";
44 | public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/" + BASE_PATH);
45 |
46 | public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/todos";
47 | public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/todo";
48 | private static final UriMatcher sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH);
49 |
50 | static {
51 | sURIMatcher.addURI(AUTHORITY, BASE_PATH, CONNECTIONS);
52 | sURIMatcher.addURI(AUTHORITY, BASE_PATH + "/#", CONNECTION_ID);
53 | }
54 |
55 | protected CooperOpenHelper mOpenHelper;
56 |
57 | public ConnectionsContentProvider() {
58 | // TODO Auto-generated constructor stub
59 | }
60 |
61 | @Override
62 | public int delete(Uri arg0, String arg1, String[] arg2) {
63 | // TODO Auto-generated method stub
64 | return 0;
65 | }
66 |
67 | @Override
68 | public String getType(Uri uri) {
69 | // TODO Auto-generated method stub
70 | return null;
71 | }
72 |
73 | @Override
74 | public Uri insert(Uri uri, ContentValues values) {
75 | if (MainActivity.isDebuggable) Log.i(TAG, "Insert URI: " + uri.toString());
76 | long rowId = 0;
77 |
78 | int uriType = sURIMatcher.match(uri);
79 | switch (uriType) {
80 | case CONNECTIONS:
81 | rowId = mOpenHelper.getWritableDatabase().insert(CooperOpenHelper.CONNECTIONS_TABLE_NAME, null, values);
82 | if (MainActivity.isDebuggable) Log.i(TAG, "New Row: " + Long.toString(rowId));
83 | break;
84 | default:
85 | throw new IllegalArgumentException("Unknown URI");
86 | }
87 |
88 | if (rowId > 0) {
89 | if (MainActivity.isDebuggable) Log.i(TAG, "Notifying of update");
90 | getContext().getContentResolver().notifyChange(uri, null);
91 |
92 | Uri newUri = uri.buildUpon().appendPath(String.valueOf(rowId)).build();
93 | getContext().getContentResolver().notifyChange(newUri, null);
94 | return newUri;
95 | }
96 |
97 | throw new SQLException("Failed to insert row into " + uri);
98 | }
99 |
100 | @Override
101 | public boolean onCreate() {
102 | mOpenHelper = new CooperOpenHelper(getContext());
103 | return true;
104 | }
105 |
106 | @Override
107 | public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
108 | if (MainActivity.isDebuggable) Log.i(TAG, "Query URI: " + uri.toString());
109 |
110 | int uriType = sURIMatcher.match(uri);
111 | switch (uriType) {
112 | case CONNECTIONS:
113 | SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
114 | queryBuilder.setTables(CooperOpenHelper.CONNECTIONS_TABLE_NAME);
115 | Cursor cursor = queryBuilder.query(mOpenHelper.getReadableDatabase(), projection, selection, selectionArgs, null, null, sortOrder);
116 | cursor.setNotificationUri(getContext().getContentResolver(), uri); // to get this to update when the URI is notified of change (in updates/inserts)
117 | return cursor;
118 | default:
119 | return null;
120 | }
121 | }
122 |
123 | @Override
124 | public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
125 | int numOfRows = 0;
126 |
127 | int uriType = sURIMatcher.match(uri);
128 | switch (uriType) {
129 | case CONNECTIONS:
130 | numOfRows = mOpenHelper.getWritableDatabase().update(CooperOpenHelper.CONNECTIONS_TABLE_NAME, values, selection, selectionArgs);
131 | break;
132 | default:
133 | throw new IllegalArgumentException("Unknown URI: " + uri.toString());
134 | }
135 |
136 | if (numOfRows > 0) {
137 | getContext().getContentResolver().notifyChange(uri, null);
138 | }
139 |
140 | return numOfRows;
141 | }
142 |
143 | }
144 |
--------------------------------------------------------------------------------
/cooper/src/main/java/com/dconstructing/cooper/database/CooperOpenHelper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Cooper, a touch-friendly SSH client for Android devices
3 | * Copyright (C) 2013 David Cox
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.dconstructing.cooper.database;
19 |
20 | import android.content.Context;
21 | import android.database.sqlite.SQLiteDatabase;
22 | import android.database.sqlite.SQLiteOpenHelper;
23 | import android.provider.BaseColumns;
24 |
25 | /**
26 | * @author burgundy
27 | *
28 | */
29 | public class CooperOpenHelper extends SQLiteOpenHelper {
30 |
31 | public final String TAG = getClass().getSimpleName();
32 |
33 | public static final String DATABASE_NAME="connections.db";
34 | public static final int DATABASE_VERSION=1;
35 |
36 | public static final String CONNECTIONS_TABLE_NAME="connections";
37 | public static final String USERNAME_FIELD_NAME="username";
38 | public static final String HOST_FIELD_NAME="host";
39 |
40 | private static final String CONNECTIONS_TABLE_CREATE =
41 | "CREATE TABLE " + CONNECTIONS_TABLE_NAME + " (" +
42 | BaseColumns._ID + " INTEGER PRIMARY KEY, " +
43 | USERNAME_FIELD_NAME + " TEXT, " +
44 | HOST_FIELD_NAME + " TEXT);";
45 |
46 |
47 | public CooperOpenHelper(Context context) {
48 | super(context, DATABASE_NAME, null, DATABASE_VERSION);
49 | }
50 |
51 | @Override
52 | public void onCreate(SQLiteDatabase db) {
53 | db.execSQL(CONNECTIONS_TABLE_CREATE);
54 |
55 | }
56 |
57 | @Override
58 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/cooper/src/main/java/com/dconstructing/cooper/fragments/ConnectedDirectoryFragment.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Cooper, a touch-friendly SSH client for Android devices
3 | * Copyright (C) 2013 David Cox
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.dconstructing.cooper.fragments;
19 |
20 | import java.util.ArrayList;
21 |
22 | import android.app.Activity;
23 | import android.app.ListFragment;
24 | import android.os.Bundle;
25 | import android.util.Log;
26 | import android.view.LayoutInflater;
27 | import android.view.View;
28 | import android.view.ViewGroup;
29 | import android.widget.ArrayAdapter;
30 | import android.widget.ListView;
31 |
32 | import com.dconstructing.cooper.MainActivity;
33 | import com.dconstructing.cooper.R;
34 | import com.dconstructing.cooper.objects.FilePath;
35 |
36 | public class ConnectedDirectoryFragment extends ListFragment {
37 |
38 | public final String TAG = getClass().getSimpleName();
39 |
40 | DirectoryListener mDirectoryCallback;
41 | ArrayList mFiles;
42 | ArrayList mDirectories;
43 |
44 | @Override
45 | public void onAttach(Activity activity) {
46 | super.onAttach(activity);
47 |
48 | // Check to ensure the calling Activity implements DirectoryListener
49 | // and is therefore ready to handle callbacks.
50 | try {
51 | mDirectoryCallback = (DirectoryListener) activity;
52 | } catch (ClassCastException e) {
53 | throw new ClassCastException(activity.toString() + " must implement DirectoryListener");
54 | }
55 | }
56 |
57 | @Override
58 | public void onCreate(Bundle savedInstanceState) {
59 | if (MainActivity.isDebuggable) Log.i(TAG, "onCreate");
60 | super.onCreate(savedInstanceState);
61 | Bundle arguments = getArguments();
62 | if (arguments != null) {
63 | mFiles = arguments.getStringArrayList("files");
64 | mDirectories = arguments.getStringArrayList("directories");
65 | }
66 | }
67 |
68 | @Override
69 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
70 | if (MainActivity.isDebuggable) Log.i(TAG, "onCreateView");
71 | setRetainInstance(true);
72 | return inflater.inflate(R.layout.fragment_directory, container, false);
73 | }
74 |
75 | @Override
76 | public void onActivityCreated(Bundle savedInstanceState) {
77 | if (MainActivity.isDebuggable) Log.i(TAG, "onActivityCreated");
78 | super.onActivityCreated(savedInstanceState);
79 |
80 | if (savedInstanceState == null) {
81 | ArrayList list = new ArrayList();
82 | if (mDirectories != null) {
83 | for(String directory : mDirectories) {
84 | list.add(new FilePath(directory, true));
85 | }
86 | }
87 | if (mFiles != null) {
88 | for(String file : mFiles) {
89 | list.add(new FilePath(file, false));
90 | }
91 | }
92 | ArrayAdapter adapter = new ArrayAdapter(this.getActivity(),
93 | android.R.layout.simple_list_item_1,
94 | list);
95 | setListAdapter(adapter);
96 | }
97 | }
98 |
99 | @Override
100 | public void onListItemClick(ListView list, View view, int position, long id) {
101 | if (MainActivity.isDebuggable) Log.i(TAG, "Position: " + position + " ID: " + id);
102 | super.onListItemClick(list, view, position, id);
103 |
104 | final FilePath item = (FilePath) list.getItemAtPosition(position);
105 | if (MainActivity.isDebuggable) Log.i(TAG, "String: " + item);
106 |
107 | mDirectoryCallback.onDirectoryItemSelected(getTag(), item);
108 | }
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 | public void processResponse(ArrayList files, ArrayList directories) {
118 | if (MainActivity.isDebuggable) Log.i(TAG, "Processing new directory");
119 |
120 | ArrayAdapter adapter = (ArrayAdapter)getListAdapter();
121 | adapter.setNotifyOnChange(false);
122 | adapter.clear();
123 |
124 | for (String directory : directories) {
125 | if (MainActivity.isDebuggable) Log.i(TAG, "Adding " + directory + " to directory");
126 | adapter.add(new FilePath(directory, true));
127 | }
128 | for (String file : files) {
129 | if (MainActivity.isDebuggable) Log.i(TAG, "Adding " + file + " to directory");
130 | adapter.add(new FilePath(file, false));
131 | }
132 |
133 | if (MainActivity.isDebuggable) Log.i(TAG, "Directory contents processed");
134 | adapter.notifyDataSetChanged();
135 | }
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 | public interface DirectoryListener {
144 | public void onDirectoryItemSelected(String tag, FilePath filePath);
145 | }
146 |
147 | }
148 |
--------------------------------------------------------------------------------
/cooper/src/main/java/com/dconstructing/cooper/fragments/ConnectedFileFragment.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Cooper, a touch-friendly SSH client for Android devices
3 | * Copyright (C) 2013 David Cox
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.dconstructing.cooper.fragments;
19 |
20 | import android.app.Activity;
21 | import android.app.Fragment;
22 | import android.os.Bundle;
23 | import android.util.Log;
24 | import android.view.LayoutInflater;
25 | import android.view.View;
26 | import android.view.ViewGroup;
27 | import android.widget.EditText;
28 |
29 | import com.dconstructing.cooper.MainActivity;
30 | import com.dconstructing.cooper.R;
31 | import com.dconstructing.cooper.objects.FilePath;
32 |
33 | public class ConnectedFileFragment extends Fragment {
34 |
35 | public final String TAG = getClass().getSimpleName();
36 |
37 | FileListener mFileCallback;
38 | FilePath mPath;
39 | String mContent;
40 | Long mUuid;
41 |
42 | @Override
43 | public void onAttach(Activity activity) {
44 | super.onAttach(activity);
45 |
46 | // Check to ensure the calling Activity implements DirectoryListener
47 | // and is therefore ready to handle callbacks.
48 | try {
49 | mFileCallback = (FileListener) activity;
50 | } catch (ClassCastException e) {
51 | throw new ClassCastException(activity.toString() + " must implement FileListener");
52 | }
53 | }
54 |
55 | @Override
56 | public void onCreate(Bundle savedInstanceState) {
57 | super.onCreate(savedInstanceState);
58 | Bundle arguments = getArguments();
59 | if (arguments != null) {
60 | mPath = new FilePath(arguments.getString("path"), false);
61 | mContent = arguments.getString("content");
62 | mUuid = arguments.getLong("uuid");
63 | }
64 | }
65 |
66 | @Override
67 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
68 | if (MainActivity.isDebuggable) Log.i(TAG, "onCreateView");
69 | setRetainInstance(true);
70 | return inflater.inflate(R.layout.fragment_file, container, false);
71 | }
72 |
73 | @Override
74 | public void onActivityCreated(Bundle savedInstanceState) {
75 | super.onActivityCreated(savedInstanceState);
76 |
77 | if (savedInstanceState == null) {
78 | insertContent();
79 | }
80 | }
81 |
82 | @Override
83 | public void onDestroyView() {
84 | if (MainActivity.isDebuggable) Log.i(TAG, "onDestroyView");
85 | saveContent();
86 | super.onDestroyView();
87 | }
88 |
89 |
90 |
91 |
92 |
93 |
94 | public void processResponse(String content) {
95 | mContent = content;
96 | insertContent();
97 | }
98 |
99 | public void insertContent() {
100 | EditText editor = (EditText)getView().findViewById(R.id.fileContent);
101 | editor.setHorizontallyScrolling(true);
102 | if (mContent != null) {
103 | editor.setText(mContent);
104 | }
105 | }
106 |
107 | public void saveContent() {
108 | if (MainActivity.isDebuggable) Log.i(TAG, "Saving Content");
109 | String content = ((EditText)getView().findViewById(R.id.fileContent)).getText().toString();
110 | if (content != null) {
111 | mFileCallback.onFileSaved(mUuid, mPath, content);
112 | }
113 | }
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 | public interface FileListener {
122 | public void onFileSaved(Long Uuid, FilePath filePath, String content);
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/cooper/src/main/java/com/dconstructing/cooper/fragments/ConnectionsFragment.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Cooper, a touch-friendly SSH client for Android devices
3 | * Copyright (C) 2013 David Cox
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.dconstructing.cooper.fragments;
19 |
20 | import java.lang.ref.WeakReference;
21 |
22 | import android.app.Activity;
23 | import android.app.ListFragment;
24 | import android.app.LoaderManager;
25 | import android.content.CursorLoader;
26 | import android.content.Loader;
27 | import android.database.Cursor;
28 | import android.graphics.Color;
29 | import android.os.Bundle;
30 | import android.os.Handler;
31 | import android.os.Message;
32 | import android.provider.BaseColumns;
33 | import android.util.Log;
34 | import android.view.ContextMenu;
35 | import android.view.LayoutInflater;
36 | import android.view.Menu;
37 | import android.view.MenuInflater;
38 | import android.view.MenuItem;
39 | import android.view.View;
40 | import android.view.ViewGroup;
41 | import android.widget.AdapterView;
42 | import android.widget.ListAdapter;
43 | import android.widget.ListView;
44 | import android.widget.SimpleCursorAdapter;
45 | import android.widget.SimpleCursorAdapter.ViewBinder;
46 |
47 | import com.dconstructing.cooper.MainActivity;
48 | import com.dconstructing.cooper.R;
49 | import com.dconstructing.cooper.adapters.ConnectionAdapter;
50 | import com.dconstructing.cooper.contentproviders.ConnectionsContentProvider;
51 | import com.dconstructing.cooper.database.CooperOpenHelper;
52 | import com.dconstructing.cooper.objects.Connection;
53 |
54 | public class ConnectionsFragment extends ListFragment implements LoaderManager.LoaderCallbacks {
55 |
56 | public final String TAG = getClass().getSimpleName();
57 |
58 | public static final int MSG_SHOW_ADD_PAGE = 101;
59 |
60 | OnAddConnectionOptionListener mAddConnectionCallback;
61 | ConnectionAdapter mAdapter;
62 |
63 | boolean defaultedToAdd = false;
64 |
65 | private Handler mHandler = new IncomingHandler(this);
66 |
67 | @Override
68 | public void onAttach(Activity activity) {
69 | super.onAttach(activity);
70 |
71 | // Check to ensure the calling Activity implements OnAddConnectionOptionListener
72 | // and is therefore ready to handle callbacks.
73 | try {
74 | mAddConnectionCallback = (OnAddConnectionOptionListener) activity;
75 | } catch (ClassCastException e) {
76 | throw new ClassCastException(activity.toString() + " must implement OnAddConnectionOptionListener");
77 | }
78 | }
79 |
80 | @Override
81 | public void onCreate(Bundle savedInstanceState) {
82 | super.onCreate(savedInstanceState);
83 | setHasOptionsMenu(true); // Let the Activity know that this Fragment has menu options to add.
84 | }
85 |
86 | @Override
87 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
88 | setRetainInstance(true);
89 | return inflater.inflate(R.layout.fragment_connections, container, false);
90 | }
91 |
92 | @Override
93 | public void onViewCreated (View view, Bundle savedInstanceState) {
94 | registerForContextMenu(getListView());
95 | }
96 |
97 | @Override
98 | public void onActivityCreated(Bundle savedInstanceState) {
99 | super.onActivityCreated(savedInstanceState);
100 |
101 | if (savedInstanceState == null) {
102 | mAdapter = new ConnectionAdapter(this.getActivity(), null);
103 | setListAdapter(mAdapter);
104 |
105 | // Open the database
106 | getLoaderManager().initLoader(ConnectionsContentProvider.ALL_CONNECTIONS, null, this);
107 | }
108 | }
109 |
110 | @Override
111 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
112 | inflater.inflate(R.menu.connections, menu); // Add this Fragment's menu items to the menu.
113 | }
114 |
115 | @Override
116 | public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
117 | super.onCreateContextMenu(menu, view, menuInfo);
118 | menu.add(Menu.NONE, R.id.disconnect, Menu.NONE, R.string.disconnect);
119 | }
120 |
121 | @Override
122 | public boolean onContextItemSelected(MenuItem item) {
123 | AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
124 | if (menuInfo != null) {
125 | switch (item.getItemId()) {
126 | case R.id.disconnect:
127 | mAddConnectionCallback.disconnectFromServer(menuInfo.id);
128 | return true;
129 | }
130 | }
131 | return super.onContextItemSelected(item);
132 | }
133 |
134 | @Override
135 | public void onListItemClick(ListView list, View view, int position, long id) {
136 | if (MainActivity.isDebuggable) Log.i(TAG, "Position: " + position + " ID: " + id);
137 | super.onListItemClick(list, view, position, id);
138 |
139 | Cursor cursor = (Cursor) list.getItemAtPosition(position);
140 | if (cursor != null) {
141 | String host = cursor.getString(cursor.getColumnIndex(CooperOpenHelper.HOST_FIELD_NAME));
142 | String username = cursor.getString(cursor.getColumnIndex(CooperOpenHelper.USERNAME_FIELD_NAME));
143 |
144 | mAddConnectionCallback.connectToServer(id, host, username, true);
145 | } else {
146 | if (MainActivity.isDebuggable) Log.e(TAG, "Cursor was not found from item click");
147 | }
148 | }
149 |
150 | @Override
151 | public boolean onOptionsItemSelected(MenuItem item) {
152 | switch (item.getItemId()) {
153 | case R.id.add_connection:
154 | if (MainActivity.isDebuggable) Log.i(TAG, "Menu Item - Add Connection");
155 | mHandler.sendEmptyMessage(MSG_SHOW_ADD_PAGE);
156 | return true;
157 | default:
158 | return super.onOptionsItemSelected(item);
159 | }
160 | }
161 |
162 | @Override
163 | public Loader onCreateLoader(int loaderId, Bundle bundle) {
164 | switch(loaderId) {
165 | case ConnectionsContentProvider.ALL_CONNECTIONS:
166 | String[] projection = {BaseColumns._ID,
167 | CooperOpenHelper.USERNAME_FIELD_NAME,
168 | CooperOpenHelper.HOST_FIELD_NAME};
169 | String selection = null;
170 | String[] args = null;
171 | String sort = null;
172 | return new CursorLoader(getActivity(), ConnectionsContentProvider.CONTENT_URI, projection, selection, args, sort);
173 | default:
174 | return null;
175 | }
176 | }
177 |
178 | @Override
179 | public void onLoadFinished(Loader loader, Cursor cursor) {
180 | if (MainActivity.isDebuggable) Log.i(TAG, "Finished Loading Loader");
181 | switch (loader.getId()) {
182 | case ConnectionsContentProvider.ALL_CONNECTIONS:
183 | if (cursor.getCount() > 0) {
184 | if (MainActivity.isDebuggable) Log.i(TAG, "Got " + Integer.toString(cursor.getCount()) + " connections from database.");
185 | mAdapter.swapCursor(cursor);
186 | } else {
187 | if (MainActivity.isDebuggable) Log.i(TAG, "No connections in database. Prompt for a new one.");
188 | mAdapter.swapCursor(null);
189 | if (!defaultedToAdd) {
190 | defaultedToAdd = true; // Don't keep forcing the add page if they move away from it the first time it's pushed on them.
191 | mHandler.sendEmptyMessage(MSG_SHOW_ADD_PAGE);
192 | }
193 | }
194 | break;
195 | default:
196 | if (MainActivity.isDebuggable) Log.i(TAG, "Unknown loader id: " + Integer.toString(loader.getId()));
197 | break;
198 | }
199 | }
200 |
201 | @Override
202 | public void onLoaderReset(Loader arg0) {
203 | if (MainActivity.isDebuggable) Log.i(TAG, "Loader being reset");
204 | mAdapter.swapCursor(null);
205 | }
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 | public void updateConnectionStatus(long uuid, int status) {
216 | if (MainActivity.isDebuggable) Log.i(TAG, "Updating status of "+Long.toString(uuid)+". New status is "+Integer.toString(status));
217 | mAdapter.notifyDataSetChanged();
218 | }
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 | static class IncomingHandler extends Handler {
228 | private final WeakReference mFragment;
229 |
230 | IncomingHandler(ConnectionsFragment fragment) {
231 | mFragment = new WeakReference(fragment);
232 | }
233 |
234 | /**
235 | * Have to jump through this hoop because we want to move immediately to the add page
236 | * if the home page is loaded without any connections to display. We can't to a
237 | * fragment transaction called from onLoadFinished of the Loader Callbacks.
238 | * Even the Contextual Action Bar uses this message because we don't want to do the
239 | * same thing from multiple locations.
240 | */
241 | @Override
242 | public void handleMessage(Message msg) {
243 | ConnectionsFragment fragment = mFragment.get();
244 | if(msg.what == MSG_SHOW_ADD_PAGE) {
245 | fragment.mAddConnectionCallback.onAddConnectionSelected();
246 | }
247 | }
248 | };
249 |
250 | public interface OnAddConnectionOptionListener {
251 | public void onAddConnectionSelected();
252 | public void connectToServer(long uuid, String host, String username, boolean recycle);
253 | public void disconnectFromServer(long uuid);
254 | }
255 | }
256 |
--------------------------------------------------------------------------------
/cooper/src/main/java/com/dconstructing/cooper/fragments/NewConnectionFragment.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Cooper, a touch-friendly SSH client for Android devices
3 | * Copyright (C) 2013 David Cox
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.dconstructing.cooper.fragments;
19 |
20 | import android.app.Fragment;
21 | import android.content.ContentValues;
22 | import android.net.Uri;
23 | import android.os.Bundle;
24 | import android.util.Log;
25 | import android.view.ActionMode;
26 | import android.view.LayoutInflater;
27 | import android.view.Menu;
28 | import android.view.MenuInflater;
29 | import android.view.MenuItem;
30 | import android.view.View;
31 | import android.view.ViewGroup;
32 | import android.widget.EditText;
33 |
34 | import com.dconstructing.cooper.MainActivity;
35 | import com.dconstructing.cooper.R;
36 | import com.dconstructing.cooper.contentproviders.ConnectionsContentProvider;
37 | import com.dconstructing.cooper.database.CooperOpenHelper;
38 |
39 | public class NewConnectionFragment extends Fragment {
40 |
41 | public final String TAG = getClass().getSimpleName();
42 |
43 | ActionMode mActionMode;
44 | EditText mAddressField;
45 | EditText mUsernameField;
46 |
47 | @Override
48 | public void onCreate(Bundle savedInstanceState) {
49 | super.onCreate(savedInstanceState);
50 |
51 | mActionMode = getActivity().startActionMode(mActionModeCallback);
52 | }
53 |
54 | @Override
55 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
56 | View view = inflater.inflate(R.layout.fragment_new_connection, container, false);
57 |
58 | mAddressField = (EditText) view.findViewById(R.id.connection_address_field);
59 | mUsernameField = (EditText) view.findViewById(R.id.connection_username_field);
60 |
61 | return view;
62 | }
63 |
64 |
65 |
66 |
67 | private void saveConnection() {
68 | if (!mAddressField.getText().toString().equals("") && !mUsernameField.getText().toString().equals("")) {
69 | ContentValues contentValues = new ContentValues();
70 | contentValues.put(CooperOpenHelper.HOST_FIELD_NAME, mAddressField.getText().toString()); // string
71 | contentValues.put(CooperOpenHelper.USERNAME_FIELD_NAME, mUsernameField.getText().toString()); // string
72 |
73 | boolean idSet = false;
74 | if (idSet) {
75 | String selection = null;
76 | String[] selectionArgs = null;
77 |
78 | int rowsUpdated = getActivity().getContentResolver().update(ConnectionsContentProvider.CONTENT_URI, contentValues, selection, selectionArgs);
79 | } else {
80 | Uri newUri = getActivity().getContentResolver().insert(ConnectionsContentProvider.CONTENT_URI, contentValues);
81 | }
82 | }
83 | }
84 |
85 |
86 |
87 |
88 | private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
89 |
90 | // Called when the action mode is created; startActionMode() was called
91 | @Override
92 | public boolean onCreateActionMode(ActionMode mode, Menu menu) {
93 | MenuInflater inflater = mode.getMenuInflater();
94 | inflater.inflate(R.menu.new_connection, menu);
95 | mode.setTitle(R.string.add_connection);
96 | return true;
97 | }
98 |
99 | // Called each time the action mode is shown. Always called after onCreateActionMode, but
100 | // may be called multiple times if the mode is invalidated.
101 | @Override
102 | public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
103 | return false; // Return false if nothing is done
104 | }
105 |
106 | // Called when the user selects a contextual menu item
107 | @Override
108 | public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
109 | switch (item.getItemId()) {
110 | case R.id.cancel_new_connection:
111 | if (MainActivity.isDebuggable) Log.i(TAG, "Canceling save");
112 | // TODO: In order to cancel, key information will need to be cleared before destroying.
113 | mAddressField.setText("");
114 | mUsernameField.setText("");
115 |
116 | mode.finish(); // Action picked, so close the CAB
117 | return true;
118 | default:
119 | if (MainActivity.isDebuggable) Log.i(TAG, "Pressed: " + Integer.toString(item.getItemId()));
120 | return false;
121 | }
122 | }
123 |
124 | // Called when the user exits the action mode
125 | @Override
126 | public void onDestroyActionMode(ActionMode mode) {
127 | if (MainActivity.isDebuggable) Log.i(TAG, "Address to Save: " + mAddressField.getText());
128 | if (MainActivity.isDebuggable) Log.i(TAG, "Username to Save: " + mUsernameField.getText());
129 | if (MainActivity.isDebuggable) Log.i(TAG, "Destroying ActionMode");
130 | mActionMode = null;
131 | saveConnection();
132 | getFragmentManager().popBackStack(); // to go back
133 | }
134 | };
135 | }
136 |
--------------------------------------------------------------------------------
/cooper/src/main/java/com/dconstructing/cooper/fragments/PasswordDialogFragment.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Cooper, a touch-friendly SSH client for Android devices
3 | * Copyright (C) 2013 David Cox
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.dconstructing.cooper.fragments;
19 |
20 | import android.app.AlertDialog;
21 | import android.app.Dialog;
22 | import android.app.DialogFragment;
23 | import android.content.DialogInterface;
24 | import android.os.Bundle;
25 | import android.util.Log;
26 | import android.view.KeyEvent;
27 | import android.view.LayoutInflater;
28 | import android.view.View;
29 | import android.view.ViewGroup;
30 | import android.view.WindowManager.LayoutParams;
31 | import android.view.inputmethod.EditorInfo;
32 | import android.widget.EditText;
33 | import android.widget.TextView;
34 | import android.widget.TextView.OnEditorActionListener;
35 |
36 | import com.dconstructing.cooper.MainActivity;
37 | import com.dconstructing.cooper.R;
38 |
39 | public class PasswordDialogFragment extends DialogFragment implements OnEditorActionListener {
40 |
41 | public final String TAG = getClass().getSimpleName();
42 |
43 | private long mId;
44 | private String mHost;
45 | private String mUsername;
46 | private EditText mEditText;
47 |
48 | public PasswordDialogFragment() {
49 | }
50 |
51 | public static PasswordDialogFragment create(long id, String host, String username) {
52 | PasswordDialogFragment fragment = new PasswordDialogFragment();
53 |
54 | Bundle bundle = new Bundle();
55 | bundle.putLong("uuid", id);
56 | bundle.putString("host", host);
57 | bundle.putString("username", username);
58 | fragment.setArguments(bundle);
59 |
60 | return fragment;
61 | }
62 |
63 | @Override
64 | public void onCreate(Bundle savedInstanceState) {
65 | super.onCreate(savedInstanceState);
66 |
67 | Bundle args = getArguments();
68 | mId = args.getLong("uuid");
69 | mHost = args.getString("host");
70 | mUsername = args.getString("username");
71 | }
72 |
73 | @Override
74 | public Dialog onCreateDialog(Bundle savedInstanceState) {
75 | AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
76 | // Get the layout inflater
77 | LayoutInflater inflater = getActivity().getLayoutInflater();
78 |
79 | // Inflate and set the layout for the dialog
80 | // Pass null as the parent view because its going in the dialog layout
81 | View view = inflater.inflate(R.layout.dialog_password, null);
82 | mEditText = (EditText) view.findViewById(R.id.password_field);
83 |
84 | // Show soft keyboard automatically
85 | mEditText.requestFocus();
86 |
87 | // set listeners
88 | mEditText.setOnEditorActionListener(this);
89 |
90 | builder.setView(view)
91 | .setTitle(mUsername + "@" + mHost)
92 | // Add action buttons
93 | .setPositiveButton(R.string.login_button, new DialogInterface.OnClickListener() {
94 | @Override
95 | public void onClick(DialogInterface dialog, int id) {
96 | if (MainActivity.isDebuggable) Log.i(TAG, "'Login' button pressed in dialog");
97 | passwordSubmitted();
98 | }
99 | })
100 | .setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
101 | public void onClick(DialogInterface dialog, int id) {
102 | if (MainActivity.isDebuggable) Log.i(TAG, "'Cancel' button pressed in dialog");
103 | PasswordDialogFragment.this.getDialog().cancel();
104 | }
105 | });
106 | return builder.create();
107 | }
108 |
109 | /**
110 | * This is a hint that prompts Android to show the soft keyboard (?)
111 | * according to: http://android-developers.blogspot.com/2012/05/using-dialogfragments.html
112 | * This must be implemented here because implementing it in onCreateDialog is too early.
113 | * The "requestFocus()" portion is implemented in onCreateDialog because the desired EditText
114 | * view is not available here.
115 | */
116 | @Override
117 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
118 | getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
119 |
120 | return null;
121 | }
122 |
123 | @Override
124 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
125 | if (actionId == EditorInfo.IME_ACTION_DONE) {
126 | if (MainActivity.isDebuggable) Log.i(TAG, "DONE pressed on keyboard");
127 | passwordSubmitted();
128 | return true;
129 | }
130 | return false;
131 | }
132 |
133 |
134 |
135 |
136 |
137 | public void passwordSubmitted() {
138 | if (MainActivity.isDebuggable) Log.i(TAG, "Password submitted, but we're not logging it ;)");
139 | ((PasswordDialogListener)getActivity()).onPasswordEntered(mId, mHost, mUsername, mEditText.getText().toString());
140 | this.dismiss();
141 | }
142 |
143 |
144 |
145 |
146 |
147 |
148 | public interface PasswordDialogListener {
149 | void onPasswordEntered(long id, String host, String username, String password);
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/cooper/src/main/java/com/dconstructing/cooper/objects/Address.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Cooper, a touch-friendly SSH client for Android devices
3 | * Copyright (C) 2013 David Cox
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.dconstructing.cooper.objects;
19 |
20 | public class Address {
21 |
22 | public final String TAG = getClass().getSimpleName();
23 |
24 | public long id;
25 | public String host;
26 | public String username;
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/cooper/src/main/java/com/dconstructing/cooper/objects/Connection.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Cooper, a touch-friendly SSH client for Android devices
3 | * Copyright (C) 2013 David Cox
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.dconstructing.cooper.objects;
19 |
20 | import android.util.Log;
21 |
22 | import com.dconstructing.cooper.MainActivity;
23 | import com.jcraft.jsch.Session;
24 |
25 | public class Connection {
26 |
27 | public final String TAG = getClass().getSimpleName();
28 |
29 | public final static int NOT_CONNECTED = 0;
30 | public final static int CONNECTING = 1;
31 | public final static int CONNECTED = 10;
32 | public final static int DISCONNECTING = 11;
33 |
34 | public String path;
35 | public Session session;
36 |
37 | public void updatePath(String pathChange) {
38 | if (MainActivity.isDebuggable) Log.i(TAG, "Updating path: " + pathChange);
39 |
40 | if (pathChange.equals("..")) {
41 | // go up a directory
42 | path = path.substring(0, path.lastIndexOf("/"));
43 | } else {
44 | // add a directory
45 | path = path + "/" + pathChange.replaceAll("\n", "");
46 | }
47 |
48 | if (MainActivity.isDebuggable) Log.i(TAG, "New path: " + path);
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/cooper/src/main/java/com/dconstructing/cooper/objects/FilePath.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Cooper, a touch-friendly SSH client for Android devices
3 | * Copyright (C) 2013 David Cox
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.dconstructing.cooper.objects;
19 |
20 | public class FilePath {
21 |
22 | public boolean isDirectory = false;
23 | public String name;
24 |
25 | public FilePath(String name, boolean isDirectory) {
26 | this.isDirectory = isDirectory;
27 | this.name = name;
28 | }
29 |
30 | public String toString() {
31 | return this.name;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/cooper/src/main/java/com/dconstructing/cooper/services/ConnectionService.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of Cooper, a touch-friendly SSH client for Android devices
3 | * Copyright (C) 2013 David Cox
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.dconstructing.cooper.services;
19 |
20 | import java.io.BufferedReader;
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 | import java.io.InputStreamReader;
24 | import java.io.OutputStream;
25 | import java.lang.ref.WeakReference;
26 | import java.util.ArrayList;
27 | import java.util.Collections;
28 | import java.util.Comparator;
29 | import java.util.HashMap;
30 | import java.util.Map;
31 | import java.util.Properties;
32 | import java.util.Vector;
33 |
34 | import android.app.Service;
35 | import android.content.Intent;
36 | import android.os.Bundle;
37 | import android.os.Handler;
38 | import android.os.IBinder;
39 | import android.os.Message;
40 | import android.os.Messenger;
41 | import android.os.RemoteException;
42 | import android.util.Log;
43 |
44 | import com.dconstructing.cooper.MainActivity;
45 | import com.dconstructing.cooper.objects.Connection;
46 | import com.jcraft.jsch.ChannelSftp;
47 | import com.jcraft.jsch.JSch;
48 | import com.jcraft.jsch.JSchException;
49 | import com.jcraft.jsch.Session;
50 | import com.jcraft.jsch.SftpException;
51 |
52 | public class ConnectionService extends Service {
53 |
54 | public final String TAG = getClass().getSimpleName();
55 |
56 | public static final int MSG_CONNECTION_INITIATE = 101;
57 | public static final int MSG_CONNECTION_ESTABLISHED = 102;
58 | public static final int MSG_CONNECTION_CHECK = 103;
59 | public static final int MSG_CONNECTION_CHECKED = 104;
60 | public static final int MSG_CONNECTION_TERMINATE = 111;
61 | public static final int MSG_CONNECTION_DESTROYED = 112;
62 | public static final int MSG_COMMAND_DISPATCH = 201;
63 | public static final int MSG_COMMAND_RETURN = 202;
64 | public static final int MSG_FILE_SAVE = 301;
65 | public static final int MSG_FILE_SAVED = 302;
66 |
67 | public static final int CMD_WHERE_AM_I = 1001;
68 | public static final int CMD_CHANGE_LOCATION = 1002;
69 | public static final int CMD_DIR_READ = 2001;
70 | public static final int CMD_DIR_MAKE = 2003;
71 | public static final int CMD_DIR_DEL = 2004;
72 | public static final int CMD_FILE_READ = 3001;
73 | public static final int CMD_FILE_WRITE = 3002;
74 | public static final int CMD_FILE_MAKE = 3003;
75 | public static final int CMD_FILE_DELETE = 3004;
76 |
77 | protected Map mConnections = new HashMap();
78 |
79 | protected final Handler mHandler = new IncomingHandler(this);
80 | final Messenger mMessenger = new Messenger(mHandler);
81 |
82 | @Override
83 | public IBinder onBind(Intent intent) {
84 | if (MainActivity.isDebuggable) Log.i(TAG, "Returning the binder");
85 | return mMessenger.getBinder();
86 | }
87 |
88 |
89 | public void establishConnection(Long uuid, String host, int port, String username, String password, Messenger reply) {
90 | ConnectThread thread = new ConnectThread(uuid, host, port, username, password, reply);
91 | thread.start();
92 | }
93 |
94 | public void destroyConnection(Long uuid, Messenger reply) {
95 | Connection connection = mConnections.get(uuid);
96 | Session session = connection.session;
97 | session.disconnect();
98 |
99 | mConnections.remove(uuid);
100 |
101 | try {
102 | Bundle bundle = new Bundle();
103 | bundle.putLong("uuid",uuid);
104 | Message msg = Message.obtain(null, ConnectionService.MSG_CONNECTION_DESTROYED);
105 | if (msg != null) {
106 | msg.setData(bundle);
107 | msg.replyTo = mMessenger;
108 | reply.send(msg);
109 | }
110 | } catch (RemoteException e) {
111 | if (MainActivity.isDebuggable) Log.e(TAG, "Error replying to disconnect request", e);
112 | }
113 | }
114 |
115 | public void sendCommand(Long uuid, int command, String parameter, String content, Messenger reply) {
116 | Connection connection = mConnections.get(uuid);
117 | CommandThread thread = new CommandThread(uuid, connection.session, command, parameter, content, reply);
118 | thread.start();
119 | }
120 |
121 | public void sendResponse(long uuid, int command, String parameter, Object response, Messenger reply) {
122 | try {
123 | Bundle bundle = new Bundle();
124 | bundle.putLong("uuid", uuid);
125 | bundle.putInt("command", command);
126 | if (response instanceof String) {
127 | bundle.putString("response", (String)response);
128 | bundle.putString("parameter", parameter);
129 | } else if (response instanceof HashMap) {
130 | for (Map.Entry> entry : ((HashMap>) response).entrySet()) {
131 | bundle.putStringArrayList(entry.getKey(), entry.getValue());
132 | }
133 | }
134 | Message msg = Message.obtain(null, ConnectionService.MSG_COMMAND_RETURN);
135 | if (msg != null) {
136 | msg.setData(bundle);
137 | msg.replyTo = mMessenger;
138 | reply.send(msg);
139 | }
140 | } catch (RemoteException e) {
141 | if (MainActivity.isDebuggable) Log.e(TAG, "Error replying to command request", e);
142 | }
143 | }
144 |
145 | public boolean checkForConnection(long uuid) {
146 | if (MainActivity.isDebuggable) Log.i(TAG, "Checking connection boolean");
147 | boolean hasConnection = false;
148 | Connection connection = mConnections.get(uuid);
149 | if (connection != null) {
150 | hasConnection = true;
151 | }
152 | return hasConnection;
153 | }
154 |
155 | public void saveFile(Long uuid, String parameter, String content, Messenger reply) {
156 | Connection connection = mConnections.get(uuid);
157 | CommandThread thread = new CommandThread(uuid, connection.session, CMD_FILE_WRITE, parameter, content, reply);
158 | thread.start();
159 | }
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 | public synchronized void connected(Long uuid, Session session, Messenger reply) {
170 | if (MainActivity.isDebuggable) Log.i(TAG, "Connection successful " + uuid);
171 | Connection connection = new Connection();
172 | connection.session = session;
173 | mConnections.put(uuid, connection);
174 |
175 | try {
176 | Bundle bundle = new Bundle();
177 | bundle.putLong("uuid",uuid);
178 | Message msg = Message.obtain(null, ConnectionService.MSG_CONNECTION_ESTABLISHED);
179 | if (msg != null) {
180 | msg.setData(bundle);
181 | msg.replyTo = mMessenger;
182 | reply.send(msg);
183 | }
184 | } catch (RemoteException e) {
185 | if (MainActivity.isDebuggable) Log.e(TAG, "Error replying to connect request", e);
186 | }
187 |
188 | //sendCommand(uuid, "pwd", null, reply);
189 | }
190 |
191 | public synchronized void connectionFailed(Long uuid) {
192 | if (MainActivity.isDebuggable) Log.e(TAG, "connection failed " + Long.toString(uuid));
193 | }
194 |
195 | public synchronized void commandResponse(long uuid, int command, String parameter, Object response, Messenger reply) {
196 | if (MainActivity.isDebuggable) Log.i(TAG, "Got response from command");
197 | if (command == CMD_WHERE_AM_I) {
198 | // Response is the connection path. Set it.
199 | Connection connection = mConnections.get(uuid);
200 | connection.path = ((String)response).replaceAll("\n", "");
201 | mConnections.put(uuid, connection);
202 | sendCommand(uuid, CMD_DIR_READ, connection.path, null, reply);
203 | } else if (command == CMD_CHANGE_LOCATION) {
204 | if (MainActivity.isDebuggable) Log.i(TAG, "Updating understanding of path to: " + parameter);
205 | Connection connection = mConnections.get(uuid);
206 | connection.updatePath(parameter);
207 | sendCommand(uuid, CMD_DIR_READ, connection.path, null, reply);
208 | } else if (command == CMD_DIR_READ) {
209 | if (response instanceof Vector) {
210 | HashMap> contents = new HashMap>();
211 |
212 | ArrayList files = new ArrayList();
213 | ArrayList directories = new ArrayList();
214 | for(ChannelSftp.LsEntry item : (Vector)response) {
215 | //if (MainActivity.isDebuggable) Log.i(TAG, "Adding " + item.getFilename());
216 | if (item.getAttrs().isDir()) {
217 | directories.add(item.getFilename());
218 | } else {
219 | files.add(item.getFilename());
220 | }
221 | }
222 |
223 | Collections.sort(directories, new Comparator() {
224 | public int compare(String string, String otherString) {
225 | return string.compareToIgnoreCase(otherString);
226 | }
227 | });
228 | Collections.sort(files, new Comparator() {
229 | public int compare(String string, String otherString) {
230 | return string.compareToIgnoreCase(otherString);
231 | }
232 | });
233 |
234 | contents.put("files", files);
235 | contents.put("directories", directories);
236 |
237 | sendResponse(uuid, command, parameter, contents, reply);
238 | }
239 | } else if (command == CMD_FILE_READ) {
240 | // Opening the file, just send the response to the user
241 | sendResponse(uuid, command, parameter, (String)response, reply);
242 | } else if (command == CMD_FILE_WRITE) {
243 | sendResponse(uuid, command, parameter, (String)response, reply);
244 | }
245 | }
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 | static class IncomingHandler extends Handler { // Handler of incoming messages from clients.
254 | private final WeakReference mService;
255 |
256 | IncomingHandler(ConnectionService service) {
257 | mService = new WeakReference(service);
258 | }
259 |
260 | @Override
261 | public void handleMessage(Message msg) {
262 | ConnectionService service = mService.get();
263 | if (service != null) {
264 | if (MainActivity.isDebuggable) Log.i(service.TAG, "Message received");
265 |
266 | switch (msg.what) {
267 | case MSG_CONNECTION_INITIATE:
268 | if (MainActivity.isDebuggable) Log.i(service.TAG, "Initiate Connection");
269 | Bundle bundle = msg.getData();
270 | if (bundle != null) {
271 | service.establishConnection(bundle.getLong("uuid"), bundle.getString("host"), bundle.getInt("port"), bundle.getString("username"), bundle.getString("password"), msg.replyTo);
272 | }
273 | break;
274 | case MSG_CONNECTION_TERMINATE:
275 | if (MainActivity.isDebuggable) Log.i(service.TAG, "Terminate Connection");
276 | Bundle terminateBundle = msg.getData();
277 | if (terminateBundle != null) {
278 | service.destroyConnection(terminateBundle.getLong("uuid"), msg.replyTo);
279 | }
280 | break;
281 | case MSG_CONNECTION_CHECK:
282 | if (MainActivity.isDebuggable) Log.i(service.TAG, "Checking for existing connection");
283 | Bundle checkBundle = msg.getData();
284 | try {
285 | checkBundle.putBoolean("hasConnection", service.checkForConnection(checkBundle.getLong("uuid")));
286 | Message outgoingMsg = Message.obtain(null, ConnectionService.MSG_CONNECTION_CHECKED);
287 | if (outgoingMsg != null) {
288 | outgoingMsg.setData(checkBundle);
289 | outgoingMsg.replyTo = service.mMessenger;
290 | msg.replyTo.send(outgoingMsg);
291 | }
292 | } catch (RemoteException e) {
293 | if (MainActivity.isDebuggable) Log.e("ConnectionService Handler", "Error replying to connection check", e);
294 | }
295 | break;
296 | case MSG_COMMAND_DISPATCH:
297 | if (MainActivity.isDebuggable) Log.i(service.TAG, "Send Command Message");
298 | Bundle cmdBundle = msg.getData();
299 | if (cmdBundle != null) {
300 | service.sendCommand(cmdBundle.getLong("uuid"), cmdBundle.getInt("command"), cmdBundle.getString("parameter"), cmdBundle.getString("content"), msg.replyTo);
301 | }
302 | break;
303 | case MSG_FILE_SAVE:
304 | if (MainActivity.isDebuggable) Log.i(service.TAG, "Saving file service");
305 | Bundle saveBundle = msg.getData();
306 | if (saveBundle != null) {
307 | service.saveFile(saveBundle.getLong("uuid"), saveBundle.getString("parameter"), saveBundle.getString("content"), msg.replyTo);
308 | }
309 | break;
310 | default:
311 | super.handleMessage(msg);
312 | }
313 | }
314 | }
315 | }
316 |
317 |
318 | private class CommandThread extends Thread {
319 |
320 | private final long tUuid;
321 | private final Session tSession;
322 | private int tCommand;
323 | private final String tParameter;
324 | private final String tContent;
325 | private Messenger tReply;
326 |
327 | public CommandThread(long uuid, Session session, int command, String parameter, String content, Messenger reply) {
328 | tUuid = uuid;
329 | tSession = session;
330 | tCommand = command;
331 | tParameter = parameter;
332 | tContent = content;
333 | tReply = reply;
334 | }
335 |
336 | public void run() {
337 | if (MainActivity.isDebuggable) Log.i(TAG, "Sending command: " + tCommand);
338 |
339 | try {
340 | // An exec channel seems to give the response I want - scratch that
341 | //ChannelExec channel = (ChannelExec)tSession.openChannel("exec");
342 | //channel.setCommand((tCommand + " " + tPath).getBytes());
343 | //Channel channel = tSession.openChannel("shell");
344 | // An SFTP channel seems to give the response I want
345 | ChannelSftp channel = (ChannelSftp)tSession.openChannel("sftp");
346 | channel.connect();
347 |
348 | try {
349 | Object response = null;
350 |
351 | if (tParameter == null) {
352 | if (MainActivity.isDebuggable) Log.i(TAG, "Updating command to pwd");
353 | tCommand = CMD_WHERE_AM_I;
354 | }
355 |
356 | if (tCommand == CMD_WHERE_AM_I) {
357 | if (MainActivity.isDebuggable) Log.i(TAG, "Where am I?");
358 | String pwd = channel.pwd();
359 | response = channel.pwd();
360 | } else if (tCommand == CMD_CHANGE_LOCATION) {
361 | if (MainActivity.isDebuggable) Log.i(TAG, "Changing directory: " + tParameter);
362 | channel.cd(tParameter);
363 | } else if (tCommand == CMD_DIR_READ) {
364 | if (MainActivity.isDebuggable) Log.i(TAG, "Reading directory: " + tParameter);
365 | Vector list = channel.ls(tParameter);
366 | response = list;
367 | } else if (tCommand == CMD_FILE_READ) {
368 | if (MainActivity.isDebuggable) Log.i(TAG, "Reading file: " + tParameter);
369 | InputStream inputStream = channel.get(tParameter);
370 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
371 |
372 | StringBuilder stringBuilder = new StringBuilder();
373 | String line = null;
374 |
375 | while ((line = bufferedReader.readLine()) != null) {
376 | stringBuilder.append(line + "\n");
377 | }
378 |
379 | inputStream.close();
380 | response = stringBuilder.toString();
381 | } else if (tCommand == CMD_FILE_WRITE) {
382 | if (MainActivity.isDebuggable) Log.i(TAG, "Writing file: " + tParameter);
383 | OutputStream outputStream = channel.put(tParameter);
384 | outputStream.write(tContent.getBytes());
385 | outputStream.close();
386 | response = tContent;
387 | } else {
388 | if (MainActivity.isDebuggable) Log.e(TAG, "Command does not match anything");
389 | }
390 | commandResponse(tUuid, tCommand, tParameter, response, tReply);
391 | } catch (SftpException e) {
392 | e.printStackTrace();
393 | }
394 |
395 | channel.disconnect();
396 | } catch (IOException e) {
397 | e.printStackTrace();
398 | } catch (JSchException e) {
399 | e.printStackTrace();
400 | }
401 | }
402 | }
403 |
404 |
405 | private class ConnectThread extends Thread {
406 | private final Long tUuid;
407 | private final String tHost;
408 | private final int tPort;
409 | private final String tUsername;
410 | private final String tPassword;
411 | private Messenger tReply;
412 |
413 | public ConnectThread(Long uuid, String host, int port, String username, String password, Messenger reply) {
414 | tUuid = uuid;
415 | tHost = host;
416 | tPort = port;
417 | tUsername = username;
418 | tPassword = password;
419 | tReply = reply;
420 | }
421 |
422 | public void run() {
423 | if (MainActivity.isDebuggable) Log.i(TAG, "Initiating Connection to " + tHost);
424 | // Make a connection to remote server
425 | Properties config = new Properties();
426 | config.put("StrictHostKeyChecking", "no");
427 | config.put("compression.s2c", "zlib,none");
428 | config.put("compression.c2s", "zlib,none");
429 |
430 | JSch jsch=new JSch();
431 | try {
432 | Session session=jsch.getSession(tUsername, tHost, tPort);
433 | session.setConfig(config);
434 | session.setPassword(tPassword);
435 | session.connect();
436 | Log.i(TAG, "Connected");
437 | connected(tUuid, session, tReply);
438 | } catch (JSchException e) {
439 | connectionFailed(tUuid);
440 | }
441 | }
442 | }
443 |
444 | }
445 |
--------------------------------------------------------------------------------
/cooper/src/main/res/layout/connection_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
20 |
29 |
30 |
37 |
38 |
44 |
45 |
46 |
54 |
55 |
63 |
64 |
--------------------------------------------------------------------------------
/cooper/src/main/res/layout/dialog_password.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
20 |
26 |
27 |
34 |
35 |
--------------------------------------------------------------------------------
/cooper/src/main/res/layout/fragment_connections.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
20 |
25 |
26 |
32 |
33 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/cooper/src/main/res/layout/fragment_directory.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
20 |
25 |
26 |
32 |
33 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/cooper/src/main/res/layout/fragment_file.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
20 |
25 |
26 |
37 |
38 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/cooper/src/main/res/layout/fragment_new_connection.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
20 |
29 |
30 |
44 |
45 |
59 |
60 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/cooper/src/main/res/menu/connections.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
20 |
--------------------------------------------------------------------------------
/cooper/src/main/res/menu/new_connection.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
20 |
29 |
--------------------------------------------------------------------------------
/cooper/src/main/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/cooper/src/main/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 128dp
5 |
6 |
--------------------------------------------------------------------------------
/cooper/src/main/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/cooper/src/main/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/cooper/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 | 8dp
7 | 8dp
8 |
9 |
--------------------------------------------------------------------------------
/cooper/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/cooper/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
21 | Cooper
22 |
23 |
24 | New Connection
25 | Discard
26 |
27 | e.g. example.com
28 | e.g. johndoe
29 | password
30 | Password will be asked for at login.
31 |
32 | File Content
33 |
34 | Login
35 | Cancel
36 |
37 | Connection Indicator
38 | Disconnect
39 |
40 |
41 |
--------------------------------------------------------------------------------
/cooper/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/losttime/cooper/6318d7d291468c110a5ee191014298205a50bae1/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 09 19:08:01 MDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':cooper'
2 |
--------------------------------------------------------------------------------