package com.androidsx.rateme;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.LayerDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.Toast;

import com.androidsx.libraryrateme.R;

public class DialogRateMe extends DialogFragment {

	private String appPackageName;
	private View mView;
	private View tView;
	private Button close;
	private RatingBar ratingBar;
	private LayerDrawable stars;
	private Button RateMe;
	private Button NoThanks;

	public static DialogRateMe newInstance(String appName) {
		DialogRateMe dialogo = new DialogRateMe();
		Bundle args = new Bundle();
		args.putString("name", appName);
		dialogo.setArguments(args);
		return dialogo;
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {

		appPackageName = getArguments().getString("name");
		setupUI();

		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

		stars.getDrawable(2).setColorFilter(Color.YELLOW,
				PorterDuff.Mode.SRC_ATOP);
		ratingBar
				.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {

					@Override
					public void onRatingChanged(RatingBar ratingBar,
							float rating, boolean fromUser) {
						Toast.makeText(getActivity(),
								"Puntuacion: " + String.valueOf(rating),
								Toast.LENGTH_SHORT).show();
						if (rating >= 4.0) {
							RateMe.setVisibility(View.VISIBLE);
							NoThanks.setVisibility(View.GONE);
						}else{
							NoThanks.setVisibility(View.VISIBLE);
							RateMe.setVisibility(View.GONE);
						}
					}
				});
		close.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				dismiss();

			}
		});
		return builder
				.setView(mView)
				.setCustomTitle(tView)
				.setCancelable(false)
				.create();

	}
	private void setupUI (){
		mView = getActivity().getLayoutInflater().inflate(R.layout.library,
				null);
		tView = getActivity().getLayoutInflater().inflate(R.layout.title, null);
		close = (Button) tView.findViewById(R.id.cerrar);
		RateMe = (Button) mView.findViewById(R.id.buttonRateMe);
		NoThanks = (Button) mView.findViewById(R.id.buttonThanks);
		

		ratingBar = (RatingBar) mView.findViewById(R.id.ratingBar);
		stars = (LayerDrawable) ratingBar.getProgressDrawable();
		
	}
}

@@ -118,16 +118,47 @@
 agment;%0A
+import android.content.Intent;%0A
 import a
@@ -260,24 +260,48 @@
 erDrawable;%0A
+import android.net.Uri;%0A
 import andro
@@ -1732,13 +1732,186 @@
 %09%09%09%09
-%7D
+%09RateMe.setOnClickListener(new OnClickListener() %7B%0A%09%09%09%09%09%09%09%09%0A%09%09%09%09%09%09%09%09@Override%0A%09%09%09%09%09%09%09%09public void onClick(View v) %7B%0A%09%09%09%09%09%09%09%09%09rateApp();%0A%09%09%09%09%09%09%09%09%7D%0A%09%09%09%09%09%09%09%7D);%0A%09%09%09%09%09%09%09%0A%09%09%09%09%09%09%7D 
 else
+ 
 %7B%0A%09%09
@@ -2156,21 +2156,16 @@
  builder
-%0A%09%09%09%09
 .setView
@@ -2167,29 +2167,24 @@
 tView(mView)
-%0A%09%09%09%09
 .setCustomTi
@@ -2219,21 +2219,16 @@
 e(false)
-%0A%09%09%09%09
 .create(
@@ -2234,16 +2234,17 @@
 ();%0A%0A%09%7D%0A
+%0A
 %09private
@@ -2260,11 +2260,11 @@
 upUI
- 
 ()
+ 
 %7B%0A%09%09
@@ -2588,19 +2588,16 @@
 Thanks);
-%0A%09%09
 %0A%0A%09%09rati
@@ -2715,12 +2715,360 @@
 ();%0A
-%09%09
 %0A%09%7D%0A
+%0A%09private void rateApp() %7B%0A%09%09try %7B%0A%09%09%09startActivity(new Intent(Intent.ACTION_VIEW,%0A%09%09%09%09%09Uri.parse(%22market://details?id=%22 + appPackageName)));%0A%09%09%7D catch (android.content.ActivityNotFoundException anfe) %7B%0A%09%09%09startActivity(new Intent(Intent.ACTION_VIEW,%0A%09%09%09%09%09Uri.parse(%22http://play.google.com/store/apps/details?id=%22%0A%09%09%09%09%09%09%09+ appPackageName)));%0A%09%09%7D%0A%09%7D%0A%0A
 %7D%0A

Add OnClick in button RateMe