com.gemapps.saidit.util.ViewUtil.java Source code

Java tutorial

Introduction

Here is the source code for com.gemapps.saidit.util.ViewUtil.java

Source

/*
 *    Copyright 2017 Edu Graciano
 *
 *    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.gemapps.saidit.util;

import android.graphics.Outline;
import android.support.v4.view.ViewCompat;
import android.view.View;
import android.view.ViewOutlineProvider;

/**
 * Created by edu on 3/22/17.
 */

public class ViewUtil {

    public static final ViewOutlineProvider CIRCULAR_OUTLINE = new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            outline.setOval(view.getPaddingLeft(), view.getPaddingTop(), view.getWidth() - view.getPaddingRight(),
                    view.getHeight() - view.getPaddingBottom());
        }
    };

    /**
     * Set a new top padding
     *
     * @param view       The view to set the new top padding
     * @param paddingTop The new padding value
     */
    public static void setPaddingTop(View view, int paddingTop) {

        ViewCompat.setPaddingRelative(view, view.getPaddingLeft(), paddingTop, view.getPaddingRight(),
                view.getPaddingBottom());

    }
}