Skip to content

Commit

Permalink
Add tabs in actionbar for showing swipe tabs.
Browse files Browse the repository at this point in the history
I don't like that this requires a whole new "appcompat" dependency, so
I'm going to use PagerTitleStrip instead.
  • Loading branch information
peplin committed Aug 17, 2014
1 parent e7abc9d commit 04314dc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
3 changes: 2 additions & 1 deletion enabler/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="20" />

<application android:label="@string/app_name" android:allowBackup="true"
android:icon="@drawable/open_xc_launcher_icon_black">
android:icon="@drawable/open_xc_launcher_icon_black"
android:theme="@style/Theme.AppCompat">
<service android:name="com.openxc.enabler.preferences.PreferenceManagerService"/>
<service android:name="com.openxc.VehicleManager"/>
<service android:name="com.openxc.remote.VehicleService" android:process=":remote">
Expand Down
Binary file added enabler/libs/appcompat-v7-19.1.0.aar
Binary file not shown.
6 changes: 6 additions & 0 deletions enabler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
<artifactId>bugsnag-android</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>com.android.support</groupId>
<artifactId>appcompat-v7</artifactId>
<version>19.1.0</version>
<type>aar</type>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
Expand Down
2 changes: 1 addition & 1 deletion enabler/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="5sp"
android:paddingRight="5sp" >
android:paddingRight="5sp">

<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
Expand Down
27 changes: 25 additions & 2 deletions enabler/src/com/openxc/enabler/OpenXcEnablerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
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.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
Expand Down Expand Up @@ -39,7 +41,7 @@
* add much to your application's AndroidManifest.xml - just the
* {@link com.openxc.VehicleManager} service.
*/
public class OpenXcEnablerActivity extends FragmentActivity {
public class OpenXcEnablerActivity extends ActionBarActivity {
private static String TAG = "OpenXcEnablerActivity";

static final int NUM_TABS = 2;
Expand All @@ -63,6 +65,27 @@ public void onCreate(Bundle savedInstanceState) {
mPager = (ViewPager) findViewById(R.id.pager);
mPager.setAdapter(mAdapter);

final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.TabListener tabListener = new ActionBar.TabListener() {
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
// show the given tab
mPager.setCurrentItem(tab.getPosition());
}

public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
}

public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
};

actionBar.addTab(actionBar.newTab()
.setText("Status")
.setTabListener(tabListener));
actionBar.addTab(actionBar.newTab()
.setText("Dashboard")
.setTabListener(tabListener));

startService(new Intent(this, VehicleManager.class));
startService(new Intent(this, PreferenceManagerService.class));
Expand Down

0 comments on commit 04314dc

Please sign in to comment.