Home | History | Annotate | Download | only in dynamic
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
      5  * in compliance with the License. You may obtain a copy of the License at
      6  *
      7  * http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software distributed under the License
     10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
     11  * or implied. See the License for the specific language governing permissions and limitations under
     12  * the License.
     13  */
     14 package com.android.test.dynamic;
     15 
     16 import android.app.Activity;
     17 import android.graphics.drawable.VectorDrawable;
     18 import android.os.Bundle;
     19 import android.util.Log;
     20 import android.view.View;
     21 import android.view.View.OnClickListener;
     22 import android.view.ViewGroup;
     23 import android.widget.Button;
     24 import android.widget.CheckBox;
     25 import android.widget.CompoundButton;
     26 import android.widget.CompoundButton.OnCheckedChangeListener;
     27 import android.widget.GridLayout;
     28 
     29 @SuppressWarnings({"UnusedDeclaration"})
     30 public class VectorDrawable01 extends Activity {
     31     private static final String LOGCAT = "VectorDrawable1";
     32     int[] icon = {
     33             R.drawable.vector_drawable01,
     34             R.drawable.vector_drawable02,
     35             R.drawable.vector_drawable03,
     36             R.drawable.vector_drawable04,
     37             R.drawable.vector_drawable05,
     38             R.drawable.vector_drawable06,
     39             R.drawable.vector_drawable07,
     40             R.drawable.vector_drawable08,
     41             R.drawable.vector_drawable09,
     42             R.drawable.vector_drawable10,
     43             R.drawable.vector_drawable11,
     44             R.drawable.vector_drawable12,
     45             R.drawable.vector_drawable13,
     46             R.drawable.vector_drawable14,
     47             R.drawable.vector_drawable15,
     48             R.drawable.vector_drawable16,
     49             R.drawable.vector_drawable17,
     50             R.drawable.vector_drawable18,
     51             R.drawable.vector_drawable19,
     52             R.drawable.vector_drawable20
     53     };
     54 
     55     @Override
     56     protected void onCreate(Bundle savedInstanceState) {
     57         super.onCreate(savedInstanceState);
     58         GridLayout container = new GridLayout(this);
     59         container.setColumnCount(5);
     60         container.setBackgroundColor(0xFF888888);
     61         final Button []bArray = new Button[icon.length];
     62 
     63         CheckBox toggle = new CheckBox(this);
     64         toggle.setText("Toggle");
     65         toggle.setChecked(true);
     66         toggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {
     67             @Override
     68             public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
     69                 ViewGroup vg = (ViewGroup) buttonView.getParent();
     70                 for (int i = 0, count = vg.getChildCount(); i < count; i++) {
     71                     View child = vg.getChildAt(i);
     72                     if (child != buttonView) {
     73                         child.setEnabled(isChecked);
     74                     }
     75                 }
     76             }
     77         });
     78         container.addView(toggle);
     79 
     80         for (int i = 0; i < icon.length; i++) {
     81             Button button = new Button(this);
     82             bArray[i] = button;
     83             button.setWidth(200);
     84             button.setBackgroundResource(icon[i]);
     85             container.addView(button);
     86             VectorDrawable vd = (VectorDrawable) button.getBackground();
     87             vd.setAlpha((i + 1) * (0xFF / (icon.length + 1)));
     88         }
     89 
     90         setContentView(container);
     91 
     92     }
     93 
     94 }
     95