Exemple #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(R.string.backpack_title);
    setContentView(R.layout.activity_script);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    currentFragmentPosition = FRAGMENT_BACKPACK_SCRIPTS;

    if (savedInstanceState == null) {
      Bundle bundle = this.getIntent().getExtras();

      if (bundle != null) {
        currentFragmentPosition = bundle.getInt(EXTRA_FRAGMENT_POSITION, FRAGMENT_BACKPACK_SCRIPTS);
        backpackItem = bundle.getBoolean(BACKPACK_ITEM);
      }
    }

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    setCurrentFragment(currentFragmentPosition);
    fragmentTransaction.commit();
    fragmentTransaction.add(R.id.script_fragment_container, currentFragment, currentFragmentTag);

    final ActionBar actionBar = getSupportActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
  }
Exemple #2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_script);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    currentFragmentPosition = FRAGMENT_SCRIPTS;

    if (savedInstanceState == null) {
      Bundle bundle = this.getIntent().getExtras();

      if (bundle != null) {
        currentFragmentPosition = bundle.getInt(EXTRA_FRAGMENT_POSITION, FRAGMENT_SCRIPTS);
      }
    }

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    updateCurrentFragment(currentFragmentPosition, fragmentTransaction);
    fragmentTransaction.commit();

    final ActionBar actionBar = getSupportActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    String currentSprite = ProjectManager.getInstance().getCurrentSprite().getName();
    actionBar.setTitle(currentSprite);

    buttonAdd = (ImageButton) findViewById(R.id.button_add);
    updateHandleAddButtonClickListener();
  }
Exemple #3
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_script);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    currentFragmentPosition = FRAGMENT_SCRIPTS;

    if (savedInstanceState == null) {
      Bundle bundle = this.getIntent().getExtras();

      if (bundle != null) {
        currentFragmentPosition = bundle.getInt(EXTRA_FRAGMENT_POSITION, FRAGMENT_SCRIPTS);
      }
    }

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    updateCurrentFragment(currentFragmentPosition, fragmentTransaction);
    fragmentTransaction.commit();

    setupActionBar();
    setupBottomBar();

    buttonAdd = (ImageButton) findViewById(R.id.button_add);
    updateHandleAddButtonClickListener();
  }
  @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);
            }
          }
        });
  }
Exemple #5
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);
            }
          }
        });
  }