[
  {
    "path": ".gitignore",
    "content": "# Temporary files\n*~\n\\#*\ntmp/\n\n# Build directory\nbuild/\n\n# Eclipse files\n.metadata\n.pmd\n.apt_generated/\n\n# IntelliJ files\n.idea\n*.iml\n\n# Android built application files\n*.apk\n*.ap_\n\n# Files for the dex VM\n*.dex\n\n# Java class files\n*.class\n\n# Generated files\nbin/\ngen/\n\n# Local configuration file (sdk path, etc)\nlocal.properties\n\n# OSX files\n.DS_Store\n\n# Windows files\nThumbs.db\n\n# Gradle\n.gradle\n"
  },
  {
    "path": "LICENSE.txt",
    "content": "\n                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "README.md",
    "content": "# Hosts Editor for Android\n\nThis repository contains the source code for the Hosts-editor Android app.\n\nIt is available from [Google Play][] and [F-Droid][].\n\n![Hosts Editor for Android screenshots][]\n\nThis application, **for root devices only**, lets you modify easily your Android `/etc/hosts` file.\n\nYou might need to reboot to clear your DNS cache after any change.\n\n\n## Features\n\n* Android 2.2 and above\n* Insert, Remove, Toggle (comment/uncomment) and Modify host entries\n* Holo theme\n* Fast search engine\n* 100% free/libre, gratis, no ads\n\n\n## Building the app\n\nThe Android SDK for API level 19 is required to build the app. Then launch:\n\n    ./gradlew clean build\n\n\n## Acknowledgements\n\nThis project uses many great open-source libraries, such as:\n\n* [ActionBarSherlock][]\n* [Butterknife][]\n* [Dagger][]\n* [Commons IO][]\n* [Otto][]\n* [RootTools][]\n\n\n## License\n\n<pre>\n\n                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n</pre>\n\n\n[Google Play]: https://play.google.com/store/apps/details?id=com.nilhcem.hostseditor\n[F-Droid]: https://f-droid.org/repository/browse/?fdid=com.nilhcem.hostseditor\n[Hosts Editor for Android screenshots]: https://raw.githubusercontent.com/Nilhcem/hosts-editor-android/master/screenshot.png\n[ActionBarSherlock]: http://actionbarsherlock.com/\n[Butterknife]: http://jakewharton.github.com/butterknife/\n[Dagger]: http://square.github.com/dagger/\n[Commons IO]: http://commons.apache.org/proper/commons-io/\n[Otto]: http://square.github.com/otto/\n[RootTools]: https://code.google.com/p/roottools/\n"
  },
  {
    "path": "app/build.gradle",
    "content": "apply plugin: 'com.android.application'\napply plugin: 'com.neenbedankt.android-apt'\n\nandroid {\n    compileSdkVersion 22\n    buildToolsVersion '22.0.1'\n\n    defaultConfig {\n        applicationId 'com.nilhcem.hostseditor'\n        minSdkVersion 8\n        targetSdkVersion 22\n        versionCode 5\n        versionName '1.4'\n        resConfig 'en'\n    }\n\n    compileOptions {\n        sourceCompatibility JavaVersion.VERSION_1_7\n        targetCompatibility JavaVersion.VERSION_1_7\n    }\n\n    buildTypes {\n        release {\n            minifyEnabled false\n        }\n    }\n\n    packagingOptions {\n        exclude 'META-INF/LICENSE.txt'\n    }\n\n    lintOptions {\n        abortOnError false\n    }\n}\n\ndependencies {\n    // Commons IO\n    compile 'commons-io:commons-io:2.4'\n\n    // Dagger\n    compile 'com.google.dagger:dagger:2.0.1'\n    apt 'com.google.dagger:dagger-compiler:2.0.1'\n    compile 'javax.annotation:javax.annotation-api:1.2'\n\n    // ActionBarSherlock + Support library\n    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'\n    compile 'com.android.support:support-v4:22.2.0'\n\n    // Butterknife\n    compile 'com.jakewharton:butterknife:7.0.1'\n\n    // Logging\n    compile 'com.jakewharton.timber:timber:3.1.0'\n\n    // Otto\n    compile 'com.squareup:otto:1.3.8'\n\n    // Other jars (RootTools)\n    compile fileTree(dir: 'libs', include: '*.jar')\n}\n"
  },
  {
    "path": "app/src/main/AndroidManifest.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    package=\"com.nilhcem.hostseditor\"\n    android:installLocation=\"preferExternal\">\n\n    <uses-permission android:name=\"android.permission.ACCESS_SUPERUSER\" />\n\n    <application\n        android:name=\"com.nilhcem.hostseditor.HostsEditorApplication\"\n        android:allowBackup=\"true\"\n        android:icon=\"@drawable/ic_launcher\"\n        android:label=\"@string/app_name\"\n        android:largeHeap=\"true\"\n        android:theme=\"@style/AppTheme\">\n\n        <activity android:name=\"com.nilhcem.hostseditor.ui.list.ListHostsActivity\">\n            <intent-filter>\n                <action android:name=\"android.intent.action.MAIN\" />\n                <category android:name=\"android.intent.category.LAUNCHER\" />\n            </intent-filter>\n        </activity>\n\n        <activity android:name=\"com.nilhcem.hostseditor.ui.addedit.AddEditHostActivity\" />\n    </application>\n</manifest>\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/HostsEditorApplication.java",
    "content": "package com.nilhcem.hostseditor;\n\nimport android.app.Application;\nimport android.content.Context;\n\nimport com.nilhcem.hostseditor.core.dagger.DaggerHostsEditorComponent;\nimport com.nilhcem.hostseditor.core.dagger.HostsEditorComponent;\nimport com.nilhcem.hostseditor.core.dagger.HostsEditorModule;\nimport com.nilhcem.hostseditor.core.log.ReleaseTree;\n\nimport timber.log.Timber;\n\npublic class HostsEditorApplication extends Application {\n\n    private HostsEditorComponent mComponent;\n\n    public static HostsEditorApplication get(Context context) {\n        return (HostsEditorApplication) context.getApplicationContext();\n    }\n\n    @Override\n    public void onCreate() {\n        super.onCreate();\n        initLogger();\n        initGraph();\n    }\n\n    public HostsEditorComponent component() {\n        return mComponent;\n    }\n\n    private void initLogger() {\n        if (BuildConfig.DEBUG) {\n            Timber.plant(new Timber.DebugTree());\n        } else {\n            Timber.plant(new ReleaseTree());\n        }\n    }\n\n    private void initGraph() {\n        mComponent = DaggerHostsEditorComponent.builder()\n                .hostsEditorModule(new HostsEditorModule())\n                .build();\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/core/Host.java",
    "content": "package com.nilhcem.hostseditor.core;\n\nimport android.os.Parcel;\nimport android.os.Parcelable;\nimport android.text.TextUtils;\n\nimport com.nilhcem.hostseditor.core.util.InetAddresses;\n\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\npublic class Host implements Parcelable {\n\n    public static final String STR_COMMENT = \"#\";\n    private static final String STR_SEPARATOR = \" \";\n    private static final String HOST_PATTERN_STR = \"^\\\\s*(\" + STR_COMMENT + \"?)\\\\s*(\\\\S*)\\\\s*([^\" + STR_COMMENT + \"]*)\" + STR_COMMENT + \"?(.*)$\";\n    private static final Pattern HOST_PATTERN = Pattern.compile(HOST_PATTERN_STR);\n\n    private String mIp;\n    private String mHostName;\n    private String mComment; // When host entry has a comment at the end, eg: \"::1 localhost #myhome\"\n    private boolean mIsCommented; // When host entry starts with #, eg: \"#::1 localhost\"\n    private boolean mIsValid; // When host entry has a valid IP + hostname\n\n    public Host(String ip, String hostName, String comment, boolean isCommented, boolean isValid) {\n        mIp = ip;\n        mHostName = hostName;\n        mComment = comment;\n        mIsCommented = isCommented;\n        mIsValid = isValid;\n    }\n\n    public void merge(Host src) {\n        mIp = src.getIp();\n        mHostName = src.getHostName();\n        mComment = src.getComment();\n        mIsCommented = src.isCommented();\n        mIsValid = src.isValid();\n    }\n\n    public String getIp() {\n        return mIp;\n    }\n\n    public String getHostName() {\n        return mHostName;\n    }\n\n    public String getComment() {\n        return mComment;\n    }\n\n    public boolean isValid() {\n        return mIsValid;\n    }\n\n    public boolean isCommented() {\n        return mIsCommented;\n    }\n\n    public void toggleComment() {\n        mIsCommented = !mIsCommented;\n    }\n\n    @Override\n    public String toString() {\n        StringBuilder sb = new StringBuilder();\n\n        if (mIsCommented) {\n            sb.append(STR_COMMENT);\n        }\n        if (mIp != null) {\n            sb.append(mIp).append(STR_SEPARATOR);\n        }\n        if (mHostName != null) {\n            sb.append(mHostName);\n        }\n        if (!TextUtils.isEmpty(mComment)) {\n            sb.append(STR_SEPARATOR).append(STR_COMMENT).append(mComment);\n        }\n        return sb.toString();\n    }\n\n    public static Host fromString(String line) {\n        Matcher matcher = HOST_PATTERN.matcher(line);\n        String ip = null;\n        String hostname = null;\n        String comment = null;\n        boolean isCommented = false;\n        boolean isValid = false;\n\n        if (matcher.find()) {\n            isCommented = !TextUtils.isEmpty(matcher.group(1));\n            ip = matcher.group(2);\n            hostname = matcher.group(3).trim();\n            comment = matcher.group(4).trim();\n            if (TextUtils.isEmpty(comment)) {\n                comment = null;\n            }\n\n            isValid = !TextUtils.isEmpty(ip) && !TextUtils.isEmpty(hostname)\n                    && InetAddresses.isInetAddress(ip);\n        }\n        return new Host(ip, hostname, comment, isCommented, isValid);\n    }\n\n    public static final Parcelable.Creator<Host> CREATOR = new Parcelable.Creator<Host>() {\n\n        @Override\n        public Host createFromParcel(Parcel source) {\n            return new Host(source);\n        }\n\n        @Override\n        public Host[] newArray(int size) {\n            return new Host[size];\n        }\n    };\n\n    @Override\n    public int describeContents() {\n        return 0;\n    }\n\n    @Override\n    public void writeToParcel(Parcel dest, int flags) {\n        dest.writeString(mIp);\n        dest.writeString(mHostName);\n        dest.writeString(mComment);\n        dest.writeByte((byte) (mIsCommented ? 1 : 0));\n        dest.writeByte((byte) (mIsValid ? 1 : 0));\n    }\n\n    private Host(Parcel in) {\n        mIp = in.readString();\n        mHostName = in.readString();\n        mComment = in.readString();\n        mIsCommented = in.readByte() == 1;\n        mIsValid = in.readByte() == 1;\n    }\n\n    @Override\n    public int hashCode() {\n        final int prime = 31;\n        int result = 1;\n        result = prime * result + ((mComment == null) ? 0 : mComment.hashCode());\n        result = prime * result + ((mHostName == null) ? 0 : mHostName.hashCode());\n        result = prime * result + ((mIp == null) ? 0 : mIp.hashCode());\n        result = prime * result + (mIsCommented ? 1231 : 1237);\n        result = prime * result + (mIsValid ? 1231 : 1237);\n        return result;\n    }\n\n    @Override\n    public boolean equals(Object obj) {\n        if (this == obj) {\n            return true;\n        }\n        if (obj == null) {\n            return false;\n        }\n        if (getClass() != obj.getClass()) {\n            return false;\n        }\n        Host other = (Host) obj;\n        if (mComment == null) {\n            if (other.mComment != null) {\n                return false;\n            }\n        } else if (!mComment.equals(other.mComment)) {\n            return false;\n        }\n        if (mHostName == null) {\n            if (other.mHostName != null) {\n                return false;\n            }\n        } else if (!mHostName.equals(other.mHostName)) {\n            return false;\n        }\n        if (mIp == null) {\n            if (other.mIp != null) {\n                return false;\n            }\n        } else if (!mIp.equals(other.mIp)) {\n            return false;\n        }\n        if (mIsCommented != other.mIsCommented) {\n            return false;\n        }\n        if (mIsValid != other.mIsValid) {\n            return false;\n        }\n        return true;\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/core/HostsManager.java",
    "content": "package com.nilhcem.hostseditor.core;\n\nimport android.content.Context;\n\nimport com.stericson.RootShell.RootShell;\nimport com.stericson.RootShell.exceptions.RootDeniedException;\nimport com.stericson.RootShell.execution.Command;\nimport com.stericson.RootTools.RootTools;\n\nimport org.apache.commons.io.FileUtils;\nimport org.apache.commons.io.LineIterator;\n\nimport java.io.File;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.Locale;\nimport java.util.concurrent.TimeoutException;\n\nimport javax.inject.Inject;\nimport javax.inject.Singleton;\n\nimport timber.log.Timber;\n\n@Singleton\npublic class HostsManager {\n\n    private static final String UTF_8 = \"UTF-8\";\n    private static final String HOSTS_FILE_NAME = \"hosts\";\n    private static final String HOSTS_FILE_PATH = \"/system/etc/\" + HOSTS_FILE_NAME;\n\n    private static final String LINE_SEPARATOR = System.getProperty(\"line.separator\", \"\\n\");\n    private static final String MOUNT_TYPE_RO = \"ro\";\n    private static final String MOUNT_TYPE_RW = \"rw\";\n    private static final String COMMAND_RM = \"rm -f\";\n    private static final String COMMAND_CHOWN = \"chown 0:0\";\n    private static final String COMMAND_CHMOD_644 = \"chmod 644\";\n\n    // Do not access this field directly even in the same class, use getAllHosts() instead.\n    private List<Host> mHosts;\n\n    @Inject\n    public HostsManager() {\n    }\n\n    /**\n     * Gets all host entries from hosts file.\n     * <p><b>Must be in an async call.</b></p>\n     *\n     * @param forceRefresh if we want to force using the hosts file (not the cache)\n     * @return a list of host entries\n     */\n    public synchronized List<Host> getHosts(boolean forceRefresh) {\n        if (mHosts == null || forceRefresh) {\n            mHosts = Collections.synchronizedList(new ArrayList<Host>());\n\n            LineIterator it = null;\n            try {\n                it = FileUtils.lineIterator(new File(HOSTS_FILE_PATH), UTF_8);\n                while (it.hasNext()) {\n                    Host host = Host.fromString(it.nextLine());\n                    if (host != null) {\n                        mHosts.add(host);\n                    }\n                }\n            } catch (IOException e) {\n                Timber.e(e, \"I/O error while opening hosts file\");\n            } finally {\n                if (it != null) {\n                    LineIterator.closeQuietly(it);\n                }\n            }\n        }\n        return mHosts;\n    }\n\n    /**\n     * Saves new hosts file and creates a backup of previous file.\n     * <p><b>Must be in an async call.</b></p>\n     *\n     * @param appContext application context\n     * @return {@code true} if everything was working as expected, or {@code false} otherwise\n     */\n    public synchronized boolean saveHosts(Context appContext) {\n        if (!RootTools.isAccessGiven()) {\n            Timber.w(\"Can't get root access\");\n            return false;\n        }\n\n        // Step 1: Create temporary hosts file in /data/data/project_package/files/hosts\n        if (!createTempHostsFile(appContext)) {\n            Timber.w(\"Can't create temporary hosts file\");\n            return false;\n        }\n\n        String tmpFile = String.format(Locale.US, \"%s/%s\", appContext.getFilesDir().getAbsolutePath(), HOSTS_FILE_NAME);\n        String backupFile = String.format(Locale.US, \"%s.bak\", tmpFile);\n\n        // Step 2: Get canonical path for /etc/hosts (it could be a symbolic link)\n        String hostsFilePath = HOSTS_FILE_PATH;\n        File hostsFile = new File(HOSTS_FILE_PATH);\n        if (hostsFile.exists()) {\n            try {\n                if (FileUtils.isSymlink(hostsFile)) {\n                    hostsFilePath = hostsFile.getCanonicalPath();\n                }\n            } catch (IOException e1) {\n                Timber.e(e1, \"Can't find hosts file\");\n            }\n        } else {\n            Timber.w(\"Hosts file was not found in filesystem\");\n        }\n\n        try {\n            // Step 3: Create backup of current hosts file (if any)\n            RootTools.remount(hostsFilePath, MOUNT_TYPE_RW);\n            runRootCommand(COMMAND_RM, backupFile);\n            RootTools.copyFile(hostsFilePath, backupFile, false, true);\n\n            // Step 4: Replace hosts file with generated file\n            runRootCommand(COMMAND_RM, hostsFilePath);\n            RootTools.copyFile(tmpFile, hostsFilePath, false, true);\n\n            // Step 5: Give proper rights\n            runRootCommand(COMMAND_CHOWN, hostsFilePath);\n            runRootCommand(COMMAND_CHMOD_644, hostsFilePath);\n\n            // Step 6: Delete local file\n            appContext.deleteFile(HOSTS_FILE_NAME);\n        } catch (Exception e) {\n            Timber.e(e, \"Failed running root command\");\n            return false;\n        } finally {\n            RootTools.remount(hostsFilePath, MOUNT_TYPE_RO);\n        }\n        return true;\n    }\n\n    /**\n     * Returns a list of hosts matching the constraint parameter.\n     */\n    public List<Host> filterHosts(CharSequence constraint) {\n        List<Host> all = getHosts(false);\n        List<Host> hosts = new ArrayList<>();\n\n        for (Host host : all) {\n            if (host.isValid()) {\n                if (host.getIp().contains(constraint)\n                        || host.getHostName().contains(constraint)\n                        || (host.getComment() != null && host.getComment().contains(constraint))) {\n                    hosts.add(host);\n                }\n            }\n        }\n        return hosts;\n    }\n\n    /**\n     * Creates a temporary hosts file in {@code /data/data/project_package/files/hosts}.\n     * <p><b>Must be in an async call.</b></p>\n     *\n     * @param appContext application context\n     * @return {@code true} if the temp file was created, or {@code false} otherwise\n     */\n    private boolean createTempHostsFile(Context appContext) {\n        OutputStreamWriter writer = null;\n        try {\n            FileOutputStream out = appContext.openFileOutput(HOSTS_FILE_NAME, Context.MODE_PRIVATE);\n            writer = new OutputStreamWriter(out);\n\n            for (Host host : getHosts(false)) {\n                writer.append(host.toString()).append(LINE_SEPARATOR);\n            }\n            writer.flush();\n        } catch (IOException e) {\n            Timber.e(e, \"Error creating temporary hosts file\");\n            return false;\n        } finally {\n            if (writer != null) {\n                try {\n                    writer.close();\n                } catch (IOException e) {\n                    Timber.e(e, \"Error while closing writer\");\n                }\n            }\n        }\n        return true;\n    }\n\n    /**\n     * Executes a single argument root command.\n     * <p><b>Must be in an async call.</b></p>\n     *\n     * @param command   a command, ie {@code \"rm -f\"}, {@code \"chmod 644\"}...\n     * @param uniqueArg the unique argument for the command, usually the file name\n     */\n    private void runRootCommand(String command, String uniqueArg) throws IOException, TimeoutException, RootDeniedException {\n        Command cmd = new Command(0, false, String.format(Locale.US, \"%s %s\", command, uniqueArg));\n        RootShell.getShell(true).add(cmd);\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/core/dagger/HostsEditorComponent.java",
    "content": "package com.nilhcem.hostseditor.core.dagger;\n\nimport com.nilhcem.hostseditor.task.GenericTaskAsync;\nimport com.nilhcem.hostseditor.task.ListHostsAsync;\nimport com.nilhcem.hostseditor.ui.BaseActivity;\nimport com.nilhcem.hostseditor.ui.addedit.AddEditHostFragment;\nimport com.nilhcem.hostseditor.ui.list.ListHostsFragment;\n\nimport javax.inject.Singleton;\n\nimport dagger.Component;\n\n@Singleton\n@Component(\n        modules = {\n                HostsEditorModule.class\n        }\n)\npublic interface HostsEditorComponent {\n\n    void inject(BaseActivity activity);\n\n    void inject(GenericTaskAsync async);\n\n    void inject(AddEditHostFragment fragment);\n\n    void inject(ListHostsAsync async);\n\n    void inject(ListHostsFragment fragment);\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/core/dagger/HostsEditorModule.java",
    "content": "package com.nilhcem.hostseditor.core.dagger;\n\nimport com.squareup.otto.Bus;\n\nimport javax.inject.Singleton;\n\nimport dagger.Module;\nimport dagger.Provides;\n\n@Module\npublic class HostsEditorModule {\n\n    @Provides @Singleton Bus provideBus() {\n        return new Bus();\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/core/log/ReleaseTree.java",
    "content": "package com.nilhcem.hostseditor.core.log;\n\nimport android.util.Log;\n\nimport timber.log.Timber;\n\npublic class ReleaseTree extends Timber.Tree {\n\n    @Override\n    protected void log(int priority, String tag, String message, Throwable t) {\n        // Only log ERROR, and WTF.\n        if (priority > Log.WARN) {\n            Log.println(priority, tag, message);\n        }\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/core/util/Compatibility.java",
    "content": "package com.nilhcem.hostseditor.core.util;\n\nimport android.annotation.TargetApi;\nimport android.content.Context;\nimport android.content.res.Resources;\nimport android.graphics.Point;\nimport android.os.Build;\nimport android.util.DisplayMetrics;\nimport android.view.Display;\nimport android.view.WindowManager;\n\npublic class Compatibility {\n\n    private Compatibility() {\n        throw new UnsupportedOperationException();\n    }\n\n    /**\n     * Checks if current SDK is compatible with the desired API level.\n     *\n     * @param apiLevel the required API level.\n     * @return {@code true} if current OS is compatible.\n     */\n    private static boolean isCompatible(int apiLevel) {\n        return android.os.Build.VERSION.SDK_INT >= apiLevel;\n    }\n\n    @SuppressWarnings(\"deprecation\")\n    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)\n    public static Point getScreenDimensions(Context context) {\n        Point size = new Point();\n\n        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);\n        Display display = wm.getDefaultDisplay();\n        if (Compatibility.isCompatible(Build.VERSION_CODES.HONEYCOMB_MR2)) {\n            display.getSize(size);\n        } else {\n            size.set(display.getWidth(), display.getHeight());\n        }\n        return size;\n    }\n\n    /**\n     * This method converts dp unit to equivalent device specific value in pixels.\n     *\n     * @param dp      A value in dp (Device independent pixels) unit. Which we need to convert into pixels.\n     * @param context Context to get resources and device specific display metrics.\n     * @return A float value to represent Pixels equivalent to dp according to device.\n     */\n    public static float convertDpToPixel(float dp, Context context) {\n        Resources resources = context.getResources();\n        DisplayMetrics metrics = resources.getDisplayMetrics();\n        return dp * (metrics.densityDpi / 160f);\n    }\n\n    public static int convertDpToIntPixel(float dp, Context context) {\n        return Math.round(convertDpToPixel(dp, context));\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/core/util/InetAddresses.java",
    "content": "/*\n * Copyright (C) 2008 The Guava Authors\n *\n * NOTICE: THIS FILE WAS MODIFIED (removed all not required for the project)\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage com.nilhcem.hostseditor.core.util;\n\nimport java.net.InetAddress;\nimport java.nio.ByteBuffer;\n\n/**\n * Static utility methods pertaining to {@link InetAddress} instances.\n */\npublic final class InetAddresses {\n\n    private static final int IPV4_PART_COUNT = 4;\n    private static final int IPV6_PART_COUNT = 8;\n\n    private InetAddresses() {\n    }\n\n    /**\n     * Returns {@code true} if the supplied string is a valid IP string literal,\n     * {@code false} otherwise.\n     *\n     * @param ipString {@code String} to evaluated as an IP string literal\n     * @return {@code true} if the argument is a valid IP string literal\n     */\n    public static boolean isInetAddress(String ipString) {\n        return ipStringToBytes(ipString) != null;\n    }\n\n    private static byte[] ipStringToBytes(String ipString) {\n        // Make a first pass to categorize the characters in this string.\n        boolean hasColon = false;\n        boolean hasDot = false;\n        for (int i = 0; i < ipString.length(); i++) {\n            char c = ipString.charAt(i);\n            if (c == '.') {\n                hasDot = true;\n            } else if (c == ':') {\n                if (hasDot) {\n                    return null; // Colons must not appear after dots.\n                }\n                hasColon = true;\n            } else if (Character.digit(c, 16) == -1) {\n                return null; // Everything else must be a decimal or hex digit.\n            }\n        }\n\n        // Now decide which address family to parse.\n        if (hasColon) {\n            if (hasDot) {\n                ipString = convertDottedQuadToHex(ipString);\n                if (ipString == null) {\n                    return null;\n                }\n            }\n            return textToNumericFormatV6(ipString);\n        } else if (hasDot) {\n            return textToNumericFormatV4(ipString);\n        }\n        return null;\n    }\n\n    private static byte[] textToNumericFormatV4(String ipString) {\n        String[] address = ipString.split(\"\\\\.\", IPV4_PART_COUNT + 1);\n        if (address.length != IPV4_PART_COUNT) {\n            return null;\n        }\n\n        byte[] bytes = new byte[IPV4_PART_COUNT];\n        try {\n            for (int i = 0; i < bytes.length; i++) {\n                bytes[i] = parseOctet(address[i]);\n            }\n        } catch (NumberFormatException ex) {\n            return null;\n        }\n\n        return bytes;\n    }\n\n    private static byte[] textToNumericFormatV6(String ipString) {\n        // An address can have [2..8] colons, and N colons make N+1 parts.\n        String[] parts = ipString.split(\":\", IPV6_PART_COUNT + 2);\n        if (parts.length < 3 || parts.length > IPV6_PART_COUNT + 1) {\n            return null;\n        }\n\n        // Disregarding the endpoints, find \"::\" with nothing in between.\n        // This indicates that a run of zeroes has been skipped.\n        int skipIndex = -1;\n        for (int i = 1; i < parts.length - 1; i++) {\n            if (parts[i].length() == 0) {\n                if (skipIndex >= 0) {\n                    return null; // Can't have more than one ::\n                }\n                skipIndex = i;\n            }\n        }\n\n        int partsHi; // Number of parts to copy from above/before the \"::\"\n        int partsLo; // Number of parts to copy from below/after the \"::\"\n        if (skipIndex >= 0) {\n            // If we found a \"::\", then check if it also covers the endpoints.\n            partsHi = skipIndex;\n            partsLo = parts.length - skipIndex - 1;\n            if (parts[0].length() == 0 && --partsHi != 0) {\n                return null; // ^: requires ^::\n            }\n            if (parts[parts.length - 1].length() == 0 && --partsLo != 0) {\n                return null; // :$ requires ::$\n            }\n        } else {\n            // Otherwise, allocate the entire address to partsHi. The endpoints\n            // could still be empty, but parseHextet() will check for that.\n            partsHi = parts.length;\n            partsLo = 0;\n        }\n\n        // If we found a ::, then we must have skipped at least one part.\n        // Otherwise, we must have exactly the right number of parts.\n        int partsSkipped = IPV6_PART_COUNT - (partsHi + partsLo);\n        if (!(skipIndex >= 0 ? partsSkipped >= 1 : partsSkipped == 0)) {\n            return null;\n        }\n\n        // Now parse the hextets into a byte array.\n        ByteBuffer rawBytes = ByteBuffer.allocate(2 * IPV6_PART_COUNT);\n        try {\n            for (int i = 0; i < partsHi; i++) {\n                rawBytes.putShort(parseHextet(parts[i]));\n            }\n            for (int i = 0; i < partsSkipped; i++) {\n                rawBytes.putShort((short) 0);\n            }\n            for (int i = partsLo; i > 0; i--) {\n                rawBytes.putShort(parseHextet(parts[parts.length - i]));\n            }\n        } catch (NumberFormatException ex) {\n            return null;\n        }\n        return rawBytes.array();\n    }\n\n    private static String convertDottedQuadToHex(String ipString) {\n        int lastColon = ipString.lastIndexOf(':');\n        String initialPart = ipString.substring(0, lastColon + 1);\n        String dottedQuad = ipString.substring(lastColon + 1);\n        byte[] quad = textToNumericFormatV4(dottedQuad);\n        if (quad == null) {\n            return null;\n        }\n        String penultimate = Integer.toHexString(((quad[0] & 0xff) << 8)\n                | (quad[1] & 0xff));\n        String ultimate = Integer.toHexString(((quad[2] & 0xff) << 8)\n                | (quad[3] & 0xff));\n        return initialPart + penultimate + \":\" + ultimate;\n    }\n\n    private static byte parseOctet(String ipPart) {\n        // Note: we already verified that this string contains only hex digits.\n        int octet = Integer.parseInt(ipPart);\n        // Disallow leading zeroes, because no clear standard exists on\n        // whether these should be interpreted as decimal or octal.\n        if (octet > 255 || (ipPart.startsWith(\"0\") && ipPart.length() > 1)) {\n            throw new NumberFormatException();\n        }\n        return (byte) octet;\n    }\n\n    private static short parseHextet(String ipPart) {\n        // Note: we already verified that this string contains only hex digits.\n        int hextet = Integer.parseInt(ipPart, 16);\n        if (hextet > 0xffff) {\n            throw new NumberFormatException();\n        }\n        return (short) hextet;\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/core/util/ThreadPreconditions.java",
    "content": "package com.nilhcem.hostseditor.core.util;\n\nimport android.os.Looper;\n\nimport com.nilhcem.hostseditor.BuildConfig;\n\npublic final class ThreadPreconditions {\n\n    private ThreadPreconditions() {\n        throw new UnsupportedOperationException();\n    }\n\n    public static void checkOnMainThread() {\n        if (BuildConfig.DEBUG) {\n            if (Thread.currentThread() != Looper.getMainLooper().getThread()) {\n                throw new IllegalStateException(\"This method should be called from the Main Thread\");\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/event/CreatedHostEvent.java",
    "content": "package com.nilhcem.hostseditor.event;\n\nimport com.nilhcem.hostseditor.core.Host;\n\npublic class CreatedHostEvent {\n\n    /**\n     * Host (add mode), or the modified version of the Host entry (edit mode).\n     */\n    public final Host editedHost;\n\n    /**\n     * Original version of the Host entry (edit mode) or {@code null} (add mode).\n     */\n    public final Host originalHost;\n\n    public CreatedHostEvent(Host original, Host edited) {\n        originalHost = original;\n        editedHost = edited;\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/event/LoadingEvent.java",
    "content": "package com.nilhcem.hostseditor.event;\n\nimport android.content.Context;\n\npublic class LoadingEvent {\n\n    private final boolean mIsLoading;\n    private final int mMessageRes;\n    private final String mMessage;\n\n    public LoadingEvent() {\n        this(false, \"\");\n    }\n\n    public LoadingEvent(boolean isLoading, int messageRes) {\n        mIsLoading = isLoading;\n        mMessageRes = messageRes;\n        mMessage = null;\n    }\n\n    public LoadingEvent(boolean isLoading, String message) {\n        mIsLoading = isLoading;\n        mMessage = message;\n        mMessageRes = 0;\n    }\n\n    public boolean isLoading() {\n        return mIsLoading;\n    }\n\n    public String getMessage(Context context) {\n        if (mMessage == null) {\n            return context.getString(mMessageRes);\n        }\n        return mMessage;\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/event/RefreshHostsEvent.java",
    "content": "package com.nilhcem.hostseditor.event;\n\nimport com.nilhcem.hostseditor.core.Host;\n\nimport java.util.List;\n\n/**\n * Sent to the bus when hosts need to be refreshed.\n */\npublic class RefreshHostsEvent {\n\n    public final List<Host> hosts;\n\n    public RefreshHostsEvent(List<Host> refreshedHosts) {\n        hosts = refreshedHosts;\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/event/StartAddEditActivityEvent.java",
    "content": "package com.nilhcem.hostseditor.event;\n\nimport com.nilhcem.hostseditor.core.Host;\n\npublic class StartAddEditActivityEvent {\n\n    /**\n     * The Host entry to modify (edit mode), or {@code null} (add mode).\n     */\n    public final Host host;\n\n    public StartAddEditActivityEvent(Host addEditHost) {\n        host = addEditHost;\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/event/TaskCompletedEvent.java",
    "content": "package com.nilhcem.hostseditor.event;\n\npublic class TaskCompletedEvent {\n\n    public final String tag;\n    public final boolean isSuccessful;\n\n    public TaskCompletedEvent(String pTag, boolean pIsSuccessful) {\n        tag = pTag;\n        isSuccessful = pIsSuccessful;\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/task/AddEditHostAsync.java",
    "content": "package com.nilhcem.hostseditor.task;\n\nimport android.content.Context;\n\nimport com.nilhcem.hostseditor.R;\nimport com.nilhcem.hostseditor.core.Host;\n\nimport java.util.List;\n\nimport timber.log.Timber;\n\n/**\n * AsyncTask that inserts or edits an host entry and triggers a {@code TaskCompletedEvent} event.\n */\npublic class AddEditHostAsync extends GenericTaskAsync {\n\n    public AddEditHostAsync(Context appContext, boolean flagMsg) {\n        super(appContext, flagMsg);\n    }\n\n    @Override\n    protected void process(Host... params) {\n        Timber.d(\"Add/Edit host\");\n        Host host = params[0];\n        Host original = params[1];\n\n        List<Host> hosts = mHostsManager.getHosts(false);\n        if (original == null) {\n            hosts.add(host);\n        } else {\n            hosts.get(hosts.indexOf(original)).merge(host);\n        }\n    }\n\n    @Override\n    protected int getLoadingMsgRes() {\n        return mFlagLoadingMsg ? R.string.loading_add : R.string.loading_edit;\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/task/GenericTaskAsync.java",
    "content": "package com.nilhcem.hostseditor.task;\n\nimport android.content.Context;\nimport android.os.AsyncTask;\n\nimport com.nilhcem.hostseditor.HostsEditorApplication;\nimport com.nilhcem.hostseditor.core.Host;\nimport com.nilhcem.hostseditor.core.HostsManager;\nimport com.nilhcem.hostseditor.event.LoadingEvent;\nimport com.nilhcem.hostseditor.event.TaskCompletedEvent;\nimport com.squareup.otto.Bus;\n\nimport javax.inject.Inject;\n\nimport timber.log.Timber;\n\npublic abstract class GenericTaskAsync extends AsyncTask<Host, Void, Void> {\n\n    @Inject Bus mBus;\n    @Inject HostsManager mHostsManager;\n\n    private Context mAppContext;\n    protected boolean mFlagLoadingMsg; // which loading message (between 2) to display: (singular/plural) - (add/edit).\n\n    public GenericTaskAsync(Context appContext, boolean flagMsg) {\n        mAppContext = appContext;\n        mFlagLoadingMsg = flagMsg;\n        HostsEditorApplication.get(appContext).component().inject(this);\n    }\n\n    @Override\n    protected void onPreExecute() {\n        super.onPreExecute();\n        mBus.post(new LoadingEvent(true, getLoadingMsgRes()));\n    }\n\n    @Override\n    protected Void doInBackground(Host... params) {\n        process(params);\n        if (!mHostsManager.saveHosts(mAppContext)) {\n            cancel(false);\n        }\n        return null;\n    }\n\n    @Override\n    protected void onPostExecute(Void result) {\n        super.onPostExecute(result);\n        Timber.d(\"Task fully executed\");\n        mBus.post(new TaskCompletedEvent(getClass().getSimpleName(), true));\n    }\n\n    @Override\n    protected void onCancelled() {\n        super.onCancelled();\n        Timber.w(\"Task cancelled\");\n        mBus.post(new TaskCompletedEvent(getClass().getSimpleName(), false));\n    }\n\n    /**\n     * This method should edit the main {@code List<Host>}.\n     *\n     * @param params selected Hosts from the main ListView.\n     */\n    protected abstract void process(Host... params);\n\n    protected abstract int getLoadingMsgRes();\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/task/ListHostsAsync.java",
    "content": "package com.nilhcem.hostseditor.task;\n\nimport android.content.Context;\nimport android.os.AsyncTask;\n\nimport com.nilhcem.hostseditor.HostsEditorApplication;\nimport com.nilhcem.hostseditor.R;\nimport com.nilhcem.hostseditor.core.Host;\nimport com.nilhcem.hostseditor.core.HostsManager;\nimport com.nilhcem.hostseditor.event.LoadingEvent;\nimport com.nilhcem.hostseditor.event.RefreshHostsEvent;\nimport com.squareup.otto.Bus;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport javax.inject.Inject;\n\n/**\n * AsyncTask that gets all valid hosts and triggers a {@code RefreshHostEvent} event.\n */\npublic class ListHostsAsync extends AsyncTask<Boolean, Void, List<Host>> {\n\n    @Inject Bus mBus;\n    @Inject HostsManager mHostsManager;\n\n    public ListHostsAsync(Context context) {\n        HostsEditorApplication.get(context).component().inject(this);\n    }\n\n    @Override\n    protected void onPreExecute() {\n        super.onPreExecute();\n        mBus.post(new LoadingEvent(true, R.string.loading_hosts));\n    }\n\n    @Override\n    protected List<Host> doInBackground(Boolean... params) {\n        Boolean forceRefresh = params[0];\n        if (forceRefresh == null) {\n            forceRefresh = false;\n        }\n\n        List<Host> allHosts = mHostsManager.getHosts(forceRefresh);\n\n        // Filter to get only valid hosts\n        List<Host> validHosts = new ArrayList<>();\n        for (Host host : allHosts) {\n            if (host.isValid()) {\n                validHosts.add(host);\n            }\n        }\n        return validHosts;\n    }\n\n    @Override\n    protected void onPostExecute(List<Host> result) {\n        super.onPostExecute(result);\n        mBus.post(new RefreshHostsEvent(result));\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/task/RemoveHostsAsync.java",
    "content": "package com.nilhcem.hostseditor.task;\n\nimport android.content.Context;\n\nimport com.nilhcem.hostseditor.R;\nimport com.nilhcem.hostseditor.core.Host;\n\nimport java.util.List;\n\nimport timber.log.Timber;\n\n/**\n * AsyncTask that removes one or many host entries and triggers a {@code TaskCompletedEvent} event.\n */\npublic class RemoveHostsAsync extends GenericTaskAsync {\n\n    public RemoveHostsAsync(Context appContext, boolean flagMsg) {\n        super(appContext, flagMsg);\n    }\n\n    @Override\n    protected void process(Host... params) {\n        Timber.d(\"Remove hosts\");\n\n        List<Host> hosts = mHostsManager.getHosts(false);\n        for (Host host : params) {\n            hosts.remove(host);\n        }\n    }\n\n    @Override\n    protected int getLoadingMsgRes() {\n        return mFlagLoadingMsg ? R.string.loading_remove_single : R.string.loading_remove_multiple;\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/task/ToggleHostsAsync.java",
    "content": "package com.nilhcem.hostseditor.task;\n\nimport android.content.Context;\n\nimport com.nilhcem.hostseditor.R;\nimport com.nilhcem.hostseditor.core.Host;\n\nimport timber.log.Timber;\n\n/**\n * AsyncTask that toggles one or many host entries and triggers a {@code TaskCompletedEvent} event.\n */\npublic class ToggleHostsAsync extends GenericTaskAsync {\n\n    public ToggleHostsAsync(Context appContext, boolean flagMsg) {\n        super(appContext, flagMsg);\n    }\n\n    @Override\n    protected void process(Host... params) {\n        Timber.d(\"Toggle hosts\");\n\n        for (Host host : params) {\n            host.toggleComment();\n        }\n    }\n\n    @Override\n    protected int getLoadingMsgRes() {\n        return mFlagLoadingMsg ? R.string.loading_toggle_single : R.string.loading_toggle_multiple;\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/ui/BaseActivity.java",
    "content": "package com.nilhcem.hostseditor.ui;\n\nimport android.os.Bundle;\n\nimport com.actionbarsherlock.app.SherlockFragmentActivity;\nimport com.nilhcem.hostseditor.HostsEditorApplication;\nimport com.squareup.otto.Bus;\n\nimport javax.inject.Inject;\n\n/**\n * All activities should extend this for dependency injection.\n */\npublic abstract class BaseActivity extends SherlockFragmentActivity {\n\n    @Inject protected Bus mBus;\n    protected HostsEditorApplication mApp;\n\n    @Override\n    protected void onCreate(Bundle state) {\n        super.onCreate(state);\n        mApp = HostsEditorApplication.get(this);\n        mApp.component().inject(this);\n    }\n\n    @Override\n    protected void onResume() {\n        super.onResume();\n        mBus.register(this);\n    }\n\n    @Override\n    protected void onPause() {\n        mBus.unregister(this);\n        super.onPause();\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/ui/BaseFragment.java",
    "content": "package com.nilhcem.hostseditor.ui;\n\nimport android.app.Activity;\nimport android.os.Bundle;\n\nimport com.actionbarsherlock.app.SherlockFragment;\nimport com.actionbarsherlock.app.SherlockFragmentActivity;\nimport com.nilhcem.hostseditor.BuildConfig;\nimport com.nilhcem.hostseditor.HostsEditorApplication;\nimport com.squareup.otto.Bus;\n\nimport javax.inject.Inject;\n\n/**\n * All fragments should extend this for dependency injection.\n */\npublic class BaseFragment extends SherlockFragment {\n\n    @Inject protected Bus mBus;\n\n    protected HostsEditorApplication mApp;\n    protected SherlockFragmentActivity mActivity;\n\n    @Override\n    public void onAttach(Activity activity) {\n        if (BuildConfig.DEBUG && !(activity instanceof SherlockFragmentActivity)) {\n            throw new UnsupportedOperationException(\"Activity must be a SherlockFragmentActivity\");\n        }\n\n        super.onAttach(activity);\n        mApp = HostsEditorApplication.get(activity);\n        mActivity = (SherlockFragmentActivity) activity;\n    }\n\n    @Override\n    public void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setRetainInstance(true);\n    }\n\n    @Override\n    public void onResume() {\n        super.onResume();\n        mBus.register(this);\n    }\n\n    @Override\n    public void onPause() {\n        mBus.unregister(this);\n        super.onPause();\n    }\n\n    @Override\n    public void onDetach() {\n        mApp = null;\n        mActivity = null;\n        super.onDetach();\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/ui/about/AboutDialogFragment.java",
    "content": "package com.nilhcem.hostseditor.ui.about;\n\nimport android.content.Intent;\nimport android.net.Uri;\nimport android.os.Bundle;\nimport android.view.LayoutInflater;\nimport android.view.View;\nimport android.view.ViewGroup;\n\nimport com.actionbarsherlock.app.SherlockDialogFragment;\nimport com.nilhcem.hostseditor.R;\n\nimport butterknife.ButterKnife;\nimport butterknife.OnClick;\n\npublic class AboutDialogFragment extends SherlockDialogFragment {\n\n    public static final String TAG = AboutDialogFragment.class.getSimpleName();\n    private static final String GITHUB_URL = \"https://github.com/Nilhcem/hosts-editor-android\";\n\n    @Override\n    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {\n        View view = inflater.inflate(R.layout.about_dialog, container, false);\n        ButterKnife.bind(this, view);\n        getDialog().setTitle(R.string.about_title);\n        return view;\n    }\n\n    @Override\n    public void onDestroyView() {\n        ButterKnife.unbind(this);\n        super.onDestroyView();\n    }\n\n    @OnClick(R.id.aboutGitHub)\n    void openGitHubUrl() {\n        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(GITHUB_URL));\n        startActivity(browserIntent);\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/ui/addedit/AddEditHostActivity.java",
    "content": "package com.nilhcem.hostseditor.ui.addedit;\n\nimport android.content.Intent;\nimport android.os.Bundle;\nimport android.support.v4.app.FragmentManager;\nimport android.support.v4.app.FragmentTransaction;\n\nimport com.actionbarsherlock.app.ActionBar;\nimport com.actionbarsherlock.view.Menu;\nimport com.actionbarsherlock.view.MenuItem;\nimport com.nilhcem.hostseditor.R;\nimport com.nilhcem.hostseditor.core.Host;\nimport com.nilhcem.hostseditor.event.CreatedHostEvent;\nimport com.nilhcem.hostseditor.ui.BaseActivity;\nimport com.nilhcem.hostseditor.ui.list.ListHostsActivity;\nimport com.squareup.otto.Subscribe;\n\npublic class AddEditHostActivity extends BaseActivity {\n\n    public static final String EXTRA_HOST_ORIGINAL = \"hostOriginal\"; // useful in Edit mode, this is the original Host entry before being edited.\n    public static final String EXTRA_HOST_MODIFIED = \"hostModified\"; // the new Host entry, after having been edited.\n\n    private AddEditHostFragment mFragment;\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n\n        Host hostToEdit = getHostFromIntent();\n        initActionBar(hostToEdit);\n\n        // Add fragment\n        FragmentManager fm = getSupportFragmentManager();\n        mFragment = (AddEditHostFragment) fm.findFragmentByTag(AddEditHostFragment.TAG);\n        if (mFragment == null) {\n            mFragment = AddEditHostFragment.newInstance(hostToEdit);\n            FragmentTransaction ft = fm.beginTransaction();\n            ft.replace(android.R.id.content, mFragment, AddEditHostFragment.TAG);\n            ft.commit();\n        }\n    }\n\n    @Override\n    public boolean onCreateOptionsMenu(Menu menu) {\n        getSupportMenuInflater().inflate(R.menu.add_edit_menu, menu);\n        return true;\n    }\n\n    @Override\n    public boolean onPrepareOptionsMenu(Menu menu) {\n        MenuItem item = menu.findItem(R.id.action_add_rm_comment);\n        if (mFragment.hasComment()) {\n            item.setTitle(R.string.action_remove_comment);\n        } else {\n            item.setTitle(R.string.action_add_comment);\n        }\n        return super.onPrepareOptionsMenu(menu);\n    }\n\n    @Override\n    public boolean onOptionsItemSelected(MenuItem item) {\n        switch (item.getItemId()) {\n            case android.R.id.home:\n                Intent intent = new Intent(this, ListHostsActivity.class);\n                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);\n                startActivity(intent);\n                return true;\n            case R.id.action_add_rm_comment:\n                mFragment.toggleCommentVisibility();\n                return true;\n            default:\n                return super.onOptionsItemSelected(item);\n        }\n    }\n\n    @Subscribe\n    public void onHostCreatedFromFragment(CreatedHostEvent event) {\n        Intent returnIntent = new Intent();\n        returnIntent.putExtra(EXTRA_HOST_ORIGINAL, event.originalHost);\n        returnIntent.putExtra(EXTRA_HOST_MODIFIED, event.editedHost);\n        setResult(RESULT_OK, returnIntent);\n        finish();\n    }\n\n    private Host getHostFromIntent() {\n        Host host = null;\n\n        Bundle bundle = getIntent().getExtras();\n        if (bundle != null) {\n            host = bundle.getParcelable(EXTRA_HOST_ORIGINAL);\n        }\n        return host;\n    }\n\n    private void initActionBar(Host hostToEdit) {\n        int titleRes;\n        if (hostToEdit == null) {\n            titleRes = R.string.add_host_title;\n        } else {\n            titleRes = R.string.edit_host_title;\n        }\n\n        ActionBar actionBar = getSupportActionBar();\n        actionBar.setDisplayHomeAsUpEnabled(true);\n        actionBar.setDisplayShowTitleEnabled(true);\n        actionBar.setTitle(titleRes);\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/ui/addedit/AddEditHostFragment.java",
    "content": "package com.nilhcem.hostseditor.ui.addedit;\n\nimport android.app.AlertDialog;\nimport android.content.DialogInterface;\nimport android.os.Bundle;\nimport android.text.TextUtils;\nimport android.view.LayoutInflater;\nimport android.view.View;\nimport android.view.ViewGroup;\nimport android.widget.Button;\nimport android.widget.EditText;\nimport android.widget.TextView;\n\nimport com.nilhcem.hostseditor.R;\nimport com.nilhcem.hostseditor.core.Host;\nimport com.nilhcem.hostseditor.core.util.InetAddresses;\nimport com.nilhcem.hostseditor.event.CreatedHostEvent;\nimport com.nilhcem.hostseditor.ui.BaseFragment;\n\nimport java.util.regex.Pattern;\n\nimport butterknife.Bind;\nimport butterknife.ButterKnife;\nimport butterknife.OnClick;\n\npublic class AddEditHostFragment extends BaseFragment {\n\n    public static final String TAG = AddEditHostFragment.class.getSimpleName();\n\n    private static final String ARG_HOST = \"mInitialHost\";\n    private static final Pattern HOSTNAME_INVALID_CHARS_PATTERN = Pattern.compile(\"^.*[#'\\\",\\\\\\\\]+.*$\");\n\n    private Host mInitialHost; // \"edit mode\" only - null for \"add mode\"\n    private AlertDialog mErrorAlert;\n\n    @Bind(R.id.addEditHostIp) EditText mIp;\n    @Bind(R.id.addEditHostName) EditText mHostName;\n    @Bind(R.id.addEditComment) EditText mComment;\n    @Bind(R.id.addEditCommentLabel) TextView mCommentLabel;\n    @Bind(R.id.addEditHostButton) Button mButton;\n\n    public static AddEditHostFragment newInstance(Host hostToEdit) {\n        AddEditHostFragment fragment = new AddEditHostFragment();\n\n        if (hostToEdit != null) {\n            Bundle args = new Bundle();\n            args.putParcelable(ARG_HOST, hostToEdit);\n            fragment.setArguments(args);\n        }\n        return fragment;\n    }\n\n    @Override\n    public void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        mApp.component().inject(this);\n        Bundle arguments = getArguments();\n        if (arguments != null) {\n            mInitialHost = arguments.getParcelable(ARG_HOST);\n        }\n    }\n\n    @Override\n    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {\n        View view = inflater.inflate(R.layout.add_edit_host_layout, container, false);\n        ButterKnife.bind(this, view);\n\n        if (mInitialHost == null) {\n            mButton.setText(R.string.add_host_title);\n        } else {\n            mIp.setText(mInitialHost.getIp());\n            mHostName.setText(mInitialHost.getHostName());\n            mButton.setText(R.string.edit_host_title);\n\n            String comment = mInitialHost.getComment();\n            if (!TextUtils.isEmpty(comment)) {\n                mComment.setText(comment);\n                toggleCommentVisibility();\n            }\n        }\n        return view;\n    }\n\n    @Override\n    public void onStop() {\n        if (mErrorAlert != null) {\n            mErrorAlert.dismiss();\n        }\n        super.onStop();\n    }\n\n    @Override\n    public void onDestroyView() {\n        ButterKnife.unbind(this);\n        super.onDestroyView();\n    }\n\n    @OnClick(R.id.addEditHostButton)\n    void onAddEditHostButtonClicked(Button button) {\n        if (button.getId() == R.id.addEditHostButton) {\n            String ip = mIp.getText().toString();\n            String hostname = mHostName.getText().toString();\n            String comment = mComment.getText().toString();\n            if (TextUtils.isEmpty(comment)) {\n                comment = null;\n            }\n            int error = checkFormErrors(ip, hostname);\n\n            if (error == 0) {\n                Host edited = new Host(ip, hostname, comment, false, true);\n                mBus.post(new CreatedHostEvent(mInitialHost, edited));\n            } else {\n                mErrorAlert = new AlertDialog.Builder(mActivity)\n                        .setTitle(R.string.add_edit_error_title)\n                        .setMessage(error)\n                        .setCancelable(true)\n                        .setNeutralButton(R.string.add_edit_error_ok, new DialogInterface.OnClickListener() {\n                            @Override\n                            public void onClick(DialogInterface dialog, int which) {\n                                // Do nothing\n                            }\n                        })\n                        .create();\n                mErrorAlert.show();\n            }\n        }\n    }\n\n    public boolean hasComment() {\n        return mComment.getVisibility() == View.VISIBLE;\n    }\n\n    public void toggleCommentVisibility() {\n        int visibility;\n        if (hasComment()) {\n            visibility = View.GONE;\n            mComment.setText(\"\");\n        } else {\n            visibility = View.VISIBLE;\n        }\n\n        mComment.setVisibility(visibility);\n        mCommentLabel.setVisibility(visibility);\n    }\n\n    private int checkFormErrors(String ip, String hostname) {\n        int error = 0;\n\n        if (TextUtils.isEmpty(hostname) || HOSTNAME_INVALID_CHARS_PATTERN.matcher(hostname).matches()) {\n            error = R.string.add_edit_error_hostname;\n        }\n        if (TextUtils.isEmpty(ip) || !InetAddresses.isInetAddress(ip)) {\n            error = R.string.add_edit_error_ip;\n        }\n        return error;\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/ui/list/ListHostsActivity.java",
    "content": "package com.nilhcem.hostseditor.ui.list;\n\nimport android.content.Intent;\nimport android.os.Bundle;\nimport android.support.v4.app.FragmentManager;\nimport android.support.v4.app.FragmentTransaction;\nimport android.text.TextUtils;\nimport android.view.KeyEvent;\nimport android.view.View;\nimport android.widget.ProgressBar;\nimport android.widget.TextView;\n\nimport com.actionbarsherlock.view.Menu;\nimport com.actionbarsherlock.view.MenuItem;\nimport com.actionbarsherlock.widget.SearchView;\nimport com.nilhcem.hostseditor.R;\nimport com.nilhcem.hostseditor.core.Host;\nimport com.nilhcem.hostseditor.event.LoadingEvent;\nimport com.nilhcem.hostseditor.event.StartAddEditActivityEvent;\nimport com.nilhcem.hostseditor.ui.BaseActivity;\nimport com.nilhcem.hostseditor.ui.about.AboutDialogFragment;\nimport com.nilhcem.hostseditor.ui.addedit.AddEditHostActivity;\nimport com.squareup.otto.Subscribe;\n\nimport butterknife.Bind;\nimport butterknife.ButterKnife;\nimport timber.log.Timber;\n\npublic class ListHostsActivity extends BaseActivity {\n\n    private static final int REQUESTCODE_ADDEDIT_ACTIVITY = 1;\n    private static final String STR_EMPTY = \"\";\n    private static final String INSTANCE_STATE_LOADING = \"loading\";\n    private static final String INSTANCE_STATE_LOADING_MESSAGE = \"loadingMessage\";\n    private static final String INSTANCE_STATE_SEARCH = \"search\";\n\n    @Bind(R.id.listLoading) ProgressBar mProgressBar;\n    @Bind(R.id.listLoadingMsg) TextView mLoadingMsg;\n\n    private ListHostsFragment mFragment;\n    private String mSearchQuery = STR_EMPTY;\n    private MenuItem mSearchItem;\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.list_hosts_layout);\n        ButterKnife.bind(this);\n\n        FragmentManager fm = getSupportFragmentManager();\n        mFragment = (ListHostsFragment) fm.findFragmentById(R.id.listHostsFragment);\n\n        if (savedInstanceState == null) {\n            onLoadingEvent(new LoadingEvent(true, R.string.loading_hosts));\n        }\n    }\n\n    @Override\n    public boolean onCreateOptionsMenu(Menu menu) {\n        getSupportMenuInflater().inflate(R.menu.list_menu, menu);\n\n        // Init search\n        mSearchItem = menu.findItem(R.id.action_search);\n        SearchView searchView = (SearchView) mSearchItem.getActionView();\n        if (searchView != null) {\n            searchView.setQueryHint(getString(R.string.action_search));\n            searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {\n                @Override\n                public boolean onQueryTextSubmit(String query) {\n                    mSearchItem.collapseActionView();\n                    return true;\n                }\n\n                @Override\n                public boolean onQueryTextChange(String newText) {\n                    Timber.d(\"Search query: %s\", newText);\n                    setSearchQuery(newText);\n                    mFragment.filterList(newText);\n                    return true;\n                }\n            });\n        }\n        return true;\n    }\n\n    @Override\n    protected void onResume() {\n        super.onResume();\n        mFragment.filterList(mSearchQuery);\n    }\n\n    @Override\n    public boolean onKeyDown(int keyCode, KeyEvent event) {\n        switch (keyCode) {\n            case KeyEvent.KEYCODE_BACK:\n                if (!TextUtils.isEmpty(mSearchQuery)) {\n                    // Revert search\n                    setSearchQuery(STR_EMPTY);\n                    mFragment.filterList(mSearchQuery);\n                    return true;\n                }\n                break;\n            case KeyEvent.KEYCODE_SEARCH:\n                mSearchItem.expandActionView();\n                return true;\n        }\n        return super.onKeyDown(keyCode, event);\n    }\n\n    @Override\n    public boolean onOptionsItemSelected(MenuItem item) {\n        switch (item.getItemId()) {\n            case R.id.action_add_host:\n                mBus.post(new StartAddEditActivityEvent(null));\n                return true;\n            case R.id.action_reload_hosts:\n                mFragment.refreshHosts(true);\n                return true;\n            case R.id.action_select_all:\n                mFragment.selectAll();\n                return true;\n            case R.id.action_about:\n                displayAboutDialog();\n                return true;\n            default:\n                return super.onOptionsItemSelected(item);\n        }\n    }\n\n    @Override\n    protected void onActivityResult(int requestCode, int resultCode, Intent data) {\n        super.onActivityResult(requestCode, resultCode, data);\n\n        Timber.d(\"Activity result received\");\n        if (requestCode == REQUESTCODE_ADDEDIT_ACTIVITY) {\n            if (resultCode == RESULT_OK) {\n                Host modified = data.getParcelableExtra(AddEditHostActivity.EXTRA_HOST_MODIFIED);\n                Host original = data.getParcelableExtra(AddEditHostActivity.EXTRA_HOST_ORIGINAL);\n\n                boolean addMode = (original == null);\n                onLoadingEvent(new LoadingEvent(true, addMode ? R.string.loading_add : R.string.loading_edit));\n                mFragment.addEditHost(addMode, new Host[]{modified, original});\n            }\n        }\n    }\n\n    @Override\n    protected void onSaveInstanceState(Bundle outState) {\n        super.onSaveInstanceState(outState);\n        outState.putBoolean(INSTANCE_STATE_LOADING, mProgressBar.getVisibility() == View.VISIBLE);\n        outState.putString(INSTANCE_STATE_LOADING_MESSAGE, mLoadingMsg.getText().toString());\n        outState.putString(INSTANCE_STATE_SEARCH, mSearchQuery);\n    }\n\n    @Override\n    protected void onRestoreInstanceState(Bundle savedInstanceState) {\n        super.onRestoreInstanceState(savedInstanceState);\n        boolean isLoading = savedInstanceState.getBoolean(INSTANCE_STATE_LOADING, true);\n\n        if (isLoading) {\n            String loadingMsg = savedInstanceState.getString(INSTANCE_STATE_LOADING_MESSAGE);\n            if (loadingMsg == null) {\n                loadingMsg = STR_EMPTY;\n            }\n            onLoadingEvent(new LoadingEvent(true, loadingMsg));\n        }\n        setSearchQuery(savedInstanceState.getString(INSTANCE_STATE_SEARCH));\n    }\n\n    @Override\n    protected void onDestroy() {\n        ButterKnife.unbind(this);\n        super.onDestroy();\n    }\n\n    @Subscribe\n    public void onStartAddEditActivityEvent(StartAddEditActivityEvent event) {\n        Timber.d(\"Ready to start AddEditActivity\");\n        Intent intent = new Intent(this, AddEditHostActivity.class);\n        intent.putExtra(AddEditHostActivity.EXTRA_HOST_ORIGINAL, event.host);\n        startActivityForResult(intent, REQUESTCODE_ADDEDIT_ACTIVITY);\n    }\n\n    @Subscribe\n    public void onLoadingEvent(LoadingEvent event) {\n        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();\n\n        mLoadingMsg.setText(event.getMessage(this));\n        if (event.isLoading()) {\n            Timber.d(\"Start loading\");\n            if (mSearchItem != null) {\n                setSearchQuery(STR_EMPTY);\n                mSearchItem.collapseActionView();\n            }\n\n            mProgressBar.setVisibility(View.VISIBLE);\n            mLoadingMsg.setVisibility(View.VISIBLE);\n            ft.hide(mFragment);\n        } else {\n            Timber.d(\"Stop loading\");\n            mProgressBar.setVisibility(View.GONE);\n            mLoadingMsg.setVisibility(View.GONE);\n            ft.show(mFragment);\n        }\n        ft.commitAllowingStateLoss();\n    }\n\n    private void setSearchQuery(String searchQuery) {\n        mSearchQuery = searchQuery;\n        setActionBarTitle();\n    }\n\n    private void setActionBarTitle() {\n        int titleRes;\n\n        if (TextUtils.isEmpty(mSearchQuery)) {\n            titleRes = R.string.app_name;\n        } else {\n            titleRes = R.string.action_search_results;\n        }\n        getSupportActionBar().setTitle(titleRes);\n    }\n\n    private void displayAboutDialog() {\n        FragmentManager fm = getSupportFragmentManager();\n        AboutDialogFragment dialog = new AboutDialogFragment();\n        dialog.show(fm, AboutDialogFragment.TAG);\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/ui/list/ListHostsAdapter.java",
    "content": "package com.nilhcem.hostseditor.ui.list;\n\nimport android.content.Context;\nimport android.view.View;\nimport android.view.ViewGroup;\nimport android.widget.AbsListView.LayoutParams;\nimport android.widget.BaseAdapter;\nimport android.widget.Filter;\nimport android.widget.Filterable;\n\nimport com.nilhcem.hostseditor.core.Host;\nimport com.nilhcem.hostseditor.core.util.Compatibility;\nimport com.nilhcem.hostseditor.core.util.ThreadPreconditions;\nimport com.nilhcem.hostseditor.ui.widget.CheckableHostItem;\n\nimport java.util.Collections;\nimport java.util.List;\n\nimport javax.inject.Inject;\n\nimport timber.log.Timber;\n\npublic class ListHostsAdapter extends BaseAdapter implements Filterable {\n\n    private final ListHostsSearchFilter mSearchFilter;\n\n    private List<Host> mHosts = Collections.emptyList();\n    private Context mAppContext;\n\n    private int mIpMinWidth;\n    private int mIpMaxWidth;\n\n    @Inject public ListHostsAdapter(ListHostsSearchFilter searchFilter) {\n        mSearchFilter = searchFilter;\n    }\n\n    public void init(Context appContext) {\n        mAppContext = appContext;\n    }\n\n    public void updateHosts(List<Host> hosts) {\n        ThreadPreconditions.checkOnMainThread();\n        if (hosts == null) {\n            mHosts = Collections.emptyList();\n        } else {\n            mHosts = hosts;\n        }\n        notifyDataSetChanged();\n    }\n\n    public void computeViewWidths(Context context) {\n        // The IP column can be very large, especially when it holds ipv6 with 39 chars.\n        // Its size has to be generated programmatically, as it should fit with the device's width.\n        // A tablet can afford having a large column but not a phone.\n\n        int screenWidth = Compatibility.getScreenDimensions(context).x;\n        Timber.d(\"Screen width: %d\", screenWidth);\n\n        // 1: Compute minimum width.\n        // Min width must be between [100dp, 160dp]. If possible, 30% of screen width.\n        int minWidth = screenWidth * 30 / 100;\n        int minRange = Compatibility.convertDpToIntPixel(100f, context);\n        int maxRange = Compatibility.convertDpToIntPixel(160f, context);\n\n        if (minWidth < minRange) {\n            minWidth = minRange;\n        }\n        if (minWidth > maxRange) {\n            minWidth = maxRange;\n        }\n\n        // 2: Compute maximum width, usually 35% of screen width.\n        int maxWidth = screenWidth * 35 / 100;\n        if (maxWidth < minWidth) {\n            maxWidth = minWidth;\n        }\n\n        Timber.d(\"Min width: %d - Max width: %d\", minWidth, maxWidth);\n        mIpMinWidth = minWidth;\n        mIpMaxWidth = maxWidth;\n    }\n\n    @Override\n    public int getCount() {\n        return mHosts.size();\n    }\n\n    @Override\n    public Host getItem(int position) {\n        return mHosts.get(position);\n    }\n\n    @Override\n    public long getItemId(int position) {\n        return position;\n    }\n\n    @Override\n    public View getView(int position, View convertView, ViewGroup parent) {\n        CheckableHostItem view;\n\n        if (convertView == null) {\n            view = new CheckableHostItem(mAppContext);\n        } else {\n            view = (CheckableHostItem) convertView;\n        }\n\n        Host host = getItem(position);\n        view.init(host, mIpMinWidth, mIpMaxWidth);\n        return view;\n    }\n\n    @Override\n    public Filter getFilter() {\n        return mSearchFilter;\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/ui/list/ListHostsFragment.java",
    "content": "package com.nilhcem.hostseditor.ui.list;\n\nimport android.app.AlertDialog;\nimport android.app.Dialog;\nimport android.content.DialogInterface;\nimport android.os.Bundle;\nimport android.util.SparseBooleanArray;\nimport android.view.LayoutInflater;\nimport android.view.View;\nimport android.view.ViewGroup;\nimport android.widget.AdapterView;\nimport android.widget.AdapterView.OnItemClickListener;\nimport android.widget.AdapterView.OnItemLongClickListener;\nimport android.widget.ListView;\n\nimport com.actionbarsherlock.view.ActionMode;\nimport com.actionbarsherlock.view.Menu;\nimport com.actionbarsherlock.view.MenuInflater;\nimport com.actionbarsherlock.view.MenuItem;\nimport com.nilhcem.hostseditor.R;\nimport com.nilhcem.hostseditor.core.Host;\nimport com.nilhcem.hostseditor.event.LoadingEvent;\nimport com.nilhcem.hostseditor.event.RefreshHostsEvent;\nimport com.nilhcem.hostseditor.event.StartAddEditActivityEvent;\nimport com.nilhcem.hostseditor.event.TaskCompletedEvent;\nimport com.nilhcem.hostseditor.task.AddEditHostAsync;\nimport com.nilhcem.hostseditor.task.ListHostsAsync;\nimport com.nilhcem.hostseditor.task.RemoveHostsAsync;\nimport com.nilhcem.hostseditor.task.ToggleHostsAsync;\nimport com.nilhcem.hostseditor.ui.BaseFragment;\nimport com.squareup.otto.Subscribe;\n\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Locale;\n\nimport javax.inject.Inject;\n\nimport butterknife.Bind;\nimport butterknife.ButterKnife;\nimport timber.log.Timber;\n\npublic class ListHostsFragment extends BaseFragment implements OnItemClickListener, OnItemLongClickListener {\n\n    @Inject ListHostsAdapter mAdapter;\n\n    @Bind(R.id.listHosts) ListView mListView;\n\n    private ActionMode mMode;\n    private MenuItem mEditMenuItem;\n    private Dialog mDisplayedDialog;\n\n    @Override\n    public void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        mApp.component().inject(this);\n        mAdapter.init(mApp);\n    }\n\n    @Override\n    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {\n        boolean firstCall = (mListView == null);\n\n        View view = inflater.inflate(R.layout.list_hosts_fragment, container, false);\n        ButterKnife.bind(this, view);\n\n        mListView.setAdapter(mAdapter);\n        mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);\n        mListView.setFastScrollEnabled(true);\n        mListView.setItemsCanFocus(false);\n        mListView.setOnItemClickListener(this);\n        mListView.setOnItemLongClickListener(this);\n\n        View emptyLayout = view.findViewById(R.id.listEmptyLayout);\n        if (emptyLayout != null) {\n            mListView.setEmptyView(emptyLayout);\n        }\n\n        mAdapter.computeViewWidths(mActivity);\n\n        if (firstCall) {\n            refreshHosts(false);\n        }\n        return view;\n    }\n\n    @Override\n    public void onPause() {\n        finishActionMode();\n        if (mDisplayedDialog != null) {\n            mDisplayedDialog.dismiss();\n            mDisplayedDialog = null;\n        }\n        super.onPause();\n    }\n\n    @Override\n    public void onDestroyView() {\n        ButterKnife.unbind(this);\n        super.onDestroyView();\n    }\n\n    @Override\n    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {\n        int nbCheckedElements = 0;\n        SparseBooleanArray checked = mListView.getCheckedItemPositions();\n        for (int i = 0; i < checked.size(); i++) {\n            if (checked.valueAt(i)) {\n                nbCheckedElements++;\n            }\n        }\n        displayActionMode(nbCheckedElements);\n    }\n\n    @Override\n    public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {\n        if (mMode == null) {\n            Host host = mAdapter.getItem(position);\n            mBus.post(new StartAddEditActivityEvent(host));\n            return true;\n        }\n        return false;\n    }\n\n    @Subscribe\n    public void onTaskFinished(TaskCompletedEvent task) {\n        Timber.d(\"Task %s finished\", task.tag);\n        if (task.isSuccessful) {\n            refreshHosts(false);\n        } else {\n            displayErrorDialog();\n        }\n    }\n\n    @Subscribe\n    public void onHostsRefreshed(RefreshHostsEvent hosts) {\n        Timber.d(\"Refreshing listview\");\n        finishActionMode();\n        mAdapter.updateHosts(hosts.hosts);\n        mBus.post(new LoadingEvent());\n    }\n\n    public void addEditHost(boolean addMode, Host[] hosts) {\n        new AddEditHostAsync(mApp, addMode).execute(hosts);\n    }\n\n    public void refreshHosts(boolean forceRefresh) {\n        new ListHostsAsync(mApp).execute(forceRefresh);\n    }\n\n    public void selectAll() {\n        int nbElem = mAdapter.getCount();\n\n        if (nbElem > 0) {\n            for (int i = 0; i < nbElem; i++) {\n                mListView.setItemChecked(i, true);\n            }\n            displayActionMode(nbElem);\n        }\n    }\n\n    public void filterList(String filter) {\n        mAdapter.getFilter().filter(filter);\n    }\n\n    private void displayActionMode(int nbCheckedElements) {\n        if (nbCheckedElements > 0) {\n            if (mMode == null) {\n                mMode = mActivity.startActionMode(new ModeCallback());\n            }\n\n            if (mEditMenuItem != null) {\n                mEditMenuItem.setVisible(nbCheckedElements == 1);\n            }\n            mMode.setTitle(String.format(Locale.US, getString(R.string.list_menu_selected), nbCheckedElements));\n        } else {\n            finishActionMode();\n        }\n    }\n\n    private final class ModeCallback implements ActionMode.Callback {\n\n        @Override\n        public boolean onCreateActionMode(ActionMode mode, Menu menu) {\n            MenuInflater inflater = mActivity.getSupportMenuInflater();\n            inflater.inflate(R.menu.list_contextual_actions, menu);\n            return true;\n        }\n\n        @Override\n        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {\n            mEditMenuItem = menu.findItem(R.id.cab_action_edit);\n            return false;\n        }\n\n        @Override\n        public void onDestroyActionMode(ActionMode mode) {\n            for (int i = 0; i < mListView.getAdapter().getCount(); i++) {\n                mListView.setItemChecked(i, false);\n            }\n            mMode = null;\n            mEditMenuItem = null;\n        }\n\n        @Override\n        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {\n            Host[] selectedItems = getSelectedItems();\n\n            switch (item.getItemId()) {\n                case R.id.cab_action_edit:\n                    mBus.post(new StartAddEditActivityEvent(selectedItems[0]));\n                    break;\n                case R.id.cab_action_delete:\n                    displayDeleteConfirmationDialog(selectedItems);\n                    break;\n                case R.id.cab_action_toggle:\n                    new ToggleHostsAsync(mApp, selectedItems.length == 1).execute(selectedItems);\n                    break;\n                default:\n                    return false;\n            }\n            mode.finish();\n            return true;\n        }\n\n        private Host[] getSelectedItems() {\n            List<Host> items = new ArrayList<>();\n\n            int len = mListView.getCount();\n            SparseBooleanArray checked = mListView.getCheckedItemPositions();\n            for (int i = 0; i < len; i++) {\n                if (checked.get(i)) {\n                    items.add(mAdapter.getItem(i));\n                }\n            }\n            return items.toArray(new Host[items.size()]);\n        }\n    }\n\n    private void displayDeleteConfirmationDialog(final Host[] selectedItems) {\n        mDisplayedDialog = new AlertDialog.Builder(mActivity)\n                .setTitle(R.string.delete_dialog_title)\n                .setMessage(getResources().getQuantityText(R.plurals.delete_dialog_content, selectedItems.length))\n                .setPositiveButton(R.string.delete_dialog_delete, new DialogInterface.OnClickListener() {\n                    @Override\n                    public void onClick(DialogInterface dialog, int which) {\n                        new RemoveHostsAsync(mApp, selectedItems.length == 1).execute(selectedItems);\n                    }\n                })\n                .setNegativeButton(R.string.delete_dialog_cancel, new DialogInterface.OnClickListener() {\n                    @Override\n                    public void onClick(DialogInterface dialog, int which) {\n                        // Do nothing\n                    }\n                })\n                .create();\n        mDisplayedDialog.show();\n    }\n\n    private void displayErrorDialog() {\n        mBus.post(new LoadingEvent());\n        mDisplayedDialog = new AlertDialog.Builder(mActivity)\n                .setTitle(R.string.list_error_title)\n                .setMessage(R.string.list_error_content)\n                .setNeutralButton(R.string.list_error_ok, new DialogInterface.OnClickListener() {\n                    @Override\n                    public void onClick(DialogInterface dialog, int which) {\n                        refreshHosts(true);\n                    }\n                })\n                .setOnCancelListener(new DialogInterface.OnCancelListener() {\n                    @Override\n                    public void onCancel(DialogInterface dialog) {\n                        refreshHosts(true);\n                    }\n                })\n                .create();\n        mDisplayedDialog.show();\n    }\n\n    private void finishActionMode() {\n        if (mMode != null) {\n            mMode.finish();\n        }\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/ui/list/ListHostsSearchFilter.java",
    "content": "package com.nilhcem.hostseditor.ui.list;\n\nimport android.text.TextUtils;\nimport android.widget.Filter;\n\nimport com.nilhcem.hostseditor.core.Host;\nimport com.nilhcem.hostseditor.core.HostsManager;\nimport com.nilhcem.hostseditor.event.RefreshHostsEvent;\nimport com.squareup.otto.Bus;\n\nimport java.util.List;\n\nimport javax.inject.Inject;\n\nimport timber.log.Timber;\n\npublic class ListHostsSearchFilter extends Filter {\n\n    private final Bus mBus;\n    private final HostsManager mHostsManager;\n\n    @Inject public ListHostsSearchFilter(Bus bus, HostsManager hostsManager) {\n        mBus = bus;\n        mHostsManager = hostsManager;\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    @Override\n    protected void publishResults(CharSequence constraint, FilterResults results) {\n        if (!TextUtils.isEmpty(constraint)) {\n            Timber.d(\"Publishing result for: %s\", constraint);\n        }\n        mBus.post(new RefreshHostsEvent((List<Host>) results.values));\n    }\n\n    @Override\n    protected FilterResults performFiltering(CharSequence constraint) {\n        if (!TextUtils.isEmpty(constraint)) {\n            Timber.d(\"Perform filtering for: %s\", constraint);\n        }\n        FilterResults results = new FilterResults();\n        results.values = mHostsManager.filterHosts(constraint);\n        return results;\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/ui/widget/CheckableHostItem.java",
    "content": "package com.nilhcem.hostseditor.ui.widget;\n\nimport android.content.Context;\nimport android.content.res.Resources;\nimport android.text.TextUtils;\nimport android.view.LayoutInflater;\nimport android.view.View;\nimport android.widget.Checkable;\nimport android.widget.RelativeLayout;\nimport android.widget.TextView;\n\nimport com.nilhcem.hostseditor.R;\nimport com.nilhcem.hostseditor.core.Host;\n\nimport java.util.Locale;\n\nimport butterknife.Bind;\nimport butterknife.ButterKnife;\n\n/**\n * Custom component that implements the Checkable interface.\n *\n * @see \"http://www.marvinlabs.com/2010/10/29/custom-listview-ability-check-items/\"\n */\npublic class CheckableHostItem extends RelativeLayout implements Checkable {\n\n    @Bind(R.id.hostItemIp) TextView mIp;\n    @Bind(R.id.hostItemHostname) TextView mHostname;\n    @Bind(R.id.hostItemComment) TextView mComment;\n    @Bind(R.id.hostItemCheckbox) InertCheckBox mCheckbox;\n\n    private int mTextColor;\n    private int mCommentColor;\n\n    public CheckableHostItem(Context context) {\n        super(context);\n        initLayout(context);\n    }\n\n    private void initLayout(Context context) {\n        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);\n        View view = inflater.inflate(R.layout.checkable_host_item, this, true);\n        ButterKnife.bind(this, view);\n\n        Resources res = context.getResources();\n        mTextColor = res.getColor(R.color.list_hosts_entry);\n        mCommentColor = res.getColor(R.color.list_hosts_comment);\n    }\n\n    public void init(Host host, int ipMinWidth, int ipMaxWidth) {\n        String ip = String.format(Locale.US, \"%s%s\", (host.isCommented() ? Host.STR_COMMENT : \"\"), host.getIp());\n\n        int textColor;\n        if (host.isCommented()) {\n            textColor = mCommentColor;\n        } else {\n            textColor = mTextColor;\n        }\n\n        mIp.setText(ip);\n        mIp.setTextColor(textColor);\n        mIp.setMinimumWidth(ipMinWidth);\n        mIp.setMaxWidth(ipMaxWidth);\n        mHostname.setText(host.getHostName());\n        mHostname.setTextColor(textColor);\n        mCheckbox.setChecked(false);\n\n        String comment = host.getComment();\n        if (TextUtils.isEmpty(comment)) {\n            mComment.setVisibility(View.GONE);\n        } else {\n            mComment.setText(String.format(Locale.US, \"%s%s\", Host.STR_COMMENT, comment));\n            mComment.setVisibility(View.VISIBLE);\n        }\n    }\n\n\n    @Override\n    public boolean isChecked() {\n        return mCheckbox.isChecked();\n    }\n\n    @Override\n    public void setChecked(boolean checked) {\n        mCheckbox.setChecked(checked);\n    }\n\n    @Override\n    public void toggle() {\n        mCheckbox.toggle();\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/ui/widget/InertCheckBox.java",
    "content": "package com.nilhcem.hostseditor.ui.widget;\n\nimport android.content.Context;\nimport android.util.AttributeSet;\nimport android.view.KeyEvent;\nimport android.view.MotionEvent;\nimport android.widget.CheckBox;\n\n/**\n * CheckBox that does not react to any user event in order to let the container handle them.\n */\npublic class InertCheckBox extends CheckBox {\n\n    public InertCheckBox(Context context, AttributeSet attrs, int defStyle) {\n        super(context, attrs, defStyle);\n    }\n\n    public InertCheckBox(Context context, AttributeSet attrs) {\n        super(context, attrs);\n    }\n\n    public InertCheckBox(Context context) {\n        super(context);\n    }\n\n    @Override\n    public boolean onTouchEvent(MotionEvent event) {\n        return false;\n    }\n\n    @Override\n    public boolean onKeyDown(int keyCode, KeyEvent event) {\n        return false;\n    }\n\n    @Override\n    public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {\n        return false;\n    }\n\n    @Override\n    public boolean onKeyPreIme(int keyCode, KeyEvent event) {\n        return false;\n    }\n\n    @Override\n    public boolean onKeyShortcut(int keyCode, KeyEvent event) {\n        return false;\n    }\n\n    @Override\n    public boolean onKeyUp(int keyCode, KeyEvent event) {\n        return false;\n    }\n\n    @Override\n    public boolean onTrackballEvent(MotionEvent event) {\n        return false;\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/ui/widget/TypefacedButton.java",
    "content": "package com.nilhcem.hostseditor.ui.widget;\n\nimport android.content.Context;\nimport android.util.AttributeSet;\nimport android.widget.Button;\n\n/**\n * Button using a custom font.\n *\n * @see TypefacedTextView\n */\npublic final class TypefacedButton extends Button {\n\n    public TypefacedButton(Context context, AttributeSet attrs) {\n        super(context, attrs);\n        TypefacedTextView.applyFont(context, attrs, this);\n    }\n}\n"
  },
  {
    "path": "app/src/main/java/com/nilhcem/hostseditor/ui/widget/TypefacedTextView.java",
    "content": "package com.nilhcem.hostseditor.ui.widget;\n\nimport android.content.Context;\nimport android.content.res.TypedArray;\nimport android.graphics.Typeface;\nimport android.util.AttributeSet;\nimport android.widget.TextView;\n\nimport com.nilhcem.hostseditor.R;\n\n/**\n * TextView using a custom font.\n *\n * @see \"http://stackoverflow.com/questions/4395309/android-want-to-set-custom-fonts-for-whole-application-not-runtime/9199258#9199258\"\n */\npublic final class TypefacedTextView extends TextView {\n\n    public TypefacedTextView(Context context, AttributeSet attrs) {\n        super(context, attrs);\n\n        // Typeface.createFromAsset doesn't work in the layout editor. Skipping...\n        if (isInEditMode()) {\n            return;\n        }\n\n        TypefacedTextView.applyFont(context, attrs, this);\n    }\n\n    static void applyFont(Context context, AttributeSet attrs, TextView view) {\n        TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.TypefacedTextView);\n        if (styledAttrs != null) {\n            String fontName = styledAttrs.getString(R.styleable.TypefacedTextView_typeface);\n            styledAttrs.recycle();\n\n            if (fontName != null) {\n                Typeface typeface = Typeface.createFromAsset(context.getAssets(), fontName);\n                view.setTypeface(typeface);\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "app/src/main/res/layout/about_dialog.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<ScrollView\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:paddingBottom=\"10dp\"\n    android:paddingLeft=\"16dp\"\n    android:paddingRight=\"16dp\"\n    android:paddingTop=\"10dp\">\n\n    <LinearLayout\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:orientation=\"vertical\">\n\n        <!-- Content -->\n        <com.nilhcem.hostseditor.ui.widget.TypefacedTextView\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"wrap_content\"\n            android:text=\"@string/about_text\"\n            android:textSize=\"16sp\"\n            app:typeface=\"fonts/Roboto-Regular.ttf\"/>\n\n        <!-- GitHub button -->\n        <com.nilhcem.hostseditor.ui.widget.TypefacedButton\n            android:id=\"@+id/aboutGitHub\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"wrap_content\"\n            android:layout_marginBottom=\"12dp\"\n            android:layout_marginTop=\"12dp\"\n            android:text=\"@string/about_github_button\"\n            app:typeface=\"fonts/Roboto-Regular.ttf\"/>\n\n        <!-- Date - Author -->\n        <com.nilhcem.hostseditor.ui.widget.TypefacedTextView\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"wrap_content\"\n            android:autoLink=\"web\"\n            android:gravity=\"center\"\n            android:text=\"@string/about_author\"\n            app:typeface=\"fonts/Roboto-Italic.ttf\"/>\n    </LinearLayout>\n</ScrollView>\n"
  },
  {
    "path": "app/src/main/res/layout/add_edit_host_layout.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<ScrollView\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n    xmlns:tools=\"http://schemas.android.com/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:paddingBottom=\"@dimen/activity_vertical_margin\"\n    android:paddingLeft=\"@dimen/activity_horizontal_margin\"\n    android:paddingRight=\"@dimen/activity_horizontal_margin\"\n    android:paddingTop=\"@dimen/activity_vertical_margin\">\n\n    <LinearLayout\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:orientation=\"vertical\">\n\n        <!-- IP (label) -->\n        <com.nilhcem.hostseditor.ui.widget.TypefacedTextView\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:text=\"@string/add_edit_ip\"\n            android:textSize=\"@dimen/add_edit_label_size\"\n            app:typeface=\"fonts/Roboto-Regular.ttf\"/>\n\n        <!-- IP (input) -->\n        <EditText\n            android:id=\"@+id/addEditHostIp\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"wrap_content\"\n            android:layout_marginBottom=\"@dimen/add_edit_form_margin\"\n            android:digits=\"0123456789abcdefABCDEF.:\"\n            android:ems=\"10\"\n            android:inputType=\"textNoSuggestions\">\n\n            <requestFocus/>\n        </EditText>\n\n        <!-- Hostname (label) -->\n        <com.nilhcem.hostseditor.ui.widget.TypefacedTextView\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:text=\"@string/add_edit_name\"\n            android:textSize=\"@dimen/add_edit_label_size\"\n            app:typeface=\"fonts/Roboto-Regular.ttf\"/>\n\n        <!-- Hostname (input) -->\n        <EditText\n            android:id=\"@+id/addEditHostName\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"wrap_content\"\n            android:layout_marginBottom=\"@dimen/add_edit_form_margin\"\n            android:ems=\"10\"\n            android:inputType=\"textNoSuggestions\"/>\n\n        <!-- Comment (label) - hidden by default -->\n        <com.nilhcem.hostseditor.ui.widget.TypefacedTextView\n            android:id=\"@+id/addEditCommentLabel\"\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:text=\"@string/add_edit_comment\"\n            android:textSize=\"@dimen/add_edit_label_size\"\n            android:visibility=\"gone\"\n            app:typeface=\"fonts/Roboto-Regular.ttf\"\n            tools:visibility=\"visible\"/>\n\n        <!-- Comment (input) - hidden by default -->\n        <EditText\n            android:id=\"@+id/addEditComment\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"wrap_content\"\n            android:layout_marginBottom=\"@dimen/add_edit_form_margin\"\n            android:ems=\"10\"\n            android:inputType=\"text\"\n            android:visibility=\"gone\"\n            tools:visibility=\"visible\"/>\n\n        <!-- \"Add/Edit Host\" Button -->\n        <com.nilhcem.hostseditor.ui.widget.TypefacedButton\n            android:id=\"@+id/addEditHostButton\"\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:layout_gravity=\"center_horizontal\"\n            android:layout_marginTop=\"10dp\"\n            android:drawableLeft=\"@drawable/ic_action_add_dark\"\n            android:drawablePadding=\"8dp\"\n            app:typeface=\"fonts/Roboto-Light.ttf\"\n            tools:text=\"@string/add_host_title\"/>\n    </LinearLayout>\n</ScrollView>\n"
  },
  {
    "path": "app/src/main/res/layout/checkable_host_item.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<RelativeLayout\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:tools=\"http://schemas.android.com/tools\"\n    android:layout_width=\"wrap_content\"\n    android:layout_height=\"wrap_content\"\n    android:paddingBottom=\"4dp\"\n    android:paddingTop=\"4dp\">\n\n    <!-- Left part (IP) -->\n    <TextView\n        android:id=\"@+id/hostItemIp\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:layout_alignParentLeft=\"true\"\n        android:layout_centerVertical=\"true\"\n        android:focusable=\"false\"\n        android:paddingLeft=\"8dp\"\n        android:paddingRight=\"18dp\"\n        android:textIsSelectable=\"false\"\n        android:textSize=\"16sp\"\n        tools:text=\"127.0.0.1\"/>\n\n    <!-- Middle part (hostname/comment) -->\n    <LinearLayout\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:layout_centerVertical=\"true\"\n        android:layout_toLeftOf=\"@+id/hostItemCheckbox\"\n        android:layout_toRightOf=\"@+id/hostItemIp\"\n        android:focusable=\"false\"\n        android:orientation=\"vertical\">\n\n        <!-- Hostname -->\n        <TextView\n            android:id=\"@+id/hostItemHostname\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"wrap_content\"\n            android:focusable=\"false\"\n            android:textIsSelectable=\"false\"\n            android:textSize=\"16sp\"\n            tools:text=\"localhost\"/>\n\n        <!-- Comment -->\n        <TextView\n            android:id=\"@+id/hostItemComment\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"wrap_content\"\n            android:focusable=\"false\"\n            android:textColor=\"@color/list_hosts_comment\"\n            android:textSize=\"12sp\"\n            android:visibility=\"gone\"\n            tools:text=\"#comment\"\n            tools:visibility=\"visible\"/>\n    </LinearLayout>\n\n    <!-- Right part (checkbox) -->\n    <com.nilhcem.hostseditor.ui.widget.InertCheckBox\n        android:id=\"@+id/hostItemCheckbox\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:layout_alignParentRight=\"true\"\n        android:layout_centerVertical=\"true\"\n        android:focusable=\"false\"/>\n</RelativeLayout>\n"
  },
  {
    "path": "app/src/main/res/layout/list_hosts_empty.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<ScrollView\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\">\n\n    <LinearLayout\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:gravity=\"center\"\n        android:orientation=\"vertical\">\n\n        <com.nilhcem.hostseditor.ui.widget.TypefacedTextView\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:layout_gravity=\"center\"\n            android:gravity=\"center\"\n            android:text=\"@string/list_empty\"\n            android:textSize=\"24sp\"\n            app:typeface=\"fonts/Roboto-Regular.ttf\"/>\n\n        <com.nilhcem.hostseditor.ui.widget.TypefacedTextView\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:layout_gravity=\"center\"\n            android:gravity=\"center\"\n            android:text=\"@string/list_empty_desc\"\n            android:textSize=\"12sp\"\n            app:typeface=\"fonts/Roboto-Italic.ttf\"/>\n    </LinearLayout>\n</ScrollView>\n"
  },
  {
    "path": "app/src/main/res/layout/list_hosts_fragment.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<FrameLayout\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:tools=\"http://schemas.android.com/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\">\n\n    <!-- Hosts list -->\n    <ListView\n        android:id=\"@+id/listHosts\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        tools:listitem=\"@layout/checkable_host_item\"/>\n\n    <!-- Empty layout -->\n    <ViewStub\n        android:id=\"@+id/listEmptyLayout\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:layout_gravity=\"center\"\n        android:layout=\"@layout/list_hosts_empty\"\n        android:visibility=\"gone\"/>\n</FrameLayout>\n"
  },
  {
    "path": "app/src/main/res/layout/list_hosts_layout.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<LinearLayout\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n    xmlns:tools=\"http://schemas.android.com/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:gravity=\"center\"\n    android:orientation=\"vertical\">\n\n    <!-- Hosts list -->\n    <fragment\n        android:id=\"@+id/listHostsFragment\"\n        android:name=\"com.nilhcem.hostseditor.ui.list.ListHostsFragment\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\n        tools:layout=\"@layout/list_hosts_fragment\"/>\n\n    <!-- Loading (progress bar) -->\n    <ProgressBar\n        android:id=\"@+id/listLoading\"\n        style=\"?android:attr/progressBarStyleLarge\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:visibility=\"gone\"/>\n\n    <!-- Loading (message) -->\n    <com.nilhcem.hostseditor.ui.widget.TypefacedTextView\n        android:id=\"@+id/listLoadingMsg\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:gravity=\"center\"\n        android:paddingTop=\"12dp\"\n        android:textSize=\"18sp\"\n        android:visibility=\"gone\"\n        app:typeface=\"fonts/Roboto-Regular.ttf\"/>\n</LinearLayout>\n"
  },
  {
    "path": "app/src/main/res/menu/add_edit_menu.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<menu xmlns:android=\"http://schemas.android.com/apk/res/android\">\n\n    <!-- Add / Remove comment -->\n    <item\n        android:id=\"@+id/action_add_rm_comment\"\n        android:showAsAction=\"never|withText\"\n        android:title=\"@string/action_add_comment\"/>\n</menu>\n"
  },
  {
    "path": "app/src/main/res/menu/list_contextual_actions.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<menu xmlns:android=\"http://schemas.android.com/apk/res/android\">\n\n    <!-- Edit (visible when only one element is selected) -->\n    <item\n        android:id=\"@+id/cab_action_edit\"\n        android:icon=\"@drawable/ic_action_edit\"\n        android:orderInCategory=\"1\"\n        android:showAsAction=\"ifRoom|withText\"\n        android:title=\"@string/list_menu_edit\"\n        android:visible=\"false\"/>\n\n    <!-- Toggle (comment/uncomment) -->\n    <item\n        android:id=\"@+id/cab_action_toggle\"\n        android:icon=\"@drawable/ic_action_toggle\"\n        android:orderInCategory=\"2\"\n        android:showAsAction=\"ifRoom|withText\"\n        android:title=\"@string/list_menu_toggle\"/>\n\n    <!-- Delete -->\n    <item\n        android:id=\"@+id/cab_action_delete\"\n        android:icon=\"@drawable/ic_action_delete\"\n        android:orderInCategory=\"3\"\n        android:showAsAction=\"ifRoom|withText\"\n        android:title=\"@string/list_menu_delete\"/>\n</menu>\n"
  },
  {
    "path": "app/src/main/res/menu/list_menu.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<menu xmlns:android=\"http://schemas.android.com/apk/res/android\">\n\n    <!-- Search -->\n    <item\n        android:id=\"@+id/action_search\"\n        android:actionViewClass=\"com.actionbarsherlock.widget.SearchView\"\n        android:icon=\"@drawable/ic_action_search\"\n        android:showAsAction=\"ifRoom|withText|collapseActionView\"\n        android:title=\"@string/action_search\"/>\n\n    <!-- Add host -->\n    <item\n        android:id=\"@+id/action_add_host\"\n        android:icon=\"@drawable/ic_action_add_dark\"\n        android:showAsAction=\"ifRoom|withText\"\n        android:title=\"@string/action_add_host\"/>\n\n    <!-- Reload -->\n    <item\n        android:id=\"@+id/action_reload_hosts\"\n        android:icon=\"@drawable/ic_menu_refresh\"\n        android:showAsAction=\"never|withText\"\n        android:title=\"@string/action_reload\"/>\n\n    <!-- Select all -->\n    <item\n        android:id=\"@+id/action_select_all\"\n        android:icon=\"@drawable/ic_menu_mark\"\n        android:showAsAction=\"never|withText\"\n        android:title=\"@string/action_select_all\"/>\n\n    <!-- About -->\n    <item\n        android:id=\"@+id/action_about\"\n        android:icon=\"@drawable/ic_menu_info_details\"\n        android:showAsAction=\"never|withText\"\n        android:title=\"@string/action_about\"/>\n</menu>\n"
  },
  {
    "path": "app/src/main/res/values/attrs.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <declare-styleable name=\"TypefacedTextView\">\n        <attr name=\"typeface\" format=\"string\"/>\n    </declare-styleable>\n</resources>\n"
  },
  {
    "path": "app/src/main/res/values/colors.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <color name=\"list_hosts_entry\">#fff3f3f3</color>\n    <color name=\"list_hosts_comment\">#ff909090</color>\n</resources>\n"
  },
  {
    "path": "app/src/main/res/values/dimens.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <!-- Default screen margins, per the Android Design guidelines -->\n    <dimen name=\"activity_horizontal_margin\">16dp</dimen>\n    <dimen name=\"activity_vertical_margin\">16dp</dimen>\n\n    <!-- Add/Edit host -->\n    <dimen name=\"add_edit_form_margin\">20dp</dimen>\n    <dimen name=\"add_edit_label_size\">16sp</dimen>\n</resources>\n"
  },
  {
    "path": "app/src/main/res/values/strings.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <string name=\"app_name\">Hosts Editor</string>\n\n    <!-- Action bar menu -->\n    <string name=\"action_search\">Search</string>\n    <string name=\"action_search_results\">Search results</string>\n    <string name=\"action_add_host\">Add Host</string>\n    <string name=\"action_reload\">Reload host entries</string>\n    <string name=\"action_select_all\">Select all hosts</string>\n    <string name=\"action_about\">About</string>\n\n    <!-- Add/Edit host -->\n    <string name=\"add_host_title\">Add Hostname</string>\n    <string name=\"edit_host_title\">Edit Hostname</string>\n    <string name=\"add_edit_ip\">IP Address:</string>\n    <string name=\"add_edit_name\">Hostname:</string>\n    <string name=\"add_edit_comment\">Comment:</string>\n    <string name=\"add_edit_error_title\">Error</string>\n    <string name=\"add_edit_error_ip\">IP address is invalid</string>\n    <string name=\"add_edit_error_hostname\">Hostname is invalid</string>\n    <string name=\"add_edit_error_ok\">OK</string>\n\n    <!-- Add/Edit host menu -->\n    <string name=\"action_add_comment\">Add comment</string>\n    <string name=\"action_remove_comment\">Remove comment</string>\n\n    <!-- List hosts (empty layout) -->\n    <string name=\"list_empty\">No \\'hosts\\' records found.</string>\n    <string name=\"list_empty_desc\">We couldn\\'t find any host entry.\\nFeel free to add some!</string>\n\n    <!-- List hosts (contextual menu) -->\n    <string name=\"list_menu_selected\">%d selected</string>\n    <string name=\"list_menu_edit\">Edit</string>\n    <string name=\"list_menu_delete\">Delete</string>\n    <string name=\"list_menu_toggle\">Toggle</string>\n\n    <!-- List hosts error dialog -->\n    <string name=\"list_error_title\">Error</string>\n    <string name=\"list_error_content\">Can\\'t edit hosts file, make sure you have root/SuperUser rights.\\nThe app should be allowed to request super user access.</string>\n    <string name=\"list_error_ok\">OK</string>\n\n    <!-- Delete confirmation dialog -->\n    <string name=\"delete_dialog_title\">Delete</string>\n    <plurals name=\"delete_dialog_content\">\n        <item quantity=\"one\">Delete selected host?</item>\n        <item quantity=\"other\">Delete selected hosts?</item>\n    </plurals>\n    <string name=\"delete_dialog_cancel\">Cancel</string>\n    <string name=\"delete_dialog_delete\">Delete</string>\n\n    <!-- Loading messages -->\n    <string name=\"loading_hosts\">Loading host entries</string>\n    <string name=\"loading_add\">Adding entry</string>\n    <string name=\"loading_edit\">Editing entry</string>\n    <string name=\"loading_remove_single\">Removing entry</string>\n    <string name=\"loading_remove_multiple\">Removing entries</string>\n    <string name=\"loading_toggle_single\">Toggling entry</string>\n    <string name=\"loading_toggle_multiple\">Toggling entries</string>\n\n    <!-- About -->\n    <string name=\"about_title\">About Hosts Editor</string>\n    <string name=\"about_text\">This app lets you modify your /etc/hosts file on Android.\\nYou might need to reboot to clear your DNS cache after any change.</string>\n    <string name=\"about_author\">2013 &#8211; 2015\\n<a href=\"http://www.nilhcem.com\">http://www.nilhcem.com</a></string>\n    <string name=\"about_github_button\">GitHub</string>\n</resources>\n"
  },
  {
    "path": "app/src/main/res/values/styles.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <!--\n        Base application theme, dependent on API level. This theme is replaced\n        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.\n    -->\n    <style name=\"AppBaseTheme\" parent=\"@style/Theme.Sherlock\">\n        <!--\n            Theme customizations available in newer API levels can go in\n            res/values-vXX/styles.xml, while customizations related to\n            backward-compatibility can go here.\n        -->\n    </style>\n\n    <!-- Application theme. -->\n    <style name=\"AppTheme\" parent=\"AppBaseTheme\">\n        <!-- All customizations that are NOT specific to a particular API-level can go here. -->\n    </style>\n</resources>\n"
  },
  {
    "path": "app/src/main/res/values-sw720dp-land/dimens.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <!--\n         Customize dimensions originally defined in res/values/dimens.xml (such as\n         screen margins) for sw720dp devices (e.g. 10\" tablets) in landscape here.\n    -->\n    <dimen name=\"activity_horizontal_margin\">128dp</dimen>\n</resources>\n"
  },
  {
    "path": "build.gradle",
    "content": "// Top-level build file where you can add configuration options common to all sub-projects/modules.\n\nbuildscript {\n    repositories {\n        jcenter()\n    }\n    dependencies {\n        classpath 'com.android.tools.build:gradle:1.2.3'\n        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'\n    }\n}\n\nallprojects {\n    repositories {\n        jcenter()\n    }\n}\n"
  },
  {
    "path": "gradle/wrapper/gradle-wrapper.properties",
    "content": "#Mon Jul 13 13:14:00 GMT 2015\ndistributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\nzipStoreBase=GRADLE_USER_HOME\nzipStorePath=wrapper/dists\ndistributionUrl=https\\://services.gradle.org/distributions/gradle-2.4-all.zip\n"
  },
  {
    "path": "gradlew",
    "content": "#!/usr/bin/env bash\n\n##############################################################################\n##\n##  Gradle start up script for UN*X\n##\n##############################################################################\n\n# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\nDEFAULT_JVM_OPTS=\"\"\n\nAPP_NAME=\"Gradle\"\nAPP_BASE_NAME=`basename \"$0\"`\n\n# Use the maximum available, or set MAX_FD != -1 to use that value.\nMAX_FD=\"maximum\"\n\nwarn ( ) {\n    echo \"$*\"\n}\n\ndie ( ) {\n    echo\n    echo \"$*\"\n    echo\n    exit 1\n}\n\n# OS specific support (must be 'true' or 'false').\ncygwin=false\nmsys=false\ndarwin=false\ncase \"`uname`\" in\n  CYGWIN* )\n    cygwin=true\n    ;;\n  Darwin* )\n    darwin=true\n    ;;\n  MINGW* )\n    msys=true\n    ;;\nesac\n\n# For Cygwin, ensure paths are in UNIX format before anything is touched.\nif $cygwin ; then\n    [ -n \"$JAVA_HOME\" ] && JAVA_HOME=`cygpath --unix \"$JAVA_HOME\"`\nfi\n\n# Attempt to set APP_HOME\n# Resolve links: $0 may be a link\nPRG=\"$0\"\n# Need this for relative symlinks.\nwhile [ -h \"$PRG\" ] ; do\n    ls=`ls -ld \"$PRG\"`\n    link=`expr \"$ls\" : '.*-> \\(.*\\)$'`\n    if expr \"$link\" : '/.*' > /dev/null; then\n        PRG=\"$link\"\n    else\n        PRG=`dirname \"$PRG\"`\"/$link\"\n    fi\ndone\nSAVED=\"`pwd`\"\ncd \"`dirname \\\"$PRG\\\"`/\" >&-\nAPP_HOME=\"`pwd -P`\"\ncd \"$SAVED\" >&-\n\nCLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar\n\n# Determine the Java command to use to start the JVM.\nif [ -n \"$JAVA_HOME\" ] ; then\n    if [ -x \"$JAVA_HOME/jre/sh/java\" ] ; then\n        # IBM's JDK on AIX uses strange locations for the executables\n        JAVACMD=\"$JAVA_HOME/jre/sh/java\"\n    else\n        JAVACMD=\"$JAVA_HOME/bin/java\"\n    fi\n    if [ ! -x \"$JAVACMD\" ] ; then\n        die \"ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\n    fi\nelse\n    JAVACMD=\"java\"\n    which java >/dev/null 2>&1 || die \"ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\nfi\n\n# Increase the maximum file descriptors if we can.\nif [ \"$cygwin\" = \"false\" -a \"$darwin\" = \"false\" ] ; then\n    MAX_FD_LIMIT=`ulimit -H -n`\n    if [ $? -eq 0 ] ; then\n        if [ \"$MAX_FD\" = \"maximum\" -o \"$MAX_FD\" = \"max\" ] ; then\n            MAX_FD=\"$MAX_FD_LIMIT\"\n        fi\n        ulimit -n $MAX_FD\n        if [ $? -ne 0 ] ; then\n            warn \"Could not set maximum file descriptor limit: $MAX_FD\"\n        fi\n    else\n        warn \"Could not query maximum file descriptor limit: $MAX_FD_LIMIT\"\n    fi\nfi\n\n# For Darwin, add options to specify how the application appears in the dock\nif $darwin; then\n    GRADLE_OPTS=\"$GRADLE_OPTS \\\"-Xdock:name=$APP_NAME\\\" \\\"-Xdock:icon=$APP_HOME/media/gradle.icns\\\"\"\nfi\n\n# For Cygwin, switch paths to Windows format before running java\nif $cygwin ; then\n    APP_HOME=`cygpath --path --mixed \"$APP_HOME\"`\n    CLASSPATH=`cygpath --path --mixed \"$CLASSPATH\"`\n\n    # We build the pattern for arguments to be converted via cygpath\n    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`\n    SEP=\"\"\n    for dir in $ROOTDIRSRAW ; do\n        ROOTDIRS=\"$ROOTDIRS$SEP$dir\"\n        SEP=\"|\"\n    done\n    OURCYGPATTERN=\"(^($ROOTDIRS))\"\n    # Add a user-defined pattern to the cygpath arguments\n    if [ \"$GRADLE_CYGPATTERN\" != \"\" ] ; then\n        OURCYGPATTERN=\"$OURCYGPATTERN|($GRADLE_CYGPATTERN)\"\n    fi\n    # Now convert the arguments - kludge to limit ourselves to /bin/sh\n    i=0\n    for arg in \"$@\" ; do\n        CHECK=`echo \"$arg\"|egrep -c \"$OURCYGPATTERN\" -`\n        CHECK2=`echo \"$arg\"|egrep -c \"^-\"`                                 ### Determine if an option\n\n        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition\n            eval `echo args$i`=`cygpath --path --ignore --mixed \"$arg\"`\n        else\n            eval `echo args$i`=\"\\\"$arg\\\"\"\n        fi\n        i=$((i+1))\n    done\n    case $i in\n        (0) set -- ;;\n        (1) set -- \"$args0\" ;;\n        (2) set -- \"$args0\" \"$args1\" ;;\n        (3) set -- \"$args0\" \"$args1\" \"$args2\" ;;\n        (4) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" ;;\n        (5) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" ;;\n        (6) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" ;;\n        (7) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" ;;\n        (8) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" \"$args7\" ;;\n        (9) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" \"$args7\" \"$args8\" ;;\n    esac\nfi\n\n# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules\nfunction splitJvmOpts() {\n    JVM_OPTS=(\"$@\")\n}\neval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS\nJVM_OPTS[${#JVM_OPTS[*]}]=\"-Dorg.gradle.appname=$APP_BASE_NAME\"\n\nexec \"$JAVACMD\" \"${JVM_OPTS[@]}\" -classpath \"$CLASSPATH\" org.gradle.wrapper.GradleWrapperMain \"$@\"\n"
  },
  {
    "path": "gradlew.bat",
    "content": "@if \"%DEBUG%\" == \"\" @echo off\r\n@rem ##########################################################################\r\n@rem\r\n@rem  Gradle startup script for Windows\r\n@rem\r\n@rem ##########################################################################\r\n\r\n@rem Set local scope for the variables with windows NT shell\r\nif \"%OS%\"==\"Windows_NT\" setlocal\r\n\r\n@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\r\nset DEFAULT_JVM_OPTS=\r\n\r\nset DIRNAME=%~dp0\r\nif \"%DIRNAME%\" == \"\" set DIRNAME=.\r\nset APP_BASE_NAME=%~n0\r\nset APP_HOME=%DIRNAME%\r\n\r\n@rem Find java.exe\r\nif defined JAVA_HOME goto findJavaFromJavaHome\r\n\r\nset JAVA_EXE=java.exe\r\n%JAVA_EXE% -version >NUL 2>&1\r\nif \"%ERRORLEVEL%\" == \"0\" goto init\r\n\r\necho.\r\necho ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\r\necho.\r\necho Please set the JAVA_HOME variable in your environment to match the\r\necho location of your Java installation.\r\n\r\ngoto fail\r\n\r\n:findJavaFromJavaHome\r\nset JAVA_HOME=%JAVA_HOME:\"=%\r\nset JAVA_EXE=%JAVA_HOME%/bin/java.exe\r\n\r\nif exist \"%JAVA_EXE%\" goto init\r\n\r\necho.\r\necho ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%\r\necho.\r\necho Please set the JAVA_HOME variable in your environment to match the\r\necho location of your Java installation.\r\n\r\ngoto fail\r\n\r\n:init\r\n@rem Get command-line arguments, handling Windowz variants\r\n\r\nif not \"%OS%\" == \"Windows_NT\" goto win9xME_args\r\nif \"%@eval[2+2]\" == \"4\" goto 4NT_args\r\n\r\n:win9xME_args\r\n@rem Slurp the command line arguments.\r\nset CMD_LINE_ARGS=\r\nset _SKIP=2\r\n\r\n:win9xME_args_slurp\r\nif \"x%~1\" == \"x\" goto execute\r\n\r\nset CMD_LINE_ARGS=%*\r\ngoto execute\r\n\r\n:4NT_args\r\n@rem Get arguments from the 4NT Shell from JP Software\r\nset CMD_LINE_ARGS=%$\r\n\r\n:execute\r\n@rem Setup the command line\r\n\r\nset CLASSPATH=%APP_HOME%\\gradle\\wrapper\\gradle-wrapper.jar\r\n\r\n@rem Execute Gradle\r\n\"%JAVA_EXE%\" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% \"-Dorg.gradle.appname=%APP_BASE_NAME%\" -classpath \"%CLASSPATH%\" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%\r\n\r\n:end\r\n@rem End local scope for the variables with windows NT shell\r\nif \"%ERRORLEVEL%\"==\"0\" goto mainEnd\r\n\r\n:fail\r\nrem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of\r\nrem the _cmd.exe /c_ return code!\r\nif  not \"\" == \"%GRADLE_EXIT_CONSOLE%\" exit 1\r\nexit /b 1\r\n\r\n:mainEnd\r\nif \"%OS%\"==\"Windows_NT\" endlocal\r\n\r\n:omega\r\n"
  },
  {
    "path": "settings.gradle",
    "content": "include ':app'\n"
  }
]