ViewLabel is not refreshed after returning from another Activity

25 views
Skip to first unread message

Ale Perez

unread,
Aug 4, 2015, 9:06:43 AM8/4/15
to Nutiteq-dev
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

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

And there is the another activity, a Notes Management System.



I post content of onActivityResult in order you see, that I get the right value


    08-04 14:27:25.067: I/WmsMapActivity(13656): onActivityResult:: requestCode: 12

    08-04 14:27:25.067: I/WmsMapActivity(13656): onActivityResult:: requestCode: 12 result_ok

    08-04 14:27:25.067: I/WmsMapActivity(13656): onActivityResult:: dataReturnedIntent != null

    08-04 14:27:25.067: I/WmsMapActivity(13656): onActivityResult:: dataReturnedIntent != null textnote_number: 4



That's my Code in onActivityResult
                         ...
                   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;
                       ...



And that's the code to define the 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 there my popup_field_newer Layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relLayoutFieldLabel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@color/white" >
    
    <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>



</RelativeLayout>




Mark

unread,
Aug 4, 2015, 9:55:04 AM8/4/15
to Nutiteq-dev
Hi Ale,

this happens only after the app is paused and then resumed? As a workaround, perhaps you can simply re-create the ViewLabel and replace the old label of the selected vector element when app is resumed?

Regards,
Mark

Ale Perez

unread,
Aug 4, 2015, 10:21:14 AM8/4/15
to Nutiteq-dev
Hi Mark, I have logged and I get that

08-04 14:27:25.033: I/TextNoteActivity(13656): onClick::save_note note_id: 4 note: [FARMGUID:1FCD3C7E-7450-4CE0-A851-DCE516D36333, FIELDGUID:975D1A6F-6DC5-4A0A-ACE8-B0DC183BB3F5, TIMESTAMP:2015-08-04 14:27:24.998, Filename:/storage/emulated/0/MyEO/texts/text_20150804_142725.txt, CREATION_DATE:2015-08-04 14:27:24.998, Notename:tzu, MODIFICATION_DATE:2015-08-04 14:27:24.998, FARMNAME:2_Rauwolf, FIELDNAME:Am Dietweg, DataType:TextData, ContentType:, ]
08-04 14:27:25.039: I/TextNoteActivity(13656): count::result: 4
08-04 14:27:25.044: I/TextNoteActivity(13656): onPause::0
08-04 14:27:25.067: I/WmsMapActivity(13656): onActivityResult:: requestCode: 12
08-04 14:27:25.067: I/WmsMapActivity(13656): onActivityResult:: requestCode: 12 result_ok
08-04 14:27:25.067: I/WmsMapActivity(13656): onActivityResult:: dataReturnedIntent != null
08-04 14:27:25.067: I/WmsMapActivity(13656): onActivityResult:: dataReturnedIntent != null textnote_number: 4
08-04 14:27:25.067: I/WmsMapActivity(13656): onRestart
08-04 14:27:25.075: I/WmsMapActivity(13656): onStart:: locationCircle: com.nutiteq.utils.overlay.MyLocationCircle@1e719779
08-04 14:27:25.083: I/WmsMapActivity(13656): setSettings::rotation: false
08-04 14:27:25.083: I/WmsMapActivity(13656): setSettings::show_my_location: false
08-04 14:27:25.083: I/WmsMapActivity(13656): setSettings::self_positioning: false
08-04 14:27:25.083: I/WmsMapActivity(13656): initGPS::0 
08-04 14:27:25.094: I/MyLocationCircle(13656): update:: coordinates (0,0)
08-04 14:27:25.099: I/WmsMapActivity(13656): onResume:: #myPolygons: 18
08-04 14:27:25.099: I/WmsMapActivity(13656): onResume:: #myPolygons: 18
08-04 14:27:25.101: I/WmsMapActivity(13656): onResume:: #myPolygons: 18

I will try to workaround with requestLayout() instead with invalidate. I'll tell you later how it was.

Kind Regards


...
Reply all
Reply to author
Forward
0 new messages