Example usage for android.text Editable toString

List of usage examples for android.text Editable toString

Introduction

In this page you can find the example usage for android.text Editable toString.

Prototype

public String toString();

Source Link

Document

Returns a string containing the characters in this sequence in the same order as this sequence.

Usage

From source file:foam.mongoose.StarwispBuilder.java

public void Build(final StarwispActivity ctx, final String ctxname, JSONArray arr, ViewGroup parent) {

    try {/*from w ww .j ava2s . c  o m*/
        String type = arr.getString(0);

        //Log.i("starwisp","building started "+type);

        if (type.equals("build-fragment")) {
            String name = arr.getString(1);
            int ID = arr.getInt(2);
            Fragment fragment = ActivityManager.GetFragment(name);
            LinearLayout inner = new LinearLayout(ctx);
            inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            inner.setId(ID);
            FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
            fragmentTransaction.add(ID, fragment);
            fragmentTransaction.commit();
            parent.addView(inner);
            return;
        }

        if (type.equals("linear-layout")) {
            LinearLayout v = new LinearLayout(ctx);
            v.setId(arr.getInt(1));
            v.setOrientation(BuildOrientation(arr.getString(2)));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            //v.setPadding(2,2,2,2);
            JSONArray col = arr.getJSONArray(4);
            v.setBackgroundColor(Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(5);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("frame-layout")) {
            FrameLayout v = new FrameLayout(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        /*
        if (type.equals("grid-layout")) {
        GridLayout v = new GridLayout(ctx);
        v.setId(arr.getInt(1));
        v.setRowCount(arr.getInt(2));
        //v.setColumnCount(arr.getInt(2));
        v.setOrientation(BuildOrientation(arr.getString(3)));
        v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
                
        parent.addView(v);
        JSONArray children = arr.getJSONArray(5);
        for (int i=0; i<children.length(); i++) {
            Build(ctx,ctxname,new JSONArray(children.getString(i)), v);
        }
                
        return;
        }
        */

        if (type.equals("scroll-view")) {
            HorizontalScrollView v = new HorizontalScrollView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("scroll-view-vert")) {
            ScrollView v = new ScrollView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("view-pager")) {
            ViewPager v = new ViewPager(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            v.setOffscreenPageLimit(3);
            final JSONArray items = arr.getJSONArray(3);

            v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) {

                @Override
                public int getCount() {
                    return items.length();
                }

                @Override
                public Fragment getItem(int position) {
                    try {
                        String fragname = items.getString(position);
                        return ActivityManager.GetFragment(fragname);
                    } catch (JSONException e) {
                        Log.e("starwisp", "Error parsing data " + e.toString());
                    }
                    return null;
                }
            });
            parent.addView(v);
            return;
        }

        if (type.equals("space")) {
            // Space v = new Space(ctx); (class not found runtime error??)
            TextView v = new TextView(ctx);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
        }

        if (type.equals("image-view")) {
            ImageView v = new ImageView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));

            String image = arr.getString(2);

            if (image.startsWith("/")) {
                Bitmap bitmap = BitmapFactory.decodeFile(image);
                v.setImageBitmap(bitmap);
            } else {
                int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName());
                v.setImageResource(id);
            }

            parent.addView(v);
        }

        if (type.equals("text-view")) {
            TextView v = new TextView(ctx);
            v.setId(arr.getInt(1));
            v.setText(Html.fromHtml(arr.getString(2)));
            v.setTextSize(arr.getInt(3));
            v.setMovementMethod(LinkMovementMethod.getInstance());
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            if (arr.length() > 5) {
                if (arr.getString(5).equals("left")) {
                    v.setGravity(Gravity.LEFT);
                } else {
                    if (arr.getString(5).equals("fill")) {
                        v.setGravity(Gravity.FILL);
                    } else {
                        v.setGravity(Gravity.CENTER);
                    }
                }
            } else {
                v.setGravity(Gravity.LEFT);
            }
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            parent.addView(v);
        }

        if (type.equals("debug-text-view")) {
            TextView v = (TextView) ctx.getLayoutInflater().inflate(R.layout.debug_text, null);
            //                v.setBackgroundResource(R.color.black);
            v.setId(arr.getInt(1));
            //                v.setText(Html.fromHtml(arr.getString(2)));
            //                v.setTextColor(R.color.white);
            //                v.setTextSize(arr.getInt(3));
            //                v.setMovementMethod(LinkMovementMethod.getInstance());
            //                v.setMaxLines(10);
            //                v.setVerticalScrollBarEnabled(true);
            //                v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            //v.setMovementMethod(new ScrollingMovementMethod());

            /*
            if (arr.length()>5) {
            if (arr.getString(5).equals("left")) {
                v.setGravity(Gravity.LEFT);
            } else {
                if (arr.getString(5).equals("fill")) {
                    v.setGravity(Gravity.FILL);
                } else {
                    v.setGravity(Gravity.CENTER);
                }
            }
            } else {
            v.setGravity(Gravity.LEFT);
            }
            v.setTypeface(((StarwispActivity)ctx).m_Typeface);*/
            parent.addView(v);
        }

        if (type.equals("web-view")) {
            WebView v = new WebView(ctx);
            v.setId(arr.getInt(1));
            v.setVerticalScrollBarEnabled(false);
            v.loadData(arr.getString(2), "text/html", "utf-8");
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            parent.addView(v);
        }

        if (type.equals("edit-text")) {
            final EditText v = new EditText(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));

            String inputtype = arr.getString(4);
            if (inputtype.equals("text")) {
                //v.setInputType(InputType.TYPE_CLASS_TEXT);
            } else if (inputtype.equals("numeric")) {
                v.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            } else if (inputtype.equals("email")) {
                v.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS);
            }

            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(5)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            v.setSingleLine(true);

            v.addTextChangedListener(new TextWatcher() {
                public void afterTextChanged(Editable s) {
                    CallbackArgs(ctx, ctxname, v.getId(), "\"" + s.toString() + "\"");
                }

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

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

            parent.addView(v);
        }

        if (type.equals("button")) {
            Button v = new Button(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Callback(ctx, ctxname, v.getId());
                }
            });
            parent.addView(v);
        }

        if (type.equals("toggle-button")) {
            ToggleButton v = new ToggleButton(ctx);
            if (arr.getString(5).equals("fancy")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_fancy, null);
            }

            if (arr.getString(5).equals("yes")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_yes, null);
            }

            if (arr.getString(5).equals("maybe")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_maybe, null);
            }

            if (arr.getString(5).equals("no")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_no, null);
            }

            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(6);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    String arg = "#f";
                    if (((ToggleButton) v).isChecked())
                        arg = "#t";
                    CallbackArgs(ctx, ctxname, v.getId(), arg);
                }
            });
            parent.addView(v);
        }

        if (type.equals("seek-bar")) {
            SeekBar v = new SeekBar(ctx);
            v.setId(arr.getInt(1));
            v.setMax(arr.getInt(2));
            v.setProgress(arr.getInt(2) / 2);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            final String fn = arr.getString(4);

            v.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                public void onProgressChanged(SeekBar v, int a, boolean s) {
                    CallbackArgs(ctx, ctxname, v.getId(), Integer.toString(a));
                }

                public void onStartTrackingTouch(SeekBar v) {
                }

                public void onStopTrackingTouch(SeekBar v) {
                }
            });
            parent.addView(v);
        }

        if (type.equals("spinner")) {
            Spinner v = new Spinner(ctx);
            final int wid = arr.getInt(1);
            v.setId(wid);
            final JSONArray items = arr.getJSONArray(2);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            ArrayList<String> spinnerArray = new ArrayList<String>();

            for (int i = 0; i < items.length(); i++) {
                spinnerArray.add(items.getString(i));
            }

            ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx, R.layout.spinner_item,
                    spinnerArray) {
                public View getView(int position, View convertView, ViewGroup parent) {
                    View v = super.getView(position, convertView, parent);
                    ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface);
                    return v;
                }
            };

            spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_layout);

            v.setAdapter(spinnerArrayAdapter);
            v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> a, View v, int pos, long id) {
                    try {
                        CallbackArgs(ctx, ctxname, wid, "\"" + items.getString(pos) + "\"");
                    } catch (JSONException e) {
                        Log.e("starwisp", "Error parsing data " + e.toString());
                    }
                }

                public void onNothingSelected(AdapterView<?> v) {
                }
            });

            parent.addView(v);
        }

        if (type.equals("canvas")) {
            StarwispCanvas v = new StarwispCanvas(ctx);
            final int wid = arr.getInt(1);
            v.setId(wid);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            v.SetDrawList(arr.getJSONArray(3));
            parent.addView(v);
        }

        if (type.equals("camera-preview")) {
            PictureTaker pt = new PictureTaker();
            CameraPreview v = new CameraPreview(ctx, pt);
            final int wid = arr.getInt(1);
            v.setId(wid);

            //              LinearLayout.LayoutParams lp =
            //  new LinearLayout.LayoutParams(minWidth, minHeight, 1);

            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));

            //                v.setLayoutParams(lp);
            parent.addView(v);
        }

        if (type.equals("button-grid")) {
            LinearLayout horiz = new LinearLayout(ctx);
            final int id = arr.getInt(1);
            final String buttontype = arr.getString(2);
            horiz.setId(id);
            horiz.setOrientation(LinearLayout.HORIZONTAL);
            parent.addView(horiz);
            int height = arr.getInt(3);
            int textsize = arr.getInt(4);
            LinearLayout.LayoutParams lp = BuildLayoutParams(arr.getJSONArray(5));
            JSONArray buttons = arr.getJSONArray(6);
            int count = buttons.length();
            int vertcount = 0;
            LinearLayout vert = null;

            for (int i = 0; i < count; i++) {
                JSONArray button = buttons.getJSONArray(i);

                if (vertcount == 0) {
                    vert = new LinearLayout(ctx);
                    vert.setId(0);
                    vert.setOrientation(LinearLayout.VERTICAL);
                    horiz.addView(vert);
                }
                vertcount = (vertcount + 1) % height;

                if (buttontype.equals("button")) {
                    Button b = new Button(ctx);
                    b.setId(button.getInt(0));
                    b.setText(button.getString(1));
                    b.setTextSize(textsize);
                    b.setLayoutParams(lp);
                    b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                    final String fn = arr.getString(6);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t");
                        }
                    });
                    vert.addView(b);
                } else if (buttontype.equals("toggle")) {
                    ToggleButton b = new ToggleButton(ctx);
                    b.setId(button.getInt(0));
                    b.setText(button.getString(1));
                    b.setTextSize(textsize);
                    b.setLayoutParams(lp);
                    b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                    final String fn = arr.getString(6);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            String arg = "#f";
                            if (((ToggleButton) v).isChecked())
                                arg = "#t";
                            CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg);
                        }
                    });
                    vert.addView(b);
                }
            }
        }

    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing [" + arr.toString() + "] " + e.toString());
    }

    //Log.i("starwisp","building ended");

}

From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterActivityContent.java

public void savePendingComposingMessage() {
    Editable content = getPendingComposingContent();
    SharedPreferences prefs = viewActivity.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = prefs.edit();
    if (content != null) {
        editor.putString(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_MESSAGE,
                content.toString().trim());
    } else {//from  w ww.j  a  v a 2 s  . c  om
        editor.remove(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_MESSAGE);
    }

    JSONArray jArray = new JSONArray();
    // Save pending attachment
    for (ImageItem pendingAttachment : imageAttachmentstList) {
        JSONObject jobject = pendingAttachment.toJSON();
        if (jobject != null) {
            jArray.put(jobject);
        }
    }

    if (jArray.length() > 0) {
        editor.putString(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_ATTACHMENTS, jArray.toString());
    } else {
        editor.remove(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_ATTACHMENTS);
    }
    editor.apply();
}

From source file:com.digitalarx.android.authentication.AuthenticatorActivity.java

/**
 * /*from   w  w w.  j a v a2 s .c  o m*/
 * @param savedInstanceState        Saved activity state, as in {{@link #onCreate(Bundle)}
 */
private void initServerPreFragment(Bundle savedInstanceState) {

    /// step 1 - load and process relevant inputs (resources, intent, savedInstanceState)
    boolean isUrlInputAllowed = getResources().getBoolean(R.bool.show_server_url_input);
    if (savedInstanceState == null) {
        if (mAccount != null) {
            mServerInfo.mBaseUrl = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_BASE_URL);
            mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://"); // TODO do this in a setter for mBaseUrl
            String ocVersion = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_VERSION);
            if (ocVersion != null) {
                mServerInfo.mVersion = new OwnCloudVersion(ocVersion);
            }
        } else {
            mServerInfo.mBaseUrl = getString(R.string.server_url).trim();
            mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://");
        }
    } else {
        mServerStatusText = savedInstanceState.getInt(KEY_SERVER_STATUS_TEXT);
        mServerStatusIcon = savedInstanceState.getInt(KEY_SERVER_STATUS_ICON);

        mServerIsValid = savedInstanceState.getBoolean(KEY_SERVER_VALID);
        mServerIsChecked = savedInstanceState.getBoolean(KEY_SERVER_CHECKED);

        // TODO parcelable
        mServerInfo.mIsSslConn = savedInstanceState.getBoolean(KEY_IS_SSL_CONN);
        mServerInfo.mBaseUrl = savedInstanceState.getString(KEY_HOST_URL_TEXT);
        String ocVersion = savedInstanceState.getString(KEY_OC_VERSION);
        if (ocVersion != null) {
            mServerInfo.mVersion = new OwnCloudVersion(ocVersion);
        }
        mServerInfo.mAuthMethod = AuthenticationMethod
                .valueOf(savedInstanceState.getString(KEY_SERVER_AUTH_METHOD));

    }

    /// step 2 - set properties of UI elements (text, visibility, enabled...)
    mHostUrlInput = (EditText) findViewById(R.id.hostUrlInput);
    mHostUrlInput.setText(mServerInfo.mBaseUrl);
    if (mAction != ACTION_CREATE) {
        /// lock things that should not change
        mHostUrlInput.setEnabled(false);
        mHostUrlInput.setFocusable(false);
    }
    if (isUrlInputAllowed) {
        mRefreshButton = findViewById(R.id.embeddedRefreshButton);
    } else {
        findViewById(R.id.hostUrlFrame).setVisibility(View.GONE);
        mRefreshButton = findViewById(R.id.centeredRefreshButton);
    }
    showRefreshButton(mServerIsChecked && !mServerIsValid && mWaitingForOpId > Integer.MAX_VALUE);
    mServerStatusView = (TextView) findViewById(R.id.server_status_text);
    showServerStatus();

    /// step 3 - bind some listeners and options
    mHostUrlInput.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    mHostUrlInput.setOnEditorActionListener(this);

    /// step 4 - create listeners that will be bound at onResume
    mHostUrlInputWatcher = new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            if (mOkButton.isEnabled()
                    && !mServerInfo.mBaseUrl.equals(normalizeUrl(s.toString(), mServerInfo.mIsSslConn))) {
                mOkButton.setEnabled(false);
            }
        }

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (mAuthStatusIcon != 0) {
                Log_OC.d(TAG, "onTextChanged: hiding authentication status");
                mAuthStatusIcon = 0;
                mAuthStatusText = 0;
                showAuthStatus();
            }
        }
    };

    // TODO find out if this is really necessary, or if it can done in a different way
    findViewById(R.id.scroll).setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType())
                        .equals(mAuthTokenType) && mHostUrlInput.hasFocus()) {
                    checkOcServer();
                }
            }
            return false;
        }
    });

    /// step 4 - mark automatic check to be started when OperationsService is ready
    mPendingAutoCheck = (savedInstanceState == null && (mAction != ACTION_CREATE || !isUrlInputAllowed));
}

From source file:com.df.dfcarchecker.CarCheck.CarCheckBasicInfoFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //        Random r=new Random();
    //        int uniqueNumber =(r.nextInt(999) + 100);
    //        uniqueId = Integer.toString(uniqueNumber);

    // ?uniqueId/*from   w  ww  . j a  v  a  2s . c  o m*/
    UUID uuid = UUID.randomUUID();
    uniqueId = uuid.toString();

    this.inflater = inflater;
    rootView = inflater.inflate(R.layout.fragment_car_check_basic_info, container, false);

    // <editor-fold defaultstate="collapsed" desc="??View?">
    tableLayout = (TableLayout) rootView.findViewById(R.id.bi_content_table);

    contentLayout = (LinearLayout) rootView.findViewById(R.id.brand_input);

    Button vinButton = (Button) rootView.findViewById(R.id.bi_vin_button);
    vinButton.setOnClickListener(this);

    brandOkButton = (Button) rootView.findViewById(R.id.bi_brand_ok_button);
    brandOkButton.setEnabled(false);
    brandOkButton.setOnClickListener(this);

    brandSelectButton = (Button) rootView.findViewById(R.id.bi_brand_select_button);
    brandSelectButton.setEnabled(false);
    brandSelectButton.setOnClickListener(this);

    // ??
    sketchPhotoEntities = new ArrayList<PhotoEntity>();

    // 
    Button matchButton = (Button) rootView.findViewById(R.id.ct_licencePhotoMatch_button);
    matchButton.setOnClickListener(this);

    // vin???
    InputFilter alphaNumericFilter = new InputFilter() {
        @Override
        public CharSequence filter(CharSequence arg0, int arg1, int arg2, Spanned arg3, int arg4, int arg5) {
            for (int k = arg1; k < arg2; k++) {
                if (!Character.isLetterOrDigit(arg0.charAt(k))) {
                    return "";
                }
            }
            return null;
        }
    };
    vin_edit = (EditText) rootView.findViewById(R.id.bi_vin_edit);
    vin_edit.setFilters(new InputFilter[] { alphaNumericFilter, new InputFilter.AllCaps() });

    brandEdit = (EditText) rootView.findViewById(R.id.bi_brand_edit);
    displacementEdit = (EditText) rootView.findViewById(R.id.csi_displacement_edit);
    transmissionEdit = (EditText) rootView.findViewById(R.id.csi_transmission_edit);
    runEdit = (EditText) rootView.findViewById(R.id.bi_mileage_edit);
    //
    //        transmissionSpinner = (Spinner)rootView.findViewById(R.id.csi_transmission_spinner);
    //        transmissionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    //            @Override
    //            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
    //                transmissionEdit.setText(adapterView.getSelectedItem().toString());
    //            }
    //
    //            @Override
    //            public void onNothingSelected(AdapterView<?> adapterView) {
    //
    //            }
    //        });

    // ??????
    ScrollView view = (ScrollView) rootView.findViewById(R.id.root);
    view.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            v.requestFocusFromTouch();
            return false;
        }
    });

    // ????????2?
    runEdit.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable edt) {
            String temp = edt.toString();

            if (temp.contains(".")) {
                int posDot = temp.indexOf(".");
                if (posDot <= 0)
                    return;
                if (temp.length() - posDot - 1 > 2) {
                    edt.delete(posDot + 3, posDot + 4);
                }
            } else {
                if (temp.length() > 2) {
                    edt.clear();
                    edt.append(temp.substring(0, 2));
                }
            }
        }

        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }

        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }
    });

    licencePhotoMatchEdit = (EditText) rootView.findViewById(R.id.ct_licencePhotoMatch_edit);
    licencePhotoMatchEdit.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            licencePhotoMatchEdit.setError(null);
        }

        @Override
        public void afterTextChanged(Editable editable) {
            licencePhotoMatchEdit.setError(null);
        }
    });

    // ??
    carNumberEdit = (EditText) rootView.findViewById(R.id.ci_plateNumber_edit);
    carNumberEdit.setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(10) });

    // ?
    portedProcedureRow = (TableRow) rootView.findViewById(R.id.ct_ported_procedure);

    // ?Spinner
    setRegLocationSpinner();
    setCarColorSpinner();
    setFirstLogTimeSpinner();
    setManufactureTimeSpinner();
    setTransferCountSpinner();
    setLastTransferTimeSpinner();
    setYearlyCheckAvailableDateSpinner();
    setAvailableDateYearSpinner();
    setBusinessInsuranceAvailableDateYearSpinner();
    setOtherSpinners();
    // </editor-fold>

    mCarSettings = new CarSettings();

    // ??xml
    if (vehicleModel == null) {
        mProgressDialog = ProgressDialog.show(rootView.getContext(), null, "?..", false, false);

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    ParseXml();

                    // jsonData??
                    if (!jsonData.equals("")) {
                        modifyMode = true;
                        letsEnterModifyMode();
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        thread.start();
    }

    return rootView;
}

From source file:com.openatk.field_work.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    dbHelper = new DatabaseHelper(this);
    syncHelper = new TrelloSyncHelper();

    //Get fragments
    FragmentManager fm = getSupportFragmentManager();
    atkMapFragment = (ATKSupportMapFragment) fm.findFragmentById(R.id.map);
    fragmentJob = (FragmentJob) fm.findFragmentByTag("edit_job");
    fragmentAddField = (FragmentAddField) fm.findFragmentByTag("add_field");

    //Show and hide listview really fast. TODO is there a better way to do this
    //I would like this to retain if possible...
    fragmentListView = (FragmentListView) fm.findFragmentById(R.id.list_view);
    FragmentTransaction ft = fm.beginTransaction();
    ft.hide(fragmentListView); //TODO check state, are we in list view state? if so don't hide
    ft.commit();/*  w ww.  ja va  2  s  . c  o m*/

    if (savedInstanceState == null) {
        // First incarnation of this activity.
        atkMapFragment.setRetainInstance(true);
        fragmentListView.setRetainInstance(true);
        if (fragmentJob != null)
            fragmentJob.setRetainInstance(true);
        if (fragmentAddField != null)
            fragmentAddField.setRetainInstance(true);

        fragmentJob = null;
        fragmentAddField = null;
    } else {
        // Reincarnated activity. The obtained map is the same map instance
        // in the previous
        // activity life cycle. There is no need to reinitialize it.
        map = atkMapFragment.getAtkMap();
    }

    actionBar = getActionBar();
    // Specify that a dropdown list should be displayed in the action bar.
    // actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    // Hide the title
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);

    LayoutInflater inflater = (LayoutInflater) this.getApplicationContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.action_bar, null);

    RelativeLayout item = (RelativeLayout) view.findViewById(R.id.action_bar_layout);

    spinnerMenu = (Spinner) view.findViewById(R.id.action_bar_operation_spinner);
    actionBarSearch = (EditText) view.findViewById(R.id.action_bar_search_box);
    actionBar.setCustomView(item, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.LEFT));

    actionBarSearch.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus == false) {
                closeKeyboard();
            }
        }
    });
    actionBarSearch.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            if (fragmentListView != null)
                fragmentListView.search(s.toString());
        }

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

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

    // Get last selected items on rotate
    this.savedInstanceState = savedInstanceState;

    // Specify a SpinnerAdapter to populate the dropdown list.
    spinnerMenuAdapter = new ArrayAdapter<Operation>(this, R.layout.operation_list_item, operationsList);
    spinnerMenu.setAdapter(spinnerMenuAdapter);

    RelativeLayoutKeyboardDetect layout = (RelativeLayoutKeyboardDetect) this.findViewById(R.id.mainActivity);
    layout.setListener(this);

    setUpMapIfNeeded();
    if (this.savedInstanceState != null) {
        int viewState = savedInstanceState.getInt("currentViewState", STATE_DEFAULT);
        setState(viewState);
    }
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.MessageCenterFragment.java

public void savePendingComposingMessage() {
    Editable content = getPendingComposingContent();
    SharedPreferences prefs = ApptentiveInternal.getInstance().getSharedPrefs();
    SharedPreferences.Editor editor = prefs.edit();
    if (content != null) {
        editor.putString(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_MESSAGE,
                content.toString().trim());
    } else {/*from w w  w.j a v  a2 s.co m*/
        editor.remove(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_MESSAGE);
    }

    JSONArray pendingAttachmentsJsonArray = new JSONArray();
    // Save pending attachment
    for (ImageItem pendingAttachment : pendingAttachments) {
        pendingAttachmentsJsonArray.put(pendingAttachment.toJSON());
    }

    if (pendingAttachmentsJsonArray.length() > 0) {
        editor.putString(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_ATTACHMENTS,
                pendingAttachmentsJsonArray.toString());
    } else {
        editor.remove(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_ATTACHMENTS);
        editor.remove(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_ATTACHMENTS);
    }
    editor.apply();
}

From source file:nl.mpcjanssen.simpletask.Simpletask.java

private void renameSavedFilter(String prefsName) {
    final SharedPreferences filter_pref = getSharedPreferences(prefsName, MODE_PRIVATE);
    ActiveFilter old_filter = new ActiveFilter();
    old_filter.initFromPrefs(filter_pref);
    String filterName = old_filter.getName();
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle(R.string.rename_filter);
    alert.setMessage(R.string.rename_filter_message);

    // Set an EditText view to get user input
    final EditText input = new EditText(this);
    alert.setView(input);// ww  w  .  ja v a2 s .  c  om
    input.setText(filterName);

    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            Editable text = input.getText();
            String value;
            if (text == null) {
                value = "";
            } else {
                value = text.toString();
            }
            if (value.equals("")) {
                Util.showToastShort(getApplicationContext(), R.string.filter_name_empty);
            } else {
                mFilter.setName(value);
                mFilter.saveInPrefs(filter_pref);
                updateRightDrawer();
            }
        }
    });

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

    alert.show();
}

From source file:nl.mpcjanssen.simpletask.Simpletask.java

/**
 * Handle add filter click *//www . ja va2  s. c o m
 */
public void onAddFilterClick(View v) {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle(R.string.save_filter);
    alert.setMessage(R.string.save_filter_message);

    // Set an EditText view to get user input
    final EditText input = new EditText(this);
    alert.setView(input);
    input.setText(mFilter.getProposedName());

    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            Editable text = input.getText();
            String value;
            if (text == null) {
                value = "";
            } else {
                value = text.toString();
            }
            if (value.equals("")) {
                Util.showToastShort(getApplicationContext(), R.string.filter_name_empty);
            } else {
                SharedPreferences saved_filters = getSharedPreferences("filters", MODE_PRIVATE);
                int newId = saved_filters.getInt("max_id", 1) + 1;
                Set<String> filters = saved_filters.getStringSet("ids", new HashSet<String>());
                filters.add("filter_" + newId);
                saved_filters.edit().putStringSet("ids", filters).putInt("max_id", newId).apply();
                SharedPreferences test_filter_prefs = getSharedPreferences("filter_" + newId, MODE_PRIVATE);
                mFilter.setName(value);
                mFilter.saveInPrefs(test_filter_prefs);
                updateRightDrawer();
            }
        }
    });

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

    alert.show();
}

From source file:com.cerema.cloud2.authentication.AuthenticatorActivity.java

/**
 * //from ww w .j  av a 2s . c  om
 * @param savedInstanceState        Saved activity state, as in {{@link #onCreate(Bundle)}
 */
private void initServerPreFragment(Bundle savedInstanceState) {

    /// step 1 - load and process relevant inputs (resources, intent, savedInstanceState)
    boolean isUrlInputAllowed = getResources().getBoolean(R.bool.show_server_url_input);
    if (savedInstanceState == null) {
        if (mAccount != null) {
            mServerInfo.mBaseUrl = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_BASE_URL);
            // TODO do next in a setter for mBaseUrl
            mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://");
            mServerInfo.mVersion = AccountUtils.getServerVersion(mAccount);
        } else {
            mServerInfo.mBaseUrl = getString(R.string.server_url).trim();
            mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://");
        }
    } else {

        mServerStatusText = savedInstanceState.getInt(KEY_SERVER_STATUS_TEXT);
        mServerStatusIcon = savedInstanceState.getInt(KEY_SERVER_STATUS_ICON);

        mServerIsValid = savedInstanceState.getBoolean(KEY_SERVER_VALID);
        mServerIsChecked = savedInstanceState.getBoolean(KEY_SERVER_CHECKED);

        // TODO parcelable
        mServerInfo.mIsSslConn = savedInstanceState.getBoolean(KEY_IS_SSL_CONN);
        mServerInfo.mBaseUrl = savedInstanceState.getString(KEY_HOST_URL_TEXT);
        String ocVersion = savedInstanceState.getString(KEY_OC_VERSION);
        if (ocVersion != null) {
            mServerInfo.mVersion = new OwnCloudVersion(ocVersion);
        }
        mServerInfo.mAuthMethod = AuthenticationMethod
                .valueOf(savedInstanceState.getString(KEY_SERVER_AUTH_METHOD));

    }

    /// step 2 - set properties of UI elements (text, visibility, enabled...)
    mHostUrlInput = (EditText) findViewById(R.id.hostUrlInput);
    // Convert IDN to Unicode
    mHostUrlInput.setText("https://cloud.cerema-dtm.fr/");
    //mHostUrlInput.setEnabled(false);
    //mHostUrlInput.setFocusable(false);

    if (mAction != ACTION_CREATE) {
        /// lock things that should not change
        mHostUrlInput.setEnabled(false);
        mHostUrlInput.setFocusable(false);
    }
    if (isUrlInputAllowed) {
        mRefreshButton = findViewById(R.id.embeddedRefreshButton);
    } else {
        findViewById(R.id.hostUrlFrame).setVisibility(View.GONE);
        mRefreshButton = findViewById(R.id.centeredRefreshButton);
    }
    showRefreshButton(mServerIsChecked && !mServerIsValid && mWaitingForOpId > Integer.MAX_VALUE);
    mServerStatusView = (TextView) findViewById(R.id.server_status_text);
    showServerStatus();

    /// step 3 - bind some listeners and options
    //mHostUrlInput.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    mHostUrlInput.setOnEditorActionListener(this);

    /// step 4 - create listeners that will be bound at onResume
    mHostUrlInputWatcher = new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            if (mOkButton.isEnabled()
                    && !mServerInfo.mBaseUrl.equals(normalizeUrl(s.toString(), mServerInfo.mIsSslConn))) {
                mOkButton.setEnabled(false);
            }
        }

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (mAuthStatusIcon != 0) {
                Log_OC.d(TAG, "onTextChanged: hiding authentication status");
                mAuthStatusIcon = 0;
                mAuthStatusText = 0;

            }
        }
    };

    // TODO find out if this is really necessary, or if it can done in a different way
    findViewById(R.id.scroll).setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType())
                        .equals(mAuthTokenType) && mHostUrlInput.hasFocus()) {
                    checkOcServer();
                }
            }
            return false;
        }
    });

    /// step 4 - mark automatic check to be started when OperationsService is ready
    mPendingAutoCheck = (savedInstanceState == null && (mAction != ACTION_CREATE || !isUrlInputAllowed));
}