Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.taxipixi.incarapp.widgets;
- import android.annotation.TargetApi;
- import android.content.Context;
- import android.content.Intent;
- import android.graphics.Color;
- import android.graphics.drawable.Drawable;
- import android.net.Uri;
- import android.os.Build;
- import android.support.v4.app.FragmentActivity;
- import android.text.Spannable;
- import android.text.SpannableString;
- import android.text.style.AbsoluteSizeSpan;
- import android.text.style.ForegroundColorSpan;
- import android.util.AttributeSet;
- import android.util.TypedValue;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.RelativeLayout;
- import android.widget.TextView;
- import com.google.android.gms.maps.CameraUpdateFactory;
- import com.google.android.gms.maps.model.LatLng;
- import com.taxipixi.Constants;
- import com.taxipixi.entity.CabType;
- import com.taxipixi.entity.Order;
- import com.taxipixi.incarapp.R;
- import com.taxipixi.incarapp.api.MenuListeners;
- import com.taxipixi.incarapp.api.SystemTime;
- import com.taxipixi.incarapp.api.Timeformatter;
- import com.taxipixi.incarapp.application.IncarApp;
- import com.taxipixi.incarapp.fare.JourneyInfo;
- import com.taxipixi.map.ExtendedMapFragment;
- import com.taxipixi.navigation.OverlaysForRouteGenerator;
- import com.taxipixi.utils.DecimalFormating;
- import com.taxipixi.widget.AddressWidget;
- import java.math.BigDecimal;
- import java.text.SimpleDateFormat;
- import java.util.Locale;
- public class JourneyInfoWidget_M extends LinearLayout
- {
- private ViewGroup contactInfo;
- private AddressWidget origin;
- private AddressWidget destination;
- private ExtendedMapFragment mapFragment;
- private ImageView navigate;
- //public LinearLayout dropOff;
- private OverlaysForRouteGenerator overlaysForRouteGenerator;
- private TextView time;
- //, fare_per_min;
- private TextView distance;
- private TextView packageDuration;
- //private TextView fee;
- //private TextView total;
- //public TextView perKmCost;
- //public TextView fare_10_frst_value;
- //public TextView min_km_value;
- //public TextView fare_after_min_km, immediate_future;
- //public LinearLayout cabFareInfoLayout;
- //public RelativeLayout cabFareHireLayout,plus_hire_time;
- boolean isEnglish = false;
- //private SimpleDateFormat dateFormatter = new SimpleDateFormat("d MMMM, hh:mm aa"); //changed to 24 hour format
- private SimpleDateFormat dateFormatter = new SimpleDateFormat("d MMMM, HH:mm aa");
- public JourneyInfoWidget_M(Context context) {
- super(context);
- initializeComponent();
- }
- public JourneyInfoWidget_M(Context context, AttributeSet attrs) {
- super(context, attrs);
- initializeComponent();
- }
- @TargetApi(Build.VERSION_CODES.HONEYCOMB)
- public JourneyInfoWidget_M(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- initializeComponent();
- }
- private void initializeComponent() {
- /*dropOff = (LinearLayout) findViewById(R.id.drop_off);
- dropOff = (LinearLayout) findViewById(R.id.drop_off);*/
- LayoutInflater.from(getContext()).inflate(R.layout.new_widget_journey_info, this);
- //contactInfo = (ViewGroup) findViewById(R.id.contact_info);
- FragmentActivity fa = (FragmentActivity) getContext();
- try{
- mapFragment = (ExtendedMapFragment) fa.getSupportFragmentManager().findFragmentById(R.id.mapfragment);
- View zoomControls = mapFragment.getView().findViewById(0x1);
- if (zoomControls != null && zoomControls.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
- // ZoomControl is inside of RelativeLayout
- RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) zoomControls.getLayoutParams();
- // Align it to - parent bottom above Buttons
- //params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, R.id.actionButtonsLayout);
- final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
- getResources().getDisplayMetrics());
- final int marginBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 120, getResources().getDisplayMetrics());
- params.setMargins(margin, margin, margin, marginBottom);
- zoomControls.setLayoutParams(params);
- }
- mapFragment.getView().setVisibility(View.GONE);
- }
- catch(Exception ex){
- ex.printStackTrace();
- }
- origin = (AddressWidget) findViewById(R.id.origin);
- destination = (AddressWidget) findViewById(R.id.destination);
- time = (TextView) findViewById(R.id.time);
- // distance = (TextView) findViewById(R.id.distance);
- packageDuration = (TextView) findViewById(R.id.package_duration);
- /*fee = (TextView) findViewById(R.id.fee);
- total = (TextView) findViewById(R.id.total);
- perKmCost = (TextView) findViewById(R.id.perKmFare);
- fare_10_frst_value = (TextView) findViewById(R.id.fare_10_frst_value);
- min_km_value = (TextView) findViewById(R.id.min_km_value);
- fare_after_min_km = (TextView) findViewById(R.id.fare_after_min_km);
- cabFareInfoLayout = (LinearLayout) findViewById(R.id.cabFareInfoLayout);
- cabFareHireLayout = (RelativeLayout) findViewById(R.id.cabFareHireLayout);
- plus_hire_time = (RelativeLayout) findViewById(R.id.plus_hire_time);
- fare_per_min = (TextView) findViewById(R.id.fare_per_min);*///Deleted by Mechele
- //immediate_future = (TextView) findViewById(R.id.immediate_future);
- navigate = (ImageView) findViewById(R.id.navigate);
- navigate.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View view) {
- setViewExpanded(!isViewExpanded());
- }
- });
- // MenuListeners.registerNewDestinationReceiverAndSetter(destination.addressTextView);//transpher texview for setting destination in case of update
- }
- public void setViewExpanded(boolean closed) {
- LatLng latLng = null;
- String description="";
- if(origin!=null && origin.getPlace()!=null){
- latLng = origin.getPlace().getLatLng();
- description = origin.getPlace().getDescription() ;
- }
- boolean activityFound = true;
- if(latLng!=null){
- try{
- String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?daddr=%f,%f (%s)", latLng.latitude, latLng.longitude, description);
- Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
- intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
- getContext().startActivity(intent);
- IncarApp.isNewOrderNeedToBeShown = false;
- }catch (Exception ex){
- activityFound = false;
- IncarApp.isNewOrderNeedToBeShown = true;
- }
- }
- if(activityFound)
- return;
- /*int currVisibility = contactInfo.getVisibility();
- if (closed && currVisibility != View.VISIBLE) {
- contactInfo.setVisibility(View.VISIBLE);
- if(mapFragment!=null)
- mapFragment.getView().setVisibility(View.GONE);
- } else if (!closed && currVisibility == View.VISIBLE) {
- contactInfo.setVisibility(View.GONE);
- if(mapFragment!=null)
- mapFragment.getView().setVisibility(View.VISIBLE);
- }*/
- }
- public boolean isViewExpanded() {
- return contactInfo.getVisibility() == View.VISIBLE;
- }
- public void setJourneyInfo(JourneyInfo journeyInfo, CabType cabType) {
- String currency = cabType.getCurrency();
- isEnglish = cabType.isEnglish();
- origin.onNewPlace(journeyInfo.getPickup(), true);
- if (destination!=null) {
- destination.onNewPlace(journeyInfo.getDestination(), true);
- //destination.setIcon(R.drawable.ic_drop);
- } else {
- //dropOff.setVisibility(GONE);
- }
- if(journeyInfo.getBookingType()==null || journeyInfo.getBookingType().equals(Constants.HOURLY)){
- packageDuration.setVisibility(VISIBLE);
- String packageDetails = journeyInfo.getPackageType();
- if(packageDetails.equalsIgnoreCase("FULL DAY")){
- int days = journeyInfo.getDays();
- String daysString = " DAYS" ;
- if(days==1)
- daysString = " DAY";
- packageDetails = days + daysString;
- }
- if(journeyInfo.getDistanceInMeters()>0){
- packageDetails = packageDetails + " /" + journeyInfo.getDistanceInKM() + " KM";
- }
- packageDuration.setText(packageDetails);
- // destination.setAddressText(packageDetails, true);
- // destination.setIcon(R.drawable.package_duration);
- }
- if (journeyInfo.getRequestedPickupTime() == null) {
- time.setText(
- getContext().getString(R.string.confirmation_time_asap));
- } else {
- long timeLong = journeyInfo.getRequestedPickupTime();
- // time.setText(setDayTimeColor(Timeformatter.getDateTimeFromSeconds(timeLong, currency)));
- long networkTS = SystemTime.getSystemTime();
- /*if(timeLong*1000 <= networkTS + 45*60*1000){
- time.setText(setDayTimeColor(Timeformatter.getDateTimeFromSeconds(timeLong, currency), true));
- Drawable img = getContext().getResources().getDrawable( R.drawable.immediate_order_icon );
- immediate_future.setCompoundDrawablesWithIntrinsicBounds( img, null, null, null);
- immediate_future.setText(getResources().getString(R.string.immediate_order));
- }else{
- time.setText(setDayTimeColor(Timeformatter.getDateTimeFromSeconds(timeLong, currency), false));
- Drawable img = getContext().getResources().getDrawable( R.drawable.future_order );
- immediate_future.setCompoundDrawablesWithIntrinsicBounds( img, null, null, null);
- immediate_future.setText(getResources().getString(R.string.future_order));
- immediate_future.setTextColor(Color.BLUE);
- }*/
- }
- /*if(journeyInfo.getFee().floatValue()<=0) {
- total.setText(currency +" "+ DecimalFormating.getStringFormatted(journeyInfo.getCost()));
- fee.setVisibility(View.GONE);
- }else{
- BigDecimal feeAmount = journeyInfo.getFee();
- fee.setText(currency+" " + DecimalFormating.getStringFormatted(feeAmount));
- if(currency.equalsIgnoreCase("RM")){
- fee.setCompoundDrawablesWithIntrinsicBounds(R.drawable.call_fee,0,0,0);
- } else if(Locale.getDefault().equals("ru")){
- fee.setCompoundDrawablesWithIntrinsicBounds(R.drawable.fee_ru,0,0,0);
- } else if(Locale.getDefault().equals("az") || Locale.getDefault().equals("tr")){
- fee.setCompoundDrawablesWithIntrinsicBounds(R.drawable.fee_az,0,0,0);
- }
- if(journeyInfo.getHideFee()==1 || cabType.getHideFeeInfo()==1)
- fee.setVisibility(View.GONE);
- else
- fee.setVisibility(View.VISIBLE);
- }*///Deleted by Mechele
- /*if (journeyInfo.getDestination()==null && journeyInfo.getBookingType().equals(Constants.POINT_TO_POINT)) {
- total.setText("-");
- distance.setText("");
- total.setVisibility(View.GONE);
- }else {
- BigDecimal journeyCost = journeyInfo.getCost();
- total.setText(currency + " " + DecimalFormating.getStringFormatted(journeyCost));
- distance.setText(setTimeOrAdressColor(journeyInfo.getDistanceInKM() +" KM"));
- total.setVisibility(View.VISIBLE);
- }*/
- /*if(currency.equals("RM") || !journeyInfo.getBookingType().equals(Constants.POINT_TO_POINT) || journeyInfo.getInitialFare()==null ){
- perKmCost.setText(currency+ " " + DecimalFormating.getStringFormatted(journeyInfo.getPerKMFare())+"/-");
- perKmCost.setVisibility(View.VISIBLE);
- cabFareInfoLayout.setVisibility(View.GONE);
- }
- else {
- cabFareInfoLayout.setVisibility(View.VISIBLE);
- fare_10_frst_value.setText(setRsFareColorFont(currency+ " " + DecimalFormating.getStringFormatted(journeyInfo.getInitialFare())));
- if(journeyInfo.getMinimum()>0)
- min_km_value.setText(setRsFareColorFont(getContext().getString(R.string.first) + " " + journeyInfo.getMinimum() + "KM "));
- else
- min_km_value.setText(getContext().getString(R.string.initial_charge));
- fare_after_min_km.setText(setRsFareColorFont(currency+ " " + DecimalFormating.getStringFormatted(journeyInfo.getPerKMFare())));
- perKmCost.setVisibility(View.GONE);
- if(journeyInfo.getHireTimeFareDay()!=null && journeyInfo.getHireTimeFareDay().doubleValue()>0){
- fare_per_min.setText(setRsFareColorFont(currency + " " + DecimalFormating.getStringFormatted(journeyInfo.getHireTimeFareDay())));
- cabFareHireLayout.setVisibility(View.VISIBLE);
- plus_hire_time.setVisibility(View.VISIBLE);
- }
- }*///Deleted by Mechele
- if(mapFragment!=null)
- mapFragment.getMap().moveCamera(CameraUpdateFactory.newLatLng(journeyInfo.getPickup().getLatLng()));
- }
- public AddressWidget getDestinationTextView(){
- return destination;
- }
- public ExtendedMapFragment getMapView() {
- return mapFragment;
- }
- private Spannable setDayTimeColor (String s, boolean red){//setting red color for date and time based upon ", " position from time formater
- int color = Color.RED;
- if(!red)
- color = Color.BLUE ;
- int index = s.indexOf(", ");
- Spannable span = new SpannableString(s);
- span.setSpan(new ForegroundColorSpan(color), 0, index-3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- span.setSpan(new AbsoluteSizeSpan(30, true), 0, index-3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- span.setSpan(new ForegroundColorSpan(color), index+2, index+7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- span.setSpan(new AbsoluteSizeSpan(30, true), index+2, index+7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- return span;
- }
- private Spannable setTimeOrAdressColor (String s){
- int index = s.indexOf(" ");
- Spannable spannable = new SpannableString(s);
- spannable.setSpan(new ForegroundColorSpan(Color.RED), 0, index, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- spannable.setSpan(new AbsoluteSizeSpan(30, true), 0, index, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- return spannable;
- }
- private Spannable setRsFareColorFont (String s){
- int index = s.indexOf(" ");
- Spannable spannable = new SpannableString(s);
- spannable.setSpan(new ForegroundColorSpan(Color.RED), index+1, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- return spannable;
- }
- }
Add Comment
Please, Sign In to add comment