package com.probeez.profiles.gsensor;
import static com.probeez.profiles.gsensor.EvalConditionService.STATE_POSITION;
import static com.probeez.profiles.gsensor.WindowOrientationListener.TILT_UP;
import static com.probeez.profiles.plugin.PluginIntent.ACTION_EDIT_CONDITION;
import static com.probeez.profiles.plugin.PluginIntent.EXTRA_STATE;
import static com.probeez.profiles.plugin.PluginIntent.EXTRA_SUMMARY;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import com.probeez.profiles.plugin.PluginIntent;
public class EditConditionActivity extends Activity
implements OnClickListener, OnCancelListener
{
private ArrayAdapter<CharSequence> mAdapter;
private int mPosition;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (!ACTION_EDIT_CONDITION.equals(intent.getAction())) {
finish();
return;
}
Bundle state = intent.getBundleExtra(EXTRA_STATE);
mPosition = state!=null? state.getInt(STATE_POSITION, TILT_UP): TILT_UP;
}
@Override
protected void onResume() {
super.onResume();
showDialog(0);
}
@Override
protected Dialog onCreateDialog(int id) {
mAdapter = ArrayAdapter.createFromResource(
this, R.array.positions, android.R.layout.select_dialog_singlechoice);
return new AlertDialog.Builder(this)
.setTitle(R.string.plugin_title)
.setSingleChoiceItems(mAdapter, mPosition, this)
.setOnCancelListener(this)
.create();
}
@Override
public void onCancel(DialogInterface dialog) {
setResult(RESULT_CANCELED);
finish();
}
@Override
public void onClick(DialogInterface dialog, int position) {
PluginIntent data = new PluginIntent(this);
data.putExtra(EXTRA_SUMMARY, mAdapter.getItem(position));
Bundle state = data.getState();
state.putInt(STATE_POSITION, position);
setResult(RESULT_OK, data);
finish();
}
}
|