├── .gitignore ├── AndroidManifest.xml ├── README ├── assets └── quranstreamingDB ├── default.properties ├── res ├── drawable-hdpi │ └── icon.png ├── drawable-ldpi │ └── icon.png ├── drawable-mdpi │ └── icon.png ├── layout │ ├── download_progress.xml │ ├── listview.xml │ ├── listview_ar.xml │ ├── main_ar.xml │ ├── setup.xml │ └── setup_ar.xml ├── menu │ └── mainmenu.xml └── values │ ├── color.xml │ ├── strings.xml │ └── styles.xml └── src └── com └── android └── QuranSteaming ├── ArabicReshaper.java ├── ArabicUtilities.java ├── DBAdapter.java ├── DownloadProgress.java ├── ListAdapter.java ├── PlayingService.java ├── PlaylistManager.java ├── ProjectObject.java ├── QuranSteaming.java └── setup.java /.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .project 3 | .settings 4 | bin 5 | gen 6 | .DS_Store 7 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hammady/Islamic-Streamer-Android/989d36d18a7b4013d5e6a0f94aa3666e60e48bcf/README -------------------------------------------------------------------------------- /assets/quranstreamingDB: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hammady/Islamic-Streamer-Android/989d36d18a7b4013d5e6a0f94aa3666e60e48bcf/assets/quranstreamingDB -------------------------------------------------------------------------------- /default.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "build.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=android-9 12 | -------------------------------------------------------------------------------- /res/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hammady/Islamic-Streamer-Android/989d36d18a7b4013d5e6a0f94aa3666e60e48bcf/res/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /res/drawable-ldpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hammady/Islamic-Streamer-Android/989d36d18a7b4013d5e6a0f94aa3666e60e48bcf/res/drawable-ldpi/icon.png -------------------------------------------------------------------------------- /res/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hammady/Islamic-Streamer-Android/989d36d18a7b4013d5e6a0f94aa3666e60e48bcf/res/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /res/layout/download_progress.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 11 | 12 | 14 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /res/layout/listview.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 22 | 33 | 41 | 49 | 50 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /res/layout/listview_ar.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 22 | 33 | 41 | 49 | 50 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /res/layout/main_ar.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 18 | 23 | 29 | 38 | 47 | 48 | 49 | 53 | 56 | 64 | 65 | 66 | 67 | 68 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /res/layout/setup.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 9 | 15 | 16 | 17 | 18 | 24 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /res/layout/setup_ar.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 9 | 15 | 16 | 17 | 18 | 24 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /res/menu/mainmenu.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /res/values/color.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #b0b0ff 4 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Hello World, QuranSteaming! 4 | حقيبة المسلم/Muslim Bag 5 | Select Language 6 | اختر اللغه 7 | 8 | _id 9 | category_name_a 10 | category_name_e 11 | 12 | 13 | العربيه 14 | English 15 | 16 | 17 | _id 18 | server_name_e 19 | server_name_a 20 | url 21 | 22 | 23 | _id 24 | shaikh_id 25 | surah_id 26 | 27 | 28 | _id 29 | shaikh_name_a 30 | shaikh_name_e 31 | url 32 | 33 | 34 | a._id 35 | a.surah_name_a 36 | a.surah_name_e 37 | c._id is_checked 38 | b.is_playing 39 | a.url 40 | 41 | 42 | _id 43 | url 44 | surah_name_e 45 | surah_name_a 46 | 47 | Select Category 48 | Select Shaikh 49 | Start Streaming 50 | Listen To 51 | Stop 52 | View available Surah 53 | Download 54 | Play Selected 55 | Listen 56 | Download 57 | Settings 58 | اختر مجموعه 59 | اختر الشيخ 60 | توقف 61 | تحميل 62 | الاستماع للمختاره 63 | مشاهدة السور المتاحه 64 | استمع 65 | تحميل 66 | الاعدادات 67 | Site To Use 68 | الموقع المستخدم 69 | Streaming Now 70 | التدفق يتم الان 71 | Please wait 72 | من فضلك الانتظار 73 | Sorry 74 | نعتذر 75 | Can\'t reach the server, No internet connection 76 | تعذر الوصول الى المصدر، لا يوجد اتصال بالانترنت 77 | Downloading selected Items 78 | تحميل السور المختاره 79 | Downloading Completed Successfully 80 | تم التحميل بنجاح 81 | Preparing Download 82 | تجهيز التنزيلات 83 | Preparing for download now 84 | يتم تجهيز التنزيلات الان 85 | Exit 86 | 87 | -------------------------------------------------------------------------------- /res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #b0b0ff 4 | 5 | 8 | 13 | 14 | -------------------------------------------------------------------------------- /src/com/android/QuranSteaming/ArabicReshaper.java: -------------------------------------------------------------------------------- 1 | package com.android.QuranSteaming; 2 | 3 | public class ArabicReshaper{ 4 | private String _returnString; 5 | public String getReshapedWord(){ 6 | 7 | return _returnString; 8 | } 9 | public static char DEFINED_CHARACTERS_ORGINAL_ALF_UPPER_MDD = 0x0622; 10 | public static char DEFINED_CHARACTERS_ORGINAL_ALF_UPPER_HAMAZA = 0x0623; 11 | public static char DEFINED_CHARACTERS_ORGINAL_ALF_LOWER_HAMAZA = 0x0625; 12 | public static char DEFINED_CHARACTERS_ORGINAL_ALF = 0x0627; 13 | public static char DEFINED_CHARACTERS_ORGINAL_LAM =0x0644; 14 | 15 | public static char[][] LAM_ALEF_GLPHIES= 16 | {{15270,65270,65269}, 17 | {15271,65272,65271}, 18 | {1575, 65276,65275}, 19 | {1573, 65274,65273} 20 | }; 21 | 22 | 23 | public static char[][] ARABIC_GLPHIES= 24 | { 25 | { 1616,65146,65146,65147,65147,2 } , 26 | 27 | { 1569,65152,65163,65164,65152,3 } , 28 | { 1570,65153,65153,65154,65154,2 } , 29 | { 1571,65155,65155,65156,65156,2 } , 30 | { 1572,65157,65157,65158,65158,2 } , 31 | { 1573,65159,65159,65160,65160,2 } , 32 | { 1575,65165,65165,65166,65166,2 } , /*alif*/ 33 | { 1576,65167,65169,65170,65168,4 } , /*ba*/ 34 | { 1577,65171,65171,65172,65172,2 } , 35 | { 1578,65173,65175,65176,65174,4 } , 36 | { 1579,65177,65179,65180,65178,4 } , 37 | { 1580,65181,65183,65184,65182,4 } , 38 | { 1581,65185,65187,65188,65186,4 } , 39 | { 1582,65189,65191,65192,65190,4 } , 40 | { 1583,65193,65193,65194,65194,2 } , 41 | { 1584,65195,65195,65196,65196,2 } , 42 | { 1585,65197,65197,65198,65198,2 } , 43 | { 1586,65199,65199,65200,65200,2 } , 44 | { 1587,65201,65203,65204,65202,4 } , 45 | { 1588,65205,65207,65208,65206,4 } , 46 | { 1589,65209,65211,65212,65210,4 } , 47 | { 1590,65213,65215,65216,65214,4 } , 48 | { 1591,65217,65219,65218,65220,4 } , 49 | { 1592,65221,65223,65222,65222,4 } , 50 | { 1593,65225,65227,65228,65226,4 } , 51 | { 1594,65229,65231,65232,65230,4 } , 52 | { 1601,65233,65235,65236,65234,4 } , 53 | { 1602,65237,65239,65240,65238,4 } , 54 | { 1603,65241,65243,65244,65242,4 } , 55 | { 1604,65245,65247,65248,65246,4 } , 56 | { 1605,65249,65251,65252,65250,4 } , 57 | { 1606,65253,65255,65256,65254,4 } , 58 | { 1607,65257,65259,65260,65258,4 } , 59 | { 1608,65261,65261,65262,65262,2 } , 60 | { 1609,65263,65263,65264,65264,2 } , 61 | { 1574,65161,65163,65163,65162,2 } , 62 | { 1610,65265,65267,65268,65266,4 } }; 63 | 64 | private char getReshapedGlphy(char target,int location){ 65 | //Iterate over the 36 characters in the GLPHIES Matrix 66 | for(int n = 0; n0){ 249 | return (char)getLamAlef(alef,lam,true)+" "; 250 | } 251 | 252 | } 253 | 254 | //For the First Letter 255 | reshapedLetters[0]=getReshapedGlphy(wordLetters[0], 2); 256 | 257 | //The current Letter 258 | char currentLetter=wordLetters[0]; 259 | 260 | /** 261 | * The Main Iterator 262 | */ 263 | 264 | //Iterate over the word from the second character till the second to the last 265 | for(int i=1;i0){ 269 | //Check if the Letter before the Lam is 2 Forms Letter, to Make the Lam Alef as its the end of the Word 270 | if((i-2 < 0) || ((i-2 >= 0) && (getGlphyType(wordLetters[i-2])==2))){ 271 | 272 | //Mark the letter of Lam as Lam Indicator 273 | reshapedLetters[i-1]=lamIndicator; 274 | 275 | //Assign Lam Alef to the Letter of Alef 276 | reshapedLetters[i]=(char)getLamAlef(wordLetters[i], currentLetter, true); 277 | 278 | }else{ //The Letter before the Lam is more than 2 Forms Letter 279 | 280 | //Mark the letter of Lam as Lam Indicator 281 | reshapedLetters[i-1]=lamIndicator; 282 | 283 | //Assign Lam Alef to the Letter of Alef 284 | reshapedLetters[i]=(char)getLamAlef(wordLetters[i], currentLetter, false); 285 | } 286 | }else{ //The Word doesn't have LamAlef 287 | 288 | int beforeLast=i-1; 289 | 290 | //Check if the Letter Before Last has only 2 Forms, for the current Letter to be as a start for a new Word! 291 | if(getGlphyType(wordLetters[beforeLast])==2){ 292 | 293 | //If the letter has only 2 shapes, then it doesnt matter which position it is, It'll be always the second form 294 | reshapedLetters[i]=getReshapedGlphy(wordLetters[i], 2); 295 | }else{ 296 | 297 | //Then it should be in the middle which should be placed in its right form [3] 298 | reshapedLetters[i]=getReshapedGlphy(wordLetters[i], 3); 299 | } 300 | } 301 | //Assign the CurrentLetter as the Word Letter 302 | currentLetter=wordLetters[i]; 303 | } 304 | 305 | 306 | /** 307 | * The Last Letters Check 308 | */ 309 | 310 | //Check if the Letters are Lam Alef 311 | if(getLamAlef(wordLetters[wordLength-1], wordLetters[wordLength-2], true)>0){ 312 | 313 | //Check if the Letter before the Lam is 2 Forms Letter, to Make the Lam Alef as its the end of the Word 314 | if(getGlphyType(wordLetters[wordLength-3])==2){ //check for the last letter 315 | 316 | //Mark the letter of Lam as Lam Indicator 317 | reshapedLetters[wordLength-2]=lamIndicator; 318 | 319 | //Assign Lam Alef to the Letter of Alef 320 | reshapedLetters[wordLength-1]=(char)getLamAlef(wordLetters[wordLength-1], wordLetters[wordLength-2], true); 321 | }else { 322 | 323 | //Mark the letter of Lam as Lam Indicator 324 | reshapedLetters[wordLength-2]=lamIndicator; 325 | 326 | //Assign Lam Alef to the Letter of Alef 327 | reshapedLetters[wordLength-1]=(char)getLamAlef(wordLetters[wordLength-1], wordLetters[wordLength-2], false); 328 | } 329 | 330 | }else { 331 | //check for the last letter Before last has 2 forms, that means that the last Letter will be alone. 332 | if(getGlphyType(wordLetters[wordLength-2])==2){ 333 | //If the letter has only 2 shapes, then it doesn't matter which position it is, It'll be always the second form 334 | reshapedLetters[wordLength-1]=getReshapedGlphy(wordLetters[wordLength-1], 1); 335 | }else { 336 | //Put the right form of the character, 4 for the last letter in the word 337 | reshapedLetters[wordLength-1]=getReshapedGlphy(wordLetters[wordLength-1], 4); 338 | } 339 | } 340 | 341 | /** 342 | * Assign the Final Results of Shaped Word 343 | */ 344 | 345 | //Iterate over the Reshaped Letters and remove the Lam Indicators 346 | for(int i=0;i finalWords=new ArrayList(); 88 | 89 | //Temp word to hold the current word 90 | String tempWord=""; 91 | 92 | //Iterate over the Word Length 93 | for(int i=0;i1) 145 | result.append("\n"); 146 | } 147 | return result.toString(); 148 | } else { 149 | return null; 150 | } 151 | 152 | } 153 | /** 154 | * The Main Reshaping Function to be Used in Android Program 155 | * @param allText The text to be Reshaped 156 | * @return the Reshaped Text 157 | */ 158 | public static String reshapeSentence(String sentence){ 159 | 160 | //get the Words from the Text 161 | String[] words=getWords(sentence); 162 | 163 | //prepare the Reshaped Text 164 | StringBuffer reshapedText=new StringBuffer(""); 165 | 166 | //Iterate over the Words 167 | for(int i=0;i0){ 147 | myOutput.write(buffer, 0, length); 148 | } 149 | //Close the streams 150 | myOutput.flush(); 151 | myOutput.close(); 152 | myInput.close(); 153 | } 154 | 155 | public void openDataBase() throws SQLiteException{ 156 | //Open the database 157 | String myPath = DB_PATH + DB_NAME; 158 | setDb(SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE)); 159 | } 160 | 161 | //---closes the database--- 162 | public void close() 163 | { 164 | DBHelper.close(); 165 | } 166 | 167 | // Add your public helper methods to access and get content from the database. 168 | // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy 169 | // to you to create adapters for your views. 170 | 171 | public Cursor getData(String sql,String[] columns,String filter,String type,String sortCol) 172 | { 173 | Cursor cr=null; 174 | if(type=="select") 175 | cr =getDb().query(sql, columns, filter,null,null,null,sortCol); 176 | else 177 | try { 178 | getDb().execSQL(sql); 179 | } catch (SQLException e) { 180 | e.printStackTrace(); 181 | } 182 | return cr; 183 | } 184 | 185 | public Cursor getData(String sql,String[] columns,String filter,String type) 186 | { 187 | Cursor cr=null; 188 | if(type=="select") 189 | cr =getDb().query(sql, columns, filter,null,null,null,null); 190 | else 191 | try { 192 | getDb().beginTransaction(); 193 | String fullSql = sql; 194 | String subSql=""; 195 | int statementIndex=sql.indexOf(";"); 196 | while(statementIndex>0) 197 | { 198 | subSql = fullSql.substring(0,statementIndex); 199 | getDb().execSQL(subSql); 200 | fullSql = fullSql.substring(statementIndex+1); 201 | statementIndex=fullSql.indexOf(";"); 202 | } 203 | if (fullSql.length()!=0) 204 | { 205 | getDb().execSQL(fullSql); 206 | } 207 | 208 | } catch (SQLException e) { 209 | e.printStackTrace(); 210 | Toast.makeText(context,"10"+e.getMessage(),Toast.LENGTH_LONG).show(); 211 | } 212 | finally{ 213 | getDb().setTransactionSuccessful(); 214 | getDb().endTransaction(); 215 | 216 | } 217 | return cr; 218 | } 219 | 220 | /** 221 | * @param db the db to set 222 | */ 223 | public void setDb(SQLiteDatabase db) { 224 | this.db = db; 225 | } 226 | 227 | /** 228 | * @return the db 229 | */ 230 | public SQLiteDatabase getDb() { 231 | return db; 232 | } 233 | 234 | } -------------------------------------------------------------------------------- /src/com/android/QuranSteaming/DownloadProgress.java: -------------------------------------------------------------------------------- 1 | package com.android.QuranSteaming; 2 | 3 | import java.util.ArrayList; 4 | 5 | import android.app.Activity; 6 | import android.app.Notification; 7 | import android.app.NotificationManager; 8 | import android.app.PendingIntent; 9 | import android.content.Context; 10 | import android.content.Intent; 11 | import android.content.res.Resources; 12 | import android.os.Bundle; 13 | import android.widget.ProgressBar; 14 | import android.widget.RemoteViews; 15 | 16 | /** 17 | * Simulates a download and updates the notification bar with a Progress 18 | * 19 | * @author Nico Heid 20 | * 21 | */ 22 | public class DownloadProgress extends Activity { 23 | 24 | public static int totalSize =0 ; 25 | public static ArrayList downloaded; 26 | private int totalDownloadedSize = 0; 27 | ProgressBar progressBar; 28 | private int progress = 0; 29 | public static boolean isInUse = false; 30 | 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | // get the layout 35 | setContentView(R.layout.download_progress); 36 | // configure the intent 37 | Intent intent = new Intent(this, DownloadProgress.class); 38 | final PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0); 39 | 40 | // configure the notification 41 | final Notification notification = new Notification(R.drawable.icon, QuranSteaming.language.equalsIgnoreCase("EN")? getApplication().getString(R.string.downloadText):ArabicUtilities.reshape(getApplication().getString(R.string.downloadText_ar)), System.currentTimeMillis()); 42 | notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT; 43 | notification.contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.download_progress); 44 | notification.contentIntent = pendingIntent; 45 | //notification.contentView.setImageViewResource(R.id.status_icon, R.drawable.ic_menu_save); 46 | notification.contentView.setTextViewText(R.id.status_text, QuranSteaming.language.equalsIgnoreCase("EN")? getApplication().getString(R.string.downloadText):ArabicUtilities.reshape(getApplication().getString(R.string.downloadText_ar))); 47 | notification.contentView.setProgressBar(R.id.status_progress, 100, progress, false); 48 | 49 | @SuppressWarnings("static-access") 50 | final NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService( 51 | getApplicationContext().NOTIFICATION_SERVICE); 52 | 53 | notificationManager.notify(12, notification); 54 | 55 | // simulate progress 56 | Thread download = new Thread() { 57 | 58 | @Override 59 | public void run() { 60 | 61 | while(getTotalDowbloaded()=0;i--) 90 | { 91 | totalDownloaded += downloaded.get(i); 92 | downloaded.remove(i); 93 | } 94 | totalDownloadedSize = totalDownloaded; 95 | downloaded.add(totalDownloaded); 96 | return totalDownloaded; 97 | } 98 | private void onDownloadComplete() { 99 | String ns = Context.NOTIFICATION_SERVICE; 100 | NotificationManager nm = (NotificationManager) getSystemService(ns); 101 | 102 | long when = System.currentTimeMillis(); 103 | Notification notification = new Notification(R.drawable.icon, 104 | "Download Completed", when); 105 | notification.defaults |= Notification.DEFAULT_SOUND 106 | | Notification.FLAG_AUTO_CANCEL; 107 | 108 | Context context = getApplicationContext(); 109 | CharSequence contentTitle = getTitle().toString(); 110 | Resources r=context.getResources(); 111 | CharSequence contentText = ArabicUtilities.reshape(r.getString(QuranSteaming.language.equalsIgnoreCase("EN")?R.string.downloadCompleted:R.string.downloadCompleted_ar)); 112 | Intent notificationIntent = new Intent(context, QuranSteaming.class); 113 | PendingIntent contentIntent = PendingIntent.getActivity(context, 0, 114 | notificationIntent, 0); 115 | 116 | notification.setLatestEventInfo(context, contentTitle, contentText, 117 | contentIntent); 118 | nm.notify(1,notification); 119 | } 120 | 121 | } -------------------------------------------------------------------------------- /src/com/android/QuranSteaming/ListAdapter.java: -------------------------------------------------------------------------------- 1 | package com.android.QuranSteaming; 2 | 3 | import android.widget.ArrayAdapter; 4 | import android.widget.BaseAdapter; 5 | import android.widget.CheckBox; 6 | import android.widget.CompoundButton; 7 | import android.widget.CompoundButton.OnCheckedChangeListener; 8 | import android.widget.ImageView; 9 | import android.widget.ListView; 10 | import android.widget.RelativeLayout; 11 | import android.widget.Toast; 12 | import java.util.ArrayList; 13 | 14 | import com.android.QuranSteaming.QuranSteaming.playMode; 15 | 16 | import android.content.Context; 17 | import android.database.Cursor; 18 | import android.graphics.Color; 19 | import android.view.LayoutInflater; 20 | import android.view.View; 21 | import android.view.View.OnClickListener; 22 | import android.view.ViewGroup; 23 | import android.widget.TextView; 24 | 25 | public class ListAdapter extends ArrayAdapter implements 26 | OnClickListener { 27 | private Context context; 28 | 29 | final String SETTING_TODOLIST = "todolist"; 30 | RelativeLayout alaListItemId; 31 | static boolean isManuallyChecked= false; 32 | 33 | public ListAdapter(Context context, int textViewResourceId, 34 | ArrayList dataItems) { 35 | super(context, textViewResourceId, dataItems); 36 | this.context = context; 37 | } 38 | 39 | @Override 40 | public View getView(int position, View convertView, ViewGroup parent) 41 | { 42 | 43 | View v = convertView; 44 | //Get the current alert object 45 | String surahName = getItem(position).surahName; 46 | int surahId = getItem(position).surahId; 47 | 48 | if (v == null) { 49 | LayoutInflater inflater = (LayoutInflater) context 50 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 51 | if(QuranSteaming.language.equalsIgnoreCase("EN")) 52 | v = inflater.inflate(R.layout.listview, null); 53 | else 54 | v = inflater.inflate(R.layout.listview_ar, null); 55 | } 56 | alaListItemId = (RelativeLayout)v.findViewById(R.id.alaListItemId); 57 | if (position%2==0) 58 | alaListItemId.setBackgroundColor(Color.GRAY); 59 | else 60 | alaListItemId.setBackgroundColor(Color.DKGRAY); 61 | 62 | /*//Inflate the view 63 | if(convertView==null) 64 | { 65 | alertView = new LinearLayout(getContext()); 66 | String inflater = Context.LAYOUT_INFLATER_SERVICE; 67 | LayoutInflater vi; 68 | vi = (LayoutInflater)getContext().getSystemService(inflater); 69 | vi.inflate(resource, alertView, true); 70 | } 71 | else 72 | { 73 | alertView = (LinearLayout) convertView; 74 | }*/ 75 | //Get the text boxes from the listitem.xml file 76 | TextView tvSurahName =(TextView)v.findViewById(R.id.tvSurahName); 77 | TextView tvSurahId =(TextView)v.findViewById(R.id.tvSurahId); 78 | TextView tvItemPosition =(TextView)v.findViewById(R.id.tvItemPosition); 79 | ImageView ivImg =(ImageView)v.findViewById(R.id.ivImg); 80 | CheckBox cb = (CheckBox)v.findViewById(R.id.cbListViewItem); 81 | if(cb.getVisibility()!=View.VISIBLE) 82 | if (getItem(position).isChecked) 83 | { 84 | QuranSteaming.selectedCount ++; 85 | } 86 | cb.setOnCheckedChangeListener(null); 87 | cb.setChecked(getItem(position).isChecked); 88 | cb.setOnCheckedChangeListener(new OnCheckedChangeListener() { 89 | @Override 90 | public void onCheckedChanged(CompoundButton arg0, boolean isChecked) { 91 | View v = (View)arg0.getParent(); 92 | TextView tv=(TextView) v.findViewById(R.id.tvSurahId); 93 | TextView tvItemPosition=(TextView) v.findViewById(R.id.tvItemPosition); 94 | try 95 | { 96 | QuranSteaming.dbaAdabter.openDataBase(); 97 | } 98 | catch(Exception ex) 99 | { 100 | Toast.makeText(context,ex.getMessage(),Toast.LENGTH_LONG).show(); 101 | } 102 | 103 | String str; 104 | String itemValue=""; 105 | itemValue=QuranSteaming.getShaikhSurahID(String.valueOf(QuranSteaming.selectedShaikh),tv.getText().toString()); 106 | Integer position = Integer.parseInt(tvItemPosition.getText().toString()); 107 | if(isChecked) 108 | { 109 | if(QuranSteaming.selectedShaikh!= QuranSteaming.playingShaikh) 110 | { 111 | QuranSteaming.selectedCount=0; 112 | str= "delete from playlist_item"; 113 | QuranSteaming.dbaAdabter.getData(str, null, null, QuranSteaming.update); 114 | } 115 | QuranSteaming.playingShaikh = QuranSteaming.selectedShaikh; 116 | str="insert into playlist_item(playlist_id, shaikh_surah_id) values('1','"+itemValue+"')"; 117 | if(!isManuallyChecked) 118 | { 119 | ListAdapter.this.getItem(position).isChecked=true; 120 | QuranSteaming.selectedCount++; 121 | } 122 | } 123 | else 124 | { 125 | str="delete from playlist_item where playlist_id='1' and shaikh_surah_id='"+itemValue+"'"; 126 | ListAdapter.this.getItem(position).isChecked=false; 127 | QuranSteaming.selectedCount--; 128 | } 129 | View v2=((View)((View)((View)((View)((View)((View)v.getParent()).getParent()).getParent()).getParent()).getParent().getParent().getParent()).findViewById(R.id.alaMenuLayout)); 130 | if(QuranSteaming.selectedCount==0) 131 | { 132 | if((v2.findViewById(R.id.btnStopStream).getVisibility()!=View.VISIBLE)&&(QuranSteaming.isPaused!=true)) 133 | { 134 | v2.setVisibility(View.INVISIBLE); 135 | v2.findViewById(R.id.btnStartStream).setVisibility(View.INVISIBLE); 136 | } 137 | if((QuranSteaming.mp!=null)&&(QuranSteaming.mp.isPlaying())) 138 | v2.findViewById(R.id.btnStartStream).setVisibility(View.INVISIBLE); 139 | v2.findViewById(R.id.btnDownload).setVisibility(View.INVISIBLE); 140 | v2.findViewById(R.id.btnAddToPlaylist).setVisibility(View.INVISIBLE); 141 | } 142 | else 143 | { 144 | v2.setVisibility(View.VISIBLE); 145 | v2.findViewById(R.id.btnDownload).setVisibility(View.VISIBLE); 146 | v2.findViewById(R.id.btnAddToPlaylist).setVisibility(View.VISIBLE); 147 | v2.findViewById(R.id.btnStartStream).setVisibility(View.VISIBLE); 148 | } 149 | if(!isManuallyChecked) 150 | QuranSteaming.dbaAdabter.getData(str, null, null, QuranSteaming.update); 151 | QuranSteaming.dbaAdabter.close(); 152 | } 153 | }); 154 | ivImg.setOnClickListener(new OnClickListener() { 155 | 156 | @Override 157 | public void onClick(View v) { 158 | ImageView ivImg =(ImageView)v; 159 | ivImg.setVisibility(View.INVISIBLE); 160 | //QuranSteaming.stopStreamingAudio(); 161 | } 162 | }); 163 | tvSurahName.setOnClickListener(new OnClickListener() { 164 | 165 | @Override 166 | public void onClick(View v) { 167 | QuranSteaming.isRunning=false; 168 | View nv=(View) v.getParent(); 169 | //hideAllPlayImage((ListView)nv.getParent().getParent()); 170 | final ImageView ivImg =(ImageView)((View)nv.getParent()).findViewById(R.id.ivImg); 171 | View v2 = ((View)((View)((View)((View)((View)((View)v.getParent()).getParent()).getParent()).getParent()).getParent().getParent().getParent()).findViewById(R.id.alaMenuLayout)); 172 | if(v2.findViewById(R.id.btnStopStream).getVisibility()==View.VISIBLE) 173 | { 174 | ivImg.setVisibility(View.INVISIBLE); 175 | QuranSteaming.stopStreamingAudio(v2); 176 | return; 177 | } 178 | //v2.setVisibility(View.VISIBLE); 179 | //v2.findViewById(R.id.btnStopstream).setVisibility(View.VISIBLE); 180 | TextView tvSurahId =(TextView)((View) v.getParent()).findViewById(R.id.tvSurahId); 181 | QuranSteaming.selectedSurah = Long.parseLong(tvSurahId.getText().toString()); 182 | QuranSteaming.selectedSurahURL=getSurahURL(QuranSteaming.selectedSurah); 183 | QuranSteaming.setPlayingMode(playMode.singleItem); 184 | Listen(ivImg,v2); 185 | } 186 | }); 187 | //Assign the appropriate data from our alert object above 188 | tvSurahName.setText(surahName); 189 | tvSurahId.setText(String.valueOf(surahId)); 190 | tvItemPosition.setText(String.valueOf(position)); 191 | if (getItem(position).isChecked) 192 | { 193 | isManuallyChecked = true; 194 | //cb.setChecked(true); 195 | isManuallyChecked = false; 196 | } 197 | return v; 198 | } 199 | private void Listen(ImageView v,View v2) 200 | { 201 | QuranSteaming.startStreamingAudio(v,QuranSteaming.selectedSurahURL,v2); 202 | } 203 | public String getSurahURL(Long surahID) 204 | { 205 | Cursor cr=null; 206 | String strSurahURL=""; 207 | ArrayAdapter adapter1=ArrayAdapter.createFromResource(QuranSteaming.context,R.array.surah_url,android.R.layout.simple_spinner_item); 208 | String[] tableColumns = new String [adapter1.getCount()]; 209 | String strTableColumns =""; 210 | DBAdapter dbaAdabter= new DBAdapter(QuranSteaming.context); 211 | try 212 | { 213 | dbaAdabter.openDataBase(); 214 | } 215 | catch(Exception ex) 216 | { 217 | //Toast.makeText(this,"6"+ex.getMessage(),Toast.LENGTH_LONG).show(); 218 | } 219 | for (int i=0;i0) 24 | { 25 | cr1=dbaAdabter.getDb().rawQuery("select min(a._id) id from playlist_item a where a._id>"+playingIndex,null); 26 | if((cr1.getCount()==0)&&(isLooping)) 27 | return 0; 28 | } 29 | else 30 | { 31 | cr1=dbaAdabter.getDb().rawQuery("select max(a._id) id from playlist_item a where a._id<"+playingIndex,null); 32 | if((cr1.getCount()==0)&&(isLooping)) 33 | cr1=dbaAdabter.getDb().rawQuery("select max(a._id) id from playlist_item a",null); 34 | else 35 | return prevIndex; 36 | cr1.moveToFirst(); 37 | prevIndex= cr1.getInt(cr1.getColumnIndex("id")); 38 | cr1=dbaAdabter.getDb().rawQuery("select max(a._id) id from playlist_item a where a._id<"+prevIndex,null); 39 | if((cr1.getCount()==0)) 40 | prevIndex = -1; 41 | } 42 | cr1.moveToFirst(); 43 | prevIndex= cr1.getInt(cr1.getColumnIndex("id")); 44 | } 45 | return index; 46 | } 47 | public void setPlayingIndex(int playingIndex) { 48 | PlaylistManager.playingIndex = playingIndex; 49 | } 50 | public PlaylistManager() { 51 | try 52 | { 53 | dbaAdabter.createDataBase(); 54 | } 55 | catch (IOException ioe) 56 | { 57 | throw new Error("Unable to create database"); 58 | } 59 | try 60 | { 61 | dbaAdabter.openDataBase(); 62 | } 63 | catch(Exception ex) 64 | { 65 | ex.printStackTrace(); 66 | } 67 | Cursor cr1=dbaAdabter.getDb().rawQuery("select lang,server_name from config",null); 68 | cr1.moveToFirst(); 69 | static_url= cr1.getString(cr1.getColumnIndex("server_name")); 70 | dbaAdabter.close(); 71 | } 72 | public String getNextItemURL() 73 | { 74 | String retURL=""; 75 | try 76 | { 77 | dbaAdabter.openDataBase(); 78 | } 79 | catch(Exception ex) 80 | { 81 | ex.printStackTrace(); 82 | } 83 | 84 | Cursor cr1=dbaAdabter.getDb().rawQuery("select a._id id,b.url||c.url URL from playlist_item a,shaikh b, surah c, shaikh_surah d where a.shaikh_surah_id = d._id and d.shaikh_id = b._id and d.surah_id = c._id and a._id>"+playingIndex+" limit 1",null); 85 | if(!cr1.moveToFirst()&&isLooping) 86 | { 87 | cr1=dbaAdabter.getDb().rawQuery("select a._id id,b.url||c.url URL from playlist_item a,shaikh b, surah c, shaikh_surah d where a.shaikh_surah_id = d._id and d.shaikh_id = b._id and d.surah_id = c._id and a._id>0 limit 1",null); 88 | playingIndex = 0; 89 | } 90 | if(cr1.moveToFirst()) 91 | { 92 | playingIndex = Integer.parseInt(cr1.getString(cr1.getColumnIndex("id"))); 93 | retURL = cr1.getString(cr1.getColumnIndex("URL")); 94 | File f; 95 | try { 96 | f = new File(sanitizePath(QuranSteaming.context, "/QuranStreaming/"+retURL)); 97 | if(f.exists()) 98 | { 99 | return f.getPath(); 100 | } 101 | retURL = static_url+ retURL; 102 | } catch (Exception e) { 103 | e.printStackTrace(); 104 | } 105 | } 106 | dbaAdabter.close(); 107 | return retURL; 108 | } 109 | private String sanitizePath(Context con,String path) throws Exception { 110 | //Toast.makeText(con, "sanitizePath", Toast.LENGTH_LONG).show(); 111 | if (!path.startsWith("/")) { 112 | path = "/" + path; 113 | } 114 | if (!path.contains(".")) { 115 | path += ".mp3"; 116 | } 117 | 118 | if(DirectoryNotExists(con,Environment.getExternalStorageDirectory().getAbsolutePath()+new File(path).getParentFile().toString())) 119 | { 120 | createFolder(); 121 | } 122 | return Environment.getExternalStorageDirectory().getAbsolutePath() + path; 123 | } 124 | private boolean DirectoryNotExists(Context con, String path) throws Exception 125 | { 126 | File directory = new File(path); 127 | if (!directory.exists() && !directory.mkdirs()) { 128 | 129 | //Toast.makeText(con, "error creating folder", Toast.LENGTH_LONG).show(); 130 | //Log.e(con,"callRecorder","error creating folder"); 131 | return true; 132 | } 133 | return false; 134 | } 135 | private void createFolder() 136 | { 137 | 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/com/android/QuranSteaming/ProjectObject.java: -------------------------------------------------------------------------------- 1 | package com.android.QuranSteaming; 2 | 3 | public class ProjectObject { 4 | int surahId; 5 | String surahName; 6 | boolean selected=false; 7 | boolean isPlaying= false; 8 | boolean isChecked= false; 9 | } 10 | -------------------------------------------------------------------------------- /src/com/android/QuranSteaming/QuranSteaming.java: -------------------------------------------------------------------------------- 1 | package com.android.QuranSteaming; 2 | 3 | import java.io.File; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.net.HttpURLConnection; 8 | import java.net.URL; 9 | import java.util.ArrayList; 10 | import android.app.Activity; 11 | import android.app.ActivityManager; 12 | import android.app.ActivityManager.RunningServiceInfo; 13 | import android.app.ProgressDialog; 14 | import android.content.ComponentName; 15 | import android.content.Context; 16 | import android.content.Intent; 17 | import android.content.ServiceConnection; 18 | import android.content.res.Resources; 19 | import android.database.Cursor; 20 | import android.media.MediaPlayer; 21 | import android.net.ConnectivityManager; 22 | import android.net.NetworkInfo; 23 | import android.os.Bundle; 24 | import android.os.Environment; 25 | import android.os.Handler; 26 | import android.os.IBinder; 27 | import android.os.Message; 28 | import android.telephony.PhoneStateListener; 29 | import android.telephony.TelephonyManager; 30 | import android.util.Log; 31 | import android.view.Menu; 32 | import android.view.MenuInflater; 33 | import android.view.MenuItem; 34 | import android.view.View; 35 | import android.widget.AdapterView; 36 | import android.widget.AdapterView.OnItemClickListener; 37 | import android.widget.ArrayAdapter; 38 | import android.widget.BaseAdapter; 39 | import android.widget.ImageButton; 40 | import android.widget.ImageView; 41 | import android.widget.ListView; 42 | import android.widget.SimpleCursorAdapter; 43 | import android.widget.Spinner; 44 | import android.widget.TextView; 45 | import android.widget.Toast; 46 | import android.widget.AdapterView.OnItemSelectedListener; 47 | 48 | public class QuranSteaming extends Activity { 49 | static enum playMode{ 50 | playlist, 51 | singleItem, 52 | empty 53 | } 54 | static class HandlerAction{ 55 | final int HideMenuBar = 10; 56 | public int getHideMenuBar() { 57 | return HideMenuBar; 58 | } 59 | public int getDismissDialog() { 60 | return dismissDialog; 61 | } 62 | final int dismissDialog = 0; 63 | final int notifyListViewAdapter = 1; 64 | final int showSorryMessage = 2; 65 | final int showWaitMessage= 3; 66 | final int showPlayMenu = 4; 67 | final int onPauseAction = 5; 68 | }; 69 | static HandlerAction myHandlerAction= new HandlerAction(); 70 | public static boolean isRunning = false; 71 | PlaylistManager plManger; 72 | public static DBAdapter dbaAdabter; 73 | String[] tableColumns; 74 | public static String select ="select"; 75 | public static String update ="update"; 76 | public static String static_url; 77 | public static String static_path; 78 | public static String language =""; 79 | public static MediaPlayer mp; 80 | public static Context context; 81 | public static playMode playingMode = playMode.empty; 82 | public static boolean isPaused = false; 83 | static PhoneStateListener listener; 84 | Spinner spnCategory; 85 | Spinner spnShaikh; 86 | static Integer selectedCount = 0; 87 | static ProgressDialog progDailog; 88 | static boolean Mediaready= false; 89 | Long selectedCategory; 90 | static Long selectedShaikh; 91 | static Long playingShaikh; 92 | static String selectedShaikhURL; 93 | static Long selectedSurah; 94 | static String sourceFile; 95 | static View alaMenuLayout; 96 | static String selectedSurahURL; 97 | static boolean isPausedDueToCall = false; 98 | //private Updater playlistUpdater=new Updater(); 99 | /** 100 | * buttons definition 101 | */ 102 | ImageButton btnStartStream; 103 | ImageButton btnDownload; 104 | ImageButton stopStreamButton; 105 | ImageButton btnMoveToNext; 106 | ImageButton btnMoveToPrev; 107 | ImageButton btnAddToPlaylist; 108 | /** 109 | * end buttons definition 110 | */ 111 | static ListView lvSurah; 112 | ArrayList Surahs=null; 113 | ListAdapter arrayAdapter; 114 | public static PlayingService s; 115 | private static boolean waitTillPlay=false; 116 | 117 | public static Handler handler = new Handler() { 118 | private void showHideMenu() 119 | { 120 | if((s!=null)&&(s.getIsPlaying())) 121 | { 122 | alaMenuLayout.setVisibility(View.VISIBLE); 123 | alaMenuLayout.findViewById(R.id.btnPlayNext).setVisibility(View.VISIBLE); 124 | alaMenuLayout.findViewById(R.id.btnPlayPrevious).setVisibility(View.VISIBLE); 125 | //findViewById(R.id.alaMenuLayout).findViewById(R.id.btnStartStream).setVisibility(View.VISIBLE); 126 | alaMenuLayout.findViewById(R.id.btnStopStream).setVisibility(View.VISIBLE); 127 | } 128 | } 129 | @Override 130 | public void handleMessage(Message msg) { 131 | final Resources r=context.getResources(); 132 | if(msg.what==myHandlerAction.getHideMenuBar()) 133 | { 134 | if(selectedCount>0) 135 | { 136 | alaMenuLayout.findViewById(R.id.btnStartStream).setVisibility(View.VISIBLE); 137 | alaMenuLayout.findViewById(R.id.btnStopStream).setVisibility(View.INVISIBLE); 138 | } 139 | else 140 | { 141 | alaMenuLayout.setVisibility(View.INVISIBLE); 142 | alaMenuLayout.findViewById(R.id.btnStartStream).setVisibility(View.INVISIBLE); 143 | alaMenuLayout.findViewById(R.id.btnStopStream).setVisibility(View.INVISIBLE); 144 | alaMenuLayout.findViewById(R.id.btnPlayNext).setVisibility(View.INVISIBLE); 145 | alaMenuLayout.findViewById(R.id.btnPlayPrevious).setVisibility(View.INVISIBLE); 146 | } 147 | } 148 | else if (msg.what==myHandlerAction.getDismissDialog()) 149 | { 150 | progDailog.dismiss(); 151 | } 152 | else if (msg.what==myHandlerAction.notifyListViewAdapter) 153 | { 154 | ((BaseAdapter)lvSurah.getAdapter()).notifyDataSetChanged(); 155 | } 156 | else if(msg.what==myHandlerAction.showSorryMessage) 157 | { 158 | if(language.equalsIgnoreCase("EN")) 159 | progDailog = ProgressDialog.show(context,r.getString(R.string.Sorry), r.getString(R.string.noInternetConnection),true); 160 | else 161 | progDailog = ProgressDialog.show(context,ArabicUtilities.reshape(r.getString(R.string.Sorry_ar)), ArabicUtilities.reshape(r.getString(R.string.noInternetConnection_ar)),true); 162 | } 163 | else if(msg.what==myHandlerAction.showWaitMessage) 164 | { 165 | if(language.equalsIgnoreCase("EN")) 166 | progDailog = ProgressDialog.show(context,r.getString(R.string.txtStreamingText), r.getString(R.string.txtStreamingWaitText),true); 167 | else 168 | progDailog = ProgressDialog.show(context,ArabicUtilities.reshape(r.getString(R.string.txtStreamingText_ar)), ArabicUtilities.reshape(r.getString(R.string.txtStreamingWaitText_ar)),true); 169 | } 170 | else if(msg.what==myHandlerAction.showPlayMenu) 171 | { 172 | showHideMenu(); 173 | } 174 | else if(msg.what==myHandlerAction.onPauseAction) 175 | { 176 | alaMenuLayout.findViewById(R.id.btnStartStream).setVisibility(View.VISIBLE); 177 | alaMenuLayout.findViewById(R.id.btnStopStream).setVisibility(View.INVISIBLE); 178 | } 179 | } 180 | }; 181 | /** Called when the activity is first created. */ 182 | @Override 183 | public void onCreate(Bundle savedInstanceState) { 184 | super.onCreate(savedInstanceState); 185 | selectedCount=0; 186 | PlayingService.setMainActivity(this); 187 | //creating an intent for the service 188 | Intent intent = new Intent(this,PlayingService.class); 189 | if(!isMyServiceRunning()) 190 | startService(intent); 191 | bindService(intent, mConnection, BIND_AUTO_CREATE); 192 | dbaAdabter = new DBAdapter(getBaseContext()); 193 | //checking db existance 194 | try 195 | { 196 | dbaAdabter.createDataBase(); 197 | } 198 | catch (IOException ioe) 199 | { 200 | throw new Error("Unable to create database"); 201 | } 202 | //opening database 203 | try 204 | { 205 | dbaAdabter.openDataBase(); 206 | } 207 | catch(Exception ex) 208 | { 209 | Toast.makeText(this,"6"+ex.getMessage(),Toast.LENGTH_LONG).show(); 210 | } 211 | Cursor cr1=dbaAdabter.getDb().rawQuery("select lang,server_name from config",null); 212 | cr1.moveToFirst(); 213 | Integer ind=cr1.getColumnIndex("lang"); 214 | language = cr1.getString(ind); 215 | static_path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/QuranStreaming/"; 216 | 217 | try 218 | { 219 | /*if (language.equalsIgnoreCase("EN")) 220 | setContentView(R.layout.main); 221 | else*/ 222 | setContentView(R.layout.main_ar); 223 | } 224 | catch (Exception e) { 225 | Toast.makeText(this,"6"+e.getMessage(),Toast.LENGTH_LONG).show(); 226 | } 227 | ind=cr1.getColumnIndex("server_name"); 228 | static_url= cr1.getString(ind); 229 | cr1.close(); 230 | dbaAdabter.close(); 231 | 232 | if((language.length()==0) || (language.equals( null))) 233 | { 234 | showSetupForm(); 235 | } 236 | context = this; 237 | alaMenuLayout = (View)findViewById(R.id.alaMenuLayout); 238 | lvSurah = (ListView) findViewById(R.id.lvSurah); 239 | lvSurah.setOnItemClickListener(new OnItemClickListener() { 240 | 241 | @Override 242 | public void onItemClick(AdapterView arg0, View arg1, int arg2, 243 | long arg3) { 244 | isRunning=false; 245 | final ImageView ivImg =(ImageView)arg0.findViewById(R.id.ivImg); 246 | View menuView = ((View)((View)((View)((View)((View)arg0.getParent()).getParent()).getParent()).getParent()).getParent()).findViewById(R.id.alaMenuLayout); 247 | if(menuView.findViewById(R.id.btnStopStream).getVisibility()==View.VISIBLE) 248 | { 249 | ivImg.setVisibility(View.INVISIBLE); 250 | QuranSteaming.stopStreamingAudio(arg0); 251 | return; 252 | } 253 | //v2.setVisibility(View.VISIBLE); 254 | //v2.findViewById(R.id.btnStopstream).setVisibility(View.VISIBLE); 255 | TextView tvSurahId =(TextView)arg0.findViewById(R.id.tvSurahId); 256 | QuranSteaming.selectedSurah = Long.parseLong(tvSurahId.getText().toString()); 257 | QuranSteaming.selectedSurahURL=getSurahURL(QuranSteaming.selectedSurah); 258 | playingMode= playMode.singleItem; 259 | Listen(ivImg,arg0); 260 | } 261 | }); 262 | // buttons on click listeners 263 | buttonsSetOnClickLister(); 264 | //spinner on item selected listener 265 | spinnerSetOnitemSelectLister(); 266 | 267 | fillCategoy(); 268 | addTelephoneListener(); 269 | isMediaPlayingThread(); 270 | //showHideMenu(); 271 | } 272 | private void addTelephoneListener() 273 | { 274 | TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 275 | // Create a new PhoneStateListener 276 | listener = new PhoneStateListener() { 277 | @Override 278 | public void onCallStateChanged(int state, String incomingNumber) { 279 | try{ 280 | switch (state) { 281 | case TelephonyManager.CALL_STATE_IDLE: 282 | 283 | if(isPausedDueToCall) 284 | { 285 | isPausedDueToCall = false; 286 | if(playingMode == playMode.singleItem) 287 | { 288 | mp.start(); 289 | findViewById(R.id.btnStartStream).setVisibility(View.INVISIBLE); 290 | findViewById(R.id.btnStopStream).setVisibility(View.VISIBLE); 291 | findViewById(R.id.alaMenuLayout).setVisibility(View.VISIBLE); 292 | } 293 | else 294 | { 295 | if(s!=null) 296 | s.continuePlaying(); 297 | } 298 | } 299 | break; 300 | case TelephonyManager.CALL_STATE_OFFHOOK: 301 | if(mp.isPlaying()) 302 | { 303 | isPausedDueToCall = true; 304 | stopStreamingAudio(findViewById(R.id.alaMenuLayout)); 305 | } 306 | break; 307 | case TelephonyManager.CALL_STATE_RINGING: 308 | if(mp.isPlaying()) 309 | { 310 | isPausedDueToCall = true; 311 | stopStreamingAudio(findViewById(R.id.alaMenuLayout)); 312 | } 313 | break; 314 | } 315 | } 316 | catch(Exception e) 317 | { 318 | e.printStackTrace(); 319 | } 320 | } 321 | }; 322 | tm.listen(listener, PhoneStateListener.LISTEN_CALL_STATE); 323 | } 324 | private void Listen(ImageView v,View v2) 325 | { 326 | QuranSteaming.startStreamingAudio(v,QuranSteaming.selectedSurahURL,v2); 327 | } 328 | @Override 329 | public boolean onCreateOptionsMenu(Menu menu) { 330 | try{ 331 | MenuInflater inflater = getMenuInflater(); 332 | inflater.inflate(R.menu.mainmenu, menu); 333 | return true; 334 | } 335 | catch(Exception ex) 336 | { 337 | Toast.makeText(this,"11"+ex.getMessage(),Toast.LENGTH_LONG).show(); 338 | return true; 339 | } 340 | } 341 | // This method is called once the menu is selected 342 | @Override 343 | public boolean onOptionsItemSelected(MenuItem item) { 344 | switch (item.getItemId()) { 345 | // We have only one menu option 346 | case R.id.iSetting: 347 | // Launch Preference activity 348 | Intent i = new Intent(QuranSteaming.this, setup.class); 349 | startActivity(i); 350 | break; 351 | case R.id.iQuit: 352 | quitApplication(); 353 | break; 354 | default: 355 | break; 356 | } 357 | return true; 358 | } 359 | void showSetupForm() 360 | { 361 | try 362 | { 363 | Intent i = new Intent(QuranSteaming.this, setup.class); 364 | startActivity(i); 365 | } 366 | catch(Exception ex) 367 | { 368 | Toast.makeText(QuranSteaming.this,ex.getMessage(),Toast.LENGTH_LONG).show(); 369 | } 370 | 371 | } 372 | private void fillCategoy() 373 | { 374 | ArrayAdapter adapter1; 375 | 376 | try 377 | { 378 | adapter1=ArrayAdapter.createFromResource(this,R.array.Category,android.R.layout.simple_spinner_item); 379 | tableColumns = new String [adapter1.getCount()]; 380 | for (int i=0;i0?spnCategory.getSelectedItemId():2 , "1"); 438 | } 439 | public void fillShaikh(long categoryId,String selectMode) 440 | { 441 | ArrayAdapter adapter1; 442 | String strTableColumns =""; 443 | try{ 444 | adapter1=ArrayAdapter.createFromResource(this,R.array.shaikh,android.R.layout.simple_spinner_item); 445 | tableColumns = new String [adapter1.getCount()]; 446 | for (int i=0;i adapter1=ArrayAdapter.createFromResource(this,R.array.shaikh,android.R.layout.simple_spinner_item); 509 | tableColumns = new String [adapter1.getCount()]; 510 | String strTableColumns =""; 511 | for (int i=0;itrue if the phone is connected 614 | */ 615 | public static boolean isConnected(Context context) 616 | { 617 | ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 618 | if (connectivity != null) 619 | { 620 | NetworkInfo[] info = connectivity.getAllNetworkInfo(); 621 | if (info != null) 622 | for (int i = 0; i < info.length; i++) 623 | if (info[i].getState() == NetworkInfo.State.CONNECTED) 624 | { 625 | return true; 626 | } 627 | 628 | } 629 | return false; 630 | } 631 | public static void stopStreamingAudio(View v) 632 | { 633 | if ((mp != null)) 634 | { 635 | 636 | v.findViewById(R.id.btnStopStream).setVisibility(View.INVISIBLE); 637 | v.findViewById(R.id.btnStartStream).setVisibility(View.VISIBLE); 638 | if(mp.isPlaying()) 639 | { 640 | mp.pause(); 641 | isPaused = true; 642 | } 643 | } 644 | } 645 | public void onDestroy(Bundle savedInstanceState) { 646 | mp.stop(); 647 | mp.release(); 648 | } 649 | public static void setLanguage(String lang) { 650 | QuranSteaming.language = lang; 651 | } 652 | public static String getLanguage() { 653 | return QuranSteaming.language; 654 | } 655 | public static void setSelectedSurah(Long surah) { 656 | QuranSteaming.selectedSurah = surah; 657 | } 658 | public static Long getSelectedSurah() { 659 | return QuranSteaming.selectedSurah; 660 | } 661 | public static void setSelectedShaikh(Long shaikh) { 662 | QuranSteaming.selectedSurah = shaikh; 663 | } 664 | public static Long getSelectedShaikh() { 665 | return QuranSteaming.selectedShaikh; 666 | } 667 | public void fillSurah(long ShaikhId) 668 | { 669 | Surahs = new ArrayList(); 670 | if (language.equalsIgnoreCase("EN")) 671 | { 672 | arrayAdapter = new ListAdapter(QuranSteaming.this, R.layout.listview,Surahs); 673 | } 674 | else 675 | { 676 | arrayAdapter = new ListAdapter(QuranSteaming.this, R.layout.listview_ar,Surahs); 677 | } 678 | lvSurah.setAdapter(arrayAdapter); 679 | lvSurah.setItemsCanFocus(false); 680 | lvSurah.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 681 | 682 | 683 | /*** 684 | * normal DB code 685 | */ 686 | ArrayAdapter adapter1; 687 | String strTableColumns =""; 688 | //lvSurah= getListView(); 689 | lvSurah.setCacheColorHint(0); 690 | 691 | try{ 692 | adapter1=ArrayAdapter.createFromResource(this,R.array.surah,android.R.layout.simple_list_item_1); 693 | tableColumns = new String [adapter1.getCount()]; 694 | for (int i=0;i0) 727 | { 728 | String colName=""; 729 | if (QuranSteaming.language.equalsIgnoreCase("EN")) 730 | colName ="surah_name_e"; 731 | else 732 | colName ="surah_name_a"; 733 | int nameInd =cr.getColumnIndex(colName); 734 | int idInd =cr.getColumnIndex("_id"); 735 | //int idIsChecked =cr.getColumnIndex("is_checked"); 736 | int idIsPlaying =cr.getColumnIndex("is_playing"); 737 | if(cr.moveToFirst()) 738 | { 739 | do 740 | { 741 | ProjectObject o=new ProjectObject(); 742 | o.surahName= ArabicUtilities.reshape(cr.getString(nameInd)); 743 | o.surahId= Integer.parseInt(cr.getString(idInd)); 744 | if((cr.getString(idIsPlaying) != null)&&(cr.getString(idIsPlaying).length() != 0)) 745 | o.isPlaying = true; 746 | //if((cr.getString(idIsChecked) != null)&&(cr.getString(idIsChecked).length() != 0)) 747 | o.isChecked = false; 748 | Surahs.add(o); 749 | }while(cr.moveToNext()); 750 | } 751 | arrayAdapter.notifyDataSetChanged(); 752 | } 753 | dbaAdabter.close(); 754 | } 755 | public static String getShaikhSurahID(String ShaikhId,String SurahId) 756 | { 757 | String ShaikhSurahId=""; 758 | 759 | Cursor cr=null; 760 | ArrayAdapter adapter1=ArrayAdapter.createFromResource(QuranSteaming.context,R.array.shaikhSurah,android.R.layout.two_line_list_item); 761 | String[] tableColumns = new String [adapter1.getCount()]; 762 | String strTableColumns =""; 763 | DBAdapter dbaAdabter= new DBAdapter(QuranSteaming.context); 764 | try 765 | { 766 | dbaAdabter.openDataBase(); 767 | } 768 | catch(Exception ex) 769 | { 770 | //Toast.makeText(this,"6"+ex.getMessage(),Toast.LENGTH_LONG).show(); 771 | } 772 | for (int i=0;i(); 877 | } 878 | handler.sendEmptyMessage(myHandlerAction.dismissDialog); 879 | if(DownloadProgress.totalSize!=0) 880 | { 881 | if(!DownloadProgress.isInUse) 882 | { 883 | try 884 | { 885 | Intent intent = new Intent(QuranSteaming.this,DownloadProgress.class); 886 | DownloadProgress.isInUse= true; 887 | startActivity(intent); 888 | } 889 | catch (Exception e) { 890 | e.printStackTrace(); 891 | } 892 | } 893 | for(int i=0;i 0 ) { 1002 | f1.write(buffer,0, len1); 1003 | DownloadProgress.downloaded.add(len1); 1004 | } 1005 | 1006 | f1.close(); 1007 | 1008 | /* Convert the Bytes read to a String. */ 1009 | Log.d("Muslim Bag", "download ready in" 1010 | + ((System.currentTimeMillis() - startTime) / 1000) 1011 | + " sec"); 1012 | 1013 | } catch (IOException e) { 1014 | Log.d("Muslim Bag", "Error: " + e); 1015 | } 1016 | } 1017 | public String getSurahURL(Long surahID) 1018 | { 1019 | Cursor cr=null; 1020 | String strSurahURL=""; 1021 | ArrayAdapter adapter1=ArrayAdapter.createFromResource(QuranSteaming.context,R.array.surah_url,android.R.layout.simple_spinner_item); 1022 | String[] tableColumns = new String [adapter1.getCount()]; 1023 | String strTableColumns =""; 1024 | DBAdapter dbaAdabter= new DBAdapter(QuranSteaming.context); 1025 | try 1026 | { 1027 | dbaAdabter.openDataBase(); 1028 | } 1029 | catch(Exception ex) 1030 | { 1031 | //Toast.makeText(this,"6"+ex.getMessage(),Toast.LENGTH_LONG).show(); 1032 | } 1033 | for (int i=0;i arg0, View arg1, int arg2, 1113 | long arg3) { 1114 | long newSelectedValue=arg3; 1115 | 1116 | if(selectedCategory!=newSelectedValue) 1117 | { 1118 | if(((View)arg1.getParent().getParent().getParent().getParent().getParent()).findViewById(R.id.alaMenuLayout).findViewById(R.id.btnStopStream).getVisibility()==View.INVISIBLE) 1119 | ((View)arg1.getParent().getParent().getParent().getParent().getParent()).findViewById(R.id.alaMenuLayout).setVisibility(View.INVISIBLE); 1120 | ((View)arg1.getParent().getParent().getParent().getParent().getParent()).findViewById(R.id.alaMenuLayout).findViewById(R.id.btnDownload).setVisibility(View.INVISIBLE); 1121 | fillShaikh(newSelectedValue, "1"); 1122 | selectedCategory = newSelectedValue; 1123 | } 1124 | } 1125 | 1126 | @Override 1127 | public void onNothingSelected(AdapterView arg0) { 1128 | 1129 | } 1130 | 1131 | }); 1132 | spnShaikh = (Spinner) findViewById(R.id.spnShaikh); 1133 | spnShaikh.setOnItemSelectedListener(new OnItemSelectedListener() { 1134 | @Override 1135 | public void onItemSelected(AdapterView arg0, View arg1, int arg2, 1136 | long arg3) { 1137 | long newSelectedValue=arg3; 1138 | 1139 | if(selectedShaikh!=newSelectedValue) 1140 | { 1141 | selectedCount = 0; 1142 | if(((View)arg1.getParent().getParent().getParent().getParent().getParent()).findViewById(R.id.alaMenuLayout).findViewById(R.id.btnStopStream).getVisibility()==View.INVISIBLE) 1143 | ((View)arg1.getParent().getParent().getParent().getParent().getParent()).findViewById(R.id.alaMenuLayout).setVisibility(View.INVISIBLE); 1144 | ((View)arg1.getParent().getParent().getParent().getParent().getParent()).findViewById(R.id.alaMenuLayout).findViewById(R.id.btnDownload).setVisibility(View.INVISIBLE); 1145 | selectedShaikh = newSelectedValue; 1146 | selectedShaikhURL = getShaikhURL(selectedShaikh); 1147 | fillSurah(selectedShaikh); 1148 | } 1149 | } 1150 | 1151 | @Override 1152 | public void onNothingSelected(AdapterView arg0) { 1153 | 1154 | } 1155 | 1156 | 1157 | 1158 | }); 1159 | } 1160 | private void buttonsSetOnClickLister() 1161 | { 1162 | btnStartStream = (ImageButton) findViewById(R.id.btnStartStream); 1163 | btnStartStream.setOnClickListener(new View.OnClickListener() { 1164 | public void onClick(View view) { 1165 | onPlayClick((View) view.getParent()); 1166 | }}); 1167 | 1168 | btnMoveToNext = (ImageButton) findViewById(R.id.btnPlayNext); 1169 | btnMoveToNext.setOnClickListener(new View.OnClickListener() { 1170 | public void onClick(View view) { 1171 | moveToNext(view); 1172 | }}); 1173 | 1174 | btnMoveToPrev = (ImageButton) findViewById(R.id.btnPlayPrevious); 1175 | btnMoveToPrev.setOnClickListener(new View.OnClickListener() { 1176 | public void onClick(View view) { 1177 | moveToPrev(view); 1178 | }}); 1179 | 1180 | stopStreamButton = (ImageButton) findViewById(R.id.btnStopStream); 1181 | stopStreamButton.setOnClickListener(new View.OnClickListener() { 1182 | public void onClick(View view) { 1183 | View v = (View)view.getParent(); 1184 | stopStreamingAudio(v); 1185 | onPauseClick(view); 1186 | }}); 1187 | 1188 | btnDownload = (ImageButton) findViewById(R.id.btnDownload); 1189 | btnDownload.setOnClickListener(new View.OnClickListener() { 1190 | 1191 | @Override 1192 | public void onClick(View v) { 1193 | download(lvSurah.getAdapter()); 1194 | }}); 1195 | 1196 | btnAddToPlaylist = (ImageButton) findViewById(R.id.btnAddToPlaylist); 1197 | btnAddToPlaylist.setOnClickListener(new View.OnClickListener() { 1198 | 1199 | @Override 1200 | public void onClick(View v) { 1201 | //download(lvSurah.getAdapter()); 1202 | }}); 1203 | } 1204 | @Override 1205 | protected void onDestroy() { 1206 | super.onDestroy(); 1207 | 1208 | try { 1209 | //api.removeListener(collectorListener); 1210 | s.isRunning= false; 1211 | stopService(new Intent(this, PlayingService.class)); 1212 | unbindService(mConnection); 1213 | } catch (Throwable t) { 1214 | // catch any issues, typical for destroy routines 1215 | // even if we failed to destroy something, we need to continue destroying 1216 | 1217 | } 1218 | 1219 | 1220 | } 1221 | private ServiceConnection mConnection = new ServiceConnection() { 1222 | @Override 1223 | public void onServiceConnected(ComponentName className, IBinder binder) { 1224 | s = ((PlayingService.MyBinder) binder).getService(); 1225 | handler.sendEmptyMessage(myHandlerAction.showPlayMenu); 1226 | Toast.makeText(QuranSteaming.this, "Connected", 1227 | Toast.LENGTH_SHORT).show(); 1228 | } 1229 | @Override 1230 | public void onServiceDisconnected(ComponentName className) { 1231 | s = null; 1232 | } 1233 | }; 1234 | void doBindService() { 1235 | bindService(new Intent(this, PlayingService.class), mConnection, 1236 | Context.BIND_AUTO_CREATE); 1237 | } 1238 | private void quitApplication() 1239 | { 1240 | finish(); 1241 | } 1242 | public playMode getPlayingMode() { 1243 | return playingMode; 1244 | } 1245 | public static void setPlayingMode(playMode playingMode) { 1246 | QuranSteaming.playingMode = playingMode; 1247 | } 1248 | private void isMediaPlayingThread() 1249 | { 1250 | new Thread(){ 1251 | @Override 1252 | public void run() { 1253 | try{ 1254 | while(true) 1255 | { 1256 | sleep(1000); 1257 | if((mp!=null)&&(!mp.isPlaying())&&(alaMenuLayout.getVisibility()==View.VISIBLE)) 1258 | { 1259 | sleep(6000); 1260 | if((!waitTillPlay)&&(!mp.isPlaying())&&(playingMode!=playMode.playlist)) 1261 | { 1262 | handler.sendEmptyMessage(myHandlerAction.getHideMenuBar()); 1263 | } 1264 | } 1265 | } 1266 | } 1267 | catch (Exception e) { 1268 | e.printStackTrace(); 1269 | } 1270 | }; 1271 | }.start(); 1272 | } 1273 | class Updater extends Thread { 1274 | private static final long DELAY = 3000; // three second 1275 | 1276 | public Updater() { 1277 | super("Updater"); 1278 | } 1279 | 1280 | @Override 1281 | public void run() { 1282 | while (isRunning) { 1283 | try { 1284 | if(mp==null) 1285 | { 1286 | mp = new MediaPlayer(); 1287 | } 1288 | if(!mp.isPlaying()) 1289 | { 1290 | plManger.isLooping = true; 1291 | String path = plManger.getNextItemURL(); 1292 | if(!path.startsWith("/")) 1293 | { 1294 | if(!isConnected(context)) 1295 | { 1296 | handler.sendEmptyMessage(myHandlerAction.showSorryMessage); 1297 | sleep(DELAY); 1298 | handler.sendEmptyMessage(myHandlerAction.dismissDialog); 1299 | } 1300 | } 1301 | if(path!= "") 1302 | { 1303 | handler.sendEmptyMessage(myHandlerAction.showWaitMessage); 1304 | mp.stop(); 1305 | mp.reset(); 1306 | mp.setDataSource(path); 1307 | mp.prepare(); 1308 | mp.start(); 1309 | handler.sendEmptyMessage(myHandlerAction.dismissDialog); 1310 | } 1311 | } 1312 | Thread.sleep(DELAY); 1313 | } 1314 | catch (Exception e) { 1315 | e.printStackTrace(); 1316 | isRunning = false; 1317 | } 1318 | } 1319 | } 1320 | } 1321 | 1322 | private boolean isMyServiceRunning() { 1323 | ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); 1324 | for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { 1325 | if ("com.android.QuranSteaming.PlayingService".equals(service.service.getClassName())) { 1326 | return true; 1327 | } 1328 | } 1329 | return false; 1330 | } 1331 | } -------------------------------------------------------------------------------- /src/com/android/QuranSteaming/setup.java: -------------------------------------------------------------------------------- 1 | package com.android.QuranSteaming; 2 | import android.app.Activity; 3 | import android.database.Cursor; 4 | import android.os.Bundle; 5 | import android.widget.ArrayAdapter; 6 | import android.widget.SimpleCursorAdapter; 7 | import android.widget.Spinner; 8 | import android.widget.TextView; 9 | import android.widget.Toast; 10 | 11 | public class setup extends Activity { 12 | DBAdapter dbaAdabter; 13 | String[] tableColumns; 14 | Spinner spnLang; 15 | Spinner spnSites; 16 | TextView tvLabel; 17 | /** Called when the activity is first created. */ 18 | @Override 19 | public void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | if (QuranSteaming.language.equalsIgnoreCase("EN")) 22 | setContentView(R.layout.setup); 23 | else 24 | setContentView(R.layout.setup_ar); 25 | spnLang = (Spinner)findViewById(R.id.spnLang); 26 | spnSites = (Spinner)findViewById(R.id.spnSites); 27 | tvLabel = (TextView)findViewById(R.id.tvLang); 28 | if(QuranSteaming.language.equalsIgnoreCase("EN")) 29 | tvLabel.setText(ArabicUtilities.reshape(getApplication().getString(R.string.tvLang))); 30 | else 31 | tvLabel.setText(ArabicUtilities.reshape(getApplication().getString(R.string.tvLang_ar))); 32 | dbaAdabter = new DBAdapter(getBaseContext()); 33 | fillSites(); 34 | } 35 | private void fillSites() 36 | { 37 | ArrayAdapter adapter1; 38 | 39 | try 40 | { 41 | adapter1=ArrayAdapter.createFromResource(this,R.array.Server,android.R.layout.simple_spinner_item); 42 | tableColumns = new String [adapter1.getCount()]; 43 | for (int i=0;i adapter1=ArrayAdapter.createFromResource(this,R.array.Server,android.R.layout.simple_spinner_item); 144 | tableColumns = new String [adapter1.getCount()]; 145 | String strTableColumns =""; 146 | for (int i=0;i