Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timob-16212: implement setDisplayShowHome and Title for action bar #5640

Merged
merged 4 commits into from Apr 23, 2014
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -11,14 +11,14 @@
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiFileHelper;
import org.appcelerator.titanium.util.TiUrl;

import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Message;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;

@Kroll.proxy(propertyAccessors = {
TiC.PROPERTY_ON_HOME_ICON_ITEM_SELECTED
Expand All @@ -36,6 +36,8 @@ public class ActionBarProxy extends KrollProxy
private static final int MSG_SET_HOME_BUTTON_ENABLED = MSG_FIRST_ID + 107;
private static final int MSG_SET_NAVIGATION_MODE = MSG_FIRST_ID + 108;
private static final int MSG_SET_SUBTITLE = MSG_FIRST_ID + 109;
private static final int MSG_SET_DISPLAY_SHOW_HOME = MSG_FIRST_ID + 110;
private static final int MSG_SET_DISPLAY_SHOW_TITLE = MSG_FIRST_ID + 111;
private static final String SHOW_HOME_AS_UP = "showHomeAsUp";
private static final String BACKGROUND_IMAGE = "backgroundImage";
private static final String TITLE = "title";
Expand All @@ -45,6 +47,7 @@ public class ActionBarProxy extends KrollProxy
private static final String TAG = "ActionBarProxy";

private ActionBar actionBar;
private boolean showTitleEnabled = true;

public ActionBarProxy(ActionBarActivity activity)
{
Expand Down Expand Up @@ -112,6 +115,35 @@ public void setSubtitle(String subTitle)
}
}

@Kroll.method
public void setDisplayShowHomeEnabled(boolean show) {
if (actionBar == null) {
return;
}

if (TiApplication.isUIThread()) {
actionBar.setDisplayShowHomeEnabled(show);
} else {
Message message = getMainHandler().obtainMessage(MSG_SET_DISPLAY_SHOW_HOME, show);
message.sendToTarget();
}
}

@Kroll.method
public void setDisplayShowTitleEnabled(boolean show) {
if (actionBar == null) {
return;
}

if (TiApplication.isUIThread()) {
actionBar.setDisplayShowTitleEnabled(show);
showTitleEnabled = show;
} else {
Message message = getMainHandler().obtainMessage(MSG_SET_DISPLAY_SHOW_TITLE, show);
message.sendToTarget();
}
}

@Kroll.method @Kroll.getProperty
public String getSubtitle()
{
Expand Down Expand Up @@ -247,8 +279,8 @@ private void handleSetBackgroundImage(String url)
Drawable backgroundImage = getDrawableFromUrl(url);
//This is a workaround due to https://code.google.com/p/styled-action-bar/issues/detail?id=3. [TIMOB-12148]
if (backgroundImage != null) {
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayShowTitleEnabled(!showTitleEnabled);
actionBar.setDisplayShowTitleEnabled(showTitleEnabled);
actionBar.setBackgroundDrawable(backgroundImage);
}
}
Expand Down Expand Up @@ -306,7 +338,20 @@ public boolean handleMessage(Message msg)
case MSG_SET_SUBTITLE:
handleSetSubTitle(msg.getData().getString(TiC.PROPERTY_SUBTITLE));
return true;

case MSG_SET_DISPLAY_SHOW_HOME: {
boolean show = TiConvert.toBoolean(msg.obj, true);
if (actionBar != null) {
actionBar.setDisplayShowHomeEnabled(show);
}
return true;
}
case MSG_SET_DISPLAY_SHOW_TITLE: {
boolean show = TiConvert.toBoolean(msg.obj, true);
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(show);
showTitleEnabled = show;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return statement

}
case MSG_SHOW:
handleShow();
return true;
Expand Down
26 changes: 25 additions & 1 deletion apidoc/Titanium/Android/ActionBar.yml
Expand Up @@ -64,7 +64,31 @@ methods:
See also:
[hide](http://developer.android.com/reference/android/app/ActionBar.html#hide())
in the Android API Reference.


- name: setDisplayShowHomeEnabled
summary: Shows or hides the action bar home icon
parameters:
- name: show
summary: Boolean to show or hide action bar home icon
type: Boolean
description: |
See also:
[setDisplayShowHomeEnabled](http://developer.android.com/reference/android/app/ActionBar.html#setDisplayShowHomeEnabled(boolean))
in the Android API Reference.
since: ["3.3.0"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect. validate will fail. Use
since : "3.3.0"


- name: setDisplayShowTitleEnabled
summary: Shows or hides the action bar title/subtitle
parameters:
- name: show
summary: Boolean to show or hide action bar title/subtitle
type: Boolean
description: |
See also:
[setDisplayShowTitleEnabled](http://developer.android.com/reference/android/app/ActionBar.html#setDisplayShowTitleEnabled(boolean))
in the Android API Reference.
since: ["3.3.0"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect. validate will fail. Use
since : "3.3.0"


- name: show
summary: Shows the action bar if it is currently hidden.
description: |
Expand Down