package athary.audio.ency;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class NowPlayingActivity extends Activity {
	
	private TextView ind_txt;
	private TextView starttime;
    private TextView durationtime;
    private ImageButton fav_img;
    private ImageButton share_img;
    
	private final Handler handler = new Handler();

	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.photos_layout);
        
		initViews();
		Appearance();
		setListeners();
		setupHandler();
    }

	private void setupHandler() {
		handler.removeCallbacks(sendUpdatesToUI);
		handler.postDelayed(sendUpdatesToUI, 100); // 1 second
	}

	private Runnable sendUpdatesToUI = new Runnable() {

		public void run() {
			ind_txt.setText(IntroActivity.mytxt);
			starttime.setText(IntroActivity.stime);
			durationtime.setText(IntroActivity.etime);
			
			if (IntroActivity.fav == 1) fav_img.setImageResource(R.drawable.nstar2);
			else fav_img.setImageResource(R.drawable.nstar);
			
			handler.postDelayed(this, 100); // 2 seconds

		}
	};

	private void initViews() {

		ind_txt = (TextView) findViewById(R.id.ind_txt);
		starttime = (TextView) findViewById(R.id.txtstart);
		durationtime = (TextView) findViewById(R.id.txtduration);		
		fav_img = (ImageButton) findViewById(R.id.fav_img);	
		share_img = (ImageButton) findViewById(R.id.share_img);	
		fav_img.setImageResource(R.drawable.nstar);
	}

	private void Appearance() {
		int type = Typeface.NORMAL;
		Typeface tf = IntroActivity.tf; 
		Typeface tfdefault = Typeface.createFromAsset(getAssets(), "font2.ttf");
		float fontsize = IntroActivity.fontsize;
		ind_txt.setTypeface(tf,type);
		ind_txt.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontsize);
		starttime.setTypeface(tf,type);
		starttime.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontsize - 1);
		durationtime.setTypeface(tf,type);
		durationtime.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontsize - 1);
				
		// ind_txt.setText(Html.fromHtml(TXT) + "\n\n" + TAF);
		  
		
	}

	private void setListeners() {
		
		fav_img.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {

				if (IntroActivity.fav == 1) {
					IntroActivity.mDbHelper.updatebyFAV(IntroActivity.CODE, IntroActivity.seq, 0);
					IntroActivity.FAVS[IntroActivity.viewindex] = 0;
				}
				else if (IntroActivity.fav == 0) {
					IntroActivity.mDbHelper.updatebyFAV(IntroActivity.CODE, IntroActivity.seq, 1);
					IntroActivity.FAVS[IntroActivity.viewindex] = 1;
				}
				
			}
		});

		share_img.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {

				if (!IntroActivity.txt_for_shrae.equals("")) {
				Intent sendIntent_TXT = new Intent();
				sendIntent_TXT.setAction(Intent.ACTION_SEND);
				sendIntent_TXT.putExtra(Intent.EXTRA_TEXT, IntroActivity.txt_for_shrae);
				sendIntent_TXT.setType("text/plain");
				startActivity(sendIntent_TXT);
				}
				/*Intent sendIntent_TAF = new Intent();
				sendIntent_TAF.setAction(Intent.ACTION_SEND);
				//sendIntent_TAF.putExtra(Intent.EXTRA_TEXT, IntroActivity.taf_for_shrae);
				sendIntent_TAF.setType("text/plain");
				startActivity(sendIntent_TAF);
				*/
			}
		});
		
	}

	@Override
	protected void onResume() {
		super.onResume();
	}
	
	protected void onDestroy() {
		handler.removeCallbacks(sendUpdatesToUI);
		super.onDestroy();
	}


}
