コード例 #1
0
  private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    TypedArray attr =
        context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, 0);
    mColorNormal = attr.getColor(R.styleable.FloatingActionButton_fab_colorNormal, 0xFFDA4336);
    mColorPressed = attr.getColor(R.styleable.FloatingActionButton_fab_colorPressed, 0xFFE75043);
    mColorDisabled = attr.getColor(R.styleable.FloatingActionButton_fab_colorDisabled, 0xFFAAAAAA);
    mColorRipple = attr.getColor(R.styleable.FloatingActionButton_fab_colorRipple, 0x99FFFFFF);
    mShowShadow = attr.getBoolean(R.styleable.FloatingActionButton_fab_showShadow, true);
    mShadowColor = attr.getColor(R.styleable.FloatingActionButton_fab_shadowColor, 0x66000000);
    mShadowRadius =
        attr.getDimensionPixelSize(
            R.styleable.FloatingActionButton_fab_shadowRadius, mShadowRadius);
    mShadowXOffset =
        attr.getDimensionPixelSize(
            R.styleable.FloatingActionButton_fab_shadowXOffset, mShadowXOffset);
    mShadowYOffset =
        attr.getDimensionPixelSize(
            R.styleable.FloatingActionButton_fab_shadowYOffset, mShadowYOffset);
    mFabSize = attr.getInt(R.styleable.FloatingActionButton_fab_size, SIZE_NORMAL);
    mLabelText = attr.getString(R.styleable.FloatingActionButton_fab_label);
    mShouldProgressIndeterminate =
        attr.getBoolean(R.styleable.FloatingActionButton_fab_progress_indeterminate, false);
    mProgressColor = attr.getColor(R.styleable.FloatingActionButton_fab_progress_color, 0xFF009688);
    mProgressBackgroundColor =
        attr.getColor(R.styleable.FloatingActionButton_fab_progress_backgroundColor, 0x4D000000);
    mProgressMax = attr.getInt(R.styleable.FloatingActionButton_fab_progress_max, mProgressMax);
    mShowProgressBackground =
        attr.getBoolean(R.styleable.FloatingActionButton_fab_progress_showBackground, true);

    if (attr.hasValue(R.styleable.FloatingActionButton_fab_progress)) {
      mProgress = attr.getInt(R.styleable.FloatingActionButton_fab_progress, 0);
      mShouldSetProgress = true;
    }

    if (attr.hasValue(R.styleable.FloatingActionButton_fab_elevationCompat)) {
      float elevation =
          attr.getDimensionPixelOffset(R.styleable.FloatingActionButton_fab_elevationCompat, 0);
      if (isInEditMode()) {
        setElevation(elevation);
      } else {
        setElevationCompat(elevation);
      }
    }

    initShowAnimation(attr);
    initHideAnimation(attr);
    attr.recycle();

    if (isInEditMode()) {
      if (mShouldProgressIndeterminate) {
        setIndeterminate(true);
      } else if (mShouldSetProgress) {
        saveButtonOriginalPosition();
        setProgress(mProgress, false);
      }
    }

    //        updateBackground();
    setClickable(true);
  }
コード例 #2
0
  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    saveButtonOriginalPosition();

    if (mShouldProgressIndeterminate) {
      setIndeterminate(true);
      mShouldProgressIndeterminate = false;
    } else if (mShouldSetProgress) {
      setProgress(mProgress, mAnimateProgress);
      mShouldSetProgress = false;
    } else if (mShouldUpdateButtonPosition) {
      updateButtonPosition();
      mShouldUpdateButtonPosition = false;
    }
    super.onSizeChanged(w, h, oldw, oldh);

    setupProgressBounds();
    setupProgressBarPaints();
    updateBackground();
  }
コード例 #3
0
  public void sharePhoto() {

    final FloatingActionButton share = (FloatingActionButton) findViewById(R.id.share);
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    share.setEnabled(false);
    share.setIndeterminate(true);

    Thread t =
        new Thread(
            new Runnable() {
              @Override
              public void run() {
                pushObjectToSP();

                File directory_gags =
                    new File(
                        getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
                            + File.separator
                            + "gags");
                if (!directory_gags.exists()) {
                  directory_gags.mkdirs();
                }
                final File dir_app = new File(directory_gags + File.separator + photo_id);

                FileOutputStream out = null;
                try {
                  out = new FileOutputStream(dir_app);
                  bp.getBitmap(true).compress(Bitmap.CompressFormat.PNG, 100, out);
                } catch (Exception e) {
                  e.printStackTrace();
                } finally {
                  try {
                    if (out != null) {
                      out.close();
                    }
                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                }

                runOnUiThread(
                    new Runnable() {
                      @Override
                      public void run() {
                        share.setEnabled(true);
                        share.setIndeterminate(false);
                      }
                    });

                Uri uri = Uri.fromFile(dir_app);
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_SEND);
                intent.setType("image/*");

                Boolean boo = prefs.getBoolean("useTitleAsMessage", false);

                intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");
                if (boo) {
                  intent.putExtra(android.content.Intent.EXTRA_TEXT, gagTitle);
                } else {
                  intent.putExtra(android.content.Intent.EXTRA_TEXT, "");
                }
                intent.putExtra(Intent.EXTRA_STREAM, uri);
                startActivity(Intent.createChooser(intent, "Share Gag to..."));
              }
            });
    t.start();
  }
コード例 #4
0
  public void savePhoto() {

    final FloatingActionButton save = (FloatingActionButton) findViewById(R.id.save);
    save.setEnabled(false);
    save.setIndeterminate(true);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    String file_path = prefs.getString("path", null);

    String format = prefs.getString("image_format", "0");

    class FORMAT {
      public String ext;
      public Bitmap.CompressFormat bitmap_format;
      public Integer q;

      public void setString(String x) {
        this.ext = x;
      }

      public void setBitmapFormat(Bitmap.CompressFormat x) {
        this.bitmap_format = x;
      }

      public void setQuality(Integer x) {
        this.q = x;
      }
    }

    final FORMAT f = new FORMAT();

    if (format.equals("0")) {
      f.setString(".png");
      f.setBitmapFormat(Bitmap.CompressFormat.PNG);
      f.setQuality(100);
    } else {
      f.setString(".jpeg");
      f.setBitmapFormat(Bitmap.CompressFormat.JPEG);
      f.setQuality(80);
    }

    assert file_path != null;
    final File dir = new File(file_path);
    if (!dir.exists()) {
      dir.mkdirs();
    }

    Thread normal_save =
        new Thread(
            new Runnable() {
              @Override
              public void run() {
                pushObjectToSP();

                String modifiedTitle = gagTitle.replaceAll(" ", "-");
                File file = new File(dir, modifiedTitle + f.ext);

                FileOutputStream outo = null;
                try {
                  outo = new FileOutputStream(file);
                  bp.getBitmap(true).compress(f.bitmap_format, f.q, outo);
                } catch (Exception e) {
                  e.printStackTrace();
                } finally {
                  try {
                    if (outo != null) {
                      outo.close();
                    }
                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                }

                File directory_gags =
                    new File(
                        getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
                            + File.separator
                            + "gags");
                if (!directory_gags.exists()) {
                  directory_gags.mkdirs();
                }
                File dir_app = new File(directory_gags + File.separator + photo_id);
                FileOutputStream outi = null;

                try {
                  outi = new FileOutputStream(dir_app);
                  bp.getBitmap(true).compress(f.bitmap_format, f.q, outi);
                } catch (Exception e) {
                  e.printStackTrace();
                } finally {
                  try {
                    if (outi != null) {
                      outi.close();
                    }
                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                }

                Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                intent.setData(Uri.fromFile(file));
                sendBroadcast(intent);

                runOnUiThread(
                    new Runnable() {
                      @Override
                      public void run() {
                        save.setIndeterminate(false);
                        Toast.makeText(
                                getApplicationContext(),
                                "Gag saved successfully",
                                Toast.LENGTH_LONG)
                            .show();
                      }
                    });
              }
            });

    normal_save.start();
  }