forked from soarcn/BottomSheet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
soarcn#72 introduce a helper to create shareIntent picker
- Loading branch information
Showing
4 changed files
with
70 additions
and
32 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
63 changes: 63 additions & 0 deletions
63
library/src/main/java/com/cocosw/bottomsheet/BottomSheetHelper.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,63 @@ | ||
package com.cocosw.bottomsheet; | ||
|
||
import android.app.Activity; | ||
import android.content.ComponentName; | ||
import android.content.DialogInterface; | ||
import android.content.Intent; | ||
import android.content.pm.ActivityInfo; | ||
import android.content.pm.PackageManager; | ||
import android.content.pm.ResolveInfo; | ||
import android.support.annotation.NonNull; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* A helper class, | ||
* <p/> | ||
* Project: BottomSheet | ||
* Created by LiaoKai(soarcn) on 2015/7/18. | ||
*/ | ||
public class BottomSheetHelper { | ||
|
||
|
||
/** | ||
* Create a BottomSheet Builder for creating share intent chooser. | ||
* You still need to call show() to display it like: | ||
* <p/> | ||
* Intent sharingIntent = new Intent(Intent.ACTION_SEND); | ||
* shareIntent.setType("text/plain"); | ||
* shareIntent.putExtra(Intent.EXTRA_TEXT, "hello"); | ||
* BottomSheetHelper.shareAction(activity,sharingIntent).show(); | ||
* | ||
* @param activity Activity instance | ||
* @param intent shareIntent | ||
* @return BottomSheet builder | ||
*/ | ||
public static BottomSheet.Builder shareAction(@NonNull final Activity activity, @NonNull final Intent intent) { | ||
BottomSheet.Builder builder = new BottomSheet.Builder(activity).grid(); | ||
PackageManager pm = activity.getPackageManager(); | ||
|
||
final List<ResolveInfo> list = pm.queryIntentActivities(intent, 0); | ||
|
||
for (int i = 0; i < list.size(); i++) { | ||
builder.sheet(i, list.get(i).loadIcon(pm), list.get(i).loadLabel(pm)); | ||
} | ||
|
||
builder.listener(new DialogInterface.OnClickListener() { | ||
@Override | ||
public void onClick(@NonNull DialogInterface dialog, int which) { | ||
ActivityInfo activityInfo = list.get(which).activityInfo; | ||
ComponentName name = new ComponentName(activityInfo.applicationInfo.packageName, | ||
activityInfo.name); | ||
Intent newIntent = (Intent) intent.clone(); | ||
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | | ||
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); | ||
newIntent.setComponent(name); | ||
activity.startActivity(newIntent); | ||
} | ||
}); | ||
builder.limit(R.integer.bs_initial_grid_row); | ||
return builder; | ||
} | ||
|
||
} |
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