Search in sources :

Example 1 with ShareDialog

use of com.facebook.share.widget.ShareDialog in project android-oss by kickstarter.

the class ThanksActivity method onCreate.

@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.thanks_layout);
    ButterKnife.bind(this);
    ((KSApplication) getApplication()).component().inject(this);
    shareDialog = new ShareDialog(this);
    final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    recommendedProjectsRecyclerView.setLayoutManager(layoutManager);
    adapter = new ThanksAdapter(viewModel);
    recommendedProjectsRecyclerView.setAdapter(adapter);
    Observable.timer(500L, TimeUnit.MILLISECONDS, Schedulers.newThread()).compose(ignoreValues()).compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> animateBackground());
    RxView.clicks(shareButton).compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> viewModel.inputs.shareClick());
    RxView.clicks(shareOnFacebookButton).compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> viewModel.inputs.shareOnFacebookClick());
    RxView.clicks(shareOnTwitterButton).compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> viewModel.inputs.shareOnTwitterClick());
    viewModel.outputs.projectName().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::showBackedProject);
    viewModel.outputs.showConfirmGamesNewsletterDialog().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> showConfirmGamesNewsletterDialog());
    viewModel.outputs.showGamesNewsletterDialog().compose(bindToLifecycle()).take(1).delay(700L, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> showGamesNewsletterDialog());
    viewModel.outputs.showRatingDialog().compose(bindToLifecycle()).take(1).delay(700L, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> showRatingDialog());
    viewModel.outputs.showRecommendations().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::showRecommendations);
    viewModel.outputs.startDiscovery().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startDiscovery);
    viewModel.outputs.startProject().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startProject);
    viewModel.outputs.startShare().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startShare);
    viewModel.outputs.startShareOnFacebook().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startShareOnFacebook);
    viewModel.outputs.startShareOnTwitter().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startShareOnTwitter);
}
Also used : ThanksAdapter(com.kickstarter.ui.adapters.ThanksAdapter) ShareDialog(com.facebook.share.widget.ShareDialog) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 2 with ShareDialog

use of com.facebook.share.widget.ShareDialog in project react-native-fbsdk by facebook.

the class FBShareDialogModule method canShow.

@ReactMethod
public void canShow(ReadableMap shareContent, Promise promise) {
    if (getCurrentActivity() != null) {
        ShareDialog shareDialog = new ShareDialog(getCurrentActivity());
        promise.resolve(mShareDialogMode == null ? shareDialog.canShow(Utility.buildShareContent(shareContent)) : shareDialog.canShow(Utility.buildShareContent(shareContent), mShareDialogMode));
    } else {
        promise.reject("No current activity.");
    }
}
Also used : ShareDialog(com.facebook.share.widget.ShareDialog) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 3 with ShareDialog

use of com.facebook.share.widget.ShareDialog in project facebook-android-sdk by facebook.

the class HelloFacebookSampleActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    callbackManager = CallbackManager.Factory.create();
    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            handlePendingAction();
            updateUI();
        }

        @Override
        public void onCancel() {
            if (pendingAction != PendingAction.NONE) {
                showAlert();
                pendingAction = PendingAction.NONE;
            }
            updateUI();
        }

        @Override
        public void onError(FacebookException exception) {
            if (pendingAction != PendingAction.NONE && exception instanceof FacebookAuthorizationException) {
                showAlert();
                pendingAction = PendingAction.NONE;
            }
            updateUI();
        }

        private void showAlert() {
            new AlertDialog.Builder(HelloFacebookSampleActivity.this).setTitle(R.string.cancelled).setMessage(R.string.permission_not_granted).setPositiveButton(R.string.ok, null).show();
        }
    });
    shareDialog = new ShareDialog(this);
    shareDialog.registerCallback(callbackManager, shareCallback);
    if (savedInstanceState != null) {
        String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
        pendingAction = PendingAction.valueOf(name);
    }
    setContentView(R.layout.main);
    profileTracker = new ProfileTracker() {

        @Override
        protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
            updateUI();
            // It's possible that we were waiting for Profile to be populated in order to
            // post a status update.
            handlePendingAction();
        }
    };
    profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture);
    greeting = (TextView) findViewById(R.id.greeting);
    postStatusUpdateButton = (Button) findViewById(R.id.postStatusUpdateButton);
    postStatusUpdateButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            onClickPostStatusUpdate();
        }
    });
    postPhotoButton = (Button) findViewById(R.id.postPhotoButton);
    postPhotoButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            onClickPostPhoto();
        }
    });
    // Can we present the share dialog for regular links?
    canPresentShareDialog = ShareDialog.canShow(ShareLinkContent.class);
    // Can we present the share dialog for photos?
    canPresentShareDialogWithPhotos = ShareDialog.canShow(SharePhotoContent.class);
}
Also used : AlertDialog(android.app.AlertDialog) ShareLinkContent(com.facebook.share.model.ShareLinkContent) SharePhotoContent(com.facebook.share.model.SharePhotoContent) ShareDialog(com.facebook.share.widget.ShareDialog) LoginResult(com.facebook.login.LoginResult) View(android.view.View) ProfilePictureView(com.facebook.login.widget.ProfilePictureView) TextView(android.widget.TextView) Profile(com.facebook.Profile) FacebookException(com.facebook.FacebookException)

Example 4 with ShareDialog

use of com.facebook.share.widget.ShareDialog in project facebook-android-sdk by facebook.

the class RpsFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        wins = savedInstanceState.getInt(WIN_KEY);
        losses = savedInstanceState.getInt(LOSS_KEY);
        ties = savedInstanceState.getInt(TIE_KEY);
        computerChoice = savedInstanceState.getInt(COMPUTER_CHOICE_KEY);
        playerChoice = savedInstanceState.getInt(PLAYER_CHOICE_KEY);
        currentState = (RpsState) savedInstanceState.getSerializable(STATE_KEY);
        result = (RpsResult) savedInstanceState.getSerializable(RESULT_KEY);
        pendingPublish = savedInstanceState.getBoolean(PENDING_PUBLISH_KEY);
        shouldImplicitlyPublish = savedInstanceState.getBoolean(IMPLICIT_PUBLISH_KEY);
    }
    callbackManager = CallbackManager.Factory.create();
    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            AccessToken accessToken = AccessToken.getCurrentAccessToken();
            if (accessToken.getPermissions().contains(ADDITIONAL_PERMISSIONS)) {
                publishResult();
            } else {
                handleError();
            }
        }

        @Override
        public void onCancel() {
            handleError();
        }

        @Override
        public void onError(FacebookException exception) {
            handleError();
        }

        private void handleError() {
            // this means the user did not grant us write permissions, so
            // we don't do implicit publishes
            shouldImplicitlyPublish = false;
            pendingPublish = false;
        }
    });
    FacebookCallback<Sharer.Result> callback = new FacebookCallback<Sharer.Result>() {

        @Override
        public void onCancel() {
            Log.d(TAG, "Canceled");
        }

        @Override
        public void onError(FacebookException error) {
            Log.d(TAG, String.format("Error: %s", error.toString()));
        }

        @Override
        public void onSuccess(Sharer.Result result) {
            Log.d(TAG, "Success!");
        }
    };
    shareDialog = new ShareDialog(this);
    shareDialog.registerCallback(callbackManager, callback);
    messageDialog = new MessageDialog(this);
    messageDialog.registerCallback(callbackManager, callback);
    FacebookCallback<AppInviteDialog.Result> appInviteCallback = new FacebookCallback<AppInviteDialog.Result>() {

        @Override
        public void onSuccess(AppInviteDialog.Result result) {
            Log.d(TAG, "Success!");
        }

        @Override
        public void onCancel() {
            Log.d(TAG, "Canceled");
        }

        @Override
        public void onError(FacebookException error) {
            Log.d(TAG, String.format("Error: %s", error.toString()));
        }
    };
    appInviteDialog = new AppInviteDialog(this);
    appInviteDialog.registerCallback(callbackManager, appInviteCallback);
    // Initialize in-app billing service
    serviceConnection = new ServiceConnection() {

        @Override
        public void onServiceDisconnected(ComponentName name) {
            inAppBillingService = null;
            Utility.logd(TAG, "In-app billing service disconnected");
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            inAppBillingService = IInAppBillingService.Stub.asInterface(service);
            Utility.logd(TAG, "In app billing service connected");
            try {
                Bundle ownedItems = inAppBillingService.getPurchases(IN_APP_PURCHASE_VERSION, context.getPackageName(), "inapp", null);
                int response = ownedItems.getInt("RESPONSE_CODE");
                if (response == 0) {
                    ArrayList<String> ownedSkus = ownedItems.getStringArrayList(INAPP_PURCHASE_ITEM_LIST);
                    ArrayList<String> purchaseDataList = ownedItems.getStringArrayList(INAPP_PURCHASE_DATA_LIST);
                    ArrayList<String> signatureList = ownedItems.getStringArrayList(INAPP_DATA_SIGNATURE_LIST);
                    for (int i = 0; i < purchaseDataList.size(); ++i) {
                        String purchaseData = purchaseDataList.get(i);
                        try {
                            JSONObject jo = new JSONObject(purchaseData);
                            String token = jo.getString("purchaseToken");
                            consumePurchase(context.getPackageName(), token);
                        } catch (JSONException e) {
                            Log.e(TAG, "Error parsing purchase data.", e);
                        }
                    }
                }
            } catch (RemoteException e) {
                Log.e(TAG, "Consuming purchase remote exception.", e);
            }
        }
    };
    context = this.getActivity().getApplicationContext();
    Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");
    context.bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
}
Also used : ServiceConnection(android.content.ServiceConnection) ShareDialog(com.facebook.share.widget.ShareDialog) Bundle(android.os.Bundle) LoginResult(com.facebook.login.LoginResult) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) LoginResult(com.facebook.login.LoginResult) IBinder(android.os.IBinder) AppInviteDialog(com.facebook.share.widget.AppInviteDialog) JSONObject(org.json.JSONObject) AccessToken(com.facebook.AccessToken) FacebookException(com.facebook.FacebookException) Sharer(com.facebook.share.Sharer) ComponentName(android.content.ComponentName) MessageDialog(com.facebook.share.widget.MessageDialog) RemoteException(android.os.RemoteException)

Example 5 with ShareDialog

use of com.facebook.share.widget.ShareDialog in project react-native-fbsdk by facebook.

the class FBShareDialogModule method show.

@ReactMethod
public void show(ReadableMap shareContent, final Promise promise) {
    if (getCurrentActivity() != null) {
        ShareDialog shareDialog = new ShareDialog(getCurrentActivity());
        shareDialog.registerCallback(getCallbackManager(), new ShareDialogCallback(promise));
        shareDialog.setShouldFailOnDataError(mShouldFailOnError);
        if (mShareDialogMode != null) {
            shareDialog.show(Utility.buildShareContent(shareContent), mShareDialogMode);
        } else {
            shareDialog.show(Utility.buildShareContent(shareContent));
        }
    } else {
        promise.reject("No current activity.");
    }
}
Also used : ShareDialog(com.facebook.share.widget.ShareDialog) ReactMethod(com.facebook.react.bridge.ReactMethod)

Aggregations

ShareDialog (com.facebook.share.widget.ShareDialog)5 FacebookException (com.facebook.FacebookException)2 LoginResult (com.facebook.login.LoginResult)2 ReactMethod (com.facebook.react.bridge.ReactMethod)2 AlertDialog (android.app.AlertDialog)1 PendingIntent (android.app.PendingIntent)1 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 ServiceConnection (android.content.ServiceConnection)1 Bundle (android.os.Bundle)1 IBinder (android.os.IBinder)1 RemoteException (android.os.RemoteException)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 View (android.view.View)1 TextView (android.widget.TextView)1 AccessToken (com.facebook.AccessToken)1 Profile (com.facebook.Profile)1 ProfilePictureView (com.facebook.login.widget.ProfilePictureView)1 Sharer (com.facebook.share.Sharer)1 ShareLinkContent (com.facebook.share.model.ShareLinkContent)1