<commit_before>package edu.agh.mindmap.activity

import scala.collection.mutable

import com.actionbarsherlock.app.SherlockFragmentActivity
import android.os.Bundle
import edu.agh.mindmap.R
import android.widget.{HorizontalScrollView, TabHost}
import android.support.v4.app.{Fragment, FragmentActivity}
import android.content.{ActivityNotFoundException, Intent, Context}
import android.view.View
import edu.agh.mindmap.fragment.MapListFragment
import scala.reflect.ClassTag
import com.michalrus.helper.ScalaActivity
import com.actionbarsherlock.view.{MenuItem, Menu}
import com.ipaulpro.afilechooser.utils.FileUtils
import android.app.Activity
import edu.agh.mindmap.model.MindMap

object MainActivity {
  val FileChooserRequestCode = 31337
}

class MainActivity extends SherlockFragmentActivity with ScalaActivity {

  lazy val tabHost = find[TabHost](R.id.tabhost)
  lazy val tabManager = new TabManager(this, tabHost, android.R.id.tabcontent, R.id.tab_scroll)

  override def onCreateOptionsMenu(menu: Menu) = {
    def add(id: Int, s: Int, icon: Int) =
      menu.add(Menu.NONE, id, Menu.NONE, s).
        setIcon(icon).
        setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)

    add(R.id.action_import, R.string.action_import, R.drawable.icon_import)
    add(R.id.action_create, R.string.action_create, R.drawable.icon_create)

    true
  }

  override def onOptionsItemSelected(item: MenuItem) = {
    item.getItemId match {
      case R.id.action_import => showImportDialog()
      case R.id.action_create => log("create")
      case _ =>
    }

    true
  }

  def showImportDialog() {
    val target = FileUtils.createGetContentIntent
    val intent = Intent.createChooser(target, getString(R.string.choose_xmind))
    try {
      startActivityForResult(intent, MainActivity.FileChooserRequestCode)
    } catch {
      case _: ActivityNotFoundException =>
    }
  }

  override def onActivityResult(request: Int, result: Int, data: Intent) {
    request match {
      case MainActivity.FileChooserRequestCode if result == Activity.RESULT_OK && data != null =>
        try {
          val file = FileUtils.getFile(data.getData)
          val map = MindMap.importFrom(file)
          // TODO: open a new tab with this map
        }
      case _ =>
    }
  }

  override def onCreate(bundle: Bundle) {
    super.onCreate(bundle)
    setContentView(R.layout.main)
    tabHost.setup()

    tabManager.addTab[MapListFragment]("all", "All maps")

    Option(bundle) foreach (b => {
      tabHost.setCurrentTabByTag(b.getString("tab"))<commit_msg>Call super.onActivityResult, too<commit_after>package edu.agh.mindmap.activity

import scala.collection.mutable

import com.actionbarsherlock.app.SherlockFragmentActivity
import android.os.Bundle
import edu.agh.mindmap.R
import android.widget.{HorizontalScrollView, TabHost}
import android.support.v4.app.{Fragment, FragmentActivity}
import android.content.{ActivityNotFoundException, Intent, Context}
import android.view.View
import edu.agh.mindmap.fragment.MapListFragment
import scala.reflect.ClassTag
import com.michalrus.helper.ScalaActivity
import com.actionbarsherlock.view.{MenuItem, Menu}
import com.ipaulpro.afilechooser.utils.FileUtils
import android.app.Activity
import edu.agh.mindmap.model.MindMap

object MainActivity {
  val FileChooserRequestCode = 31337
}

class MainActivity extends SherlockFragmentActivity with ScalaActivity {

  lazy val tabHost = find[TabHost](R.id.tabhost)
  lazy val tabManager = new TabManager(this, tabHost, android.R.id.tabcontent, R.id.tab_scroll)

  override def onCreateOptionsMenu(menu: Menu) = {
    def add(id: Int, s: Int, icon: Int) =
      menu.add(Menu.NONE, id, Menu.NONE, s).
        setIcon(icon).
        setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)

    add(R.id.action_import, R.string.action_import, R.drawable.icon_import)
    add(R.id.action_create, R.string.action_create, R.drawable.icon_create)

    true
  }

  override def onOptionsItemSelected(item: MenuItem) = {
    item.getItemId match {
      case R.id.action_import => showImportDialog()
      case R.id.action_create => log("create")
      case _ =>
    }

    true
  }

  def showImportDialog() {
    val target = FileUtils.createGetContentIntent
    val intent = Intent.createChooser(target, getString(R.string.choose_xmind))
    try {
      startActivityForResult(intent, MainActivity.FileChooserRequestCode)
    } catch {
      case _: ActivityNotFoundException =>
    }
  }

  override def onActivityResult(request: Int, result: Int, data: Intent) {
    request match {
      case MainActivity.FileChooserRequestCode if result == Activity.RESULT_OK && data != null =>
        try {
          val file = FileUtils.getFile(data.getData)
          val map = MindMap.importFrom(file)
          // TODO: open a new tab with this map
        }
      case _ =>
    }
    super.onActivityResult(request, result, data)
  }

  override def onCreate(bundle: Bundle) {
    super.onCreate(bundle)
    setContentView(R.layout.main)
    tabHost.setup()

    tabManager.addTab[MapListFragment]("all", "All maps")

    Option(bundle) foreach (b => {
      tabHost.setCurrentTabByTag(b.getString("tab"))
{'fraction_non_alphanumeric': 0.1011801122073902, 'fraction_numerical': 0.0023215322112594312, 'mean_word_length': 3.813780260707635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '3140164', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1589, 'n_words': 324}