Commits

skarumuru  committed 985786c

Added grid layout

  • Participants
  • Parent commits fa145fa

Comments (0)

Files changed (8)

File res/drawable/grid_icon.png

Added
New image

File res/drawable/list_icon.png

Added
New image

File res/layout/fragment_music_list.xml

             android:layout_height="wrap_content"
             android:layout_weight="1"
             android:text="@string/quit" />
+
+        <ImageView
+            android:id="@+id/listview_icon"
+            android:layout_width="30dp"
+            android:layout_height="30dp"
+            android:layout_gravity="center_vertical|center_horizontal"
+            android:contentDescription="@string/app_name"
+            android:padding="2dp"
+            android:src="@drawable/list_icon" />
+
+        <ImageView
+            android:id="@+id/gridview_icon"
+            android:layout_width="30dp"
+            android:layout_height="30dp"
+            android:layout_gravity="center_vertical|center_horizontal"
+            android:contentDescription="@string/app_name"
+            android:padding="2dp"
+            android:src="@drawable/grid_icon" />
     </LinearLayout>
 
-    <ListView
-        android:id="@+id/songs_list_view"
+    <ViewFlipper
+        android:id="@+id/view_flipper"
         android:layout_width="match_parent"
-        android:layout_height="match_parent" />
+        android:layout_height="match_parent" >
+
+        <ListView
+            android:id="@+id/songs_list_view"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent" />
+        
+        <GridView
+            android:id="@+id/songs_grid_view"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent" />
+    </ViewFlipper>
 
 </LinearLayout>

File res/layout/grid_view_each_album.xml

         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_gravity="center_vertical"
-        android:gravity="center_vertical"
+        android:gravity="center_vertical|center_horizontal"
         android:singleLine="true"
         android:textStyle="bold" />
 

File src/com/w4rlock/backpapermusic/MusicPlayListActivity.java

 package com.w4rlock.backpapermusic;
 
-import android.content.Intent;
 import android.os.Bundle;
 import android.support.v7.app.ActionBarActivity;
 import android.view.Menu;
 		int id = item.getItemId();
 		if (id == android.R.id.home)
 		{
-			Intent i = new Intent(this, MusicActivity.class);
-			i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
-			startActivity(i);
+//			Intent i = new Intent(this, MusicActivity.class);
+//			i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+//			startActivity(i);
+			finish();
 			return true;
 		}
 		if (id == R.id.action_settings)

File src/com/w4rlock/backpapermusic/MusicPlayerActivity.java

 package com.w4rlock.backpapermusic;
 
-import android.content.Intent;
 import android.os.Bundle;
 import android.support.v7.app.ActionBarActivity;
 import android.view.Menu;
 	{
 		int id = item.getItemId();
 		if(id == android.R.id.home){
-			Intent i = new Intent(this,MusicActivity.class);
-			i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
-			startActivity(i);
+//			Intent i = new Intent(this,MusicActivity.class);
+//			i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+//			startActivity(i);
+			finish();
 			return true;
 		}
 		if (id == R.id.action_settings)

File src/com/w4rlock/backpapermusic/fragments/MusicListFragment.java

 import android.net.Uri;
 import android.os.Bundle;
 import android.support.v4.app.Fragment;
-import android.support.v4.app.LoaderManager;
-import android.support.v4.content.Loader;
 import android.support.v4.view.MenuItemCompat;
 import android.support.v7.widget.SearchView;
 import android.view.LayoutInflater;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
 import android.widget.Button;
+import android.widget.GridView;
+import android.widget.ImageView;
 import android.widget.ListView;
-import android.widget.Toast;
+import android.widget.ViewFlipper;
 
 import com.w4rlock.backpapermusic.MusicPlayListActivity;
 import com.w4rlock.backpapermusic.MusicPlayerActivity;
 import com.w4rlock.backpapermusic.R;
+import com.w4rlock.backpapermusic.adapters.MusicGridViewAdapter;
 import com.w4rlock.backpapermusic.adapters.MusicListViewAdapter;
 import com.w4rlock.backpapermusic.loaders.LoadSongsList;
 import com.w4rlock.backpapermusic.loaders.LoadingInterface;
 import com.w4rlock.backpapermusic.loaders.MusicDataAsyncTaskLoad;
-import com.w4rlock.backpapermusic.loaders.MusicDataLoader;
-import com.w4rlock.backpapermusic.loaders.MusicDataAsyncTaskLoad.MusicDataAsyncTaskCallback;
 import com.w4rlock.backpapermusic.models.AsyncResult;
 import com.w4rlock.backpapermusic.models.Song;
 import com.w4rlock.backpapermusic.models.SongItem;
 	private static final String DEBUG_TAG = "MusicListFragment";
 	public static final ArrayList<Song> musics = new ArrayList<Song>();
 	private MusicListViewAdapter mMusicAdapter;
+	private MusicGridViewAdapter mMusicGridAdapter;
 	private ListView songsList;
-
-	private static final int LOADER_ID = 0;
+	private ViewFlipper mViewFlipper;
+	private GridView songsGridView;
 
 	public MusicListFragment()
 	{
 		setHasOptionsMenu(true);
 
 		songsList = (ListView) rootView.findViewById(R.id.songs_list_view);
-		mMusicAdapter = new MusicListViewAdapter(getActivity(), musics);
-		songsList.setAdapter(mMusicAdapter);
+		songsGridView = (GridView) rootView.findViewById(R.id.songs_grid_view);
+		mViewFlipper = (ViewFlipper) rootView.findViewById(R.id.view_flipper);
 		songsList.setOnItemClickListener(new AdapterView.OnItemClickListener()
 		{
 
 			@Override
 			public void onItemClick(AdapterView<?> parent, View view, int position, long id)
 			{
-
+				Song music = (Song) parent.getItemAtPosition(position);
+				showDialogWithSongs(music);
 			}
-
 		});
-		songsList.setOnItemClickListener(new AdapterView.OnItemClickListener()
+		songsGridView.setOnItemClickListener(new AdapterView.OnItemClickListener()
 		{
 
 			@Override
 				getActivity().startActivity(playerIntent);
 			}
 		});
+
+		((ImageView) rootView.findViewById(R.id.listview_icon)).setOnClickListener(new View.OnClickListener()
+		{
+
+			@Override
+			public void onClick(View v)
+			{
+				viewFlipperShowThisChild(0);
+			}
+		});
+
+		((ImageView) rootView.findViewById(R.id.gridview_icon)).setOnClickListener(new View.OnClickListener()
+		{
+
+			@Override
+			public void onClick(View v)
+			{
+				viewFlipperShowThisChild(1);
+			}
+		});
+		viewFlipperShowThisChild(1);
 		loadData();
 		return rootView;
 	}
 
+	private void viewFlipperShowThisChild(int whichChild)
+	{
+		switch (whichChild)
+		{
+		case 0:
+			// show list view
+			songsGridView.setAdapter(null);
+			mMusicGridAdapter = null;
+			mMusicAdapter = new MusicListViewAdapter(getActivity(), musics);
+			songsList.setAdapter(mMusicAdapter);
+			break;
+		case 1:
+			// show grid view
+			songsList.setAdapter(null);
+			mMusicAdapter = null;
+			mMusicGridAdapter = new MusicGridViewAdapter(getActivity(), musics);
+			songsGridView.setNumColumns(3);
+			songsGridView.setAdapter(mMusicGridAdapter);
+			break;
+		default:
+			break;
+		}
+		mViewFlipper.setDisplayedChild(whichChild);
+	}
+
 	private final MusicDataAsyncTaskLoad.MusicDataAsyncTaskCallback musicLoadedCallback = new MusicDataAsyncTaskLoad.MusicDataAsyncTaskCallback()
 	{
 
 			{
 				musics.add(m);
 			}
-			mMusicAdapter.notifyDataSetChanged();
+			if(mMusicAdapter != null)
+				mMusicAdapter.notifyDataSetChanged();
+			if(mMusicGridAdapter != null)
+				mMusicGridAdapter.notifyDataSetChanged();
 		}
 	};
 
 			}
 			mMusicAdapter = new MusicListViewAdapter(getActivity(), tempMusic);
 		}
-		songsList.setAdapter(mMusicAdapter);
+		if(songsList != null)
+			songsList.setAdapter(mMusicAdapter);
 	}
 
 	@Override

File src/com/w4rlock/backpapermusic/fragments/MusicPlayListFragment.java

 				Uri uri = Uri.parse("http://nothing.com/");
 				i.setData(uri);
 				getActivity().startService(i);
+				playListDisplayAdapter.notifyDataSetChanged();
 			}
 		});
 		return rootView;