NoticeGuideActivity.java 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. package com.epson.mobilephone.common.guide;
  2. import android.content.Intent;
  3. import android.content.res.Configuration;
  4. import android.os.Bundle;
  5. import android.preference.PreferenceManager;
  6. import android.support.p000v4.app.Fragment;
  7. import android.support.p000v4.app.FragmentManager;
  8. import android.support.p000v4.app.FragmentStatePagerAdapter;
  9. import android.support.p000v4.view.ViewPager;
  10. import android.view.View;
  11. import android.view.ViewGroup;
  12. import android.widget.Button;
  13. import android.widget.ImageView;
  14. import android.widget.LinearLayout;
  15. import android.widget.TextView;
  16. import com.epson.guidelib.C0907R;
  17. import com.epson.mobilephone.common.guide.GuideWebviewFragment;
  18. import java.util.ArrayList;
  19. import java.util.Locale;
  20. public class NoticeGuideActivity extends AppCompatActivity implements GuideWebviewFragment.MyClickListener {
  21. public static int DIALOG_MODE_OFF = 20001;
  22. public static int DIALOG_MODE_ON = 20000;
  23. public static int DIALOG_MODE_ONLY_BUTTON = 20002;
  24. public static String KEY_BOOT_GROUP = "BOOT_GROUP";
  25. public static String KEY_BOOT_MODE = "BOOT_MODE";
  26. public static String KEY_DIALOG_BUTTON_NO = "DIALOG_NO";
  27. public static String KEY_DIALOG_BUTTON_YES = "DIALOG_YES";
  28. public static String KEY_DIALOG_MODE = "DIALOG_MODE";
  29. public static String KEY_DIALOG_TITLE = "DIALOG_TITLE";
  30. public static String KEY_GUIDE_VER = "GUIDE_VER";
  31. public static String KEY_HTML_PATH = "HTML_PATH";
  32. public static int MODE_AUTO = 10001;
  33. public static int MODE_MANUAL = 10000;
  34. public String SP_KEY_GUIDE_VER = "GuideVersion";
  35. private String boot_group;
  36. private int boot_mode;
  37. private int dialog_mode;
  38. private ArrayList<String> htmlpath = new ArrayList<>();
  39. private MyFragmentStatePagerAdapter mAdapter;
  40. private Button mCancel;
  41. private String mDialogButtonNo = "";
  42. private String mDialogButtonYes = "";
  43. private TextView mDialogText;
  44. private String mDialogTextMessage = "";
  45. private View mGrayLine_Hor;
  46. private LinearLayout mGuideDialogView;
  47. private Button mOK;
  48. private LinearLayout mPageDisplayView;
  49. private MyViewPager mViewPager;
  50. private int version;
  51. protected void onCreate(Bundle bundle) {
  52. String str;
  53. super.onCreate(bundle);
  54. setContentView(C0907R.layout.activity_notice_guide);
  55. Intent intent = getIntent();
  56. if (intent != null) {
  57. htmlpath = intent.getStringArrayListExtra(KEY_HTML_PATH);
  58. if (this.htmlpath.size() == 0) {
  59. finish();
  60. }
  61. boot_mode = intent.getIntExtra(KEY_BOOT_MODE, 0);
  62. boot_group = intent.getStringExtra(KEY_BOOT_GROUP);
  63. dialog_mode = intent.getIntExtra(KEY_DIALOG_MODE, 0);
  64. version = intent.getIntExtra(KEY_GUIDE_VER, 0);
  65. mDialogTextMessage = intent.getStringExtra(KEY_DIALOG_TITLE);
  66. mDialogButtonYes = intent.getStringExtra(KEY_DIALOG_BUTTON_YES);
  67. mDialogButtonNo = intent.getStringExtra(KEY_DIALOG_BUTTON_NO);
  68. if (this.boot_group != null) {
  69. SP_KEY_GUIDE_VER += "-" + boot_group;
  70. }
  71. }
  72. if (this.boot_mode == MODE_AUTO) {
  73. if (this.version <= PreferenceManager.getDefaultSharedPreferences(this).getInt(this.SP_KEY_GUIDE_VER, 0)) {
  74. finish();
  75. }
  76. }
  77. final MyPageAdapter myPageAdapter = new MyPageAdapter();
  78. mAdapter = new MyFragmentStatePagerAdapter(getSupportFragmentManager(), htmlpath);
  79. mViewPager = (MyViewPager) findViewById(C0907R.C0909id.guideViewPager);
  80. mViewPager.setAdapter(mAdapter);
  81. mViewPager.setOffscreenPageLimit(2);
  82. mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  83. public void onPageScrollStateChanged(int i) {
  84. }
  85. public void onPageScrolled(int i, float f, int i2) {
  86. }
  87. public void onPageSelected(int i) {
  88. myPageAdapter.changePage(i);
  89. }
  90. });
  91. mPageDisplayView = (LinearLayout) findViewById(C0907R.C0909id.pageDisplayViewGroup);
  92. myPageAdapter.setPageSize(mPageDisplayView, mAdapter.getCount());
  93. myPageAdapter.changePage(mViewPager.getCurrentItem());
  94. mGuideDialogView = (LinearLayout) findViewById(C0907R.C0909id.guide_dialog_layout);
  95. mGrayLine_Hor = findViewById(C0907R.C0909id.guide_dialog_horizon_gray_line);
  96. mDialogText = (TextView) findViewById(C0907R.C0909id.guide_dialog_message);
  97. int i = dialog_mode;
  98. if (i == DIALOG_MODE_ON || i == DIALOG_MODE_ONLY_BUTTON) {
  99. mGuideDialogView.setVisibility(0);
  100. ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) mGuideDialogView.getLayoutParams();
  101. marginLayoutParams.width = (int) Utils.dptopx(Utils.getWebViewDP(this, getApplicationContext()) + Utils.LAYOUT_MEARGIN, getApplicationContext());
  102. mGuideDialogView.setLayoutParams(marginLayoutParams);
  103. mOK = (Button) findViewById(C0907R.C0909id.ok_button);
  104. mCancel = (Button) findViewById(C0907R.C0909id.cancel_btn);
  105. String str2 = mDialogButtonYes;
  106. if (str2 != null) {
  107. mOK.setText(str2);
  108. }
  109. String str3 = mDialogButtonNo;
  110. if (str3 != null) {
  111. mCancel.setText(str3);
  112. }
  113. mOK.setOnClickListener(new View.OnClickListener() {
  114. public void onClick(View view) {
  115. NoticeGuideActivity.this.setResult(-1);
  116. NoticeGuideActivity.this.onClickClose();
  117. }
  118. });
  119. mCancel.setOnClickListener(new View.OnClickListener() {
  120. public void onClick(View view) {
  121. NoticeGuideActivity.this.setResult(0);
  122. NoticeGuideActivity.this.onClickClose();
  123. }
  124. });
  125. if (this.dialog_mode == DIALOG_MODE_ON && (str = mDialogTextMessage) != null) {
  126. mDialogText.setText(str);
  127. }
  128. if (this.dialog_mode == DIALOG_MODE_ONLY_BUTTON) {
  129. mGrayLine_Hor.setVisibility(8);
  130. mDialogText.setVisibility(8);
  131. mOK.setBackground(getResources().getDrawable(C0907R.C0908drawable.rectangle_left_button));
  132. mCancel.setBackground(getResources().getDrawable(C0907R.C0908drawable.rectangle_right_button));
  133. }
  134. }
  135. }
  136. public void onBackPressed() {
  137. onClickClose();
  138. }
  139. public void onClickClose() {
  140. if (this.boot_mode == MODE_AUTO) {
  141. PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(this.SP_KEY_GUIDE_VER, version).apply();
  142. }
  143. finish();
  144. }
  145. public void onConfigurationChanged(Configuration configuration) {
  146. switch (configuration.orientation) {
  147. case 1:
  148. if (this.dialog_mode == DIALOG_MODE_ON) {
  149. mGuideDialogView.setVisibility(0);
  150. break;
  151. }
  152. break;
  153. case 2:
  154. if (this.dialog_mode == DIALOG_MODE_ON) {
  155. mGuideDialogView.setVisibility(8);
  156. break;
  157. }
  158. break;
  159. }
  160. super.onConfigurationChanged(configuration);
  161. }
  162. public static class MyFragmentStatePagerAdapter extends FragmentStatePagerAdapter {
  163. private ArrayList<String> HTML_PAGE;
  164. private int PAGE_LENGTH;
  165. private MyFragmentStatePagerAdapter(FragmentManager fragmentManager, ArrayList<String> arrayList) {
  166. super(fragmentManager);
  167. HTML_PAGE = new ArrayList<>();
  168. PAGE_LENGTH = 0;
  169. HTML_PAGE = arrayList;
  170. PAGE_LENGTH = arrayList.size();
  171. }
  172. public Fragment getItem(int i) {
  173. return GuideWebviewFragment.newInstance(String.format(Locale.US, HTML_PAGE.get(i), new Object[]{Integer.valueOf(i + 1)}));
  174. }
  175. public int getCount() {
  176. return PAGE_LENGTH;
  177. }
  178. }
  179. class MyPageAdapter {
  180. private ImageView[] mPagePosition;
  181. private MyPageAdapter() {
  182. }
  183. private void setPageSize(@NonNull ViewGroup viewGroup, int i) {
  184. mPagePosition = new ImageView[i];
  185. int i2 = 0;
  186. while (i2 < i) {
  187. ImageView imageView = new ImageView(NoticeGuideActivity.this.getApplicationContext());
  188. imageView.setImageResource(C0907R.C0908drawable.cycle02);
  189. int i3 = i2 + 1;
  190. viewGroup.addView(imageView, i3);
  191. mPagePosition[i2] = imageView;
  192. i2 = i3;
  193. }
  194. }
  195. private void changePage(int i) {
  196. int i2 = 0;
  197. while (true) {
  198. ImageView[] imageViewArr = mPagePosition;
  199. if (i2 < imageViewArr.length) {
  200. if (imageViewArr[i2] != null) {
  201. if (i == i2) {
  202. imageViewArr[i2].setImageResource(C0907R.C0908drawable.cycle03);
  203. } else {
  204. imageViewArr[i2].setImageResource(C0907R.C0908drawable.cycle02);
  205. }
  206. }
  207. i2++;
  208. } else {
  209. return;
  210. }
  211. }
  212. }
  213. }
  214. }