小编ant*_*009的帖子

测试互联网连接的最快方法

C#2008 SP1

我使用此代码连接到我们的客户端网站.这适用于软电话应用程序.在用户拨打电话之前,软电话必须测试是否存在活动的Internet连接.

所以,希望我所做的是使用httpWebRequest类连接到我们的客户网站.如果响应正常,则可以继续进行Internet连接.

但是,我注意到响应的响应时间太长.我不确定这不是一种非常有效的测试方法.

但是,当我浏览他们的网站时,加载页面只需不到一秒钟.但是当我使用HttpWebRequest类时需要太长时间

所以对此的要求是:

有时会在客户办公室使用代理.我不能使用TCPClient类(没有代理属性).

代理不支持SOCKS,因此无法使用Sockets类.

我需要使用超时属性.所以不能使用WebClient类.这是因为软电话会冻结,直到返回响应.几秒钟后超时.

所以我唯一能想到的就是HttpWebRequest类.

  HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.xxxxxxxxx.com");
            request.Timeout = 5000;
            request.Credentials = CredentialCache.DefaultNetworkCredentials;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                Console.WriteLine("IsSIPServerAvailable: " + response.StatusCode);
                isAvailable = true;
            }
Run Code Online (Sandbox Code Playgroud)

========使用p\Invoke编辑====

 [DllImport("wininet.dll", CharSet = CharSet.Auto)]
    private extern static bool InternetGetConnectedState(ref InternetConnectionState_e lpdwFlags, int dwReserved);

 [Flags]
    enum InternetConnectionState_e : int
    {
        INTERNET_CONNECTION_MODEM = 0x1,
        INTERNET_CONNECTION_LAN = 0x2,
        INTERNET_CONNECTION_PROXY = 0x4,
        INTERNET_RAS_INSTALLED = 0x10,
        INTERNET_CONNECTION_OFFLINE = 0x20,
        INTERNET_CONNECTION_CONFIGURED = 0x40
    }

 // In function …
Run Code Online (Sandbox Code Playgroud)

c# networking

22
推荐指数
3
解决办法
4万
查看次数

这是为不同版本提供不同值/样式的正确方法

Android Studio 2.1 preview 3
Run Code Online (Sandbox Code Playgroud)

这只是一个问题,因为我很困惑,因为我已经看到了许多替代方案.

我创建了一个新的android项目,我的Activity扩展了AppCompatActivity

public class MainActivity extends AppCompatActivity {
Run Code Online (Sandbox Code Playgroud)

我希望transparent statusbar21台及以上的设备运行.

所以在我,values/styles我有以下

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

在我,values-21/styles我有以下

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

        <!-- Make the statusbar transparent -->
        <item name="android:windowTranslucentStatus">true</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

我的清单我选择了主题

android:theme="@style/AppTheme"
Run Code Online (Sandbox Code Playgroud)

只是一些问题

  1. 这是正确的方法,还是有更好的方法吗?
  2. values-21/styles继承所有的颜色,values/styles …

android

22
推荐指数
3
解决办法
1476
查看次数

C#2005:从表单的标题栏中删除图标

客户要求我从表单的标题栏中删除该图标.因为他们不想显示任何图标.但我猜测,当我点击图标属性时,你必须浏览到一些图标.

c# forms titlebar

21
推荐指数
2
解决办法
3万
查看次数

undefined C struct forward声明

我有一个头文件port.h,port.c和我的main.c

我收到以下错误:'ports'使用未定义的struct'port_t'

我想,因为我在.h文件中声明了结构,并且.c文件中的实际结构是可以的.

我需要有前向声明,因为我想在port.c文件中隐藏一些数据.

在我的port.h中,我有以下内容:

/* port.h */
struct port_t;
Run Code Online (Sandbox Code Playgroud)

port.c:

/* port.c */
#include "port.h"
struct port_t
{
    unsigned int port_id;
    char name;
};
Run Code Online (Sandbox Code Playgroud)

main.c中:

/* main.c */
#include <stdio.h>
#include "port.h"

int main(void)
{
struct port_t ports;

return 0;
}
Run Code Online (Sandbox Code Playgroud)

非常感谢任何建议,

c struct declaration forward

20
推荐指数
3
解决办法
4万
查看次数

合并到分支机构,无论你合并到哪一个?

git版本1.7.5.4

我有大约5个分支机构.全部来自同一个初始分支.

我想合并两个分支.比如,branch1和branch2.这些分支有很多不同之处.

我目前正在研究branch1,并且刚刚意识到我在branch2中实现了一些我希望在branch1中实现的更改.

合并的最佳方式是什么?

checkout branch2 and merge branch1
Run Code Online (Sandbox Code Playgroud)

要么

checkout branch1 and merge branch2
Run Code Online (Sandbox Code Playgroud)

或者,您需要签出哪个分支以与另一个分支合并?

git version-control

20
推荐指数
1
解决办法
3554
查看次数

使用片段共享转换时,返回转换无法正常工作

我有2个片段ListMovieFragmentDetailMovieFragment.

我有一个接口,在ListMovieFragment该实现MainActivity.我正在使用共享元素转换; 当我点击图像视图ListMovieFragmentonMovieSelected被称为中MainActivity.

ListMovieFragment作品过渡.
但是当我单击back按钮时,从DetailMovieFragmentListMovieFragment 转换到ListMovieFragment无法正常工作.

什么是错的gif

这是MainActivity.我想我有一个错误的组合来设置片段的转换.

public class MainActivity extends AppCompatActivity implements ListMovieFragment.MovieSelectedListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if(savedInstanceState == null) {
            ListMovieFragment listMovieFragment = new ListMovieFragment();

            FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
            fragmentTransaction.add(R.id.activity_main, listMovieFragment, ListMovieFragment.TAG);
            fragmentTransaction.commit();
        }
    }

    @Override
    public void onMovieSelected(int movieId) {
        DetailMovieFragment detailMovieFragment =
                (DetailMovieFragment)getSupportFragmentManager().findFragmentByTag(DetailMovieFragment.TAG);
        /* Create a new DetailMovieFragment if not exits …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-transitions fragment-transitions

20
推荐指数
1
解决办法
1243
查看次数

为宏__FUNCTION__和__func__定义#define的跨平台

使用gcc 4.4.2和WinXP Visual Studio C++ 2008进行编译

#if defined ( WIN32 )
#define __FUNCTION__ __func__
#endif
Run Code Online (Sandbox Code Playgroud)

因为我想使用宏来显示函数名称.我已经做了以上所以我可以跨平台,并在linux或windows上编译时使用相同的函数.

但是,当我在WinXP上编译时,我收到以下错误:

__func__ undeclared identifier
Run Code Online (Sandbox Code Playgroud)

我不能#define像这样的宏吗?

非常感谢任何建议,

c macros visual-studio

19
推荐指数
2
解决办法
2万
查看次数

org.apache.http.impl.io.DefaultHttpRequestWriterFactory中的NoSuchFieldError INSTANCE

java version "1.7.0_71" 
Gradle 2.1
Run Code Online (Sandbox Code Playgroud)

你好,

UPDATE:
Run Code Online (Sandbox Code Playgroud)

依赖关系

gradle dependencies | grep httpcore
|    +--- org.apache.httpcomponents:httpcore:4.3.3
|    +--- org.apache.httpcomponents:httpcore:4.3.3
|    +--- org.apache.httpcomponents:httpcore:4.3.3
|    +--- org.apache.httpcomponents:httpcore:4.3.3
|    |         |    |         |    +--- org.apache.httpcomponents:httpcore:4.1 -> 4.3.3
|    +--- org.apache.httpcomponents:httpcore:4.3.3
|    |         |    |         |    +--- org.apache.httpcomponents:httpcore:4.1 -> 4.3.3
Run Code Online (Sandbox Code Playgroud)

这是否意味着我有4.1这是4.3.3的软链接?看起来很奇怪,因为当我打印出类加载器正在加载它时似乎加载4.3.3:/home/steve/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.3.3/f91b7a4aadc5cf486df6e4634748d7dd7a73f06d/httpcore-4.3.3.jar看起来很奇怪.

当我尝试运行我的httpClient时,我不断收到此错误.一切都编好了.

java.lang.NoSuchFieldError: INSTANCE
        at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52
Run Code Online (Sandbox Code Playgroud)

我的代码非常简单,删除了不重要的代码来保持它的小:

public class GenieClient {
    private CloseableHttpClient mClient;

    public GenieClient() {
        ClassLoader classLoader = GenieClient.class.getClassLoader();
        URL resource = classLoader.getResource("org/apache/http/message/BasicLineFormatter.class");
        log.log(Level.INFO, "resource: " + resource);

        mClient = …
Run Code Online (Sandbox Code Playgroud)

java gradle apache-httpclient-4.x

19
推荐指数
3
解决办法
2万
查看次数

单击动画制作Fab(放大/缩小)

我试图模仿动画和下面的浮动动作按钮的颜色变化.

浮动操作按钮的工作方式是白色关闭,蓝色打开.

在此输入图像描述

但是,我没有成功完成动画和改变颜色.

这些都是我尝试这样做的,因为你可以看到我已经评论了我尝试过的所有不同方法.

这是我的代码:

    @SuppressWarnings("unused")
    @OnClick(R.id.fabMovieFavourite)
    public void addMovieFavourite(View view) {
 /*       final Animator animator = AnimatorInflater.loadAnimator(getActivity(), R.animator.add_favourite_movie);
        animator.setTarget(view);)
        animator.start();
 */
/*
        AnimatorSet animatorSet = new AnimatorSet();
        PropertyValuesHolder propertyValuesHolderX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1.1f);
        PropertyValuesHolder propertyValuesHolderY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1.1f);
        ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(view, propertyValuesHolderX, propertyValuesHolderY);
        objectAnimator.setDuration(300);
        objectAnimator.setInterpolator(new OvershootInterpolator(10f));
*/

        /*
        objectAnimator.setRepeatCount(1);
        objectAnimator.setRepeatMode(ObjectAnimator.REVERSE);
*/

/*
        PropertyValuesHolder propertyValuesHolderX2 = PropertyValuesHolder.ofFloat(View.SCALE_X, 0.9f);
        PropertyValuesHolder propertyValuesHolderY2 = PropertyValuesHolder.ofFloat(View.SCALE_Y, 0.9f);
        ObjectAnimator objectAnimator2 = ObjectAnimator.ofPropertyValuesHolder(view, propertyValuesHolderX2, propertyValuesHolderY2);
        objectAnimator.setDuration(300);
        objectAnimator2.setInterpolator(new OvershootInterpolator(10f));

        animatorSet.playSequentially(objectAnimator, objectAnimator2);
        objectAnimator.start();
*/

      //  view.BackgroundTintList(ContextCompat.getColorStateList(getContext(), R.color.primary));
        //view.setBackgroundColor(ContextCompat.getColor(getActivity(), …
Run Code Online (Sandbox Code Playgroud)

java animation android android-animation floating-action-button

19
推荐指数
1
解决办法
1474
查看次数

使用Spock和Robospock创建SQLite数据库的单元测试

spock-core:0.7-groovy-2.0
robospock:0.5.0
Android Studio 0.8.2
Fedora release 20 (Heisenbug)
Run Code Online (Sandbox Code Playgroud)

这是完整的解决方案.现在它成功编译并运行单元测试,目录结构与预览编辑相同.请随意评论任何看起来不正确的事情.

编辑解决方案=====

的build.gradle:

apply plugin: 'java'
apply plugin: 'groovy'

repositories {
    mavenCentral()

    maven {
        // Location of Android SDK for compiling otherwise get this error:
        /* Could not find com.android.support:support-v4:19.0.1.
           Required by:
           :testSQLite:unspecified > org.robospock:robospock:0.5.0 > org.robolectric:robolectric:2.3 */
        url "/home/steve/local/android-studio/sdk/extras/android/m2repository/"
    }
}

dependencies {
    // just compile so we can use the sqlite API
    compile 'com.google.android:android:4.1.1.4', {
        // Do not bring in dependencies
        transitive = false
    }

    testCompile 'org.codehaus.groovy:groovy:2.3.+'
    testCompile 'org.spockframework:spock-core:0.7-groovy-2.0' …
Run Code Online (Sandbox Code Playgroud)

java sqlite android unit-testing robospock

18
推荐指数
2
解决办法
2701
查看次数