/* 
 * Copyright 2017 Vector Creations Ltd
 * 
 * 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 im.vector.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
import android.support.annotation.IntDef;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import org.w3c.dom.Text;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import im.vector.R;

public class UnreadCounterBadgeView extends RelativeLayout {
    // the background settings
    public static final int HIGHLIGHTED = 0;
    public static final int NOTIFIED = 1;
    public static final int DEFAULT = 2;

    @IntDef({HIGHLIGHTED, NOTIFIED, DEFAULT})
    @Retention(RetentionPolicy.SOURCE)
    public @interface Status {
    }

    private TextView mCounterTextView;
    private View mParentView;

    public UnreadCounterBadgeView(Context context) {
        super(context);
        init();
    }

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

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

    private void init() {
        inflate(getContext(), R.layout.unread_counter_badge, this);
        mCounterTextView = (TextView) findViewById(R.id.unread_counter_badge_text_view);
        mParentView = findViewById(R.id.unread_counter_badge_layout);
    }

    /**
     * Update the badge value and its status
     *
     * @param value  the new value
     * @param status the new status
     */
    public void updateCounter(int value, @Status int status) {
        if (value > 0) {
            if (value > 999) {
                mCounterTextView.setText((value / 1000) + "." + ((value % 1000) / 100) + "K");
            } else {
                mCounterTextView.setText(value + "");
            }
            setVisibility(View.VISIBLE);

            GradientDrawable shape = new GradientDrawable();
            shape.setShape(GradientDrawable.RECTANGLE);
            shape.setCornerRadius(100);
            if (status == HIGHLIGHTED) {
                shape.setColor(getContext().getResources().getColor(R.color.vector_fuchsia_color));
            } else if (status == NOTIFIED) {
                shape.setColor(getContext().getResources().getColor(R.color.vector_green_color));
            } else { //if (status == DEFAULT)
                shape.setColor(getContext().getResources().getColor(R.color.vector_silver_color));
            }
            mParentView.setBackground(shape);
        } else {
            setVisibility(View.INVISIBLE);
        }
    }
}
@@ -662,40 +662,8 @@
 xt;%0A
-import android.graphics.Bitmap;%0A
 impo
@@ -728,15 +728,33 @@
 oid.
-net.Uri
+support.annotation.IntDef
 ;%0Aim
@@ -774,33 +774,40 @@
 support.
-annotation.IntDef
+v4.content.ContextCompat
 ;%0Aimport
@@ -864,41 +864,8 @@
 ew;%0A
-import android.widget.ImageView;%0A
 impo
@@ -935,34 +935,8 @@
 w;%0A%0A
-import org.w3c.dom.Text;%0A%0A
 impo
@@ -2814,45 +2814,45 @@
 lor(
-get
 Context
-().getResources().getColor(
+Compat.getColor(getContext(), 
 R.co
@@ -2959,45 +2959,45 @@
 lor(
-get
 Context
-().getResources().getColor(
+Compat.getColor(getContext(), 
 R.co
@@ -3103,45 +3103,45 @@
 lor(
-get
 Context
-().getResources().getColor(
+Compat.getColor(getContext(), 
 R.co

Fix deprecated method