Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-25757
Browse files Browse the repository at this point in the history
  • Loading branch information
garymathews committed Feb 21, 2018
2 parents 39ca47d + 7d46dc5 commit 1fe167d
Show file tree
Hide file tree
Showing 25 changed files with 572 additions and 218 deletions.
73 changes: 39 additions & 34 deletions android/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @module cli/_build
*
* @copyright
* Copyright (c) 2009-2017 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2018 by Appcelerator, Inc. All Rights Reserved.
*
* Copyright (c) 2012-2013 Chris Talkington, contributors.
* {@link https://github.com/ctalkington/node-archiver}
Expand All @@ -24,13 +24,11 @@ const ADB = require('node-titanium-sdk/lib/adb'),
appc = require('node-appc'),
archiver = require('archiver'),
async = require('async'),
babel = require('babel-core'),
Builder = require('../lib/base-builder.js'),
CleanCSS = require('clean-css'),
DOMParser = require('xmldom').DOMParser,
ejs = require('ejs'),
EmulatorManager = require('node-titanium-sdk/lib/emulator'),
env = require('babel-preset-env'),
fields = require('fields'),
fs = require('fs'),
i18n = require('node-titanium-sdk/lib/i18n'),
Expand Down Expand Up @@ -917,6 +915,13 @@ AndroidBuilder.prototype.validate = function validate(logger, config, cli) {
this.dxMaxMemory = cli.tiapp.properties['android.dx.maxmemory'] && cli.tiapp.properties['android.dx.maxmemory'].value || config.get('android.dx.maxMemory', '1024M');
this.dxMaxIdxNumber = cli.tiapp.properties['android.dx.maxIdxNumber'] && cli.tiapp.properties['android.dx.maxIdxNumber'].value || config.get('android.dx.maxIdxNumber', '65536');

// Transpilation details
this.transpile = cli.tiapp['transpile'] !== false; // FIXME Does this properly default to true?
// We get a string here like 6.2.414.36, we need to convert it to 62 (integer)
const v8Version = this.packageJson.v8.version;
const found = v8Version.match(V8_STRING_VERSION_REGEXP);
this.chromeVersion = parseInt(found[1] + found[2]); // concat the first two numbers as string, then turn to int

// manually inject the build profile settings into the tiapp.xml
switch (this.deployType) {
case 'production':
Expand Down Expand Up @@ -1633,13 +1638,9 @@ process.exit(1);
for (let dependency of timodule.modules) {
if (!dependency.platform || /^android$/.test(dependency.platform)) {

let missing = true;
for (let module of this.nativeLibModules) {
if (module.id === dependency.id) {
missing = false;
break;
}
}
let missing = !this.nativeLibModules.some(function (mod) {
return mod.id === dependency.id;
});
if (missing) {
dependency.depended = module;

Expand Down Expand Up @@ -2701,39 +2702,43 @@ AndroidBuilder.prototype.copyResources = function copyResources(next) {

try {
this.cli.createHook('build.android.copyResource', this, function (from, to, cb) {
// parse the AST
const originalContents = fs.readFileSync(from).toString();
const r = jsanalyze.analyzeJs(originalContents, { minify: this.minifyJS, filename: from });
// Populate an initial object to pass in. This won't have modified
// contents or symbols populated, which it used to at this point,
// but I don't think any plugin relied on that behavior, while
// hyperloop would clobber the contents if we didn't do the mods
// inside the compile hook.
const r = {
original: originalContents,
contents: originalContents,
symbols: []
};
this.cli.createHook('build.android.compileJsFile', this, function (r, from, to, cb2) {
// Read the possibly modified file contents
const source = r.contents;
// Analyze Ti API usage, possibly also minify/transpile
const modified = jsanalyze.analyzeJs(source, {
filename: from,
minify: this.minifyJS,
transpile: this.transpile,
targets: {
chrome: this.chromeVersion
}
});
const newContents = modified.contents;

// we want to sort by the "to" filename so that we correctly handle file overwriting
this.tiSymbols[to] = r.symbols;
// we want to sort by the "to" filename so that we correctly handle file overwriting
this.tiSymbols[to] = modified.symbols;

// Now transpile too!
this.cli.createHook('build.android.compileJsFile', this, function (r, from, to, cb2) {
const dir = path.dirname(to);
fs.existsSync(dir) || wrench.mkdirSyncRecursive(dir);
// We get a string here like 6.2.414.36, we need to convert it to 62 (integer)
const v8Version = this.packageJson.v8.version;
const found = v8Version.match(V8_STRING_VERSION_REGEXP);
const chromeVersion = parseInt(found[1] + found[2]); // concat the first two numbers as string, then turn to int
const result = babel.transform(r.contents, {
filename: from,
presets: [
[ env, {
'targets': {
'chrome': chromeVersion,
}
}]
]
});
const newContents = result.code;

// If we're able to symlink and the contents didn't change, great let's just symlink
if (symlinkFiles && newContents === originalContents) {
this.logger.debug(__('Copying %s => %s', from.cyan, to.cyan));
copyFile.call(this, from, to, cb2);
} else {
// code changed or we can't symlink. Either way, write the file to dest
this.logger.debug(__('Copying %s => %s', from.cyan, to.cyan));
// TODO If dest file exists and contents match, don't do anything?
this.logger.debug(__('Writing modified contents to %s', to.cyan));
fs.writeFile(to, newContents, cb2);
}
})(r, from, to, cb);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,25 @@ public boolean isProvider(String name)

public boolean getLocationServicesEnabled()
{
// Fetch all enabled location providers.
List<String> providerNames = locationManager.getProviders(true);
if ((providerNames == null) || (providerNames.size() <= 0)) {
return false;
}

// Log all providers currently enabled.
if (Log.isDebugModeEnabled()) {
Log.i(TAG, "Enabled location provider count: " + providerNames.size());

for (String providerName : providerNames) {
Log.i(TAG, providerName + " service available");
}
}

return providerNames.size() != 0 && getLastKnownLocation() != null;
// Only return true if location can be obtained via GPS or WiFi/Cellular.
// Ignore "passive" provider and "test" providers.
boolean isEnabled = providerNames.contains(LocationManager.GPS_PROVIDER);
isEnabled |= providerNames.contains(LocationManager.NETWORK_PROVIDER);
return isEnabled;
}

public Location getLastKnownLocation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.common.Log;
Expand All @@ -17,7 +18,6 @@
import android.media.MediaMetadataRetriever;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.webkit.URLUtil;
Expand Down Expand Up @@ -173,10 +173,10 @@ private int setDataSource(Uri mUri, MediaMetadataRetriever mMediaMetadataRetriev
}
} else {
mUri = TiUIHelper.getRedirectUri(mUri);
if (Build.VERSION.SDK_INT >= 14) {
mMediaMetadataRetriever.setDataSource(TiApplication.getAppRootOrCurrentActivity(), mUri);
if (URLUtil.isNetworkUrl(mUri.toString())) {
mMediaMetadataRetriever.setDataSource(mUri.toString(), new HashMap<String, String>());
} else {
mMediaMetadataRetriever.setDataSource(mUri.toString());
mMediaMetadataRetriever.setDataSource(TiApplication.getAppRootOrCurrentActivity(), mUri);
}
}
} catch (IOException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP

} else if (key.equals(TiC.PROPERTY_REPEAT_MODE)) {
videoView.setRepeatMode(TiConvert.toInt(newValue));
} else if (key.equals(TiC.PROPERTY_SHOWS_CONTROLS)) {
setMediaControlStyle(getPlayerProxy().getMediaControlStyle());
} else {
super.propertyChanged(key, oldValue, newValue, proxy);
}
Expand Down Expand Up @@ -208,8 +210,8 @@ public void setMediaControlStyle(int style)
return;
}

// Determine if the overlaid controls should be shown/hidden based on given media style.
boolean showController = true;

switch (style) {
case MediaModule.VIDEO_CONTROL_DEFAULT:
case MediaModule.VIDEO_CONTROL_EMBEDDED:
Expand All @@ -222,6 +224,17 @@ public void setMediaControlStyle(int style)
break;
}

// If VideoPlayer's "showsControls" property is false,
// then ignore "mediaControlStyle" property and hide controls.
VideoPlayerProxy proxy = getPlayerProxy();
if (proxy != null) {
Object value = proxy.getProperty(TiC.PROPERTY_SHOWS_CONTROLS);
if ((value instanceof Boolean) && value.equals(Boolean.FALSE)) {
showController = false;
}
}

// Show/hide the video's overlaid controls.
if (showController) {
if (mediaController == null) {
mediaController = new MediaController(proxy.getActivity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import android.os.Handler;
import android.os.Message;
import android.os.Messenger;
import android.webkit.URLUtil;

// clang-format off
@Kroll.proxy(creatableInModule = MediaModule.class,
Expand All @@ -44,7 +45,8 @@
"endPlaybackTime",
"playableDuration",
TiC.PROPERTY_VOLUME,
TiC.PROPERTY_REPEAT_MODE
TiC.PROPERTY_REPEAT_MODE,
TiC.PROPERTY_SHOWS_CONTROLS,
})
// clang-format on
public class VideoPlayerProxy extends TiViewProxy implements TiLifecycle.OnLifecycleEvent
Expand Down Expand Up @@ -93,6 +95,7 @@ public VideoPlayerProxy()
{
super();
defaultValues.put(TiC.PROPERTY_VOLUME, 1.0f);
defaultValues.put(TiC.PROPERTY_SHOWS_CONTROLS, true);
}

@Override
Expand Down Expand Up @@ -806,15 +809,11 @@ public void requestThumbnailImagesAtTimes(Object[] times, Object option, KrollFu
cancelAllThumbnailImageRequests();
mTiThumbnailRetriever = new TiThumbnailRetriever();
String url = TiConvert.toString(getProperty(TiC.PROPERTY_URL));
if (url.startsWith("file://")) {
mTiThumbnailRetriever.setUri(
Uri.parse(this.resolveUrl(null, TiConvert.toString(this.getProperty(TiC.PROPERTY_URL)))));
} else {
String path = url.contains(":") ? new TitaniumBlob(url).getNativePath() : resolveUrl(null, url);
Uri uri = Uri.parse(path);
mTiThumbnailRetriever.setUri(uri);
if (!URLUtil.isValidUrl(url)) {
url = resolveUrl(null, url);
}

Uri uri = Uri.parse(url);
mTiThumbnailRetriever.setUri(uri);
mTiThumbnailRetriever.getBitmap(TiConvert.toIntArray(times), TiConvert.toInt(option),
createThumbnailResponseHandler(callback));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public TiUIDrawerLayout(final DrawerLayoutProxy proxy)
this.activity = (AppCompatActivity) proxy.getActivity();
LayoutInflater inflater = LayoutInflater.from(this.activity);
layout = (DrawerLayout) inflater.inflate(id_drawer_layout, null, false);
layout.setDrawerListener(new DrawerListener());
toolbar = (Toolbar) layout.findViewById(id_toolbar);

// Check if the theme provides a default ActionBar
Expand Down Expand Up @@ -165,34 +164,6 @@ private void drawerSlideEvent(View drawerView, float slideOffset)
}
}

private class DrawerListener implements DrawerLayout.DrawerListener
{

@Override
public void onDrawerClosed(View drawerView)
{
drawerClosedEvent(drawerView);
}

@Override
public void onDrawerOpened(View drawerView)
{
drawerOpenedEvent(drawerView);
}

@Override
public void onDrawerSlide(View drawerView, float slideOffset)
{
drawerSlideEvent(drawerView, slideOffset);
}

@Override
public void onDrawerStateChanged(int state)
{
drawerStateChangedEvent(state);
}
}

public void toggleLeft()
{
if (layout.isDrawerOpen(Gravity.START)) {
Expand Down Expand Up @@ -254,40 +225,45 @@ public boolean isRightVisible()
private void initDrawerToggle()
{

AppCompatActivity activity = (AppCompatActivity) proxy.getActivity();
if (activity.getSupportActionBar() == null) {
final AppCompatActivity activity = (AppCompatActivity) proxy.getActivity();
if (activity == null) {
return;
}

activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
activity.getSupportActionBar().setHomeButtonEnabled(true);
if (activity.getSupportActionBar() != null) {
activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
activity.getSupportActionBar().setHomeButtonEnabled(true);
}

drawerToggle = new ActionBarDrawerToggle(activity, layout, id_drawer_open_string, id_drawer_close_string) {
@Override
public void onDrawerClosed(View drawerView)
{
super.onDrawerClosed(drawerView);
drawerClosedEvent(drawerView);
}

@Override
public void onDrawerOpened(View drawerView)
{
super.onDrawerOpened(drawerView);
drawerOpenedEvent(drawerView);
}

@Override
public void onDrawerSlide(View drawerView, float slideOffset)
{
super.onDrawerSlide(drawerView, slideOffset);
drawerSlideEvent(drawerView, slideOffset);
}

@Override
public void onDrawerStateChanged(int state)
{
super.onDrawerStateChanged(state);
drawerStateChangedEvent(state);
}
};
layout.setDrawerListener(drawerToggle);
layout.addDrawerListener(drawerToggle);
layout.post(new Runnable() {
@Override
public void run()
Expand Down Expand Up @@ -586,7 +562,7 @@ public void release()
{
if (layout != null) {
layout.removeAllViews();
layout.setDrawerListener(null);
layout.removeDrawerListener(drawerToggle);
layout = null;
}
if (leftFrame != null) {
Expand Down Expand Up @@ -625,7 +601,9 @@ private int getDevicePixels(Object value)

private View getNativeView(TiViewProxy viewProxy)
{
View nativeView = viewProxy.getOrCreateView().getOuterView();
TiUIView view = viewProxy.getOrCreateView();
View outerView = view.getOuterView();
View nativeView = outerView != null ? outerView : view.getNativeView();
ViewGroup parentViewGroup = (ViewGroup) nativeView.getParent();
if (parentViewGroup != null) {
parentViewGroup.removeAllViews();
Expand Down

0 comments on commit 1fe167d

Please sign in to comment.