From 65bd9e3530af538e63ef2fd54ea5837fa47fc8f8 Mon Sep 17 00:00:00 2001 From: stefan-niedermann Date: Sat, 25 Jan 2020 09:29:44 +0100 Subject: [PATCH] #466 Header title not aligned Move to toolbars --- app/src/main/AndroidManifest.xml | 6 +-- .../notes/android/activity/AboutActivity.java | 4 ++ .../android/activity/EditNoteActivity.java | 30 +++++++++------ .../android/activity/ExceptionActivity.java | 4 ++ .../res/drawable/ic_arrow_back_white_24dp.xml | 5 +++ app/src/main/res/drawable/splashscreen.xml | 2 +- app/src/main/res/layout/activity_about.xml | 14 +++++++ app/src/main/res/layout/activity_edit.xml | 26 +++++++++++++ .../main/res/layout/activity_exception.xml | 38 +++++++++++-------- .../res/layout/activity_notes_list_view.xml | 3 ++ app/src/main/res/values/styles.xml | 5 +-- 11 files changed, 102 insertions(+), 35 deletions(-) create mode 100644 app/src/main/res/drawable/ic_arrow_back_white_24dp.xml create mode 100644 app/src/main/res/layout/activity_edit.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1ae7ba0a..d8f1c2e4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -30,8 +30,7 @@ + android:label="@string/app_name"> @@ -85,8 +84,7 @@ android:parentActivityName="it.niedermann.owncloud.notes.android.activity.NotesListViewActivity" /> + android:name=".android.activity.SelectSingleNoteActivity"> diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/AboutActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/AboutActivity.java index 6c5cbf82..5a081c0d 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/AboutActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/AboutActivity.java @@ -4,6 +4,7 @@ import android.os.Bundle; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; @@ -21,6 +22,8 @@ import it.niedermann.owncloud.notes.util.ExceptionHandler; public class AboutActivity extends AppCompatActivity { + @BindView(R.id.toolbar) + Toolbar toolbar; @BindView(R.id.pager) ViewPager mViewPager; @BindView(R.id.tabs) @@ -33,6 +36,7 @@ public class AboutActivity extends AppCompatActivity { setContentView(R.layout.activity_about); ButterKnife.bind(this); + setSupportActionBar(toolbar); mViewPager.setAdapter(new TabsPagerAdapter(getSupportFragmentManager())); mTabLayout.setupWithViewPager(mViewPager); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java index 4db29f06..e51d807d 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java @@ -8,8 +8,8 @@ import android.util.Log; import android.view.Menu; import android.view.MenuItem; -import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; import java.io.BufferedReader; @@ -19,6 +19,8 @@ import java.io.InputStreamReader; import java.util.Calendar; import java.util.Objects; +import butterknife.BindView; +import butterknife.ButterKnife; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.android.fragment.BaseNoteFragment; import it.niedermann.owncloud.notes.android.fragment.NoteEditFragment; @@ -45,6 +47,9 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm public static final String PARAM_CATEGORY = "category"; public static final String PARAM_CONTENT = "content"; + @BindView(R.id.toolbar) + Toolbar toolbar; + private BaseNoteFragment fragment; @Override @@ -52,15 +57,17 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm super.onCreate(savedInstanceState); Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this)); + setContentView(R.layout.activity_edit); + + ButterKnife.bind(this); + if (savedInstanceState == null) { launchNoteFragment(); } else { - fragment = (BaseNoteFragment) getSupportFragmentManager().findFragmentById(android.R.id.content); - } - ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - actionBar.setDisplayHomeAsUpEnabled(true); + fragment = (BaseNoteFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_container_view); } + + setSupportActionBar(toolbar); } @Override @@ -144,7 +151,7 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm if (savedState != null) { fragment.setInitialSavedState(savedState); } - getSupportFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commit(); + getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container_view, fragment).commit(); } /** @@ -179,7 +186,7 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm } CloudNote newNote = new CloudNote(0, Calendar.getInstance(), NoteUtil.generateNonEmptyNoteTitle(content, this), content, favorite, category, null); fragment = NoteEditFragment.newInstanceWithNewNote(newNote); - getSupportFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commit(); + getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container_view, fragment).commit(); } private void launchReadonlyNote() { @@ -197,7 +204,7 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm } fragment = NoteReadonlyFragment.newInstance(content.toString()); - getSupportFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commit(); + getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container_view, fragment).commit(); } @Override @@ -249,11 +256,10 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm @Override public void onNoteUpdated(DBNote note) { - ActionBar actionBar = Objects.requireNonNull(getSupportActionBar()); if (note != null) { - actionBar.setTitle(note.getTitle()); + toolbar.setTitle(note.getTitle()); if (!note.getCategory().isEmpty()) { - actionBar.setSubtitle(NoteUtil.extendCategory(note.getCategory())); + toolbar.setSubtitle(NoteUtil.extendCategory(note.getCategory())); } } else { // Maybe account is not authenticated -> note == null diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/ExceptionActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/ExceptionActivity.java index 1ea5457a..e19496c5 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/ExceptionActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/ExceptionActivity.java @@ -9,6 +9,7 @@ import android.widget.Toast; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import java.util.Objects; @@ -22,6 +23,8 @@ public class ExceptionActivity extends AppCompatActivity { Throwable throwable; + @BindView(R.id.toolbar) + Toolbar toolbar; @BindView(R.id.message) TextView message; @BindView(R.id.stacktrace) @@ -35,6 +38,7 @@ public class ExceptionActivity extends AppCompatActivity { setContentView(R.layout.activity_exception); ButterKnife.bind(this); super.onCreate(savedInstanceState); + setSupportActionBar(toolbar); throwable = ((Throwable) getIntent().getSerializableExtra(KEY_THROWABLE)); throwable.printStackTrace(); Objects.requireNonNull(getSupportActionBar()).setTitle(getString(R.string.simple_error)); diff --git a/app/src/main/res/drawable/ic_arrow_back_white_24dp.xml b/app/src/main/res/drawable/ic_arrow_back_white_24dp.xml new file mode 100644 index 00000000..cc2b6f53 --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_back_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/splashscreen.xml b/app/src/main/res/drawable/splashscreen.xml index 68ee3ac9..e61ed69b 100644 --- a/app/src/main/res/drawable/splashscreen.xml +++ b/app/src/main/res/drawable/splashscreen.xml @@ -1,7 +1,7 @@ - + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_exception.xml b/app/src/main/res/layout/activity_exception.xml index 88c1224d..eb3a633c 100644 --- a/app/src/main/res/layout/activity_exception.xml +++ b/app/src/main/res/layout/activity_exception.xml @@ -1,31 +1,38 @@ + android:orientation="vertical"> - + android:layout_height="?attr/actionBarSize" + android:background="?attr/colorPrimary" + android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" + app:contentInsetStartWithNavigation="0dp" + app:elevation="4dp" + app:titleMarginStart="0dp" + tools:title="@string/simple_exception" /> - - - + diff --git a/app/src/main/res/layout/activity_notes_list_view.xml b/app/src/main/res/layout/activity_notes_list_view.xml index 965714b5..e4f7f700 100644 --- a/app/src/main/res/layout/activity_notes_list_view.xml +++ b/app/src/main/res/layout/activity_notes_list_view.xml @@ -1,6 +1,7 @@ @@ -17,6 +18,8 @@ android:background="?attr/colorPrimary" app:titleMarginStart="0dp" app:contentInsetStartWithNavigation="0dp" + tools:title="@string/app_name" + tools:navigationIcon="@drawable/ic_arrow_back_white_24dp" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:elevation="4dp" /> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 5b0f8299..4b50d1e4 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -7,9 +7,6 @@ @color/primary true @color/bg_normal - - - @@ -17,6 +14,8 @@