├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── bigerdranch │ │ └── android │ │ └── test │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── bigerdranch │ │ │ └── android │ │ │ └── test │ │ │ ├── MainActivity.java │ │ │ ├── dao │ │ │ ├── AesTest.java │ │ │ ├── DatabaseHelper.java │ │ │ ├── JsonTodata.java │ │ │ ├── MyDao.java │ │ │ └── PwdData.java │ │ │ ├── management.java │ │ │ ├── other.java │ │ │ ├── password.java │ │ │ ├── setting │ │ │ ├── CustomLayout.java │ │ │ ├── RandomPassword.java │ │ │ ├── Scan.java │ │ │ ├── SwipeListView.java │ │ │ └── qrCreat.java │ │ │ └── settings.java │ └── res │ │ ├── drawable │ │ ├── button.png │ │ ├── ic_menu_camera.xml │ │ ├── ic_menu_gallery.xml │ │ ├── ic_menu_manage.xml │ │ ├── ic_menu_management.xml │ │ ├── ic_menu_other.xml │ │ ├── ic_menu_password.xml │ │ ├── ic_menu_send.xml │ │ ├── ic_menu_share.xml │ │ ├── ic_menu_slideshow.xml │ │ ├── ic_name.xml │ │ ├── ic_password.xml │ │ ├── ic_scan_light.xml │ │ ├── ic_user.xml │ │ └── side_nav_bar.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_management.xml │ │ ├── activity_other.xml │ │ ├── activity_password.xml │ │ ├── activity_scan.xml │ │ ├── activity_settings.xml │ │ ├── app_bar_main.xml │ │ ├── app_bar_management.xml │ │ ├── app_bar_other.xml │ │ ├── app_bar_password.xml │ │ ├── content_main.xml │ │ ├── content_management.xml │ │ ├── content_other.xml │ │ ├── content_password.xml │ │ ├── create_password.xml │ │ ├── edit_password.xml │ │ ├── nav_header_main.xml │ │ ├── nav_header_management.xml │ │ ├── nav_header_other.xml │ │ ├── nav_header_password.xml │ │ ├── password_show.xml │ │ └── slip_item_layout.xml │ │ ├── menu │ │ ├── activity_main_drawer.xml │ │ ├── activity_management_drawer.xml │ │ ├── activity_other_drawer.xml │ │ ├── activity_password_drawer.xml │ │ ├── main.xml │ │ ├── management.xml │ │ ├── other.xml │ │ └── password.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ ├── ic_scan_light_down.png │ │ ├── ic_scan_light_on.png │ │ ├── ico.png │ │ └── ico_title.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ ├── ic_scan_light_down.png │ │ ├── ic_scan_light_on.png │ │ ├── ico.png │ │ └── ico_title.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ ├── ic_scan_light_down.png │ │ ├── ic_scan_light_on.png │ │ ├── ico.png │ │ └── ico_title.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ ├── ic_scan_light_down.png │ │ ├── ic_scan_light_on.png │ │ ├── ico.png │ │ └── ico_title.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ ├── ic_scan_light_down.png │ │ ├── ic_scan_light_on.png │ │ ├── ico.png │ │ └── ico_title.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── bigerdranch │ └── android │ └── test │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── image ├── 1.png ├── 10.png ├── 11.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png └── 9.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 密码管理器 2 | 3 | ## 实现功能 4 | * 密码侧滑增删查改 5 | * 二维码扫描添加 6 | * 侧滑菜单 7 | * 加密分享密码 8 | * 根据要求生成密码 9 | * 自定义扫描页面 10 | * 密码界面增加禁止截屏 11 | 12 | ## 依赖 13 | * 基于zxing进行的二维码扫描 14 | * 基于SwipeListView进行的ListView侧滑菜单实现 15 | * 基于随机数的密码生成 16 | * 基于AES(Advanced Encryption Standard)进行加密二维码 17 | 18 | ## 说明 19 | 此项目运用sqlite进行本地存储密码,通过围绕二维码进行的密码管理器,可以通过二维码进行分享密码,记录密码 20 | 实现功能有限,采用AES加密算法,且显示密码界面禁止截屏,安全有保障。 21 | 22 | *** 23 | # 页面展示 24 | 25 | ## 首页 26 | ![img](./image/1.png) 27 | ## 侧滑菜单 28 | ![img](./image/4.png) 29 | ## 密码加入 30 | ![img](./image/7.png) 31 | ## 密码分享 32 | ![img](./image/6.png) 33 | ## 密码生成 34 | ![img](./image/8.png) 35 | ## 密码查看 36 | ![img](./image/2.png) 37 | ## 密码编辑更新 38 | ![img](./image/11.png) 39 | ## 密码 40 | ![img](./image/5.png) 41 | ## 密码删除 42 | ![img](./image/9.png) 43 | ## 密码侧滑编辑 44 | ![img](./image/10.png) 45 | ## 关于软件 46 | ![img](./image/3.png) 47 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion "25.0.3" 6 | defaultConfig { 7 | applicationId "com.bigerdranch.android.test" 8 | minSdkVersion 22 9 | targetSdkVersion 26 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | 28 | 29 | compile 'com.journeyapps:zxing-android-embedded:3.5.0' 30 | compile 'com.android.support:appcompat-v7:26.+' 31 | compile 'com.android.support:support-v4:26.+' 32 | compile 'com.android.support:design:26.+' 33 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 34 | compile 'com.jakewharton:butterknife:8.5.1' 35 | compile 'com.google.code.gson:gson:2.6.2' 36 | testCompile 'junit:junit:4.12' 37 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1' 38 | } 39 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/bigerdranch/android/test/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.bigerdranch.android.test; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.bigerdranch.android.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 33 | 37 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigerdranch/android/test/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.bigerdranch.android.test; 2 | 3 | import android.content.Intent; 4 | import android.database.sqlite.SQLiteDatabase; 5 | import android.graphics.Bitmap; 6 | import android.os.Bundle; 7 | import android.support.v7.app.AlertDialog; 8 | import android.view.View; 9 | import android.support.design.widget.NavigationView; 10 | import android.support.v4.view.GravityCompat; 11 | import android.support.v4.widget.DrawerLayout; 12 | import android.support.v7.app.ActionBarDrawerToggle; 13 | import android.support.v7.app.AppCompatActivity; 14 | import android.support.v7.widget.Toolbar; 15 | import android.view.Menu; 16 | import android.view.MenuItem; 17 | import android.widget.Button; 18 | import android.widget.EditText; 19 | import android.widget.ImageView; 20 | import android.widget.TextView; 21 | import android.widget.Toast; 22 | 23 | import com.bigerdranch.android.test.dao.DatabaseHelper; 24 | import com.bigerdranch.android.test.dao.MyDao; 25 | import com.bigerdranch.android.test.setting.Scan; 26 | import com.bigerdranch.android.test.setting.qrCreat; 27 | import com.google.zxing.BarcodeFormat; 28 | import com.google.zxing.MultiFormatWriter; 29 | import com.google.zxing.WriterException; 30 | import com.google.zxing.common.BitMatrix; 31 | import com.google.zxing.integration.android.*; 32 | import com.journeyapps.barcodescanner.BarcodeEncoder; 33 | 34 | public class MainActivity extends AppCompatActivity 35 | implements NavigationView.OnNavigationItemSelectedListener { 36 | 37 | private TextView tv_content; 38 | private EditText et_input; 39 | private ImageView img; 40 | private Button btnSan; 41 | private Button btn_generate; 42 | 43 | @Override 44 | protected void onCreate(Bundle savedInstanceState) { 45 | super.onCreate(savedInstanceState); 46 | setContentView(R.layout.activity_main); 47 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 48 | setSupportActionBar(toolbar); 49 | 50 | //二维码,初始化监控 51 | init_all(); 52 | 53 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 54 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( 55 | this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 56 | drawer.setDrawerListener(toggle); 57 | toggle.syncState(); 58 | 59 | NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 60 | navigationView.setNavigationItemSelectedListener(this); 61 | } 62 | //初始化 63 | private void init_all(){ 64 | DatabaseHelper databaseHelper = new DatabaseHelper(MainActivity.this); 65 | databaseHelper.getWritableDatabase().query("pwdinf",null,null,null,null,null,null); 66 | tv_content = (TextView) findViewById(R.id.tv_content); 67 | et_input = (EditText) findViewById(R.id.et_input); 68 | img = (ImageView) findViewById(R.id.img); 69 | btnSan = (Button) findViewById(R.id.btnSan); 70 | btn_generate = (Button) findViewById(R.id.btn_generate); 71 | btnSan.setOnClickListener(new View.OnClickListener() { 72 | @Override 73 | public void onClick(View view) { 74 | IntentIntegrator intentIntegrator = new IntentIntegrator(MainActivity.this); 75 | intentIntegrator.setOrientationLocked(true) 76 | .setCaptureActivity(Scan.class) // 设置自定义的activity是CustomActivity 77 | .initiateScan(); // 初始化扫描 78 | } 79 | }); 80 | btn_generate.setOnClickListener(new View.OnClickListener() { 81 | @Override 82 | public void onClick(View view) { 83 | String str = et_input.getText().toString();//输入的内容 84 | if (str.equals("")) { 85 | Toast.makeText(MainActivity.this, "输入不能为空", Toast.LENGTH_SHORT).show(); 86 | } else { 87 | Bitmap bitmap = qrCreat.createQRCodeBitmap(str,480,480); 88 | img.setImageBitmap(bitmap); 89 | } 90 | } 91 | }); 92 | } 93 | //二维码扫描 94 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 95 | IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); 96 | if (result != null) { 97 | if (result.getContents() == null) { 98 | Toast.makeText(this, "取消扫描", Toast.LENGTH_LONG).show(); 99 | } else { 100 | tv_content.setText(result.getContents()); 101 | tv_content.setHeight(20); 102 | } 103 | } else { 104 | super.onActivityResult(requestCode, resultCode, data); 105 | } 106 | } 107 | 108 | 109 | @Override 110 | public void onBackPressed() { 111 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 112 | if (drawer.isDrawerOpen(GravityCompat.START)) { 113 | drawer.closeDrawer(GravityCompat.START); 114 | } else { 115 | super.onBackPressed(); 116 | } 117 | } 118 | 119 | @Override 120 | public boolean onCreateOptionsMenu(Menu menu) { 121 | // Inflate the menu; this adds items to the action bar if it is present. 122 | getMenuInflater().inflate(R.menu.main, menu); 123 | return true; 124 | } 125 | 126 | @Override 127 | public boolean onOptionsItemSelected(MenuItem item) { 128 | // Handle action bar item clicks here. The action bar will 129 | // automatically handle clicks on the Home/Up button, so long 130 | // as you specify a parent activity in AndroidManifest.xml. 131 | int id = item.getItemId(); 132 | Intent intent = new Intent(); 133 | //noinspection SimplifiableIfStatement 134 | if (id == R.id.action_settings) { 135 | intent.setClass(MainActivity.this, settings.class); 136 | startActivity(intent); 137 | return true; 138 | } 139 | 140 | return super.onOptionsItemSelected(item); 141 | } 142 | 143 | @SuppressWarnings("StatementWithEmptyBody") 144 | @Override 145 | public boolean onNavigationItemSelected(MenuItem item) { 146 | // Handle navigation view item clicks here. 147 | int id = item.getItemId(); 148 | Intent intent = new Intent(); 149 | if (id == R.id.qr_code) { 150 | // Handle the camera action 151 | intent.setClass(MainActivity.this, MainActivity.class); 152 | startActivity(intent); 153 | } else if (id == R.id.password) { 154 | intent.setClass(MainActivity.this, password.class); 155 | startActivity(intent); 156 | } else if (id == R.id.management) { 157 | intent.setClass(MainActivity.this, management.class); 158 | startActivity(intent); 159 | } else if (id == R.id.other) { 160 | intent.setClass(MainActivity.this, other.class); 161 | startActivity(intent); 162 | } 163 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 164 | drawer.closeDrawer(GravityCompat.START); 165 | return true; 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigerdranch/android/test/dao/AesTest.java: -------------------------------------------------------------------------------- 1 | package com.bigerdranch.android.test.dao; 2 | 3 | /** 4 | * Created by Administrator on 2017/12/4. 5 | */ 6 | 7 | import java.security.Key; 8 | import java.security.SecureRandom; 9 | 10 | import javax.crypto.Cipher; 11 | import javax.crypto.SecretKey; 12 | import javax.crypto.spec.SecretKeySpec; 13 | 14 | //AES算法加密 15 | public class AesTest { 16 | public static byte[] encrypt(byte[] datasource, String password) throws Exception { 17 | SecureRandom random = new SecureRandom(); 18 | Key key = toKey(password.getBytes()); 19 | Cipher cipher = Cipher.getInstance("AES"); 20 | cipher.init(Cipher.ENCRYPT_MODE, key, random); 21 | return cipher.doFinal(datasource); 22 | } 23 | //AES解密 24 | public static byte[] decrypt(byte[] src, String password) throws Exception { 25 | SecureRandom random = new SecureRandom(); 26 | Key key = toKey(password.getBytes()); 27 | Cipher cipher = Cipher.getInstance("AES"); 28 | cipher.init(Cipher.DECRYPT_MODE, key, random); 29 | return cipher.doFinal(src); 30 | } 31 | private static Key toKey(byte[] key) throws Exception { 32 | SecretKey secretKey = new SecretKeySpec(key, "AES"); 33 | return secretKey; 34 | } 35 | //二进制转换为字符串 36 | public static String byte2String(byte[] b) { 37 | StringBuilder hs = new StringBuilder(); 38 | String stmp; 39 | for (int n = 0; b != null && n < b.length; n++) { 40 | stmp = Integer.toHexString(b[n] & 0XFF); 41 | if (stmp.length() == 1) 42 | hs.append('0'); 43 | hs.append(stmp); 44 | } 45 | return hs.toString(); 46 | } 47 | //字符串转换为二进制 48 | public static byte[] str2Byte(String strIn) throws NumberFormatException { 49 | byte[] arrB = strIn.getBytes(); 50 | int iLen = arrB.length; 51 | byte[] arrOut = new byte[iLen / 2]; 52 | for (int i = 0; i < iLen; i = i + 2) { 53 | String strTmp = new String(arrB, i, 2); 54 | arrOut[i / 2] = (byte) Integer.parseInt(strTmp, 16); 55 | } 56 | return arrOut; 57 | } 58 | // public static void main(String[] args) throws Exception { 59 | // String str = "abddddc123tesaabbc"; 60 | // String password = "1234567890ABCDEF"; 61 | // System.out.println("加密前:" + str); 62 | // byte[] result = AesTest.encrypt(str.getBytes(),password); 63 | // String res = byte2String(result); 64 | // System.out.println("加密后:"+res); 65 | // byte[] decryResult = AesTest.decrypt(str2Byte(res), password); 66 | // System.out.println("解密后:"+new String(decryResult)); 67 | // 68 | // } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigerdranch/android/test/dao/DatabaseHelper.java: -------------------------------------------------------------------------------- 1 | package com.bigerdranch.android.test.dao; 2 | 3 | import android.content.ContentValues; 4 | import android.content.Context; 5 | import android.database.Cursor; 6 | import android.database.sqlite.SQLiteDatabase; 7 | import android.database.sqlite.SQLiteDatabase.CursorFactory; 8 | import android.database.sqlite.SQLiteException; 9 | import android.database.sqlite.SQLiteOpenHelper; 10 | 11 | import java.io.IOException; 12 | 13 | public class DatabaseHelper extends SQLiteOpenHelper { 14 | private static final String databaseName = "pwd.db";//数据库名称 15 | private static final String tableName = "pwdinf"; 16 | private static final String databasePath = "/data/data/com.bigerdranch.android.test/databases/"; 17 | public DatabaseHelper(Context context, String name, CursorFactory factory,int version) {//构造函数,接收上下文作为参数,直接调用的父类的构造函数 18 | super(context, name, factory, version); 19 | // TODO Auto-generated constructor stub 20 | } 21 | public DatabaseHelper(Context context) {//构造函数,接收上下文作为参数,直接调用的父类的构造函数 22 | super(context,databaseName,null,1); 23 | // TODO Auto-generated constructor stub 24 | } 25 | @Override 26 | public void onCreate(SQLiteDatabase sqLiteDatabase) {//创建数据表pwdinf(id,name,username,password) 27 | String str = "CREATE TABLE "+tableName+" ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,'name' VARCHAR(100) NOT NULL,'username' VARCHAR(100) NOT NULL,'password' VARCHAR(200) NOT NULL)"; 28 | sqLiteDatabase.execSQL(str); 29 | } 30 | 31 | @Override 32 | public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { 33 | sqLiteDatabase.execSQL("DROP TABLE IF EXISTS"+tableName); 34 | onCreate(sqLiteDatabase); 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /app/src/main/java/com/bigerdranch/android/test/dao/JsonTodata.java: -------------------------------------------------------------------------------- 1 | package com.bigerdranch.android.test.dao; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Created by Administrator on 2017/12/3. 7 | */ 8 | 9 | public class JsonTodata { 10 | @SerializedName("http") 11 | private String name; 12 | @SerializedName("url") 13 | private String username; 14 | @SerializedName("all") 15 | private String password; 16 | 17 | public JsonTodata() { 18 | } 19 | 20 | public JsonTodata(String name, String username, String password) { 21 | this.name = name; 22 | this.username = username; 23 | this.password = password; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public String getUsername() { 35 | return username; 36 | } 37 | 38 | public void setUsername(String username) { 39 | this.username = username; 40 | } 41 | 42 | public String getPassword() { 43 | return password; 44 | } 45 | 46 | public void setPassword(String password) { 47 | this.password = password; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigerdranch/android/test/dao/MyDao.java: -------------------------------------------------------------------------------- 1 | package com.bigerdranch.android.test.dao; 2 | 3 | import android.content.ContentValues; 4 | import android.content.Context; 5 | import android.database.Cursor; 6 | import android.database.sqlite.SQLiteDatabase; 7 | 8 | /** 9 | * Created by Administrator on 2017/12/2. 10 | */ 11 | 12 | public class MyDao { 13 | private SQLiteDatabase sqLiteDatabase; 14 | private DatabaseHelper databaseHelper; 15 | 16 | public MyDao(Context context) { 17 | databaseHelper=new DatabaseHelper(context,"pwd.db",null,1); 18 | } 19 | 20 | public Cursor getAll(String orderBy, String where) {//返回表中的数据,where是调用时候传进来的搜索内容,orderby是设置中传进来的列表排序类型 21 | String sql = "SELECT * FORM pwdinf"; 22 | StringBuffer stringBuffer = new StringBuffer(sql); 23 | if (where != null) { 24 | stringBuffer.append("WHERE"); 25 | stringBuffer.append(where); 26 | } 27 | if (orderBy != null) { 28 | stringBuffer.append("ORDER BY"); 29 | stringBuffer.append(orderBy); 30 | } 31 | return (databaseHelper.getReadableDatabase().rawQuery(stringBuffer.toString(), null)); 32 | } 33 | 34 | public Cursor getAll(){ 35 | Cursor cursor = databaseHelper.getWritableDatabase().query("pwdinf",null,null,null,null,null,null); 36 | return cursor; 37 | } 38 | 39 | public Cursor getByName(PwdData pwdData) {//根据点击事件获取name,查询数据库 40 | String sql = "SELECT * FORM pwdinf WHERE name=?"; 41 | String[] name = {pwdData.getName()}; 42 | return (databaseHelper.getReadableDatabase().rawQuery(sql, name)); 43 | } 44 | 45 | public Cursor getByUserName(PwdData pwdData) {//根据点击事件获取username,查询数据库 46 | String sql = "SELECT * FORM pwdinf WHERE name=?"; 47 | String[] name = {pwdData.getUsername()}; 48 | return (databaseHelper.getReadableDatabase().rawQuery(sql, name)); 49 | } 50 | 51 | public void insert(PwdData pwdData) { 52 | ContentValues contentValues = new ContentValues(); 53 | contentValues.put("name", pwdData.getName()); 54 | contentValues.put("username", pwdData.getUsername()); 55 | contentValues.put("password", pwdData.getPassword()); 56 | databaseHelper.getWritableDatabase().insert("pwdinf", null, contentValues); 57 | } 58 | 59 | public void update(PwdData pwdData, String id) { 60 | ContentValues contentValues = new ContentValues(); 61 | String[] args = {id}; 62 | contentValues.put("name", pwdData.getName()); 63 | contentValues.put("username", pwdData.getUsername()); 64 | contentValues.put("password", pwdData.getPassword()); 65 | databaseHelper.getWritableDatabase().update("pwdinf", contentValues, "id=?", args); 66 | } 67 | 68 | public void delete(String id){ 69 | String[] args = {id}; 70 | databaseHelper.getWritableDatabase().delete("pwdinf","id=?",args); 71 | } 72 | 73 | public String getId(Cursor cursor) { 74 | return (cursor.getString(cursor.getColumnIndex("id"))); 75 | } 76 | 77 | public String getName(Cursor cursor) { 78 | return (cursor.getString(cursor.getColumnIndex("name"))); 79 | } 80 | 81 | public String getUserName(Cursor cursor) { 82 | return (cursor.getString(cursor.getColumnIndex("username"))); 83 | } 84 | 85 | public String getPassword(Cursor cursor) { 86 | return (cursor.getString(cursor.getColumnIndex("password"))); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigerdranch/android/test/dao/PwdData.java: -------------------------------------------------------------------------------- 1 | package com.bigerdranch.android.test.dao; 2 | 3 | import android.database.sqlite.SQLiteDatabase; 4 | 5 | public class PwdData { 6 | private String id; 7 | private String name; 8 | private String username; 9 | private String password; 10 | 11 | public PwdData() { 12 | } 13 | 14 | public PwdData(JsonTodata jsonTodata) { 15 | this.name = jsonTodata.getName(); 16 | this.username = jsonTodata.getUsername(); 17 | this.password = jsonTodata.getPassword(); 18 | } 19 | 20 | public PwdData(String id, String name, String username, String password) { 21 | this.id = id; 22 | this.name = name; 23 | this.username = username; 24 | this.password = password; 25 | } 26 | 27 | public PwdData(String name, String username, String password) { 28 | this.name = name; 29 | this.username = username; 30 | this.password = password; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "{"+"\"http\":\"" + name +"\",\"url\":\"" + username +"\",\"all\":\"" + password + "\"}"; 36 | } 37 | 38 | public String getId() { 39 | return id; 40 | } 41 | 42 | public void setId(String id) { 43 | this.id = id; 44 | } 45 | 46 | public String getName() { 47 | return name; 48 | } 49 | 50 | public void setName(String name) { 51 | this.name = name; 52 | } 53 | 54 | public String getUsername() { 55 | return username; 56 | } 57 | 58 | public void setUsername(String username) { 59 | this.username = username; 60 | } 61 | 62 | public String getPassword() { 63 | return password; 64 | } 65 | 66 | public void setPassword(String password) { 67 | this.password = password; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigerdranch/android/test/management.java: -------------------------------------------------------------------------------- 1 | package com.bigerdranch.android.test; 2 | 3 | import android.content.Intent; 4 | import android.database.Cursor; 5 | import android.os.Bundle; 6 | import android.support.design.widget.NavigationView; 7 | import android.support.v4.view.GravityCompat; 8 | import android.support.v4.widget.DrawerLayout; 9 | import android.support.v7.app.ActionBarDrawerToggle; 10 | import android.support.v7.app.AlertDialog; 11 | import android.support.v7.app.AppCompatActivity; 12 | import android.support.v7.widget.Toolbar; 13 | import android.view.Menu; 14 | import android.view.MenuItem; 15 | import android.view.View; 16 | import android.view.Window; 17 | import android.widget.Button; 18 | import android.widget.CheckBox; 19 | import android.widget.EditText; 20 | import android.widget.ImageView; 21 | import android.widget.SeekBar; 22 | import android.widget.TextView; 23 | import android.widget.Toast; 24 | 25 | import com.bigerdranch.android.test.dao.AesTest; 26 | import com.bigerdranch.android.test.dao.JsonTodata; 27 | import com.bigerdranch.android.test.dao.MyDao; 28 | import com.bigerdranch.android.test.dao.PwdData; 29 | import com.bigerdranch.android.test.setting.RandomPassword; 30 | import com.bigerdranch.android.test.setting.Scan; 31 | import com.google.gson.Gson; 32 | import com.google.zxing.integration.android.IntentIntegrator; 33 | import com.google.zxing.integration.android.IntentResult; 34 | 35 | 36 | public class management extends AppCompatActivity 37 | implements NavigationView.OnNavigationItemSelectedListener { 38 | //表单数据 39 | private EditText pwd_editText_name; 40 | private EditText pwd_editText_pass; 41 | private EditText pwd_editText_username; 42 | private ImageView pwd_img; 43 | private Button pwd_button_submit; 44 | private Button pwd_button_createQr; 45 | private Button pwd_button_clean; 46 | private Button pwd_button_createPassword; 47 | private Button shareToDb_button; 48 | final MyDao myDao = new MyDao(this); 49 | 50 | @Override 51 | protected void onCreate(Bundle savedInstanceState) { 52 | super.onCreate(savedInstanceState); 53 | setContentView(R.layout.activity_management); 54 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 55 | setSupportActionBar(toolbar); 56 | 57 | //获取控件,监控操作 58 | init_all(); 59 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 60 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( 61 | this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 62 | drawer.setDrawerListener(toggle); 63 | toggle.syncState(); 64 | 65 | NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 66 | navigationView.setNavigationItemSelectedListener(this); 67 | } 68 | 69 | private void init_all() { 70 | pwd_editText_name = (EditText) findViewById(R.id.pwd_editText_name); 71 | pwd_editText_pass = (EditText) findViewById(R.id.pwd_editText_pass); 72 | pwd_editText_username = (EditText) findViewById(R.id.pwd_editText_username); 73 | // pwd_img = (ImageView) findViewById(R.id.pwd_img); 74 | pwd_button_submit = (Button) findViewById(R.id.pwd_button_submit); 75 | // pwd_button_createQr = (Button) findViewById(R.id.pwd_button_createQr); 76 | pwd_button_clean = (Button) findViewById(R.id.pwd_button_clean); 77 | pwd_button_createPassword = (Button) findViewById(R.id.pwd_button_createPassword); 78 | shareToDb_button = (Button) findViewById(R.id.ShareToDb_button); 79 | //数据库对象 80 | Cursor cursor = null;//存储查询对象 81 | 82 | //自定义数据库帮助类 83 | if (cursor != null) { 84 | stopManagingCursor(cursor); 85 | cursor.close(); 86 | } 87 | pwd_button_submit.setOnClickListener(new View.OnClickListener() { 88 | @Override 89 | public void onClick(View view) { 90 | String name = pwd_editText_name.getText().toString(); 91 | String pass = pwd_editText_pass.getText().toString(); 92 | String user = pwd_editText_username.getText().toString(); 93 | if (name.equals("") && pass.equals("") && user.equals("")) { 94 | Toast.makeText(management.this, "名称,用户名,密码不能为空", Toast.LENGTH_SHORT).show(); 95 | } else if (pass.equals("")) { 96 | Toast.makeText(management.this, "密码不能为空", Toast.LENGTH_SHORT).show(); 97 | } else { 98 | PwdData pwdData = new PwdData(); 99 | pwdData.setName(name); 100 | pwdData.setUsername(user); 101 | pwdData.setPassword(pass); 102 | myDao.insert(pwdData); 103 | Toast.makeText(management.this, "名称,用户名,密码写入数据库", Toast.LENGTH_SHORT).show(); 104 | } 105 | 106 | } 107 | }); 108 | //生成二维码 109 | // pwd_button_createQr.setOnClickListener(new View.OnClickListener() { 110 | // @Override 111 | // public void onClick(View view) { 112 | // String name = pwd_editText_name.getText().toString(); 113 | // String pass = pwd_editText_pass.getText().toString(); 114 | // String user = pwd_editText_username.getText().toString(); 115 | // if (name.equals("") && pass.equals("") && user.equals("")) { 116 | // Toast.makeText(management.this, "名称,用户名,密码不能为空", Toast.LENGTH_SHORT).show(); 117 | // } else if (pass.equals("")) { 118 | // Toast.makeText(management.this, "密码不能为空", Toast.LENGTH_SHORT).show(); 119 | // } else { 120 | // PwdData pwdData = new PwdData(); 121 | // pwdData.setName(name); 122 | // pwdData.setUsername(user); 123 | // pwdData.setPassword(pass); 124 | // String str = pwdData.toString(); 125 | // Bitmap bitmap = qrCreat.createQRCodeBitmap(str, 480, 480); 126 | // pwd_img.setImageBitmap(bitmap); 127 | // } 128 | // } 129 | // }); 130 | 131 | pwd_button_clean.setOnClickListener(new View.OnClickListener() { 132 | @Override 133 | public void onClick(View view) { 134 | pwd_editText_name.setText(""); 135 | pwd_editText_pass.setText(""); 136 | } 137 | }); 138 | 139 | pwd_button_createPassword.setOnClickListener(new View.OnClickListener() { 140 | @Override 141 | public void onClick(View view) { 142 | final AlertDialog builder = new AlertDialog.Builder(management.this).create(); 143 | builder.show(); 144 | Window window = builder.getWindow(); 145 | window.setContentView(R.layout.create_password); 146 | final SeekBar seekBar = (SeekBar) window.findViewById(R.id.seekBar); 147 | final CheckBox checkBox_upperCase = (CheckBox) window.findViewById(R.id.checkBox_uppercase); 148 | final CheckBox checkBox_lowerCase = (CheckBox) window.findViewById(R.id.checkBox_lowercase); 149 | final CheckBox checkBox_digital = (CheckBox) window.findViewById(R.id.checkBox_digital); 150 | final CheckBox checkBox_specialChar = (CheckBox) window.findViewById(R.id.checkBox_specialchar); 151 | final TextView length = (TextView)window.findViewById(R.id.length); 152 | Button button_determine = (Button) window.findViewById(R.id.button_determine); 153 | Button button_cancal = (Button) window.findViewById(R.id.button_cancal); 154 | seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 155 | @Override 156 | public void onProgressChanged(SeekBar seekBar, int i, boolean b) { 157 | length.setText(seekBar.getProgress()+""); 158 | } 159 | 160 | @Override 161 | public void onStartTrackingTouch(SeekBar seekBar) { 162 | 163 | } 164 | 165 | @Override 166 | public void onStopTrackingTouch(SeekBar seekBar) { 167 | 168 | } 169 | }); 170 | //确定键设值 171 | button_determine.setOnClickListener(new View.OnClickListener() { 172 | @Override 173 | public void onClick(View view) { 174 | String string = ""; 175 | if (checkBox_upperCase.isChecked()) { 176 | string += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 177 | } 178 | if (checkBox_lowerCase.isChecked()) { 179 | string += "abcdefghijklmnopqrstuvwxyz"; 180 | } 181 | if (checkBox_digital.isChecked()) { 182 | string += "1234567890"; 183 | } 184 | if (checkBox_specialChar.isChecked()) { 185 | string += "~!@#$%^&*.?"; 186 | } 187 | int PasswordLenth = seekBar.getProgress(); 188 | //密码生成 189 | RandomPassword randomPassword = new RandomPassword(); 190 | String password = randomPassword.makeRandomPassword(PasswordLenth,string); 191 | //显示密码 192 | pwd_editText_pass.setText(password); 193 | builder.cancel();//退出 194 | } 195 | }); 196 | //取消键设值 197 | button_cancal.setOnClickListener(new View.OnClickListener() { 198 | @Override 199 | public void onClick(View view) { 200 | builder.cancel();//退出 201 | } 202 | }); 203 | } 204 | }); 205 | 206 | shareToDb_button.setOnClickListener(new View.OnClickListener() { 207 | @Override 208 | public void onClick(View view) { 209 | IntentIntegrator intentIntegrator = new IntentIntegrator(management.this); 210 | intentIntegrator.setOrientationLocked(true) 211 | .setCaptureActivity(Scan.class) // 设置自定义的activity是CustomActivity 212 | .initiateScan(); // 初始化扫描 213 | } 214 | }); 215 | } 216 | 217 | //二维码扫描 218 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 219 | IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); 220 | if (result != null) { 221 | if (result.getContents() == null) { 222 | Toast.makeText(this, "取消扫描", Toast.LENGTH_LONG).show(); 223 | } else { 224 | String password = "1234567890ABCDEF"; 225 | String string = result.getContents(); 226 | try { 227 | byte[] decryResult = AesTest.decrypt(AesTest.str2Byte(string), password); 228 | string = new String(decryResult); 229 | } catch (Exception e) { 230 | e.printStackTrace(); 231 | } 232 | Gson gson = new Gson(); 233 | JsonTodata jsonTodata = gson.fromJson(string, JsonTodata.class); 234 | PwdData pwdData = new PwdData(jsonTodata); 235 | myDao.insert(pwdData); 236 | Toast.makeText(management.this, "名称,用户名,密码写入数据库", Toast.LENGTH_SHORT).show(); 237 | } 238 | } else { 239 | super.onActivityResult(requestCode, resultCode, data); 240 | } 241 | } 242 | 243 | 244 | @Override 245 | public void onBackPressed() { 246 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 247 | if (drawer.isDrawerOpen(GravityCompat.START)) { 248 | drawer.closeDrawer(GravityCompat.START); 249 | } else { 250 | super.onBackPressed(); 251 | } 252 | } 253 | 254 | @Override 255 | public boolean onCreateOptionsMenu(Menu menu) { 256 | // Inflate the menu; this adds items to the action bar if it is present. 257 | getMenuInflater().inflate(R.menu.management, menu); 258 | return true; 259 | } 260 | 261 | @Override 262 | public boolean onOptionsItemSelected(MenuItem item) { 263 | // Handle action bar item clicks here. The action bar will 264 | // automatically handle clicks on the Home/Up button, so long 265 | // as you specify a parent activity in AndroidManifest.xml. 266 | int id = item.getItemId(); 267 | Intent intent = new Intent(); 268 | //noinspection SimplifiableIfStatement 269 | if (id == R.id.action_settings) { 270 | intent.setClass(management.this, settings.class); 271 | startActivity(intent); 272 | return true; 273 | } 274 | 275 | return super.onOptionsItemSelected(item); 276 | } 277 | 278 | @SuppressWarnings("StatementWithEmptyBody") 279 | @Override 280 | public boolean onNavigationItemSelected(MenuItem item) { 281 | // Handle navigation view item clicks here. 282 | int id = item.getItemId(); 283 | Intent intent = new Intent(); 284 | if (id == R.id.qr_code) { 285 | // Handle the camera action 286 | intent.setClass(management.this, MainActivity.class); 287 | startActivity(intent); 288 | } else if (id == R.id.password) { 289 | intent.setClass(management.this, password.class); 290 | startActivity(intent); 291 | } else if (id == R.id.management) { 292 | intent.setClass(management.this, management.class); 293 | startActivity(intent); 294 | } else if (id == R.id.other) { 295 | intent.setClass(management.this, other.class); 296 | startActivity(intent); 297 | } 298 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 299 | drawer.closeDrawer(GravityCompat.START); 300 | return true; 301 | } 302 | } 303 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigerdranch/android/test/other.java: -------------------------------------------------------------------------------- 1 | package com.bigerdranch.android.test; 2 | 3 | import android.content.DialogInterface; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | import android.os.Bundle; 7 | import android.support.design.widget.FloatingActionButton; 8 | import android.support.design.widget.Snackbar; 9 | import android.support.v7.app.AlertDialog; 10 | import android.view.View; 11 | import android.support.design.widget.NavigationView; 12 | import android.support.v4.view.GravityCompat; 13 | import android.support.v4.widget.DrawerLayout; 14 | import android.support.v7.app.ActionBarDrawerToggle; 15 | import android.support.v7.app.AppCompatActivity; 16 | import android.support.v7.widget.Toolbar; 17 | import android.view.Menu; 18 | import android.view.MenuItem; 19 | import android.widget.TextView; 20 | 21 | public class other extends AppCompatActivity 22 | implements NavigationView.OnNavigationItemSelectedListener { 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.activity_other); 28 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 29 | setSupportActionBar(toolbar); 30 | 31 | 32 | init(); 33 | 34 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 35 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( 36 | this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 37 | drawer.setDrawerListener(toggle); 38 | toggle.syncState(); 39 | 40 | NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 41 | navigationView.setNavigationItemSelectedListener(this); 42 | } 43 | 44 | private void init() { 45 | TextView contact = (TextView) findViewById(R.id.other_contact); 46 | contact.setOnClickListener(new View.OnClickListener() { 47 | @Override 48 | public void onClick(View view) { 49 | Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + 12345)); 50 | intent.putExtra("sms_body", "BUG report:"); 51 | startActivity(intent); 52 | } 53 | }); 54 | TextView help = (TextView) findViewById(R.id.other_help); 55 | help.setOnClickListener(new View.OnClickListener() { 56 | @Override 57 | public void onClick(View view) { 58 | AlertDialog.Builder builder = new AlertDialog.Builder(other.this); 59 | builder.setTitle("帮助"); 60 | builder.setMessage("这是一款密码管理器,可以用来生成记录各种密码。"); 61 | builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { 62 | @Override 63 | public void onClick(DialogInterface dialogInterface, int i) { 64 | 65 | } 66 | }); 67 | builder.show(); 68 | } 69 | }); 70 | TextView function = (TextView)findViewById(R.id.other_function); 71 | function.setOnClickListener(new View.OnClickListener() { 72 | @Override 73 | public void onClick(View view) { 74 | AlertDialog.Builder builder = new AlertDialog.Builder(other.this); 75 | builder.setTitle("功能介绍"); 76 | builder.setMessage("1.密码本地存储\n2.二维码扫描存储\n3.二维码分享密码\n4.二维码加密"); 77 | builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { 78 | @Override 79 | public void onClick(DialogInterface dialogInterface, int i) { 80 | 81 | } 82 | }); 83 | builder.show(); 84 | } 85 | }); 86 | } 87 | 88 | @Override 89 | public void onBackPressed() { 90 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 91 | if (drawer.isDrawerOpen(GravityCompat.START)) { 92 | drawer.closeDrawer(GravityCompat.START); 93 | } else { 94 | super.onBackPressed(); 95 | } 96 | } 97 | 98 | @Override 99 | public boolean onCreateOptionsMenu(Menu menu) { 100 | // Inflate the menu; this adds items to the action bar if it is present. 101 | getMenuInflater().inflate(R.menu.other, menu); 102 | return true; 103 | } 104 | 105 | @Override 106 | public boolean onOptionsItemSelected(MenuItem item) { 107 | // Handle action bar item clicks here. The action bar will 108 | // automatically handle clicks on the Home/Up button, so long 109 | // as you specify a parent activity in AndroidManifest.xml. 110 | int id = item.getItemId(); 111 | Intent intent = new Intent(); 112 | //noinspection SimplifiableIfStatement 113 | if (id == R.id.action_settings) { 114 | intent.setClass(other.this, settings.class); 115 | startActivity(intent); 116 | return true; 117 | } 118 | 119 | return super.onOptionsItemSelected(item); 120 | } 121 | 122 | @SuppressWarnings("StatementWithEmptyBody") 123 | @Override 124 | public boolean onNavigationItemSelected(MenuItem item) { 125 | // Handle navigation view item clicks here. 126 | int id = item.getItemId(); 127 | Intent intent = new Intent(); 128 | if (id == R.id.qr_code) { 129 | // Handle the camera action 130 | intent.setClass(other.this, MainActivity.class); 131 | startActivity(intent); 132 | } else if (id == R.id.password) { 133 | intent.setClass(other.this, password.class); 134 | startActivity(intent); 135 | } else if (id == R.id.management) { 136 | intent.setClass(other.this, management.class); 137 | startActivity(intent); 138 | } else if (id == R.id.other) { 139 | intent.setClass(other.this, other.class); 140 | startActivity(intent); 141 | } 142 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 143 | drawer.closeDrawer(GravityCompat.START); 144 | return true; 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigerdranch/android/test/password.java: -------------------------------------------------------------------------------- 1 | package com.bigerdranch.android.test; 2 | 3 | import android.content.DialogInterface; 4 | import android.content.Intent; 5 | import android.database.Cursor; 6 | import android.database.SQLException; 7 | import android.graphics.Bitmap; 8 | import android.os.Bundle; 9 | import android.support.v7.app.AlertDialog; 10 | import android.view.Gravity; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.support.design.widget.NavigationView; 14 | import android.support.v4.view.GravityCompat; 15 | import android.support.v4.widget.DrawerLayout; 16 | import android.support.v7.app.ActionBarDrawerToggle; 17 | import android.support.v7.app.AppCompatActivity; 18 | import android.support.v7.widget.Toolbar; 19 | import android.view.Menu; 20 | import android.view.MenuItem; 21 | import android.view.ViewGroup; 22 | import android.view.View.OnClickListener; 23 | import android.view.Window; 24 | import android.widget.AbsListView; 25 | import android.widget.BaseAdapter; 26 | import android.widget.Button; 27 | import android.widget.CheckBox; 28 | import android.widget.CompoundButton; 29 | import android.widget.CompoundButton.OnCheckedChangeListener; 30 | import android.widget.EditText; 31 | import android.widget.ImageView; 32 | import android.widget.LinearLayout; 33 | import android.widget.ListView; 34 | import android.widget.TextView; 35 | import android.widget.Toast; 36 | 37 | import com.bigerdranch.android.test.dao.AesTest; 38 | import com.bigerdranch.android.test.dao.MyDao; 39 | import com.bigerdranch.android.test.dao.PwdData; 40 | import com.bigerdranch.android.test.setting.SwipeListView; 41 | import com.bigerdranch.android.test.setting.qrCreat; 42 | 43 | import java.util.ArrayList; 44 | import java.util.HashSet; 45 | import java.util.List; 46 | import java.util.Set; 47 | 48 | public class password extends AppCompatActivity 49 | implements NavigationView.OnNavigationItemSelectedListener { 50 | private List pwdDatasList = new ArrayList();//所有列表数据 51 | private Set sets = new HashSet(); 52 | MyDao myDao = new MyDao(this); 53 | 54 | @Override 55 | protected void onCreate(Bundle savedInstanceState) { 56 | super.onCreate(savedInstanceState); 57 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,WindowManager.LayoutParams.FLAG_SECURE); 58 | 59 | setContentView(R.layout.activity_password); 60 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 61 | setSupportActionBar(toolbar); 62 | 63 | //初始化操作 64 | init_all(); 65 | 66 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 67 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( 68 | this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 69 | drawer.setDrawerListener(toggle); 70 | toggle.syncState(); 71 | 72 | NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 73 | navigationView.setNavigationItemSelectedListener(this); 74 | } 75 | 76 | private void init_all() { 77 | ListView listView = (ListView) findViewById(R.id.password_listView); 78 | try { 79 | Cursor cursor = myDao.getAll(); 80 | while (cursor.moveToNext()) { 81 | String id = myDao.getId(cursor); 82 | String name = myDao.getName(cursor); 83 | String username = myDao.getUserName(cursor); 84 | String password = myDao.getPassword(cursor); 85 | PwdData pwdData = new PwdData(id, name, username, password); 86 | pwdDatasList.add(pwdData); 87 | } 88 | } catch (SQLException e) { 89 | 90 | } 91 | 92 | if (pwdDatasList.isEmpty()) { 93 | // LinearLayout password_LinerLayout = (LinearLayout) findViewById(R.id.password_listView); 94 | // TextView textViewEmptyShow = new TextView(this); 95 | // textViewEmptyShow.setTextSize(24); 96 | // textViewEmptyShow.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); 97 | // textViewEmptyShow.setText("暂无数据,请添加"); 98 | // password_LinerLayout.addView(textViewEmptyShow); 99 | // listView.addView(textViewEmptyShow); 100 | } else { 101 | //显示 102 | listView.setAdapter(new myAdapter()); 103 | listView.setOnScrollListener(new AbsListView.OnScrollListener() { 104 | @Override 105 | public void onScrollStateChanged(AbsListView view, int scrollState) { 106 | switch (scrollState) { 107 | //当listview开始滑动时,若有item的状态为Open,则Close,然后移除 108 | case SCROLL_STATE_TOUCH_SCROLL: 109 | if (sets.size() > 0) { 110 | for (SwipeListView s : sets) { 111 | s.setStatus(SwipeListView.Status.Close, true); 112 | sets.remove(s); 113 | } 114 | } 115 | break; 116 | } 117 | } 118 | @Override 119 | public void onScroll(AbsListView view, int firstVisibleItem, 120 | int visibleItemCount, int totalItemCount) { 121 | 122 | } 123 | }); 124 | // listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 125 | // @Override 126 | // public void onItemClick(AdapterView adapterView, View view, int i, long l) { 127 | // Toast.makeText(password.this,i,Toast.LENGTH_LONG).show(); 128 | // } 129 | // }); 130 | /* for (PwdData p : pwdDatasList){ 131 | TextView textViewNotEmptyShow = new TextView(this); 132 | textViewNotEmptyShow.setTextSize(36); 133 | textViewNotEmptyShow.setText("名称: "+p.getName()); 134 | LinearLayout linearLayoutNotEmptyShow = new LinearLayout(this); 135 | linearLayoutNotEmptyShow.addView(textViewNotEmptyShow); 136 | password_LinerLayout.addView(linearLayoutNotEmptyShow); 137 | } 138 | */ 139 | } 140 | } 141 | 142 | class MyOnSlipStatusListener implements SwipeListView.OnSwipeStatusListener { 143 | 144 | private SwipeListView slipListLayout; 145 | 146 | public MyOnSlipStatusListener(SwipeListView slipListLayout) { 147 | this.slipListLayout = slipListLayout; 148 | } 149 | 150 | @Override 151 | public void onStatusChanged(SwipeListView.Status status) { 152 | if (status == SwipeListView.Status.Open) { 153 | //若有其他的item的状态为Open,则Close,然后移除 154 | if (sets.size() > 0) { 155 | for (SwipeListView s : sets) { 156 | s.setStatus(SwipeListView.Status.Close, true); 157 | sets.remove(s); 158 | } 159 | } 160 | sets.add(slipListLayout); 161 | } else { 162 | if (sets.contains(slipListLayout)) 163 | sets.remove(slipListLayout); 164 | } 165 | } 166 | 167 | @Override 168 | public void onStartCloseAnimation() { 169 | 170 | } 171 | 172 | @Override 173 | public void onStartOpenAnimation() { 174 | 175 | } 176 | 177 | } 178 | 179 | //适配器类 180 | class myAdapter extends BaseAdapter { 181 | @Override 182 | public int getCount() { 183 | return pwdDatasList.size(); 184 | } 185 | 186 | @Override 187 | public Object getItem(int arg0) { 188 | return pwdDatasList.get(arg0); 189 | } 190 | 191 | @Override 192 | public long getItemId(int arg0) { 193 | return arg0; 194 | } 195 | 196 | @Override 197 | public View getView(final int arg0, View view, ViewGroup arg2) { 198 | if (view == null) { 199 | view = LayoutInflater.from(password.this).inflate( 200 | R.layout.slip_item_layout, null); 201 | } 202 | //listView显示 203 | TextView tv_name = (TextView) view.findViewById(R.id.tv_name); 204 | TextView tv_username = (TextView) view.findViewById(R.id.tv_username); 205 | // TextView tv_password = (TextView) view.findViewById(R.id.tv_password); 206 | tv_name.setText(pwdDatasList.get(arg0).getName()); 207 | tv_username.setText(pwdDatasList.get(arg0).getUsername()); 208 | // tv_password.setText(pwdDatasList.get(arg0).getPassword()); 209 | final SwipeListView sll_main = (SwipeListView) view 210 | .findViewById(R.id.sll_main); 211 | TextView tv_edit = (TextView) view.findViewById(R.id.tv_edit); 212 | TextView tv_share = (TextView) view.findViewById(R.id.tv_share); 213 | TextView tv_delete = (TextView) view.findViewById(R.id.tv_delete); 214 | TextView tv_see = (TextView) view.findViewById(R.id.tv_see); 215 | sll_main.setOnSwipeStatusListener(new MyOnSlipStatusListener( 216 | sll_main)); 217 | 218 | //侧滑查看监控 219 | tv_see.setOnClickListener(new OnClickListener() { 220 | @Override 221 | public void onClick(View view) { 222 | sll_main.setStatus(SwipeListView.Status.Close, true); 223 | final PwdData pwdData = pwdDatasList.get(arg0); 224 | 225 | final AlertDialog builder = new AlertDialog.Builder(password.this).create(); 226 | builder.show(); 227 | Window window = builder.getWindow(); 228 | window.setContentView(R.layout.password_show); 229 | TextView passwordShow_name = (TextView) window.findViewById(R.id.passwordShow_name); 230 | TextView passwordShow_username = (TextView) window.findViewById(R.id.passwordShow_username); 231 | final TextView passwordShow_password = (TextView) window.findViewById(R.id.passwordShow_password); 232 | final CheckBox password_passwordShow = (CheckBox) window.findViewById(R.id.password_passwordShow); 233 | Button passwordShow_cancal = (Button) window.findViewById(R.id.passwordShow_cancal); 234 | //页面设值 235 | final String space = " "; 236 | passwordShow_name.setText(space + pwdData.getName()); 237 | passwordShow_username.setText(space + pwdData.getUsername()); 238 | passwordShow_password.setText(space + "************"); 239 | password_passwordShow.setOnCheckedChangeListener(new OnCheckedChangeListener() { 240 | @Override 241 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 242 | // 通过这个方法,来监听当前的checkbox是否被选中 243 | if (isChecked) { 244 | passwordShow_password.setText(space + pwdData.getPassword()); 245 | } else { 246 | passwordShow_password.setText(space + "************"); 247 | } 248 | } 249 | }); 250 | //取消键退出 251 | passwordShow_cancal.setOnClickListener(new OnClickListener() { 252 | @Override 253 | public void onClick(View view) { 254 | notifyDataSetChanged(); 255 | builder.cancel(); 256 | } 257 | }); 258 | // notifyDataSetChanged(); 259 | } 260 | 261 | }); 262 | 263 | //侧滑分享监控 264 | tv_share.setOnClickListener(new OnClickListener() { 265 | @Override 266 | public void onClick(View view) { 267 | //AlertDialog标题设置 268 | TextView title = new TextView(password.this); 269 | title.setText("二维码分享密码"); 270 | title.setPadding(10, 10, 10, 10); 271 | title.setGravity(Gravity.CENTER); 272 | // title.setTextColor(getResources().getColor(R.color.greenBG)); 273 | title.setTextSize(23); 274 | 275 | sll_main.setStatus(SwipeListView.Status.Close, true); 276 | PwdData pwdData = pwdDatasList.get(arg0); 277 | String str = pwdData.toString(); 278 | 279 | //加密字符串 280 | String password = "1234567890ABCDEF"; 281 | AesTest aesTest = new AesTest(); 282 | try { 283 | byte[] result = AesTest.encrypt(str.getBytes(), password); 284 | str = AesTest.byte2String(result); 285 | } catch (Exception e) { 286 | e.printStackTrace(); 287 | } 288 | Bitmap bitmap = qrCreat.createQRCodeBitmap(str, 480, 480); 289 | ImageView imageView = new ImageView(password.this); 290 | imageView.setImageBitmap(bitmap); 291 | AlertDialog.Builder builder = new AlertDialog.Builder(password.this); 292 | builder.setCustomTitle(title) 293 | .setView(imageView) 294 | .setNegativeButton("取消", null) 295 | .show(); 296 | notifyDataSetChanged(); 297 | } 298 | }); 299 | //侧滑置顶监控 300 | // tv_Top.setOnClickListener(new OnClickListener() { 301 | // @Override 302 | // public void onClick(View view) { 303 | // sll_main.setStatus(SwipeListView.Status.Close, true); 304 | // PwdData str = pwdDatasList.get(arg0); 305 | // pwdDatasList.remove(arg0); 306 | // pwdDatasList.add(0, str); 307 | // notifyDataSetChanged(); 308 | // } 309 | // }); 310 | //侧滑编辑监控 311 | tv_edit.setOnClickListener(new OnClickListener() { 312 | @Override 313 | public void onClick(View view) { 314 | sll_main.setStatus(SwipeListView.Status.Close, true); 315 | final PwdData pwdData = pwdDatasList.get(arg0); 316 | //设置AlertDialog样式,自定义 317 | final AlertDialog builder = new AlertDialog.Builder(password.this).create(); 318 | builder.show(); 319 | Window window = builder.getWindow(); 320 | window.setContentView(R.layout.edit_password); 321 | final EditText edit_editText_name = (EditText) window.findViewById(R.id.edit_editText_name); 322 | final EditText edit_editText_username = (EditText) window.findViewById(R.id.edit_editText_username); 323 | final EditText edit_editText_password = (EditText) window.findViewById(R.id.edit_editText_password); 324 | Button edit_button_submit = (Button) window.findViewById(R.id.edit_button_submit); 325 | Button edit_button_cancal = (Button) window.findViewById(R.id.edit_button_cancal); 326 | //提示框填值 327 | edit_editText_name.setText(pwdData.getName()); 328 | edit_editText_username.setText(pwdData.getUsername()); 329 | edit_editText_password.setText(pwdData.getPassword()); 330 | edit_button_submit.setOnClickListener(new OnClickListener() { 331 | @Override 332 | public void onClick(View view) { 333 | String name = edit_editText_name.getText().toString(); 334 | String username = edit_editText_username.getText().toString(); 335 | String password = edit_editText_password.getText().toString(); 336 | pwdData.setName(name); 337 | pwdData.setUsername(username); 338 | pwdData.setPassword(password); 339 | myDao.update(pwdData, pwdData.getId()); 340 | notifyDataSetChanged(); 341 | builder.cancel(); 342 | } 343 | }); 344 | edit_button_cancal.setOnClickListener(new OnClickListener() { 345 | @Override 346 | public void onClick(View view) { 347 | builder.cancel();//退出AlertDialo 348 | } 349 | }); 350 | } 351 | }); 352 | //侧滑删除监控 353 | tv_delete.setOnClickListener(new OnClickListener() { 354 | @Override 355 | public void onClick(View view) { 356 | //AlertDialog标题设置 357 | TextView title = new TextView(password.this); 358 | title.setText("提示"); 359 | title.setPadding(10, 10, 10, 10); 360 | title.setGravity(Gravity.CENTER); 361 | // title.setTextColor(getResources().getColor(R.color.greenBG)); 362 | title.setTextSize(23); 363 | sll_main.setStatus(SwipeListView.Status.Close, true); 364 | PwdData str = pwdDatasList.get(arg0); 365 | final PwdData str_in = str; 366 | AlertDialog.Builder builder = new AlertDialog.Builder(password.this); 367 | builder.setCustomTitle(title) 368 | .setMessage("是否删除该密码") 369 | .setPositiveButton("确定", new DialogInterface.OnClickListener() { 370 | @Override 371 | public void onClick(DialogInterface dialogInterface, int i) { 372 | myDao.delete(str_in.getId()); 373 | pwdDatasList.remove(arg0); 374 | notifyDataSetChanged(); 375 | Toast.makeText(password.this, str_in.getName() + "已删除", Toast.LENGTH_LONG).show(); 376 | } 377 | }) 378 | .setNegativeButton("取消", new DialogInterface.OnClickListener() { 379 | @Override 380 | public void onClick(DialogInterface dialogInterface, int i) { 381 | Toast.makeText(password.this, str_in.getName() + "未删除", Toast.LENGTH_LONG).show(); 382 | } 383 | }) 384 | .show(); 385 | } 386 | }); 387 | return view; 388 | } 389 | } 390 | 391 | @Override 392 | public void onBackPressed() { 393 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 394 | if (drawer.isDrawerOpen(GravityCompat.START)) { 395 | drawer.closeDrawer(GravityCompat.START); 396 | } else { 397 | super.onBackPressed(); 398 | } 399 | } 400 | 401 | @Override 402 | public boolean onCreateOptionsMenu(Menu menu) { 403 | // Inflate the menu; this adds items to the action bar if it is present. 404 | getMenuInflater().inflate(R.menu.password, menu); 405 | return true; 406 | } 407 | 408 | @Override 409 | public boolean onOptionsItemSelected(MenuItem item) { 410 | // Handle action bar item clicks here. The action bar will 411 | // automatically handle clicks on the Home/Up button, so long 412 | // as you specify a parent activity in AndroidManifest.xml. 413 | int id = item.getItemId(); 414 | Intent intent = new Intent(); 415 | //noinspection SimplifiableIfStatement 416 | if (id == R.id.action_settings) { 417 | intent.setClass(password.this, settings.class); 418 | startActivity(intent); 419 | return true; 420 | } 421 | 422 | return super.onOptionsItemSelected(item); 423 | } 424 | 425 | @SuppressWarnings("StatementWithEmptyBody") 426 | @Override 427 | public boolean onNavigationItemSelected(MenuItem item) { 428 | // Handle navigation view item clicks here. 429 | int id = item.getItemId(); 430 | Intent intent = new Intent(); 431 | if (id == R.id.qr_code) { 432 | // Handle the camera action 433 | intent.setClass(password.this, MainActivity.class); 434 | startActivity(intent); 435 | } else if (id == R.id.password) { 436 | intent.setClass(password.this, password.class); 437 | startActivity(intent); 438 | } else if (id == R.id.management) { 439 | intent.setClass(password.this, management.class); 440 | startActivity(intent); 441 | } else if (id == R.id.other) { 442 | intent.setClass(password.this, other.class); 443 | startActivity(intent); 444 | } 445 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 446 | drawer.closeDrawer(GravityCompat.START); 447 | return true; 448 | } 449 | } 450 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigerdranch/android/test/setting/CustomLayout.java: -------------------------------------------------------------------------------- 1 | package com.bigerdranch.android.test.setting; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.ViewGroup; 6 | /** 7 | * Created by Administrator on 2017/12/4. 8 | */ 9 | 10 | public class CustomLayout extends ViewGroup { 11 | 12 | public CustomLayout(Context context) { 13 | super(context); 14 | } 15 | 16 | public CustomLayout(Context context, AttributeSet attrs, int defStyle) { 17 | super(context, attrs, defStyle); 18 | } 19 | 20 | public CustomLayout(Context context, AttributeSet attrs) { 21 | super(context, attrs); 22 | } 23 | 24 | @Override 25 | protected void onLayout(boolean changed, int l, int t, int r, int b) { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigerdranch/android/test/setting/RandomPassword.java: -------------------------------------------------------------------------------- 1 | package com.bigerdranch.android.test.setting; 2 | 3 | import java.util.Random; 4 | 5 | /** 6 | * Created by Administrator on 2017/12/2. 7 | */ 8 | 9 | public class RandomPassword { 10 | private String upperCase; 11 | private String lowerCase; 12 | private String digital; 13 | private String specialChar; 14 | 15 | public String makeRandomPassword(int len, String string) { 16 | 17 | // char charr[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%^&*.?".toCharArray(); 18 | //System.out.println("字符数组长度:" + charr.length); //可以看到调用此方法多少次 19 | char charr[] = string.toCharArray(); 20 | StringBuilder sb = new StringBuilder(); 21 | Random r = new Random(); 22 | for (int x = 0; x < len; ++x) { 23 | sb.append(charr[r.nextInt(charr.length)]); 24 | } 25 | return sb.toString(); 26 | } 27 | 28 | public String getUpperCase() { 29 | return upperCase; 30 | } 31 | 32 | public void setUpperCase(String upperCase) { 33 | this.upperCase = upperCase; 34 | } 35 | 36 | public String getLowerCase() { 37 | return lowerCase; 38 | } 39 | 40 | public void setLowerCase(String lowerCase) { 41 | this.lowerCase = lowerCase; 42 | } 43 | 44 | public String getDigital() { 45 | return digital; 46 | } 47 | 48 | public void setDigital(String digital) { 49 | this.digital = digital; 50 | } 51 | 52 | public String getSpecialChar() { 53 | return specialChar; 54 | } 55 | 56 | public void setSpecialChar(String specialChar) { 57 | this.specialChar = specialChar; 58 | } 59 | 60 | public RandomPassword() { 61 | } 62 | 63 | public RandomPassword(String upperCase, String lowerCase, String digital, String specialChar) { 64 | this.upperCase = upperCase; 65 | this.lowerCase = lowerCase; 66 | this.digital = digital; 67 | this.specialChar = specialChar; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigerdranch/android/test/setting/Scan.java: -------------------------------------------------------------------------------- 1 | package com.bigerdranch.android.test.setting; 2 | 3 | import android.content.pm.PackageManager; 4 | import android.os.PersistableBundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.view.KeyEvent; 8 | import android.view.View; 9 | import android.widget.Button; 10 | import android.widget.Toast; 11 | 12 | import com.bigerdranch.android.test.R; 13 | import com.journeyapps.barcodescanner.CaptureManager; 14 | import com.journeyapps.barcodescanner.DecoratedBarcodeView; 15 | 16 | import butterknife.BindView; 17 | import butterknife.ButterKnife; 18 | import butterknife.OnClick; 19 | 20 | public class Scan extends AppCompatActivity implements DecoratedBarcodeView.TorchListener{ 21 | 22 | @BindView(R.id.btn_switch) Button swichLight; 23 | @BindView(R.id.dbv_custom) DecoratedBarcodeView mDBV; 24 | 25 | private CaptureManager captureManager; 26 | private boolean isLightOn = false; 27 | 28 | @Override 29 | protected void onPause() { 30 | super.onPause(); 31 | captureManager.onPause(); 32 | } 33 | 34 | @Override 35 | protected void onResume() { 36 | super.onResume(); 37 | captureManager.onResume(); 38 | } 39 | 40 | @Override 41 | protected void onDestroy() { 42 | super.onDestroy(); 43 | captureManager.onDestroy(); 44 | } 45 | 46 | @Override 47 | public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) { 48 | super.onSaveInstanceState(outState, outPersistentState); 49 | captureManager.onSaveInstanceState(outState); 50 | } 51 | 52 | @Override 53 | public boolean onKeyDown(int keyCode, KeyEvent event) { 54 | return mDBV.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event); 55 | } 56 | 57 | @Override 58 | protected void onCreate(Bundle savedInstanceState) { 59 | super.onCreate(savedInstanceState); 60 | setContentView(R.layout.activity_scan); 61 | ButterKnife.bind(this); 62 | 63 | mDBV.setTorchListener(this); 64 | 65 | // 如果没有闪光灯功能,就去掉相关按钮 66 | if(!hasFlash()) { 67 | swichLight.setVisibility(View.GONE); 68 | } 69 | 70 | //重要代码,初始化捕获 71 | captureManager = new CaptureManager(this,mDBV); 72 | captureManager.initializeFromIntent(getIntent(),savedInstanceState); 73 | captureManager.decode(); 74 | } 75 | 76 | // torch 手电筒 77 | @Override 78 | public void onTorchOn() { 79 | // Toast.makeText(this,"torch on", Toast.LENGTH_LONG).show(); 80 | isLightOn = true; 81 | } 82 | 83 | @Override 84 | public void onTorchOff() { 85 | // Toast.makeText(this,"torch off",Toast.LENGTH_LONG).show(); 86 | isLightOn = false; 87 | } 88 | 89 | // 判断是否有闪光灯功能 90 | private boolean hasFlash() { 91 | return getApplicationContext().getPackageManager() 92 | .hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH); 93 | } 94 | 95 | // 点击切换闪光灯 96 | @OnClick(R.id.btn_switch) 97 | public void swichLight(){ 98 | if(isLightOn){ 99 | mDBV.setTorchOff(); 100 | swichLight.setBackgroundResource(R.mipmap.ic_scan_light_down); 101 | }else{ 102 | mDBV.setTorchOn(); 103 | swichLight.setBackgroundResource(R.mipmap.ic_scan_light_on); 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigerdranch/android/test/setting/SwipeListView.java: -------------------------------------------------------------------------------- 1 | package com.bigerdranch.android.test.setting; 2 | 3 | import android.content.Context; 4 | import android.support.v4.view.ViewCompat; 5 | import android.support.v4.widget.ViewDragHelper; 6 | import android.support.v4.widget.ViewDragHelper.Callback; 7 | import android.util.AttributeSet; 8 | import android.util.Log; 9 | import android.view.MotionEvent; 10 | import android.view.View; 11 | import android.widget.FrameLayout; 12 | 13 | /** 14 | * Created by Administrator on 2017/12/3. 15 | */ 16 | 17 | public class SwipeListView extends FrameLayout { 18 | 19 | private View hiddenView; 20 | private View itemView; 21 | private int hiddenViewWidth; 22 | private ViewDragHelper mDragHelper; 23 | private int hiddenViewHeight; 24 | private int itemWidth; 25 | private int itemHeight; 26 | private OnSwipeStatusListener listener; 27 | private Status status = Status.Close; 28 | private boolean smooth = true; 29 | 30 | public static final String TAG = "SlipListLayout"; 31 | 32 | // 状态 33 | public enum Status { 34 | Open, Close 35 | } 36 | 37 | /** 38 | * 设置侧滑状态 39 | * 40 | * @param status 41 | * 状态 Open or Close 42 | * @param smooth 43 | * 若为true则有过渡动画,否则没有 44 | */ 45 | public void setStatus(Status status, boolean smooth) { 46 | this.status = status; 47 | if (status == Status.Open) { 48 | open(smooth); 49 | } else { 50 | close(smooth); 51 | } 52 | } 53 | 54 | public void setOnSwipeStatusListener(OnSwipeStatusListener listener) { 55 | this.listener = listener; 56 | } 57 | 58 | /** 59 | * 是否设置过渡动画 60 | * 61 | * @param smooth 62 | */ 63 | public void setSmooth(boolean smooth) { 64 | this.smooth = smooth; 65 | } 66 | 67 | public interface OnSwipeStatusListener { 68 | 69 | /** 70 | * 当状态改变时回调 71 | * 72 | * @param status 73 | */ 74 | void onStatusChanged(Status status); 75 | 76 | /** 77 | * 开始执行Open动画 78 | */ 79 | void onStartCloseAnimation(); 80 | 81 | /** 82 | * 开始执行Close动画 83 | */ 84 | void onStartOpenAnimation(); 85 | 86 | } 87 | 88 | public SwipeListView(Context context) { 89 | this(context, null); 90 | } 91 | 92 | public SwipeListView(Context context, AttributeSet attrs) { 93 | super(context, attrs); 94 | mDragHelper = ViewDragHelper.create(this, callback); 95 | } 96 | 97 | // ViewDragHelper的回调 98 | Callback callback = new Callback() { 99 | 100 | @Override 101 | public boolean tryCaptureView(View view, int arg1) { 102 | return view == itemView; 103 | } 104 | 105 | @Override 106 | public int clampViewPositionHorizontal(View child, int left, int dx) { 107 | if (child == itemView) { 108 | if (left > 0) { 109 | return 0; 110 | } else { 111 | left = Math.max(left, -hiddenViewWidth); 112 | return left; 113 | } 114 | } 115 | return 0; 116 | } 117 | 118 | @Override 119 | public int getViewHorizontalDragRange(View child) { 120 | return hiddenViewWidth; 121 | } 122 | 123 | @Override 124 | public void onViewPositionChanged(View changedView, int left, int top, 125 | int dx, int dy) { 126 | if (itemView == changedView) { 127 | hiddenView.offsetLeftAndRight(dx); 128 | } 129 | // 有时候滑动很快的话 会出现隐藏按钮的linearlayout没有绘制的问题 130 | // 为了确保绘制成功 调用 invalidate 131 | invalidate(); 132 | } 133 | 134 | public void onViewReleased(View releasedChild, float xvel, float yvel) { 135 | // 向右滑xvel为正 向左滑xvel为负 136 | if (releasedChild == itemView) { 137 | if (xvel == 0 138 | && Math.abs(itemView.getLeft()) > hiddenViewWidth / 2.0f) { 139 | open(smooth); 140 | } else if (xvel < 0) { 141 | open(smooth); 142 | } else { 143 | close(smooth); 144 | } 145 | } 146 | } 147 | 148 | }; 149 | private Status preStatus = Status.Close; 150 | 151 | /** 152 | * 侧滑关闭 153 | * 154 | * @param smooth 155 | * 为true则有平滑的过渡动画 156 | */ 157 | private void close(boolean smooth) { 158 | preStatus = status; 159 | status = Status.Close; 160 | if (smooth) { 161 | if (mDragHelper.smoothSlideViewTo(itemView, 0, 0)) { 162 | if (listener != null) { 163 | Log.i(TAG, "start close animation"); 164 | listener.onStartCloseAnimation(); 165 | } 166 | ViewCompat.postInvalidateOnAnimation(this); 167 | } 168 | } else { 169 | layout(status); 170 | } 171 | if (listener != null && preStatus == Status.Open) { 172 | Log.i(TAG, "close"); 173 | listener.onStatusChanged(status); 174 | } 175 | } 176 | 177 | /** 178 | * 179 | * @param status 180 | */ 181 | private void layout(Status status) { 182 | if (status == Status.Close) { 183 | hiddenView.layout(itemWidth, 0, itemWidth + hiddenViewWidth, 184 | itemHeight); 185 | itemView.layout(0, 0, itemWidth, itemHeight); 186 | } else { 187 | hiddenView.layout(itemWidth - hiddenViewWidth, 0, itemWidth, 188 | itemHeight); 189 | itemView.layout(-hiddenViewWidth, 0, itemWidth - hiddenViewWidth, 190 | itemHeight); 191 | } 192 | } 193 | 194 | /** 195 | * 侧滑打开 196 | * 197 | * @param smooth 198 | * 为true则有平滑的过渡动画 199 | */ 200 | private void open(boolean smooth) { 201 | preStatus = status; 202 | status = Status.Open; 203 | if (smooth) { 204 | if (mDragHelper.smoothSlideViewTo(itemView, -hiddenViewWidth, 0)) { 205 | if (listener != null) { 206 | Log.i(TAG, "start open animation"); 207 | listener.onStartOpenAnimation(); 208 | } 209 | ViewCompat.postInvalidateOnAnimation(this); 210 | } 211 | } else { 212 | layout(status); 213 | } 214 | if (listener != null && preStatus == Status.Close) { 215 | Log.i(TAG, "open"); 216 | listener.onStatusChanged(status); 217 | } 218 | } 219 | 220 | @Override 221 | public void computeScroll() { 222 | super.computeScroll(); 223 | // 开始执行动画 224 | if (mDragHelper.continueSettling(true)) { 225 | ViewCompat.postInvalidateOnAnimation(this); 226 | } 227 | } 228 | 229 | // 让ViewDragHelper来处理触摸事件 230 | public boolean onInterceptTouchEvent(MotionEvent ev) { 231 | final int action = ev.getAction(); 232 | if (action == MotionEvent.ACTION_CANCEL) { 233 | mDragHelper.cancel(); 234 | return false; 235 | } 236 | return mDragHelper.shouldInterceptTouchEvent(ev); 237 | } 238 | 239 | // 让ViewDragHelper来处理触摸事件 240 | public boolean onTouchEvent(MotionEvent event) { 241 | mDragHelper.processTouchEvent(event); 242 | return true; 243 | }; 244 | 245 | @Override 246 | protected void onFinishInflate() { 247 | super.onFinishInflate(); 248 | hiddenView = getChildAt(0); // 得到隐藏按钮的linearlayout 249 | itemView = getChildAt(1); // 得到最上层的linearlayout 250 | } 251 | 252 | @Override 253 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 254 | super.onSizeChanged(w, h, oldw, oldh); 255 | // 测量子View的长和宽 256 | itemWidth = itemView.getMeasuredWidth(); 257 | itemHeight = itemView.getMeasuredHeight(); 258 | hiddenViewWidth = hiddenView.getMeasuredWidth(); 259 | hiddenViewHeight = hiddenView.getMeasuredHeight(); 260 | } 261 | 262 | @Override 263 | protected void onLayout(boolean changed, int left, int top, int right, 264 | int bottom) { 265 | layout(Status.Close); 266 | } 267 | 268 | } -------------------------------------------------------------------------------- /app/src/main/java/com/bigerdranch/android/test/setting/qrCreat.java: -------------------------------------------------------------------------------- 1 | package com.bigerdranch.android.test.setting; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.Color; 5 | import android.support.annotation.ColorInt; 6 | import android.support.annotation.Nullable; 7 | import android.text.TextUtils; 8 | 9 | import com.google.zxing.BarcodeFormat; 10 | import com.google.zxing.EncodeHintType; 11 | import com.google.zxing.WriterException; 12 | import com.google.zxing.common.BitMatrix; 13 | import com.google.zxing.qrcode.QRCodeWriter; 14 | 15 | import java.util.Hashtable; 16 | 17 | /** 18 | * Created by Administrator on 2017/11/30. 19 | */ 20 | 21 | public class qrCreat { 22 | 23 | 24 | /** 25 | * 创建二维码位图 26 | * 27 | * @param content 字符串内容(支持中文) 28 | * @param width 位图宽度(单位:px) 29 | * @param height 位图高度(单位:px) 30 | * @return 31 | */ 32 | @Nullable 33 | public static Bitmap createQRCodeBitmap(String content, int width, int height) { 34 | return createQRCodeBitmap(content, width, height, "UTF-8", "H", "2", Color.BLACK, Color.WHITE); 35 | } 36 | 37 | /** 38 | * 创建二维码位图 (支持自定义配置和自定义样式) 39 | * 40 | * @param content 字符串内容 41 | * @param width 位图宽度,要求>=0(单位:px) 42 | * @param height 位图高度,要求>=0(单位:px) 43 | * @param character_set 字符集/字符转码格式 (支持格式:{@link CharacterSetECI })。传null时,zxing源码默认使用 "ISO-8859-1" 44 | * @param error_correction 容错级别 (支持级别:{@link ErrorCorrectionLevel })。传null时,zxing源码默认使用 "L" 45 | * @param margin 空白边距 (可修改,要求:整型且>=0), 传null时,zxing源码默认使用"4"。 46 | * @param color_black 黑色色块的自定义颜色值 47 | * @param color_white 白色色块的自定义颜色值 48 | * @return 49 | */ 50 | @Nullable 51 | public static Bitmap createQRCodeBitmap(String content, int width, int height, 52 | @Nullable String character_set, @Nullable String error_correction, @Nullable String margin, 53 | @ColorInt int color_black, @ColorInt int color_white) { 54 | 55 | /** 1.参数合法性判断 */ 56 | if (TextUtils.isEmpty(content)) { // 字符串内容判空 57 | return null; 58 | } 59 | 60 | if (width < 0 || height < 0) { // 宽和高都需要>=0 61 | return null; 62 | } 63 | 64 | try { 65 | /** 2.设置二维码相关配置,生成BitMatrix(位矩阵)对象 */ 66 | Hashtable hints = new Hashtable<>(); 67 | 68 | if (!TextUtils.isEmpty(character_set)) { 69 | hints.put(EncodeHintType.CHARACTER_SET, character_set); // 字符转码格式设置 70 | } 71 | 72 | if (!TextUtils.isEmpty(error_correction)) { 73 | hints.put(EncodeHintType.ERROR_CORRECTION, error_correction); // 容错级别设置 74 | } 75 | 76 | if (!TextUtils.isEmpty(margin)) { 77 | hints.put(EncodeHintType.MARGIN, margin); // 空白边距设置 78 | } 79 | BitMatrix bitMatrix = new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints); 80 | 81 | /** 3.创建像素数组,并根据BitMatrix(位矩阵)对象为数组元素赋颜色值 */ 82 | int[] pixels = new int[width * height]; 83 | for (int y = 0; y < height; y++) { 84 | for (int x = 0; x < width; x++) { 85 | if (bitMatrix.get(x, y)) { 86 | pixels[y * width + x] = color_black; // 黑色色块像素设置 87 | } else { 88 | pixels[y * width + x] = color_white; // 白色色块像素设置 89 | } 90 | } 91 | } 92 | 93 | /** 4.创建Bitmap对象,根据像素数组设置Bitmap每个像素点的颜色值,之后返回Bitmap对象 */ 94 | Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 95 | bitmap.setPixels(pixels, 0, width, 0, 0, width, height); 96 | return bitmap; 97 | } catch (WriterException e) { 98 | e.printStackTrace(); 99 | } 100 | 101 | return null; 102 | } 103 | 104 | 105 | } 106 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigerdranch/android/test/settings.java: -------------------------------------------------------------------------------- 1 | package com.bigerdranch.android.test; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | public class settings extends AppCompatActivity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.activity_settings); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futurepw/Remember/5a22a8eefe188847780c8447e120ce692ba1bc22/app/src/main/res/drawable/button.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_camera.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_gallery.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_manage.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_management.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_other.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_password.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_send.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_share.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_slideshow.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_name.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_password.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_scan_light.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_user.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/side_nav_bar.xml: -------------------------------------------------------------------------------- 1 | 3 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_management.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_other.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_password.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_scan.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 28 | 29 | 30 | 31 |