Android Open Source - VideoInfoViewer Box View






From Project

Back to project page VideoInfoViewer.

License

The source code is released under:

Copyright (c) 2014 Rory Hool Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. Unless required by applicab...

If you think the Android project VideoInfoViewer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
   Copyright (c) 2014 Rory Hool//from w  ww  . ja  v a  2s . co  m
   
   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.roryhool.videoinfoviewer.views;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.animation.RotateAnimation;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.coremedia.iso.boxes.Box;
import com.googlecode.mp4parser.AbstractContainerBox;
import com.roryhool.videoinfoviewer.R;
import com.roryhool.videoinfoviewer.analytics.Analytics;
import com.roryhool.videoinfoviewer.utils.AtomHelper;

public class BoxView extends FrameLayout {

   public interface BoxViewOnClickListener {
      public void onClickInfo( Box box );
   }

   public static BoxView CreateBoxViewAndChildren( Context context, BoxViewOnClickListener listener, Box box ) {
      BoxView boxView = new BoxView( context );
      boxView.loadBox( box );
      boxView.setBoxViewOnClickListener( listener );

      if ( box instanceof AbstractContainerBox ) {
         Log.d( "this", "box is instance of AbstractContainerBox" );

         AbstractContainerBox containerBox = (AbstractContainerBox) box;
         for ( Box childBox : containerBox.getBoxes() ) {
            Log.d( "this", "adding child " + childBox.getType() + " - " + childBox.getClass().getName() );
            BoxView childView = BoxView.CreateBoxViewAndChildren( context, listener, childBox );

            boxView.addChildBoxView( childView );
         }
      } else {
         boxView.hideExpandButton();
      }
      return boxView;
   }

   Box mBox;

   RelativeLayout mBoxLayout;

   TextView mTypeView;

   TextView mDescriptionView;

   ToggleButton mExpandButton;

   ImageView mBoxIcon;

   LinearLayout mChildBoxes;

   BoxViewOnClickListener mListener;

   ImageButton mInfoButton;

   public BoxView( Context context ) {
      super( context );

      addView( View.inflate( context, R.layout.box, null ) );

      mTypeView = (TextView) findViewById( R.id.box_type );
      mDescriptionView = (TextView) findViewById( R.id.box_description );
      mExpandButton = (ToggleButton) findViewById( R.id.box_expand_button );
      mBoxIcon = (ImageView) findViewById( R.id.box_icon );
      mChildBoxes = (LinearLayout) findViewById( R.id.child_boxes );
      mInfoButton = (ImageButton) findViewById( R.id.box_info_button );

      mExpandButton.setOnCheckedChangeListener( mExpandClickListener );
      mInfoButton.setOnClickListener( mInfoButtonClickListener );
   }

   public void loadBox( Box box ) {
      mBox = box;
      mTypeView.setText( mBox.getType() );

      String name = AtomHelper.GetNameForType( mBox.getType() );

      if ( name == null ) {
         Analytics.Instance( getContext() ).LogEvent( "Video Info", "Failed to get name for type ", mBox.getType() );
      }
      mDescriptionView.setText( name );
   }

   private void setBoxViewOnClickListener( BoxViewOnClickListener listener ) {
      mListener = listener;
   }

   private void addChildBoxView( BoxView childView ) {
      mChildBoxes.addView( childView );
   }

   private void hideExpandButton() {
      mExpandButton.setClickable( false );
      mBoxIcon.setVisibility( View.INVISIBLE );
   }
   
   private OnCheckedChangeListener mExpandClickListener = new OnCheckedChangeListener() {

      @Override
      public void onCheckedChanged( CompoundButton view, boolean checked ) {

         int from = checked ? -90 : 0;
         int to = checked ? 0 : -90;

         RotateAnimation animation = new RotateAnimation( from, to, mBoxIcon.getWidth() / 2, mBoxIcon.getHeight() / 2 );
         animation.setDuration( 600 );
         animation.setFillAfter( true );
         mBoxIcon.startAnimation( animation );

         int visibility = checked ? View.VISIBLE : View.GONE;
         for ( int i = 0; i < mChildBoxes.getChildCount(); i++ ) {
            View childView = mChildBoxes.getChildAt( i );
            childView.setVisibility( visibility );
         }
      }
   };

   OnClickListener mInfoButtonClickListener = new OnClickListener() {

      @Override
      public void onClick( View view ) {
         if ( mListener != null ) {
            mListener.onClickInfo( mBox );
         }
      }
   };

}




Java Source Code List

com.roryhool.videoinfoviewer.AtomActivity.java
com.roryhool.videoinfoviewer.BuildConfig.java
com.roryhool.videoinfoviewer.CreditsFragment.java
com.roryhool.videoinfoviewer.Extras.java
com.roryhool.videoinfoviewer.MainActivity.java
com.roryhool.videoinfoviewer.SearchActivity.java
com.roryhool.videoinfoviewer.SearchFragment.java
com.roryhool.videoinfoviewer.VideoActivity.java
com.roryhool.videoinfoviewer.VideoInfoViewerApp.java
com.roryhool.videoinfoviewer.analytics.Analytics.java
com.roryhool.videoinfoviewer.animation.ResizeAnimation.java
com.roryhool.videoinfoviewer.atomfragments.AtomInfoFragment.java
com.roryhool.videoinfoviewer.atomfragments.AtomStructureFragment.java
com.roryhool.videoinfoviewer.data.Video.java
com.roryhool.videoinfoviewer.search.SearchItem.java
com.roryhool.videoinfoviewer.utils.AtomHelper.java
com.roryhool.videoinfoviewer.utils.BoxUtils.java
com.roryhool.videoinfoviewer.utils.CursorHelper.java
com.roryhool.videoinfoviewer.utils.FontManager.java
com.roryhool.videoinfoviewer.utils.FormatUtils.java
com.roryhool.videoinfoviewer.utils.IsoFileCache.java
com.roryhool.videoinfoviewer.utils.Logg.java
com.roryhool.videoinfoviewer.utils.UriHelper.java
com.roryhool.videoinfoviewer.utils.VideoCache.java
com.roryhool.videoinfoviewer.utils.ViewUtils.java
com.roryhool.videoinfoviewer.views.BoxInfoView.java
com.roryhool.videoinfoviewer.views.BoxView.java
com.roryhool.videoinfoviewer.views.DisableableScrollView.java
com.roryhool.videoinfoviewer.views.RobotoTextView.java
com.roryhool.videoinfoviewer.views.ScaledTextureView.java
com.roryhool.videoinfoviewer.views.VideoPlayerView.java