Home

Awesome

SectorMenu效果演示

image

如何使用

<com.rance.library.SectorMenuButton    
  android:id="@+id/sector_menu"    
  android:layout_width="wrap_content"    
  android:layout_height="wrap_content"    
  app:aebAnimDurationMillis="175"    
  app:aebBlurBackground="true"    
  app:aebBlurRadius="10"    
  app:aebButtonElevation="0dp"    
  app:aebButtonGapDp="60dp"    
  app:aebEndAngleDegree="359"    
  app:aebIsSelectionMode="false"    
  app:aebMainButtonRotateAnimDurationMillis="300"    
  app:aebMainButtonRotateDegree="0"    
  app:aebMainButtonSizeDp="50dp"    
  app:aebRippleEffect="true"    
  app:aebStartAngleDegree="270"    
  app:aebSubButtonSizeDp="50dp" />
private void initSectorMenuButton() {    
  SectorMenuButton sectorMenuButton = (SectorMenuButton) findViewById(R.id.sector_menu);    
  final List<ButtonData> buttonDatas = new ArrayList<>();    
  int[] drawable = {R.mipmap.like, R.mipmap.mark, R.mipmap.search, R.mipmap.copy};    
  for (int i = 0; i < 4; i++) {        
    //最后一个参数表示padding
    ButtonData buttonData = ButtonData.buildIconButton(this, drawable[i], 0);            
    buttonData.setBackgroundColorId(this, R.color.colorAccent);        
    buttonDatas.add(buttonData);    
  }    
  sectorMenuButton.setButtonDatas(buttonDatas);    
  setListener(sectorMenuButton);
}
private void setListener(final SectorMenuButton button) {    
  button.setButtonEventListener(new ButtonEventListener() {        
    @Override        
    public void onButtonClicked(int index) {            
      showToast("button" + index);        
    }        
    @Override        
    public void onExpand() {            
      showToast("onExpand");        
    }        
    @Override        
    public void onCollapse() {            
      showToast("onCollapse");        
    }    
  });
}

自定义属性说明

其它说明

因为当中用到了高斯模糊效果,代码如下

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@WorkerThread
private Bitmap getBlurBitmap(Context context, Bitmap inBitmap, float radius) {
  if (context == null || inBitmap == null) {
    throw new IllegalArgumentException("have not called setParams() before call execute()");
  }
  int width = Math.round(inBitmap.getWidth() * SCALE);
  int height = Math.round(inBitmap.getHeight() * SCALE);
  Bitmap in = Bitmap.createScaledBitmap(inBitmap, width, height, false);
  Bitmap out = Bitmap.createBitmap(in);
  RenderScript rs = RenderScript.create(context);
  ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs,Element.U8_4(rs));
  Allocation allocationIn = Allocation.createFromBitmap(rs, in);
  Allocation allocationOut = Allocation.createFromBitmap(rs, out);
  blurScript.setRadius(radius);
  blurScript.setInput(allocationIn);
  blurScript.forEach(allocationOut);
  allocationOut.copyTo(out);
  allocationIn.destroy();
  allocationOut.destroy();
  blurScript.destroy();
  rs.destroy();
  return out;
}

Android Studio中,support v8包不能通过添加dependencies的方式加入。从sdk的目录下手动拷贝到工程的libs下面。这个包的参考路径如下:sdk/build-tools/21.1.1/renderscript/lib/renderscript-v8.jar。 但是有个更简单的方法,只要在build.gradle中加入下面两句话即可直接使用RenderScript相关API:

defaultConfig { 
    ... 
    //start 
    renderscriptTargetApi 18 
    renderscriptSupportModeEnabled true 
    //end
 }