├── .gitignore
├── project.properties
├── res
├── raw
│ ├── majed.mp3
│ └── notification.mp3
├── drawable-hdpi
│ ├── logo.png
│ ├── shefrah.jpg
│ ├── background.PNG
│ ├── background2.png
│ ├── prayerstable.png
│ ├── alertbackground.PNG
│ ├── praytimetext4.png
│ ├── prayerstable_left.png
│ ├── prayerstable_right.png
│ ├── praytimebackground.png
│ └── secondary_background.png
├── drawable-ldpi
│ ├── bbg.png
│ ├── icon.png
│ ├── logo.png
│ ├── shefrah.jpg
│ └── background1.png
├── drawable-mdpi
│ ├── bbg.png
│ ├── icon.png
│ ├── logo.png
│ ├── shefrah.jpg
│ └── background1.png
├── layout
│ ├── alert.xml
│ ├── cityfindermanual.xml
│ ├── about.xml
│ ├── cityfinder.xml
│ └── main.xml
├── xml
│ └── settings.xml
└── values
│ └── strings.xml
├── assets
├── CountriesDB
└── fonts
│ ├── KacstTitle.ttf
│ ├── Roboto-Regular.ttf
│ └── DroidNaskh-Regular.ttf
├── ReadMe
├── .settings
└── org.eclipse.jdt.core.prefs
├── gen
└── com
│ └── shefra
│ └── prayertimes
│ ├── BuildConfig.java
│ └── R.java
├── src
└── com
│ └── shefra
│ └── prayertimes
│ ├── manager
│ ├── Country.java
│ ├── City.java
│ ├── PrayerState.java
│ ├── CityLocationListener.java
│ ├── Preference.java
│ └── Manager.java
│ ├── moazen
│ ├── Date.java
│ ├── Coordinate.java
│ ├── Season.java
│ ├── Mazhab.java
│ ├── Calender.java
│ ├── Time.java
│ └── PrayerTime.java
│ ├── services
│ ├── PhoneStateBroadcastReceiver.java
│ ├── OnBootService.java
│ ├── CustomPhoneStateListener.java
│ ├── PrayerService.java
│ └── PrayerReceiver.java
│ ├── helper
│ ├── Typefaces.java
│ ├── TimeHelper.java
│ └── DatabaseHelper.java
│ └── activity
│ ├── About.java
│ ├── AlertActivity.java
│ ├── CityFinderManual.java
│ ├── SettingsActivity.java
│ ├── MainActivity.java
│ └── CityFinder.java
├── lint.xml
├── .classpath
├── .project
├── proguard.cfg
└── AndroidManifest.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # Project target.
2 | target=android-7
3 |
--------------------------------------------------------------------------------
/res/raw/majed.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/raw/majed.mp3
--------------------------------------------------------------------------------
/assets/CountriesDB:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/assets/CountriesDB
--------------------------------------------------------------------------------
/res/raw/notification.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/raw/notification.mp3
--------------------------------------------------------------------------------
/assets/fonts/KacstTitle.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/assets/fonts/KacstTitle.ttf
--------------------------------------------------------------------------------
/res/drawable-hdpi/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-hdpi/logo.png
--------------------------------------------------------------------------------
/res/drawable-ldpi/bbg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-ldpi/bbg.png
--------------------------------------------------------------------------------
/res/drawable-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-ldpi/icon.png
--------------------------------------------------------------------------------
/res/drawable-ldpi/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-ldpi/logo.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/bbg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-mdpi/bbg.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-mdpi/logo.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/shefrah.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-hdpi/shefrah.jpg
--------------------------------------------------------------------------------
/res/drawable-ldpi/shefrah.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-ldpi/shefrah.jpg
--------------------------------------------------------------------------------
/res/drawable-mdpi/shefrah.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-mdpi/shefrah.jpg
--------------------------------------------------------------------------------
/assets/fonts/Roboto-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/assets/fonts/Roboto-Regular.ttf
--------------------------------------------------------------------------------
/res/drawable-hdpi/background.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-hdpi/background.PNG
--------------------------------------------------------------------------------
/res/drawable-hdpi/background2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-hdpi/background2.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/prayerstable.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-hdpi/prayerstable.png
--------------------------------------------------------------------------------
/res/drawable-ldpi/background1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-ldpi/background1.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/background1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-mdpi/background1.png
--------------------------------------------------------------------------------
/assets/fonts/DroidNaskh-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/assets/fonts/DroidNaskh-Regular.ttf
--------------------------------------------------------------------------------
/res/drawable-hdpi/alertbackground.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-hdpi/alertbackground.PNG
--------------------------------------------------------------------------------
/res/drawable-hdpi/praytimetext4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-hdpi/praytimetext4.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/prayerstable_left.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-hdpi/prayerstable_left.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/prayerstable_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-hdpi/prayerstable_right.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/praytimebackground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-hdpi/praytimebackground.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/secondary_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shefra/prayertimes/HEAD/res/drawable-hdpi/secondary_background.png
--------------------------------------------------------------------------------
/ReadMe:
--------------------------------------------------------------------------------
1 | Tomaanina is Islamic Android application helps users to know prayers times, get notification on Adhan ( prayer call) and turn the mobile into silent mode during the prayers time.It's an open source application.
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
3 | org.eclipse.jdt.core.compiler.compliance=1.5
4 | org.eclipse.jdt.core.compiler.source=1.5
5 |
--------------------------------------------------------------------------------
/gen/com/shefra/prayertimes/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.shefra.prayertimes;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/manager/Country.java:
--------------------------------------------------------------------------------
1 | package com.shefra.prayertimes.manager;
2 |
3 | public class Country {
4 | public String id=null;
5 | public String name=null;
6 |
7 | public String shortName = null;
8 | public String longName = null;
9 | }
10 |
--------------------------------------------------------------------------------
/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/manager/City.java:
--------------------------------------------------------------------------------
1 | package com.shefra.prayertimes.manager;
2 |
3 | public class City {
4 | public String name = null;
5 | public String id = null;
6 | public int timeZone = -999;
7 | public String longitude;
8 | public String latitude ;
9 | public Country country;
10 | public City(){
11 | this.country = new Country();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/moazen/Date.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.shefra.prayertimes.moazen;
6 | /**
7 | *
8 | * @author Admin
9 | */
10 | public class Date {
11 | public Date(int day,int month,int year)
12 | {
13 | this.day = day;
14 | this.month = month;
15 | this.year = year;
16 | }
17 |
18 | int day;
19 | int month;
20 | int year;
21 |
22 |
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/moazen/Coordinate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.shefra.prayertimes.moazen;
6 | /**
7 | *
8 | * @author Admin
9 | */
10 | public class Coordinate {
11 | public double longitude;
12 | public double latitude;
13 | public int zone;
14 | public Coordinate(){}
15 | public Coordinate(double longitude,double latitude,int zone){
16 | this.longitude = longitude;
17 | this.latitude = latitude;
18 | this.zone = zone;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/services/PhoneStateBroadcastReceiver.java:
--------------------------------------------------------------------------------
1 | package com.shefra.prayertimes.services;
2 |
3 |
4 |
5 | import android.content.BroadcastReceiver;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.telephony.PhoneStateListener;
9 | import android.telephony.TelephonyManager;
10 |
11 | public class PhoneStateBroadcastReceiver extends BroadcastReceiver{
12 |
13 | @Override
14 | public void onReceive(Context context, Intent intent) {
15 |
16 | TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
17 | telephonyManager.listen(new CustomPhoneStateListener(context), PhoneStateListener.LISTEN_CALL_STATE);
18 |
19 | }
20 |
21 | }
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/services/OnBootService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * OnBootService Class is an: Android Service that boots with the System to run
3 | * ServiceSetAlarm so the set alarm won't be lost.
4 | */
5 |
6 | package com.shefra.prayertimes.services;
7 |
8 | import android.content.BroadcastReceiver;
9 | import android.content.Context;
10 | import android.content.Intent;
11 | import android.util.Log;
12 |
13 | public class OnBootService extends BroadcastReceiver {
14 |
15 | public void onReceive(Context context, Intent intent) {
16 | if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
17 | Intent serviceIntent = new Intent(context, PrayerService.class);
18 | context.startService(serviceIntent);
19 | }else{
20 | //Log.e("OnBootService", "Received unexpected intent " + intent.toString());
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | tomaanina
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/moazen/Season.java:
--------------------------------------------------------------------------------
1 | package com.shefra.prayertimes.moazen;
2 |
3 |
4 | public class Season {
5 | public enum Type {
6 | Winter,
7 | Summer
8 | }
9 |
10 | Season(){this.season=Type.Winter;}
11 | Season(Type T){this.season=T;}
12 | public void setSeason(Type season){
13 | this.season=season;
14 | }
15 | public void setSeason(String season){
16 | if(season.equals("Winter"))
17 | this.season=Type.Winter;
18 | else
19 | this.season=Type.Summer;
20 |
21 | }
22 |
23 | public final Type type(){return seasonInt() ;}
24 | public final Type seasonInt(){return season;}
25 | public final String seasonString(){
26 | String tmp;
27 | if(season.equals(Type.Winter))
28 | tmp="Winter";
29 | else
30 | tmp = "Summer";
31 | return tmp;
32 | }
33 | private Type season;
34 |
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/helper/Typefaces.java:
--------------------------------------------------------------------------------
1 | package com.shefra.prayertimes.helper;
2 |
3 | import java.util.Hashtable;
4 |
5 | import android.content.Context;
6 | import android.graphics.Typeface;
7 | import android.util.Log;
8 |
9 | // prevent Android bug that leads to memory leaks.
10 | // this workaround done by @HTH and @Brian. more info in :
11 | // http://code.google.com/p/android/issues/detail?id=9904
12 | public class Typefaces {
13 | private static final String TAG = "tomaanina";
14 |
15 | private static final Hashtable cache = new Hashtable();
16 |
17 | public static Typeface get(Context c, String assetPath) {
18 | synchronized (cache) {
19 | if (!cache.containsKey(assetPath)) {
20 | try {
21 | Typeface t = Typeface.createFromAsset(c.getAssets(),
22 | assetPath);
23 | cache.put(assetPath, t);
24 | } catch (Exception e) {
25 | //Log.e(TAG, "Could not get typeface '" + assetPath
26 | // + "' because " + e.getMessage());
27 | return null;
28 | }
29 | }
30 | return cache.get(assetPath);
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/moazen/Mazhab.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.shefra.prayertimes.moazen;
6 | /**
7 | *
8 | * @author aziz
9 | */
10 | public class Mazhab {
11 | public enum Type {
12 | Default,
13 | Hanafi
14 | }
15 |
16 | Mazhab(){this.mazhab=Type.Default;}
17 | Mazhab(Type T){this.mazhab=T;}
18 | public void setMazhab(Type mazhab){
19 | this.mazhab=mazhab;
20 | }
21 | public void setMazhab(String mazhab){
22 | if(mazhab.equals("Default"))
23 | this.mazhab=Type.Default;
24 | else
25 | this.mazhab=Type.Hanafi;
26 |
27 | }
28 |
29 | public final Type type(){return mazhabInt() ;}
30 | public final Type mazhabInt(){return mazhab;}
31 | public final String mazhabString(){
32 | String tmp;
33 | if(mazhab.equals(Type.Default))
34 | tmp="Default";
35 | else
36 | tmp = "Hanafi";
37 | return tmp;
38 | }
39 | private Type mazhab;
40 |
41 | }
42 |
43 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/manager/PrayerState.java:
--------------------------------------------------------------------------------
1 | package com.shefra.prayertimes.manager;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import android.content.SharedPreferences.Editor;
6 | import android.preference.PreferenceManager;
7 |
8 | public class PrayerState {
9 | public static final int UNKNOWN = 1000;
10 | public static final int WAITING_AZAN = 0;
11 | public static final int PRE_DOING_AZAN = 1;
12 | public static final int DOING_AZAN = 2;
13 | public static final int WAITING_PRAYER = 3;
14 |
15 | private Context context;
16 |
17 | public PrayerState(Context context) {
18 | this.context = context;
19 | setNextState(WAITING_AZAN);
20 | }
21 |
22 | public int getCurrentState() {
23 | SharedPreferences pref = PreferenceManager
24 | .getDefaultSharedPreferences(this.context);
25 | return pref.getInt("prayerState", WAITING_AZAN);
26 | }
27 |
28 | public void setNextState(int state) {
29 | SharedPreferences pref = PreferenceManager
30 | .getDefaultSharedPreferences(this.context);
31 | Editor editor = pref.edit();
32 | editor.putInt("prayerState", state);
33 | editor.putLong("stateChangeTime", System.currentTimeMillis());
34 | editor.commit();
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/proguard.cfg:
--------------------------------------------------------------------------------
1 | -optimizationpasses 5
2 | -dontusemixedcaseclassnames
3 | -dontskipnonpubliclibraryclasses
4 | -dontpreverify
5 | -verbose
6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
7 |
8 | -keep public class * extends android.app.Activity
9 | -keep public class * extends android.app.Application
10 | -keep public class * extends android.app.Service
11 | -keep public class * extends android.content.BroadcastReceiver
12 | -keep public class * extends android.content.ContentProvider
13 | -keep public class * extends android.app.backup.BackupAgentHelper
14 | -keep public class * extends android.preference.Preference
15 | -keep public class com.android.vending.licensing.ILicensingService
16 |
17 | -keepclasseswithmembernames class * {
18 | native ;
19 | }
20 |
21 | -keepclasseswithmembernames class * {
22 | public (android.content.Context, android.util.AttributeSet);
23 | }
24 |
25 | -keepclasseswithmembernames class * {
26 | public (android.content.Context, android.util.AttributeSet, int);
27 | }
28 |
29 | -keepclassmembers enum * {
30 | public static **[] values();
31 | public static ** valueOf(java.lang.String);
32 | }
33 |
34 | -keep class * implements android.os.Parcelable {
35 | public static final android.os.Parcelable$Creator *;
36 | }
37 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/services/CustomPhoneStateListener.java:
--------------------------------------------------------------------------------
1 | package com.shefra.prayertimes.services;
2 |
3 | import com.shefra.prayertimes.manager.Manager;
4 |
5 | import android.telephony.PhoneStateListener;
6 |
7 | import android.content.Context;
8 | import android.telephony.TelephonyManager;
9 |
10 | public class CustomPhoneStateListener extends PhoneStateListener {
11 |
12 | //private static final String TAG = "PhoneStateChanged";
13 | Context context; //Context to make Toast if required
14 | public CustomPhoneStateListener(Context context) {
15 | super();
16 | this.context = context;
17 | }
18 |
19 | @Override
20 | public void onCallStateChanged(int state, String incomingNumber) {
21 | super.onCallStateChanged(state, incomingNumber);
22 |
23 | switch (state) {
24 | case TelephonyManager.CALL_STATE_IDLE:
25 | //when Idle i.e no call
26 | Manager.isPhoneIdle = true;
27 | break;
28 | case TelephonyManager.CALL_STATE_OFFHOOK:
29 | //when Off hook i.e in call
30 | Manager.isPhoneIdle = false;
31 | break;
32 | case TelephonyManager.CALL_STATE_RINGING:
33 | //when Ringing
34 | Manager.isPhoneIdle = false;
35 | break;
36 | default:
37 | break;
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/res/layout/alert.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
12 |
13 |
14 |
17 |
18 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/res/layout/cityfindermanual.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
12 |
23 |
24 |
31 |
32 |
38 |
39 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/moazen/Calender.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.shefra.prayertimes.moazen;
6 | /**
7 | *
8 | * @author aziz
9 | */
10 | public class Calender {
11 | public enum Type {
12 | UmmAlQuraUniv,
13 | EgytionGeneralAuthorityofSurvey,
14 | UnivOfIslamicScincesKarachi,
15 | IslamicSocietyOfNorthAmerica,
16 | MuslimWorldLeague
17 | }
18 | private Type calender ;
19 | public Calender(){this.calender=Type.UmmAlQuraUniv;}//default constructor
20 | public Calender(Type T){ this.calender= T;}//one-argument constructor
21 |
22 | public void setCalender(Type T){this.calender=T;}
23 | public void setCalender(String string){
24 |
25 | if (string.equals("UmmAlQuraUniv"))
26 | calender=Type.UmmAlQuraUniv;
27 |
28 | else if (string.equals("EgytionGeneralAuthorityofSurvey"))
29 | calender=Type.EgytionGeneralAuthorityofSurvey;
30 |
31 | else if (string.equals("UnivOfIslamicScincesKarachi"))
32 | calender=Type.UnivOfIslamicScincesKarachi;
33 |
34 | else if (string.equals("IslamicSocietyOfNorthAmerica"))
35 | calender=Type.IslamicSocietyOfNorthAmerica;
36 |
37 | else
38 | calender=Type.MuslimWorldLeague;
39 |
40 | }
41 |
42 | public final Type type (){return this.calenderInt();}
43 | public final Type calenderInt(){return this.calender;}
44 | public final String calenderString(){
45 | String tmp;
46 | if( calender == Type.UmmAlQuraUniv )
47 | tmp="UmmAlQuraUniv";
48 |
49 | else if( calender == Type.EgytionGeneralAuthorityofSurvey )
50 | tmp="EgytionGeneralAuthorityofSurvey";
51 |
52 | else if( calender == Type.UnivOfIslamicScincesKarachi )
53 | tmp="UnivOfIslamicScincesKarachi";
54 |
55 | else if( calender == Type.IslamicSocietyOfNorthAmerica )
56 | tmp="IslamicSocietyOfNorthAmerica";
57 |
58 | else
59 | tmp="MuslimWorldLeague";
60 |
61 | return tmp;
62 | }
63 | }
64 |
65 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/services/PrayerService.java:
--------------------------------------------------------------------------------
1 | package com.shefra.prayertimes.services;
2 |
3 | import com.shefra.prayertimes.manager.Manager;
4 |
5 | import android.app.Service;
6 | import android.content.BroadcastReceiver;
7 | import android.content.Context;
8 | import android.content.Intent;
9 | import android.content.IntentFilter;
10 | import android.os.Handler;
11 | import android.os.IBinder;
12 | import android.os.Message;
13 | import android.os.SystemClock;
14 | import android.util.Log;
15 |
16 | public class PrayerService extends Service {
17 |
18 | private static IntentFilter s_intentFilter;
19 | long mStartTime;
20 |
21 | static {
22 | s_intentFilter = new IntentFilter();
23 | s_intentFilter.addAction(Intent.ACTION_TIME_TICK);
24 | s_intentFilter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
25 | s_intentFilter.addAction(Intent.ACTION_TIME_CHANGED);
26 | }
27 |
28 | @Override
29 | public IBinder onBind(Intent arg0) {
30 | // TODO Auto-generated method stub
31 | return null;
32 | }
33 |
34 | @Override
35 | public void onCreate() {
36 | try {
37 | super.onCreate();
38 | Manager.initPrayerState(this);
39 | Manager.initPrayerAlarm(this, PrayerReceiver.class);
40 | this.registerReceiver(this.m_timeChangedReceiver, s_intentFilter);
41 | //prayerHandler = new PrayerHandler2(this);
42 | //prayerHandler.postDelayed(mUpdateTimeTask, 10000); // as soon as possible ( 10 seconds )
43 |
44 | } catch (Exception e) {
45 | //Log.e("onCreateService", e.getMessage(), e.getCause());
46 | }
47 |
48 | }
49 |
50 | // time changed listener
51 | private final BroadcastReceiver m_timeChangedReceiver = new BroadcastReceiver() {
52 | @Override
53 | public void onReceive(Context context, Intent intent) {
54 | final String action = intent.getAction();
55 |
56 | if (action.equals(Intent.ACTION_TIME_CHANGED) ||
57 | action.equals(Intent.ACTION_TIMEZONE_CHANGED))
58 | {
59 | Manager.cancelPrayerAlarm();
60 | Manager.initPrayerState(PrayerService.this);
61 | Manager.initPrayerAlarm(PrayerService.this,PrayerReceiver.class);
62 |
63 | }
64 | }
65 | };
66 |
67 |
68 |
69 |
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/activity/About.java:
--------------------------------------------------------------------------------
1 | package com.shefra.prayertimes.activity;
2 |
3 | import com.shefra.prayertimes.R;
4 |
5 | import android.app.Activity;
6 | import android.content.Intent;
7 | import android.os.Bundle;
8 | import android.view.View;
9 | import android.view.View.OnClickListener;
10 | import android.widget.Button;
11 | import android.widget.Toast;
12 |
13 | public class About extends Activity {
14 | @Override
15 | public void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | this.setContentView(R.layout.about);// TODO create a new layout
18 | Button feedback = (Button) findViewById(R.id.feadbackButton);
19 | feedback.setOnClickListener(new OnClickListener() {
20 |
21 | public void onClick(View v) {
22 | Intent i = new Intent(Intent.ACTION_SEND);
23 | i.setType("message/rfc822");
24 | i.putExtra(Intent.EXTRA_EMAIL, new String[] { About.this
25 | .getString(R.string.feedbackEmail) });
26 | i.putExtra(Intent.EXTRA_SUBJECT,
27 | About.this.getString(R.string.feedbackSubject));
28 | i.putExtra(Intent.EXTRA_TEXT,
29 | About.this.getString(R.string.feedbackBody));
30 | try {
31 | startActivity(Intent.createChooser(i, About.this
32 | .getString(R.string.feedbackChooserString)));
33 | } catch (android.content.ActivityNotFoundException ex) {
34 | Toast.makeText(About.this,
35 | About.this.getString(R.string.feedbackFailed),
36 | Toast.LENGTH_SHORT).show();
37 | }
38 | }
39 | });
40 |
41 | Button contactus = (Button) findViewById(R.id.contactUsButton);
42 | contactus.setOnClickListener(new OnClickListener() {
43 |
44 | public void onClick(View v) {
45 | Intent i = new Intent(Intent.ACTION_SEND);
46 | i.setType("message/rfc822");
47 | i.putExtra(Intent.EXTRA_EMAIL, new String[] { About.this
48 | .getString(R.string.contactusEmail) });
49 | i.putExtra(Intent.EXTRA_SUBJECT,
50 | About.this.getString(R.string.contactusSubject));
51 | i.putExtra(Intent.EXTRA_TEXT,
52 | About.this.getString(R.string.contactusBody));
53 | try {
54 | startActivity(Intent.createChooser(i, About.this
55 | .getString(R.string.contactusChooserString)));
56 | } catch (android.content.ActivityNotFoundException ex) {
57 | Toast.makeText(About.this,
58 | About.this.getString(R.string.contactusFailed),
59 | Toast.LENGTH_SHORT).show();
60 | }
61 | }
62 | });
63 |
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/moazen/Time.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.shefra.prayertimes.moazen;
6 |
7 | /**
8 | *
9 | * @author Admin
10 | */
11 | public class Time {
12 | public Time(double time) {
13 | this.m_time = convertToTime(time, false);
14 | }
15 |
16 | public Time(double time, boolean isAM) {
17 | this.m_time = convertToTime(time, isAM);
18 | }
19 |
20 | public final String text() {
21 | return m_time;
22 | }
23 |
24 | public final int hour() {
25 | return m_hour;
26 | }
27 |
28 | public final int minute() {
29 | return m_minute;
30 | }
31 |
32 | public final int second() {
33 | return m_second;
34 | }
35 |
36 | public final String zone() {
37 | return m_zone;
38 | }
39 |
40 | private String convertToTime(double var, boolean isAM) {
41 | String time = "";
42 | int ivar = (int) var;
43 | if (isAM) {
44 | if ((ivar % 12) < 12 && (ivar % 12) > 0)
45 | this.m_zone = "AM";
46 | else
47 | this.m_zone = "PM";
48 | } else
49 | this.m_zone = "PM";
50 |
51 | if (ivar > 12) { // convert hour from 24 to 12
52 | if (ivar % 12 > 9)
53 | time += toString(ivar % 12);
54 | else
55 | time += "0" + toString(ivar % 12);
56 | this.m_hour = ivar % 12;
57 | } else if (ivar == 12) {
58 | time += toString(ivar);
59 | this.m_hour = ivar;
60 | } else {
61 | if (ivar <= 9)
62 | time += "0" + toString(ivar);
63 | else
64 | time += toString(ivar);
65 | this.m_hour = ivar;
66 | }
67 |
68 | time += ":";
69 |
70 | var -= ivar;
71 | var *= 60;
72 | ivar = (int) var; // for minutes
73 | this.m_minute = ivar;
74 | if (ivar < 10) {
75 | time += "0" + toString(ivar);
76 | } else {
77 | time += toString(ivar);
78 | }
79 |
80 | time += ":";
81 |
82 | var -= ivar;
83 | var *= 60;
84 | ivar = (int) var;// for seconds
85 | this.m_second = ivar;
86 |
87 | if (ivar < 10) {
88 | time += "0" + toString(ivar);
89 | } else {
90 | time += toString(ivar);
91 | }
92 | time += " ";
93 |
94 | time += this.m_zone;
95 | return time;
96 |
97 | }
98 |
99 | private static String toString(int value) {
100 | String Stime = Integer.toString(value);
101 | return Stime;
102 | }
103 |
104 | private String m_time;
105 |
106 | int m_hour;
107 | int m_minute;
108 | int m_second;
109 | String m_zone;
110 | }
111 |
--------------------------------------------------------------------------------
/res/xml/settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
20 |
25 |
30 |
31 |
32 |
33 |
36 |
40 |
43 |
44 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/helper/TimeHelper.java:
--------------------------------------------------------------------------------
1 | package com.shefra.prayertimes.helper;
2 |
3 | public class TimeHelper {
4 | public static int to24(String time) {
5 | String[] t = time.split(":");
6 | String[] AMORPM = t[2].split(" ");
7 | int houer = Integer.parseInt(t[0]);
8 | if (AMORPM[1].equals("PM") && houer != 12)
9 | houer += 12;
10 | return houer;
11 | }
12 |
13 | public static int getMinute(String time) {
14 | String[] t = time.split(":");
15 | return Integer.parseInt(t[1]);
16 | }
17 |
18 | // different
19 | public static int different(int current, int prayer) {
20 | if (current <= prayer)
21 | return prayer - current;
22 | return (prayer + (24 * 3600)) - current;
23 | }
24 |
25 | // different 2
26 | public static int different2(int time1, int time2) {
27 | if (time1 <= time2)
28 | return time2 - time1;
29 | return (time2 + (24 * 3600)) - time1;
30 | }
31 |
32 | // different between two times in 12 hour mode
33 | // 3:00 - 9:00 pm = 6 hour
34 | // return seconds
35 | // public static int different12hour(int time1, int time2) {
36 | // if(time2>= 12 * 3600)
37 | // time2 = time2 - 12*3600;
38 | // if(time1>= 12 * 3600)
39 | // time1 = time1 - 12*3600;
40 | //
41 | // return Math.abs(time2 - time1);
42 | // }
43 | public static int getSecond(String time) {
44 | String[] t = time.split(":");
45 | String[] s = t[2].split(" ");
46 | return Integer.parseInt(s[0]);
47 | }
48 |
49 | public static int getSec(String time) {
50 | int sec = 0;
51 | String[] temp = time.split(":");
52 | sec = Integer.parseInt(temp[0]) * 3600;
53 | sec += Integer.parseInt(temp[1]) * 60;
54 | temp = temp[2].split(" ");
55 | sec += Integer.parseInt(temp[0]);
56 | return sec;
57 | }
58 |
59 | public static String getTimeWithoutSeconds(String time){
60 | String[] t = time.split(":");
61 | String[] AMORPM = t[2].split(" ");
62 | String newTime = t[0]+":"+t[1]+" " +AMORPM[1];
63 | return newTime;
64 | }
65 | public static String secondsToTime(double time) {
66 |
67 | int hours = (int) (time / 3600);
68 | time = time - (hours * 3600);
69 | int minutes = (int) (time / 60);
70 | time = time - minutes * 60;
71 | // int seconds = (int) time;// for visibility matter (Timer issue) TODO
72 | // is't right ?(MOHAMMED)
73 | String remTime = "";
74 | if ((hours % 12) > 9) {
75 | remTime = (hours % 12) + ":";
76 | } else {
77 | remTime = "0" + (hours % 12) + ":";
78 | }
79 |
80 | if (minutes > 9) {
81 | remTime += minutes;
82 | } else {
83 | remTime += "0" + minutes;
84 | }
85 |
86 | return remTime;
87 | }
88 |
89 | public static int getSec(int hh, int mm, int ss) {
90 | return ((hh * 3600) + (mm * 60) + ss);
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/res/layout/about.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
29 |
30 |
43 |
44 |
55 |
56 |
66 |
67 |
77 |
78 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
33 |
34 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
47 |
48 |
51 |
52 |
53 |
54 |
55 |
56 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
74 |
75 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/activity/AlertActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * AlertActivity Class : implements OnCompletionListener beside extending Activity
3 | * because we need to finish() the activity once the Sound is completed
4 | *
5 | */
6 | package com.shefra.prayertimes.activity;
7 |
8 | //import com.AzizHuss.ArabicRehaper.ArabicReshape;
9 | import com.shefra.prayertimes.R;
10 | import com.shefra.prayertimes.activity.*;
11 | import com.shefra.prayertimes.helper.Typefaces;
12 | import com.shefra.prayertimes.manager.Manager;
13 |
14 | import android.app.Activity;
15 | import android.content.Context;
16 | import android.content.Intent;
17 | import android.media.MediaPlayer;
18 | import android.media.MediaPlayer.OnCompletionListener;
19 | import android.os.Bundle;
20 | import android.os.PowerManager;
21 | import android.os.PowerManager.WakeLock;
22 | import android.view.View;
23 | import android.view.View.OnClickListener;
24 | import android.view.WindowManager;
25 | import android.widget.Button;
26 | import android.widget.TextView;
27 |
28 | public class AlertActivity extends Activity implements OnCompletionListener {
29 | private MediaPlayer mPlayer;
30 | WakeLock wakeLock ;
31 |
32 | @Override
33 | public void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | this.setContentView(R.layout.alert);
36 |
37 | /*
38 | * This code together with the one in onDestroy() will make the screen
39 | * be always on until this Activity destroyed.
40 | */
41 |
42 | Intent intent = this.getIntent();
43 | if(intent.getBooleanExtra("runFromService", false) == false)
44 | {
45 | Intent intent2 = new Intent(this,MainActivity.class);
46 | this.startActivity(intent2);
47 | this.finish();
48 | }else{
49 | intent.putExtra("runFromService", true);
50 | }
51 | PowerManager pm = (PowerManager) this.getApplicationContext().getSystemService(Context.POWER_SERVICE);
52 | wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
53 | wakeLock.acquire();
54 | getWindow().addFlags(
55 | WindowManager.LayoutParams.FLAG_FULLSCREEN
56 | | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
57 | //Manager.acquireScreen(this);
58 |
59 | String ardroid = getString(R.string.azandoaa);
60 |
61 | TextView azanDoaa = (TextView) findViewById(R.id.azandoaa);
62 | azanDoaa.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/DroidNaskh-Regular.ttf"));
63 | azanDoaa.setText(ardroid);
64 |
65 | try {
66 |
67 | mPlayer = MediaPlayer.create(AlertActivity.this, R.raw.majed);
68 | mPlayer.setOnCompletionListener(AlertActivity.this);
69 | mPlayer.start();
70 |
71 |
72 | } catch (Exception e) {
73 |
74 | }
75 |
76 | Button b = (Button) findViewById(R.id.button2);
77 | b.setOnClickListener(new OnClickListener() {
78 | public void onClick(View v) {
79 | mPlayer.stop();
80 | finish();
81 | }
82 | });
83 |
84 | }
85 |
86 | @Override
87 | public void onDestroy() {
88 | //Manager.releaseScreen(this);
89 | wakeLock.release();
90 | this.mPlayer.stop();
91 | super.onDestroy();
92 | }
93 |
94 | public void onCompletion(MediaPlayer mp) {
95 | Intent intent2 = new Intent(this,MainActivity.class);
96 | this.startActivity(intent2);
97 | this.finish();
98 | }
99 |
100 | public void onStop(){
101 | super.onStop();
102 | // TODO :
103 | // we might need to finish() this activity and set a flag runFromService from here.. ?
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/manager/CityLocationListener.java:
--------------------------------------------------------------------------------
1 | package com.shefra.prayertimes.manager;
2 |
3 | import com.shefra.prayertimes.activity.CityFinder;
4 | import com.shefra.prayertimes.activity.CityFinder;
5 |
6 | import android.app.Activity;
7 | import android.app.ProgressDialog;
8 | import android.content.Context;
9 | import android.content.DialogInterface;
10 | import android.location.Location;
11 | import android.location.LocationListener;
12 | import android.location.LocationManager;
13 | import android.os.Bundle;
14 | import android.os.Handler;
15 |
16 | public class CityLocationListener implements LocationListener {
17 | LocationManager locManager;
18 | Context context;
19 | private Integer objectType;
20 |
21 | public CityLocationListener(Context context, Integer objectType) {
22 | this.context = context;
23 | this.objectType = objectType;
24 | }
25 |
26 | public void startSearch() {
27 | try {
28 | locManager = (LocationManager) context
29 | .getSystemService(Context.LOCATION_SERVICE);
30 |
31 | // If the network provider works run it , else try GPS provider
32 | // TODO : what will happen if GPS and Network providers are not
33 | // supported ?
34 |
35 | if (!locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
36 | // the last parameter is Location Listener which is this object
37 | // since we implement LocationListener Interface
38 | // read more on Android
39 | if (locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
40 | locManager.requestLocationUpdates(
41 | LocationManager.GPS_PROVIDER, 0, 0, this);
42 | } else {
43 | CityFinder finder = (CityFinder) context;
44 | finder.onSearchStopped(null);
45 | }
46 | } else {
47 | // the last parameter is Location Listener which is this object
48 | // since we implement LocationListener Interface
49 | // read more on Android
50 | locManager.requestLocationUpdates(
51 | LocationManager.NETWORK_PROVIDER, 0, 0, this);
52 |
53 | }
54 | } catch (Exception e) {
55 | e = e;
56 |
57 | }
58 |
59 | }
60 |
61 | // private int updateLocation(Location location) {
62 | // if (location != null) {
63 | // final double lat = location.getLatitude();
64 | // final double lng = location.getLongitude();
65 | //
66 | // try {
67 | // Manager manager = new Manager(context);
68 | // manager.findCurrentCity(lat, lng);
69 | // // update main activity since the city name is changed
70 | // // just update all views
71 | //
72 | // } catch (Exception e) {
73 | // return -1;
74 | //
75 | // }
76 | //
77 | // }
78 | // locManager.removeUpdates(this);
79 | // CityFinder cityFinder = (CityFinder) context;
80 | // cityFinder.stopSearch();
81 | // return 0 ; // successful
82 | // }
83 |
84 | public void stopSearch() {
85 | if (locManager != null)
86 | locManager.removeUpdates(this);
87 | }
88 |
89 | // Location Listener implementation
90 | // read Android doc for more info
91 | // this methods is triggered when new location ( latitiude and longitude )
92 | // is found by the system
93 | public void updateWithNewLocation(Location location) {
94 | String latLongString = "";
95 |
96 | if (location != null) {
97 | double lat = location.getLatitude();
98 | double lng = location.getLongitude();
99 |
100 | }
101 |
102 | // ok , we don't need this listener anymore :)
103 | this.stopSearch();
104 | // and hide the waiting dialog
105 | CityFinder finder = (CityFinder) context;
106 | finder.onSearchStopped(location);
107 |
108 | }
109 |
110 | // read Android Docs
111 | public void onLocationChanged(Location location) {
112 | updateWithNewLocation(location);
113 | }
114 |
115 | // read Android Docs
116 | public void onProviderDisabled(String provider) {
117 | updateWithNewLocation(null);
118 | }
119 |
120 | public void onProviderEnabled(String provider) {
121 | provider = provider ;
122 | }
123 |
124 | public void onStatusChanged(String provider, int status, Bundle extras) {
125 | provider = provider ;
126 | }
127 |
128 | }
--------------------------------------------------------------------------------
/res/layout/cityfinder.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
29 |
30 |
40 |
41 |
51 |
52 |
61 |
62 |
71 |
72 |
82 |
83 |
92 |
93 |
100 |
101 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/manager/Preference.java:
--------------------------------------------------------------------------------
1 | package com.shefra.prayertimes.manager;
2 |
3 | import java.util.Map;
4 |
5 | import android.content.Context;
6 | import android.content.SharedPreferences;
7 | import android.content.SharedPreferences.Editor;
8 | import android.preference.PreferenceManager;
9 |
10 | public class Preference {
11 |
12 | private Context context;
13 | public String mazhab = null;
14 | public String calender = null;
15 | public String season = null;
16 | public City city = null;
17 |
18 | public static String DEFAULT_COUNTRY_ID = "211" ; // SA
19 | public static String DEFAULT_COUNTRY_NAME = "Saudi Arabia" ; // SA
20 | public static String DEFAULT_CITY_ID = "14244";
21 | public static String DEFAULT_CITY_NAME = "Makkah";
22 | public static Integer DEFAULT_TIMEZONE = 3;
23 | public static String DEFAULT_LATITUDE = "21.4300003051758";
24 | public static String DEFAULT_LONGITUDE = "39.8199996948242";
25 | public static String DEFAULT_CALENDAR = "UmmAlQuraUniv";
26 | public static String DEFAULT_MAZHAB = "Default";
27 | public static String DEFAULT_SEASON = "Winter";
28 | public static Integer DEFAULT_SILENT_DURATION = 20 * 60 * 1000;
29 | public static Integer DEFAULT_SILENT_START= 2 * 60 * 1000;
30 | public Preference(Context context) {
31 | this.context = context;
32 | }
33 |
34 | public void fetchCurrentPreferences() {
35 |
36 | SharedPreferences preferences = PreferenceManager
37 | .getDefaultSharedPreferences(context);
38 | this.city = new City();
39 | this.city.name = (String) preferences.getString("cityName",DEFAULT_CITY_NAME);
40 | this.city.id = (String) preferences.getString("cityNo",DEFAULT_CITY_ID);
41 | this.city.country.name = (String) preferences.getString("countryName",DEFAULT_COUNTRY_NAME);
42 | this.city.country.id = (String) preferences.getString("countryNo",DEFAULT_COUNTRY_ID);
43 | this.city.timeZone = (Integer) preferences.getInt("timeZone",DEFAULT_TIMEZONE);
44 | this.city.latitude = (String) preferences.getString("latitude", DEFAULT_LATITUDE);
45 | this.city.longitude = (String) preferences.getString("longitude", DEFAULT_LONGITUDE);
46 | this.calender = (String) preferences.getString("calendar",DEFAULT_CALENDAR);
47 | this.mazhab = (String) preferences.getString("mazhab",DEFAULT_MAZHAB);
48 | this.season = (String) preferences.getString("season",DEFAULT_SEASON);
49 |
50 | }
51 |
52 | public boolean isFirstStart(){
53 | SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
54 | boolean firstStart = pref.getBoolean("firstStart",true);
55 | return firstStart;
56 | }
57 |
58 | public void setFirstStart(boolean firstStart) {
59 | SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
60 | Editor edit = pref.edit();
61 | edit.putBoolean("firstStart", firstStart);
62 | edit.commit();
63 | }
64 |
65 | public void setCityName(String name) {
66 | SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
67 | Editor edit = pref.edit();
68 | edit.putString("cityName", name);
69 | edit.commit();
70 | }
71 |
72 | public void setLongitude(String longitude) {
73 | SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
74 | Editor edit = pref.edit();
75 | edit.putString("longitude", longitude);
76 | edit.commit();
77 | }
78 |
79 | public void setLatitude(String latitude) {
80 | SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
81 | Editor edit = pref.edit();
82 | edit.putString("latitude", latitude);
83 | edit.commit();
84 | }
85 |
86 | public void setCountryName(String name) {
87 | SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
88 | Editor edit = pref.edit();
89 | edit.putString("countryName", name);
90 | edit.commit();
91 | }
92 |
93 |
94 | public void setTimeZone(Integer timeZone) {
95 | SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
96 | Editor edit = pref.edit();
97 | edit.putInt("timeZone", timeZone);
98 | edit.commit();
99 | }
100 |
101 | public int getSilentDuration() {
102 | SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
103 | return Integer.parseInt(pref.getString("silentDuration",Integer.toString(DEFAULT_SILENT_DURATION))) * 60 * 1000;
104 | }
105 |
106 | public void setCityNo(String id) {
107 | if(id == null)
108 | return;
109 | SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
110 | Editor edit = pref.edit();
111 | edit.putString("cityNo", id);
112 | edit.commit();
113 |
114 | }
115 |
116 | public void setCountryNo(String id) {
117 | if(id == null)
118 | return;
119 | SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
120 | Editor edit = pref.edit();
121 | edit.putString("countryNo", id);
122 | edit.commit();
123 |
124 | }
125 |
126 | public boolean isAutoSilentDisabled(){
127 | SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
128 | return pref.getBoolean("disable",false);
129 | }
130 |
131 | public int getSilentStart(){
132 | SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
133 | return Integer.parseInt(pref.getString("silentStart",Integer.toString(DEFAULT_SILENT_START))) * 60 * 1000;
134 | }
135 |
136 | public Map getAll(){
137 | SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
138 | return pref.getAll();
139 | }
140 |
141 | }
142 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/activity/CityFinderManual.java:
--------------------------------------------------------------------------------
1 | package com.shefra.prayertimes.activity;
2 |
3 | import com.shefra.prayertimes.R;
4 | import com.shefra.prayertimes.R.id;
5 | import com.shefra.prayertimes.R.layout;
6 | import com.shefra.prayertimes.helper.DatabaseHelper;
7 | import com.shefra.prayertimes.helper.Typefaces;
8 | import com.shefra.prayertimes.manager.City;
9 | import com.shefra.prayertimes.manager.Manager;
10 | import com.shefra.prayertimes.manager.Preference;
11 |
12 | import android.app.Activity;
13 | import android.content.Intent;
14 | import android.database.Cursor;
15 | import android.os.Bundle;
16 | import android.util.Log;
17 | import android.view.View;
18 | import android.view.View.OnClickListener;
19 | import android.widget.AdapterView;
20 | import android.widget.AdapterView.OnItemClickListener;
21 | import android.widget.AdapterView.OnItemSelectedListener;
22 | import android.widget.ArrayAdapter;
23 | import android.widget.Button;
24 | import android.widget.SimpleCursorAdapter;
25 | import android.widget.Spinner;
26 | import android.widget.SpinnerAdapter;
27 | import android.widget.TextView;
28 | import android.widget.Toast;
29 |
30 | public class CityFinderManual extends Activity {
31 |
32 | private Spinner countrySpinner;
33 | private Spinner citySpinner;
34 | private Button saveButton;
35 | private View caneclButton;
36 | private boolean onCreateDone;
37 | private Preference preference;
38 | private DatabaseHelper databaseHelper;
39 | private boolean isCityCursorOpen;
40 |
41 | /** Called when the activity is first created. */
42 | @Override
43 | public void onCreate(Bundle savedInstanceState) {
44 | try {
45 | super.onCreate(savedInstanceState);
46 | this.setContentView(R.layout.cityfindermanual);
47 |
48 | TextView textView = (TextView) findViewById(R.id.textView1);
49 | textView.setTypeface(Typefaces.get(this.getBaseContext(),
50 | "fonts/DroidNaskh-Regular.ttf"));
51 |
52 | citySpinner = (Spinner) findViewById(R.id.citySpinner);
53 | countrySpinner = (Spinner) findViewById(R.id.countrySpinner);
54 |
55 | databaseHelper = new DatabaseHelper(getApplicationContext());
56 | Manager manager = new Manager(this);
57 | preference = manager.getPreference();
58 | preference.fetchCurrentPreferences();
59 |
60 | this.fillCountrySpinner();
61 | countrySpinner.setSelection(Integer
62 | .valueOf(preference.city.country.id) - 1);
63 | this.fillCitySpinner(Long.parseLong(preference.city.country.id));
64 |
65 | countrySpinner
66 | .setOnItemSelectedListener(new OnItemSelectedListener() {
67 |
68 | public void onItemSelected(AdapterView> parentView,
69 | View selectedItemView, int position, long id) {
70 | // don't fill the Spinner if onCreate method is
71 | // working
72 | // to prevent double filling , since it has been
73 | // filled
74 | fillCitySpinner(id);
75 | }
76 |
77 | public void onNothingSelected(AdapterView> parentView) {
78 | // your code here
79 | }
80 |
81 | });
82 |
83 | this.saveButton = (Button) findViewById(R.id.saveButton);
84 | this.saveButton.setOnClickListener(new OnClickListener() {
85 |
86 | public void onClick(View arg0) {
87 | try {
88 | long id = citySpinner.getSelectedItemId();
89 | City city = databaseHelper.getCity(id);
90 | Manager manager = new Manager(CityFinderManual.this);
91 | manager.updateCity(city, CityFinderManual.this);
92 | Toast.makeText(
93 | CityFinderManual.this,
94 | CityFinderManual.this
95 | .getString(R.string.cityUpdated),
96 | Toast.LENGTH_SHORT).show();
97 | Intent intent = new Intent(CityFinderManual.this,
98 | MainActivity.class);
99 | startActivity(intent);
100 | } catch (Exception e) {
101 | //Log.e("tomaanina", e.getMessage(), e.getCause());
102 | }
103 | }
104 |
105 | });
106 | } catch (Exception e) {
107 | //Log.e("tomaanina", e.getMessage(), e.getCause());
108 | }
109 | }
110 |
111 | public void onStart() {
112 | super.onStart();
113 | }
114 |
115 | private int getItemPosition(Spinner spinner, String name) {
116 | int i = 0;
117 | SpinnerAdapter adapter = spinner.getAdapter();
118 | for (i = 0; i < adapter.getCount(); i++) {
119 | Cursor temp = (Cursor) adapter.getItem(i);
120 | String n = temp.getString(temp.getColumnIndex("cityName"));
121 | if (name.equals(n)) {
122 | return i;
123 | }
124 | }
125 | return i;
126 | }
127 |
128 | private void fillCountrySpinner() {
129 |
130 | Cursor cursor = databaseHelper.getCountryList();
131 |
132 | String[] columns = new String[] { "country_name" };
133 | int[] to = new int[] { android.R.id.text1 };
134 |
135 | SimpleCursorAdapter countryAdapter = new SimpleCursorAdapter(this,
136 | android.R.layout.simple_spinner_item, cursor, columns, to);
137 | countryAdapter
138 | .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
139 |
140 | this.countrySpinner.setAdapter(countryAdapter);
141 |
142 | }
143 |
144 | private void fillCitySpinner(long id) {
145 | if (this.isCityCursorOpen) {
146 | SimpleCursorAdapter b = (SimpleCursorAdapter) this.citySpinner
147 | .getAdapter();
148 | Cursor oldCursor = b.getCursor();
149 |
150 | if (oldCursor.isClosed() == false) {
151 | oldCursor.close();
152 | }
153 | }
154 |
155 | Cursor cursor = databaseHelper.getCityCursor(id);
156 |
157 | String[] columns = new String[] { "cityName" };
158 | int[] to = new int[] { android.R.id.text1 };
159 |
160 | SimpleCursorAdapter cityAdapter = new SimpleCursorAdapter(this,
161 | android.R.layout.simple_spinner_item, cursor, columns, to);
162 | cityAdapter
163 | .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
164 |
165 | this.citySpinner.setAdapter(cityAdapter);
166 | this.isCityCursorOpen = true;
167 |
168 | }
169 |
170 | public void onStop() {
171 | super.onStop();
172 |
173 | }
174 |
175 | public void onDestroy() {
176 | super.onDestroy();
177 | SimpleCursorAdapter a = (SimpleCursorAdapter) this.countrySpinner
178 | .getAdapter();
179 | a.getCursor().close();
180 | SimpleCursorAdapter b = (SimpleCursorAdapter) this.citySpinner
181 | .getAdapter();
182 | b.getCursor().close();
183 |
184 | databaseHelper.close();
185 |
186 | }
187 |
188 | }
189 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/services/PrayerReceiver.java:
--------------------------------------------------------------------------------
1 | package com.shefra.prayertimes.services;
2 |
3 |
4 | import java.io.IOException;
5 | import java.util.Date;
6 |
7 | import com.shefra.prayertimes.R;
8 | import com.shefra.prayertimes.helper.TimeHelper;
9 | import com.shefra.prayertimes.manager.Manager;
10 | import com.shefra.prayertimes.manager.PrayerState;
11 | import com.shefra.prayertimes.manager.Preference;
12 |
13 | import android.app.AlarmManager;
14 | import android.app.Notification;
15 | import android.app.NotificationManager;
16 | import android.app.PendingIntent;
17 | import android.content.BroadcastReceiver;
18 | import android.content.Context;
19 | import android.content.Intent;
20 | import android.content.SharedPreferences;
21 | import android.content.SharedPreferences.Editor;
22 | import android.media.AudioManager;
23 | import android.media.Ringtone;
24 | import android.media.RingtoneManager;
25 | import android.net.Uri;
26 | import android.os.Message;
27 | import android.preference.PreferenceManager;
28 | import android.util.Log;
29 |
30 | /*
31 | * The Prayer Alarm Life Cycle has three states :
32 | * 1- Waiting for the Next Azan: Wait until the Azan time.
33 | * 2- PreDoing the Azan: if the mobile mode is in neither silent nor vibrate
34 | * then play the Azan soudn track + move to the next state when the Azan sound track finished.Currently we don;t know when, but we assume that three minutes is enought.
35 | * 3- On Doing the Azan: for the future. when we able to detect that the sound track is finished then move to the next state. currently , we move to the next state after 3 minutes always.
36 | * 4- On Waiting the prayer:
37 | */
38 | public class PrayerReceiver extends BroadcastReceiver {
39 |
40 | private PrayerState prayerState;
41 | private AudioManager am;
42 | private Context context;
43 | private SharedPreferences pref;
44 | private Editor editor;
45 | private int silentDuration;
46 | private int silentStart ;
47 | private int delayMilliSeconds = 1000 * 60; // one minute by default.
48 | private Object obj;
49 |
50 |
51 | @Override
52 | public void onReceive(Context context, Intent intent) {
53 | this.context = context;
54 | pref = PreferenceManager.getDefaultSharedPreferences(this.context);
55 |
56 | Manager m = new Manager(context);
57 | Preference p = m.getPreference();
58 | this.silentDuration = p.getSilentDuration();
59 | this.silentStart = p.getSilentStart();
60 | //Log.i("com.shefrah.prayertimes","SilentDuration:"+ this.silentDuration);
61 | editor = pref.edit();
62 | try {
63 |
64 | prayerState = Manager.getPrayerState();
65 | am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
66 | switch (prayerState.getCurrentState()) {
67 |
68 | case PrayerState.WAITING_AZAN:
69 | onWaitingAzan();
70 |
71 | break;
72 | case PrayerState.DOING_AZAN:
73 | onDoingAzan();
74 | break;
75 |
76 | case PrayerState.WAITING_PRAYER:
77 | onWaitingPrayer();
78 |
79 | break;
80 |
81 | }
82 |
83 | } catch (Exception e) {
84 | // TODO Auto-generated catch block
85 | //Log.e("com.shefrah.prayertimes", e.getMessage());
86 | }
87 |
88 | }
89 |
90 |
91 | public int getDelayMilliSeconds() {
92 | return delayMilliSeconds;
93 | }
94 |
95 | public void setDelayMilliSeconds(int delayMilliSeconds) {
96 | this.delayMilliSeconds = delayMilliSeconds;
97 | }
98 |
99 | private void onWaitingAzan() {
100 | try {
101 | //Log.i("com.shefrah.prayertimes",
102 | //"WAITING_AZAN:" + Long.toString(System.currentTimeMillis()));
103 |
104 | // change it to normal mode only if you are not waiting the prayer (
105 | // out of the prayer time)
106 | // don't change it to Normal until you have already have changed it
107 | // to silent
108 | boolean isRingerModeChangedToSilent = pref.getBoolean(
109 | "isRingerModeChangedToSilent", false);
110 | if (isRingerModeChangedToSilent == true) {
111 | am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
112 | editor.putBoolean("isRingerModeChangedToSilent", false);
113 | editor.commit();
114 | }
115 |
116 | // What is the remaining time until the next prayer ?
117 | Date date = new Date();
118 | int dd = date.getDate();
119 | int mm = date.getMonth() + 1;
120 | int yy = date.getYear() + 1900;
121 | int h = date.getHours();
122 | int m = date.getMinutes();
123 | int s = date.getSeconds();
124 | int nearestPrayerTime = Manager.computeNearestPrayerTime(context,
125 | h, m, s, yy, mm, dd);
126 | int deffTime = TimeHelper.different((h * 3600 + m * 60 + s),
127 | nearestPrayerTime);
128 | deffTime = deffTime * 1000; // to milliseconds
129 |
130 | // ok , come back after X seconds to do the Azan
131 | prayerState.setNextState(PrayerState.DOING_AZAN);
132 | this.delayMilliSeconds = deffTime;
133 | //Log.i("com.shefrah.prayertimes","AZAN_AFTER:" + deffTime);
134 | //this.postDelayed((Runnable)obj, delayMilliSeconds );
135 | Manager.updatePrayerAlarm(delayMilliSeconds);
136 |
137 | } catch (Exception e) {
138 | //Log.e("com.shefrah.prayertimes", e.getMessage());
139 | }
140 | }
141 |
142 | private void onDoingAzan() {
143 | //Log.i("com.shefrah.prayertimes",
144 | // "DOING_AZAN:" + Long.toString(System.currentTimeMillis()));
145 |
146 |
147 | prayerState.setNextState(PrayerState.WAITING_PRAYER);
148 | this.delayMilliSeconds = this.silentStart;
149 | if(this.delayMilliSeconds < 2000*60)
150 | this.delayMilliSeconds =2000*60; // two minutes - at lease
151 | Manager.playAzanNotification(context);
152 | //this.postDelayed((Runnable)obj, delayMilliSeconds );
153 | Manager.updatePrayerAlarm(delayMilliSeconds);
154 |
155 |
156 | }
157 |
158 | private void onWaitingPrayer() {
159 | //Log.i("com.shefrah.prayertimes","WAITING_PRAYER:" + Long.toString(System.currentTimeMillis()));
160 | Manager manager = new Manager(this.context);
161 | Preference preference = manager.getPreference();
162 | AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
163 | if(am.getRingerMode() == AudioManager.RINGER_MODE_NORMAL && preference.isAutoSilentDisabled()==false ){
164 | am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
165 | editor.putBoolean("isRingerModeChangedToSilent", true);
166 | editor.commit();
167 | }
168 | this.delayMilliSeconds = silentDuration;
169 | prayerState.setNextState(PrayerState.WAITING_AZAN);
170 | //this.postDelayed((Runnable)obj, delayMilliSeconds );
171 | Manager.updatePrayerAlarm(delayMilliSeconds);
172 |
173 |
174 | }
175 |
176 |
177 | }
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | طمأنينة
5 | ص
6 | م
7 |
8 |
9 | - حنفي
10 | - شافعي...
11 |
12 |
13 | - Hanafi
14 | - Default
15 |
16 |
17 | - صيفي
18 | - شتوي
19 |
20 |
21 | - Summer
22 | - Winter
23 |
24 |
25 | - أم القرى
26 | - أمريكا الشمالية
27 | - جامعة العلوم الإسلامية بكراتشى
28 | - رابطة العالم الإسلامي
29 | - الهيئة العامة المصرية للمساحة
30 |
31 |
32 | - UmmAlQuraUniv
33 | - IslamicSocietyOfNorthAmerica
34 | - UnivOfIslamicScincesKarachi
35 | - MuslimWorldLeague
36 | - EgytionGeneralAuthorityofSurvey
37 |
38 |
39 | - بعد الأذان مباشرة
40 | - 10 دقيقة
41 | - 20 دقيقة
42 |
43 |
44 | - 2
45 | - 10
46 | - 20
47 |
48 |
49 | - 10 دقيقة
50 | - 20 دقيقة
51 | - 30 دقيقة
52 |
53 |
54 | - 10
55 | - 20
56 | - 30
57 |
58 |
59 | - بدون صوت
60 | - تنبيه
61 | - أذان كامل
62 |
63 |
64 | - Disable
65 | - short
66 | - full
67 |
68 |
69 | إعدادات المدينة
70 | المدينة
71 | ابحث عن مدينتي
72 | البحث عن المدينة التي تتواجد بها الآن عن طريق أبراج الاتصالات أو عن طريق الأقمار الصناعية
73 | الدولة
74 | اختر الدولة
75 | المدينة
76 | اختر المدينة
77 | إعدادات الوضع الصامت
78 | إيقاف التحويل إلى صامت
79 | إيقاف التحويل التلقائي إلى الوضع الصامت عندما يحين وقت الأذان
80 | وقت البدء بالوضع الصامت
81 | متى يتم التحويل إلى صامت؟
82 | متى ترغب بالتحويل إلى الوضع الصامت عندما يحين وقت الأذان
83 | مدة الوضع الصامت
84 | مدة بقاء النظام على الوضع الصامت بعد الأذان
85 | مدة البقاء على الوضع الصامت
86 | إعدادات عامة
87 | صوت الإشعار
88 | صوت الإشعار
89 | المذهب الفقهي
90 | المذهب الفقهي
91 |
92 | التوقيت
93 | التوقيت
94 | البحث التلقائي
95 | البحث اليدوي
96 | المحاولة مرة أخرى
97 | الإعدادات
98 | عن الفريق
99 | إغلاق
100 | 20 دقيقة
101 | 30 دقيقة
102 | 10 دقائق
103 | بعد الأذان مباشرة
104 | خدمة جي-بي-إس و خدمة أبراج الشبكة لاتعمل الآن ، في حال أردت أن تقوم بالبحث التلقائي عن المدينة فيجب تشغيلها ثم العودة مرة أخرى ، سيتم نقلك الآن لإعدادات النظام
105 | خدمة جي-بي-إس أو خدمة أبراج الشبكة تعمل ، سيتم البحث الآن عن مدينتك
106 | حان وقت الصلاة
107 | حان وقت الصلاة
108 | تطوير و برمجة فريق شيفرة
109 | لا يمكن الحصول على إحداثيات موقعك الحالي.يجب تفعيل جي-بي-إس أو شبكة الاتصال أو محاولة البحث بطريقة يدوية.
110 | الرجاء الانتظار
111 | إلغاء
112 | موافق
113 | لم يتم العثور على مدينة في موقعك الحالي
114 | سيتم البحث بإستخدام أبراج الشبكة أو خدمة جي-بي-إس ، تأكد من تفعيل إحدى الخدمتين ليتم العثور على المدينة
115 | 1.1 Final Release
116 | http://www.shefrah.com
117 | طريقة الحساب
118 | طريقة الحساب
119 | الفجر
120 | الظهر
121 | العصر
122 | المغرب
123 | العشاء
124 | الصلاة القادمة بعد
125 | المدينة
126 | اللهم ربَّ هذه الدعوة التامة ، والصلاة القائمة ، آت محمداً الوسيلة والفضيلة ، وابعثه اللهم مقاماً محموداً الذي وعدته.
127 | الإعدادات تظهر أن مدينتك الحالية هي:
128 | نتيجة البحث تظهر أن موقعك في مدينة:
129 | البحث عن طريق الانترنت
130 | البحث دون اتصال بالانترنت
131 | لا أريد تحديث موقعي
132 | العودة للواجهة الرئيسية
133 | إعادة البحث
134 | نعم صحيح
135 | لا يمكن الاتصال بالانترنت.حاول مرة أخرى أو استخدم خيار البحث دون اتصال بالانترنت
136 | حصل خطأ أثناء البحث عن مدينتك.حاول مرة أخرى أو استخدم خيار البحث عن طريق الانترنت
137 | اختر الدولة ثم المدينة التي تتواجد بها الآن ، سيتم حفظ المدينة وتحديث إعدادات التطبيق. إذا لم تجد المدينة في القائمة ولم تستطع إيجادها عن طريق البحث التلقائي ، قم بمراسلتنا لنضيف مدينتك لقائمة المدن.
138 | لقد تم تحديث موقعك الحالي بنجاح
139 | تحديث المدينة
140 | تواصل معنا
141 | أبلغ عن مشكلة
142 | shefrahteam@gmail.com
143 | [طمأنينة][feedback]
144 | لا تنسى إضافة معلومات عن نوع جهازك و النظام الذي يعمل عليه
145 | اختر تطبيق الإيميل
146 | لا يمكن العثور على تطبيق للبريد الإلكتروني على جهازك
147 | shefrahteam@gmail.com
148 | [طمأنينة][general]
149 | لا تنسى إضافة معلومات عن نوع جهازك و النظام الذي يعمل عليه
150 | اختر تطبيق الإيميل
151 | لا يمكن العثور على تطبيق للبريد الإلكتروني على جهازك
152 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/activity/SettingsActivity.java:
--------------------------------------------------------------------------------
1 | package com.shefra.prayertimes.activity;
2 |
3 |
4 |
5 | import java.util.List;
6 |
7 | import com.shefra.prayertimes.R;
8 | import com.shefra.prayertimes.activity.*;
9 | import com.shefra.prayertimes.helper.DatabaseHelper;
10 | import com.shefra.prayertimes.manager.*;
11 | import com.shefra.prayertimes.manager.Preference;
12 | import com.shefra.prayertimes.services.PrayerService;
13 |
14 | import android.content.Context;
15 | import android.content.Intent;
16 | import android.content.SharedPreferences;
17 | import android.content.SharedPreferences.Editor;
18 | import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
19 | import android.location.LocationManager;
20 | import android.os.Bundle;
21 | import android.preference.*;
22 | import android.preference.Preference.OnPreferenceChangeListener;
23 | import android.preference.Preference.OnPreferenceClickListener;
24 | import android.widget.Toast;
25 |
26 | // this class is the main class for Settings screen
27 | // It used PreferenceActivity to do the job
28 | // read more on Android Doc about Preference
29 | public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener {
30 | Manager m;
31 | DatabaseHelper databaseHelper ;
32 |
33 |
34 |
35 | @Override
36 | public void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | addPreferencesFromResource(R.xml.settings);
39 |
40 | // initialized the Settings activity with new values
41 | this.init();
42 |
43 | }
44 | public void init(){
45 | m = new Manager(getApplicationContext());
46 | databaseHelper = new DatabaseHelper(getApplicationContext());
47 | databaseHelper.close();
48 | try {
49 |
50 | Preference preference = m.getPreference();
51 | preference.fetchCurrentPreferences();
52 | // country List preference assigned with Country listener
53 | // to get know when the country is changed
54 | // the same thing with city preference
55 | // ListPreference countryPreference = (ListPreference) findPreference("country");
56 | // ListPreference cityPreference = (ListPreference) findPreference("city");
57 | // CountryListener countryListener = new CountryListener(cityPreference,m);
58 | // countryPreference.setOnPreferenceChangeListener(countryListener);
59 | // CityListener cityListener = new CityListener(cityPreference,m);
60 | // cityPreference.setOnPreferenceChangeListener(cityListener);
61 | //
62 | // // fill country preference list with country list
63 | // fillCountryPreference(countryPreference);
64 | // String v = countryPreference.getValue();
65 | // if(v == null)
66 | // v = DEFAULT_COUNTRY_ID;//TODO
67 | // CityListener.fillCityPreference(cityPreference,v ,databaseHelper);
68 | //
69 | // ok , now let us set summary sections for each preference
70 |
71 | String countryName = preference.city.country.name;
72 | String cityName = preference.city.name; //TODO: check default value/ the second parameter
73 |
74 | // countryPreference.setSummary(countryName);
75 | //
76 | //
77 | // String cityId = pref.getString("city", "1"); // TODO : check default value/ second parameter
78 | // cityPreference.setSummary(databaseHelper.getCity(Integer.parseInt(cityId)).cityName);
79 | //
80 | // set Summary text for each element in the setting screen
81 | // Read more about summary code on Android Docs!
82 | // It used to display the selected value ( current value ) under the element
83 | // e.g. if the current country "XYZ" the it displays XYZ under the element
84 | // it reads the value from xml ( preference file) and uses Manager helper functions as well
85 | PreferenceScreen ps = (PreferenceScreen) findPreference("first_preferencescreen");
86 | ps.setSummary(countryName + "/" + cityName);
87 | ps.setOnPreferenceClickListener(new OnPreferenceClickListener(){
88 |
89 | public boolean onPreferenceClick(
90 | android.preference.Preference arg0) {
91 | Intent intent = new Intent(SettingsActivity.this,CityFinder.class);
92 | SettingsActivity.this.startActivity(intent);
93 | return false;
94 | }
95 |
96 | });
97 |
98 | ListPreference ssLP = (ListPreference) findPreference("silentStart");
99 | String silentStart = ssLP.getEntry().toString();
100 | ssLP.setSummary(silentStart);
101 |
102 | ListPreference sdLP = (ListPreference) findPreference("silentDuration");
103 | String silentDuration = sdLP.getEntry().toString();
104 | sdLP.setSummary(silentDuration);
105 |
106 | ListPreference nsLP = (ListPreference) findPreference("notSound");
107 | String nsString = nsLP.getEntry().toString();
108 | nsLP.setSummary(nsString);
109 |
110 |
111 | ListPreference mazhabP = (ListPreference) findPreference("mazhab");
112 | MazhabListener mazhabListener= new MazhabListener();
113 | mazhabP.setOnPreferenceChangeListener(mazhabListener);
114 | String mazhabSummary = mazhabP.getEntry().toString();
115 | mazhabP.setSummary(mazhabSummary);
116 |
117 | ListPreference seasonP = (ListPreference) findPreference("season");
118 | SeasonListener seasonListener= new SeasonListener();
119 | seasonP.setOnPreferenceChangeListener(seasonListener);
120 | String seasonSummary = seasonP.getEntry().toString();
121 | seasonP.setSummary(seasonSummary);
122 |
123 |
124 | ListPreference calendarP = (ListPreference) findPreference("calendar");
125 | CalendarListener calendarListener= new CalendarListener();
126 | calendarP.setOnPreferenceChangeListener(calendarListener);
127 | String calSummary = calendarP.getEntry().toString();
128 | calendarP.setSummary(calSummary);
129 | } catch (Exception e) {
130 | // TODO Auto-generated catch block
131 | e.printStackTrace();
132 | }
133 | }
134 |
135 |
136 | // // read data from database into preference list
137 | // private void fillCountryPreference(ListPreference countryPref) {
138 | // List countryList = databaseHelper.getCountryList();
139 | // CharSequence[] countryEntries = new CharSequence[countryList.size()];
140 | // CharSequence[] countryEntryValues = new CharSequence[countryList.size()];
141 | // int i = 0;
142 | // for (Country c : countryList) {
143 | // countryEntries[i] = c.countryName;
144 | // countryEntryValues[i] = Integer.toString(c.countryNo);
145 | // i++;
146 | // }
147 | // countryPref.setEntries(countryEntries);
148 | // countryPref.setDefaultValue("211");
149 | // countryPref.setEntryValues(countryEntryValues);
150 | //
151 | // }
152 |
153 | protected void onResume() {
154 | super.onResume();
155 | this.init();
156 | getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener( this );
157 | }
158 |
159 | protected void onPause() {
160 | super.onPause();
161 | getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener( this );
162 | }
163 |
164 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
165 | this.init();
166 | }
167 |
168 | private class MazhabListener implements OnPreferenceChangeListener
169 | {
170 | public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
171 |
172 | // restart the service when the value changed, by this way
173 | // the service will calculate the remaining time to the next prayer
174 | // based on the new prayer time
175 | Intent intent = new Intent(SettingsActivity.this, PrayerService.class);
176 | startService(intent);
177 | return true;
178 | }
179 |
180 |
181 | }
182 |
183 | private class CalendarListener implements OnPreferenceChangeListener
184 | {
185 | public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
186 |
187 | // restart the service when the value changed, by this way
188 | // the service will calculate the remaining time to the next prayer
189 | // based on the new prayer time
190 | // SharedPreferences pref = PreferenceManager
191 | // .getDefaultSharedPreferences(getApplicationContext());
192 | // Editor editor = pref.edit();
193 | // editor.putString("calendar",newValue.toString());
194 | Intent intent = new Intent(SettingsActivity.this, PrayerService.class);
195 | startService(intent);
196 | return true;
197 | }
198 |
199 | }
200 |
201 | private class SeasonListener implements OnPreferenceChangeListener
202 | {
203 | public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
204 |
205 | // restart the service when the value changed, by this way
206 | // the service will calculate the remaining time to the next prayer
207 | // based on the new prayer time
208 | // SharedPreferences pref = PreferenceManager
209 | // .getDefaultSharedPreferences(SettingsActivity.this);
210 | // Editor editor = pref.edit();
211 | // editor.putString("season",newValue.toString());
212 | Intent intent = new Intent(SettingsActivity.this, PrayerService.class);
213 | startService(intent);
214 | return true;
215 | }
216 | }
217 |
218 |
219 |
220 | }
--------------------------------------------------------------------------------
/gen/com/shefra/prayertimes/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 |
8 | package com.shefra.prayertimes;
9 |
10 | public final class R {
11 | public static final class array {
12 | public static final int calendarEntry=0x7f070004;
13 | public static final int calendarValues=0x7f070005;
14 | public static final int mazhab=0x7f070000;
15 | public static final int mazhabValues=0x7f070001;
16 | public static final int notSoundEntry=0x7f07000a;
17 | public static final int notSoundValues=0x7f07000b;
18 | public static final int season=0x7f070002;
19 | public static final int seasonValues=0x7f070003;
20 | public static final int silentDurationEntry=0x7f070008;
21 | public static final int silentDurationEntryValues=0x7f070009;
22 | public static final int silentStartEntry=0x7f070006;
23 | public static final int silentStartEntryValues=0x7f070007;
24 | }
25 | public static final class attr {
26 | }
27 | public static final class drawable {
28 | public static final int alertbackground=0x7f020000;
29 | public static final int background=0x7f020001;
30 | public static final int background1=0x7f020002;
31 | public static final int background2=0x7f020003;
32 | public static final int bbg=0x7f020004;
33 | public static final int icon=0x7f020005;
34 | public static final int logo=0x7f020006;
35 | public static final int prayerstable=0x7f020007;
36 | public static final int prayerstable_left=0x7f020008;
37 | public static final int prayerstable_right=0x7f020009;
38 | public static final int praytimebackground=0x7f02000a;
39 | public static final int praytimetext4=0x7f02000b;
40 | public static final int secondary_background=0x7f02000c;
41 | public static final int shefrah=0x7f02000d;
42 | }
43 | public static final class id {
44 | public static final int asrTV=0x7f08001d;
45 | public static final int asrTime=0x7f08001c;
46 | public static final int azandoaa=0x7f080006;
47 | public static final int button2=0x7f080007;
48 | public static final int cityLabel=0x7f080015;
49 | public static final int cityName=0x7f080014;
50 | public static final int citySpinner=0x7f080012;
51 | public static final int contactUsButton=0x7f080004;
52 | public static final int countrySpinner=0x7f080011;
53 | public static final int dlgMsg=0x7f08000f;
54 | public static final int duhrTV=0x7f08001b;
55 | public static final int duhrTime=0x7f08001a;
56 | public static final int fajrTV=0x7f080019;
57 | public static final int fajrTime=0x7f080018;
58 | public static final int feadbackButton=0x7f080005;
59 | public static final int findCityCorrect=0x7f08000a;
60 | public static final int findCityHome=0x7f080008;
61 | public static final int findCityNoInternet=0x7f08000d;
62 | public static final int findCityResearcht=0x7f080009;
63 | public static final int findCityUsingInternet=0x7f08000c;
64 | public static final int imageView1=0x7f080000;
65 | public static final int ishaTV=0x7f080021;
66 | public static final int ishaTime=0x7f080020;
67 | public static final int magribTV=0x7f08001f;
68 | public static final int magribTime=0x7f08001e;
69 | public static final int nosearch=0x7f08000e;
70 | public static final int progressBar1=0x7f080010;
71 | public static final int remainingText=0x7f080017;
72 | public static final int remainingTime=0x7f080016;
73 | public static final int resultTextView=0x7f08000b;
74 | public static final int saveButton=0x7f080013;
75 | public static final int textView1=0x7f080001;
76 | public static final int textView2=0x7f080002;
77 | public static final int textView3=0x7f080003;
78 | }
79 | public static final class layout {
80 | public static final int about=0x7f030000;
81 | public static final int alert=0x7f030001;
82 | public static final int cityfinder=0x7f030002;
83 | public static final int cityfindermanual=0x7f030003;
84 | public static final int main=0x7f030004;
85 | }
86 | public static final class raw {
87 | public static final int majed=0x7f050000;
88 | public static final int notification=0x7f050001;
89 | }
90 | public static final class string {
91 | public static final int about=0x7f060020;
92 | public static final int am=0x7f060001;
93 | public static final int app_name=0x7f060000;
94 | public static final int asrtxt=0x7f060037;
95 | public static final int autoCitySummary=0x7f060006;
96 | public static final int autoCityTitle=0x7f060005;
97 | public static final int autoSearch=0x7f06001c;
98 | public static final int autoSearchHowDisabled=0x7f060026;
99 | public static final int autoSearchHowEnabled=0x7f060027;
100 | public static final int azandoaa=0x7f06003c;
101 | public static final int calcMethodDlgTitle=0x7f060034;
102 | public static final int calcMethodTitle=0x7f060033;
103 | public static final int cancel=0x7f06002d;
104 | public static final int city=0x7f060009;
105 | public static final int cityDlgTitle=0x7f06000a;
106 | public static final int cityUpdated=0x7f060048;
107 | public static final int cityfinder_correct=0x7f060044;
108 | public static final int cityfinder_desc=0x7f06003d;
109 | public static final int cityfinder_desc2=0x7f06003e;
110 | public static final int cityfinder_home=0x7f060042;
111 | public static final int cityfinder_nosearch=0x7f060041;
112 | public static final int cityfinder_research=0x7f060043;
113 | public static final int cityfinder_searchInternet=0x7f06003f;
114 | public static final int cityfinder_searchWithoutInternet=0x7f060040;
115 | public static final int citytxt=0x7f06003b;
116 | public static final int close=0x7f060021;
117 | public static final int contact_us=0x7f06004a;
118 | public static final int contactusBody=0x7f060053;
119 | public static final int contactusChooserString=0x7f060054;
120 | public static final int contactusEmail=0x7f060051;
121 | public static final int contactusFailed=0x7f060055;
122 | public static final int contactusSubject=0x7f060052;
123 | public static final int country=0x7f060007;
124 | public static final int countryDlgTitle=0x7f060008;
125 | public static final int dialogAutoSearchMessage=0x7f060030;
126 | public static final int disableSummary=0x7f06000d;
127 | public static final int disableTitle=0x7f06000c;
128 | public static final int duhrtxt=0x7f060036;
129 | public static final int fajrtxt=0x7f060035;
130 | public static final int feedback=0x7f06004b;
131 | public static final int feedbackBody=0x7f06004e;
132 | public static final int feedbackChooserString=0x7f06004f;
133 | public static final int feedbackEmail=0x7f06004c;
134 | public static final int feedbackFailed=0x7f060050;
135 | public static final int feedbackSubject=0x7f06004d;
136 | public static final int firstPreferencescreenTitle=0x7f060004;
137 | public static final int generalSettings=0x7f060014;
138 | public static final int gpsAndNetworkIsDisabled=0x7f06002b;
139 | public static final int ishatxt=0x7f060039;
140 | public static final int locationSettings=0x7f060003;
141 | public static final int magribtxt=0x7f060038;
142 | public static final int manualSearch=0x7f06001d;
143 | public static final int manualSearchDesc=0x7f060047;
144 | public static final int manualSearchSave=0x7f060049;
145 | public static final int mazhabDlgTitle=0x7f060018;
146 | public static final int mazhabSummary=0x7f060019;
147 | public static final int mazhabTitle=0x7f060017;
148 | public static final int minutes10=0x7f060024;
149 | public static final int minutes20=0x7f060022;
150 | public static final int minutes30=0x7f060023;
151 | public static final int noCityInDB=0x7f060046;
152 | public static final int noInternet=0x7f060045;
153 | public static final int noLocationFound=0x7f06002f;
154 | public static final int notContent=0x7f060029;
155 | public static final int notSoundDlgTitle=0x7f060016;
156 | public static final int notSoundTitle=0x7f060015;
157 | public static final int notTitle=0x7f060028;
158 | public static final int now=0x7f060025;
159 | public static final int ok=0x7f06002e;
160 | public static final int pleaseWait=0x7f06002c;
161 | public static final int pm=0x7f060002;
162 | public static final int reSearch=0x7f06001e;
163 | public static final int remaintxt=0x7f06003a;
164 | public static final int seasonDlgTitle=0x7f06001b;
165 | public static final int seasonTitle=0x7f06001a;
166 | public static final int settings=0x7f06001f;
167 | public static final int silentDurationDlgTitle=0x7f060013;
168 | public static final int silentDurationSummary=0x7f060012;
169 | public static final int silentDurationTitle=0x7f060011;
170 | public static final int silentSettings=0x7f06000b;
171 | public static final int silentStartDlgTitle=0x7f06000f;
172 | public static final int silentStartSummary=0x7f060010;
173 | public static final int silentStartTitle=0x7f06000e;
174 | public static final int teamName=0x7f06002a;
175 | public static final int version=0x7f060031;
176 | public static final int website=0x7f060032;
177 | }
178 | public static final class xml {
179 | public static final int settings=0x7f040000;
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.shefra.prayertimes.activity;
2 |
3 |
4 |
5 | import java.io.IOException;
6 | import java.util.Date;
7 | import java.util.List;
8 | import java.util.Timer;
9 | import java.util.TimerTask;
10 |
11 | import com.shefra.prayertimes.R;
12 | import com.shefra.prayertimes.helper.DatabaseHelper;
13 | import com.shefra.prayertimes.helper.TimeHelper;
14 | import com.shefra.prayertimes.helper.Typefaces;
15 | import com.shefra.prayertimes.manager.*;
16 |
17 | import android.app.Activity;
18 | import android.content.Intent;
19 | import android.os.Bundle;
20 | import android.os.Handler;
21 | import android.util.Log;
22 | import android.view.Menu;
23 | import android.view.MenuItem;
24 | import android.widget.TextView;
25 |
26 |
27 | // MainActivity represents main screen that is displayed to the user
28 | // it Contains main data such as prayer times , remaining time until next prayer,
29 | // city name , and so on ..
30 | public class MainActivity extends Activity {
31 |
32 |
33 | @Override
34 | public void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | this.setContentView(R.layout.main);
37 | try{
38 | // create Manager object and use it to :
39 | // - load database into system folder at the first time
40 | // - get some data from database (prayer times .. )
41 | // - write some data to the database when necessary .
42 | Manager m = new Manager(getApplicationContext());
43 | DatabaseHelper databaseHelper = new DatabaseHelper(getApplicationContext());
44 |
45 | try {
46 | // this method will work just one time as it is implemented
47 | // it copies the database file from assets folder to data folder
48 | // this step is necessary since that way Android system works :)
49 | databaseHelper.createDatabase();
50 | databaseHelper.close();
51 | } catch (IOException e) {
52 | //Log.e("tomaanina",e.getCause() + ":" + e.getMessage());
53 | }
54 |
55 | // initialize the view objects with the data
56 | this.init();
57 |
58 | // run the app service , read PrayerService for more info
59 | m.restartPrayerService(this);
60 |
61 | // check xml preference file to check if this is the first run for the app
62 | // in the user device.
63 |
64 | Preference pref = m.getPreference();
65 | if(pref.isFirstStart())
66 | {
67 | // run some stuff at first time
68 | // e.g. search for the use city
69 | // TODO : in the future we should run a wizard
70 | // it improve the usability for our app .
71 | this.onFirstStart();
72 |
73 | // ok , change the flag to false , by this way we prevent onFirstStart method from running again
74 | pref.setFirstStart(false);
75 | }
76 | }catch(Exception e){
77 |
78 | }
79 |
80 |
81 | }
82 |
83 | public void init() {
84 |
85 | final Manager manager = new Manager(getApplicationContext());
86 | Preference preference = manager.getPreference();
87 |
88 | preference.fetchCurrentPreferences();
89 | TextView cityTextView = (TextView) findViewById(R.id.cityName);
90 | cityTextView.setText(preference.city.name);
91 | cityTextView.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/DroidNaskh-Regular.ttf"));
92 |
93 | TextView remainingTV = (TextView) findViewById(R.id.remainingText);
94 | TextView cityLabelTV = (TextView) findViewById(R.id.cityLabel);
95 | TextView fajrTV = (TextView) findViewById(R.id.fajrTV);
96 | TextView duhrTV = (TextView) findViewById(R.id.duhrTV);
97 | TextView asrTV = (TextView) findViewById(R.id.asrTV);
98 | TextView magribTV = (TextView) findViewById(R.id.magribTV);
99 | TextView ishaTV = (TextView) findViewById(R.id.ishaTV);
100 |
101 | remainingTV.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/DroidNaskh-Regular.ttf"));
102 | cityLabelTV.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/DroidNaskh-Regular.ttf"));
103 |
104 | fajrTV.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/KacstTitle.ttf"));
105 | duhrTV.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/KacstTitle.ttf"));
106 | asrTV.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/KacstTitle.ttf"));
107 | magribTV.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/KacstTitle.ttf"));
108 | ishaTV.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/KacstTitle.ttf"));
109 |
110 | // get current date
111 | // read Android/Java documentation for more info
112 | Date date = new Date();
113 | final int dd = date.getDate();//calendar.get(Calendar.DAY_OF_MONTH);
114 | final int mm = date.getMonth()+1;//7;//calendar.get(Calendar.MONTH+1);
115 | final int yy = date.getYear()+1900;//calendar.get(Calendar.YEAR);
116 |
117 |
118 | try {
119 |
120 | // get prayertimes as a List
121 | // index 0 : Fajr time
122 | // index 1 : Dhur time
123 | // and so on , until index 4 witch is Isha time
124 | List prayersList = Manager.getPrayerTimes(getApplicationContext(),dd, mm, yy);
125 | TextView fajrTime = (TextView) findViewById(R.id.fajrTime);
126 | TextView duhrTime = (TextView) findViewById(R.id.duhrTime);
127 | TextView asrTime = (TextView) findViewById(R.id.asrTime);
128 | TextView magribTime = (TextView) findViewById(R.id.magribTime);
129 | TextView ishaTime = (TextView) findViewById(R.id.ishaTime);
130 |
131 | // Dump sol. replace AM and PM with Arabic Letters, The current font is not good enough to be used
132 | // with Arabic Letters
133 | //String timeFormatted = prayersList.get(0).replace("AM", this.getString(R.string.am)).replace("PM",this.getString(R.string.pm));
134 |
135 | fajrTime.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/Roboto-Regular.ttf"));
136 | fajrTime.setText(TimeHelper.getTimeWithoutSeconds(prayersList.get(0)));
137 | duhrTime.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/Roboto-Regular.ttf"));
138 | duhrTime.setText(TimeHelper.getTimeWithoutSeconds(prayersList.get(1)));
139 | asrTime.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/Roboto-Regular.ttf"));
140 | asrTime.setText(TimeHelper.getTimeWithoutSeconds(prayersList.get(2)));
141 | magribTime.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/Roboto-Regular.ttf"));
142 | magribTime.setText(TimeHelper.getTimeWithoutSeconds(prayersList.get(3)));
143 | ishaTime.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/Roboto-Regular.ttf"));
144 | ishaTime.setText(TimeHelper.getTimeWithoutSeconds(prayersList.get(4)));
145 |
146 | // Timer used to decrease the remaining time to next prayer
147 | updateRemainingTime(yy, mm, dd); //to calculate the nearest pray
148 | Timer myTimer =new Timer();
149 | TimerTask scanTask ;
150 | final Handler handler = new Handler();
151 |
152 | scanTask = new TimerTask() {
153 | public void run() {
154 |
155 | handler.post(new Runnable() {
156 | public void run() {
157 | try {
158 | updateRemainingTime(yy, mm, dd);
159 | } catch (IOException e) {
160 |
161 | }
162 | }
163 | });
164 | }};
165 |
166 |
167 | // start the timer
168 | // 60000 ms == 60 seconds == 1 minutes :)
169 | myTimer.schedule(scanTask, 0, 60000);
170 |
171 |
172 | } catch (Exception e) {
173 | // TODO Auto-generated catch block
174 | //Log.e("tomaanina",e.getCause() + " : " + e.getMessage());
175 | }
176 |
177 |
178 | }
179 |
180 | public void updateRemainingTime(int yy, int mm, int dd ) throws IOException{
181 | Date date = new Date();
182 |
183 | int h = date.getHours();//calendar.get(Calendar.HOUR_OF_DAY);
184 | int m = date.getMinutes();//calendar.get(Calendar.MINUTE);
185 | int s = date.getSeconds();//calendar.get(Calendar.SECOND);
186 | // get remaining text view and change its value to " remaining time)
187 | TextView remainingTime = (TextView) findViewById(R.id.remainingTime);
188 | // nearest prayer time ,
189 | // for example :Asr : 3:10
190 | // difference : Current time - Asr time == Current Time - 3:10 = remaining time
191 | int time = Manager.computeNearestPrayerTime(getApplicationContext(),h, m,s, yy, mm, dd);
192 | int def = TimeHelper.different((h*3600+m*60+s),time);
193 | remainingTime.setText(TimeHelper.secondsToTime(def));
194 | remainingTime.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/Roboto-Regular.ttf"));
195 | }
196 |
197 | // add main menu items
198 | @Override
199 | public boolean onCreateOptionsMenu(Menu menu) {
200 | menu.add(0, 1, 1, getString(R.string.settings));
201 | menu.add(0, 3, 3, getString(R.string.about));
202 | // find the current city automatically
203 | menu.add(0, 4, 4, getString(R.string.autoCityTitle));
204 | return true;
205 | }
206 |
207 | @Override
208 | public boolean onOptionsItemSelected(MenuItem item) {
209 |
210 | switch (item.getItemId()) {
211 | case 1:
212 | // run Settings screen
213 | Intent myIntent = new Intent(this, SettingsActivity.class);
214 | startActivity(myIntent);
215 | return true;
216 | case 3:
217 | // run About screen
218 | Intent MyIntent = new Intent (this , About.class);
219 | startActivity(MyIntent);
220 |
221 | return true;
222 | case 4:
223 | // run auto city finder dialog .
224 | //new AutoCityMainActivity(this, dialog).startSearch();
225 | //return true;
226 | case 5:
227 | // run City Finder Activity
228 | Intent cityFinderActivity = new Intent (this , CityFinder.class);
229 | startActivity(cityFinderActivity);
230 |
231 | return true;
232 | }
233 | return super.onOptionsItemSelected(item);
234 |
235 | }
236 |
237 | // update the view on resume
238 | public void onResume(){
239 | super.onResume();
240 | this.init();
241 | }
242 |
243 |
244 | // this method is triggered at the first time
245 | // put here what you want to execute at the first run for the app on this device
246 |
247 | public void onFirstStart(){
248 |
249 | Intent cityFinderActivity = new Intent (this , CityFinder.class);
250 | startActivity(cityFinderActivity);
251 |
252 | }
253 |
254 |
255 |
256 | }
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/moazen/PrayerTime.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 |
6 | /**
7 | *
8 | * @author Admin
9 | */
10 | package com.shefra.prayertimes.moazen;
11 |
12 | public final class PrayerTime {
13 |
14 | // Shared variable used in Calculation Algorithm
15 | protected static double DegToRad = 0.017453292;
16 | protected static double RadToDeg = 57.29577951;
17 |
18 | protected Coordinate m_coordinate;
19 | protected Date m_date;
20 | protected Calender m_calender;
21 | protected Mazhab m_mazhab;
22 | protected Season m_season;
23 |
24 | protected double fajr;
25 | protected double shrouk;
26 | protected double zuhr;
27 | protected double asr;
28 | protected double maghrib;
29 | protected double isha;
30 | protected double dec;
31 |
32 | public PrayerTime(){
33 | this.m_coordinate = new Coordinate(0,0,0);
34 | this.m_date =new Date(0,0,0);
35 | }
36 | public PrayerTime(Coordinate co, Date da, Calender ca, Mazhab ma, Season se){
37 | this.m_coordinate = co ;
38 | this.m_date = da;
39 | this.m_calender = ca;
40 | this.m_mazhab = ma;
41 | this.m_season = se;
42 | }
43 | public PrayerTime(double lot,double lat,int zone,int day,int month,int year, Calender ca, Mazhab ma, Season se){
44 | this.m_coordinate = new Coordinate(lot,lat,zone);
45 | this.m_date = new Date(day,month,year);
46 | this.m_calender = ca;
47 | this.m_mazhab = ma;
48 | this.m_season = se;
49 |
50 | }
51 | public PrayerTime(double lot,double lat,int zone,int day,int month,int year, String calender, String mazhab, String season){
52 | this.m_coordinate = new Coordinate(lot,lat,zone);
53 | this.m_date = new Date(day,month,year);
54 | setCalender(calender);
55 | setMazhab(mazhab);
56 | setSeason(season);
57 | }
58 | public PrayerTime(double lot,double lat,int zone,int day,int month,int year){
59 | m_coordinate = new Coordinate(lot,lat,zone);
60 | m_date = new Date(day,month,year);
61 | m_calender = new Calender();
62 | m_mazhab = new Mazhab();
63 | m_season = new Season();
64 | }
65 |
66 | // Calculate Prayer times.
67 | // Must use firstly.
68 | public void calculate(){
69 | int year = m_date.year;
70 | int month = m_date.month;
71 | int day = m_date.day;
72 |
73 | double longitude = m_coordinate.longitude;
74 | double latitude = m_coordinate.latitude;
75 | int zone = m_coordinate.zone;
76 |
77 | double julianDay=(367*year)-(int)(((year+(int)((month+9)/12))*7)/4)+(int)(275*month/9)+day-730531.5;
78 |
79 |
80 | double sunLength=280.461+0.9856474*julianDay;
81 | sunLength=removeDublication(sunLength);
82 |
83 |
84 | double middleSun=357.528+0.9856003*julianDay;
85 | middleSun=removeDublication(middleSun);
86 | double lambda=sunLength+1.915*Math.sin(middleSun*DegToRad)+0.02*Math.sin(2*middleSun*DegToRad);
87 | lambda=removeDublication(lambda);
88 |
89 | double obliquity=23.439-0.0000004*julianDay;
90 | double alpha=RadToDeg*Math.atan(Math.cos(obliquity*DegToRad)*Math.tan(lambda*DegToRad));
91 |
92 | if (lambda > 90 && lambda < 180)
93 | alpha+=180;
94 |
95 | else if (lambda > 180 && lambda < 360)
96 | alpha+=360;
97 |
98 |
99 | double ST=100.46+0.985647352*julianDay;
100 | ST=removeDublication(ST);
101 |
102 |
103 | dec=RadToDeg*Math.asin(Math.sin(obliquity*DegToRad)*Math.sin(lambda*DegToRad));
104 |
105 | double noon=alpha-ST;
106 |
107 | if (noon < 0)
108 | noon+=360;
109 |
110 | double UTNoon=noon-longitude;
111 |
112 | double localNoon=(UTNoon/15)+zone;
113 |
114 | zuhr=localNoon; //Zuhr Time.
115 |
116 | maghrib=localNoon+equation(-0.8333)/15; // Maghrib Time
117 |
118 | shrouk=localNoon-equation(-0.8333)/15; // Shrouk Time
119 |
120 |
121 | double fajrAlt = 0;
122 | double ishaAlt = 0;
123 | if (this.m_calender.type() == Calender.Type.UmmAlQuraUniv) {
124 | fajrAlt=-18.5;
125 | } else if (this.m_calender.type() == Calender.Type.EgytionGeneralAuthorityofSurvey) {
126 | fajrAlt=-19.5;
127 | ishaAlt=-17.5;
128 | } else if (m_calender.type() == Calender.Type.MuslimWorldLeague) {
129 | fajrAlt=-18;
130 | ishaAlt=-17;
131 | } else if (m_calender.type() == Calender.Type.IslamicSocietyOfNorthAmerica) {
132 | fajrAlt=ishaAlt=-15;
133 | } else if (m_calender.type() == Calender.Type.UnivOfIslamicScincesKarachi) {
134 | fajrAlt=ishaAlt=-18;
135 | }
136 |
137 | fajr=localNoon-equation(fajrAlt)/15; // Fajr Time
138 |
139 | isha=localNoon+equation(ishaAlt)/15; // Isha Time
140 |
141 |
142 | if( m_calender.type() == Calender.Type.UmmAlQuraUniv )
143 | isha=maghrib+1.5;
144 |
145 | double asrAlt;
146 |
147 | if( m_mazhab.type() == Mazhab.Type.Hanafi)
148 | asrAlt=90-RadToDeg*Math.atan(2+Math.tan(Math.abs(latitude-dec)*DegToRad));
149 | else
150 | asrAlt=90-RadToDeg*Math.atan(1+Math.tan(Math.abs(latitude-dec)*DegToRad));
151 |
152 | asr=localNoon+equation(asrAlt)/15; // Asr Time.
153 |
154 | // Add one hour to all times if the season is Summmer.
155 | if( m_season.type() == Season.Type.Summer) {
156 | fajr+=1;
157 | shrouk+=1;
158 | zuhr+=1;
159 | asr+=1;
160 | maghrib+=1;
161 | isha+=1;
162 | }
163 | }
164 |
165 |
166 |
167 | // Prayer Time
168 | public Time zuhrTime(){
169 | Time t = new Time(this.zuhr,true);
170 | return t;
171 | }
172 | public Time asrTime(){
173 | Time t = new Time(this.asr);
174 | return t;
175 | }
176 | public Time fajrTime(){
177 | Time t = new Time(this.fajr,true);
178 | return t;
179 | }
180 | public Time ishaTime(){
181 | Time t = new Time(this.isha);
182 | return t;
183 | }
184 | public Time maghribTime(){
185 | Time t = new Time(this.maghrib);
186 | return t;
187 | }
188 | public Time shroukTime(){
189 | Time t = new Time(this.shrouk,true);
190 | return t;
191 | }
192 |
193 |
194 |
195 | // getter and setter functions.
196 |
197 | public Calender calender(){return m_calender;}
198 | public void setCalender( Calender calender){m_calender=calender;}
199 | public void setCalender(Calender.Type calender){m_calender.setCalender(calender);}
200 | public void setCalender( String calender){m_calender.setCalender(calender);}
201 |
202 | public Mazhab mazhab(){return this.m_mazhab;}
203 | public void setMazhab(Mazhab mazhab){this.m_mazhab=mazhab;}
204 | public void setMazhab(Mazhab.Type mazhab){this.m_mazhab.setMazhab(mazhab);}
205 | public void setMazhab(String mazhab){this.m_mazhab.setMazhab(mazhab);}
206 |
207 | public Season season(){return this.m_season;}
208 | public void setSeason(Season season){this.m_season=season;}
209 | public void setSeason(Season.Type season){this.m_season.setSeason(season);}
210 | public void setSeason( String season){this.m_season.setSeason(season);}
211 |
212 | public Coordinate coordinate(){return this.m_coordinate;}
213 | public void setCoordinate( Coordinate coordinate){this.m_coordinate=coordinate;}
214 | public void setCoordinate(double lot,double lat,int zone){
215 | this.m_coordinate.longitude=lot;
216 | this.m_coordinate.latitude=lat;
217 | this.m_coordinate.zone=zone;
218 | }
219 |
220 | public double longitude(){return this.m_coordinate.longitude;}
221 | public double latitude(){return this.m_coordinate.latitude;}
222 | public double zone() {return this.m_coordinate.zone;}
223 |
224 | public Date date(){return this.m_date;}
225 | public int day(){return this.m_date.day;}
226 | public int month(){return this.m_date.month;}
227 | public int year(){return this.m_date.year;}
228 | public void setDay(int day){this.m_date.day=day;}
229 | public void setMonth(int month){this.m_date.month=month;}
230 | public void setYear(int year){this.m_date.year=year;}
231 | public void setDate(int day,int month,int year){
232 | this.m_date.day=day;
233 | this.m_date.month=month;
234 | this.m_date.year=year;
235 | }
236 | public void setDate(Date date){this.m_date = date;}
237 |
238 | public void setData(Coordinate co,Date da,Calender ca,Mazhab ma,Season se){
239 | this.m_coordinate = co;
240 | this.m_date = da;
241 | this.m_calender=ca;
242 | this.m_mazhab=ma;
243 | this.m_season=se;
244 | }
245 | public void setData(double lot,double lat,int zone,int day,int month,int year, Calender ca, Mazhab ma, Season se){
246 | setCoordinate(lot,lat,zone);
247 | setDate(day,month,year);
248 | setCalender(ca);
249 | setMazhab(ma);
250 | setSeason(se);
251 |
252 | }
253 | public void setData(double lot,double lat,int zone,int day,int month,int year, String calender, String mazhab, String season){
254 | setCoordinate(lot,lat,zone);
255 | setDate(day,month,year);
256 | setCalender(calender);
257 | setMazhab(mazhab);
258 | setSeason(season);
259 | }
260 |
261 |
262 |
263 |
264 | // just used in calculate() function.
265 | protected double equation(double alt){
266 | return RadToDeg*Math.acos((Math.sin(alt*DegToRad)-Math.sin(dec*DegToRad)*Math.sin(m_coordinate.latitude*DegToRad))/(Math.cos(dec*DegToRad)*Math.cos(m_coordinate.latitude*DegToRad)));
267 | }
268 |
269 | protected double removeDublication(double var){
270 | if (var > 360) {
271 | var/=360;
272 | var-=(int)var;
273 | var*=360;
274 | }
275 | return var;
276 | }
277 | protected double abs(double var){
278 |
279 | if( var < 0 )
280 | return -var;
281 | else
282 | return var;
283 | }
284 |
285 | /* public static void main(String[] args){
286 | PrayerTime prayerTime = new PrayerTime(46.7825,24.6505,3,14,6,2011);
287 | // calculate prayer times.
288 | prayerTime.setMazhab("Hanafi");
289 | prayerTime.calculate();
290 | System.out.println(prayerTime.asrTime().text());
291 |
292 |
293 | }*/
294 | }
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/helper/DatabaseHelper.java:
--------------------------------------------------------------------------------
1 | package com.shefra.prayertimes.helper;
2 |
3 | import java.io.File;
4 | import java.io.FileOutputStream;
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.io.OutputStream;
8 | import java.util.ArrayList;
9 | import java.util.Locale;
10 |
11 | import com.shefra.prayertimes.manager.City;
12 | import com.shefra.prayertimes.manager.Country;
13 | import com.shefra.prayertimes.manager.Manager;
14 | import com.shefra.prayertimes.manager.Preference;
15 |
16 | import android.content.Context;
17 | import android.content.SharedPreferences;
18 | import android.database.Cursor;
19 | import android.database.sqlite.SQLiteDatabase;
20 | import android.database.sqlite.SQLiteException;
21 | import android.database.sqlite.SQLiteOpenHelper;
22 | import android.preference.PreferenceManager;
23 | import android.util.Log;
24 |
25 | public class DatabaseHelper extends SQLiteOpenHelper {
26 | private static String DB_PATH = "/data/data/com.shefra.prayertimes/databases/";
27 | private static String DB_NAME = "CountriesDB";
28 | private Context context;
29 | private SQLiteDatabase db;
30 |
31 | public DatabaseHelper(Context applicationContext) {
32 | super(applicationContext, DB_NAME, null, 1);
33 | this.context = applicationContext;
34 | }
35 |
36 | // -----------DataBase methods-----------//
37 | public String getDatabasePath() {
38 | return DB_PATH;
39 | }
40 |
41 | public String getDatabaseName() {
42 | return DB_NAME;
43 | }
44 |
45 | // // used to know if the database is installed or not
46 | // private boolean checkDataBase() {
47 | // SQLiteDatabase checkDB = null;
48 | // try{
49 | //
50 | // try{
51 | // String myPath = DB_PATH + DB_NAME;
52 | // checkDB = SQLiteDatabase.openDatabase(myPath, null,
53 | // SQLiteDatabase.OPEN_READONLY);
54 | // } catch (SQLiteException e) {
55 | // // database does't exist yet.
56 | // }
57 | //
58 | // if (checkDB != null) {
59 | // checkDB.close();
60 | // }
61 | //
62 | // }catch(Exception e){
63 | // Log.e("Tomaanina", e.getMessage(),e.getCause());
64 | // }
65 | // return checkDB != null ? true : false;
66 | //
67 | // }
68 | // suggested by sultan
69 | private boolean checkDataBase() {
70 | File checkDB = new File(DB_PATH + DB_NAME);
71 | return checkDB.exists();
72 | }
73 |
74 | // copy the database from assets folder to data folder (system folder)
75 | // Android system does not allow to access the database from assets folder
76 |
77 | // BE CAREFUL : the file must not be bigger then 1 Mega byte :(
78 | public void createDatabase() throws IOException {
79 | boolean dbExist = checkDataBase();
80 | if (dbExist) {
81 | // do nothing - database already exist
82 | } else {
83 | // By calling this method an empty database will be created into
84 | // the default system path
85 | // of your application so we are gonna be able to overwrite that
86 | // database with our new database.
87 | this.getReadableDatabase();
88 | try {
89 | copyDataBase();
90 | } catch (IOException e) {
91 | throw new Error("Error copying database");
92 | }
93 | }
94 | }
95 |
96 | // read createDatabase method for more comments
97 | public void copyDataBase() throws IOException {
98 | // Open your local db as the input stream
99 | InputStream myInput = this.context.getAssets().open(DB_NAME);
100 | // Path to the just created empty db
101 | String outFileName = DB_PATH + DB_NAME;
102 | // Open the empty db as the output stream
103 | OutputStream myOutput = new FileOutputStream(outFileName);
104 | // transfer bytes from the inputfile to the outputfile
105 | byte[] buffer = new byte[1024];
106 | int length;
107 | while ((length = myInput.read(buffer)) > 0) {
108 | myOutput.write(buffer, 0, length);
109 | }
110 | // Close the streams
111 | myOutput.flush();
112 | myOutput.close();
113 | myInput.close();
114 | }
115 |
116 | @Override
117 | public synchronized void close() {
118 | if (db != null)
119 | db.close();
120 | super.close();
121 | }
122 |
123 | @Override
124 | public void onCreate(SQLiteDatabase db) {
125 |
126 | }
127 |
128 | @Override
129 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
130 |
131 | }
132 |
133 | // get country details based on country id
134 | // useful when read country id from xml preference
135 |
136 | public Country getCountry(int countrId) {
137 | SQLiteDatabase db;
138 | Country country = new Country();
139 |
140 | db = SQLiteDatabase.openOrCreateDatabase(DB_PATH + DB_NAME, null);
141 | db.setVersion(1);
142 | db.setLocale(Locale.getDefault());
143 | db.setLockingEnabled(true);
144 |
145 | Cursor cur = db.query("country", null, "country_id=" + countrId, null,
146 | null, null, null);
147 | cur.moveToFirst();
148 | while (cur.isAfterLast() == false) {
149 |
150 | country.id = Integer.toString(cur.getInt(0));
151 | // not all the country has Arabic name
152 | // so use English name instead
153 | // prevents NULL error that happens when put NULL
154 | // into a view object ( e.g. ListView )
155 | if (cur.getString(2) != null)
156 | country.name = cur.getString(2);
157 | else
158 | country.name = cur.getString(1);
159 | cur.moveToNext();
160 | }
161 | cur.close();
162 | db.close();
163 | return country;
164 | }
165 |
166 | // / get city details based on city id
167 | // useful when read city id from preference file ( xml file/ setting file)
168 | public City getCity(long cityId) {
169 | City city = new City();
170 |
171 | db = SQLiteDatabase.openOrCreateDatabase(DB_PATH + DB_NAME, null);
172 | db.setVersion(1);
173 | db.setLocale(Locale.getDefault());
174 | db.setLockingEnabled(true);
175 |
176 | Cursor cur = db
177 | .rawQuery(
178 | "select cit.*,cnt.name from citiesTable cit,country cnt where cit.country_id == cnt.country_id and cityNO=?",
179 | new String[] { Long.toString(cityId) });
180 | cur.moveToFirst();
181 | while (cur.isAfterLast() == false) {
182 | city.id = Integer.toString(cur.getInt(0));
183 | // not all the city has Arabic name
184 | // so use English name instead
185 | // prevents NULL error that happens when put NULL
186 | // into a view object ( e.g. ListView )
187 | if (cur.getString(2) != null)
188 | city.name = cur.getString(2);
189 | else
190 | city.name = cur.getString(1);
191 |
192 | city.latitude = cur.getString(3);
193 | city.longitude = cur.getString(4);
194 | city.timeZone = cur.getInt(5);
195 | city.country.id = cur.getString(6);
196 | city.country.name = cur.getString(7);
197 |
198 | cur.moveToNext();
199 | }
200 | cur.close();
201 | db.close();
202 | return city;
203 | }
204 |
205 | // read the preference file( xml file)
206 | // to get the selected city id
207 | // then get city detailed based on that id
208 | public City getCurrentCity() {
209 | Manager m = new Manager(this.context);
210 | Preference pref = m.getPreference();
211 | pref.fetchCurrentPreferences();
212 | return pref.city;
213 | }
214 |
215 | /*
216 | * public azanAttribute getData(int id) { db =
217 | * SQLiteDatabase.openOrCreateDatabase(DB_PATH + DB_NAME, null);
218 | * db.setVersion(1); db.setLocale(Locale.getDefault());
219 | * db.setLockingEnabled(true);
220 | *
221 | * azanAttribute aA = new azanAttribute(); String select =
222 | * "select cityName,latitude,longitude,timeZone,country_id from citiesTable where cityNO ="
223 | * + id; Cursor cur = db.rawQuery(select, null); cur.moveToFirst();
224 | *
225 | * aA.cityName = cur.getString(0); aA.latitude = cur.getString(1);
226 | * aA.longitude = cur.getString(2); aA.timeZone = cur.getString(3);
227 | * aA.countryNo = cur.getString(4);
228 | *
229 | * cur.close(); db.close(); return aA; }
230 | */
231 |
232 | // -----------get methods-----------//
233 | // git city list based on country id
234 | // if id = -1 => means return all cities in the database
235 | public ArrayList getCityList(int id) {
236 | ArrayList city = new ArrayList();
237 | try {
238 | db = SQLiteDatabase.openDatabase(DB_PATH + DB_NAME, null,
239 | SQLiteDatabase.NO_LOCALIZED_COLLATORS
240 | | SQLiteDatabase.CREATE_IF_NECESSARY);
241 | db.setVersion(1);
242 | db.setLocale(Locale.getDefault());
243 | db.setLockingEnabled(true);
244 |
245 | String whereClause = null;
246 | if (id != -1) {
247 | whereClause = "country_id=" + id;
248 | }
249 | Cursor cur = db.query("citiesTable", new String[] { "cityNO",
250 | "cityName", "cityNameAr", "latitude", "longitude" },
251 | whereClause, null, null, null, null);
252 | cur.moveToFirst();
253 | while (cur.isAfterLast() == false) {
254 | City c = new City();
255 | c.id = Integer.toString(cur.getInt(0));
256 |
257 | // not all the city has Arabic name
258 | // so use English name instead
259 | // prevents NULL error that happens when put NULL
260 | // into a view object ( e.g. ListView )
261 | if (cur.getString(2) != null)
262 | c.name = cur.getString(2);
263 | else
264 | c.name = cur.getString(1);
265 |
266 | c.latitude = cur.getString(3);
267 | c.longitude = cur.getString(4);
268 | city.add(c);
269 | cur.moveToNext();
270 | }
271 | cur.close();
272 | db.close();
273 | } catch (Exception e) {
274 | //Log.e("tomaanina", e.getMessage(), e.getCause());
275 | }
276 | return city;
277 | }
278 |
279 | public Cursor getCityCursor(long id) {
280 | if (db != null && db.isOpen())
281 | db.close();
282 | db = SQLiteDatabase.openOrCreateDatabase(DB_PATH + DB_NAME, null);
283 | db.setVersion(1);
284 | db.setLocale(Locale.getDefault());
285 | db.setLockingEnabled(true);
286 |
287 | Cursor cur = db
288 | .rawQuery(
289 | "SELECT cityNO as _id , cityName from citiesTable WHERE country_id = ? ORDER BY cityNO",
290 | new String[] { Long.toString(id) });
291 |
292 | return cur;
293 | }
294 |
295 | // get all country from the database
296 | public Cursor getCountryList() {
297 | if (db != null && db.isOpen())
298 | db.close();
299 | db = SQLiteDatabase.openOrCreateDatabase(DB_PATH + DB_NAME, null);
300 | db.setVersion(1);
301 | db.setLocale(Locale.getDefault());
302 | db.setLockingEnabled(true);
303 | Cursor cur = db
304 | .rawQuery(
305 | "SELECT country_id as _id , name as country_name from country ORDER BY country_id",
306 | null);
307 | // Cursor cur = db.query("country", new String[]{"name"}, null, null,
308 | // null, null, null);
309 | return cur;
310 |
311 | /*
312 | * cur.moveToFirst();
313 | *
314 | * while (cur.isAfterLast() == false) { Country c = new Country(); c.id
315 | * = Integer.toString(cur.getInt(0)); // not all the country has Arabic
316 | * name // so use English name instead // prevents NULL error that
317 | * happens when put NULL // into a view object ( e.g. ListView ) if
318 | * (cur.getString(2) != null) c.name = cur.getString(2); else c.name =
319 | * cur.getString(1);
320 | *
321 | * country.add(c); cur.moveToNext(); } cur.close(); db.close(); return
322 | * country;
323 | */
324 | }
325 |
326 | }
327 |
--------------------------------------------------------------------------------
/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
22 |
23 |
37 |
38 |
51 |
52 |
53 |
62 |
63 |
77 |
78 |
91 |
92 |
93 |
99 |
100 |
115 |
116 |
130 |
131 |
132 |
138 |
139 |
154 |
155 |
169 |
170 |
171 |
177 |
178 |
193 |
194 |
208 |
209 |
210 |
216 |
217 |
232 |
233 |
247 |
248 |
249 |
255 |
256 |
271 |
272 |
286 |
287 |
288 |
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/manager/Manager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Manager class is managing the connection between the ( Database | XML-Files )
3 | * and the ( Prayer Model | Setting Screen | Main Screen )
4 | *
5 | *
6 | * these are the Main functionalities: ( #MAIN FUNCTION , %HOW DOES IT WORKS , $METHOD APPEARANCE "SERIALLY" ).
7 | * # Store City-Attributes.
8 | * % By the city-ID -> Gets City Attributes -> Stores the City Data in the XML.
9 | * $ ( setSetting() -> getData() -> xmlWriter() ).
10 | *
11 | * # Calculate Prayer-Times.
12 | * % By Reading the City Attributes -> Runs the Prayer-Model to get Prayer Times.
13 | * $ ( xmlReader() -> getPrayerTimes() ).
14 | *
15 | * # Find out Nearest-Prayer-Time.
16 | * % By Calculating Prayer-Times and Comparing current time with them to get the next one.
17 | * $ ( getPrayerTimes() -> nearestPrayerTime() ).
18 | *
19 | * # Copy the Country DataBase to the Device -> TODO MAIN FUNCTION (ABDULLAH).
20 | * % TODO HOW DOES IT WORKS .
21 | * $ TODO METHOD APPEARANCE "SERIALLY" .
22 | *
23 | * # Find Current City Location -> TODO MAIN FUNCTION (MOHAMMED).
24 | * % TODO HOW DOES IT WORKS .
25 | * $ TODO METHOD APPEARANCE "SERIALLY" .
26 | *
27 | * #.
28 | * %.
29 | * $.
30 | */
31 | package com.shefra.prayertimes.manager;
32 |
33 | import java.io.FileOutputStream;
34 | import java.io.IOException;
35 | import java.io.InputStream;
36 | import java.io.OutputStream;
37 | import java.util.ArrayList;
38 | import java.util.Arrays;
39 | import java.util.Collections;
40 | import java.util.Comparator;
41 | import java.util.Locale;
42 |
43 | import com.shefra.prayertimes.R;
44 | import com.shefra.prayertimes.activity.AlertActivity;
45 | import com.shefra.prayertimes.activity.MainActivity;
46 | import com.shefra.prayertimes.helper.DatabaseHelper;
47 | import com.shefra.prayertimes.helper.TimeHelper;
48 | import com.shefra.prayertimes.moazen.PrayerTime;
49 | import com.shefra.prayertimes.services.PrayerReceiver;
50 | import com.shefra.prayertimes.services.PrayerService;
51 |
52 | import android.app.Activity;
53 | import android.app.AlarmManager;
54 | import android.app.KeyguardManager;
55 | import android.app.KeyguardManager.KeyguardLock;
56 | import android.app.Notification;
57 | import android.app.NotificationManager;
58 | import android.app.PendingIntent;
59 | import android.app.Service;
60 | import android.content.BroadcastReceiver;
61 | import android.content.Context;
62 | import android.content.Intent;
63 | import android.content.SharedPreferences;
64 | import android.content.SharedPreferences.Editor;
65 | import android.database.Cursor;
66 | import android.database.sqlite.*;
67 | import android.media.AudioManager;
68 | import android.net.Uri;
69 | import android.os.PowerManager;
70 | import android.os.PowerManager.WakeLock;
71 | import android.preference.PreferenceManager;
72 |
73 | // Manager is the main class that works as layer between the app and database/xml files
74 | public class Manager {
75 |
76 | private Context context;
77 | DatabaseHelper databaseHelper;
78 | private static Intent prayerIntet;
79 | private static PendingIntent prayerPendingIntent;
80 | private static AlarmManager prayerAlarmManager;
81 | public static long interval;
82 | private static PrayerState prayerState;
83 | private static Service prayerService;
84 | private static int UNIQUE_ID = 32289;
85 | public static boolean isPhoneIdle = true;
86 |
87 | public Manager(Context applicationContext) {
88 |
89 | this.context = applicationContext;
90 | databaseHelper = new DatabaseHelper(applicationContext);
91 | }
92 |
93 | public static void acquireScreen(Context context) {
94 | PowerManager pm = (PowerManager) context.getApplicationContext()
95 | .getSystemService(Context.POWER_SERVICE);
96 | WakeLock wakeLock = pm
97 | .newWakeLock(
98 | (PowerManager.SCREEN_BRIGHT_WAKE_LOCK
99 | | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP),
100 | "TAG");
101 | wakeLock.acquire();
102 | }
103 |
104 | public static void releaseScreen(Context context) {
105 | KeyguardManager keyguardManager = (KeyguardManager) context
106 | .getApplicationContext().getSystemService(
107 | Context.KEYGUARD_SERVICE);
108 | KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("TAG");
109 | keyguardLock.disableKeyguard();
110 | }
111 |
112 | public static void initPrayerAlarm(Service service,
113 | Class receiver) {
114 | Manager.prayerService = service; // we may need it ?
115 | Manager.prayerIntet = new Intent(service, receiver);
116 | Manager.prayerPendingIntent = PendingIntent
117 | .getBroadcast(service, 1234432, Manager.prayerIntet,
118 | PendingIntent.FLAG_UPDATE_CURRENT);
119 | Manager.prayerAlarmManager = (AlarmManager) service
120 | .getSystemService(Context.ALARM_SERVICE);
121 | Manager.prayerAlarmManager.set(AlarmManager.RTC_WAKEUP,
122 | System.currentTimeMillis() + 1000, Manager.prayerPendingIntent);
123 | }
124 |
125 | public static void updatePrayerAlarm(long newTimeInterval) {
126 | Manager.prayerAlarmManager.set(AlarmManager.RTC_WAKEUP,
127 | System.currentTimeMillis() + newTimeInterval,
128 | Manager.prayerPendingIntent);
129 | }
130 |
131 | public static void cancelPrayerAlarm() {
132 | Manager.prayerAlarmManager.cancel(prayerPendingIntent);
133 | }
134 |
135 | public static void initPrayerState(Context context) {
136 | Manager.prayerState = new PrayerState(context);
137 |
138 | }
139 |
140 | public static PrayerState getPrayerState() {
141 | return prayerState;
142 | }
143 |
144 | // get nearest prayer time based on current time
145 |
146 | public static int computeNearestPrayerTime(Context context, int hour,
147 | int min, int sec, int year, int month, int day) throws IOException {
148 | ArrayList prayerTimes = getPrayerTimes(context, day, month,
149 | year);
150 | int[] prayerTimeInSeconds = new int[5];
151 | prayerTimes.get(0);
152 | // Convert prayer times to seconds
153 | prayerTimeInSeconds[0] = TimeHelper.getSec(
154 | TimeHelper.to24(prayerTimes.get(0)),
155 | TimeHelper.getMinute(prayerTimes.get(0)),
156 | TimeHelper.getSecond(prayerTimes.get(0)));
157 | prayerTimeInSeconds[1] = TimeHelper.getSec(
158 | TimeHelper.to24(prayerTimes.get(1)),
159 | TimeHelper.getMinute(prayerTimes.get(1)),
160 | TimeHelper.getSecond(prayerTimes.get(1)));
161 | prayerTimeInSeconds[2] = TimeHelper.getSec(
162 | TimeHelper.to24(prayerTimes.get(2)),
163 | TimeHelper.getMinute(prayerTimes.get(2)),
164 | TimeHelper.getSecond(prayerTimes.get(2)));
165 | prayerTimeInSeconds[3] = TimeHelper.getSec(
166 | TimeHelper.to24(prayerTimes.get(3)),
167 | TimeHelper.getMinute(prayerTimes.get(3)),
168 | TimeHelper.getSecond(prayerTimes.get(3)));
169 | prayerTimeInSeconds[4] = TimeHelper.getSec(
170 | TimeHelper.to24(prayerTimes.get(4)),
171 | TimeHelper.getMinute(prayerTimes.get(4)),
172 | TimeHelper.getSecond(prayerTimes.get(4)));
173 | // sort ascending
174 | Arrays.sort(prayerTimeInSeconds);
175 | // default value is the first prayer in the day
176 | int nearestPrayer = prayerTimeInSeconds[0];
177 | // convert current time to seconds
178 | int currentTime = hour * 3600 + min * 60 + sec;
179 |
180 | for (Integer prayertime : prayerTimeInSeconds) {
181 | int pt = prayertime;
182 | if (pt >= currentTime)// return first prayer after this time (
183 | // nearest prayer)
184 | return pt;
185 | }
186 | return nearestPrayer;
187 | }
188 |
189 | /*
190 | * public static int computePreviuosPrayerTime(Context context, int hour,
191 | * int min, int sec, int year, int month, int day) throws IOException {
192 | *
193 | * ArrayList prayerTimes = getPrayerTimes(context, day, month,
194 | * year); Integer[] prayerTimeInSeconds = new Integer[5];
195 | *
196 | * // Convert prayer times to seconds prayerTimeInSeconds[0] = new
197 | * Integer(TimeHelper.getSec( TimeHelper.to24(prayerTimes.get(0)),
198 | * TimeHelper.getMinute(prayerTimes.get(0)),
199 | * TimeHelper.getSecond(prayerTimes.get(0)))); prayerTimeInSeconds[1] = new
200 | * Integer(TimeHelper.getSec( TimeHelper.to24(prayerTimes.get(1)),
201 | * TimeHelper.getMinute(prayerTimes.get(1)),
202 | * TimeHelper.getSecond(prayerTimes.get(1)))); prayerTimeInSeconds[2] = new
203 | * Integer(TimeHelper.getSec( TimeHelper.to24(prayerTimes.get(2)),
204 | * TimeHelper.getMinute(prayerTimes.get(2)),
205 | * TimeHelper.getSecond(prayerTimes.get(2)))); prayerTimeInSeconds[3] = new
206 | * Integer(TimeHelper.getSec( TimeHelper.to24(prayerTimes.get(3)),
207 | * TimeHelper.getMinute(prayerTimes.get(3)),
208 | * TimeHelper.getSecond(prayerTimes.get(3)))); prayerTimeInSeconds[4] = new
209 | * Integer(TimeHelper.getSec( TimeHelper.to24(prayerTimes.get(4)),
210 | * TimeHelper.getMinute(prayerTimes.get(4)),
211 | * TimeHelper.getSecond(prayerTimes.get(4))));
212 | *
213 | * // sort descending Arrays.sort(prayerTimeInSeconds, new
214 | * Comparator() {
215 | *
216 | * @Override public int compare(Integer lhs, Integer rhs) { return
217 | * rhs.compareTo(lhs); } });
218 | *
219 | * // default value is the last prayer in the day ( Witch is Isha) //
220 | * remember , we sorted it descending int previousTime =
221 | * prayerTimeInSeconds[0]; int firstTime = prayerTimeInSeconds[4]; //
222 | * convert current time to seconds int currentTime = hour * 3600 + min * 60
223 | * + sec; int i=0; for (Integer prayertime : prayerTimeInSeconds) { int pt =
224 | * prayertime; i++; // return the last prayer if (pt <= currentTime) return
225 | * pt; } // in case if the current time is less then all the prayers time
226 | *
227 | * if(i == 5) return firstTime; else return previousTime;
228 | *
229 | * }
230 | */
231 |
232 | // -----------set method-----------//
233 | /*
234 | * public void setSetting(SettingAttributes sa) { azanAttribute aA =
235 | * databaseHelper.getData(sa.city.cityNo); sa.city.latitude = aA.latitude;
236 | * sa.city.longitude = aA.longitude; sa.city.timeZone = aA.timeZone;
237 | * sa.country.countryNo = Integer.parseInt(aA.countryNo);
238 | * this.setSettingAttributes(sa); }
239 | *
240 | * // -----------XML methods-----------// public void
241 | * setSettingAttributes(SettingAttributes sa) { SharedPreferences pref =
242 | * PreferenceManager .getDefaultSharedPreferences(this.context); Editor
243 | * editor = pref.edit(); editor.putString("country",
244 | * Integer.toString(sa.country.countryNo)); editor.putString("city",
245 | * Integer.toString(sa.city.cityNo)); editor.putString("latitude",
246 | * sa.city.latitude); editor.putString("longitude", sa.city.longitude);
247 | * editor.putString("timeZone", sa.city.timeZone);
248 | * editor.putString("isCityChanged", "true"); editor.commit(); }
249 | *
250 | * public static SettingAttributes getSettingAttributes(Context context) {
251 | * SettingAttributes sa = new SettingAttributes(); SharedPreferences pref =
252 | * PreferenceManager .getDefaultSharedPreferences(context); // Mecca values
253 | * sa.city.timeZone = pref.getString("timeZone", "3"); sa.city.latitude =
254 | * pref.getString("latitude", "21.43"); sa.city.longitude =
255 | * pref.getString("longitude", "39.82"); sa.calender =
256 | * pref.getString("calendar", "UmmAlQuraUniv"); sa.mazhab =
257 | * pref.getString("mazhab", "Default"); sa.season = pref.getString("season",
258 | * "Winter"); return sa; }
259 | */
260 |
261 | public static ArrayList getPrayerTimes(Context context, int dd,
262 | int mm, int yy) throws IOException {
263 |
264 | ArrayList prayerList = new ArrayList();
265 | Manager manager = new Manager(context);
266 | Preference preference = manager.getPreference();
267 | preference.fetchCurrentPreferences();
268 | PrayerTime prayerTime = new PrayerTime(
269 | Double.parseDouble(preference.city.longitude),
270 | Double.parseDouble(preference.city.latitude),
271 | (int) preference.city.timeZone, dd, mm, yy);
272 | prayerTime.setSeason(preference.season);
273 | prayerTime.setCalender(preference.calender);
274 | prayerTime.setMazhab(preference.mazhab);
275 | prayerTime.calculate();
276 | prayerList.add(prayerTime.fajrTime().text());
277 | prayerList.add(prayerTime.zuhrTime().text());
278 | prayerList.add(prayerTime.asrTime().text());
279 | prayerList.add(prayerTime.maghribTime().text());
280 | prayerList.add(prayerTime.ishaTime().text());
281 | return prayerList;
282 | }
283 |
284 | public Context getContext() {
285 | return context;
286 | }
287 |
288 | // find the current city based on its latitude and longtiude
289 | // I DON'T KNOW HOW THE METHOD WORKS !?
290 | public City findCurrentCity(double latitude, double longitude) {
291 | try {
292 | double min = 0;
293 | int i = 0, pos = 0;
294 | ArrayList cityList = databaseHelper.getCityList(-1);
295 | for (City city : cityList) {
296 | double lat = Double.parseDouble(city.latitude);
297 | double lon = Double.parseDouble(city.longitude);
298 | double pk = (180 / 3.14159);
299 | double a1 = (lat / pk);
300 | double a2 = (lon / pk);
301 |
302 | double b1 = (latitude / pk);
303 | double b2 = (longitude / pk);
304 |
305 | double t1 = (Math.cos(a1) * Math.cos(a2) * Math.cos(b1) * Math
306 | .cos(b2));
307 | double t2 = (Math.cos(a1) * Math.sin(a2) * Math.cos(b1) * Math
308 | .sin(b2));
309 | double t3 = (Math.sin(a1) * Math.sin(b1));
310 | double tt = Math.acos(t1 + t2 + t3);
311 | double dist = (6366000 * tt);
312 | if (dist < min || i == 0) {
313 | min = dist;
314 | pos = i;
315 | }
316 | i++;
317 | }
318 | if (pos < cityList.size() && cityList.get(pos) != null) {
319 | String cityId = cityList.get(pos).id;
320 | Integer cityNo = -1;
321 | if (cityId != null) {
322 | cityNo = Integer.parseInt(cityId);
323 | }
324 | if (cityNo == -1)
325 | cityNo = 1;
326 |
327 | City city = databaseHelper.getCity(cityNo);
328 | databaseHelper.close();
329 | return city;
330 |
331 | }
332 |
333 | } catch (Exception e) {
334 | } finally {
335 | databaseHelper.close();
336 | }
337 | return null;
338 |
339 | }
340 |
341 | public static void playAzanNotification(Context context) {
342 | Intent intent;
343 | SharedPreferences pref = PreferenceManager
344 | .getDefaultSharedPreferences(context);
345 | String azanMode = pref.getString("notSound", "short");
346 | AudioManager am = (AudioManager) context
347 | .getSystemService(Context.AUDIO_SERVICE);
348 |
349 | if (azanMode.equals("full")
350 | && am.getRingerMode() == AudioManager.RINGER_MODE_NORMAL
351 | && Manager.isPhoneIdle == true) {
352 | intent = new Intent(context, AlertActivity.class);
353 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
354 | | Intent.FLAG_ACTIVITY_NO_HISTORY);
355 | intent.putExtra("runFromService", true);
356 | context.startActivity(intent);
357 | } else if (!(azanMode.equals("disable"))
358 | && (azanMode.equals("short") || (am.getRingerMode() == AudioManager.RINGER_MODE_SILENT || am
359 | .getRingerMode() == AudioManager.RINGER_MODE_VIBRATE))
360 | || Manager.isPhoneIdle == false) {
361 |
362 | CharSequence contentTitle = context.getString(R.string.notTitle);
363 | CharSequence contentText = context.getString(R.string.notContent);
364 | long when = System.currentTimeMillis();
365 |
366 | NotificationManager mNotificationManager = (NotificationManager) context
367 | .getSystemService(Context.NOTIFICATION_SERVICE);
368 |
369 | Intent notificationIntent = new Intent(context, MainActivity.class);
370 | PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
371 | notificationIntent, 0);
372 |
373 | Notification notification = new Notification(
374 | com.shefra.prayertimes.R.drawable.icon, contentText, when);
375 | notification.sound = Uri
376 | .parse("android.resource://com.shefra.prayertimes/raw/notification");
377 | notification.flags |= Notification.FLAG_AUTO_CANCEL;
378 | notification.setLatestEventInfo(context, contentTitle, contentText,
379 | contentIntent);
380 | mNotificationManager.notify(UNIQUE_ID, notification);
381 | }
382 |
383 | }
384 |
385 | public Preference getPreference() {
386 |
387 | return new Preference(this.context);
388 | }
389 |
390 | public void updateCity(City city, Activity activity) {
391 | Preference pref = this.getPreference();
392 | pref.setCityName(city.name);
393 | pref.setCityNo(city.id);
394 | pref.setCountryName(city.country.name);
395 | pref.setCountryNo(city.country.id);
396 | pref.setLongitude(city.longitude);
397 | pref.setLatitude(city.latitude);
398 | pref.setTimeZone(city.timeZone);
399 |
400 | Manager.cancelPrayerAlarm();
401 | Manager.initPrayerState(Manager.prayerService);
402 | Manager.initPrayerAlarm(Manager.prayerService,PrayerReceiver.class);
403 |
404 | }
405 |
406 | // it does not work ?
407 | public void restartPrayerService(Activity activty) {
408 | Intent intent = new Intent(activty, PrayerService.class);
409 | context.startService(intent);
410 | }
411 |
412 | }
--------------------------------------------------------------------------------
/src/com/shefra/prayertimes/activity/CityFinder.java:
--------------------------------------------------------------------------------
1 | package com.shefra.prayertimes.activity;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStreamReader;
6 | import java.io.StringReader;
7 | import java.util.ArrayList;
8 | import java.util.List;
9 | import java.util.Timer;
10 | import java.util.TimerTask;
11 |
12 | import javax.xml.parsers.DocumentBuilder;
13 | import javax.xml.parsers.DocumentBuilderFactory;
14 | import javax.xml.parsers.ParserConfigurationException;
15 |
16 | import org.apache.http.HttpEntity;
17 | import org.apache.http.HttpResponse;
18 | import org.apache.http.HttpStatus;
19 | import org.apache.http.client.ClientProtocolException;
20 | import org.apache.http.client.methods.HttpGet;
21 | import org.apache.http.impl.client.DefaultHttpClient;
22 | import org.apache.http.params.BasicHttpParams;
23 | import org.apache.http.params.HttpConnectionParams;
24 | import org.apache.http.params.HttpParams;
25 | import org.json.JSONArray;
26 | import org.json.JSONException;
27 | import org.json.JSONObject;
28 | import org.w3c.dom.CharacterData;
29 | import org.w3c.dom.Document;
30 | import org.w3c.dom.Element;
31 | import org.w3c.dom.Node;
32 | import org.w3c.dom.NodeList;
33 | import org.xml.sax.InputSource;
34 | import org.xml.sax.SAXException;
35 |
36 | import com.shefra.prayertimes.R;
37 | import com.shefra.prayertimes.R.id;
38 | import com.shefra.prayertimes.helper.Typefaces;
39 | import com.shefra.prayertimes.manager.City;
40 | import com.shefra.prayertimes.manager.CityLocationListener;
41 | import com.shefra.prayertimes.manager.Manager;
42 | import com.shefra.prayertimes.manager.Preference;
43 |
44 | import android.app.Activity;
45 | import android.app.AlertDialog;
46 | import android.content.DialogInterface;
47 | import android.content.Intent;
48 | import android.location.Location;
49 | import android.os.AsyncTask;
50 | import android.os.Bundle;
51 | import android.os.Handler;
52 | import android.util.Log;
53 | import android.view.Gravity;
54 | import android.view.View;
55 | import android.view.View.OnClickListener;
56 | import android.widget.Button;
57 | import android.widget.ProgressBar;
58 | import android.widget.TextView;
59 | import android.widget.Toast;
60 |
61 | public class CityFinder extends Activity {
62 |
63 | protected static final int SEARCH_TYPE_DATABASE = 1;
64 | protected static final int SEARCH_TYPE_INTERNET = 2;
65 | public static final int SEARCH_TIME = 1000 * 120;
66 | private CityLocationListener cityLoc;
67 | private com.shefra.prayertimes.activity.CityFinder.CityFinderTask cityFinderTask;
68 | public City city;
69 | protected int searchType;
70 | int TIME_ZONE = 0, CITY_DATA = 1;
71 | String[] url = new String[2];
72 | String[] data = new String[2];
73 |
74 | private TextView resultTextView;
75 | public View progressDialog;
76 |
77 | private Button findCityNoInternet;
78 | private Button findCityUsingInternet;
79 | private Button noSearchButton;
80 | private Button homeButton;
81 | private Button researchButton;
82 | private Button correctButton;
83 | private TextView descTextView;
84 | private Timer myTimer;
85 | public boolean searchDBError;
86 | public boolean searchInternetError;
87 |
88 | @Override
89 | public void onCreate(Bundle savedInstanceState) {
90 | super.onCreate(savedInstanceState);
91 | setContentView(R.layout.cityfinder);
92 | try {
93 | descTextView = (TextView) findViewById(R.id.dlgMsg);
94 | resultTextView = (TextView) findViewById(R.id.resultTextView);
95 | descTextView.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/DroidNaskh-Regular.ttf"));
96 | resultTextView.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/DroidNaskh-Regular.ttf"));
97 |
98 | findCityNoInternet = (Button) findViewById(R.id.findCityNoInternet);
99 | findCityUsingInternet = (Button) findViewById(R.id.findCityUsingInternet);
100 | noSearchButton = (Button) findViewById(R.id.nosearch);
101 |
102 | homeButton = (Button) findViewById(R.id.findCityHome);
103 | correctButton = (Button) findViewById(R.id.findCityCorrect);
104 | researchButton = (Button) findViewById(R.id.findCityResearcht);
105 | homeButton.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/DroidNaskh-Regular.ttf"));
106 | correctButton.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/DroidNaskh-Regular.ttf"));
107 | researchButton.setTypeface(Typefaces.get(this.getBaseContext(), "fonts/DroidNaskh-Regular.ttf"));
108 |
109 | progressDialog = (ProgressBar) findViewById(R.id.progressBar1);
110 | progressDialog.setVisibility(View.GONE);
111 | Manager m = new Manager(this);
112 | Preference pref = m.getPreference();
113 | pref.fetchCurrentPreferences();
114 | resultTextView.setText(pref.city.name);
115 |
116 | findCityNoInternet.setOnClickListener(new OnClickListener() {
117 |
118 | public void onClick(View v) {
119 | try {
120 | CityFinder.this.searchType = CityFinder.SEARCH_TYPE_DATABASE;
121 | cityLoc = new CityLocationListener(CityFinder.this, 2);
122 | cityLoc.startSearch();
123 | progressDialog.setVisibility(View.VISIBLE);
124 | CityFinder.this.waitSearch(SEARCH_TIME);
125 |
126 | } catch (Exception e) {
127 | //Log.e("tomaanina", e.getMessage(), e.getCause());
128 | }
129 | }
130 |
131 | });
132 |
133 | findCityUsingInternet.setOnClickListener(new OnClickListener() {
134 |
135 | public void onClick(View v) {
136 | try {
137 | CityFinder.this.searchType = CityFinder.SEARCH_TYPE_INTERNET;
138 | cityLoc = new CityLocationListener(CityFinder.this, 2);
139 | cityLoc.startSearch();
140 | progressDialog.setVisibility(View.VISIBLE);
141 |
142 | CityFinder.this.waitSearch(SEARCH_TIME);
143 |
144 | } catch (Exception e) {
145 | //Log.e("tomaanina", e.getMessage(), e.getCause());
146 | }
147 | }
148 |
149 | });
150 |
151 | researchButton.setOnClickListener(new OnClickListener() {
152 |
153 | public void onClick(View v) {
154 | CityFinder.this.city = null;
155 |
156 | CityFinder.this.researchButton.setVisibility(View.GONE);
157 | CityFinder.this.homeButton.setVisibility(View.GONE);
158 | CityFinder.this.correctButton.setVisibility(View.GONE);
159 | CityFinder.this.descTextView.setText(CityFinder.this
160 | .getString(R.string.cityfinder_desc));
161 |
162 | CityFinder.this.findCityNoInternet
163 | .setVisibility(View.VISIBLE);
164 | CityFinder.this.findCityUsingInternet
165 | .setVisibility(View.VISIBLE);
166 | CityFinder.this.noSearchButton.setVisibility(View.VISIBLE);
167 | }
168 | });
169 |
170 | correctButton.setOnClickListener(new OnClickListener() {
171 |
172 | public void onClick(View v) {
173 | Manager manager = new Manager(CityFinder.this);
174 | manager.updateCity(city, CityFinder.this);
175 | Intent intent = new Intent(CityFinder.this,
176 | MainActivity.class);
177 | startActivity(intent);
178 | }
179 | });
180 |
181 | noSearchButton.setOnClickListener(new OnClickListener() {
182 |
183 | public void onClick(View v) {
184 | Intent intent = new Intent(CityFinder.this,
185 | MainActivity.class);
186 | startActivity(intent);
187 |
188 | }
189 | });
190 |
191 | homeButton.setOnClickListener(new OnClickListener() {
192 |
193 | public void onClick(View v) {
194 | Intent intent = new Intent(CityFinder.this,
195 | MainActivity.class);
196 | startActivity(intent);
197 | }
198 | });
199 | } catch (Exception e) {
200 | //Log.e("tomaanina", e.getMessage(), e.getCause());
201 | }
202 | }
203 |
204 | private void waitSearch(int ms) {
205 | myTimer = new Timer();
206 | TimerTask scanTask;
207 | final Handler handler = new Handler();
208 |
209 | scanTask = new TimerTask() {
210 | public void run() {
211 |
212 | handler.post(new Runnable() {
213 | public void run() {
214 | try {
215 | CityFinder.this.cityLoc.updateWithNewLocation(null);
216 | } catch (Exception e) {
217 |
218 | }
219 | }
220 | });
221 | }
222 | };
223 |
224 | myTimer.schedule(scanTask, ms);
225 | }
226 |
227 | public void onSearchStopped(Location location) {
228 | // if (cityFinderTask != null) {
229 | // is it safe to change the done var from UI thread?
230 | // in another way: is it necessary to do that manually ?
231 | // cityFinderTask.setDone(true);
232 |
233 | // cityFinderTask.cancel(true);
234 |
235 | // }
236 | this.myTimer.cancel();
237 | cityFinderTask = new CityFinderTask();
238 | this.cityFinderTask.execute(new Location[] { location });
239 |
240 | }
241 |
242 | private class CityFinderTask extends
243 | AsyncTask {
244 | private Location loc;
245 |
246 | @Override
247 | protected void onPreExecute() {
248 | try {
249 | super.onPreExecute();
250 | } catch (Exception e) {
251 | //Log.e("", e.getMessage(), e.getCause());
252 | }
253 | }
254 |
255 | @Override
256 | protected String doInBackground(Location... params) {
257 | try {
258 | // TODO: wait 10 seconds then stop the process and invoke
259 | Location location = params[0];
260 | this.loc = location;
261 |
262 | if (CityFinder.this.searchType == CityFinder.SEARCH_TYPE_DATABASE) {
263 | try {
264 |
265 | Manager manager = new Manager(CityFinder.this);
266 |
267 | city = manager.findCurrentCity(loc.getLatitude(),
268 | loc.getLongitude());
269 | CityFinder.this.searchDBError = false;
270 |
271 | } catch (Exception e) {
272 | CityFinder.this.searchDBError = true;
273 | }
274 | } else {
275 | try {
276 | city = this.getPosition(loc.getLongitude(),
277 | loc.getLatitude());
278 | CityFinder.this.searchInternetError = false;
279 |
280 | } catch (Exception e) {
281 | CityFinder.this.searchInternetError = true;
282 |
283 | }
284 | }
285 | } catch (Exception e) {
286 | //Log.e("", e.getMessage(), e.getCause());
287 | }
288 | return null;
289 | }
290 |
291 | protected void onPostExecute(String result) {
292 | progressDialog.setVisibility(View.GONE);
293 | if (this.loc == null) {
294 | AlertDialog.Builder builder = new AlertDialog.Builder(
295 | CityFinder.this);
296 | builder.setMessage(
297 | CityFinder.this
298 | .getString(R.string.gpsAndNetworkIsDisabled))
299 | .setPositiveButton(
300 | CityFinder.this.getString(R.string.reSearch),
301 | new DialogInterface.OnClickListener() {
302 | public void onClick(DialogInterface dialog,
303 | int id) {
304 | dialog.cancel();
305 | }
306 | })
307 | .setNegativeButton(R.string.manualSearch,
308 | new DialogInterface.OnClickListener() {
309 | public void onClick(DialogInterface dialog,
310 | int id) {
311 | Intent intent = new Intent(
312 | CityFinder.this,
313 | CityFinderManual.class);
314 | CityFinder.this.startActivity(intent);
315 | }
316 | });
317 | AlertDialog alert = builder.create();
318 | alert.show();
319 | return;
320 | }
321 | if (CityFinder.this.searchType == CityFinder.SEARCH_TYPE_DATABASE) {
322 | try {
323 |
324 | if (CityFinder.this.searchDBError) {
325 | throw new Exception();
326 | }
327 |
328 | resultTextView.setText(CityFinder.this.city.name);
329 |
330 | CityFinder.this.findCityNoInternet.setVisibility(View.GONE);
331 | CityFinder.this.findCityUsingInternet
332 | .setVisibility(View.GONE);
333 | CityFinder.this.noSearchButton.setVisibility(View.GONE);
334 | CityFinder.this.researchButton.setVisibility(View.VISIBLE);
335 | CityFinder.this.homeButton.setVisibility(View.VISIBLE);
336 | CityFinder.this.correctButton.setVisibility(View.VISIBLE);
337 | CityFinder.this.descTextView.setText(CityFinder.this
338 | .getString(R.string.cityfinder_desc2));
339 | } catch (Exception e) {
340 | AlertDialog.Builder builder = new AlertDialog.Builder(
341 | CityFinder.this);
342 | builder.setMessage(
343 | CityFinder.this.getString(R.string.noCityInDB))
344 | .setPositiveButton(
345 | CityFinder.this.getString(R.string.close),
346 | null);
347 | AlertDialog alert = builder.create();
348 | alert.show();
349 | //Log.e("tomaanina", e.getMessage(), e.getCause());
350 | }
351 | } else {
352 | try {
353 | if (CityFinder.this.searchInternetError) {
354 | throw new Exception();
355 | }
356 | resultTextView.setText(CityFinder.this.city.name);
357 | CityFinder.this.findCityNoInternet.setVisibility(View.GONE);
358 | CityFinder.this.findCityUsingInternet
359 | .setVisibility(View.GONE);
360 | CityFinder.this.noSearchButton.setVisibility(View.GONE);
361 | CityFinder.this.descTextView.setText(CityFinder.this
362 | .getString(R.string.cityfinder_desc2));
363 | CityFinder.this.researchButton.setVisibility(View.VISIBLE);
364 | CityFinder.this.homeButton.setVisibility(View.VISIBLE);
365 | CityFinder.this.correctButton.setVisibility(View.VISIBLE);
366 | } catch (Exception e) {
367 | AlertDialog.Builder builder = new AlertDialog.Builder(
368 | CityFinder.this);
369 | builder.setMessage(
370 | CityFinder.this.getString(R.string.noInternet))
371 | .setPositiveButton(
372 | CityFinder.this.getString(R.string.close),
373 | null);
374 | AlertDialog alert = builder.create();
375 | alert.show();
376 | //Log.e("tomaanina", e.getMessage(), e.getCause());
377 | }
378 |
379 | }
380 |
381 | }
382 |
383 | public City getPosition(double lon, double lat)
384 | throws ClientProtocolException, IOException,
385 | ParserConfigurationException, Exception {
386 | City city = new City();
387 | url[TIME_ZONE] = "http://www.earthtools.org/timezone/" + lat + "/"
388 | + lon;
389 | url[CITY_DATA] = "http://173.194.67.95/maps/api/geocode/json?latlng="
390 | + lat + "," + lon + "&sensor=true";
391 | data[TIME_ZONE] = getRequest(url[TIME_ZONE]);
392 | data[CITY_DATA] = getRequest(url[CITY_DATA]);
393 | city = getLocation(data[CITY_DATA]);
394 | city.timeZone = getTimeZone(data[TIME_ZONE]);
395 | city.latitude = Double.toString(lat);
396 | city.longitude = Double.toString(lon);
397 |
398 | return city;
399 | }
400 |
401 | public int getTimeZone(String TimeZoneContent)
402 | throws ParserConfigurationException, ClientProtocolException,
403 | Exception, SAXException {
404 |
405 | CharacterData cd;
406 | try {
407 | DocumentBuilderFactory dbf = DocumentBuilderFactory
408 | .newInstance();
409 | DocumentBuilder db = dbf.newDocumentBuilder();
410 | InputSource is = new InputSource();
411 | is.setCharacterStream(new StringReader(TimeZoneContent));
412 | Document doc = db.parse(is);
413 |
414 | NodeList nodeList = doc.getElementsByTagName("offset");
415 | Element n = (Element) nodeList.item(0);
416 | String data = getCharacterDataFromElement(n);
417 | return Integer.valueOf(data);
418 | } catch (Exception e) {
419 | throw e;
420 | }
421 |
422 | }
423 |
424 | public City getLocation(String s) throws ClientProtocolException {
425 | City temp = new City();
426 |
427 | try {
428 |
429 | JSONObject jArray = new JSONObject(s);
430 |
431 | JSONArray jResult = jArray.getJSONArray("results");
432 | JSONObject jAddCom = jResult.getJSONObject(0);
433 |
434 | JSONArray jResult1 = jAddCom.getJSONArray("address_components");
435 | List AddCombList = new ArrayList();
436 | for (int i = 0; i < jResult1.length(); i++) {
437 | AddCombList.add(jResult1.getJSONObject(i));
438 | if (AddCombList.get(i).getString("types")
439 | .contains("country")) {
440 | temp.country.longName = AddCombList.get(i).getString(
441 | "long_name");
442 | temp.country.name = temp.country.longName;
443 | temp.country.shortName = AddCombList.get(i).getString(
444 | "short_name");
445 | if (temp.country.name == null) {
446 | temp.country.name = temp.country.shortName;
447 | }
448 | } else if (AddCombList.get(i).getString("types")
449 | .contains("administrative_area_level_1"))
450 | temp.name = AddCombList.get(i).getString("long_name");
451 | }
452 |
453 | } catch (JSONException e) {
454 | Toast msg = Toast.makeText(getApplicationContext(),
455 | "Error thrown: " + e.getMessage(), Toast.LENGTH_LONG);
456 | msg.setGravity(Gravity.CENTER, msg.getXOffset() / 2,
457 | msg.getYOffset() / 2);
458 | msg.show();
459 | // TODO Auto-generated catch block
460 | e.printStackTrace();
461 | }
462 |
463 | return temp;
464 | }
465 |
466 | public String getRequest(String url) {
467 |
468 | String line = "";
469 | String content = "";
470 | HttpGet httpRequest = new HttpGet(url);
471 | HttpParams httpParameters = new BasicHttpParams();
472 | // Set the timeout in milliseconds until a connection is
473 | // established.
474 | int timeoutConnection = 10000;
475 | HttpConnectionParams.setConnectionTimeout(httpParameters,
476 | timeoutConnection);
477 | // Set the default socket timeout (SO_TIMEOUT)
478 | // in milliseconds which is the timeout for waiting for data.
479 | int timeoutSocket = 10000;
480 |
481 | HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
482 |
483 | DefaultHttpClient client = new DefaultHttpClient(httpParameters);
484 |
485 | HttpResponse httpResponse;
486 | try {
487 | httpResponse = client.execute(httpRequest);
488 |
489 | final int statusCode = httpResponse.getStatusLine()
490 | .getStatusCode();
491 |
492 | if (statusCode != HttpStatus.SC_OK) {
493 | //Log.e("tomaanina", "Time Out");
494 | }
495 |
496 | HttpEntity httpEntity = httpResponse.getEntity();
497 | // InputStream in = httpEntity.getContent();
498 |
499 | // return in;
500 |
501 | BufferedReader in = new BufferedReader(new InputStreamReader(
502 | httpEntity.getContent()));
503 | while ((line = in.readLine()) != null)
504 | content += line;
505 | in.close();
506 |
507 | } catch (Exception e) {
508 | // TODO Auto-generated catch block
509 | e.printStackTrace();
510 | }
511 | return content;
512 | }
513 |
514 | }
515 |
516 | public static String getCharacterDataFromElement(Element e) {
517 | Node child = e.getFirstChild();
518 | if (child instanceof CharacterData) {
519 | CharacterData cd = (CharacterData) child;
520 | return cd.getData();
521 | }
522 | return "";
523 | }
524 |
525 | public void onPause() {
526 |
527 | super.onPause();
528 | }
529 |
530 | public void onStop() {
531 | super.onStop();
532 | }
533 |
534 | public void onDestroy() {
535 | super.onDestroy();
536 | // TODO : Double check
537 | // is that thread safe ? as I know , LocationListener runs on different
538 | // thread ?
539 | if (this.cityLoc != null)
540 | this.cityLoc.stopSearch();
541 | }
542 |
543 | }
544 |
--------------------------------------------------------------------------------