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,16 +28,14 @@ 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;
|
||||
|
||||
|
@ -47,165 +45,128 @@ import com.github.nutomic.controldlna.upnp.UpnpPlayer;
|
|||
* @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 fragments.
|
||||
*/
|
||||
SectionsPagerAdapter mSectionsPagerAdapter;
|
||||
|
||||
/**
|
||||
* Holds the section contents.
|
||||
*/
|
||||
private ViewPager mViewPager;
|
||||
/**
|
||||
* Allows tab swiping.
|
||||
*/
|
||||
ViewPager mViewPager;
|
||||
|
||||
/**
|
||||
* Fragment for first tab, holding media renderers.
|
||||
*/
|
||||
private RendererFragment mRendererFragment = new RendererFragment();
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
|
||||
/**
|
||||
* Fragment for second tab, holding media servers.
|
||||
*/
|
||||
private ServerFragment mServerFragment = new ServerFragment();
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||
actionBar.setDisplayShowTitleEnabled(false);
|
||||
actionBar.setDisplayShowHomeEnabled(false);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
// ViewPager and its adapters use support library
|
||||
// fragments, so use getSupportFragmentManager.
|
||||
mSectionsPagerAdapter = new SectionsPagerAdapter(
|
||||
getSupportFragmentManager());
|
||||
|
||||
// Set up the action bar.
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setDisplayShowHomeEnabled(false);
|
||||
actionBar.setDisplayShowTitleEnabled(false);
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||
mViewPager = (ViewPager) findViewById(R.id.pager);
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
mViewPager.setOnPageChangeListener(
|
||||
new ViewPager.SimpleOnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
actionBar.setSelectedNavigationItem(position);
|
||||
}
|
||||
});
|
||||
|
||||
mViewPager = (ViewPager) findViewById(R.id.pager);
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
TabListener tabListener = new ActionBar.TabListener() {
|
||||
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
|
||||
mViewPager.setCurrentItem(tab.getPosition());
|
||||
}
|
||||
|
||||
// Select correct tab after swiping.
|
||||
mViewPager.setOnPageChangeListener(
|
||||
new ViewPager.SimpleOnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
actionBar.setSelectedNavigationItem(position);
|
||||
}
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Listener for the 'back' key.
|
||||
*/
|
||||
public interface OnBackPressedListener {
|
||||
public boolean onBackPressed();
|
||||
}
|
||||
actionBar.addTab(actionBar.newTab()
|
||||
.setText(R.string.title_server)
|
||||
.setTabListener(tabListener));
|
||||
actionBar.addTab(actionBar.newTab()
|
||||
.setText(R.string.title_renderer)
|
||||
.setTabListener(tabListener));
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
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.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches to the "renderer" tab.
|
||||
*/
|
||||
public void switchToRendererTab() {
|
||||
Log.d("tag", "called");
|
||||
getSupportActionBar().selectTab(getSupportActionBar().getTabAt(1));
|
||||
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