Skip to content
Permalink
Browse files
Merge pull request #5959 from mahdihijazi/tv_version_number
[Android] Show the version number on the title for the Android TV UI
  • Loading branch information
degasus committed Sep 8, 2017
2 parents b969040 + 9918d6e commit ce670c1
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 18 deletions.
@@ -0,0 +1,80 @@
package org.dolphinemu.dolphinemu.ui.main;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v17.leanback.widget.TitleViewAdapter;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.dolphinemu.dolphinemu.R;

public class CustomTitleView extends LinearLayout implements TitleViewAdapter.Provider {
private final TextView mTitleView;
private final View mBadgeView;

private final TitleViewAdapter mTitleViewAdapter = new TitleViewAdapter() {
@Override
public View getSearchAffordanceView()
{
return null;
}

@Override
public void setTitle(CharSequence titleText)
{
CustomTitleView.this.setTitle(titleText);
}

@Override
public void setBadgeDrawable(Drawable drawable)
{
CustomTitleView.this.setBadgeDrawable(drawable);
}
};

public CustomTitleView(Context context)
{
this(context, null);
}

public CustomTitleView(Context context, AttributeSet attrs)
{
this(context, attrs, 0);
}

public CustomTitleView(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
View root = LayoutInflater.from(context).inflate(R.layout.tv_title, this);
mTitleView = (TextView) root.findViewById(R.id.title);
mBadgeView = root.findViewById(R.id.badge);
}

public void setTitle(CharSequence title)
{
if (title != null)
{
mTitleView.setText(title);
mTitleView.setVisibility(View.VISIBLE);
mBadgeView.setVisibility(View.VISIBLE);
}
}

public void setBadgeDrawable(Drawable drawable)
{
if (drawable != null)
{
mTitleView.setVisibility(View.GONE);
mBadgeView.setVisibility(View.VISIBLE);
}
}

@Override
public TitleViewAdapter getTitleViewAdapter()
{
return mTitleViewAdapter;
}
}
@@ -2,9 +2,8 @@


import android.database.Cursor;

import org.dolphinemu.dolphinemu.BuildConfig;
import org.dolphinemu.dolphinemu.DolphinApplication;
import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.model.GameDatabase;
import org.dolphinemu.dolphinemu.utils.SettingsFile;
@@ -27,9 +26,7 @@ public MainPresenter(MainView view)

public void onCreate()
{
// TODO Rather than calling into native code, this should use the commented line below.
// String versionName = BuildConfig.VERSION_NAME;
String versionName = NativeLibrary.GetVersionString();
String versionName = BuildConfig.VERSION_NAME;
mView.setVersionString(versionName);
}

@@ -17,6 +17,7 @@
import android.support.v17.leanback.widget.Presenter;
import android.support.v17.leanback.widget.Row;
import android.support.v17.leanback.widget.RowPresenter;
import android.support.v4.content.ContextCompat;
import android.widget.Toast;

import org.dolphinemu.dolphinemu.R;
@@ -45,6 +46,16 @@ protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tv_main);

setupUI();

mPresenter.onCreate();

// Stuff in this block only happens when this activity is newly created (i.e. not a rotation)
if (savedInstanceState == null)
StartupHandler.HandleInit(this);
}

void setupUI() {
final FragmentManager fragmentManager = getFragmentManager();
mBrowseFragment = new BrowseFragment();
fragmentManager
@@ -54,14 +65,9 @@ protected void onCreate(Bundle savedInstanceState)

// Set display parameters for the BrowseFragment
mBrowseFragment.setHeadersState(BrowseFragment.HEADERS_ENABLED);
mBrowseFragment.setTitle(getString(R.string.app_name));
mBrowseFragment.setBadgeDrawable(getResources().getDrawable(
R.drawable.ic_launcher, null));
mBrowseFragment.setBrandColor(getResources().getColor(R.color.dolphin_blue_dark));
mBrowseFragment.setBrandColor(ContextCompat.getColor(this, R.color.dolphin_blue_dark));
buildRowsAdapter();

mPresenter.onCreate();

mBrowseFragment.setOnItemViewClickedListener(
new OnItemViewClickedListener()
{
@@ -88,20 +94,15 @@ public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowP
}
}
});

// Stuff in this block only happens when this activity is newly created (i.e. not a rotation)
if (savedInstanceState == null)
StartupHandler.HandleInit(this);
}

/**
* MainView
*/

@Override
public void setVersionString(String version)
{
// No-op
mBrowseFragment.setTitle(version);
}

@Override
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<org.dolphinemu.dolphinemu.ui.main.CustomTitleView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/browse_title_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"/>
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v17.leanback.widget.TitleView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:visibility="gone"
android:layout_alignTop="@+id/badge"
android:layout_alignBottom="@+id/badge"
android:layout_alignParentRight="true"
android:id="@+id/title"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"/>

<ImageView
android:visibility="gone"
android:layout_toLeftOf="@id/title"
android:id="@+id/badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"/>

</RelativeLayout>
</android.support.v17.leanback.widget.TitleView>
@@ -113,7 +113,7 @@
</style>

<!-- Android TV Themes -->
<style name="DolphinTvBase" parent="Theme.Leanback">
<style name="DolphinTvBase" parent="Theme.Leanback.Browse">
<item name="colorPrimary">@color/dolphin_blue</item>
<item name="colorPrimaryDark">@color/dolphin_blue_dark</item>

@@ -125,6 +125,7 @@

<style name="DolphinTvGamecube" parent="DolphinTvBase">
<item name="colorAccent">@color/dolphin_accent_gamecube</item>
<item name="browseTitleViewLayout">@layout/titleview</item>
</style>

<style name="InGameMenuOption" parent="Widget.AppCompat.Button.Borderless">

0 comments on commit ce670c1

Please sign in to comment.