142 lines
3.7 KiB
Java
142 lines
3.7 KiB
Java
package com.mhalka.qurantranslationdisplay;
|
|
|
|
import com.mhalka.qurantranslationdisplay.VerticalMarqueeTextView.ScrollingStoppedListener;
|
|
|
|
import android.app.Activity;
|
|
import android.content.res.AssetManager;
|
|
import android.os.Bundle;
|
|
import android.text.method.ScrollingMovementMethod;
|
|
import android.util.DisplayMetrics;
|
|
import android.util.Log;
|
|
import android.view.animation.Animation;
|
|
import android.view.animation.LinearInterpolator;
|
|
import android.view.animation.TranslateAnimation;
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
/**
|
|
* An example full-screen activity that shows and hides the system UI (i.e.
|
|
* status bar and navigation/system bar) with user interaction.
|
|
*
|
|
* @see SystemUiHider
|
|
*/
|
|
public class ShowAyah extends Activity {
|
|
|
|
private static int NUMBER_OF_MILISECONDS_TO_READ_ONE_LINE = 2500;
|
|
private VerticalMarqueeTextView ayah;
|
|
private TextView chapterName;
|
|
int currentChapter=1;
|
|
int currentVerse=1;
|
|
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_show_ayah);
|
|
ayah = (VerticalMarqueeTextView) findViewById(R.id.ayah);
|
|
chapterName = (TextView) findViewById(R.id.chapter_name_verse_number);
|
|
ayah.setMovementMethod(new ScrollingMovementMethod());
|
|
ayah.pauseMarquee();
|
|
|
|
|
|
|
|
|
|
|
|
ayah.setPixelYOffSet(ayah.getMaxLines() * ayah.getLineHeight());
|
|
|
|
ayah.setOnScrollingStoppedListener(new ScrollingStoppedListener() {
|
|
|
|
@Override
|
|
public void scrollingStopped(VerticalMarqueeTextView v) {
|
|
nextAyah();
|
|
|
|
}
|
|
|
|
|
|
});
|
|
showAyah(currentChapter, currentVerse);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public void nextAyah() {
|
|
currentVerse++;
|
|
boolean verseExists = showAyah(currentChapter, currentVerse);
|
|
if (!verseExists) {
|
|
currentChapter++;
|
|
if(currentChapter > 114)currentChapter = 1;
|
|
currentVerse = 1;
|
|
showAyah(currentChapter, currentVerse);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
public boolean showAyah(int chapter, int verse ) {
|
|
|
|
|
|
|
|
try {
|
|
ayah.setText("");
|
|
ayah.scrollTo(0, 0);
|
|
AssetManager assetManager = getAssets();
|
|
QuranReader reader = new QuranReader(assetManager, "quran_content");
|
|
reader.setChapter(chapter);
|
|
String verseText = reader.getVerse(verse);
|
|
|
|
if(verseText.equals("")) return false;
|
|
// Start or restart the Marquee if paused.
|
|
|
|
|
|
ayah.setText(verseText);
|
|
chapterName.setText(reader.getChapterName() + " " + String.valueOf(chapter) + ":" + String.valueOf(verse));
|
|
int duration = ayah.getLineCount() * NUMBER_OF_MILISECONDS_TO_READ_ONE_LINE;
|
|
|
|
// let them reflect a bit on one liners ! :) (also solves a bug )
|
|
if(duration <= NUMBER_OF_MILISECONDS_TO_READ_ONE_LINE) duration = 2 * NUMBER_OF_MILISECONDS_TO_READ_ONE_LINE;
|
|
if(ayah.getLineCount() > ayah.getMaxLines()) duration = ayah.getMaxLines() * NUMBER_OF_MILISECONDS_TO_READ_ONE_LINE;
|
|
ayah.setDuration(duration);
|
|
if (ayah.isPaused()) {
|
|
ayah.resumeMarquee();
|
|
}
|
|
return true;
|
|
}
|
|
catch (Exception e) {
|
|
Log.d("SHOWAYAH",e.toString());
|
|
return false;
|
|
}
|
|
|
|
|
|
}
|
|
@Override
|
|
protected void onResume() {
|
|
|
|
// Start or restart the Marquee if paused.
|
|
if (ayah.isPaused()) {
|
|
ayah.resumeMarquee();
|
|
}
|
|
super.onResume();
|
|
}
|
|
|
|
@Override
|
|
protected void onPause() {
|
|
|
|
// Pause the Marquee when the Activity pauses.
|
|
ayah.pauseMarquee();
|
|
super.onPause();
|
|
}
|
|
|
|
@Override
|
|
protected void onDestroy() {
|
|
|
|
ayah.stopMarquee();
|
|
super.onDestroy();
|
|
}
|
|
|
|
}
|