/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * 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
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 cz.mynarik.accelerometer_0v5;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;

import java.util.Set;

/**
 * This Activity appears as a dialog. It lists any paired devices and
 * devices detected in the area after discovery. When a device is chosen
 * by the user, the MAC address of the device is sent back to the parent
 * Activity in the result Intent.
 */
public class AdvancedOptionsActivity extends Activity {
    // Debugging
    private static final String TAG = "AdvancedOptionsActivity";
    private static final boolean D = true;
    public int val=6;


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

        // Setup the window
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.activity_advanced);
        RadioButton rbt_acc = (RadioButton)findViewById(R.id.rbtn_acc);
        RadioButton rbt_gyr = (RadioButton)findViewById(R.id.rbtn_gyr);
        RadioButton rbt_fusion = (RadioButton)findViewById(R.id.rbtn_fusion);

        // Set result CANCELED incase the user backs out
        Bundle extras = getIntent().getExtras();
            val = extras.getInt("in");
            Log.e("CheckValue",String.valueOf(val));
        switch(val){
            case 4:
                rbt_acc.setChecked(true);
                //Log.e("setCheck","acc");
                break;
            case 5:
                rbt_gyr.setChecked(true);
                //Log.e("setCheck","gyr");
                break;
            case 6:
                rbt_fusion.setChecked(true);
                //Log.e("setCheck","fusion");
                break;
        }


    }
    public void onRadioButtonClicked(View view) {
        // Is the button now checked?
        boolean checked = ((RadioButton) view).isChecked();

        // Check which radio button was clicked
        switch(view.getId()) {
            case R.id.rbtn_acc:
                if (checked) {
                    Log.e("rbtn", "acc");
                    val=4;

                }
                    break;
            case R.id.rbtn_gyr:
                if (checked) {
                    Log.e("rbtn", "gyr");
                    val=5;
                }
                    break;
            case R.id.rbtn_fusion:
                if (checked){
                    Log.e("rbtn","fusion");
                    val=6;
                }
                    break;
        }

    }
    public void onButtonClicked(View view) {
        Intent returnIntent=new Intent();
        returnIntent.putExtra("out",val);
        setResult(RESULT_OK,returnIntent);
        finish();
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();

        // Make sure we're not doing discovery anymore
    }
    @Override
    protected void onStop() {


        // Make sure we're not doing discovery anymore
        super.onStop();
    }

}
