1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settingslib.widget; 18 19 import android.content.res.Resources; 20 import android.content.res.Resources.Theme; 21 import android.graphics.Path; 22 import android.graphics.drawable.AdaptiveIconDrawable; 23 import android.graphics.drawable.ShapeDrawable; 24 import android.graphics.drawable.shapes.PathShape; 25 import android.util.AttributeSet; 26 import android.util.PathParser; 27 28 import org.xmlpull.v1.XmlPullParser; 29 import org.xmlpull.v1.XmlPullParserException; 30 31 import java.io.IOException; 32 33 /** 34 * Draws a filled {@link ShapeDrawable} using the path from {@link AdaptiveIconDrawable}. 35 */ 36 public class AdaptiveIconShapeDrawable extends ShapeDrawable { AdaptiveIconShapeDrawable()37 public AdaptiveIconShapeDrawable() { 38 super(); 39 } 40 AdaptiveIconShapeDrawable(Resources resources)41 public AdaptiveIconShapeDrawable(Resources resources) { 42 super(); 43 init(resources); 44 } 45 46 @Override inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme)47 public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme) 48 throws XmlPullParserException, IOException { 49 super.inflate(r, parser, attrs, theme); 50 init(r); 51 } 52 init(Resources resources)53 private void init(Resources resources) { 54 final float pathSize = AdaptiveIconDrawable.MASK_SIZE; 55 final Path path = new Path(PathParser.createPathFromPathData( 56 resources.getString(com.android.internal.R.string.config_icon_mask))); 57 setShape(new PathShape(path, pathSize, pathSize)); 58 } 59 } 60