Example usage for android.view View setOnDragListener

List of usage examples for android.view View setOnDragListener

Introduction

In this page you can find the example usage for android.view View setOnDragListener.

Prototype

public void setOnDragListener(OnDragListener l) 

Source Link

Document

Register a drag event listener callback object for this View.

Usage

From source file:com.svpino.longhorn.artifacts.StockTileProcessor.java

@TargetApi(11)
private static void enableTileAsADropLocation(final Fragment fragment, View tile) {
    if (isHoneycombOrLater()) {
        tile.setOnDragListener(new OnDragListener() {

            @Override//  ww w  .  j a  v a 2s . c om
            public boolean onDrag(View view, DragEvent event) {
                return ((OnDragTileListener) fragment).onDrag(view, event);
            }
        });
    }
}

From source file:it.vibin.sideswipe.drag.SwipeMenuManager.java

/**
 * DropZone.Idle MUST be set (should be the lowest Z-axis view, which is as large as the screen).
 * /*  w w w.  j  ava 2 s .  co m*/
 * @param dropZone   {@link DropZone}
 * @param view      View
 */
public void setDropZone(DropZone dropZone, View view) {
    view.setOnDragListener(this);
    mDropZones.put(dropZone, view);
}

From source file:meizhi.meizhi.malin.utils.DestroyCleanUtil.java

@SuppressLint("ObsoleteSdkInt")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static void unBindView(View view) {
    if (view == null)
        return;//from  w w  w .ja  v a 2 s.  c om
    Drawable drawable;
    int i;
    //1.
    try {
        view.setOnClickListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //2.
    try {
        view.setOnCreateContextMenuListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //3.
    try {
        view.setOnFocusChangeListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //4.
    try {
        view.setOnKeyListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //5.
    try {
        view.setOnLongClickListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //6.
    try {
        view.setOnTouchListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //7.
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
            view.setOnApplyWindowInsetsListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //8.
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            view.setOnContextClickListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //9.
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            view.setOnScrollChangeListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //10.
    try {
        view.setOnDragListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //11.
    try {
        view.setOnGenericMotionListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //12.
    try {
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR2) {//13
            view.setOnHoverListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //13.
    try {
        view.setOnSystemUiVisibilityChangeListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    /**
     * @see SwipeRefreshLayout#onDetachedFromWindow()
     */
    if (view.getBackground() != null && !view.getClass().getName().equals(CIRCLE_CLASS)) {
        try {
            view.getBackground().setCallback(null);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {//16
                view.setBackgroundDrawable(null);
            } else {
                view.setBackground(null);
            }
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //ImageView
    if (view instanceof ImageView) {
        try {
            ImageView imageView = (ImageView) view;
            drawable = imageView.getDrawable();
            if (drawable != null) {
                drawable.setCallback(null);
            }
            imageView.setImageDrawable(null);
            imageView.setImageBitmap(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //TextView
    if (view instanceof TextView) {
        try {
            TextView textView = (TextView) view;
            textView.setCompoundDrawables(null, null, null, null);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                textView.setCompoundDrawablesRelative(null, null, null, null);
            }
            textView.setCursorVisible(false);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //ImageButton
    if (view instanceof ImageButton) {
        try {
            ImageButton imageButton = (ImageButton) view;
            drawable = imageButton.getDrawable();
            if (drawable != null) {
                drawable.setCallback(null);
            }
            imageButton.setImageDrawable(null);
            imageButton.setImageBitmap(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //ListView
    if (view instanceof ListView) {
        ListView listView = (ListView) view;

        try {
            listView.setAdapter(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnScrollListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnItemClickListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnItemLongClickListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnItemSelectedListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //RecyclerView
    if (view instanceof RecyclerView) {
        try {
            RecyclerView recyclerView = (RecyclerView) view;
            recyclerView.setAdapter(null);
            recyclerView.setChildDrawingOrderCallback(null);
            recyclerView.setOnScrollListener(null);
            recyclerView.addOnScrollListener(null);
            recyclerView.removeOnScrollListener(null);
            recyclerView.setRecyclerListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //WebView
    if (view instanceof WebView) {

        WebView webView = (WebView) view;
        try {
            webView.stopLoading();
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.removeAllViews();
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.setWebChromeClient(null);
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.setWebViewClient(null);
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.destroy();
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            if (null != view.getParent() && view.getParent() instanceof ViewGroup) {
                ((ViewGroup) view.getParent()).removeView(view);
            }
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

    }

    //SurfaceView
    if (view instanceof SurfaceView) {
        try {
            SurfaceView surfaceView = (SurfaceView) view;
            SurfaceHolder holder = surfaceView.getHolder();
            if (holder != null) {
                Surface surface = holder.getSurface();
                if (surface != null) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                        surface.release();
                    }
                }
            }
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }
    }

    view.destroyDrawingCache();
    view.clearAnimation();

    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        int childCount = (viewGroup).getChildCount();
        for (i = 0; i < childCount; i++) {
            unBindView((viewGroup).getChildAt(i));
        }
    }
}

From source file:rosmi.acagild.alarmclock.ringing.AlarmRingingFragment.java

@Nullable
@Override//  www.j a  va 2  s  .c o  m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    Logger.init(getActivity());
    Bundle args = getArguments();
    UUID alarmId = UUID.fromString(args.getString(ARGS_ALARM_ID));
    mAlarm = AlarmList.get(getContext()).getAlarm(alarmId);

    View view = inflater.inflate(R.layout.fragment_alarm_ringing, container, false);

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) {
        TextView timeField = (TextView) view.findViewById(R.id.alarm_ringing_time);
        timeField.setText(DateTimeUtilities.getUserTimeString(getContext(), mAlarm.getTimeHour(),
                mAlarm.getTimeMinute()));
    }

    TextView dateField = (TextView) view.findViewById(R.id.alarm_ringing_date);
    dateField.setText(DateTimeUtilities.getFullDateStringForNow());

    String name = mAlarm.getTitle();
    TextView titleField = (TextView) view.findViewById(R.id.alarm_ringing_title);
    titleField.setText(name);

    ImageView dismissButton = (ImageView) view.findViewById(R.id.alarm_ringing_dismiss);
    dismissButton.setOnDragListener(new View.OnDragListener() {
        @Override
        public boolean onDrag(View v, DragEvent event) {
            switch (event.getAction()) {
            case DragEvent.ACTION_DROP:
                dismissAlarm();
                break;
            case DragEvent.ACTION_DRAG_ENDED:
                if (mShowClockOnDragEnd) {
                    mAlarmRingingClock.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            mAlarmRingingClock.setVisibility(View.VISIBLE);
                        }
                    }, SHOW_CLOCK_AFTER_UNSUCCESSFUL_DRAG_DELAY);
                }
                break;
            default:
                break;
            }
            return true;
        }
    });

    // Dismiss ringing if someone presses the dismiss button directly
    dismissButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dismissAlarm();
        }
    });

    ImageView snoozeButton = (ImageView) view.findViewById(R.id.alarm_ringing_snooze);
    snoozeButton.setOnDragListener(new View.OnDragListener() {
        @Override
        public boolean onDrag(View v, DragEvent event) {
            switch (event.getAction()) {
            case DragEvent.ACTION_DROP:
                mCallback.onRingingSnooze();
                break;
            default:
                break;
            }
            return true;
        }
    });

    // Snooze ringing if someone presses the snooze button directly
    snoozeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mCallback.onRingingSnooze();
        }
    });

    // Allow the view to listen to the drag event to update arrow animations accordingly
    view.setOnDragListener(new View.OnDragListener() {
        @Override
        public boolean onDrag(View v, DragEvent event) {
            switch (event.getAction()) {
            case DragEvent.ACTION_DRAG_LOCATION:
                // Update the left/right arrow visibility based on the current drag location.
                onClockDragLocation(event.getX(), event.getY(), v.getWidth() / 2);
                break;
            case DragEvent.ACTION_DROP:
                // The user has dropped the drag, but it is dropped within the view, instead of the target
                // drop zones to dismiss or snooze.
                // Restore to show both left arrow and right arrow animations.
                mDragZone = DragZone.NEAR_MIDDLE_OF_VIEW;
                updateArrowsBasedOnDragZone(mDragZone);
                break;
            default:
                break;
            }
            return true;
        }
    });

    mAlarmRingingClock = (ImageView) view.findViewById(R.id.alarm_ringing_clock);
    mAlarmRingingClock.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                ClipData dragData = ClipData.newPlainText("", "");
                View.DragShadowBuilder shadow = new View.DragShadowBuilder(mAlarmRingingClock);
                mAlarmRingingClock.startDrag(dragData, shadow, null, 0);
                mAlarmRingingClock.setVisibility(View.INVISIBLE);
                return true;
            } else {
                return false;
            }

        }
    });

    initializeClockAnimation(view);

    Loggable.AppAction appAction = new Loggable.AppAction(Loggable.Key.APP_ALARM_RINGING);

    appAction.putJSON(mAlarm.toJSON());
    Logger.track(appAction);

    return view;
}

From source file:com.microsoft.mimickeralarm.ringing.AlarmRingingFragment.java

@Nullable
@Override/*from  ww w. j a  va2  s  .com*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    Logger.init(getActivity());
    Bundle args = getArguments();
    UUID alarmId = UUID.fromString(args.getString(ARGS_ALARM_ID));
    mAlarm = AlarmList.get(getContext()).getAlarm(alarmId);

    View view = inflater.inflate(R.layout.fragment_alarm_ringing, container, false);

    if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) {
        TextView timeField = (TextView) view.findViewById(R.id.alarm_ringing_time);
        timeField.setText(DateTimeUtilities.getUserTimeString(getContext(), mAlarm.getTimeHour(),
                mAlarm.getTimeMinute()));
    }

    TextView dateField = (TextView) view.findViewById(R.id.alarm_ringing_date);
    dateField.setText(DateTimeUtilities.getFullDateStringForNow());

    String name = mAlarm.getTitle();
    TextView titleField = (TextView) view.findViewById(R.id.alarm_ringing_title);
    titleField.setText(name);

    ImageView dismissButton = (ImageView) view.findViewById(R.id.alarm_ringing_dismiss);
    dismissButton.setOnDragListener(new View.OnDragListener() {
        @Override
        public boolean onDrag(View v, DragEvent event) {
            switch (event.getAction()) {
            case DragEvent.ACTION_DROP:
                dismissAlarm();
                break;
            case DragEvent.ACTION_DRAG_ENDED:
                if (mShowClockOnDragEnd) {
                    mAlarmRingingClock.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            mAlarmRingingClock.setVisibility(View.VISIBLE);
                        }
                    }, SHOW_CLOCK_AFTER_UNSUCCESSFUL_DRAG_DELAY);
                }
                break;
            default:
                break;
            }
            return true;
        }
    });

    // Dismiss ringing if someone presses the dismiss button directly
    dismissButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dismissAlarm();
        }
    });

    ImageView snoozeButton = (ImageView) view.findViewById(R.id.alarm_ringing_snooze);
    snoozeButton.setOnDragListener(new View.OnDragListener() {
        @Override
        public boolean onDrag(View v, DragEvent event) {
            switch (event.getAction()) {
            case DragEvent.ACTION_DROP:
                mCallback.onRingingSnooze();
                break;
            default:
                break;
            }
            return true;
        }
    });

    // Snooze ringing if someone presses the snooze button directly
    snoozeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mCallback.onRingingSnooze();
        }
    });

    // Allow the view to listen to the drag event to update arrow animations accordingly
    view.setOnDragListener(new View.OnDragListener() {
        @Override
        public boolean onDrag(View v, DragEvent event) {
            switch (event.getAction()) {
            case DragEvent.ACTION_DRAG_LOCATION:
                // Update the left/right arrow visibility based on the current drag location.
                onClockDragLocation(event.getX(), event.getY(), v.getWidth() / 2);
                break;
            case DragEvent.ACTION_DROP:
                // The user has dropped the drag, but it is dropped within the view, instead of the target
                // drop zones to dismiss or snooze.
                // Restore to show both left arrow and right arrow animations.
                mDragZone = DragZone.NEAR_MIDDLE_OF_VIEW;
                updateArrowsBasedOnDragZone(mDragZone);
                break;
            default:
                break;
            }
            return true;
        }
    });

    mAlarmRingingClock = (ImageView) view.findViewById(R.id.alarm_ringing_clock);
    mAlarmRingingClock.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                ClipData dragData = ClipData.newPlainText("", "");
                View.DragShadowBuilder shadow = new View.DragShadowBuilder(mAlarmRingingClock);
                mAlarmRingingClock.startDrag(dragData, shadow, null, 0);
                mAlarmRingingClock.setVisibility(View.INVISIBLE);
                return true;
            } else {
                return false;
            }

        }
    });

    initializeClockAnimation(view);

    Loggable.AppAction appAction = new Loggable.AppAction(Loggable.Key.APP_ALARM_RINGING);

    appAction.putJSON(mAlarm.toJSON());
    Logger.track(appAction);

    return view;
}