Skip to content

Commit

Permalink
Merge pull request #5862 from pingwang2011/timob-17222
Browse files Browse the repository at this point in the history
Timob 17222: Android: support the theme property for windows
  • Loading branch information
hieupham007 committed Jul 15, 2014
2 parents b992c1d + 52de443 commit 35966fb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import org.appcelerator.titanium.TiDimension;
import org.appcelerator.titanium.TiTranslucentActivity;
import org.appcelerator.titanium.proxy.ActivityProxy;
import org.appcelerator.titanium.proxy.DecorViewProxy;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.proxy.TiWindowProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiRHelper;
import org.appcelerator.titanium.view.TiUIView;

import ti.modules.titanium.ui.widget.TiView;
Expand Down Expand Up @@ -310,6 +310,19 @@ private void fillIntent(Activity activity, Intent intent)
if (hasProperty(TiC.PROPERTY_WINDOW_PIXEL_FORMAT)) {
intent.putExtra(TiC.PROPERTY_WINDOW_PIXEL_FORMAT, TiConvert.toInt(getProperty(TiC.PROPERTY_WINDOW_PIXEL_FORMAT), PixelFormat.UNKNOWN));
}

// Set the theme property
if (hasProperty(TiC.PROPERTY_THEME)) {
String theme = TiConvert.toString(getProperty(TiC.PROPERTY_THEME));
if (theme != null) {
try {
intent.putExtra(TiC.PROPERTY_THEME,
TiRHelper.getResource("style." + theme.replaceAll("[^A-Za-z0-9_]", "_")));
} catch (Exception e) {
Log.w(TAG, "Cannot find the theme: " + theme);
}
}
}
}

@Override
Expand Down
8 changes: 8 additions & 0 deletions android/templates/build/theme.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowActionBar">false</item>
<!-- AppCompat Compatibility -->
<item name="windowActionBar">false</item>
</style>

<style name="Theme.Titanium" parent="@style/<%- flags %>">
<item name="android:windowBackground">@drawable/background</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<!-- AppCompat Compatibility -->
<item name="windowActionBar">false</item>
</style>

<style name="Theme.AppCompat.Translucent">
Expand All @@ -24,6 +29,9 @@
<style name="Theme.AppCompat.Translucent.NoTitleBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowActionBar">false</item>
<!-- AppCompat Compatibility -->
<item name="windowActionBar">false</item>
</style>

<style name="Theme.AppCompat.Translucent.NoTitleBar.Fullscreen">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ public TiWindowProxy getWindowProxy()
public void setWindowProxy(TiWindowProxy proxy)
{
this.window = proxy;
updateTitle();
}

/**
Expand Down Expand Up @@ -508,6 +507,13 @@ protected void onCreate(Bundle savedInstanceState)
layout.setKeepScreenOn(intent.getBooleanExtra(TiC.PROPERTY_KEEP_SCREEN_ON, layout.getKeepScreenOn()));
}

// Set the theme of the activity before calling super.onCreate().
// On 2.3 devices, it does not work if the theme is set after super.onCreate.
int theme = getIntentInt(TiC.PROPERTY_THEME, -1);
if (theme != -1) {
this.setTheme(theme);
}

super.onCreate(savedInstanceState);

// we only want to set the current activity for good in the resume state but we need it right now.
Expand All @@ -527,6 +533,10 @@ protected void onCreate(Bundle savedInstanceState)

setContentView(layout);

// Set the title of the activity after setContentView.
// On 2.3 devices, if the title is set before setContentView, the app will crash when a NoTitleBar theme is used.
updateTitle();

sendMessage(msgActivityCreatedId);
// for backwards compatibility
sendMessage(msgId);
Expand Down
5 changes: 5 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -2204,6 +2204,11 @@ public class TiC
*/
public static final String PROPERTY_TEXTID = "textid";

/**
* @module.api
*/
public static final String PROPERTY_THEME = "theme";

/**
* @module.api
*/
Expand Down
10 changes: 10 additions & 0 deletions apidoc/Titanium/UI/Window.yml
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,16 @@ properties:
platforms: [iphone,ipad]
type: Boolean

- name: theme
summary: Name of the theme to apply to the window.
description: |
Set the theme of the window. It can be either a [built-in theme](http://docs.appcelerator.com/titanium/3.0/#!/guide/Android_Themes-section-34636181_AndroidThemes-Built-inThemes)
or a [custom theme](http://docs.appcelerator.com/titanium/3.0/#!/guide/Android_Themes-section-34636181_AndroidThemes-CustomThemes).
platforms: [android]
type: String
since: "3.4.0"
availability: creation

- name: title
summary: Title of the window.
description: |
Expand Down

0 comments on commit 35966fb

Please sign in to comment.