// Path: AndroidDemos/app/src/main/java/com/zhangtielei/demos/async/programming/callback/emoji/EmojiDownloader.java
// public interface EmojiDownloader {
//     /**
//      * 开始下载指定的表情包
//      * @param emojiPackage
//      */
//     void startDownloadEmoji(EmojiPackage emojiPackage);
// 
//     /**
//      * 设置监听器.
//      * @param listener
//      */
//     void setEmojiDownloadListener(EmojiDownloadListener listener);
// 
//     /**
//      * 这里定义回调相关的接口. 不是我们要讨论的重点.
//      * 这里的定义用于完整演示.
//      */
// 
//     interface EmojiDownloadListener {
//         /**
//          * 表情包下载成功回调.
//          * @param emojiPackage
//          */
//         void emojiDownloadSuccess(EmojiPackage emojiPackage);
// 
//         /**
//          * 表情包下载失败回调.
//          * @param emojiPackage
//          * @param errorCode 为简单起见, 这里的值复用{@link com.zhangtielei.demos.async.programming.callback.download.v3.DownloadListener}中的错误码定义.
//          * @param errorMessage
//          */
//         void emojiDownloadFailed(EmojiPackage emojiPackage, int errorCode, String errorMessage);
// 
//         /**
//          * 表情包下载进度回调. 每次下载完一个图片文件后回调一次.
//          * @param emojiPackage
//          * @param downloadEmojiUrl 当前刚下载完的图片文件URL
//          */
//         void emojiDownloadProgress(EmojiPackage emojiPackage, String downloadEmojiUrl);
//     }
// 
// }
// 
// Path: AndroidDemos/app/src/main/java/com/zhangtielei/demos/async/programming/callback/emoji/EmojiPackage.java
// public class EmojiPackage {
//     /**
//      * 表情包ID
//      */
//     public long emojiId;
//     /**
//      * 表情包图片列表
//      */
//     public List<String> emojiUrls;
// }
// 
// Path: AndroidDemos/app/src/main/java/com/zhangtielei/demos/async/programming/common/utils/TextLogUtil.java
// public class TextLogUtil {
//     /**
//      * 在一个TextView上追加一行日志.
//      * @param logTextView
//      * @param log
//      */
//     public static void println(TextView logTextView, CharSequence log) {
//         SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
//         String timestamp = sdf.format(new Date());
// 
//         CharSequence newText = timestamp + ": " + log;
//         CharSequence oldText = logTextView.getText();
//         if (oldText == null || oldText.length() <= 0) {
//             logTextView.setText(newText);
//         }
//         else {
//             logTextView.setText(oldText + "\n" + newText);
//         }
//     }
// }


import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import com.zhangtielei.demos.async.programming.R;
import com.zhangtielei.demos.async.programming.callback.emoji.EmojiDownloader;
import com.zhangtielei.demos.async.programming.callback.emoji.EmojiPackage;
import com.zhangtielei.demos.async.programming.common.utils.TextLogUtil;
import java.util.ArrayList;
/*
 * Copyright (C) 2016 Tielei Zhang (zhangtielei.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.zhangtielei.demos.async.programming.callback.emoji.v4;



/**
 * 利用支持上下文传递的异步接口来实现表情包下载的演示页面.
 */
public class EmojiDownloadDemoActivity extends AppCompatActivity {
    private TextView description;
    private TextView logTextView;

    private EmojiDownloader emojiDownloader;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_log_display);

        description = (TextView) findViewById(R.id.description);
        logTextView = (TextView) findViewById(R.id.log_display);

        description.setText(R.string.emoji_download_demo4_description);

        emojiDownloader = new MyEmojiDownloader();
        emojiDownloader.setEmojiDownloadListener(new EmojiDownloader.EmojiDownloadListener() {
            @Override
            public void emojiDownloadSuccess(EmojiPackage emojiPackage) {
                TextLogUtil.println(logTextView, "emoji package (emojiId: " + emojiPackage.emojiId + ") downloaded success!");
            }

            @Override
            public void emojiDownloadFailed(EmojiPackage emojiPackage, int errorCode, String errorMessage) {
                TextLogUtil.println(logTextView, "emoji package (emojiId: " + emojiPackage.emojiId + ") downloaded failed! errorCode: " + errorCode + ", errorMessage: " + errorMessage);
            }

            @Override
            public void emojiDownloadProgress(EmojiPackage emojiPackage, String downloadEmojiUrl) {
                TextLogUtil.println(logTextView, "progress: " + downloadEmojiUrl + " downloaded...");
            }
        });

        //构造要下载的表情包
// Path: AndroidDemos/app/src/main/java/com/zhangtielei/demos/async/programming/callback/emoji/EmojiDownloader.java
// public interface EmojiDownloader {
//     /**
//      * 开始下载指定的表情包
//      * @param emojiPackage
//      */
//     void startDownloadEmoji(EmojiPackage emojiPackage);
// 
//     /**
//      * 设置监听器.
//      * @param listener
//      */
//     void setEmojiDownloadListener(EmojiDownloadListener listener);
// 
//     /**
//      * 这里定义回调相关的接口. 不是我们要讨论的重点.
//      * 这里的定义用于完整演示.
//      */
// 
//     interface EmojiDownloadListener {
//         /**
//          * 表情包下载成功回调.
//          * @param emojiPackage
//          */
//         void emojiDownloadSuccess(EmojiPackage emojiPackage);
// 
//         /**
//          * 表情包下载失败回调.
//          * @param emojiPackage
//          * @param errorCode 为简单起见, 这里的值复用{@link com.zhangtielei.demos.async.programming.callback.download.v3.DownloadListener}中的错误码定义.
//          * @param errorMessage
//          */
//         void emojiDownloadFailed(EmojiPackage emojiPackage, int errorCode, String errorMessage);
// 
//         /**
//          * 表情包下载进度回调. 每次下载完一个图片文件后回调一次.
//          * @param emojiPackage
//          * @param downloadEmojiUrl 当前刚下载完的图片文件URL
//          */
//         void emojiDownloadProgress(EmojiPackage emojiPackage, String downloadEmojiUrl);
//     }
// 
// }
// 
// Path: AndroidDemos/app/src/main/java/com/zhangtielei/demos/async/programming/callback/emoji/EmojiPackage.java
// public class EmojiPackage {
//     /**
//      * 表情包ID
//      */
//     public long emojiId;
//     /**
//      * 表情包图片列表
//      */
//     public List<String> emojiUrls;
// }
// 
// Path: AndroidDemos/app/src/main/java/com/zhangtielei/demos/async/programming/common/utils/TextLogUtil.java
// public class TextLogUtil {
//     /**
//      * 在一个TextView上追加一行日志.
//      * @param logTextView
//      * @param log
//      */
//     public static void println(TextView logTextView, CharSequence log) {
//         SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
//         String timestamp = sdf.format(new Date());
// 
//         CharSequence newText = timestamp + ": " + log;
//         CharSequence oldText = logTextView.getText();
//         if (oldText == null || oldText.length() <= 0) {
//             logTextView.setText(newText);
//         }
//         else {
//             logTextView.setText(oldText + "\n" + newText);
//         }
//     }
// }


// Path: AndroidDemos/app/src/main/java/com/zhangtielei/demos/async/programming/callback/emoji/v4/EmojiDownloadDemoActivity.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import com.zhangtielei.demos.async.programming.R;
import com.zhangtielei.demos.async.programming.callback.emoji.EmojiDownloader;
import com.zhangtielei.demos.async.programming.callback.emoji.EmojiPackage;
import com.zhangtielei.demos.async.programming.common.utils.TextLogUtil;
import java.util.ArrayList;

/*
 * Copyright (C) 2016 Tielei Zhang (zhangtielei.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.zhangtielei.demos.async.programming.callback.emoji.v4;



/**
 * 利用支持上下文传递的异步接口来实现表情包下载的演示页面.
 */
public class EmojiDownloadDemoActivity extends AppCompatActivity {
    private TextView description;
    private TextView logTextView;

    private EmojiDownloader emojiDownloader;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_log_display);

        description = (TextView) findViewById(R.id.description);
        logTextView = (TextView) findViewById(R.id.log_display);

        description.setText(R.string.emoji_download_demo4_description);

        emojiDownloader = new MyEmojiDownloader();
        emojiDownloader.setEmojiDownloadListener(new EmojiDownloader.EmojiDownloadListener() {
            @Override
            public void emojiDownloadSuccess(EmojiPackage emojiPackage) {
                TextLogUtil.println(logTextView, "emoji package (emojiId: " + emojiPackage.emojiId + ") downloaded success!");
            }

            @Override
            public void emojiDownloadFailed(EmojiPackage emojiPackage, int errorCode, String errorMessage) {
                TextLogUtil.println(logTextView, "emoji package (emojiId: " + emojiPackage.emojiId + ") downloaded failed! errorCode: " + errorCode + ", errorMessage: " + errorMessage);
            }

            @Override
            public void emojiDownloadProgress(EmojiPackage emojiPackage, String downloadEmojiUrl) {
                TextLogUtil.println(logTextView, "progress: " + downloadEmojiUrl + " downloaded...");
            }
        });

        //构造要下载的表情包
        EmojiPackage emojiPackage = new EmojiPackage();