Advertisement
Guest User

Untitled

a guest
Mar 7th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.12 KB | None | 0 0
  1. public class ButtonControler extends AppCompatActivity {
  2.  
  3.  
  4. public ButtonControler(){}
  5.  
  6. public void buttonPressed()
  7. {
  8. //add the buttons contorls
  9. //if the top button is pushed get the promotion page
  10. final ImageButton promo = (ImageButton)findViewById(R.id.apivita);
  11. promo.setOnClickListener(new View.OnClickListener() {
  12. @Override
  13. public void onClick(View v) {
  14. Intent getPromos = new Intent(v.getContext(),PromotionMain.class);
  15. startActivity(getPromos);
  16. }
  17. });
  18. //if the button 1 is pushed get the defulat webview page
  19. final ImageButton button1 = (ImageButton)findViewById(R.id.button1);
  20. button1.setOnClickListener(new View.OnClickListener() {
  21. @Override
  22. public void onClick(View v) {
  23. Log.d("Button1: ", "Pressed");
  24. Intent button1Pressed = new Intent(v.getContext(),MyWebViewMain.class);
  25. startActivity(button1Pressed);
  26. }
  27. });
  28.  
  29.  
  30. //if the cart is pushed get the cart webview page
  31. final ImageButton cart = (ImageButton)findViewById(R.id.button2);
  32. cart.setOnClickListener(new View.OnClickListener() {
  33. @Override
  34. public void onClick(View v) {
  35. Log.d("Cart: ","Pressed");
  36. Intent myCart = new Intent(v.getContext(),Cart.class);
  37. startActivity(myCart);
  38. }
  39. });
  40.  
  41. //if the button 3 is pushed get the defulat webview page
  42. final ImageButton button3 = (ImageButton)findViewById(R.id.button3);
  43. button3.setOnClickListener(new View.OnClickListener() {
  44. @Override
  45. public void onClick(View v) {
  46. Log.d("Button3: ","Pressed");
  47. Intent buttonPressed = new Intent(v.getContext(),MyWebViewMain.class);
  48. startActivity(buttonPressed);
  49. }
  50. });
  51.  
  52. //if the button 4 is pushed get the defulat webview page
  53. final ImageButton button4 = (ImageButton)findViewById(R.id.button4);
  54. button4.setOnClickListener(new View.OnClickListener() {
  55. @Override
  56. public void onClick(View v) {
  57. Log.d("Button4: ","Pressed");
  58. Intent buttonPressed = new Intent(v.getContext(),MyWebViewMain.class);
  59. startActivity(buttonPressed);
  60. }
  61. });
  62.  
  63. //if the Store list is pushed get the defulat webview page
  64. final ImageButton storeList = (ImageButton)findViewById(R.id.button5);
  65. storeList.setOnClickListener(new View.OnClickListener() {
  66. @Override
  67. public void onClick(View v) {
  68. Log.d("StoreList: ","Pressed");
  69. Intent myStoreList = new Intent(v.getContext(),StoreList.class);
  70. startActivity(myStoreList);
  71. }
  72. });
  73.  
  74. //if the Store list is pushed get the notification
  75. final Button notification = (Button)findViewById(R.id.gcmlogo);
  76. notification.setOnClickListener(new View.OnClickListener() {
  77. @Override
  78. public void onClick(View v) {
  79. Log.d("Notificatiion: ","Pressed");
  80. Intent myNotification = new Intent(v.getContext(),GCMMainActivity.class);
  81. startActivity(myNotification);
  82. }
  83. });
  84.  
  85. //if the Store list is pushed get the notification
  86. final Button myPage = (Button)findViewById(R.id.mypage);
  87. myPage.setOnClickListener(new View.OnClickListener() {
  88. @Override
  89. public void onClick(View v) {
  90. Log.d("MyPage: ","Pressed");
  91. //read the stored values
  92. String storedUser = CustomerPerferences.readString(getApplicationContext(), CustomerPerferences.USER_NAME, "");
  93. String storedPass =CustomerPerferences.readString(getApplicationContext(), CustomerPerferences.PASSWORD, "");
  94. //see if use has entered a username and password
  95. if(storedUser.equals("USER_NAME"))
  96. {
  97. Log.d("Loging in", "Go!");
  98. Intent goToLogin = new Intent(v.getContext(),LoginPage.class);
  99. startActivity(goToLogin);
  100. }else
  101. {
  102.  
  103. Intent goToLogin = new Intent(v.getContext(),CustomerPage.class);
  104. goToLogin.putExtra("user_name", storedUser);
  105. startActivity(goToLogin);
  106. }
  107.  
  108. }
  109. });
  110.  
  111. public class PromotionMain extends AppCompatActivity {
  112.  
  113. //gobal variables
  114. //these are where the paths will be stored
  115. final ArrayList<String> pictureArray = new ArrayList<String>();
  116. final ArrayList<String> pathArray = new ArrayList<String>();
  117. final ArrayList<String> labelArray = new ArrayList<String>();
  118. //Promotiion website
  119. final String promos = myUrl;
  120.  
  121. @Override
  122. protected void onCreate(Bundle savedInstanceState) {
  123. super.onCreate(savedInstanceState);
  124. setContentView(R.layout.promotion_layout);
  125.  
  126. //parse the JSON string
  127. //parse the JSON string
  128. JSONParser jp = new JSONParser();
  129.  
  130. try {
  131. jp.parsesData(promos, pictureArray, pathArray, labelArray);
  132. } catch (IOException e) {
  133. e.printStackTrace();
  134. }
  135. ArrayList<ListItem> listData = getListData();
  136.  
  137. final ListView listView = (ListView) findViewById(R.id.custom_list);
  138. listView.setAdapter(new CustomListAdapter(this, listData));
  139. listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  140.  
  141. //here is a method to either send the user to the poduct page
  142. //or to the main page in the app
  143. //open a new activity and close this one down
  144. @Override
  145. public void onItemClick(AdapterView<?> a, View v, int position, long id) {
  146. ListItem promoData = (ListItem) listView.getItemAtPosition(position);
  147. //Toast.makeText(PromotionMain.this, "Selected :" + " " + promoData.getPathUrl(), Toast.LENGTH_LONG).show();
  148. //open up a new activity and send it to this site http://52.68.68.86/magento
  149. //lest open up the corrisponding webpage
  150. Intent reDirect = new Intent();
  151. reDirect.setAction(Intent.ACTION_VIEW);
  152. reDirect.addCategory(Intent.CATEGORY_BROWSABLE);
  153. //need to make sure that if it is not a url them do nothing in future rendtions
  154. //other wise it will crash the app
  155. reDirect.setData(Uri.parse(promoData.getPathUrl()));
  156. String newUrl = Uri.parse(promoData.getPathUrl()).toString();
  157. //check to see if there is a path for the promotion
  158. if (newUrl.contains("http")) {
  159. startActivity(reDirect);
  160. } else {
  161. //if not do nothing
  162. Log.d("Path URL: ", " is null");
  163. }
  164.  
  165. }
  166. });
  167.  
  168. //add the buttons contorls
  169. // buttonPressed();
  170. ButtonControler bc = new ButtonControler();
  171. bc.buttonPressed();
  172. //ButtonControler bc = new ButtonControler();
  173. //bc.pressed(promo,cart,storeList,button1,button3,button4,null);
  174.  
  175. }
  176. private ArrayList<ListItem> getListData() {
  177. ArrayList<ListItem> listGetData = new ArrayList<ListItem>();
  178.  
  179.  
  180. //get the url for the image from the picture array list
  181. for (int i = 0; i < pictureArray.size(); i++) {
  182. ListItem imageData = new ListItem();
  183. imageData.setUrl(pictureArray.get(i));
  184. imageData.setPathUrl(pathArray.get(i));
  185. imageData.setLableTitle(labelArray.get(i));
  186. listGetData.add(imageData);
  187.  
  188. }
  189. return listGetData;
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement