當前位置: 首頁>>代碼示例>>Java>>正文


Java ShareCompat.IntentReader方法代碼示例

本文整理匯總了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;
}
 
開發者ID:romannurik,項目名稱:muzei,代碼行數:21,代碼來源:GalleryAddPhotosActivity.java

示例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);
    }
}
 
開發者ID:mecid,項目名稱:robird-reborn,代碼行數:26,代碼來源:HomeActivity.java

示例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();
}
 
開發者ID:tasomaniac,項目名稱:OpenLinkWith,代碼行數:19,代碼來源:AddToHomeScreen.java

示例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 "";
}
 
開發者ID:dimtion,項目名稱:Shaarlier,代碼行數:11,代碼來源:AddActivity.java

示例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();
}
 
開發者ID:tasomaniac,項目名稱:OpenLinkWith,代碼行數:28,代碼來源:ShareToOpenWith.java

示例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);
}
 
開發者ID:tasomaniac,項目名稱:OpenLinkWith,代碼行數:9,代碼來源:Urls.java

示例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();
            }
        });
    }
}
 
開發者ID:romannurik,項目名稱:muzei,代碼行數:33,代碼來源:GalleryAddPhotosActivity.java

示例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;
            }
        });
    }
}
 
開發者ID:liulinbo,項目名稱:Amumu,代碼行數:72,代碼來源:PostNewDesignerNewsStory.java

示例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);
}
 
開發者ID:yongjhih,項目名稱:android-proguards,代碼行數:75,代碼來源:PostNewDesignerNewsStory.java

示例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);
}
 
開發者ID:nickbutcher,項目名稱:plaid,代碼行數:72,代碼來源:PostNewDesignerNewsStory.java

示例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();
    }
}
 
開發者ID:dimtion,項目名稱:Shaarlier,代碼行數:54,代碼來源:AddActivity.java


注:本文中的android.support.v4.app.ShareCompat.IntentReader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。