diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..afbdab3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser new file mode 100644 index 0000000..aec72cf Binary files /dev/null and b/.idea/caches/build_file_checksums.ser differ diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..7ac24c7 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e0d5b93 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d780875 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/BaliNumbers.iml b/BaliNumbers.iml new file mode 100644 index 0000000..0a59619 --- /dev/null +++ b/BaliNumbers.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/app.iml b/app/app.iml new file mode 100644 index 0000000..1759da4 --- /dev/null +++ b/app/app.iml @@ -0,0 +1,145 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..94b3837 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,25 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 27 + buildToolsVersion '28.0.3' + + defaultConfig { + applicationId "com.balicodes.balinumbers" + minSdkVersion 15 + targetSdkVersion 27 + versionCode 2 + versionName "1.0.1" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "com.android.support:appcompat-v7:27.1.1" +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..b04f9c7 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /home/eka/Documents/android-sdk/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/src/androidTest/java/com/balicodes/balinumbers/ApplicationTest.java b/app/src/androidTest/java/com/balicodes/balinumbers/ApplicationTest.java new file mode 100644 index 0000000..6138340 --- /dev/null +++ b/app/src/androidTest/java/com/balicodes/balinumbers/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.balicodes.balinumbers; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..6709e1f --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + diff --git a/app/src/main/assets/embassies.json b/app/src/main/assets/embassies.json new file mode 100644 index 0000000..1c8f182 --- /dev/null +++ b/app/src/main/assets/embassies.json @@ -0,0 +1,153 @@ +{ + "version": 1, + "title": "Embassies", + "list": [ + { + "title": "USA", + "title_id": "AMERIKA", + "desc": " Konsulat Jendral Denpasar", + "number": ["+62361-233605"], + "address": "Jl. Hayam Wuruk No. 188, Denpasar 80235" + }, + { + "title": "AUSTRALIA", + "desc": "Konsulat Jenderal Denpasar (Bali dan NTB)", + "number": ["+62361-241118"], + "address": "Jl. Tantular 32, Renon, Denpasar" + }, + { + "title": "UNITED KINGDOM (UK)", + "title_id": "INGGRIS", + "desc": "Konsulat Jenderal Denpasar (Bali dan Lombok)", + "number": ["+62361-270601"], + "address": "Jl. Tirta Nadi 20, Sanur, Denpasar 80238" + }, + { + "title": "BRAZIL", + "desc": "Konsulat Jenderal Bali", + "number": ["+62361-757775"], + "address": "Jl. Raya Legian No. 186, Kuta 80361" + }, + { + "title": "CHILE", + "title_id": "CHILI", + "desc": "Konsulat Jenderal Denpasar (Bali dan NTB)", + "number": ["+62361-286465"], + "address": "Jl. Pangembak 17, Sanur" + }, + { + "title": "FRANCE", + "title_id": "PRANCIS", + "desc": "Konsulat Jenderal Denpasar (Bali dan Lombok)", + "number": ["+62361-285485"], + "address": "Jl. Mertasari Gg. II No. 08, Sanur" + }, + { + "title": "GERMANY", + "title_id": "JERMAN", + "desc": "Konsulat Jenderal Denpasar (Bali dan NTB)", + "number": ["+62361-288535"], + "address": "Jl. Pantai Karang No. 17, Sanur" + }, + { + "title": "HUNGARY", + "title_id": "HUNGARIA", + "desc": "Konsulat Jenderal Denpasar", + "number": ["+62361-287701"], + "address": "Jl. By Pass Ngurah Rai No. 219, Sanur" + }, + { + "title": "ITALY", + "title_id": "ITALIA", + "desc": "Konsulat Jendral Denpasar (Bali dan NTB)", + "number": ["+62361-701005"], + "address": "Lotus Enterprise Building, Jl. Bypass Ngurah Rai, Jimbaran" + }, + { + "title": "JAPAN", + "title_id": "JEPANG", + "desc": "Konsulat Jendral Denpasar (Bali, NTB, NTT)", + "number": ["+62361-227628"], + "address": "Jl. Raya Puputan 170, Renon, Denpasar 80235" + }, + { + "title": "MALAYSIA", + "desc": "Konsulat Jendral Denpasar", + "number": ["+62361-752520"], + "address": "Jl. Pantai Kuta, Legian Bali 80030" + }, + { + "title": "MEXICO", + "title_id": "MEKSIKO", + "desc": "Konsulat Jendral Denpasar (Bali, NTB, NTT & Jayapura)", + "number": ["+62361-223266"], + "address": "Jl. Prof. Moh. Yamin No. 1A, Renon, Denpasar" + }, + { + "title": "NETHERLANDS", + "title_id": "BELANDA", + "desc": "Konsulat Jendral Denpasar (Bali dan NTB)", + "number": ["+62361-751517"], + "address": "Jl. Raya Kuta 127, Kuta 80361" + }, + { + "title": "DENMARK", + "desc": "Konsulat Jendral Denpasar (Bali dan Lombok)", + "number": ["+62361-701070"], + "address": "Mimpi Resort, Kawasan Bukit Permai, Jimbaran" + }, + { + "title": "NORWAY", + "title_id": "NORWEGIA", + "desc": "Konsulat Jendral Denpasar", + "number": ["+62361-701070"], + "address": "Mimpi Resort, Kawasan Bukit Permai, Jimbaran" + }, + { + "title": "SLOVAKIA", + "desc": "Konsulat Jendral Denpasar", + "number": ["+62361-426171", "+62361-421385"], + "address": "Jl. Gunung Agung no. 93, Denpasar 80118" + }, + { + "title": "SPAIN", + "title_id": "SPANYOL", + "desc": "Konsulat Jendral Denpasar", + "number": ["+62361-769286", "+62361-769287"], + "address": "Kompleks Istana Kuta Galeria, Blok Vallet 2, No. 11" + }, + { + "title": "SWEDEN & FINLAND", + "title_id": "SWEDIA & FINLANDIA", + "desc": "Konsulat Jendral Denpasar (Bali, NTB dan NTT)", + "number": ["+62361-282223"], + "address": "Jl. Segara Ayu, Sanur, Denpasar 80030" + }, + { + "title": "SWEDEN & FINLAND", + "title_id": "SWEDIA & FINLANDIA", + "desc": "Konsulat Jendral Denpasar (Bali, NTB dan NTT)", + "number": ["+62361-282223"], + "address": "Jl. Segara Ayu, Sanur, Denpasar 80030" + }, + { + "title": "SWITZERLAND", + "title_id": "SWISS", + "desc": "Konsulat Jendral Denpasar", + "number": ["+62361-751735", "+62361-761511"], + "address": "Kompleks Istana Kuta Galeria (former Central Parking)" + }, + { + "title": "THAILAND", + "desc": "Konsulat Jendral Denpasar", + "number": ["+62361-263310"], + "address": "Jl. Puputan Raya No. 81, Renon Denpasar 80235" + }, + { + "title": "TIMOR LESTE", + "desc": "Konsulat Jendral Denpasar", + "number": ["+62361-235093"], + "address": "Jalan Prof. Yamin No. 4, Renon Denpasar" + } + ] +} \ No newline at end of file diff --git a/app/src/main/assets/emergency.json b/app/src/main/assets/emergency.json new file mode 100644 index 0000000..d0535f1 --- /dev/null +++ b/app/src/main/assets/emergency.json @@ -0,0 +1,41 @@ +{ + "version": 1, + "title": "Emergency", + "list": [ + { + "title": "Police", + "title_id": "Polisi", + "number": ["110"] + }, + { + "title": "Ambulance", + "title_id": "Ambulan", + "number": ["118", "119"] + }, + { + "title": "Fire Fighter", + "title_id": "Pemadam Kebakaran", + "number": ["113", "1131"] + }, + { + "title": "Search and Resque", + "title_id": "Badan SAR Bali", + "number": ["115", "+62361-751115"] + }, + { + "title": "Natural Disaster", + "title_id": "Posko Bencana Alam", + "number": ["129"] + }, + { + "title": "Kuta Life Guard", + "title_id": "Penyelamat Pantai Kuta", + "number": ["+62361-755660"] + }, + { + "title": "Tourist Information", + "title_id": "Informasi Turis", + "number": ["166"] + } + ] +} \ No newline at end of file diff --git a/app/src/main/assets/fire_fighters.json b/app/src/main/assets/fire_fighters.json new file mode 100644 index 0000000..69936fb --- /dev/null +++ b/app/src/main/assets/fire_fighters.json @@ -0,0 +1,43 @@ +{ + "version": 1, + "title": "Fire Fighters", + "hotline": "113", + "list": [ + { + "title": "Denpasar", + "number": ["+62361-484013"] + }, + { + "title": "Badung", + "number": ["+62361-411333"] + }, + { + "title": "Tabanan", + "number": ["+62361-812113"] + }, + { + "title": "Buleleng", + "number": ["+62362-21113"] + }, + { + "title": "Gianyar", + "number": ["+62361-943113"] + }, + { + "title": "Bangli", + "number": ["+62361-92869"] + }, + { + "title": "Klungkung", + "number": ["+62366-22655"] + }, + { + "title": "Karangasem", + "number": ["+62363-21113"] + }, + { + "title": "Jembrana", + "number": ["+62365-41113"] + } + ] +} \ No newline at end of file diff --git a/app/src/main/assets/hospitals.json b/app/src/main/assets/hospitals.json new file mode 100644 index 0000000..ebba0f4 --- /dev/null +++ b/app/src/main/assets/hospitals.json @@ -0,0 +1,203 @@ +{ + "version": 1, + "title": "Hospitals", + "hotline": "118", + "list": [ + { + "title": "RSU Sanglah", + "number": ["+62361-227911", "+62361-227915"], + "address": "Jl. Pulau Nias, Denpasar", + "area": "Denpasar" + }, + { + "title": "RSU Bhakti Rahayu", + "number": ["+62361-430245"], + "email": "bhaktirahayu@hotmail.com", + "address": "Jl. Gatot Subroto II/11 Denpasar", + "area": "Denpasar" + }, + { + "title": "RSU Dharma Usadha", + "number": ["+62361-227560"], + "address": "Jl. PB. Sudirman No. 50, Denpasar", + "area": "Denpasar" + }, + { + "title": "RSU Dharma Yadnya", + "number": ["+62361-462488"], + "address": "Jl. W.R. Supratman No. 256, Denpasar Timur", + "area": "Denpasar" + }, + { + "title": "RSJ Bina Atma", + "number": ["+62361-437462", "+62361-425744"], + "address": "Jl. Cokroaminoto Km 5, Denpasar", + "area": "Denpasar" + }, + { + "title": "RS Kasih Ibu", + "number": ["+62361-223036"], + "email": "kasih.ibu@telkom.net", + "address": "Jl. Teuku Umar No. 120, Denpasar", + "area": "Denpasar" + }, + { + "title": "RSU Manuaba", + "number": ["+62361-426393"], + "address": "Jl. HOS Cokroaminoto No. 28, Denpasar", + "area": "Denpasar" + }, + { + "title": "RS Penyakit Dalam Sari Dharma", + "number": ["+62361-226866"], + "address": "Jl. P Seram 8, Denpasar", + "area": "Denpasar" + }, + { + "title": "RS Trijata", + "number": ["+62361-234670"], + "address": "Jl. Trijata No. 32, Denpasar", + "area": "Denpasar" + }, + { + "title": "RSU Puri Rahardja", + "number": ["+62361-222013"], + "address": "Jl. W.R. Supratman No. 14, Denpasar", + "area": "Denpasar" + }, + { + "title": "RSU Niti Mandala", + "number": ["+62361-265105"], + "address": "Jl. Tekad Unda No. 1, Denpasar", + "area": "Denpasar" + }, + { + "title": "RSU Surya Husadha", + "number": ["+62361-233787"], + "address": "Jl. Pulau Serangan 1, Denpasar", + "area": "Denpasar" + }, + { + "title": "RSU Udayana", + "number": ["+62361-228061", "+62361-228003"], + "address": "Jl. PB Sudirman No. 1, Denpasar", + "area": "Denpasar" + }, + { + "title": "RSUD Wangaya", + "number": ["+62361-222141", "+62361-222142"], + "address": "Jl. Kartini No. 133, Denpasar", + "area": "Denpasar" + }, + { + "title": "BIMC Hospital", + "number": ["+62361-761263"], + "email": "info@bimcbali.com", + "address": "Jl. Bypass Ngurah Rai 100 X, Kuta 80361", + "area": "Denpasar" + }, + { + "title": "RSU Graha Asih", + "number": ["+62361-764860"], + "email": "info@grahaasih.com", + "address": "Jalan I Gusti Ngurah Rai No. 33X, Kuta", + "area": "Denpasar" + }, + { + "title": "RSUD Sanjiwani Gianyar", + "number": ["+62361-943020"], + "address": "Jl. Ciung Wanara No. 2, Gianyar", + "area": "Gianyar" + }, + { + "title": "RSU Ari Santi", + "number": ["+62361-974573"], + "address": "Jl. Raya Mas, Ubud, Gianyar", + "area": "Gianyar" + }, + { + "title": "RS Dharma Kerti", + "number": ["+62361-811424"], + "address": "Jl. Teratai No. 16, Tabanan", + "area": "Tabanan" + }, + { + "title": "RSU Gelgel", + "number": ["+62361-811444", "+62361-812359"], + "address": "Jl. Mawar No. 76, Tabanan", + "area": "Tabanan" + }, + { + "title": "RSU Tabanan", + "number": ["+62361-811027"], + "address": "Jl. Pahlawan No. 14, Tabanan", + "area": "Tabanan" + }, + { + "title": "RSJ Propinsi Bali", + "number": ["+62366-91073"], + "address": "Jl. Kusuma Yudha No. 29, Bangli", + "area": "Bangli" + }, + { + "title": "RSUD Bangli", + "number": ["+62366-91002", "+62366-91521"], + "address": "Jl. Kusuma Yudha No. 27, Bangli", + "area": "Bangli" + }, + { + "title": "RSU Karya Dharma Husada", + "number": ["+62362-21890"], + "address": "Jl. Yudistira No.7, Singaraja", + "area": "Singaraja" + }, + { + "title": "RSU Kertha Usada", + "number": ["+62362-26277"], + "address": "Jl. Cendrawasih No. 5, Singaraja", + "area": "Singaraja" + }, + { + "title": "RS Khusus Bedah Graha Juanda", + "number": ["+62361-423467"], + "address": "Jl. Cokroaminoto No. 30, Singaraja", + "area": "Singaraja" + }, + { + "title": "RSU Singaraja", + "number": ["+62362-22046"], + "address": "Jl. I Gusti Ngurah Rai No.30, Singaraja", + "area": "Singaraja" + }, + { + "title": "RS TNI-AD Singaraja", + "number": ["+62362-22543"], + "address": "Jl. Ngurah Rai No. 70, Singaraja", + "area": "Singaraja" + }, + { + "title": "RSUD Klungkung", + "number": ["+62366-21172"], + "address": "Jl. Flamboyan No. 40 Semarapura, Klungkung", + "area": "Klungkung" + }, + { + "title": "RS Semara Husada", + "number": ["+62361-21043"], + "address": "Jl. Patimura No. 23, Semarapura", + "area": "Klungkung" + }, + { + "title": "RSU Negara", + "number": ["+62365-41006"], + "address": "Jl. Wijaya Kusuma No. 17, Negara", + "area": "Jembrana" + }, + { + "title": "RSU Amlapura", + "number": ["+62366-21470"], + "address": "Jl. Ngurah Rai, Amlapura", + "area": "Karangasem" + } + ] +} \ No newline at end of file diff --git a/app/src/main/assets/police.json b/app/src/main/assets/police.json new file mode 100644 index 0000000..b18f22b --- /dev/null +++ b/app/src/main/assets/police.json @@ -0,0 +1,67 @@ +{ + "version": 1, + "title": "Police", + "hotline": "110", + "list": [ + { + "title": "POLDA Bali", + "number": ["+62361-223699"] + }, + { + "title": "POLTABES Denpasar", + "number": ["+62361-427352"] + }, + { + "title": "Polsek Kota Denpasar", + "number": ["+62361-224456"] + }, + { + "title": "Polsek Sanur", + "number": ["+62361-288597"] + }, + { + "title": "Polsek Kuta", + "number": ["+62361-751598"] + }, + { + "title": "Polsek Bualu", + "number": ["+62361-772110"] + }, + { + "title": "Polsek Mengwi", + "number": ["+62361-411270"] + }, + { + "title": "Polres Gianyar", + "number": ["+62361-945820"] + }, + { + "title": "Polres Tabanan", + "number": ["+62361-814432"] + }, + { + "title": "Polres Buleleng", + "number": ["+62362-22331"] + }, + { + "title": "Polres Bangli", + "number": ["+62361-91561"] + }, + { + "title": "Polres Klungkung", + "number": ["+62366-22169"] + }, + { + "title": "Polres Karangasem", + "number": ["+62363-23155"] + }, + { + "title": "Polres Jembrana", + "number": ["+62365-23155"] + }, + { + "title": "Polres Gianyar", + "number": ["+62361-945820"] + } + ] +} \ No newline at end of file diff --git a/app/src/main/assets/taxi.json b/app/src/main/assets/taxi.json new file mode 100644 index 0000000..2450d9e --- /dev/null +++ b/app/src/main/assets/taxi.json @@ -0,0 +1,38 @@ +{ + "version": 1, + "title": "Taxi", + "list": [ + { + "title": "Bali Taxi / Blue Bird", + "number": ["+62361-701111"] + }, + { + "title": "Ramayana Taxi", + "number": ["+62361-765303"] + }, + { + "title": "Rajawali Taxi", + "number": ["+62361-484537"] + }, + { + "title": "Airport Taxi", + "number": ["+62361-751011"] + }, + { + "title": "Komotra Taxi", + "number": ["+62361-759102"] + }, + { + "title": "Ngurah Rai Taxi", + "number": ["+62361-724724"] + }, + { + "title": "Wahana Taxi", + "number": ["+62361-241444"] + }, + { + "title": "Pan Wirthi Taxi", + "number": ["+62363-723366"] + } + ] +} \ No newline at end of file diff --git a/app/src/main/java/com/balicodes/balinumbers/BaseListAdapter.java b/app/src/main/java/com/balicodes/balinumbers/BaseListAdapter.java new file mode 100644 index 0000000..840b749 --- /dev/null +++ b/app/src/main/java/com/balicodes/balinumbers/BaseListAdapter.java @@ -0,0 +1,109 @@ +package com.balicodes.balinumbers; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.Button; +import android.widget.TextView; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.List; + +/** + * Created by eka on 7/4/15. + */ +public class BaseListAdapter extends BaseAdapter { + + private Context context; + private List items; + private int layoutId; + + public BaseListAdapter(Context context, List items, int layoutId) { + this.context = context; + this.items = items; + this.layoutId = layoutId; + } + + @Override + public int getCount() { + return items.size(); + } + + @Override + public Object getItem(int position) { + return items.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + private void call(String number) { + Intent intent = new Intent(Intent.ACTION_DIAL); + intent.setData(Uri.parse(number)); + if (intent.resolveActivity(context.getPackageManager()) != null) { + context.startActivity(intent); + } + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + if (convertView == null) { + LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + convertView = inflater.inflate(layoutId, parent, false); + } + JSONObject item = items.get(position); + + // Main title + TextView text1 = (TextView) convertView.findViewById(R.id.text1); + try { + text1.setText(item.getString("title")); + } catch (JSONException e) { + e.printStackTrace(); + } + + // Area + String area = null; + try { + area = item.getString("area"); + } catch (JSONException e) { + e.printStackTrace(); + } + + // Sub title + TextView text2 = (TextView) convertView.findViewById(R.id.text2); + String number = null; + JSONArray numbers = null; + try { + numbers = item.getJSONArray("number"); + number = numbers.getString(0); + String sub = area != null ? area + " - " + number : number; + text2.setText(sub); + } catch (JSONException e) { + e.printStackTrace(); + } + + // direct call button + if (layoutId == R.layout.list_item_direct && number != null) { + Button callBtn = (Button) convertView.findViewById(R.id.callBtn); + + final String finalNumber = "tel:" + number; + callBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + call(finalNumber); + } + }); + } + + return convertView; + } +} diff --git a/app/src/main/java/com/balicodes/balinumbers/BaseSection.java b/app/src/main/java/com/balicodes/balinumbers/BaseSection.java new file mode 100644 index 0000000..b1096fe --- /dev/null +++ b/app/src/main/java/com/balicodes/balinumbers/BaseSection.java @@ -0,0 +1,254 @@ +package com.balicodes.balinumbers; + +import android.app.AlertDialog; +import android.content.Intent; +import android.net.Uri; +import android.os.AsyncTask; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.ListView; +import android.widget.TextView; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by eka on 7/3/15. + */ +public class BaseSection extends Fragment implements AdapterView.OnItemClickListener { + + protected List items = new ArrayList(); + private BaseListAdapter listAdapter; + private LinearLayout hotlineContainer, addContainer; + private ListView listView; + private String hotlineNumber; + private TextView hotlineText; + private Button hotlineBtn; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + listAdapter = new BaseListAdapter(getActivity(), items, getListItemLayoutId()); + } + + public void call(String number) { + Intent intent = new Intent(Intent.ACTION_DIAL); + intent.setData(Uri.parse(number)); + if (intent.resolveActivity(getActivity().getPackageManager()) != null) { + getActivity().startActivity(intent); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(getLayoutId(), container, false); + listView = (ListView) view.findViewById(getListViewLayoutId()); + listView.setAdapter(listAdapter); + listView.setOnItemClickListener(this); + hotlineContainer = (LinearLayout) view.findViewById(R.id.hotlineContainer); + hotlineContainer.setVisibility(View.GONE); + + addContainer = (LinearLayout) view.findViewById(R.id.adContainer); + addContainer.setVisibility(View.GONE); + + hotlineText = (TextView) view.findViewById(R.id.hotlineText); + hotlineBtn = (Button) view.findViewById(R.id.hotlineBtn); + hotlineBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + call(hotlineNumber); + } + }); + + // Load JSON file asynchronously + new JsonLoader().execute(getJsonFileName()); + return view; + } + + public String getJsonFileName() { + return null; + } + + public int getLayoutId() { + return R.layout.list; + } + + public boolean isDirectCallAction() { + return false; + } + + public int getListItemLayoutId() { + if (isDirectCallAction()) { + return R.layout.list_item_direct; + } else { + return R.layout.list_item; + } + } + + public int getListViewLayoutId() { + return R.id.list; + } + + public String getHotlineText(String number) { + return "HOTLINE - " + number; + } + + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + JSONObject obj = items.get(position); + String title = null; + String desc = null; + String address = null; + JSONArray phones = null; + + try { + title = obj.getString("title"); + } catch (JSONException e) { + e.printStackTrace(); + } + try { + desc = obj.getString("desc"); + } catch (JSONException e) { + e.printStackTrace(); + } + try { + address = obj.getString("address"); + } catch (JSONException e) { + e.printStackTrace(); + } + try { + phones = obj.getJSONArray("number"); + } catch (JSONException e) { + e.printStackTrace(); + } + + // Inflate the popup content layout + View detailPopup = getActivity().getLayoutInflater().inflate(R.layout.list_item_detail, null, false); + TextView descTxt = (TextView) detailPopup.findViewById(R.id.descTxt); + TextView addressTxt = (TextView) detailPopup.findViewById(R.id.addressTxt); + Button phone1Btn = (Button) detailPopup.findViewById(R.id.phone1Btn); + Button phone2Btn = (Button) detailPopup.findViewById(R.id.phone2Btn); + + if (desc != null) { + descTxt.setText(desc); + } else { + descTxt.setVisibility(View.GONE); + } + + if (address != null) { + addressTxt.setText(address); + } else { + addressTxt.setVisibility(View.GONE); + } + + if (phones != null) { + if (phones.length() > 1) { + try { + final String phone1 = phones.getString(0).toString(); + final String phone2 = phones.getString(1).toString(); + phone1Btn.setText(getText(R.string.call) + " " + phone1); + phone2Btn.setText(getText(R.string.call) + " " + phone2); + phone1Btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + call("tel:" + phone1); + } + }); + phone2Btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + call("tel:" + phone2); + } + }); + } catch (JSONException e) { + e.printStackTrace(); + } + } else { + phone2Btn.setVisibility(View.GONE); + try { + final String phone1 = phones.getString(0).toString(); + phone1Btn.setText(getText(R.string.call) + " " + phone1); + phone1Btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + call("tel:" + phone1); + } + }); + } catch (JSONException e) { + e.printStackTrace(); + } + } + } else { + phone1Btn.setVisibility(View.GONE); + phone2Btn.setVisibility(View.GONE); + } + + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setTitle(title); + builder.setView(detailPopup); + builder.create(); + builder.show(); + } + + public JSONObject loadJsonFile(String filename) { + try { + InputStream stream = getActivity().getAssets().open(filename); + int size = stream.available(); + byte[] buffer = new byte[size]; + stream.read(buffer); + stream.close(); + return new JSONObject(new String(buffer, "UTF-8")); + } catch (IOException e) { + e.printStackTrace(); + return null; + } catch (JSONException e) { + e.printStackTrace(); + return null; + } + } + + public class JsonLoader extends AsyncTask { + @Override + protected JSONObject doInBackground(String... params) { + JSONObject obj = loadJsonFile(params[0]); + return obj; + } + + @Override + protected void onPostExecute(JSONObject jsonObject) { + items.clear(); + try { + JSONArray list = jsonObject.getJSONArray("list"); + for (int i = 0; i < list.length(); i++) { + JSONObject item = list.getJSONObject(i); + items.add(item); + } + listAdapter.notifyDataSetChanged(); + } catch (JSONException e) { + e.printStackTrace(); + } + + try { + String number = jsonObject.getString("hotline"); + hotlineText.setText(getHotlineText(number)); + hotlineNumber = "tel:" + number; + hotlineContainer.setVisibility(View.VISIBLE); + } catch (JSONException e) { + e.printStackTrace(); + } + } + } +} diff --git a/app/src/main/java/com/balicodes/balinumbers/MainActivity.java b/app/src/main/java/com/balicodes/balinumbers/MainActivity.java new file mode 100644 index 0000000..4136db7 --- /dev/null +++ b/app/src/main/java/com/balicodes/balinumbers/MainActivity.java @@ -0,0 +1,84 @@ +package com.balicodes.balinumbers; + +import android.app.AlertDialog; +import android.content.ActivityNotFoundException; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.support.v4.view.ViewPager; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; + +public class MainActivity extends AppCompatActivity { + private ViewPager viewPager; + private PagerAdapter pagerAdapter; + private Toolbar toolbar; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + toolbar = (Toolbar) findViewById(R.id.toolbar); + toolbar.setTitleTextColor(getResources().getColor(R.color.white)); + toolbar.setTitle(R.string.app_name); + + setSupportActionBar(toolbar); + + pagerAdapter = new PagerAdapter(getSupportFragmentManager(), this); + viewPager = (ViewPager) findViewById(R.id.pager); + viewPager.setAdapter(pagerAdapter); + viewPager.setOffscreenPageLimit(6); + } + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_main, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + switch (id){ + case R.id.action_share: + Intent sendIntent = new Intent(); + sendIntent.setAction(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_text)); + sendIntent.setType("text/plain"); + startActivity(sendIntent); + break; + case R.id.action_rate: + Uri uri = Uri.parse("market://details?id=" + this.getPackageName()); + Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); + try { + startActivity(goToMarket); + } catch (ActivityNotFoundException e) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + this.getPackageName()))); + } + break; + case R.id.action_about: + // Inflate the about message contents + View messageView = getLayoutInflater().inflate(R.layout.about, null, false); + + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setIcon(R.drawable.ic_launcher); + builder.setTitle(R.string.app_name_short); + builder.setView(messageView); + builder.create(); + builder.show(); + break; + } + + return super.onOptionsItemSelected(item); + } +} diff --git a/app/src/main/java/com/balicodes/balinumbers/PagerAdapter.java b/app/src/main/java/com/balicodes/balinumbers/PagerAdapter.java new file mode 100644 index 0000000..f2799cc --- /dev/null +++ b/app/src/main/java/com/balicodes/balinumbers/PagerAdapter.java @@ -0,0 +1,68 @@ +package com.balicodes.balinumbers; + +import android.content.Context; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; + +import com.balicodes.balinumbers.sections.Embassies; +import com.balicodes.balinumbers.sections.Emergency; +import com.balicodes.balinumbers.sections.FireFighter; +import com.balicodes.balinumbers.sections.Hospitals; +import com.balicodes.balinumbers.sections.Police; +import com.balicodes.balinumbers.sections.Taxi; + +/** + * Created by eka on 7/3/15. + */ +public class PagerAdapter extends FragmentPagerAdapter { + private Context context; + + public PagerAdapter(FragmentManager fm, Context context) { + super(fm); + this.context = context; + } + + @Override + public Fragment getItem(int i) { + switch (i) { + case 0: + return new Emergency(); + case 1: + return new Police(); + case 2: + return new Hospitals(); + case 3: + return new FireFighter(); + case 4: + return new Taxi(); + case 5: + return new Embassies(); + } + return null; + } + + @Override + public int getCount() { + return 6; + } + + @Override + public CharSequence getPageTitle(int position) { + switch (position) { + case 0: + return Emergency.TITLE; + case 1: + return Police.TITLE; + case 2: + return Hospitals.TITLE; + case 3: + return FireFighter.TITLE; + case 4: + return Taxi.TITLE; + case 5: + return Embassies.TITLE; + } + return super.getPageTitle(position); + } +} diff --git a/app/src/main/java/com/balicodes/balinumbers/sections/Embassies.java b/app/src/main/java/com/balicodes/balinumbers/sections/Embassies.java new file mode 100644 index 0000000..bcb62af --- /dev/null +++ b/app/src/main/java/com/balicodes/balinumbers/sections/Embassies.java @@ -0,0 +1,15 @@ +package com.balicodes.balinumbers.sections; + +import com.balicodes.balinumbers.BaseSection; + +/** + * Created by eka on 7/5/15. + */ +public class Embassies extends BaseSection { + public static String TITLE = "Embassies"; + + @Override + public String getJsonFileName() { + return "embassies.json"; + } +} diff --git a/app/src/main/java/com/balicodes/balinumbers/sections/Emergency.java b/app/src/main/java/com/balicodes/balinumbers/sections/Emergency.java new file mode 100644 index 0000000..6b2738c --- /dev/null +++ b/app/src/main/java/com/balicodes/balinumbers/sections/Emergency.java @@ -0,0 +1,20 @@ +package com.balicodes.balinumbers.sections; + +import com.balicodes.balinumbers.BaseSection; + +/** + * Created by eka on 7/4/15. + */ +public class Emergency extends BaseSection { + public static String TITLE = "Emergency"; + + @Override + public String getJsonFileName() { + return "emergency.json"; + } + + @Override + public boolean isDirectCallAction() { + return true; + } +} diff --git a/app/src/main/java/com/balicodes/balinumbers/sections/FireFighter.java b/app/src/main/java/com/balicodes/balinumbers/sections/FireFighter.java new file mode 100644 index 0000000..b1ef40b --- /dev/null +++ b/app/src/main/java/com/balicodes/balinumbers/sections/FireFighter.java @@ -0,0 +1,20 @@ +package com.balicodes.balinumbers.sections; + +import com.balicodes.balinumbers.BaseSection; + +/** + * Created by eka on 7/5/15. + */ +public class FireFighter extends BaseSection { + public static String TITLE = "Fire Fighters"; + + @Override + public String getJsonFileName() { + return "fire_fighters.json"; + } + + @Override + public boolean isDirectCallAction() { + return true; + } +} diff --git a/app/src/main/java/com/balicodes/balinumbers/sections/Hospitals.java b/app/src/main/java/com/balicodes/balinumbers/sections/Hospitals.java new file mode 100644 index 0000000..7229405 --- /dev/null +++ b/app/src/main/java/com/balicodes/balinumbers/sections/Hospitals.java @@ -0,0 +1,20 @@ +package com.balicodes.balinumbers.sections; + +import com.balicodes.balinumbers.BaseSection; + +/** + * Created by eka on 7/3/15. + */ +public class Hospitals extends BaseSection { + public static String TITLE = "Hospitals"; + + @Override + public String getJsonFileName() { + return "hospitals.json"; + } + + @Override + public String getHotlineText(String number) { + return "AMBULANCE - " + number; + } +} diff --git a/app/src/main/java/com/balicodes/balinumbers/sections/Police.java b/app/src/main/java/com/balicodes/balinumbers/sections/Police.java new file mode 100644 index 0000000..3d79533 --- /dev/null +++ b/app/src/main/java/com/balicodes/balinumbers/sections/Police.java @@ -0,0 +1,20 @@ +package com.balicodes.balinumbers.sections; + +import com.balicodes.balinumbers.BaseSection; + +/** + * Created by eka on 7/3/15. + */ +public class Police extends BaseSection { + public static String TITLE = "Police"; + + @Override + public String getJsonFileName() { + return "police.json"; + } + + @Override + public boolean isDirectCallAction() { + return true; + } +} diff --git a/app/src/main/java/com/balicodes/balinumbers/sections/Taxi.java b/app/src/main/java/com/balicodes/balinumbers/sections/Taxi.java new file mode 100644 index 0000000..dff0437 --- /dev/null +++ b/app/src/main/java/com/balicodes/balinumbers/sections/Taxi.java @@ -0,0 +1,20 @@ +package com.balicodes.balinumbers.sections; + +import com.balicodes.balinumbers.BaseSection; + +/** + * Created by eka on 7/5/15. + */ +public class Taxi extends BaseSection { + public static String TITLE = "Taxi"; + + @Override + public String getJsonFileName() { + return "taxi.json"; + } + + @Override + public boolean isDirectCallAction() { + return true; + } +} diff --git a/app/src/main/res/drawable-hdpi/ic_chevron_right.png b/app/src/main/res/drawable-hdpi/ic_chevron_right.png new file mode 100644 index 0000000..c11a2a5 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_chevron_right.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_launcher.png b/app/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100755 index 0000000..0a80225 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_phone_grey.png b/app/src/main/res/drawable-hdpi/ic_phone_grey.png new file mode 100644 index 0000000..ba1a2d2 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_phone_grey.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_launcher.png b/app/src/main/res/drawable-mdpi/ic_launcher.png new file mode 100755 index 0000000..2769631 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/drawable/green_button.xml b/app/src/main/res/drawable/green_button.xml new file mode 100644 index 0000000..5879aee --- /dev/null +++ b/app/src/main/res/drawable/green_button.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/green_button_normal.xml b/app/src/main/res/drawable/green_button_normal.xml new file mode 100644 index 0000000..1aacb3b --- /dev/null +++ b/app/src/main/res/drawable/green_button_normal.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/green_button_pressed.xml b/app/src/main/res/drawable/green_button_pressed.xml new file mode 100644 index 0000000..eb3769d --- /dev/null +++ b/app/src/main/res/drawable/green_button_pressed.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/green_button_reverse.xml b/app/src/main/res/drawable/green_button_reverse.xml new file mode 100644 index 0000000..2ac42fb --- /dev/null +++ b/app/src/main/res/drawable/green_button_reverse.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/orange_button.xml b/app/src/main/res/drawable/orange_button.xml new file mode 100644 index 0000000..3c08e2d --- /dev/null +++ b/app/src/main/res/drawable/orange_button.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/orange_button_normal.xml b/app/src/main/res/drawable/orange_button_normal.xml new file mode 100644 index 0000000..93d5984 --- /dev/null +++ b/app/src/main/res/drawable/orange_button_normal.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/orange_button_pressed.xml b/app/src/main/res/drawable/orange_button_pressed.xml new file mode 100644 index 0000000..8a2e8e9 --- /dev/null +++ b/app/src/main/res/drawable/orange_button_pressed.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/about.xml b/app/src/main/res/layout/about.xml new file mode 100644 index 0000000..c257966 --- /dev/null +++ b/app/src/main/res/layout/about.xml @@ -0,0 +1,23 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..e85ec72 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/list.xml b/app/src/main/res/layout/list.xml new file mode 100644 index 0000000..62fb7b8 --- /dev/null +++ b/app/src/main/res/layout/list.xml @@ -0,0 +1,60 @@ + + + + + + + +