DragEventListener不工作在三星S7(6.0) [英] DragEventListener not working on Samsung S7 (6.0)

查看:226
本文介绍了DragEventListener不工作在三星S7(6.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找与这个方向一致的方向。我有一个卡片融合游戏( Five Kings ),其中已经升高了约6个月;我的最新版本0.9.22自3月份以来一直稳定。然而,最近我收到了用户无法将丢弃物拖放到丢弃堆的报告,而普通的线程似乎是使用Android 6.0的三星S7。当您从手中拖动卡片时,您可以拖动的位置变得透明,当您拖动卡片时,它们将恢复正常(alpha = 1)。其他地方你可以拖动似乎工作正常,但丢弃堆不会变暗或明亮,这使我认为拖动事件监听器不工作。



这是$ code> DiscardPileDragEventListener :

  class DiscardPileDragEventListener implements View.OnDragListener {

//这是系统调用拖动事件到
//监听器时调用的方法。
@Override
public boolean onDrag(final View v,final DragEvent event){
//如果不在播放的正确点,我们还没有准备好接受拖动
CardView cv =(CardView)v;

//定义一个变量来存储传入事件的操作类型
final int action = event.getAction();

//处理每个预期事件
switch(action){
case DragEvent.ACTION_DRAG_STARTED:
//确定此视图是否可以接受拖动的数据
if(cv.isAcceptDrag()&& event.getClipDescription()。hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)){
//淡出绘图桩
cv.startAnimation(实用程序) instantFade(FiveKings.HALF_TRANSPARENT_ALPHA,FiveKings.HALF_TRANSPARENT_ALPHA));
//返回true表示View可以接受拖动的数据。
返回true;
} else {
//提醒用户在前几轮中应该做什么
((FiveKings)cv.getContext())。setShowHint(null,FiveKings.HandleHint.SHOW_HINT ,FiveKings.GameDifficulty.EASY);
//返回false。在当前拖放操作期间,此视图将
//不会再次收到事件,直到发送ACTION_DRAG_ENDED。
返回false;
}

case DragEvent.ACTION_DRAG_ENTERED:
cv.clearAnimation();
返回true;

case DragEvent.ACTION_DRAG_LOCATION:
//忽略事件
return true;

case DragEvent.ACTION_DRAG_EXITED:
cv.startAnimation(Utilities.instantFade(FiveKings.HALF_TRANSPARENT_ALPHA,FiveKings.HALF_TRANSPARENT_ALPHA));
返回true;

case DragEvent.ACTION_DROP:
cv.clearAnimation();
//获取包含拖动数据的项
ClipData.Item item = event.getClipData()。getItemAt(0); //这是查看索引以恢复哪个卡

//从项目获取文本数据。
String dragData = item.getText()。toString();

//处理这里的异常,如果没有找到,返回false(没有处理)
int iView = -1;
try {
iView = Integer.parseInt(dragData);
} catch(NumberFormatException e){
return false;
}
return((FiveKings)cv.getContext())。abandonCard(iView);

case DragEvent.ACTION_DRAG_ENDED:
if(cv.isAcceptDrag())cv.clearAnimation();
返回true;

//收到一个未知的操作类型。
default:
Log.e(DiscardPileDragEventListener,OnDragListener收到的未知操作类型);
}

return false;
}
}

这里是设置实际拖动卡片的代码片段;在这个CardView是ImageView的一个子类:

 (卡片卡:meld){
//突出显示通配符,除非没有拖动(电脑转,或人的最后转)
CardView cv =新的CardView(这个,卡,iView,allowDragging?highlightWildCardRank:null);
cv.setTag(iView); //允许我们将索引传递给dragData而不处理通过
...
cv.bringToFront()的凌乱对象;
cv.setClickable(false); // TODO:B:允许选择,单击多拖动?
if(allowDragging){//最终转动后不拖动电脑卡或人卡
cv.setOnDragListener(new CardViewDragEventListener()); //需要每张卡将拖动的卡重置为正常的可见性(alpha)
cv.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View v,MotionEvent事件){
if(event.getAction()!= MotionEvent.ACTION_DOWN)return false;
//使用标签作为标签创建新的ClipData,纯文本MIME类型和
//包含View索引的字符串,这将在
// ClipData中创建一个新的ClipDescription对象,并将其MIME类型条目设置为text / plain
ClipData dragData = ClipData.newPlainText Discard,v.getTag()。toString());
View.DragShadowBuilder cardDragShadow = new CardViewDragShadowBuilder(v);

v.startAnimation(Utilities.instantFade Kings.HALF_TRANSPARENT_ALPHA,FiveKings.HALF_TRANSPARENT_ALPHA));
//开始拖动
v.startDrag(dragData,cardDragShadow,null,0);
返回true;
} // end onClick
});
} // end if allowDragging
...

而在onCreate ,我在DragListener上设置了Discard Pile:

  ... 
mDiscardPile.setOnDragListener(new DiscardPileDragEventListener());
...

一个皱纹是我在父视图中也有一个onDragListener的丢弃桩,当您将卡片拖到丢弃桩时提供消息。这在我的测试中工作得很好,但我只是想知道它是否与某种程度相关。



请欣赏关于朝哪个方向发展的任何建议。

解决方案

事实证明,三星为S7推出了称为游戏调谐器的功能,并将其反向移植到S6和其他设备。它会自动更改在市场上标记为游戏的所有已安装应用的分辨率。这对于图形驱动的游戏来说非常有用,但是完全可以通过拖放来完成像我这样的卡片游戏。注意,即使您没有进入游戏调谐器应用程序,也会发生这种情况。



所以,如果您在游戏或应用程序中体验到这一点,请问用户是否安装了游戏调谐器请求他们将分辨率设置为100%(他们可以在游戏中做到这一点)。



更新Mar2017:
我现在有99 %的解决方案。即使没有安装游戏调谐器,三星也会缩放游戏(显然为75%)。所以你需要安装游戏调谐器,然后将分辨率重置为100%,使拖放工作正常。



1%我没有是为什么他们会做这样的事情。


I'm looking for a direction to go with this one. I have a card melding game (Five Kings) which has been up for about 6 months; my latest version 0.9.22 has been stable since March. However, recently I have been getting reports of users unable to drag discards to the discard pile, and the common thread seems to be Samsung S7 with Android 6.0 . When you drag a card from your hand, the places you can drag turn transparent and when you drag over them they go back to normal (alpha=1). Other places you can drag seem to be working ok, but the discard pile doesn't go dim or bright, which makes me think the Drag Event listener isn't working.

Here's the DiscardPileDragEventListener:

class DiscardPileDragEventListener implements View.OnDragListener {

    // This is the method that the system calls when it dispatches a drag event to the
    // listener.
    @Override
    public boolean onDrag(final View v, final DragEvent event) {
        //that we are not ready to accept the drag if not at the right point of the play
        CardView cv = (CardView)v;

        // Defines a variable to store the action type for the incoming event
        final int action = event.getAction();

        // Handles each of the expected events
        switch(action) {
            case DragEvent.ACTION_DRAG_STARTED:
                // Determines if this View can accept the dragged data
                if (cv.isAcceptDrag() && event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
                    //fades out of the draw pile
                    cv.startAnimation(Utilities.instantFade(FiveKings.HALF_TRANSPARENT_ALPHA, FiveKings.HALF_TRANSPARENT_ALPHA));
                    // returns true to indicate that the View can accept the dragged data.
                    return true;
                } else {
                    //remind user what they should be doing if in the first few rounds
                    ((FiveKings) cv.getContext()).setShowHint(null, FiveKings.HandleHint.SHOW_HINT, FiveKings.GameDifficulty.EASY);
                    // Returns false. During the current drag and drop operation, this View will
                    // not receive events again until ACTION_DRAG_ENDED is sent.
                    return false;
                }

            case DragEvent.ACTION_DRAG_ENTERED:
                cv.clearAnimation();
                return true;

            case DragEvent.ACTION_DRAG_LOCATION:
                // Ignore the event
                return true;

            case DragEvent.ACTION_DRAG_EXITED:
                cv.startAnimation(Utilities.instantFade(FiveKings.HALF_TRANSPARENT_ALPHA, FiveKings.HALF_TRANSPARENT_ALPHA));
                return true;

            case DragEvent.ACTION_DROP:
                cv.clearAnimation();
                // Gets the item containing the dragged data
                ClipData.Item item = event.getClipData().getItemAt(0); //this is the View index to recover which card

                // Gets the text data from the item.
                String dragData = item.getText().toString();

                //Handle exception here and return false (drop wasn't handled) if it wasn't found
                int iView = -1;
                try {
                    iView = Integer.parseInt(dragData);
                }catch (NumberFormatException e) {
                    return false;
                }
                return ((FiveKings)cv.getContext()).discardedCard(iView);

            case DragEvent.ACTION_DRAG_ENDED:
                if (cv.isAcceptDrag()) cv.clearAnimation();
                return true;

            // An unknown action type was received.
            default:
                Log.e("DiscardPileDragEventListener", "Unknown action type received by OnDragListener.");
        }

        return false;
    }
}

Here's the code snippets which sets up the actual dragged card; in this CardView is a subclass of ImageView:

            for (Card card : meld) {
                //highlight wildcards unless no dragging (Computer turn, or Human final turn)
                CardView cv = new CardView(this, card, iView, allowDragging ? highlightWildCardRank : null);
                cv.setTag(iView); //allows us to pass the index into the dragData without dealing with messy object passing
...
                cv.bringToFront();
                cv.setClickable(false); //TODO:B: Allow selection by clicking for multi-drag?
                if (allowDragging) {//no dragging of computer cards or Human cards after final turn
                    cv.setOnDragListener(new CardViewDragEventListener()); //needed per-card to reset the dragged card to normal visibility (alpha)
                    cv.setOnTouchListener(new View.OnTouchListener() {
                        @Override
                        public boolean onTouch(View v, MotionEvent event) {
                            if (event.getAction() != MotionEvent.ACTION_DOWN) return false;
                            // Create a new ClipData using the tag as a label, the plain text MIME type, and
                            // the string containing the View index. This will create a new ClipDescription object within the
                            // ClipData, and set its MIME type entry to "text/plain"
                            ClipData dragData = ClipData.newPlainText("Discard", v.getTag().toString());
                            View.DragShadowBuilder cardDragShadow = new CardViewDragShadowBuilder(v);

                            v.startAnimation(Utilities.instantFade(FiveKings.HALF_TRANSPARENT_ALPHA, FiveKings.HALF_TRANSPARENT_ALPHA));
                            // Starts the drag
                            v.startDrag(dragData, cardDragShadow, null, 0);
                            return true;
                        }//end onClick
                    });
                }//end if allowDragging
...

And in the onCreate, I set up the Discard Pile onDragListener:

...
        mDiscardPile.setOnDragListener(new DiscardPileDragEventListener());
...

One wrinkle is that I also have a an onDragListener in the parent view of the Discard Pile, to provide a message as you drag your card to the Discard Pile. This has worked fine in my testing, but I just wonder if it's related somehow.

Would appreciate any suggestions as to which direction to head.

解决方案

It turns out that Samsung introduced a feature called Game Tuner for S7 and back-ported it to S6 and other devices. It automatically changes the Resolution Ratio for any installed app marked as a "Game" in the market. This works great for a graphics driven game, but completely screws up a card game like mine with Drag-and-drop. Note this happens even if you never go into the Game Tuner app.

So, if you experience this with your game or app, ask if the user has Game Tuner installed and ask them to set Resolution Ratio to 100% (they can do that on a game-by-game basis).

UPDATE Mar2017: I now have 99% of the solution. Even WITHOUT Game Tuner installed, Samsung scales a game (apparently to 75%). So you HAVE to install Game Tuner and then reset the Resolution to 100% to make drag-and-drop work properly.

The 1% I don't have is why they would do something stupid like this.

这篇关于DragEventListener不工作在三星S7(6.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆