Пример #1
0
 @Override
 public void handleMessage(Message msg) {
   uploadbar.setProgress(msg.getData().getInt("length"));
   float num = (float) uploadbar.getProgress() / (float) uploadbar.getMax();
   int result = (int) (num * 100);
   resultView.setText(result + "%");
   if (uploadbar.getProgress() == uploadbar.getMax()) {
     Toast.makeText(MainActivity.this, R.string.success, 1).show();
   }
 }
 public void updateProgress(int progress) {
   if (progress == progressBar.getMax() || progress == 0) {
     progressBar.setVisibility(View.INVISIBLE);
   } else {
     progressBar.setVisibility(View.VISIBLE);
   }
   progressBar.setProgress(progress);
 }
Пример #3
0
  public void Gain50Exp(View view) {
    user.gain_exp(50);
    mProgress.incrementProgressBy(50);

    Snackbar snackbar = Snackbar.make(view, "You got 50 EXP!", Snackbar.LENGTH_LONG);
    snackbar.setAction("Action", null).show();

    if (mProgress.getProgress() >= mProgress.getMax()) {
      LevelUp(view);
    }
  }
Пример #4
0
 private void updateLike() {
   if (this.currentAnim != null) {
     this.currentAnim.end();
   }
   //    if (this.mLikeView.getVisibility() == View.GONE) {
   //      this.mLikeView.setVisibility(View.VISIBLE);
   //    }
   mLikeProgress.setProgress(isLiking ? mLikeProgress.getMax() : 0);
   String text = (isLiking ? LIKE_SYMBOL : UNLIKE_SYMBOL) + " " + this.likingCount;
   mLikeTextView.setText(text);
   mLikeTextView.setTextColor(
       getResources().getColor(isLiking ? R.color.white_trans : R.color.jianshu_trans));
 }
  private void editProgressBars() {
    player.pullFromDatabase();
    ProgressBar healthbar = (ProgressBar) findViewById(R.id.progressBar_health);
    healthbar.setMax(100); // TODO calc the max health
    healthbar.setProgress(player.getHealth());
    TextView health = (TextView) findViewById(R.id.txt_health_ratio);
    health.setText(healthbar.getProgress() + "/" + healthbar.getMax());

    ProgressBar xpbar = (ProgressBar) findViewById(R.id.progressBar_experience);
    Resources res = getResources();
    int[] levels = res.getIntArray(R.array.Levels);
    xpbar.setMax(190000); // Cap Level
    for (int i = 0; i < levels.length; i++) {
      if (levels[i] > player.getXP()) {
        xpbar.setMax(levels[i]);
        EditText level = (EditText) findViewById(R.id.editText_Level);
        level.setText("" + ++i);
        break;
      }
    }
    xpbar.setProgress(player.getXP());
    TextView xp = (TextView) findViewById(R.id.txt_experience_ratio);
    xp.setText(xpbar.getProgress() + "/" + xpbar.getMax());
  }
 @UiThread
 private void updateTimeDisplayTo(int secondsIn, int secondsTotal) {
   if (mFullHeightLayout) {
     if (updateSeekBar) {
       if (seekBar.getMax() != secondsTotal) {
         seekBar.setMax(secondsTotal);
         totalTime.setText(Util.formatElapsedTime(secondsTotal));
       }
       seekBar.setProgress(secondsIn);
       currentTime.setText(Util.formatElapsedTime(secondsIn));
     }
   } else {
     if (mProgressBar.getMax() != secondsTotal) {
       mProgressBar.setMax(secondsTotal);
     }
     mProgressBar.setProgress(secondsIn);
   }
 }
        @Override
        public void handleMessage(Message msg) {

          progressBarh.setProgress(msg.getData().getInt("size"));

          float temp = (float) progressBarh.getProgress() / (float) progressBarh.getMax();

          int progress = (int) (temp * 100);
          if (progress == 100) {
            Toast.makeText(DownImageActivity.this, "下载完成!", Toast.LENGTH_LONG).show();
            dialog.dismiss();

            File mFile = new File(msg.getData().getString("uri"));
            Intent install = new Intent();
            install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            install.setAction(android.content.Intent.ACTION_VIEW);
            install.setDataAndType(Uri.fromFile(mFile), "application/vnd.android.package-archive");
            startActivity(install);
          }
          dialog.setMessage("下载进度:" + progress + " %");
        }
        public void handleMessage(Message msg) {
          if (!Thread.currentThread().isInterrupted()) {
            switch (msg.what) {
              case 0:
                progressBarh.setMax(FileLength);
                Log.i("文件长度----------->", progressBarh.getMax() + "");
                break;
              case 1:
                progressBarh.setProgress(DownedFileLength);
                int x = DownedFileLength * 100 / FileLength;
                // textView.setText(x+"%");
                dialog.setMessage("已下载 " + x + "%,请稍后...");

                break;
              case 2:
                Toast.makeText(getApplicationContext(), "下载完成", Toast.LENGTH_LONG).show();
                dialog.dismiss();
                break;

              default:
                break;
            }
          }
        }
  private void increaseProgressBy(int val) {
    if (expBar.getProgress() + val >= expBar.getMax()) {
      stLevel++;
      qAnswered = 0;
      level.setText(String.valueOf(stLevel));

      if ((val - (expBar.getMax() - expBar.getProgress())) > 0) {
        expBar.setProgress(val - (expBar.getMax() - expBar.getProgress()));
      } else {
        expBar.setProgress(0);
      }
      expBar.setMax((int) (expBar.getMax() * LEVEL_SCALE));
      experience.setText(String.valueOf(expBar.getProgress()) + "/" + expBar.getMax());
      Toast.makeText(
              this,
              "Congratulations!\nYou've reached level " + level.getText().toString(),
              Toast.LENGTH_SHORT)
          .show();
    } else {
      expBar.setProgress(expBar.getProgress() + val);
      experience.setText(String.valueOf(expBar.getProgress()) + "/" + expBar.getMax());
    }

    if (stLevel % 2 == 0 && qAnswered < 3) {
      qButton.setEnabled(true);
      saveProgressInfo("QANSWERED", qAnswered);
      setupAlert();

    } else {
      qButton.setEnabled(false);
    }

    saveProgressInfo("LEVEL", level.getText().toString());
    saveProgressInfo("EXPERIENCE", String.valueOf(expBar.getProgress()));
    saveProgressInfo("EXPCAP", String.valueOf(expBar.getMax()));
  }
        @Override
        public void handleMessage(Message msg) {

          switch (msg.what) {
            case 1:
              {
                uploadbar.setProgress(msg.getData().getInt("length"));
                float num = (float) uploadbar.getProgress() / (float) uploadbar.getMax();
                int result = (int) (num * 100);
                resultView.setText(result + "%");
                if (uploadbar.getProgress() == uploadbar.getMax()) {

                  Toast.makeText(SubmitActivity.this, R.string.success, 1).show();
                }
              }
              break;
              // 上传视频
            case 2:
              {
                try {
                  postVedioInfo();

                } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
              }
              break;
            case 3:
              {
                if (sinax) showShare(true, "SinaWeibo", false);
                if (tecentx) showShare(true, "TencentWeibo", false);
                if (renrenx) showShare(true, "Renren", false);
                if (doubanx) showShare(true, "Douban", false);

                jumpActivity(SquareActivity.class);
              }
              break;
            case 4:
              {
                HashMap<String, Integer> map = (HashMap<String, Integer>) msg.obj;
                int whichItem = map.get("whichItem");
                int whichpop = map.get("whichPop");

                if (whichpop == CLASSFICATION_POP) {
                  classificationTextView.setText(classficationlist.get(whichItem));
                  choose_classfication_popupWindow.dismiss();
                } else if (whichpop == ChooseGroup_POP) {
                  String chooseString = grouplist.get(whichItem);
                  if (addShareGroupTextView
                      .getText()
                      .toString()
                      .equals(getString(R.string.submit_shareGroupOriginalString))) {

                    addShareGroupTextView.setText(chooseString);
                    shareGroupId = groupMap.get(chooseString);
                  } else {
                    addShareGroupTextView.setText(
                        addShareGroupTextView.getText().toString() + ";" + chooseString);
                    shareGroupId = shareGroupId + ";" + groupMap.get(chooseString);
                  }
                }
              }
              break;
            case 5:
              {
                showToastMessage(msg.obj.toString());
              }
              break;
              // 获取到了分类信息,准备获取分组信息
            case GET_CLASSFICATION:
              {
                initGroup();
              }
            default:
              break;
          }
        }
 public int getMax() {
   if (mProgress != null) {
     return mProgress.getMax();
   }
   return mMax;
 }
Пример #12
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_article);

    this.handler = new Handler();

    Intent intent = getIntent();
    mUrl = intent.getStringExtra("url");
    //    mTitle = intent.getStringExtra("title");
    //    mSummary = intent.getStringExtra("summary");
    //    mAuthor = intent.getStringExtra("author");
    mLoadingArticle = (LoadingTextView) findViewById(R.id.loading_article);
    mWebView = (ObservableWebView) findViewById(R.id.web);
    mWebView.setOnScrollChangedCallback(this);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.addJavascriptInterface(this, "article");
    mRetryButton = (Button) findViewById(R.id.retry);
    this.scanLight = (View) findViewById(R.id.scan_light);

    final ArticleActivity that = this;

    this.fadeIn = AnimationUtils.loadAnimation(this, R.anim.fade_in);
    this.fadeOut = AnimationUtils.loadAnimation(this, R.anim.fade_out);
    this.fadeOut.setAnimationListener(
        new Animation.AnimationListener() {
          @Override
          public void onAnimationStart(Animation animation) {}

          @Override
          public void onAnimationEnd(Animation animation) {
            ArticleActivity.this.mLikeView.setVisibility(View.GONE);
          }

          @Override
          public void onAnimationRepeat(Animation animation) {}
        });

    this.scanAnim = AnimationUtils.loadAnimation(this, R.anim.scan);
    this.scanAnim.setAnimationListener(
        new Animation.AnimationListener() {

          @Override
          public void onAnimationStart(Animation animation) {
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            that.scanFinishedDialogFragment = ScanFinishedDialogFragment.newInstance();
            that.scanFinishedDialogFragment.show(ft, "scan");
          }

          @Override
          public void onAnimationEnd(Animation animation) {
            ArticleActivity.this.scanLight.setVisibility(View.GONE);
          }

          @Override
          public void onAnimationRepeat(Animation animation) {}
        });

    mLikeProgress = (ProgressBar) findViewById(R.id.like_progress);
    this.likingAnim =
        ObjectAnimator.ofInt(this.mLikeProgress, "progress", 2, mLikeProgress.getMax() - 1);
    this.likingAnim.setDuration(2000);
    this.unlikingAnim =
        ObjectAnimator.ofInt(this.mLikeProgress, "progress", mLikeProgress.getMax() - 1, 2);
    this.unlikingAnim.setDuration(2000);

    mLikeView = findViewById(R.id.like);
    mLikeTextView = (TextView) findViewById(R.id.like_text);
    mLikeView.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            final ArticleActivity that = ArticleActivity.this;
            final int max = mLikeProgress.getMax();
            if (that.isLikingProgressing) {
              return;
            }
            that.isLikingProgressing = true;

            that.currentAnim = that.isLiking ? that.unlikingAnim : that.likingAnim;
            that.currentAnim.start();

            (new AsyncTask<Void, Void, Boolean>() {

                  @Override
                  protected Boolean doInBackground(Void... params) {
                    Object httpResult = JianshuSession.getsInstance().postSync(that.likeUrl, false);
                    if (httpResult instanceof String) {
                      String str = (String) httpResult;
                      if (str.startsWith("$")) {
                        if (str.contains("addClass('note-liked')")) {
                          that.isLiking = true;
                        } else if (str.contains("removeClass('note-liked')")) {
                          that.isLiking = false;
                        }
                        Matcher matcher = LIKE_COUNT_PATTERN.matcher(str);
                        if (matcher.find()) {
                          that.likingCount = Integer.parseInt(matcher.group(1));
                        }
                        return true;
                      }
                    }
                    return false;
                  }

                  @Override
                  protected void onPostExecute(Boolean succeed) {
                    that.isLikingProgressing = false;
                    // 即使是网络问题失败了,也要重置进度条状态
                    updateLike();
                    if (!succeed) {
                      Toast.makeText(that, "网络似乎不给力", Toast.LENGTH_LONG).show();
                    }
                  }
                })
                .execute();
          }
        });

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    // 滑动返回
    mSwipeBackLayout = getSwipeBackLayout();
    mSwipeBackLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);

    mRetryButton.setOnClickListener(
        new Button.OnClickListener() {

          @Override
          public void onClick(View v) {
            mRetryButton.setVisibility(View.INVISIBLE);
            mLoadingArticle.setVisibility(View.VISIBLE);
            loadArticle();
          }
        });

    mDownloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);

    mFinalHttp = new FinalHttp();

    Object[] state = StatePool.getInstance().getState("article");
    if (state != null) {
      String url = (String) state[0];
      if (mUrl.equals(url)) {
        this.mTitle = (String) state[1];
        this.mAuthor = (String) state[2];
        this.content = (String) state[3];
        mWebView.setVisibility(View.VISIBLE);
        mWebView.loadData(this.content, "text/html; charset=UTF-8", null);
        return;
      }
    }
    loadArticle();
  }
  public void testIfRGBSeekBarsDoChangeColor()
      throws SecurityException, IllegalArgumentException, NoSuchFieldException,
          IllegalAccessException {
    final int RGB_TAB_INDEX = 1;
    testOpenColorPickerOnClickOnColorButton();
    TabHost tabHost = (TabHost) mSolo.getView(R.id.colorview_tabColors);
    TabWidget colorTabWidget = tabHost.getTabWidget();
    mSolo.clickOnView(colorTabWidget.getChildAt(RGB_TAB_INDEX), true);
    mSolo.waitForText(mSolo.getString(R.string.color_red));
    final Paint originalStrokePaint =
        (Paint)
            PrivateAccess.getMemberValue(
                BaseTool.class, PaintroidApplication.currentTool, "mCanvasPaint");
    final int originalPaintColor = originalStrokePaint.getColor();
    final ArrayList<ProgressBar> currentProgressBars = mSolo.getCurrentViews(ProgressBar.class);
    assertEquals("No progress bars for ARGB :-(", currentProgressBars.size(), 4);
    final ArrayList<TextView> currentTextViews =
        mSolo.getCurrentViews(TextView.class, mSolo.getView(R.id.rgb_base_layout));
    assertEquals("Missing some text views RGBA and ARGV-values", 9, currentTextViews.size());
    int textValueCounter = 1;
    for (; textValueCounter < currentTextViews.size(); textValueCounter += 2) {
      int textValueAsInteger =
          Integer.parseInt((String) currentTextViews.get(textValueCounter).getText());
      assertTrue(
          "Not in range 0<=textValue<=255", textValueAsInteger >= 0 && textValueAsInteger <= 255);
    }

    textValueCounter = 1;
    for (ProgressBar barToChange : currentProgressBars) {
      int changeSeekBarTo = (barToChange.getProgress() + 33) % barToChange.getMax();
      mSolo.setProgressBar(barToChange, changeSeekBarTo);
      mSolo.sleep(50);
      if (textValueCounter == 4) { // alpha 0-100%
        int expectetAlphaTextValue = (int) (changeSeekBarTo / 2.55f);
        assertEquals(
            "Text value did not change index:" + textValueCounter,
            expectetAlphaTextValue,
            Integer.parseInt((String) currentTextViews.get(textValueCounter * 2 - 1).getText()));
      } else
        assertEquals(
            "Text value did not change index:" + textValueCounter,
            changeSeekBarTo,
            Integer.parseInt((String) currentTextViews.get(textValueCounter * 2 - 1).getText()));
      textValueCounter++;
    }
    mSolo.goBack();
    final Paint rgbChangedStrokePaint =
        (Paint)
            PrivateAccess.getMemberValue(
                BaseTool.class, PaintroidApplication.currentTool, "mCanvasPaint");
    final int rgbChangedPaintColor = rgbChangedStrokePaint.getColor();
    assertFalse(
        "Alpha value did not change",
        Color.alpha(rgbChangedPaintColor) == Color.alpha(originalPaintColor));
    assertFalse(
        "Red value did not change",
        Color.red(rgbChangedPaintColor) == Color.red(originalPaintColor));
    assertFalse(
        "Green value did not change",
        Color.green(rgbChangedPaintColor) == Color.green(originalPaintColor));
    assertFalse(
        "Blue value did not change",
        Color.blue(rgbChangedPaintColor) == Color.blue(originalPaintColor));
  }
Пример #14
0
 public void updateProgressBar() {
   if (progressBar.getMax() > (iterator.getSize() - 1)) {
     progressBar.setMax(iterator.getSize() - 1);
   }
   progressBar.setProgress(iterator.getIndexNum());
 }
 @Override
 public void handleMessage(Message msg) {
   tv.setText(a * 100 / pb.getMax() + "%");
 }
 private void stopProgressBar() {
   if (mTimer != null) mTimer.cancel();
   mProgressBar.setProgress(mProgressBar.getMax());
 }