diff options
| author | Eder Bastos <bastos.eder@gmail.com> | 2015-05-10 10:29:29 -0400 |
|---|---|---|
| committer | Eder Bastos <bastos.eder@gmail.com> | 2015-05-10 10:30:09 -0400 |
| commit | 3f1465196c7ea13a99517ddcdcd56f75d4359f99 (patch) | |
| tree | 4a55628d4fc51300361b96cbedb6b04baa0e3146 /Source/Android/app/src | |
| parent | 24c6be9d0f8dfddc84898cd02c2b98c34f444712 (diff) | |
Add touch feedback to GameGridActivity and AddDirectoryActivity.
Diffstat (limited to 'Source/Android/app/src')
7 files changed, 147 insertions, 114 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/FileAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/FileAdapter.java index 7f4acf6abe..2414883279 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/FileAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/FileAdapter.java @@ -4,6 +4,7 @@ import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Toast; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.model.FileListItem; @@ -102,8 +103,14 @@ public class FileAdapter extends RecyclerView.Adapter<FileViewHolder> implements return mFileList.size(); } + /** + * When a file is clicked, determine if it is a directory; if it is, show that new directory's + * contents. If it is not, end the activity successfully. + * + * @param view + */ @Override - public void onClick(View view) + public void onClick(final View view) { String path = (String) view.getTag(); @@ -111,8 +118,26 @@ public class FileAdapter extends RecyclerView.Adapter<FileViewHolder> implements if (clickedFile.isDirectory()) { - mFileList = generateFileList(clickedFile); - notifyDataSetChanged(); + final ArrayList<FileListItem> fileList = generateFileList(clickedFile); + + if (fileList.isEmpty()) + { + Toast.makeText(view.getContext(), R.string.add_directory_empty_folder, Toast.LENGTH_SHORT).show(); + } else + { + // Delay the loading of the new directory to give a little bit of time for UI feedback + // to happen. Hacky, but good enough for now; this is necessary because we're modifying + // the RecyclerView's contents, rather than constructing a new one. + view.getHandler().postDelayed(new Runnable() + { + @Override + public void run() + { + mFileList = fileList; + notifyDataSetChanged(); + } + }, 200); + } } else { // Pass the activity the path of the parent directory of the clicked file. @@ -120,6 +145,12 @@ public class FileAdapter extends RecyclerView.Adapter<FileViewHolder> implements } } + /** + * For a given directory, return a list of Files it contains. + * + * @param directory + * @return + */ private ArrayList<FileListItem> generateFileList(File directory) { File[] children = directory.listFiles(); @@ -145,6 +176,12 @@ public class FileAdapter extends RecyclerView.Adapter<FileViewHolder> implements return mPath; } + /** + * Mostly just allows the activity's menu option to kick us up a level in the directory + * structure. + * + * @param path + */ public void setPath(String path) { mPath = path; @@ -154,8 +191,11 @@ public class FileAdapter extends RecyclerView.Adapter<FileViewHolder> implements notifyDataSetChanged(); } - public static interface FileClickListener + /** + * Callback for when the user wants to add the visible directory to the library. + */ + public interface FileClickListener { - public void finishSuccessfully(); + void finishSuccessfully(); } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java index bf7bf435b7..883107a410 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java @@ -1,5 +1,7 @@ package org.dolphinemu.dolphinemu.adapters; +import android.app.Activity; +import android.content.Intent; import android.graphics.Rect; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; @@ -9,12 +11,16 @@ import android.view.ViewGroup; import com.squareup.picasso.Picasso; import org.dolphinemu.dolphinemu.R; +import org.dolphinemu.dolphinemu.dialogs.GameDetailsDialog; +import org.dolphinemu.dolphinemu.emulation.EmulationActivity; import org.dolphinemu.dolphinemu.model.Game; import org.dolphinemu.dolphinemu.viewholders.GameViewHolder; import java.util.ArrayList; -public class GameAdapter extends RecyclerView.Adapter<GameViewHolder> +public class GameAdapter extends RecyclerView.Adapter<GameViewHolder> implements + View.OnClickListener, + View.OnLongClickListener { private ArrayList<Game> mGameList; @@ -42,6 +48,9 @@ public class GameAdapter extends RecyclerView.Adapter<GameViewHolder> View gameCard = LayoutInflater.from(parent.getContext()) .inflate(R.layout.card_game, parent, false); + gameCard.setOnClickListener(this); + gameCard.setOnLongClickListener(this); + // Use that view to create a ViewHolder. GameViewHolder holder = new GameViewHolder(gameCard); return holder; @@ -74,7 +83,6 @@ public class GameAdapter extends RecyclerView.Adapter<GameViewHolder> { holder.textDescription.setText(game.getDescription()); } - holder.buttonDetails.setTag(game.getGameId()); holder.path = game.getPath(); holder.screenshotPath = game.getScreenPath(); @@ -92,6 +100,45 @@ public class GameAdapter extends RecyclerView.Adapter<GameViewHolder> return mGameList.size(); } + /** + * Launches the game that was clicked on. + * + * @param view The card representing the game the user wants to play. + */ + @Override + public void onClick(View view) + { + GameViewHolder holder = (GameViewHolder) view.getTag(); + + // Start the emulation activity and send the path of the clicked ISO to it. + Intent intent = new Intent(view.getContext(), EmulationActivity.class); + + intent.putExtra("SelectedGame", holder.path); + + view.getContext().startActivity(intent); + } + + /** + * Launches the details activity for this Game, using an ID stored in the + * details button's Tag. + * + * @param view The Card button that was long-clicked. + */ + @Override + public boolean onLongClick(View view) + { + GameViewHolder holder = (GameViewHolder) view.getTag(); + + // Get the ID of the game we want to look at. + // TODO This should be all we need to pass in, eventually. + // String gameId = (String) holder.gameId; + + Activity activity = (Activity) view.getContext(); + GameDetailsDialog.newInstance(holder.game).show(activity.getFragmentManager(), "game_details"); + + return true; + } + public static class SpacesItemDecoration extends RecyclerView.ItemDecoration { private int space; @@ -108,7 +155,6 @@ public class GameAdapter extends RecyclerView.Adapter<GameViewHolder> outRect.right = space; outRect.bottom = space; outRect.top = space; - } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/viewholders/GameViewHolder.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/viewholders/GameViewHolder.java index 47acf588de..18e271e0f5 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/viewholders/GameViewHolder.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/viewholders/GameViewHolder.java @@ -19,7 +19,6 @@ public class GameViewHolder extends RecyclerView.ViewHolder public ImageView imageScreenshot; public TextView textGameTitle; public TextView textDescription; - public ImageButton buttonDetails; // Used to handle onClick(). Set this in onBindViewHolder(). public String path; @@ -30,54 +29,10 @@ public class GameViewHolder extends RecyclerView.ViewHolder { super(itemView); - itemView.setOnClickListener(mCardClickListener); + itemView.setTag(this); imageScreenshot = (ImageView) itemView.findViewById(R.id.image_game_screen); textGameTitle = (TextView) itemView.findViewById(R.id.text_game_title); textDescription = (TextView) itemView.findViewById(R.id.text_game_description); - buttonDetails = (ImageButton) itemView.findViewById(R.id.button_details); - - buttonDetails.setOnClickListener(mDetailsButtonListener); } - - private View.OnClickListener mCardClickListener = new View.OnClickListener() - { - /** - * Launches the game that was clicked on. - * - * @param view The card representing the game the user wants to play. - */ - @Override - public void onClick(View view) - { - // Start the emulation activity and send the path of the clicked ROM to it. - Intent intent = new Intent(view.getContext(), EmulationActivity.class); - - intent.putExtra("SelectedGame", path); - - view.getContext().startActivity(intent); - } - }; - - private View.OnClickListener mDetailsButtonListener = new View.OnClickListener() - { - - /** - * Launches the details activity for this Game, using an ID stored in the - * details button's Tag. - * - * @param view The Details button that was clicked on. - */ - @Override - public void onClick(View view) - { - // Get the ID of the game we want to look at. - // TODO This should be all we need to pass in, eventually. - // String gameId = (String) view.getTag(); - - Activity activity = (Activity) view.getContext(); - GameDetailsDialog.newInstance(game).show(activity.getFragmentManager(), "game_details"); - } - }; - } diff --git a/Source/Android/app/src/main/res/layout/card_game.xml b/Source/Android/app/src/main/res/layout/card_game.xml index e0aa7f01f4..dc8321f8f8 100644 --- a/Source/Android/app/src/main/res/layout/card_game.xml +++ b/Source/Android/app/src/main/res/layout/card_game.xml @@ -2,9 +2,14 @@ <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" - android:layout_width="200dp" - android:layout_height="250dp" - android:transitionName="card_game"> + android:layout_width="0dp" + tools:layout_width="224dp" + android:layout_height="256dp" + android:transitionName="card_game" + android:focusable="true" + android:clickable="true" + android:foreground="?android:attr/selectableItemBackground" + > <LinearLayout android:layout_width="match_parent" @@ -17,53 +22,37 @@ android:layout_height="0dp" android:transitionName="image_game_screen" android:layout_weight="1" - tools:src="@drawable/placeholder_screenshot"/> + tools:src="@drawable/placeholder_screenshot" + tools:scaleType="centerCrop"/> + + <TextView + android:id="@+id/text_game_title" + style="@android:style/TextAppearance.Material.Subhead" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginLeft="16dp" + android:layout_marginRight="16dp" + android:layout_marginTop="16dp" + android:layout_toStartOf="@+id/button_details" + android:ellipsize="end" + android:lines="1" + android:maxLines="1" + tools:text="The Legend of Zelda: The Wind Waker"/> + + <TextView + android:id="@+id/text_game_description" + style="@android:style/TextAppearance.Material.Caption" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="16dp" + android:layout_marginTop="8dp" + android:layout_marginLeft="16dp" + android:layout_marginRight="16dp" + android:ellipsize="end" + android:lines="1" + android:maxLines="1" + tools:text="Zany rhythm action!"/> - <RelativeLayout - android:layout_width="match_parent" - android:layout_height="72dp"> - - - <TextView - android:id="@+id/text_game_title" - style="@android:style/TextAppearance.Material.Subhead" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentStart="true" - android:layout_below="@+id/image_game_screen" - android:layout_marginLeft="16dp" - android:layout_marginTop="16dp" - android:layout_toStartOf="@+id/button_details" - android:ellipsize="end" - android:lines="1" - android:maxLines="1" - tools:text="Rhythm Heaven Fever"/> - - <TextView - android:id="@+id/text_game_description" - style="@android:style/TextAppearance.Material.Caption" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignEnd="@+id/text_game_title" - android:layout_alignParentBottom="true" - android:layout_alignStart="@+id/text_game_title" - android:layout_marginBottom="16dp" - android:layout_toStartOf="@+id/button_details" - android:ellipsize="end" - android:lines="1" - android:maxLines="1" - android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sed odio vel quam auctor euismod. Pellentesque odio nibh, fermentum ut hendrerit id, ultrices et justo. " - tools:text="Zany rhythm action!"/> - - <ImageButton - android:id="@+id/button_details" - style="@android:style/Widget.Material.Light.Button.Borderless.Small" - android:layout_width="48dp" - android:layout_height="48dp" - android:layout_alignParentEnd="true" - android:layout_alignTop="@+id/text_game_title" - android:src="@drawable/ic_action_overflow"/> - </RelativeLayout> </LinearLayout> </android.support.v7.widget.CardView> diff --git a/Source/Android/app/src/main/res/layout/list_item_file.xml b/Source/Android/app/src/main/res/layout/list_item_file.xml index 3999d0368b..7d54e77d27 100644 --- a/Source/Android/app/src/main/res/layout/list_item_file.xml +++ b/Source/Android/app/src/main/res/layout/list_item_file.xml @@ -1,30 +1,31 @@ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" - android:orientation="horizontal" android:layout_width="match_parent" - android:layout_height="56dp"> + android:layout_height="56dp" + android:background="?android:attr/selectableItemBackground" + android:orientation="horizontal"> <ImageView android:id="@+id/image_type" - android:background="@drawable/oval_ripple_grey" - tools:src="@drawable/ic_wii" - android:layout_gravity="center_vertical" android:layout_width="32dp" android:layout_height="32dp" + android:layout_gravity="center_vertical" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" - android:padding="4dp"/> + android:background="@drawable/oval_ripple_grey" + android:padding="4dp" + tools:src="@drawable/ic_wii"/> <TextView + android:id="@+id/text_file_name" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_weight="1" + android:layout_gravity="center_vertical" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" - tools:text="File Name" + android:layout_weight="1" android:textSize="16sp" - android:layout_gravity="center_vertical" - android:id="@+id/text_file_name"/> + tools:text="File Name"/> </LinearLayout>
\ No newline at end of file diff --git a/Source/Android/app/src/main/res/menu/menu_add_directory.xml b/Source/Android/app/src/main/res/menu/menu_add_directory.xml index c459811868..667d28a4f0 100644 --- a/Source/Android/app/src/main/res/menu/menu_add_directory.xml +++ b/Source/Android/app/src/main/res/menu/menu_add_directory.xml @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> + <!-- TODO Please give me an icon! --> <item android:id="@+id/menu_up_one_level" android:title="@string/add_directory_up_one_level" diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index 37ce0b1365..99defca7bf 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -221,6 +221,7 @@ <string name="other">Other</string> - <string name="add_directory_title">Add Directory to Library</string> + <string name="add_directory_title">Add Folder to Library</string> <string name="add_directory_up_one_level">Up one level</string> + <string name="add_directory_empty_folder">That folder is empty.</string> </resources> |
