-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3419 from billdawson/ayeung-timob-11601-3_0_X
Timob 11601 3 0 x: Android: Expose ActionBar methods
- Loading branch information
Showing
6 changed files
with
344 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
232 changes: 232 additions & 0 deletions
232
android/titanium/src/java/org/appcelerator/titanium/proxy/ActionBarProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
/** | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2012 by Appcelerator, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
package org.appcelerator.titanium.proxy; | ||
|
||
import org.appcelerator.kroll.KrollProxy; | ||
import org.appcelerator.kroll.annotations.Kroll; | ||
import org.appcelerator.titanium.TiApplication; | ||
import org.appcelerator.titanium.TiC; | ||
import org.appcelerator.titanium.util.TiFileHelper; | ||
import org.appcelerator.titanium.util.TiUrl; | ||
|
||
import android.app.ActionBar; | ||
import android.app.Activity; | ||
import android.graphics.drawable.Drawable; | ||
import android.os.Build; | ||
import android.os.Message; | ||
|
||
@Kroll.proxy(propertyAccessors = { | ||
TiC.PROPERTY_ON_HOME_ICON_ITEM_SELECTED | ||
}) | ||
public class ActionBarProxy extends KrollProxy | ||
{ | ||
private static final int MSG_FIRST_ID = KrollProxy.MSG_LAST_ID + 1; | ||
private static final int MSG_DISPLAY_HOME_AS_UP = MSG_FIRST_ID + 100; | ||
private static final int MSG_SET_BACKGROUND_IMAGE = MSG_FIRST_ID + 101; | ||
private static final int MSG_SET_TITLE = MSG_FIRST_ID + 102; | ||
private static final int MSG_SHOW = MSG_FIRST_ID + 103; | ||
private static final int MSG_HIDE = MSG_FIRST_ID + 104; | ||
private static final int MSG_SET_LOGO = MSG_FIRST_ID + 105; | ||
private static final int MSG_SET_ICON = MSG_FIRST_ID + 106; | ||
|
||
private static final String SHOW_HOME_AS_UP = "showHomeAsUp"; | ||
private static final String BACKGROUND_IMAGE = "backgroundImage"; | ||
private static final String TITLE = "title"; | ||
private static final String LOGO = "logo"; | ||
private static final String ICON = "icon"; | ||
|
||
private ActionBar actionBar; | ||
|
||
public ActionBarProxy(Activity activity) | ||
{ | ||
super(); | ||
actionBar = activity.getActionBar(); | ||
} | ||
|
||
@Kroll.method @Kroll.setProperty | ||
public void setDisplayHomeAsUp(boolean showHomeAsUp) | ||
{ | ||
if(TiApplication.isUIThread()) { | ||
handlesetDisplayHomeAsUp(showHomeAsUp); | ||
} else { | ||
Message message = getMainHandler().obtainMessage(MSG_DISPLAY_HOME_AS_UP, showHomeAsUp); | ||
message.getData().putBoolean(SHOW_HOME_AS_UP, showHomeAsUp); | ||
message.sendToTarget(); | ||
} | ||
} | ||
|
||
@Kroll.method @Kroll.setProperty | ||
public void setBackgroundImage(String url) | ||
{ | ||
if (TiApplication.isUIThread()) { | ||
handleSetBackgroundImage(url); | ||
} else { | ||
Message message = getMainHandler().obtainMessage(MSG_SET_BACKGROUND_IMAGE, url); | ||
message.getData().putString(BACKGROUND_IMAGE, url); | ||
message.sendToTarget(); | ||
} | ||
} | ||
|
||
@Kroll.method @Kroll.setProperty | ||
public void setTitle(String title) | ||
{ | ||
if (TiApplication.isUIThread()) { | ||
handleSetTitle(title); | ||
} else { | ||
Message message = getMainHandler().obtainMessage(MSG_SET_TITLE, title); | ||
message.getData().putString(TITLE, title); | ||
message.sendToTarget(); | ||
} | ||
} | ||
|
||
@Kroll.method @Kroll.getProperty | ||
public String getTitle() | ||
{ | ||
return (String) actionBar.getTitle(); | ||
} | ||
|
||
@Kroll.method | ||
public void show() | ||
{ | ||
if (TiApplication.isUIThread()) { | ||
handleShow(); | ||
} else { | ||
getMainHandler().obtainMessage(MSG_SHOW).sendToTarget(); | ||
} | ||
} | ||
|
||
@Kroll.method | ||
public void hide() | ||
{ | ||
if (TiApplication.isUIThread()) { | ||
handleHide(); | ||
} else { | ||
getMainHandler().obtainMessage(MSG_HIDE).sendToTarget(); | ||
} | ||
} | ||
|
||
@Kroll.method @Kroll.setProperty | ||
public void setLogo(String url) | ||
{ | ||
if (Build.VERSION.SDK_INT >= TiC.API_LEVEL_ICE_CREAM_SANDWICH) { | ||
if (TiApplication.isUIThread()) { | ||
handleSetLogo(url); | ||
} else { | ||
Message message = getMainHandler().obtainMessage(MSG_SET_LOGO, url); | ||
message.getData().putString(LOGO, url); | ||
message.sendToTarget(); | ||
} | ||
} | ||
} | ||
|
||
@Kroll.method @Kroll.setProperty | ||
public void setIcon(String url) | ||
{ | ||
if (Build.VERSION.SDK_INT >= TiC.API_LEVEL_ICE_CREAM_SANDWICH) { | ||
if (TiApplication.isUIThread()) { | ||
handleSetIcon(url); | ||
} else { | ||
Message message = getMainHandler().obtainMessage(MSG_SET_ICON, url); | ||
message.getData().putString(ICON, url); | ||
message.sendToTarget(); | ||
} | ||
} | ||
} | ||
|
||
private void handleSetIcon(String url) | ||
{ | ||
Drawable icon = getDrawableFromUrl(url); | ||
if (icon != null) { | ||
actionBar.setIcon(icon); | ||
} | ||
} | ||
|
||
private void handleSetTitle(String title) | ||
{ | ||
actionBar.setTitle(title); | ||
} | ||
|
||
private void handleShow() | ||
{ | ||
actionBar.show(); | ||
} | ||
|
||
private void handleHide() | ||
{ | ||
actionBar.hide(); | ||
} | ||
|
||
private void handleSetBackgroundImage(String url) | ||
{ | ||
Drawable backgroundImage = getDrawableFromUrl(url); | ||
if (backgroundImage != null) { | ||
actionBar.setBackgroundDrawable(backgroundImage); | ||
} | ||
} | ||
|
||
private void handlesetDisplayHomeAsUp(boolean showHomeAsUp) | ||
{ | ||
actionBar.setDisplayHomeAsUpEnabled(showHomeAsUp); | ||
} | ||
|
||
private void handleSetLogo(String url) | ||
{ | ||
Drawable logo = getDrawableFromUrl(url); | ||
if (logo != null) { | ||
actionBar.setLogo(logo); | ||
} | ||
} | ||
|
||
private Drawable getDrawableFromUrl(String url) | ||
{ | ||
TiUrl imageUrl = new TiUrl((String) url); | ||
TiFileHelper tfh = new TiFileHelper(TiApplication.getInstance()); | ||
return tfh.loadDrawable(imageUrl.resolve(), false); | ||
} | ||
|
||
@Override | ||
public boolean handleMessage(Message msg) | ||
{ | ||
switch (msg.what) { | ||
case MSG_DISPLAY_HOME_AS_UP: | ||
handlesetDisplayHomeAsUp(msg.getData().getBoolean(SHOW_HOME_AS_UP)); | ||
return true; | ||
case MSG_SET_BACKGROUND_IMAGE: | ||
handleSetBackgroundImage(msg.getData().getString(BACKGROUND_IMAGE)); | ||
return true; | ||
case MSG_SET_TITLE: | ||
handleSetTitle(msg.getData().getString(TITLE)); | ||
return true; | ||
case MSG_SHOW: | ||
handleShow(); | ||
return true; | ||
case MSG_HIDE: | ||
handleHide(); | ||
return true; | ||
case MSG_SET_LOGO: | ||
handleSetLogo(msg.getData().getString(LOGO)); | ||
return true; | ||
case MSG_SET_ICON: | ||
handleSetIcon(msg.getData().getString(ICON)); | ||
return true; | ||
} | ||
return super.handleMessage(msg); | ||
} | ||
|
||
@Override | ||
public void onPropertyChanged(String name, Object value) | ||
{ | ||
if (Build.VERSION.SDK_INT >= TiC.API_LEVEL_ICE_CREAM_SANDWICH | ||
&& TiC.PROPERTY_ON_HOME_ICON_ITEM_SELECTED.equals(name)) { | ||
// If we have a listener on the home icon item, then enable the home button (we need to do this for ICS and | ||
// above) | ||
actionBar.setHomeButtonEnabled(true); | ||
} | ||
super.onPropertyChanged(name, value); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
name: Titanium.Android.ActionBar | ||
summary: The Titanium binding of an Android Action Bar. | ||
description: | | ||
According to the Android API Reference, an action bar is a window feature that identifies | ||
the application and user location, and provides user actions and navigation modes. This | ||
feature is only available in Android 3.0 (API level 11) and above. | ||
See: [Action Bar](http://developer.android.com/guide/topics/ui/actionbar.html) | ||
in the Android API Reference. | ||
extends: Titanium.Proxy | ||
platforms: [android] | ||
createable: false | ||
since: "3.0" | ||
methods: | ||
- name: hide | ||
summary: Hides the action bar if it is currently showing. | ||
description: | | ||
See also: | ||
[hide](http://developer.android.com/reference/android/app/ActionBar.html#hide()) | ||
in the Android API Reference. | ||
- name: show | ||
summary: Shows the action bar if it is currently hidden. | ||
description: | | ||
See also: | ||
[show](http://developer.android.com/reference/android/app/ActionBar.html#show()) | ||
in the Android API Reference. | ||
properties: | ||
- name: backgroundImage | ||
summary: The background image for the action bar, specified as a local file path or URL. | ||
type: String | ||
permission: write-only | ||
|
||
- name: displayHomeAsUp | ||
summary: Displays an "up" affordance on the "home" area of the action bar. | ||
description: | | ||
See also: [setDisplayHomeAsUpEnabled](http://developer.android.com/reference/android/app/ActionBar.html#setDisplayHomeAsUpEnabled(boolean)) | ||
in the Android Developer Reference. | ||
type: Boolean | ||
permission: write-only | ||
|
||
- name: icon | ||
summary: Sets the application icon displayed in the "home" area of the action bar, specified as a local file path or URL. | ||
description: | | ||
This method is only available on Android 4.0 (API 14) and above. See also: | ||
[setIcon](http://developer.android.com/reference/android/app/ActionBar.html#setIcon(android.graphics.drawable.Drawable)) | ||
in the Android Developer Reference. | ||
type: String | ||
permission: write-only | ||
|
||
- name: logo | ||
summary: Sets the application logo displayed in the "home" area of the action bar, specified as a local file path or URL. | ||
description: | | ||
This method is only available on Android 4.0 (API 14) and above. See also: | ||
[setLogo](http://developer.android.com/reference/android/app/ActionBar.html#setLogo(android.graphics.drawable.Drawable)) | ||
in the Android Developer Reference. | ||
type: String | ||
permission: write-only | ||
|
||
- name: title | ||
summary: Sets the title of the action bar. | ||
type: String |
Oops, something went wrong.