<commit_before>package com.mapswithme.maps.bookmarks;

import android.content.Context;
import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
import android.text.Editable;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.HeaderViewListAdapter;
import android.widget.ImageButton;
import android.widget.TextView;

import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.data.Bookmark;
import com.mapswithme.maps.bookmarks.data.ParcelablePoint;
import com.mapswithme.util.statistics.Statistics;

public class ChooseBookmarkCategoryActivity extends AbstractBookmarkCategoryActivity
{
  private FooterHandler m_handler;

  private Bookmark getBookmarkFromIntent()
  {
    // Note that Point result from the intent is actually a pair
    // of (category index, bookmark index in category).
    final Point cab = ((ParcelablePoint) getIntent().getParcelableExtra(BookmarkActivity.PIN)).getPoint();
    return mManager.getBookmark(cab.x, cab.y);
  }

  @Override
  protected ChooseBookmarkCategoryAdapter getAdapter()
  {
    return (ChooseBookmarkCategoryAdapter) ((HeaderViewListAdapter) getListView().getAdapter()).getWrappedAdapter();
  }

  @Override
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);

    setListAdapter(new ChooseBookmarkCategoryAdapter(this, getIntent().getIntExtra(BookmarkActivity.PIN_SET, 0)));

    m_handler = new FooterHandler();
    getListView().setOnItemClickListener(new OnItemClickListener()
    {
      @Override
      public void onItemClick(AdapterView<?> parent, View view, int position, long id)
      {
        m_handler.switchToAddButton();
        getAdapter().chooseItem(position);

        final Bookmark bmk = getBookmarkFromIntent();
        bmk.setCategoryId(position);
        getIntent().putExtra(BookmarkActivity.PIN,
            new ParcelablePoint(bmk.getCategoryId(), bmk.getBookmarkId()));

        onBackPressed();
      }
    });

    registerForContextMenu(getListView());
  }

  @Override
  public void onBackPressed()
  {
    m_handler.createCategoryIfNeeded();

    setResult(RESULT_OK, new Intent().putExtra(BookmarkActivity.PIN, getIntent().getParcelableExtra(BookmarkActivity.PIN)));

    super.onBackPressed();
  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data)
  {
    if (resultCode == RESULT_OK)
    {
      getAdapter().chooseItem(data.getIntExtra(BookmarkActivity.PIN_SET, 0));

      getIntent().putExtra(BookmarkActivity.PIN, data.getParcelableExtra(BookmarkActivity.PIN));
    }<commit_msg>[android] Fixed Category selection on Android < 3.<commit_after>package com.mapswithme.maps.bookmarks;

import android.content.Context;
import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
import android.text.Editable;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.HeaderViewListAdapter;
import android.widget.ImageButton;
import android.widget.TextView;

import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.data.Bookmark;
import com.mapswithme.maps.bookmarks.data.ParcelablePoint;
import com.mapswithme.util.statistics.Statistics;

public class ChooseBookmarkCategoryActivity extends AbstractBookmarkCategoryActivity
{
  private FooterHandler m_handler;

  private Bookmark getBookmarkFromIntent()
  {
    // Note that Point result from the intent is actually a pair
    // of (category index, bookmark index in category).
    final Point cab = ((ParcelablePoint) getIntent().getParcelableExtra(BookmarkActivity.PIN)).getPoint();
    return mManager.getBookmark(cab.x, cab.y);
  }

  @Override
  protected ChooseBookmarkCategoryAdapter getAdapter()
  {
    return (ChooseBookmarkCategoryAdapter) ((HeaderViewListAdapter) getListView().getAdapter()).getWrappedAdapter();
  }

  @Override
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);

    m_handler = new FooterHandler();
    getListView().setOnItemClickListener(new OnItemClickListener()
    {
      @Override
      public void onItemClick(AdapterView<?> parent, View view, int position, long id)
      {
        m_handler.switchToAddButton();
        getAdapter().chooseItem(position);

        final Bookmark bmk = getBookmarkFromIntent();
        bmk.setCategoryId(position);
        getIntent().putExtra(BookmarkActivity.PIN,
            new ParcelablePoint(bmk.getCategoryId(), bmk.getBookmarkId()));

        onBackPressed();
      }
    });

    // Set adapter only after FooterHandler is initialized and added into layout.
    setListAdapter(new ChooseBookmarkCategoryAdapter(this, getIntent().getIntExtra(BookmarkActivity.PIN_SET, 0)));

    registerForContextMenu(getListView());
  }

  @Override
  public void onBackPressed()
  {
    m_handler.createCategoryIfNeeded();

    setResult(RESULT_OK, new Intent().putExtra(BookmarkActivity.PIN, getIntent().getParcelableExtra(BookmarkActivity.PIN)));

    super.onBackPressed();
  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data)
  {
    if (resultCode == RESULT_OK)
    {
      getAdapter().chooseItem(data.getIntExtra(BookmarkActivity.PIN_SET, 0));

      getIntent().putExtra(BookmarkActivity.PIN, data.getParcelableExtra(BookmarkActivity.PIN));
    }
{'fraction_non_alphanumeric': 0.10025273799494525, 'fraction_numerical': 0.0008424599831508003, 'mean_word_length': 4.865612648221344, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, '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': '1091698', 'n_tokens_mistral': 1713, 'n_tokens_neox': 1654, 'n_words': 325}