プロジェクト

全般

プロフィール

« | » 

リビジョン 79a6e367

みぞ @mizo0203 さんが約7年前に追加

Refactoring TwitterTimelineTalker

差分を表示:

src/com/mizo0203/twitter/timeline/talker/Talker.java
49 49
  }
50 50

  
51 51
  public static enum YukkuriVoice {
52

  
53
    /**
54
     * ゆっくりボイス - 霊夢
55
     */
52 56
    REIMU("f1"), //
57

  
58
    /**
59
     * ゆっくりボイス - 魔理沙
60
     */
53 61
    MARISA("f2"), //
54 62
    ;
55 63

  
src/com/mizo0203/twitter/timeline/talker/TwitterTimelineTalker.java
1 1
package com.mizo0203.twitter.timeline.talker;
2 2

  
3
import java.util.Locale;
3 4
import twitter4j.StallWarning;
4 5
import twitter4j.Status;
5 6
import twitter4j.StatusDeletionNotice;
......
10 11

  
11 12
public class TwitterTimelineTalker {
12 13

  
13
  private boolean mVoice_f1 = true;
14
  /**
15
   * ISO 639 言語コード - 日本語 (ja)
16
   */
17
  public static final String LANG_JA = Locale.JAPAN.getLanguage();
18

  
19
  private Talker.YukkuriVoice mYukkuriVoice = Talker.YukkuriVoice.REIMU;
14 20
  private final TwitterStream mTwitterStream;
15 21
  private final Talker mTalker;
16 22

  
17 23
  public TwitterTimelineTalker(Configuration configuration, Talker talker) {
18 24
    mTwitterStream = new TwitterStreamFactory(configuration).getInstance();
19
    mTwitterStream.addListener(new MyStatusListener());
25
    mTwitterStream.addListener(new OnStatusEvent());
20 26
    mTalker = talker;
21 27
  }
22 28

  
23 29
  public void start() {
30
    // OnStatusEvent に Twitter タイムラインが通知される
24 31
    mTwitterStream.user();
25 32
  }
26 33

  
27
  private class MyStatusListener implements StatusListener {
34
  private class OnStatusEvent implements StatusListener {
28 35

  
29 36
    public void onStatus(final Status status) {
30
      if (!"ja".equalsIgnoreCase(status.getLang())) {
37
      if (!LANG_JA.equalsIgnoreCase(status.getLang())) {
31 38
        return;
32 39
      }
40

  
33 41
      final StringBuffer buffer = new StringBuffer();
34 42
      buffer.append(status.getUser().getName());
35 43
      buffer.append("さんから、");
36 44
      buffer.append(status.getText());
37 45
      System.out.println(buffer);
38 46

  
39
      // System.out.println("@" + status.getUser().getScreenName() + " | "
40
      // + status.getText() + " 【 https://twitter.com/" +
41
      // status.getUser().getScreenName() + "/status/" + status.getId() +
42
      // " 】");
43
      // こんな感じでstatusについている名前とかを色々表示させるとさらに欲しい情報にたどり着けると思います
47
      mTalker.talkAsync(UrlUtil.convURLEmpty(buffer).replaceAll("\n", "。"), mYukkuriVoice);
44 48

  
45

  
46
      mTalker.talkAsync(UrlUtil.convURLEmpty(buffer).replaceAll("\n", "。"),
47
          (mVoice_f1 ? Talker.YukkuriVoice.REIMU : Talker.YukkuriVoice.MARISA));
48
      mVoice_f1 = !mVoice_f1;
49
      // 読み上げは、霊夢と魔理沙が交互に行なう
50
      if (mYukkuriVoice == Talker.YukkuriVoice.REIMU) {
51
        mYukkuriVoice = Talker.YukkuriVoice.MARISA;
52
      } else {
53
        mYukkuriVoice = Talker.YukkuriVoice.REIMU;
54
      }
49 55

  
50 56
    }
51 57

  

他の形式にエクスポート: Unified diff