| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 
 | package com.mycoprod.akhetib.mycoprod;
 
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.TextView;
import android.widget.Toast;
 
import java.util.ArrayList;
 
public class DisplayMyCoProd extends Activity {
 
    public static final String POS_EXCEL = "posExcel";
    public static final String RETOUR = "retourArriere";
 
    static final int ETATRESULT = 1;  // The request code
 
 
    static int ligneMasteris = 16, ligneSLE = 16,ligneSLT = 16, lignePACA = 16, ligneThionville = 38, ligneINFRA = 38;
    static int ligneAppros = 38,lignePlanification = 38,ligneMethodes = 60,ligneCopro = 60,ligneMOD = 60,ligneInstallationsOutillages = 60,ligneRAEC = 82,ligneMotifInconnu = 82;
    static int cptRdvOK = 0;
 
    TextView txtv;
    String pathFile;
 
    public ArrayList<Locom> myList;
 
    LocomAdpater dataAdapter;
    ListView listView;
    SearchView sv;
 
    static boolean i = true;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.display_my_co_prod);
 
        Intent intent = getIntent();
        pathFile = intent.getStringExtra("EXTRA_pathFile");
 
        txtv = (TextView) findViewById(R.id.textView);
        txtv.setText(pathFile);
 
        listView = (ListView) findViewById(R.id.display_listview);
        sv = (SearchView) findViewById(R.id.searchView);
 
        myList = new ArrayList<Locom>();
        dataAdapter = new LocomAdpater(this, myList);
 
        listView.setAdapter(dataAdapter);
 
        listView.setOnItemClickListener(new ItemListView());
 
 
        DownLoadExcel dlExcel = new DownLoadExcel(DisplayMyCoProd.this, pathFile);
        dlExcel.execute();
 
        sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String text) {
                return false;
            }
 
            @Override
            public boolean onQueryTextChange(String query) {
                dataAdapter.getFilter().filter(query);
                return false;
            }
        });
    }
 
    public void populate(ArrayList<Locom> locom) {
        //this.dataAdapter.clear();
        this.dataAdapter.addAll(locom);
        this.dataAdapter.notifyDataSetChanged();
    }
 
 
    private class ItemListView implements AdapterView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
 
            ViewGroup vg = (ViewGroup) view;
            TextView tv_e = (TextView) vg.findViewById(R.id.tv_engin);
            TextView tv_v = (TextView) vg.findViewById(R.id.tv_visite);
 
            String engin = tv_e.getText().toString();
            String visite = tv_v.getText().toString();
 
            if (engin.equals("") || visite.equals("")) {
                //DO NOTHING
                Toast.makeText(DisplayMyCoProd.this, "Aucun élément sélectionné !", Toast.LENGTH_SHORT).show();
 
            } else {
                Toast toast = Toast.makeText(DisplayMyCoProd.this, engin + " : " + visite, Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0);
                toast.show();
 
 
 
                Intent ChoixDMCPActivity = new Intent(DisplayMyCoProd.this, HMoment.class);
                ChoixDMCPActivity.putExtra("EXTRA_PATHFILE", pathFile);
                ChoixDMCPActivity.putExtra("EXTRA_TV_E", engin);
                ChoixDMCPActivity.putExtra("EXTRA_TV_V", visite);
                ChoixDMCPActivity.putExtra("POSITION", position);
                Toast.makeText(DisplayMyCoProd.this, "position = "+position, Toast.LENGTH_SHORT).show();
                Toast.makeText(DisplayMyCoProd.this, "id="+id, Toast.LENGTH_SHORT).show();
                startActivityForResult(ChoixDMCPActivity, ETATRESULT);
 
            }
        }
    }
 
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == ETATRESULT) {
            if (resultCode == Activity.RESULT_OK) {
 
                Bundle bundle = data.getExtras();
                ArrayList<Locom> myListComReturned = bundle.getParcelableArrayList("ETATRESULT");
                populate(myListComReturned);
 
                System.out.println("ArrayList RESULT OK");
            } else if (resultCode == 0) {
                System.out.println("ArrrayList RESULT CANCELLED");
            }
        }
    }
 
    public void displayFormulaire(View view) {
        Intent FormulaireActivity = new Intent(this, Formulaire.class);
        FormulaireActivity.putExtra("EXTRA_PATHFILE", pathFile);
        startActivity(FormulaireActivity);
    }
 
    public void retourArriere(View view) {
        SharedPreferences sharedPref = getSharedPreferences(RETOUR, Activity.MODE_PRIVATE);
        String nomRetour = sharedPref.getString("nomRetour","");
 
        loadPosExcel();
 
        switch (nomRetour) {
            case "MASTERIS":
                ligneMasteris--;
                break;
 
            case "THIONVILLE":
                ligneThionville--;
                break;
 
            case "STF ELECTRIQUE":
                ligneSLE--;
                break;
 
            case "SLT":
                ligneSLT--;
                break;
 
            case "PACA":
                lignePACA--;
                break;
 
            case "INFRA":
                ligneINFRA--;
                break;
 
            case "Appros":
                ligneAppros--;
                break;
 
            case "Planification":
                lignePlanification--;
                break;
 
            case "Méthodes":
                ligneMethodes--;
                break;
 
            case "Coprod":
                ligneCopro--;
                break;
 
            case "MOD":
                ligneMOD--;
                break;
 
            case "Installations / Outillages":
                ligneInstallationsOutillages--;
                break;
 
            case "RA/EC : ":
                ligneRAEC--;
                break;
 
            case "Motif Inconnu : ":
                ligneMotifInconnu--;
                break;
 
            default:
                Toast.makeText(this, "Erreur la dernière ligne n'a pas été effacée :" + nomRetour, Toast.LENGTH_LONG).show();
                System.out.println("Erreur la dernière ligne n'a pas été effacée :" + nomRetour);
                break;
 
        }
 
        Toast.makeText(DisplayMyCoProd.this, "La dernière saisie a été effacée ! : " + nomRetour, Toast.LENGTH_LONG).show();
 
        savePosExcel();
    }
 
 
    private void savePosExcel() {
 
        SharedPreferences sharedPref = getSharedPreferences(POS_EXCEL, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPref.edit();
 
        editor.putInt("positionExcelMas", ligneMasteris);
        editor.putInt("positionExcelSLE", ligneSLE);
        editor.putInt("positionExcelSLT", ligneSLT);
        editor.putInt("positionExcelPACA", lignePACA);
        editor.putInt("positionExcelThi", ligneThionville);
        editor.putInt("positionExcelINF", ligneINFRA);
        editor.putInt("positionExcelAPP", ligneAppros);
        editor.putInt("positionExcelPLA", lignePlanification);
        editor.putInt("positionExcelMET", ligneMethodes);
        editor.putInt("positionExcelCOP", ligneCopro);
        editor.putInt("positionExcelMOD", ligneMOD);
        editor.putInt("positionExcelINSOUT", ligneInstallationsOutillages);
        editor.putInt("positionExcelRAEC", ligneRAEC);
        editor.putInt("positionExcelMOTINC", ligneMotifInconnu);
        editor.putInt("rdvTraite", cptRdvOK);
        editor.commit();
    }
 
    private void loadPosExcel() {
        SharedPreferences sharedPref = getSharedPreferences(POS_EXCEL, Activity.MODE_PRIVATE);
 
        int posMas = sharedPref.getInt("positionExcelMas", 16);
        int posSLE = sharedPref.getInt("positionExcelSLE", 16);
        int posSLT = sharedPref.getInt("positionExcelSLT", 16);
        int posPACA = sharedPref.getInt("positionExcelPACA", 16);
        int posThi = sharedPref.getInt("positionExcelThi", 38);
        int posINF = sharedPref.getInt("positionExcelINF", 38);
        int posAPP = sharedPref.getInt("positionExcelAPP", 38);
        int posPLA = sharedPref.getInt("positionExcelPLA", 38);
        int posMET = sharedPref.getInt("positionExcelMET", 60);
        int posCOP = sharedPref.getInt("positionExcelCOP", 60);
        int posMOD = sharedPref.getInt("positionExcelMOD", 60);
        int posINSOUT = sharedPref.getInt("positionExcelINSOUT", 60);
        int posRAEC = sharedPref.getInt("positionExcelRAEC", 82);
        int posMOTINC = sharedPref.getInt("positionExcelMOTINC", 82);
        int rdvOK = sharedPref.getInt("rdvTraite", 0);
 
        ligneMasteris = posMas;
        ligneSLE = posSLE;
        ligneSLT = posSLT;
        lignePACA = posPACA;
        ligneThionville = posThi;
        ligneINFRA = posINF;
        ligneAppros = posAPP;
        lignePlanification = posPLA;
        ligneMethodes = posMET;
        ligneCopro = posCOP;
        ligneMOD = posMOD;
        ligneInstallationsOutillages = posINSOUT;
        ligneRAEC = posRAEC;
        ligneMotifInconnu = posMOTINC;
        cptRdvOK = rdvOK;
    }
} |