├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── tspoon
│ │ └── androidtoolbelt
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── tspoon
│ │ └── androidtoolbelt
│ │ ├── App.java
│ │ ├── component
│ │ ├── activity
│ │ │ ├── BaseAbstractToolbarActivity.java
│ │ │ └── MainActivity.java
│ │ ├── fragment
│ │ │ ├── BaseFragment.java
│ │ │ └── MemoryFragment.java
│ │ └── service
│ │ │ ├── MemoryService.java
│ │ │ ├── MemoryServiceConnection.java
│ │ │ ├── MessageHandler.java
│ │ │ ├── ServiceHolder.java
│ │ │ └── ServiceHolderImplTest.java
│ │ ├── utils
│ │ ├── ByteArrayWrapper.java
│ │ ├── MemoryUtils.java
│ │ └── Utils.java
│ │ └── view
│ │ ├── ArcView.java
│ │ ├── SlidingTabLayout.java
│ │ └── SlidingTabStrip.java
│ └── res
│ ├── drawable-hdpi
│ └── ic_github_circle_white_48dp.png
│ ├── drawable-mdpi
│ └── ic_github_circle_white_48dp.png
│ ├── drawable-xhdpi
│ └── ic_github_circle_white_48dp.png
│ ├── drawable-xxhdpi
│ └── ic_github_circle_white_48dp.png
│ ├── drawable-xxxhdpi
│ └── ic_github_circle_white_48dp.png
│ ├── drawable
│ └── selector_button.xml
│ ├── layout
│ ├── activity_main.xml
│ ├── fragment_memory.xml
│ ├── layout_tab.xml
│ └── toolbar.xml
│ ├── menu
│ └── menu_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-v21
│ └── styles.xml
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── compiler
├── .gitignore
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── tspoon
│ └── androidtoolbelt
│ └── compiler
│ ├── Registry.java
│ ├── ToolbeltProcessor.java
│ └── writer
│ ├── MemoryServiceWriter.java
│ ├── ServiceHolderWriter.java
│ └── SourceWriter.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea
4 | .DS_Store
5 | /build
6 |
7 | # Crashlytics
8 | **com_crashlytics_export_strings.xml
9 | **crashlytics.properties
10 |
11 | *.apk
12 | *.iml
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Android Developer Toolbelt
2 | ============
3 | On-device low-memory testing for Android. Fill your phone's RAM and see how your application performs. [Download the app][Play Store Link], tap the Fill Memory button, and re-open your app - hopefully nothing breaks :)
4 |
5 | Why?
6 | ------
7 | In my expierence this is where the majority of bugs in Android applications are found. It's also one of the hardest and most time consuming things to test. If you're getting large volumes of seemingly un-reproducable crashes in your logs, my bet is it's something to do with your app being put into a background state.
8 |
9 | How to Test Your App
10 | ------
11 | There are three main ways this tool can be used to test your app:
12 |
13 | 1. Testing your Application/Activities being placed into background.
14 | 2. Testing your process being killed (i.e. everything in memory, including all static variables will be removed).
15 | 3. Testing your app while under memory pressure (maybe more useful for games).
16 |
17 | To test cases 1 & 2, use the instructions below. For testing while under memory pressure, just don't press the stop button (unfortunately this can sometimes lead to freezing issues on some devices)[2].
18 |
19 | 1. Start your application and build up some state you want to test i.e. play with it a little.
20 | 2. Start this app & tap the Fill Memory button. You'll see the memory counter decrease. When it hits a point when it seemingly cannot go any lower or the low memory indicator is `true`[2], your app has *probably*[3] been placed into a background state.
21 | 3. Press the Stop button and return to your app to ensure all state has been properly restored.
22 |
23 | [1] I'm planning on adding a Pause button soon, so that the memory level can be kept constant - which should make this kind of testing much easier.
24 |
25 | [2] Not all devices will be able to reach the state where the 'Low Memory' indicator is true. This is an indicator for the operating system as a whole, not specific applications. Your app can still be placed into background as normal (when the indicator can't seem to go much lower).
26 |
27 | [3] Android kills applications using different criteria - I can't guarantee when it will kill your app, the longer you wait, the more likely your app has been killed. When you notice the RAM counter bouncing up and down (~10% mark on a Nexus 5), you know that Android is freeing up memory by killing applications & services.
28 |
29 |
30 | Under the Hood
31 | -------
32 | If you want to fill an Android device's memory - there are two methods of programatically doing this (that I know of):
33 |
34 | 1. Use the NDK and `malloc()` to fill the native heap.
35 | 2. Use multiple processes and fill the standard Java heap for each one.
36 |
37 | I opted for the latter method for two reasons:
38 |
39 | 1. Easier to control. Less chance of doing something stupid and having memory that doesn't get cleaned up when finished testing.
40 | 2. My experience with similar apps seems to indicate that the native heap hits an upper limit memory usage (~1Gb). On recent devices, this sometimes isn't enough to trigger the low-memory state.
41 |
42 | In order to get the application to run in multiple process I'm using multiple `Services`, each with a seperate `android:process` attribute set in the manifest. Normally this would mean writing code for ~20 Service classes, but that's where code generation comes to the rescue! The `compiler` module handles generating the source code for these classes.
43 |
44 |
45 | License
46 | -------
47 |
48 | Copyright 2015 Oisín O'Neill
49 |
50 | Licensed under the Apache License, Version 2.0 (the "License");
51 | you may not use this file except in compliance with the License.
52 | You may obtain a copy of the License at
53 |
54 | http://www.apache.org/licenses/LICENSE-2.0
55 |
56 | Unless required by applicable law or agreed to in writing, software
57 | distributed under the License is distributed on an "AS IS" BASIS,
58 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
59 | See the License for the specific language governing permissions and
60 | limitations under the License.
61 |
62 | [Play Store Link]: https://play.google.com/store/apps/details?id=com.tspoon.androidtoolbelt
63 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | maven { url 'http://download.crashlytics.com/maven' }
4 | }
5 |
6 | dependencies {
7 | classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
8 | }
9 | }
10 | apply plugin: 'com.android.application'
11 | apply plugin: 'crashlytics'
12 |
13 | repositories {
14 | maven { url 'http://download.crashlytics.com/maven' }
15 | }
16 |
17 | apply plugin: 'com.neenbedankt.android-apt'
18 |
19 | configurations {
20 | apt
21 | }
22 |
23 |
24 | Properties properties = new Properties()
25 | // Note, this will throw an error from Crashlytics without a valid key
26 | properties.setProperty("crashlytics.key", "INVALID_KEY")
27 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
28 |
29 | def crashlyticsKey = properties.getProperty('crashlytics.key')
30 |
31 |
32 | android {
33 | compileSdkVersion 22
34 | buildToolsVersion "22.0.1"
35 |
36 | defaultConfig {
37 | applicationId "com.tspoon.androidtoolbelt"
38 | minSdkVersion 9
39 | targetSdkVersion 22
40 | versionCode 3
41 | versionName "1.0.2"
42 | manifestPlaceholders = [ crashlyticsKey:crashlyticsKey ]
43 | }
44 | buildTypes {
45 | release {
46 | minifyEnabled false
47 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
48 | }
49 | }
50 | packagingOptions {
51 | exclude 'META-INF/services/javax.annotation.processing.Processor'
52 | }
53 | }
54 |
55 | dependencies {
56 | compile fileTree(dir: 'libs', include: ['*.jar'])
57 | compile 'com.android.support:appcompat-v7:22.0.0'
58 | compile 'com.jakewharton:butterknife:6.+'
59 | compile 'com.jakewharton.timber:timber:2.4.2'
60 |
61 | apt project(':compiler')
62 | compile 'com.crashlytics.android:crashlytics:1.+'
63 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/oisin/android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/tspoon/androidtoolbelt/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
29 |
30 |
33 |
34 |
37 |
38 |
41 |
42 |
45 |
46 |
49 |
50 |
53 |
54 |
57 |
58 |
61 |
62 |
65 |
66 |
69 |
70 |
73 |
74 |
77 |
78 |
81 |
82 |
85 |
86 |
89 |
110 |
113 |
114 |
115 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tspoon/androidtoolbelt/App.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt;
2 |
3 | import android.app.Application;
4 |
5 | import com.crashlytics.android.Crashlytics;
6 | import com.tspoon.androidtoolbelt.component.service.ServiceHolder;
7 | import com.tspoon.androidtoolbelt.component.service.ServiceHolderImplTest;
8 |
9 | import timber.log.Timber;
10 |
11 | public class App extends Application {
12 |
13 | private static final boolean TEST_MODE = false;
14 |
15 | private static ServiceHolder sServiceHolder;
16 |
17 |
18 | @Override
19 | public void onCreate() {
20 | super.onCreate();
21 |
22 | Timber.plant(new Timber.DebugTree());
23 |
24 | try {
25 | if (TEST_MODE) {
26 | sServiceHolder = new ServiceHolderImplTest();
27 | } else {
28 | Class adapterClass = Class.forName(ServiceHolder.QUALIFIED_NAME);
29 | sServiceHolder = (ServiceHolder) adapterClass.newInstance();
30 | }
31 | } catch (Exception e) {
32 | Timber.e(e, "Error initializing ServiceHolder.");
33 | Crashlytics.logException(e);
34 | }
35 | }
36 |
37 | public static ServiceHolder getServiceHolder() {
38 | return sServiceHolder;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tspoon/androidtoolbelt/component/activity/BaseAbstractToolbarActivity.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt.component.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.ActionBar;
5 | import android.support.v7.app.ActionBarActivity;
6 | import android.support.v7.widget.Toolbar;
7 | import android.view.MenuItem;
8 |
9 | import butterknife.ButterKnife;
10 |
11 | public abstract class BaseAbstractToolbarActivity extends ActionBarActivity {
12 |
13 | protected ActionBar mActionBar;
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(getLayoutId());
19 |
20 | ButterKnife.inject(this);
21 |
22 | setSupportActionBar(getToolbar());
23 | mActionBar = getSupportActionBar();
24 | mActionBar.setDisplayHomeAsUpEnabled(true);
25 | mActionBar.setHomeButtonEnabled(true);
26 | mActionBar.setDisplayShowTitleEnabled(true);
27 | }
28 |
29 | @Override
30 | public boolean onOptionsItemSelected(MenuItem item) {
31 | switch (item.getItemId()) {
32 | case android.R.id.home:
33 | onBackPressed();
34 | return true;
35 | default:
36 | return super.onOptionsItemSelected(item);
37 | }
38 | }
39 |
40 | protected abstract Toolbar getToolbar();
41 |
42 | protected abstract int getLayoutId();
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tspoon/androidtoolbelt/component/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt.component.activity;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.support.v4.app.Fragment;
8 | import android.support.v4.app.FragmentManager;
9 | import android.support.v4.app.FragmentPagerAdapter;
10 | import android.support.v4.view.ViewPager;
11 | import android.support.v7.widget.Toolbar;
12 | import android.view.Menu;
13 | import android.view.MenuItem;
14 |
15 | import com.crashlytics.android.Crashlytics;
16 | import com.tspoon.androidtoolbelt.R;
17 | import com.tspoon.androidtoolbelt.component.fragment.MemoryFragment;
18 | import com.tspoon.androidtoolbelt.view.SlidingTabLayout;
19 |
20 | import butterknife.InjectView;
21 |
22 |
23 | public class MainActivity extends BaseAbstractToolbarActivity {
24 |
25 | @InjectView(R.id.toolbar) Toolbar mToolbar;
26 | @InjectView(R.id.viewpager) ViewPager mViewPager;
27 | @InjectView(R.id.sliding_tabs) SlidingTabLayout mTabLayout;
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | // Do this here so it doesn't start for all threads
33 | Crashlytics.start(this);
34 |
35 | mViewPager.setAdapter(new PagerAdapter(this, getSupportFragmentManager()));
36 |
37 | //mTabLayout.setDistributeEvenly(true);
38 | //mTabLayout.setCustomTabView(R.layout.layout_tab, 0);
39 | //mTabLayout.setSelectedIndicatorColors(Color.WHITE);
40 | //mTabLayout.setViewPager(mViewPager);
41 |
42 | mActionBar.setDisplayHomeAsUpEnabled(false);
43 |
44 | setTitle(R.string.app_name_short);
45 | }
46 |
47 |
48 | @Override
49 | public boolean onCreateOptionsMenu(Menu menu) {
50 | getMenuInflater().inflate(R.menu.menu_main, menu);
51 | return true;
52 | }
53 |
54 | @Override
55 | public boolean onOptionsItemSelected(MenuItem item) {
56 | switch (item.getItemId()) {
57 | case R.id.action_github:
58 | startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.url_github))));
59 | return true;
60 | case R.id.action_share:
61 | Intent intent = new Intent(Intent.ACTION_SEND);
62 | intent.setType("text/plain");
63 | intent.putExtra(Intent.EXTRA_TITLE, "The Android Developer's Toolbelt - " + getString(R.string.url_share));
64 | startActivity(Intent.createChooser(intent, "Share with..."));
65 | return true;
66 | default:
67 | return super.onOptionsItemSelected(item);
68 | }
69 | }
70 |
71 | @Override
72 | protected Toolbar getToolbar() {
73 | return mToolbar;
74 | }
75 |
76 | @Override
77 | protected int getLayoutId() {
78 | return R.layout.activity_main;
79 | }
80 |
81 | private void openLink(String string) {
82 |
83 | }
84 |
85 | public static enum NavItem {
86 | MEMORY(R.string.nav_memory);
87 |
88 | public int titleRes;
89 |
90 | NavItem(int resId) {
91 | titleRes = resId;
92 | }
93 | }
94 |
95 | private static class PagerAdapter extends FragmentPagerAdapter {
96 |
97 | private static final NavItem[] ITEMS = NavItem.values();
98 |
99 | private Context mContext;
100 |
101 | public PagerAdapter(Context context, FragmentManager fm) {
102 | super(fm);
103 | mContext = context;
104 | }
105 |
106 | @Override
107 | public Fragment getItem(int position) {
108 | switch (ITEMS[position]) {
109 | case MEMORY:
110 | return MemoryFragment.newInstance();
111 | default:
112 | return null;
113 | }
114 | }
115 |
116 | @Override
117 | public int getCount() {
118 | return ITEMS.length;
119 | }
120 |
121 | @Override
122 | public CharSequence getPageTitle(int position) {
123 | return mContext.getString(ITEMS[position].titleRes).toUpperCase();
124 | }
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tspoon/androidtoolbelt/component/fragment/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt.component.fragment;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v7.app.ActionBarActivity;
7 | import android.view.View;
8 |
9 | import butterknife.ButterKnife;
10 |
11 | public abstract class BaseFragment extends Fragment {
12 |
13 | protected ActionBarActivity mActivity;
14 |
15 | @Override
16 | public void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setHasOptionsMenu(true);
19 | }
20 |
21 | @Override
22 | public void onAttach(Activity activity) {
23 | super.onAttach(activity);
24 | mActivity = (ActionBarActivity) activity;
25 | }
26 |
27 | @Override
28 | public void onDetach() {
29 | super.onDetach();
30 | mActivity = null;
31 | }
32 |
33 | @Override
34 | public void onViewCreated(View view, Bundle savedInstanceState) {
35 | super.onViewCreated(view, savedInstanceState);
36 | setTitle();
37 | ButterKnife.inject(this, view);
38 | }
39 |
40 | @Override
41 | public void onDestroyView() {
42 | super.onDestroyView();
43 | ButterKnife.reset(this);
44 | }
45 |
46 | @Override
47 | public void onResume() {
48 | super.onResume();
49 | }
50 |
51 | protected void setTitle() {
52 |
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tspoon/androidtoolbelt/component/fragment/MemoryFragment.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt.component.fragment;
2 |
3 | import android.app.Activity;
4 | import android.app.ActivityManager;
5 | import android.os.Bundle;
6 | import android.os.Handler;
7 | import android.os.Process;
8 | import android.support.annotation.Nullable;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.Button;
13 | import android.widget.TextView;
14 |
15 | import com.tspoon.androidtoolbelt.App;
16 | import com.tspoon.androidtoolbelt.R;
17 | import com.tspoon.androidtoolbelt.utils.MemoryUtils;
18 | import com.tspoon.androidtoolbelt.view.ArcView;
19 |
20 | import java.util.List;
21 |
22 | import butterknife.InjectView;
23 | import butterknife.OnClick;
24 | import timber.log.Timber;
25 |
26 | public class MemoryFragment extends BaseFragment {
27 |
28 | @InjectView(R.id.memory_total_value) TextView mTextTotal;
29 | @InjectView(R.id.memory_free_value) TextView mTextFree;
30 | //@InjectView(R.id.memory_total_value) TextView mTextCurrent;
31 | @InjectView(R.id.memory_low_value) TextView mTextLow;
32 | @InjectView(R.id.memory_arc) ArcView mArc;
33 |
34 | @InjectView(R.id.button_memory) Button mButtonFill;
35 |
36 | private MemoryUtils mMemoryUtils;
37 | private Handler mHandler = new Handler();
38 |
39 | private boolean mUpdate;
40 |
41 | public static MemoryFragment newInstance() {
42 | return new MemoryFragment();
43 | }
44 |
45 | @Override
46 | public void onCreate(Bundle savedInstanceState) {
47 | super.onCreate(savedInstanceState);
48 | mMemoryUtils = MemoryUtils.get(mActivity);
49 | }
50 |
51 | @Override
52 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
53 | return inflater.inflate(R.layout.fragment_memory, container, false);
54 | }
55 |
56 | @Override
57 | public void onViewCreated(View view, Bundle savedInstanceState) {
58 | super.onViewCreated(view, savedInstanceState);
59 |
60 | mArc.setTextBottom("RAM");
61 | }
62 |
63 | @Override
64 | public void onResume() {
65 | super.onResume();
66 | mUpdate = true;
67 | mHandler.post(new UpdateRunnable());
68 | }
69 |
70 | @Override
71 | public void onPause() {
72 | super.onPause();
73 | mUpdate = false;
74 | }
75 |
76 | @OnClick(R.id.button_memory)
77 | public void onClickFill() {
78 | if (mButtonFill.getTag() == null) {
79 | App.getServiceHolder().startServices(mActivity);
80 | mButtonFill.setText(R.string.memory_fill_stop);
81 | mButtonFill.setTag("started");
82 | } else {
83 | ActivityManager am = (ActivityManager) mActivity.getSystemService(Activity.ACTIVITY_SERVICE);
84 | List services = am.getRunningServices(999);
85 | String packageName = mActivity.getPackageName();
86 | for (ActivityManager.RunningServiceInfo service : services) {
87 | if (service.process.startsWith(packageName)) {
88 | Timber.d("Killing " + service.process);
89 | Process.sendSignal(service.pid, Process.SIGNAL_KILL);
90 | }
91 | }
92 | //App.getServiceHolder().stopServices();
93 | mButtonFill.setText(R.string.memory_fill_start);
94 | mButtonFill.setTag(null);
95 | }
96 | }
97 |
98 | class UpdateRunnable implements Runnable {
99 |
100 | @Override
101 | public void run() {
102 | if (mUpdate) {
103 | mMemoryUtils.update();
104 | mTextTotal.setText(mMemoryUtils.getRamSize() + "");
105 | mTextFree.setText(mMemoryUtils.getAvailableMemory() + "");
106 | mTextLow.setText(String.valueOf(mMemoryUtils.isLowMemory()).toUpperCase());
107 | mArc.setProgress(mMemoryUtils.getFreeMemoryPercentage());
108 | mMemoryUtils.getMemoryThreshold();
109 |
110 | mHandler.postDelayed(this, 1000);
111 | } else {
112 | mHandler.removeCallbacks(this);
113 | }
114 | }
115 | }
116 |
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tspoon/androidtoolbelt/component/service/MemoryService.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt.component.service;
2 |
3 | import android.app.IntentService;
4 | import android.content.Intent;
5 | import android.os.IBinder;
6 | import android.os.Messenger;
7 |
8 | import com.tspoon.androidtoolbelt.utils.ByteArrayWrapper;
9 | import com.tspoon.androidtoolbelt.utils.MemoryUtils;
10 |
11 | import java.util.ArrayList;
12 | import java.util.Random;
13 |
14 | import timber.log.Timber;
15 |
16 | public class MemoryService extends IntentService {
17 |
18 | private final Messenger mMessenger;
19 |
20 | private ArrayList mAllocations = new ArrayList<>();
21 | private Boolean mRun;
22 |
23 | public MemoryService() {
24 | super(MemoryService.class.getName());
25 | mMessenger = new Messenger(new MessageHandler(mRun));
26 | }
27 |
28 | @Override
29 | public IBinder onBind(Intent intent) {
30 | Timber.d("onBind: " + intent);
31 | return mMessenger.getBinder();
32 | }
33 |
34 | @Override
35 | protected void onHandleIntent(Intent intent) {
36 | mRun = true;
37 | while (mRun) {
38 | Timber.d("Attempting Allocation...");
39 |
40 | if (MemoryUtils.isMemoryAvailable()) {
41 | byte[] bytes = new byte[1024 * 1024 * 5];
42 | new Random().nextBytes(bytes);
43 | mAllocations.add(new ByteArrayWrapper(bytes));
44 | Timber.d("Allocated new block");
45 | }
46 |
47 | try {
48 | Thread.sleep(1000);
49 | } catch (InterruptedException e) {
50 | e.printStackTrace();
51 | }
52 | }
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tspoon/androidtoolbelt/component/service/MemoryServiceConnection.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt.component.service;
2 |
3 | import android.content.ComponentName;
4 | import android.content.ServiceConnection;
5 | import android.os.Bundle;
6 | import android.os.IBinder;
7 | import android.os.Message;
8 | import android.os.Messenger;
9 | import android.os.RemoteException;
10 |
11 | import timber.log.Timber;
12 |
13 | public class MemoryServiceConnection implements ServiceConnection {
14 |
15 | private Messenger mMessenger;
16 | private boolean mConnected;
17 |
18 | @Override
19 | public void onServiceConnected(ComponentName name, IBinder service) {
20 | mMessenger = new Messenger(service);
21 | mConnected = true;
22 | }
23 |
24 | @Override
25 | public void onServiceDisconnected(ComponentName name) {
26 | mMessenger = null;
27 | mConnected = false;
28 | }
29 |
30 | public void stopService() {
31 | if (mConnected) {
32 | Message message = Message.obtain();
33 |
34 | Bundle data = new Bundle();
35 | data.putString(MessageHandler.KEY_MESSAGE, MessageHandler.MSG_STOP);
36 | message.setData(data);
37 | try {
38 | mMessenger.send(message);
39 | } catch (RemoteException e) {
40 | e.printStackTrace();
41 | }
42 |
43 | } else {
44 | Timber.w("Attempting to stop a service that's not connected.");
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tspoon/androidtoolbelt/component/service/MessageHandler.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt.component.service;
2 |
3 | import android.os.Handler;
4 | import android.os.Message;
5 |
6 | import timber.log.Timber;
7 |
8 | public class MessageHandler extends Handler {
9 |
10 | public static final String KEY_MESSAGE = "KEY_MESSAGE";
11 | public static final String MSG_STOP = "STOP";
12 |
13 | private Boolean mRun;
14 |
15 | MessageHandler(Boolean run) {
16 | mRun = run;
17 | }
18 |
19 | @Override
20 | public void handleMessage(Message msg) {
21 | super.handleMessage(msg);
22 | if (msg.getData() != null) {
23 | String message = msg.getData().getString(KEY_MESSAGE);
24 | Timber.d("Service received message: " + message);
25 | switch (message) {
26 | case MSG_STOP:
27 | mRun = false;
28 | break;
29 | }
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/tspoon/androidtoolbelt/component/service/ServiceHolder.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt.component.service;
2 |
3 | import android.content.Context;
4 |
5 | public interface ServiceHolder {
6 |
7 | public static final String QUALIFIED_NAME = ServiceHolder.class.getCanonicalName() + "Impl";
8 |
9 | public void startServices(Context context);
10 |
11 | public void stopServices();
12 |
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tspoon/androidtoolbelt/component/service/ServiceHolderImplTest.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt.component.service;
2 |
3 | import android.app.Service;
4 | import android.content.Context;
5 | import android.content.Intent;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | import timber.log.Timber;
11 |
12 | public class ServiceHolderImplTest implements ServiceHolder {
13 |
14 | private static final List> SERVICES = new ArrayList>() {{
15 | add(MemoryService.class);
16 | }};
17 | private static final List CONNECTIONS = new ArrayList<>();
18 |
19 | @Override
20 | public void startServices(Context context) {
21 | for (Class extends Service> service : SERVICES) {
22 | Intent intent = new Intent(context, service);
23 | context.startService(intent);
24 |
25 | MemoryServiceConnection connection = new MemoryServiceConnection();
26 | context.bindService(intent, connection, Context.BIND_AUTO_CREATE);
27 | }
28 | }
29 |
30 | @Override
31 | public void stopServices() {
32 | Timber.d("Stopping Services... " + CONNECTIONS.size() + " connections found.");
33 | while (CONNECTIONS.size() > 0) {
34 | CONNECTIONS.remove(0).stopService();
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tspoon/androidtoolbelt/utils/ByteArrayWrapper.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt.utils;
2 |
3 | public class ByteArrayWrapper {
4 | byte[] bytes;
5 |
6 | public ByteArrayWrapper(byte[] bytes) {
7 | this.bytes = bytes;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tspoon/androidtoolbelt/utils/MemoryUtils.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt.utils;
2 |
3 | import android.app.ActivityManager;
4 | import android.content.Context;
5 | import android.os.Build;
6 |
7 | import java.io.IOException;
8 | import java.io.RandomAccessFile;
9 | import java.util.regex.Pattern;
10 |
11 | import timber.log.Timber;
12 |
13 | public class MemoryUtils {
14 |
15 | private static final int MB = 1024 * 1024;
16 |
17 | private static MemoryUtils sInstance;
18 |
19 |
20 | private ActivityManager.MemoryInfo mMemoryInfo = new ActivityManager.MemoryInfo();
21 | private ActivityManager mActivityManager;
22 |
23 | private MemoryUtils(Context context) {
24 | mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
25 | update();
26 |
27 | Timber.d(this.toString());
28 | }
29 |
30 | public static MemoryUtils get(Context context) {
31 | if (sInstance == null) {
32 | sInstance = new MemoryUtils(context);
33 | }
34 | return sInstance;
35 | }
36 |
37 | public void update() {
38 | mActivityManager.getMemoryInfo(mMemoryInfo);
39 | }
40 |
41 | public float getAvailableMemory() {
42 | return mMemoryInfo.availMem / MB;
43 | }
44 |
45 | public boolean isLowMemory() {
46 | return mMemoryInfo.lowMemory;
47 | }
48 |
49 | public long getMemoryThreshold() {
50 | return mMemoryInfo.threshold / MB;
51 | }
52 |
53 | public float getRamSize() {
54 | long memory;
55 | if (Build.VERSION.SDK_INT >= 16) {
56 | memory = mMemoryInfo.totalMem;
57 | } else {
58 | memory = readRamSizeFromSystem();
59 | }
60 | return memory / MB;
61 | }
62 |
63 | public float getFreeMemoryPercentage() {
64 | return (getAvailableMemory() / getRamSize()) * 100;
65 | }
66 |
67 | private static long readRamSizeFromSystem() {
68 | try {
69 | RandomAccessFile memFile = new RandomAccessFile("/proc/meminfo", "r");
70 | Pattern pattern = Pattern.compile("[0-9]+");
71 |
72 | memFile.close();
73 | String memory = pattern.matcher(memFile.readLine()).group();
74 | return Long.parseLong(memory) * 1024;
75 | } catch (IOException e) {
76 | e.printStackTrace();
77 | }
78 | return -1;
79 | }
80 |
81 | @Override
82 | public String toString() {
83 | return "MemoryUtils{" +
84 | "availMem=" + mMemoryInfo.availMem +
85 | ", lowMemory=" + mMemoryInfo.lowMemory +
86 | ", threshold=" + mMemoryInfo.threshold +
87 | ", totalMem=" + getRamSize() +
88 | '}';
89 | }
90 |
91 | public static boolean isMemoryAvailable() {
92 | float freeMemoryPercent = 100 - (Runtime.getRuntime().totalMemory() / (float) Runtime.getRuntime().maxMemory()) * 100;
93 | if (freeMemoryPercent > 10) {
94 | return true;
95 | }
96 | return false;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tspoon/androidtoolbelt/utils/Utils.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt.utils;
2 |
3 | import android.content.res.Resources;
4 | import android.util.TypedValue;
5 |
6 | public class Utils {
7 |
8 | public static int dpToPixels(Resources resources, float pixels) {
9 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, pixels, resources.getDisplayMetrics());
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tspoon/androidtoolbelt/view/ArcView.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt.view;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.DashPathEffect;
8 | import android.graphics.Paint;
9 | import android.graphics.RectF;
10 | import android.text.TextPaint;
11 | import android.text.TextUtils;
12 | import android.util.AttributeSet;
13 | import android.view.View;
14 |
15 | import com.tspoon.androidtoolbelt.R;
16 | import com.tspoon.androidtoolbelt.utils.Utils;
17 |
18 | /**
19 | * Inspired by https://github.com/lzyzsd/CircleProgress
20 | */
21 | public class ArcView extends View {
22 |
23 | private static final int ARC_ANGLE = (int) (360 * 0.8f);
24 | private final int COLOR_TEXT = Color.WHITE;
25 | private final int COLOR_FINISHED = Color.WHITE;
26 | private final int COLOR_UNFINISHED = Color.parseColor("#55FFFFFF");
27 | private final int MAX = 100;
28 |
29 | private RectF mRect = new RectF();
30 | private TextPaint mTextPaint = new TextPaint();
31 | private Paint mPaint = new Paint();
32 |
33 | private int mStrokeWidth;
34 | private int mTextSizeLarge;
35 | private int mTextSizeSmall;
36 | private float mArcBottomHeight;
37 |
38 | private float mProgress;
39 | private String mTextBottom;
40 |
41 | public ArcView(Context context) {
42 | super(context);
43 | init();
44 | }
45 |
46 | public ArcView(Context context, AttributeSet attrs) {
47 | super(context, attrs);
48 | init();
49 | }
50 |
51 | public ArcView(Context context, AttributeSet attrs, int defStyleAttr) {
52 | super(context, attrs, defStyleAttr);
53 | init();
54 | }
55 |
56 | public ArcView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
57 | super(context, attrs, defStyleAttr, defStyleRes);
58 | init();
59 | }
60 |
61 | private void init() {
62 | Resources res = getContext().getResources();
63 |
64 | mStrokeWidth = Utils.dpToPixels(res, 10);
65 | mTextSizeLarge = res.getDimensionPixelSize(R.dimen.text_size_arc_large);
66 | mTextSizeSmall = res.getDimensionPixelSize(R.dimen.text_size_arc_small);
67 |
68 | mTextPaint.setColor(COLOR_TEXT);
69 | mTextPaint.setTextSize(mTextSizeLarge);
70 | mTextPaint.setAntiAlias(true);
71 |
72 | mPaint = new Paint();
73 | mPaint.setColor(COLOR_UNFINISHED);
74 | mPaint.setAntiAlias(true);
75 | mPaint.setStrokeWidth(mStrokeWidth);
76 | mPaint.setStyle(Paint.Style.STROKE);
77 | //mPaint.setStrokeCap(Paint.Cap.ROUND);
78 | mPaint.setPathEffect(new DashPathEffect(new float[]{2, 2}, 0));
79 | }
80 |
81 | public float getProgress() {
82 | return mProgress;
83 | }
84 |
85 | public void setProgress(float progress) {
86 | mProgress = progress;
87 | invalidate();
88 | }
89 |
90 | public void setTextBottom(String textBottom) {
91 | mTextBottom = textBottom;
92 | }
93 |
94 | @Override
95 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
96 | setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
97 |
98 | int width = MeasureSpec.getSize(widthMeasureSpec);
99 | float radius = width / 2f;
100 | float angle = (360 - ARC_ANGLE) / 2f;
101 |
102 | mRect.set(mStrokeWidth / 2f, mStrokeWidth / 2f, width - mStrokeWidth / 2f, MeasureSpec.getSize(heightMeasureSpec) - mStrokeWidth / 2f);
103 | mArcBottomHeight = radius * (float) (1 - Math.cos(angle / 180 * Math.PI));
104 | }
105 |
106 | @Override
107 | protected void onDraw(Canvas canvas) {
108 | super.onDraw(canvas);
109 |
110 | float startAngle = 270 - ARC_ANGLE / 2f;
111 | float finishedSweepAngle = mProgress / (float) MAX * ARC_ANGLE;
112 |
113 | mPaint.setColor(COLOR_UNFINISHED);
114 | canvas.drawArc(mRect, startAngle, ARC_ANGLE, false, mPaint);
115 | mPaint.setColor(COLOR_FINISHED);
116 | canvas.drawArc(mRect, startAngle, finishedSweepAngle, false, mPaint);
117 |
118 | String text = String.valueOf((int) mProgress);
119 | if (!TextUtils.isEmpty(text)) {
120 |
121 | mTextPaint.setColor(COLOR_TEXT);
122 | mTextPaint.setTextSize(mTextSizeLarge);
123 | float textHeight = mTextPaint.descent() + mTextPaint.ascent();
124 | float textBaseline = (getHeight() - textHeight) / 2.0f;
125 | canvas.drawText(text, (getWidth() - mTextPaint.measureText(text)) / 2.0f, textBaseline, mTextPaint);
126 |
127 | mTextPaint.setColor(COLOR_UNFINISHED);
128 | mTextPaint.setTextSize(mTextSizeSmall);
129 | float suffixHeight = mTextPaint.descent() + mTextPaint.ascent();
130 | canvas.drawText("%", getWidth() / 2.0f + mTextPaint.measureText(text), textBaseline + textHeight - suffixHeight, mTextPaint);
131 | }
132 |
133 | if (!TextUtils.isEmpty(mTextBottom)) {
134 | mTextPaint.setColor(COLOR_TEXT);
135 | mTextPaint.setTextSize(mTextSizeSmall);
136 | float bottomTextBaseline = getHeight() - mArcBottomHeight - (mTextPaint.descent() + mTextPaint.ascent()) / 2;
137 | canvas.drawText(mTextBottom, (getWidth() - mTextPaint.measureText(mTextBottom)) / 2.0f, bottomTextBaseline, mTextPaint);
138 | }
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tspoon/androidtoolbelt/view/SlidingTabLayout.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.tspoon.androidtoolbelt.view;
18 |
19 | import android.content.Context;
20 | import android.graphics.Typeface;
21 | import android.support.v4.view.PagerAdapter;
22 | import android.support.v4.view.ViewPager;
23 | import android.util.AttributeSet;
24 | import android.util.SparseArray;
25 | import android.util.TypedValue;
26 | import android.view.Gravity;
27 | import android.view.LayoutInflater;
28 | import android.view.View;
29 | import android.view.ViewGroup;
30 | import android.widget.HorizontalScrollView;
31 | import android.widget.LinearLayout;
32 | import android.widget.TextView;
33 |
34 | /**
35 | * To be used with ViewPager to provide a tab indicator component which give constant feedback as to
36 | * the user's scroll progress.
37 | *
38 | * To use the component, simply add it to your view hierarchy. Then in your
39 | * {@link android.app.Activity} or {@link android.support.v4.app.Fragment} call
40 | * {@link #setViewPager(android.support.v4.view.ViewPager)} providing it the ViewPager this layout is being used for.
41 | *
42 | * The colors can be customized in two ways. The first and simplest is to provide an array of colors
43 | * via {@link #setSelectedIndicatorColors(int...)}. The
44 | * alternative is via the {@link TabColorizer} interface which provides you complete control over
45 | * which color is used for any individual position.
46 | *
47 | * The views used as tabs can be customized by calling {@link #setCustomTabView(int, int)},
48 | * providing the layout ID of your custom layout.
49 | */
50 | public class SlidingTabLayout extends HorizontalScrollView {
51 | /**
52 | * Allows complete control over the colors drawn in the tab layout. Set with
53 | * {@link #setCustomTabColorizer(TabColorizer)}.
54 | */
55 | public interface TabColorizer {
56 |
57 | /**
58 | * @return return the color of the indicator used when {@code position} is selected.
59 | */
60 | int getIndicatorColor(int position);
61 |
62 | }
63 |
64 | private static final int TITLE_OFFSET_DIPS = 24;
65 | private static final int TAB_VIEW_PADDING_DIPS = 16;
66 | private static final int TAB_VIEW_TEXT_SIZE_SP = 12;
67 |
68 | private int mTitleOffset;
69 |
70 | private int mTabViewLayoutId;
71 | private int mTabViewTextViewId;
72 | private boolean mDistributeEvenly;
73 |
74 | private ViewPager mViewPager;
75 | private SparseArray mContentDescriptions = new SparseArray();
76 | private ViewPager.OnPageChangeListener mViewPagerPageChangeListener;
77 |
78 | private final SlidingTabStrip mTabStrip;
79 |
80 | public SlidingTabLayout(Context context) {
81 | this(context, null);
82 | }
83 |
84 | public SlidingTabLayout(Context context, AttributeSet attrs) {
85 | this(context, attrs, 0);
86 | }
87 |
88 | public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) {
89 | super(context, attrs, defStyle);
90 |
91 | // Disable the Scroll Bar
92 | setHorizontalScrollBarEnabled(false);
93 | // Make sure that the Tab Strips fills this View
94 | setFillViewport(true);
95 |
96 | mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);
97 |
98 | mTabStrip = new SlidingTabStrip(context);
99 | addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
100 | }
101 |
102 | /**
103 | * Set the custom {@link TabColorizer} to be used.
104 | *
105 | * If you only require simple custmisation then you can use
106 | * {@link #setSelectedIndicatorColors(int...)} to achieve
107 | * similar effects.
108 | */
109 | public void setCustomTabColorizer(TabColorizer tabColorizer) {
110 | mTabStrip.setCustomTabColorizer(tabColorizer);
111 | }
112 |
113 | public void setDistributeEvenly(boolean distributeEvenly) {
114 | mDistributeEvenly = distributeEvenly;
115 | }
116 |
117 | /**
118 | * Sets the colors to be used for indicating the selected tab. These colors are treated as a
119 | * circular array. Providing one color will mean that all tabs are indicated with the same color.
120 | */
121 | public void setSelectedIndicatorColors(int... colors) {
122 | mTabStrip.setSelectedIndicatorColors(colors);
123 | }
124 |
125 | /**
126 | * Set the {@link android.support.v4.view.ViewPager.OnPageChangeListener}. When using {@link SlidingTabLayout} you are
127 | * required to set any {@link android.support.v4.view.ViewPager.OnPageChangeListener} through this method. This is so
128 | * that the layout can update it's scroll position correctly.
129 | *
130 | * @see android.support.v4.view.ViewPager#setOnPageChangeListener(android.support.v4.view.ViewPager.OnPageChangeListener)
131 | */
132 | public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
133 | mViewPagerPageChangeListener = listener;
134 | }
135 |
136 | /**
137 | * Set the custom layout to be inflated for the tab views.
138 | *
139 | * @param layoutResId Layout id to be inflated
140 | * @param textViewId id of the {@link android.widget.TextView} in the inflated view
141 | */
142 | public void setCustomTabView(int layoutResId, int textViewId) {
143 | mTabViewLayoutId = layoutResId;
144 | mTabViewTextViewId = textViewId;
145 | }
146 |
147 | /**
148 | * Sets the associated view pager. Note that the assumption here is that the pager content
149 | * (number of tabs and tab titles) does not change after this call has been made.
150 | */
151 | public void setViewPager(ViewPager viewPager) {
152 | mTabStrip.removeAllViews();
153 |
154 | mViewPager = viewPager;
155 | if (viewPager != null) {
156 | viewPager.setOnPageChangeListener(new InternalViewPagerListener());
157 | populateTabStrip();
158 | }
159 | }
160 |
161 | /**
162 | * Create a default view to be used for tabs. This is called if a custom tab view is not set via
163 | * {@link #setCustomTabView(int, int)}.
164 | */
165 | protected TextView createDefaultTabView(Context context) {
166 | TextView textView = new TextView(context);
167 | textView.setGravity(Gravity.CENTER);
168 | textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
169 | textView.setTypeface(Typeface.DEFAULT_BOLD);
170 | textView.setLayoutParams(new LinearLayout.LayoutParams(
171 | ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
172 |
173 | TypedValue outValue = new TypedValue();
174 | getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
175 | outValue, true);
176 | textView.setBackgroundResource(outValue.resourceId);
177 | textView.setAllCaps(true);
178 |
179 | int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
180 | textView.setPadding(padding, padding, padding, padding);
181 |
182 | return textView;
183 | }
184 |
185 | private void populateTabStrip() {
186 | final PagerAdapter adapter = mViewPager.getAdapter();
187 | final OnClickListener tabClickListener = new TabClickListener();
188 |
189 | for (int i = 0; i < adapter.getCount(); i++) {
190 | View tabView = null;
191 | TextView tabTitleView = null;
192 |
193 | if (mTabViewLayoutId != 0) {
194 | // If there is a custom tab view layout id set, try and inflate it
195 | tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip,
196 | false);
197 | tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
198 | }
199 |
200 | if (tabView == null) {
201 | tabView = createDefaultTabView(getContext());
202 | }
203 |
204 | if (tabTitleView == null && TextView.class.isInstance(tabView)) {
205 | tabTitleView = (TextView) tabView;
206 | }
207 |
208 | if (mDistributeEvenly) {
209 | LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
210 | lp.width = 0;
211 | lp.weight = 1;
212 | }
213 |
214 | tabTitleView.setText(adapter.getPageTitle(i));
215 | tabView.setOnClickListener(tabClickListener);
216 | String desc = mContentDescriptions.get(i, null);
217 | if (desc != null) {
218 | tabView.setContentDescription(desc);
219 | }
220 |
221 | mTabStrip.addView(tabView);
222 | if (i == mViewPager.getCurrentItem()) {
223 | tabView.setSelected(true);
224 | }
225 | }
226 | }
227 |
228 | public void setContentDescription(int i, String desc) {
229 | mContentDescriptions.put(i, desc);
230 | }
231 |
232 | @Override
233 | protected void onAttachedToWindow() {
234 | super.onAttachedToWindow();
235 |
236 | if (mViewPager != null) {
237 | scrollToTab(mViewPager.getCurrentItem(), 0);
238 | }
239 | }
240 |
241 | private void scrollToTab(int tabIndex, int positionOffset) {
242 | final int tabStripChildCount = mTabStrip.getChildCount();
243 | if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) {
244 | return;
245 | }
246 |
247 | View selectedChild = mTabStrip.getChildAt(tabIndex);
248 | if (selectedChild != null) {
249 | int targetScrollX = selectedChild.getLeft() + positionOffset;
250 |
251 | if (tabIndex > 0 || positionOffset > 0) {
252 | // If we're not at the first child and are mid-scroll, make sure we obey the offset
253 | targetScrollX -= mTitleOffset;
254 | }
255 |
256 | scrollTo(targetScrollX, 0);
257 | }
258 | }
259 |
260 | private class InternalViewPagerListener implements ViewPager.OnPageChangeListener {
261 | private int mScrollState;
262 |
263 | @Override
264 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
265 | int tabStripChildCount = mTabStrip.getChildCount();
266 | if ((tabStripChildCount == 0) || (position < 0) || (position >= tabStripChildCount)) {
267 | return;
268 | }
269 |
270 | mTabStrip.onViewPagerPageChanged(position, positionOffset);
271 |
272 | View selectedTitle = mTabStrip.getChildAt(position);
273 | int extraOffset = (selectedTitle != null)
274 | ? (int) (positionOffset * selectedTitle.getWidth())
275 | : 0;
276 | scrollToTab(position, extraOffset);
277 |
278 | if (mViewPagerPageChangeListener != null) {
279 | mViewPagerPageChangeListener.onPageScrolled(position, positionOffset,
280 | positionOffsetPixels);
281 | }
282 | }
283 |
284 | @Override
285 | public void onPageScrollStateChanged(int state) {
286 | mScrollState = state;
287 |
288 | if (mViewPagerPageChangeListener != null) {
289 | mViewPagerPageChangeListener.onPageScrollStateChanged(state);
290 | }
291 | }
292 |
293 | @Override
294 | public void onPageSelected(int position) {
295 | if (mScrollState == ViewPager.SCROLL_STATE_IDLE) {
296 | mTabStrip.onViewPagerPageChanged(position, 0f);
297 | scrollToTab(position, 0);
298 | }
299 | for (int i = 0; i < mTabStrip.getChildCount(); i++) {
300 | mTabStrip.getChildAt(i).setSelected(position == i);
301 | }
302 | if (mViewPagerPageChangeListener != null) {
303 | mViewPagerPageChangeListener.onPageSelected(position);
304 | }
305 | }
306 |
307 | }
308 |
309 | private class TabClickListener implements OnClickListener {
310 | @Override
311 | public void onClick(View v) {
312 | for (int i = 0; i < mTabStrip.getChildCount(); i++) {
313 | if (v == mTabStrip.getChildAt(i)) {
314 | mViewPager.setCurrentItem(i);
315 | return;
316 | }
317 | }
318 | }
319 | }
320 |
321 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/tspoon/androidtoolbelt/view/SlidingTabStrip.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.tspoon.androidtoolbelt.view;
18 |
19 | import android.R;
20 | import android.content.Context;
21 | import android.graphics.Canvas;
22 | import android.graphics.Color;
23 | import android.graphics.Paint;
24 | import android.util.AttributeSet;
25 | import android.util.TypedValue;
26 | import android.view.View;
27 | import android.widget.LinearLayout;
28 |
29 | class SlidingTabStrip extends LinearLayout {
30 |
31 | private static final int DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS = 0;
32 | private static final byte DEFAULT_BOTTOM_BORDER_COLOR_ALPHA = 0x26;
33 | private static final int SELECTED_INDICATOR_THICKNESS_DIPS = 3;
34 | private static final int DEFAULT_SELECTED_INDICATOR_COLOR = 0xFF33B5E5;
35 |
36 | private final int mBottomBorderThickness;
37 | private final Paint mBottomBorderPaint;
38 |
39 | private final int mSelectedIndicatorThickness;
40 | private final Paint mSelectedIndicatorPaint;
41 |
42 | private final int mDefaultBottomBorderColor;
43 |
44 | private int mSelectedPosition;
45 | private float mSelectionOffset;
46 |
47 | private SlidingTabLayout.TabColorizer mCustomTabColorizer;
48 | private final SimpleTabColorizer mDefaultTabColorizer;
49 |
50 | SlidingTabStrip(Context context) {
51 | this(context, null);
52 | }
53 |
54 | SlidingTabStrip(Context context, AttributeSet attrs) {
55 | super(context, attrs);
56 | setWillNotDraw(false);
57 |
58 | final float density = getResources().getDisplayMetrics().density;
59 |
60 | TypedValue outValue = new TypedValue();
61 | context.getTheme().resolveAttribute(R.attr.colorForeground, outValue, true);
62 | final int themeForegroundColor = outValue.data;
63 |
64 | mDefaultBottomBorderColor = setColorAlpha(themeForegroundColor,
65 | DEFAULT_BOTTOM_BORDER_COLOR_ALPHA);
66 |
67 | mDefaultTabColorizer = new SimpleTabColorizer();
68 | mDefaultTabColorizer.setIndicatorColors(DEFAULT_SELECTED_INDICATOR_COLOR);
69 |
70 | mBottomBorderThickness = (int) (DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS * density);
71 | mBottomBorderPaint = new Paint();
72 | mBottomBorderPaint.setColor(mDefaultBottomBorderColor);
73 |
74 | mSelectedIndicatorThickness = (int) (SELECTED_INDICATOR_THICKNESS_DIPS * density);
75 | mSelectedIndicatorPaint = new Paint();
76 | }
77 |
78 | void setCustomTabColorizer(SlidingTabLayout.TabColorizer customTabColorizer) {
79 | mCustomTabColorizer = customTabColorizer;
80 | invalidate();
81 | }
82 |
83 | void setSelectedIndicatorColors(int... colors) {
84 | // Make sure that the custom colorizer is removed
85 | mCustomTabColorizer = null;
86 | mDefaultTabColorizer.setIndicatorColors(colors);
87 | invalidate();
88 | }
89 |
90 | void onViewPagerPageChanged(int position, float positionOffset) {
91 | mSelectedPosition = position;
92 | mSelectionOffset = positionOffset;
93 | invalidate();
94 | }
95 |
96 | @Override
97 | protected void onDraw(Canvas canvas) {
98 | final int height = getHeight();
99 | final int childCount = getChildCount();
100 | final SlidingTabLayout.TabColorizer tabColorizer = mCustomTabColorizer != null
101 | ? mCustomTabColorizer
102 | : mDefaultTabColorizer;
103 |
104 | // Thick colored underline below the current selection
105 | if (childCount > 0) {
106 | View selectedTitle = getChildAt(mSelectedPosition);
107 | int left = selectedTitle.getLeft();
108 | int right = selectedTitle.getRight();
109 | int color = tabColorizer.getIndicatorColor(mSelectedPosition);
110 |
111 | if (mSelectionOffset > 0f && mSelectedPosition < (getChildCount() - 1)) {
112 | int nextColor = tabColorizer.getIndicatorColor(mSelectedPosition + 1);
113 | if (color != nextColor) {
114 | color = blendColors(nextColor, color, mSelectionOffset);
115 | }
116 |
117 | // Draw the selection partway between the tabs
118 | View nextTitle = getChildAt(mSelectedPosition + 1);
119 | left = (int) (mSelectionOffset * nextTitle.getLeft() +
120 | (1.0f - mSelectionOffset) * left);
121 | right = (int) (mSelectionOffset * nextTitle.getRight() +
122 | (1.0f - mSelectionOffset) * right);
123 | }
124 |
125 | mSelectedIndicatorPaint.setColor(color);
126 |
127 | canvas.drawRect(left, height - mSelectedIndicatorThickness, right,
128 | height, mSelectedIndicatorPaint);
129 | }
130 |
131 | // Thin underline along the entire bottom edge
132 | canvas.drawRect(0, height - mBottomBorderThickness, getWidth(), height, mBottomBorderPaint);
133 | }
134 |
135 | /**
136 | * Set the alpha value of the {@code color} to be the given {@code alpha} value.
137 | */
138 | private static int setColorAlpha(int color, byte alpha) {
139 | return Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color));
140 | }
141 |
142 | /**
143 | * Blend {@code color1} and {@code color2} using the given ratio.
144 | *
145 | * @param ratio of which to blend. 1.0 will return {@code color1}, 0.5 will give an even blend,
146 | * 0.0 will return {@code color2}.
147 | */
148 | private static int blendColors(int color1, int color2, float ratio) {
149 | final float inverseRation = 1f - ratio;
150 | float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation);
151 | float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
152 | float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation);
153 | return Color.rgb((int) r, (int) g, (int) b);
154 | }
155 |
156 | private static class SimpleTabColorizer implements SlidingTabLayout.TabColorizer {
157 | private int[] mIndicatorColors;
158 |
159 | @Override
160 | public final int getIndicatorColor(int position) {
161 | return mIndicatorColors[position % mIndicatorColors.length];
162 | }
163 |
164 | void setIndicatorColors(int... colors) {
165 | mIndicatorColors = colors;
166 | }
167 | }
168 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_github_circle_white_48dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T-Spoon/Android-Developer-Toolbelt/c8a53cc8622742036aa7d1dc6da2d5058a7ac8a4/app/src/main/res/drawable-hdpi/ic_github_circle_white_48dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_github_circle_white_48dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T-Spoon/Android-Developer-Toolbelt/c8a53cc8622742036aa7d1dc6da2d5058a7ac8a4/app/src/main/res/drawable-mdpi/ic_github_circle_white_48dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_github_circle_white_48dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T-Spoon/Android-Developer-Toolbelt/c8a53cc8622742036aa7d1dc6da2d5058a7ac8a4/app/src/main/res/drawable-xhdpi/ic_github_circle_white_48dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_github_circle_white_48dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T-Spoon/Android-Developer-Toolbelt/c8a53cc8622742036aa7d1dc6da2d5058a7ac8a4/app/src/main/res/drawable-xxhdpi/ic_github_circle_white_48dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_github_circle_white_48dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T-Spoon/Android-Developer-Toolbelt/c8a53cc8622742036aa7d1dc6da2d5058a7ac8a4/app/src/main/res/drawable-xxxhdpi/ic_github_circle_white_48dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/selector_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
10 |
11 |
16 |
17 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_memory.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
13 |
14 |
18 |
19 |
24 |
25 |
30 |
31 |
32 |
33 |
34 |
42 |
43 |
47 |
48 |
54 |
55 |
60 |
61 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
77 |
78 |
84 |
85 |
90 |
91 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
107 |
108 |
114 |
115 |
120 |
121 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
143 |
144 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_tab.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/toolbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T-Spoon/Android-Developer-Toolbelt/c8a53cc8622742036aa7d1dc6da2d5058a7ac8a4/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T-Spoon/Android-Developer-Toolbelt/c8a53cc8622742036aa7d1dc6da2d5058a7ac8a4/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T-Spoon/Android-Developer-Toolbelt/c8a53cc8622742036aa7d1dc6da2d5058a7ac8a4/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T-Spoon/Android-Developer-Toolbelt/c8a53cc8622742036aa7d1dc6da2d5058a7ac8a4/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T-Spoon/Android-Developer-Toolbelt/c8a53cc8622742036aa7d1dc6da2d5058a7ac8a4/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #4CAF50
4 | #43A047
5 |
6 | #607D8B
7 | #546E7A
8 |
9 | @color/material_blue_grey_500
10 | @color/material_blue_grey_600
11 | #333
12 | #FFF
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 | 48dp
7 | 24dp
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Android Developer Toolbelt
3 | Android Toolbelt
4 |
5 | https://play.google.com/store/apps/details?id=com.tspoon.androidtoolbelt
6 | https://github.com/T-Spoon/Android-Developer-Toolbelt
7 | @string/url_play_store
8 |
9 | Share
10 | Github
11 |
12 | Memory
13 |
14 | Total:
15 | Free:
16 | Low Memory:
17 |
18 | FREE RAM
19 | %1$d MB / %2$d MB
20 |
21 | Fill Memory
22 | Stop
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
19 |
20 |
30 |
31 |
34 |
35 |
38 |
39 |
42 |
43 |
45 |
46 |
53 |
54 |
57 |
58 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.1.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/compiler/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea
4 | .DS_Store
5 | /build
6 |
7 | # Crashlytics
8 | **com_crashlytics_export_strings.xml
9 |
10 | *.apk
11 | *.iml
--------------------------------------------------------------------------------
/compiler/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 |
3 | sourceCompatibility = 1.7
4 | targetCompatibility = 1.7
5 |
6 | sourceSets {
7 | main {
8 | java {
9 | srcDirs = ['src/main/java', /*'../app/src/main/java'*/]
10 | }
11 | }
12 | }
13 |
14 | dependencies {
15 | compile fileTree(dir: 'libs', include: ['*.jar'])
16 | compile files("${System.properties['java.home']}/../lib/tools.jar")
17 | compile 'com.google.android:android:4.1.1.4'
18 | compile 'com.squareup:javapoet:1.0.0'
19 | compile 'com.google.auto.service:auto-service:1.0-rc2'
20 | compile 'com.jakewharton.timber:timber:2.4.2'
21 | }
--------------------------------------------------------------------------------
/compiler/src/main/java/com/tspoon/androidtoolbelt/compiler/Registry.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt.compiler;
2 |
3 | import javax.annotation.processing.Filer;
4 | import javax.annotation.processing.Messager;
5 | import javax.lang.model.util.Elements;
6 | import javax.lang.model.util.Types;
7 |
8 | public class Registry {
9 |
10 | private static Registry sInstance;
11 |
12 | private Messager mMessager;
13 | private Types mTypeUtils;
14 | private Elements mElementUtils;
15 | private Filer mFiler;
16 |
17 | public static void init(Messager messager, Types types, Elements elements, Filer filer) {
18 | sInstance = new Registry(messager, types, elements, filer);
19 | }
20 |
21 | public static Registry get() {
22 | return sInstance;
23 | }
24 |
25 | private Registry(Messager messager, Types types, Elements elements, Filer filer) {
26 | mMessager = messager;
27 | mTypeUtils = types;
28 | mElementUtils = elements;
29 | mFiler = filer;
30 | }
31 |
32 | public Messager getMessager() {
33 | return mMessager;
34 | }
35 |
36 | public Types getTypeUtils() {
37 | return mTypeUtils;
38 | }
39 |
40 | public Elements getElementUtils() {
41 | return mElementUtils;
42 | }
43 |
44 | public Filer getFiler() {
45 | return mFiler;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/tspoon/androidtoolbelt/compiler/ToolbeltProcessor.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt.compiler;
2 |
3 | import com.google.auto.service.AutoService;
4 | import com.tspoon.androidtoolbelt.compiler.writer.MemoryServiceWriter;
5 | import com.tspoon.androidtoolbelt.compiler.writer.ServiceHolderWriter;
6 |
7 | import java.io.IOException;
8 | import java.io.Writer;
9 | import java.util.Set;
10 |
11 | import javax.annotation.processing.AbstractProcessor;
12 | import javax.annotation.processing.ProcessingEnvironment;
13 | import javax.annotation.processing.Processor;
14 | import javax.annotation.processing.RoundEnvironment;
15 | import javax.lang.model.element.TypeElement;
16 | import javax.tools.JavaFileObject;
17 |
18 | @AutoService(Processor.class)
19 | public class ToolbeltProcessor extends AbstractProcessor {
20 |
21 | public static final int NUMBER_OF_SERVICES = 15;
22 |
23 | @Override
24 | public synchronized void init(ProcessingEnvironment processingEnv) {
25 | super.init(processingEnv);
26 | Registry.init(processingEnv.getMessager(), processingEnv.getTypeUtils(), processingEnv.getElementUtils(), processingEnv.getFiler());
27 |
28 | for (int i = 1; i <= NUMBER_OF_SERVICES; i++) {
29 | MemoryServiceWriter serviceWriter = new MemoryServiceWriter(i);
30 | try {
31 | JavaFileObject object = Registry.get().getFiler().createSourceFile(serviceWriter.getFileName());
32 | Writer writer = object.openWriter();
33 | serviceWriter.writeSource(writer);
34 | writer.flush();
35 | writer.close();
36 | } catch (IOException e) {
37 | e.printStackTrace();
38 | }
39 | }
40 |
41 |
42 | ServiceHolderWriter holderWriter = new ServiceHolderWriter();
43 | try {
44 | JavaFileObject object = Registry.get().getFiler().createSourceFile(holderWriter.getFileName());
45 | Writer writer = object.openWriter();
46 | holderWriter.writeSource(writer);
47 | writer.flush();
48 | writer.close();
49 | } catch (IOException e) {
50 | e.printStackTrace();
51 | }
52 | }
53 |
54 | @Override
55 | public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) {
56 | return false;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/tspoon/androidtoolbelt/compiler/writer/MemoryServiceWriter.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt.compiler.writer;
2 |
3 | import android.app.IntentService;
4 | import android.content.Intent;
5 | import android.os.IBinder;
6 | import android.os.Messenger;
7 |
8 | import com.squareup.javapoet.ClassName;
9 | import com.squareup.javapoet.CodeBlock;
10 | import com.squareup.javapoet.FieldSpec;
11 | import com.squareup.javapoet.JavaFile;
12 | import com.squareup.javapoet.MethodSpec;
13 | import com.squareup.javapoet.ParameterizedTypeName;
14 | import com.squareup.javapoet.TypeName;
15 | import com.squareup.javapoet.TypeSpec;
16 |
17 | import java.io.IOException;
18 | import java.io.Writer;
19 | import java.util.ArrayList;
20 | import java.util.Random;
21 |
22 | import javax.lang.model.element.Modifier;
23 |
24 | import timber.log.Timber;
25 |
26 | public class MemoryServiceWriter implements SourceWriter {
27 |
28 | private int mNumber;
29 |
30 | private static final ClassName CLASS_MEMORY_UTILS = ClassName.get("com.tspoon.androidtoolbelt.utils", "MemoryUtils");
31 |
32 | public MemoryServiceWriter(int number) {
33 | mNumber = number;
34 | }
35 |
36 | public String getFileName() {
37 | return PACKAGE + "." + getSimpleName();
38 | }
39 |
40 | @Override
41 | public void writeSource(Writer writer) throws IOException {
42 |
43 | TypeSpec typeSpec = TypeSpec.classBuilder(getSimpleName())
44 | .superclass(ClassName.get(IntentService.class))
45 | .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
46 | .addField(createFieldMessenger())
47 | .addField(createFieldAllocations())
48 | .addField(createFieldRun())
49 | .addMethod(createConstructor())
50 | .addMethod(createOnBind())
51 | .addMethod(createOnHandleIntent())
52 | .build();
53 |
54 | JavaFile javaFile = JavaFile.builder(PACKAGE, typeSpec)
55 | .addFileComment("Generated by MemoryServiceWriter.java. Do not modify!")
56 | .build();
57 |
58 | javaFile.writeTo(writer);
59 | }
60 |
61 | private String getSimpleName() {
62 | return "MemoryService" + mNumber;
63 | }
64 |
65 | private FieldSpec createFieldMessenger() {
66 | return FieldSpec.builder(ClassName.get(Messenger.class), "mMessenger", Modifier.PRIVATE, Modifier.FINAL).build();
67 | }
68 |
69 | private FieldSpec createFieldAllocations() {
70 | return FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(ArrayList.class), ClassName.bestGuess("com.tspoon.androidtoolbelt.utils.ByteArrayWrapper")), "mAllocations", Modifier.PRIVATE, Modifier.FINAL)
71 | .initializer("new $T<>()", ArrayList.class)
72 | .build();
73 | }
74 |
75 | private FieldSpec createFieldRun() {
76 | return FieldSpec.builder(Boolean.class, "mRun", Modifier.PRIVATE)
77 | .build();
78 | }
79 |
80 | private MethodSpec createConstructor() {
81 | CodeBlock code = CodeBlock.builder()
82 | .addStatement("super($L.class.getName())", getFileName())
83 | .addStatement("mMessenger = new $T(new $T(mRun))", Messenger.class, ClassName.bestGuess("com.tspoon.androidtoolbelt.component.service.MessageHandler"))
84 | .build();
85 |
86 | return MethodSpec.constructorBuilder()
87 | .addModifiers(Modifier.PUBLIC)
88 | .addCode(code)
89 | .build();
90 | }
91 |
92 | private MethodSpec createOnBind() {
93 | CodeBlock code = CodeBlock.builder()
94 | .addStatement("$T.d(\"onBind: \" + intent)", Timber.class)
95 | .addStatement("return mMessenger.getBinder()")
96 | .build();
97 |
98 | return MethodSpec.methodBuilder("onBind")
99 | .addAnnotation(Override.class)
100 | .addModifiers(Modifier.PUBLIC)
101 | .addParameter(ClassName.get(Intent.class), "intent")
102 | .returns(ClassName.get(IBinder.class))
103 | .addCode(code)
104 | .build();
105 | }
106 |
107 |
108 | private MethodSpec createOnHandleIntent() {
109 | CodeBlock code = CodeBlock.builder()
110 | .addStatement("mRun = true")
111 |
112 | .addStatement("// This is to prevent all services trying to allocate at once. Spread them out evenly")
113 | .beginControlFlow("try")
114 | .addStatement("$T.sleep(" + (mNumber * 50) + ")", Thread.class)
115 | .endControlFlow()
116 | .beginControlFlow("catch ($T e)", InterruptedException.class)
117 | .endControlFlow()
118 |
119 | .beginControlFlow("while(mRun)")
120 |
121 | .addStatement("mRun = $L.isMemoryAvailable()", CLASS_MEMORY_UTILS)
122 | .addStatement("$T.d(\"Attempting Allocation...\")", Timber.class)
123 |
124 | .beginControlFlow("if(!$T.get(getApplicationContext()).isLowMemory())", CLASS_MEMORY_UTILS)
125 | .addStatement("byte[] bytes = new byte[1024 * 1024 * 2]")
126 | .addStatement("new $T().nextBytes(bytes)", Random.class)
127 | .addStatement("mAllocations.add(new ByteArrayWrapper(bytes))")
128 | .addStatement("$T.d(\"Allocated new block\")", Timber.class)
129 |
130 | .beginControlFlow("try")
131 | .addStatement("$T.sleep(1000)", Thread.class)
132 | .endControlFlow()
133 | .beginControlFlow("catch ($T e)", InterruptedException.class)
134 | .addStatement("e.printStackTrace()")
135 | .endControlFlow()
136 |
137 | .endControlFlow()
138 | .endControlFlow()
139 | .build();
140 |
141 |
142 | return MethodSpec.methodBuilder("onHandleIntent")
143 | .addAnnotation(Override.class)
144 | .addModifiers(Modifier.PROTECTED)
145 | .addParameter(ClassName.get(Intent.class), "intent")
146 | .returns(TypeName.VOID)
147 | .addCode(code.toString())
148 | .build();
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/tspoon/androidtoolbelt/compiler/writer/ServiceHolderWriter.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt.compiler.writer;
2 |
3 | import android.app.Service;
4 | import android.content.Context;
5 | import android.content.Intent;
6 |
7 | import com.squareup.javapoet.ClassName;
8 | import com.squareup.javapoet.CodeBlock;
9 | import com.squareup.javapoet.FieldSpec;
10 | import com.squareup.javapoet.JavaFile;
11 | import com.squareup.javapoet.MethodSpec;
12 | import com.squareup.javapoet.ParameterizedTypeName;
13 | import com.squareup.javapoet.TypeName;
14 | import com.squareup.javapoet.TypeSpec;
15 | import com.squareup.javapoet.WildcardTypeName;
16 | import com.tspoon.androidtoolbelt.compiler.ToolbeltProcessor;
17 |
18 | import java.io.IOException;
19 | import java.io.Writer;
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | import javax.lang.model.element.Modifier;
24 |
25 | import timber.log.Timber;
26 |
27 | public class ServiceHolderWriter implements SourceWriter {
28 |
29 | private static final String CLASS_NAME = "ServiceHolderImpl";
30 |
31 | private static final String FIELD_SERVICES = "SERVICES";
32 | private static final String FIELD_CONNECTIONS = "CONNECTIONS";
33 |
34 | @Override
35 | public String getFileName() {
36 | return PACKAGE + "." + CLASS_NAME;
37 | }
38 |
39 | @Override
40 | public void writeSource(Writer writer) throws IOException {
41 | TypeSpec typeSpec = TypeSpec.classBuilder(CLASS_NAME)
42 | .addSuperinterface(ClassName.get(PACKAGE, "ServiceHolder"))
43 | .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
44 | .addField(createFieldServices())
45 | .addField(createFieldConnections())
46 | .addMethod(createStartServices())
47 | .addMethod(createStopServices())
48 | .build();
49 |
50 | JavaFile javaFile = JavaFile.builder(PACKAGE, typeSpec)
51 | .addFileComment("Generated by MemoryServiceWriter.java. Do not modify!")
52 | .build();
53 |
54 | javaFile.writeTo(writer);
55 | }
56 |
57 | private FieldSpec createFieldServices() {
58 | TypeName type = ParameterizedTypeName.get(ClassName.get(List.class), ParameterizedTypeName.get(ClassName.get(Class.class), WildcardTypeName.subtypeOf(ClassName.get(Service.class))));
59 |
60 | CodeBlock.Builder builder = CodeBlock.builder()
61 | .add("new $T(){{\n", ParameterizedTypeName.get(ClassName.get(ArrayList.class), ParameterizedTypeName.get(ClassName.get(Class.class), WildcardTypeName.subtypeOf(ClassName.get(Service.class)))));
62 |
63 | for (int i = 1; i <= ToolbeltProcessor.NUMBER_OF_SERVICES; i++) {
64 | builder.addStatement("add($T.class)", ClassName.bestGuess("MemoryService" + i));
65 | }
66 | builder.add("}}");
67 |
68 | return FieldSpec.builder(type, FIELD_SERVICES, Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
69 | .initializer(builder.build().toString())
70 | .build();
71 | }
72 |
73 | private FieldSpec createFieldConnections() {
74 | TypeName type = ParameterizedTypeName.get(ClassName.get(List.class), ClassName.get(PACKAGE, "MemoryServiceConnection"));
75 | return FieldSpec.builder(type, FIELD_CONNECTIONS, Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
76 | .initializer("new $T<>()", ArrayList.class)
77 | .build();
78 | }
79 |
80 |
81 | private MethodSpec createStartServices() {
82 | ClassName memoryServiceConnection = ClassName.get(PACKAGE, "MemoryServiceConnection");
83 |
84 | CodeBlock code = CodeBlock.builder()
85 | .beginControlFlow("for($T service: $L)", ParameterizedTypeName.get(ClassName.get(Class.class), WildcardTypeName.subtypeOf(Service.class)), FIELD_SERVICES)
86 | .addStatement("$T intent = new $T(context, service)", Intent.class, Intent.class)
87 | .addStatement("context.startService(intent)")
88 | .add("\n")
89 | .addStatement("$T connection = new $T()", memoryServiceConnection, memoryServiceConnection)
90 | .addStatement("context.bindService(intent, connection, Context.BIND_AUTO_CREATE)")
91 | .endControlFlow()
92 | .build();
93 |
94 | return MethodSpec.methodBuilder("startServices")
95 | .addAnnotation(Override.class)
96 | .addModifiers(Modifier.PUBLIC)
97 | .addParameter(ClassName.get(Context.class), "context")
98 | .addCode(code)
99 | .build();
100 | }
101 |
102 | private MethodSpec createStopServices() {
103 | CodeBlock code = CodeBlock.builder()
104 | .addStatement("$T.d(\"Stopping Services... \" + $L.size() + \" connections found.\")", Timber.class, FIELD_CONNECTIONS)
105 | .beginControlFlow("while($L.size() > 0)", FIELD_CONNECTIONS)
106 | .addStatement("$L.remove(0).stopService()", FIELD_CONNECTIONS)
107 | .endControlFlow()
108 | .build();
109 |
110 | return MethodSpec.methodBuilder("stopServices")
111 | .addAnnotation(Override.class)
112 | .addModifiers(Modifier.PUBLIC)
113 | .addCode(code)
114 | .build();
115 | }
116 |
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/compiler/src/main/java/com/tspoon/androidtoolbelt/compiler/writer/SourceWriter.java:
--------------------------------------------------------------------------------
1 | package com.tspoon.androidtoolbelt.compiler.writer;
2 |
3 | import java.io.IOException;
4 | import java.io.Writer;
5 |
6 | public interface SourceWriter {
7 |
8 | static final String PACKAGE = "com.tspoon.androidtoolbelt.component.service";
9 |
10 | String getFileName();
11 |
12 | void writeSource(Writer writer) throws IOException;
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/T-Spoon/Android-Developer-Toolbelt/c8a53cc8622742036aa7d1dc6da2d5058a7ac8a4/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-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 ':app', ':compiler'
2 |
--------------------------------------------------------------------------------