Skip to content

Commit

Permalink
Merge pull request dolphin-emu#2389 from sigmabeta/lollipop-ui-tweaks
Browse files Browse the repository at this point in the history
Android: Add file browser screen to new UI, and several tweaks.
  • Loading branch information
Sonicadvance1 committed May 11, 2015
2 parents e4f23ef + f3aec52 commit 5bbaa85
Show file tree
Hide file tree
Showing 46 changed files with 836 additions and 232 deletions.
8 changes: 4 additions & 4 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
If you make any contributions to Dolphin after December 1st, 2014, you are agreeing that any code you have contributed will be licensed under the GNU GPL version 2 (or any later version).

## Coding Style
---

- [Introduction] (#introduction)
- [Styling and formatting] (#styling-and-formatting)
Expand All @@ -20,14 +19,12 @@ If you make any contributions to Dolphin after December 1st, 2014, you are agree


## Introduction
---

This guide is for developers who wish to contribute to the Dolphin codebase. It will detail how to properly style and format code to fit this project. This guide also offers suggestions on specific functions and other varia that may be used in code.

Following this guide and formatting your code as detailed will likely get your pull request merged much faster than if you don't (assuming the written code has no mistakes in itself).

## Styling and formatting
---

### General
- Try to limit lines of code to a maximum of 100 characters.
Expand Down Expand Up @@ -130,7 +127,6 @@ private:
```

## Code Specific
---

### General
- Using C++11 features is OK and recommended.
Expand Down Expand Up @@ -229,3 +225,7 @@ private:
// Class definitions
};
```

## Java

The Android project is currently written in Java. If you are using Android Studio to contribute, you can import the project's code style from `code-style-java.jar`, located in `[Dolphin Root]/Source/Android`. Please organize imports before committing.
2 changes: 1 addition & 1 deletion Source/Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ dependencies {
compile 'de.hdodenhof:circleimageview:1.2.2'

// For loading huge screenshots from the disk.
compile "com.squareup.picasso:picasso:2.4.0"
compile 'com.squareup.picasso:picasso:2.5.2'
}
7 changes: 6 additions & 1 deletion Source/Android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<activity
android:name=".activities.GameGridActivity"
android:label="Dolphin New UI"
android:theme="@style/DolphinWii">
android:theme="@style/DolphinGamecube">

<!-- This intentfilter marks this Activity as the one that gets launched from Home screen. -->
<intent-filter>
Expand All @@ -25,6 +25,11 @@
</intent-filter>
</activity>

<activity
android:name=".activities.AddDirectoryActivity"
android:theme="@style/DolphinWii"
android:label="@string/add_directory_title"/>

<activity
android:name="org.dolphinemu.dolphinemu.gamelist.GameListActivity"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package org.dolphinemu.dolphinemu.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toolbar;

import org.dolphinemu.dolphinemu.BuildConfig;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.adapters.FileAdapter;

/**
* An Activity that shows a list of files and folders, allowing the user to tell the app which folder(s)
* contains the user's games.
*/
public class AddDirectoryActivity extends Activity implements FileAdapter.FileClickListener
{
public static final String KEY_CURRENT_PATH = BuildConfig.APPLICATION_ID + ".path";

private FileAdapter mAdapter;
private Toolbar mToolbar;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_add_directory);

mToolbar = (Toolbar) findViewById(R.id.toolbar_folder_list);
setActionBar(mToolbar);

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list_files);

// Specifying the LayoutManager determines how the RecyclerView arranges views.
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(layoutManager);

String path;
// Stuff in this block only happens when this activity is newly created (i.e. not a rotation)
if (savedInstanceState == null)
{
path = Environment.getExternalStorageDirectory().getPath();
}
else
{
// Get the path we were looking at before we rotated.
path = savedInstanceState.getString(KEY_CURRENT_PATH);
}

mAdapter = new FileAdapter(path, this);
recyclerView.setAdapter(mAdapter);
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_add_directory, menu);

return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.menu_up_one_level:
mAdapter.upOneLevel();
break;
}

return super.onOptionsItemSelected(item);
}


@Override
protected void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);

// Save the path we're looking at so when rotation is done, we start from same folder.
outState.putString(KEY_CURRENT_PATH, mAdapter.getPath());
}

/**
* Tell the GameGridActivity that launched this Activity that the user picked a folder.
*/
@Override
public void finishSuccessfully()
{
Intent resultData = new Intent();

resultData.putExtra(KEY_CURRENT_PATH, mAdapter.getPath());
setResult(RESULT_OK, resultData);

finish();
}

@Override
public void updateSubtitle(String path)
{
mToolbar.setSubtitle(path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toolbar;

import org.dolphinemu.dolphinemu.AssetCopyService;
Expand All @@ -24,11 +27,15 @@
import java.util.HashSet;
import java.util.Set;

public class GameGridActivity extends Activity
/**
* The main Activity of the Lollipop style UI. Shows a grid of games on tablets & landscape phones,
* shows a list of games on portrait phones.
*/
public final class GameGridActivity extends Activity
{
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
private static final int REQUEST_ADD_DIRECTORY = 1;

private GameAdapter mAdapter;

@Override
protected void onCreate(Bundle savedInstanceState)
Expand All @@ -39,21 +46,34 @@ protected void onCreate(Bundle savedInstanceState)
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_game_list);
setActionBar(toolbar);

mRecyclerView = (RecyclerView) findViewById(R.id.grid_games);
ImageButton buttonAddDirectory = (ImageButton) findViewById(R.id.button_add_directory);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.grid_games);

// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
//mRecyclerView.setHasFixedSize(true);

// Specifying the LayoutManager determines how the RecyclerView arranges views.
mLayoutManager = new GridLayoutManager(this, 4);
mRecyclerView.setLayoutManager(mLayoutManager);
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this, 4);
recyclerView.setLayoutManager(layoutManager);

mRecyclerView.addItemDecoration(new GameAdapter.SpacesItemDecoration(8));
recyclerView.addItemDecoration(new GameAdapter.SpacesItemDecoration(8));

// Create an adapter that will relate the dataset to the views on-screen.
mAdapter = new GameAdapter(getGameList());
mRecyclerView.setAdapter(mAdapter);
recyclerView.setAdapter(mAdapter);

buttonAddDirectory.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
Intent fileChooser = new Intent(GameGridActivity.this, AddDirectoryActivity.class);

// The second argument to this method is read below in onActivityResult().
startActivityForResult(fileChooser, REQUEST_ADD_DIRECTORY);
}
});

// Stuff in this block only happens when this activity is newly created (i.e. not a rotation)
if (savedInstanceState == null)
Expand All @@ -64,11 +84,46 @@ protected void onCreate(Bundle savedInstanceState)
}
}

/**
* Callback from AddDirectoryActivity. Applies any changes necessary to the GameGridActivity.
*
* @param requestCode An int describing whether the Activity that is returning did so successfully.
* @param resultCode An int describing what Activity is giving us this callback.
* @param result The information the returning Activity is providing us.
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent result)
{
// If the user picked a file, as opposed to just backing out.
if (resultCode == RESULT_OK)
{
// Sanity check to make sure the Activity that just returned was the AddDirectoryActivity;
// other activities might use this callback in the future (don't forget to change Javadoc!)
if (requestCode == REQUEST_ADD_DIRECTORY)
{
// Get the path the user selected in AddDirectoryActivity.
String path = result.getStringExtra(AddDirectoryActivity.KEY_CURRENT_PATH);

// Store this path as a preference.
// TODO Use SQLite instead.
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = prefs.edit();

editor.putString(AddDirectoryActivity.KEY_CURRENT_PATH, path);

// Using commit, not apply, in order to block so the next method has the correct data to load.
editor.commit();

mAdapter.setGameList(getGameList());
}
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.gamelist_menu, menu);
inflater.inflate(R.menu.menu_game_grid, menu);
return true;

}
Expand All @@ -82,48 +137,43 @@ private ArrayList<Game> getGameList()

NativeLibrary.SetUserDirectory(DefaultDir);

String Directories = NativeLibrary.GetConfig("Dolphin.ini", "General", "ISOPaths", "0");
Log.v("DolphinEmu", "Directories: " + Directories);
int intDirectories = Integer.parseInt(Directories);

// Extensions to filter by.
Set<String> exts = new HashSet<String>(Arrays.asList(".dff", ".dol", ".elf", ".gcm", ".gcz", ".iso", ".wad", ".wbfs"));

for (int a = 0; a < intDirectories; ++a)
{
String BrowseDir = NativeLibrary.GetConfig("Dolphin.ini", "General", "ISOPath" + a, "");
Log.v("DolphinEmu", "Directory " + a + ": " + BrowseDir);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

String path = prefs.getString(AddDirectoryActivity.KEY_CURRENT_PATH, "/");

File currentDir = new File(BrowseDir);
File[] dirs = currentDir.listFiles();
try
File currentDir = new File(path);
File[] dirs = currentDir.listFiles();
try
{
for (File entry : dirs)
{
for (File entry : dirs)
if (!entry.isHidden() && !entry.isDirectory())
{
if (!entry.isHidden() && !entry.isDirectory())
{
String entryName = entry.getName();

// Check that the file has an appropriate extension before trying to read out of it.
if (exts.contains(entryName.toLowerCase().substring(entryName.lastIndexOf('.'))))
{
GcGame game = new GcGame(NativeLibrary.GetTitle(entry.getAbsolutePath()),
NativeLibrary.GetDescription(entry.getAbsolutePath()).replace("\n", " "),
// TODO Some games might actually not be from this region, believe it or not.
"United States",
entry.getAbsolutePath(),
NativeLibrary.GetGameId(entry.getAbsolutePath()),
NativeLibrary.GetDate(entry.getAbsolutePath()));

gameList.add(game);
}
String entryName = entry.getName();

// Check that the file has an appropriate extension before trying to read out of it.
if (exts.contains(entryName.toLowerCase().substring(entryName.lastIndexOf('.'))))
{
GcGame game = new GcGame(NativeLibrary.GetTitle(entry.getAbsolutePath()),
NativeLibrary.GetDescription(entry.getAbsolutePath()).replace("\n", " "),
// TODO Some games might actually not be from this region, believe it or not.
"United States",
entry.getAbsolutePath(),
NativeLibrary.GetGameId(entry.getAbsolutePath()),
NativeLibrary.GetDate(entry.getAbsolutePath()));

gameList.add(game);
}

}
} catch (Exception ignored)
{

}
} catch (Exception ignored)
{

}

return gameList;
Expand Down
Loading

0 comments on commit 5bbaa85

Please sign in to comment.