package com.breadwallet.presenter.activities.intro;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

import com.breadwallet.R;
import com.breadwallet.presenter.activities.SetPinActivity;
import com.breadwallet.presenter.activities.settings.WebViewActivity;
import com.breadwallet.presenter.activities.util.ActivityUTILS;
import com.breadwallet.presenter.activities.util.BRActivity;
import com.breadwallet.presenter.interfaces.BRAuthCompletion;
import com.breadwallet.tools.animation.BRAnimator;
import com.breadwallet.tools.security.AuthManager;
import com.breadwallet.tools.security.PostAuthenticationProcessor;
import com.breadwallet.tools.util.BRConstants;
import com.platform.HTTPServer;

public class WriteDownActivity extends BRActivity {
    private static final String TAG = WriteDownActivity.class.getName();
    private Button writeButton;
    private ImageButton close;
    public static boolean appVisible = false;
    private static WriteDownActivity app;

    public static WriteDownActivity getApp() {
        return app;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_write_down);

        writeButton = (Button) findViewById(R.id.button_write_down);
        close = (ImageButton) findViewById(R.id.close_button);
        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                close();
            }
        });
        ImageButton faq = (ImageButton) findViewById(R.id.faq_button);
        faq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(WriteDownActivity.this, WebViewActivity.class);
                intent.putExtra("url", HTTPServer.URL_SUPPORT);
                intent.putExtra("articleId", BRConstants.paperPhrase);
                app.startActivity(intent);
                app.overridePendingTransition(R.anim.enter_from_bottom, R.anim.empty_300);
            }
        });
        writeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!BRAnimator.isClickAllowed()) return;
                AuthManager.getInstance().authPrompt(WriteDownActivity.this, null, "Please enter your PIN to continue.", true, new BRAuthCompletion() {
                    @Override
                    public void onComplete() {
                        PostAuthenticationProcessor.getInstance().onPhraseCheckAuth(WriteDownActivity.this, false);
                    }

                    @Override
                    public void onCancel() {

                    }
                });

            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        appVisible = true;
        app = this;
        ActivityUTILS.init(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        appVisible = false;
    }

    @Override
    public void onBackPressed() {
        Intent intent = new Intent(WriteDownActivity.this, SetPinActivity.class);
        startActivity(intent);
        overridePendingTransition(R.anim.enter_from_right, R.anim.exit_to_left);
        finish();

    }

    private void close() {
        BRAnimator.startBreadActivity(this, false);
        if (!isDestroyed()) finish();
        //additional code
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
    }

}

@@ -46,16 +46,81 @@
 intro;%0A%0A
+import android.app.Activity;%0Aimport android.app.ActivityManager;%0A
 import a
@@ -819,16 +819,63 @@
 stants;%0A
+import com.breadwallet.wallet.BRWalletManager;%0A
 import c
@@ -3345,110 +3345,101 @@
     
-Intent intent = new Intent(WriteDownActivity.this, SetPinActivity.class);%0A        startActivity(intent
+close();%0A%0A    %7D%0A%0A    private void close() %7B%0A        BRAnimator.startBreadActivity(this, false
 );%0A 
@@ -3482,24 +3482,15 @@
 nim.
-enter_from_right
+fade_up
 , R.
@@ -3506,117 +3506,14 @@
 _to_
-left);%0A        finish();%0A%0A    %7D%0A%0A    private void close() %7B%0A        BRAnimator.startBreadActivity(this, false
+bottom
 );%0A 

fix back button on paper key