Example #1
0
  /** Called when the activity is first created. */
  @TargetApi(11)
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    _txtView = (TextView) findViewById(R.id.textView1);
    _scroll = (ScrollView) findViewById(R.id.scrollView1);
    _logTextView = (TextView) findViewById(R.id.logTextView);
    _startStopButton = (Button) findViewById(R.id.button1);
    _debugButton = (ToggleButton) findViewById(R.id.debugButton);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      // Ensure to scroll down on each text change
      _logTextView.addOnLayoutChangeListener(
          new OnLayoutChangeListener() {
            public void onLayoutChange(
                View v,
                int left,
                int top,
                int right,
                int bottom,
                int oldLeft,
                int oldTop,
                int oldRight,
                int oldBottom) {
              _scroll.smoothScrollTo(0, _logTextView.getHeight());
            }
          });
    }
  }
 private void init(Context context) {
   inflate(context, R.layout.captioned_image_view, this);
   mTextView = (TextView) findViewById(R.id.text);
   mImageView = (SquareImageView) findViewById(R.id.image);
   mScrimColor = getResources().getColor(R.color.grid_item_scrim);
   mTextView.addOnLayoutChangeListener(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;
  }