小编Pru*_*hvi的帖子

使用RecyclerView和CardView触摸反馈

我很想为我的开源库启用触摸反馈.

我创造了一个RecyclerView和一个CardView.该CardView包含不同的区域不同的onClick动作.现在,如果用户点击卡中的任何位置,我很乐意触发Ripple效果,但我无法实现此行为.

这是我的listitem,您也可以在GitHub上找到它:https://github.com/mikepenz/AboutLibraries/blob/master/library/src/main/res/layout/listitem_opensource.xml

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:background="@drawable/button_rect_normal"/>

<LinearLayout
    android:padding="6dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:gravity="center_vertical"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/libraryName"
            android:textColor="@color/title_openSource"
            android:textSize="@dimen/textSizeLarge_openSource"
            android:textStyle="normal"
            android:layout_width="0dp"
            android:layout_weight="5"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:maxLines="1"/>

        <TextView
            android:id="@+id/libraryCreator"
            android:textColor="@color/text_openSource"
            android:textStyle="normal"
            android:layout_width="0dp"
            android:layout_weight="2"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:gravity="right"
            android:maxLines="2"
            android:textSize="@dimen/textSizeSmall_openSource"/>
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1px"
        android:layout_marginTop="4dp"
        android:background="@color/dividerLight_openSource"/>

    <TextView
        android:id="@+id/libraryDescription"
        android:textSize="@dimen/textSizeSmall_openSource"
        android:textStyle="normal"
        android:textColor="@color/text_openSource"
        android:padding="8dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxLines="20">
    </TextView>

    <View
        android:id="@+id/libraryBottomDivider"
        android:layout_width="match_parent"
        android:layout_height="1px"
        android:layout_marginTop="4dp"
        android:background="@color/dividerLight_openSource"/>

    <LinearLayout
        android:id="@+id/libraryBottomContainer"
        android:gravity="center_vertical"
        android:paddingLeft="8dp"
        android:paddingTop="4dp"
        android:paddingRight="8dp" …
Run Code Online (Sandbox Code Playgroud)

android touch-feedback android-cardview rippledrawable android-recyclerview

67
推荐指数
7
解决办法
5万
查看次数

当应用在后台或未运行时,推送通知无法正常工作

我正在使用Firebase Cloud Messaging发送推送通知.

这是我的FirebaseMessageService:

public class FireBaseMessageService extends FirebaseMessagingService {


@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Log.e("TAG", "From: " + remoteMessage.getFrom());
    Log.e("TAG", "Notification Message Body: " + remoteMessage.getData().get("CardName")+"  :  "+remoteMessage.getData().get("CardCode"));
    sendNotification(remoteMessage.getNotification().getBody());
}


private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, StartActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher_final)
            .setContentTitle("Notification")
            .setContentText(messageBody)
            .setTicker("Test")
            .setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_SOUND)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(0 /* ID …
Run Code Online (Sandbox Code Playgroud)

service android push-notification android-notifications firebase-cloud-messaging

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

--main-dex-list中的类太多,超出了主要的dex容量

我正在尝试运行检测测试用例,但在dex转换时得到以下错误意外顶级异常:

com.android.dex.DexException: Too many classes in --main-dex-list, main dex capacity exceeded
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:494)
        at com.android.dx.command.dexer.Main.runMultiDex(Main.java:334)
        at com.android.dx.command.dexer.Main.run(Main.java:244)
        at com.android.dx.command.dexer.Main.main(Main.java:215)
        at com.android.dx.command.Main.main(Main.java:106)

:App:dexDebug FAILED
Run Code Online (Sandbox Code Playgroud)

如何在gradle中解决此问题?

dex android-gradle-plugin

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

如何编写一个简单的Java程序,找到两个数字之间最大的公约数?

这是一个问题:

"编写一个名为gcd的方法,它接受两个整数作为参数,并返回两个数字的最大公约数.两个整数a和b的最大公约数(GCD)是a和b两者的最大整数.任何数字和1的GCD是1,任何数字的GCD和0都是该数字.

计算两个数字的GCD的一种有效方法是使用Euclid算法,该算法表明以下内容:

GCD(A, B) = GCD(B, A % B) 
GCD(A, 0) = Absolute value of A"
Run Code Online (Sandbox Code Playgroud)

我真的很困惑如何解决这个问题.我只想提供一些提示和提示,告诉我到目前为止我在程序中做错了什么.(我必须放入扫描仪,这是我老师的要求.)不要给我一个完整的代码,因为我有点想自己解决这个问题.也许只是给我一个暗示我如何结合你在上面看到的这个公式.(如果你想知道为什么我输入== 0,那是因为我认为如果你有两个数字,比如0和90,他们的GCD会是0吗?)

此外,我的代码必须包括while循环......如果循环我会更喜欢...

提前致谢!:)

我目前的计划:

public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int a = console.nextInt();
        int b = console.nextInt();
        gcd (a, b);
    }

    public static void gcd(int a, int b) {
        System.out.print("Type in two numbers and I will print outs its Greatest Common Divisor: ");
        int gcdNum1 = console.nextInt();
        int gcdNum2 = console.nextInt();
        while (gcdNum1 == 0) { …
Run Code Online (Sandbox Code Playgroud)

java loops while-loop greatest-common-divisor

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

IntentService的Android ServiceTestCase

我目前正在为Android应用程序编写单元测试,并偶然发现了以下问题:

我用它ServiceTestCase来测试IntentService这样的:

@Override
public void setUp() throws Exception {
    super.setUp();      
}

public void testService()
{
    Intent intent = new Intent(getSystemContext(), MyIntentService.class);
    super.startService(intent);     
    assertNotNull(getService());        
}
Run Code Online (Sandbox Code Playgroud)

但是我注意到我IntentService的创建(意味着onCreate被调用),但我从未接到过调用onHandleIntent(Intent intent)

有人已经IntentServiceServiceTestCase课堂上测试了吗?

谢谢!

android servicetestcase

11
推荐指数
2
解决办法
5201
查看次数

由于'java.lang.NullPointerException'导致Instrumentation运行失败

我试图通过扩展测试类来为我的应用程序中的活动编写单元测试用例ActivityUnitTestCase.我可以提前成功运行测试用例,但现在我总是在运行时遇到异常.虽然我对处理非常熟悉,但我NullPointerExceptions无法弄清楚造成这种情况的问题.我找不到任何类似的问题,所以我发布了这个问题.

堆栈跟踪显示我的代码中此行有一个空对象引用

activity = startActivity(mIntent, null, null);
Run Code Online (Sandbox Code Playgroud)

但该startActivity方法应该得到我正在测试的活动的实例.我不确定为什么它会返回null.

这是堆栈跟踪.

java.lang.NullPointerException: Attempt to write to field 'android.os.IBinder android.app.ActivityThread.mLastIntendedActivityToken' on a null object reference
at android.app.Activity.performCreate(Activity.java:6372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.support.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:346)
at android.test.ActivityUnitTestCase.startActivity(ActivityUnitTestCase.java:158)
at com.abc.test.MainActivityTest.access$100(MainActivityTest.java:16)
at com.abc.test.MainActivityTest$1.run(MainActivityTest.java:34)
at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:1891)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6117)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

Test running failed: Instrumentation run failed due to 'java.lang.NullPointerException'
Run Code Online (Sandbox Code Playgroud)

这是Test类

public class MainActivityTest extends ActivityUnitTestCase<MainActivity>{

    private Intent mIntent;
    private MainActivity activity; …
Run Code Online (Sandbox Code Playgroud)

android nullpointerexception activityunittestcase android-instrumentation

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

什么是bigquery键盘快捷键?

谷歌的bigquery编辑器有键盘快捷键.例如,ctrl+ space组成一个新查询.我怀疑有更多的快捷方式,但我没有找到有用的列表.有谁知道吗?

google-bigquery

11
推荐指数
4
解决办法
9600
查看次数

如何在gradle中执行不在同一个包中的多个测试类?

我有以下测试类.

  1. com.baz.bar.Foo

  2. com.bar.foo.Baz

  3. com.foo.baz.Bar

我想执行com.baz.bar.Foocom.bar.foo.Baz.我知道如何执行所有这些以及如何执行其中一个.我不知道如何执行任何任意设置.

unit-testing gradle

10
推荐指数
2
解决办法
3864
查看次数

如何在android中为首选项添加涟漪效果?

我正在努力在触摸(选择)首选项时添加涟漪效果.我通过扩展来定制我的偏好ListPreference.我试图通过编程方式设置涟漪效果,RippleDrawable但我没有看到动画.

这是我的自定义偏好类

public class CustomListPreference extends ListPreference {

        public CustomListPreference(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        public CustomListPreference(Context context) {
            super(context);
        }

        @Override
        protected void onBindView(View view) {
            super.onBindView(view);
            setCustomStyle(view);
        }

        private void setCustomStyle(View view) {
            TextView titleView = (TextView) view.findViewById(android.R.id.title);
            titleView.setTypeface(InitActivity.TYPEFACE_REGULAR);
            TextView summary = (TextView) view.findViewById(android.R.id.summary);
            summary.setTypeface(InitActivity.TYPEFACE_REGULAR);

            //Setting the drawable here, but it doesn't work.        
            RippleDrawable drawable = (RippleDrawable) getContext().getResources().getDrawable(R.drawable.my_ripple_background);
            view.setBackGround(drawable);
        }

} 
Run Code Online (Sandbox Code Playgroud)

我的喜好布局

<?xml version="1.0" encoding="utf-8"?>

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- opens a subscreen of …
Run Code Online (Sandbox Code Playgroud)

android android-preferences listpreference rippledrawable

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

如何在切换视图时使UISearchController处于非活动状态

关于我们观点设定的一点背景:

在a里面NavigationController,我们有一个UITabBarController(带有3个标签),UIViewController其中有一个UISearchController.

有一个错误,如果我们离开UISearchController活动并切换到另一个视图,当我们返回到搜索视图时,整个屏幕都是黑色的.但是,当UISearchController它不活动并且我们切换视图时,这不会发生.

我们试图在控制视图之间设置控制器不活动; 然而,当UISearchController是segueing事件的活跃没有得到所谓的(没有日志打印从出现viewWillDissapear,viewWillAppear等等)

在其他线程上查看,我们尝试了设置,self.definesPresentationContext = true 但这不起作用.

有没有其他人有这个问题或知道如何解决它?

uitabbarcontroller uisearchbar ios swift uisearchcontroller

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