title: Android support library 23.4.0: android.support.v7.widget.TintContextWrapper cannot be cast to Activity
body: <p>So I updated to the latest support libraries, and got a crash I am not able to fix. My build.gradle now has these dependencies:</p>
  
  <pre><code>dependencies {
      compile 'com.android.support:appcompat-v7:23.4.0'
      compile 'com.android.support:gridlayout-v7:23.4.0'
      compile 'com.android.support:support-v4:23.4.0'
      compile 'com.android.support:cardview-v7:23.4.0'
      compile 'com.android.support:recyclerview-v7:23.4.0'
      compile 'com.android.support:design:23.4.0'
      // More stuff...
  }
  </code></pre>
  
  <p>I had a working listener that is used to catch clicks and start a new Activity. This was working fine in support libraries v. 23.1.0, but not in 23.4.0 (and 23.3.0):</p>
  
  <pre><code>public class IngredientItemOnClickListener implements OnClickListener
  {
      private Ingredient mIngredient;
  
      public IngredientItemOnClickListener(Ingredient ingredient)
      {
          mIngredient= ingredient;
      }
  
      @Override
      public void onClick(View view)
      {
          MyActivity myActivity = (MyActivity) view.getContext(); // &lt;-- crash here
          myActivity.showIngredientActivity(mIngredient);
      }
  }
  </code></pre>
  
  <p>This listener is simply attached to an <code>ImageButton</code> and thereafter the color of the Button is tinted, like this:</p>
  
  <pre><code>Ingredient ingredient = getIngredient();
  myImageButton.setOnClickListener(new IngredientItemOnClickListener(ingredient));
  Drawable drawable = Tinting.tint(myActivity, R.drawable.my_icon, R.color.red);
  myImageButton.setImageDrawable(drawable);
  </code></pre>
  
  <p>where <code>Tinting.tint()</code> is my own tinting function:</p>
  
  <pre><code>public class Tinting
  {
      @Nullable
      public static Drawable tint(Context context, int drawableId, int colorId)
      {
          final Drawable drawable = ContextCompat.getDrawable(context, drawableId);
          if (drawable != null)
          {
              final Drawable wrapped = DrawableCompat.wrap(drawable);
              drawable.mutate();
              DrawableCompat.setTint(wrapped, ContextCompat.getColor(context, colorId));
          }
          return drawable;
      }
  }
  </code></pre>
  
  <p>Previously when I clicked the button everything worked as expected, but now the Context of the View seems to have changed to <code>TintContextWrapper</code> which I can find little information about. I found <a href="https://code.google.com/p/android/issues/detail?id=208643">this issue</a>, but the project member advises to ask here on StackOverflow, so here it is.</p>
  
  <h3>What have I tried?</h3>
  
  <p>Since the project member in the Google issue stated <em>You will need to obtain the activity from the wrapped context.</em> I tried casting to <code>TintContextWrapper</code> instead of <code>MyActivity</code>, which works fine, but I cannot figure out how to get <code>MyActivity</code> from <code>TintContextWrapper</code>.</p>
  
  <h3>So my questions are:</h3>
  
  <ol>
  <li>How can I get <code>MyActivity</code> from the <code>TintContextWrapper</code>?</li>
  <li>Why is my <code>ImageButton</code> suddenly wrapped in a <code>TintContextWrapper</code>.</li>
  <li>Should this behavior really be expected? </li>
  </ol>
  
  <h3>Definition of ImageButton in xml is simply:</h3>
  
  <pre><code>&lt;ImageButton
      android:id="@+id/my_id"
      android:src="@drawable/my_icon" /&gt;
  </code></pre>
  
  <h3>Stack trace:</h3>
  
  <pre><code>java.lang.ClassCastException: android.support.v7.widget.TintContextWrapper cannot be cast to com.my.app.activities.MyActivity
      at com.my.app.listeners.IngredientItemOnClickListener.onClick(IngredientItemOnClickListener.java:21)
      at android.view.View.performClick(View.java:4475)
      at android.view.View$PerformClick.run(View.java:18786)
      at android.os.Handler.handleCallback(Handler.java:730)
      at android.os.Handler.dispatchMessage(Handler.java:92)
      at android.os.Looper.loop(Looper.java:176)
      at android.app.ActivityThread.main(ActivityThread.java:5419)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:525)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
      at dalvik.system.NativeStart.main(Native Method)
  </code></pre>