本文整理汇总了Java中android.support.v4.app.ShareCompat.IntentReader方法的典型用法代码示例。如果您正苦于以下问题:Java ShareCompat.IntentReader方法的具体用法?Java ShareCompat.IntentReader怎么用?Java ShareCompat.IntentReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.app.ShareCompat
的用法示例。
在下文中一共展示了ShareCompat.IntentReader方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCallingApplication
import android.support.v4.app.ShareCompat; //导入方法依赖的package包/类
@Nullable
private String getCallingApplication(ShareCompat.IntentReader intentReader) {
String callingPackage = intentReader.getCallingPackage();
if (TextUtils.isEmpty(callingPackage)) {
Uri referrer = ActivityCompat.getReferrer(this);
if (referrer != null) {
callingPackage = referrer.getHost();
}
}
CharSequence label = null;
if (!TextUtils.isEmpty(callingPackage)) {
PackageManager pm = getPackageManager();
try {
label = pm.getApplicationLabel(pm.getApplicationInfo(callingPackage, 0));
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Could not retrieve label for package " + callingPackage, e);
}
}
return label != null ? label.toString() : null;
}
示例2: handleShareIntent
import android.support.v4.app.ShareCompat; //导入方法依赖的package包/类
private void handleShareIntent(final ShareCompat.IntentReader reader) {
Analytics.event(Analytics.SHARE_VIA_ROBIRD);
if (reader.getStreamCount() > 0) {
final int count = reader.getStreamCount() > 4 ? 4 : reader.getStreamCount();
ComposeFragment
.share(new ArrayList<Uri>() {
{
for (int i = 0; i < count; ++i)
add(reader.getStream(i));
}
})
.show(getSupportFragmentManager(), ComposeFragment.TAG_SHARE);
} else {
final StringBuilder shareBuilder = new StringBuilder();
if (!TextUtils.isEmpty(reader.getSubject()))
shareBuilder.append(reader.getSubject()).append(" ");
shareBuilder.append(reader.getText());
ComposeFragment
.share(shareBuilder.toString())
.show(getSupportFragmentManager(), ComposeFragment.TAG_SHARE);
}
}
示例3: onCreate
import android.support.v4.app.ShareCompat; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
analytics.sendScreenView("AddToHomeScreen");
final ShareCompat.IntentReader reader = ShareCompat.IntentReader.from(this);
String foundUrl = Urls.extractUrlFrom(getIntent(), reader);
if (foundUrl != null) {
Intent intent = RedirectFixActivity.createIntent(this, foundUrl)
.putExtra(ResolverActivity.EXTRA_ADD_TO_HOME_SCREEN, true);
startActivity(intent);
} else {
Toast.makeText(this, R.string.error_invalid_url, Toast.LENGTH_SHORT).show();
}
finish();
}
示例4: extractTitle
import android.support.v4.app.ShareCompat; //导入方法依赖的package包/类
/**
* Method to extract the title from shared data
**/
private String extractTitle(ShareCompat.IntentReader reader) {
if (reader.getSubject() != null && !NetworkManager.isUrl(reader.getSubject())){
return reader.getSubject();
}
return "";
}
示例5: onCreate
import android.support.v4.app.ShareCompat; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
AndroidInjection.inject(this);
super.onCreate(savedInstanceState);
analytics.sendScreenView("ShareToOpenWith");
if (isFromDirectShare(getIntent())) {
analytics.sendEvent(
"Direct Share",
"Clicked",
"true"
);
}
final ShareCompat.IntentReader reader = ShareCompat.IntentReader.from(this);
String foundUrl = Urls.extractUrlFrom(getIntent(), reader);
if (foundUrl != null) {
String callerPackage = CallerPackageExtractor.from(this).extract();
Intent intent = RedirectFixActivity.createIntent(this, foundUrl)
.putExtra(ShareCompat.EXTRA_CALLING_PACKAGE, callerPackage);
startActivity(intent);
} else {
Toast.makeText(this, R.string.error_invalid_url, Toast.LENGTH_SHORT).show();
}
finish();
}
示例6: extractUrlFrom
import android.support.v4.app.ShareCompat; //导入方法依赖的package包/类
@Nullable
public static String extractUrlFrom(Intent intent, ShareCompat.IntentReader reader) {
CharSequence text = reader.getText();
if (text == null) {
text = getExtraSelectedText(intent);
}
return findFirstUrl(text);
}
示例7: onCreate
import android.support.v4.app.ShareCompat; //导入方法依赖的package包/类
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ShareCompat.IntentReader intentReader =
ShareCompat.IntentReader.from(this);
if (!intentReader.isShareIntent()) {
finish();
return;
}
String callingApplication = getCallingApplication(intentReader);
mStreamCount = intentReader.getStreamCount();
for (int index = 0; index < mStreamCount; index++) {
final Uri photoUri = intentReader.getStream(index);
ChosenPhoto chosenPhoto = new ChosenPhoto(photoUri);
final LiveData<Long> insertLiveData = GalleryDatabase.getInstance(this).chosenPhotoDao()
.insert(this, chosenPhoto, callingApplication);
insertLiveData.observeForever(new Observer<Long>() {
@Override
public void onChanged(@Nullable final Long id) {
insertLiveData.removeObserver(this);
if (id == null || id == 0L) {
Log.e(TAG, "Unable to insert chosen artwork for " + photoUri);
mFailureCount++;
} else {
mSuccessCount++;
}
updateCount();
}
});
}
}
示例8: onCreate
import android.support.v4.app.ShareCompat; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post_new_designer_news_story);
ButterKnife.bind(this);
if (!FabTransform.setup(this, bottomSheetContent)) {
MorphTransform.setup(this, bottomSheetContent,
ContextCompat.getColor(this, R.color.background_light), 0);
}
bottomSheet.registerCallback(new BottomSheet.Callbacks() {
@Override
public void onSheetDismissed() {
// After a drag dismiss, finish without the shared element return transition as
// it no longer makes sense. Let the launching window know it's a drag dismiss so
// that it can restore any UI used as an entering shared element
setResult(RESULT_DRAG_DISMISSED);
finish();
}
});
scrollContainer.setListener(new ObservableScrollView.OnScrollListener() {
@Override
public void onScrolled(int scrollY) {
if (scrollY != 0
&& sheetTitle.getTranslationZ() != appBarElevation) {
sheetTitle.animate()
.translationZ(appBarElevation)
.setStartDelay(0L)
.setDuration(80L)
.setInterpolator(AnimUtils.getFastOutSlowInInterpolator
(PostNewDesignerNewsStory.this))
.start();
} else if (scrollY == 0 && sheetTitle.getTranslationZ() == appBarElevation) {
sheetTitle.animate()
.translationZ(0f)
.setStartDelay(0L)
.setDuration(80L)
.setInterpolator(AnimUtils.getFastOutSlowInInterpolator
(PostNewDesignerNewsStory.this))
.start();
}
}
});
// check for share intent
if (isShareIntent()) {
ShareCompat.IntentReader intentReader = ShareCompat.IntentReader.from(this);
url.setText(intentReader.getText());
title.setText(intentReader.getSubject());
// when receiving a share there is no shared element transition so animate up the
// bottom sheet to establish the spatial model i.e. that it can be dismissed downward
overridePendingTransition(R.anim.post_story_enter, R.anim.fade_out_rapidly);
bottomSheetContent.getViewTreeObserver().addOnPreDrawListener(
new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
bottomSheetContent.getViewTreeObserver().removeOnPreDrawListener(this);
bottomSheetContent.setTranslationY(bottomSheetContent.getHeight());
bottomSheetContent.animate()
.translationY(0f)
.setStartDelay(120L)
.setDuration(240L)
.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator
(PostNewDesignerNewsStory.this));
return false;
}
});
}
}
示例9: onCreate
import android.support.v4.app.ShareCompat; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post_new_designer_news_story);
ButterKnife.bind(this);
if (!FabTransform.setup(this, bottomSheetContent)) {
MorphTransform.setup(this, bottomSheetContent,
ContextCompat.getColor(this, R.color.background_light), 0);
}
bottomSheet.registerCallback(new BottomSheet.Callbacks() {
@Override
public void onSheetDismissed() {
// After a drag dismiss, finish without the shared element return transition as
// it no longer makes sense. Let the launching window know it's a drag dismiss so
// that it can restore any UI used as an entering shared element
setResult(RESULT_DRAG_DISMISSED);
finish();
}
});
scrollContainer.setListener(new ObservableScrollView.OnScrollListener() {
@Override
public void onScrolled(int scrollY) {
if (scrollY != 0
&& sheetTitle.getTranslationZ() != appBarElevation) {
sheetTitle.animate()
.translationZ(appBarElevation)
.setStartDelay(0L)
.setDuration(80L)
.setInterpolator(AnimUtils.getFastOutSlowInInterpolator
(PostNewDesignerNewsStory.this))
.start();
} else if (scrollY == 0 && sheetTitle.getTranslationZ() == appBarElevation) {
sheetTitle.animate()
.translationZ(0f)
.setStartDelay(0L)
.setDuration(80L)
.setInterpolator(AnimUtils.getFastOutSlowInInterpolator
(PostNewDesignerNewsStory.this))
.start();
}
}
});
// check for share intent
if (isShareIntent()) {
ShareCompat.IntentReader intentReader = ShareCompat.IntentReader.from(this);
url.setText(intentReader.getText());
title.setText(intentReader.getSubject());
}
if (!hasSharedElementTransition()) {
// when launched from share or app shortcut there is no shared element transition so
// animate up the bottom sheet to establish the spatial model i.e. that it can be
// dismissed downward
overridePendingTransition(R.anim.post_story_enter, R.anim.post_story_exit);
bottomSheetContent.getViewTreeObserver().addOnPreDrawListener(
new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
bottomSheetContent.getViewTreeObserver().removeOnPreDrawListener(this);
bottomSheetContent.setTranslationY(bottomSheetContent.getHeight());
bottomSheetContent.animate()
.translationY(0f)
.setStartDelay(120L)
.setDuration(240L)
.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator
(PostNewDesignerNewsStory.this));
return false;
}
});
}
ShortcutHelper.reportPostUsed(this);
}
示例10: onCreate
import android.support.v4.app.ShareCompat; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post_new_designer_news_story);
ButterKnife.bind(this);
if (!FabTransform.setup(this, bottomSheetContent)) {
MorphTransform.setup(this, bottomSheetContent,
ContextCompat.getColor(this, R.color.background_light), 0);
}
bottomSheet.registerCallback(new BottomSheet.Callbacks() {
@Override
public void onSheetDismissed() {
// After a drag dismiss, finish without the shared element return transition as
// it no longer makes sense. Let the launching window know it's a drag dismiss so
// that it can restore any UI used as an entering shared element
setResult(RESULT_DRAG_DISMISSED);
finish();
}
});
scrollContainer.setListener(scrollY -> {
if (scrollY != 0
&& sheetTitle.getTranslationZ() != appBarElevation) {
sheetTitle.animate()
.translationZ(appBarElevation)
.setStartDelay(0L)
.setDuration(80L)
.setInterpolator(AnimUtils.getFastOutSlowInInterpolator
(PostNewDesignerNewsStory.this))
.start();
} else if (scrollY == 0 && sheetTitle.getTranslationZ() == appBarElevation) {
sheetTitle.animate()
.translationZ(0f)
.setStartDelay(0L)
.setDuration(80L)
.setInterpolator(AnimUtils.getFastOutSlowInInterpolator
(PostNewDesignerNewsStory.this))
.start();
}
});
// check for share intent
if (isShareIntent()) {
ShareCompat.IntentReader intentReader = ShareCompat.IntentReader.from(this);
url.setText(intentReader.getText());
title.setText(intentReader.getSubject());
}
if (!hasSharedElementTransition()) {
// when launched from share or app shortcut there is no shared element transition so
// animate up the bottom sheet to establish the spatial model i.e. that it can be
// dismissed downward
overridePendingTransition(R.anim.post_story_enter, R.anim.post_story_exit);
bottomSheetContent.getViewTreeObserver().addOnPreDrawListener(
new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
bottomSheetContent.getViewTreeObserver().removeOnPreDrawListener(this);
bottomSheetContent.setTranslationY(bottomSheetContent.getHeight());
bottomSheetContent.animate()
.translationY(0f)
.setStartDelay(120L)
.setDuration(240L)
.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator
(PostNewDesignerNewsStory.this));
return false;
}
});
}
ShortcutHelper.reportPostUsed(this);
}
示例11: onCreate
import android.support.v4.app.ShareCompat; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_add);
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
// Get the user preferences :
SharedPreferences pref = getSharedPreferences(getString(R.string.params), MODE_PRIVATE);
this.privateShare = pref.getBoolean(getString(R.string.p_default_private), true);
this.m_prefOpenDialog = pref.getBoolean(getString(R.string.p_show_share_dialog), true);
this.autoTitle = pref.getBoolean(getString(R.string.p_auto_title), true);
this.autoDescription = pref.getBoolean(getString(R.string.p_auto_description), false);
this.tweet = pref.getBoolean(getString(R.string.p_shaarli2twitter), false);
stopLoadingTitle = false;
stopLoadingDescription = false;
// Check if there is at least one account, if so launch the settings :
getAllAccounts();
if (this.allAccounts.isEmpty()) {
Intent intentLaunchSettings = new Intent(this, MainActivity.class);
startActivity(intentLaunchSettings);
} else if (Intent.ACTION_SEND.equals(action) && "text/plain".equals(type)) {
ShareCompat.IntentReader reader = ShareCompat.IntentReader.from(this);
String sharedUrl = reader.getText().toString();
String sharedUrlTrimmed = this.extractUrl(sharedUrl);
String defaultTitle = this.extractTitle(reader);
String defaultDescription = intent.getStringExtra("description") != null ? intent.getStringExtra("description") : "";
String defaultTags = intent.getStringExtra("tags") != null ? intent.getStringExtra("tags") : "";
if (!autoTitle){
defaultTitle = "";
}
if (!autoDescription){
defaultDescription = "";
}
// Show edit dialog if the users wants
if (m_prefOpenDialog) {
handleDialog(sharedUrlTrimmed, defaultTitle, defaultDescription, defaultTags);
} else {
if (autoTitle || autoDescription) {
loadAutoTitleAndDescription(sharedUrlTrimmed, defaultTitle, defaultDescription);
}
handleSendPost(sharedUrlTrimmed, defaultTitle, defaultDescription, defaultTags, privateShare, this.chosenAccount, this.tweet);
}
} else {
Toast.makeText(getApplicationContext(), R.string.add_not_handle, Toast.LENGTH_SHORT).show();
}
}