예제 #1
0
파일: Project.java 프로젝트: Bioxar/Catroid
  public void setDeviceData(Context context) {
    // TODO add other header values
    xmlHeader.setPlatform(Constants.PLATFORM_NAME);
    xmlHeader.setPlatformVersion((double) Build.VERSION.SDK_INT);
    xmlHeader.setDeviceName(Build.MODEL);

    xmlHeader.setCatrobatLanguageVersion(Constants.CURRENT_CATROBAT_LANGUAGE_VERSION);
    xmlHeader.setApplicationBuildName(Constants.APPLICATION_BUILD_NAME);
    xmlHeader.setApplicationBuildNumber(Constants.APPLICATION_BUILD_NUMBER);

    if (context == null) {
      xmlHeader.setApplicationVersion("unknown");
      xmlHeader.setApplicationName("unknown");
    } else {
      xmlHeader.setApplicationVersion(Utils.getVersionName(context));
      xmlHeader.setApplicationName(context.getString(R.string.app_name));
    }
  }
예제 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_webview);

    ActionBar actionBar = getActionBar();
    actionBar.hide();

    Intent intent = getIntent();
    url = intent.getStringExtra(INTENT_PARAMETER_URL);
    if (url == null) {
      url = Constants.BASE_URL_HTTPS;
    }
    callingActivity = intent.getStringExtra(CALLING_ACTIVITY);

    webView = (WebView) findViewById(R.id.webView);

    webView.setWebChromeClient(
        new WebChromeClient() {
          private ProgressDialog progressCircle;

          @Override
          public void onProgressChanged(WebView view, int progress) {
            if (progressCircle == null) {
              progressCircle = new ProgressDialog(view.getContext(), R.style.WebViewLoadingCircle);
              progressCircle.setCancelable(true);
              progressCircle.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
              progressCircle.show();
            }

            if (progress == 100) {
              progressCircle.dismiss();
              progressCircle = null;
            }
          }
        });
    webView.setWebViewClient(new MyWebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    String language = String.valueOf(Constants.CURRENT_CATROBAT_LANGUAGE_VERSION);
    String flavor = Constants.FLAVOR_DEFAULT;
    String version = Utils.getVersionName(getApplicationContext());
    String platform = Constants.PLATFORM_DEFAULT;
    webView
        .getSettings()
        .setUserAgentString(
            "Catrobat/" + language + " " + flavor + "/" + version + " Platform/" + platform);

    webView.loadUrl(url);

    webView.setDownloadListener(
        new DownloadListener() {
          @Override
          public void onDownloadStart(
              String url,
              String userAgent,
              String contentDisposition,
              String mimetype,
              long contentLength) {
            Log.d(
                WebViewActivity.class.getSimpleName(),
                "contentDisposition: " + contentDisposition + "   " + mimetype);

            if (getExtentionFromContentDisposition(contentDisposition)
                .contains(Constants.CATROBAT_EXTENSION)) {
              DownloadUtil.getInstance()
                  .prepareDownloadAndStartIfPossible(WebViewActivity.this, url);
            } else if (url.contains(Constants.LIBRARY_BASE_URL)) {
              String name = getMediaNameFromUrl(url);
              String mediaType = getMediaTypeFromContentDisposition(contentDisposition);
              String fileName = name + getExtentionFromContentDisposition(contentDisposition);
              String tempPath = null;
              switch (mediaType) {
                case Constants.MEDIA_TYPE_LOOK:
                  tempPath = Constants.TMP_LOOKS_PATH;
                  break;
                case Constants.MEDIA_TYPE_SOUND:
                  tempPath = Constants.TMP_SOUNDS_PATH;
              }
              String filePath = Utils.buildPath(tempPath, fileName);
              resultIntent.putExtra(MEDIA_FILE_PATH, filePath);
              DownloadUtil.getInstance()
                  .prepareMediaDownloadAndStartIfPossible(
                      WebViewActivity.this, url, mediaType, name, filePath, callingActivity);
            } else {
              DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));

              request.setTitle(
                  getString(R.string.notification_download_title_pending)
                      + " "
                      + DownloadUtil.getInstance().getProjectNameFromUrl(url));
              request.setDescription(getString(R.string.notification_download_pending));
              request.setNotificationVisibility(
                  DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
              request.setDestinationInExternalPublicDir(
                  Environment.DIRECTORY_DOWNLOADS,
                  DownloadUtil.getInstance().getProjectNameFromUrl(url)
                      + ANDROID_APPLICATION_EXTENSION);
              request.setMimeType(mimetype);

              registerReceiver(
                  onDownloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

              DownloadManager downloadManager =
                  (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
              downloadManager.enqueue(request);
            }
          }
        });
  }
예제 #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_webview);

    ActionBar actionBar = getSupportActionBar();
    actionBar.hide();

    Intent intent = getIntent();
    url = intent.getStringExtra(INTENT_PARAMETER_URL);
    if (url == null) {
      url = Constants.BASE_URL_HTTPS;
    }

    webView = (WebView) findViewById(R.id.webView);
    webView.setWebChromeClient(new WebChromeClient());
    webView.setWebViewClient(new MyWebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);

    String language = String.valueOf(Constants.CURRENT_CATROBAT_LANGUAGE_VERSION);
    String flavor = Constants.FLAVOR_DEFAULT;
    String version = Utils.getVersionName(getApplicationContext());
    String platform = Constants.PLATFORM_DEFAULT;
    webView
        .getSettings()
        .setUserAgentString(
            "Catrobat/" + language + " " + flavor + "/" + version + " Platform/" + platform);

    webView.loadUrl(url);

    webView.setDownloadListener(
        new DownloadListener() {
          @Override
          public void onDownloadStart(
              String url,
              String userAgent,
              String contentDisposition,
              String mimetype,
              long contentLength) {
            Log.e("TAG", "contentDisposition: " + contentDisposition + "   " + mimetype);
            if (contentDisposition.contains(Constants.CATROBAT_EXTENSION)) {
              DownloadUtil.getInstance()
                  .prepareDownloadAndStartIfPossible(WebViewActivity.this, url);
            } else {
              DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));

              request.setTitle(
                  getString(R.string.notification_download_title_pending)
                      + " "
                      + DownloadUtil.getInstance().getProjectNameFromUrl(url));
              request.setDescription(getString(R.string.notification_download_pending));
              request.setNotificationVisibility(
                  DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
              request.setDestinationInExternalPublicDir(
                  Environment.DIRECTORY_DOWNLOADS,
                  DownloadUtil.getInstance().getProjectNameFromUrl(url)
                      + ANDROID_APPLICATION_EXTENSION);
              request.setMimeType(mimetype);

              registerReceiver(
                  onDownloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

              DownloadManager downloadManager =
                  (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
              downloadManager.enqueue(request);
            }
          }
        });
  }