コード例 #1
0
ファイル: Browser.java プロジェクト: elevenfive/Viz
  public void confirmDownload(ResourceBuilder builder) {
    Context context = getActivity();
    if (context == null) {
      Log.w("Can not confirm download without context");
      return;
    }

    // Block the save dialog from popping up over an existing popup. This
    // is a hack put in place for the DailyMotion builder that triggers
    // multiple downloads for some reason.
    if (mConfirmationInProgress) {
      Log.w("Ignoring download request from builder!!!");
      return;
    }

    mConfirmationInProgress = true;

    if (builder.isContainerURL()) {
      // if this is mysterious, it's no surprise -- it sucks.  The link
      // the user clicked on was not a direct link to the content, so we
      // need to parse the page to get the URL. Unfortunately, we don't
      // have access to the downloaded content, so we have to
      // re-download the page and parse it.  This is embarrasing and
      // should be fixed as it would make the user experience better,
      // but not sure how to do it and there are other, more interesting
      // goals.
      Log.d("Found container URL.");
      new ResourceParserTask().run(builder);
    } else {
      sendMessage(
          ActivityDelegate.MSG_BROWSER, ActivityDelegate.MSG_BROWSER_SAVEDIALOG_SHOW, builder);
    }
  }
コード例 #2
0
ファイル: Browser.java プロジェクト: elevenfive/Viz
 @Override
 protected Void doInBackground(ResourceBuilder... builders) {
   Void v = null;
   mResourceBuilder = builders[0];
   Log.d("Fetching container from " + mResourceBuilder);
   result = mResourceBuilder.fetchContainer(this);
   return v;
 }
コード例 #3
0
ファイル: Browser.java プロジェクト: elevenfive/Viz
  /** Called through sendMessage with id MSG_BROWSER_SAVEDIALOG_SHOW */
  public AlertDialog saveDialog(final Context context, Object obj) {
    final ResourceBuilder resourceBuilder = (ResourceBuilder) obj;
    LayoutInflater factory = LayoutInflater.from(context);
    final View root = factory.inflate(R.layout.savefiledialog, null);

    TextView title = (TextView) root.findViewById(R.id.savefile_title);
    title.setText(resourceBuilder.getTitle(mVizWebView));

    final EditText editor = (EditText) root.findViewById(R.id.savefile_filename);

    final AlertDialog dialog =
        new AlertDialog.Builder(context)
            .setIcon(R.drawable.ic_launcher)
            .setTitle(VizApp.getResString(R.string.savedialog_ok))
            .setView(root)
            .setPositiveButton(
                R.string.savedialog_ok,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {
                    String userFilename = editor.getText().toString();
                    if (!errorCheckPathAndFile(userFilename)) {
                      sendMessage(
                          ActivityDelegate.MSG_BROWSER,
                          ActivityDelegate.MSG_BROWSER_SAVEDIALOG_SHOW,
                          resourceBuilder);
                      return;
                    }
                    Log.d("User downloading to: " + userFilename);
                    resourceBuilder.setFilename(userFilename);
                    startDownload(resourceBuilder.build());
                  }
                })
            .setNegativeButton(
                R.string.savedialog_cancel,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {
                    Log.d("User canceled download");
                    mConfirmationInProgress = false;
                  }
                })
            .create();

    editor.setText(resourceBuilder.getDefaultFilename(mVizWebView));
    editor.setSingleLine();
    editor.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          // an enter on the keyboard triggers the download.
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            String userFilename = null;
            if (editor.getText() != null) {
              userFilename = editor.getText().toString();
            }
            if (!errorCheckPathAndFile(userFilename)) {
              sendMessage(
                  ActivityDelegate.MSG_BROWSER,
                  ActivityDelegate.MSG_BROWSER_SAVEDIALOG_SHOW,
                  resourceBuilder);
              return true;
            }
            resourceBuilder.setFilename(userFilename);
            Log.d("User downloading to: " + userFilename);
            startDownload(resourceBuilder.build());
            dialog.dismiss();
            return true;
          }
        });

    return dialog;
  }