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:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterActivityContent.java

@Override
public void onFinishComposing() {
    messageCenterListAdapter.setForceShowKeyboard(false);
    Util.hideSoftKeyboard(viewActivity, viewActivity.findViewById(android.R.id.content));
    if (contextualMessage != null) {
        unsendMessagesCount++;/*from   w w w  . j  a  v a  2 s.c o m*/
        MessageManager.sendMessage(viewActivity.getApplicationContext(), contextualMessage);
        contextualMessage = null;
    }
    Editable content = getPendingComposingContent();
    final String messageText = (content != null) ? content.toString().trim() : "";
    final ArrayList<ImageItem> messageAttachments = new ArrayList<ImageItem>();
    messageAttachments.addAll(imageAttachmentstList);
    // Close all composing UI
    clearComposingUi(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            messages.remove(actionBarItem);
            messages.remove(composingItem);
            actionBarItem = null;
            composingItem = null;
            messageEditText = null;
            messageCenterListAdapter.clearComposing();
            messageCenterListAdapter.notifyDataSetChanged();
            clearPendingComposingMessage();
            // Send out the new message. The delay is added to ensure the CardView showing animation
            // is visible after the keyboard is hidden
            if (!messageText.isEmpty() || imageAttachmentstList.size() != 0) {
                Bundle b = new Bundle();
                b.putString(COMPOSING_EDITTEXT_STATE, messageText);
                b.putParcelableArrayList(COMPOSING_ATTACHMENTS, messageAttachments);
                Message msg = messageCenterViewHandler.obtainMessage(MSG_START_SENDING, messageText);
                msg.setData(b);
                messageCenterViewHandler.sendMessageDelayed(msg, DEFAULT_DELAYMILLIS);
            }

            imageAttachmentstList.clear();
            showFab();
            showProfileButton();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }
    }, null, DEFAULT_DELAYMILLIS);
}

From source file:com.money.manager.ex.transactions.EditTransactionCommonFunctions.java

public void initTransactionNumberControls() {
    // Transaction number

    if (!TextUtils.isEmpty(transactionEntity.getTransactionNumber())) {
        viewHolder.edtTransNumber.setText(transactionEntity.getTransactionNumber());
    }//from  ww  w .  j ava 2 s .  com

    viewHolder.edtTransNumber.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            setDirty(true);

            transactionEntity.setTransactionNumber(editable.toString());
        }
    });

    viewHolder.btnTransNumber.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AccountTransactionRepository repo = new AccountTransactionRepository(getContext());

            String sql = "SELECT MAX(CAST(" + ITransactionEntity.TRANSACTIONNUMBER + " AS INTEGER)) FROM "
                    + repo.getSource() + " WHERE " + ITransactionEntity.ACCOUNTID + "=?";

            String accountId = transactionEntity.getAccountId().toString();
            Cursor cursor = mDatabase.query(sql, accountId);
            if (cursor == null)
                return;

            if (cursor.moveToFirst()) {
                String transNumber = cursor.getString(0);
                if (TextUtils.isEmpty(transNumber)) {
                    transNumber = "0";
                }
                if ((!TextUtils.isEmpty(transNumber)) && TextUtils.isDigitsOnly(transNumber)) {
                    try {
                        // Use Money type to support very large numbers.
                        Money transactionNumber = MoneyFactory.fromString(transNumber);
                        viewHolder.edtTransNumber
                                .setText(transactionNumber.add(MoneyFactory.fromString("1")).toString());
                    } catch (Exception e) {
                        Timber.e(e, "increasing transaction number");
                    }
                }
            }
            cursor.close();
        }
    });
}

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

@Override
public void onCancelComposing() {
    Util.hideSoftKeyboard(hostingActivityRef.get(), getView());

    JSONObject data = new JSONObject();
    try {/*from w  ww .j  a va  2  s.  c  o m*/
        Editable content = getPendingComposingContent();
        int bodyLength = (content != null) ? content.toString().trim().length() : 0;
        data.put("body_length", bodyLength);
    } catch (JSONException e) {
        //
    }
    EngagementModule.engageInternal(hostingActivityRef.get(), interaction,
            MessageCenterInteraction.EVENT_NAME_COMPOSE_CLOSE, data.toString());
    messagingActionHandler.sendMessage(messagingActionHandler.obtainMessage(MSG_REMOVE_COMPOSER));
    if (messageCenterRecyclerViewAdapter != null) {
        addExpectationStatusIfNeeded();
    }
    pendingAttachments.clear();
    composerEditText.getText().clear();
    composingViewSavedState = null;
    clearPendingComposingMessage();
    showFab();
    showProfileButton();
}

From source file:com.ariesmcrae.mymemories.ui.story.EditStoryFragment.java

public StoryData makeStoryDataFromUI() {

    Editable titleEditable = titleET.getText();
    Editable bodyEditable = bodyET.getText();
    String audioLinkEditable = (String) audioLinkET.getText();
    String videoLinkEditable = (String) videoLinkET.getText();
    Editable imageNameEditable = imageNameET.getText();
    String imageMetaDataEditable = (String) imageMetaDataET.getText();
    Editable tagsEditable = tagsET.getText();
    String storyTimeEditable = (String) storyTimeET.getText();
    Editable latitudeEditable = latitudeET.getText();
    Editable longitudeEditable = longitudeET.getText();

    // Try to parse the date into long format
    try {/*from  w  w w .  ja  v  a  2  s  . c  o  m*/
        date = StoryData.FORMAT.parse(storyTimeEditable.toString());
    } catch (ParseException e1) {
        Log.e("CreateStoryFragment", "Date was not parsable, reverting to current time");
        date = new Date();
    }

    long loginId = 0;
    long storyId = 0;
    String title = "";
    String body = "";
    String audioLink = "";
    String videoLink = "";
    String imageName = "";
    String imageMetaData = "";
    String tags = "";
    long creationTime = 0;
    long storyTime = 0;
    double latitude = 0;
    double longitude = 0;

    // pull values from Editables
    title = String.valueOf(titleEditable.toString());
    body = String.valueOf(bodyEditable.toString());
    audioLink = String.valueOf(audioLinkEditable.toString());
    videoLink = String.valueOf(videoLinkEditable.toString());
    imageName = String.valueOf(imageNameEditable.toString());
    imageMetaData = String.valueOf(imageMetaDataEditable.toString());
    tags = String.valueOf(tagsEditable.toString());
    storyTime = date.getTime();
    latitude = Double.valueOf(latitudeEditable.toString());
    longitude = Double.valueOf(longitudeEditable.toString());

    // return new StoryData object with
    return new StoryData(getUniqueKey(), loginId, storyId, title, body, audioLink, videoLink, imageName,
            imageMetaData, tags, creationTime, storyTime, latitude, longitude);

}

From source file:com.ariesmcrae.mymemories.ui.story.CreateStoryFragment.java

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

    // Get the EditTexts
    titleET = (EditText) getView().findViewById(R.id.story_create_value_title);
    bodyET = (EditText) getView().findViewById(R.id.story_create_value_body);
    audioCaptureButton = (Button) getView().findViewById(R.id.story_create_value_audio_link);
    videoCaptureButton = (Button) getView().findViewById(R.id.story_create_value_video_button);
    imageNameET = (EditText) getView().findViewById(R.id.story_create_value_image_name);
    imageCaptureButton = (Button) getView().findViewById(R.id.story_create_value_image_button);
    storyTimeET = (TextView) getView().findViewById(R.id.story_create_value_story_time);
    locationButton = (Button) getView().findViewById(R.id.story_create_value_location_button);

    imageLocation = (TextView) getView().findViewById(R.id.story_create_value_image_location);
    videoLocation = (TextView) getView().findViewById(R.id.story_create_value_video_location);
    audioLocation = (TextView) getView().findViewById(R.id.story_create_value_audio_location);

    latitudeValue = (TextView) getView().findViewById(R.id.story_create_value_latitude);
    longitudeValue = (TextView) getView().findViewById(R.id.story_create_value_longitude);

    buttonClear = (Button) getView().findViewById(R.id.story_create_button_reset);
    buttonCancel = (Button) getView().findViewById(R.id.story_create_button_cancel);
    buttonCreate = (Button) getView().findViewById(R.id.story_create_button_save);

    buttonClear.setOnClickListener(new OnClickListener() {
        @Override//w  w  w .  jav  a2 s. c  om
        public void onClick(View v) {
            titleET.setText("" + "");
            bodyET.setText("" + "");
            imageNameET.setText("" + "");
            imageLocation.setText("" + "");
            videoLocation.setText("" + "");
            audioLocation.setText("" + "");
            storyTimeET.setText("Click text to set");
            latitudeValue.setText("" + "0");
            longitudeValue.setText("" + "0");
        }
    });

    buttonCancel.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (getResources().getBoolean(R.bool.isTablet) == true) {
                // put
                mOpener.openViewStoryFragment(0);
            } else {
                getActivity().finish(); // same as hitting 'back' button
            }
        }
    });
    buttonCreate.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            // local Editables
            Editable titleCreateable = titleET.getText();
            Editable bodyCreateable = bodyET.getText();
            Editable imageNameCreateable = imageNameET.getText();
            String storyTimeCreateable = storyTimeET.getText().toString();

            // Try to parse the date into long format
            try {
                date = StoryData.FORMAT.parse(storyTimeCreateable.toString());
            } catch (ParseException e1) {
                Log.e("CreateStoryFragment", "Date was not parsable, reverting to current time");
                date = new Date();
            }

            // For future expansion: The loginId and storyId need to be
            // generated by the system
            long loginId = 0;
            long storyId = 0;
            String title = "";
            String body = "";
            String audioLink = "";
            String videoLink = "";
            String imageName = "";
            String imageData = "";
            long storyTime = 0;
            double latitude = 0;
            double longitude = 0;

            // pull values from Editables
            title = String.valueOf(titleCreateable.toString());
            body = String.valueOf(bodyCreateable.toString());
            if (audioPath != null)
                audioLink = audioPath;
            if (fileUri != null)
                videoLink = fileUri.toString();
            imageName = String.valueOf(imageNameCreateable.toString());
            if (imagePathFinal != null)
                imageData = imagePathFinal.toString();
            if (loc != null) {
                latitude = loc.getLatitude();
                longitude = loc.getLongitude();
            }
            storyTime = date.getTime();
            Log.i(LOG_TAG, String.valueOf(storyTime));

            // new StoryData object with above info
            StoryData newData = new StoryData(-1,
                    // -1 row index, because there is no way to know which
                    // row it will go into
                    loginId, storyId, title, body, audioLink, videoLink, imageName, imageData, "", 0, storyTime,
                    latitude, longitude);
            Log.d(CreateStoryFragment.class.getCanonicalName(), "imageName" + imageNameET.getText());

            Log.d(CreateStoryFragment.class.getCanonicalName(), "newStoryData:" + newData);

            // insert it through Resolver to be put into ContentProvider
            try {
                resolver.insert(newData);
            } catch (RemoteException e) {
                Log.e(LOG_TAG, "Caught RemoteException => " + e.getMessage());
                e.printStackTrace();
            }
            // return back to proper state
            if (getResources().getBoolean(R.bool.isTablet) == true) {
                // put
                mOpener.openViewStoryFragment(0);
            } else {
                getActivity().finish(); // same as hitting 'back' button
            }
        }
    });

}

From source file:edu.vuum.mocca.ui.story.CreateStoryFragment.java

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

    // Get the EditTexts
    titleET = (EditText) getView().findViewById(R.id.story_create_value_title);
    bodyET = (EditText) getView().findViewById(R.id.story_create_value_body);
    audioCaptureButton = (Button) getView().findViewById(R.id.story_create_value_audio_link);
    videoCaptureButton = (Button) getView().findViewById(R.id.story_create_value_video_button);
    imageNameET = (EditText) getView().findViewById(R.id.story_create_value_image_name);
    imageCaptureButton = (Button) getView().findViewById(R.id.story_create_value_image_button);
    storyTimeET = (TextView) getView().findViewById(R.id.story_create_value_story_time);
    locationButton = (Button) getView().findViewById(R.id.story_create_value_location_button);

    imageLocation = (TextView) getView().findViewById(R.id.story_create_value_image_location);
    videoLocation = (TextView) getView().findViewById(R.id.story_create_value_video_location);
    audioLocation = (TextView) getView().findViewById(R.id.story_create_value_audio_location);

    latitudeValue = (TextView) getView().findViewById(R.id.story_create_value_latitude);
    longitudeValue = (TextView) getView().findViewById(R.id.story_create_value_longitude);

    buttonClear = (Button) getView().findViewById(R.id.story_create_button_reset);
    buttonCancel = (Button) getView().findViewById(R.id.story_create_button_cancel);
    buttonCreate = (Button) getView().findViewById(R.id.story_create_button_save);

    buttonClear.setOnClickListener(new OnClickListener() {
        @Override//from  www .  j a v  a2  s. c  o m
        public void onClick(View v) {
            titleET.setText("" + "");
            bodyET.setText("" + "");
            videoCaptureButton.setText("" + "");
            imageNameET.setText("" + "");
            imageCaptureButton.setText("" + "");
            storyTimeET.setText("" + 0);
            locationButton.setText("" + 0);
        }
    });

    buttonCancel.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (getResources().getBoolean(R.bool.isTablet) == true) {
                // put
                mOpener.openViewStoryFragment(0);
            } else {
                getActivity().finish(); // same as hitting 'back' button
            }
        }
    });
    buttonCreate.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            // local Editables
            Editable titleCreateable = titleET.getText();
            Editable bodyCreateable = bodyET.getText();
            Editable imageNameCreateable = imageNameET.getText();
            String storyTimeCreateable = storyTimeET.getText().toString();

            // Try to parse the date into long format
            try {
                date = StoryData.FORMAT.parse(storyTimeCreateable.toString());
            } catch (ParseException e1) {
                // TODO Auto-generated catch block
                Log.e("CreateStoryFragment", "Date was not parsable, reverting to current time");
                date = new Date();
            }

            // For future expansion: The loginId and storyId need to be generated by the system
            long loginId = 0;
            long storyId = 0;
            String title = "";
            String body = "";
            String audioLink = "";
            String videoLink = "";
            String imageName = "";
            String imageData = "";
            long storyTime = 0;
            double latitude = 0;
            double longitude = 0;

            // pull values from Editables
            title = String.valueOf(titleCreateable.toString());
            body = String.valueOf(bodyCreateable.toString());
            if (audioPath != null)
                audioLink = audioPath;
            if (fileUri != null)
                videoLink = fileUri.toString();
            imageName = String.valueOf(imageNameCreateable.toString());
            if (imagePathFinal != null)
                imageData = imagePathFinal.toString();
            if (loc != null) {
                latitude = loc.getLatitude();
                longitude = loc.getLongitude();
            }
            storyTime = date.getTime();
            Log.i(LOG_TAG, String.valueOf(storyTime));

            // new StoryData object with above info
            StoryData newData = new StoryData(-1,
                    // -1 row index, because there is no way to know which
                    // row it will go into
                    loginId, storyId, title, body, audioLink, videoLink, imageName, imageData, "", 0, storyTime,
                    latitude, longitude);
            Log.d(CreateStoryFragment.class.getCanonicalName(), "imageName" + imageNameET.getText());

            Log.d(CreateStoryFragment.class.getCanonicalName(), "newStoryData:" + newData);

            // insert it through Resolver to be put into ContentProvider
            try {
                resolver.insert(newData);
            } catch (RemoteException e) {
                Log.e(LOG_TAG, "Caught RemoteException => " + e.getMessage());
                e.printStackTrace();
            }
            // return back to proper state
            if (getResources().getBoolean(R.bool.isTablet) == true) {
                // put
                mOpener.openViewStoryFragment(0);
            } else {
                getActivity().finish(); // same as hitting 'back' button
            }
        }
    });

}

From source file:edu.vuum.mocca.ui.story.EditStoryFragment.java

public StoryData makeStoryDataFromUI() {

    Editable titleEditable = titleET.getText();
    Editable bodyEditable = bodyET.getText();
    String audioLinkEditable = (String) audioLinkET.getText();
    String videoLinkEditable = (String) videoLinkET.getText();
    Editable imageNameEditable = imageNameET.getText();
    String imageMetaDataEditable = (String) imageMetaDataET.getText();
    Editable tagsEditable = tagsET.getText();
    String storyTimeEditable = (String) storyTimeET.getText();
    Editable latitudeEditable = latitudeET.getText();
    Editable longitudeEditable = longitudeET.getText();

    // Try to parse the date into long format
    try {/*from   w  w  w .j  ava  2s  .  c o  m*/
        date = StoryData.FORMAT.parse(storyTimeEditable.toString());
    } catch (ParseException e1) {
        // TODO Auto-generated catch block
        Log.e("CreateStoryFragment", "Date was not parsable, reverting to current time");
        date = new Date();
    }

    long loginId = 0;
    long storyId = 0;
    String title = "";
    String body = "";
    String audioLink = "";
    String videoLink = "";
    String imageName = "";
    String imageMetaData = "";
    String tags = "";
    long creationTime = 0;
    long storyTime = 0;
    double latitude = 0;
    double longitude = 0;

    // pull values from Editables
    title = String.valueOf(titleEditable.toString());
    body = String.valueOf(bodyEditable.toString());
    audioLink = String.valueOf(audioLinkEditable.toString());
    videoLink = String.valueOf(videoLinkEditable.toString());
    imageName = String.valueOf(imageNameEditable.toString());
    imageMetaData = String.valueOf(imageMetaDataEditable.toString());
    tags = String.valueOf(tagsEditable.toString());
    storyTime = date.getTime();
    latitude = Double.valueOf(latitudeEditable.toString());
    longitude = Double.valueOf(longitudeEditable.toString());

    // return new StoryData object with
    return new StoryData(getUniqueKey(), loginId, storyId, title, body, audioLink, videoLink, imageName,
            imageMetaData, tags, creationTime, storyTime, latitude, longitude);

}

From source file:org.zywx.wbpalmstar.plugin.chatkeyboard.ACEChatKeyboardView.java

public void insertTextByKeyword(String keyword, String insertText, String color, boolean isReplaceKeyword) {
    if (TextUtils.isEmpty(keyword) || TextUtils.isEmpty(insertText)) {
        return;/* ww  w .  j a v a2s  .co  m*/
    }
    if (TextUtils.isEmpty(color)) {
        color = "#507daf";
    }
    Editable editable = mEditText.getText();
    int lastAtPosition = mLastAtPosition;
    if (editable.length() < keyword.length() || editable.length() < lastAtPosition + keyword.length()) {
        return;
    }
    if (!keyword.equals(editable.subSequence(lastAtPosition, lastAtPosition + keyword.length()).toString())) {
        if (!editable.toString().contains(keyword)) {
            return;
        }
        lastAtPosition = editable.toString().lastIndexOf(keyword);
    }
    if (isReplaceKeyword) {
        editable.replace(lastAtPosition, lastAtPosition + keyword.length(),
                Html.fromHtml("<font color=\"" + color + "\">" + insertText + "</font>"));
    } else {
        editable.insert(lastAtPosition + keyword.length(),
                Html.fromHtml("<font color=\"" + color + "\">" + insertText + "</font>"));
    }
    lastAtPosition += insertText.length() + (isReplaceKeyword ? 0 : keyword.length());
    mEditText.setSelection(lastAtPosition);
}

From source file:foam.jellyfish.StarwispBuilder.java

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

    try {//from   w w w  .ja  v a 2 s. co 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_NUMBER_FLAG_DECIMAL | 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);
            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) {
                    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,
                    android.R.layout.simple_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;
                }
            };

            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("nomadic")) {
            final int wid = arr.getInt(1);
            NomadicSurfaceView v = new NomadicSurfaceView(ctx, wid);
            v.setId(wid);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));

            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:org.buffer.android.buffertextinputlayout.BufferTextInputLayout.java

private void setEditText(EditText editText) {
    // If we already have an EditText, throw an exception
    if (this.editText != null) {
        throw new IllegalArgumentException("We already have an EditText, can only have one");
    }/*from w w  w.  ja v  a2 s.com*/
    if (!(editText instanceof TextInputEditText)) {
        Log.i(LOG_TAG,
                "EditText added is not a TextInputEditText. Please switch to using that" + " class instead.");
    }
    this.editText = editText;
    final boolean hasPasswordTransformation = hasPasswordTransformation();
    // Use the EditText's typeface, and it's text size for our expanded text
    if (!hasPasswordTransformation) {
        // We don't want a monospace font just because we have a password field
        collapsingTextHelper.setTypefaces(this.editText.getTypeface());
    }
    collapsingTextHelper.setExpandedTextSize(this.editText.getTextSize());
    final int editTextGravity = this.editText.getGravity();
    collapsingTextHelper.setCollapsedTextGravity(
            Gravity.TOP | (editTextGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK));
    collapsingTextHelper.setExpandedTextGravity(editTextGravity);
    // Add a TextWatcher so that we know when the text input has changed
    this.editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            setCounterVisible(counterVisible
                    && s.length() >= (getCounterMaxLength() - charactersRemainingUntilCounterDisplay));
            updateLabelState(true);
            if (counterEnabled) {
                updateCounter(s.length());
            }
            if (textInputListener != null)
                textInputListener.onTextChanged(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) {
        }
    });
    // Use the EditText's hint colors if we don't have one set
    if (defaultTextColor == null) {
        defaultTextColor = this.editText.getHintTextColors();
    }
    // If we do not have a valid hint, try and retrieve it from the EditText, if enabled
    if (isHintEnabled && TextUtils.isEmpty(hint)) {
        setHint(this.editText.getHint());
        // Clear the EditText's hint as we will display it ourselves
        this.editText.setHint(null);
    }
    if (counterView != null) {
        updateCounter(this.editText.getText().length());
    }
    if (indicatorArea != null) {
        adjustIndicatorPadding();
    }
    updatePasswordToggleView();
    // Update the label visibility with no animation
    updateLabelState(false);
}