/*
 * Copyright 2016 Peter Kenji Yamanaka
 *
 * 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
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.
 */

package com.pyamsoft.pydroid.app.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.AppCompatDrawableManager;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import com.pyamsoft.pydroid.R;

public class VectorTextView extends NoLeakTextView {

  public VectorTextView(Context context) {
    super(context);
    init(null);
  }

  public VectorTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init(attrs);
  }

  public VectorTextView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init(attrs);
  }

  private void init(@Nullable AttributeSet attrs) {
    if (attrs != null) {
      final Context context = getContext();
      final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.VectorTextView);

      // Obtain DrawableManager used to pull Drawables safely, and check if we're in RTL
      final AppCompatDrawableManager dm = AppCompatDrawableManager.get();
      final boolean rtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;

      // Grab the compat drawable resources from the XML
      final int startDrawableRes = a.getResourceId(R.styleable.VectorTextView_drawableStart, 0);
      final int topDrawableRes = a.getResourceId(R.styleable.VectorTextView_drawableTop, 0);
      final int endDrawableRes = a.getResourceId(R.styleable.VectorTextView_drawableEnd, 0);
      final int bottomDrawableRes = a.getResourceId(R.styleable.VectorTextView_drawableBottom, 0);

      // Load the used drawables, falling back to whatever may be set in an "android:" namespace attribute
      final Drawable[] currentDrawables = getCompoundDrawables();
      final Drawable left =
          startDrawableRes != 0 ? dm.getDrawable(context, startDrawableRes) : currentDrawables[0];
      final Drawable right =
          endDrawableRes != 0 ? dm.getDrawable(context, endDrawableRes) : currentDrawables[1];
      final Drawable top =
          topDrawableRes != 0 ? dm.getDrawable(context, topDrawableRes) : currentDrawables[2];
      final Drawable bottom =
          bottomDrawableRes != 0 ? dm.getDrawable(context, bottomDrawableRes) : currentDrawables[3];

      // Account for RTL and apply the compound Drawables
      final Drawable start = rtl ? right : left;
      final Drawable end = rtl ? left : right;
      setCompoundDrawablesWithIntrinsicBounds(start, top, end, bottom);

      a.recycle();
    }
  }
}

@@ -871,73 +871,19 @@
 .v7.
-widget.AppCompatDrawableManager;%0Aimport android.support.v7.widget
+content.res
 .App
@@ -888,24 +888,25 @@
 ppCompat
-TextView
+Resources
 ;%0Aimport
@@ -1668,82 +1668,8 @@
 RTL%0A
-      final AppCompatDrawableManager dm = AppCompatDrawableManager.get();%0A
     
@@ -2430,34 +2430,50 @@
 wableRes != 0 ? 
-dm
+AppCompatResources
 .getDrawable(con
@@ -2487,32 +2487,46 @@
 tartDrawableRes)
+%0A             
  : currentDrawab
@@ -2586,34 +2586,50 @@
 wableRes != 0 ? 
-dm
+AppCompatResources
 .getDrawable(con
@@ -2641,32 +2641,46 @@
  endDrawableRes)
+%0A             
  : currentDrawab
@@ -2738,34 +2738,50 @@
 wableRes != 0 ? 
-dm
+AppCompatResources
 .getDrawable(con
@@ -2793,32 +2793,46 @@
  topDrawableRes)
+%0A             
  : currentDrawab
@@ -2908,10 +2908,26 @@
 0 ? 
-dm
+AppCompatResources
 .get
@@ -2962,16 +2962,30 @@
 ableRes)
+%0A             
  : curre

Update vector text