Skip to content

Commit

Permalink
refacttoring, add HelpActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan on t530 committed Feb 20, 2017
1 parent 4a61847 commit 75e7321
Show file tree
Hide file tree
Showing 23 changed files with 264 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Expand Up @@ -62,6 +62,6 @@ dependencies {
compile project(':libspectrafiles')
compile project(':core')
compile project(':libprefs')
compile project(':libmail')
compile project(':libcomm')
}

Expand Up @@ -25,7 +25,8 @@

public class BaseActivity extends AppCompatActivity //ActionBarActivity
{
protected View mainContent;
protected View topView;

// protected static final int ACT_ITEM_LIVE_VIEW = 0;
// protected static final int ACT_ITEM_VIEW_CONFIG = 1;
// protected static final int ACT_ITEM_VIEW_PLOT = 2;
Expand Down Expand Up @@ -165,14 +166,15 @@ public void getScreenOrientation() {
mViewSettings.setDeviceOrientation(mDeviceOrientation);
}
protected void sendFeedback() {
topView = getWindow().getDecorView().getRootView();
boolean success = EmailIntentBuilder.from(this)
.to("jan.debiec@ue-mail.de")
.subject(getString(R.string.feedback_subject))
.body(getString(R.string.feedback_body))
.start();

if (!success) {
Snackbar.make(mainContent, R.string.error_no_email_app, Snackbar.LENGTH_LONG).show();
Snackbar.make(topView, R.string.error_no_email_app, Snackbar.LENGTH_LONG).show();
}
}

Expand All @@ -181,9 +183,14 @@ protected void showVersion(){
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
String version = pInfo.versionName;
int verCode = pInfo.versionCode;
topView = getWindow().getDecorView().getRootView();
String stringToDisplay = getString(R.string.content_version) + version;
Toast.makeText(this, stringToDisplay, Toast.LENGTH_LONG)
.show();

// this snackbar overlaps the action bar in portrait mode
Snackbar.make(topView, stringToDisplay, Snackbar.LENGTH_LONG).show();

// Toast.makeText(this, stringToDisplay, Toast.LENGTH_LONG)
// .show();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,26 @@
package de.jandrotek.android.aspectra.libcomm;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("de.jandrotek.android.aspectra.libmail.test", appContext.getPackageName());
}
}
16 changes: 16 additions & 0 deletions libcomm/src/main/AndroidManifest.xml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.jandrotek.android.aspectra.libcomm">

<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">
<activity android:name="de.jandrotek.android.aspectra.libcomm.MailActivity" />
<activity
android:name="de.jandrotek.android.aspectra.libcomm.HelpActivity"
android:label="@string/title_activity_help"
android:theme="@style/AppTheme.NoActionBar"></activity>
</application>

</manifest>
@@ -0,0 +1,29 @@
package de.jandrotek.android.aspectra.libcomm;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

public class HelpActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}

}
@@ -0,0 +1,84 @@
package de.jandrotek.android.aspectra.libcomm;

import android.support.design.widget.Snackbar;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import de.cketti.mailto.EmailIntentBuilder;

public class MailActivity extends AppCompatActivity {

View mainContent;

EditText emailTo;

EditText emailCc;

EditText emailBcc;

EditText emailSubject;

EditText emailBody;

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

emailTo.setText(R.string.content_to);
emailSubject.setText(R.string.content_subject);
}

private void sendFeedback() {
boolean success = EmailIntentBuilder.from(this)
.to("cketti@gmail.com")
.subject(getString(R.string.feedback_subject))
.body(getString(R.string.feedback_body))
.start();

if (!success) {
Snackbar.make(mainContent, R.string.error_no_email_app, Snackbar.LENGTH_LONG).show();
}
}


private void sendEmail() {
String to = emailTo.getText().toString();
String cc = emailCc.getText().toString();
String bcc = emailBcc.getText().toString();
String subject = emailSubject.getText().toString();
String body = emailBody.getText().toString();

EmailIntentBuilder builder = EmailIntentBuilder.from(this);

try {
if (!TextUtils.isEmpty(to)) {
builder.to(to);
}
if (!TextUtils.isEmpty(cc)) {
builder.cc(cc);
}
if (!TextUtils.isEmpty(bcc)) {
builder.bcc(bcc);
}
if (!TextUtils.isEmpty(subject)) {
builder.subject(subject);
}
if (!TextUtils.isEmpty(body)) {
builder.body(body);
}

boolean success = builder.start();
if (!success) {
Snackbar.make(mainContent, R.string.error_no_email_app, Snackbar.LENGTH_LONG).show();
}
} catch (IllegalArgumentException e) {
String errorMessage = getString(R.string.argument_error, e.getMessage());
Snackbar.make(mainContent, errorMessage, Snackbar.LENGTH_LONG).show();
}
}
}
34 changes: 34 additions & 0 deletions libcomm/src/main/res/layout/activity_help.xml
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="de.jandrotek.android.aspectra.libcomm.HelpActivity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_help" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>
16 changes: 16 additions & 0 deletions libcomm/src/main/res/layout/content_help.xml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_help"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="de.jandrotek.android.aspectra.libcomm.HelpActivity"
tools:showIn="@layout/activity_help">

</RelativeLayout>
9 changes: 9 additions & 0 deletions libcomm/src/main/res/values-v21/styles.xml
@@ -0,0 +1,9 @@
<resources>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>
Expand Up @@ -2,4 +2,5 @@
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
</resources>
Expand Up @@ -14,4 +14,5 @@
<string name="error_no_email_app">No email app found</string>
<string name="feedback_body">[Your feedback here]</string>
<string name="argument_error">Error: %s</string>
<string name="title_activity_help">HelpActivity</string>
</resources>
17 changes: 17 additions & 0 deletions libcomm/src/main/res/values/styles.xml
@@ -0,0 +1,17 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>
@@ -0,0 +1,17 @@
package de.jandrotek.android.aspectra.libcomm;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
12 changes: 0 additions & 12 deletions libmail/src/main/AndroidManifest.xml

This file was deleted.

8 changes: 0 additions & 8 deletions libmail/src/main/res/values/styles.xml

This file was deleted.

2 changes: 1 addition & 1 deletion mailtest/build.gradle
Expand Up @@ -30,5 +30,5 @@ dependencies {
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
testCompile 'junit:junit:4.12'
compile project(':libmail')
compile project(':libcomm')
}
2 changes: 1 addition & 1 deletion settings.gradle
@@ -1 +1 @@
include ':app', ':core', ':touchtest', ':fileviewer', ':libtouch', ':libprefs', ':libspectrafiles', ':libplotspectrav3', ':analyze', ':plottest', ':espressofirsttest', ':mailtest', ':libmail'
include ':app', ':core', ':touchtest', ':fileviewer', ':libtouch', ':libprefs', ':libspectrafiles', ':libplotspectrav3', ':analyze', ':plottest', ':espressofirsttest', ':mailtest', ':libcomm'

0 comments on commit 75e7321

Please sign in to comment.