/*
 *  Copyright 2016 Google Inc. All Rights Reserved.
 *
 *  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.google.android.apps.forscience.whistlepunk;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.widget.ImageView;

/**
 * Static util class for working with SensorAppearance instances
 */
public final class Appearances {
    private Appearances() {
        // prevent construction
    }

    /**
     * Not thread-safe: only call from main thread!
     */
    public static void applyDrawableToImageView(Drawable drawable, ImageView view, int color) {
        drawable.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
        view.setImageDrawable(drawable);
    }

    public static String getSensorDisplayName(SensorAppearance appearance, Context context) {
        String units = appearance.getUnits(context);
        return TextUtils.isEmpty(units) ?
                appearance.getName(context) : String.format(context.getResources().getString(
                R.string.header_name_and_units), appearance.getName(context), units);
    }
}

/*
 *  Copyright 2016 Google Inc. All Rights Reserved.
 *
 *  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.google.android.apps.forscience.whistlepunk;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.widget.ImageView;

/**
 * Static util class for working with SensorAppearance instances
 */
public final class Appearances {
    private Appearances() {
        // prevent construction
    }

    /**
     * Not thread-safe: only call from main thread!
     */
    public static void applyDrawableToImageView(Drawable drawable, ImageView view, int color) {
        drawable.mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
        view.setImageDrawable(drawable);
    }

    public static String getSensorDisplayName(SensorAppearance appearance, Context context) {
        String units = appearance.getUnits(context);
        return TextUtils.isEmpty(units) ?
                appearance.getName(context) : String.format(context.getResources().getString(
                R.string.header_name_and_units), appearance.getName(context), units);
    }
}

Fix sensor icon colors.