diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..63cb77a --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +*.iml +.gradle +/local.properties +.idea +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..63cb77a --- /dev/null +++ b/app/.gitignore @@ -0,0 +1,8 @@ +*.iml +.gradle +/local.properties +.idea +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..ef909fe --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,35 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 27 + defaultConfig { + applicationId "ru.nikijava.exercise1" + minSdkVersion 19 + targetSdkVersion 27 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + buildToolsVersion '27.0.3' + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'com.android.support:appcompat-v7:27.1.1' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + implementation 'com.android.support:recyclerview-v7:27.1.1' + implementation 'com.android.support:design:27.1.1' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /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 diff --git a/app/src/androidTest/java/ru/nikijava/exercise1/ExampleInstrumentedTest.java b/app/src/androidTest/java/ru/nikijava/exercise1/ExampleInstrumentedTest.java new file mode 100644 index 0000000..b110918 --- /dev/null +++ b/app/src/androidTest/java/ru/nikijava/exercise1/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package ru.nikijava.exercise1; + +import static org.junit.Assert.assertEquals; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * 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.getTargetContext(); + + assertEquals("ru.nikijava.exercise1", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..41e3f99 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/ru/nikijava/exercise1/MainActivity.java b/app/src/main/java/ru/nikijava/exercise1/MainActivity.java new file mode 100644 index 0000000..af11360 --- /dev/null +++ b/app/src/main/java/ru/nikijava/exercise1/MainActivity.java @@ -0,0 +1,57 @@ +package ru.nikijava.exercise1; + +import android.content.Context; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +public class MainActivity extends AppCompatActivity { + + private EditText etMessage; + private Button btnPreview; + private Button btnClear; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + initView(); + btnPreview.setOnClickListener(this::showPreview); + btnClear.setOnClickListener(v -> etMessage.setText("")); + } + + private void initView() { + etMessage = findViewById(R.id.etMessage); + btnPreview = findViewById(R.id.btnPreview); + btnClear = findViewById(R.id.btnClear); + } + + private String getMessage() { + return etMessage.getText().toString(); + } + + private void showKeyboard() { + etMessage.requestFocus(); + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) imm.showSoftInput(etMessage, InputMethodManager.SHOW_IMPLICIT); + } + + + @Override + protected void onResume() { + super.onResume(); + etMessage.postDelayed(this::showKeyboard, 300); + } + + private void showPreview(View v) { + if (!etMessage.getText().toString().trim().equals("")) { + SendEmailActivity.start(getMessage(), this); + } else { + Toast.makeText(this, R.string.message_empty_enter, Toast.LENGTH_LONG).show(); + } + } +} diff --git a/app/src/main/java/ru/nikijava/exercise1/SendEmailActivity.java b/app/src/main/java/ru/nikijava/exercise1/SendEmailActivity.java new file mode 100644 index 0000000..f5ae18b --- /dev/null +++ b/app/src/main/java/ru/nikijava/exercise1/SendEmailActivity.java @@ -0,0 +1,57 @@ +package ru.nikijava.exercise1; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +public class SendEmailActivity extends AppCompatActivity { + + private static final String KEY_MESSAGE = "key_message"; + private static final String emailTo = "nikrestinpiece@gmail.com"; + + private Button btnEmail; + private TextView tvMessage; + + private String message; + + public static void start(String message, Context context) { + Intent intent = new Intent(context, SendEmailActivity.class); + intent.putExtra(KEY_MESSAGE, message); + context.startActivity(intent); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_send_email); + initView(); + + message = getIntent().getStringExtra(KEY_MESSAGE); + tvMessage.setText(message); + + btnEmail.setOnClickListener(v -> startEmailClient()); + } + + private void initView() { + btnEmail = findViewById(R.id.btnEmail); + tvMessage = findViewById(R.id.tvMessage); + } + + private void startEmailClient() { + Intent intent = new Intent(Intent.ACTION_SENDTO); + intent.setData(Uri.parse("mailto:" + emailTo)); + intent.putExtra(Intent.EXTRA_TEXT, message); + intent.putExtra(Intent.EXTRA_SUBJECT, "Hello, guys!"); + if (intent.resolveActivity(getPackageManager()) != null) { + startActivity(intent); + } else { + Toast.makeText(this, R.string.message_no_email_client, Toast.LENGTH_LONG).show(); + } + } + +} 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..07f9e85 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + 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..5713f34 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,171 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout-land/activity_main.xml b/app/src/main/res/layout-land/activity_main.xml new file mode 100644 index 0000000..9df0890 --- /dev/null +++ b/app/src/main/res/layout-land/activity_main.xml @@ -0,0 +1,59 @@ + + + + + + + + + +