Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ButtonControler extends AppCompatActivity {
- public ButtonControler(){}
- public void buttonPressed()
- {
- //add the buttons contorls
- //if the top button is pushed get the promotion page
- final ImageButton promo = (ImageButton)findViewById(R.id.apivita);
- promo.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent getPromos = new Intent(v.getContext(),PromotionMain.class);
- startActivity(getPromos);
- }
- });
- //if the button 1 is pushed get the defulat webview page
- final ImageButton button1 = (ImageButton)findViewById(R.id.button1);
- button1.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Log.d("Button1: ", "Pressed");
- Intent button1Pressed = new Intent(v.getContext(),MyWebViewMain.class);
- startActivity(button1Pressed);
- }
- });
- //if the cart is pushed get the cart webview page
- final ImageButton cart = (ImageButton)findViewById(R.id.button2);
- cart.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Log.d("Cart: ","Pressed");
- Intent myCart = new Intent(v.getContext(),Cart.class);
- startActivity(myCart);
- }
- });
- //if the button 3 is pushed get the defulat webview page
- final ImageButton button3 = (ImageButton)findViewById(R.id.button3);
- button3.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Log.d("Button3: ","Pressed");
- Intent buttonPressed = new Intent(v.getContext(),MyWebViewMain.class);
- startActivity(buttonPressed);
- }
- });
- //if the button 4 is pushed get the defulat webview page
- final ImageButton button4 = (ImageButton)findViewById(R.id.button4);
- button4.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Log.d("Button4: ","Pressed");
- Intent buttonPressed = new Intent(v.getContext(),MyWebViewMain.class);
- startActivity(buttonPressed);
- }
- });
- //if the Store list is pushed get the defulat webview page
- final ImageButton storeList = (ImageButton)findViewById(R.id.button5);
- storeList.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Log.d("StoreList: ","Pressed");
- Intent myStoreList = new Intent(v.getContext(),StoreList.class);
- startActivity(myStoreList);
- }
- });
- //if the Store list is pushed get the notification
- final Button notification = (Button)findViewById(R.id.gcmlogo);
- notification.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Log.d("Notificatiion: ","Pressed");
- Intent myNotification = new Intent(v.getContext(),GCMMainActivity.class);
- startActivity(myNotification);
- }
- });
- //if the Store list is pushed get the notification
- final Button myPage = (Button)findViewById(R.id.mypage);
- myPage.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Log.d("MyPage: ","Pressed");
- //read the stored values
- String storedUser = CustomerPerferences.readString(getApplicationContext(), CustomerPerferences.USER_NAME, "");
- String storedPass =CustomerPerferences.readString(getApplicationContext(), CustomerPerferences.PASSWORD, "");
- //see if use has entered a username and password
- if(storedUser.equals("USER_NAME"))
- {
- Log.d("Loging in", "Go!");
- Intent goToLogin = new Intent(v.getContext(),LoginPage.class);
- startActivity(goToLogin);
- }else
- {
- Intent goToLogin = new Intent(v.getContext(),CustomerPage.class);
- goToLogin.putExtra("user_name", storedUser);
- startActivity(goToLogin);
- }
- }
- });
- public class PromotionMain extends AppCompatActivity {
- //gobal variables
- //these are where the paths will be stored
- final ArrayList<String> pictureArray = new ArrayList<String>();
- final ArrayList<String> pathArray = new ArrayList<String>();
- final ArrayList<String> labelArray = new ArrayList<String>();
- //Promotiion website
- final String promos = myUrl;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.promotion_layout);
- //parse the JSON string
- //parse the JSON string
- JSONParser jp = new JSONParser();
- try {
- jp.parsesData(promos, pictureArray, pathArray, labelArray);
- } catch (IOException e) {
- e.printStackTrace();
- }
- ArrayList<ListItem> listData = getListData();
- final ListView listView = (ListView) findViewById(R.id.custom_list);
- listView.setAdapter(new CustomListAdapter(this, listData));
- listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- //here is a method to either send the user to the poduct page
- //or to the main page in the app
- //open a new activity and close this one down
- @Override
- public void onItemClick(AdapterView<?> a, View v, int position, long id) {
- ListItem promoData = (ListItem) listView.getItemAtPosition(position);
- //Toast.makeText(PromotionMain.this, "Selected :" + " " + promoData.getPathUrl(), Toast.LENGTH_LONG).show();
- //open up a new activity and send it to this site http://52.68.68.86/magento
- //lest open up the corrisponding webpage
- Intent reDirect = new Intent();
- reDirect.setAction(Intent.ACTION_VIEW);
- reDirect.addCategory(Intent.CATEGORY_BROWSABLE);
- //need to make sure that if it is not a url them do nothing in future rendtions
- //other wise it will crash the app
- reDirect.setData(Uri.parse(promoData.getPathUrl()));
- String newUrl = Uri.parse(promoData.getPathUrl()).toString();
- //check to see if there is a path for the promotion
- if (newUrl.contains("http")) {
- startActivity(reDirect);
- } else {
- //if not do nothing
- Log.d("Path URL: ", " is null");
- }
- }
- });
- //add the buttons contorls
- // buttonPressed();
- ButtonControler bc = new ButtonControler();
- bc.buttonPressed();
- //ButtonControler bc = new ButtonControler();
- //bc.pressed(promo,cart,storeList,button1,button3,button4,null);
- }
- private ArrayList<ListItem> getListData() {
- ArrayList<ListItem> listGetData = new ArrayList<ListItem>();
- //get the url for the image from the picture array list
- for (int i = 0; i < pictureArray.size(); i++) {
- ListItem imageData = new ListItem();
- imageData.setUrl(pictureArray.get(i));
- imageData.setPathUrl(pathArray.get(i));
- imageData.setLableTitle(labelArray.get(i));
- listGetData.add(imageData);
- }
- return listGetData;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement