commit c20333e05c7e59b3d2ef7fa21ea02a430e8c91b1 Author: 马菁泽 <1023963162@qq.com> Date: Sat Jun 25 12:19:41 2022 +0800 提交项目 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.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/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..b3405b3 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +My Application \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..b13c090 --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..526b4c2 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..4c8964e --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..815fe8d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/.idea/.gitignore b/app/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/app/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/app/.idea/gradle.xml b/app/.idea/gradle.xml new file mode 100644 index 0000000..630989d --- /dev/null +++ b/app/.idea/gradle.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/app/.idea/misc.xml b/app/.idea/misc.xml new file mode 100644 index 0000000..46fefaa --- /dev/null +++ b/app/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/app/.idea/modules.xml b/app/.idea/modules.xml new file mode 100644 index 0000000..e1f9e1c --- /dev/null +++ b/app/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..60d35b7 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,50 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdkVersion 29 + buildToolsVersion "30.0.3" + + defaultConfig { + applicationId "com.example.myapplication" + minSdkVersion 21 + targetSdkVersion 29 + 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' + implementation 'androidx.navigation:navigation-fragment:2.3.0' + implementation 'androidx.navigation:navigation-ui:2.3.0' + testImplementation 'junit:junit:4.+' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + + implementation 'androidx.recyclerview:recyclerview:1.1.0' + implementation "com.squareup.okhttp3:okhttp:4.9.3" +// implementation 'androidx.recyclerview:recyclerview:1.0.0' +// implementation 'com.android.support:recyclerview-v7:29.0.0' + //Gson + implementation 'com.google.code.gson:gson:2.6.2' + + implementation 'com.android.support.constraint:constraint-layout:1.1.3' +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/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/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.java new file mode 100644 index 0000000..982ba51 --- /dev/null +++ b/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.myapplication; + +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.myapplication", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..5b3ec1d --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/BaseResponse.java b/app/src/main/java/com/example/myapplication/BaseResponse.java new file mode 100644 index 0000000..bc67fd3 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/BaseResponse.java @@ -0,0 +1,29 @@ +package com.example.myapplication; + +public class BaseResponse { + + public static final Integer CODE_200 = 200; + public static final Integer CODE_401 = 401; + public static final Integer CODE_404 = 404; + public static final Integer CODE_500 = 500; + public static final Integer CODE_5217 = 5217; + public static final Integer CODE_5311 = 5311; + public static final Integer CODE_5314 = 5314; + + private Integer code; + private String msg; + + private T data; + + public Integer getCode() { + return code; + } + + public String getMsg() { + return msg; + } + + public T getData() { + return data; + } +} diff --git a/app/src/main/java/com/example/myapplication/Contact.java b/app/src/main/java/com/example/myapplication/Contact.java new file mode 100644 index 0000000..238c945 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/Contact.java @@ -0,0 +1,78 @@ +package com.example.myapplication; +public class Contact { + int _id; + String uri; + byte[] _image; + String mes; + String name; + int account; + + public void setAccount(int account) { + this.account = account; + } + + public int getAccount() { + return account; + } + + public String getMes() { + return mes; + } + + public void setMes(String mes) { + this.mes = mes; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Contact() { + + } + + public Contact(int keyId, String name, byte[] image) { + this._id = keyId; + this.uri = name; + this._image = image; + + } + + public Contact(String name, byte[] image) { + this.uri = name; + this._image = image; + + } + + public Contact(byte[] image) { + this._image = image; + } + + public int getID() { + return this._id; + } + + public void setID(int keyId) { + this._id = keyId; + } + + public String getUri() { + return this.uri; + } + + public void setUri(String name) { + this.uri = name; + } + + public byte[] getImage() { + return this._image; + } + + public void setImage(byte[] image) { + this._image = image; + } +} diff --git a/app/src/main/java/com/example/myapplication/ContantActivity.java b/app/src/main/java/com/example/myapplication/ContantActivity.java new file mode 100644 index 0000000..0f5b7cc --- /dev/null +++ b/app/src/main/java/com/example/myapplication/ContantActivity.java @@ -0,0 +1,282 @@ +package com.example.myapplication; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import androidx.core.content.FileProvider; + +import android.Manifest; +import android.annotation.TargetApi; +import android.content.ContentUris; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.database.Cursor; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Matrix; +import android.icu.text.SelectFormat; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.provider.DocumentsContract; +import android.provider.MediaStore; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +public class ContantActivity extends AppCompatActivity { + + AlertDialog.Builder builder = null; + public static final int TAKE_PHOTO = 1; + public static final int CHOOSE_PHOTO = 0; + private File cameraFile; + private Uri imageUri; + private EditText contant; + private ImageView imageView; + private TextView textView; + private Button button; + private Bitmap bitmapTake; + private Bitmap bitmapAlbum; + private Bitmap bitmap; + private DataBaseHandler db; + private Contact contact = new Contact(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_contant2); + + initView(); + textView.setText(getIntent().getStringExtra("name")); + } + + private void initView() { + db = new DataBaseHandler(this); + contant = findViewById(R.id.et_content); + imageView = findViewById(R.id.iv_photo); + button = findViewById(R.id.bt__share); + textView = findViewById(R.id.tv_nick_name); + imageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showChoosePicDialog(); + } + }); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (bitmapTake == null) { + bitmap = bitmapAlbum; + } else { + bitmap = bitmapTake; + } + Matrix matrix = new Matrix(); + int width = bitmap.getWidth(); + int height = bitmap.getHeight(); + matrix.postScale(0.3f, 0.3f); + Bitmap smallBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + smallBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); + byte[] imageInByte = stream.toByteArray(); + contact.setImage(imageInByte); + contact.setName(textView.getText().toString()); + contact.setMes(contant.getText().toString()); + db.addContact(contact); + bitmap.recycle(); + smallBitmap.recycle(); + Intent intent = new Intent(ContantActivity.this,MainActivity.class); + startActivity(intent); + finish(); + } + }); + } + + private void showChoosePicDialog() { + builder = new androidx.appcompat.app.AlertDialog.Builder(this); + String[] items = {"选择本地照片", "拍照"}; + builder.setItems(items, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (which) { + case CHOOSE_PHOTO: // 选择本地照片 + if (ContextCompat.checkSelfPermission(ContantActivity.this, + Manifest.permission.WRITE_EXTERNAL_STORAGE) != + PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(ContantActivity.this, + new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, CHOOSE_PHOTO); + } else { + openAlbum(); + } + break; + case TAKE_PHOTO: // 拍照 + if (ContextCompat.checkSelfPermission(ContantActivity.this, Manifest.permission.CAMERA) != + PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(ContantActivity.this, + new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}, TAKE_PHOTO); + } else { + takePhoto(); + } + break; + default: + } + } + }); + builder.create().show(); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + super.onActivityResult(requestCode, resultCode, data); + switch (requestCode) { + case TAKE_PHOTO: + if (resultCode == RESULT_OK) { + try { + //将拍摄的照片显示出来 + bitmapTake = BitmapFactory.decodeStream(getContentResolver() + .openInputStream(imageUri)); + imageView.setImageBitmap(bitmapTake); +// contact.setUri(getImagePath(imageUri, null)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + break; + case CHOOSE_PHOTO: + if (resultCode == RESULT_OK) { + //判断手机系统版本号 + if (Build.VERSION.SDK_INT >= 19) { + //4.4及以上系统使用这个方法处理图片 + handleImageOnkita(data); + } else { + //4.4以下系统使用这个方法处理图片 + handleImageBeforeKitKat(data); + } + } + break; + default: + break; + } + } + + private void openAlbum() { + Intent intent = new Intent("android.intent.action.PICK"); + intent.setType("image/*"); + startActivityForResult(intent, CHOOSE_PHOTO);//打开相册 + } + + private void displayImage(String imagePath) { + if (imagePath != null) { + bitmapAlbum = BitmapFactory.decodeFile(imagePath); + imageView.setImageBitmap(bitmapAlbum); +// contact.setUri(imagePath); + } else { + Toast.makeText(this, "没有得到照片", Toast.LENGTH_SHORT).show(); + } + } + + private void takePhoto() { + //创建File对象,用于存储拍照后的图片 + cameraFile = new File(getExternalCacheDir(), "image.jpg"); + if (!cameraFile.exists()) { + try { + cameraFile.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + imageUri = FileProvider.getUriForFile(this, "com.example.project2315.fileprovider", cameraFile); + } else { + imageUri = Uri.fromFile(cameraFile); + } + Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); + intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); + startActivityForResult(intent, TAKE_PHOTO); + } + + private void handleImageBeforeKitKat(Intent data) { + Uri uri = data.getData(); + String imagePath = getImagePath(uri, null); + displayImage(imagePath); + } + + @TargetApi(19) + private void handleImageOnkita(Intent data) { + String imagePath = null; + Uri uri = data.getData(); + if (DocumentsContract.isDocumentUri(this, uri)) { + String docid = DocumentsContract.getDocumentId(uri); + if ("com.android.providers.media.documents".equals(uri.getAuthority())) { + String id = docid.split(":")[1]; + String selection = MediaStore.Images.Media._ID + "=" + id; + imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection); + } else if ("com.android.providers.downloads.document".equals(uri.getAuthority())) { + Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://download/public_downloads"), + Long.valueOf(docid)); + imagePath = getImagePath(contentUri, null); + } + } else if ("content".equalsIgnoreCase(uri.getScheme())) { + imagePath = getImagePath(uri, null); + } else if ("file".equalsIgnoreCase(uri.getScheme())) { + imagePath = uri.getPath(); + } + displayImage(imagePath); + } + + + private String getImagePath(Uri uri, String selection) { + String path = null; + Cursor cursor = getContentResolver().query(uri, null, selection, + null, null); + if (cursor != null) { + if (cursor.moveToFirst()) { + path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA)); + } + cursor.close(); + } + return path; + } + + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + switch (requestCode) { + case 0: + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + openAlbum(); + } else { + showChoosePicDialog(); + Toast.makeText(this, "你拒绝了权限", + Toast.LENGTH_SHORT).show(); + } + break; + case 1: + if (permissions[0].equals(Manifest.permission.CAMERA) && permissions[1].equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + takePhoto(); + } else { + Toast.makeText(this, "你拒绝了权限", + Toast.LENGTH_SHORT).show(); + showChoosePicDialog(); + } + break; + default: + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/DataBaseHandler.java b/app/src/main/java/com/example/myapplication/DataBaseHandler.java new file mode 100644 index 0000000..54875b7 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/DataBaseHandler.java @@ -0,0 +1,104 @@ +package com.example.myapplication; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.util.Log; + +import java.util.ArrayList; +import java.util.List; + +public class DataBaseHandler extends SQLiteOpenHelper { + + private static final int DATABASE_VERSION = 6; + private static final String DATABASE_NAME = "imagedb"; + private static final String TABLE_CONTACTS = "contacts"; + private static final String KEY_ID = "id"; + private static final String KEY_NAME = "name"; + private static final String KEY_IMAGE = "image"; + private static final String PEOPLE = "people"; + private static final String MESSAGE = "message"; + private static final String ACCOUNT = "account"; + + + public DataBaseHandler(Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + } + + @Override + public void onCreate(SQLiteDatabase db) { + String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "(" + + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT," + + KEY_IMAGE + " BLOB," + PEOPLE + " TEXT," + MESSAGE + " TEXT," + ACCOUNT + " INTEGER" + ")"; + db.execSQL(CREATE_CONTACTS_TABLE); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS); + onCreate(db); + } + + + public void addContact(Contact contact) { + SQLiteDatabase db = this.getWritableDatabase(); + + ContentValues values = new ContentValues(); + values.put(KEY_NAME, contact.uri); + values.put(KEY_IMAGE, contact._image); + values.put(PEOPLE, contact.name); + values.put(MESSAGE, contact.mes); + values.put(ACCOUNT, contact.account); + db.insert(TABLE_CONTACTS, null, values); + db.close(); + } + + // 获取所有contact + public List getAllContacts() { + List contactList = new ArrayList(); + String selectQuery = "SELECT * FROM contacts ORDER BY name"; + + SQLiteDatabase db = this.getWritableDatabase(); + Cursor cursor = db.rawQuery(selectQuery, null); + if (cursor.moveToFirst()) { + do { + Contact contact = new Contact(); + contact.setID(Integer.parseInt(cursor.getString(0))); + contact.setUri(cursor.getString(1)); + contact.setImage(cursor.getBlob(2)); + contact.setName(cursor.getString(3)); + contact.setMes(cursor.getString(4)); + contact.setAccount(Integer.parseInt(cursor.getString(5))); + contactList.add(contact); + } while (cursor.moveToNext()); + } + db.close(); + return contactList; + + } + + // Updating single contact + public int updateContact(Contact contact) { + SQLiteDatabase db = this.getWritableDatabase(); + + ContentValues values = new ContentValues(); + values.put(KEY_NAME, contact.uri); + values.put(KEY_IMAGE, contact._image); + values.put(PEOPLE, contact.name); + values.put(MESSAGE, contact.mes); + values.put(ACCOUNT, contact.account); + // updating row + return db.update(TABLE_CONTACTS, values, KEY_ID + " = ?", + new String[]{String.valueOf(contact.getID())}); + + } + + public void deleteContact(Contact contact) { + SQLiteDatabase db = this.getWritableDatabase(); + db.delete(TABLE_CONTACTS, KEY_ID + " = ?", + new String[]{String.valueOf(contact.getID())}); + db.close(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/FriendsActivity.java b/app/src/main/java/com/example/myapplication/FriendsActivity.java new file mode 100644 index 0000000..d917af5 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/FriendsActivity.java @@ -0,0 +1,37 @@ +package com.example.myapplication; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.TextView; + +import java.util.Map; + +public class FriendsActivity extends AppCompatActivity { + + private LinearLayout firstLl; + private LinearLayout secondLl; + private TextView name; + private TextView sex; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_frends); + + name = findViewById(R.id.name); + sex = findViewById(R.id.sex); + firstLl = findViewById(R.id.people_first); + secondLl = findViewById(R.id.people_second); + + int isPerson = getIntent().getIntExtra("isperson", 0); + if (isPerson != 1) { + secondLl.setVisibility(View.GONE); + firstLl.setVisibility(View.VISIBLE); + name.setText(getIntent().getStringExtra("name")); + sex.setText(getIntent().getStringExtra("sex")); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/LoginActivity.java b/app/src/main/java/com/example/myapplication/LoginActivity.java new file mode 100644 index 0000000..f28326e --- /dev/null +++ b/app/src/main/java/com/example/myapplication/LoginActivity.java @@ -0,0 +1,106 @@ +package com.example.myapplication; + +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.EditText; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.AppCompatButton; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; + +import java.io.IOException; +import java.lang.reflect.Modifier; +import java.lang.reflect.Type; + +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.ResponseBody; + +public class LoginActivity extends AppCompatActivity { + + private static final String TAG = LoginActivity.class.getSimpleName(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_login1); + + AppCompatButton btnSignIn = findViewById(R.id.btn_signin); + AppCompatButton btnSignUp = findViewById(R.id.btn_signup); + + + EditText etUserName = findViewById(R.id.et_username); + EditText etPassword = findViewById(R.id.et_password); + + btnSignIn.setOnClickListener(v -> { + + OkHttpClient client = new OkHttpClient().newBuilder() + .build(); + + String userName = etUserName.getText().toString(); + String password = etPassword.getText().toString(); + + Request request = new LoginRequest(userName, password).build(); + + client.newCall(request).enqueue(new Callback() { + @Override public void onFailure(Call call, IOException e) { + e.printStackTrace(); + } + + @Override public void onResponse(Call call, Response response) throws IOException { + try { + ResponseBody responseBody = response.body(); + String body = responseBody.string(); + + Log.d(TAG, body); + + if (!response.isSuccessful()) { + throw new IOException("Unexpected code " + response); + } else { + Gson gson = new GsonBuilder().excludeFieldsWithModifiers(Modifier.STATIC).create(); + + Type baseResponseType = new TypeToken>() {}.getType(); + + BaseResponse baseResponse = gson.fromJson(body, baseResponseType); + + if (baseResponse.getCode().equals(BaseResponse.CODE_200)) { + LoginResponse loginResponse = baseResponse.getData(); + String loginResponseString = gson.toJson(loginResponse); + Log.d(TAG, "login response: " + loginResponseString); + + ToastInstance.getInstance().show(LoginActivity.this, "Welcome back, " + loginResponse.getUserName(), Toast.LENGTH_LONG); + + Intent intent = new Intent(LoginActivity.this, MainActivity.class); + startActivity(intent); + + } else if (baseResponse.getCode().equals(BaseResponse.CODE_500)) { + ToastInstance.getInstance().show(LoginActivity.this, "username or password incorrect!", Toast.LENGTH_LONG); + } + + } + } catch (IOException exception) { + exception.printStackTrace(); + } + } + }); + }); + + btnSignUp.setOnClickListener(new View.OnClickListener(){ + + @Override + public void onClick(View view) { + Intent intent = new Intent(LoginActivity.this, RegisterActivity.class); + startActivity(intent); + } + } ); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/LoginRequest.java b/app/src/main/java/com/example/myapplication/LoginRequest.java new file mode 100644 index 0000000..b6b184b --- /dev/null +++ b/app/src/main/java/com/example/myapplication/LoginRequest.java @@ -0,0 +1,43 @@ +package com.example.myapplication; + +import okhttp3.Headers; +import okhttp3.MediaType; +import okhttp3.Request; +import okhttp3.RequestBody; + +public class LoginRequest { + + private Request request; + + private String userName; + private String password; + private Headers headers; + + private String userNameKey = "username"; + private String passwordKey = "password"; + + private String params; + + public LoginRequest(String userName, String password) { + this.userName = userName; + this.password = password; + this.params = "?" + userNameKey + "=" + userName + + "&" + passwordKey + "=" + password; + } + + public Request build() { + + MediaType mediaType = MediaType.parse("application/json"); + RequestBody body = RequestBody.create("", mediaType); + + request = new Request.Builder() + .url(UrlConstant.getLoginUrl() + params) + .method("POST", body) + .addHeader("Content-Type", "application/json") + .addHeader(UrlConstant.AppIdKey, UrlConstant.AppId) + .addHeader(UrlConstant.AppSecretKey, UrlConstant.AppSecret) + .build(); + + return request; + } +} diff --git a/app/src/main/java/com/example/myapplication/LoginResponse.java b/app/src/main/java/com/example/myapplication/LoginResponse.java new file mode 100644 index 0000000..8b586f0 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/LoginResponse.java @@ -0,0 +1,35 @@ +package com.example.myapplication; + +import com.google.gson.annotations.SerializedName; + +import java.math.BigInteger; + +public class LoginResponse { + private String appKey; + + private BigInteger id; + + @SerializedName("username") + private String userName; + + private String password; + + @SerializedName("sex") + private Integer sexCode; + + private String avatar; + @SerializedName("introduce") + private String introduction; + + private BigInteger createTime; + private BigInteger lastUpdateTime; + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + +} diff --git a/app/src/main/java/com/example/myapplication/LoginResponseB.java b/app/src/main/java/com/example/myapplication/LoginResponseB.java new file mode 100644 index 0000000..5e29546 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/LoginResponseB.java @@ -0,0 +1,60 @@ +package com.example.myapplication; + +import com.google.gson.annotations.SerializedName; + +import java.math.BigInteger; + +public class LoginResponseB { + /* + { + "code": 200, + "msg": "登录成功", + "data": { + "id": "1534026874529910784", + "appKey": "7e7ef16381b147e6b211665b557259a7", + "username": "balabala", + "password": null, + "sex": null, + "introduce": null, + "avatar": null, + "createTime": "1654575482386", + "lastUpdateTime": "1654575482386" + } + } + */ + + String msg; + int code; + + LoginResponseInner data; + + public class LoginResponseInner { + private String appKey; + + private BigInteger id; + + @SerializedName("username") + private String userName; + + private String password; + + @SerializedName("sex") + private Integer sexCode; + + private String avatar; + @SerializedName("introduce") + private String introduction; + + private BigInteger createTime; + private BigInteger lastUpdateTime; + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + } +} diff --git a/app/src/main/java/com/example/myapplication/MainActivity.java b/app/src/main/java/com/example/myapplication/MainActivity.java new file mode 100644 index 0000000..07e9af5 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/MainActivity.java @@ -0,0 +1,283 @@ +package com.example.myapplication; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import androidx.core.content.FileProvider; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import android.Manifest; +import android.annotation.TargetApi; +import android.content.ContentResolver; +import android.content.ContentUris; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.pm.PackageManager; +import android.database.Cursor; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Matrix; +import android.media.ExifInterface; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.os.Environment; +import android.provider.DocumentsContract; +import android.provider.MediaStore; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.Toast; + +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.tabs.TabLayout; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class MainActivity extends AppCompatActivity { + + public static final int TAKE_PHOTO = 1; + public static final int CHOOSE_PHOTO = 0; + AlertDialog.Builder builder = null; + private File cameraFile; + private FrameLayout frameLayout; + private RecyclerView recyclerView; + private RecycleAdapter adapter; + private FloatingActionButton button; + private Button delete; + private Button person; + private Button friends; + private Uri imageUri; + private ArrayList imageArry = new ArrayList(); + private DataBaseHandler db; + private static File mPhotoFile = null; + private Map map; + private boolean isLove = false; + private int isPerson; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + map = new HashMap<>(); + SharedPreferences data = getSharedPreferences("data", Context.MODE_PRIVATE); + isPerson = data.getInt("isperson",1); + if (isPerson == 1) { + SharedPreferences sh = getSharedPreferences("mes", Context.MODE_PRIVATE); + map.put("name", sh.getString("name", "")); + map.put("sex", sh.getString("sex", "")); + map.put("city", sh.getString("city", "")); + } else { + map.put("name", "马菁泽"); + map.put("sex", "男"); + map.put("city", "广西桂林"); + } + initView(); + updateFromDb(); + if (isEmpty(imageArry)) { + frameLayout.setVisibility(View.VISIBLE); + recyclerView.setVisibility(View.GONE); + } + } + + + private void updateFromDb() { + List contacts = db.getAllContacts(); + for (Contact cn : contacts) { + imageArry.add(cn); + } + adapter.notifyDataSetChanged(); + } + + private void initView() { + + + //frameLayout = findViewById(R.id.no_image); + db = new DataBaseHandler(this); + recyclerView = findViewById(R.id.recycle_view); + button = findViewById(R.id.bt_photo); + //delete = findViewById(R.id.bt__delete); + //person = findViewById(R.id.person_message); + //friends = findViewById(R.id.friends); + adapter = new RecycleAdapter(imageArry); + recyclerView.setAdapter(adapter); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + +// person.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// map.put("key", "1"); +// Intent intent = new Intent(MainActivity.this, PersonActivity.class); +// intent.putExtra("mes", (Serializable) map); +// startActivity(intent); +// } +// }); + +// friends.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// SharedPreferences sh = getSharedPreferences("mes", Context.MODE_PRIVATE); +// Intent intent = new Intent(MainActivity.this, FriendsActivity.class); +// intent.putExtra("isperson",isPerson); +// intent.putExtra("name",sh.getString("name","")); +// intent.putExtra("sex",sh.getString("sex","")); +// startActivity(intent); +// } +// }); +// +// delete.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// List contacts = db.getAllContacts(); +// for (Contact cn : contacts) { +// db.deleteContact(cn); +// } +// upDateList(); +// Toast.makeText(MainActivity.this, "清空数据库成功!", Toast.LENGTH_SHORT).show(); +// startActivity(new Intent(MainActivity.this, MainActivity.class)); +// finish(); +// } +// }); + + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(MainActivity.this, ContantActivity.class); + intent.putExtra("name", (String) map.get("name")); + Log.w("ssssssssssssssssssssss", "button: "+map); + startActivity(intent); + } + }); + + adapter.setOnLoveClickListener(new RecycleAdapter.OnLoveClickListener() { + @Override + public void onClick(int position, ImageView imageLove) { + if (!isLove) { + imageLove.setImageResource(R.mipmap.ic_love_have); + Contact contact = new Contact(); + contact = imageArry.get(position); + contact.setAccount((contact.getAccount()) + 1); + db.updateContact(contact); + imageLove.setEnabled(false); + adapter.notifyDataSetChanged(); + } + } + }); + + adapter.setOnItemLongClickListener(new RecycleAdapter.OnItemLongClickListener() { + @Override + public void onClick(int position) { + Bitmap bitmap = BitmapFactory.decodeByteArray(imageArry.get(position)._image, 0, imageArry.get(position)._image.length); + saveBitmap(getApplicationContext(), bitmap, "aa"); + } + }); + TabLayout tabLayout = findViewById(R.id.tabLayout); + tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { + @Override + public void onTabSelected(TabLayout.Tab tab) { + int position = tab.getPosition(); + LinearLayout layout = findViewById(R.id.personLayout); + switch (position) + { + case 0: + recyclerView.setVisibility(View.VISIBLE); + layout.setVisibility(View.INVISIBLE); + break; + case 1 : + recyclerView.setVisibility(View.INVISIBLE); + layout.setVisibility(View.VISIBLE); + break; + } + } + + @Override + public void onTabUnselected(TabLayout.Tab tab) { + + } + + @Override + public void onTabReselected(TabLayout.Tab tab) { + + } + }); + } + + private void saveBitmap(Context context, Bitmap bm, String picName) { + try { + String dir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/renji/" + picName + ".jpg"; + File f = new File(dir); + if (!f.exists()) { + f.getParentFile().mkdirs(); + f.createNewFile(); + } + FileOutputStream out = new FileOutputStream(f); + bm.compress(Bitmap.CompressFormat.PNG, 90, out); + out.flush(); + out.close(); + Uri uri = Uri.fromFile(f); + Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); + intent.setData(uri); + context.sendBroadcast(intent); + Toast.makeText(context, "图片保存成功!", Toast.LENGTH_SHORT).show(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + Toast.makeText(context, "图片保存失败!", Toast.LENGTH_SHORT).show(); + } + } + + /*private void upDateList() { + if (isEmpty(imageArry)) { + frameLayout.setVisibility(View.VISIBLE); + recyclerView.setVisibility(View.GONE); + } else { + frameLayout.setVisibility(View.GONE); + recyclerView.setVisibility(View.VISIBLE); + adapter.notifyDataSetChanged(); + } + }*/ + + private Boolean isEmpty(List images) { + if (images.size() == 0) { + return true; + } else { + return false; + } + } + + /*@Override + protected void onResume() { + super.onResume(); + if (!isEmpty(imageArry)) { + } + upDateList(); + }*/ + + @Override + protected void onDestroy() { + super.onDestroy(); + } + + + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/PersonActivity.java b/app/src/main/java/com/example/myapplication/PersonActivity.java new file mode 100644 index 0000000..6790226 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/PersonActivity.java @@ -0,0 +1,66 @@ +package com.example.myapplication; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +public class PersonActivity extends AppCompatActivity { + + private EditText nameEt; + private EditText sexEt; + private EditText cityEt; + private Button button; + private SharedPreferences.Editor editor; + private SharedPreferences sharedPreferences; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_person); + + initView(); + sharedPreferences = getSharedPreferences("mes", MODE_PRIVATE); + editor = sharedPreferences.edit(); + Map map = (Map) getIntent().getSerializableExtra("mes"); + if (map != null) { + if ("1".equals(map.get("key"))) { + button.setVisibility(View.GONE); + button.setEnabled(false); + nameEt.setEnabled(false); + sexEt.setEnabled(false); + cityEt.setEnabled(false); + nameEt.setText(String.valueOf(map.get("name"))); + sexEt.setText(String.valueOf(map.get("sex"))); + cityEt.setText(String.valueOf(map.get("city"))); + } + } + } + + private void initView() { + nameEt = findViewById(R.id.tv_modify_name); + sexEt = findViewById(R.id.tv_modify_sex); + cityEt = findViewById(R.id.tv_city); + button = findViewById(R.id.bt_save); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + editor.putString("name", nameEt.getText().toString()); + editor.putString("sex", sexEt.getText().toString()); + editor.putString("city", cityEt.getText().toString()); + editor.apply(); + Intent intent = new Intent(PersonActivity.this, MainActivity.class); + startActivity(intent); + finish(); + } + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/RecycleAdapter.java b/app/src/main/java/com/example/myapplication/RecycleAdapter.java new file mode 100644 index 0000000..ae12a85 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/RecycleAdapter.java @@ -0,0 +1,111 @@ +package com.example.myapplication; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.text.Layout; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.recyclerview.widget.RecyclerView; + +import java.io.ByteArrayInputStream; +import java.util.ArrayList; +import java.util.List; + +public class RecycleAdapter extends RecyclerView.Adapter { + + private ArrayList imageArry; + private OnItemLongClickListener longClickListener; + private OnLoveClickListener loveClickListener; + + + public interface OnItemLongClickListener { + void onClick(int position); + } + + public interface OnLoveClickListener { + void onClick(int position, ImageView imageLove); + } + + + public void setOnLoveClickListener(OnLoveClickListener listener) { + loveClickListener = listener; + } + + + public void setOnItemLongClickListener(OnItemLongClickListener longClickListener) { + this.longClickListener = longClickListener; + } + + public RecycleAdapter(ArrayList imageArry) { + this.imageArry = imageArry; + } + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false); + ViewHolder holder = new ViewHolder(view); + return holder; + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder holder, int position) { + Contact picture = imageArry.get(position); + byte[] outImage = picture._image; + ByteArrayInputStream imageStream = new ByteArrayInputStream(outImage); + Bitmap theImage = BitmapFactory.decodeStream(imageStream); + holder.imageView.setImageBitmap(theImage); + holder.nameTv.setText(picture.getName()); + holder.content.setText(picture.getMes()); + holder.accountTv.setText(String.valueOf(picture.account)); + holder.imageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (longClickListener != null) { + longClickListener.onClick(position); + } + } + }); + holder.imageLove.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (loveClickListener != null) { + loveClickListener.onClick(position, holder.imageLove); + } + } + }); + } + + @Override + public int getItemCount() { + return imageArry.size(); + } + + class ViewHolder extends RecyclerView.ViewHolder { + + private ImageView imageView; + private ImageView imageLove; + private TextView nameTv; + private TextView accountTv; + private TextView content; + private View view; + + public ViewHolder(@NonNull View itemView) { + super(itemView); + view = itemView; + imageView = view.findViewById(R.id.image); + content = view.findViewById(R.id.tv_content); + imageLove = view.findViewById(R.id.iv_love); + accountTv = view.findViewById(R.id.love_account); + nameTv = view.findViewById(R.id.message_name); + } + + } +} diff --git a/app/src/main/java/com/example/myapplication/RegisterActivity.java b/app/src/main/java/com/example/myapplication/RegisterActivity.java new file mode 100644 index 0000000..fa49bca --- /dev/null +++ b/app/src/main/java/com/example/myapplication/RegisterActivity.java @@ -0,0 +1,111 @@ +package com.example.myapplication; + +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.EditText; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.AppCompatButton; +import androidx.appcompat.widget.AppCompatTextView; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; + +import java.io.IOException; +import java.lang.reflect.Modifier; +import java.lang.reflect.Type; + +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.ResponseBody; + +public class RegisterActivity extends AppCompatActivity { + + private static final String TAG = RegisterActivity.class.getSimpleName(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_register); + + AppCompatButton btnSignUp = findViewById(R.id.btn_signup2); + + EditText etUserName = findViewById(R.id.et_username); + EditText etPassword = findViewById(R.id.et_password); + EditText etConfirmPassword = findViewById(R.id.et_confirm_password); + + AppCompatTextView tvBackToSignIn = findViewById(R.id.tv_backto_signin); + + btnSignUp.setOnClickListener(v -> { + + + String userName = etUserName.getText().toString(); + String password = etPassword.getText().toString(); + String confirmPassword = etConfirmPassword.getText().toString(); + + if (!password.equals(confirmPassword)) { + ToastInstance.getInstance() + .show(RegisterActivity.this, "password unmatched!", Toast.LENGTH_LONG); + + return; + } + + OkHttpClient client = new OkHttpClient().newBuilder() + .build(); + + Request request = new RegisterRequest(userName, password).build(); + + client.newCall(request).enqueue(new Callback() { + @Override public void onFailure(Call call, IOException e) { + e.printStackTrace(); + } + + @Override public void onResponse(Call call, Response response) throws IOException { + try { + ResponseBody responseBody = response.body(); + String body = responseBody.string(); + + Log.d(TAG, body); + + if (!response.isSuccessful()) { + throw new IOException("Unexpected code " + response); + } else { + Gson gson = new GsonBuilder().excludeFieldsWithModifiers(Modifier.STATIC).create(); + + Type baseResponseType = new TypeToken>() {}.getType(); + + BaseResponse baseResponse = gson.fromJson(body, baseResponseType); + + if (baseResponse.getCode().equals(BaseResponse.CODE_200)) { + String loginResponse = baseResponse.getData(); + + ToastInstance.getInstance().show(RegisterActivity.this, "Welcome, " + userName, Toast.LENGTH_LONG); + + finish(); + + } else if (baseResponse.getCode().equals(BaseResponse.CODE_500)) { + ToastInstance.getInstance().show(RegisterActivity.this, "username or password incorrect!", Toast.LENGTH_LONG); + } + + } + } catch (IOException exception) { + exception.printStackTrace(); + } + } + }); + }); + + tvBackToSignIn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + finish(); + } + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/RegisterRequest.java b/app/src/main/java/com/example/myapplication/RegisterRequest.java new file mode 100644 index 0000000..9d31be6 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/RegisterRequest.java @@ -0,0 +1,43 @@ +package com.example.myapplication; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.annotations.SerializedName; + +import java.lang.reflect.Modifier; + +import okhttp3.MediaType; +import okhttp3.Request; +import okhttp3.RequestBody; + +public class RegisterRequest { + + private Request request; + + @SerializedName("username") + private String userName; + private String password; + + public RegisterRequest(String userName, String password) { + this.userName = userName; + this.password = password; + } + + public Request build() { + MediaType mediaType = MediaType.parse("application/json"); + Gson gson = new GsonBuilder().excludeFieldsWithModifiers(Modifier.STATIC).create(); + + String requestBody = gson.toJson(this); + RequestBody body = RequestBody.create(requestBody, mediaType); + + request = new Request.Builder() + .url(UrlConstant.getRegisterUrl()) + .method("POST", body) + .addHeader("Content-Type", "application/json") + .addHeader(UrlConstant.AppIdKey, UrlConstant.AppId) + .addHeader(UrlConstant.AppSecretKey, UrlConstant.AppSecret) + .build(); + + return request; + } +} diff --git a/app/src/main/java/com/example/myapplication/RegisterResponse.java b/app/src/main/java/com/example/myapplication/RegisterResponse.java new file mode 100644 index 0000000..885fbd8 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/RegisterResponse.java @@ -0,0 +1,5 @@ +package com.example.myapplication; + +public class RegisterResponse { + +} diff --git a/app/src/main/java/com/example/myapplication/ToastInstance.java b/app/src/main/java/com/example/myapplication/ToastInstance.java new file mode 100644 index 0000000..629fe3e --- /dev/null +++ b/app/src/main/java/com/example/myapplication/ToastInstance.java @@ -0,0 +1,29 @@ +package com.example.myapplication; + +import android.app.Activity; +import android.widget.Toast; + +public class ToastInstance { + private static ToastInstance instance = new ToastInstance(); + + public static ToastInstance getInstance() { + if (instance == null) { + instance = new ToastInstance(); + } + return instance; + } + + private ToastInstance() { + } + + public void show(Activity activity, String text, int duration) { + if (activity != null) { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + Toast.makeText(activity, text, duration).show(); + } + }); + } + } +} diff --git a/app/src/main/java/com/example/myapplication/UrlConstant.java b/app/src/main/java/com/example/myapplication/UrlConstant.java new file mode 100644 index 0000000..46ea3a8 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/UrlConstant.java @@ -0,0 +1,49 @@ +package com.example.myapplication; + +import okhttp3.Headers; + +public final class UrlConstant { + public static final String BaseURL = "http://47.107.52.7:88"; + public static final String LoginPath = "/member/photo/user/login"; + public static final String RegisterPath = "/member/photo/user/register"; + public static final String UploadPhotosPath = "/member/photo/image/upload"; + public static final String PublishPhotosPath = "/member/photo/share/add"; + public static final String PhotosPath = "/member/photo/share"; + + public static final String AppId = "0b8b6fd7bb8e485da72c9186652c9b85"; + public static final String AppSecret = "6733365198f66a27f4f5eb2707ebc55247a8c"; + + public static final String AppIdKey = "appId"; + public static final String AppSecretKey = "appSecret"; + + + public Headers headers = new Headers.Builder() + .add(AppIdKey, AppId) + .add(AppSecretKey, AppSecret) + .add("Content-Type", "application/json") + .build(); + + public static String getLoginUrl() { + return BaseURL + LoginPath; + } + + public static String getUploadPhotosUrl() { + return BaseURL + UploadPhotosPath; + } + + public static String getPublishPhotosUrl() { + return BaseURL + PublishPhotosPath; + } + + public static String getPhotosUrl() { + return BaseURL + PhotosPath; + } + + public static String getRegisterUrl() { + return BaseURL + RegisterPath; + } + + public Headers getHeaders() { + return headers; + } +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_login_btn.xml b/app/src/main/res/drawable/bg_login_btn.xml new file mode 100644 index 0000000..39c74f3 --- /dev/null +++ b/app/src/main/res/drawable/bg_login_btn.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_login_btn_disable.xml b/app/src/main/res/drawable/bg_login_btn_disable.xml new file mode 100644 index 0000000..4f519e2 --- /dev/null +++ b/app/src/main/res/drawable/bg_login_btn_disable.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_login_edit.xml b/app/src/main/res/drawable/bg_login_edit.xml new file mode 100644 index 0000000..e18f117 --- /dev/null +++ b/app/src/main/res/drawable/bg_login_edit.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/btn_round_corner.xml b/app/src/main/res/drawable/btn_round_corner.xml new file mode 100644 index 0000000..8094d19 --- /dev/null +++ b/app/src/main/res/drawable/btn_round_corner.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/btn_round_primary.xml b/app/src/main/res/drawable/btn_round_primary.xml new file mode 100644 index 0000000..4ad3277 --- /dev/null +++ b/app/src/main/res/drawable/btn_round_primary.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/btn_round_stroke.xml b/app/src/main/res/drawable/btn_round_stroke.xml new file mode 100644 index 0000000..56e8b24 --- /dev/null +++ b/app/src/main/res/drawable/btn_round_stroke.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_baseline_photo_size_select_actual_24.xml b/app/src/main/res/drawable/ic_baseline_photo_size_select_actual_24.xml new file mode 100644 index 0000000..81fbb41 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_photo_size_select_actual_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_bus_time1.png b/app/src/main/res/drawable/ic_bus_time1.png new file mode 100644 index 0000000..b950ce8 Binary files /dev/null and b/app/src/main/res/drawable/ic_bus_time1.png differ diff --git a/app/src/main/res/drawable/ic_enter_icon_petname.png b/app/src/main/res/drawable/ic_enter_icon_petname.png new file mode 100644 index 0000000..ec13127 Binary files /dev/null and b/app/src/main/res/drawable/ic_enter_icon_petname.png differ diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/icon_praising.png b/app/src/main/res/drawable/icon_praising.png new file mode 100644 index 0000000..de7114c Binary files /dev/null and b/app/src/main/res/drawable/icon_praising.png differ diff --git a/app/src/main/res/layout/activity_contant.xml b/app/src/main/res/layout/activity_contant.xml new file mode 100644 index 0000000..b76274e --- /dev/null +++ b/app/src/main/res/layout/activity_contant.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_contant2.xml b/app/src/main/res/layout/activity_contant2.xml new file mode 100644 index 0000000..1dd2033 --- /dev/null +++ b/app/src/main/res/layout/activity_contant2.xml @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +