<commit_before>package com.onegini.dialogs;

import org.apache.cordova.CordovaActivity;

import android.content.pm.ActivityInfo;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.StateListDrawable;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.onegini.model.PinConfigModel;
import com.onegini.util.DeviceUtil;
import com.onegini.util.JSONResourceReader;

public class PinScreenActivity extends CordovaActivity {

  // this const might be configurable in next sprints
  private static final int MAX_DIGITS = 5;

  private static final String HTML_CHAR_DOT = "&#9679;";
  private static final String HTML_CHAR_DASH = "&mdash;";

  private static boolean isCreatePinFlow;

  public static void setCreatePinFlow(final boolean isCreatePinFlow) {
    PinScreenActivity.isCreatePinFlow = isCreatePinFlow;
  }

  private int deleteKeyNormalResourceId;
  private final char[] pin = new char[MAX_DIGITS];

  private final TextView[] pinInputs = new TextView[MAX_DIGITS];
  private Resources resources;
  private String packageName;
  private PinConfigModel pinConfigModel;
  private Typeface customFontRegular;
  private Typeface customFontLight;
  private int cursorIndex = 0;

  private TextView titleTextView;
  private TextView pinForgottenTextView;
  private TextView errorTextView;
  private TextView pinLabelTextView;

  private Button deleteButton;
  private int logoResourceId;
  private int digitKeyNormalResourceId;
  private int digitKeyFocusedResourceId;

  private int deleteKeyFocusedResourceId;

  private static PinScreenActivity instance;

  public static PinScreenActivity getInstance() {
    return instance;
  }

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    resources = getResources();
    packageName = getPackageName();
    setContentView(resources.getIdentifier("activity_pin_screen", "layout", packageName));
    lockScreenOrientation();
    initialize();
    resetPin();
    instance = this;
  }

  @Override
  protected void onResume() {
    super.onResume();
    updateInputView();
  }

  @Override
  protected void onPause() {
    resetPin();
    super.onPause();
  }

  @Override
  protected void onNewIntent(final Intent intent) {
    setIntent(intent);
    updateTexts(intent);
    resetPin();
  }

  private void lockScreenOrientation() {
    if (DeviceUtil.isTablet(this)) {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
    else {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
  }

  private void initialize() {
    initConfig();
    initAssets();
    initLayout();
  }

  private void initConfig() {
    final int configurationPointer = resources.getIdentifier("pin_config", "raw", packageName);
    final JSONResourceReader jsonResourceReader = new JSONResourceReader();
    final String configString = jsonResourceReader.parse(resources, configurationPointer);
    pinConfigModel = jsonResourceReader.map(PinConfigModel.class, configString);
  }

  private void initAssets() {
    logoResourceId = resources.getIdentifier(
        getDrawableNameFromFileName(pinConfigModel.getLogoImage()),
        "drawable",
        packageName
    );

    digitKeyNormalResourceId = resources.getIdentifier(
        getDrawableNameFromFileName(pinConfigModel.getKeyNormalStateImage()),<commit_msg>MS-285 disable back button for  native pin screens<commit_after>package com.onegini.dialogs;

import org.apache.cordova.CordovaActivity;

import android.content.pm.ActivityInfo;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.StateListDrawable;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.onegini.model.PinConfigModel;
import com.onegini.util.DeviceUtil;
import com.onegini.util.JSONResourceReader;

public class PinScreenActivity extends CordovaActivity {

  // this const might be configurable in next sprints
  private static final int MAX_DIGITS = 5;

  private static final String HTML_CHAR_DOT = "&#9679;";
  private static final String HTML_CHAR_DASH = "&mdash;";

  private static boolean isCreatePinFlow;

  public static void setCreatePinFlow(final boolean isCreatePinFlow) {
    PinScreenActivity.isCreatePinFlow = isCreatePinFlow;
  }

  private int deleteKeyNormalResourceId;
  private final char[] pin = new char[MAX_DIGITS];

  private final TextView[] pinInputs = new TextView[MAX_DIGITS];
  private Resources resources;
  private String packageName;
  private PinConfigModel pinConfigModel;
  private Typeface customFontRegular;
  private Typeface customFontLight;
  private int cursorIndex = 0;

  private TextView titleTextView;
  private TextView pinForgottenTextView;
  private TextView errorTextView;
  private TextView pinLabelTextView;

  private Button deleteButton;
  private int logoResourceId;
  private int digitKeyNormalResourceId;
  private int digitKeyFocusedResourceId;

  private int deleteKeyFocusedResourceId;

  private static PinScreenActivity instance;

  public static PinScreenActivity getInstance() {
    return instance;
  }

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    resources = getResources();
    packageName = getPackageName();
    setContentView(resources.getIdentifier("activity_pin_screen", "layout", packageName));
    lockScreenOrientation();
    initialize();
    resetPin();
    instance = this;
  }

  @Override
  protected void onResume() {
    super.onResume();
    updateInputView();
  }

  @Override
  protected void onPause() {
    resetPin();
    super.onPause();
  }

  @Override
  protected void onNewIntent(final Intent intent) {
    setIntent(intent);
    updateTexts(intent);
    resetPin();
  }

  @Override
  public void onBackPressed() {
    // we don't want to be able to go back from the pin screen
    return;
  }

  private void lockScreenOrientation() {
    if (DeviceUtil.isTablet(this)) {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
    else {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
  }

  private void initialize() {
    initConfig();
    initAssets();
    initLayout();
  }

  private void initConfig() {
    final int configurationPointer = resources.getIdentifier("pin_config", "raw", packageName);
    final JSONResourceReader jsonResourceReader = new JSONResourceReader();
    final String configString = jsonResourceReader.parse(resources, configurationPointer);
    pinConfigModel = jsonResourceReader.map(PinConfigModel.class, configString);
  }

  private void initAssets() {
    logoResourceId = resources.getIdentifier(
        getDrawableNameFromFileName(pinConfigModel.getLogoImage()),
        "drawable",
        packageName
    );

    digitKeyNormalResourceId = resources.getIdentifier(
        getDrawableNameFromFileName(pinConfigModel.getKeyNormalStateImage()),
{'fraction_non_alphanumeric': 0.08076138681169273, 'fraction_numerical': 0.0020394289598912306, 'mean_word_length': 4.720062208398134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3835183', 'n_tokens_mistral': 2069, 'n_tokens_neox': 1994, 'n_words': 492}