Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-28178
Browse files Browse the repository at this point in the history
  • Loading branch information
ssekhri committed Oct 8, 2020
2 parents d56f734 + 5ba35d3 commit adbdeea
Show file tree
Hide file tree
Showing 18 changed files with 980 additions and 560 deletions.
46 changes: 30 additions & 16 deletions android/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3291,35 +3291,49 @@ AndroidBuilder.prototype.generateI18N = async function generateI18N() {
return locale;
}

for (const locale of Object.keys(data)) {
const localeSuffixName = (locale === 'en' ? '' : '-' + resolveRegionName(locale));
const dirPath = path.join(this.buildAppMainResDir, `values${localeSuffixName}`);
const filePath = path.join(dirPath, 'ti_i18n_strings.xml');
// Traverse all loaded i18n locales and write them to XML files under the Android "res" folder.
for (const locale in data) {
// Create a localized strings dictionary if no i18n "strings.xml" file was found.
const localeData = data[locale];
if (!localeData.strings) {
localeData.strings = {};
}

// Add localized app name to strings dictionary under the "app_name" key:
// 1) If not already defined in i18n "strings.xml" file. (This is undocumented, but some devs do this.)
// 2) If defined in i18n "app.xml". (The preferred cross-platform way to localize it.)
// 3) Default to "tiapp.xml" file's <name/> if not defined under i18n. (Not localized.)
let appName = localeData.strings.app_name;
if (!appName) {
appName = localeData.app && localeData.app.appname;
if (!appName) {
appName = this.tiapp.name;
}
localeData.strings.app_name = appName;
}

// Create the XML content for all localized strings.
const dom = new DOMParser().parseFromString('<resources/>', 'text/xml');
const root = dom.documentElement;
const appname = data[locale].app && data[locale].app.appname || this.tiapp.name;
const appnameNode = dom.createElement('string');

appnameNode.setAttribute('name', 'app_name');
appnameNode.setAttribute('formatted', 'false');
appnameNode.appendChild(dom.createTextNode(appname));
root.appendChild(dom.createTextNode('\n\t'));
root.appendChild(appnameNode);
data[locale].strings && Object.keys(data[locale].strings).forEach(function (name) {
for (const name in localeData.strings) {
if (name.indexOf(' ') !== -1) {
badStringNames[locale] || (badStringNames[locale] = []);
badStringNames[locale].push(name);
} else if (name !== 'appname') {
} else {
const node = dom.createElement('string');
node.setAttribute('name', name);
node.setAttribute('formatted', 'false');
node.appendChild(dom.createTextNode(data[locale].strings[name].replace(/\\?'/g, '\\\'').replace(/^\s+/g, replaceSpaces).replace(/\s+$/g, replaceSpaces)));
node.appendChild(dom.createTextNode(localeData.strings[name].replace(/\\?'/g, '\\\'').replace(/^\s+/g, replaceSpaces).replace(/\s+$/g, replaceSpaces)));
root.appendChild(dom.createTextNode('\n\t'));
root.appendChild(node);
}
});
}
root.appendChild(dom.createTextNode('\n'));

// Create the XML file under the Android "res/values-<locale>" folder.
const localeSuffixName = (locale === 'en' ? '' : '-' + resolveRegionName(locale));
const dirPath = path.join(this.buildAppMainResDir, `values${localeSuffixName}`);
const filePath = path.join(dirPath, 'ti_i18n_strings.xml');
this.logger.debug(__('Writing %s strings => %s', locale.cyan, filePath.cyan));
await fs.ensureDir(dirPath);
await fs.writeFile(filePath, '<?xml version="1.0" encoding="UTF-8"?>\n' + dom.documentElement.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ public class AndroidModule extends KrollModule
@Kroll.constant
public static final int FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION =
ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION;
@Kroll.constant
public static final int FOREGROUND_SERVICE_TYPE_MICROPHONE = ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE;
@Kroll.constant
public static final int FOREGROUND_SERVICE_TYPE_CAMERA = ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA;

protected RProxy r;
private LinkedList<BroadcastReceiverProxy> registeredBroadcastReceiverProxyList = new LinkedList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ protected void executeServiceCode(ServiceProxy proxy)
if (!fullUrl.contains("://") && !fullUrl.startsWith("/") && proxy.getCreationUrl().baseUrl != null) {
fullUrl = proxy.getCreationUrl().baseUrl + fullUrl;
}

if (Log.isDebugModeEnabled()) {
if (url != fullUrl) {
Log.d(TAG, "Eval JS Service:" + url + " (" + fullUrl + ")");
} else {
Log.d(TAG, "Eval JS Service:" + url);
String message = "Eval JS Service: " + url;
if (!url.equals(fullUrl)) {
message += " (" + fullUrl + ")";
}
Log.d(TAG, message);
}

if (fullUrl.startsWith(TiC.URL_APP_PREFIX)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
TiC.PROPERTY_ICON,
TiC.PROPERTY_TITLE,
TiC.PROPERTY_TITLE_COLOR,
TiC.PROPERTY_TITLEID
TiC.PROPERTY_TITLEID,
TiC.PROPERTY_BADGE,
TiC.PROPERTY_BADGE_COLOR
})
public class TabProxy extends TiViewProxy
{
Expand Down Expand Up @@ -253,6 +255,12 @@ public void onPropertyChanged(String name, Object value)
if (name.equals(TiC.PROPERTY_ICON)) {
((TiUIAbstractTabGroup) tabGroupProxy.getOrCreateView()).updateTabIcon(tabGroupProxy.getTabIndex(this));
}
if (name.equals(TiC.PROPERTY_BADGE)) {
((TiUIAbstractTabGroup) tabGroupProxy.getOrCreateView()).updateBadge(tabGroupProxy.getTabIndex(this));
}
if (name.equals(TiC.PROPERTY_BADGE_COLOR)) {
((TiUIAbstractTabGroup) tabGroupProxy.getOrCreateView()).updateBadgeColor(tabGroupProxy.getTabIndex(this));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ public abstract class TiUIAbstractTabGroup extends TiUIView
*/
public abstract void setBackgroundColor(int colorInt);

/**
* Update the tab badge
*
* @param index of the Tab to update.
*/
public abstract void updateBadge(int index);

/**
* Update the tab badge color
*
* @param index of the Tab to update.
*/
public abstract void updateBadgeColor(int index);

/**
* Updates the tab's background drawables to the proper color states.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,7 @@
*/
package ti.modules.titanium.ui.widget.tabgroup;

import android.annotation.SuppressLint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import com.google.android.material.bottomnavigation.BottomNavigationItemView;
import com.google.android.material.bottomnavigation.BottomNavigationMenuView;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.bottomnavigation.LabelVisibilityMode;

import android.view.MenuItem;
import android.view.View;
import android.view.ViewParent;
import java.util.ArrayList;

import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiBaseActivity;
Expand All @@ -27,7 +17,18 @@
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiCompositeLayout;

import java.util.ArrayList;
import android.annotation.SuppressLint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewParent;

import com.google.android.material.badge.BadgeDrawable;
import com.google.android.material.bottomnavigation.BottomNavigationItemView;
import com.google.android.material.bottomnavigation.BottomNavigationMenuView;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.bottomnavigation.LabelVisibilityMode;

import ti.modules.titanium.ui.TabGroupProxy;
import ti.modules.titanium.ui.TabProxy;
Expand Down Expand Up @@ -160,7 +161,7 @@ public void addTabItemInController(TiViewProxy tabProxy)
return;
}
// Create a new item with id representing its index in mMenuItemsArray.
MenuItem menuItem = this.mBottomNavigationView.getMenu().add(null);
MenuItem menuItem = this.mBottomNavigationView.getMenu().add(0, this.mMenuItemsArray.size(), 0, "");
// Set the click listener.
menuItem.setOnMenuItemClickListener(this);
// Add the MenuItem to the menu of BottomNavigationView.
Expand Down Expand Up @@ -190,6 +191,10 @@ private void updateDrawablesAfterNewItem(int index)
updateTabTitle(index);
// Set the icon.
updateTabIcon(index);
// Set the badge
updateBadge(index);
// Set the badge color
updateBadgeColor(index);
for (int i = 0; i < this.mBottomNavigationView.getMenu().size(); i++) {
// Set the title text color.
updateTabTitleColor(i);
Expand Down Expand Up @@ -275,6 +280,48 @@ public void updateTabTitle(int index)
}

@SuppressLint("RestrictedApi")
@Override
public void updateBadge(int index)
{
if ((index < 0) || (index >= this.tabs.size())) {
return;
}

TiViewProxy tabProxy = this.tabs.get(index).getProxy();
if (tabProxy == null) {
return;
}

int menuItemId = this.mBottomNavigationView.getMenu().getItem(index).getItemId();
BadgeDrawable badgeDrawable = this.mBottomNavigationView.getOrCreateBadge(menuItemId);
if (tabProxy.getProperty(TiC.PROPERTY_BADGE) != null) {
badgeDrawable.setVisible(true);
badgeDrawable.setNumber(TiConvert.toInt(tabProxy.getProperty(TiC.PROPERTY_BADGE), 0));
} else {
badgeDrawable.setVisible(false);
}
}

@Override
public void updateBadgeColor(int index)
{
if ((index < 0) || (index >= this.tabs.size())) {
return;
}

TiViewProxy tabProxy = this.tabs.get(index).getProxy();
if (tabProxy == null) {
return;
}

int menuItemId = this.mBottomNavigationView.getMenu().getItem(index).getItemId();
if (tabProxy.getProperty(TiC.PROPERTY_BADGE_COLOR) != null) {
BadgeDrawable badgeDrawable = this.mBottomNavigationView.getOrCreateBadge(menuItemId);
badgeDrawable.setBackgroundColor(
TiConvert.toColor((String) tabProxy.getProperty(TiC.PROPERTY_BADGE_COLOR)));
}
}

@Override
public void updateTabTitleColor(int index)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@
*/
package ti.modules.titanium.ui.widget.tabgroup;

import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import com.google.android.material.tabs.TabLayout;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiBaseActivity;
import org.appcelerator.titanium.TiC;
Expand All @@ -24,6 +15,17 @@
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiCompositeLayout;

import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.android.material.badge.BadgeDrawable;
import com.google.android.material.tabs.TabLayout;

import ti.modules.titanium.ui.TabGroupProxy;

/**
Expand Down Expand Up @@ -161,6 +163,10 @@ public void addTabItemInController(TiViewProxy tabProxy)
updateTabBackgroundDrawable(tabIndex);
// Set the icon.
updateTabIcon(tabIndex);
// Set the badge.
updateBadge(tabIndex);
// Set the badge.color
updateBadgeColor(tabIndex);
}

/**
Expand Down Expand Up @@ -261,6 +267,47 @@ public void updateTabTitleColor(int index)
}
}

@Override
public void updateBadge(int index)
{
// Validate index input.
if (index < 0 || index >= tabs.size()) {
return;
}
TiViewProxy tabProxy = tabs.get(index).getProxy();
if (tabProxy == null) {
return;
}

BadgeDrawable badgeDrawable = this.mTabLayout.getTabAt(index).getOrCreateBadge();
if (tabProxy.getProperty(TiC.PROPERTY_BADGE) != null) {
badgeDrawable.setVisible(true);
badgeDrawable.setNumber(TiConvert.toInt(tabProxy.getProperty(TiC.PROPERTY_BADGE), 0));
} else {
badgeDrawable.setVisible(false);
}
}

@Override
public void updateBadgeColor(int index)
{
// Validate index input.
if (index < 0 || index >= tabs.size()) {
return;
}
TiViewProxy tabProxy = tabs.get(index).getProxy();
if (tabProxy == null) {
return;
}

BadgeDrawable badgeDrawable = this.mTabLayout.getTabAt(index).getOrCreateBadge();
if (tabProxy.getProperty(TiC.PROPERTY_BADGE_COLOR) != null) {
badgeDrawable.setVisible(true);
badgeDrawable.setBackgroundColor(
TiConvert.toColor((String) tabProxy.getProperty(TiC.PROPERTY_BADGE_COLOR)));
}
}

@Override
public void updateTabIcon(int index)
{
Expand Down

0 comments on commit adbdeea

Please sign in to comment.