Skip to content

Commit

Permalink
Android: FAB now changes color to match the visible platform.
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmabeta committed Jun 22, 2015
1 parent d6d0d54 commit fe5b477
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 5 deletions.
Expand Up @@ -5,6 +5,7 @@
import android.content.Intent;
import android.content.Loader;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.database.Cursor;
import android.os.Bundle;
import android.preference.PreferenceManager;
Expand All @@ -19,6 +20,9 @@
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.OvershootInterpolator;

import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
Expand Down Expand Up @@ -48,6 +52,10 @@ public final class MainActivity extends AppCompatActivity implements LoaderManag

private ViewPager mViewPager;
private PlatformPagerAdapter mPlatformPagerAdapter;
private FloatingActionButton mButtonAddDirectory;

private static Interpolator mHideInterpolator = new AccelerateInterpolator();
private static Interpolator mShowInterpolator = new OvershootInterpolator();

@Override
protected void onCreate(Bundle savedInstanceState)
Expand All @@ -74,8 +82,8 @@ protected void onCreate(Bundle savedInstanceState)
tabLayout.setupWithViewPager(mViewPager);

// Set up the FAB.
FloatingActionButton buttonAddDirectory = (FloatingActionButton) findViewById(R.id.button_add_directory);
buttonAddDirectory.setOnClickListener(new View.OnClickListener()
mButtonAddDirectory = (FloatingActionButton) findViewById(R.id.button_add_directory);
mButtonAddDirectory.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
Expand All @@ -87,6 +95,41 @@ public void onClick(View view)
}
});

mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener()
{
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
{
}

@Override
public void onPageScrollStateChanged(int state)
{
}

@Override
public void onPageSelected(int position)
{
Log.i("DolphinEmu", "[MainActivity] Page selected: " + position);

switch (position)
{
case Game.PLATFORM_GC:
changeFabColor(R.color.fab_gamecube);
break;

case Game.PLATFORM_WII:
changeFabColor(R.color.fab_wii);
break;

case Game.PLATFORM_WII_WARE:
changeFabColor(R.color.fab_wiiware);
break;
}
}

});

// Stuff in this block only happens when this activity is newly created (i.e. not a rotation)
if (savedInstanceState == null)
{
Expand All @@ -105,6 +148,34 @@ public void onClick(View view)
}
}

private void changeFabColor(int colorResourceId)
{
final ColorStateList tint = getResources().getColorStateList(colorResourceId);

// Hide the button.
mButtonAddDirectory.animate()
.withLayer()
.setDuration(100)
.setInterpolator(mHideInterpolator)
.scaleX(0.0f)
.scaleY(0.0f)
.withEndAction(new Runnable()
{
@Override
public void run()
{
// Change the button's color, then show it again.
mButtonAddDirectory.setBackgroundTintList(tint);
mButtonAddDirectory.animate()
.withLayer()
.setDuration(150)
.setInterpolator(mShowInterpolator)
.scaleX(1.0f)
.scaleY(1.0f);
}
});
}

/**
* Callback from AddDirectoryActivity. Applies any changes necessary to the GameGridActivity.
*
Expand Down
Expand Up @@ -7,6 +7,7 @@
import android.database.Cursor;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
Expand Down Expand Up @@ -53,12 +54,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.grid_games);

// Specifying the LayoutManager determines how the RecyclerView arranges views.

RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getActivity(),
getResources().getInteger(R.integer.game_grid_columns));
recyclerView.setLayoutManager(layoutManager);

recyclerView.setLayoutManager(layoutManager);
recyclerView.addItemDecoration(new GameAdapter.SpacesItemDecoration(8));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setHasFixedSize(true);

// Create an adapter that will relate the dataset to the views on-screen. +1 because of LOADER_ID_ALL
getLoaderManager().initLoader(mPlatform, null,
Expand Down
4 changes: 4 additions & 0 deletions Source/Android/app/src/main/res/color/fab_gamecube.xml
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/dolphin_accent_gamecube"/>
</selector>
4 changes: 4 additions & 0 deletions Source/Android/app/src/main/res/color/fab_wii.xml
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/dolphin_accent_wii"/>
</selector>
4 changes: 4 additions & 0 deletions Source/Android/app/src/main/res/color/fab_wiiware.xml
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/dolphin_accent_wiiware"/>
</selector>
1 change: 1 addition & 0 deletions Source/Android/app/src/main/res/layout/activity_main.xml
Expand Up @@ -43,6 +43,7 @@
android:layout_margin="32dp"
android:src="@drawable/ic_add"
app:borderWidth="0dp"
app:backgroundTint="@color/fab_gamecube"
app:rippleColor="?android:colorPrimaryDark"
app:layout_anchor="@+id/pager_platforms"
app:layout_anchorGravity="bottom|right|end"/>
Expand Down
5 changes: 4 additions & 1 deletion Source/Android/app/src/main/res/layout/fragment_grid.xml
Expand Up @@ -11,5 +11,8 @@
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
tools:listitem="@layout/grid_card_game"/>
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:clipToPadding="false"
tools:listitem="@layout/card_game"/>
</FrameLayout>

0 comments on commit fe5b477

Please sign in to comment.