Skip to content

Commit

Permalink
Theming: Startup & Activity animations: Quicker, less flashing, closes
Browse files Browse the repository at this point in the history
  • Loading branch information
gsantner committed Jan 9, 2022
1 parent 02cd0c3 commit c87752a
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 99 deletions.
5 changes: 2 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
android:requestLegacyExternalStorage="true"
android:resizeableActivity="true"
android:supportsRtl="true"
android:theme="@style/AppTheme.Unified"
android:theme="@style/AppTheme.Unified.StartupFlash"
android:usesCleartextTraffic="true"
tools:targetApi="o">

Expand All @@ -70,8 +70,7 @@
<activity
android:name=".activity.SettingsActivity"
android:label="@string/settings"
android:parentActivityName=".activity.MainActivity"
android:theme="@style/AppTheme.Unified" />
android:parentActivityName=".activity.MainActivity" />
<activity
android:name=".activity.ActionOrderActivity"
android:parentActivityName=".activity.SettingsActivity">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import static android.support.v7.widget.helper.ItemTouchHelper.ACTION_STATE_DRAG;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.DividerItemDecoration;
Expand All @@ -36,8 +35,6 @@
import net.gsantner.markor.format.todotxt.TodoTxtTextActions;
import net.gsantner.markor.format.zimwiki.ZimWikiTextActions;
import net.gsantner.markor.ui.hleditor.TextActions;
import net.gsantner.markor.util.ActivityUtils;
import net.gsantner.markor.util.AppSettings;
import net.gsantner.markor.util.ContextUtils;

import java.util.ArrayList;
Expand All @@ -58,12 +55,6 @@ public class ActionOrderActivity extends MarkorBaseActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setExitTransition(null);
}
final AppSettings appSettings = new AppSettings(this);
final ActivityUtils contextUtils = new ActivityUtils(this);
contextUtils.setAppLanguage(appSettings.getLanguage());
super.onCreate(savedInstanceState);
setContentView(R.layout.action_order_activity);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.app.ActivityManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.RectF;
import android.net.Uri;
Expand Down Expand Up @@ -60,8 +59,6 @@ public class DocumentActivity extends MarkorBaseActivity {
private FragmentManager _fragManager;
private Document _document;

private AppSettings _appSettings;
private ActivityUtils _contextUtils;

private static boolean nextLaunchTransparentBg = false;

Expand All @@ -88,7 +85,7 @@ public static void launch(Activity activity, File path, Boolean isFolder, Boolea
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
}
nextLaunchTransparentBg = (activity instanceof MainActivity);
activity.startActivity(intent);
new ActivityUtils(activity).animateToActivity(intent, false, 0).freeContextRef();
}

public static Object[] checkIfLikelyTextfileAndGetExt(File file) {
Expand Down Expand Up @@ -137,24 +134,14 @@ public static void askUserIfWantsToOpenFileInThisApp(final Activity activity, fi
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setEnterTransition(null);
}
AppSettings.clearDebugLog();
_appSettings = new AppSettings(this);
_contextUtils = new ActivityUtils(this);
_contextUtils.setAppLanguage(_appSettings.getLanguage());
if (_appSettings.isEditorStatusBarHidden()) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
if (nextLaunchTransparentBg) {
getWindow().getDecorView().setBackgroundColor(Color.TRANSPARENT);
//getWindow().getDecorView().setBackgroundColor(Color.TRANSPARENT);
nextLaunchTransparentBg = false;
}
setContentView(R.layout.document__activity);
_contextUtils.setAppLanguage(_appSettings.getLanguage());
ButterKnife.bind(this);
if (_appSettings.isEditorStatusBarHidden()) {
if (_appSettings.isHideSystemStatusbar()) {
AndroidBug5497Workaround.assistActivity(this);
}

Expand Down Expand Up @@ -215,7 +202,7 @@ private void showNotSupportedMessage() {
).replace("\n", "<br/>");

DialogInterface.OnClickListener listener = (dialogInterface, i) -> {
_contextUtils.openWebpageInExternalBrowser(getString(R.string.sync_client_support_issue_url));
_activityUtils.openWebpageInExternalBrowser(getString(R.string.sync_client_support_issue_url));
};

new AlertDialog.Builder(this)
Expand All @@ -237,7 +224,7 @@ public boolean dispatchTouchEvent(MotionEvent event) {
Rect activityVisibleSize = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(activityVisibleSize);

if (event.getAction() == MotionEvent.ACTION_DOWN && event.getY() > (_toolbar.getBottom() + _contextUtils.convertDpToPx(8)) & event.getY() < (activityVisibleSize.bottom - _contextUtils.convertDpToPx(52))) {
if (event.getAction() == MotionEvent.ACTION_DOWN && event.getY() > (_toolbar.getBottom() + _activityUtils.convertDpToPx(8)) & event.getY() < (activityVisibleSize.bottom - _activityUtils.convertDpToPx(52))) {
point.set(event.getX(), event.getY(), 0, 0);
} else if (event.getAction() == MotionEvent.ACTION_UP) {
point.set(point.left, point.top, event.getX(), event.getY());
Expand Down
22 changes: 4 additions & 18 deletions app/src/main/java/net/gsantner/markor/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import net.gsantner.markor.ui.FilesystemViewerCreator;
import net.gsantner.markor.ui.NewFileDialog;
import net.gsantner.markor.util.ActivityUtils;
import net.gsantner.markor.util.AppSettings;
import net.gsantner.markor.util.PermissionChecker;
import net.gsantner.markor.util.ShareUtil;
import net.gsantner.opoc.activity.GsFragmentBase;
Expand Down Expand Up @@ -79,26 +78,13 @@ public class MainActivity extends MarkorBaseActivity implements FilesystemViewer
private SectionsPagerAdapter _viewPagerAdapter;

private boolean _doubleBackToExitPressedOnce;

private AppSettings _appSettings;
private ActivityUtils _contextUtils;
private ShareUtil _shareUtil;

@SuppressLint("SdCardPath")
@Override
protected void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setExitTransition(null);
}
_appSettings = new AppSettings(this);
_contextUtils = new ActivityUtils(this);
_shareUtil = new ShareUtil(this);
_contextUtils.setAppLanguage(_appSettings.getLanguage());
if (_appSettings.isOverviewStatusBarHidden()) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
_appSettings.applyAppTheme();
super.onCreate(savedInstanceState);
_shareUtil = new ShareUtil(this);
setContentView(R.layout.main__activity);
ButterKnife.bind(this);
setSupportActionBar(_toolbar);
Expand Down Expand Up @@ -197,7 +183,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
if (item.getItemId() == R.id.action_settings) {
new ActivityUtils(this).animateToActivity(SettingsActivity.class, false, null);
new ActivityUtils(this).animateToActivity(SettingsActivity.class, false, null).freeContextRef();
return true;
}
return false;
Expand All @@ -209,8 +195,8 @@ public boolean onCreateOptionsMenu(final Menu menu) {

menu.findItem(R.id.action_settings).setVisible(_appSettings.isShowSettingsOptionInMainToolbar());

_contextUtils.tintMenuItems(menu, true, Color.WHITE);
_contextUtils.setSubMenuIconsVisiblity(menu, true);
_activityUtils.tintMenuItems(menu, true, Color.WHITE);
_activityUtils.setSubMenuIconsVisiblity(menu, true);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,35 @@

import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.WindowManager;

import net.gsantner.markor.R;
import net.gsantner.markor.util.ActivityUtils;
import net.gsantner.markor.util.AppSettings;
import net.gsantner.opoc.activity.GsActivityBase;

public abstract class MarkorBaseActivity extends GsActivityBase<AppSettings> {

@Override
protected void onPreCreate(@Nullable Bundle savedInstanceState) {
super.onPreCreate(savedInstanceState); // _appSettings, _activityUtils gets available
setTheme(R.style.AppTheme_Unified);
_appSettings.applyAppTheme();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setEnterTransition(null);
getWindow().setExitTransition(null);
}
_activityUtils.setAppLanguage(_appSettings.getLanguage()).freeContextRef(); // invalidates actvity references
_activityUtils.freeContextRef();
_activityUtils = new ActivityUtils(this);
if (_appSettings.isHideSystemStatusbar()) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}

@Override
public Integer getNewNavigationBarColor() {
return _activityUtils.parseColor(_appSettings.getNavigationBarColor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Boolean onPreferenceClicked(Preference preference, String key, int keyRes
return true;
}
case R.string.pref_key__more_info__settings: {
au.animateToActivity(SettingsActivity.class, false, 124);
au.animateToActivity(SettingsActivity.class, false, 124).freeContextRef();
return true;
}
case R.string.pref_key__more_info__rate_app: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import net.gsantner.markor.util.ActivityUtils;
import net.gsantner.markor.util.AppSettings;
import net.gsantner.markor.util.BackupUtils;
import net.gsantner.markor.util.ContextUtils;
import net.gsantner.markor.util.PermissionChecker;
import net.gsantner.markor.util.ShareUtil;
import net.gsantner.opoc.preference.FontPreferenceCompat;
Expand Down Expand Up @@ -64,25 +63,15 @@ public static class RESULT {

public void onCreate(Bundle b) {
// Must be applied before setContentView
AppSettings appSettings = new AppSettings(this);
ContextUtils contextUtils = new ContextUtils(this);
contextUtils.setAppLanguage(appSettings.getLanguage());
super.onCreate(b);

/*
ActivityUtils au = new ActivityUtils(this);
boolean extraLaunchersEnabled = appSettings.isSpecialFileLaunchersEnabled();
au.setLauncherActivityEnabled(OpenEditorQuickNoteActivity.class, extraLaunchersEnabled);
au.setLauncherActivityEnabled(OpenEditorTodoActivity.class, extraLaunchersEnabled);
*/

// Load UI
setContentView(R.layout.settings__activity);
ButterKnife.bind(this);

// Custom code
FontPreferenceCompat.additionalyCheckedFolder = new File(appSettings.getNotebookDirectory(), ".app/fonts");
iconColor = contextUtils.rcolor(R.color.primary_text);
FontPreferenceCompat.additionalyCheckedFolder = new File(_appSettings.getNotebookDirectory(), ".app/fonts");
iconColor = _activityUtils.rcolor(R.color.primary_text);
toolbar.setTitle(R.string.settings);
setSupportActionBar(toolbar);
toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp));
Expand Down Expand Up @@ -205,7 +194,7 @@ public void doUpdatePreferences() {
R.string.pref_key__swipe_to_change_mode,
R.string.pref_key__todotxt__hl_delay,
R.string.pref_key__markdown__hl_delay_v2,
R.string.pref_key__is_editor_statusbar_hidden,
R.string.pref_key__theming_hide_system_statusbar,
R.string.pref_key__tab_width_v2,
R.string.pref_key__editor_line_spacing,
};
Expand All @@ -226,7 +215,7 @@ protected void onPreferenceChanged(final SharedPreferences prefs, final String k
} else if (eq(key, R.string.pref_key__app_theme)) {
_as.applyAppTheme();
getActivity().finish();
} else if (eq(key, R.string.pref_key__is_overview_statusbar_hidden)) {
} else if (eq(key, R.string.pref_key__theming_hide_system_statusbar)) {
activityRetVal = RESULT.RESTART_REQ;
_as.setRecreateMainRequired(true);
} else if (eq(key, R.string.pref_key__is_launcher_for_special_files_enabled)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ protected void openActivityAndClose(final Intent openIntent, File file) {
}
openIntent.putExtra(Document.EXTRA_PATH, openIntent.hasExtra(Document.EXTRA_PATH) ? openIntent.getSerializableExtra(Document.EXTRA_PATH) : file);
openIntent.putExtra(Document.EXTRA_PATH_IS_FOLDER, openIntent.hasExtra(Document.EXTRA_PATH_IS_FOLDER) ? openIntent.getSerializableExtra(Document.EXTRA_PATH_IS_FOLDER) : file.isDirectory());
ActivityUtils au = new ActivityUtils(this);
au.animateToActivity(openIntent, true, 1);
new ActivityUtils(this).animateToActivity(openIntent, true, 1).freeContextRef();
}
} catch (Exception ignored) {
finish();
Expand Down
8 changes: 2 additions & 6 deletions app/src/main/java/net/gsantner/markor/util/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ public int[] getMarkdownTableOfContentLevels() {
return ret;
}

public boolean isEditorStatusBarHidden() {
return getBool(R.string.pref_key__is_editor_statusbar_hidden, false);
public boolean isHideSystemStatusbar() {
return getBool(R.string.pref_key__theming_hide_system_statusbar, false);
}

public boolean isSpecialFileLaunchersEnabled() {
Expand All @@ -222,10 +222,6 @@ public boolean isDisallowScreenshots() {
return getBool(R.string.pref_key__is_disallow_screenshots, false);
}

public boolean isOverviewStatusBarHidden() {
return getBool(R.string.pref_key__is_overview_statusbar_hidden, false);
}

public String getLanguage() {
return getString(R.string.pref_key__language, "");
}
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/net/gsantner/opoc/activity/GsActivityBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ public abstract class GsActivityBase<AS extends SharedPreferencesPropertyBackend

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
onPreCreate(savedInstanceState);
super.onCreate(savedInstanceState);
_savedInstanceState = savedInstanceState;
_appSettings = createAppSettingsInstance(this);
_activityUtils = new ActivityUtils(this);

m_setActivityBackgroundColor.callback();
m_setActivityNavigationBarColor.callback();
Expand All @@ -54,6 +52,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
}
}

protected void onPreCreate(@Nullable Bundle savedInstanceState) {
_savedInstanceState = savedInstanceState;
_appSettings = createAppSettingsInstance(this);
_activityUtils = new ActivityUtils(this);
}

public AS createAppSettingsInstance(Context applicationContext) {
return null;
}
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/net/gsantner/opoc/util/ActivityUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public void freeContextRef() {
* @param finishFromActivity true: Finish the current activity
* @param requestCode Request code for stating the activity, not waiting for result if null
*/
public void animateToActivity(Class to, Boolean finishFromActivity, Integer requestCode) {
animateToActivity(new Intent(_activity, to), finishFromActivity, requestCode);
public ActivityUtils animateToActivity(Class to, Boolean finishFromActivity, Integer requestCode) {
return animateToActivity(new Intent(_activity, to), finishFromActivity, requestCode);
}

/**
Expand All @@ -87,7 +87,7 @@ public void animateToActivity(Class to, Boolean finishFromActivity, Integer requ
* @param finishFromActivity true: Finish the current activity
* @param requestCode Request code for stating the activity, not waiting for result if null
*/
public void animateToActivity(Intent intent, Boolean finishFromActivity, Integer requestCode) {
public ActivityUtils animateToActivity(Intent intent, Boolean finishFromActivity, Integer requestCode) {
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
if (requestCode != null) {
_activity.startActivityForResult(intent, requestCode);
Expand All @@ -99,6 +99,7 @@ public void animateToActivity(Intent intent, Boolean finishFromActivity, Integer
if (finishFromActivity != null && finishFromActivity) {
_activity.finish();
}
return this;
}


Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/net/gsantner/opoc/util/ContextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,11 @@ public Locale getLocaleByAndroidCode(String androidLC) {
* {@code androidLC} may be in any of the forms: en, de, de-rAt
* If given an empty string, the default (system) locale gets loaded
*/
public void setAppLanguage(final String androidLC) {
public ContextUtils setAppLanguage(final String androidLC) {
Locale locale = getLocaleByAndroidCode(androidLC);
locale = (locale != null && !androidLC.isEmpty()) ? locale : Resources.getSystem().getConfiguration().locale;
setLocale(locale);
return this;
}

public ContextUtils setLocale(final Locale locale) {
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values/string-not_translatable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="pref_key__font_family" translatable="false">pref_key__font_family</string>
<string name="pref_key__editor_font_size" translatable="false">pref_key__editor_font_size</string>
<string name="pref_key__app_theme" translatable="false">pref_key__app_theme</string>
<string name="pref_key__is_editor_statusbar_hidden" translatable="false">pref_key__is_editor_statusbar_hidden</string>
<string name="pref_key__is_overview_statusbar_hidden" translatable="false">pref_key__is_overview_statusbar_hidden</string>
<string name="pref_key__theming_hide_system_statusbar" translatable="false">pref_key__theming_hide_system_statusbar</string>
<string name="pref_key__language" translatable="false">pref_key__language</string>
<string name="pref_key__is_main_recreate_required" translatable="false">pref_key__is_main_recreate_required</string>
<string name="pref_key__sort_method" translatable="false">pref_key__sort_method</string>
Expand Down
Loading

0 comments on commit c87752a

Please sign in to comment.