<commit_before>package ch.ffhs.esa.bewegungsmelder;

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 * 
 * Author: <NAME> <<EMAIL>>
 * Contributors:
 * 	- <NAME> <<EMAIL>> 
 *  - <NAME> <<EMAIL>> 
 *  - <NAME> <<EMAIL>>
 *  */

import ch.ffhs.esa.bewegungsmelder.DeveloperActivity.MotionDetectionStatusReceiver;
import android.os.Bundle;
import android.os.Vibrator;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
	private static final String TAG = MainActivity.class.getSimpleName();
	private static final int RESULT_SETTINGS = 1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
	@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
 
        case R.id.action_settings:
            Intent i = new Intent(this, UserSettingActivity.class);
            startActivityForResult(i, RESULT_SETTINGS);
            break;
 
        }
 
        return true;
    }
	
	public void onContactButtonClick(View view) {
		Intent intent = new Intent(this, AddContact.class);
		startActivity(intent);
	
	}
	
	public void onModeButtonClick() {
			
	}
	
/* ----------------------- Start of Timer Service / WiR 2013-12-16 ------------ */
	
	public void onSupervisionButtonClick(View view) {		
		boolean motionServiceRunning = false;
		/* Test if service running */
		ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
		for(RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)){
			if(MotionDetectionService.class.getName().equals(service.service.getClassName())){
				motionServiceRunning = true;
			}
		}
		// Stop if running
		if(motionServiceRunning){
			stopService(new Intent(this, MotionDetectionService.class));
			motionServiceRunning = false;
		}
		// Start if not running
		else{
			MotionDetectionStatusReceiver br = new MotionDetectionStatusReceiver();
			registerReceiver(br, new IntentFilter(MotionDetectionService.MOTION_DETECTION_ACTION));
			startService(new Intent(this, MotionDetectionService.class));
		}
	}
	// Receiver des MotionDetection Services
	public class MotionDetectionStatusReceiver extends BroadcastReceiver{
		@Override
		public void onReceive(Context context, Intent intent) {

			if (intent.getAction().equals(MotionDetectionService.MOTION_DETECTION_ACTION)){
				Log.d(TAG, "MotionDetection Broadcast received!!!");
				Bundle bundle = intent.getExtras();
				if (bundle != null){
					String textMsg = "Status: " + (String) bundle.get("TIMER_RUNNING_STR") + " Time left: " + (String) bundle.get("TIME_LEFT");

					TextView textViewTimeLeft = (TextView) findViewById(R.id.timeLeftTextView); 
					textViewTimeLeft.setText(textMsg);
					Log.d(TAG, textMsg);

					// stop service, unregister Broadcast receiver
					if(!(Boolean)bundle.get("TIMER_RUNNING_BOOL")){
						context.stopService(new Intent(context, MotionDetectionService.class));
						context.unregisterReceiver(MotionDetectionStatusReceiver.this);
						Log.d(TAG, "Broadcast receiver unregistered, service stopped!");
					}
				}
			}
		}
	}
	
	/* ----------------------- End of Timer Service / WiR 2013-12-16 ------------ */

	private void enableSupervision() {
		
	}
	
	private void disableSupervision() {<commit_msg>Timer in MainActivity eingefügt & getestet.<commit_after>package ch.ffhs.esa.bewegungsmelder;

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 * 
 * Author: <NAME> <<EMAIL>>
 * Contributors:
 * 	- <NAME> <<EMAIL>> 
 *  - <NAME> <<EMAIL>> 
 *  - <NAME> <<EMAIL>>
 *  */

import ch.ffhs.esa.bewegungsmelder.DeveloperActivity.MotionDetectionStatusReceiver;
import android.os.Bundle;
import android.os.Vibrator;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
	private static final String TAG = MainActivity.class.getSimpleName();
	boolean motionServiceRunning = false;
	private static final int RESULT_SETTINGS = 1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
	@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
 
        case R.id.action_settings:
            Intent i = new Intent(this, UserSettingActivity.class);
            startActivityForResult(i, RESULT_SETTINGS);
            break;
 
        }
 
        return true;
    }
	
	public void onContactButtonClick(View view) {
		Intent intent = new Intent(this, AddContact.class);
		startActivity(intent);
	
	}
	
	public void onModeButtonClick() {
			
	}
	
/* ----------------------- Start of Timer Service / WiR 2013-12-16 ------------ */
	
	public void onSupervisionButtonClicked(View view) {		

		/* Test if service running */
		ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
		for(RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)){
			if(MotionDetectionService.class.getName().equals(service.service.getClassName())){
				motionServiceRunning = true;
			}
		}
		// Stop if running
		if(motionServiceRunning){
			Log.d(TAG, "Stopping service!");
			stopService(new Intent(this, MotionDetectionService.class));
			motionServiceRunning = false;
			TextView textViewTimeLeft = (TextView) findViewById(R.id.textViewTimeLeft); 
			textViewTimeLeft.setText("not running"); // TODO: Sauber implementieren
		}
		// Start if not running
		else{
			Log.d(TAG, "Starting service!");
			MotionDetectionStatusReceiver br = new MotionDetectionStatusReceiver();
			registerReceiver(br, new IntentFilter(MotionDetectionService.MOTION_DETECTION_ACTION));
			startService(new Intent(this, MotionDetectionService.class));
		}
	}
	// Receiver des MotionDetection Services
	public class MotionDetectionStatusReceiver extends BroadcastReceiver{
		@Override
		public void onReceive(Context context, Intent intent) {
			if (intent.getAction().equals(MotionDetectionService.MOTION_DETECTION_ACTION)){
				Log.d(TAG, "MotionDetection Broadcast received!!!");
				Bundle bundle = intent.getExtras();
				Log.d(TAG, "Extras read!!!");
				if (bundle != null){
					Log.d(TAG, "bundle != null");
					String textMsg = "Status: " + (String) bundle.get("TIMER_RUNNING_STR") + " Time left: " + (String) bundle.get("TIME_LEFT");

					TextView textViewTimeLeft = (TextView) findViewById(R.id.textViewTimeLeft); 
					textViewTimeLeft.setText(textMsg);
					Log.d(TAG, textMsg);

					// stop service, unregister Broadcast receiver
					if(!(Boolean)bundle.get("TIMER_RUNNING_BOOL")){
						context.stopService(new Intent(context, MotionDetectionService.class));
						context.unregisterReceiver(MotionDetectionStatusReceiver.this);
						Log.d(TAG, "Broadcast receiver unregistered, service stopped!");
					}
				}
			}
		}
	}
	
	/* ----------------------- End of Timer Service / WiR 2013-12-16 ------------ */

	private void enableSupervision() {
		
	}
	
	private void disableSupervision() {
{'fraction_non_alphanumeric': 0.12089810017271158, 'fraction_numerical': 0.004835924006908463, 'mean_word_length': 3.926829268292683, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1556027', 'n_tokens_mistral': 2830, 'n_tokens_neox': 2466, 'n_words': 593}