NoticeGuideActivity.java 9.0 KB

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