Migrate to SlidingTabLayout

This commit is contained in:
Adrian Ulrich 2015-12-31 20:53:39 +01:00
parent b08fd9ab14
commit 9a319f9e05
8 changed files with 112 additions and 111 deletions

View File

@ -42,7 +42,6 @@ THE SOFTWARE.
<activity
android:name="LibraryActivity"
android:theme="@style/Library"
android:uiOptions="splitActionBarWhenNarrow"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@ -27,13 +27,12 @@ THE SOFTWARE.
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<View
android:id="@+id/actionbar_elevation_hack"
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="?float_color"
android:elevation="4dp"
/>
<android.support.iosched.tabs.VanillaTabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/tabs_background" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"

View File

@ -21,6 +21,10 @@
<!-- showqueue info -->
<color name="now_playing_marker">@color/vanillaAccent</color>
<!-- library tabs -->
<color name="tabs_background">@color/vanillaPrimary</color>
<color name="tabs_active_indicator">@android:color/primary_text_dark</color>
<!-- themed overlay colors for full playback activity -->
<color name="overlay_background_light">#ffeeeeee</color>
<color name="overlay_foreground_light">#f000</color>

11
res/values/colors.xml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- now-playing screen buttons tint -->
<color name="controls_active">@android:color/holo_blue_dark</color>
<color name="controls_normal">#fff5f5f5</color>
<!-- showqueue info -->
<color name="now_playing_marker">@android:color/holo_blue_dark</color>
<!-- library tabs -->
<color name="tabs_background">#ff1e1e1e</color>
<color name="tabs_active_indicator">@android:color/holo_blue_dark</color>
</resources>

View File

@ -21,13 +21,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<resources>
<!-- now-playing screen buttons tint -->
<color name="controls_active">@android:color/holo_blue_dark</color>
<color name="controls_normal">#fff5f5f5</color>
<!-- showqueue info -->
<color name="now_playing_marker">@android:color/holo_blue_dark</color>
<!-- styles -->
<style name="Dialog" parent="android:Theme.Holo.Dialog" />
<style name="DialogMinWidth" parent="android:Theme.Holo.Dialog.MinWidth" />

View File

@ -0,0 +1,85 @@
/*
* Copyright (C) 2015-2016 Adrian Ulrich <adrian@blinkenlights.ch>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package android.support.iosched.tabs;
import android.app.ActionBar;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
import android.os.Build;
/**
* Simple wrapper for SlidingTabLayout which takes
* care of setting sane per-platform defaults
*/
public class VanillaTabLayout extends SlidingTabLayout {
public VanillaTabLayout(Context context) {
this(context, null);
}
public VanillaTabLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public VanillaTabLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setCustomTabColorizer(new TabColorizer(context));
setDistributeEvenly(true);
}
/**
* Overrides the default text color
*/
@Override
protected TextView createDefaultTabView(Context context) {
TextView view = super.createDefaultTabView(context);
int color = getResources().getColor(android.R.color.primary_text_dark);
view.setTextColor(color);
return view;
}
/**
* Borrow elevation of given action bar
*
* @param ab The active action bar
*/
public void inheritElevation(ActionBar ab) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
return; // noop on earlier releases
float elevation = ab.getElevation();
ab.setElevation(0.0f);
setElevation(elevation);
}
private static class TabColorizer implements SlidingTabLayout.TabColorizer {
private final int mTabIndicatorColor;
TabColorizer(Context context) {
mTabIndicatorColor = context.getResources().getColor(ch.blinkenlights.android.vanilla.R.color.tabs_active_indicator);
}
@Override
public final int getIndicatorColor(int position) {
return mTabIndicatorColor;
}
}
}

View File

@ -1,93 +0,0 @@
/*
* Copyright (C) 2012 Christopher Eby <kreed@kreed.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package ch.blinkenlights.android.vanilla;
import android.annotation.TargetApi;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.net.Uri;
import android.provider.MediaStore;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
/**
* Framework methods only in Honeycomb or above go here.
*/
@TargetApi(11)
public class CompatHoneycomb {
/**
* Add ActionBar tabs for LibraryActivity.
*
* @param activity The activity to add to.
*/
public static void addActionBarTabs(final LibraryActivity activity)
{
ActionBar.TabListener listener = new ActionBar.TabListener() {
private final LibraryActivity mActivity = activity;
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft)
{
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft)
{
mActivity.mViewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft)
{
}
};
ActionBar ab = activity.getActionBar();
ab.removeAllTabs();
int[] order = activity.mPagerAdapter.mTabOrder;
int[] titles = LibraryPagerAdapter.TITLES;
for (int i = 0, n = activity.mPagerAdapter.getCount(); i != n; ++i) {
ab.addTab(ab.newTab().setText(titles[order[i]]).setTabListener(listener));
}
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
}
/**
* Select the ActionBar tab at the given position.
*
* @param activity The activity that owns the ActionBar.
* @param position The tab's position.
*/
public static void selectTab(Activity activity, int position)
{
ActionBar ab = activity.getActionBar();
if (position < ab.getTabCount()) {
ab.selectTab(ab.getTabAt(position));
}
}
}

View File

@ -40,6 +40,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.support.iosched.tabs.VanillaTabLayout;
import android.support.v4.view.ViewPager;
import android.text.Editable;
import android.text.TextUtils;
@ -137,7 +138,7 @@ public class LibraryActivity
private HorizontalScrollView mLimiterScroller;
private ViewGroup mLimiterViews;
private VanillaTabLayout mVanillaTabLayout;
/**
* The action to execute when a row is tapped.
*/
@ -201,6 +202,8 @@ public class LibraryActivity
mPermissionRequest.setVisibility(View.VISIBLE);
}
mVanillaTabLayout = (VanillaTabLayout)findViewById(R.id.sliding_tabs);
mVanillaTabLayout.inheritElevation(getActionBar());
loadTabOrder();
int page = settings.getInt(PrefKeys.LIBRARY_PAGE, PrefDefaults.LIBRARY_PAGE);
@ -235,7 +238,8 @@ public class LibraryActivity
private void loadTabOrder()
{
if (mPagerAdapter.loadTabOrder()) {
CompatHoneycomb.addActionBarTabs(this);
// Reinitializes all tabs
mVanillaTabLayout.setViewPager(mViewPager);
}
}
@ -1008,7 +1012,6 @@ public class LibraryActivity
mCurrentAdapter = adapter;
mLastActedId = LibraryAdapter.INVALID_ID;
updateLimiterViews();
CompatHoneycomb.selectTab(this, position);
if (adapter != null && (adapter.getLimiter() == null || adapter.getMediaType() == MediaUtils.TYPE_FILE)) {
// Save current page so it is opened on next startup. Don't save if
// the page was expanded to, as the expanded page isn't the starting