<commit_before>package org.stepic.droid.ui.activities

import android.app.Activity
import android.content.Intent
import android.support.v4.app.Fragment
import android.view.MenuItem
import org.stepic.droid.base.SingleFragmentActivity
import org.stepic.droid.ui.fragments.CodePlaygroundFragment
import org.stepic.droid.ui.util.BackButtonHandler
import org.stepic.droid.ui.util.OnBackClickListener
import java.lang.ref.WeakReference

class CodePlaygroundActivity : SingleFragmentActivity(), BackButtonHandler {

    companion object {
        const val CODE_KEY = "code_key"
        const val LANG_KEY = "lang_key"

        fun intentForLaunch(callingActivity: Activity, code: String, lang: String): Intent {
            val intent = Intent(callingActivity, CodePlaygroundActivity::class.java)
            intent.putExtra(CODE_KEY, code)
            intent.putExtra(LANG_KEY, lang)
            return intent
        }
    }

    private var onBackClickListener: WeakReference<OnBackClickListener>? = null

    override fun createFragment(): Fragment = CodePlaygroundFragment.newInstance(intent.getStringExtra(CODE_KEY), intent.getStringExtra(LANG_KEY))

    override fun applyTransitionPrev() {
        //no-op
    }


    override fun setBackClickListener(onBackClickListener: OnBackClickListener) {
        this.onBackClickListener = WeakReference(onBackClickListener)
    }

    override fun removeBackClickListener(onBackClickListener: OnBackClickListener) {
        this.onBackClickListener = null
    }


    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        when (item?.itemId) {
            android.R.id.home -> {
                if (fragmentBackKeyIntercept()) {
                    return true
                } else {
                    finish();
                    return true<commit_msg>hide softKeyPad, when user finish code playground<commit_after>package org.stepic.droid.ui.activities

import android.app.Activity
import android.content.Intent
import android.support.v4.app.Fragment
import android.view.MenuItem
import org.stepic.droid.base.SingleFragmentActivity
import org.stepic.droid.ui.fragments.CodePlaygroundFragment
import org.stepic.droid.ui.util.BackButtonHandler
import org.stepic.droid.ui.util.OnBackClickListener
import java.lang.ref.WeakReference

class CodePlaygroundActivity : SingleFragmentActivity(), BackButtonHandler {

    companion object {
        const val CODE_KEY = "code_key"
        const val LANG_KEY = "lang_key"

        fun intentForLaunch(callingActivity: Activity, code: String, lang: String): Intent {
            val intent = Intent(callingActivity, CodePlaygroundActivity::class.java)
            intent.putExtra(CODE_KEY, code)
            intent.putExtra(LANG_KEY, lang)
            return intent
        }
    }

    private var onBackClickListener: WeakReference<OnBackClickListener>? = null

    override fun createFragment(): Fragment = CodePlaygroundFragment.newInstance(intent.getStringExtra(CODE_KEY), intent.getStringExtra(LANG_KEY))

    override fun applyTransitionPrev() {
        //no-op
    }


    override fun setBackClickListener(onBackClickListener: OnBackClickListener) {
        this.onBackClickListener = WeakReference(onBackClickListener)
    }

    override fun removeBackClickListener(onBackClickListener: OnBackClickListener) {
        this.onBackClickListener = null
    }

    override fun finish() {
        hideSoftKeypad()
        super.finish()
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        when (item?.itemId) {
            android.R.id.home -> {
                if (fragmentBackKeyIntercept()) {
                    return true
                } else {
                    finish()
                    return true
{'fraction_non_alphanumeric': 0.08011711471919085, 'fraction_numerical': 0.0005323396326856535, 'mean_word_length': 3.053937432578209, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7152684', 'n_tokens_mistral': 995, 'n_tokens_neox': 956, 'n_words': 200}