Пример #1
0
  @Override
  protected void onListItemClick(ListView l, View v, final int position, long id) {
    super.onListItemClick(l, v, position, id);

    // play this selection.
    String movieurl = video_absolutepath[(int) position];
    Log.d(TAG, " operation on " + movieurl);

    pu.launchVideoPlayer(this, movieurl);
  }
Пример #2
0
  public boolean onContextItemSelected(MenuItem item) {

    AdapterView.AdapterContextMenuInfo info =
        (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    Log.d(TAG, " got " + item.getItemId() + " at position " + info.position);

    if (!videos_available) {
      return true;
    }

    movieurl = video_absolutepath[info.position];
    sdrecord_id = video_ids[info.position];
    moviefilename = video_filename[info.position];
    hosted_url = hosted_urls[info.position];
    Log.d(
        TAG,
        " operation on "
            + movieurl
            + " id "
            + sdrecord_id
            + " filename "
            + moviefilename
            + " hosted url "
            + hosted_url);

    switch (item.getItemId()) {
      case MENU_ITEM_1:
        // play
        pu.launchVideoPlayer(this, movieurl);
        break;

      case MENU_ITEM_2:
        // delete

        // ask if sure they want to delete ?
        AlertDialog delete_dialog =
            new AlertDialog.Builder(this)
                .setMessage(R.string.really_delete_video)
                .setPositiveButton(
                    R.string.yes,
                    new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int whichButton) {

                        // deleting files,
                        if (!pu.deleteVideo(movieurl)) {
                          Log.w(TAG, "Cant delete file " + movieurl);
                        }
                        // and removing DB records!
                        if (dbutils.deleteSDFileRecord(sdrecord_id) == -1) {
                          Log.w(TAG, "Cant delete record " + sdrecord_id);
                        }

                        reloadList();
                      }
                    })
                .setNegativeButton(
                    R.string.cancel,
                    new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int whichButton) {}
                    })
                .show();

        break;

      case MENU_ITEM_3:
        // publish to video bin
        String[] strs_vb =
            dbutils.getTitleAndDescriptionFromID(new String[] {Long.toString(sdrecord_id)});
        // grab thread
        thread_vb =
            pu.videoUploadToVideoBin(
                this,
                handler,
                movieurl,
                strs_vb[0],
                strs_vb[1] + "\n" + getString(R.string.uploaded_by_),
                emailPreference,
                sdrecord_id);
        break;

      case MENU_ITEM_4:
        // email
        pu.launchEmailIntentWithCurrentVideo(this, movieurl);
        break;

      case MENU_ITEM_6:
        // FTP server upload
        thread_ftp =
            pu.videoUploadToFTPserver(
                this, handler, moviefilename, movieurl, emailPreference, sdrecord_id);

        break;

      case MENU_ITEM_7:
        // youtube

        String possibleEmail = null;
        // We need a linked google account for youtube.
        Account[] accounts = AccountManager.get(this).getAccountsByType("com.google");

        /*
        for (Account account : accounts) {
        	// TODO: Check possibleEmail against an email regex or treat
        	// account.name as an email address only for certain
        	// account.type values.
        	possibleEmail = account.name;
        	Log.d(TAG, "Could use : " + possibleEmail);
        }*/

        possibleEmail = accounts[0].name;

        if (possibleEmail != null) {
          Log.d(TAG, "Using account name for youtube upload .. " + possibleEmail);
          // This launches the youtube upload process
          pu.getYouTubeAuthTokenWithPermissionAndUpload(
              this, possibleEmail, movieurl, handler, emailPreference, sdrecord_id);
        } else {

          // throw up dialog
          AlertDialog no_email =
              new AlertDialog.Builder(this)
                  .setMessage(R.string.no_email_account_for_youtube)
                  .setPositiveButton(
                      R.string.yes,
                      new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {}
                      })
                  .show();
        }
        break;

      case MENU_ITEM_8:
        // Title and Description of Video

        showTitleDescriptionDialog();

        break;

      case MENU_ITEM_9:
        // Email the HOSTED URL field of the currently selected video

        if (hosted_url != null && hosted_url.length() > 0) {
          Intent i = new Intent(Intent.ACTION_SEND);
          i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          i.setType("message/rfc822");
          i.putExtra(Intent.EXTRA_TEXT, hosted_url);
          this.startActivity(i);
        } else {
          Toast.makeText(
                  this,
                  R.string.video_is_not_uploaded_yet_no_hosted_url_available_,
                  Toast.LENGTH_LONG)
              .show();
        }

        break;

      case MENU_ITEM_12:
        // View the HOSTED URL field of the currently selected video in a
        // web browser.

        if (hosted_url != null && hosted_url.length() > 0) {
          Intent i2 = new Intent(Intent.ACTION_VIEW);
          i2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          i2.setData(Uri.parse(hosted_url));
          this.startActivity(i2);
        } else {
          Toast.makeText(
                  this,
                  R.string.video_is_not_uploaded_yet_no_hosted_url_available_,
                  Toast.LENGTH_LONG)
              .show();
        }
        break;
    }

    return true;
  }