content: package com.music.player.bhandari.m.customViews;
  
  import android.content.Context;
  
  import androidx.annotation.NonNull;
  
  import android.util.AttributeSet;
  import android.util.Log;
  import android.util.TypedValue;
  import android.view.MotionEvent;
  import android.view.ScaleGestureDetector;
  import android.widget.TextView;
  
  /**
   * Copyright 2017 Amit Bhandari AB
   * <p>
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * <p>
   * http://www.apache.org/licenses/LICENSE-2.0
   * <p>
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  public class ZoomTextView extends TextView {
      private static final String TAG = "ZoomTextView";
      private ScaleGestureDetector mScaleDetector;
  
      private float mScaleFactor = 1.f;
      private float defaultSize;
  
      private float zoomLimit = 3.0f;
  
  
      public ZoomTextView(Context context) {
          super(context);
          initialize();
      }
  
      public ZoomTextView(Context context, AttributeSet attrs) {
          super(context, attrs);
          initialize();
      }
  
      public ZoomTextView(Context context, AttributeSet attrs, int defStyleAttr) {
          super(context, attrs, defStyleAttr);
          initialize();
      }
  
      private void initialize() {
          defaultSize = getTextSize();
          mScaleDetector = new ScaleGestureDetector(getContext(), new ScaleListener());
  
      }
  
      /***
       * @param zoomLimit
       * Default value is 3, 3 means text can zoom 3 times the default size
       */
  
      public void setZoomLimit(float zoomLimit) {
          this.zoomLimit = zoomLimit;
      }
  
      @Override
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          super.onMeasure(widthMeasureSpec, heightMeasureSpec);
      }
  
      @Override
      public boolean onTouchEvent(@NonNull MotionEvent ev) {
          super.onTouchEvent(ev);
          mScaleDetector.onTouchEvent(ev);
          return true;
      }
  
      /*Scale Gesture listener class,
      mScaleFactor is getting the scaling value
      and mScaleFactor is mapped between 1.0 and and zoomLimit
      that is 3.0 by default. You can also change it. 3.0 means text
      can zoom to 3 times the default value.*/
  
      private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
          @Override
          public boolean onScale(ScaleGestureDetector detector) {
              mScaleFactor *= detector.getScaleFactor();
              mScaleFactor = Math.max(1.0f, Math.min(mScaleFactor, zoomLimit));
              setTextSize(TypedValue.COMPLEX_UNIT_PX, defaultSize * mScaleFactor);
              Log.e(TAG, String.valueOf(mScaleFactor));
              return true;
          }
      }
  }