Style changes

This commit is contained in:
serso 2016-03-19 23:18:38 +01:00
parent a3d786b191
commit bf420d9bcd
19 changed files with 89 additions and 275 deletions

View File

@ -23,20 +23,17 @@
package org.solovyev.android.calculator;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
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.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.calculator.converter.ConverterFragment;
import org.solovyev.android.calculator.history.History;
import org.solovyev.android.calculator.keyboard.PartialKeyboardUi;
@ -45,9 +42,6 @@ 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;
@ -76,9 +70,6 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
Toolbar toolbar;
@Bind(R.id.editor)
FrameLayout editor;
@Nullable
@Bind(R.id.card)
CardView card;
private boolean useBackAsPrevious;
public CalculatorActivity() {
@ -112,8 +103,7 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
startupHelper.onMainActivityOpened(this);
}
toggleOrientationChange();
prepareCardAndToolbar();
updateOrientation();
preferences.registerOnSharedPreferenceChangeListener(this);
preferredPreferences.check(this, false);
@ -172,11 +162,11 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
}
if (Preferences.Gui.rotateScreen.getKey().equals(key)) {
toggleOrientationChange();
updateOrientation();
}
}
private void toggleOrientationChange() {
private void updateOrientation() {
if (Preferences.Gui.rotateScreen.getPreference(preferences)) {
setRequestedOrientation(SCREEN_ORIENTATION_UNSPECIFIED);
} else {
@ -205,26 +195,4 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
}
return false;
}
private void prepareCardAndToolbar() {
if (card == null) {
return;
}
final Resources resources = getResources();
final int cardTopMargin = resources.getDimensionPixelSize(R.dimen.cpp_card_margin);
final int preLollipopCardTopPadding = Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ? card.getPaddingTop() : 0;
{
final ViewGroup.LayoutParams lp = toolbar.getLayoutParams();
lp.height += cardTopMargin + preLollipopCardTopPadding;
toolbar.setLayoutParams(lp);
// center icons in toolbar
toolbar.setPadding(toolbar.getPaddingLeft(), toolbar.getPaddingTop() + cardTopMargin / 2 + preLollipopCardTopPadding, toolbar.getPaddingRight(), toolbar.getPaddingBottom() + cardTopMargin / 2);
}
final ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) card.getLayoutParams();
final int actionWidth = resources.getDimensionPixelSize(R.dimen.abc_action_button_min_width_overflow_material) + 2 * resources.getDimensionPixelSize(R.dimen.abc_action_bar_overflow_padding_start_material);
lp.leftMargin = actionWidth + 2 * toolbar.getPaddingLeft();
lp.rightMargin = actionWidth + 2 * toolbar.getPaddingRight();
card.setLayoutParams(lp);
}
}

View File

@ -22,17 +22,23 @@
package org.solovyev.android.calculator.wizard;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;
import android.widget.TextView;
import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.keyboard.BaseKeyboardUi;
import org.solovyev.android.views.Adjuster;
import org.solovyev.android.views.dragbutton.DirectionDragButton;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import static org.solovyev.android.calculator.App.cast;
import static org.solovyev.android.calculator.wizard.CalculatorMode.engineer;
import static org.solovyev.android.calculator.wizard.CalculatorMode.simple;
import static org.solovyev.android.views.dragbutton.DragDirection.*;
@ -42,11 +48,20 @@ public class ChooseModeWizardStep extends WizardFragment implements AdapterView.
private DirectionDragButton button;
private TextView description;
@Inject
Typeface typeface;
@Override
protected int getViewResId() {
return R.layout.cpp_wizard_step_choose_mode;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
cast(this).getComponent().inject(this);
}
@Override
public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState);
@ -58,6 +73,8 @@ public class ChooseModeWizardStep extends WizardFragment implements AdapterView.
spinner.setOnItemSelectedListener(this);
button = (DirectionDragButton) root.findViewById(R.id.wizard_mode_button);
BaseActivity.setFont(button, typeface);
Adjuster.adjustText(button, BaseKeyboardUi.getTextScale(getActivity()));
description = (TextView) root.findViewById(R.id.wizard_mode_description);
updateDescription(mode);
}

View File

@ -25,7 +25,6 @@ import javax.annotation.Nullable;
import javax.inject.Inject;
import static org.solovyev.android.calculator.App.cast;
import static org.solovyev.android.calculator.App.toPixels;
public abstract class WizardFragment extends Fragment implements View.OnClickListener {
@ -75,7 +74,7 @@ public abstract class WizardFragment extends Fragment implements View.OnClickLis
final ViewGroup content = (ViewGroup) view.findViewById(R.id.wizard_content);
inflater.inflate(getViewResId(), content, true);
Adjuster.maxWidth(content, toPixels(view, 300));
Adjuster.maxWidth(content, getResources().getDimensionPixelSize(R.dimen.cpp_wizard_max_width));
nextButton = (TextView) view.findViewById(R.id.wizard_next);
if (nextButton != null) {

View File

@ -2,10 +2,7 @@ package org.solovyev.android.views.dragbutton;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.*;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextPaint;
@ -112,14 +109,15 @@ public class DirectionTextView {
if (array.hasValue(direction.textAttr)) {
value = Strings.nullToEmpty(array.getString(direction.textAttr));
}
padding = array.getDimensionPixelSize(direction.paddingAttr, defPadding);
scale = array.getFloat(direction.scaleAttr, defScale);
} else {
value = "";
scale = defScale;
padding = defPadding;
}
alpha = defAlpha;
color = defColor;
padding = defPadding;
initPaint(base);
}
@ -214,12 +212,11 @@ public class DirectionTextView {
final int paddingRight = padding;
final int paddingTop = padding;
final int paddingBottom = padding;
final int verticalPaddings = 0;
switch (direction) {
case up:
case down:
offset.x = -paddingLeft - bounds.width();
offset.x = -paddingLeft - bounds.width() - bounds.left;
if (direction == DragDirection.up) {
offset.y = paddingTop + fixedTextHeight;
} else {
@ -233,7 +230,7 @@ public class DirectionTextView {
} else {
offset.x = -paddingRight - bounds.width();
}
offset.y = paddingTop - verticalPaddings / 2 + fixedTextHeight / 2;
offset.y = (paddingTop - paddingBottom) / 2 + fixedTextHeight / 2;
break;
}
}

View File

@ -6,10 +6,10 @@ import org.solovyev.android.calculator.R;
public enum DragDirection {
up(180f - 45f, 180f - 0f, R.styleable.DirectionText_directionTextUp, R.styleable.DirectionText_directionTextScaleUp),
down(0f, 45f, R.styleable.DirectionText_directionTextDown, R.styleable.DirectionText_directionTextScaleDown),
left(90f - 45f, 90f + 45f, R.styleable.DirectionText_directionTextLeft, R.styleable.DirectionText_directionTextScaleLeft),
right(90f - 45f, 90f + 45f, R.styleable.DirectionText_directionTextRight, R.styleable.DirectionText_directionTextScaleRight);
up(180f - 45f, 180f - 0f, R.styleable.DirectionText_directionTextUp, R.styleable.DirectionText_directionTextScaleUp, R.styleable.DirectionText_directionTextPaddingUp),
down(0f, 45f, R.styleable.DirectionText_directionTextDown, R.styleable.DirectionText_directionTextScaleDown, R.styleable.DirectionText_directionTextPaddingDown),
left(90f - 45f, 90f + 45f, R.styleable.DirectionText_directionTextLeft, R.styleable.DirectionText_directionTextScaleLeft, R.styleable.DirectionText_directionTextPaddingLeft),
right(90f - 45f, 90f + 45f, R.styleable.DirectionText_directionTextRight, R.styleable.DirectionText_directionTextScaleRight, R.styleable.DirectionText_directionTextPaddingRight);
final float angleFrom;
final float angleTo;
@ -17,11 +17,14 @@ public enum DragDirection {
final int textAttr;
@StyleableRes
final int scaleAttr;
@StyleableRes
final int paddingAttr;
DragDirection(float angleFrom, float angleTo, int textAttr, int scaleAttr) {
DragDirection(float angleFrom, float angleTo, @StyleableRes int textAttr, @StyleableRes int scaleAttr, @StyleableRes int paddingAttr) {
this.angleFrom = angleFrom;
this.angleTo = angleTo;
this.textAttr = textAttr;
this.scaleAttr = scaleAttr;
this.paddingAttr = paddingAttr;
}
}

View File

@ -1,79 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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
-->
<LinearLayout
a:id="@+id/main"
style="@style/CppMain"
xmlns:a="http://schemas.android.com/apk/res/android"
a:orientation="vertical">
<FrameLayout
a:layout_width="match_parent"
a:layout_height="0dp"
a:layout_weight="3">
<android.support.v7.widget.Toolbar
a:id="@+id/toolbar"
a:layout_width="match_parent"
a:layout_height="?actionBarSize" />
<android.support.v7.widget.CardView
a:id="@+id/card"
style="?attr/cpp_card_style"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:layout_margin="@dimen/cpp_card_margin">
<LinearLayout
a:layout_width="match_parent"
a:layout_height="match_parent"
a:orientation="vertical">
<FrameLayout
a:id="@+id/editor"
a:layout_width="match_parent"
a:layout_height="0dp"
a:layout_weight="2" />
<View
a:layout_width="match_parent"
a:layout_height="1px"
a:background="?android:attr/listDivider" />
<FrameLayout
a:id="@+id/display"
a:layout_width="match_parent"
a:layout_height="0dp"
a:layout_weight="1" />
</LinearLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
<FrameLayout
a:id="@+id/keyboard"
a:layout_width="match_parent"
a:layout_height="0dp"
a:layout_weight="4" />
</LinearLayout>

View File

@ -1,122 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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
-->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:orientation="vertical">
<LinearLayout
a:layout_width="match_parent"
a:layout_height="0dp"
a:layout_weight="1"
a:baselineAligned="false"
a:orientation="horizontal">
<include layout="@layout/cpp_app_button_left" />
<include layout="@layout/cpp_app_button_erase" />
<include layout="@layout/cpp_app_button_copy" />
<include layout="@layout/cpp_app_button_paste" />
<include layout="@layout/cpp_app_button_donate" />
<include layout="@layout/cpp_app_button_clear" />
<include layout="@layout/cpp_app_button_right" />
</LinearLayout>
<LinearLayout
a:layout_width="match_parent"
a:layout_height="0dp"
a:layout_weight="1"
a:baselineAligned="false"
a:orientation="horizontal">
<include layout="@layout/cpp_app_button_vars" />
<include layout="@layout/cpp_app_button_7" />
<include layout="@layout/cpp_app_button_8" />
<include layout="@layout/cpp_app_button_9" />
<include layout="@layout/cpp_app_button_multiplication" />
<include layout="@layout/cpp_app_button_division" />
<include layout="@layout/cpp_app_button_equals" />
</LinearLayout>
<LinearLayout
a:layout_width="match_parent"
a:layout_height="0dp"
a:layout_weight="1"
a:baselineAligned="false"
a:orientation="horizontal">
<include layout="@layout/cpp_app_button_functions" />
<include layout="@layout/cpp_app_button_4" />
<include layout="@layout/cpp_app_button_5" />
<include layout="@layout/cpp_app_button_6" />
<include layout="@layout/cpp_app_button_plus" />
<include layout="@layout/cpp_app_button_minus" />
<include layout="@layout/cpp_app_button_round_brackets" />
</LinearLayout>
<LinearLayout
a:layout_width="match_parent"
a:layout_height="0dp"
a:layout_weight="1"
a:baselineAligned="false"
a:orientation="horizontal">
<include layout="@layout/cpp_app_button_operators" />
<include layout="@layout/cpp_app_button_1" />
<include layout="@layout/cpp_app_button_2" />
<include layout="@layout/cpp_app_button_3" />
<include layout="@layout/cpp_app_button_0" />
<include layout="@layout/cpp_app_button_dot" />
<include layout="@layout/cpp_app_button_history" />
</LinearLayout>
</LinearLayout>

View File

@ -28,6 +28,7 @@
xmlns:tools="http://schemas.android.com/tools"
a:id="@id/cpp_button_period"
style="?attr/cpp_button_style_digit"
c:directionTextScale="0.6"
a:text="."
c:directionTextUp=","
tools:ignore="HardcodedText" />

View File

@ -30,6 +30,7 @@
a:background="@drawable/button_no_bg"
a:text="="
a:textColor="?attr/cpp_text_color"
c:directionTextColor="?attr/cpp_text_color"
c:directionTextDown="@string/cpp_plot_button_text"
c:directionTextUp="≡"
tools:ignore="HardcodedText" />

View File

@ -27,5 +27,6 @@
a:id="@id/cpp_button_history"
style="?attr/cpp_button_style_control"
a:src="@drawable/ic_history_white_48dp"
app:directionTextScale="0.5"
app:directionTextDown="@string/cpp_kb_redo"
app:directionTextUp="@string/cpp_kb_undo" />

View File

@ -25,5 +25,6 @@
<org.solovyev.android.calculator.DisplayView
android:id="@+id/calculator_display"
style="@style/CppText.Display"
xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="@dimen/cpp_display_padding" />
android:paddingLeft="@dimen/cpp_display_padding_side"
android:paddingRight="@dimen/cpp_display_padding_side"
xmlns:android="http://schemas.android.com/apk/res/android"/>

View File

@ -59,8 +59,8 @@
<org.solovyev.android.views.dragbutton.DirectionDragButton
a:id="@+id/wizard_mode_button"
style="?attr/cpp_button_style_operation"
a:layout_width="100dp"
a:layout_height="100dp"
a:layout_width="@dimen/cpp_wizard_preview_button_size"
a:layout_height="@dimen/cpp_wizard_preview_button_size"
a:text="7" />
</FrameLayout>

View File

@ -27,14 +27,14 @@
a:layout_width="wrap_content"
a:layout_height="wrap_content"
a:background="?attr/cpp_editor_bg"
a:minWidth="200dp"
a:minWidth="@dimen/cpp_wizard_preview_width"
a:orientation="vertical"
a:padding="3dp"
tools:ignore="Overdraw">
<LinearLayout
a:layout_width="match_parent"
a:layout_height="60dp"
a:layout_height="@dimen/cpp_wizard_preview_row_height"
a:orientation="horizontal">
<include layout="@layout/cpp_app_button_equals_no_bg" />
@ -51,27 +51,27 @@
<LinearLayout
a:layout_width="match_parent"
a:layout_height="60dp"
a:layout_height="@dimen/cpp_wizard_preview_row_height"
a:orientation="horizontal">
<include layout="@layout/cpp_app_button_0" />
<include layout="@layout/cpp_app_button_copy" />
<include layout="@layout/cpp_app_button_1" />
<include layout="@layout/cpp_app_button_plus" />
<include layout="@layout/cpp_app_button_clear" />
</LinearLayout>
<LinearLayout
a:layout_width="match_parent"
a:layout_height="60dp"
a:layout_height="@dimen/cpp_wizard_preview_row_height"
a:orientation="horizontal">
<include layout="@layout/cpp_app_button_1" />
<include layout="@layout/cpp_app_button_paste" />
<include layout="@layout/cpp_app_button_0" />
<include layout="@layout/cpp_app_button_minus" />
<include layout="@layout/cpp_app_button_memory" />
</LinearLayout>
</LinearLayout>

View File

@ -45,13 +45,11 @@
<org.solovyev.android.views.dragbutton.DirectionDragButton
a:id="@+id/wizard_dragbutton"
style="?attr/cpp_button_style_operation"
a:layout_width="wrap_content"
a:layout_height="wrap_content"
a:layout_width="@dimen/cpp_wizard_preview_button_size"
a:layout_height="@dimen/cpp_wizard_preview_button_size"
a:layout_weight="0"
a:layout_gravity="center"
a:layout_margin="0dp"
a:layout_weight="0"
a:minHeight="100dp"
a:minWidth="100dp"
a:text="9"
c:directionTextDown="^2"
c:directionTextUp="%" />

View File

@ -24,5 +24,6 @@
<dimen name="cpp_min_editor_text_size">18sp</dimen>
<dimen name="cpp_display_text_size">20sp</dimen>
<dimen name="cpp_clickable_area_size">40dp</dimen>
<dimen name="cpp_keyboard_button_direction_text_padding">1dp</dimen>
<dimen name="cpp_keyboard_button_direction_text_padding_updown">1dp</dimen>
<dimen name="cpp_keyboard_button_direction_text_padding_left">1dp</dimen>
</resources>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="cpp_keyboard_button_direction_text_padding_updown">16dp</dimen>
<dimen name="cpp_keyboard_button_direction_text_padding_left">16dp</dimen>
<dimen name="cpp_display_padding_side">16dp</dimen>
<dimen name="cpp_wizard_preview_width">400dp</dimen>
<dimen name="cpp_wizard_preview_row_height">133dp</dimen>
<dimen name="cpp_wizard_max_width">400dp</dimen>
<dimen name="cpp_wizard_preview_button_size">150dp</dimen>
</resources>

View File

@ -13,7 +13,8 @@
<item name="cpp_direction_text_scale_units" format="float" type="dimen">0.3</item>
<dimen name="cpp_button_corner">1dp</dimen>
<dimen name="cpp_keyboard_button_direction_text_padding">4dp</dimen>
<dimen name="cpp_keyboard_button_direction_text_padding_updown">4dp</dimen>
<dimen name="cpp_keyboard_button_direction_text_padding_left">2dp</dimen>
<dimen name="cpp_keyboard_button_text_size">30dp</dimen>
<dimen name="cpp_keyboard_simple_image_button_padding">12dp</dimen>
@ -27,6 +28,7 @@
<!--only for not multipane-->
<dimen name="cpp_editor_padding">5dp</dimen>
<dimen name="cpp_display_padding">3dp</dimen>
<dimen name="cpp_display_padding_side">10dp</dimen>
<dimen name="cpp_widget_keyboard_button_text_size">20dp</dimen>
@ -46,4 +48,8 @@
<dimen name="cpp_card_margin">4dp</dimen>
<dimen name="list_item_height">48dp</dimen>
<dimen name="cpp_wizard_preview_width">200dp</dimen>
<dimen name="cpp_wizard_preview_row_height">64dp</dimen>
<dimen name="cpp_wizard_max_width">300dp</dimen>
<dimen name="cpp_wizard_preview_button_size">100dp</dimen>
</resources>

View File

@ -9,6 +9,10 @@
<attr name="directionTextLeft" format="string"/>
<attr name="directionTextScale" format="float"/>
<attr name="directionTextPadding" format="dimension"/>
<attr name="directionTextPaddingUp" format="dimension"/>
<attr name="directionTextPaddingDown" format="dimension"/>
<attr name="directionTextPaddingRight" format="dimension"/>
<attr name="directionTextPaddingLeft" format="dimension"/>
<attr name="directionTextScaleUp" format="float"/>
<attr name="directionTextScaleDown" format="float"/>
<attr name="directionTextScaleRight" format="float"/>

View File

@ -36,7 +36,10 @@
<item name="android:scaleType">centerInside</item>
<item name="directionTextColor">@color/cpp_button_text</item>
<item name="directionTextScale">@dimen/cpp_direction_text_scale</item>
<item name="directionTextPadding">@dimen/cpp_keyboard_button_direction_text_padding</item>
<item name="directionTextPaddingUp">@dimen/cpp_keyboard_button_direction_text_padding_updown</item>
<item name="directionTextPaddingDown">@dimen/cpp_keyboard_button_direction_text_padding_updown</item>
<item name="directionTextPaddingRight">@dimen/cpp_keyboard_button_direction_text_padding_updown</item>
<item name="directionTextPaddingLeft">@dimen/cpp_keyboard_button_direction_text_padding_left</item>
</style>
<style name="CppText.Editor.Onscreen.Light" parent="CppText.Editor.Onscreen">
@ -75,6 +78,10 @@
<item name="android:textSize">@dimen/cpp_display_text_size</item>
<item name="android:scrollHorizontally">false</item>
<item name="android:scrollbars">none</item>
<item name="android:paddingRight">@dimen/cpp_display_padding</item>
<item name="android:paddingLeft">@dimen/cpp_display_padding</item>
<item name="android:paddingTop">@dimen/cpp_display_padding</item>
<item name="android:paddingBottom">@dimen/cpp_display_padding</item>
</style>
<style name="CppImageButton">