Giter Club home page Giter Club logo

signproject's Introduction

SignProject

签到

image

使用

修改你的 build.gradle文件

//root project
allprojects {
        repositories {
            ...
	   maven { url 'https://jitpack.io' }
		}
	}
    
//module project
     dependencies {
           implementation 'com.github.android-zj:SignProject:1.0.0'
    }
    

使用方法

public class MainActivity extends AppCompatActivity {
    private List<SignView> mSignViews;
    private TextView tv_sign;//签到按钮
    private int signNum = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        mSignViews = new ArrayList<>();
        mSignViews.add((SignView) findViewById(R.id.sv_1));
        mSignViews.add((SignView) findViewById(R.id.sv_2));
        mSignViews.add((SignView) findViewById(R.id.sv_3));
        mSignViews.add((SignView) findViewById(R.id.sv_4));
        mSignViews.add((SignView) findViewById(R.id.sv_5));
        mSignViews.add((SignView) findViewById(R.id.sv_6));
        mSignViews.add((SignView) findViewById(R.id.sv_7));
        initSignView();

        tv_sign = findViewById(R.id.tv_sign);
        tv_sign.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setSignContent(++signNum);
            }
        });
    }

    private void initSignView() {
        //设置SignView
        for (int i = 0; i < mSignViews.size(); i++) {
            String textTop = String.valueOf(i);
            String textBottom = i == 0 ? "今天" : "Day" + (i + 1);
            mSignViews.get(i).setTextTopAndBottom(textTop, textBottom, 0, 2);
        }
    }

    //设置签到内容
    private void setSignContent(int sign) {
        if (sign > 0) {
            if (sign <= 7) {
                tv_sign.setText("已签到" + sign + "天");
                tv_sign.setTextColor(Color.parseColor("#606060"));
                tv_sign.setBackgroundResource(R.drawable.bt_signed);
                setSignView(sign);
            } else {
                Toast.makeText(this, "本周已签到7天", Toast.LENGTH_SHORT).show();
            }

        } else {
            tv_sign.setText("今日未签到");
            tv_sign.setTextColor(ContextCompat.getColor(this, R.color.red));
            tv_sign.setBackgroundResource(R.drawable.group_item_name);
        }

    }

    private void setSignView(int sign) {
        //设置SignView
        for (int i = 0; i < sign; i++) {
            String textTop = String.valueOf(sign);
            String textBottom = sign == 1 ? "今天" : "Day" + (i + 1);
            //int colorStyle = i < today ? 0 : (i == today ? (sign.IsSign ? 3 : 1) : 2);

            // lineStyle  显示的横线款式,0:都有线条,1左边无线条,2右边无线条;
            // colorStyle 显示的颜色款式,0:都是红色,1左红右灰,2都是灰色,3线左红右灰,圈是红色的
          if (i>0 && i < 6) {//i比sign小1
                mSignViews.get(i).setTextTopAndBottom(textTop, textBottom, 0, 0);//textTop文字宽度  textBottom底部文字
            } else if (i == 6) {
                mSignViews.get(i).setTextTopAndBottom(textTop, textBottom, 2, 0);
            }else if(i==0){
                mSignViews.get(i).setTextTopAndBottom(textTop, textBottom, 1, 0);
            }
        }
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.