Example usage for android.widget TextView getEditableText

List of usage examples for android.widget TextView getEditableText

Introduction

In this page you can find the example usage for android.widget TextView getEditableText.

Prototype

public Editable getEditableText() 

Source Link

Document

Return the text that TextView is displaying as an Editable object.

Usage

From source file:com.nerderylabs.android.nerdalert.ui.fragment.MainFragment.java

private void persistNametagValues(TextView view) {
    Context context = getContext();
    // stop publishing if the info has changed
    if (Settings.isPublishing(context)) {
        nearbyInterface.unpublish(myInfo);
        nearbyInterface.unsubscribe();/*from  www.  j a v a 2  s  . co  m*/
    }
    switch (view.getId()) {
    case R.id.my_name:
        myInfo.setName(view.getEditableText().toString());
        Settings.setName(context, view.getEditableText().toString());
        break;
    case R.id.my_tagline:
        myInfo.setTagline(view.getEditableText().toString());
        Settings.setTagline(context, view.getEditableText().toString());
        break;
    }
    Log.d(TAG, "myInfo: " + myInfo);
}

From source file:org.sandholm.max.juttele.activity.ConversationActivity.java

/**
 * On create//from  www  . j av  a  2s  .  c  om
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    serverId = getIntent().getExtras().getInt("serverId");
    server = Yaaic.getInstance().getServerById(serverId);
    Settings settings = new Settings(this);

    // Finish activity if server does not exist anymore - See #55
    if (server == null) {
        this.finish();
    }

    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    setTitle(server.getTitle());

    setContentView(R.layout.conversations);

    boolean isLandscape = (getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE);

    EditText input = (EditText) findViewById(R.id.input);
    input.setOnKeyListener(inputKeyListener);

    input.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                sendMessage(v.getText().toString());

                // Workaround for a race condition in EditText
                // Instead of calling input.setText("");
                // See:
                // - https://github.com/pocmo/Yaaic/issues/67
                // - http://code.google.com/p/android/issues/detail?id=17508
                TextKeyListener.clear(v.getEditableText());
                return true;
            } else {
                return false;
            }
        }

    });
    input.setHint(server.getIdentity().getNickname());

    pager = (ViewPager) findViewById(R.id.pager);

    pagerAdapter = new ConversationPagerAdapter(this, server);
    pager.setAdapter(pagerAdapter);

    final float density = getResources().getDisplayMetrics().density;

    indicator = (ConversationIndicator) findViewById(R.id.titleIndicator);
    indicator.setServer(server);
    //indicator.setTypeface(Typeface.MONOSPACE);
    indicator.setViewPager(pager);

    //indicator.setFooterColor(0xFF31B6E7);
    indicator.setFooterLineHeight(1 * density);
    indicator.setFooterIndicatorHeight(3 * density);
    indicator.setFooterIndicatorStyle(IndicatorStyle.Underline);
    indicator.setSelectedColor(0xFFFFFFFF);
    indicator.setSelectedBold(true);
    //indicator.setBackgroundColor(0xFF181818);

    historySize = settings.getHistorySize();

    if (server.getStatus() == Status.PRE_CONNECTING) {
        server.clearConversations();
        pagerAdapter.clearConversations();
        server.getConversation(ServerInfo.DEFAULT_NAME).setHistorySize(historySize);
    }

    float fontSize = settings.getFontSize();
    indicator.setTextSize(fontSize * density);

    input.setTextSize(settings.getFontSize());
    //input.setTypeface(Typeface.MONOSPACE);

    // Optimization : cache field lookups
    Collection<Conversation> mConversations = server.getConversations();

    for (Conversation conversation : mConversations) {
        // Only scroll to new conversation if it was selected before
        if (conversation.getStatus() == Conversation.STATUS_SELECTED) {
            onNewConversation(conversation.getName());
        } else {
            createNewConversation(conversation.getName());
        }
    }

    int setInputTypeFlags = 0;

    setInputTypeFlags |= InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;

    if (settings.autoCapSentences()) {
        setInputTypeFlags |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
    }

    if (isLandscape && settings.imeExtract()) {
        setInputTypeFlags |= InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE;
    }

    if (!settings.imeExtract()) {
        input.setImeOptions(input.getImeOptions() | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    }

    input.setInputType(input.getInputType() | setInputTypeFlags);

    // Create a new scrollback history
    scrollback = new Scrollback();
}

From source file:com.air.mobilebrowser.BrowserActivity.java

/** Logs an onscreen message for debugging. */
public void logMessage(final TextView consoleView, String message, String value, int color) {
    if (mIsDebugEnabled && consoleView != null) {
        consoleView.setOnFocusChangeListener(new OnFocusChangeListener() {

            @Override/*  ww  w.  jav  a 2 s. c o  m*/
            public void onFocusChange(View v, boolean hasFocus) {

                ViewParent parent = consoleView.getParent();
                final ScrollView scroll = (ScrollView) parent;

                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {

                        scroll.smoothScrollTo(0, consoleView.getMeasuredHeight() + 10);

                    }
                }, 0);

            }
        });
        Editable editable = consoleView.getEditableText();

        SpannableString str = null;

        if (editable == null) {
            editable = new SpannableStringBuilder();
            str = new SpannableString(message + ": " + value);
            str.setSpan(new ForegroundColorSpan(color), message.length() + 2,
                    message.length() + 2 + value.length(), 0);
        } else {
            str = new SpannableString("\n" + message + ": " + value);
            str.setSpan(new ForegroundColorSpan(color), message.length() + 2,
                    message.length() + 3 + value.length(), 0);
        }

        editable.append(str);

        consoleView.setText(editable, TextView.BufferType.EDITABLE);

        ViewParent parent = consoleView.getParent();
        if (parent instanceof ScrollView) {
            final ScrollView scroll = (ScrollView) parent;

            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {

                    scroll.smoothScrollTo(0, consoleView.getMeasuredHeight() + 10);

                }
            }, 1000);
        }
    }
}

From source file:org.tigase.mobile.muc.JoinMucDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Dialog dialog = new Dialog(getActivity());
    dialog.setCancelable(true);// w w  w  .j a  va2  s .c  o m
    dialog.setCanceledOnTouchOutside(true);

    dialog.setContentView(R.layout.join_room_dialog);
    dialog.setTitle(getString(R.string.aboutButton));

    ArrayList<String> accounts = new ArrayList<String>();
    for (Account account : AccountManager.get(getActivity()).getAccountsByType(Constants.ACCOUNT_TYPE)) {
        accounts.add(account.name);
    }

    final Spinner accountSelector = (Spinner) dialog.findViewById(R.id.muc_accountSelector);
    final Button joinButton = (Button) dialog.findViewById(R.id.muc_joinButton);
    final Button cancelButton = (Button) dialog.findViewById(R.id.muc_cancelButton);
    final TextView name = (TextView) dialog.findViewById(R.id.muc_name);
    final TextView roomName = (TextView) dialog.findViewById(R.id.muc_roomName);
    final TextView mucServer = (TextView) dialog.findViewById(R.id.muc_server);
    final TextView nickname = (TextView) dialog.findViewById(R.id.muc_nickname);
    final TextView password = (TextView) dialog.findViewById(R.id.muc_password);
    final CheckBox autojoin = (CheckBox) dialog.findViewById(R.id.muc_autojoin);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item,
            accounts.toArray(new String[] {}));
    accountSelector.setAdapter(adapter);

    Bundle data = getArguments();
    final boolean editMode = data != null && data.containsKey("editMode") && data.getBoolean("editMode");
    final String id = data != null ? data.getString("id") : null;

    if (data != null) {
        accountSelector.setSelection(adapter.getPosition(data.getString("account")));

        name.setText(data.getString("name"));
        roomName.setText(data.getString("room"));
        mucServer.setText(data.getString("server"));
        nickname.setText(data.getString("nick"));
        password.setText(data.getString("password"));
        autojoin.setChecked(data.getBoolean("autojoin"));
    }

    if (!editMode) {
        name.setVisibility(View.GONE);
        autojoin.setVisibility(View.GONE);
    } else {
        joinButton.setText("Save");
    }

    cancelButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            dialog.dismiss();

        }
    });
    joinButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (editMode) {

                BareJID account = BareJID.bareJIDInstance(accountSelector.getSelectedItem().toString());
                final Jaxmpp jaxmpp = ((MessengerApplication) getActivity().getApplicationContext())
                        .getMultiJaxmpp().get(account);

                Bundle data = new Bundle();

                data.putString("id", id);
                data.putString("account", account.toString());
                data.putString("name", name.getText().toString());
                data.putString("room", roomName.getText().toString());
                data.putString("server", mucServer.getText().toString());
                data.putString("nick", nickname.getText().toString());
                data.putString("password", password.getText().toString());
                data.putBoolean("autojoin", autojoin.isChecked());

                ((BookmarksActivity) getActivity()).saveItem(data);

                dialog.dismiss();
                return;
            }

            BareJID account = BareJID.bareJIDInstance(accountSelector.getSelectedItem().toString());
            final Jaxmpp jaxmpp = ((MessengerApplication) getActivity().getApplicationContext())
                    .getMultiJaxmpp().get(account);

            Runnable r = new Runnable() {

                @Override
                public void run() {
                    try {
                        Room room = jaxmpp.getModule(MucModule.class).join(
                                roomName.getEditableText().toString(), mucServer.getEditableText().toString(),
                                nickname.getEditableText().toString(), password.getEditableText().toString());
                        if (task != null)
                            task.execute(room);
                    } catch (Exception e) {
                        Log.w("MUC", "", e);
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            };
            (new Thread(r)).start();
            dialog.dismiss();
        }
    });

    return dialog;
}