Advertisement
rucinskic

MusicGridItem problem

Jul 7th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.54 KB | None | 0 0
  1. ////////////////////////
  2. /// values > attrs.xml
  3. ////////////////////////
  4.  
  5. <?xml version="1.0" encoding="utf-8"?>
  6. <resources>
  7.    
  8.     <declare-styleable name="MusicGridItem">
  9.        
  10.         <attr name="image_source" format="reference" />
  11.         <attr name="text" format="string" />
  12.         <attr name="text_color" format="color" />
  13.         <attr name="bar_color" format="color" />
  14.         <attr name="icon_source" format="reference" />
  15.         <attr name="checkbox_color" format="string" />
  16.         <attr name="checkbox_gravity" format="enum">
  17.            <enum name="left" value="0"/>
  18.            <enum name="right" value="1"/>
  19.         </attr>
  20.         <attr name="extend_image" format="boolean" />
  21.        
  22.         <attr name="android:checkable" />
  23.         <attr name="android:width" />
  24.         <attr name="android:height" />
  25.        
  26.     </declare-styleable>
  27.    
  28. </resources>
  29.  
  30.  
  31. ////////////////////////////////////
  32. /// src > ... > MusicGridItem.java
  33. ////////////////////////////////////
  34.  
  35. public class MusicGridItem extends View {
  36.  
  37.     int imageSource;
  38.     String text;
  39.     int textColor;
  40.     int barColor;
  41.     int iconSource;
  42.     int checkboxColor;
  43.     int checkboxGravity;
  44.     boolean isImageExtended;
  45.    
  46.     boolean isSelectable;
  47.     int width;
  48.     int height;
  49.    
  50.     public MusicGridItem(Context context, AttributeSet attrs) {
  51.        
  52.         super(context, attrs);
  53.        
  54.         TypedArray attr = context.getTheme().obtainStyledAttributes(attrs, android.R.styleable.MusicGridItem, 0, 0);
  55.        
  56.         try {
  57.            
  58.             imageSource = attr.getResourceId(  R.resources.musicgriditem_image_source, 0);
  59.            
  60.         } finally {
  61.            
  62.             attr.recycle();
  63.            
  64.         }
  65.     }
  66.  
  67. }
  68.  
  69.  
  70. ////////////////////////////////////////////
  71. /// concept layout.xml example intentions
  72. ////////////////////////////////////////////
  73.  
  74. Note: it mimics Google Play Musics "music grid item" on mobile
  75.  
  76. <FrameLayout
  77.         android:layout_width="200dp"
  78.         android:layout_height="100dp" >
  79.  
  80.         <ImageView android:id="@+id/image"
  81.            
  82.             android:layout_width="wrap_content"
  83.             android:layout_height="wrap_content"
  84.             android:background="@color/black"
  85.             android:src="@drawable/artistPhotoGeneric" >
  86.            
  87.         </ImageView>
  88.        
  89.         <CheckBox
  90.             android:id="@+id/select"
  91.             android:layout_width="wrap_content"
  92.             android:layout_height="wrap_content"
  93.            
  94.             android:layout_gravity="right"
  95.             android:layout_margin="10dp"
  96.             android:background="@color/white">
  97.            
  98.         </CheckBox>
  99.        
  100.         <LinearLayout
  101.             android:layout_width="match_parent"
  102.             android:layout_height="wrap_content"
  103.             android:layout_gravity="bottom"
  104.                        
  105.             android:orientation="horizontal"
  106.            
  107.             android:background="@color/black">
  108.  
  109.             <TextView
  110.                 android:id="@+id/description"
  111.                 android:layout_width="wrap_content"
  112.                 android:layout_height="wrap_content"
  113.                 android:layout_weight="1"
  114.                 android:text="Artist_Name"
  115.                 android:textAppearance="?android:attr/textAppearanceMedium" >
  116.                
  117.             </TextView>
  118.  
  119.             <ImageView
  120.                 android:id="@+id/more"
  121.                 android:layout_width="24dp"
  122.                 android:layout_height="24dp"
  123.                 android:src="@drawable/ic_launcher" >
  124.                
  125.             </ImageView>
  126.            
  127.         </LinearLayout>
  128.    
  129.   </FrameLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement