/*
 * Copyright 2015 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.blockly.android.ui.vertical;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;

import com.google.blockly.android.ui.WorkspaceHelper;
import com.google.blockly.android.ui.fieldview.BasicFieldColorView;

/**
 * {@link BasicFieldColorView} with a inset emboss that matches its containing BlockView.
 */
public class FieldColorView extends BasicFieldColorView {
    protected WorkspaceHelper mHelper;

    public FieldColorView(Context context) {
        super(context);
    }

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

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

    public void setWorkspaceHelper(WorkspaceHelper helper) {
        mHelper = helper;
        maybeAcquireParentBlockView();
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        maybeAcquireParentBlockView();
    }

    private void maybeAcquireParentBlockView() {
        BlockView blockView = (mHelper != null && ViewCompat.isAttachedToWindow(this)) ?
            (BlockView) mHelper.getClosestAncestorBlockView(this) : null;
        if (blockView != null) {
            int foregroundId = blockView.getBlock().isShadow() ?
                    R.drawable.inset_field_border_shadow : R.drawable.inset_field_border;
            Drawable foreground = getResources().getDrawable(foregroundId);
            foreground.setColorFilter(blockView.getColorFilter());
            setForeground(foreground);
        }
    }
}

@@ -1084,16 +1084,118 @@
 rView %7B%0A
+    protected static final int MIN_WIDTH_DP = 40;%0A    protected static final int MIN_HEIGHT_DP = 41;%0A%0A
     prot
@@ -1225,16 +1225,16 @@
 Helper;%0A
-
 %0A    pub
@@ -1295,16 +1295,47 @@
 ntext);%0A
+        initPostConstructor();%0A
     %7D%0A%0A 
@@ -1429,16 +1429,47 @@
 attrs);%0A
+        initPostConstructor();%0A
     %7D%0A%0A 
@@ -1595,16 +1595,47 @@
 eAttr);%0A
+        initPostConstructor();%0A
     %7D%0A%0A 
@@ -2010,24 +2010,24 @@
 ToWindow();%0A
-
         mayb
@@ -2056,24 +2056,269 @@
 w();%0A    %7D%0A%0A
+    private void initPostConstructor() %7B%0A        float density = getContext().getResources().getDisplayMetrics().density;%0A        setMinimumWidth((int) (MIN_WIDTH_DP * density));%0A        setMinimumHeight((int) (MIN_HEIGHT_DP * density));%0A    %7D%0A%0A
     private 

set min height of colour fields in vertical implementation