package com.insidesecure.drm.android.reference.activities;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.Toast;
import com.insidesecure.drm.android.reference.Constants;

import com.insidesecure.drm.android.reference.xoplayer.R;

public class EulaActivity extends Activity
{
    private static final String TAG = "EulaActivity";
    public WebView mWebView;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {

        String eulaURL = "file://" + Constants.CONFIGURATION_CDESC_PATH + "eula-2013-02-21.htm";

        super.onCreate(savedInstanceState);
        setContentView(R.layout.eula);

        final Toast toast = Toast.makeText(this, "Scroll-down to approve the END-USER LICENSE AGREEMENT.", 10000);
        toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 140);
        toast.show();

        final SharedPreferences sharedPreferences = getSharedPreferences(Constants.PREFERENCES_FILENAME, Context.MODE_PRIVATE);
        final SharedPreferences.Editor editor = sharedPreferences.edit();

        //agree button
        Button button = (Button) findViewById(R.id.button_accept_eula);
        button.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(final View view)
            {
                //store value
                editor.putBoolean(Constants.PREFERENCES_EULA_ACCEPTED, true);
                editor.commit();

                //return
                setResult(1, null);
                finish();
            }
        });

        mWebView = (WebView) findViewById(R.id.browser_view);
        mWebView.clearCache(true);

        mWebView.loadUrl(eulaURL);
    }

    @Override
    public void onBackPressed()
    {
        Log.e(TAG, "on back pressed");
    }
}
