-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from tvbarthel/develop
Develop
- Loading branch information
Showing
23 changed files
with
534 additions
and
121 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
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
55 changes: 55 additions & 0 deletions
55
library/src/main/java/fr/tvbarthel/intentshare/LayoutManagerFactory.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,55 @@ | ||
package fr.tvbarthel.intentshare; | ||
|
||
import android.content.Context; | ||
import android.os.Build; | ||
import android.support.v7.widget.GridLayoutManager; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
|
||
/** | ||
* Factory used to handle layout manager according to the device android version seamlessly | ||
*/ | ||
final class LayoutManagerFactory { | ||
|
||
private static final int MARSHMALLOW_SPAN_COUNT = 4; | ||
|
||
/** | ||
* Non instantiable class. | ||
*/ | ||
private LayoutManagerFactory() { | ||
|
||
} | ||
|
||
/** | ||
* Build the layout manager for the {@link TargetActivity} list displayed to the user | ||
* during the target activity selection. | ||
* | ||
* @param context context used to instantiate layout manager. | ||
* @return layout manager matching the native look and feel linked to the device SDK version. | ||
*/ | ||
public static RecyclerView.LayoutManager buildLayoutManager(Context context) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, MARSHMALLOW_SPAN_COUNT); | ||
gridLayoutManager.setSpanSizeLookup(new MarshmallowSpanSizeLookup()); | ||
return gridLayoutManager; | ||
} else { | ||
return new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false); | ||
} | ||
} | ||
|
||
/** | ||
* SpanSizeLookup used to fit the native look and feel provided by | ||
* {@link android.content.Intent#createChooser(android.content.Intent, CharSequence)} | ||
*/ | ||
private static final class MarshmallowSpanSizeLookup extends GridLayoutManager.SpanSizeLookup { | ||
|
||
@Override | ||
public int getSpanSize(int position) { | ||
if (position == 0) { | ||
return MARSHMALLOW_SPAN_COUNT; // header taking the full width; | ||
} else { | ||
return 1; // target activity taking one unit; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.