<commit_before>package com.wisape.android.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Message;
import android.support.v7.widget.AppCompatEditText;

import com.facebook.drawee.view.SimpleDraweeView;
import com.wisape.android.R;
import com.wisape.android.common.StoryManager;
import com.wisape.android.model.StorySettingsInfo;
import com.wisape.android.util.FrescoFactory;

import java.io.File;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by tony on 2015/7/24.
 */
public class StoryReleaseActivity extends BaseActivity{
    public static final int REQUEST_CODE_STORY_RELEASE = 110;
    private static final String TAG = StoryReleaseActivity.class.getSimpleName();
    private static final int WHAT_LOAD_STORY_SETTINGS = 0x01;
    private static final int WHAT_RELEASE_STORY = 0x02;

    public static final String EXTRA_STORY_CHANNEL = "extra_story_channel";

    public static final int CHANNEL_FACEBOOK = 0x01;
    public static final int CHANNEL_MESSENGER = 0x02;
    public static final int CHANNEL_TWITTER = 0x03;
    public static final int CHANNEL_LINKEDIN = 0x04;
    public static final int CHANNEL_WECHAT = 0x05;
    public static final int CHANNEL_MOMENTS = 0x06;
    public static final int CHANNEL_GOOGLE_PLUS = 0x07;
    public static final int CHANNEL_COPY_URL = 0x08;
    public static final int CHANNEL_QR_CODE = 0x09;
    public static final int CHANNEL_EMAIL = 0x0a;
    public static final int CHANNEL_SMS = 0x0b;
    public static final int CHANNEL_MORE = 0x0c;

    public static final String PACKAGE_FACEBOOK = "";

    public static void launch(Activity activity, int requestCode){
        activity.startActivityForResult(getIntent(activity), requestCode);
    }

    public static Intent getIntent(Context context){
        Intent intent = new Intent(context.getApplicationContext(), StoryReleaseActivity.class);
        return intent;
    }

    @InjectView(R.id.story_settings_name)
    protected AppCompatEditText storyNameEdit;
    @InjectView(R.id.story_settings_desc)
    protected AppCompatEditText storyDescEdit;
    @InjectView(R.id.story_settings_cover_sdv)
    protected SimpleDraweeView storyCoverView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_story_release);
        ButterKnife.inject(this);
        startLoad(WHAT_LOAD_STORY_SETTINGS, null);
    }

    @Override
    protected Message onLoadBackgroundRunning(int what, Bundle args) throws AsyncLoaderError {
        Message msg;
        switch (what){
            default :
                msg = null;
                break;

            case WHAT_LOAD_STORY_SETTINGS :
                msg = Message.obtain();
                StorySettingsInfo settings = StoryManager.acquireStorySettings(getApplicationContext());
                msg.obj = settings;
                msg.arg1 = STATUS_SUCCESS;
                break;

            case WHAT_RELEASE_STORY :
                msg = Message.obtain();
                msg.what = WHAT_RELEASE_STORY;
                msg.setData(args);
                break;
        }
        return msg;
    }

    @Override
    protected void onLoadCompleted(Message data) {
        switch (data.what){
            default :
                return;

            case WHAT_LOAD_STORY_SETTINGS :
                if(STATUS_SUCCESS == data.arg1){
                    StorySettingsInfo settings = (StorySettingsInfo)data.obj;
                    storyNameEdit.setText(settings.defaultName);
                    storyDescEdit.setText(settings.defaultDesc);
                    Uri cover = settings.defaultCover;
                    if(null != cover){
                        FrescoFactory.bindImageFromUri(storyCoverView, cover);
                    }
                }
                break;

            case WHAT_RELEASE_STORY :
                Bundle bundle = data.getData();
                int channel = bundle.getInt(EXTRA_STORY_CHANNEL,0);
                share2Platform(channel);
                break;
        }
    }

    private void releaseStory(int channel){
        Bundle args = new Bundle();
        args.putInt(EXTRA_STORY_CHANNEL, channel);
        startLoad(WHAT_RELEASE_STORY, args);
    }

    private void share2Platform(int channel){
        File template = new File(StoryManager.getStoryTemplateDirectory(),"mingpian01");
        File thumb = new File(template,"thumb.jpg");
        String msg = "推荐给大家，http://www.wisape.com/demo/playstory/index.html";
        switch (channel){
            case CHANNEL_MORE:{
                shareMessage("标题", "消息标题", msg, thumb);
                break;
            }<commit_msg>新增Facebook分享<commit_after>package com.wisape.android.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Message;
import android.support.v7.widget.AppCompatEditText;

import com.facebook.drawee.view.SimpleDraweeView;
import com.wisape.android.R;
import com.wisape.android.common.StoryManager;
import com.wisape.android.model.StorySettingsInfo;
import com.wisape.android.util.FrescoFactory;

import java.io.File;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by tony on 2015/7/24.
 */
public class StoryReleaseActivity extends BaseActivity{
    public static final int REQUEST_CODE_STORY_RELEASE = 110;
    private static final String TAG = StoryReleaseActivity.class.getSimpleName();
    private static final int WHAT_LOAD_STORY_SETTINGS = 0x01;
    private static final int WHAT_RELEASE_STORY = 0x02;

    public static final String EXTRA_STORY_CHANNEL = "extra_story_channel";

    public static final int CHANNEL_FACEBOOK = 0x01;
    public static final int CHANNEL_MESSENGER = 0x02;
    public static final int CHANNEL_TWITTER = 0x03;
    public static final int CHANNEL_LINKEDIN = 0x04;
    public static final int CHANNEL_WECHAT = 0x05;
    public static final int CHANNEL_MOMENTS = 0x06;
    public static final int CHANNEL_GOOGLE_PLUS = 0x07;
    public static final int CHANNEL_COPY_URL = 0x08;
    public static final int CHANNEL_QR_CODE = 0x09;
    public static final int CHANNEL_EMAIL = 0x0a;
    public static final int CHANNEL_SMS = 0x0b;
    public static final int CHANNEL_MORE = 0x0c;

    public static final String PACKAGE_FACEBOOK = "";

    public static void launch(Activity activity, int requestCode){
        activity.startActivityForResult(getIntent(activity), requestCode);
    }

    public static Intent getIntent(Context context){
        Intent intent = new Intent(context.getApplicationContext(), StoryReleaseActivity.class);
        return intent;
    }

    @InjectView(R.id.story_settings_name)
    protected AppCompatEditText storyNameEdit;
    @InjectView(R.id.story_settings_desc)
    protected AppCompatEditText storyDescEdit;
    @InjectView(R.id.story_settings_cover_sdv)
    protected SimpleDraweeView storyCoverView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_story_release);
        ButterKnife.inject(this);
        startLoad(WHAT_LOAD_STORY_SETTINGS, null);
    }

    @Override
    protected Message onLoadBackgroundRunning(int what, Bundle args) throws AsyncLoaderError {
        Message msg;
        switch (what){
            default :
                msg = null;
                break;

            case WHAT_LOAD_STORY_SETTINGS :
                msg = Message.obtain();
                StorySettingsInfo settings = StoryManager.acquireStorySettings(getApplicationContext());
                msg.obj = settings;
                msg.arg1 = STATUS_SUCCESS;
                break;

            case WHAT_RELEASE_STORY :
                msg = Message.obtain();
                msg.what = WHAT_RELEASE_STORY;
                msg.setData(args);
                break;
        }
        return msg;
    }

    @Override
    protected void onLoadCompleted(Message data) {
        switch (data.what){
            default :
                return;

            case WHAT_LOAD_STORY_SETTINGS :
                if(STATUS_SUCCESS == data.arg1){
                    StorySettingsInfo settings = (StorySettingsInfo)data.obj;
                    storyNameEdit.setText(settings.defaultName);
                    storyDescEdit.setText(settings.defaultDesc);
                    Uri cover = settings.defaultCover;
                    if(null != cover){
                        FrescoFactory.bindImageFromUri(storyCoverView, cover);
                    }
                }
                break;

            case WHAT_RELEASE_STORY :
                Bundle bundle = data.getData();
                int channel = bundle.getInt(EXTRA_STORY_CHANNEL,0);
                share2Platform(channel);
                break;
        }
    }

    private void releaseStory(int channel){
        Bundle args = new Bundle();
        args.putInt(EXTRA_STORY_CHANNEL, channel);
        startLoad(WHAT_RELEASE_STORY, args);
    }

    private void share2Platform(int channel){
        File template = new File(StoryManager.getStoryTemplateDirectory(),"mingpian01");
        File thumb = new File(template,"thumb.jpg");
        String msg = "推荐给大家，http://www.wisape.com/demo/playstory/index.html";
        switch (channel){
            case CHANNEL_MORE:{
                shareMessage("标题", "消息标题", msg, thumb);
                break;
            }
            case CHANNEL_FACEBOOK:{
                shareMessage("com.facebook.katana","标题", "消息标题", msg, thumb);
                break;
            }
{'fraction_non_alphanumeric': 0.07697697697697697, 'fraction_numerical': 0.011411411411411412, 'mean_word_length': 2.5266501941404873, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2144908', 'n_tokens_mistral': 2987, 'n_tokens_neox': 2758, 'n_words': 625}