Replaced ActionBarSherlock with Support Library appcompat.
This commit is contained in:
parent
3207eb3e5b
commit
fa6d444d1b
6 changed files with 162 additions and 159 deletions
|
@ -17,7 +17,7 @@
|
|||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.Sherlock.Light" >
|
||||
android:theme="@style/Theme.AppCompat.Light" >
|
||||
|
||||
<activity
|
||||
android:name="com.github.nutomic.controldlna.gui.MainActivity"
|
||||
|
|
Binary file not shown.
|
@ -12,4 +12,4 @@
|
|||
|
||||
# Project target.
|
||||
target=android-18
|
||||
android.library.reference.1=../actionbarsherlock
|
||||
android.library.reference.1=../android-support-v7-appcompat
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.view.ViewPager
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity" />
|
||||
android:layout_height="match_parent" />
|
||||
|
|
|
@ -28,184 +28,145 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
package com.github.nutomic.controldlna.gui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.Log;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBar.Tab;
|
||||
import android.support.v7.app.ActionBar.TabListener;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import com.github.nutomic.controldlna.R;
|
||||
import com.github.nutomic.controldlna.upnp.UpnpPlayer;
|
||||
|
||||
/**
|
||||
* Main activity, with tabs for media servers and media renderers.
|
||||
*
|
||||
*
|
||||
* @author Felix Ableitner
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class MainActivity extends SherlockFragmentActivity implements
|
||||
ActionBar.TabListener {
|
||||
public class MainActivity extends ActionBarActivity {
|
||||
|
||||
/**
|
||||
* Interface which allows listening to "back" button presses.
|
||||
*/
|
||||
public interface OnBackPressedListener {
|
||||
boolean onBackPressed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manages all UPNP connections including playback.
|
||||
*/
|
||||
private UpnpPlayer mPlayer = new UpnpPlayer();
|
||||
|
||||
/**
|
||||
* Provides Fragments, holding all of them in memory.
|
||||
*/
|
||||
private SectionsPagerAdapter mSectionsPagerAdapter =
|
||||
new SectionsPagerAdapter(getSupportFragmentManager());
|
||||
|
||||
/**
|
||||
* Holds the section contents.
|
||||
*/
|
||||
private ViewPager mViewPager;
|
||||
|
||||
/**
|
||||
* Fragment for first tab, holding media renderers.
|
||||
*/
|
||||
private RendererFragment mRendererFragment = new RendererFragment();
|
||||
|
||||
/**
|
||||
* Fragment for second tab, holding media servers.
|
||||
*/
|
||||
private ServerFragment mServerFragment = new ServerFragment();
|
||||
/**
|
||||
* Holds fragments.
|
||||
*/
|
||||
SectionsPagerAdapter mSectionsPagerAdapter;
|
||||
|
||||
/**
|
||||
* Allows tab swiping.
|
||||
*/
|
||||
ViewPager mViewPager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
|
||||
// Set up the action bar.
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setDisplayShowHomeEnabled(false);
|
||||
actionBar.setDisplayShowTitleEnabled(false);
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||
actionBar.setDisplayShowTitleEnabled(false);
|
||||
actionBar.setDisplayShowHomeEnabled(false);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
mViewPager = (ViewPager) findViewById(R.id.pager);
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
// ViewPager and its adapters use support library
|
||||
// fragments, so use getSupportFragmentManager.
|
||||
mSectionsPagerAdapter = new SectionsPagerAdapter(
|
||||
getSupportFragmentManager());
|
||||
|
||||
mViewPager = (ViewPager) findViewById(R.id.pager);
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
mViewPager.setOnPageChangeListener(
|
||||
new ViewPager.SimpleOnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
actionBar.setSelectedNavigationItem(position);
|
||||
}
|
||||
});
|
||||
|
||||
// Select correct tab after swiping.
|
||||
mViewPager.setOnPageChangeListener(
|
||||
new ViewPager.SimpleOnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
actionBar.setSelectedNavigationItem(position);
|
||||
}
|
||||
});
|
||||
TabListener tabListener = new ActionBar.TabListener() {
|
||||
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
|
||||
mViewPager.setCurrentItem(tab.getPosition());
|
||||
}
|
||||
|
||||
actionBar.addTab(actionBar.newTab()
|
||||
.setText(R.string.title_server)
|
||||
.setTabListener(this));
|
||||
actionBar.addTab(actionBar.newTab()
|
||||
.setText(R.string.title_renderer)
|
||||
.setTabListener(this));
|
||||
|
||||
mPlayer.open(getApplicationContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mPlayer.close(getApplicationContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabSelected(ActionBar.Tab tab,
|
||||
FragmentTransaction fragmentTransaction) {
|
||||
mViewPager.setCurrentItem(tab.getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(ActionBar.Tab tab,
|
||||
FragmentTransaction fragmentTransaction) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(ActionBar.Tab tab,
|
||||
FragmentTransaction fragmentTransaction) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Fragment corresponding to current tab.
|
||||
*/
|
||||
public class SectionsPagerAdapter extends FragmentPagerAdapter {
|
||||
|
||||
public SectionsPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
switch (position) {
|
||||
case 0: return mServerFragment;
|
||||
case 1: return mRendererFragment;
|
||||
default: return null;
|
||||
@Override
|
||||
public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener for the 'back' key.
|
||||
*/
|
||||
public interface OnBackPressedListener {
|
||||
public boolean onBackPressed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Forwards back press to active Fragment (unless the fragment is
|
||||
* showing its root view).
|
||||
*/
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
OnBackPressedListener currentFragment = (OnBackPressedListener)
|
||||
mSectionsPagerAdapter.getItem(mViewPager.getCurrentItem());
|
||||
if (!currentFragment.onBackPressed())
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes volume on key press.
|
||||
*/
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
switch (event.getKeyCode()) {
|
||||
case KeyEvent.KEYCODE_VOLUME_UP:
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN)
|
||||
mPlayer.increaseVolume();
|
||||
return true;
|
||||
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN)
|
||||
mPlayer.decreaseVolume();
|
||||
return true;
|
||||
default:
|
||||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
@Override
|
||||
public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
|
||||
}
|
||||
};
|
||||
|
||||
actionBar.addTab(actionBar.newTab()
|
||||
.setText(R.string.title_server)
|
||||
.setTabListener(tabListener));
|
||||
actionBar.addTab(actionBar.newTab()
|
||||
.setText(R.string.title_renderer)
|
||||
.setTabListener(tabListener));
|
||||
|
||||
mPlayer.open(getApplicationContext());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns shared instance of UpnpPlayer.
|
||||
*/
|
||||
public UpnpPlayer getUpnpPlayer() {
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mPlayer.close(getApplicationContext());
|
||||
}
|
||||
|
||||
/**
|
||||
* Forwards back press to active Fragment (unless the fragment is
|
||||
* showing its root view).
|
||||
*/
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
OnBackPressedListener currentFragment = (OnBackPressedListener)
|
||||
mSectionsPagerAdapter.getItem(mViewPager.getCurrentItem());
|
||||
if (!currentFragment.onBackPressed())
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes volume on key press.
|
||||
*/
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
switch (event.getKeyCode()) {
|
||||
case KeyEvent.KEYCODE_VOLUME_UP:
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN)
|
||||
mPlayer.increaseVolume();
|
||||
return true;
|
||||
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN)
|
||||
mPlayer.decreaseVolume();
|
||||
return true;
|
||||
default:
|
||||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns shared instance of UPNP player.
|
||||
* @return
|
||||
*/
|
||||
public UpnpPlayer getUpnpPlayer() {
|
||||
return mPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the UPNP renderer tab in the activity.
|
||||
*/
|
||||
public void switchToRendererTab() {
|
||||
Log.d("tag", "called");
|
||||
getSupportActionBar().selectTab(getSupportActionBar().getTabAt(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches to the "renderer" tab.
|
||||
*/
|
||||
public void switchToRendererTab() {
|
||||
mViewPager.setCurrentItem(1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package com.github.nutomic.controldlna.gui;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
|
||||
|
||||
|
||||
//Since this is an object collection, use a FragmentStatePagerAdapter,
|
||||
//and NOT a FragmentPagerAdapter.
|
||||
public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
|
||||
|
||||
/**
|
||||
* Fragment for second tab, holding media servers.
|
||||
*/
|
||||
private ServerFragment mServerFragment = new ServerFragment();
|
||||
|
||||
/**
|
||||
* Fragment for first tab, holding media renderers.
|
||||
*/
|
||||
private RendererFragment mRendererFragment = new RendererFragment();
|
||||
|
||||
|
||||
public SectionsPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
switch (position) {
|
||||
case 0: return mServerFragment;
|
||||
case 1: return mRendererFragment;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue