小编Gab*_*tin的帖子

应用材料时结果不良

我有一个带有两个简单对象(glutSolidCube和glutSolidTeapot)的openGL 3d场景.当我在启用GL_COLOR_MATERIAL的情况下设置灯光时,我得到以下结果:

在此输入图像描述

这很好.然后当我设置我自己的材料时:

//diffuse light color variables
GLfloat dlr = 0.4;
GLfloat dlg = 0.6;
GLfloat dlb = 0.9;

//ambient light color variables
GLfloat alr = 0.7;
GLfloat alg = 0.7;
GLfloat alb = 0.7;

//ambient light color variables
GLfloat slr = 0.4;
GLfloat slg = 0.4;
GLfloat slb = 0.4;


GLfloat DiffuseLight[]  = {dlr, dlg, dlb}; //set DiffuseLight[] to the specified values
GLfloat AmbientLight[]  = {alr, alg, alb}; //set AmbientLight[] to the specified values
GLfloat SpecularLight[] = {slr, slg, …
Run Code Online (Sandbox Code Playgroud)

opengl

4
推荐指数
1
解决办法
474
查看次数

GridView行高度表现不正常

我正在使用GridView,它显示带有背景图像和文本的线性布局,就像这个示例:

http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/

就像那个例子,我正在使用该代码使图像具有圆角.

问题是,如果我不使用圆角,我的所有网格项都是相同的高度,无论它们里面有什么文字,即使我的所有图像都是相同的大小.

但是如果我使用它,则将项目高度包装到内容中.

我尝试将我的线性布局定义为wrap_content,fill_parent,match_parent甚至是固定高度,但系统只是忽略了我.

这是我的网格布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFDDDDDD"
    android:orientation="vertical"
    tools:context=".RouteListActivity" >

    <GridView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/gridview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_margin="20dp"
        android:layout_weight="2"
        android:animateLayoutChanges="false"
        android:clipChildren="false"
        android:clipToPadding="false"
        android:drawSelectorOnTop="true"
        android:gravity="center"
        android:horizontalSpacing="10dp"
        android:numColumns="2"
        android:scrollingCache="false"
        android:stretchMode="columnWidth"
        android:verticalSpacing="10dp" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的网格项:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearlayoutGridLabel"
    android:layout_width="wrap_content"
    android:layout_height="150dp"
    android:layout_weight="1"
    android:gravity="bottom|left"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/id_ruta"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:visibility="gone" />

    <TextView
        android:id="@+id/routenameGridLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:background="#77000000"
        android:gravity="bottom"
        android:padding="5dp"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

加上适配器中的getView:

@Override
    public View getView(int position, View convertView, ViewGroup parent) { …
Run Code Online (Sandbox Code Playgroud)

android gridview

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

等待Dialog Fragment输入的活动

我创建了一个带有自定义AlertDialog的DialogFragment,我需要在我的应用程序的几个点上显示它.该对话框要求用户输入一些数据.

我想找到一种方法来调用对话框的活动,等待用户输入,然后在用户按下ok按钮时执行变量操作(如果按下取消,则不执行任何操作).

AFAIK在Android中没有"模态对话框",那么实现这种(通常的)行为的正确方法是什么?

android dialog

4
推荐指数
1
解决办法
2507
查看次数

记录用户在Spring MVC中的操作

我有一个用Spring MVC编写的非常大的应用程序.我想保留一个"活动记录",跟踪用户在我的应用程序中执行的操作.

在第一阶段我只想要一个活动日志,它可以只是在用户操作期间调用的控制器方法的列表,但稍后我希望这个信息更"人类可读",即代替"modifyAccount"( accountId = 5,accountBalance = 500)类似"用户X更新帐户5到500的余额".

我看到的问题是,由于我的应用程序非常大,我不想修改我的每个操作来添加此日志记录机制.是否有更灵活,声明性的方式来做到这一点?

spring spring-mvc

4
推荐指数
1
解决办法
3781
查看次数

Eclipse没有正确部署我的Web应用程序

我正在尝试使用Eclipse Kepler上的Maven创建一个基础Spring项目(安装了m2eclipse).Eclipse没有报告任何错误,但是当我点击Run on Server(或运行Maven Install)时,只部署了来自META-INF和WEB-INF文件的原始文件.这不包括我的dispatcher-servlet.xml配置文件,从而导致FileNotFoundException:

java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

这是我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/dispatcher-servlet.xml
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)

这是我项目文件夹的屏幕截图:

在此输入图像描述

如您所见,只有选定的文件显示在已部署的资源中.

eclipse spring spring-mvc maven

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

压缩室可流动防止更新

getPlaces我的存储库中有一个方法:

override fun getPlaces(filter: FilterRequest): Flowable<List<Place>> {
    return from(placesApi.filter(filter))
            .doOnSuccess {
                placesDao.savePlaces(it)
            }
            .flatMapPublisher { it ->
                placesDao.getPlaces(it.map { it.placeId })
            }
}
Run Code Online (Sandbox Code Playgroud)

此方法从api收集结果,然后将结果保存在数据库中,并返回一个带有flow的流,其中包含通过id从数据库中检索到的位置Flowable

@Query("select * from Places where placeId in (:placesIds)")
fun getPlaces(placesIds: List<String>) : Flowable<List<Place>>
Run Code Online (Sandbox Code Playgroud)

现在,每次我更改其中一个对象时,就可以在整个应用程序中看到所有更改。

现在,我想将这些结果与到当前位置的距离结合起来,如下所示:

 override fun addDistanceToPlaces(req: Flowable<List<Place>>): Flowable<List<Place>> {
        return req
                .zipWith(getLastLocation().toFlowable(BackpressureStrategy.LATEST),
                        BiFunction<List<Place>, Location, List<Place>> { places, location ->
                            places.forEach {
                                var placeLocation = Location(it.placeName)
                                placeLocation.latitude = it.latitude
                                placeLocation.longitude = it.longitude

                                it.distance = location.distanceTo(placeLocation)
                            }
                            places.sortedBy {
                                it.distance
                            }
                        })
                .onErrorResumeNext …
Run Code Online (Sandbox Code Playgroud)

android rx-java2 android-room

4
推荐指数
1
解决办法
275
查看次数

Maven 编译 UTF-8 和属性文件

我正在使用 maven 使用以下配置编译我的项目:

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
<plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <encoding>UTF-8</encoding>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                        <showDeprecation>true</showDeprecation>
                        <showWarnings>true</showWarnings>
                    </configuration>
                </plugin>
            </plugins>
Run Code Online (Sandbox Code Playgroud)

该项目应该是 UTF-8,但按照惯例 .properties 文件应该是 latin1 (ISO 8859-1) 并且 Eclipse 以这种方式对待它们(我知道我可以改变 Eclipse 的行为方式,但这不是重点)。我使用 .properties 文件进行国际化。

问题是,使用 Eclipse 部署到 Tomcat,我可以很好地看到我的特殊字符,但是当通过 maven(例如,通过 Jenkins)编译时,我得到了所有混乱的字符,就像 Maven 不知何故将我所有的 .properties 转换为 UTF -8,从而搞砸了我所有的 i18n 消息。

解决这个问题的正确方法是什么?感觉这应该是一个非常普遍的问题,但我还没有在网上找到有效的解决方案。

java eclipse utf-8 maven jenkins

3
推荐指数
1
解决办法
2295
查看次数

通过 Retrofit 使用响应标头作为返回对象的一部分

我正在使用 Retrofit + RxJava + GSON 来使用 REST API 进行搜索。API 的构建方式是,它返回对象列表和总结果作为响应 ( total-results) 中的标头:

@GET("search/events?eager=[competition,tv]")
    fun searchEvents(@Query("q") q: String, @Query("category") category: String, @Query("order") order: String): Single<List<Event>>
Run Code Online (Sandbox Code Playgroud)

我想返回 Single,其中 SearchResult 是:

SearchResult {
 var total: Int
var events: List<Event>
}
Run Code Online (Sandbox Code Playgroud)

这可能吗?

android gson rx-java retrofit rx-java2

3
推荐指数
1
解决办法
1972
查看次数

Windows中的时间戳(以毫秒为单位)

我需要及时测量两个单独的事件并比较它们(不在同一个应用程序中),所以我想知道同一个引用的时间戳(同一台机器上的不同应用程序).

在Windows系统上执行此操作的最简单方法是什么?我读过gettimeofday,但这似乎是一个特定于Unix的函数.

另外我不想使用boost或任何其他外部库(Windows库很好).

c++ windows

2
推荐指数
1
解决办法
9821
查看次数

无法将[JmsManagedConnectionFactoryImpl]类型的值转换为所需类型[javax.jms.ConnectionFactory]

我通过JNDI建立了一个JMSTemplate,如下所示:

<bean id="jmsTopicCancelacionTemplate" class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory" ref="connectionFactory" />
        <property name="defaultDestination" ref="cancelacionTopic" />
        <property name="messageConverter" ref="oxmMessageConverter" />
        <property name="destinationResolver" ref="jmsDestResolver" />
        <property name="pubSubDomain" value="true" />
    </bean>

 <!-- look up the JMS ConnectionFactory in JNDI -->
    <bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
            <value>java:comp/env/jms/ConnectionFactory</value>
        </property>
    </bean>

<bean id="requestQueue" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
            <value>java:comp/env/jms/SchedulingRequestQueue</value>
        </property>
    </bean>
Run Code Online (Sandbox Code Playgroud)

我的web.xml:

<resource-ref>
    <description>JMS Connection</description>
    <res-ref-name>jms/ConnectionFactory</res-ref-name>
    <res-type>javax.jms.ConnectionFactory</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试在我的Websphere中绑定JNDI资源时,在启动我的应用程序时出现以下错误:

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jms.core.JmsTemplate com.plexus.xesac_il.server.service.decide.DecideServiceImpl.jmsTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsTemplate' …
Run Code Online (Sandbox Code Playgroud)

java websphere spring jndi jms

2
推荐指数
1
解决办法
5650
查看次数

如何将字节块读入struct

我有这个资源文件,我需要处理,包含一组文件.

首先,资源文件列出了其中包含的所有文件,以及其他一些数据,例如在此结构中:

struct FileEntry{
     byte Value1;
     char Filename[12];
     byte Value2;
     byte FileOffset[3];
     float whatever;
}
Run Code Online (Sandbox Code Playgroud)

所以我需要读取这个大小的块.

我正在使用FileStream中的Read函数,但是如何指定struct的大小?我用了:

int sizeToRead = Marshal.SizeOf(typeof(Header));
Run Code Online (Sandbox Code Playgroud)

然后将此值传递给Read,但之后我只能读取一组byte [],我不知道如何转换为指定的值(我知道如何获取单字节值...但不是其余的).

另外我需要指定一个不安全的上下文,我不知道它是否正确......

在我看来,读取字节流比我在.NET中认为的更难:)

谢谢!

.net c# struct filestream

1
推荐指数
2
解决办法
9508
查看次数

null == object而不是object == null

我在一些地方看到过这种情况,人们正在使用

if(null == myInstance)
Run Code Online (Sandbox Code Playgroud)

代替

if(myInstance == null)
Run Code Online (Sandbox Code Playgroud)

前者只是风格问题还是在后者(更直观,在我看来)中有任何性能影响?

language-agnostic null

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

自定义视图上的可绘制标记向量无效

我创建了一个带有图像图标的自定义视图,并像这样初始化它:

XML

IconFieldLinearLayout.java

private void initAttr(Context context, AttributeSet attrs) {

        if (attrs != null) {
            TypedArray a = context.obtainStyledAttributes(attrs,
                    R.styleable.IconFieldLinearLayout, 0, 0);



            Drawable icon = a.getDrawable(R.styleable.IconFieldLinearLayout_icon);
            boolean tintIcon = a.getBoolean(R.styleable.IconFieldLinearLayout_tintIcon, true);
            int color = a.getColor(R.styleable.IconFieldLinearLayout_tintColor, Color.WHITE);

            a.recycle();
            initIcon(context, icon, tintIcon, color);
        } else {
            initIcon(context, mDefaultDrawable, true, Color.WHITE);
        }
    }
Run Code Online (Sandbox Code Playgroud)

当我使用这个 drawable 在 Android 4.3 上运行它时:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#ffff"
        android:pathData="M12,5.9c1.16,0 2.1,0.94 2.1,2.1s-0.94,2.1 -2.1,2.1S9.9,9.16 9.9,8s0.94,-2.1 2.1,-2.1m0,9c2.97,0 6.1,1.46 6.1,2.1v1.1L5.9,18.1L5.9,17c0,-0.64 3.13,-2.1 6.1,-2.1M12,4C9.79,4 8,5.79 8,8s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 …
Run Code Online (Sandbox Code Playgroud)

android android-vectordrawable

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