diff --git a/res/layout/fragment_wizard_page_single_boolean.xml b/res/layout/fragment_wizard_page_single_boolean.xml new file mode 100644 index 0000000000000000000000000000000000000000..1ecb5a54d957c211129553d1842c13d8b70980be --- /dev/null +++ b/res/layout/fragment_wizard_page_single_boolean.xml @@ -0,0 +1,45 @@ +<!-- + Copyright 2013 str4d + + 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. + --> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + style="@style/WizardPageContainer"> + + <TextView style="@style/WizardPageTitle" /> + + <ScrollView android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" + android:paddingLeft="16dp" + android:paddingRight="16dp" + android:scrollbarStyle="outsideOverlay"> + + <LinearLayout android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <CheckBox android:id="@+id/wizard_check_box" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:saveEnabled="false" + android:layout_marginBottom="16dp" + android:text="@string/enabled" /> + + <TextView style="@style/WizardFormLabel" + android:id="@+id/wizard_text_field_desc" /> + + </LinearLayout> + </ScrollView> +</LinearLayout> diff --git a/res/layout/fragment_wizard_page_text_field.xml b/res/layout/fragment_wizard_page_text_field.xml index 0d12578e0c3d60f3374c824bcd43dba385c12b2a..6f6e8fcbe918d08045b4126bc81a72207717ef8f 100644 --- a/res/layout/fragment_wizard_page_text_field.xml +++ b/res/layout/fragment_wizard_page_text_field.xml @@ -1,3 +1,19 @@ +<!-- + Copyright 2013 str4d + + 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. + --> + <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/WizardPageContainer"> @@ -18,7 +34,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:saveEnabled="false" - android:inputType="textCapWords" + android:inputType="text" android:layout_marginBottom="16dp" /> <TextView style="@style/WizardFormLabel" diff --git a/res/values/strings.xml b/res/values/strings.xml index c976cf2c4c989db4772582b30f639887e4a602e2..5ed2141fd5ea064adc7ff207b40fa0a4e0114f81 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -93,6 +93,7 @@ <string name="prev">Previous</string> <string name="finish">Submit</string> <string name="review">Review</string> + <string name="enabled">Enabled</string> <string name="i2ptunnel_wizard_submit_confirm_message">Create tunnel?</string> <string name="i2ptunnel_wizard_submit_confirm_button">Create tunnel</string> diff --git a/src/net/i2p/android/i2ptunnel/activity/TunnelWizardModel.java b/src/net/i2p/android/i2ptunnel/activity/TunnelWizardModel.java index 6f088fc0943e82b8cc5da63af003b576b8d43f01..66acd5758ea972877ecff0f6e72d6b19ae332a7d 100644 --- a/src/net/i2p/android/i2ptunnel/activity/TunnelWizardModel.java +++ b/src/net/i2p/android/i2ptunnel/activity/TunnelWizardModel.java @@ -5,6 +5,7 @@ import net.i2p.android.wizard.model.AbstractWizardModel; import net.i2p.android.wizard.model.BranchPage; import net.i2p.android.wizard.model.MultipleFixedChoicePage; import net.i2p.android.wizard.model.PageList; +import net.i2p.android.wizard.model.SingleFixedBooleanPage; import net.i2p.android.wizard.model.SingleFixedChoicePage; import net.i2p.android.wizard.model.TextFieldPage; @@ -30,7 +31,10 @@ public class TunnelWizardModel extends AbstractWizardModel { .setDescription("The name of the tunnel, for identification in the tunnel list.") .setRequired(true), new TextFieldPage(this, "Description") - .setDescription("A description of the tunnel. This is optional and purely informative.") + .setDescription("A description of the tunnel. This is optional and purely informative."), + new SingleFixedBooleanPage(this, "Auto start") + .setDescription("Should the tunnel automatically start when the router starts?") + .setRequired(true) ); } diff --git a/src/net/i2p/android/wizard/model/SingleFixedBooleanPage.java b/src/net/i2p/android/wizard/model/SingleFixedBooleanPage.java new file mode 100644 index 0000000000000000000000000000000000000000..d9625628a3ca4efd04c7a716d9a1def6fc99739f --- /dev/null +++ b/src/net/i2p/android/wizard/model/SingleFixedBooleanPage.java @@ -0,0 +1,61 @@ +/* + * Copyright 2013 str4d + * + * 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 net.i2p.android.wizard.model; + +import java.util.ArrayList; + +import net.i2p.android.wizard.ui.SingleBooleanFragment; + +import android.support.v4.app.Fragment; + +public class SingleFixedBooleanPage extends Page { + protected String mDesc = ""; + protected String mLabel = null; + + public SingleFixedBooleanPage(ModelCallbacks callbacks, String title) { + super(callbacks, title); + } + + @Override + public Fragment createFragment() { + return SingleBooleanFragment.create(getKey()); + } + + @Override + public void getReviewItems(ArrayList<ReviewItem> dest) { + dest.add(new ReviewItem(getTitle(), + mData.getBoolean(SIMPLE_DATA_KEY) ? "Yes" : "No", getKey())); + } + + public SingleFixedBooleanPage setLabel(String label) { + mLabel = label; + return this; + } + + public String getLabel() { + return mLabel; + } + + public SingleFixedBooleanPage setDescription(String desc) { + mDesc = desc; + return this; + } + + public String getDesc() { + return mDesc; + } +} diff --git a/src/net/i2p/android/wizard/ui/SingleBooleanFragment.java b/src/net/i2p/android/wizard/ui/SingleBooleanFragment.java new file mode 100644 index 0000000000000000000000000000000000000000..69db5faacdcf945cc385f94ddceb3d5580a2fa0f --- /dev/null +++ b/src/net/i2p/android/wizard/ui/SingleBooleanFragment.java @@ -0,0 +1,102 @@ +/* + * Copyright 2013 str4d + * + * 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 net.i2p.android.wizard.ui; + +import net.i2p.android.router.R; +import net.i2p.android.wizard.model.Page; +import net.i2p.android.wizard.model.SingleFixedBooleanPage; +import android.app.Activity; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.TextView; + +public class SingleBooleanFragment extends Fragment { + private static final String ARG_KEY = "key"; + + private PageFragmentCallbacks mCallbacks; + private String mKey; + private SingleFixedBooleanPage mPage; + private CheckBox mCheckBox; + + public static SingleBooleanFragment create(String key) { + Bundle args = new Bundle(); + args.putString(ARG_KEY, key); + + SingleBooleanFragment fragment = new SingleBooleanFragment(); + fragment.setArguments(args); + return fragment; + } + + public SingleBooleanFragment() { + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + Bundle args = getArguments(); + mKey = args.getString(ARG_KEY); + mPage = (SingleFixedBooleanPage) mCallbacks.onGetPage(mKey); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_wizard_page_single_boolean, container, false); + ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle()); + ((TextView) rootView.findViewById(R.id.wizard_text_field_desc)).setText(mPage.getDesc()); + + mCheckBox = ((CheckBox) rootView.findViewById(R.id.wizard_check_box)); + if (mPage.getLabel() != null) + mCheckBox.setText(mPage.getLabel()); + return rootView; + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + + if (!(activity instanceof PageFragmentCallbacks)) { + throw new ClassCastException("Activity must implement PageFragmentCallbacks"); + } + + mCallbacks = (PageFragmentCallbacks) activity; + } + + @Override + public void onDetach() { + super.onDetach(); + mCallbacks = null; + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + mPage.getData().putBoolean(Page.SIMPLE_DATA_KEY, isChecked); + mPage.notifyDataChanged(); + } + }); + } +}