예제 #1
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {

    View vi = convertView;
    if (convertView == null) vi = inflater.inflate(R.layout.list_row, null);

    TextView title = (TextView) vi.findViewById(R.id.title);
    TextView tvTesto = (TextView) vi.findViewById(R.id.subtitle);
    ImageView foto = (ImageView) vi.findViewById(R.id.list_image);
    facebook = (ImageView) vi.findViewById(R.id.facebook);
    day = data.get(position);

    if (day.getTesto().length() > 19) {
      testoNota = day.getTesto().substring(0, 20) + "...";
    } else {
      testoNota = day.getTesto();
    }
    title.setText(testoNota);
    title.setTypeface(font);
    tvTesto.setText(day.getData());
    tvTesto.setTypeface(font);
    facebook.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            Log.e("qui entra?", "onclick");
            share(day);
          }
        });

    if (day.getNomefoto().equals("NOFOTO")) {
      foto.setImageResource(R.drawable.avatar);
      Log.e("entra nel getnomefoto?", "boh");
    } else {
      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inJustDecodeBounds = true;
      BitmapFactory.decodeFile(day.getNomefoto(), options);
      // resize the picture for memory.
      int width = options.outWidth / 240 + 1;
      int height = options.outHeight / 320 + 1;
      int sampleSize = Math.max(width, height);
      options.inSampleSize = sampleSize;
      options.inJustDecodeBounds = false;
      // convert to bitmap with declared size.
      Bitmap immagine = BitmapFactory.decodeFile(day.getNomefoto(), options);
      foto.setImageBitmap(immagine);
    }
    return vi;
  }
예제 #2
0
  public void share(Day giorno) {

    Bundle params = new Bundle();
    params.putString("name", "Ecco cosa mi è successo " + giorno.getData());
    params.putString("caption", giorno.getTesto());
    params.putString("description", "DearDiary è il tuo diario quotidiano su Android!");
    params.putString("link", "https://www.facebook.com/peppeuz");
    params.putString("picture", "http://imgbin.org/images/12252.png");
    if (Session.getActiveSession() == null) {
      alert();

    } else {
      WebDialog feedDialog =
          (new WebDialog.FeedDialogBuilder(activity, Session.getActiveSession(), params))
              .setOnCompleteListener(
                  new OnCompleteListener() {

                    @Override
                    public void onComplete(Bundle values, FacebookException error) {
                      if (error == null) {

                        final String postId = values.getString("post_id");
                        if (postId != null) {
                          Toast.makeText(
                                  activity,
                                  "Post effettuato correttamente!"
                                  // + postId

                                  ,
                                  Toast.LENGTH_SHORT)
                              .show();
                        } else {
                          // User clicked the Cancel button
                          Toast.makeText(
                                  activity.getApplicationContext(),
                                  "Post annullato",
                                  Toast.LENGTH_SHORT)
                              .show();
                        }
                      } else if (error instanceof FacebookOperationCanceledException) {
                        // User clicked the "x" button
                        Toast.makeText(
                                activity.getApplicationContext(),
                                "Post annullato",
                                Toast.LENGTH_SHORT)
                            .show();
                      } else {
                        // Generic, ex: network error
                        Toast.makeText(
                                activity.getApplicationContext(),
                                "Si è presentato un errore durante la pubblicazione",
                                Toast.LENGTH_SHORT)
                            .show();
                      }
                    }
                  })
              .build();
      feedDialog.show();
    }
  }