Example usage for android.text InputType TYPE_CLASS_NUMBER

List of usage examples for android.text InputType TYPE_CLASS_NUMBER

Introduction

In this page you can find the example usage for android.text InputType TYPE_CLASS_NUMBER.

Prototype

int TYPE_CLASS_NUMBER

To view the source code for android.text InputType TYPE_CLASS_NUMBER.

Click Source Link

Document

Class for numeric text.

Usage

From source file:com.emobc.android.activities.generators.FormActivityGenerator.java

private EditText insertNumberField(Activity activity, FormDataItem dataItem) {
    EditText txt = insertTextField(activity, dataItem);
    txt.setInputType(InputType.TYPE_CLASS_NUMBER);
    return txt;
}

From source file:nz.ac.otago.psyanlab.common.designer.program.stage.EditPropPropertiesFragment.java

/**
 * Creates an edit text entry field that allows the user to enter a
 * fractional number.//w  ww .j  a  v a2  s  .c  o m
 * 
 * @param signedAnnotation
 * @return EditText
 */
private View newFloatInputView(boolean isSigned, float f) {
    EditText view = new EditText(getActivity());
    if (isSigned) {
        view.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL
                | InputType.TYPE_NUMBER_FLAG_SIGNED);
    } else {
        view.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    }
    view.setSingleLine();
    view.setText(String.valueOf(f));
    return view;
}

From source file:com.bvhloc.numpicker.widget.NumberPicker.java

public NumberPicker(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);

    mStart = DEFAULT_START;//ww w.j  av a 2  s  .co m
    mEnd = DEFAULT_END;
    mCurrent = mStart;

    boolean vertical = true;
    int displayedValues = 0;

    if (attrs != null && !isInEditMode()) {
        // this crashes in edit mode (?!)
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.NumberPicker);

        mStart = a.getInt(R.styleable.NumberPicker_rangeStart, DEFAULT_START);
        mEnd = a.getInt(R.styleable.NumberPicker_rangeEnd, DEFAULT_END);
        mSpeed = a.getInt(R.styleable.NumberPicker_speed, (int) mSpeed);
        mSpeedUp = mSpeed;
        mCurrent = a.getInt(R.styleable.NumberPicker_current, mCurrent);

        mNumColor = a.getColor(R.styleable.NumberPicker_numColor,
                ContextCompat.getColor(context, android.R.color.primary_text_light));
        mNumBackground = a.getDrawable(R.styleable.NumberPicker_numBackground);
        mNumSize = a.getDimension(R.styleable.NumberPicker_numSize, mNumSize);
        mNumHorizontalPadding = (int) a.getDimension(R.styleable.NumberPicker_numHorizontalPadding, mNumSize);
        mNumHorizontalPadding = (int) a.getDimension(R.styleable.NumberPicker_numVeticalPadding, mNumSize);
        mIncrementDrawable = a.getDrawable(R.styleable.NumberPicker_incrementDrawable);
        mDecrementDrawable = a.getDrawable(R.styleable.NumberPicker_decrementDrawable);
        mKeyboardInput = a.getBoolean(R.styleable.NumberPicker_keyboardInput, mKeyboardInput);

        String orientation = a.getString(R.styleable.NumberPicker_android_orientation);
        displayedValues = a.getResourceId(R.styleable.NumberPicker_displayedValues, 0);

        if (orientation != null) {
            vertical = !"0".equals(orientation);
        }

        a.recycle();
    } else if (attrs != null && isInEditMode()) {
        // fix orientation attribute for editor
        String orientation = attrs.getAttributeValue("http://schemas.android.com/apk/res/android",
                "orientation");

        if (orientation != null) {
            vertical = !"horizontal".equals(orientation);
        }
    }
    // set a wrong orientation so our own orientation method will perform changes
    super.setOrientation(!vertical ? VERTICAL : HORIZONTAL);
    setOrientation(vertical ? VERTICAL : HORIZONTAL);

    mChangeHandler = new Handler();
    InputFilter inputFilter = new NumberPickerInputFilter();
    mNumberInputFilter = new NumberRangeKeyListener();
    mIncrementButton = (NumberPickerButton) findViewById(R.id.increment);
    mIncrementButton.setOnClickListener(this);
    mIncrementButton.setOnLongClickListener(this);
    mIncrementButton.setNumberPicker(this);
    mDecrementButton = (NumberPickerButton) findViewById(R.id.decrement);
    mDecrementButton.setOnClickListener(this);
    mDecrementButton.setOnLongClickListener(this);
    mDecrementButton.setNumberPicker(this);

    mIncrementButton.setBackground(null);
    mDecrementButton.setBackground(null);
    mIncrementButton.setScaleType(ImageView.ScaleType.FIT_CENTER);
    mDecrementButton.setScaleType(ImageView.ScaleType.FIT_CENTER);

    if (mIncrementDrawable != null) {
        mIncrementButton.setImageDrawable(mIncrementDrawable);
    }
    if (mDecrementDrawable != null) {
        mDecrementButton.setImageDrawable(mDecrementDrawable);
    }

    mText = (EditText) findViewById(R.id.timepicker_input);
    mText.setOnFocusChangeListener(this);
    mText.setFilters(new InputFilter[] { inputFilter });
    mText.setRawInputType(InputType.TYPE_CLASS_NUMBER);
    LayoutParams params = (LayoutParams) mText.getLayoutParams();
    params.weight = 1;
    mText.setLayoutParams(params);

    mText.setPadding(mNumHorizontalPadding, mNumVerticalPadding, mNumHorizontalPadding, mNumVerticalPadding);
    mText.setTextSize(mNumSize);
    if (mNumBackground != null) {
        mText.setBackground(mNumBackground);
    } else {
        mText.setBackground(ContextCompat.getDrawable(context, android.R.drawable.edit_text));
    }
    if (!mKeyboardInput) {
        mText.setEnabled(false);
    }
    mText.setTextColor(mNumColor);

    if (!isEnabled()) {
        setEnabled(false);
    }

    if (displayedValues != 0) {
        setDisplayedRange(mStart, displayedValues);
    } else {
        setRange(mStart, mEnd);
    }
}

From source file:at.alladin.rmbt.android.about.RMBTAboutFragment.java

private void handleHiddenCode() {
    if (++developerFeatureCounter >= 10) {
        developerFeatureCounter = 0;// ww w .j av  a  2  s.  c o  m
        final EditText input = new EditText(getActivity());
        input.setInputType(InputType.TYPE_CLASS_NUMBER);
        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setView(input);
        builder.setTitle(R.string.about_hidden_feature_dialog_title);
        builder.setMessage(R.string.about_hidden_feature_dialog_enter_code);
        builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int which) {

                try {
                    final String data = input.getText().toString();
                    if (!data.matches("\\d{8}")) {
                        Toast.makeText(getActivity(), R.string.about_hidden_feature_dialog_msg_try_again,
                                Toast.LENGTH_LONG).show();
                        return;
                    }

                    final int dataInt = Integer.parseInt(data);
                    if (dataInt == 0) // deactivate all features
                    {
                        ConfigHelper.setUserLoopModeState(getActivity(), false);
                        ConfigHelper.setDevModeState(getActivity(), false);
                        ConfigHelper.setServerSelectionState(getActivity(), false);
                        ((RMBTMainActivity) getActivity()).checkSettings(true, null); // refresh server list
                        Toast.makeText(getActivity(), R.string.about_hidden_feature_dialog_msg_deactivated,
                                Toast.LENGTH_LONG).show();
                        return;
                    }

                    if (ConfigHelper.isValidCheckSum(dataInt)) { // developer mode
                        if (dataInt == AppConstants.DEVELOPER_UNLOCK_CODE) {
                            ConfigHelper.setDevModeState(getActivity(), true);
                            Toast.makeText(getActivity(), R.string.about_dev_mode_activated, Toast.LENGTH_LONG)
                                    .show();
                        } else if (dataInt == AppConstants.DEVELOPER_LOCK_CODE) {
                            ConfigHelper.setDevModeState(getActivity(), false);
                            Toast.makeText(getActivity(), R.string.about_dev_mode_deactivated,
                                    Toast.LENGTH_LONG).show();
                        }
                        // loop mode
                        else if (dataInt == AppConstants.LOOP_MODE_UNLOCK_CODE) {
                            ConfigHelper.setUserLoopModeState(getActivity(), true);
                            Toast.makeText(getActivity(), R.string.about_loop_mode_activated, Toast.LENGTH_LONG)
                                    .show();
                        } else if (dataInt == AppConstants.LOOP_MODE_LOCK_CODE) {
                            ConfigHelper.setUserLoopModeState(getActivity(), false);
                            Toast.makeText(getActivity(), R.string.about_loop_mode_deactivated,
                                    Toast.LENGTH_LONG).show();
                        }
                        // server selection
                        else if (dataInt == AppConstants.SERVER_SELECTION_UNLOCK_CODE) {
                            ConfigHelper.setServerSelectionState(getActivity(), true);
                            ((RMBTMainActivity) getActivity()).checkSettings(true, null); // refresh server list
                            Toast.makeText(getActivity(), R.string.about_server_selection_activated,
                                    Toast.LENGTH_LONG).show();
                        } else if (dataInt == AppConstants.SERVER_SELECTION_LOCK_CODE) {
                            ConfigHelper.setServerSelectionState(getActivity(), false);
                            ((RMBTMainActivity) getActivity()).checkSettings(true, null); // refresh server list
                            Toast.makeText(getActivity(), R.string.about_server_selection_deactivated,
                                    Toast.LENGTH_LONG).show();
                        }
                        // code not used
                        else {
                            Toast.makeText(getActivity(), R.string.about_hidden_feature_dialog_msg_try_again,
                                    Toast.LENGTH_LONG).show();
                        }
                    } else
                        Toast.makeText(getActivity(), R.string.about_hidden_feature_dialog_msg_try_again,
                                Toast.LENGTH_LONG).show();
                } catch (Exception e) // ignore errors
                {
                    e.printStackTrace();
                }
            }
        });
        builder.setNegativeButton(android.R.string.cancel, null);

        dialog = builder.create();
        dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
        dialog.show();
    }
}

From source file:com.auth0.android.lock.views.ValidatedInputView.java

private void setupInputValidation() {
    String hint = "";
    String error = "";
    input.setTransformationMethod(null);
    Log.v(TAG, "Setting up validation for field of type " + dataType);
    switch (dataType) {
    case EMAIL://from   w ww .  j ava2 s. c o m
        input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
        inputIcon = R.drawable.com_auth0_lock_ic_email;
        hint = getResources().getString(R.string.com_auth0_lock_hint_email);
        error = getResources().getString(R.string.com_auth0_lock_input_error_email);
        break;
    case PASSWORD:
        input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        input.setTransformationMethod(PasswordTransformationMethod.getInstance());
        input.setTypeface(Typeface.DEFAULT);
        inputIcon = R.drawable.com_auth0_lock_ic_password;
        hint = getResources().getString(R.string.com_auth0_lock_hint_password);
        error = getResources().getString(R.string.com_auth0_lock_input_error_password);
        break;
    case USERNAME_OR_EMAIL:
        input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
        inputIcon = R.drawable.com_auth0_lock_ic_username;
        hint = getResources().getString(R.string.com_auth0_lock_hint_username_or_email);
        error = getResources().getString(R.string.com_auth0_lock_input_error_username_email);
        break;
    case TEXT_NAME:
        input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
        inputIcon = R.drawable.com_auth0_lock_ic_username;
        hint = getResources().getString(R.string.com_auth0_lock_hint_username);
        error = getResources().getString(R.string.com_auth0_lock_input_error_empty);
        break;
    case NON_EMPTY_USERNAME:
        input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
        inputIcon = R.drawable.com_auth0_lock_ic_username;
        hint = getResources().getString(R.string.com_auth0_lock_hint_username);
        error = getResources().getString(R.string.com_auth0_lock_input_error_username_empty);
        break;
    case USERNAME:
        input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
        inputIcon = R.drawable.com_auth0_lock_ic_username;
        hint = getResources().getString(R.string.com_auth0_lock_hint_username);
        error = String.format(getResources().getString(R.string.com_auth0_lock_input_error_username),
                MIN_USERNAME_LENGTH, MAX_USERNAME_LENGTH);
        break;
    case NUMBER:
        input.setInputType(InputType.TYPE_CLASS_NUMBER);
        inputIcon = R.drawable.com_auth0_lock_ic_password;
        hint = getResources().getString(R.string.com_auth0_lock_hint_code);
        error = getResources().getString(R.string.com_auth0_lock_input_error_empty);
        break;
    case MFA_CODE:
        input.setInputType(InputType.TYPE_CLASS_NUMBER);
        inputIcon = R.drawable.com_auth0_lock_ic_password;
        hint = getResources().getString(R.string.com_auth0_lock_hint_code);
        error = getResources().getString(R.string.com_auth0_lock_input_error_code);
        break;
    case MOBILE_PHONE:
        input.setInputType(InputType.TYPE_CLASS_NUMBER);
        inputIcon = R.drawable.com_auth0_lock_ic_mobile;
        hint = getResources().getString(R.string.com_auth0_lock_hint_phone_number);
        error = getResources().getString(R.string.com_auth0_lock_input_error_phone_number);
        break;
    case PHONE_NUMBER:
        input.setInputType(InputType.TYPE_CLASS_PHONE);
        inputIcon = R.drawable.com_auth0_lock_ic_phone;
        hint = getResources().getString(R.string.com_auth0_lock_hint_phone_number);
        error = getResources().getString(R.string.com_auth0_lock_input_error_phone_number);
        break;
    }
    input.setHint(hint);
    errorDescription.setText(error);
    icon.setImageResource(inputIcon);
}

From source file:tinygsn.gui.android.ActivityViewDataNew.java

private void addTableViewModeLatest() {
    table_view_mode = (TableLayout) findViewById(R.id.table_view_mode);
    // table_view_mode.setLayoutParams(new
    // TableLayout.LayoutParams(LayoutParams.FILL_PARENT,
    // LayoutParams.WRAP_CONTENT));
    table_view_mode.removeAllViews();//from w w  w.  j ava  2s . com

    TableRow row = new TableRow(this);

    TextView txt = new TextView(this);
    txt.setText("         View ");
    txt.setTextColor(Color.parseColor("#000000"));
    row.addView(txt);

    final EditText editText_numLatest = new EditText(this);
    editText_numLatest.setText("10");
    editText_numLatest.setInputType(InputType.TYPE_CLASS_NUMBER);
    editText_numLatest.requestFocus();
    editText_numLatest.setTextColor(Color.parseColor("#000000"));
    row.addView(editText_numLatest);

    editText_numLatest.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

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

        @Override
        public void afterTextChanged(Editable s) {
            try {
                numLatest = Integer.parseInt(editText_numLatest.getText().toString());
                loadLatestData();
            } catch (NumberFormatException e) {
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
                alertDialogBuilder.setTitle("Please input a number!");
            }
        }
    });

    txt = new TextView(this);
    txt.setText(" latest values");
    txt.setTextColor(Color.parseColor("#000000"));
    row.addView(txt);

    txt = new TextView(this);
    txt.setText("            ");
    row.addView(txt);
    table_view_mode.addView(row);

    row = new TableRow(this);
    Button detailBtn = new Button(this);
    detailBtn.setText("Detail");

    // detailBtn.setBackground(getResources().getDrawable(R.drawable.info));
    // detailBtn.setWidth(200);
    detailBtn.setTextSize(TEXT_SIZE + 2);
    detailBtn.setTextColor(Color.parseColor("#000000"));
    detailBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialogDetail();
        }
    });

    Button plotDataBtn = new Button(this);
    plotDataBtn.setText("Plot data");
    plotDataBtn.setTextSize(TEXT_SIZE + 2);
    plotDataBtn.setTextColor(Color.parseColor("#000000"));
    // plotDataBtn.setBackground(getResources().getDrawable(R.drawable.chart));

    // LinearLayout.LayoutParams params = plotDataBtn.getLayoutParams();
    // params.width = 50;
    // plotDataBtn.setLayoutParams(params);

    plotDataBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            viewChart();
        }
    });

    TableRow.LayoutParams rowParams = new TableRow.LayoutParams();
    // params.addRule(TableRow.LayoutParams.FILL_PARENT);
    rowParams.span = 2;

    row.addView(detailBtn, rowParams);
    row.addView(plotDataBtn, rowParams);

    // detailBtn.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
    // LayoutParams.WRAP_CONTENT));
    // plotDataBtn.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
    // LayoutParams.WRAP_CONTENT));

    row.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    table_view_mode.addView(row);
}

From source file:nz.ac.otago.psyanlab.common.designer.program.stage.EditPropPropertiesFragment.java

/**
 * Creates an edit text entry field that allows the user to enter an
 * integer.//from w  ww . j a  v  a  2 s .  c  o  m
 * 
 * @param i
 * @param posOnlyAnnotation
 * @return EditText
 */
private View newIntegerInputView(boolean isSigned, int i) {
    EditText view = new EditText(getActivity());
    if (isSigned) {
        view.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_NORMAL
                | InputType.TYPE_NUMBER_FLAG_SIGNED);
    } else {
        view.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_NORMAL);
    }
    view.setSingleLine();
    view.setText(String.valueOf(i));
    return view;
}

From source file:me.philio.pinentry.PinEntryView.java

/**
 * Create views and add them to the view group
 */// w ww  .  ja  v a2  s  .  co  m
@TargetApi(21)
private void addViews() {
    // Add a digit view for each digit
    for (int i = 0; i < mDigits; i++) {
        DigitView digitView = new DigitView(getContext());
        digitView.setWidth(mDigitWidth);
        digitView.setHeight(mDigitHeight);
        digitView.setBackgroundResource(mDigitBackground);
        digitView.setTextColor(mDigitTextColor);
        digitView.setTextSize(mDigitTextSize);
        digitView.setGravity(Gravity.CENTER);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            digitView.setElevation(mDigitElevation);
        }
        addView(digitView);
    }

    // Add an "invisible" edit text to handle input
    mEditText = new EditText(getContext());
    mEditText.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
    mEditText.setTextColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
    mEditText.setCursorVisible(false);
    mEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(mDigits) });
    mEditText.setInputType(InputType.TYPE_CLASS_NUMBER);
    mEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    mEditText.setPadding(mEditText.getPaddingLeft(), mEditText.getPaddingTop(), mEditText.getPaddingRight(),
            100);
    mEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            // Update the selected state of the views
            int length = mEditText.getText().length();
            for (int i = 0; i < mDigits; i++) {
                getChildAt(i)
                        .setSelected(hasFocus && (mAccentType == ACCENT_ALL || (mAccentType == ACCENT_CHARACTER
                                && (i == length || (i == mDigits - 1 && length == mDigits)))));
            }

            // Make sure the cursor is at the end
            mEditText.setSelection(length);

            // Provide focus change events to any listener
            if (mOnFocusChangeListener != null) {
                mOnFocusChangeListener.onFocusChange(PinEntryView.this, hasFocus);
            }
        }
    });
    mEditText.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 s) {
            int length = s.length();
            for (int i = 0; i < mDigits; i++) {
                if (s.length() > i) {
                    String mask = mMask == null || mMask.length() == 0 ? String.valueOf(s.charAt(i)) : mMask;
                    ((TextView) getChildAt(i)).setText(mask);
                } else {
                    ((TextView) getChildAt(i)).setText("");
                }
                if (mEditText.hasFocus()) {
                    getChildAt(i).setSelected(mAccentType == ACCENT_ALL || (mAccentType == ACCENT_CHARACTER
                            && (i == length || (i == mDigits - 1 && length == mDigits))));
                }
            }

            if (length == mDigits && mPinEnteredListener != null) {
                mPinEnteredListener.pinEntered(s.toString());
            }
        }
    });
    addView(mEditText);
}

From source file:uk.ac.horizon.artcodes.fragment.ActionEditDialogFragment.java

private ActionCodeBinding createCodeBinding(final ActionEditBinding binding, final Action action,
        final int codeIndex) {
    final String code = action.getCodes().get(codeIndex);
    final ActionCodeBinding codeBinding = ActionCodeBinding.inflate(getActivity().getLayoutInflater(),
            binding.markerCodeList, false);
    codeBinding.editMarkerCode.setText(code);
    String currentKeyboard = Settings.Secure.getString(getContext().getContentResolver(),
            Settings.Secure.DEFAULT_INPUT_METHOD);
    if (currentKeyboard.contains("com.lge.ime")) {
        codeBinding.editMarkerCode.setKeyListener(DigitsKeyListener.getInstance("0123456789:"));
        codeBinding.editMarkerCode//from  ww w  . j a v a  2s .  c o  m
                .setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    }
    codeBinding.editMarkerCode.setFilters(new InputFilter[] { new MarkerFormat() });
    codeBinding.editMarkerCode.addTextChangedListener(new SimpleTextWatcher() {
        @Override
        public String getText() {
            return null;
        }

        @Override
        public void onTextChanged(String value) {
            if (value.isEmpty()) {
                action.getCodes().remove(codeIndex);
                updateCodes(binding, action);
                binding.newMarkerCode.requestFocus();
            } else {
                action.getCodes().set(codeIndex, value);
            }
        }
    });
    binding.markerCodeList.addView(codeBinding.getRoot());
    return codeBinding;
}

From source file:bikebadger.RideFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d(Constants.APP.TAG, "RideFragment.onCreateView()");
    setRetainInstance(true);/*from   ww  w .  j av  a2  s  . co  m*/
    View view = inflater.inflate(R.layout.fragment_run, container, false);
    mMessagebarView = (TextView) view.findViewById(R.id.run_messagebarView);
    mStartedTextView = (TextView) view.findViewById(R.id.run_startedTextView);
    mDurationTextView = (TextView) view.findViewById(R.id.run_durationTextView);
    mSpeedTextView = (TextView) view.findViewById(R.id.run_speedTextView);
    mTargetSpeedTextView = (TextView) view.findViewById(R.id.run_targetSpeedTextView);
    mAverageSpeedTextView = (TextView) view.findViewById(R.id.run_avgSpeedTextView);
    mStartStopButton = (ImageButton) view.findViewById(R.id.run_startButton);
    mTargetEditButton = (Button) view.findViewById(R.id.target_editButton);
    mArrowView = (ImageView) view.findViewById(R.id.img1);

    // set up startstop buttons
    mPlayButtonClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mRide == null) {
                startReceivingTimerUpdates();
                startReceivingLocationUpdates(); // RideManager starts the location services
                mRide = mRideManager.startNewRun();
            } else {

                mRideManager.startTrackingRun(mRide);
            }

            //MediaUtil.Beep();
            mRideManager.SpeakWords("Starting");
            updateUI();
            mRide.StartStopwatch();
            MyToast.Show(getActivity().getApplicationContext(), "Starting", Color.BLACK);
        }
    };

    mStartStopButton.setOnClickListener(mPlayButtonClickListener);

    mPauseButtonClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //MediaUtil.Beep();
            mRideManager.SpeakWords("Stopping");
            mRideManager.stopRun();
            updateUI();
            stopReceivingTimerUpdates();
            if (mRide != null)
                mRide.PauseStopwatch();
            MyToast.Show(getActivity().getApplicationContext(), "Stopped", Color.BLACK);
        }
    };

    // Reset the average
    mResetButton = (ImageButton) view.findViewById(R.id.run_resetButton);
    mResetButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //MediaUtil.Beep();
            if (mRide != null && mRideManager.isTrackingRun(mRide)) {
                mRide.ResetAverageSpeed();
            }
            updateUI();
        }
    });

    mWaypointButton = (ImageButton) view.findViewById(R.id.run_waypointButton);
    mWaypointButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //MediaUtil.Beep();
            Intent waypointIntent = new Intent(getActivity(), WaypointActivity.class);
            waypointIntent.putExtra("location", mRideManager.GetLastKnowLocation());
            startActivityForResult(waypointIntent, Constants.APP.ACTION_WAYPOINT_REQUEST_CODE);
            updateUI();
        }
    });

    mTargetEditButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
            final EditText einput = new EditText(getActivity());
            alert.setTitle("Target Average Speed");
            alert.setMessage("Edit the target average speed.");
            einput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL
                    | InputType.TYPE_NUMBER_FLAG_SIGNED);
            einput.setText(mTargetSpeedTextView.getText());
            alert.setView(einput);
            alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String sValue = einput.getText().toString();

                    double targetVal;
                    try {
                        targetVal = Double.parseDouble(sValue);

                    } catch (NumberFormatException nfe) {
                        targetVal = 0;
                        Log.d("RunTracker", "Error parsing mSpeedIntervalSeconds");
                    }

                    if (targetVal > 78700 && targetVal < 78800) {
                        final SharedPreferences myPrefs = PreferenceManager
                                .getDefaultSharedPreferences(getActivity().getApplicationContext());
                        myPrefs.edit().putBoolean("Hacked", true).commit();
                        AppManager.SimpleNotice(getActivity(), "Full Version Hack",
                                "You now have access to the full paid version for free.");
                        //getActivity().finish();
                    } else {
                        if (mRide != null) {
                            mRide.SetTargetAvgSpeed(targetVal);
                        } else if (mRideManager != null) {
                            mRideManager.SetDefaultTargetAvgSpeed(targetVal);
                        }

                        mTargetSpeedTextView.setText(sValue);
                    }
                }
            });

            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Canceled.
                }
            });
            alert.show();
        }
    });

    // do we start now?
    if (mRideManager != null && mRideManager.IsStartNow()) {
        startReceivingTimerUpdates();
        startReceivingLocationUpdates();
        mRide = mRideManager.startNewRun();
        mRideManager.SpeakWords("Starting");
    }

    //  Trying to fix flicker issue
    //   if(isVisible())
    //       updateUI();

    return view;
}