diff options
author | Julian_Chu <walkingice@0xlab.org> | 2011-07-13 19:17:29 +0800 |
---|---|---|
committer | Julian_Chu <walkingice@0xlab.org> | 2011-07-15 15:53:35 +0800 |
commit | 102e2945bd479be9b4a917e9ceec89faf07f1870 (patch) | |
tree | c5579e3d3561e5f24e3fea56b0cd0a4667fd9bc8 | |
parent | d7f51eabc3f972f98d690f344f599f816e052a41 (diff) | |
download | 0xbench-102e2945bd479be9b4a917e9ceec89faf07f1870.tar.gz |
Add Activity Settings
This activity allows you to do some settings
such as customize path to store benchmarking result.
-rw-r--r-- | AndroidManifest.xml | 8 | ||||
-rw-r--r-- | res/layout/settings.xml | 66 | ||||
-rw-r--r-- | res/values/strings.xml | 3 | ||||
-rw-r--r-- | src/org/zeroxlab/benchmark/ActivitySettings.java | 151 |
4 files changed, 228 insertions, 0 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 6a45e2f..a5f7972 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -25,6 +25,14 @@ </intent-filter> </activity> + <activity + android:name="ActivitySettings" + android:screenOrientation="nosensor" > + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + </intent-filter> + </activity> + <activity android:name="TesterCanvas" android:screenOrientation="nosensor" diff --git a/res/layout/settings.xml b/res/layout/settings.xml new file mode 100644 index 0000000..347cdc0 --- /dev/null +++ b/res/layout/settings.xml @@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Authored By Julian Chu <walkingice@0xlab.org> + + Copyright (C) 2011 0xlab - http://0xlab.org/ + + 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. +--> + +<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + > + <LinearLayout + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:padding="5dp"> + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/settings_path_hint" + /> + <TextView android:id="@+id/path_selection" + android:layout_width="match_parent" + android:layout_height="wrap_content" + /> + <RelativeLayout android:id="@+id/result_path_pane" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + <RadioGroup android:id="@+id/radio_group_path" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical"> + <RadioButton android:id="@+id/radio_sdcard" + android:layout_width="match_parent" + android:layout_height="wrap_content" + /> + <RadioButton android:id="@+id/radio_custom" + android:text="@string/settings_custom_path" + android:layout_width="match_parent" + android:layout_height="wrap_content" + /> + </RadioGroup> + <Button android:id="@+id/edit_dir" + android:layout_alignParentRight="true" + android:layout_alignBottom="@id/radio_group_path" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/settings_edit_path" + /> + </RelativeLayout> + </LinearLayout> +</ScrollView> + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 1daa12c..0882c81 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -19,6 +19,9 @@ <string name="login">Login</string> +<string name="settings_path_hint">Save result to...</string> +<string name="settings_custom_path">Customize</string> +<string name="settings_edit_path">Edit Custom Path</string> <!-- its not typo --> <string name="banner_info_text">Hell World!</string> diff --git a/src/org/zeroxlab/benchmark/ActivitySettings.java b/src/org/zeroxlab/benchmark/ActivitySettings.java new file mode 100644 index 0000000..9aebd9e --- /dev/null +++ b/src/org/zeroxlab/benchmark/ActivitySettings.java @@ -0,0 +1,151 @@ +/* + * Authored By Julian Chu <walkingice@0xlab.org> + * + * Copyright (C) 2011 0xlab - http://0xlab.org/ + * + * 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 org.zeroxlab.benchmark; + +import android.util.Log; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.os.Bundle; +import android.os.Environment; +import android.os.Handler; +import android.os.Message; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.RadioButton; +import android.widget.ScrollView; +import android.widget.TextView; + +import org.zeroxlab.utils.BenchUtil; + +public class ActivitySettings extends Activity implements View.OnClickListener { + + public final static String TAG = "Benchmark"; + private Context mContext; + private Button mEdit; + private TextView mPathView; + private String mPath; + private RadioListener mRadioListener; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mContext = this; + initViews(); + } + + @Override + protected void onPause() { + super.onPause(); + finish(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + } + + public void onClick(View v) { + if (v == mEdit) { + alertInput(); + } + } + + private void initViews() { + setContentView(R.layout.settings); + mRadioListener = new RadioListener(); + RadioButton radio_sdcard = (RadioButton) findViewById(R.id.radio_sdcard); + RadioButton radio_custom = (RadioButton) findViewById(R.id.radio_custom); + mPathView = (TextView) findViewById(R.id.path_selection); + mEdit = (Button) findViewById(R.id.edit_dir); + + mEdit.setOnClickListener(this); + + radio_sdcard.setOnClickListener(mRadioListener); + radio_custom.setOnClickListener(mRadioListener); + + radio_sdcard.setText(BenchUtil.DEFAULT_RESULT_DIR); + + /* Retrieve preference of path selection */ + int selection = BenchUtil.getResultSelection(this); + if (selection == BenchUtil.RESULT_SELECTION_SDCARD) { + radio_sdcard.performClick(); + } else if (selection == BenchUtil.RESULT_SELECTION_CUSTOM) { + radio_custom.performClick(); + } else { + Log.e(TAG, "Choosen an unknown radio button in Settings Activity"); + } + + } + + private void alertInput() { + final AlertDialog.Builder alert = new AlertDialog.Builder(this); + final EditText edit = new EditText(this); + edit.setText(BenchUtil.getCustomDir(this)); + alert.setView(edit); + alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + BenchUtil.setCustomDir(mContext, edit.getText().toString()); + updateHint(); + } + }); + alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + dialog.cancel(); + } + }); + alert.show(); + } + + private void updateHint() { + final int selection = BenchUtil.getResultSelection(this); + if (selection == BenchUtil.RESULT_SELECTION_SDCARD) { + mPath = BenchUtil.DEFAULT_RESULT_DIR; + } else if (selection == BenchUtil.RESULT_SELECTION_CUSTOM) { + mPath = BenchUtil.getCustomDir(mContext); + } else { + Log.e(TAG, "I don't understand what did you choose!"); + } + + mPathView.setText(mPath); + } + + private class RadioListener implements View.OnClickListener { + public void onClick(View v) { + if (v.getId() == R.id.radio_sdcard) { + BenchUtil.setResultSelection(mContext, BenchUtil.RESULT_SELECTION_SDCARD); + } else if (v.getId() == R.id.radio_custom) { + BenchUtil.setResultSelection(mContext, BenchUtil.RESULT_SELECTION_CUSTOM); + } else { + Log.e(TAG, "I don't know what did you click!"); + return; + } + + updateHint(); + } + } +} |