-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
277 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/src/main/java/co/paulburke/android/itemtouchhelperdemo/MainFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (C) 2015 Paul Burke | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package co.paulburke.android.itemtouchhelperdemo; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.support.v4.app.ListFragment; | ||
import android.view.View; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.ListView; | ||
|
||
/** | ||
* @author Paul Burke (ipaulpro) | ||
*/ | ||
public class MainFragment extends ListFragment { | ||
|
||
public interface OnListItemClickListener { | ||
void onListItemClick(int position); | ||
} | ||
|
||
private OnListItemClickListener mItemClickListener; | ||
|
||
public MainFragment() { | ||
} | ||
|
||
@Override | ||
public void onAttach(Activity activity) { | ||
super.onAttach(activity); | ||
|
||
mItemClickListener = (OnListItemClickListener) activity; | ||
} | ||
|
||
@Override | ||
public void onActivityCreated(Bundle savedInstanceState) { | ||
super.onActivityCreated(savedInstanceState); | ||
|
||
final String[] items = getResources().getStringArray(R.array.main_items); | ||
final ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), | ||
android.R.layout.simple_list_item_1, items); | ||
setListAdapter(adapter); | ||
} | ||
|
||
@Override | ||
public void onListItemClick(ListView l, View v, int position, long id) { | ||
mItemClickListener.onListItemClick(position); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
app/src/main/java/co/paulburke/android/itemtouchhelperdemo/RecyclerGridFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (C) 2015 Paul Burke | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package co.paulburke.android.itemtouchhelperdemo; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v7.widget.GridLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.support.v7.widget.helper.ItemTouchHelper; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import co.paulburke.android.itemtouchhelperdemo.helper.OnStartDragListener; | ||
import co.paulburke.android.itemtouchhelperdemo.helper.SimpleItemTouchHelperCallback; | ||
|
||
/** | ||
* @author Paul Burke (ipaulpro) | ||
*/ | ||
public class RecyclerGridFragment extends Fragment implements OnStartDragListener { | ||
|
||
private ItemTouchHelper mItemTouchHelper; | ||
|
||
public RecyclerGridFragment() { | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
return new RecyclerView(container.getContext()); | ||
} | ||
|
||
@Override | ||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
super.onViewCreated(view, savedInstanceState); | ||
|
||
final RecyclerListAdapter adapter = new RecyclerListAdapter(getActivity(), this); | ||
|
||
RecyclerView recyclerView = (RecyclerView) view; | ||
recyclerView.setHasFixedSize(true); | ||
recyclerView.setAdapter(adapter); | ||
|
||
final int spanCount = getResources().getInteger(R.integer.grid_columns); | ||
final GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), spanCount); | ||
recyclerView.setLayoutManager(layoutManager); | ||
|
||
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(adapter); | ||
mItemTouchHelper = new ItemTouchHelper(callback); | ||
mItemTouchHelper.attachToRecyclerView(recyclerView); | ||
} | ||
|
||
@Override | ||
public void onStartDrag(RecyclerView.ViewHolder viewHolder) { | ||
mItemTouchHelper.startDrag(viewHolder); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/src/main/java/co/paulburke/android/itemtouchhelperdemo/helper/OnStartDragListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (C) 2015 Paul Burke | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package co.paulburke.android.itemtouchhelperdemo.helper; | ||
|
||
import android.support.v7.widget.RecyclerView; | ||
|
||
/** | ||
* Listener for manual initiation of a drag. | ||
*/ | ||
public interface OnStartDragListener { | ||
|
||
/** | ||
* Called when a view is requesting a start of a drag. | ||
* | ||
* @param viewHolder The holder of the view to drag. | ||
*/ | ||
void onStartDrag(RecyclerView.ViewHolder viewHolder); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.