├── .gitignore ├── .gitlab-ci.yml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── pringstudio │ │ └── agnosthings │ │ ├── ApplicationTest.java │ │ └── MainActivityTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── pringstudio │ │ │ └── agnosthings │ │ │ ├── AgnosthingsApi.java │ │ │ ├── FragmentAbout.java │ │ │ ├── FragmentHome.java │ │ │ ├── FragmentSaklar.java │ │ │ ├── MainActivity.java │ │ │ ├── NavAdapter.java │ │ │ ├── PringIntro.java │ │ │ ├── SaklarAdapter.java │ │ │ ├── SaklarHistory.java │ │ │ ├── SaklarHistoryAdapter.java │ │ │ ├── model │ │ │ └── Saklar.java │ │ │ └── view │ │ │ ├── DividerItemDecoration.java │ │ │ ├── ProgressBarAnimation.java │ │ │ └── RecyclerItemClickListener.java │ └── res │ │ ├── anim │ │ └── rotate_refresh.xml │ │ ├── drawable │ │ ├── circle_shape.xml │ │ ├── circular_progress_bar.xml │ │ ├── header.png │ │ ├── ic_account_circle.xml │ │ ├── ic_cached_grey.xml │ │ ├── ic_cached_grey_200.xml │ │ ├── ic_cached_grey_200_24dp.xml │ │ ├── ic_cached_grey_200_36dp.xml │ │ ├── ic_dashboard_grey.xml │ │ ├── ic_info_grey.xml │ │ ├── ic_lightbulb_outline_green.xml │ │ ├── ic_lightbulb_outline_grey.xml │ │ ├── ic_mail_grey.xml │ │ ├── ic_question.xml │ │ ├── ic_refresh_grey_100.xml │ │ ├── ic_refresh_grey_300.xml │ │ ├── splash_access.png │ │ ├── splash_air.png │ │ ├── splash_lampu.png │ │ ├── splash_listrik.png │ │ ├── splash_lpg.png │ │ ├── splash_notif.png │ │ └── splash_suhu.png │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_saklar_history.xml │ │ ├── content_main.xml │ │ ├── content_saklar_history.xml │ │ ├── fragment_about.xml │ │ ├── fragment_home.xml │ │ ├── fragment_saklar.xml │ │ ├── item_recycler_history.xml │ │ ├── item_recycler_saklar.xml │ │ ├── iv_refresh.xml │ │ ├── nav_drawer_header.xml │ │ └── nav_drawer_item_row.xml │ │ ├── menu │ │ ├── menu_home.xml │ │ ├── menu_main.xml │ │ ├── menu_saklar.xml │ │ └── menu_saklar_history.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 │ └── test │ └── java │ └── com │ └── pringstudio │ └── agnosthings │ └── ExampleUnitTest.java ├── build.gradle ├── device-2016-05-08-154208.png ├── device-2016-05-16-183543.png ├── device-2016-05-16-183600.png ├── device-2016-05-16-183613.png ├── device-2016-05-16-183636.png ├── device-2016-05-16-183648.png ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/android,intellij 3 | 4 | ### Android ### 5 | # Built application files 6 | *.apk 7 | *.ap_ 8 | 9 | # Files for the Dalvik VM 10 | *.dex 11 | 12 | # Java class files 13 | *.class 14 | 15 | # Generated files 16 | bin/ 17 | gen/ 18 | out/ 19 | 20 | # Gradle files 21 | .gradle/ 22 | build/ 23 | 24 | # Local configuration file (sdk path, etc) 25 | local.properties 26 | 27 | # Proguard folder generated by Eclipse 28 | proguard/ 29 | 30 | # Log Files 31 | *.log 32 | 33 | # Android Studio Navigation editor temp files 34 | .navigation/ 35 | 36 | # Android Studio captures folder 37 | captures/ 38 | 39 | # Intellij 40 | *.iml 41 | 42 | # Keystore files 43 | *.jks 44 | 45 | ### Android Patch ### 46 | gen-external-apklibs 47 | 48 | 49 | ### Intellij ### 50 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 51 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 52 | 53 | # User-specific stuff: 54 | .idea/workspace.xml 55 | .idea/tasks.xml 56 | .idea/dictionaries 57 | .idea/vcs.xml 58 | .idea/jsLibraryMappings.xml 59 | .idea/* 60 | # Sensitive or high-churn files: 61 | .idea/dataSources.ids 62 | .idea/dataSources.xml 63 | .idea/dataSources.local.xml 64 | .idea/sqlDataSources.xml 65 | .idea/dynamic.xml 66 | .idea/uiDesigner.xml 67 | 68 | # Gradle: 69 | .idea/gradle.xml 70 | .idea/libraries 71 | 72 | # Mongo Explorer plugin: 73 | .idea/mongoSettings.xml 74 | 75 | ## File-based project format: 76 | *.iws 77 | 78 | ## Plugin-specific files: 79 | 80 | # IntelliJ 81 | /out/ 82 | 83 | # mpeltonen/sbt-idea plugin 84 | .idea_modules/ 85 | 86 | # JIRA plugin 87 | atlassian-ide-plugin.xml 88 | 89 | # Crashlytics plugin (for Android Studio and IntelliJ) 90 | com_crashlytics_export_strings.xml 91 | crashlytics.properties 92 | crashlytics-build.properties 93 | fabric.properties 94 | 95 | ### Intellij Patch ### 96 | *.iml 97 | # Screenshot 98 | device*.png 99 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | image: jangrewe/gitlab-ci-android 2 | 3 | stages: 4 | - build 5 | 6 | debug: 7 | stage: build 8 | except: 9 | - release 10 | script: 11 | - ./gradlew assembleDebug 12 | artifacts: 13 | paths: 14 | - app/build/outputs/apk/app-debug.apk 15 | 16 | release: 17 | stage: build 18 | only: 19 | - release 20 | script: 21 | - ./gradlew assembleRelease 22 | artifacts: 23 | paths: 24 | - app/build/outputs/apk/app-release.apk 25 | -------------------------------------------------------------------------------- /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 2016 (c) Pring Studio 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AndroidSmartHome 2 | Android Smart Home App using Agnosthing.com IoT Platform. 3 | 4 | Dicoding Challenge [AgnosThings Savvy Home Apps Challenges](https://www.dicoding.com/challenges/71) 5 | 6 | ## API 7 | You can register your Agnosthings api UID here [Agnosthings.com](http://agnosthings.com/) 8 | 9 | ## Screenshot 10 | ![Screenshot](/device-2016-05-16-183636.png?raw=true "Screenshot") 11 | 12 | ## License 13 | ``` 14 | Copyright 2016 (c) Pring Studio 15 | 16 | Licensed under the Apache License, Version 2.0 (the "License"); 17 | you may not use this file except in compliance with the License. 18 | You may obtain a copy of the License at 19 | 20 | http://www.apache.org/licenses/LICENSE-2.0 21 | 22 | Unless required by applicable law or agreed to in writing, software 23 | distributed under the License is distributed on an "AS IS" BASIS, 24 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | See the License for the specific language governing permissions and 26 | limitations under the License. 27 | ``` 28 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'realm-android' 3 | 4 | android { 5 | compileSdkVersion 23 6 | buildToolsVersion "23.0.3" 7 | 8 | defaultConfig { 9 | applicationId "com.pringstudio.agnosthings" 10 | minSdkVersion 15 11 | targetSdkVersion 23 12 | versionCode 3 13 | versionName "1.1-beta" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled true 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | 22 | splits { 23 | // Split apks on build target ABI, view all options for the splits here: 24 | // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits 25 | abi { 26 | enable false 27 | reset() 28 | include 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'x86', 'x86_64' 29 | } 30 | } 31 | } 32 | 33 | repositories { 34 | maven { url "https://jitpack.io" } 35 | mavenCentral() 36 | } 37 | 38 | 39 | dependencies { 40 | compile fileTree(dir: 'libs', include: ['*.jar']) 41 | testCompile 'junit:junit:4.12' 42 | compile 'com.android.support:appcompat-v7:23.3.0' 43 | compile 'com.android.support:design:23.3.0' 44 | compile 'com.android.support:recyclerview-v7:23.3.0' 45 | compile 'com.android.support:cardview-v7:23.3.0' 46 | compile 'com.loopj.android:android-async-http:1.4.9' 47 | compile 'com.github.PhilJay:MPAndroidChart:v2.2.4' 48 | compile 'com.github.paolorotolo:appintro:3.4.0' 49 | } 50 | -------------------------------------------------------------------------------- /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 /opt/android/android-sdk-linux/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/pringstudio/agnosthings/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.pringstudio.agnosthings; 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/androidTest/java/com/pringstudio/agnosthings/MainActivityTest.java: -------------------------------------------------------------------------------- 1 | package com.pringstudio.agnosthings; 2 | 3 | import android.test.ActivityInstrumentationTestCase2; 4 | 5 | /** 6 | * Created by sucipto on 4/14/16. 7 | */ 8 | public class MainActivityTest extends ActivityInstrumentationTestCase2{ 9 | 10 | public MainActivityTest(){ 11 | super(MainActivity.class); 12 | } 13 | 14 | // First Test 15 | public void testActivityExists(){ 16 | MainActivity activity = getActivity(); 17 | assertNotNull(activity); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 14 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 29 | 32 | 33 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/pringstudio/agnosthings/AgnosthingsApi.java: -------------------------------------------------------------------------------- 1 | package com.pringstudio.agnosthings; 2 | 3 | import android.content.Context; 4 | import android.support.design.widget.Snackbar; 5 | import android.text.TextUtils; 6 | import android.util.Log; 7 | import android.widget.Toast; 8 | 9 | import com.loopj.android.http.AsyncHttpClient; 10 | import com.loopj.android.http.JsonHttpResponseHandler; 11 | import com.pringstudio.agnosthings.model.Saklar; 12 | 13 | import org.json.JSONArray; 14 | import org.json.JSONObject; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Collection; 18 | import java.util.Collections; 19 | import java.util.HashMap; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | import cz.msebera.android.httpclient.Header; 24 | import io.realm.Realm; 25 | import io.realm.RealmConfiguration; 26 | import io.realm.RealmResults; 27 | 28 | /** 29 | * Created by sucipto on 5/1/16. 30 | */ 31 | public class AgnosthingsApi { 32 | 33 | Realm realm; 34 | Context context; 35 | 36 | // HTTP CLient 37 | AsyncHttpClient httpClient = new AsyncHttpClient(); 38 | 39 | // Get saklar agnosting api channel 40 | String saklar_channel = "http://agnosthings.com/6fb658cc-05fe-11e6-8001-005056805279/"; 41 | 42 | // Listenner 43 | private SaklarValueUpdateListener saklarValueUpdateListener; 44 | private SaklarHistoryLoadedListener saklarHistoryLoadedListener; 45 | private SuhuLoadedListener suhuLoadedListener; 46 | private PDAMLoadedListener pdamLoadedListener; 47 | private ListrikLoadedListener listrikLoadedListener; 48 | private LPGLoadedListener lpgLoadedListener; 49 | 50 | // Saklar value proccessed data 51 | int processedData = 0; 52 | 53 | public AgnosthingsApi(Context context) { 54 | 55 | this.context = context; 56 | 57 | saklarValueUpdateListener = null; 58 | 59 | // Init Realm 60 | RealmConfiguration config = new RealmConfiguration.Builder(context) 61 | .name("agnosthings.realm") 62 | .schemaVersion(1) 63 | .build(); 64 | 65 | realm = Realm.getInstance(config); 66 | } 67 | 68 | // Send data to agnosthing api server 69 | public void pushDataSaklar() { 70 | 71 | //Log.d("pushDataSaklar()","Fire..!!"); 72 | 73 | // Get All Saklar 74 | RealmResults saklars = realm.where(Saklar.class).findAll(); 75 | 76 | 77 | // Get saklar item 78 | List saklar_item = new ArrayList<>(); 79 | for (Saklar saklar : saklars) { 80 | saklar_item.add(saklar.getId() + "=" + saklar.getValue()); 81 | } 82 | 83 | String saklarku = TextUtils.join(",", saklar_item); 84 | 85 | String api_url = saklar_channel +"feed?push="+ saklarku; 86 | //Log.d("AgnosthingApi", "Saklarku : " + api_url); 87 | 88 | // Cancel all pending request 89 | httpClient.cancelAllRequests(true); 90 | httpClient.cancelRequests(context,true); 91 | 92 | // Call new api request 93 | httpClient.get(context, api_url, new JsonHttpResponseHandler() { 94 | @Override 95 | public void onSuccess(int statusCode, Header[] headers, JSONObject response) { 96 | //super.onSuccess(statusCode, headers, response); 97 | 98 | try { 99 | if (response.getString("code").equals("200") && response.getString("value").equals("Data has been successfully added")) { 100 | Toast.makeText(context, "Data updated ", Toast.LENGTH_SHORT).show(); 101 | }else{ 102 | Toast.makeText(context, "Failed to Update data", Toast.LENGTH_SHORT).show(); 103 | } 104 | } catch (Exception e) { 105 | Toast.makeText(context, "Api Cal Failed", Toast.LENGTH_SHORT).show(); 106 | } 107 | 108 | 109 | } 110 | 111 | @Override 112 | public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { 113 | super.onFailure(statusCode, headers, throwable, errorResponse); 114 | Toast.makeText(context, "API Call Failed", Toast.LENGTH_SHORT).show(); 115 | } 116 | 117 | @Override 118 | public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { 119 | super.onFailure(statusCode, headers, responseString, throwable); 120 | Toast.makeText(context, "API Call Failed", Toast.LENGTH_SHORT).show(); 121 | throwable.printStackTrace(); 122 | } 123 | 124 | @Override 125 | public void onCancel() { 126 | Log.d("AgnosthingApi","Request Canceled"); 127 | } 128 | }); 129 | 130 | } 131 | 132 | // Retreive Data from api server 133 | public void retreiveSaklarValue(){ 134 | // Get All Saklar 135 | final RealmResults saklars = realm.where(Saklar.class).findAll(); 136 | 137 | 138 | 139 | for (final Saklar saklar : saklars){ 140 | final String saklar_url = saklar_channel+"field/last/feed/174/"+saklar.getId(); 141 | //Log.d("Saklar URL",saklar_url); 142 | 143 | httpClient.setTimeout(30); 144 | httpClient.get(context,saklar_url, new JsonHttpResponseHandler(){ 145 | @Override 146 | public void onSuccess(int statusCode, Header[] headers, JSONObject response) { 147 | //super.onSuccess(statusCode, headers, response); 148 | try { 149 | int oldValue = saklar.getValue(); 150 | int newValue = response.getInt("value"); 151 | realm.beginTransaction(); 152 | saklar.setValue(newValue); 153 | realm.commitTransaction(); 154 | 155 | processedData++; 156 | 157 | if(saklars.size() == processedData){ 158 | if(saklarValueUpdateListener != null){ 159 | // Send Signal to listenner 160 | saklarValueUpdateListener.onValueLoaded(); 161 | } 162 | } 163 | 164 | //Log.d("Update Skalar Value","UPdating saklar value "+saklar.getId()+" From: "+oldValue+" to "+newValue); 165 | }catch (Exception e){ 166 | Toast.makeText(context,"Get data "+saklar.getId()+" fail!",Toast.LENGTH_SHORT).show(); 167 | e.printStackTrace(); 168 | } 169 | 170 | } 171 | 172 | @Override 173 | public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { 174 | //super.onFailure(statusCode, headers, responseString, throwable); 175 | if(saklarValueUpdateListener != null){ 176 | // Send Signal to listenner 177 | saklarValueUpdateListener.onFail(); 178 | } 179 | throwable.printStackTrace(); 180 | } 181 | 182 | @Override 183 | public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { 184 | if(saklarValueUpdateListener != null){ 185 | // Send Signal to listenner 186 | saklarValueUpdateListener.onFail(); 187 | } 188 | throwable.printStackTrace(); 189 | } 190 | }); 191 | 192 | 193 | } 194 | } 195 | 196 | // Retreive Saklar History 197 | public void getSaklarHistory(String id){ 198 | 199 | final List> historyList = new ArrayList<>(); 200 | 201 | 202 | httpClient.setTimeout(30); 203 | httpClient.cancelRequests(context,true); 204 | httpClient.cancelAllRequests(true); 205 | 206 | String api_url = saklar_channel+"field/week/feed/174/"+id; 207 | 208 | httpClient.get(context,api_url, new JsonHttpResponseHandler(){ 209 | 210 | @Override 211 | public void onSuccess(int statusCode, Header[] headers, JSONObject response) { 212 | if(statusCode == 200){ 213 | try { 214 | JSONArray dataList = response.getJSONArray("cValue"); 215 | for(int x = 0; x < dataList.length(); x++){ 216 | String data = dataList.get(x).toString(); 217 | String value = data.split(",")[0]; 218 | String date = data.split(",")[1]; 219 | 220 | Map history = new HashMap<>(); 221 | history.put("value",value); 222 | history.put("date",date); 223 | historyList.add(history); 224 | //Log.d("API",history.toString()); 225 | } 226 | 227 | if(saklarHistoryLoadedListener != null){ 228 | saklarHistoryLoadedListener.onDataLoaded(historyList); 229 | } 230 | }catch (Exception e){ 231 | e.printStackTrace(); 232 | } 233 | } 234 | } 235 | 236 | }); 237 | 238 | } 239 | 240 | // Mengambil data suhu dari server dan menampilkan sebagai chart. 241 | public void getDataSuhu(){ 242 | 243 | final List> dataSuhu = new ArrayList<>(); 244 | 245 | httpClient.setTimeout(30); 246 | String api_url = "http://agnosthings.com/c68a9cbe-15d3-11e6-8001-005056805279/channel/last/feed/275/12"; 247 | 248 | httpClient.get(context,api_url,new JsonHttpResponseHandler(){ 249 | @Override 250 | public void onSuccess(int statusCode, Header[] headers, JSONObject response) { 251 | if(statusCode == 200){ 252 | try { 253 | JSONArray dataList = response.getJSONArray("cValue"); 254 | for(int x = 0; x < dataList.length(); x++){ 255 | String data = dataList.get(x).toString(); 256 | String value = data.split(",")[1]; 257 | String date = data.split(",")[2]; 258 | 259 | Map history = new HashMap<>(); 260 | history.put("value",value); 261 | history.put("date",date); 262 | dataSuhu.add(history); 263 | //Log.d("getDataSuhu()",history.toString()); 264 | } 265 | 266 | if(suhuLoadedListener != null){ 267 | Collections.reverse(dataSuhu); 268 | suhuLoadedListener.onDataLoaded(dataSuhu); 269 | } 270 | }catch (Exception e){ 271 | e.printStackTrace(); 272 | } 273 | } 274 | } 275 | 276 | @Override 277 | public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { 278 | if(suhuLoadedListener != null){ 279 | suhuLoadedListener.onFail(); 280 | } 281 | throwable.printStackTrace(); 282 | } 283 | 284 | @Override 285 | public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { 286 | if(suhuLoadedListener != null){ 287 | suhuLoadedListener.onFail(); 288 | } 289 | throwable.printStackTrace(); 290 | } 291 | }); 292 | } 293 | 294 | public void getDataPDAM(){ 295 | final List> dataPDAM = new ArrayList<>(); 296 | 297 | httpClient.setTimeout(30); 298 | String api_url = "http://agnosthings.com/96b322c6-15d4-11e6-8001-005056805279/channel/last/feed/278/100"; 299 | 300 | httpClient.get(context,api_url,new JsonHttpResponseHandler(){ 301 | @Override 302 | public void onSuccess(int statusCode, Header[] headers, JSONObject response) { 303 | if(statusCode == 200){ 304 | try { 305 | JSONArray dataList = response.getJSONArray("cValue"); 306 | for(int x = 0; x < dataList.length(); x++){ 307 | String data = dataList.get(x).toString(); 308 | String value = data.split(",")[1]; 309 | String date = data.split(",")[2]; 310 | 311 | Map history = new HashMap<>(); 312 | history.put("value",value); 313 | history.put("date",date); 314 | dataPDAM.add(history); 315 | //Log.d("getdataPDAM()",history.toString()); 316 | } 317 | 318 | if(pdamLoadedListener != null){ 319 | Collections.reverse(dataPDAM); 320 | pdamLoadedListener.onDataLoaded(dataPDAM); 321 | } 322 | }catch (Exception e){ 323 | e.printStackTrace(); 324 | } 325 | } 326 | } 327 | 328 | @Override 329 | public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { 330 | if(pdamLoadedListener != null){ 331 | pdamLoadedListener.onFail(); 332 | } 333 | throwable.printStackTrace(); 334 | } 335 | 336 | @Override 337 | public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { 338 | if(pdamLoadedListener != null){ 339 | pdamLoadedListener.onFail(); 340 | } 341 | throwable.printStackTrace(); 342 | } 343 | }); 344 | } 345 | 346 | public void getDataListrik(){ 347 | String api_url = "http://agnosthings.com/f9de5cb8-15d3-11e6-8001-005056805279/channel/last/feed/276/1"; 348 | httpClient.get(context,api_url,new JsonHttpResponseHandler(){ 349 | @Override 350 | public void onSuccess(int statusCode, Header[] headers, JSONObject response) { 351 | //super.onSuccess(statusCode, headers, response); 352 | if(statusCode == 200){ 353 | try { 354 | String data = response 355 | .getJSONArray("cValue") 356 | .getString(0); 357 | 358 | if(listrikLoadedListener != null){ 359 | listrikLoadedListener.onDataLoaded(data); 360 | } 361 | }catch (Exception e){ 362 | e.printStackTrace(); 363 | if(listrikLoadedListener != null){ 364 | listrikLoadedListener.onFail(); 365 | } 366 | } 367 | } 368 | } 369 | 370 | @Override 371 | public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { 372 | //super.onFailure(statusCode, headers, throwable, errorResponse); 373 | if(listrikLoadedListener != null){ 374 | listrikLoadedListener.onFail(); 375 | } 376 | } 377 | 378 | @Override 379 | public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { 380 | //super.onFailure(statusCode, headers, responseString, throwable); 381 | if(listrikLoadedListener != null){ 382 | listrikLoadedListener.onFail(); 383 | } 384 | } 385 | }); 386 | } 387 | 388 | public void getDataLPG(){ 389 | String api_url = "http://agnosthings.com/82f8f396-15d4-11e6-8001-005056805279/channel/last/feed/277/1"; 390 | httpClient.get(context,api_url,new JsonHttpResponseHandler(){ 391 | @Override 392 | public void onSuccess(int statusCode, Header[] headers, JSONObject response) { 393 | //super.onSuccess(statusCode, headers, response); 394 | if(statusCode == 200){ 395 | try { 396 | String data = response 397 | .getJSONArray("cValue") 398 | .getString(0); 399 | 400 | if(lpgLoadedListener != null){ 401 | lpgLoadedListener.onDataLoaded(data); 402 | } 403 | }catch (Exception e){ 404 | e.printStackTrace(); 405 | if(lpgLoadedListener != null){ 406 | lpgLoadedListener.onFail(); 407 | } 408 | } 409 | } 410 | } 411 | 412 | @Override 413 | public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { 414 | //super.onFailure(statusCode, headers, throwable, errorResponse); 415 | if(lpgLoadedListener != null){ 416 | lpgLoadedListener.onFail(); 417 | } 418 | } 419 | 420 | @Override 421 | public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { 422 | //super.onFailure(statusCode, headers, responseString, throwable); 423 | if(lpgLoadedListener != null){ 424 | lpgLoadedListener.onFail(); 425 | } 426 | } 427 | }); 428 | } 429 | 430 | // Listener for Saklar update value 431 | public interface SaklarValueUpdateListener{ 432 | void onValueLoaded(); 433 | void onFail(); 434 | } 435 | 436 | public interface SaklarHistoryLoadedListener{ 437 | void onDataLoaded(List> data); 438 | } 439 | 440 | // Listener Suhu ruangan 441 | public interface SuhuLoadedListener{ 442 | void onDataLoaded(List> data); 443 | void onFail(); 444 | } 445 | 446 | // Listener PDAM 447 | public interface PDAMLoadedListener{ 448 | void onDataLoaded(List> data); 449 | void onFail(); 450 | } 451 | 452 | // Listener Listrik 453 | public interface ListrikLoadedListener{ 454 | void onDataLoaded(String data); 455 | void onFail(); 456 | } 457 | 458 | // Listener LPG 459 | public interface LPGLoadedListener{ 460 | void onDataLoaded(String data); 461 | void onFail(); 462 | } 463 | 464 | public void setSaklarHistoryLoadedListener(SaklarHistoryLoadedListener listener){ 465 | this.saklarHistoryLoadedListener = listener; 466 | } 467 | 468 | public void setSaklarValueUpdateListener(SaklarValueUpdateListener listener){ 469 | this.saklarValueUpdateListener = listener; 470 | } 471 | 472 | // Listener setter 473 | public void setSuhuLoadedListener(SuhuLoadedListener listener){ 474 | this.suhuLoadedListener = listener; 475 | } 476 | 477 | // Listener pdam setter 478 | public void setPDAMLoadedListener(PDAMLoadedListener listener){ 479 | this.pdamLoadedListener = listener; 480 | } 481 | 482 | // Listener listrik setter 483 | public void setListrikLoadedListener(ListrikLoadedListener listener){ 484 | this.listrikLoadedListener = listener; 485 | } 486 | 487 | // Listener listrik setter 488 | public void setLPGLoadedListener(LPGLoadedListener listener){ 489 | this.lpgLoadedListener = listener; 490 | } 491 | 492 | 493 | 494 | } 495 | -------------------------------------------------------------------------------- /app/src/main/java/com/pringstudio/agnosthings/FragmentAbout.java: -------------------------------------------------------------------------------- 1 | package com.pringstudio.agnosthings; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | /** 11 | * Created by sucipto on 4/13/16. 12 | */ 13 | public class FragmentAbout extends Fragment { 14 | // Empty Constructor 15 | public FragmentAbout(){} 16 | 17 | @Override 18 | public void onCreate(@Nullable Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | } 21 | 22 | @Nullable 23 | @Override 24 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 25 | View view = inflater.inflate(R.layout.fragment_about, container, false); 26 | return view; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/pringstudio/agnosthings/FragmentHome.java: -------------------------------------------------------------------------------- 1 | package com.pringstudio.agnosthings; 2 | 3 | import android.animation.ValueAnimator; 4 | import android.content.Context; 5 | import android.content.DialogInterface; 6 | import android.content.SharedPreferences; 7 | import android.graphics.Color; 8 | import android.os.Bundle; 9 | import android.support.annotation.Nullable; 10 | import android.support.design.widget.Snackbar; 11 | import android.support.v4.app.Fragment; 12 | import android.support.v7.app.AlertDialog; 13 | import android.text.InputType; 14 | import android.util.Log; 15 | import android.view.LayoutInflater; 16 | import android.view.Menu; 17 | import android.view.MenuInflater; 18 | import android.view.MenuItem; 19 | import android.view.View; 20 | import android.view.ViewGroup; 21 | import android.view.animation.Animation; 22 | import android.view.animation.AnimationUtils; 23 | import android.widget.EditText; 24 | import android.widget.ImageView; 25 | import android.widget.LinearLayout; 26 | import android.widget.ProgressBar; 27 | import android.widget.TextView; 28 | 29 | import com.github.mikephil.charting.charts.LineChart; 30 | import com.github.mikephil.charting.data.Entry; 31 | import com.github.mikephil.charting.data.LineData; 32 | import com.github.mikephil.charting.data.LineDataSet; 33 | import com.pringstudio.agnosthings.view.ProgressBarAnimation; 34 | 35 | 36 | import java.text.SimpleDateFormat; 37 | import java.util.ArrayList; 38 | import java.util.Date; 39 | import java.util.List; 40 | import java.util.Map; 41 | import java.util.TimeZone; 42 | 43 | /** 44 | * Created by sucipto on 4/13/16. 45 | */ 46 | public class FragmentHome extends Fragment { 47 | 48 | View mainView; 49 | LineChart chartSuhu, chartPDAM; 50 | Menu mainMenu; 51 | 52 | AgnosthingsApi api; 53 | 54 | LinearLayout pulsaListrikLayout; 55 | 56 | // Shared Prefrence 57 | SharedPreferences sharedPreferences; 58 | 59 | // Empty Constructor 60 | public FragmentHome(){ 61 | setHasOptionsMenu(true); 62 | } 63 | 64 | @Override 65 | public void onCreate(@Nullable Bundle savedInstanceState) { 66 | super.onCreate(savedInstanceState); 67 | // Shared prefrence 68 | sharedPreferences = getContext().getSharedPreferences("LISTRIK",Context.MODE_PRIVATE); 69 | 70 | // Default KWH 71 | if(sharedPreferences.getInt("KWH",0) == 0){ 72 | SharedPreferences.Editor editor = sharedPreferences.edit(); 73 | editor.putInt("KWH",200); 74 | editor.commit(); 75 | } 76 | 77 | } 78 | 79 | @Nullable 80 | @Override 81 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 82 | super.onCreateView(inflater,container,savedInstanceState); 83 | mainView = inflater.inflate(R.layout.fragment_home, container, false); 84 | 85 | 86 | // Setup api 87 | api = new AgnosthingsApi(getContext()); 88 | 89 | // Setup chart 90 | setupChart(); 91 | 92 | // Setup listener 93 | setupListener(); 94 | 95 | return mainView; 96 | } 97 | 98 | @Override 99 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 100 | super.onCreateOptionsMenu(menu, inflater); 101 | inflater.inflate(R.menu.menu_home, menu); 102 | mainMenu = menu; 103 | } 104 | 105 | @Override 106 | public boolean onOptionsItemSelected(MenuItem item) { 107 | int id = item.getItemId(); 108 | 109 | switch (id){ 110 | case R.id.menu_home_refresh: 111 | updateChart(); 112 | //startAnimateRefreshMenu(true); 113 | return true; 114 | default: 115 | return super.onOptionsItemSelected(item); 116 | } 117 | 118 | } 119 | 120 | private void setupListener(){ 121 | pulsaListrikLayout = (LinearLayout) mainView.findViewById(R.id.pulsaListrik); 122 | pulsaListrikLayout.setOnClickListener(new View.OnClickListener() { 123 | @Override 124 | public void onClick(View v) { 125 | AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); 126 | builder.setTitle("Masukan KWH Token"); 127 | 128 | // Linear layout container view 129 | LinearLayout layoutDialog = new LinearLayout(getContext()); 130 | layoutDialog.setOrientation(LinearLayout.VERTICAL); 131 | layoutDialog.setPadding(10,10,10,10); 132 | 133 | // Textview untuk deskripsi 134 | TextView textDialog = new TextView(getContext()); 135 | textDialog.setText("Masukkan nilai KWH yang anda dapatkan saat membeli token listrik"); 136 | textDialog.setPadding(6,6,6,6); 137 | layoutDialog.addView(textDialog); 138 | 139 | // EditText untuk input 140 | final EditText input = new EditText(getContext()); 141 | input.setText(String.valueOf(sharedPreferences.getInt("KWH",0))); 142 | input.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER); 143 | 144 | layoutDialog.addView(input); 145 | 146 | builder.setView(layoutDialog); 147 | 148 | builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { 149 | @Override 150 | public void onClick(DialogInterface dialog, int which) { 151 | int kwhValue = Integer.valueOf(input.getText().toString()); 152 | 153 | SharedPreferences.Editor editor = sharedPreferences.edit(); 154 | editor.putInt("KWH",kwhValue); 155 | editor.commit(); 156 | 157 | } 158 | }); 159 | 160 | builder.setNegativeButton("Batal", new DialogInterface.OnClickListener() { 161 | @Override 162 | public void onClick(DialogInterface dialog, int which) { 163 | dialog.cancel(); 164 | } 165 | }); 166 | 167 | builder.show(); 168 | } 169 | }); 170 | } 171 | 172 | 173 | private void setupChart(){ 174 | // Setup chart suhu 175 | chartSuhu = (LineChart) mainView.findViewById(R.id.home_chart_suhu); 176 | chartPDAM = (LineChart) mainView.findViewById(R.id.home_chart_pdam); 177 | chartSuhu.setDescription(""); 178 | chartPDAM.setDescription(""); 179 | 180 | 181 | 182 | updateChart(); 183 | 184 | } 185 | 186 | private void updateChart(){ 187 | 188 | 189 | api.getDataSuhu(); 190 | api.setSuhuLoadedListener(new AgnosthingsApi.SuhuLoadedListener() { 191 | @Override 192 | public void onDataLoaded(List> data) { 193 | 194 | ArrayList entrySuhu = new ArrayList<>(); 195 | ArrayList labelSuhu = new ArrayList<>(); 196 | 197 | entrySuhu.clear(); 198 | labelSuhu.clear(); 199 | 200 | // Date formater 201 | SimpleDateFormat sourceFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z"); 202 | Date parsed = new Date(); 203 | 204 | SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); 205 | dateFormat.setTimeZone(TimeZone.getDefault()); 206 | 207 | SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm"); 208 | timeFormat.setTimeZone(TimeZone.getDefault()); 209 | // end date formater 210 | 211 | int x = 0; 212 | for(Map suhu : data){ 213 | try{ 214 | parsed = sourceFormat.parse(suhu.get("date").toString()); 215 | }catch (Exception e){ 216 | Log.e("setSuhuLoadedListener","Error parsing date"); 217 | e.printStackTrace(); 218 | } 219 | entrySuhu.add(new Entry(Float.parseFloat(suhu.get("value").toString()),x)); 220 | labelSuhu.add(timeFormat.format(parsed)); 221 | x++; 222 | } 223 | 224 | LineDataSet dataSetSuhu = new LineDataSet(entrySuhu, "Derajat celcius"); 225 | dataSetSuhu.setColor(Color.parseColor("#009688")); 226 | dataSetSuhu.setCircleColor(Color.parseColor("#ffcdd2")); 227 | dataSetSuhu.setCircleColorHole(Color.parseColor("#f44336")); 228 | 229 | LineData dataSuhu = new LineData(labelSuhu, dataSetSuhu); 230 | 231 | chartSuhu.setData(dataSuhu); 232 | 233 | // Update data 234 | chartSuhu.notifyDataSetChanged(); 235 | 236 | // Animate 237 | chartSuhu.animateY(1000); 238 | } 239 | 240 | @Override 241 | public void onFail() { 242 | try{ 243 | Snackbar.make(getView(),"Refresh data gagal, coba lagi nanti", Snackbar.LENGTH_LONG).show(); 244 | }catch (Exception e){ 245 | e.printStackTrace(); 246 | } 247 | } 248 | }); 249 | 250 | // Get data PDAM 251 | 252 | api.getDataPDAM(); 253 | api.setPDAMLoadedListener(new AgnosthingsApi.PDAMLoadedListener() { 254 | @Override 255 | public void onDataLoaded(List> data) { 256 | ArrayList entryPDAM = new ArrayList<>(); 257 | ArrayList labelPDAM = new ArrayList<>(); 258 | 259 | // Date formater 260 | SimpleDateFormat sourceFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z"); 261 | Date parsed = new Date(); 262 | 263 | SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); 264 | dateFormat.setTimeZone(TimeZone.getDefault()); 265 | 266 | SimpleDateFormat timeFormat = new SimpleDateFormat("DD"); 267 | timeFormat.setTimeZone(TimeZone.getDefault()); 268 | // end date formater 269 | 270 | int x = 0; 271 | for(Map pdam : data){ 272 | try{ 273 | parsed = sourceFormat.parse(pdam.get("date").toString()); 274 | }catch (Exception e){ 275 | Log.e("setSuhuLoadedListener","Error parsing date"); 276 | e.printStackTrace(); 277 | } 278 | entryPDAM.add(new Entry(Float.parseFloat(pdam.get("value").toString()),x)); 279 | labelPDAM.add(timeFormat.format(parsed)); 280 | x++; 281 | } 282 | 283 | 284 | LineDataSet dataSetPDAM = new LineDataSet(entryPDAM, "Meter Kibik"); 285 | dataSetPDAM.setColor(Color.parseColor("#2196f3")); 286 | dataSetPDAM.setCircleColor(Color.parseColor("#ffcdd2")); 287 | dataSetPDAM.setCircleColorHole(Color.parseColor("#f44336")); 288 | 289 | LineData dataPDAM = new LineData(labelPDAM, dataSetPDAM); 290 | 291 | chartPDAM.setData(dataPDAM); 292 | chartPDAM.animateY(1000); 293 | chartPDAM.notifyDataSetChanged(); 294 | } 295 | 296 | @Override 297 | public void onFail() { 298 | try{ 299 | Snackbar.make(getView(),"Refresh data gagal, coba lagi nanti", Snackbar.LENGTH_LONG).show(); 300 | }catch (Exception e){ 301 | e.printStackTrace(); 302 | } 303 | } 304 | }); 305 | 306 | final ProgressBar progressBarListrik = (ProgressBar) mainView.findViewById(R.id.progressListrik); 307 | final ProgressBar progressBarLPG = (ProgressBar) mainView.findViewById(R.id.progressLpg); 308 | final TextView listrikUpdated = (TextView) mainView.findViewById(R.id.update_listrik_text); 309 | final TextView listrikProgress = (TextView) mainView.findViewById(R.id.progress_listrik_text); 310 | final TextView lpgUpdated = (TextView) mainView.findViewById(R.id.update_lpg_text); 311 | final TextView lpgProgress = (TextView) mainView.findViewById(R.id.progress_lpg_text); 312 | final int maxValue = sharedPreferences.getInt("KWH",100); 313 | 314 | 315 | // Reset Progressbar 316 | //progressBar.setProgress(0); 317 | ProgressBarAnimation animation = new ProgressBarAnimation(progressBarListrik,progressBarListrik.getProgress(),0); 318 | animation.setDuration(500); 319 | progressBarListrik.setAnimation(animation); 320 | 321 | startCountAnimation(listrikProgress,500,(progressBarListrik.getProgress()*100)/maxValue,0); 322 | 323 | ProgressBarAnimation animation2 = new ProgressBarAnimation(progressBarLPG,progressBarLPG.getProgress(),0); 324 | animation2.setDuration(500); 325 | progressBarLPG.setAnimation(animation2); 326 | 327 | listrikUpdated.setText("Loading..."); 328 | listrikProgress.setText("0%"); 329 | 330 | lpgUpdated.setText("Loading..."); 331 | lpgProgress.setText("0%"); 332 | 333 | api.getDataListrik(); 334 | api.setListrikLoadedListener(new AgnosthingsApi.ListrikLoadedListener() { 335 | @Override 336 | public void onDataLoaded(String data) { 337 | String kwh = data.split(",")[1]; 338 | String lastDate = data.split(",")[2]; 339 | 340 | // Date formater 341 | SimpleDateFormat sourceFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z"); 342 | Date parsed = new Date(); 343 | 344 | SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy HH:mm"); 345 | dateFormat.setTimeZone(TimeZone.getDefault()); 346 | 347 | // end date formater 348 | 349 | try { 350 | parsed = sourceFormat.parse(lastDate); 351 | }catch (Exception e){ 352 | e.printStackTrace(); 353 | } 354 | 355 | String newDate = dateFormat.format(parsed); 356 | 357 | String prosentase = String.valueOf((Integer.valueOf(kwh)*100)/maxValue); 358 | 359 | 360 | listrikUpdated.setText("Update : \n"+newDate); 361 | listrikProgress.setText(prosentase+"%"); 362 | startCountAnimation(listrikProgress,1000,0,Integer.valueOf(prosentase)); 363 | 364 | 365 | //Update Progressbar 366 | progressBarListrik.setMax(maxValue); 367 | progressBarListrik.setProgress(Integer.valueOf(kwh)); 368 | ProgressBarAnimation animation = new ProgressBarAnimation(progressBarListrik,0,Integer.valueOf(kwh)); 369 | animation.setDuration(1000); 370 | progressBarListrik.setAnimation(animation); 371 | 372 | 373 | //startAnimateRefreshMenu(false); 374 | Log.d("Listrik","Loaded , Data : "+kwh+", date: "+newDate); 375 | } 376 | 377 | @Override 378 | public void onFail() { 379 | try{ 380 | Snackbar.make(getView(),"Refresh data gagal, coba lagi nanti", Snackbar.LENGTH_LONG).show(); 381 | }catch (Exception e){ 382 | e.printStackTrace(); 383 | } 384 | } 385 | }); 386 | 387 | api.getDataLPG(); 388 | api.setLPGLoadedListener(new AgnosthingsApi.LPGLoadedListener() { 389 | @Override 390 | public void onDataLoaded(String data) { 391 | String prosentase = data.split(",")[1]; 392 | String lastDate = data.split(",")[2]; 393 | 394 | // Date formater 395 | SimpleDateFormat sourceFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z"); 396 | Date parsed = new Date(); 397 | 398 | SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy HH:mm"); 399 | dateFormat.setTimeZone(TimeZone.getDefault()); 400 | 401 | // end date formater 402 | 403 | try { 404 | parsed = sourceFormat.parse(lastDate); 405 | }catch (Exception e){ 406 | e.printStackTrace(); 407 | } 408 | 409 | String newDate = dateFormat.format(parsed); 410 | 411 | // Update text 412 | lpgUpdated.setText("Update : \n"+newDate); 413 | lpgProgress.setText(prosentase+"%"); 414 | startCountAnimation(lpgProgress,1000,0,Integer.valueOf(prosentase)); 415 | 416 | //Update Progressbar 417 | //progressBarLPG.setMax(maxValue); 418 | progressBarLPG.setProgress(Integer.valueOf(prosentase)); 419 | ProgressBarAnimation animation = new ProgressBarAnimation(progressBarLPG,0,Integer.valueOf(prosentase)); 420 | animation.setDuration(1000); 421 | progressBarLPG.setAnimation(animation); 422 | } 423 | 424 | @Override 425 | public void onFail() { 426 | try{ 427 | Snackbar.make(getView(),"Refresh data gagal, coba lagi nanti", Snackbar.LENGTH_LONG).show(); 428 | }catch (Exception e){ 429 | e.printStackTrace(); 430 | } 431 | } 432 | }); 433 | 434 | 435 | 436 | } 437 | 438 | private void startCountAnimation(TextView textProgress, int duration, int from, int to) { 439 | ValueAnimator animator = new ValueAnimator(); 440 | animator.setObjectValues(from, to); 441 | animator.setDuration(duration); 442 | final TextView textView = textProgress; 443 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 444 | public void onAnimationUpdate(ValueAnimator animation) { 445 | textView.setText("" + (int) animation.getAnimatedValue()+"%"); 446 | } 447 | }); 448 | animator.start(); 449 | } 450 | 451 | private void startAnimateRefreshMenu(boolean start){ 452 | //TODO: Gak bisa berenti muter, gak di pake dulu lah 453 | LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 454 | ImageView iv = (ImageView)inflater.inflate(R.layout.iv_refresh, null); 455 | Animation rotation = AnimationUtils.loadAnimation(getContext(), R.anim.rotate_refresh); 456 | rotation.setRepeatCount(Animation.INFINITE); 457 | iv.startAnimation(rotation); 458 | //item.setActionView(iv); 459 | if(start){ 460 | mainMenu.findItem(R.id.menu_home_refresh).setActionView(iv); 461 | }else { 462 | mainMenu.findItem(R.id.menu_home_refresh).setIcon(R.drawable.ic_cached_grey_200_36dp); 463 | } 464 | } 465 | 466 | 467 | } 468 | -------------------------------------------------------------------------------- /app/src/main/java/com/pringstudio/agnosthings/FragmentSaklar.java: -------------------------------------------------------------------------------- 1 | package com.pringstudio.agnosthings; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.util.Log; 10 | import android.view.LayoutInflater; 11 | import android.view.Menu; 12 | import android.view.MenuInflater; 13 | import android.view.MenuItem; 14 | import android.view.View; 15 | import android.view.ViewGroup; 16 | 17 | import com.pringstudio.agnosthings.model.Saklar; 18 | import com.pringstudio.agnosthings.view.DividerItemDecoration; 19 | import com.pringstudio.agnosthings.view.RecyclerItemClickListener; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | import io.realm.Realm; 25 | import io.realm.RealmConfiguration; 26 | import io.realm.RealmResults; 27 | 28 | /** 29 | * Created by sucipto on 4/14/16. 30 | */ 31 | public class FragmentSaklar extends Fragment { 32 | 33 | // Main View 34 | View mainView; 35 | 36 | // RecyclerView Saklar 37 | private RecyclerView recyclerView; 38 | 39 | // Data adapter recyclerview 40 | SaklarAdapter saklarAdapter; 41 | 42 | // Data Saklar 43 | List saklarList = new ArrayList<>(); 44 | 45 | // Realm 46 | Realm realm; 47 | 48 | // Realm saklar result 49 | RealmResults results; 50 | 51 | /** 52 | * ============================================================================================= 53 | */ 54 | 55 | // Empty Constructor 56 | public FragmentSaklar() { 57 | // Nothing 58 | setHasOptionsMenu(true); 59 | } 60 | 61 | @Override 62 | public void onCreate(@Nullable Bundle savedInstanceState) { 63 | super.onCreate(savedInstanceState); 64 | 65 | // Init Realm 66 | RealmConfiguration config = new RealmConfiguration.Builder(getContext()) 67 | .name("agnosthings.realm") 68 | .schemaVersion(1) 69 | .build(); 70 | 71 | realm = Realm.getInstance(config); 72 | 73 | } 74 | 75 | @Nullable 76 | @Override 77 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 78 | mainView = inflater.inflate(R.layout.fragment_saklar, container, false); 79 | 80 | // Init Saklar RecyclerView 81 | setupSaklarRecycler(); 82 | 83 | return mainView; 84 | } 85 | 86 | @Override 87 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 88 | super.onCreateOptionsMenu(menu, inflater); 89 | inflater.inflate(R.menu.menu_saklar, menu); 90 | 91 | } 92 | 93 | @Override 94 | public boolean onOptionsItemSelected(MenuItem item) { 95 | int id = item.getItemId(); 96 | 97 | switch (id){ 98 | case R.id.menu_refresh: 99 | getDataSaklar(); 100 | return true; 101 | default: 102 | return super.onOptionsItemSelected(item); 103 | } 104 | 105 | } 106 | 107 | private void setupSaklarRecycler() { 108 | // Init The View 109 | recyclerView = (RecyclerView) mainView.findViewById(R.id.saklar_recycler); 110 | 111 | // Set Adapter 112 | saklarAdapter = new SaklarAdapter(saklarList); 113 | recyclerView.setAdapter(saklarAdapter); 114 | 115 | // Set Layout manager 116 | recyclerView.setLayoutManager(new LinearLayoutManager(getActivity().getApplicationContext())); 117 | 118 | // Item Decorator / Divider on list 119 | recyclerView.addItemDecoration(new DividerItemDecoration(getActivity())); 120 | 121 | // Add click listenner 122 | saklarAdapter.setOnSaklarItemClickListener(new SaklarAdapter.OnSaklarItemClickListener() { 123 | @Override 124 | public void onClick(View v, int pos) { 125 | Intent saklarHistory = new Intent(getContext(),SaklarHistory.class); 126 | Saklar item = saklarList.get(pos); 127 | saklarHistory.putExtra("saklarID",item.getId()); 128 | startActivity(saklarHistory); 129 | } 130 | }); 131 | 132 | // Populate data 133 | getDataSaklar(); 134 | 135 | } 136 | 137 | /** 138 | * Get Data Saklar dari API 139 | */ 140 | 141 | private void getDataSaklar() { 142 | 143 | // Clear Item 144 | saklarList.clear(); 145 | 146 | // Api Class 147 | AgnosthingsApi agnosthingsApi = new AgnosthingsApi(getContext()); 148 | 149 | // Update subtittle 150 | setSubTitle("Updating data ..."); 151 | 152 | // Set Listenner 153 | agnosthingsApi.setSaklarValueUpdateListener(new AgnosthingsApi.SaklarValueUpdateListener() { 154 | @Override 155 | public void onValueLoaded() { 156 | results = realm.where(Saklar.class).findAll(); 157 | saklarList.clear(); 158 | saklarList.addAll(results); 159 | saklarAdapter.notifyDataSetChanged(); 160 | setSubTitle(""); 161 | } 162 | 163 | @Override 164 | public void onFail(){ 165 | setSubTitle("Update data failed"); 166 | } 167 | }); 168 | 169 | // Retrieve value from server (Update value from online server) 170 | agnosthingsApi.retreiveSaklarValue(); 171 | 172 | 173 | // Get The Data 174 | results = realm.where(Saklar.class).findAll(); 175 | 176 | if (results.size() == 0) { 177 | 178 | realm.beginTransaction(); 179 | 180 | Saklar saklar1 = realm.createObject(Saklar.class); 181 | 182 | saklar1.setId("lampu_kanan"); 183 | saklar1.setName("Lampu Teras"); 184 | saklar1.setValue(1); 185 | 186 | Saklar saklar2 = realm.createObject(Saklar.class); 187 | 188 | saklar2.setId("lampu_kiri"); 189 | saklar2.setName("Lampu Dapur"); 190 | saklar2.setValue(0); 191 | 192 | Saklar saklar3 = realm.createObject(Saklar.class); 193 | 194 | saklar3.setId("lampu_tengah"); 195 | saklar3.setName("Lampu Kamar"); 196 | saklar3.setValue(1); 197 | 198 | Saklar saklar4 = realm.createObject(Saklar.class); 199 | 200 | saklar4.setId("lampu_halaman"); 201 | saklar4.setName("Lampu Taman"); 202 | saklar4.setValue(1); 203 | 204 | Saklar saklar5 = realm.createObject(Saklar.class); 205 | 206 | saklar5.setId("lampu_jalan"); 207 | saklar5.setName("Lampu Jalan"); 208 | saklar5.setValue(1); 209 | 210 | realm.commitTransaction(); 211 | 212 | results = realm.where(Saklar.class).findAll(); 213 | 214 | } 215 | 216 | saklarList.addAll(results); 217 | 218 | // Notify the adapter 219 | saklarAdapter.notifyDataSetChanged(); 220 | } 221 | 222 | private void setTitle(String title){ 223 | try { 224 | ((MainActivity) getActivity()) 225 | .getSupportActionBar() 226 | .setTitle(title); 227 | } catch (Exception e) { 228 | e.printStackTrace(); 229 | } 230 | } 231 | 232 | private void setSubTitle(String sub){ 233 | try { 234 | ((MainActivity) getActivity()) 235 | .getSupportActionBar() 236 | .setSubtitle(sub); 237 | } catch (Exception e) { 238 | e.printStackTrace(); 239 | } 240 | } 241 | 242 | 243 | } 244 | -------------------------------------------------------------------------------- /app/src/main/java/com/pringstudio/agnosthings/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.pringstudio.agnosthings; 2 | 3 | import android.content.Intent; 4 | import android.content.SharedPreferences; 5 | import android.os.Bundle; 6 | import android.preference.PreferenceManager; 7 | import android.support.v4.app.Fragment; 8 | import android.support.v4.app.FragmentTransaction; 9 | import android.support.v4.widget.DrawerLayout; 10 | import android.support.v7.app.ActionBarDrawerToggle; 11 | import android.support.v7.app.AppCompatActivity; 12 | import android.support.v7.widget.LinearLayoutManager; 13 | import android.support.v7.widget.RecyclerView; 14 | import android.support.v7.widget.Toolbar; 15 | import android.view.View; 16 | import android.view.Menu; 17 | import android.view.MenuItem; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | 23 | public class MainActivity extends AppCompatActivity { 24 | 25 | // Keperluan Navigation Drawer 26 | // --------------------------------------------------------------------------------------------- 27 | private Toolbar toolbar; 28 | RecyclerView navRecyclerView; 29 | NavAdapter navAdapter; 30 | RecyclerView.LayoutManager navLayoutManager; 31 | DrawerLayout navDrawerLayout; 32 | ActionBarDrawerToggle navDrawerToogle; 33 | List navMenuList = new ArrayList<>(); 34 | 35 | // Fragment content index 36 | int currentFragment = 1; 37 | 38 | /** 39 | * ********************************************************************************************* 40 | * Overrided Method 41 | * Letakkan Overrided Method di bawah line ini 42 | * ********************************************************************************************* 43 | */ 44 | 45 | @Override 46 | protected void onCreate(Bundle savedInstanceState) { 47 | super.onCreate(savedInstanceState); 48 | setContentView(R.layout.activity_main); 49 | 50 | // Material Toolbar / actionbar 51 | toolbar = (Toolbar) findViewById(R.id.toolbar); 52 | setSupportActionBar(toolbar); 53 | // Show Menu on toolbar 54 | getSupportActionBar().setDisplayShowHomeEnabled(true); 55 | 56 | // Init Drawer navigation menu 57 | setupNavigationDrawer(); 58 | 59 | // Set default content for startup activity 60 | setFragmentContent(currentFragment); // 0 is Home fragment 61 | 62 | // Launch app intro 63 | showIntro(); 64 | 65 | } 66 | 67 | @Override 68 | public boolean onCreateOptionsMenu(Menu menu) { 69 | // Inflate the menu; this adds items to the action bar if it is present. 70 | //getMenuInflater().inflate(R.menu.menu_main, menu); 71 | return true; 72 | } 73 | 74 | @Override 75 | public boolean onOptionsItemSelected(MenuItem item) { 76 | // Handle action bar item clicks here. The action bar will 77 | // automatically handle clicks on the Home/Up button, so long 78 | // as you specify a parent activity in AndroidManifest.xml. 79 | int id = item.getItemId(); 80 | 81 | //noinspection SimplifiableIfStatement 82 | if (id == R.id.action_settings) { 83 | return true; 84 | } 85 | 86 | return super.onOptionsItemSelected(item); 87 | } 88 | 89 | @Override 90 | public void onStart() { 91 | super.onStart(); 92 | } 93 | 94 | @Override 95 | public void onStop() { 96 | super.onStop(); 97 | } 98 | 99 | /** 100 | * ********************************************************************************************** 101 | * Custom Method 102 | * Letakkan Custom Method di bawah line ini 103 | * ********************************************************************************************** 104 | */ 105 | 106 | /** 107 | * Setup Menu Item 108 | */ 109 | private void setupMenuItem(){ 110 | // Create Home Menu 111 | FragmentMenu home = new FragmentMenu( 112 | new FragmentHome(), 113 | "Dashboard", 114 | R.drawable.ic_dashboard_grey 115 | ); 116 | navMenuList.add(home); 117 | 118 | // Recycerlview 119 | FragmentMenu recycler = new FragmentMenu( 120 | new FragmentSaklar(), 121 | "Saklar Lampu", 122 | R.drawable.ic_cached_grey, 123 | "Semua Saklar Lampu" 124 | ); 125 | 126 | navMenuList.add(recycler); 127 | 128 | // Create About menu 129 | FragmentMenu about = new FragmentMenu( 130 | new FragmentAbout(), 131 | "About", 132 | R.drawable.ic_info_grey, 133 | "About Us" 134 | ); 135 | navMenuList.add(about); 136 | } 137 | 138 | /** 139 | * Setup Navigation Drawer 140 | **/ 141 | private void setupNavigationDrawer() { 142 | 143 | // Get Menu Item 144 | setupMenuItem(); 145 | 146 | // Extract Menu title and Icons for adapter 147 | ArrayList menuTitles = new ArrayList<>(); 148 | ArrayList menuIcons = new ArrayList<>(); 149 | for(FragmentMenu menu : navMenuList){ 150 | menuTitles.add(menu.getMenuName()); 151 | menuIcons.add(menu.getMenuIcon()); 152 | } 153 | 154 | // Get the recyclerview 155 | navRecyclerView = (RecyclerView) findViewById(R.id.nav_drawer_recycler); 156 | navRecyclerView.setHasFixedSize(true); 157 | 158 | // Navigation Recycler Adapter 159 | navAdapter = new NavAdapter( 160 | menuTitles, 161 | menuIcons, 162 | "", 163 | "", 164 | this 165 | ); 166 | 167 | // Apply the adapter to recyclerview 168 | navRecyclerView.setAdapter(navAdapter); 169 | 170 | // Navigation Layout manager 171 | navLayoutManager = new LinearLayoutManager(this); 172 | navRecyclerView.setLayoutManager(navLayoutManager); 173 | 174 | // Navigation DrawerLayout 175 | navDrawerLayout = (DrawerLayout) findViewById(R.id.nav_drawer_layout); 176 | 177 | // Drawer Toogle 178 | navDrawerToogle = new ActionBarDrawerToggle(this, navDrawerLayout, toolbar, R.string.open_drawer, R.string.close_drawer) { 179 | @Override 180 | public void onDrawerOpened(View drawerView) { 181 | super.onDrawerOpened(drawerView); 182 | // Ketika drawer dibuka 183 | } 184 | 185 | @Override 186 | public void onDrawerClosed(View drawerView) { 187 | super.onDrawerClosed(drawerView); 188 | // Ketika drawer ditutup 189 | } 190 | }; 191 | 192 | // Menu item click Listener 193 | navAdapter.setOnItemClickListener(new NavAdapter.NavItemClickListener() { 194 | @Override 195 | public void onItemClick(int position, View view) { 196 | 197 | // Tutup drawer jika yang di klik bukan menu 198 | if(position != 0){ 199 | // Set Fragment content 200 | setFragmentContent(position); 201 | // Notify selected menu changed 202 | navAdapter.notifyDataSetChanged(); 203 | // Close when menu item clicked 204 | navDrawerLayout.closeDrawers(); 205 | } 206 | 207 | } 208 | }); 209 | 210 | // Set Drawer Listenner 211 | navDrawerLayout.addDrawerListener(navDrawerToogle); 212 | 213 | // SyncState drawer with Home menu on actionbar 214 | navDrawerToogle.syncState(); 215 | 216 | } 217 | 218 | /** 219 | * Fragment View Manager 220 | * Untuk melakukan update view di halaman depan tanpa membuat activity baru 221 | * dengan menggunakan fragment. 222 | * @param: view this is the index number of view 223 | * @param: title Android toolbar Title (default is app name) 224 | * @param: subtitle Android toolbar subtitle (default null) 225 | **/ 226 | private void setFragmentContent(int position){ 227 | 228 | // Get Fragment Transaction 229 | FragmentTransaction transaction = getSupportFragmentManager() 230 | .beginTransaction(); 231 | 232 | FragmentMenu menuItem = navMenuList.get(position-1); 233 | 234 | // Create fragment object 235 | Fragment fragment = menuItem.getFragment(); 236 | String title = menuItem.getTitle(); 237 | String subtitle = menuItem.getSubtitle(); 238 | 239 | // Update index 240 | currentFragment = position; 241 | 242 | 243 | 244 | // Apply Fragment to Main Frame 245 | if(fragment != null){ 246 | transaction.replace(R.id.frame_main, fragment); 247 | transaction.addToBackStack(null); 248 | transaction.commit(); 249 | } 250 | 251 | // Change the Toolbar title 252 | try { 253 | if(title != null){ 254 | getSupportActionBar() 255 | .setTitle(title); 256 | }else{ 257 | getSupportActionBar() 258 | .setTitle(getText(R.string.app_name).toString()); 259 | } 260 | 261 | // Change Toolbar subtitle 262 | if(subtitle != null){ 263 | getSupportActionBar() 264 | .setSubtitle(subtitle); 265 | }else { 266 | getSupportActionBar().setSubtitle(""); 267 | } 268 | } catch (Exception e) { 269 | e.printStackTrace(); 270 | } 271 | } 272 | 273 | // Show intro for first usage 274 | private void showIntro(){ 275 | // Declare a new thread to do a preference check 276 | Thread t = new Thread(new Runnable() { 277 | @Override 278 | public void run() { 279 | // Initialize SharedPreferences 280 | SharedPreferences getPrefs = PreferenceManager 281 | .getDefaultSharedPreferences(getBaseContext()); 282 | 283 | // Create a new boolean and preference and set it to true 284 | boolean isFirstStart = getPrefs.getBoolean("firstStart", true); 285 | 286 | // If the activity has never started before... 287 | if (isFirstStart) { 288 | 289 | // Launch app intro 290 | Intent i = new Intent(MainActivity.this, PringIntro.class); 291 | startActivity(i); 292 | 293 | // Make a new preferences editor 294 | SharedPreferences.Editor e = getPrefs.edit(); 295 | 296 | // Edit preference to make it false because we don't want this to run again 297 | e.putBoolean("firstStart", false); 298 | 299 | // Apply changes 300 | e.apply(); 301 | } 302 | } 303 | }); 304 | 305 | // Start the thread 306 | t.start(); 307 | } 308 | 309 | /** 310 | * Inner Class Menu Fragment Object 311 | * Digunakan untuk membuat menu item di Drawer menu 312 | */ 313 | class FragmentMenu{ 314 | 315 | String menuName, title, subtitle; 316 | int menuIcon; 317 | Fragment fragment; 318 | 319 | // Empty Constructor 320 | public FragmentMenu(){ 321 | // 322 | } 323 | 324 | // Full Constructor 325 | public FragmentMenu(Fragment fragment, String menuName, int icon, String title, String subtitle){ 326 | this.fragment = fragment; 327 | this.menuName = menuName; 328 | this.title = title; 329 | this.menuIcon = icon; 330 | this.subtitle = subtitle; 331 | } 332 | 333 | // Without Subtitle 334 | public FragmentMenu(Fragment fragment, String menuName, int icon, String title){ 335 | this.fragment = fragment; 336 | this.title = title; 337 | this.menuIcon = icon; 338 | this.menuName = menuName; 339 | } 340 | 341 | // Without Title & Subtitle 342 | public FragmentMenu(Fragment fragment, String menuName, int icon){ 343 | this.fragment = fragment; 344 | this.menuIcon = icon; 345 | this.menuName = menuName; 346 | } 347 | 348 | public String getTitle() { 349 | return title; 350 | } 351 | 352 | public void setTitle(String title) { 353 | this.title = title; 354 | } 355 | 356 | public String getSubtitle() { 357 | return subtitle; 358 | } 359 | 360 | public void setSubtitle(String subtitle) { 361 | this.subtitle = subtitle; 362 | } 363 | 364 | public int getMenuIcon() { 365 | return menuIcon; 366 | } 367 | 368 | public void setMenuIcon(int menuIcon) { 369 | this.menuIcon = menuIcon; 370 | } 371 | 372 | public Fragment getFragment() { 373 | return fragment; 374 | } 375 | 376 | public void setFragment(Fragment fragment) { 377 | this.fragment = fragment; 378 | } 379 | 380 | public String getMenuName() { 381 | return menuName; 382 | } 383 | 384 | public void setMenuName(String menuName) { 385 | this.menuName = menuName; 386 | } 387 | } 388 | 389 | } 390 | -------------------------------------------------------------------------------- /app/src/main/java/com/pringstudio/agnosthings/NavAdapter.java: -------------------------------------------------------------------------------- 1 | package com.pringstudio.agnosthings; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Color; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.ImageView; 11 | import android.widget.TextView; 12 | 13 | import java.util.ArrayList; 14 | 15 | /** 16 | * Created by Sucipto on 1/24/16. 17 | * Copyright (c) Chip Labs 2016 18 | */ 19 | public class NavAdapter extends RecyclerView.Adapter { 20 | private static final int TYPE_ITEM = 1; 21 | private static final int TYPE_HEADER = 0; 22 | 23 | private ArrayList navTitles; 24 | private ArrayList navIcons; 25 | private String navTitle; 26 | private String navDesc; 27 | private Context main_context; 28 | private static NavItemClickListener clickListener; 29 | 30 | // Selected 31 | private static int selectedPos = 1; // 0 adalah header 32 | 33 | public static class NavHolder extends RecyclerView.ViewHolder { 34 | int HolderId; 35 | 36 | TextView textView; 37 | ImageView imageView; 38 | TextView title; 39 | TextView description; 40 | Context context; 41 | 42 | public NavHolder(View view, int ViewType, Context c){ 43 | super(view); 44 | 45 | context = c; 46 | 47 | if(ViewType == TYPE_ITEM){ 48 | textView = (TextView) view.findViewById(R.id.nav_drawer_menu_text); 49 | imageView = (ImageView) view.findViewById(R.id.nav_drawer_menu_icon); 50 | HolderId = 1; 51 | }else{ 52 | title = (TextView) view.findViewById(R.id.nav_drawer_header_title); 53 | description = (TextView) view.findViewById(R.id.nav_drawer_header_subtittle); 54 | HolderId = 0; 55 | } 56 | 57 | // Set Listener 58 | view.setOnClickListener(new View.OnClickListener() { 59 | @Override 60 | public void onClick(View v) { 61 | int position = getAdapterPosition(); 62 | clickListener.onItemClick(position, v); 63 | // Update selected position 64 | selectedPos = position; 65 | } 66 | }); 67 | 68 | //Set item Clickable 69 | // http://stackoverflow.com/a/28454385/3086112 70 | view.setClickable(true); 71 | } 72 | 73 | } 74 | 75 | NavAdapter(ArrayList Titles, ArrayList Icons, String title, String description, Context cont){ 76 | this.navTitles = Titles; 77 | this.navIcons = Icons; 78 | this.navTitle = title; 79 | this.navDesc = description; 80 | this.main_context = cont; 81 | 82 | } 83 | 84 | @Override 85 | public NavHolder onCreateViewHolder(ViewGroup parent, int viewType) { 86 | if(viewType == TYPE_ITEM){ 87 | View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.nav_drawer_item_row,parent,false); 88 | NavHolder navHolder = new NavHolder(v,viewType, main_context); 89 | return navHolder; 90 | }else if(viewType == TYPE_HEADER){ 91 | View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.nav_drawer_header,parent,false); 92 | NavHolder navHolder = new NavHolder(v,viewType, main_context); 93 | return navHolder; 94 | }else { 95 | return null; 96 | } 97 | } 98 | 99 | @Override 100 | public int getItemCount() { 101 | return navTitles.size()+1; 102 | } 103 | 104 | @Override 105 | public void onBindViewHolder(NavHolder holder, final int position) { 106 | if(holder.HolderId == 1){ 107 | // Menu item 108 | holder.textView.setText(navTitles.get(position-1)); 109 | holder.imageView.setImageResource(navIcons.get(position-1)); 110 | // Set selected item 111 | if(selectedPos == position){ 112 | // Membuat selectable effect di menu item 113 | holder.itemView.setBackgroundColor(Color.parseColor("#E0E0E0")); 114 | }else{ 115 | // Mengembalikan selectableItemBackground 116 | // http://stackoverflow.com/a/31292299/3086112 117 | int[] attrs = new int[]{R.attr.selectableItemBackground}; 118 | TypedArray typedArray = main_context.obtainStyledAttributes(attrs); 119 | int backgroundResource = typedArray.getResourceId(0,0); 120 | holder.itemView.setBackgroundResource(backgroundResource); 121 | typedArray.recycle(); 122 | } 123 | }else{ 124 | // Header 125 | holder.title.setText(navTitle); 126 | holder.description.setText(navDesc); 127 | } 128 | } 129 | 130 | @Override 131 | public int getItemViewType(int position) { 132 | if(isPositionHeader(position)){ 133 | return TYPE_HEADER; 134 | }else{ 135 | return TYPE_ITEM; 136 | } 137 | } 138 | 139 | private boolean isPositionHeader(int position){ 140 | return position == 0; 141 | } 142 | 143 | public interface NavItemClickListener{ 144 | public void onItemClick(int position, View view); 145 | } 146 | 147 | public void setOnItemClickListener(NavItemClickListener myClickListener){ 148 | clickListener = myClickListener; 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /app/src/main/java/com/pringstudio/agnosthings/PringIntro.java: -------------------------------------------------------------------------------- 1 | package com.pringstudio.agnosthings; 2 | 3 | import android.graphics.Color; 4 | import android.os.Bundle; 5 | 6 | import com.github.paolorotolo.appintro.AppIntro2; 7 | import com.github.paolorotolo.appintro.AppIntroFragment; 8 | 9 | /** 10 | * Created by sucipto on 5/10/16. 11 | */ 12 | public class PringIntro extends AppIntro2 { 13 | // Please DO NOT override onCreate. Use init. 14 | 15 | @Override 16 | public void init(Bundle savedInstanceState) { 17 | 18 | 19 | addSlide(AppIntroFragment.newInstance( 20 | "Teknologi Cloud", 21 | "Akses dan monitor rumah anda dimana saja, kapan saja dengan teknologi cloud", 22 | R.drawable.splash_access, 23 | Color.parseColor("#8bc34a")) 24 | ); 25 | 26 | addSlide(AppIntroFragment.newInstance( 27 | "Monitor Suhu", 28 | "Monitoring data suhu ruangan rumah anda", 29 | R.drawable.splash_suhu, 30 | Color.parseColor("#7e57c2")) 31 | ); 32 | 33 | addSlide(AppIntroFragment.newInstance( 34 | "Monitoring PDAM", 35 | "Memonitor pemakaian Air PDAM anda", 36 | R.drawable.splash_air, 37 | Color.parseColor("#ff9800")) 38 | ); 39 | 40 | addSlide(AppIntroFragment.newInstance( 41 | "Saklar Jarak jauh", 42 | "Kini anda tidak takut lupa mematikan lampu, karena dapat anda kontrol dari SmartPhone anda", 43 | R.drawable.splash_lampu, 44 | Color.parseColor("#ff5722")) 45 | ); 46 | 47 | addSlide(AppIntroFragment.newInstance( 48 | "Monitor Konsumsi Listrik", 49 | "Memonitor pemakaian pulsa listrik anda", 50 | R.drawable.splash_listrik, 51 | Color.parseColor("#03a9f4")) 52 | ); 53 | 54 | addSlide(AppIntroFragment.newInstance( 55 | "Tak perlu khawatir lagi pakai LPG", 56 | "Memonitor pemakaian gas LPG yang ada di dapur anda", 57 | R.drawable.splash_lpg, 58 | Color.parseColor("#7e57c2")) 59 | ); 60 | /* 61 | addSlide(AppIntroFragment.newInstance( 62 | "Notifikasi Pintar", 63 | "Pemberitahuan yang membuat anda selalu waspada", 64 | R.drawable.splash_notif, 65 | Color.parseColor("#7e57c2")) 66 | ); 67 | 68 | */ 69 | setProgressButtonEnabled(true); 70 | 71 | 72 | setDepthAnimation(); 73 | } 74 | 75 | 76 | 77 | @Override 78 | public void onDonePressed() { 79 | // Do something when users tap on Done button. 80 | this.finish(); 81 | } 82 | 83 | @Override 84 | public void onSlideChanged() { 85 | // Do something when the slide changes. 86 | } 87 | 88 | @Override 89 | public void onNextPressed() { 90 | // Do something when users tap on Next button. 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /app/src/main/java/com/pringstudio/agnosthings/SaklarAdapter.java: -------------------------------------------------------------------------------- 1 | package com.pringstudio.agnosthings; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.support.v7.widget.SwitchCompat; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.CompoundButton; 10 | import android.widget.ImageView; 11 | import android.widget.TextView; 12 | 13 | import com.pringstudio.agnosthings.model.Saklar; 14 | 15 | import java.util.List; 16 | 17 | import io.realm.Realm; 18 | import io.realm.RealmConfiguration; 19 | 20 | /** 21 | * Created by sucipto on 4/25/16. 22 | */ 23 | public class SaklarAdapter extends RecyclerView.Adapter { 24 | 25 | private List saklarList; 26 | 27 | // Realm 28 | Realm realm; 29 | 30 | // Context 31 | Context context; 32 | 33 | // Listener 34 | OnSaklarItemClickListener saklarItemClickListener; 35 | 36 | public class SaklarHolder extends RecyclerView.ViewHolder { 37 | public TextView saklarName; 38 | public SwitchCompat saklarSwitch; 39 | public ImageView saklarIcon; 40 | 41 | public SaklarHolder(View view) { 42 | super(view); 43 | 44 | saklarName = (TextView) view.findViewById(R.id.saklar_text); 45 | saklarSwitch = (SwitchCompat) view.findViewById(R.id.saklar_switch); 46 | saklarIcon = (ImageView) view.findViewById(R.id.saklar_icon); 47 | 48 | // Click Listener 49 | view.setClickable(true); 50 | view.setOnClickListener(new View.OnClickListener() { 51 | @Override 52 | public void onClick(View v) { 53 | int position = getAdapterPosition(); 54 | if (saklarItemClickListener != null) { 55 | saklarItemClickListener.onClick(v, position); 56 | } 57 | } 58 | }); 59 | } 60 | } 61 | 62 | public SaklarAdapter(List saklarList) { 63 | this.saklarList = saklarList; 64 | 65 | 66 | } 67 | 68 | @Override 69 | public SaklarHolder onCreateViewHolder(ViewGroup parent, int viewType) { 70 | 71 | context = parent.getContext(); 72 | 73 | View itemView = LayoutInflater.from(context) 74 | .inflate(R.layout.item_recycler_saklar, parent, false); 75 | 76 | // Init Realm 77 | RealmConfiguration config = new RealmConfiguration.Builder(context) 78 | .name("agnosthings.realm") 79 | .schemaVersion(1) 80 | .build(); 81 | 82 | realm = Realm.getInstance(config); 83 | 84 | return new SaklarHolder(itemView); 85 | } 86 | 87 | @Override 88 | public void onBindViewHolder(final SaklarHolder holder, final int position) { 89 | 90 | final Saklar saklar = saklarList.get(position); 91 | 92 | // Saklar Switch Listenner 93 | CompoundButton.OnCheckedChangeListener toggleListener = new CompoundButton.OnCheckedChangeListener() { 94 | @Override 95 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 96 | 97 | AgnosthingsApi api = new AgnosthingsApi(context); 98 | 99 | realm.beginTransaction(); 100 | if (isChecked) { 101 | saklar.setValue(1); 102 | holder.saklarIcon.setImageResource(R.drawable.ic_lightbulb_outline_green); 103 | } else { 104 | saklar.setValue(0); 105 | holder.saklarIcon.setImageResource(R.drawable.ic_lightbulb_outline_grey); 106 | } 107 | realm.commitTransaction(); 108 | 109 | // Push updated data saklar 110 | api.pushDataSaklar(); 111 | } 112 | }; 113 | 114 | holder.saklarName.setText(saklar.getName()); 115 | 116 | // Disable Listener sementara 117 | holder.saklarSwitch.setOnCheckedChangeListener(null); 118 | 119 | // Set Saklar dari Object / Database 120 | if (saklar.getValue() == 1) { 121 | holder.saklarIcon.setImageResource(R.drawable.ic_lightbulb_outline_green); 122 | holder.saklarSwitch.setChecked(true); 123 | } else if (saklar.getValue() == 0) { 124 | holder.saklarIcon.setImageResource(R.drawable.ic_lightbulb_outline_grey); 125 | holder.saklarSwitch.setChecked(false); 126 | } 127 | 128 | holder.saklarSwitch.setOnCheckedChangeListener(toggleListener); 129 | 130 | } 131 | 132 | @Override 133 | public int getItemCount() { 134 | return saklarList.size(); 135 | } 136 | 137 | // Listener interface 138 | public interface OnSaklarItemClickListener { 139 | public void onClick(View v, int pos); 140 | } 141 | 142 | // Listenner setter 143 | public void setOnSaklarItemClickListener(OnSaklarItemClickListener listener) { 144 | this.saklarItemClickListener = listener; 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /app/src/main/java/com/pringstudio/agnosthings/SaklarHistory.java: -------------------------------------------------------------------------------- 1 | package com.pringstudio.agnosthings; 2 | 3 | import android.os.Bundle; 4 | import android.support.design.widget.FloatingActionButton; 5 | import android.support.design.widget.Snackbar; 6 | import android.support.v4.app.NavUtils; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.support.v7.widget.Toolbar; 11 | import android.util.Log; 12 | import android.view.MenuItem; 13 | import android.view.View; 14 | import android.widget.TextView; 15 | 16 | import com.pringstudio.agnosthings.view.DividerItemDecoration; 17 | 18 | import org.w3c.dom.Text; 19 | 20 | import java.util.ArrayList; 21 | import java.util.HashMap; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | public class SaklarHistory extends AppCompatActivity { 26 | 27 | private RecyclerView recyclerView; 28 | private SaklarHistoryAdapter saklarHistoryAdapter; 29 | private TextView textHistory; 30 | 31 | private List> historyData = new ArrayList<>(); 32 | 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | setContentView(R.layout.activity_saklar_history); 37 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 38 | setSupportActionBar(toolbar); 39 | 40 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 41 | fab.setOnClickListener(new View.OnClickListener() { 42 | @Override 43 | public void onClick(View view) { 44 | getHistoryData(); 45 | } 46 | }); 47 | 48 | getSupportActionBar().setHomeButtonEnabled(true); 49 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 50 | 51 | // Setup View 52 | setupLayout(); 53 | 54 | // Title 55 | getSupportActionBar().setTitle("History Saklar"); 56 | getSupportActionBar().setSubtitle("Data terakhri 2016/05/04 20:09:05"); 57 | 58 | } 59 | 60 | @Override 61 | public boolean onOptionsItemSelected(MenuItem item) { 62 | switch (item.getItemId()){ 63 | case android.R.id.home: 64 | // Untuk Kembali ke halaman berikutnya daripada kembali ke MainActivity 65 | // http://stackoverflow.com/a/33252156/3086112 66 | this.finish(); 67 | return true; 68 | default: 69 | return super.onOptionsItemSelected(item); 70 | } 71 | 72 | } 73 | 74 | private void setupLayout(){ 75 | // Setup recyclerview 76 | // ------------------ 77 | 78 | // Get the view 79 | recyclerView = (RecyclerView) findViewById(R.id.recycler_saklar_history); 80 | recyclerView.setLayoutManager(new LinearLayoutManager(this)); 81 | recyclerView.addItemDecoration(new DividerItemDecoration(this)); 82 | // Get adapter 83 | saklarHistoryAdapter = new SaklarHistoryAdapter(historyData); 84 | recyclerView.setAdapter(saklarHistoryAdapter); 85 | 86 | // SaklarHistory 87 | textHistory = (TextView) findViewById(R.id.history_text); 88 | 89 | getHistoryData(); 90 | } 91 | 92 | private void getHistoryData(){ 93 | textHistory.setText("Loading..."); 94 | textHistory.setVisibility(View.VISIBLE); 95 | recyclerView.setVisibility(View.GONE); 96 | 97 | AgnosthingsApi api = new AgnosthingsApi(this); 98 | 99 | api.getSaklarHistory(getIntent().getStringExtra("saklarID")); 100 | 101 | api.setSaklarHistoryLoadedListener(new AgnosthingsApi.SaklarHistoryLoadedListener() { 102 | @Override 103 | public void onDataLoaded(List> data) { 104 | if(data.size() == 0){ 105 | textHistory.setText("No data"); 106 | }else{ 107 | textHistory.setVisibility(View.GONE); 108 | recyclerView.setVisibility(View.VISIBLE); 109 | historyData.clear(); 110 | historyData.addAll(data); 111 | saklarHistoryAdapter.notifyDataSetChanged(); 112 | } 113 | 114 | Log.d("ListenerDarta","Data Loaded Data : "+data.toString()); 115 | Log.d("ListenerDarta","Data Loaded HistoryList : "+historyData.toString()); 116 | } 117 | }); 118 | 119 | Log.d("History","Data loaded : "+historyData.toString()); 120 | 121 | // Update ui 122 | saklarHistoryAdapter.notifyDataSetChanged(); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /app/src/main/java/com/pringstudio/agnosthings/SaklarHistoryAdapter.java: -------------------------------------------------------------------------------- 1 | package com.pringstudio.agnosthings; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.support.v7.widget.SwitchCompat; 6 | import android.util.Log; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.CompoundButton; 11 | import android.widget.ImageView; 12 | import android.widget.TextView; 13 | 14 | import com.pringstudio.agnosthings.model.Saklar; 15 | 16 | import org.w3c.dom.Text; 17 | 18 | import java.text.SimpleDateFormat; 19 | import java.util.ArrayList; 20 | import java.util.Date; 21 | import java.util.HashMap; 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.TimeZone; 25 | 26 | import io.realm.Realm; 27 | import io.realm.RealmConfiguration; 28 | 29 | /** 30 | * Created by sucipto on 5/3/16. 31 | */ 32 | public class SaklarHistoryAdapter extends RecyclerView.Adapter { 33 | 34 | private List> historyData; 35 | 36 | // Realm 37 | private Realm realm; 38 | 39 | // Context 40 | private Context context; 41 | 42 | // Listener 43 | private OnSaklarItemClickListener saklarItemClickListener; 44 | 45 | public class SaklarHistoryHolder extends RecyclerView.ViewHolder { 46 | public TextView historyDate; 47 | public TextView historyClock; 48 | public ImageView historyImage; 49 | 50 | public SaklarHistoryHolder(View view) { 51 | super(view); 52 | 53 | historyDate = (TextView) view.findViewById(R.id.history_date); 54 | historyClock = (TextView) view.findViewById(R.id.history_clock); 55 | historyImage = (ImageView) view.findViewById(R.id.history_image); 56 | 57 | } 58 | 59 | 60 | } 61 | 62 | public SaklarHistoryAdapter(List> data) { 63 | this.historyData = data; 64 | } 65 | 66 | @Override 67 | public SaklarHistoryHolder onCreateViewHolder(ViewGroup parent, int viewType) { 68 | 69 | context = parent.getContext(); 70 | 71 | View itemView = LayoutInflater.from(context) 72 | .inflate(R.layout.item_recycler_history, parent, false); 73 | 74 | 75 | return new SaklarHistoryHolder(itemView); 76 | } 77 | 78 | @Override 79 | public void onBindViewHolder(final SaklarHistoryHolder holder, final int position) { 80 | 81 | Map history = historyData.get(position); 82 | Log.d("Adapter","Data : "+history.toString()); 83 | 84 | SimpleDateFormat sourceFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z"); 85 | Date parsed = new Date(); 86 | 87 | SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy"); 88 | dateFormat.setTimeZone(TimeZone.getDefault()); 89 | 90 | SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss"); 91 | timeFormat.setTimeZone(TimeZone.getDefault()); 92 | 93 | 94 | 95 | try{ 96 | parsed = sourceFormat.parse(history.get("date")); 97 | }catch (Exception e){ 98 | Log.e("HistoryAdapter","Error parsing date"); 99 | e.printStackTrace(); 100 | } 101 | 102 | String tanggal = dateFormat.format(parsed); 103 | String jam = timeFormat.format(parsed); 104 | Log.d("HistoryAdapter",tanggal); 105 | 106 | holder.historyDate.setText(tanggal); 107 | holder.historyClock.setText(jam); 108 | if(history.get("value") == "1" | Integer.valueOf(history.get("value")) == 1){ 109 | holder.historyImage.setImageResource(R.drawable.ic_lightbulb_outline_green); 110 | }else{ 111 | holder.historyImage.setImageResource(R.drawable.ic_lightbulb_outline_grey); 112 | } 113 | 114 | } 115 | 116 | @Override 117 | public int getItemCount() { 118 | return historyData.size(); 119 | } 120 | 121 | // Listener interface 122 | public interface OnSaklarItemClickListener { 123 | public void onClick(View v, int pos); 124 | } 125 | 126 | // Listenner setter 127 | public void setOnSaklarItemClickListener(OnSaklarItemClickListener listener) { 128 | this.saklarItemClickListener = listener; 129 | } 130 | 131 | } 132 | -------------------------------------------------------------------------------- /app/src/main/java/com/pringstudio/agnosthings/model/Saklar.java: -------------------------------------------------------------------------------- 1 | package com.pringstudio.agnosthings.model; 2 | 3 | import io.realm.RealmObject; 4 | 5 | /** 6 | * Created by sucipto on 4/25/16. 7 | */ 8 | public class Saklar extends RealmObject { 9 | private String id; 10 | private String name; 11 | private int value; 12 | 13 | public Saklar(){ 14 | // Empty Constructor 15 | } 16 | 17 | public Saklar(String name) { 18 | this.name = name; 19 | } 20 | 21 | public String getId() { 22 | return id; 23 | } 24 | 25 | public void setId(String id) { 26 | this.id = id; 27 | } 28 | 29 | public int getValue() { 30 | return value; 31 | } 32 | 33 | public void setValue(int value) { 34 | this.value = value; 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/com/pringstudio/agnosthings/view/DividerItemDecoration.java: -------------------------------------------------------------------------------- 1 | package com.pringstudio.agnosthings.view; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.drawable.Drawable; 7 | import android.support.v4.content.ContextCompat; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.view.View; 10 | 11 | /** 12 | * Created by sucipto on 3/7/16. 13 | */ 14 | public class DividerItemDecoration extends RecyclerView.ItemDecoration { 15 | 16 | private static final int[] ATTRS = new int[]{android.R.attr.listDivider}; 17 | 18 | private Drawable mDivider; 19 | 20 | /** 21 | * Default divider will be used 22 | */ 23 | public DividerItemDecoration(Context context) { 24 | final TypedArray styledAttributes = context.obtainStyledAttributes(ATTRS); 25 | mDivider = styledAttributes.getDrawable(0); 26 | styledAttributes.recycle(); 27 | } 28 | 29 | /** 30 | * Custom divider will be used 31 | */ 32 | public DividerItemDecoration(Context context, int resId) { 33 | mDivider = ContextCompat.getDrawable(context, resId); 34 | } 35 | 36 | @Override 37 | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { 38 | int left = parent.getPaddingLeft(); 39 | int right = parent.getWidth() - parent.getPaddingRight(); 40 | 41 | int childCount = parent.getChildCount(); 42 | for (int i = 0; i < childCount; i++) { 43 | View child = parent.getChildAt(i); 44 | 45 | RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); 46 | 47 | int top = child.getBottom() + params.bottomMargin; 48 | int bottom = top + mDivider.getIntrinsicHeight(); 49 | 50 | mDivider.setBounds(left, top, right, bottom); 51 | mDivider.draw(c); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/pringstudio/agnosthings/view/ProgressBarAnimation.java: -------------------------------------------------------------------------------- 1 | package com.pringstudio.agnosthings.view; 2 | 3 | import android.view.animation.Animation; 4 | import android.view.animation.Transformation; 5 | import android.widget.ProgressBar; 6 | 7 | /** 8 | * Created by sucipto on 5/10/16. 9 | */ 10 | public class ProgressBarAnimation extends Animation { 11 | private ProgressBar progressBar; 12 | private float from; 13 | private float to; 14 | 15 | public ProgressBarAnimation(ProgressBar progressBar, float from, float to) { 16 | super(); 17 | this.progressBar = progressBar; 18 | this.from = from; 19 | this.to = to; 20 | } 21 | 22 | @Override 23 | protected void applyTransformation(float interpolatedTime, Transformation t) { 24 | super.applyTransformation(interpolatedTime, t); 25 | float value = from + (to - from) * interpolatedTime; 26 | progressBar.setProgress((int) value); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /app/src/main/java/com/pringstudio/agnosthings/view/RecyclerItemClickListener.java: -------------------------------------------------------------------------------- 1 | package com.pringstudio.agnosthings.view; 2 | 3 | /** 4 | * Created by sucipto on 5/2/16. 5 | * Based on : http://stackoverflow.com/a/26826692 6 | */ 7 | import android.content.Context; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.view.GestureDetector; 10 | import android.view.MotionEvent; 11 | import android.view.View; 12 | 13 | public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener { 14 | public interface OnItemClickListener { 15 | void onItemClick(View view, int position); 16 | 17 | void onItemLongClick(View view, int position); 18 | } 19 | 20 | private OnItemClickListener mListener; 21 | 22 | private GestureDetector mGestureDetector; 23 | 24 | public RecyclerItemClickListener(Context context, final RecyclerView recyclerView, OnItemClickListener listener) { 25 | mListener = listener; 26 | 27 | mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { 28 | @Override 29 | public boolean onSingleTapUp(MotionEvent e) { 30 | return true; 31 | } 32 | 33 | @Override 34 | public void onLongPress(MotionEvent e) { 35 | View childView = recyclerView.findChildViewUnder(e.getX(), e.getY()); 36 | 37 | if (childView != null && mListener != null) { 38 | mListener.onItemLongClick(childView, recyclerView.getChildAdapterPosition(childView)); 39 | } 40 | } 41 | }); 42 | } 43 | 44 | @Override 45 | public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) { 46 | View childView = view.findChildViewUnder(e.getX(), e.getY()); 47 | 48 | if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) { 49 | mListener.onItemClick(childView, view.getChildAdapterPosition(childView)); 50 | } 51 | 52 | return false; 53 | } 54 | 55 | @Override 56 | public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) { 57 | } 58 | 59 | @Override 60 | public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { 61 | } 62 | } -------------------------------------------------------------------------------- /app/src/main/res/anim/rotate_refresh.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/circle_shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/circular_progress_bar.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suciptoid/AndroidSmartHome/3a16a8f56bbe0a449c4bf97c304cca7c5bec33c4/app/src/main/res/drawable/header.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_account_circle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_cached_grey.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_cached_grey_200.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_cached_grey_200_24dp.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_cached_grey_200_36dp.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_dashboard_grey.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_info_grey.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_lightbulb_outline_green.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_lightbulb_outline_grey.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_mail_grey.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_question.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_refresh_grey_100.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_refresh_grey_300.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/splash_access.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suciptoid/AndroidSmartHome/3a16a8f56bbe0a449c4bf97c304cca7c5bec33c4/app/src/main/res/drawable/splash_access.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/splash_air.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suciptoid/AndroidSmartHome/3a16a8f56bbe0a449c4bf97c304cca7c5bec33c4/app/src/main/res/drawable/splash_air.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/splash_lampu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suciptoid/AndroidSmartHome/3a16a8f56bbe0a449c4bf97c304cca7c5bec33c4/app/src/main/res/drawable/splash_lampu.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/splash_listrik.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suciptoid/AndroidSmartHome/3a16a8f56bbe0a449c4bf97c304cca7c5bec33c4/app/src/main/res/drawable/splash_listrik.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/splash_lpg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suciptoid/AndroidSmartHome/3a16a8f56bbe0a449c4bf97c304cca7c5bec33c4/app/src/main/res/drawable/splash_lpg.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/splash_notif.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suciptoid/AndroidSmartHome/3a16a8f56bbe0a449c4bf97c304cca7c5bec33c4/app/src/main/res/drawable/splash_notif.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/splash_suhu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suciptoid/AndroidSmartHome/3a16a8f56bbe0a449c4bf97c304cca7c5bec33c4/app/src/main/res/drawable/splash_suhu.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 19 | 20 | 24 | 25 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 46 | 47 | 48 | 49 | 50 | 51 | 54 | 61 | 62 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_saklar_history.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 17 | 18 | 25 | 26 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_saklar_history.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 20 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_about.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 15 | 21 | 27 | 34 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 13 | 14 | 15 | 21 | 22 | 27 | 28 | 36 | 37 | 41 | 42 | 43 | 44 | 45 | 50 | 51 | 55 | 56 | 57 | 62 | 63 | 72 | 73 | 76 | 77 | 86 | 87 | 98 | 99 | 111 | 120 | 121 | 122 | 123 | 131 | 132 | 135 | 136 | 144 | 145 | 146 | 157 | 158 | 170 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 192 | 193 | 198 | 199 | 207 | 208 | 212 | 213 | 214 | 215 | 216 | 221 | 225 | 231 | 235 | 236 | 242 | 246 | 247 | 248 | 252 | 258 | 262 | 263 | 269 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_saklar.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_recycler_history.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 17 | 23 | 28 | 29 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_recycler_saklar.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 20 | 21 | 30 | 31 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/res/layout/iv_refresh.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/layout/nav_drawer_header.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 21 | 22 | 31 | 32 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /app/src/main/res/layout/nav_drawer_item_row.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 22 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_saklar.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_saklar_history.xml: -------------------------------------------------------------------------------- 1 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suciptoid/AndroidSmartHome/3a16a8f56bbe0a449c4bf97c304cca7c5bec33c4/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suciptoid/AndroidSmartHome/3a16a8f56bbe0a449c4bf97c304cca7c5bec33c4/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suciptoid/AndroidSmartHome/3a16a8f56bbe0a449c4bf97c304cca7c5bec33c4/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suciptoid/AndroidSmartHome/3a16a8f56bbe0a449c4bf97c304cca7c5bec33c4/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/suciptoid/AndroidSmartHome/3a16a8f56bbe0a449c4bf97c304cca7c5bec33c4/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #009688 4 | #004D40 5 | #1E88E5 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 16dp 6 | 180dp 7 | 16dp 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Smart Home 3 | Settings 4 | Drawer Tittle 5 | Nav Drawer Subtittle 6 | Open Drawer 7 | Close Drawer 8 | SaklarHistory 9 | 10 | "Material is the metaphor.\n\n" 11 | 12 | "A material metaphor is the unifying theory of a rationalized space and a system of motion." 13 | "The material is grounded in tactile reality, inspired by the study of paper and ink, yet " 14 | "technologically advanced and open to imagination and magic.\n" 15 | "Surfaces and edges of the material provide visual cues that are grounded in reality. The " 16 | "use of familiar tactile attributes helps users quickly understand affordances. Yet the " 17 | "flexibility of the material creates new affordances that supercede those in the physical " 18 | "world, without breaking the rules of physics.\n" 19 | "The fundamentals of light, surface, and movement are key to conveying how objects move, " 20 | "interact, and exist in space and in relation to each other. Realistic lighting shows " 21 | "seams, divides space, and indicates moving parts.\n\n" 22 | 23 | "Bold, graphic, intentional.\n\n" 24 | 25 | "The foundational elements of print based design typography, grids, space, scale, color, " 26 | "and use of imagery guide visual treatments. These elements do far more than please the " 27 | "eye. They create hierarchy, meaning, and focus. Deliberate color choices, edge to edge " 28 | "imagery, large scale typography, and intentional white space create a bold and graphic " 29 | "interface that immerse the user in the experience.\n" 30 | "An emphasis on user actions makes core functionality immediately apparent and provides " 31 | "waypoints for the user.\n\n" 32 | 33 | "Motion provides meaning.\n\n" 34 | 35 | "Motion respects and reinforces the user as the prime mover. Primary user actions are " 36 | "inflection points that initiate motion, transforming the whole design.\n" 37 | "All action takes place in a single environment. Objects are presented to the user without " 38 | "breaking the continuity of experience even as they transform and reorganize.\n" 39 | "Motion is meaningful and appropriate, serving to focus attention and maintain continuity. " 40 | "Feedback is subtle yet clear. Transitions are efficient yet coherent.\n\n" 41 | 42 | "3D world.\n\n" 43 | 44 | "The material environment is a 3D space, which means all objects have x, y, and z " 45 | "dimensions. The z-axis is perpendicularly aligned to the plane of the display, with the " 46 | "positive z-axis extending towards the viewer. Every sheet of material occupies a single " 47 | "position along the z-axis and has a standard 1dp thickness.\n" 48 | "On the web, the z-axis is used for layering and not for perspective. The 3D world is " 49 | "emulated by manipulating the y-axis.\n\n" 50 | 51 | "Light and shadow.\n\n" 52 | 53 | "Within the material environment, virtual lights illuminate the scene. Key lights create " 54 | "directional shadows, while ambient light creates soft shadows from all angles.\n" 55 | "Shadows in the material environment are cast by these two light sources. In Android " 56 | "development, shadows occur when light sources are blocked by sheets of material at " 57 | "various positions along the z-axis. On the web, shadows are depicted by manipulating the " 58 | "y-axis only. The following example shows the card with a height of 6dp.\n\n" 59 | 60 | "Resting elevation.\n\n" 61 | 62 | "All material objects, regardless of size, have a resting elevation, or default elevation " 63 | "that does not change. If an object changes elevation, it should return to its resting " 64 | "elevation as soon as possible.\n\n" 65 | 66 | "Component elevations.\n\n" 67 | 68 | "The resting elevation for a component type is consistent across apps (e.g., FAB elevation " 69 | "does not vary from 6dp in one app to 16dp in another app).\n" 70 | "Components may have different resting elevations across platforms, depending on the depth " 71 | "of the environment (e.g., TV has a greater depth than mobile or desktop).\n\n" 72 | 73 | "Responsive elevation and dynamic elevation offsets.\n\n" 74 | 75 | "Some component types have responsive elevation, meaning they change elevation in response " 76 | "to user input (e.g., normal, focused, and pressed) or system events. These elevation " 77 | "changes are consistently implemented using dynamic elevation offsets.\n" 78 | "Dynamic elevation offsets are the goal elevation that a component moves towards, relative " 79 | "to the component’s resting state. They ensure that elevation changes are consistent " 80 | "across actions and component types. For example, all components that lift on press have " 81 | "the same elevation change relative to their resting elevation.\n" 82 | "Once the input event is completed or cancelled, the component will return to its resting " 83 | "elevation.\n\n" 84 | 85 | "Avoiding elevation interference.\n\n" 86 | 87 | "Components with responsive elevations may encounter other components as they move between " 88 | "their resting elevations and dynamic elevation offsets. Because material cannot pass " 89 | "through other material, components avoid interfering with one another any number of ways, " 90 | "whether on a per component basis or using the entire app layout.\n" 91 | "On a component level, components can move or be removed before they cause interference. " 92 | "For example, a floating action button (FAB) can disappear or move off screen before a " 93 | "user picks up a card, or it can move if a snackbar appears.\n" 94 | "On the layout level, design your app layout to minimize opportunities for interference. " 95 | "For example, position the FAB to one side of stream of a cards so the FAB won’t interfere " 96 | "when a user tries to pick up one of cards.\n\n" 97 | 98 | Refresh 99 | Intro 100 | Intro 101 | 102 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 |