Acg sentence control

Acg sentence control

Source code introduction

Keep your favorite people, favorite lines, and unforgettable words in anime in your phone.
Source code running screenshot

Source code snippet:

  1. package com.ftbeat.acgdialogue;
  2.   
  3. import java.io.File;
  4.   
  5. import android.annotation.TargetApi;
  6. import android.graphics.Bitmap;
  7. import android.os.Build;
  8. import android.os.Bundle;
  9. import android.support.v4.app.Fragment;
  10. import android.view.LayoutInflater;
  11. import android.view.View;
  12. import android.view.ViewGroup;
  13. import android.view.animation.Animation;
  14. import android.view.animation.AnimationUtils;
  15. import android.widget.ImageView;
  16. import android.widget.TextView;
  17. import android.widget.Toast;
  18.   
  19. import com.ftbeat.R;
  20. import com.ftbeat.acg.Acg;
  21. import com.ftbeat.acg.AcgLab;
  22. import com.ftbeat.acglist.AcgListFragment;
  23. import com.ftbeat.media.AudioPlayer;
  24. import com.ftbeat.utils.PictureUtils;
  25.   
  26. public   class AcgDialogueFragment extends Fragment {
  27.   
  28. // private static final String TAG = "AcgDialogueFragment";  
  29. public   static   final String EXTRA_ACG_ID = "com.ftbeat.acg.acg_id" ;
  30.   
  31. private TextView mDialogueTextView;
  32. private TextView mPersonageTextView;
  33. private ImageView mHeadImageView;
  34. private ImageView mRippleImageView;
  35.   
  36. private Acg mAcg;
  37. private   static AudioPlayer mPlayer;
  38.   
  39. public   static AudioPlayer getPlayer() {
  40. if (mPlayer == null ) {
  41. mPlayer = new AudioPlayer();
  42. }
  43. return mPlayer;
  44. }
  45.   
  46. /**
  47. * Construct an AcgDialogueFragment by ID
  48. *
  49. * @param id
  50. * @return
  51. */  
  52. public   static AcgDialogueFragment newInstance( int id) {
  53. Bundle args = new Bundle();
  54. args.putSerializable(EXTRA_ACG_ID, id);
  55.   
  56. AcgDialogueFragment fragment = new AcgDialogueFragment();
  57. fragment.setArguments(args);
  58.   
  59. return fragment;
  60. }
  61.   
  62. /**
  63. * Create the DialogueFragment view
  64. *
  65. */  
  66. @TargetApi (Build.VERSION_CODES.HONEYCOMB)
  67. @Override  
  68. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  69. Bundle savedInstanceState) {
  70. // TODO Auto-generated method stub  
  71. View v = inflater.inflate(R.layout.fragment_acg_dialogue, container,
  72. false );
  73.   
  74. int id = (Integer) getArguments().getSerializable(EXTRA_ACG_ID);
  75. mAcg = AcgLab.get(getActivity()).getAcg(id);
  76.   
  77. mDialogueTextView = (TextView) v.findViewById(R.id.dialogue_tv);
  78. //Wrap from the following punctuation mark  
  79. String dialogue = mAcg.getDialogue().replace( "," , "\n" );
  80. dialogue = dialogue.replace( "." , "\n" );
  81. dialogue = dialogue.replace( "?" , "\n" );
  82. dialogue = dialogue.replace( "!" , "\n" );
  83. mDialogueTextView.setText(dialogue);
  84.   
  85. mPersonageTextView = (TextView) v.findViewById(R.id.personage_tv);
  86. if (!mAcg.getPersonage().isEmpty()) {
  87. mPersonageTextView.setText( "--" + mAcg.getPersonage());
  88. } else {
  89. mPersonageTextView.setText( "" );
  90. }
  91.   
  92. mHeadImageView = (ImageView) v.findViewById(R.id.avatar_iv);
  93. mRippleImageView = (ImageView) v.findViewById(R.id.ripple_iv);
  94. // Separate the sentences that come with the application and the sentences added by the user  
  95. if (mAcg.getId() < AcgListFragment.SYSTEM_DIALODUE_LENGHT) {
  96. mHeadImageView.setImageResource(Integer.parseInt(mAcg.getHead()));
  97. mHeadImageView.setOnClickListener( new View.OnClickListener() {
  98.   
  99. @Override  
  100. public   void onClick(View v) {
  101. // TODO Auto-generated method stub  
  102. // Set up the water wave animation  
  103. Animation anim = AnimationUtils.loadAnimation(
  104. getActivity(), R.anim.anim_ripple);
  105. mRippleImageView.startAnimation(anim);
  106.   
  107. AcgDialogueFragment.getPlayer().play(getActivity(),
  108. Integer.parseInt(mAcg.getSound()));
  109. }
  110. });
  111. } else {
  112. // The image path does not exist or is not set  
  113. File file = new File(mAcg.getHead());
  114. if (mAcg.getHead().isEmpty() || (!file.exists())) {
  115. // Set the default image  
  116. mHeadImageView.setImageResource(R.drawable.saber);
  117. } else {
  118. Bitmap bmp = PictureUtils.getScaledBitmapFromPath(
  119. getActivity(), mAcg.getHead());
  120. bmp = PictureUtils.getRoundBitmap(bmp);
  121. mHeadImageView.setImageBitmap(bmp);
  122. }
  123. mHeadImageView.setOnClickListener( new View.OnClickListener() {
  124.   
  125. @Override  
  126. public   void onClick(View v) {
  127. // TODO Auto-generated method stub  
  128. // Set up the water wave animation  
  129. Animation anim = AnimationUtils.loadAnimation(
  130. getActivity(), R.anim.anim_ripple);
  131. mRippleImageView.startAnimation(anim);
  132.   
  133. if (mAcg.getId() < AcgListFragment.SYSTEM_DIALODUE_LENGHT) {
  134. AcgDialogueFragment.getPlayer().play(getActivity(),
  135. Integer.parseInt(mAcg.getSound()));
  136. } else {
  137. if (mAcg.getSound().isEmpty()) {
  138. Toast.makeText(getActivity(),
  139. R.string.tip_not_sound, Toast.LENGTH_SHORT)
  140. .show();
  141. } else {
  142. AcgDialogueFragment.getPlayer().play(getActivity(),
  143. mAcg.getSound());
  144. }
  145. }
  146. }
  147. });
  148. }
  149.   
  150. return v;
  151. }
  152.   
  153. @Override  
  154. public   void onPause() {
  155. // TODO Auto-generated method stub  
  156. super .onPause();
  157.   
  158. AcgDialogueFragment.getPlayer().stop();
  159. }
  160. }

Source code link: http://download..com/data/1984836

<<:  Android application source code for smart agriculture

>>:  Google executives express willingness to return to the Chinese market

Recommend

As an operations manager, what is your daily job?

Different products, different product stages, dif...

Kotlin has become the new darling of Android after waking up [with code]

Preface Did you watch the live broadcast of Googl...

Thunderstorms occur frequently in summer. How to ensure flight safety?

Have you ever had the experience of being woken u...

The first 20 sentences to chat with girls on WeChat

Introduction to the top 20 sentences for chatting...

Analysis of hot-selling cases in Internet operations

The past 2021 was a bit magical, a bit miraculous...

How to make money by placing ads on your website?

There are more and more new webmasters nowadays. ...

Can eating dark chocolate help you lose weight? Why not do these 4 things!

Author: Xue Qingxin, registered dietitian Reviewe...

After three years of rapid development, Jitu is slowing down

The "barbarian" Jitu has learned how to...

The super moon will appear! Come and see it tomorrow night

Poster production: Feng Juan According to astrono...