List of usage examples for android.widget ImageView setOnDragListener
public void setOnDragListener(OnDragListener l)
From source file:com.example.android.dragsource.DragSourceFragment.java
@Nullable @Override//from ww w . j av a2 s.c o m public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_dragsource, null); // Set up two image views for global drag and drop with a permission grant. Uri imageUri = getFileUri(R.drawable.image1, "image1.png"); ImageView imageView = (ImageView) view.findViewById(R.id.image_one); setUpDraggableImage(imageView, imageUri); imageView.setImageURI(imageUri); imageUri = getFileUri(R.drawable.image2, "image2.png"); imageView = (ImageView) view.findViewById(R.id.image_two); setUpDraggableImage(imageView, imageUri); imageView.setImageURI(imageUri); // Set up the local drop target area. final ImageView localImageTarget = (ImageView) view.findViewById(R.id.local_target); localImageTarget.setOnDragListener(new ImageDragListener() { @Override protected boolean setImageUri(View view, DragEvent event, Uri uri) { mLocalImageUri = uri; Log.d(TAG, "Setting local image to: " + uri); return super.setImageUri(view, event, uri); } }); if (savedInstanceState != null) { final String uriString = savedInstanceState.getString(IMAGE_URI); if (uriString != null) { mLocalImageUri = Uri.parse(uriString); Log.d(TAG, "Restoring local image to: " + mLocalImageUri); localImageTarget.setImageURI(mLocalImageUri); } } return view; }
From source file:com.example.android.droptarget.DropTargetFragment.java
@Nullable @Override/*from w w w .j a va 2 s .c om*/ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_droptarget, container, false); final ImageView imageView = (ImageView) rootView.findViewById(R.id.image_target); ImageDragListener imageDragListener = new PermissionAwareImageDragListener(); imageView.setOnDragListener(imageDragListener); // Restore the application state if an image was being displayed. if (savedInstanceState != null) { final String uriString = savedInstanceState.getString(IMAGE_URI); if (uriString != null) { mImageUri = Uri.parse(uriString); imageView.setImageURI(mImageUri); } } mReleasePermissionCheckBox = (CheckBox) rootView.findViewById(R.id.release_checkbox); return rootView; }
From source file:rosmi.acagild.alarmclock.ringing.AlarmRingingFragment.java
@Nullable @Override//from w w w . ja 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 .jav a 2 s. c om*/ 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; }