Remove ActivityUi

This commit is contained in:
serso 2016-03-01 11:57:48 +01:00
parent 6427c91953
commit a6bb109514
17 changed files with 338 additions and 396 deletions

View File

@ -1,301 +0,0 @@
/*
* Copyright 2013 serso aka se.solovyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Contact details
*
* Email: se.solovyev@gmail.com
* Site: http://se.solovyev.org
*/
package org.solovyev.android.calculator;
import static org.solovyev.android.calculator.App.cast;
import android.app.Activity;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.annotation.DrawableRes;
import android.support.annotation.LayoutRes;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.solovyev.android.Activities;
import org.solovyev.android.Check;
import org.solovyev.android.Views;
import org.solovyev.android.calculator.history.History;
import org.solovyev.android.calculator.language.Language;
import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.calculator.view.Tabs;
import butterknife.Bind;
import butterknife.ButterKnife;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
public class ActivityUi {
@Nonnull
private final AppCompatActivity activity;
private final int layoutId;
@Nonnull
private final Tabs tabs;
@Inject
SharedPreferences preferences;
@Inject
Editor editor;
@Inject
History history;
@Inject
Keyboard keyboard;
@Inject
Calculator calculator;
@Inject
Typeface typeface;
@Bind(R.id.main)
ViewGroup mainView;
@Nullable
@Bind(R.id.toolbar)
Toolbar toolbar;
@Nullable
@Bind(R.id.fab)
FloatingActionButton fab;
@Nonnull
private Preferences.Gui.Theme theme = Preferences.Gui.Theme.material_theme;
@Nonnull
private Preferences.Gui.Layout layout = Preferences.Gui.Layout.main_calculator;
@Nonnull
private Language language = Languages.SYSTEM_LANGUAGE;
public ActivityUi(@Nonnull AppCompatActivity activity, @LayoutRes int layoutId) {
this.activity = activity;
this.layoutId = layoutId;
tabs = new Tabs(activity);
}
public static boolean restartIfThemeChanged(@Nonnull Activity activity, @Nonnull Preferences.Gui.Theme oldTheme) {
final Preferences.Gui.Theme newTheme = Preferences.Gui.theme.getPreference(App.getPreferences());
final int themeId = oldTheme.getThemeFor(activity);
final int newThemeId = newTheme.getThemeFor(activity);
if (themeId != newThemeId) {
Activities.restartActivity(activity);
return true;
}
return false;
}
public static boolean restartIfLanguageChanged(@Nonnull Activity activity, @Nonnull Language oldLanguage) {
final Language current = App.getLanguages().getCurrent();
if (!current.equals(oldLanguage)) {
Activities.restartActivity(activity);
return true;
}
return false;
}
public static void reportActivityStop(@Nonnull Activity activity) {
App.getGa().getAnalytics().reportActivityStop(activity);
}
public static void reportActivityStart(@Nonnull Activity activity) {
App.getGa().getAnalytics().reportActivityStart(activity);
}
public static void setFont(@Nonnull TextView view, @Nonnull Typeface newTypeface) {
final Typeface oldTypeface = view.getTypeface();
if (oldTypeface == newTypeface) {
return;
}
final int style = oldTypeface != null ? oldTypeface.getStyle() : Typeface.NORMAL;
view.setTypeface(newTypeface, style);
}
public void onPreCreate(@Nonnull Activity activity) {
cast(activity.getApplication()).getComponent().inject(this);
theme = Preferences.Gui.getTheme(preferences);
activity.setTheme(theme.getThemeFor(activity));
layout = Preferences.Gui.getLayout(preferences);
language = App.getLanguages().getCurrent();
}
public void onCreate() {
// let's disable locking of screen for monkeyrunner
if (App.isMonkeyRunner(activity)) {
final KeyguardManager km = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
//noinspection deprecation
km.newKeyguardLock(activity.getClass().getName()).disableKeyguard();
}
App.getLanguages().updateContextLocale(activity, false);
activity.setContentView(layoutId);
ButterKnife.bind(this, activity);
fixFonts(mainView);
addHelpInfo(activity, mainView);
initToolbar();
}
private void initToolbar() {
if (toolbar == null) {
return;
}
if (activity instanceof CalculatorActivity) {
return;
}
activity.setSupportActionBar(toolbar);
final ActionBar actionBar = activity.getSupportActionBar();
Check.isNotNull(actionBar);
actionBar.setDisplayHomeAsUpEnabled(true);
}
public void onPause() {
tabs.onPause();
}
public void onDestroy() {
}
@Nonnull
public Language getLanguage() {
return language;
}
@Nonnull
public Preferences.Gui.Layout getLayout() {
return layout;
}
@Nonnull
public Preferences.Gui.Theme getTheme() {
return theme;
}
public void onResume() {
if (!restartIfThemeChanged(activity, theme)) {
restartIfLanguageChanged(activity, language);
}
}
private void addHelpInfo(@Nonnull Activity activity, @Nonnull View root) {
if (!App.isMonkeyRunner(activity)) {
return;
}
if (!(root instanceof ViewGroup)) {
return;
}
final TextView helperTextView = new TextView(activity);
final DisplayMetrics dm = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
helperTextView.setTextSize(15);
helperTextView.setTextColor(Color.WHITE);
final Configuration c = activity.getResources().getConfiguration();
final StringBuilder helpText = new StringBuilder();
helpText.append("Size: ");
if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_XLARGE, c)) {
helpText.append("xlarge");
} else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, c)) {
helpText.append("large");
} else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_NORMAL, c)) {
helpText.append("normal");
} else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_SMALL, c)) {
helpText.append("small");
} else {
helpText.append("unknown");
}
helpText.append(" (").append(dm.widthPixels).append("x").append(dm.heightPixels).append(")");
helpText.append(" Density: ");
switch (dm.densityDpi) {
case DisplayMetrics.DENSITY_LOW:
helpText.append("ldpi");
break;
case DisplayMetrics.DENSITY_MEDIUM:
helpText.append("mdpi");
break;
case DisplayMetrics.DENSITY_HIGH:
helpText.append("hdpi");
break;
case DisplayMetrics.DENSITY_XHIGH:
helpText.append("xhdpi");
break;
case DisplayMetrics.DENSITY_TV:
helpText.append("tv");
break;
}
helpText.append(" (").append(dm.densityDpi).append(")");
helperTextView.setText(helpText);
((ViewGroup) root).addView(helperTextView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
public void onStop(@Nonnull Activity activity) {
reportActivityStop(activity);
}
public void onStart(@Nonnull Activity activity) {
reportActivityStart(activity);
}
protected void fixFonts(@Nonnull View root) {
// some devices ship own fonts which causes issues with rendering. Let's use our own font for all text views
Views.processViewsOfType(root, TextView.class, new Views.ViewProcessor<TextView>() {
@Override
public void process(@Nonnull TextView view) {
setFont(view, typeface);
}
});
}
public void onPostCreate() {
tabs.onCreate();
}
@Nonnull
public Tabs getTabs() {
return tabs;
}
public void withFab(@DrawableRes int icon, @Nonnull View.OnClickListener listener) {
if (fab == null) {
Check.shouldNotHappen();
return;
}
fab.setVisibility(View.VISIBLE);
fab.setImageResource(icon);
fab.setOnClickListener(listener);
}
}

View File

@ -30,6 +30,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.IBinder;
@ -42,9 +43,12 @@ import android.support.v4.app.FragmentTransaction;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
import com.squareup.otto.Bus;
@ -184,19 +188,6 @@ public final class App {
return languages;
}
public static boolean isLg() {
if (lg == null) {
lg = "lge".equalsIgnoreCase(Build.BRAND) || "lge".equalsIgnoreCase(Build.MANUFACTURER);
}
return lg;
}
// see https://code.google.com/p/android/issues/detail?id=78154
// and http://developer.lge.com/community/forums/RetrieveForumContent.dev?detailContsId=FC29190703
public static boolean shouldOpenMenuManually() {
return isLg() && Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN;
}
@Nonnull
public static ScreenMetrics getScreenMetrics() {
return screenMetrics;
@ -349,4 +340,63 @@ public final class App {
public static boolean isTablet(@NonNull Context context) {
return context.getResources().getBoolean(R.bool.cpp_tablet);
}
static void addHelpInfo(@Nonnull Activity activity, @Nonnull View root) {
if (!isMonkeyRunner(activity)) {
return;
}
if (!(root instanceof ViewGroup)) {
return;
}
final TextView helperTextView = new TextView(activity);
final DisplayMetrics dm = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
helperTextView.setTextSize(15);
helperTextView.setTextColor(Color.WHITE);
final Configuration c = activity.getResources().getConfiguration();
final StringBuilder helpText = new StringBuilder();
helpText.append("Size: ");
if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_XLARGE, c)) {
helpText.append("xlarge");
} else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, c)) {
helpText.append("large");
} else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_NORMAL, c)) {
helpText.append("normal");
} else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_SMALL, c)) {
helpText.append("small");
} else {
helpText.append("unknown");
}
helpText.append(" (").append(dm.widthPixels).append("x").append(dm.heightPixels).append(")");
helpText.append(" Density: ");
switch (dm.densityDpi) {
case DisplayMetrics.DENSITY_LOW:
helpText.append("ldpi");
break;
case DisplayMetrics.DENSITY_MEDIUM:
helpText.append("mdpi");
break;
case DisplayMetrics.DENSITY_HIGH:
helpText.append("hdpi");
break;
case DisplayMetrics.DENSITY_XHIGH:
helpText.append("xhdpi");
break;
case DisplayMetrics.DENSITY_TV:
helpText.append("tv");
break;
}
helpText.append(" (").append(dm.densityDpi).append(")");
helperTextView.setText(helpText);
((ViewGroup) root).addView(helperTextView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
}

View File

@ -23,17 +23,17 @@ import org.solovyev.android.calculator.variables.VariablesFragment;
import org.solovyev.android.calculator.view.Tabs;
import org.solovyev.android.calculator.widget.CalculatorWidget;
import org.solovyev.android.calculator.wizard.DragButtonWizardStep;
import dagger.Component;
import org.solovyev.android.calculator.wizard.WizardActivity;
import javax.inject.Singleton;
import dagger.Component;
@Singleton
@Component(modules = AppModule.class)
public interface AppComponent {
void inject(CalculatorApplication application);
void inject(EditorFragment fragment);
void inject(ActivityUi ui);
void inject(FloatingCalculatorService service);
void inject(BaseHistoryFragment fragment);
void inject(BaseDialogFragment fragment);
@ -63,4 +63,6 @@ public interface AppComponent {
void inject(HistoryActivity activity);
void inject(Tabs tabs);
void inject(CalculatorWidget widget);
void inject(WizardActivity activity);
void inject(BaseActivity activity);
}

View File

@ -14,6 +14,7 @@ import com.squareup.otto.Bus;
import com.squareup.otto.GeneratedHandlerFinder;
import org.solovyev.android.UiThreadExecutor;
import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.checkout.Billing;
import org.solovyev.android.checkout.Checkout;
import org.solovyev.android.checkout.Inventory;
@ -56,9 +57,12 @@ public class AppModule {
@NonNull
private final Application application;
@NonNull
private final Languages languages;
public AppModule(@NonNull Application application) {
public AppModule(@NonNull Application application, @NonNull Languages languages) {
this.application = application;
this.languages = languages;
}
@Provides
@ -213,6 +217,13 @@ public class AppModule {
return Plot.newPlotter(application);
}
@Provides
@Singleton
@NonNull
public Languages provideLanguages() {
return languages;
}
@Nonnull
private File makeFilesDir() {
final File filesDir = application.getFilesDir();

View File

@ -1,43 +1,183 @@
package org.solovyev.android.calculator;
import static org.solovyev.android.calculator.App.cast;
import android.app.Activity;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.DrawableRes;
import android.support.annotation.LayoutRes;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.solovyev.android.Activities;
import org.solovyev.android.Check;
import org.solovyev.android.Views;
import org.solovyev.android.calculator.history.History;
import org.solovyev.android.calculator.language.Language;
import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.calculator.view.Tabs;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import butterknife.Bind;
import butterknife.ButterKnife;
import static org.solovyev.android.calculator.App.cast;
public class BaseActivity extends AppCompatActivity {
@Nonnull
protected final ActivityUi ui;
protected final Tabs tabs;
private final int layoutId;
@Inject
SharedPreferences preferences;
@Inject
Languages languages;
@Inject
Editor editor;
@Inject
History history;
@Inject
Keyboard keyboard;
@Inject
Calculator calculator;
@Inject
Typeface typeface;
@Bind(R.id.main)
ViewGroup mainView;
@Nullable
@Bind(R.id.toolbar)
Toolbar toolbar;
@Nullable
@Bind(R.id.fab)
FloatingActionButton fab;
@Nonnull
private Preferences.Gui.Theme theme = Preferences.Gui.Theme.material_theme;
@Nonnull
private Preferences.Gui.Layout layout = Preferences.Gui.Layout.main_calculator;
@Nonnull
private Language language = Languages.SYSTEM_LANGUAGE;
public BaseActivity() {
this(R.layout.activity_tabs);
}
public BaseActivity(@LayoutRes int layout) {
this.ui = new ActivityUi(this, layout);
this.layoutId = layout;
this.tabs = new Tabs(this);
}
@Nonnull
public ActivityUi getUi() {
return ui;
public static void reportActivityStop(@Nonnull Activity activity) {
App.getGa().getAnalytics().reportActivityStop(activity);
}
public static void reportActivityStart(@Nonnull Activity activity) {
App.getGa().getAnalytics().reportActivityStart(activity);
}
public static void setFont(@Nonnull TextView view, @Nonnull Typeface newTypeface) {
final Typeface oldTypeface = view.getTypeface();
if (oldTypeface == newTypeface) {
return;
}
final int style = oldTypeface != null ? oldTypeface.getStyle() : Typeface.NORMAL;
view.setTypeface(newTypeface, style);
}
public boolean restartIfLayoutChanged() {
final Preferences.Gui.Layout newLayout = Preferences.Gui.layout.getPreference(preferences);
if (newLayout != layout) {
Activities.restartActivity(this);
return true;
}
return false;
}
public boolean restartIfThemeChanged() {
final Preferences.Gui.Theme newTheme = Preferences.Gui.theme.getPreferenceNoError(preferences);
final int themeId = theme.getThemeFor(this);
final int newThemeId = newTheme.getThemeFor(this);
if (themeId != newThemeId) {
Activities.restartActivity(this);
return true;
}
return false;
}
public boolean restartIfLanguageChanged() {
final Language current = languages.getCurrent();
if (!current.equals(language)) {
Activities.restartActivity(this);
return true;
}
return false;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
ui.onPreCreate(this);
onPreCreate();
super.onCreate(savedInstanceState);
inject(cast(getApplication()).getComponent());
ui.onCreate();
populateTabs(ui.getTabs());
ui.onPostCreate();
disableKeyguard();
languages.updateContextLocale(this, false);
createView();
}
private void createView() {
setContentView(layoutId);
ButterKnife.bind(this, this);
fixFonts(mainView);
App.addHelpInfo(this, mainView);
initToolbar();
populateTabs(tabs);
tabs.onCreate();
}
private void initToolbar() {
if (toolbar == null) {
return;
}
if (this instanceof CalculatorActivity) {
return;
}
setSupportActionBar(toolbar);
final ActionBar actionBar = getSupportActionBar();
Check.isNotNull(actionBar);
actionBar.setDisplayHomeAsUpEnabled(true);
}
@SuppressWarnings({"ResourceType", "deprecation"})
private void disableKeyguard() {
if (App.isMonkeyRunner(this)) {
final KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
km.newKeyguardLock(getClass().getName()).disableKeyguard();
}
}
private void onPreCreate() {
cast(getApplication()).getComponent().inject(this);
theme = Preferences.Gui.getTheme(preferences);
setTheme(theme.getThemeFor(this));
layout = Preferences.Gui.getLayout(preferences);
language = App.getLanguages().getCurrent();
}
protected void populateTabs(@Nonnull Tabs tabs) {
@ -49,42 +189,42 @@ public class BaseActivity extends AppCompatActivity {
@Override
protected void onStart() {
super.onStart();
ui.onStart(this);
reportActivityStart(this);
}
@Override
protected void onStop() {
ui.onStop(this);
reportActivityStop(this);
super.onStop();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (App.shouldOpenMenuManually() && keyCode == KeyEvent.KEYCODE_MENU) {
openOptionsMenu();
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0 && toolbar != null) {
if (toolbar.isOverflowMenuShowing()) {
toolbar.hideOverflowMenu();
} else {
toolbar.showOverflowMenu();
}
return true;
}
return super.onKeyDown(keyCode, event);
return super.onKeyUp(keyCode, event);
}
@Override
protected void onResume() {
super.onResume();
ui.onResume();
if (!restartIfThemeChanged()) {
restartIfLanguageChanged();
}
}
@Override
protected void onPause() {
this.ui.onPause();
tabs.onPause();
super.onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
ui.onDestroy();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@ -94,4 +234,24 @@ public class BaseActivity extends AppCompatActivity {
}
return super.onOptionsItemSelected(item);
}
public void withFab(@DrawableRes int icon, @Nonnull View.OnClickListener listener) {
if (fab == null) {
Check.shouldNotHappen();
return;
}
fab.setVisibility(View.VISIBLE);
fab.setImageResource(icon);
fab.setOnClickListener(listener);
}
protected void fixFonts(@Nonnull View root) {
// some devices ship own fonts which causes issues with rendering. Let's use our own font for all text views
Views.processViewsOfType(root, TextView.class, new Views.ViewProcessor<TextView>() {
@Override
public void process(@Nonnull TextView view) {
setFont(view, typeface);
}
});
}
}

View File

@ -30,11 +30,13 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.CardView;
import android.support.v7.widget.Toolbar;
import android.view.*;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.FrameLayout;
import butterknife.Bind;
import butterknife.ButterKnife;
import org.solovyev.android.Activities;
import org.solovyev.android.calculator.converter.ConverterFragment;
import org.solovyev.android.calculator.history.History;
import org.solovyev.android.calculator.keyboard.PartialKeyboardUi;
@ -43,6 +45,9 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import butterknife.Bind;
import butterknife.ButterKnife;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
@ -74,7 +79,7 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
@Nullable
@Bind(R.id.card)
CardView card;
private boolean useBackAsPrev;
private boolean useBackAsPrevious;
public CalculatorActivity() {
super(R.layout.activity_main);
@ -102,7 +107,7 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
toolbar.inflateMenu(R.menu.main);
toolbar.setOnMenuItemClickListener(this);
useBackAsPrev = Preferences.Gui.useBackAsPrevious.getPreference(preferences);
useBackAsPrevious = Preferences.Gui.useBackAsPrevious.getPreference(preferences);
if (savedInstanceState == null) {
startupHelper.onMainActivityOpened(this);
}
@ -128,11 +133,9 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (useBackAsPrev) {
history.undo();
return true;
}
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0 && useBackAsPrevious) {
history.undo();
return true;
}
return super.onKeyDown(keyCode, event);
}
@ -140,12 +143,10 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
@Override
protected void onResume() {
super.onResume();
launcher.setActivity(this);
final Preferences.Gui.Layout newLayout = Preferences.Gui.layout.getPreference(preferences);
if (newLayout != ui.getLayout()) {
Activities.restartActivity(this);
if (restartIfLayoutChanged()) {
return;
}
launcher.setActivity(this);
final Window window = getWindow();
if (keepScreenOn.getPreference(preferences)) {
@ -173,7 +174,7 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
if (Preferences.Gui.useBackAsPrevious.getKey().equals(key)) {
useBackAsPrev = Preferences.Gui.useBackAsPrevious.getPreference(preferences);
useBackAsPrevious = Preferences.Gui.useBackAsPrevious.getPreference(preferences);
}
if (Preferences.Gui.rotateScreen.getKey().equals(key)) {

View File

@ -25,6 +25,7 @@ package org.solovyev.android.calculator;
import android.content.SharedPreferences;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.util.Log;
import android.util.TimingLogger;
@ -117,7 +118,7 @@ public class CalculatorApplication extends android.app.Application implements Sh
super.onCreate();
timer.addSplit("super.onCreate");
initDagger();
initDagger(languages);
timer.addSplit("initDagger");
onPostCreate(preferences, languages);
@ -125,9 +126,9 @@ public class CalculatorApplication extends android.app.Application implements Sh
timer.dumpToLog();
}
private void initDagger() {
private void initDagger(@NonNull Languages languages) {
component = DaggerAppComponent.builder()
.appModule(new AppModule(this))
.appModule(new AppModule(this, languages))
.build();
component.inject(this);
editor.init();

View File

@ -357,7 +357,7 @@ public class FloatingCalculatorView {
BaseKeyboardUi.adjustButton(button);
}
if (button instanceof TextView) {
ActivityUi.setFont((TextView) button, typeface);
BaseActivity.setFont((TextView) button, typeface);
}
}

View File

@ -57,7 +57,7 @@ public class FunctionsActivity extends BaseActivity {
}
}
ui.withFab(R.drawable.ic_add_white_36dp, new View.OnClickListener() {
withFab(R.drawable.ic_add_white_36dp, new View.OnClickListener() {
@Override
public void onClick(View v) {
EditFunctionFragment.show(FunctionsActivity.this);

View File

@ -55,10 +55,10 @@ public class HistoryActivity extends BaseActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ui.withFab(R.drawable.ic_delete_white_36dp, new View.OnClickListener() {
withFab(R.drawable.ic_delete_white_36dp, new View.OnClickListener() {
@Override
public void onClick(View v) {
final Fragment fragment = ui.getTabs().getCurrentFragment();
final Fragment fragment = tabs.getCurrentFragment();
showClearHistoryDialog(fragment instanceof RecentHistoryFragment);
}
});

View File

@ -116,7 +116,7 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
button.setVibrateOnDrag(keyboard.isVibrateOnKeypress());
prepareButton((View) button);
button.setOnDragListener(listener);
ActivityUi.setFont(button, typeface);
BaseActivity.setFont(button, typeface);
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
Adjuster.adjustText(button, textScale);
}

View File

@ -9,12 +9,12 @@ import android.support.annotation.StringRes;
import android.support.annotation.XmlRes;
import android.util.SparseArray;
import org.solovyev.android.calculator.ActivityUi;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.AppComponent;
import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.checkout.ActivityCheckout;
import org.solovyev.android.checkout.Billing;
import org.solovyev.android.checkout.Checkout;
@ -29,20 +29,20 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc
static final String EXTRA_PREFERENCE_TITLE = "preference-title";
@Nonnull
private static final SparseArray<PrefDef> preferences = new SparseArray<>();
private static final SparseArray<PrefDef> preferenceDefs = new SparseArray<>();
public static Class<? extends PreferencesActivity> getClass(@NonNull Context context) {
return App.isTablet(context) ? Dialog.class : PreferencesActivity.class;
}
static {
preferences.append(R.xml.preferences, new PrefDef("screen-main", R.string.cpp_settings));
preferences.append(R.xml.preferences_calculations, new PrefDef("screen-calculations", R.string.c_prefs_calculations_category));
preferences.append(R.xml.preferences_appearance, new PrefDef("screen-appearance", R.string.c_prefs_appearance_category));
preferences.append(R.xml.preferences_plot, new PrefDef("screen-plot", R.string.prefs_graph_screen_title));
preferences.append(R.xml.preferences_other, new PrefDef("screen-other", R.string.c_prefs_other_category));
preferences.append(R.xml.preferences_onscreen, new PrefDef("screen-onscreen", R.string.prefs_onscreen_title));
preferences.append(R.xml.preferences_widget, new PrefDef("screen-widget", R.string.prefs_widget_title));
preferenceDefs.append(R.xml.preferences, new PrefDef("screen-main", R.string.cpp_settings));
preferenceDefs.append(R.xml.preferences_calculations, new PrefDef("screen-calculations", R.string.c_prefs_calculations_category));
preferenceDefs.append(R.xml.preferences_appearance, new PrefDef("screen-appearance", R.string.c_prefs_appearance_category));
preferenceDefs.append(R.xml.preferences_plot, new PrefDef("screen-plot", R.string.prefs_graph_screen_title));
preferenceDefs.append(R.xml.preferences_other, new PrefDef("screen-other", R.string.c_prefs_other_category));
preferenceDefs.append(R.xml.preferences_onscreen, new PrefDef("screen-onscreen", R.string.prefs_onscreen_title));
preferenceDefs.append(R.xml.preferences_widget, new PrefDef("screen-widget", R.string.prefs_widget_title));
}
ActivityCheckout checkout;
@ -52,14 +52,18 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc
Billing billing;
@Inject
Products products;
@Inject
SharedPreferences preferences;
@Inject
Languages languages;
public PreferencesActivity() {
super(R.layout.activity_empty);
}
@Nonnull
static SparseArray<PrefDef> getPreferences() {
return preferences;
static SparseArray<PrefDef> getPreferenceDefs() {
return preferenceDefs;
}
public static void showPlotPreferences(@Nonnull Context context) {
@ -113,9 +117,9 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (!paused) {
if (Preferences.Gui.theme.isSameKey(key)) {
ActivityUi.restartIfThemeChanged(this, ui.getTheme());
restartIfThemeChanged();
} else if (Preferences.Gui.language.isSameKey(key)) {
ActivityUi.restartIfLanguageChanged(this, ui.getLanguage());
restartIfLanguageChanged();
}
}
}

View File

@ -1,8 +1,5 @@
package org.solovyev.android.calculator.preferences;
import static org.solovyev.android.calculator.wizard.CalculatorWizards.DEFAULT_WIZARD_FLOW;
import static org.solovyev.android.wizard.WizardUi.startWizard;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
@ -31,6 +28,9 @@ import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static org.solovyev.android.calculator.wizard.CalculatorWizards.DEFAULT_WIZARD_FLOW;
import static org.solovyev.android.wizard.WizardUi.startWizard;
public class PreferencesFragment extends org.solovyev.android.material.preferences.PreferencesFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
private static boolean SUPPORT_HEADERS = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
@ -70,7 +70,7 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
final int preference = getPreferencesResId();
if (preference == R.xml.preferences) {
final SparseArray<PreferencesActivity.PrefDef> preferences = PreferencesActivity.getPreferences();
final SparseArray<PreferencesActivity.PrefDef> preferences = PreferencesActivity.getPreferenceDefs();
for (int i = 0; i < preferences.size(); i++) {
final int xml = preferences.keyAt(i);
final PreferencesActivity.PrefDef def = preferences.valueAt(i);

View File

@ -30,8 +30,9 @@ import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import org.solovyev.android.calculator.ActivityUi;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.BaseDialogFragment;
import org.solovyev.android.calculator.R;
import org.solovyev.android.checkout.*;
@ -68,12 +69,12 @@ public class PurchaseDialogActivity extends AppCompatActivity implements Request
@Override
protected void onStart() {
super.onStart();
ActivityUi.reportActivityStart(this);
BaseActivity.reportActivityStart(this);
}
@Override
protected void onStop() {
ActivityUi.reportActivityStop(this);
BaseActivity.reportActivityStop(this);
super.onStop();
}

View File

@ -57,7 +57,7 @@ public class VariablesActivity extends BaseActivity {
}
}
ui.withFab(R.drawable.ic_add_white_36dp, new View.OnClickListener() {
withFab(R.drawable.ic_add_white_36dp, new View.OnClickListener() {
@Override
public void onClick(View v) {
EditVariableFragment.showDialog(VariablesActivity.this);

View File

@ -31,7 +31,7 @@ import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import org.solovyev.android.calculator.ActivityUi;
import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.keyboard.BaseKeyboardUi;
import org.solovyev.android.views.Adjuster;
@ -77,7 +77,7 @@ public class DragButtonWizardStep extends WizardFragment {
dragButton.setOnClickListener(this);
dragButton.setOnDragListener(
new SimpleDragListener(new DragButtonProcessor(), getActivity()));
ActivityUi.setFont(dragButton, typeface);
BaseActivity.setFont(dragButton, typeface);
Adjuster.adjustText(dragButton, BaseKeyboardUi.getTextScale(getActivity()));
actionTextView = (TextView) root.findViewById(R.id.wizard_dragbutton_action_textview);
if (savedInstanceState != null) {

View File

@ -11,11 +11,12 @@ import android.support.v7.app.AlertDialog;
import com.viewpagerindicator.PageIndicator;
import org.solovyev.android.calculator.ActivityUi;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.AppComponent;
import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.wizard.ListWizardFlow;
import org.solovyev.android.wizard.Wizard;
import org.solovyev.android.wizard.WizardFlow;
@ -26,6 +27,7 @@ import org.solovyev.android.wizard.WizardsAware;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
public class WizardActivity extends BaseActivity implements WizardsAware, SharedPreferences.OnSharedPreferenceChangeListener {
@Nonnull
@ -41,6 +43,11 @@ public class WizardActivity extends BaseActivity implements WizardsAware, Shared
@Nullable
private AlertDialog dialog;
@Inject
SharedPreferences preferences;
@Inject
Languages languages;
public WizardActivity() {
super(R.layout.cpp_activity_wizard);
}
@ -76,7 +83,13 @@ public class WizardActivity extends BaseActivity implements WizardsAware, Shared
wizard.saveLastStep(wizardUi.getStep());
}
App.getPreferences().registerOnSharedPreferenceChangeListener(this);
preferences.registerOnSharedPreferenceChangeListener(this);
}
@Override
protected void inject(@Nonnull AppComponent component) {
super.inject(component);
component.inject(this);
}
@Override
@ -181,7 +194,7 @@ public class WizardActivity extends BaseActivity implements WizardsAware, Shared
@Override
protected void onDestroy() {
App.getPreferences().unregisterOnSharedPreferenceChangeListener(this);
preferences.unregisterOnSharedPreferenceChangeListener(this);
dismissDialog();
super.onDestroy();
}
@ -196,9 +209,9 @@ public class WizardActivity extends BaseActivity implements WizardsAware, Shared
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (Preferences.Gui.theme.isSameKey(key)) {
ActivityUi.restartIfThemeChanged(this, ui.getTheme());
restartIfThemeChanged();
} else if (Preferences.Gui.language.isSameKey(key)) {
ActivityUi.restartIfLanguageChanged(this, ui.getLanguage());
restartIfLanguageChanged();
}
}