├── README ├── .gitignore ├── assets └── quranstreamingDB ├── res ├── drawable-hdpi │ └── icon.png ├── drawable-ldpi │ └── icon.png ├── drawable-mdpi │ └── icon.png ├── values │ ├── color.xml │ ├── styles.xml │ └── strings.xml ├── menu │ └── mainmenu.xml └── layout │ ├── download_progress.xml │ ├── setup.xml │ ├── setup_ar.xml │ ├── listview.xml │ ├── listview_ar.xml │ └── main_ar.xml ├── src └── com │ └── android │ └── QuranSteaming │ ├── ProjectObject.java │ ├── PlaylistManager.java │ ├── PlayingService.java │ ├── DownloadProgress.java │ ├── setup.java │ ├── DBAdapter.java │ ├── ArabicUtilities.java │ ├── ListAdapter.java │ ├── ArabicReshaper.java │ └── QuranSteaming.java ├── default.properties └── AndroidManifest.xml /README: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .project 3 | .settings 4 | bin 5 | gen 6 | .DS_Store 7 | -------------------------------------------------------------------------------- /assets/quranstreamingDB: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hammady/Islamic-Streamer-Android/HEAD/assets/quranstreamingDB -------------------------------------------------------------------------------- /res/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hammady/Islamic-Streamer-Android/HEAD/res/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /res/drawable-ldpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hammady/Islamic-Streamer-Android/HEAD/res/drawable-ldpi/icon.png -------------------------------------------------------------------------------- /res/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hammady/Islamic-Streamer-Android/HEAD/res/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /res/values/color.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #b0b0ff 4 | -------------------------------------------------------------------------------- /res/menu/mainmenu.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #b0b0ff 4 | 5 | 8 | 13 | 14 | -------------------------------------------------------------------------------- /res/layout/download_progress.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 11 | 12 | 14 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /src/com/android/QuranSteaming/PlaylistManager.java: -------------------------------------------------------------------------------- 1 | package com.android.QuranSteaming; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import android.content.Context; 7 | import android.database.Cursor; 8 | import android.os.Environment; 9 | 10 | 11 | public class PlaylistManager { 12 | private final DBAdapter dbaAdabter= new DBAdapter(QuranSteaming.context); 13 | private static int playingIndex =0; 14 | private static String static_url=""; 15 | boolean isLooping= true; 16 | public int getPlayingIndex(int index) { 17 | if(index==0) 18 | return playingIndex; 19 | else 20 | { 21 | int prevIndex=playingIndex; 22 | Cursor cr1; 23 | if(index>0) 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/PlayingService.java: -------------------------------------------------------------------------------- 1 | package com.android.QuranSteaming; 2 | 3 | import android.app.Service; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.media.MediaPlayer; 7 | import android.net.ConnectivityManager; 8 | import android.net.NetworkInfo; 9 | import android.os.Binder; 10 | import android.os.IBinder; 11 | import android.util.Log; 12 | 13 | /** 14 | * @author Moamen 15 | * 16 | */ 17 | public class PlayingService extends Service{ 18 | private static final String TAG = PlayingService.class.getSimpleName(); 19 | private boolean isPlaying = false; 20 | private static MediaPlayer mp = new MediaPlayer(); 21 | PlaylistManager plManger = new PlaylistManager(); 22 | private Updater updater; 23 | public static QuranSteaming MAIN_ACTIVITY; 24 | private final IBinder mBinder = new MyBinder(); 25 | public boolean isRunning = false; 26 | public boolean isPaused = false; 27 | @Override 28 | public void onCreate() { 29 | super.onCreate(); 30 | Log.d(TAG, "Created"); 31 | updater = new Updater(); 32 | } 33 | @Override 34 | public void onStart(Intent intent, int startId) { 35 | super.onStart(intent, startId); 36 | Log.d(TAG, "Started"); 37 | if (!(updater==null)) { 38 | updater.start(); 39 | } 40 | } 41 | 42 | public static void setMainActivity(QuranSteaming activity) 43 | { 44 | MAIN_ACTIVITY = activity; 45 | } 46 | @Override 47 | public void onDestroy() { 48 | super.onDestroy(); 49 | if(mp!= null) 50 | { 51 | mp.stop(); 52 | mp.release(); 53 | } 54 | if(updater!= null) 55 | updater.interrupt(); 56 | updater = null; 57 | Log.d(TAG, "Destroyed"); 58 | } 59 | @Override 60 | public IBinder onBind(Intent intent) { 61 | return mBinder; 62 | } 63 | // ///// Updater Thread 64 | class Updater extends Thread { 65 | private static final long DELAY = 2000; // one second 66 | public Updater() { 67 | super("Updater"); 68 | } 69 | 70 | @Override 71 | public void run() { 72 | while (true) { 73 | if(isRunning){ 74 | try { 75 | if(!mp.isPlaying()) 76 | { 77 | if(isPaused) 78 | { 79 | mp.start(); 80 | } 81 | else 82 | { 83 | plManger.isLooping = true; 84 | String path = plManger.getNextItemURL(); 85 | if(!path.startsWith("/")) 86 | { 87 | if(!isConnected(MAIN_ACTIVITY.getBaseContext())) 88 | { 89 | QuranSteaming.handler.sendEmptyMessage(QuranSteaming.myHandlerAction.showSorryMessage); 90 | sleep(DELAY); 91 | QuranSteaming.handler.sendEmptyMessage(QuranSteaming.myHandlerAction.dismissDialog); 92 | } 93 | } 94 | if(path!= "") 95 | { 96 | QuranSteaming.handler.sendEmptyMessage(QuranSteaming.myHandlerAction.showWaitMessage); 97 | mp.stop(); 98 | mp.reset(); 99 | mp.setDataSource(path); 100 | mp.prepare(); 101 | mp.start(); 102 | QuranSteaming.handler.sendEmptyMessage(QuranSteaming.myHandlerAction.dismissDialog); 103 | } 104 | } 105 | } 106 | Thread.sleep(DELAY); 107 | } 108 | catch (Exception e) { 109 | e.printStackTrace(); 110 | isRunning = false; 111 | } 112 | }else if(mp.isPlaying()) 113 | { 114 | mp.pause(); 115 | isPaused = true; 116 | } 117 | } 118 | } 119 | } 120 | public boolean getIsPlaying() { 121 | return isPlaying; 122 | } 123 | public void setIsPlaying(boolean playing) { 124 | isPlaying = playing; 125 | } 126 | public class MyBinder extends Binder { 127 | PlayingService getService() { 128 | return PlayingService.this; 129 | } 130 | } 131 | public void moveToNext() 132 | { 133 | mp.stop(); 134 | } 135 | public void moveToPrev() 136 | { 137 | plManger.setPlayingIndex(plManger.getPlayingIndex(-1)); 138 | mp.stop(); 139 | } 140 | public static boolean isConnected(Context context) 141 | { 142 | ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 143 | if (connectivity != null) 144 | { 145 | NetworkInfo[] info = connectivity.getAllNetworkInfo(); 146 | if (info != null) 147 | for (int i = 0; i < info.length; i++) 148 | if (info[i].getState() == NetworkInfo.State.CONNECTED) 149 | { 150 | return true; 151 | } 152 | 153 | } 154 | return false; 155 | } 156 | public void continuePlaying() 157 | { 158 | plManger.setPlayingIndex(plManger.getPlayingIndex(0)); 159 | mp.stop(); 160 | } 161 | public void stopPlaying() 162 | { 163 | isRunning = false; 164 | isPaused = true; 165 | } 166 | 167 | } 168 | -------------------------------------------------------------------------------- /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/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;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/ArabicUtilities.java: -------------------------------------------------------------------------------- 1 | package com.android.QuranSteaming; 2 | 3 | import java.util.ArrayList; 4 | 5 | import android.content.Context; 6 | import android.graphics.Typeface; 7 | import android.view.Gravity; 8 | import android.widget.TextView; 9 | 10 | public class ArabicUtilities { 11 | 12 | /** 13 | * the path of teh fonts file must be under assets folder 14 | */ 15 | private static final String FONTS_LOCATION_PATH = "fonts/DejaVuSans.ttf"; 16 | 17 | 18 | 19 | /** 20 | * Helper function is to check if the character passed, is Arabic 21 | * @param target The Character to check Against 22 | * @return true if the Character is Arabic letter, otherwise returns false 23 | */ 24 | private static boolean isArabicCharacter(char target){ 25 | 26 | //Iterate over the 36 Characters in ARABIC_GLPHIES Matrix 27 | for(int i = 0; i < ArabicReshaper.ARABIC_GLPHIES.length;i++){ 28 | //Check if the target Character exist in ARABIC_GLPHIES Matrix 29 | if(ArabicReshaper.ARABIC_GLPHIES[i][0]==target) 30 | return true; 31 | } 32 | 33 | return false; 34 | } 35 | 36 | /** 37 | * Helper function to split Sentence By Space 38 | * @param sentence the Sentence to Split into Array of Words 39 | * @return Array Of words 40 | */ 41 | private static String[] getWords(String sentence){ 42 | if (sentence != null) { 43 | return sentence.split("\\s"); 44 | } else { 45 | return new String[0]; 46 | } 47 | } 48 | 49 | /** 50 | * Helper function to check if the word has Arabic Letters 51 | * @param word The to check Against 52 | * @return true if the word has Arabic letters, false otherwise 53 | */ 54 | public static boolean hasArabicLetters(String word){ 55 | 56 | //Iterate over the word to check all the word's letters 57 | 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;i 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){ 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 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 | } --------------------------------------------------------------------------------