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

The following examples show how to use android.widget.TextView#post() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: arcusandroid   File: SpinnerAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
    View mView = super.getDropDownView(position, convertView, parent);
    TextView mTextView = (TextView) mView;

    // Don't change single line setting until view is rendered, otherwise this has no effect :(
    final TextView finalTextView = mTextView;
    mTextView.post(new Runnable() {
        @Override
        public void run() {
            finalTextView.setSingleLine(!wrapText);
        }
    });

    if (!isEnabled(position)) {
        mTextView.setTextColor(Color.GRAY);
    } else {
        mTextView.setTextColor(Color.BLACK);
    }
    return mView;
}
 
Example 2
public void setProgressText(final String text) {
	if(text.length() > 0) {
		try {
			setFieldVisibility("mProgressPercent", View.VISIBLE);
			
			final TextView textView = (TextView) getField("mProgressPercent").get(this);
			
			textView.post(new Runnable() {
				public void run() {
					textView.setText(text);
				}
			});
		} catch(Exception e) {
		}
	} else {
		setFieldVisibility("mProgressPercent", progressPercentVisibility);
	}
}
 
Example 3
@Override
protected void initViews(View view) {
    super.initViews(view);
    setLabel("PropertyCustomEvaluate");
    view.findViewById(R.id.btn_start_by_property).setOnClickListener(this);

    textView = (TextView) view.findViewById(R.id.text_view);
    textView.setOnClickListener(this);

    //save beginning position
    textView.post(new Runnable() {
        @Override
        public void run() {
            if (left == 0) {
                left = textView.getLeft();
            }
            if (top == 0) {
                top = textView.getTop();
            }
        }
    });
}
 
Example 4
Source Project: Markwon   File: PrecomputedActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_text_view);

    final Markwon markwon = Markwon.builder(this)
            // please note that precomputedTextCompat is no-op on devices lower than L (21)
            .textSetter(PrecomputedTextSetterCompat.create(Executors.newCachedThreadPool()))
            .build();

    final TextView textView = findViewById(R.id.text_view);
    final String markdown = "# Hello!\n\n" +
            "This _displays_ how to implement and use `PrecomputedTextCompat` with the **Markwon**\n\n" +
            "> consider using PrecomputedText only if your markdown content is large enough\n> \n" +
            "> **please note** that it works badly with `markwon-recycler` due to asynchronous nature";

    // please note that _sometimes_ (if done without `post` here) further `textView.post`
    // (that is used in PrecomputedTextSetterCompat to deliver result to main-thread) won't be called
    // making the result of pre-computation absent and text-view clear (no text)
    textView.post(() -> markwon.setMarkdown(textView, markdown));
}
 
Example 5
Source Project: UIWidget   File: UIAlertDialog.java    License: Apache License 2.0 6 votes vote down vote up
private void createMessage() {
    if (TextUtils.isEmpty(mMessageStr)) {
        return;
    }
    ViewGroup.MarginLayoutParams params = new ViewGroup.MarginLayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    mTvMessage = new TextView(mContext);
    mTvMessage.setLayoutParams(params);
    mTvMessage.setId(R.id.tv_messageAlertDialog);
    mListViews.add(0, mTvMessage);

    setTextAttribute(mTvMessage, mMessageStr, mMessageTextColor, mMessageTextSize, mMessageTextGravity, mMessageTextFakeBoldEnable);
    mTvMessage.post(new Runnable() {
        @Override
        public void run() {
            int lineCount = mTvMessage.getLineCount();
            if (lineCount > 1) {
                mTvMessage.setGravity(Gravity.LEFT | mTvMessage.getGravity());
            }
            if (mOnTextViewLineListener != null) {
                mOnTextViewLineListener.onTextViewLineListener(mTvMessage, lineCount);
            }
        }
    });
}
 
Example 6
Source Project: RichText   File: RichText.java    License: MIT License 6 votes vote down vote up
@Override
public void done(Object from) {
    if (from instanceof Integer) {
        int loadedCount = (int) from;
        if (loadedCount >= count) {
            state = RichState.loaded;
            TextView tv = textViewWeakReference.get();
            if (config.callback != null) {
                if (null != tv) {
                    tv.post(new Runnable() {
                        @Override
                        public void run() {
                            config.callback.done(true);
                        }
                    });
                }
            }
        }
    }
}
 
Example 7
Source Project: InlineActivityResult   File: AppendText.java    License: MIT License 5 votes vote down vote up
public static void appendText(TextView textView, String text){
    textView.post(new Runnable() {
        @Override
        public void run() {
            textView.setText(textView.getText()+"\n"+text);
        }
    });
}
 
Example 8
Source Project: RuntimePermission   File: AppendText.java    License: Apache License 2.0 5 votes vote down vote up
public static void appendText(TextView textView, String text){
    textView.post(new Runnable() {
        @Override
        public void run() {
            textView.setText(textView.getText()+"\n"+text);
        }
    });
}
 
Example 9
private static void applyText(
        @Nullable final TextView textView,
        @NonNull final Spanned text,
        @NonNull final TextView.BufferType bufferType,
        @NonNull final Runnable onComplete) {
    if (textView != null) {
        textView.post(new Runnable() {
            @Override
            public void run() {
                textView.setText(text, bufferType);
                onComplete.run();
            }
        });
    }
}
 
Example 10
public Thread printIncrement(final TextView textView, final Locale locale, final String format, final long startNumber, final long endNumber, final long millis) {
    final Thread thread = printIncrementPostDelayed(textView, locale, format, startNumber, endNumber, millis);
    textView.post(new Runnable() {
        @Override
        public void run() {
            thread.start();
        }
    });

    return thread;

}
 
Example 11
Source Project: NewXmPluginSDK   File: ControlActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_DONE) {
        v.post(new Runnable() {

            @Override
            public void run() {
                clearAllFocus();
                setRGB();
            }
        });
    }
    return false;
}
 
Example 12
Source Project: RichText   File: AbstractImageLoader.java    License: MIT License 5 votes vote down vote up
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 13
private void loadUserInfo(ImageView userPicture, final MyUser user, final TextView userName) {
    BitmapDownloadTask task = new BitmapDownloadTask(this, userPicture, ImageKind.User);
    task.execute(user.getPictureId() != null ? user.getPictureId().toString() : null);
    userName.post(new Runnable() {
        @Override
        public void run() {
            userName.setText(user.getDisplayName());
        }
    });
}
 
Example 14
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
	try {
		// We're going to re-add all of the fragments, so get rid of the old ones
		List<Fragment> fragments = getSupportFragmentManager().getFragments();
		if (fragments != null) {
			for (Fragment fragment : fragments) {
				if (fragment != null) {
					getSupportFragmentManager().beginTransaction().remove(fragment).commit();
				}
			}
		}
		
		if (savedInstanceState != null) {
			String consoleText = savedInstanceState.getString("consoleText");
			final int consoleScrollPos = savedInstanceState.getInt("consoleScrollPos");
			final int consoleScrollPosX = savedInstanceState.getInt("consoleScrollPosX");
			String messageText = savedInstanceState.getString("messageText");
			MessageType msgType = MessageType.deserialize(savedInstanceState.getString("messageIsError"));
			
			TextView console = (TextView) findViewById(R.id.console);
			final ScrollView consoleScroller = (ScrollView) findViewById(R.id.console_scroller);
			final HorizontalScrollView consoleScrollerX = (HorizontalScrollView) findViewById(R.id.console_scroller_x);
			
			if (consoleText != null) {
				// Assume that they're all there...
				
				console.setText(consoleText);
				
				// This doesn't actually work in practice because the text is always
				// replaced with "The sketch has been saved"...
				switch (msgType) {
					case MESSAGE:
						message(messageText);
						break;
					case ERROR:
						error(messageText);
						break;
					case WARNING:
						warning(messageText);
						break;
				}
				
				console.post(new Runnable() {
					@Override
					public void run() {
						consoleScroller.scrollTo(0, consoleScrollPos);
						consoleScrollerX.scrollTo(consoleScrollPosX, 0);
					}
				});
			}
		}
	} catch (Exception e) {
		// Who knows really...
		e.printStackTrace();
	}
	
	getGlobalState().writeCodeDeletionDebugStatus("onRestoreInstanceState()");
}
 
Example 15
/**
 * Fix inconsistencies in the vertical distribution of the content area views
 */
public void refreshMessageAreaLocation() {
	//Obtain some references
	final View content = findViewById(R.id.content);
	final View console = findViewById(R.id.console_wrapper);
	final View code = getSelectedCodeAreaScroller();
	final TextView messageArea = (TextView) findViewById(R.id.message);
	final FrameLayout autoCompileProgress = findViewById(R.id.auto_compile_progress_wrapper);
	
	if (firstResize) {
		//Use some better layout parameters - this switches from fractions/layout weights to absolute values
		code.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, code.getHeight()));
		console.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, console.getHeight()));

		firstResize = false;
	}
	
	messageArea.requestLayout();
	
	messageArea.post(() -> {
		//We need to use this in case the message area is partially off the screen
		//This is the DESIRED height, not the ACTUAL height
		message = getTextViewHeight(getApplicationContext(), messageArea.getText().toString(), messageArea.getTextSize(), findViewById(R.id.message_char_insert_wrapper).getWidth(), messageArea.getPaddingTop());

		int consoleSize = content.getHeight() - code.getHeight() - message - (extraHeaderView != null ? extraHeaderView.getHeight() : 0) - tabBarContainer.getHeight() - autoCompileProgress.getHeight();

		//We can't shrink the console if it's hidden (like when the keyboard is visible)...
		//...so shrink the code area instead
		if (consoleSize < 0 || consoleWasHidden || keyboardVisible) {
			console.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0));
			code.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
					content.getHeight() - message - (extraHeaderView != null ? extraHeaderView.getHeight() : 0) - tabBarContainer.getHeight() - autoCompileProgress.getHeight()));

			consoleWasHidden = true;
		} else {
			console.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, consoleSize));

			consoleWasHidden = false;
		}
	});
}
 
Example 16
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_flexiblespacewithimagerecyclerview);

    mFlexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    mActionBarSize = getActionBarSize();

    ObservableRecyclerView recyclerView = (ObservableRecyclerView) findViewById(R.id.recycler);
    recyclerView.setScrollViewCallbacks(this);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setHasFixedSize(false);
    final View headerView = LayoutInflater.from(this).inflate(R.layout.recycler_header, null);
    headerView.post(new Runnable() {
        @Override
        public void run() {
            headerView.getLayoutParams().height = mFlexibleSpaceImageHeight;
        }
    });
    setDummyDataWithHeader(recyclerView, headerView);

    mImageView = findViewById(R.id.image);
    mOverlayView = findViewById(R.id.overlay);

    mTitleView = (TextView) findViewById(R.id.title);
    mTitleView.setText(getTitle());
    setTitle(null);

    // mRecyclerViewBackground makes RecyclerView's background except header view.
    mRecyclerViewBackground = findViewById(R.id.list_background);

    //since you cannot programmatically add a header view to a RecyclerView we added an empty view as the header
    // in the adapter and then are shifting the views OnCreateView to compensate
    final float scale = 1 + MAX_TEXT_SCALE_DELTA;
    mRecyclerViewBackground.post(new Runnable() {
        @Override
        public void run() {
            ViewHelper.setTranslationY(mRecyclerViewBackground, mFlexibleSpaceImageHeight);
        }
    });
    ViewHelper.setTranslationY(mOverlayView, mFlexibleSpaceImageHeight);
    mTitleView.post(new Runnable() {
        @Override
        public void run() {
            ViewHelper.setTranslationY(mTitleView, (int) (mFlexibleSpaceImageHeight - mTitleView.getHeight() * scale));
            ViewHelper.setPivotX(mTitleView, 0);
            ViewHelper.setPivotY(mTitleView, 0);
            ViewHelper.setScaleX(mTitleView, scale);
            ViewHelper.setScaleY(mTitleView, scale);
        }
    });
}
 
Example 17
Source Project: ReadMark   File: WaveLoadingViewHolder.java    License: Apache License 2.0 4 votes vote down vote up
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)) + "" + " %");


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

    textView = (TextView) findViewById(R.id.test);


    if (first){
        textView.post(new Runnable() {
            @Override
            public void run() {
                tvLeft = textView.getLeft();
                tvTop = textView.getTop();
                tvRight = textView.getRight();
                tvBottom = textView.getBottom();
                first = false;
                textView.setText(tvLeft + "," + tvTop + "," + tvRight + "," + tvBottom);
            }
        });
    }


    textView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    startX = (int) event.getRawX();
                    startY = (int) event.getRawY();
                    Left = textView.getLeft();
                    Top = textView.getTop();
                    Right = textView.getRight();
                    Bottom = textView.getBottom();
                    break;
                case MotionEvent.ACTION_MOVE:
                    textView.layout(
                            (int) (Left + event.getRawX() - startX),
                            (int) (Top + event.getRawY() - startY),
                            (int) (Right + event.getRawX() - startX),
                            (int) (Bottom + event.getRawY() - startY));
                    break;
                case MotionEvent.ACTION_UP:
                    AnimatorSet set = new AnimatorSet();
                    set.playTogether(
                            ObjectAnimator.ofFloat(textView, "translationX", tvLeft - textView.getLeft()),
                            ObjectAnimator.ofFloat(textView, "translationY", tvTop - textView.getTop())
                    );
                    set.setDuration(2000).start();

                    textView.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            textView.layout(textView.getLeft(), textView.getTop(), textView.getRight(), textView.getBottom());
                        }
                    }, 2000);

                    break;
            }
            return true;
        }
    });

}
 
Example 19
Source Project: ReadMark   File: WaveLoadingViewHolder.java    License: Apache License 2.0 4 votes vote down vote up
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)) + "" + " %");


}
 
Example 20
Source Project: RichText   File: GlideImageGetter.java    License: MIT License 4 votes vote down vote up
@Override
public Drawable getDrawable(ImageHolder holder, final RichTextConfig config, TextView textView) {
    final ImageTarget target;
    final GenericRequestBuilder load;
    DrawableTypeRequest dtr;
    DrawableWrapper drawableWrapper = new DrawableWrapper();
    byte[] src = Base64.decode(holder.getSource());
    if (src != null) {
        dtr = Glide.with(textView.getContext()).load(src);
    } else {
        dtr = Glide.with(textView.getContext()).load(holder.getSource());
    }
    Rect rect = null;
    if (config.cacheType >= CacheType.LAYOUT) {
        rect = loadCache(holder.getSource());
        if (rect != null) {
            drawableWrapper.setBounds(rect);
        }
    } else {
        drawableWrapper.setBounds(0, 0, holder.getWidth(), holder.getHeight());
    }
    if (holder.isGif()) {
        target = new ImageTargetGif(textView, drawableWrapper, holder, config, this, rect);
        load = dtr.asGif();
    } else {
        target = new ImageTargetBitmap(textView, drawableWrapper, holder, config, this, rect);
        load = dtr.asBitmap().atMost();
    }
    checkTag(textView);
    targets.add(target);
    if (!config.resetSize && holder.isInvalidateSize()) {
        load.override(holder.getWidth(), holder.getHeight());
    }
    if (holder.getScaleType() == ImageHolder.ScaleType.CENTER_CROP) {
        if (holder.isGif()) {
            //noinspection ConstantConditions
            ((GifTypeRequest) load).centerCrop();
        } else {
            //noinspection ConstantConditions
            ((BitmapTypeRequest) load).centerCrop();
        }
    } else if (holder.getScaleType() == ImageHolder.ScaleType.FIT_CENTER) {
        if (holder.isGif()) {
            //noinspection ConstantConditions
            ((GifTypeRequest) load).fitCenter();
        } else {
            //noinspection ConstantConditions
            ((BitmapTypeRequest) load).fitCenter();
        }
    }
    textView.post(new Runnable() {
        @Override
        public void run() {
            load.placeholder(config.placeHolder).error(config.errorImage).into(target);
        }
    });
    drawableWrapper.setCallback(textView);
    return drawableWrapper;
}