Esempio n. 1
0
  @Override
  public View GetView(
      LayoutInflater inflater,
      ViewGroup container,
      SurveyActivity activityRef,
      SurveyAdapter surveyAdapter,
      int parentId) {

    View view = inflater.inflate(R.layout.gps_question, container, false);
    TextView label = (TextView) view.findViewById(R.id.description);
    label.setText(this.label);
    label.setTextSize(fontSize);

    Typeface tf = Typeface.createFromAsset(activityRef.getAssets(), "fonts/OpenSans-Regular.ttf");
    label.setTypeface(tf);

    try {
      label.setTextColor(Color.parseColor(color));
    } catch (Exception e) {
    }

    // SET LABELS
    TextView textlatlabel = (TextView) view.findViewById(R.id.lattext);
    textlatlabel.setText(latLabel);
    textlatlabel.setTypeface(tf);

    TextView textLonlabel = (TextView) view.findViewById(R.id.lontext);
    textLonlabel.setText(lonLabel);
    textLonlabel.setTypeface(tf);

    // GET GPS POSITION
    textLat = (TextView) view.findViewById(R.id.latitude);
    textLon = (TextView) view.findViewById(R.id.longitude);
    textLat.setTypeface(tf);
    textLon.setTypeface(tf);

    if (locationManager == null) {
      // Acquire a reference to the system Location Manager
      locationManager =
          (LocationManager) view.getContext().getSystemService(Context.LOCATION_SERVICE);

      // Define a listener that responds to location updates
      LocationListener locationListener =
          new LocationListener() {
            public void onLocationChanged(Location location) {

              if (LocationUtil.isBetterLocation(location, currentBestLocation)) {
                // Called when a new location is found by the network location provider.
                textLat.setText(String.valueOf(location.getLatitude()));
                textLon.setText(String.valueOf(location.getLongitude()));
                answer =
                    String.valueOf(location.getLatitude())
                        + "/"
                        + String.valueOf(location.getLongitude());

                // Remove the listener you previously added
                locationManager.removeUpdates(this);
              }
            }

            public void onProviderEnabled(String provider) {}

            public void onProviderDisabled(String provider) {}

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
              // TODO Auto-generated method stub

            }
          };

      // Register the listener with the Location Manager to receive location updates
      locationManager.requestLocationUpdates(
          LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
      locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);

      Criteria criteria = new Criteria();
      String provider = locationManager.getBestProvider(criteria, false);
      currentBestLocation = locationManager.getLastKnownLocation(provider);
    }

    // SET ORIENTATION
    LinearLayout layout = (LinearLayout) view.findViewById(R.id.layout);
    if (orientation.equals("horizontal")) layout.setOrientation(LinearLayout.HORIZONTAL);
    else layout.setOrientation(LinearLayout.VERTICAL);

    // SET ANSWER
    if (!answer.equals("")) {
      String[] parts = answer.split("/");
      textLat.setText(parts[0]);
      textLon.setText(parts[1]);
    }
    return view;
  }
Esempio n. 2
0
    @Override
    public void onClick(final View v) {
      int position = (int) v.getTag();
      AlertDialog.Builder builder =
          new AlertDialog.Builder(
              new ContextThemeWrapper(v.getContext(), R.style.HomePageDialogboxCustom));

      if (position == 0) {
        Intent gotolistofpet = new Intent(v.getContext(), PetList.class);
        v.getContext().startActivity(gotolistofpet);
      }
      if (position == 1) {
        Intent gotoShopProduct = new Intent(v.getContext(), Pet_Shop_List.class);
        v.getContext().startActivity(gotoShopProduct);
      }
      if (position == 2) {
        Intent gotoCampaign = new Intent(v.getContext(), Campaign_List_ForAll.class);
        v.getContext().startActivity(gotoCampaign);
      }
      if (position == 3) {
        Intent gotoPetServices = new Intent(v.getContext(), PetServices.class);
        v.getContext().startActivity(gotoPetServices);
      }
      if (position == 4) {
        adapter = new DialogListAdapter(dialogListForPetClinic);
        final Intent gotoPetClinic = new Intent(v.getContext(), PetClinic.class);
        builder.setAdapter(
            adapter,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialogInterface, int i) {
                if (i == 0) {
                  state = 0;
                  gotoPetClinic.putExtra("STATE_OF_CLICK", state);
                  v.getContext().startActivity(gotoPetClinic);

                } else if (i == 1) {
                  state = 1;
                  gotoPetClinic.putExtra("STATE_OF_CLICK", state);
                  v.getContext().startActivity(gotoPetClinic);
                }
              }
            });
        alertDialog = builder.create();
        alertDialog.show();
      }
      if (position == 5) {
        Intent gotolistofpet = new Intent(v.getContext(), PetMateList.class);
        v.getContext().startActivity(gotolistofpet);
      }
    }