diff --git a/login/.gitignore b/login/.gitignore new file mode 100644 index 0000000..643d213 --- /dev/null +++ b/login/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/login/.idea/.gitignore b/login/.idea/.gitignore new file mode 100644 index 0000000..eaf91e2 --- /dev/null +++ b/login/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/login/.idea/compiler.xml b/login/.idea/compiler.xml new file mode 100644 index 0000000..245a82c --- /dev/null +++ b/login/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/login/.idea/gradle.xml b/login/.idea/gradle.xml new file mode 100644 index 0000000..78708b3 --- /dev/null +++ b/login/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/login/.idea/jarRepositories.xml b/login/.idea/jarRepositories.xml new file mode 100644 index 0000000..94ae73a --- /dev/null +++ b/login/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/login/.idea/misc.xml b/login/.idea/misc.xml new file mode 100644 index 0000000..2925c96 --- /dev/null +++ b/login/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/login/.idea/runConfigurations.xml b/login/.idea/runConfigurations.xml new file mode 100644 index 0000000..93e4b17 --- /dev/null +++ b/login/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/login/app/.gitignore b/login/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/login/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/login/app/build.gradle b/login/app/build.gradle new file mode 100644 index 0000000..42e97fc --- /dev/null +++ b/login/app/build.gradle @@ -0,0 +1,39 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.2" + + defaultConfig { + applicationId "com.example.login" + minSdkVersion 21 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.2.1' + implementation 'androidx.constraintlayout:constraintlayout:2.0.1' + testImplementation 'junit:junit:4.+' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' +} \ No newline at end of file diff --git a/login/app/proguard-rules.pro b/login/app/proguard-rules.pro new file mode 100644 index 0000000..64b4a05 --- /dev/null +++ b/login/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/login/app/src/androidTest/java/com/example/login/ExampleInstrumentedTest.java b/login/app/src/androidTest/java/com/example/login/ExampleInstrumentedTest.java new file mode 100644 index 0000000..ef33c4c --- /dev/null +++ b/login/app/src/androidTest/java/com/example/login/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.login; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.login", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/login/app/src/main/AndroidManifest.xml b/login/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..f4c4344 --- /dev/null +++ b/login/app/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/login/app/src/main/java/com/example/login/Code.java b/login/app/src/main/java/com/example/login/Code.java new file mode 100644 index 0000000..1205603 --- /dev/null +++ b/login/app/src/main/java/com/example/login/Code.java @@ -0,0 +1,148 @@ +package com.example.login; + +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; + +import java.util.Random; + +/** + * Created by littlecurl 2018/6/24 + */ + +public class Code { + /** + * 随机数数组 + * 去除了易混淆的 数字 0 和 字母 o O + * 数字 1 和 字母 i I l L + * 数字 6 和 字母 b + * 数字 9 和 字母 q + * 字母 c C 和 G + * 字母 t (经常和随机线混在一起看不清) + */ + private static final char[] CHARS = { + '2', '3', '4', '5', '7', '8', + 'a', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', + 'n', 'p', 'r', 's', 'u', 'v', 'w', 'x', 'y', 'z', + 'A', 'B', 'D', 'E', 'F', 'H', 'J', 'K', 'M', + 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' + }; + + private static Code bmpCode; + + public static Code getInstance() { + if(bmpCode == null) + bmpCode = new Code(); + return bmpCode; + } + + //default settings + //验证码默认随机数的个数 + private static final int DEFAULT_CODE_LENGTH = 4; + //默认字体大小 + private static final int DEFAULT_FONT_SIZE = 25; + //默认线条的条数 + private static final int DEFAULT_LINE_NUMBER = 5; + //padding值 + private static final int BASE_PADDING_LEFT = 10, RANGE_PADDING_LEFT = 15, BASE_PADDING_TOP = 15, RANGE_PADDING_TOP = 20; + //验证码的默认宽高 + private static final int DEFAULT_WIDTH = 100, DEFAULT_HEIGHT = 40; + + //settings decided by the layout xml + //canvas width and height + private int width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT; + + //random word space and pading_top + private int base_padding_left = BASE_PADDING_LEFT, range_padding_left = RANGE_PADDING_LEFT, + base_padding_top = BASE_PADDING_TOP, range_padding_top = RANGE_PADDING_TOP; + + //number of chars, lines; font size + private int codeLength = DEFAULT_CODE_LENGTH, line_number = DEFAULT_LINE_NUMBER, font_size = DEFAULT_FONT_SIZE; + + //variables + private String code; + private int padding_left, padding_top; + private Random random = new Random(); + //验证码图片 + public Bitmap createBitmap() { + padding_left = 0; + + Bitmap bp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + Canvas c = new Canvas(bp); + + code = createCode(); + + c.drawColor(Color.WHITE); + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setTextSize(font_size); + //画验证码 + for (int i = 0; i < code.length(); i++) { + randomTextStyle(paint); + randomPadding(); + c.drawText(code.charAt(i) + "", padding_left, padding_top, paint); + } + //画线条 + for (int i = 0; i < line_number; i++) { + drawLine(c, paint); + } + +// c.save( Canvas.ALL_SAVE_FLAG );//保存 + c.save();//保存 + c.restore();// + return bp; + } + + public String getCode() { + return code; + } + + //生成验证码 + private String createCode() { + StringBuilder buffer = new StringBuilder(); + for (int i = 0; i < codeLength; i++) { + buffer.append(CHARS[random.nextInt(CHARS.length)]); + } + return buffer.toString(); + } + //画干扰线 + private void drawLine(Canvas canvas, Paint paint) { + int color = randomColor(); + int startX = random.nextInt(width); + int startY = random.nextInt(height); + int stopX = random.nextInt(width); + int stopY = random.nextInt(height); + paint.setStrokeWidth(1); + paint.setColor(color); + canvas.drawLine(startX, startY, stopX, stopY, paint); + } + //生成随机颜色 + private int randomColor() { + return randomColor(1); + } + + private int randomColor(int rate) { + int red = random.nextInt(256) / rate; + int green = random.nextInt(256) / rate; + int blue = random.nextInt(256) / rate; + return Color.rgb(red, green, blue); + } + //随机生成文字样式,颜色,粗细,倾斜度 + private void randomTextStyle(Paint paint) { + int color = randomColor(); + paint.setColor(color); + paint.setFakeBoldText(random.nextBoolean()); //true为粗体,false为非粗体 + float skewX = random.nextInt(11) / 10; + skewX = random.nextBoolean() ? skewX : -skewX; + paint.setTextSkewX(skewX); //float类型参数,负数表示右斜,整数左斜 + //paint.setUnderlineText(true); //true为下划线,false为非下划线 + //paint.setStrikeThruText(true); //true为删除线,false为非删除线 + } + //随机生成padding值 + private void randomPadding() { + padding_left += base_padding_left + random.nextInt(range_padding_left); + padding_top = base_padding_top + random.nextInt(range_padding_top); + } +} + diff --git a/login/app/src/main/java/com/example/login/DBOpenHelper.java b/login/app/src/main/java/com/example/login/DBOpenHelper.java new file mode 100644 index 0000000..e6e11d4 --- /dev/null +++ b/login/app/src/main/java/com/example/login/DBOpenHelper.java @@ -0,0 +1,61 @@ +package com.example.login; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; + +import java.util.ArrayList; + +public class DBOpenHelper extends SQLiteOpenHelper { + private SQLiteDatabase db; + + static String DATABASE_NAME="User"; + static String CREATE_SQL="CREATE TABLE IF NOT EXISTS User(id integer primary key autoincrement, name text,password text)";//建表 + static String DROP_SQL="DROP TABLE IF EXISTS User"; + + public DBOpenHelper (Context context){ + super(context,DATABASE_NAME,null,1); + db=getReadableDatabase(); + } + + @Override + public void onCreate(SQLiteDatabase db) { + db.execSQL(CREATE_SQL); + + } + + @Override + public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { + db.execSQL(DROP_SQL); + onCreate(db); + + } + //增删改查 + static private String INSERT_SQL="INSERT INTO User (name,password) VALUES(?,?)"; + static private String DELETE_SQL="DELETE FROM User WHERE name= AND password ="; + + public void add(String name,String password){ + db.execSQL(INSERT_SQL,new Object[]{name,password}); + } + public void delete(String name,String password){ + db.execSQL(DELETE_SQL+name+password); + } + public void update(String name,String password){ + db.execSQL("UPDATE User SET password = ?",new Object[]{password}); + } + + public ArrayList getAllDate(){ + + ArrayList list=new ArrayList(); + Cursor cursor=db.query("User",null,null,null,null,null,"name DESC"); + while (cursor.moveToNext()){ + @SuppressLint("Range") String name=cursor.getString(cursor.getColumnIndex("name")); + @SuppressLint("Range") String password = cursor.getString(cursor.getColumnIndex("password")); + list.add(new User(name,password)); + + } + return list; + } +} diff --git a/login/app/src/main/java/com/example/login/LoginActivity.java b/login/app/src/main/java/com/example/login/LoginActivity.java new file mode 100644 index 0000000..8d32c08 --- /dev/null +++ b/login/app/src/main/java/com/example/login/LoginActivity.java @@ -0,0 +1,88 @@ +package com.example.login; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; +import android.widget.TextView; +import android.widget.Toast; + +import java.util.ArrayList; + +public class LoginActivity extends AppCompatActivity implements View.OnClickListener{ + + private DBOpenHelper mDBOpenHelper; + private TextView mTvLoginactivityRegister; + private RelativeLayout mRlLoginactivityTop; + private EditText mEtLoginactivityUsername; + private EditText mEtLoginactivityPassword; + private LinearLayout mLlLoginactivityTwo; + private Button mBtLoginactivityLogin; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_login); + + initView(); + + mDBOpenHelper=new DBOpenHelper(this); + } + + + private void initView(){ + mBtLoginactivityLogin = findViewById(R.id.bt_loginactivity_login); + mTvLoginactivityRegister = findViewById(R.id.tv_loginactivity_register); + mRlLoginactivityTop = findViewById(R.id.rl_loginactivity_top); + mEtLoginactivityUsername = findViewById(R.id.et_loginactivity_username); + mEtLoginactivityPassword = findViewById(R.id.et_loginactivity_password); + mLlLoginactivityTwo = findViewById(R.id.ll_loginactivity_two); +//设置监听事件 + mBtLoginactivityLogin.setOnClickListener(this); + mTvLoginactivityRegister.setOnClickListener(this); + } + + public void onClick(View view){ + switch (view.getId()){ + + case R.id.tv_loginactivity_register: + startActivity(new Intent(this,RegisterActivity.class)); + finish(); + break; + case R.id.bt_loginactivity_login: + String name=mEtLoginactivityUsername.getText().toString().trim(); + String password=mEtLoginactivityPassword.getText().toString().trim(); + if(!TextUtils.isEmpty(name)&&!TextUtils.isEmpty(password)){ + ArrayList data=mDBOpenHelper.getAllDate(); + boolean match=false; + for(int i=0;i + + + + + + + + + + \ No newline at end of file diff --git a/login/app/src/main/res/drawable/ic_launcher_background.xml b/login/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..a4f78de --- /dev/null +++ b/login/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/login/app/src/main/res/drawable/ic_left_back.png b/login/app/src/main/res/drawable/ic_left_back.png new file mode 100644 index 0000000..ddf2de1 Binary files /dev/null and b/login/app/src/main/res/drawable/ic_left_back.png differ diff --git a/login/app/src/main/res/drawable/selector_loginactivity_button.xml b/login/app/src/main/res/drawable/selector_loginactivity_button.xml new file mode 100644 index 0000000..6f4c918 --- /dev/null +++ b/login/app/src/main/res/drawable/selector_loginactivity_button.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/login/app/src/main/res/layout/activity_login.xml b/login/app/src/main/res/layout/activity_login.xml new file mode 100644 index 0000000..1bae927 --- /dev/null +++ b/login/app/src/main/res/layout/activity_login.xml @@ -0,0 +1,149 @@ + + + + + + + + + + + + + + + + + + + + + + +