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-17964] Android 5.0: Add support for Toolbar #9147

Merged
merged 20 commits into from
Aug 23, 2017
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.app.NotificationCompat.BigPictureStyle;
import ti.modules.titanium.filesystem.ResourceHelper;

@Kroll.proxy(creatableInModule = AndroidModule.class, propertyAccessors = {
TiC.PROPERTY_DECODE_RETRIES
Expand Down Expand Up @@ -59,17 +60,6 @@ public void handleCreationDict(KrollDict d)
}
}

private TiDrawableReference makeImageSource(Object object)
{
if (object instanceof FileProxy) {
return TiDrawableReference.fromFile(this.getActivity(), ((FileProxy) object).getBaseFile());
} else if (object instanceof String) {
return TiDrawableReference.fromUrl(this, (String) object);
} else {
return TiDrawableReference.fromObject(this.getActivity(), object);
}
}

@Kroll.method @Kroll.setProperty
public void setBigLargeIcon(Object icon)
{
Expand All @@ -93,7 +83,7 @@ public void setBigLargeIcon(Object icon)
@Kroll.method @Kroll.setProperty
public void setBigPicture(Object picture)
{
TiDrawableReference source = makeImageSource(picture);
TiDrawableReference source = ResourceHelper.getInstance().makeImageSource(this,picture);
Copy link
Contributor

Choose a reason for hiding this comment

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

Remember to always space your arguments (this, picture)


// Check for decodeRetries
if (hasProperty(TiC.PROPERTY_DECODE_RETRIES)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ti.modules.titanium.filesystem;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this should go in org.appcelerator.titanium.util with our other helpers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That will create a circular dependency between 'titanium' and 'titanium-filesystem' modules.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the "ResourceHelper.java" file really needed? In all the places you call ResourceHelper.makeImageResource(), you can call the TiDrawableReference.fromObject() method and it'll provide you the same results, plus it'll support some additional image sources such as TiBlob and resource ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's way better. I didn't realize I could use it.


import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.titanium.view.TiDrawableReference;

public class ResourceHelper {

private ResourceHelper() {
instance = new ResourceHelper();
}

public static ResourceHelper getInstance() {
return instance;
}

private static ResourceHelper instance;

public static TiDrawableReference makeImageSource(KrollProxy proxy, Object object)
{
if (object instanceof FileProxy) {
return TiDrawableReference.fromFile(proxy.getActivity(), ((FileProxy) object).getBaseFile());
} else if (object instanceof String) {
return TiDrawableReference.fromUrl(proxy, (String) object);
} else {
return TiDrawableReference.fromObject(proxy.getActivity(), object);
}
}
}
212 changes: 212 additions & 0 deletions android/modules/ui/src/java/ti/modules/titanium/ui/ToolbarProxy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
package ti.modules.titanium.ui;

import android.app.Activity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.TiToolbarProxy;
import org.appcelerator.titanium.view.TiUIView;
import ti.modules.titanium.ui.android.AndroidModule;
import ti.modules.titanium.ui.widget.TiToolbar;

@Kroll.proxy(creatableInModule=AndroidModule.class, propertyAccessors = {
TiC.PROPERTY_BAR_COLOR,
TiC.PROPERTY_EXTEND_BACKGROUND,
TiC.PROPERTY_ITEMS,
TiC.PROPERTY_TRANSLUCENT,
})
public class ToolbarProxy extends TiToolbarProxy {

private static final java.lang.String TAG = "Toolbar";

public View getToolbarInstance() {
return getTiToolbarView().getNativeView();
}

private TiToolbar getTiToolbarView() {
return ((TiToolbar) getOrCreateView());
}

@Override
public TiUIView createView(Activity activity) {
return new TiToolbar(this);
}

//region Android only methods
@Kroll.method
public void collapseActionView() {
getTiToolbarView().collapseActionView();
}

@Kroll.method
public void dismissPopupMenus() {
getTiToolbarView().dismissPopupMenus();
}

@Kroll.method
public int getContentInsetEnd() {
//Gets the ending content inset for this toolbar.
return ((Toolbar) getTiToolbarView().getNativeView()).getContentInsetEnd();
}

@Kroll.method
public int getContentInsetEndWithActions() {
//Gets the end content inset to use when action buttons are present.
return ((Toolbar) getTiToolbarView().getNativeView()).getContentInsetEndWithActions();
}

@Kroll.method
public int getContentInsetLeft() {
//Gets the left content inset for this toolbar.
return ((Toolbar) getTiToolbarView().getNativeView()).getContentInsetLeft();
}

@Kroll.method
public int getContentInsetRight() {
//Gets the right content inset for this toolbar.
return ((Toolbar) getTiToolbarView().getNativeView()).getContentInsetRight();
}

@Kroll.method
public int getContentInsetStart() {
//Gets the starting content inset for this toolbar.
return ((Toolbar) getTiToolbarView().getNativeView()).getContentInsetStart();
}

@Kroll.method
public int getContentInsetStartWithNavigation() {
//Gets the start content inset to use when a navigation button is present.
return ((Toolbar) getTiToolbarView().getNativeView()).getContentInsetStartWithNavigation();
}

@Kroll.method
public int getCurrentContentInsetEnd() {
//Gets the content inset that will be used on the ending side of the bar in the current toolbar configuration.
return ((Toolbar) getTiToolbarView().getNativeView()).getCurrentContentInsetEnd();
}

@Kroll.method
public int getCurrentContentInsetLeft() {
//Gets the content inset that will be used on the left side of the bar in the current toolbar configuration.
return ((Toolbar) getTiToolbarView().getNativeView()).getCurrentContentInsetLeft();
}

@Kroll.method
public int getCurrentContentInsetRight() {
//Gets the content inset that will be used on the right side of the bar in the current toolbar configuration.
return ((Toolbar) getTiToolbarView().getNativeView()).getCurrentContentInsetRight();
}

@Kroll.method
public int getCurrentContentInsetStart() {
//Gets the content inset that will be used on the starting side of the bar in the current toolbar configuration.
return ((Toolbar) getTiToolbarView().getNativeView()).getCurrentContentInsetStart();
}

@Kroll.method
public Object getLogo() {
return getTiToolbarView().getLogo();
}

@Kroll.method
public Object getNavigationIcon() {
return getTiToolbarView().getNavigationIcon();
}

@Kroll.method
public Object getOverflowIcon() {
return getTiToolbarView().getOverflowMenuIcon();
}

@Kroll.method
public String getSubtitle() {
return ((Toolbar) getTiToolbarView().getNativeView()).getSubtitle().toString();
}

@Kroll.method
public String getTitle() {
return ((Toolbar) getTiToolbarView().getNativeView()).getTitle().toString();
}

@Kroll.method
public boolean hasExpandedActionView() {
return ((Toolbar) getTiToolbarView().getNativeView()).hasExpandedActionView();
}

@Kroll.method
public void hideOverflowMenu() {
getTiToolbarView().hideOverFlowMenu();
}

@Kroll.method
public boolean isOverflowMenuShowing() {
return ((Toolbar) getTiToolbarView().getNativeView()).isOverflowMenuShowing();
}

@Kroll.method
public void setLogo(Object object) {
getTiToolbarView().setLogo(object);
}

@Kroll.method
public void setNavigationIcon(String value) {
getTiToolbarView().setNavigationIcon(value);
}

@Kroll.method
public void setOverflowIcon(String value) {
getTiToolbarView().setOverflowMenuIcon(value);
}

@Kroll.method
public void setSubtitle(String value) {
getTiToolbarView().setSubtitle(value);
}

@Kroll.method
public void setSubtitleTextColor(String value) {
getTiToolbarView().setSubtitleTextColor(value);
}

@Kroll.method
public void setTitle(String value) {
getTiToolbarView().setTitle(value);
}

@Kroll.method
public void setTitleTextColor(String value) {
getTiToolbarView().setTitleTextColor(value);
}

//Sets the start content inset to use when action buttons are present.
@Kroll.method
public void setContentInsetEndWithActions(int value) {
getTiToolbarView().setContentInsetEndWithActions(value);
}

//Sets the start content inset to use when a navigation button is present.
@Kroll.method
public void setContentInsetStartWithNavigation(int value) {
getTiToolbarView().setContentInsetStartWithNavigation(value);
}

//Sets the content insets for this toolbar.
@Kroll.method
public void setContentInsetsAbsolute(int insetLeft, int insetRight) {
getTiToolbarView().setContentInsetsAbsolute(insetLeft,insetRight);
}

//Sets the content insets for this toolbar relative to layout direction.
@Kroll.method
public void setContentInsetsRelative(int insetStart, int insetEnd) {
getTiToolbarView().setContentInsetsRelative(insetStart,insetEnd);
}

@Kroll.method
public void showOverflowMenu() {
getTiToolbarView().showOverFlowMenu();
}
//endregion

}