/** * Set the enabled state of automatically resizing text. */ public AutofitHelper setEnabled(boolean enabled) { if (mEnabled != enabled) { mEnabled = enabled; if (enabled) { mTextView.addTextChangedListener(mTextWatcher); mTextView.addOnLayoutChangeListener(mOnLayoutChangeListener); autofit(); } else { mTextView.removeTextChangedListener(mTextWatcher); mTextView.removeOnLayoutChangeListener(mOnLayoutChangeListener); mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); } } return this; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout); TextView textView = ((TextView) findViewById(R.id.home_trafic_text)); textView.setText(getString(R.string.loading)); textView.setEnabled(true); // Thanks to Romain Guy textView.addOnLayoutChangeListener(new OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { LayoutParams params = v.getLayoutParams(); params.width = right - left; params.height = bottom - top; params.weight = 0; v.removeOnLayoutChangeListener(this); v.setLayoutParams(params); } }); }
PrinterStateDialog(@NonNull Context context, @NonNull OnDialogListener listener) { super(context, AlertDialogUtils.getAlertDialogTheme(context)); mListener = listener; setContentView(R.layout.dlg_printer_state); mVContent = findViewById(R.id.dps_sv_content); mVState = findViewById(R.id.dps_tv_state); mVNegative = findViewById(R.id.dps_btn_negative); mVPositive = findViewById(R.id.dps_btn_positive); mVState.addOnLayoutChangeListener(this); mVNegative.setOnClickListener(this); mVPositive.setOnClickListener(this); }
/** * Set the enabled state of automatically resizing text. */ public AutofitHelper setEnabled(boolean enabled) { if (mEnabled != enabled) { mEnabled = enabled; if (enabled) { mTextView.addTextChangedListener(mTextWatcher); mTextView.addOnLayoutChangeListener(mOnLayoutChangeListener); autofit(); } else { mTextView.removeTextChangedListener(mTextWatcher); mTextView.removeOnLayoutChangeListener(mOnLayoutChangeListener); mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); } } return this; }
/** * Creates a WebappUrlBar. * @param context Context to grab resources from. */ public WebappUrlBar(Context context, AttributeSet attrSet) { super(context, attrSet); mIconResourceWidths = new SparseIntArray(); mUrlBar = new TextView(context); mUrlBar.setSingleLine(true); mUrlBar.setGravity(Gravity.CENTER_VERTICAL); mUrlBar.setMovementMethod(ScrollingMovementMethod.getInstance()); mUrlBar.setHorizontalFadingEdgeEnabled(true); mSeparator = new View(context); addView(mUrlBar, new FrameLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER)); addView(mSeparator, new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.BOTTOM)); // Set the colors. mSeparator.setBackgroundColor(ApiCompatibilityUtils.getColor(context.getResources(), R.color.webapp_url_bar_separator)); setBackgroundColor(ApiCompatibilityUtils.getColor(context.getResources(), R.color.webapp_url_bar_bg)); // Listen for changes in the URL bar's size. mUrlBar.addOnLayoutChangeListener(this); }
mUrlBar.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom,