<commit_before>/*
 * Copyright (c) 2014, 2015 Data4All
 * 
 * <p>Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 * 
 * <p>http://www.apache.org/licenses/LICENSE-2.0
 * 
 * <p>Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package io.github.data4all.activity;

import io.github.data4all.R;
import io.github.data4all.logger.Log;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup.MarginLayoutParams;

/**
 * Global activity for all children activities.
 * 
 * This activity serves as a global class for all subclasses. Contains all the
 * methods that are relevant for all. For example the title bar.
 * 
 * @author <NAME>
 * @author tbrose
 * @CreationDate 10.01.2015
 * @LastUpdate 27.02.2015
 * @version 1.3
 * 
 */

public abstract class AbstractActivity extends Activity {

    /**
     * The default requestcode for
     * {@link AbstractActivity#startActivityForResult(Intent)
     * startActivityForResult(Intent)}.
     * 
     * @see AbstractActivity#startActivityForResult(android.content.Intent)
     */
    public static final int WORKFLOW_CODE = 9999;

    public static final int RESULT_FINISH = 9998;

    /*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        final MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_actionbar, menu);
        final ActionBar bar = getActionBar();
        if(bar != null) {
            getActionBar().setDisplayHomeAsUpEnabled(true);
        }
        return super.onCreateOptionsMenu(menu);
    }

    /*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onOptionsItemSelected(android.view.Menu)
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle presses on the action bar items
        boolean status;
        switch (item.getItemId()) {
        case R.id.upload_data:
            startActivity(new Intent(this, LoginActivity.class));
            status = true;
            break;
        case R.id.action_settings:
            startActivity(new Intent(this, SettingsActivity.class));
            status = true;
            break;
        case R.id.action_help:
            // TODO set help activity here
            status = true;
            break;
        // finish workflow, return to mapview
        case android.R.id.home:
            onHomePressed();
            status = true;
            break;
        default:
            return super.onOptionsItemSelected(item);
        }
        return status;
    }
    
    protected void onHomePressed() {
        onWorkflowFinished(null);
    }

    /**
     * Same as calling startActivityForResult(Intent, int) with
     * {@link AbstractActivity#WORKFLOW_CODE WORKFLOW_CODE}.
     * 
     * @author tbrose
     * 
     * @param intent
     *            The intent to start.
     * @see android.app.Activity#startActivityForResult(android.content.Intent,
     *      int)<commit_msg>Sonar refs #3316<commit_after>/*
 * Copyright (c) 2014, 2015 Data4All
 * 
 * <p>Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 * 
 * <p>http://www.apache.org/licenses/LICENSE-2.0
 * 
 * <p>Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package io.github.data4all.activity;

import io.github.data4all.R;
import io.github.data4all.logger.Log;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup.MarginLayoutParams;

/**
 * Global activity for all children activities.
 * 
 * This activity serves as a global class for all subclasses. Contains all the
 * methods that are relevant for all. For example the title bar.
 * 
 * @author <NAME>
 * @author tbrose
 * @CreationDate 10.01.2015
 * @LastUpdate 27.02.2015
 * @version 1.3
 * 
 */

public abstract class AbstractActivity extends Activity {

    /**
     * The default requestcode for
     * {@link AbstractActivity#startActivityForResult(Intent)
     * startActivityForResult(Intent)}.
     * 
     * @see AbstractActivity#startActivityForResult(android.content.Intent)
     */
    public static final int WORKFLOW_CODE = 9999;

    public static final int RESULT_FINISH = 9998;

    /*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        final MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_actionbar, menu);
        final ActionBar bar = getActionBar();
        if(bar != null) {
            getActionBar().setDisplayHomeAsUpEnabled(true);
        }
        return super.onCreateOptionsMenu(menu);
    }

    /*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onOptionsItemSelected(android.view.Menu)
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle presses on the action bar items
        boolean status;
        switch (item.getItemId()) {
        case R.id.upload_data:
            startActivity(new Intent(this, LoginActivity.class));
            status = true;
            break;
        case R.id.action_settings:
            startActivity(new Intent(this, SettingsActivity.class));
            status = true;
            break;
        case R.id.action_help:
            // TODO set help activity here
            status = true;
            break;
        // finish workflow, return to mapview
        case android.R.id.home:
            this.onHomePressed();
            status = true;
            break;
        default:
            return super.onOptionsItemSelected(item);
        }
        return status;
    }
    
    protected void onHomePressed() {
        onWorkflowFinished(null);
    }

    /**
     * Same as calling startActivityForResult(Intent, int) with
     * {@link AbstractActivity#WORKFLOW_CODE WORKFLOW_CODE}.
     * 
     * @author tbrose
     * 
     * @param intent
     *            The intent to start.
     * @see android.app.Activity#startActivityForResult(android.content.Intent,
     *      int)
{'fraction_non_alphanumeric': 0.09268823049741777, 'fraction_numerical': 0.011959771677086164, 'mean_word_length': 2.6073529411764707, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4906601', 'n_tokens_mistral': 2132, 'n_tokens_neox': 2013, 'n_words': 571}