我想将Android Studio中的最低SDK版本从API 12更改为API 14.我尝试在清单文件中更改它,即
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
Run Code Online (Sandbox Code Playgroud)
并重建项目,但我仍然得到Android Studio IDE抛出一些错误.我认为我必须在"项目属性"或类似的东西中设置min SDK,以便IDE识别出更改,但我无法在Android Studio中找到这样做的地方.
我在同一个Typescript类中定义了以下两个函数签名,即
public emit<T1>(event: string, arg1: T1): void {}
Run Code Online (Sandbox Code Playgroud)
和
public emit<T1,T2>(event: string, arg1: T1, arg2: T2): void {}
Run Code Online (Sandbox Code Playgroud)
但是,当转换打字稿时,我得到以下错误
error TS2393: Duplicate function implementation.
Run Code Online (Sandbox Code Playgroud)
我认为你可以在typescript中重载函数,只要函数签名中的参数数量不同.鉴于上述签名分别有2个和3个参数,为什么我会得到这个转换错误?
我正在尝试使用vsts-npm-auth获取 VSTS 包存储库的身份验证令牌。在我的开发机器上我可以运行命令
npm install -g vsts-npm-auth
vsts-npm-auth -config path-to-my\.npmrc
它成功地为我提供了身份验证令牌。我现在尝试将其重新创建为 VSTS 上的构建步骤,因此我创建了 powershell 脚本auth-vsts.ps1
$npmrcFile = "$PSScriptRoot\path-to-my\.npmrc";
npm install -g vsts-npm-auth;
vsts-npm-auth -config $npmrcFile;
Run Code Online (Sandbox Code Playgroud)
并将其添加为 powershell 任务。但是任务失败如下
2017-05-30T09:37:41.1082686Z ##[section]Starting: auth-vsts
2017-05-30T09:37:41.1092712Z ==============================================================================
2017-05-30T09:37:41.1092712Z Task : PowerShell
2017-05-30T09:37:41.1092712Z Description : Run a PowerShell script
2017-05-30T09:37:41.1092712Z Version : 1.2.3
2017-05-30T09:37:41.1092712Z Author : Microsoft Corporation
2017-05-30T09:37:41.1092712Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613736)
2017-05-30T09:37:41.1092712Z ==============================================================================
2017-05-30T09:37:41.1112679Z ##[command]. 'd:\a\1\s\auth-vsts.ps1'
2017-05-30T09:37:47.3792461Z C:\NPM\Modules\vsts-npm-auth -> C:\NPM\Modules\node_modules\vsts-npm-auth\bin\vsts-npm-auth.exe
2017-05-30T09:37:47.3792461Z C:\NPM\Modules
2017-05-30T09:37:47.3802239Z `-- vsts-npm-auth@0.25.0
2017-05-30T09:37:47.3802239Z
2017-05-30T09:37:47.3802239Z
2017-05-30T09:37:47.3802239Z vsts-npm-auth v0.25.0.0 …Run Code Online (Sandbox Code Playgroud) 我正在尝试ProgressBar使用以下内容以编程方式居中:
ViewGroup layout = (ViewGroup) findViewById(android.R.id.content).getRootView();
progressBar = newProgressBar(SignInActivity.this,null,android.R.attr.progressBarStyleLarge);
progressBar.setIndeterminate(true);
progressBar.setVisibility(View.VISIBLE);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100,100);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.addView(progressBar,params);
Run Code Online (Sandbox Code Playgroud)
大小设置似乎工作正常,但ProgressBar不在现有布局(由具有相对布局的xml定义)中.这里有什么明显的错误吗?
XML如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".test"
android:typeface="monospace">
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
即它只是一个空的相对布局来测试,看看我是否可以通过编程方式添加进度条.
谢谢.
我已经定义了FooService如下
import {Injectable} from "@angular/core";
export interface Foo {
Foo(): string;
}
@Injectable()
export class FooService implements Foo {
Foo(): string {
return "Fooey!";
}
}
Run Code Online (Sandbox Code Playgroud)
和BarComponent这样
import {Component} from "@angular/core";
import {FooService} from "./foo.service";
@Component({
moduleId: 'module.id',
template: '<h1>Bar Component</h1>'
})
export class BarComponent {
constructor(private fooService: FooService) {}
doFoo(): string {
return(this.fooService.Foo());
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想测试我的BarComponent,我想TypeMoq用来模仿FooService,所以我做了以下
import * as TypeMoq from 'typemoq';
import {Foo, FooService} from "./foo.service";
import {TestBed, …Run Code Online (Sandbox Code Playgroud) 我通过扩展AsyncTask类来定义一个单独的线程.在这个类中,我在AsyncTask onPostExecute和onCancelled方法中执行一些Toasts和Dialog .祝酒词需要应用程序的上下文,所以我需要做的就是:
Toast.makeText(getApplicationContext(),"Some String",1);
Run Code Online (Sandbox Code Playgroud)
创建对话框时AlertDialog.Builder,还需要在其构造函数中使用上下文.我认为这个上下文应该是Activity的上下文吗?即
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
Run Code Online (Sandbox Code Playgroud)
where getActivity可以是返回当前活动的用户定义的类.如果是这样,处理这种情况的最佳方法是什么?创建一个类getActivity或将当前活动的上下文传递给AsyncTask的构造函数?
我想我正在尝试理解使用Context- 我注意到内存泄漏可能是一个问题(还没有真正理解这一点)以及如何使用getApplicationContext()是最好的方法.
android constructor inner-classes android-context android-asynctask
我正在使用TypeScript为我的angular 2应用程序编写服务.该服务使用chrome ServiceWorker来监听推送通知(请参阅教程).代码(javascript)navigator首先使用以查看是否serviceWorker支持,然后继续完成注册等,即,
if ('serviceWorker' in navigator) {
console.log('Service Worker is supported');
navigator.serviceWorker.register('sw.js').then(function() {
return navigator.serviceWorker.ready;
}).then(function(reg) {
console.log('Service Worker is ready :^)', reg);
// TODO
}).catch(function(error) {
console.log('Service Worker error :^(', error);
});
}
Run Code Online (Sandbox Code Playgroud)
我想使用TypeScript实现上述功能.但是,目前lib.d.ts所用的打字稿编译器(见下文)似乎对定义没有定义Navigator的serviceWorker或与其相关的方法,如serviceWorker.register(我猜的,因为它是一个特定的铬实现).
interface Navigator extends Object, NavigatorID, NavigatorOnLine, NavigatorContentUtils, NavigatorStorageUtils, NavigatorGeolocation, MSNavigatorDoNotTrack, MSFileSaver, NavigatorUserMedia {
readonly appCodeName: string;
readonly cookieEnabled: boolean;
readonly language: string;
readonly maxTouchPoints: number;
readonly mimeTypes: MimeTypeArray;
readonly …Run Code Online (Sandbox Code Playgroud) 我一直在学习Angular 2,并想知道什么是存储字符串的最佳实践.我在整个应用程序中使用各种字符串:有些字符串直接放在HTML元素中,例如,
// sample.html
<h1>This is my title</h1>
Run Code Online (Sandbox Code Playgroud)
其他字符串存储在绑定到的组件模型中,例如
// boundSample.html
<h1>{{myTitle}}</h1>
// boundSample.component.ts
import ...
@Component({
templateUrl: 'boundSample.html';
})
export class BoundSampleComponent {
myTitle = 'This is another title';
}
Run Code Online (Sandbox Code Playgroud)
我担心的是我的字符串遍布整个应用程序.来自C#/ WPF背景,我习惯将我的字符串保存在一个单独的位置(例如strings.xaml),我可以将其导入代码和UI标记(即用于WPF的XAML,用于Angular的HTML).这极大地有助于可维护性和国际化.
此外,快速浏览角度2的国际化建议使用i18n属性和i18n tool.这假设我的所有字符串都是用HTML定义的,但是如果我想在代码中使用其中的一些字符串呢?
如何以及在何处为Angular2中的字符串定义单个位置,以便我可以在代码中访问这些字符串并使用国际化工具?
我已经定义了一个接口和不透明令牌,如下所示
export let AUTH_SERVICE = new OpaqueToken('auth.service');
export interface AuthService {
logIn(): void;
logOut(): void;
}
Run Code Online (Sandbox Code Playgroud)
在我的测试类中,我提供了一个存根版本AuthService,即
@Injectable()
class AuthServiceStub implements AuthService {
logIn(): void {}
logOut(): void {}
}
Run Code Online (Sandbox Code Playgroud)
并按beforeEach如下方式设置我的测试
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LoginComponent ],
providers: [
{provide: AUTH_SERVICE, useValue: AuthServiceStub}
]
});
}));
Run Code Online (Sandbox Code Playgroud)
然后我开始编写测试,即
it('should call log in on AuthService', () => {
let authService = fixture.debugElement.injector.get(AUTH_SERVICE);
spyOn(authService, 'logIn');
// expect will go here
});
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误
Error: <spyOn> : logIn() method …Run Code Online (Sandbox Code Playgroud) 我正在尝试在ASP.Net Core中加载页面时运行异步任务,即,我希望任务在用户路由到页面后立即运行,但在任务完成之前显示页面.看来,使用ASP.Net核心,您可以使用中间件来执行此类任务.所以我试图添加以下内容Startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceProvider serviceProvider)
{
// Other configurations here
app.Use(async (context, next) =>
{
if (context.Request.Path.Value.Contains("PageWithAsyncTask"))
{
var serviceWithAsyncTask = serviceProvider.GetService<IMyService>();
await serviceWithAsyncTask .DoAsync();
}
await next.Invoke();
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
Run Code Online (Sandbox Code Playgroud)
上面的问题是页面加载有延迟,直到DoAsync完成,因为我们next.Invoke()直到DoAsync完成才调用.我怎样才能正确实现上面的内容,以便next.Invoke()在我DoAsync运行后立即调用?
angular ×4
android ×3
typescript ×3
jasmine ×2
javascript ×2
asp.net ×1
asp.net-core ×1
c# ×1
constructor ×1
html ×1
middleware ×1
npm ×1
sdk ×1
string ×1
unit-testing ×1