package findyourfate.com.porutham;


import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

import android.net.Uri;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

public class tamilsample1 extends ListActivity {
	ImageView image;
	protected TextView str;
	protected SQLiteDatabase DB;
	protected Cursor cursor;
	protected ListAdapter adapter;

	LinearLayout main_container;
	TextView btit, title;
	String tamilbstar;
	TextView one, zero;
	TextView gstar, a1, b1, c1, d1, e1, f1, g1, h1, i1, j1, scr, rmk, spec;
	TextView ltit, ltit1, dinam, ganam, maken, srideep, yoni, rasi, rasiathi, vasiyam, rajju, nadi, scr1, scr2, rmk2,
			grad;

	@SuppressLint("NewApi")
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		String userAgent = new WebView(tamilsample1.this).getSettings().getUserAgentString();
		if (userAgent.contains("Mobile")) {
			setContentView(R.layout.tamiltable1);
		} else {
			setContentView(R.layout.tabtamiltable1);
		}

		FirebaseDatabase database = FirebaseDatabase.getInstance();
		DatabaseReference ref = database.getReference("Description");
		ref.setValue("Description");

		DB = (new DBHelper(this)).getWritableDatabase();
		str = (TextView) findViewById(R.id.textView1);
		btit = (TextView) findViewById(R.id.textView12);
		title = (TextView) findViewById(R.id.textView3);
		gstar = (TextView) findViewById(R.id.gs);

		a1 = (TextView) findViewById(R.id.a);
		b1 = (TextView) findViewById(R.id.b);
		c1 = (TextView) findViewById(R.id.c);
		d1 = (TextView) findViewById(R.id.d);
		e1 = (TextView) findViewById(R.id.e);
		f1 = (TextView) findViewById(R.id.f);
		g1 = (TextView) findViewById(R.id.g);
		h1 = (TextView) findViewById(R.id.h);
		i1 = (TextView) findViewById(R.id.i);
		j1 = (TextView) findViewById(R.id.j);
		scr = (TextView) findViewById(R.id.sco);
		rmk = (TextView) findViewById(R.id.mark);
		spec = (TextView) findViewById(R.id.spc);

		ltit = (TextView) findViewById(R.id.textView111);
		ltit1 = (TextView) findViewById(R.id.textView22);
		dinam = (TextView) findViewById(R.id.a2);
		ganam = (TextView) findViewById(R.id.b2);
		maken = (TextView) findViewById(R.id.c2);
		srideep = (TextView) findViewById(R.id.d2);
		yoni = (TextView) findViewById(R.id.e2);
		rasi = (TextView) findViewById(R.id.f2);
		rasiathi = (TextView) findViewById(R.id.g2);
		vasiyam = (TextView) findViewById(R.id.h2);
		rajju = (TextView) findViewById(R.id.i2);
		nadi = (TextView) findViewById(R.id.j2);

		one = (TextView) findViewById(R.id.one);
		zero = (TextView) findViewById(R.id.zero);
		scr1 = (TextView) findViewById(R.id.score);
		scr2 = (TextView) findViewById(R.id.score1);
		rmk2 = (TextView) findViewById(R.id.remark1);
		grad = (TextView) findViewById(R.id.grade1);

		Typeface fontface = Typeface.createFromAsset(getAssets(), "fonts/Bamini.ttf");

		btit.setTypeface(fontface, Typeface.BOLD);
		String tamilString2 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "ஆண் நட்சத்திரம் :-");
		btit.setText(tamilString2);

		title.setTypeface(fontface, Typeface.BOLD);
		String tamil2 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "10 பொருத்தம் - முடிவுகள்");
		title.setText(tamil2);

		gstar.setTypeface(fontface, Typeface.BOLD);
		String tamil11 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "பெண் நட்சத்திரம்");
		gstar.setText(tamil11);

		scr.setTypeface(fontface, Typeface.BOLD);
		String tamil12 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "மொத்தம்");
		scr.setText(tamil12);

		rmk.setTypeface(fontface, Typeface.BOLD);
		String tamil13 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "பொருத்தம்");
		rmk.setText(tamil13);

		spec.setTypeface(fontface, Typeface.BOLD);
		String tamil14 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "சிறப்பு");
		spec.setText(tamil14);

		ltit.setTypeface(fontface, Typeface.BOLD);
		String tamil15 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "குறிப்பு");
		ltit.setText(tamil15);

		ltit1.setTypeface(fontface, Typeface.BOLD);
		String tamil16 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "குறிப்பு");
		ltit1.setText(tamil16);

		dinam.setTypeface(fontface, Typeface.BOLD);
		String tamil17 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "தினம்");
		dinam.setText(tamil17);

		ganam.setTypeface(fontface, Typeface.BOLD);
		String tamil18 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "கணம்");
		ganam.setText(tamil18);

		maken.setTypeface(fontface, Typeface.BOLD);
		String tamil19 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "மகேந்திரம்");
		maken.setText(tamil19);

		srideep.setTypeface(fontface, Typeface.BOLD);
		String tamil20 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "ஸ்ரீ தீர்க்கம்");
		srideep.setText(tamil20);

		yoni.setTypeface(fontface, Typeface.BOLD);
		String tamil21 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "யோனி");
		yoni.setText(tamil21);

		rasi.setTypeface(fontface, Typeface.BOLD);
		String tamil22 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "ராசி");
		rasi.setText(tamil22);

		rasiathi.setTypeface(fontface, Typeface.BOLD);
		String tamil23 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "ராசி அதிபதி");
		rasiathi.setText(tamil23);

		vasiyam.setTypeface(fontface, Typeface.BOLD);
		String tamil24 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "வசியம்");
		vasiyam.setText(tamil24);

		rajju.setTypeface(fontface, Typeface.BOLD);
		String tamil25 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "ரஜ்ஜு");
		rajju.setText(tamil25);

		nadi.setTypeface(fontface, Typeface.BOLD);
		String tamil26 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "நாடி");
		nadi.setText(tamil26);

		one.setTypeface(fontface, Typeface.BOLD);
		String tamil27 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "பொருத்தம்");
		one.setText(tamil27);

		zero.setTypeface(fontface, Typeface.BOLD);
		String tamil28 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "பொருத்தம் இல்லை");
		zero.setText(tamil28);

		scr1.setTypeface(fontface, Typeface.BOLD);
		String tamil30 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "மொத்தம்");
		scr1.setText(tamil30);

		scr2.setTypeface(fontface, Typeface.BOLD);
		String tamil29 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "மொத்த பொருத்தம் ");
		scr2.setText(tamil29);

		rmk2.setTypeface(fontface, Typeface.BOLD);
		String tamil31 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "பொருத்தம்");
		rmk2.setText(tamil31);

		grad.setTypeface(fontface, Typeface.BOLD);
		String tamil32 = TamilUtil.convertToTamil(TamilUtil.BAMINI, "மொத்தம்");
		grad.setText(tamil32);

		Bundle bundle = getIntent().getExtras();
		String Starname = bundle.getString("Star");
		tamilbstar = bundle.getString("Tamilstar");
		str.setText(Starname);
		// Toast.makeText(tamilsample1.this,""+Starname, Toast.LENGTH_LONG).show();

		/*
		 * LayoutInflater inflater =
		 * (LayoutInflater)tamilsample1.this.getSystemService(Context.
		 * LAYOUT_INFLATER_SERVICE);
		 * View vi = inflater.inflate(R.layout.table1, null); //log.xml is your file.
		 * TextView tv = (TextView)vi.findViewById(R.id.dbgirlstar);
		 * tv.setTypeface(fontface);
		 */

		if (userAgent.contains("Mobile")) {

			cursor = DB.rawQuery(
					"SELECT _id, Girlstartamil, Dhinam,Ganam,Makendiram, Deerkam,Yoni,Rasi,Athipathi,Vasiyam,Rajju,Naadi,Score,tamilremrk,tamilspec FROM poo1 WHERE Boystartamil LIKE ?",
					new String[] { "%" + str.getText().toString() + "%" });
			adapter = new SimpleCursorAdapter(
					this,
					R.layout.tamiltable2,
					cursor,
					new String[] { "Girlstartamil", "Dhinam", "Ganam", "Makendiram", "Deerkam", "Yoni", "Rasi",
							"Athipathi", "Vasiyam", "Rajju", "Naadi", "Score", "tamilremrk", "tamilspec" },
					new int[] { R.id.dbgirlstar, R.id.dbdhinam, R.id.dbganam, R.id.dbmakendiram, R.id.dbdeerkam,
							R.id.dbyoni, R.id.dbrasi, R.id.dbathipathu, R.id.dbvasiyam, R.id.dbrajju, R.id.dbnaadi,
							R.id.dbscore, R.id.dbrmk, R.id.dbspecial });
			setListAdapter(adapter);
		} else {
			cursor = DB.rawQuery(
					"SELECT _id, Girlstartamil, Dhinam,Ganam,Makendiram, Deerkam,Yoni,Rasi,Athipathi,Vasiyam,Rajju,Naadi,Score,tamilremrk,tamilspec FROM poo1 WHERE Boystartamil LIKE ?",
					new String[] { "%" + str.getText().toString() + "%" });
			adapter = new SimpleCursorAdapter(
					this,
					R.layout.tabtamiltable2,
					cursor,
					new String[] { "Girlstartamil", "Dhinam", "Ganam", "Makendiram", "Deerkam", "Yoni", "Rasi",
							"Athipathi", "Vasiyam", "Rajju", "Naadi", "Score", "tamilremrk", "tamilspec" },
					new int[] { R.id.dbgirlstar, R.id.dbdhinam, R.id.dbganam, R.id.dbmakendiram, R.id.dbdeerkam,
							R.id.dbyoni, R.id.dbrasi, R.id.dbathipathu, R.id.dbvasiyam, R.id.dbrajju, R.id.dbnaadi,
							R.id.dbscore, R.id.dbrmk, R.id.dbspecial });
			setListAdapter(adapter);
		}

		ActionBar ab = getActionBar();
		if (ab != null) {
			ab.setDisplayHomeAsUpEnabled(true);
			ab.setHomeButtonEnabled(true);
		}
		str.setTypeface(fontface);
		str.setText(tamilbstar);

	}

	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater menuInflater = getMenuInflater();
		menuInflater.inflate(R.menu.activity_main, menu);
		MenuItem item = menu.findItem(R.id.cfont);
		item.setVisible(false);
		return true;
	}

	public boolean onOptionsItemSelected(MenuItem item) {
		int itemId = item.getItemId();

		if (itemId == android.R.id.home) {
			Intent int_abt = new Intent(this, index.class);
			int_abt.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(int_abt);
			return true;
		}
		else if (itemId == R.id.claculator) {
			Intent icon_calc = new Intent(this, poruthamcalculator.class);
			icon_calc.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(icon_calc);
			return true;
		}
		else if (itemId == R.id.Nakshatra) {
			Intent icon_find = new Intent(this, findnakshatra.class);
			icon_find.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(icon_find);
			return true;
		}
		else if (itemId == R.id.guru) {
			AlertDialog.Builder alt_compat = new AlertDialog.Builder(this);
			String desc = "App to find out when Guru Peyarchi or Jupiter transit takes place.";
			alt_compat.setTitle("Guru Peyarchi");
			alt_compat.setMessage(desc)
					.setCancelable(false)
					.setPositiveButton("Later", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int id) {
							dialog.cancel();
						}
					})
					.setNegativeButton("Never/Already", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int id) {
							dialog.cancel();
						}
					})
					.setNeutralButton("Open", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int id) {
							Intent browserIntent = new Intent(Intent.ACTION_VIEW,
									Uri.parse("market://details?id=findyourfate.com.gurupeyarchi"));
							startActivity(browserIntent);
						}
					});
			AlertDialog alert = alt_compat.create();
			alert.show();
			return true;
		}
		else if (itemId == R.id.icon_exit) {
			AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setMessage("Are you sure you want to leave this App.")
					.setCancelable(false)
					.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int id) {
							Intent intent = new Intent(Intent.ACTION_MAIN);
							intent.addCategory(Intent.CATEGORY_HOME);
							intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
							startActivity(intent);
						}
					})
					.setNegativeButton("No", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int id) {
							dialog.cancel();
						}
					});
			AlertDialog alert1 = builder.create();
			alert1.setTitle("Close App.");
			alert1.setIcon(R.drawable.alert);
			alert1.show();
			return true;
		}
		else if (itemId == R.id.share) {
			Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
			emailIntent.setType("text/plain");
			emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "10 Porutham by findyourfate.com");
			emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
					"Hi, I would like to suggest this 10 Porutham App to you. Click this link to download the app http://goo.gl/38FZui"
							+ "\n\n" + " Regards");
			startActivity(Intent.createChooser(emailIntent, "Share using"));
			return true;
		}
		else {
			return super.onOptionsItemSelected(item);
		}
	}

}