Permalink
Browse files

Added the customTabs Hack

  • Loading branch information...
1 parent 129678f commit 97c36e3acc64a5bf8f89de780274c0d7ac2d6d6e kevinmcdonagh committed Feb 4, 2010
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.novoda"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/Default">
+
+ <activity android:name=".Container"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ <activity android:name="Tab1Activity"></activity>
+
+ <activity android:name="Tab2Activity"></activity>
+
+ </application>
+ <uses-sdk android:minSdkVersion="3" />
+</manifest>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ >
+<TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/hello"
+ />
+</LinearLayout>
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <LinearLayout style="@style/TabContainer">
+ <LinearLayout android:id="@+id/tab1" style="@style/TabSelected">
+ <TextView style="@style/TabTxt" android:text="Tab1"/>
+ </LinearLayout>
+
+ <LinearLayout android:id="@+id/tab2" style="@style/TabUnselected">
+ <TextView style="@style/TabTxt" android:text="Tab2"/>
+ </LinearLayout>
+ </LinearLayout>
+
+</LinearLayout>
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ >
+
+ <LinearLayout style="@style/TabContainer">
+ <LinearLayout android:id="@+id/tab1" style="@style/TabUnselected">
+ <TextView style="@style/TabTxt" android:text="Tab1"/>
+ </LinearLayout>
+
+ <LinearLayout android:id="@+id/tab2" style="@style/TabSelected">
+ <TextView style="@style/TabTxt" android:text="Tab2"/>
+ </LinearLayout>
+
+ </LinearLayout>
+
+</LinearLayout>
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="hello">Hello World, Container!</string>
+ <string name="app_name">MultipleActivityTabHost</string>
+</resources>
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <style name="Default">
+ <item name="android:layout_width">wrap_content</item>
+ <item name="android:layout_height">wrap_content</item>
+ </style>
+
+ <style name="WidthFillParentBoth">
+ <item name="android:layout_width">fill_parent</item>
+ <item name="android:layout_height">fill_parent</item>
+ </style>
+
+ <style name="TabContainer">
+ <item name="android:layout_width">fill_parent</item>
+ <item name="android:layout_height">60dip</item>
+ <item name="android:orientation">horizontal</item>
+ </style>
+
+ <style name="Tab">
+ <item name="android:layout_height">fill_parent</item>
+ <item name="android:gravity">center</item>
+ <item name="android:layout_weight">33</item>
+ </style>
+
+ <style name="TabUnselected" parent="Tab">
+ <item name="android:background">@drawable/unselected</item>
+ </style>
+
+ <style name="TabSelected" parent="Tab">
+ <item name="android:background">@drawable/selected</item>
+ </style>
+
+ <style name="TabTxt">
+ <item name="android:gravity">center</item>
+ </style>
+
+
+</resources>
@@ -0,0 +1,69 @@
+package com.novoda;
+
+import android.app.TabActivity;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.widget.TabHost;
+
+public class Container extends TabActivity{
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
+ super.onCreate(savedInstanceState);
+
+ host = getTabHost();
+ Intent intent = new Intent(this, Tab1Activity.class);
+ host.addTab(host.newTabSpec("one").setIndicator("TAB1").setContent(intent));
+ intent = new Intent(this, Tab2Activity.class);
+ host.addTab(host.newTabSpec("two").setIndicator("TAB2").setContent(intent));
+
+ host.getTabWidget().getChildAt(0).getLayoutParams().height = 0;
+ host.getTabWidget().getChildAt(1).getLayoutParams().height = 0;
+
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ receiver = new TabChangeReceiver();
+ registerReceiver(receiver, new IntentFilter("com.novoda.TAB"), null, mHandler);
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ unregisterReceiver(receiver);
+ };
+
+ protected Handler mHandler = new Handler() {
+ @Override public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case SWITCH_TAB:
+ Log.i("handler", "using the handler");
+ host.setCurrentTab(msg.arg1);
+ break;
+ }
+ }
+ };
+
+ public class TabChangeReceiver extends android.content.BroadcastReceiver{
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ int intExtra = intent.getIntExtra("tab", 0);
+ Log.i(TabChangeReceiver.class.getSimpleName(), "Recieved broadcast with extra=[" + intExtra + "]");
+
+ mHandler.sendMessage(mHandler.obtainMessage(SWITCH_TAB, intExtra, 0));
+ }
+ }
+
+ private TabHost host;
+ public static final int SWITCH_TAB = 2545;
+ protected static TabChangeReceiver receiver;
+
+}
@@ -0,0 +1,25 @@
+package com.novoda;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+
+public class Tab1Activity extends Activity{
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.tab1);
+
+ findViewById(R.id.tab2).setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ Intent intent = new Intent("com.novoda.TAB");
+ intent.putExtra("tab", 1);
+ sendBroadcast(intent);
+ }
+ });
+
+ }
+}
@@ -0,0 +1,25 @@
+package com.novoda;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+
+public class Tab2Activity extends Activity{
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.tab2);
+
+ findViewById(R.id.tab1).setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ Intent intent = new Intent("com.novoda.TAB");
+ intent.putExtra("tab", 0);
+ sendBroadcast(intent);
+ }
+ });
+
+ }
+}

0 comments on commit 97c36e3

Please sign in to comment.