All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.tidalwave.bluebill.mobile.android.taxonomy.CheckableLinearLayout Maven / Gradle / Ivy

/***********************************************************************************************************************
 *
 * blueBill Mobile - open source birdwatching
 * ==========================================
 *
 * Copyright (C) 2009, 2010 by Tidalwave s.a.s. (http://www.tidalwave.it)
 * http://bluebill.tidalwave.it/mobile/
 *
 ***********************************************************************************************************************
 *
 * 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.
 *
 ***********************************************************************************************************************
 *
 * $Id: CheckableLinearLayout.java,v 8ca4217fa57c 2010/08/25 22:08:37 fabrizio $
 *
 **********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.taxonomy;

import javax.annotation.Nonnull;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Checkable;
import android.widget.LinearLayout;

/***********************************************************************************************************************
 *
 * Adapted from http://tokudu.com/2010/android-checkable-linear-layout/
 * 
 * @author  Fabrizio Giudici
 * @version $Id: $
 *
 **********************************************************************************************************************/
public class CheckableLinearLayout extends LinearLayout implements Checkable
  {
    private Checkable checkable;

    public CheckableLinearLayout (final @Nonnull Context context, final @Nonnull AttributeSet attrs)
      {
        super(context, attrs);
      }

    @Override
    protected void onFinishInflate()
      {
        super.onFinishInflate();
        final int childCount = getChildCount();

        for (int i = 0; i < childCount; i++)
          {
            final View view = getChildAt(i);

            if (view instanceof Checkable)
              {
                checkable = (Checkable)view;
                break;
              }
          }
      }

    @Override
    public boolean isChecked()
      {
        return (checkable != null) ? checkable.isChecked() : false;
      }

    @Override
    public void setChecked (final boolean checked)
      {
        if (checkable != null)
          {
            checkable.setChecked(checked);
          }
      }

    @Override
    public void toggle()
      {
        if (checkable != null)
          {
            checkable.toggle();
          }
      }
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy