Replaced ActionBarSherlock with Support Library appcompat.

This commit is contained in:
Felix Ableitner 2013-09-24 01:45:04 +02:00
parent 3207eb3e5b
commit fa6d444d1b
6 changed files with 162 additions and 159 deletions

View file

@ -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.

View file

@ -12,4 +12,4 @@
# Project target.
target=android-18
android.library.reference.1=../actionbarsherlock
android.library.reference.1=../android-support-v7-appcompat

View file

@ -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" />

View file

@ -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,8 +45,14 @@ 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.
@ -56,41 +60,31 @@ public class MainActivity extends SherlockFragmentActivity implements
private UpnpPlayer mPlayer = new UpnpPlayer();
/**
* Provides Fragments, holding all of them in memory.
* Holds fragments.
*/
private SectionsPagerAdapter mSectionsPagerAdapter =
new SectionsPagerAdapter(getSupportFragmentManager());
SectionsPagerAdapter mSectionsPagerAdapter;
/**
* Holds the section contents.
* Allows tab swiping.
*/
private ViewPager mViewPager;
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();
@Override
protected void onCreate(Bundle savedInstanceState) {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
setContentView(R.layout.activity_main);
// Set up the action bar.
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// ViewPager and its adapters use support library
// fragments, so use getSupportFragmentManager.
mSectionsPagerAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
// Select correct tab after swiping.
mViewPager.setOnPageChangeListener(
new ViewPager.SimpleOnPageChangeListener() {
@Override
@ -99,12 +93,26 @@ public class MainActivity extends SherlockFragmentActivity implements
}
});
TabListener tabListener = new ActionBar.TabListener() {
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
mViewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
}
@Override
public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
}
};
actionBar.addTab(actionBar.newTab()
.setText(R.string.title_server)
.setTabListener(this));
.setTabListener(tabListener));
actionBar.addTab(actionBar.newTab()
.setText(R.string.title_renderer)
.setTabListener(this));
.setTabListener(tabListener));
mPlayer.open(getApplicationContext());
}
@ -115,53 +123,6 @@ public class MainActivity extends SherlockFragmentActivity implements
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 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).
@ -194,18 +155,18 @@ public class MainActivity extends SherlockFragmentActivity implements
}
/**
* Returns shared instance of UpnpPlayer.
* 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);
}
}

View file

@ -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;
}
}