Skip to content

Commit

Permalink
feat(typings): Adding Android typings for API levels from 17 to 27 (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
vtrifonov authored and Alexander Vakrilov committed Jul 5, 2018
1 parent bcadcbe commit 398c9b3
Show file tree
Hide file tree
Showing 48 changed files with 1,183,360 additions and 259,921 deletions.
2 changes: 1 addition & 1 deletion tests/app/ui/button/button-tests-native.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions tests/app/ui/layouts/layout-helper.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand All @@ -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++;
}
Expand All @@ -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++;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tns-core-modules/ui/action-bar/action-bar.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions tns-core-modules/ui/core/view/view.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions tns-core-modules/ui/frame/activity.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand All @@ -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);
}
}
8 changes: 5 additions & 3 deletions tns-core-modules/ui/frame/fragment.transitions.android.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference path="transition-definitions.android.d.ts"/>

// Definitions.
import { NavigationTransition, BackstackEntry } from "../frame";
import { AnimationType } from "./fragment.transitions";
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
58 changes: 58 additions & 0 deletions tns-core-modules/ui/frame/transition-definitions.android.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
2 changes: 1 addition & 1 deletion tns-core-modules/ui/image-cache/image-cache.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tns-core-modules/ui/segmented-bar/segmented-bar.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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);
Expand All @@ -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.
}
}
Expand Down
2 changes: 1 addition & 1 deletion tns-core-modules/ui/web-view/web-view.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion tns-core-modules/utils/utils.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions tns-platform-declarations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 3 additions & 0 deletions tns-platform-declarations/android-17.d.ts
Original file line number Diff line number Diff line change
@@ -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" />
3 changes: 3 additions & 0 deletions tns-platform-declarations/android-18.d.ts
Original file line number Diff line number Diff line change
@@ -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" />
3 changes: 3 additions & 0 deletions tns-platform-declarations/android-19.d.ts
Original file line number Diff line number Diff line change
@@ -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" />
3 changes: 3 additions & 0 deletions tns-platform-declarations/android-20.d.ts
Original file line number Diff line number Diff line change
@@ -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" />
3 changes: 3 additions & 0 deletions tns-platform-declarations/android-21.d.ts
Original file line number Diff line number Diff line change
@@ -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" />
3 changes: 3 additions & 0 deletions tns-platform-declarations/android-22.d.ts
Original file line number Diff line number Diff line change
@@ -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" />
3 changes: 3 additions & 0 deletions tns-platform-declarations/android-23.d.ts
Original file line number Diff line number Diff line change
@@ -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" />
3 changes: 3 additions & 0 deletions tns-platform-declarations/android-24.d.ts
Original file line number Diff line number Diff line change
@@ -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" />
3 changes: 3 additions & 0 deletions tns-platform-declarations/android-25.d.ts
Original file line number Diff line number Diff line change
@@ -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" />
3 changes: 3 additions & 0 deletions tns-platform-declarations/android-26.d.ts
Original file line number Diff line number Diff line change
@@ -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" />
3 changes: 3 additions & 0 deletions tns-platform-declarations/android-27.d.ts
Original file line number Diff line number Diff line change
@@ -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" />
2 changes: 1 addition & 1 deletion tns-platform-declarations/android.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/// <reference path="./android/android.d.ts" />
/// <reference path="./android-17.d.ts" />
Original file line number Diff line number Diff line change
Expand Up @@ -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; } }

0 comments on commit 398c9b3

Please sign in to comment.