Java Code Examples for android.widget.TextView.post()

The following are Jave code examples for showing how to use post() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: LiteReader   File: StaffDetailSummaryViewModel.java   View Source Code Vote up 6 votes
private void initText(String summary) {
    final TextView tvSummary = getSelfView().getBinding().tvSummary;
    final ImageView ivToggle = getSelfView().getBinding().ivToggle;
    tvSummary.setVisibility(View.INVISIBLE);
    tvSummary.setText(summary);
    tvSummary.post(new Runnable() {
        @Override
        public void run() {
            fullHeight = tvSummary.getHeight();
            tvSummary.setHeight(tvSummary.getLineHeight() * maxLine);
            ivToggle.setVisibility(tvSummary.getLineCount() > maxLine ? View.VISIBLE : View.GONE);
            folded = tvSummary.getLineCount() > maxLine;
            tvSummary.setVisibility(View.VISIBLE);
        }
    });
    ivToggle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            playAnimation(tvSummary, ivToggle);
        }
    });
}
 
Example 2
Project: LiteReader   File: DetailSummaryViewModel.java   View Source Code Vote up 6 votes
@Override
public void onViewAttached(View view) {
    if (!hasAttached) {
        final TextView tvSummary = getSelfView().getBinding().tvSummary;
        final ImageView ivToggle = getSelfView().getBinding().ivToggle;
        tvSummary.setText(summary);
        tvSummary.post(new Runnable() {
            @Override
            public void run() {
                fullHeight = tvSummary.getHeight();
                tvSummary.setHeight(tvSummary.getLineHeight() * maxLine);
                ivToggle.setVisibility(tvSummary.getLineCount() > maxLine ? View.VISIBLE : View.GONE);
                folded = tvSummary.getLineCount() > maxLine;
            }
        });
        ivToggle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                playAnimation(tvSummary, ivToggle);
            }
        });
        hasAttached = true;
    }
}
 
Example 3
Project: Aequorea   File: RichText.java   View Source Code Vote up 6 votes
@Override
public void done(Object from) {
    if (from instanceof Integer) {
        int loadedCount = (int) from;
        if (loadedCount >= count) {
            state = RichState.loaded;
            if (config.cacheType >= CacheType.LAYOUT) {
                SpannableStringBuilder ssb = richText.get();
                if (ssb != null) {
                    RichTextPool.getPool().cache(config.source, ssb);
                }
            }
            if (config.callback != null) {
                TextView textView = textViewSoftReference.get();
                if (textView != null) {
                    textView.post(new Runnable() {
                        @Override
                        public void run() {
                            config.callback.done(true);
                        }
                    });
                }
            }
        }
    }
}
 
Example 4
Project: Aequorea   File: RichText.java   View Source Code Vote up 5 votes
protected void generateAndSet() {
    final TextView textView = textViewSoftReference.get();
    if (textView != null) {
        textView.post(new Runnable() {
            @Override
            public void run() {
                asyncGenerate(textView);
            }
        });
    }
}
 
Example 5
Project: Aequorea   File: AbstractImageLoader.java   View Source Code Vote up 5 votes
private void resetText() {
    final TextView tv = textViewWeakReference.get();
    if (tv != null) {
        tv.post(new Runnable() {
            @Override
            public void run() {
                CharSequence cs = tv.getText();
                tv.setText(cs);
            }
        });
    }
}
 
Example 6
Project: kfaryarok-android   File: UpdateAdapter.java   View Source Code Vote up 5 votes
@Override
public void onBindViewHolder(UpdateViewHolder holder, int position) {
    final View itemView = holder.itemView;
    Update update = updates[position];

    // set text
    final TextView tvText = itemView.findViewById(R.id.tv_updatecard_text);
    tvText.setText(update.getText());

    // messy hack that android forces me to use
    // i can't get the line count without queuing a runnable, because it isn't known yet
    // and will only be known once the layout is drawn
    // queuing a runnable will make sure that it's called after drawing
    tvText.post(() -> {
        // if line count is more than the max
        if (tvText.getLineCount() > 3) {
            // set expand view to be visible
            View viewExpand = itemView.findViewById(R.id.view_updatecard_expand);
            viewExpand.setVisibility(View.VISIBLE);
        }
    });

    // set class
    TextView tvClass = itemView.findViewById(R.id.tv_updatecard_class);
    if (update.getAffected().isGlobal()) {
        // tells user it's a global update
        tvClass.setText(R.string.global_update);
    } else {
        // appends all classes to the class textview
        if (update.getAffected() instanceof ClassesAffected) {
            // get user's class
            String userClass = PreferenceUtil.getClassPreference(holder.itemView.getContext());

            // get the affected instance
            ClassesAffected affected = (ClassesAffected) update.getAffected();

            // set class textview to show affected classes, with user's class first
            tvClass.setText(UpdateHelper.formatClassString(affected.getClassesAffected(), userClass));
        }
    }
}
 
Example 7
Project: RLibrary   File: T.java   View Source Code Vote up 5 votes
/**
     * 返回一个唯一的toast
     *
     * @param content the content
     * @param text    the text
     * @return the toast
     */
    private static Toast initToast(Context content, CharSequence text) {
        if (toast == null) {
            synchronized (T.class) {
                if (toast == null) {
                    toast = Toast.makeText(content, text, Toast.LENGTH_SHORT);
                    makeToastFullscreen(content, toast);
                    toast.setView(createToastView(content));
                }
            }
        }
        //toast.setGravity(T_GRAVITY, 0, content.getResources().getDisplayMetrics().heightPixels);
        toast.setGravity(T_GRAVITY, 0, T_OFFSET_Y);
        final View rootView = toast.getView().findViewWithTag("root");
        rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        TextView textView = (TextView) toast.getView().findViewWithTag("text");
        textView.setText(text);
        long currentTimeMillis = System.currentTimeMillis();
        if (currentTimeMillis - lastTime < 2000) {
            textView.post(new Runnable() {
                @Override
                public void run() {
//                ViewCompat.setScaleY(rootView, 0);
                    if (rootView != null) {
                        ViewCompat.setTranslationY(rootView, rootView.getMeasuredHeight());
                        ViewCompat.animate(rootView)
                                .setInterpolator(new LinearInterpolator())
                                .translationY(0)/*.scaleY(1)*/
                                .setDuration(300)
                                .start();
                    }
                }
            });
        }
        lastTime = currentTimeMillis;
        return toast;
    }
 
Example 8
Project: ReadMark   File: WaveLoadingViewHolder.java   View Source Code Vote up 4 votes
private void initViews(){
    mContentView = LayoutInflater.from(mContext)
            .inflate(R.layout.item_wave_loading_view, mViewGroup, false);
    mWaveLoadingView = (WaveLoadingView) mContentView.findViewById(R.id.wave_loading_view);
    mWaveLoadingView.post(new Runnable() {
        @Override
        public void run() {
            mWaveLoadingView.setWaveColor(mBookshelf.getColor());
        }
    });
    mRedPicker = (SeekBar) mContentView.findViewById(R.id.red_picker);
    mGreenPicker = (SeekBar) mContentView.findViewById(R.id.green_picker);
    mBluePicker = (SeekBar) mContentView.findViewById(R.id.blue_picker);
    mAmpPicker = (SeekBar) mContentView.findViewById(R.id.amp_picker);
    mWavePicker = (SeekBar) mContentView.findViewById(R.id.wave_picker);
    mCurrentPage = (EditText) mContentView.findViewById(R.id.edit_current_page);
    mTotalPages = (TextView) mContentView.findViewById(R.id.text_total_page);
    mConfirmButton = (Button) mContentView.findViewById(R.id.button_confirm);
    //mCancelButton = (Button) mContentView.findViewById(R.id.button_cancel);


    mRedPicker.post(new Runnable() {
        @Override
        public void run() {
            mRedPicker.setProgress( (int)((mBookshelf.getRed() / 255.0f) * 100));
        }
    });
    mGreenPicker.post(new Runnable() {
        @Override
        public void run() {
            mGreenPicker.setProgress((int)((mBookshelf.getGreen() / 255.0f) * 100));
        }
    });
    mBluePicker.post(new Runnable() {
        @Override
        public void run() {
            mBluePicker.setProgress((int)((mBookshelf.getBlue() / 255.0f) * 100));
        }
    });
    mAmpPicker.post(new Runnable() {
        @Override
        public void run() {
            //范围是0~1
            mAmpPicker.setProgress((int) (mBookshelf.getAmpratio() * 100));
        }
    });
    mWavePicker.post(new Runnable() {
        @Override
        public void run() {
            mWavePicker.setProgress((int) (mBookshelf.getWaveratio() * 100));
        }
    });
    mCurrentPage.post(new Runnable() {
        @Override
        public void run() {
            mCurrentPage.setText(""+mBookshelf.getCurrentpage());
        }
    });
    mTotalPages.post(new Runnable() {
        @Override
        public void run() {
            mTotalPages.setText("of "+mBookshelf.getTotalpage());
        }
    });
    //mWaveLoadingView.setProgress(mBookshelf.getProgress());
    Log.e("此时progress是",mBookshelf.getProgress()+"");
    mWaveLoadingView.setTitletext(((int)(mBookshelf.getProgress() * 100)) + "" + " %");


}