0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 12:02:16 +02:00

Merge pull request #880 from timrae/cleaner-night-mode

Clean up the night mode code using themes
This commit is contained in:
Tim Rae 2015-06-30 20:14:15 +09:00
commit 0dd3fd70b5
4 changed files with 25 additions and 92 deletions

View File

@ -30,7 +30,6 @@ import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
@ -185,7 +184,6 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
protected boolean mDisableClipboard = false;
protected boolean mInvertedColors = false;
protected boolean mNightMode = false;
private int mCurrentBackgroundColor;
private boolean mPrefSafeDisplay;
protected boolean mPrefUseTimer;
private boolean mPrefCenterVertically;
@ -247,11 +245,6 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
protected Card mCurrentCard;
private int mCurrentEase;
private int mNextTimeTextColor;
private int mNextTimeTextRecomColor;
private int mForegroundColor;
private int mButtonHeight = 0;
private boolean mConfigurationChanged = false;
@ -354,25 +347,6 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
}
};
private View.OnClickListener mCardStatisticsListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
Timber.i("AbstractFlashcardViewer:: Show card statistics");
stopTimer();
// Themes.htmlOkDialog(AbstractReviewer.this, getResources().getString(R.string.card_browser_card_details),
// mCurrentCard.getCardDetails(AbstractReviewer.this, false), new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog, int which) {
// restartTimer();
// }
// }, new OnCancelListener() {
// @Override
// public void onCancel(DialogInterface arg0) {
// restartTimer();
// }
// }).show();
}
};
// Handler for the "show answer" button
private View.OnClickListener mFlipCardListener = new View.OnClickListener() {
@ -847,7 +821,6 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
@Override
public void run() {
mChosenAnswer.setText("");
setDueMessage();
}
};
@ -911,12 +884,6 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
registerExternalStorageListener();
if (mNightMode) {
mCurrentBackgroundColor = Color.BLACK;
} else {
mCurrentBackgroundColor = Color.WHITE;
}
mUseQuickUpdate = shouldUseQuickUpdate();
initLayout();
@ -1357,15 +1324,9 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
// Set the content view to the one provided and initialize accessors.
protected void initLayout() {
mMainLayout = findViewById(R.id.main_layout);
(mMainLayout.findViewById(R.id.flashcard_frame)).setBackgroundResource(AnkiDroidApp
.getSharedPrefs(mMainLayout.getContext()).getBoolean("invertedColors", false) ? R.color.black
: R.color.white);
mCardContainer = (FrameLayout) findViewById(R.id.flashcard_frame);
mTopBarLayout = (RelativeLayout) findViewById(R.id.top_bar);
mTopBarLayout.setOnClickListener(mCardStatisticsListener);
mCardFrame = (FrameLayout) findViewById(R.id.flashcard);
mTouchLayer = (FrameLayout) findViewById(R.id.touch_layer);
mTouchLayer.setOnTouchListener(mGestureListener);
@ -1445,13 +1406,6 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
mAnswerField = (EditText) findViewById(R.id.answer_field);
mNextTimeTextColor = getResources().getColor(R.color.next_time_usual_color);
mNextTimeTextRecomColor = getResources().getColor(R.color.next_time_recommended_color);
mForegroundColor = getResources().getColor(R.color.next_time_usual_color);
if (mInvertedColors) {
setNightModeColors();
}
mLookUpIcon = findViewById(R.id.lookup_button);
mLookUpIcon.setVisibility(View.GONE);
mLookUpIcon.setOnClickListener(new OnClickListener() {
@ -1528,31 +1482,6 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
}
private void setNightModeColors() {
Resources res = getResources();
mMainLayout.setBackgroundColor(res.getColor(R.color.black));
refreshActionBar();
mForegroundColor = Color.WHITE;
mNextTimeTextColor = mForegroundColor;
mNextTimeTextRecomColor = res.getColor(R.color.next_time_recommended_color_inv);
mFlipCard.setTextColor(mForegroundColor);
mEase4.setTextColor(mNextTimeTextColor);
mCardTimer.setTextColor(mForegroundColor);
mTopBarLayout .setBackgroundColor(res.getColor(R.color.theme_primary_light_inv));
mTextBarNew.setTextColor(res.getColor(R.color.new_count_night));
mTextBarLearn
.setTextColor(res.getColor(R.color.learn_count_night));
mTextBarReview.setTextColor(res.getColor(R.color.review_count_night));
mAnswerField.setTextColor(mForegroundColor);
if (mCard != null) {
mCard.setBackgroundColor(mCurrentBackgroundColor);
}
}
protected void showEaseButtons() {
Resources res = getResources();
@ -1746,7 +1675,6 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
mNextCard = createWebView();
mNextCard.setVisibility(View.GONE);
mCardFrame.addView(mNextCard, 0);
mCard.setBackgroundColor(mCurrentBackgroundColor);
}
}
if (mCard.getVisibility() != View.VISIBLE) {
@ -1755,16 +1683,6 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
}
private void setDueMessage() {
// Decks deck = DeckManager.getMainDeck();
// if (mCurrentCard != null && deck != null && deck.getScheduler().equals("reviewEarly") &&
// mCurrentCard.getType() != Card.TYPE_FAILED) {
// mChosenAnswer.setTextColor(mForegroundColor);
// mChosenAnswer.setText(Utils.fmtTimeSpan(mCurrentCard.getCombinedDue() - Utils.now(), Utils.TIME_FORMAT_IN));
// }
}
private void updateForNewCard() {
updateScreenCounts();
@ -2219,7 +2137,6 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
Timber.d("fillFlashcard()");
Timber.d("base url = %s", mBaseUrl);
if (!mUseQuickUpdate && mCard != null && mNextCard != null) {
mNextCard.setBackgroundColor(mCurrentBackgroundColor);
mNextCard.loadDataWithBaseURL(mBaseUrl + "__viewer__.html", mCardContent.toString(), "text/html", "utf-8", null);
mNextCard.setVisibility(View.VISIBLE);
mCardFrame.removeView(mCard);
@ -2234,7 +2151,6 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
}
} else if (mCard != null) {
mCard.loadDataWithBaseURL(mBaseUrl + "__viewer__.html", mCardContent.toString(), "text/html", "utf-8", null);
mCard.setBackgroundColor(mCurrentBackgroundColor);
}
if (mShowTimer && mCardTimer.getVisibility() == View.INVISIBLE) {
switchTopBarVisibility(View.VISIBLE);

View File

@ -23,7 +23,6 @@
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/colorBackground"
android:fitsSystemWindows="true">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/root_layout"
@ -47,7 +46,7 @@
android:paddingTop="2dp"
android:paddingBottom="3dp"
android:gravity="center_vertical"
android:background="@color/theme_primary_light"
android:background="?attr/topBarColor"
android:layout_below="@+id/toolbar">
<TextView
@ -55,7 +54,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/new_count"
android:textColor="?attr/newCountColor"
android:textSize="14sp" />
<TextView
@ -65,7 +64,7 @@
android:layout_toRightOf="@+id/new_number"
android:paddingLeft="8dp"
android:text=""
android:textColor="@color/learn_count"
android:textColor="?attr/learnCountColor"
android:textSize="14sp" />
<TextView
@ -75,7 +74,7 @@
android:layout_toRightOf="@+id/learn_number"
android:paddingLeft="8dp"
android:text=""
android:textColor="@color/review_count"
android:textColor="?attr/reviewCountColor"
android:textSize="14sp" />
<TextView
@ -93,7 +92,7 @@
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="center"
android:textColor="#000000"
android:textColor="?attr/timerColor"
android:textSize="14sp"
android:visibility="invisible" />
</RelativeLayout>
@ -178,7 +177,7 @@
<LinearLayout
android:id="@+id/answer_options_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/flashcard_layout_flip"

View File

@ -30,4 +30,10 @@
<attr name="interval" format="integer" />
</declare-styleable>
<!-- Reviewer colors -->
<attr name="topBarColor" format="color"/>
<attr name="newCountColor" format="color"/>
<attr name="learnCountColor" format="color"/>
<attr name="reviewCountColor" format="color"/>
<attr name="timerColor" format="color"/>
</resources>

View File

@ -7,6 +7,12 @@
<style name="Theme_Dark" parent="Theme_White">
<item name="colorPrimary">@color/white_background_night</item>
<item name="colorPrimaryDark">@color/black</item>
<!-- Reviewer colors -->
<item name="topBarColor">@color/theme_primary_light_inv</item>
<item name="newCountColor">@color/new_count_night</item>
<item name="learnCountColor">@color/learn_count_night</item>
<item name="reviewCountColor">@color/review_count_night</item>
<item name="timerColor">@color/white</item>
</style>
<!-- White theme -->
@ -25,9 +31,15 @@
<item name="windowActionModeOverlay">true</item>
<item name="actionModeBackground">@color/theme_accent</item>
<!-- Dialog styles -->
<item name="android:listPreferredItemHeight">56dip</item>
<!-- Reviewer colors -->
<item name="topBarColor">@color/theme_primary_light</item>
<item name="newCountColor">@color/new_count</item>
<item name="learnCountColor">@color/learn_count</item>
<item name="reviewCountColor">@color/review_count</item>
<item name="timerColor">@color/black</item>
</style>
<style name="Theme_White_Statistics" parent="@style/App_Theme">