<commit_before>package com.example.knitknit;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuInflater;
import android.view.ViewGroup;

public class CountingLand extends Activity {
    private static final String TAG = "knitknit-CountingLand";
    public static Counter selectedCounter = null;

    private DataWrangler mDataWrangler;
    private Project mProject;
    private ActionMode mActionMode;

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

        getActionBar().setDisplayHomeAsUpEnabled(true);

        // Get projectID from savedInstanceState
        Long projectID = null;
        projectID = (savedInstanceState == null ?
                     null :
                     (Long) savedInstanceState.getSerializable(DataWrangler.PROJECT_KEY_ID));

        // If we still don't have projectID, get it from intent extras
        if (projectID == null) {
            Bundle extras = getIntent().getExtras();
            projectID = (extras != null ?
                         extras.getLong(DataWrangler.PROJECT_KEY_ID) :
                         null);
        }

        if (projectID == null) {
            Log.w(TAG, "projectID is null");
        }
        else{ 
            Log.w(TAG, "projectID: " + projectID);
        }

        // Load the project
        mDataWrangler = new DataWrangler(this);
        mDataWrangler.open();
        mProject = mDataWrangler.retrieveProject(projectID);
        mProject.setActivity(this);

        // Update the dateOpened on the project
        mDataWrangler.touchProject(mProject);

        // DEBUG
        Log.w(TAG, "this project has " + mProject.getCounters().size() + " counters");

        // Set the action bar title to the name of the project
        getActionBar().setTitle(mProject.getName());

        // Attach the project's view to our view
        ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
        mProject.inflate(root, getResources().getConfiguration().orientation);
        root.addView(mProject.getWrapper());
    }


    // Lifecycle Management Methods
    //@Override
    //protected void onDestroy() {
    //    super.onDestroy();

    //    mDataWrangler.close();
    //}

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

        mDataWrangler.saveProject(mProject);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        Log.w(TAG, "in onWindowFocusChanged()");
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            mProject.refreshViews();
        }
    }


    // Options Menu (Action Bar) Methods
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.countingland, menu);

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
            case android.R.id.home:
                Intent intent = new Intent(this, ProjectList.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                return true;
            case R.id.new_counter:
                // Add a new counter to the database
                long id = mDataWrangler.createCounter(mProject.getId());

                // Retrieve a counter object for the new counter
                Counter counter = mDataWrangler.retrieveCounter(id);

                // Add the counter object to the project
                mProject.addCounter(counter);
                mProject.refreshViews();
                return true;
            default:
                return false;
        }
    }


    // Other Methods
    public Project getProject() {
        return mProject;
    }

    public static boolean getZeroMode() {
        return false;
    }

    public void startActionModeForCounter(Counter counter) {
        if (mActionMode == null) {
            // Tell the ProjectWrapper to ignore touch events while we are in action mode
            ((ProjectWrapper) findViewById(R.id.project_wrapper)).setRespondToTouch(false);

            mActionMode = startActionMode(mActionModeCallback);
            mActionMode.setTag(counter);

            // Highlight thte selected counter
            counter.getWrapper().setSelected(true);
            counter.refreshViews();

            selectedCounter = counter;
        }<commit_msg>Added title of selected counter to actionbar<commit_after>package com.example.knitknit;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuInflater;
import android.view.ViewGroup;

public class CountingLand extends Activity {
    private static final String TAG = "knitknit-CountingLand";
    public static Counter selectedCounter = null;

    private DataWrangler mDataWrangler;
    private Project mProject;
    private ActionMode mActionMode;

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

        getActionBar().setDisplayHomeAsUpEnabled(true);

        // Get projectID from savedInstanceState
        Long projectID = null;
        projectID = (savedInstanceState == null ?
                     null :
                     (Long) savedInstanceState.getSerializable(DataWrangler.PROJECT_KEY_ID));

        // If we still don't have projectID, get it from intent extras
        if (projectID == null) {
            Bundle extras = getIntent().getExtras();
            projectID = (extras != null ?
                         extras.getLong(DataWrangler.PROJECT_KEY_ID) :
                         null);
        }

        if (projectID == null) {
            Log.w(TAG, "projectID is null");
        }
        else{ 
            Log.w(TAG, "projectID: " + projectID);
        }

        // Load the project
        mDataWrangler = new DataWrangler(this);
        mDataWrangler.open();
        mProject = mDataWrangler.retrieveProject(projectID);
        mProject.setActivity(this);

        // Update the dateOpened on the project
        mDataWrangler.touchProject(mProject);

        // DEBUG
        Log.w(TAG, "this project has " + mProject.getCounters().size() + " counters");

        // Set the action bar title to the name of the project
        getActionBar().setTitle(mProject.getName());

        // Attach the project's view to our view
        ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
        mProject.inflate(root, getResources().getConfiguration().orientation);
        root.addView(mProject.getWrapper());
    }


    // Lifecycle Management Methods
    //@Override
    //protected void onDestroy() {
    //    super.onDestroy();

    //    mDataWrangler.close();
    //}

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

        mDataWrangler.saveProject(mProject);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        Log.w(TAG, "in onWindowFocusChanged()");
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            mProject.refreshViews();
        }
    }


    // Options Menu (Action Bar) Methods
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.countingland, menu);

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
            case android.R.id.home:
                Intent intent = new Intent(this, ProjectList.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                return true;
            case R.id.new_counter:
                // Add a new counter to the database
                long id = mDataWrangler.createCounter(mProject.getId());

                // Retrieve a counter object for the new counter
                Counter counter = mDataWrangler.retrieveCounter(id);

                // Add the counter object to the project
                mProject.addCounter(counter);
                mProject.refreshViews();
                return true;
            default:
                return false;
        }
    }


    // Other Methods
    public Project getProject() {
        return mProject;
    }

    public static boolean getZeroMode() {
        return false;
    }

    public void startActionModeForCounter(Counter counter) {
        if (mActionMode == null) {
            // Tell the ProjectWrapper to ignore touch events while we are in action mode
            ((ProjectWrapper) findViewById(R.id.project_wrapper)).setRespondToTouch(false);

            mActionMode = startActionMode(mActionModeCallback);
            mActionMode.setTag(counter);

            // If the selected counter has a name
            if (counter.getName() != null) {
                // Set the action bar title to the name of the counter
                mActionMode.setTitle(counter.getName());
            }

            // Highlight thte selected counter
            counter.getWrapper().setSelected(true);
            counter.refreshViews();

            selectedCounter = counter;
        }
{'fraction_non_alphanumeric': 0.0902005611555648, 'fraction_numerical': 0.0, 'mean_word_length': 2.0965250965250966, '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': '5617757', 'n_tokens_mistral': 2593, 'n_tokens_neox': 2436, 'n_words': 620}