Android Open Source - droidling Shareable Card






From Project

Back to project page droidling.

License

The source code is released under:

Copyright (c) 2012 Keith Trnka Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Softwa...

If you think the Android project droidling listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.github.ktrnka.droidling;
/*from  w  w  w .j av  a  2s  . c o  m*/
import java.lang.ref.WeakReference;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.fima.cardsui.objects.RecyclableCard;

/**
 * Card with title, description, and share button.
 */
public class ShareableCard extends RecyclableCard {
    private View.OnClickListener shareListener;

    /**
     * Trying to avoid circular reference between the Activity to the share
     * button listener
     */
    private WeakReference<Context> weakContext;

    public ShareableCard(String title) {
        super(title);
    }

    public ShareableCard(String title, String text) {
        super(title, text, 0);
    }

    /**
     * @param title
     * @param text
     * @param applicationName
     * @param context Context used to start the share intent
     */
    public ShareableCard(String title, String text, CharSequence applicationName, Context context) {
        this(title, text);

        weakContext = new WeakReference<Context>(context);

        shareListener = new ShareListener("Shared stats from " + applicationName, "Stats: " + title
                + ":\n" + text);
    }

    @Override
    protected int getCardLayoutId() {
        return R.layout.card_shareable;
    }

    @Override
    protected void applyTo(View view) {
        ((TextView) view.findViewById(R.id.title)).setText(title);
        ((TextView) view.findViewById(R.id.body)).setText(desc);

        if (shareListener != null) {
            ImageView shareButton = (ImageView) view.findViewById(R.id.share);
            shareButton.setOnClickListener(shareListener);
        }
    }

    private class ShareListener implements View.OnClickListener {
        private String subject;
        private String body;
        private static final String chooserText = "Share with...";

        ShareListener(String subject, String body) {
            this.subject = subject;
            this.body = body;
        }

        public void onClick(View view) {
            Context context = weakContext.get();
            if (context == null)
                return;

            Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.setType("text/plain");
            sendIntent.putExtra(Intent.EXTRA_TEXT, body);
            sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);

            context.startActivity(Intent.createChooser(sendIntent, chooserText));
        }
    }

}




Java Source Code List

com.github.ktrnka.droidling.AboutActivity.java
com.github.ktrnka.droidling.AboutInterpersonalActivity.java
com.github.ktrnka.droidling.AboutLangIDActivity.java
com.github.ktrnka.droidling.AboutPersonalActivity.java
com.github.ktrnka.droidling.CorpusStats.java
com.github.ktrnka.droidling.DateDistribution.java
com.github.ktrnka.droidling.DiagnosticActivity.java
com.github.ktrnka.droidling.ExtendedApplication.java
com.github.ktrnka.droidling.GraphCard.java
com.github.ktrnka.droidling.ImageAdapter.java
com.github.ktrnka.droidling.InterpersonalActivity.java
com.github.ktrnka.droidling.InterpersonalCard.java
com.github.ktrnka.droidling.InterpersonalSingleStats.java
com.github.ktrnka.droidling.InterpersonalStats.java
com.github.ktrnka.droidling.LIDStats.java
com.github.ktrnka.droidling.LanguageIdentificationActivity.java
com.github.ktrnka.droidling.LanguageIdentifier.java
com.github.ktrnka.droidling.MainActivity.java
com.github.ktrnka.droidling.PersonalActivity.java
com.github.ktrnka.droidling.PersonalStats.java
com.github.ktrnka.droidling.RefreshableActivity.java
com.github.ktrnka.droidling.ShareableCard.java
com.github.ktrnka.droidling.Sms.java
com.github.ktrnka.droidling.Tokenizer.java
com.github.ktrnka.droidling.WordDistribution.java
com.github.ktrnka.droidling.helpers.AsyncDrawable.java
com.github.ktrnka.droidling.helpers.BitmapLoaderTask.java
com.github.ktrnka.droidling.helpers.Util.java