// Path: app/src/main/java/com/reddyetwo/hashmypass/app/util/RandomPrivateKeyGenerator.java
// public class RandomPrivateKeyGenerator {
// 
//     private static final int[] SUBGROUPS_LENGTH = {8, 4, 4, 4, 12};
//     private static final char SUBGROUP_SEPARATOR = '-';
//     private static final String ALLOWED_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
// 
//     private RandomPrivateKeyGenerator() {
// 
//     }
// 
//     /**
//      * Generate a random private key
//      *
//      * @return the random private key
//      */
//     public static String generate() {
//         SecureRandom sr = new SecureRandom();
//         String key = "";
//         int allowedCharsLength = ALLOWED_CHARS.length();
// 
//         for (int i = 0; i < SUBGROUPS_LENGTH.length; i++) {
//             for (int j = 0; j < SUBGROUPS_LENGTH[i]; j++) {
//                 key = key + ALLOWED_CHARS.charAt(sr.nextInt(allowedCharsLength));
//             }
//             if (i < SUBGROUPS_LENGTH.length - 1) {
//                 key += SUBGROUP_SEPARATOR;
//             }
//         }
// 
//         return key;
//     }
// }


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import com.reddyetwo.hashmypass.app.R;
import com.reddyetwo.hashmypass.app.util.RandomPrivateKeyGenerator;
/*
 * Copyright 2014 Red Dye No. 2
 *
 * This file is part of Twik.
 *
 * Twik is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Twik is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Twik.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.reddyetwo.hashmypass.app.tutorial;



/**
 * Fragment containing the tutorial private key setup screen
 */
public class TutorialSetupFragment extends Fragment {

    private EditText mPrivateKeyText;
    private PrivateKeyChangedListener mPrivateKeyChangedListener;

    /**
     * Set the listener for private key changed events.
     *
     * @param listener the {@link com.reddyetwo.hashmypass.app.tutorial.TutorialSetupFragment.PrivateKeyChangedListener} instance
     */
    public void setPrivateKeyChangedListener(PrivateKeyChangedListener listener) {
        mPrivateKeyChangedListener = listener;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        ViewGroup rootView =
                (ViewGroup) inflater.inflate(R.layout.fragment_tutorial_setup, container, false);
        mPrivateKeyText = (EditText) rootView.findViewById(R.id.private_key_text);
        mPrivateKeyText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                // Do nothing
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // Nothing to do
            }

            @Override
            public void afterTextChanged(Editable s) {
                if (mPrivateKeyChangedListener != null) {
                    mPrivateKeyChangedListener
                            .onPrivateKeyChanged(mPrivateKeyText.getText().toString());
                }
            }
        });
// Path: app/src/main/java/com/reddyetwo/hashmypass/app/util/RandomPrivateKeyGenerator.java
// public class RandomPrivateKeyGenerator {
// 
//     private static final int[] SUBGROUPS_LENGTH = {8, 4, 4, 4, 12};
//     private static final char SUBGROUP_SEPARATOR = '-';
//     private static final String ALLOWED_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
// 
//     private RandomPrivateKeyGenerator() {
// 
//     }
// 
//     /**
//      * Generate a random private key
//      *
//      * @return the random private key
//      */
//     public static String generate() {
//         SecureRandom sr = new SecureRandom();
//         String key = "";
//         int allowedCharsLength = ALLOWED_CHARS.length();
// 
//         for (int i = 0; i < SUBGROUPS_LENGTH.length; i++) {
//             for (int j = 0; j < SUBGROUPS_LENGTH[i]; j++) {
//                 key = key + ALLOWED_CHARS.charAt(sr.nextInt(allowedCharsLength));
//             }
//             if (i < SUBGROUPS_LENGTH.length - 1) {
//                 key += SUBGROUP_SEPARATOR;
//             }
//         }
// 
//         return key;
//     }
// }


// Path: app/src/main/java/com/reddyetwo/hashmypass/app/tutorial/TutorialSetupFragment.java
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import com.reddyetwo.hashmypass.app.R;
import com.reddyetwo.hashmypass.app.util.RandomPrivateKeyGenerator;

/*
 * Copyright 2014 Red Dye No. 2
 *
 * This file is part of Twik.
 *
 * Twik is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Twik is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Twik.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.reddyetwo.hashmypass.app.tutorial;



/**
 * Fragment containing the tutorial private key setup screen
 */
public class TutorialSetupFragment extends Fragment {

    private EditText mPrivateKeyText;
    private PrivateKeyChangedListener mPrivateKeyChangedListener;

    /**
     * Set the listener for private key changed events.
     *
     * @param listener the {@link com.reddyetwo.hashmypass.app.tutorial.TutorialSetupFragment.PrivateKeyChangedListener} instance
     */
    public void setPrivateKeyChangedListener(PrivateKeyChangedListener listener) {
        mPrivateKeyChangedListener = listener;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        ViewGroup rootView =
                (ViewGroup) inflater.inflate(R.layout.fragment_tutorial_setup, container, false);
        mPrivateKeyText = (EditText) rootView.findViewById(R.id.private_key_text);
        mPrivateKeyText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                // Do nothing
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // Nothing to do
            }

            @Override
            public void afterTextChanged(Editable s) {
                if (mPrivateKeyChangedListener != null) {
                    mPrivateKeyChangedListener
                            .onPrivateKeyChanged(mPrivateKeyText.getText().toString());
                }
            }
        });
        mPrivateKeyText.setText(RandomPrivateKeyGenerator.generate());