0

I have developed a ViewLabel with a custom View for my Polygons and I can show pretty well but when I go to another Activity ( through startActivityForResult() ) and return to my Map Activity with a value to update a TextView of this custom view I get the ViewLabel as before. I tried to invalidate before and after I set the number of notes but unsuccessful.

Can you tell me what I am making wrong?

That's the aspect before and after going to the another Activity

enter image description here

And here the Aspect of the other Activity, as you can see, there are 4 Notes

enter image description here

I tried to set the Note's count to the corresponding TextView but it is not showing the properly value

The Log of my onActivityResult Code shows, I can properly pass the value but the View is never refreshed.

I/WmsMapActivity(13656): onActivityResult:: requestCode: 12

I/WmsMapActivity(13656): onActivityResult:: requestCode: 12 result_ok

I/WmsMapActivity(13656): onActivityResult:: dataReturnedIntent != null

I/WmsMapActivity(13656): onActivityResult:: dataReturnedIntent != null textnote_number: 4

And it's code

                         ...
                case Constants.REQUEST_NOTES :
                      Log.i(TAG, "onActivityResult:: requestCode: "+Constants.REQUEST_NOTES);
                     if ( resultCode == RESULT_OK) {

                                    Log.i(TAG, "onActivityResult:: requestCode: "+Constants.REQUEST_NOTES+" result_ok");

                                    if (dataReturnedIntent != null) {
                                           Log.i(TAG, "onActivityResult:: dataReturnedIntent != null");
                                        String textnote_number = dataReturnedIntent.getStringExtra(Constants.TEXTNOTES_NUMBER);
                                     Log.i(TAG, "onActivityResult:: dataReturnedIntent != null textnote_number: "+textnote_number);

                                      //textNotesTV.invalidate();
                                       textnotesTV.setText(textnote_number);
                                       //textnotesTV.invalidate();
                                 } else {
                                            Log.i(TAG, "onActivityResult:: dataReturnedIntent == null");
                                }
                           } else {
                                    Log.i(TAG, "onActivityResult:: resultCode != RESULT_OK");
                           }                               
                    break;
                   ...

Here the way I create a Polygon with its corresponding Custom ViewLabel

    protected void createPolygon(String id, String fieldguid, String fieldname, String farmguid, String farmname,  
                            PolygonStyle polygonStyle, TextStyle textStyle, 
                            double[][] coordinates, String latitude, String longitude, 
                            int state, int color, ArrayList<HashMap<String, String>> processingHistory, 
                            int bioIndTreatment, String bioindcrop, String bioindboundary, String croptype,
                            boolean shown) {

    // ****************
    boolean bioIndBoundaryValue           = true, bioIndCropValue    = true; 
    boolean existingBioIndBoundary        = true, existingBioIndCrop = true;        


    ListView      history_list_view;

    noteParamList = new ArrayList<String>();
    noteParamList.add("unclicked");           //0
    noteParamList.add(fieldguid);             //1
    noteParamList.add(fieldname);             //2
    noteParamList.add(farmguid);              //3
    noteParamList.add(farmname);              //4
    noteParamList.add(latitude);              //5
    noteParamList.add(longitude);             //6
    noteParamList.add(String.valueOf(color)); //7 color = original_color

    Log.i(TAG, "CreatePolygon:note: "+noteParamList.toString());
    // We turn into vividsolutions Object, so they provide getArea Method
    //
    /** User Data **/ // guid

    //pol.setId(Long.parseLong(id));   

    //Log.i(TAG, "CreatePolygon fieldname: "+fieldname + " processingHistory: "+processingHistory);

    Projection projGeo                    = geomLayer.getProjection();
    Projection projText                   = textLayer.getProjection();

    ArrayList<MapPos> outerPoses          = new ArrayList<MapPos>();
    MapPos center                         = null;

    for(double[] coord:coordinates){
        outerPoses.add(projGeo.fromWgs84((float)coord[0],(float)coord[1]));
    }

    //Setting Popup Label if we click the area
    LayoutInflater inflater               = (LayoutInflater) this.getLayoutInflater();

    labelView                             = inflater.inflate(R.layout.popup_field_newer, null, false);
    labelView.setBackgroundColor(Color.WHITE);


    // Title - Fieldname
    TextView titelTV                      = (TextView)labelView.findViewById(R.id.popup_fieldname);
    titelTV.setTextColor(Color.BLACK);
    titelTV.setText(fieldname);        

    // Croptype
    TextView croptypeTV                   = (TextView)labelView.findViewById(R.id.popup_croptype);
    croptypeTV.setTextColor(Color.BLACK);
    croptype                              =  ( (croptype != null && croptype.length()>0 ) ? "Croptype: "+croptype:"Croptype: No data");
    croptypeTV.setText(croptype);              

    //Farmname
    TextView farmTV                       = (TextView)labelView.findViewById(R.id.popup_farmname);
    farmTV.setTextColor(Color.BLACK);
    farmname                              = "Farm: "+farmname;
    farmTV.setText(farmname);        

    // Area
    TextView areaTV                       = (TextView)labelView.findViewById(R.id.popup_area);
    GeometricUtils geomUtils              = new GeometricUtils();
    double area                           = geomUtils.computeArea(coordinates); 

    // Ceiling 2 decimal places        
    BigDecimal bd                         = new BigDecimal(area);
    BigDecimal roundOff                   = bd.setScale(2, BigDecimal.ROUND_HALF_EVEN);
    area                                  = roundOff.doubleValue();
    String areaString                     = "Area(qm): "+String.valueOf(area);        

    areaTV.setTextColor(Color.BLACK);
    areaTV.setText(areaString);        


    // Table 
    ImageView cropIV                      = (ImageView)labelView.findViewById(R.id.row_crop_value);
    ImageView boundaryIV                  = (ImageView)labelView.findViewById(R.id.row_boundary_value);
    ImageView treatmentIV                 = (ImageView)labelView.findViewById(R.id.row_treatment_value);

    int resImgId = 0;


    // Bio Ind Treatment
    switch (state) {
        case 0 : case 1:
            resImgId = R.drawable.empty;
        break;
        case 2 :

            if ( bioIndTreatment >= 3 ) {
                resImgId     = R.drawable.red;

            } else if ( bioIndTreatment == 2){
                resImgId     = R.drawable.ambar;

            } else if ( bioIndTreatment == 1 ) {                
                resImgId     = R.drawable.green;

            } else if ( bioIndTreatment == 0 ) {
                resImgId     = R.drawable.empty;

            }

        break;
    }


    Log.i(TAG, "CreatePolygon: state: "+state+" fieldname: "+fieldname+" color: "+color +" resImgId: "+resImgId);

    Resources res                  = getResources();
    Bitmap bm                      = BitmapFactory.decodeResource(res, resImgId);
    treatmentIV.setImageBitmap(bm);


    // Bio Ind Croptype
    int resBioIndCrop              = R.drawable.no_processed_long_32;

    if ( bioindcrop != null && bioindcrop.length()>0 ) {
        bioIndCropValue            = Boolean.parseBoolean(bioindcrop);

        if ( bioIndCropValue  ) {
            resBioIndCrop          = R.drawable.red;

        } else {
            resBioIndCrop          = R.drawable.green;

        }

         Log.i(TAG, "createPolygon:: fieldname: "+fieldname+", bioIndCropValue: "+bioIndCropValue+" resBioIndCrop: "+resBioIndCrop);
    } else {
        existingBioIndCrop         = false;
    }

    bm                             = BitmapFactory.decodeResource(res, resBioIndCrop);
    cropIV.setImageBitmap(bm);      

    // Bio Ind Boundary
    int resBioIndBoundary          = R.drawable.no_processed_long_32;

    if ( bioindboundary != null && bioindboundary.length()>0 ) {
        bioIndBoundaryValue        = Boolean.parseBoolean(bioindboundary); 

        if ( bioIndBoundaryValue ) {
            resBioIndBoundary      = R.drawable.red;
        } else {
            resBioIndBoundary      = R.drawable.green;
        }       
         Log.i(TAG, "createPolygon:: fieldname: "+fieldname+", bioIndboundaryValue: "+bioIndBoundaryValue+" resBioIndBoundary: "+resBioIndBoundary);
    } else {
        existingBioIndBoundary     = false;
    }       

    bm                             = BitmapFactory.decodeResource(res, resBioIndBoundary);
    boundaryIV.setImageBitmap(bm);    

    // #Notes
    HashMap<String, String> settings = session.getSettings();

    textnotesTV             = (TextView)labelView.findViewById(R.id.popup_textnotes_btn);      
    setCountNotes(settings, textnotesTV, Constants.TEXTNOTES_NUMBER);

    picturenotesTV          = (TextView)labelView.findViewById(R.id.popup_picturenotes_btn);
    setCountNotes(settings, picturenotesTV, Constants.PICNOTES_NUMBER);        

    audionotesTV            = (TextView)labelView.findViewById(R.id.popup_audionotes_btn);
    setCountNotes(settings, audionotesTV, Constants.AUDIONOTES_NUMBER);

    videonotesTV            = (TextView)labelView.findViewById(R.id.popup_videonotes_btn);
    setCountNotes(settings, videonotesTV, Constants.VIDEONOTES_NUMBER);

    RelativeLayout relLayoutFieldInfo     = (RelativeLayout)labelView.findViewById(R.id.relLayoutFieldInfo);  
    //relLayoutFieldInfo.setBackgroundColor(color);

    // Table Layout
    //TableLayout tableLayoutPopupField   = (TableLayout)labelView.findViewById(R.id.tableLayoutPopupField);



    LabelStyle labelStyle                 = LabelStyle.builder().setBackgroundColor(Color.WHITE).
    setEdgePadding((int) (12 * scale)).
    setLinePadding((int) (6 * scale)).
    setAlpha(0.85f). // half transparent, half opaque!!! 
    setTitleFont(Typeface.create("Arial", Typeface.BOLD),16 * scale).
    setTitleColor(Color.BLACK).
    setTitleAlign(Align.CENTER).
    build(); 


    ViewLabel fieldLabel                  = new ViewLabel(null, labelView, new Handler(), labelStyle );        

    // Making a resizable View

    RelativeLayout relLayout              = (RelativeLayout)labelView.findViewById(R.id.relLayoutFieldLabel); 
    relLayout.setBackgroundColor(Color.WHITE);
    relLayout.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                      MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    relLayout.layout(0, 0, labelView.getMeasuredWidth(), labelView.getMeasuredHeight());             

    // Without holes!
    Object obj                            = null;

    Polygon pol                           = new Polygon(outerPoses, fieldLabel, polygonStyle, noteParamList);


    // By Default : all invisible, just if we select one or several will be shown
    pol.setVisible(shown);
    //

    // Attach to geomLayer
    geomLayer.add(pol);
    myPolygons.add(pol);

    //Log.i(TAG,"createPolygon:: #myPolygons: "+myPolygons.size());


    double[] _centroid                    = centroid(pol);
    center                                = projText.fromWgs84(_centroid[0], _centroid[1]);

    Text textObj                          = new Text(center, fieldname, textStyle, null);
    textObj.setVisible(false);
    myPolygonTexts.add(textObj);

    textLayer.add(textObj);                                     
}

And the Layout 'popup_field_newer'

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    android:id="@+id/relLayoutFieldInfo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" >

    <LinearLayout
        android:id="@+id/linLayoutFieldInfoHeader"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="5dp"
        android:orientation="vertical" >

    <TextView
        android:id="@+id/popup_fieldname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Fieldname"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="24dp" />

    <TextView
        android:id="@+id/popup_croptype"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/popup_fieldname"
        android:layout_below="@+id/popup_fieldname"
        android:text="Crop : Triticale"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="18dp" />

    <TextView
        android:id="@+id/popup_farmname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/popup_croptype"
        android:layout_below="@+id/popup_croptype"
        android:text="Farm: Musterfarm"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="18dp" />

    <TextView
        android:id="@+id/popup_area"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/popup_farmname"
        android:layout_below="@+id/popup_farmname"
        android:text="Area(qm): 123.34"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="18dp" />        
    </LinearLayout>

    <ImageView
        android:id="@+id/popup_sat_pic"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="false"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="5dp"
        android:layout_toRightOf="@+id/linLayoutFieldInfoHeader"
        android:src="@drawable/sat_picture_no_available" />

</RelativeLayout>

<RelativeLayout
    android:id="@+id/relLayoutIndicatorsAndNotes"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignRight="@+id/relLayoutFieldInfo"
    android:layout_below="@+id/relLayoutFieldInfo"
    android:layout_marginTop="5dp" >

    <TextView
        android:id="@+id/popup_bioindicators"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/bio_explanation"
        android:layout_alignParentRight="true"
        android:text="BioIndicators"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="18dp" />

    <include
        android:id="@+id/popup_include_header_indicators"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/popup_bioindicators"
        android:layout_alignRight="@+id/bio_explanation"
        android:layout_below="@+id/popup_bioindicators"
        layout="@layout/header_indicators" />

    <include
        android:id="@+id/popup_include_value_indicators"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/popup_include_header_indicators"
        android:layout_alignRight="@+id/bio_explanation"
        android:layout_below="@+id/popup_include_header_indicators"
        layout="@layout/value_indicators" />

    <ImageView
        android:id="@+id/bio_explanation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="false"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/popup_include_value_indicators"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:src="@drawable/history_description_new" />

    <TextView
        android:id="@+id/popup_textnotes_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/bio_explanation"
        android:layout_alignRight="@+id/bio_explanation"
        android:layout_below="@+id/bio_explanation"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:text="Number of Text-Notes: " />

    <TextView
        android:id="@+id/popup_picturenotes_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/popup_textnotes_btn"
        android:layout_alignRight="@+id/popup_textnotes_btn"
        android:layout_below="@+id/popup_textnotes_btn"
        android:layout_marginBottom="5dp"
        android:text="Number of Picture-Notes: " />

    <TextView
        android:id="@+id/popup_videonotes_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/popup_textnotes_btn"
        android:layout_alignRight="@+id/popup_textnotes_btn"
        android:layout_below="@+id/popup_picturenotes_btn"
        android:layout_marginBottom="5dp"
        android:text="Number of Video-Notes: " />

    <TextView
        android:id="@+id/popup_audionotes_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/popup_textnotes_btn"
        android:layout_alignRight="@+id/popup_textnotes_btn"
        android:layout_below="@+id/popup_videonotes_btn"
        android:layout_marginBottom="5dp"
        android:text="Number of Audio-Notes: " />

</RelativeLayout>

Gödel77
  • 839
  • 3
  • 15
  • 27

1 Answers1

1

The topic is discussed in the nutiteq-dev list: https://groups.google.com/d/msg/nutiteq-dev/bTEb1ScZnbs/ivBTV4-3BgAJ

p.s. usually cross-posting only creates more confusion.

JaakL
  • 4,107
  • 5
  • 24
  • 37