summaryrefslogtreecommitdiff
path: root/Source/Android/app/src/main/java
diff options
context:
space:
mode:
authorEder Bastos <bastos.eder@gmail.com>2015-05-10 10:29:29 -0400
committerEder Bastos <bastos.eder@gmail.com>2015-05-10 10:30:09 -0400
commit3f1465196c7ea13a99517ddcdcd56f75d4359f99 (patch)
tree4a55628d4fc51300361b96cbedb6b04baa0e3146 /Source/Android/app/src/main/java
parent24c6be9d0f8dfddc84898cd02c2b98c34f444712 (diff)
Add touch feedback to GameGridActivity and AddDirectoryActivity.
Diffstat (limited to 'Source/Android/app/src/main/java')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/FileAdapter.java50
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java52
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/viewholders/GameViewHolder.java47
3 files changed, 95 insertions, 54 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");
- }
- };
-
}