Search in sources :

Example 86 with TextWatcher

use of android.text.TextWatcher in project BBS-Android by bdpqchen.

the class ThreadActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Intent intent = getIntent();
    mThreadId = intent.getIntExtra(INTENT_THREAD_ID, 0);
    mThreadFloor = intent.getIntExtra(INTENT_THREAD_FLOOR, 1);
    mThreadTitle = intent.getStringExtra(INTENT_THREAD_TITLE);
    super.onCreate(savedInstanceState);
    mSlideBackLayout.lock(!PrefUtil.isSlideBackMode());
    mContext = this;
    mPresenter.getThread(mThreadId, 0);
    mAdapter = new PostAdapter(mContext);
    mLayoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);
    mRvThreadPost.addItemDecoration(new RecyclerViewItemDecoration(5));
    mRvThreadPost.setLayoutManager(mLayoutManager);
    mRvThreadPost.setAdapter(mAdapter);
    mRvThreadPost.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            if (newState == RecyclerView.SCROLL_STATE_IDLE && lastVisibleItemPosition + 1 == mAdapter.getItemCount()) {
                if (!mEnding) {
                    mPage++;
                    mIsLoadingMore = true;
                    mPresenter.getThread(mThreadId, mPage);
                }
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            lastVisibleItemPosition = mLayoutManager.findLastVisibleItemPosition();
        }
    });
    mFbThreadWritePost.setOnClickListener(v -> {
        showCommentInput();
        resetReply();
    });
    mEtComment.addTextChangedListener(new TextWatcher() {

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (mEtComment != null && mEtComment.getText().toString().length() > 0) {
                mIvCommentOut.setVisibility(View.GONE);
                mIvCommentSend.setVisibility(View.VISIBLE);
            } else {
                mIvCommentOut.setVisibility(View.VISIBLE);
                mIvCommentSend.setVisibility(View.GONE);
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    mIvCommentOut.setOnClickListener(v -> showFab());
    mIvCommentSend.setOnClickListener(v -> sendComment(mReplyId));
    mIvStaredThread.setOnClickListener(v -> {
        if (PrefUtil.hadLogin()) {
            mPresenter.unStarThread(mThreadId);
        }
    });
    mIvStarThread.setOnClickListener(v -> {
        if (PrefUtil.hadLogin()) {
            mPresenter.starThread(mThreadId);
        }
    });
    mSrlThreadList.setColorSchemeColors(getResources().getIntArray(R.array.swipeRefreshColors));
    mSrlThreadList.setOnRefreshListener(() -> {
        mRefreshing = true;
        mPage = 0;
        mPresenter.getThread(mThreadId, mPage);
    });
    mAdapter.setOnItemClickListener((view, position) -> {
        postPosition = position;
        mReplyId = mAdapter.getPostId(position);
        showCommentInput();
    });
    mCbAnonymousComment.setOnCheckedChangeListener((buttonView, isChecked) -> {
        mIsAnonymous = isChecked;
    });
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Intent(android.content.Intent) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerViewItemDecoration(com.twtstudio.bbs.bdpqchen.bbs.commons.helper.RecyclerViewItemDecoration)

Example 87 with TextWatcher

use of android.text.TextWatcher in project diary by billthefarmer.

the class Diary method setListeners.

private void setListeners() {
    if (textView != null)
        textView.addTextChangedListener(new TextWatcher() {

            // afterTextChanged
            @Override
            public void afterTextChanged(Editable s) {
            }

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

            // onTextChanged
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // Check markdown
                if (markdown)
                    // Set flag
                    dirty = true;
            }
        });
    if (accept != null)
        accept.setOnClickListener(new View.OnClickListener() {

            // On click
            @Override
            public void onClick(View v) {
                // Check flag
                if (dirty) {
                    // Get text
                    String string = textView.getText().toString();
                    string = substitutePath(string);
                    markdownView.loadMarkdown(getBaseUrl(), string, STYLES);
                    // Clear flag
                    dirty = false;
                }
                // Animation
                Animation viewClose = AnimationUtils.loadAnimation(v.getContext(), R.anim.activity_close_exit);
                Animation viewOpen = AnimationUtils.loadAnimation(v.getContext(), R.anim.activity_open_enter);
                scrollView.startAnimation(viewClose);
                markdownView.startAnimation(viewOpen);
                Animation buttonFlipOut = AnimationUtils.loadAnimation(v.getContext(), R.anim.flip_out);
                Animation buttonFlipIn = AnimationUtils.loadAnimation(v.getContext(), R.anim.flip_in);
                accept.startAnimation(buttonFlipOut);
                edit.startAnimation(buttonFlipIn);
                // Set visibility
                markdownView.setVisibility(View.VISIBLE);
                scrollView.setVisibility(View.GONE);
                accept.setVisibility(View.GONE);
                edit.setVisibility(View.VISIBLE);
                shown = true;
            }
        });
    if (edit != null)
        edit.setOnClickListener(new View.OnClickListener() {

            // On click
            @Override
            public void onClick(View v) {
                // Animation
                Animation viewClose = AnimationUtils.loadAnimation(v.getContext(), R.anim.activity_close_exit);
                Animation viewOpen = AnimationUtils.loadAnimation(v.getContext(), R.anim.activity_open_enter);
                markdownView.startAnimation(viewClose);
                scrollView.startAnimation(viewOpen);
                Animation buttonFlipOut = AnimationUtils.loadAnimation(v.getContext(), R.anim.flip_out);
                Animation buttonFlipIn = AnimationUtils.loadAnimation(v.getContext(), R.anim.flip_in);
                edit.startAnimation(buttonFlipOut);
                accept.startAnimation(buttonFlipIn);
                // Set visibility
                markdownView.setVisibility(View.GONE);
                scrollView.setVisibility(View.VISIBLE);
                accept.setVisibility(View.VISIBLE);
                edit.setVisibility(View.GONE);
                shown = false;
            }
        });
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Animation(android.view.animation.Animation) View(android.view.View) ScrollView(android.widget.ScrollView)

Example 88 with TextWatcher

use of android.text.TextWatcher in project Talon-for-Twitter by klinker24.

the class Compose method setUpSimilar.

public void setUpSimilar() {
    attachImage[0] = (ImageView) findViewById(R.id.picture1);
    attachImage[1] = (ImageView) findViewById(R.id.picture2);
    attachImage[2] = (ImageView) findViewById(R.id.picture3);
    attachImage[3] = (ImageView) findViewById(R.id.picture4);
    attachButton = (ImageButton) findViewById(R.id.attach);
    gifButton = (ImageButton) findViewById(R.id.gif);
    emojiButton = (ImageButton) findViewById(R.id.emoji);
    emojiKeyboard = (EmojiKeyboard) findViewById(R.id.emojiKeyboard);
    reply = (EditText) findViewById(R.id.tweet_content);
    charRemaining = (TextView) findViewById(R.id.char_remaining);
    findViewById(R.id.prompt_pos).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Log.v("talon_input", "clicked the view");
            ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(reply, InputMethodManager.SHOW_FORCED);
        }
    });
    NetworkedCacheableImageView pic = (NetworkedCacheableImageView) findViewById(R.id.profile_pic);
    HoloTextView currentName = (HoloTextView) findViewById(R.id.current_name);
    if (settings.roundContactImages) {
        pic.loadImage(settings.myProfilePicUrl, false, null, NetworkedCacheableImageView.CIRCLE);
    } else {
        pic.loadImage(settings.myProfilePicUrl, false, null);
    }
    currentName.setText("@" + settings.myScreenName);
    // numberAttached.setText("0 " + getString(R.string.attached_images));
    charRemaining.setText(AppSettings.getInstance(this).tweetCharacterCount - reply.getText().length() + "");
    reply.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) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            countHandler.removeCallbacks(getCount);
            countHandler.postDelayed(getCount, 300);
        }
    });
}
Also used : NetworkedCacheableImageView(com.klinker.android.twitter.views.NetworkedCacheableImageView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) HoloTextView(com.klinker.android.twitter.views.text.HoloTextView) NetworkedCacheableImageView(com.klinker.android.twitter.views.NetworkedCacheableImageView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) HoloTextView(com.klinker.android.twitter.views.text.HoloTextView) Point(android.graphics.Point)

Example 89 with TextWatcher

use of android.text.TextWatcher in project Talon-for-Twitter by klinker24.

the class ComposeActivity method setUpLayout.

public void setUpLayout() {
    setContentView(R.layout.compose_activity);
    setUpSimilar();
    // number of accounts logged in
    int count = 0;
    if (sharedPrefs.getBoolean("is_logged_in_1", false)) {
        count++;
    }
    if (sharedPrefs.getBoolean("is_logged_in_2", false)) {
        count++;
    }
    if (count == 2) {
        findViewById(R.id.accounts).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String[] options = new String[3];
                options[0] = "@" + settings.myScreenName;
                options[1] = "@" + settings.secondScreenName;
                options[2] = getString(R.string.both_accounts);
                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                builder.setItems(options, new DialogInterface.OnClickListener() {

                    public void onClick(final DialogInterface dialog, final int item) {
                        NetworkedCacheableImageView pic = (NetworkedCacheableImageView) findViewById(R.id.profile_pic);
                        HoloTextView currentName = (HoloTextView) findViewById(R.id.current_name);
                        switch(item) {
                            case 0:
                                useAccOne = true;
                                useAccTwo = false;
                                if (settings.roundContactImages) {
                                    pic.loadImage(settings.myProfilePicUrl, false, null, NetworkedCacheableImageView.CIRCLE);
                                } else {
                                    pic.loadImage(settings.myProfilePicUrl, false, null);
                                }
                                currentName.setText("@" + settings.myScreenName);
                                break;
                            case 1:
                                useAccOne = false;
                                useAccTwo = true;
                                if (settings.roundContactImages) {
                                    pic.loadImage(settings.secondProfilePicUrl, false, null, NetworkedCacheableImageView.CIRCLE);
                                } else {
                                    pic.loadImage(settings.secondProfilePicUrl, false, null);
                                }
                                currentName.setText("@" + settings.secondScreenName);
                                break;
                            case 2:
                                useAccOne = true;
                                useAccTwo = true;
                                TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.favUser });
                                int resource = a.getResourceId(0, 0);
                                a.recycle();
                                pic.setImageResource(resource);
                                currentName.setText(getString(R.string.both_accounts));
                                break;
                        }
                    }
                });
                AlertDialog alert = builder.create();
                alert.show();
            }
        });
    }
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    UserAutoCompleteHelper.applyTo(this, reply);
    hashtagAutoComplete = new ListPopupWindow(context);
    hashtagAutoComplete.setAnchorView(reply);
    hashtagAutoComplete.setHeight(toDP(200));
    hashtagAutoComplete.setWidth((int) (width * .75));
    hashtagAutoComplete.setAdapter(new AutoCompleteHashtagAdapter(context, HashtagDataSource.getInstance(context).getCursor(reply.getText().toString()), reply));
    hashtagAutoComplete.setPromptPosition(ListPopupWindow.POSITION_PROMPT_ABOVE);
    hashtagAutoComplete.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            hashtagAutoComplete.dismiss();
        }
    });
    // watcher for the @
    reply.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) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            String searchText = reply.getText().toString();
            try {
                int position = reply.getSelectionStart() - 1;
                if (searchText.charAt(position) == '#') {
                    hashtagAutoComplete.show();
                } else if (searchText.charAt(position) == ' ') {
                    hashtagAutoComplete.dismiss();
                } else if (hashtagAutoComplete.isShowing()) {
                    String adapterText = "";
                    do {
                        adapterText = searchText.charAt(position--) + adapterText;
                    } while (searchText.charAt(position) != '#');
                    adapterText = adapterText.replace("#", "");
                    hashtagAutoComplete.setAdapter(new AutoCompleteHashtagAdapter(context, HashtagDataSource.getInstance(context).getCursor(adapterText), reply));
                }
            } catch (Exception e) {
                // there is no text
                try {
                    hashtagAutoComplete.dismiss();
                } catch (Exception x) {
                // something went really wrong I guess haha
                }
            }
        }
    });
    overflow = (ImageButton) findViewById(R.id.overflow_button);
    overflow.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
        }
    });
    attachButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            attachImage();
        }
    });
    gifButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            findGif();
        }
    });
    ImageButton at = (ImageButton) findViewById(R.id.at_button);
    at.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            int start = reply.getSelectionStart();
            reply.getText().insert(start, "@");
            reply.setSelection(start + 1);
        }
    });
    ImageButton hashtag = (ImageButton) findViewById(R.id.hashtag_button);
    hashtag.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            int start = reply.getSelectionStart();
            reply.getText().insert(start, "#");
            reply.setSelection(start + 1);
        }
    });
    final int SAVE_DRAFT = 0;
    final int VIEW_DRAFTS = 1;
    final int VIEW_QUEUE = 2;
    final int SCHEDULE = 3;
    final ImageButton overflow = (ImageButton) findViewById(R.id.overflow_button);
    overflow.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final PopupMenu menu = new PopupMenu(context, findViewById(R.id.discard_button));
            menu.getMenu().add(Menu.NONE, SAVE_DRAFT, Menu.NONE, context.getString(R.string.menu_save_draft));
            menu.getMenu().add(Menu.NONE, VIEW_DRAFTS, Menu.NONE, context.getString(R.string.menu_view_drafts));
            menu.getMenu().add(Menu.NONE, VIEW_QUEUE, Menu.NONE, context.getString(R.string.menu_view_queued));
            menu.getMenu().add(Menu.NONE, SCHEDULE, Menu.NONE, context.getString(R.string.menu_schedule_tweet));
            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem menuItem) {
                    switch(menuItem.getItemId()) {
                        case SAVE_DRAFT:
                            if (reply.getText().length() > 0) {
                                QueuedDataSource.getInstance(context).createDraft(reply.getText().toString(), currentAccount);
                                Toast.makeText(context, getResources().getString(R.string.saved_draft), Toast.LENGTH_SHORT).show();
                                reply.setText("");
                                finish();
                            } else {
                                Toast.makeText(context, getResources().getString(R.string.no_tweet), Toast.LENGTH_SHORT).show();
                            }
                            break;
                        case VIEW_DRAFTS:
                            final String[] drafts = QueuedDataSource.getInstance(context).getDrafts();
                            if (drafts.length > 0) {
                                final String[] draftsAndDelete = new String[drafts.length + 1];
                                draftsAndDelete[0] = getString(R.string.delete_all);
                                for (int i = 1; i < draftsAndDelete.length; i++) {
                                    draftsAndDelete[i] = drafts[i - 1];
                                }
                                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                                builder.setItems(draftsAndDelete, new DialogInterface.OnClickListener() {

                                    public void onClick(final DialogInterface dialog, final int item) {
                                        if (item == 0) {
                                            // clicked the delete all item
                                            new AlertDialog.Builder(context).setMessage(getString(R.string.delete_all) + "?").setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                                                @Override
                                                public void onClick(DialogInterface dialogInterface, int i) {
                                                    QueuedDataSource.getInstance(context).deleteAllDrafts();
                                                    dialogInterface.dismiss();
                                                }
                                            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                                                @Override
                                                public void onClick(DialogInterface dialogInterface, int i) {
                                                    dialogInterface.dismiss();
                                                }
                                            }).create().show();
                                            dialog.dismiss();
                                        } else {
                                            new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.apply)).setMessage(draftsAndDelete[item]).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                                                @Override
                                                public void onClick(DialogInterface dialogInterface, int i) {
                                                    reply.setText(draftsAndDelete[item]);
                                                    reply.setSelection(reply.getText().length());
                                                    QueuedDataSource.getInstance(context).deleteDraft(draftsAndDelete[item]);
                                                    dialogInterface.dismiss();
                                                }
                                            }).setNegativeButton(R.string.delete_draft, new DialogInterface.OnClickListener() {

                                                @Override
                                                public void onClick(DialogInterface dialogInterface, int i) {
                                                    QueuedDataSource.getInstance(context).deleteDraft(draftsAndDelete[item]);
                                                    dialogInterface.dismiss();
                                                }
                                            }).create().show();
                                            dialog.dismiss();
                                        }
                                    }
                                });
                                AlertDialog alert = builder.create();
                                alert.show();
                            } else {
                                Toast.makeText(context, R.string.no_drafts, Toast.LENGTH_SHORT).show();
                            }
                            break;
                        case SCHEDULE:
                            Intent schedule = new Intent(context, ViewScheduledTweets.class);
                            if (!reply.getText().toString().isEmpty()) {
                                schedule.putExtra("has_text", true);
                                schedule.putExtra("text", reply.getText().toString());
                            }
                            startActivity(schedule);
                            finish();
                            break;
                        case VIEW_QUEUE:
                            final String[] queued = QueuedDataSource.getInstance(context).getQueuedTweets(currentAccount);
                            if (queued.length > 0) {
                                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                                builder.setItems(queued, new DialogInterface.OnClickListener() {

                                    public void onClick(final DialogInterface dialog, final int item) {
                                        new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.keep_queued_tweet)).setMessage(queued[item]).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                                            @Override
                                            public void onClick(DialogInterface dialogInterface, int i) {
                                                dialogInterface.dismiss();
                                            }
                                        }).setNegativeButton(R.string.delete_draft, new DialogInterface.OnClickListener() {

                                            @Override
                                            public void onClick(DialogInterface dialogInterface, int i) {
                                                QueuedDataSource.getInstance(context).deleteQueuedTweet(queued[item]);
                                                dialogInterface.dismiss();
                                            }
                                        }).create().show();
                                        dialog.dismiss();
                                    }
                                });
                                AlertDialog alert = builder.create();
                                alert.show();
                            } else {
                                Toast.makeText(context, R.string.no_queued, Toast.LENGTH_SHORT).show();
                            }
                            break;
                    }
                    return false;
                }
            });
            menu.show();
        }
    });
    final ImageButton location = (ImageButton) findViewById(R.id.location);
    location.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!addLocation) {
                sharedPrefs.edit().putBoolean("share_location", true).commit();
                addLocation = true;
                if (!settings.addonTheme) {
                    location.setColorFilter(context.getResources().getColor(R.color.app_color));
                } else {
                    location.setColorFilter(settings.accentInt);
                }
            } else {
                sharedPrefs.edit().putBoolean("share_location", false).commit();
                addLocation = false;
                location.clearColorFilter();
            }
        }
    });
    if (sharedPrefs.getBoolean("share_location", false)) {
        location.performClick();
    }
    if (!settings.useEmoji) {
        emojiButton.setVisibility(View.GONE);
    } else {
        emojiKeyboard.setAttached((HoloEditText) reply);
        reply.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (emojiKeyboard.isShowing()) {
                    emojiKeyboard.setVisibility(false);
                    TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.emoji_button_changing });
                    int resource = a.getResourceId(0, 0);
                    a.recycle();
                    emojiButton.setImageResource(resource);
                }
            }
        });
        emojiButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (emojiKeyboard.isShowing()) {
                    emojiKeyboard.setVisibility(false);
                    new Handler().postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                            imm.showSoftInput(reply, 0);
                        }
                    }, 250);
                    TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.emoji_button_changing });
                    int resource = a.getResourceId(0, 0);
                    a.recycle();
                    emojiButton.setImageResource(resource);
                } else {
                    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(reply.getWindowToken(), 0);
                    new Handler().postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            emojiKeyboard.setVisibility(true);
                        }
                    }, 250);
                    TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.keyboard_button_changing });
                    int resource = a.getResourceId(0, 0);
                    a.recycle();
                    emojiButton.setImageResource(resource);
                }
            }
        });
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) InputMethodManager(android.view.inputmethod.InputMethodManager) AutoCompleteHashtagAdapter(com.klinker.android.twitter.adapters.AutoCompleteHashtagAdapter) TypedArray(android.content.res.TypedArray) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Handler(android.os.Handler) Intent(android.content.Intent) Point(android.graphics.Point) HoloTextView(com.klinker.android.twitter.views.text.HoloTextView) NetworkedCacheableImageView(com.klinker.android.twitter.views.NetworkedCacheableImageView) HoloTextView(com.klinker.android.twitter.views.text.HoloTextView) Point(android.graphics.Point) IOException(java.io.IOException) NetworkedCacheableImageView(com.klinker.android.twitter.views.NetworkedCacheableImageView)

Example 90 with TextWatcher

use of android.text.TextWatcher in project Talon-for-Twitter by klinker24.

the class NewScheduledTweet method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    settings = AppSettings.getInstance(this);
    Utils.setUpTheme(this, settings);
    countHandler = new Handler();
    setContentView(R.layout.scheduled_new_tweet_activity);
    Intent intent = getIntent();
    sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
    context = this;
    mEditText = (EditText) findViewById(R.id.tweet_content);
    counter = (TextView) findViewById(R.id.char_remaining);
    emojiButton = (ImageButton) findViewById(R.id.emojiButton);
    emojiKeyboard = (EmojiKeyboard) findViewById(R.id.emojiKeyboard);
    // if they are coming from the compose window with text, then display it
    if (getIntent().getBooleanExtra("has_text", false)) {
        mEditText.setText(getIntent().getStringExtra("text"));
        mEditText.setSelection(mEditText.getText().length());
    }
    final ListPopupWindow autocomplete = new ListPopupWindow(context);
    autocomplete.setAnchorView(mEditText);
    autocomplete.setHeight(Utils.toDP(100, context));
    autocomplete.setWidth(Utils.toDP(275, context));
    try {
        autocomplete.setAdapter(new AutoCompletePeopleAdapter(context, FollowersDataSource.getInstance(context).getCursor(settings.currentAccount, mEditText.getText().toString()), mEditText));
    } catch (Exception e) {
    // not really sure why
    }
    autocomplete.setPromptPosition(ListPopupWindow.POSITION_PROMPT_ABOVE);
    autocomplete.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            autocomplete.dismiss();
        }
    });
    mEditText.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) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            String searchText = mEditText.getText().toString();
            try {
                if (searchText.substring(searchText.length() - 1, searchText.length()).equals("@")) {
                    autocomplete.show();
                } else if (searchText.substring(searchText.length() - 1, searchText.length()).equals(" ")) {
                    autocomplete.dismiss();
                } else if (autocomplete.isShowing()) {
                    String[] split = mEditText.getText().toString().split(" ");
                    String adapterText;
                    if (split.length > 1) {
                        adapterText = split[split.length - 1];
                    } else {
                        adapterText = split[0];
                    }
                    adapterText = adapterText.replace("@", "");
                    autocomplete.setAdapter(new AutoCompletePeopleAdapter(context, FollowersDataSource.getInstance(context).getCursor(settings.currentAccount, adapterText), mEditText));
                }
            } catch (Exception e) {
                // there is no text
                try {
                    autocomplete.dismiss();
                } catch (Exception x) {
                // something went really wrong i guess haha
                }
            }
            countHandler.removeCallbacks(getCount);
            countHandler.postDelayed(getCount, 300);
        }
    });
    if (!sharedPrefs.getBoolean("keyboard_type", true)) {
        mEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
        mEditText.setImeOptions(EditorInfo.IME_ACTION_NONE);
    }
    startDate = intent.getStringExtra(ViewScheduledTweets.EXTRA_TIME);
    startMessage = intent.getStringExtra(ViewScheduledTweets.EXTRA_TEXT);
    if (TextUtils.isEmpty(startDate)) {
        startDate = "";
    }
    if (TextUtils.isEmpty(startMessage)) {
        startMessage = "";
    }
    final Calendar c = Calendar.getInstance();
    currentYear = c.get(Calendar.YEAR);
    currentMonth = c.get(Calendar.MONTH);
    currentDay = c.get(Calendar.DAY_OF_MONTH);
    currentHour = c.get(Calendar.HOUR_OF_DAY);
    currentMinute = c.get(Calendar.MINUTE);
    currentDate = new Date(currentYear, currentMonth, currentDay, currentHour, currentMinute);
    timeDisplay = (TextView) findViewById(R.id.currentTime);
    dateDisplay = (TextView) findViewById(R.id.currentDate);
    btDate = (Button) findViewById(R.id.setDate);
    btTime = (Button) findViewById(R.id.setTime);
    if (!startDate.equals("") && !startDate.equals("null")) {
        setDate = new Date(Long.parseLong(startDate));
        timeDone = true;
        btTime.setEnabled(true);
    } else {
        btTime.setEnabled(false);
    }
    if (mEditText.getText().toString().isEmpty()) {
        mEditText.setText(startMessage);
    }
    if (!startDate.equals("")) {
        Date startDateObj = new Date(Long.parseLong(startDate));
        if (sharedPrefs.getBoolean("hour_format", false)) {
            timeDisplay.setText(DateFormat.getTimeInstance(DateFormat.SHORT, Locale.GERMAN).format(startDateObj));
        } else {
            timeDisplay.setText(DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US).format(startDateObj));
        }
        if (sharedPrefs.getBoolean("hour_format", false)) {
            dateDisplay.setText(DateFormat.getDateInstance(DateFormat.MEDIUM).format(startDateObj));
        } else {
            dateDisplay.setText(DateFormat.getDateInstance(DateFormat.MEDIUM).format(startDateObj));
        }
    }
    if (!settings.useEmoji) {
        emojiButton.setVisibility(View.GONE);
    } else {
        emojiKeyboard.setAttached((HoloEditText) mEditText);
        mEditText.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (emojiKeyboard.isShowing()) {
                    emojiKeyboard.setVisibility(false);
                }
            }
        });
        emojiButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
                emojiKeyboard.toggleVisibility();
                RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) emojiKeyboard.getLayoutParams();
                params.topMargin = mEditText.getHeight();
                emojiKeyboard.setLayoutParams(params);
            }
        });
    }
    // sets the date button listener to call the dialog
    btDate.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            com.android.datetimepicker.date.DatePickerDialog.newInstance(reservationDate, currentYear, currentMonth, currentDay, settings.theme != AppSettings.THEME_LIGHT).show(getFragmentManager(), "date_picker");
            btTime.setEnabled(true);
        }
    });
    // sets the time button listener to call the dialog
    btTime.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            com.android.datetimepicker.time.TimePickerDialog dialog = com.android.datetimepicker.time.TimePickerDialog.newInstance(timeDate, currentHour, currentMinute, settings.militaryTime);
            if (settings.theme != AppSettings.THEME_LIGHT) {
                dialog.setThemeDark(true);
            }
            dialog.show(getFragmentManager(), "time_picker");
        }
    });
    // Inflate a "Done/Discard" custom action bar view.
    LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext().getSystemService(LAYOUT_INFLATER_SERVICE);
    final View customActionBarView = inflater.inflate(R.layout.actionbar_done_discard, null);
    FrameLayout done = (FrameLayout) customActionBarView.findViewById(R.id.actionbar_done);
    ((TextView) done.findViewById(R.id.done)).setText(R.string.done_label);
    done.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            doneClick();
        }
    });
    FrameLayout discard = (FrameLayout) customActionBarView.findViewById(R.id.actionbar_discard);
    if (!TextUtils.isEmpty(getIntent().getStringExtra(ViewScheduledTweets.EXTRA_TIME))) {
        ((TextView) discard.findViewById(R.id.discard)).setText(R.string.delete);
    }
    discard.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            discardClick();
        }
    });
    // Show the custom action bar view and hide the normal Home icon and title.
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
Also used : InputMethodManager(android.view.inputmethod.InputMethodManager) ListPopupWindow(android.widget.ListPopupWindow) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) HoloTextView(com.klinker.android.twitter.views.text.HoloTextView) ActionBar(android.app.ActionBar) Calendar(java.util.Calendar) Handler(android.os.Handler) Intent(android.content.Intent) AutoCompletePeopleAdapter(com.klinker.android.twitter.adapters.AutoCompletePeopleAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) HoloTextView(com.klinker.android.twitter.views.text.HoloTextView) Date(java.util.Date) LayoutInflater(android.view.LayoutInflater) FrameLayout(android.widget.FrameLayout) RelativeLayout(android.widget.RelativeLayout) AdapterView(android.widget.AdapterView)

Aggregations

TextWatcher (android.text.TextWatcher)192 Editable (android.text.Editable)158 View (android.view.View)96 TextView (android.widget.TextView)75 Paint (android.graphics.Paint)37 ImageView (android.widget.ImageView)30 TextPaint (android.text.TextPaint)28 EditText (android.widget.EditText)28 Intent (android.content.Intent)25 KeyEvent (android.view.KeyEvent)24 AdapterView (android.widget.AdapterView)21 ListView (android.widget.ListView)17 RecyclerView (android.support.v7.widget.RecyclerView)15 DialogInterface (android.content.DialogInterface)13 SuppressLint (android.annotation.SuppressLint)12 OnClickListener (android.view.View.OnClickListener)12 Button (android.widget.Button)12 InputMethodManager (android.view.inputmethod.InputMethodManager)11 AlertDialog (android.app.AlertDialog)10 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)9