Exemplo n.º 1
0
 private void loadSymbols() {
   Document document = XMLParser.openXML("braille.xml");
   if (document != null) {
     boolean loading = true;
     int index = 1;
     while (loading) {
       NodeList chainNode = XMLParser.xpath(document, "/braille/symbol[" + index + "]/chain");
       NodeList asciiNode = XMLParser.xpath(document, "/braille/symbol[" + index + "]/ascii");
       if (chainNode.item(0) != null) {
         String chain = chainNode.item(0).getNodeValue();
         char ascii = (char) Integer.valueOf(asciiNode.item(0).getNodeValue()).intValue();
         BrailleSymbol symbol = new BrailleSymbol(chain, ascii);
         _symbols.insert(symbol);
         index++;
       } else {
         loading = false;
       }
     }
   }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.emprunt_xml);
    String user = this.getIntent().getStringExtra("USER");
    TextView textUser = (TextView) findViewById(R.id.textViewEmprunts);

    textUser.setText("Emprunts de " + user);
    XMLParser XMl = new XMLParser();
    Livre livre = new Livre();
    InputStream inputStream = getResources().openRawResource(R.raw.livre);
    // InputStreamReader ipsr = new InputStreamReader(inputStream);
    // BufferedReader br = new BufferedReader(ipsr);
    try {
      livre = XMl.parse(inputStream);
    } catch (XmlPullParserException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    TextView livreUser = (TextView) findViewById(R.id.Livre);
    livreUser.setText(livre.toString());

    livreUser.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(EmpruntsXML.this);
            builder.setMessage("Saisir la durée avant déclenchement (en sec)");
            builder.setTitle("PARAMETRER UNE ALERTE");

            final EditText dureeChoisie = new EditText(EmpruntsXML.this);
            LinearLayout.LayoutParams lp =
                new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
            dureeChoisie.setLayoutParams(lp);
            builder.setView(dureeChoisie);

            builder.setPositiveButton(
                "Valider l'alerte",
                new DialogInterface.OnClickListener() {

                  public void onClick(DialogInterface dialog, int whichButton) {
                    String dureeAlerte = dureeChoisie.getText().toString();
                    int duree = Integer.parseInt(dureeAlerte);
                    Intent intent = new Intent(EmpruntsXML.this, TimerNotif.class);

                    PendingIntent pendingIntent =
                        PendingIntent.getBroadcast(
                            getApplicationContext(), 1, intent, PendingIntent.FLAG_ONE_SHOT);

                    AlarmManager alarmManager =
                        (AlarmManager) getSystemService(Context.ALARM_SERVICE);
                    alarmManager.set(
                        AlarmManager.RTC_WAKEUP,
                        System.currentTimeMillis() + (1000 * duree),
                        pendingIntent);
                  }
                });
            builder.show();
          }
        });

    livreUser.setOnLongClickListener(
        new View.OnLongClickListener() {
          @Override
          public boolean onLongClick(View v) {
            AlertDialog.Builder builderPenalite = new AlertDialog.Builder(EmpruntsXML.this);
            builderPenalite.setMessage("Pénalités sur les emprunts en retard");
            builderPenalite.setTitle("VOIR MES PENALITES");

            builderPenalite.setPositiveButton(
                "OK",
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {
                    Intent intent = new Intent(EmpruntsXML.this, Penalites.class);
                    startActivity(intent);
                  }
                });

            builderPenalite.setNegativeButton(
                "Annuler",
                new DialogInterface.OnClickListener() {

                  public void onClick(DialogInterface dialog, int whichButton) {}
                });

            builderPenalite.show();
            return false;
          }
        });
  }