I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 4d13e8ad authored by str4d's avatar str4d
Browse files

Added a TextFieldPage to WizardPager

parent 145b2493
No related branches found
No related tags found
No related merge requests found
<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">
<EditText android:id="@+id/wizard_text_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:saveEnabled="false"
android:inputType="textCapWords"
android:layout_marginBottom="16dp" />
<TextView style="@style/WizardFormLabel"
android:id="@+id/wizard_text_field_desc" />
</LinearLayout>
</ScrollView>
</LinearLayout>
/*
* 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 net.i2p.android.wizard.ui.TextFieldFragment;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import java.util.ArrayList;
/**
* A page asking for a text field.
*/
public class TextFieldPage extends Page {
protected String mDesc = "";
public TextFieldPage(ModelCallbacks callbacks, String title) {
super(callbacks, title);
}
@Override
public Fragment createFragment() {
return TextFieldFragment.create(getKey());
}
@Override
public void getReviewItems(ArrayList<ReviewItem> dest) {
dest.add(new ReviewItem(getTitle(), mData.getString(SIMPLE_DATA_KEY), getKey(), -1));
}
@Override
public boolean isCompleted() {
return !TextUtils.isEmpty(mData.getString(SIMPLE_DATA_KEY));
}
public TextFieldPage setDescription(String desc) {
mDesc = desc;
return this;
}
public String getDesc() {
return mDesc;
}
}
/*
* 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.TextFieldPage;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
public class TextFieldFragment extends Fragment {
private static final String ARG_KEY = "key";
private PageFragmentCallbacks mCallbacks;
private String mKey;
private TextFieldPage mPage;
private TextView mFieldView;
public static TextFieldFragment create(String key) {
Bundle args = new Bundle();
args.putString(ARG_KEY, key);
TextFieldFragment fragment = new TextFieldFragment();
fragment.setArguments(args);
return fragment;
}
public TextFieldFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
mKey = args.getString(ARG_KEY);
mPage = (TextFieldPage) mCallbacks.onGetPage(mKey);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_wizard_page_text_field, container, false);
((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());
((TextView) rootView.findViewById(R.id.wizard_text_field_desc)).setText(mPage.getDesc());
mFieldView = ((TextView) rootView.findViewById(R.id.wizard_text_field));
mFieldView.setHint(mPage.getTitle());
mFieldView.setText(mPage.getData().getString(Page.SIMPLE_DATA_KEY));
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);
mFieldView.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence charSequence, int i, int i1,
int i2) {
}
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
public void afterTextChanged(Editable editable) {
mPage.getData().putString(Page.SIMPLE_DATA_KEY,
(editable != null) ? editable.toString() : null);
mPage.notifyDataChanged();
}
});
}
@Override
public void setMenuVisibility(boolean menuVisible) {
super.setMenuVisibility(menuVisible);
// In a future update to the support library, this should override setUserVisibleHint
// instead of setMenuVisibility.
if (mFieldView != null) {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(
Context.INPUT_METHOD_SERVICE);
if (!menuVisible) {
imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment