Home | History | Annotate | Download | only in musicfx
      1 /*
      2  * Copyright (C) 2015 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.musicfx;
     18 
     19 import android.content.Context;
     20 import android.util.AttributeSet;
     21 import android.util.Log;
     22 import android.view.View;
     23 import android.view.ViewGroup;
     24 
     25 
     26 /*
     27  *  This ViewGroup contains a single view, which will be rotated by 90 degrees counterclockwise.
     28  */
     29 
     30 public class SeekBarRotator extends ViewGroup {
     31 
     32 
     33     public SeekBarRotator(Context context) {
     34         super(context);
     35     }
     36 
     37     public SeekBarRotator(Context context, AttributeSet attrs) {
     38         super(context, attrs);
     39     }
     40 
     41     public SeekBarRotator(Context context, AttributeSet attrs, int defStyleAttr) {
     42         super(context, attrs, defStyleAttr);
     43     }
     44 
     45     public SeekBarRotator(Context context, AttributeSet attrs, int defStyleAttr,
     46             int defStyleRes) {
     47         super(context, attrs, defStyleAttr, defStyleRes);
     48     }
     49 
     50     @Override
     51     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
     52         final View child = getChildAt(0);
     53 
     54         if (child.getVisibility() != GONE) {
     55             // swap width and height for child
     56             measureChild(child, heightMeasureSpec, widthMeasureSpec);
     57             setMeasuredDimension(
     58                     child.getMeasuredHeightAndState(),
     59                     child.getMeasuredWidthAndState());
     60         } else {
     61             setMeasuredDimension(
     62                     resolveSizeAndState(0, widthMeasureSpec, 0),
     63                     resolveSizeAndState(0, heightMeasureSpec, 0));
     64         }
     65     }
     66 
     67     @Override
     68     protected void onLayout(boolean changed, int l, int t, int r, int b) {
     69         final View child = getChildAt(0);
     70 
     71         if (child.getVisibility() != GONE) {
     72             // rotate the child 90 degrees counterclockwise around its upper-left
     73             child.setPivotX(0);
     74             child.setPivotY(0);
     75             child.setRotation(-90);
     76 
     77             // place the child below this view, so it rotates into view
     78             int mywidth = r - l;
     79             int myheight = b - t;
     80             int childwidth = myheight;
     81             int childheight = mywidth;
     82 
     83             child.layout(0, myheight, childwidth, myheight + childheight);
     84         }
     85     }
     86 
     87 }
     88