feat(typings): Adding Android typings for API levels from 17 to 27 (#5890)

Adding android typings for API levels from 17 to 27

BREAKING CHANGES:
There is no longer added `I` prefix in the names of the interfaces. For example `android.view.IMenuItem` is now `android.view.MenuItem`. This matches the original name of the interface in the android framework.
This commit is contained in:
Vasil Trifonov
2018-07-05 18:36:23 +03:00
committed by Alexander Vakrilov
parent bcadcbe7b5
commit 398c9b3f33
48 changed files with 1183360 additions and 259921 deletions

View File

@@ -8,7 +8,7 @@ export function getNativeText(button: buttonModule.Button): string {
}
export function getNativeTextWrap(button: buttonModule.Button): boolean {
return (<android.widget.Button>button.android).isSingleLine();
return ((<android.widget.Button>button.android).getLineCount() === 1);
}
export function getNativeFontSize(button: buttonModule.Button): number {

View File

@@ -14,14 +14,14 @@ class NativeButton extends android.widget.Button {
return global.__native(this);
}
protected onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
this.owner.widthMeasureSpec = widthMeasureSpec;
this.owner.heightMeasureSpec = heightMeasureSpec;
this.owner.measureCount++;
}
protected onLayout(changed: boolean, left: number, top: number, right: number, bottom: number): void {
public onLayout(changed: boolean, left: number, top: number, right: number, bottom: number): void {
super.onLayout(changed, left, top, right, bottom);
this.owner.arrangeCount++;
}
@@ -33,14 +33,14 @@ class NativeStackLayout extends org.nativescript.widgets.StackLayout {
return global.__native(this);
}
protected onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
this.owner.widthMeasureSpec = widthMeasureSpec;
this.owner.heightMeasureSpec = heightMeasureSpec;
this.owner.measureCount++;
}
protected onLayout(changed: boolean, left: number, top: number, right: number, bottom: number): void {
public onLayout(changed: boolean, left: number, top: number, right: number, bottom: number): void {
super.onLayout(changed, left, top, right, bottom);
this.owner.arrangeCount++;
}
@@ -52,14 +52,14 @@ class NativeGridLayout extends org.nativescript.widgets.GridLayout {
return global.__native(this);
}
protected onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
this.owner.widthMeasureSpec = widthMeasureSpec;
this.owner.heightMeasureSpec = heightMeasureSpec;
this.owner.measureCount++;
}
protected onLayout(changed: boolean, left: number, top: number, right: number, bottom: number): void {
public onLayout(changed: boolean, left: number, top: number, right: number, bottom: number): void {
super.onLayout(changed, left, top, right, bottom);
this.owner.arrangeCount++;
}

View File

@@ -1,7 +1,7 @@
import * as common from "./application-settings-common";
import { getNativeApplication } from "../application";
var sharedPreferences: android.content.ISharedPreferences;
var sharedPreferences: android.content.SharedPreferences;
function ensureSharedPreferences() {
if (!sharedPreferences) {
sharedPreferences = (<android.app.Application>getNativeApplication()).getApplicationContext().getSharedPreferences("prefs.db", 0);

View File

@@ -38,7 +38,7 @@ function initializeMenuItemClickListener(): void {
return global.__native(this);
}
onMenuItemClick(item: android.view.IMenuItem): boolean {
onMenuItemClick(item: android.view.MenuItem): boolean {
let itemId = item.getItemId();
return this.owner._onAndroidItemSelected(itemId);
}

View File

@@ -145,9 +145,9 @@ function initializeDialogFragment() {
const dialog = new DialogImpl(this, this.getActivity(), this.getTheme());
// do not override alignment unless fullscreen modal will be shown;
// do not override alignment unless fullscreen modal will be shown;
// otherwise we might break component-level layout:
// https://github.com/NativeScript/NativeScript/issues/5392
// https://github.com/NativeScript/NativeScript/issues/5392
if (!this._fullscreen && !this._stretched) {
this.owner.horizontalAlignment = "center";
this.owner.verticalAlignment = "middle";
@@ -185,7 +185,7 @@ function initializeDialogFragment() {
this._shownCallback();
}
public onDismiss(dialog: android.content.IDialogInterface): void {
public onDismiss(dialog: android.content.DialogInterface): void {
super.onDismiss(dialog);
const manager = this.getFragmentManager();
if (manager) {

View File

@@ -71,7 +71,7 @@ function initializeEditTextListeners(): void {
// owner.android.setSelection(selectionStart);
}
public afterTextChanged(editable: android.text.IEditable): void {
public afterTextChanged(editable: android.text.Editable): void {
const owner = this.owner;
if (!owner || owner._changeFromCode) {
return;

View File

@@ -16,9 +16,9 @@ class NativeScriptActivity extends android.app.Activity {
return global.__native(this);
}
protected onCreate(savedInstanceState: android.os.Bundle): void {
public onCreate(savedInstanceState: android.os.Bundle): void {
appModule.android.init(this.getApplication());
// Set isNativeScriptActivity in onCreate.
// The JS constructor might not be called because the activity is created from Android.
this.isNativeScriptActivity = true;
@@ -29,24 +29,24 @@ class NativeScriptActivity extends android.app.Activity {
this._callbacks.onCreate(this, savedInstanceState, super.onCreate);
}
protected onNewIntent(intent: android.content.Intent): void {
public onNewIntent(intent: android.content.Intent): void {
super.onNewIntent(intent);
super.setIntent(intent);
}
protected onSaveInstanceState(outState: android.os.Bundle): void {
public onSaveInstanceState(outState: android.os.Bundle): void {
this._callbacks.onSaveInstanceState(this, outState, super.onSaveInstanceState);
}
protected onStart(): void {
public onStart(): void {
this._callbacks.onStart(this, super.onStart);
}
protected onStop(): void {
public onStop(): void {
this._callbacks.onStop(this, super.onStop);
}
protected onDestroy(): void {
public onDestroy(): void {
this._callbacks.onDestroy(this, super.onDestroy);
}
@@ -58,7 +58,7 @@ class NativeScriptActivity extends android.app.Activity {
this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined /*TODO: Enable if needed*/);
}
protected onActivityResult(requestCode: number, resultCode: number, data: android.content.Intent): void {
public onActivityResult(requestCode: number, resultCode: number, data: android.content.Intent): void {
this._callbacks.onActivityResult(this, requestCode, resultCode, data, super.onActivityResult);
}
}

View File

@@ -1,3 +1,5 @@
/// <reference path="transition-definitions.android.d.ts"/>
// Definitions.
import { NavigationTransition, BackstackEntry } from "../frame";
import { AnimationType } from "./fragment.transitions";
@@ -332,7 +334,7 @@ function getTransitionListener(entry: ExpandedEntry, transition: android.transit
return new TransitionListener(entry, transition);
}
function getAnimationListener(): android.animation.Animator.IAnimatorListener {
function getAnimationListener(): android.animation.Animator.AnimatorListener {
if (!AnimationListener) {
@Interfaces([android.animation.Animator.AnimatorListener])
class AnimationListnerImpl extends java.lang.Object implements android.animation.Animator.AnimatorListener {
@@ -375,7 +377,7 @@ function getAnimationListener(): android.animation.Animator.IAnimatorListener {
return AnimationListener;
}
function addToWaitingQueue(entry: ExpandedEntry): void {
const frameId = entry.frameId;
let entries = waitingQueue.get(frameId);
@@ -387,7 +389,7 @@ function addToWaitingQueue(entry: ExpandedEntry): void {
entries.add(entry);
}
function clearAnimationListener(animator: ExpandedAnimator, listener: android.animation.Animator.IAnimatorListener): void {
function clearAnimationListener(animator: ExpandedAnimator, listener: android.animation.Animator.AnimatorListener): void {
if (!animator) {
return;
}

View File

@@ -0,0 +1,58 @@
/**
* @private
*/ /** */
// Definitions for Android API lvl 21 transitions
declare module android {
export module transition {
export abstract class Transition extends java.lang.Object {
addListener(transition: Transition.TransitionListener): Transition;
removeListener(transition: Transition.TransitionListener): Transition;
setDuration(duration: number): Transition;
setInterpolator(interpolator: android.animation.TimeInterpolator): Transition;
}
export abstract class Visibility extends android.transition.Transition {
constructor();
}
export class Slide extends Visibility {
constructor(slideEdge: number);
}
export class Fade extends Visibility {
constructor(fadingMode: number);
static IN: number;
static OUT: number;
}
export class Explode extends Visibility {
constructor();
}
export module Transition {
export interface TransitionListener {
onTransitionStart(transition: android.transition.Transition): void;
onTransitionEnd(transition: android.transition.Transition): void;
onTransitionResume(transition: android.transition.Transition): void;
onTransitionPause(transition: android.transition.Transition): void;
onTransitionCancel(transition: android.transition.Transition): void;
}
}
}
export module app {
export interface Fragment {
getEnterTransition(): android.transition.Transition;
getExitTransition(): android.transition.Transition;
getReenterTransition(): android.transition.Transition;
getReturnTransition(): android.transition.Transition;
setEnterTransition(transition: android.transition.Transition): void;
setExitTransition(transition: android.transition.Transition): void;
setReenterTransition(transition: android.transition.Transition): void;
setReturnTransition(transition: android.transition.Transition): void;
setAllowEnterTransitionOverlap(allow: boolean): void;
setAllowReturnTransitionOverlap(allow: boolean): void;
}
}
}

View File

@@ -12,7 +12,7 @@ function ensureLruBitmapCacheClass() {
return global.__native(this);
}
protected sizeOf(key: string, bitmap: android.graphics.Bitmap): number {
public sizeOf(key: string, bitmap: android.graphics.Bitmap): number {
// The cache size will be measured in kilobytes rather than
// number of items.
var result = Math.round(bitmap.getByteCount() / 1024);

View File

@@ -36,7 +36,7 @@ function initializeNativeClasses(): void {
}
apiLevel = android.os.Build.VERSION.SDK_INT;
// Indicator thickness for material - 2dip. For pre-material - 5dip.
// Indicator thickness for material - 2dip. For pre-material - 5dip.
selectedIndicatorThickness = layout.toDevicePixels(apiLevel >= 21 ? 2 : 5);
@Interfaces([android.widget.TabHost.OnTabChangeListener])
@@ -63,7 +63,7 @@ function initializeNativeClasses(): void {
createTabContent(tag: string): android.view.View {
const tv = new android.widget.TextView(this.owner._context);
// This is collapsed by default and made visible
// This is collapsed by default and made visible
// by android when TabItem becomes visible/selected.
// TODO: Try commenting visibility change.
tv.setVisibility(android.view.View.GONE);
@@ -79,7 +79,7 @@ function initializeNativeClasses(): void {
return global.__native(this);
}
protected onAttachedToWindow(): void {
public onAttachedToWindow(): void {
// overriden to remove the code that will steal the focus from edit fields.
}
}

View File

@@ -70,7 +70,7 @@ function initializeWebViewClient(): void {
let request: any = arguments[1];
let error: any = arguments[2];
super.onReceivedError(view, request, error);
super.onReceivedError(view, request, error, null);
const owner = this.owner;
if (owner) {
if (traceEnabled()) {

View File

@@ -109,7 +109,7 @@ export module ad {
export function dismissSoftInput(nativeView?: android.view.View): void {
const inputManager = getInputMethodManager();
let windowToken: android.os.IIBinder;
let windowToken: android.os.IBinder;
if (nativeView instanceof android.view.View) {
windowToken = nativeView.getWindowToken()

View File

@@ -27,3 +27,8 @@ Create `reference.d.ts`and add the following content:
```
d.ts files require a lot of memory and CPU. Consider adding skipLibCheck option to tsconfig file.
## Generate android .d.ts files
* To generate android dependencies use [android-dts-generator](https://github.com/NativeScript/android-dts-generator) with the appropriate android version and android support jars
* To regenerate android-*.d.ts file use the **android-dts-generator** passing the corresponding android jar (described [here](https://github.com/NativeScript/android-dts-generator/blob/master/README.md#generate-definitons-for-android-sdk))
* Run the **android-dts-generator** for every support jar if needed. You can check [here](https://github.com/NativeScript/android-dts-generator/blob/master/README.md#support-libraries) where you can find that jar files. Rename the ouput .d.ts file with the library name and replace the existing android-support-* files in [android](android) folder.

View File

@@ -0,0 +1,3 @@
/// <reference path="./android/android-platform-17.d.ts" />
/// <reference path="./android/android-support-17.d.ts" />
/// <reference path="./android/common.d.ts" />

View File

@@ -0,0 +1,3 @@
/// <reference path="./android/android-platform-18.d.ts" />
/// <reference path="./android/android-support-17.d.ts" />
/// <reference path="./android/common.d.ts" />

View File

@@ -0,0 +1,3 @@
/// <reference path="./android/android-platform-19.d.ts" />
/// <reference path="./android/android-support-17.d.ts" />
/// <reference path="./android/common.d.ts" />

View File

@@ -0,0 +1,3 @@
/// <reference path="./android/android-platform-20.d.ts" />
/// <reference path="./android/android-support-17.d.ts" />
/// <reference path="./android/common.d.ts" />

View File

@@ -0,0 +1,3 @@
/// <reference path="./android/android-platform-21.d.ts" />
/// <reference path="./android/android-support-17.d.ts" />
/// <reference path="./android/common.d.ts" />

View File

@@ -0,0 +1,3 @@
/// <reference path="./android/android-platform-22.d.ts" />
/// <reference path="./android/android-support-17.d.ts" />
/// <reference path="./android/common.d.ts" />

View File

@@ -0,0 +1,3 @@
/// <reference path="./android/android-platform-23.d.ts" />
/// <reference path="./android/android-support-23.d.ts" />
/// <reference path="./android/common.d.ts" />

View File

@@ -0,0 +1,3 @@
/// <reference path="./android/android-platform-24.d.ts" />
/// <reference path="./android/android-support-23.d.ts" />
/// <reference path="./android/common.d.ts" />

View File

@@ -0,0 +1,3 @@
/// <reference path="./android/android-platform-25.d.ts" />
/// <reference path="./android/android-support-23.d.ts" />
/// <reference path="./android/common.d.ts" />

View File

@@ -0,0 +1,3 @@
/// <reference path="./android/android-platform-26.d.ts" />
/// <reference path="./android/android-support-26.d.ts" />
/// <reference path="./android/common.d.ts" />

View File

@@ -0,0 +1,3 @@
/// <reference path="./android/android-platform-27.d.ts" />
/// <reference path="./android/android-support-26.d.ts" />
/// <reference path="./android/common.d.ts" />

View File

@@ -1 +1 @@
/// <reference path="./android/android.d.ts" />
/// <reference path="./android-17.d.ts" />

View File

@@ -10,4 +10,6 @@ declare function long(num: number): any;
interface ArrayConstructor {
create(type: any, count: number): any;
}
}
declare module native { export class Array<T> { constructor(); length: number; [index: number]: T; } }

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +0,0 @@
/// <reference path="./android17.d.ts" />
/// <reference path="./declarations.d.ts" />
/// <reference path="./org.nativescript.widgets.d.ts" />

View File

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
/// <reference path="./android-declarations.d.ts" />
/// <reference path="./org.nativescript.widgets.d.ts" />

View File

@@ -366,8 +366,8 @@
export class TabLayout extends android.widget.HorizontalScrollView {
constructor(context: android.content.Context);
constructor(context: android.content.Context, attrs: android.util.IAttributeSet);
constructor(context: android.content.Context, attrs: android.util.IAttributeSet, defStyle: number);
constructor(context: android.content.Context, attrs: android.util.AttributeSet);
constructor(context: android.content.Context, attrs: android.util.AttributeSet, defStyle: number);
setSelectedIndicatorColors(color: Array<number>): void;
getSelectedIndicatorColors(): Array<number>;
@@ -388,7 +388,7 @@
export class TabViewPager extends android.support.v4.view.ViewPager {
constructor(context: android.content.Context);
constructor(context: android.content.Context, attrs: android.util.IAttributeSet);
constructor(context: android.content.Context, attrs: android.util.AttributeSet);
setSwipePageEnabled(enabled: boolean): void;
}

View File

@@ -1,6 +1,8 @@
{
"extends": "../tsconfig.shared",
"exclude": [
"android-*.d.ts",
"android/android-*.d.ts",
"ios/objc-x86_64",
"node_modules",
"package"

View File

@@ -8,6 +8,8 @@
"tns-platform-declarations/node_modules/",
"tns-platform-declarations/package/",
"tns-platform-declarations/references.d.ts",
"tns-platform-declarations/android-*.d.ts",
"tns-platform-declarations/android/android-*.d.ts",
"tests/node_modules",
"tests/package/",
"tests/platforms",

View File

@@ -10,7 +10,9 @@
],
"exclude": [
"**/*.android.ts",
"**/*.android.d.ts",
"**/*.ios.ts",
"**/*.ios.d.ts",
"tns-platform-declarations",
"tns-core-modules/node-modules",
"tns-core-modules/references.d.ts"