Android Open Source - WizardPager Text Fragment






From Project

Back to project page WizardPager.

License

The source code is released under:

Apache License

If you think the Android project WizardPager listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.tech.freak.wizardpager.ui;
// w w w  . ja v a2s  .  c  o  m
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.InputType;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import com.tech.freak.wizardpager.R;
import com.tech.freak.wizardpager.model.Page;

public class TextFragment extends Fragment {
  protected static final String ARG_KEY = "key";

  private PageFragmentCallbacks mCallbacks;
  private String mKey;
  private Page mPage;

  protected EditText mEditTextInput;

  public static TextFragment create(String key) {
    Bundle args = new Bundle();
    args.putString(ARG_KEY, key);

    TextFragment f = new TextFragment();
    f.setArguments(args);
    return f;
  }

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

    Bundle args = getArguments();
    mKey = args.getString(ARG_KEY);
    mPage = mCallbacks.onGetPage(mKey);
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_page_text,
        container, false);
    ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage
        .getTitle());

    mEditTextInput = (EditText) rootView.findViewById(R.id.editTextInput);
    mEditTextInput.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);
    setInputType();
    mEditTextInput.addTextChangedListener(new TextWatcher() {

      @Override
      public void beforeTextChanged(CharSequence s, int start, int count,
          int after) {
      }

      @Override
      public void onTextChanged(CharSequence s, int start, int before,
          int count) {
      }

      @Override
      public void afterTextChanged(Editable editable) {
        mPage.getData().putString(Page.SIMPLE_DATA_KEY,
            (editable != null) ? editable.toString() : null);
        mPage.notifyDataChanged();

      }

    });
  }

  protected void setInputType() {
    mEditTextInput.setInputType(InputType.TYPE_CLASS_TEXT);
  }

  @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 (mEditTextInput != null) {
      InputMethodManager imm = (InputMethodManager) getActivity()
          .getSystemService(Context.INPUT_METHOD_SERVICE);
      if (!menuVisible) {
        imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
      }
    }
  }

}




Java Source Code List

com.example.android.wizardpager.MainActivity.java
com.example.android.wizardpager.SandwichWizardModel.java
com.example.android.wizardpager.pages.CustomerInfoFragment.java
com.example.android.wizardpager.pages.CustomerInfoPage.java
com.tech.freak.wizardpager.model.AbstractWizardModel.java
com.tech.freak.wizardpager.model.BranchPage.java
com.tech.freak.wizardpager.model.GeoPage.java
com.tech.freak.wizardpager.model.ImagePage.java
com.tech.freak.wizardpager.model.ModelCallbacks.java
com.tech.freak.wizardpager.model.MultipleFixedChoicePage.java
com.tech.freak.wizardpager.model.NumberPage.java
com.tech.freak.wizardpager.model.PageList.java
com.tech.freak.wizardpager.model.PageTreeNode.java
com.tech.freak.wizardpager.model.Page.java
com.tech.freak.wizardpager.model.ReviewItem.java
com.tech.freak.wizardpager.model.SimpleLocationListener.java
com.tech.freak.wizardpager.model.SingleFixedChoicePage.java
com.tech.freak.wizardpager.model.TextPage.java
com.tech.freak.wizardpager.ui.GeoFragment.java
com.tech.freak.wizardpager.ui.ImageFragment.java
com.tech.freak.wizardpager.ui.MultipleChoiceFragment.java
com.tech.freak.wizardpager.ui.NumberFragment.java
com.tech.freak.wizardpager.ui.PageFragmentCallbacks.java
com.tech.freak.wizardpager.ui.ReviewFragment.java
com.tech.freak.wizardpager.ui.SingleChoiceFragment.java
com.tech.freak.wizardpager.ui.StepPagerStrip.java
com.tech.freak.wizardpager.ui.TextFragment.java