Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text size and brightness preferences to show a preview under seek bar #1522

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;

Expand All @@ -31,6 +32,8 @@ public class SeekBarPreference extends Preference implements SeekBar.OnSeekBarCh
private Context mContext;
private SeekBar mSeekBar;
private TextView mValueText;
protected TextView mPreviewText;
protected TextView mArabicPreviewText;

private String mSuffix;
private int mTintColor;
Expand All @@ -53,13 +56,24 @@ public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
mSeekBar = (SeekBar) holder.findViewById(R.id.seekbar);
mValueText = (TextView) holder.findViewById(R.id.value);
mPreviewText = (TextView) holder.findViewById(R.id.pref_preview);
mPreviewText.setVisibility(getPreviewVisibility());
mArabicPreviewText = (TextView) holder.findViewById(R.id.arabic_preview);
mArabicPreviewText.setVisibility(getPreviewVisibility());
mSeekBar.setOnSeekBarChangeListener(this);
styleSeekBar();
mValue = shouldPersist() ? getPersistedInt(mDefault) : 0;
mSeekBar.setMax(mMax);
mSeekBar.setProgress(mValue);
}

/**
* Visibility of the preview view under the seek bar
*/
protected int getPreviewVisibility() {
return View.GONE;
}

private void styleSeekBar() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
final Drawable progressDrawable = mSeekBar.getProgressDrawable();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.quran.labs.androidquran.ui.preference

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.View
import android.widget.SeekBar

class SeekBarTextBrightnessPreference(context: Context?, attrs: AttributeSet?) : SeekBarPreference(context, attrs) {

override fun getPreviewVisibility(): Int = View.VISIBLE

override fun onProgressChanged(seek: SeekBar, value: Int, fromTouch: Boolean) {
super.onProgressChanged(seek, value, fromTouch)
val lineColor = Color.argb(value, 255, 255, 255)
mPreviewText.setTextColor(lineColor)
mArabicPreviewText.setTextColor(lineColor)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.quran.labs.androidquran.ui.preference

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.SeekBar

class SeekBarTextSizePreference(context: Context?, attrs: AttributeSet?) : SeekBarPreference(context, attrs) {

override fun getPreviewVisibility(): Int = View.VISIBLE

override fun onProgressChanged(seek: SeekBar, value: Int, fromTouch: Boolean) {
super.onProgressChanged(seek, value, fromTouch)
mPreviewText.textSize = value.toFloat()
mArabicPreviewText.textSize = value.toFloat() * com.quran.labs.androidquran.ui.translation.TranslationAdapter.ARABIC_MULTIPLIER
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ internal class TranslationAdapter(private val context: Context,

companion object {
private val USE_UTHMANI_SPAN = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
private const val ARABIC_MULTIPLIER = 1.4f
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making this public so SeekBarTextSizePreference can show an accurate preview of arabic text size

const val ARABIC_MULTIPLIER = 1.4f
private const val MAX_TAFSEER_LENGTH = 750
private const val HIGHLIGHT_CHANGE = 1
}
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/res/layout-v21/seekbar_pref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@
/>
</LinearLayout>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding these 2 text views under the seekbar, one for arabic and one for the translated language.
They are hidden by default in SeekBarPreference.java and the overriding classes opt in to show them and do something with them (i.e apply text size or brightness on them).

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/pref_preview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/prefs_preview"
android:gravity="center"
android:layout_weight="1"/>

<TextView
android:id="@+id/arabic_preview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="معاينة"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be @string/prefs_preview and we should add to values-ar/strings.xml

Copy link
Contributor

@ahmedre ahmedre Jan 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh - i see why now - will just show one depending on the language

android:gravity="center"
android:layout_weight="1"/>

</LinearLayout>

<LinearLayout
android:id="@android:id/widget_frame"
android:layout_width="wrap_content"
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/res/layout/seekbar_pref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@
/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/pref_preview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/prefs_preview"
android:gravity="center"
android:layout_weight="1"/>

<TextView
android:id="@+id/arabic_preview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="معاينة"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

android:gravity="center"
android:layout_weight="1"/>

</LinearLayout>

<LinearLayout
android:id="@android:id/widget_frame"
android:layout_width="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
<string name="prefs_page_type_summary">Select the type of reading pages</string>
<string name="prefs_sura_translated_name_summary">Show sura translated name</string>
<string name="prefs_sura_translated_name_title">Sura translated name</string>
<string name="prefs_preview">Preview</string>

<string name="translations" translatable="false">@string/prefs_translations</string>
<string name="more_translations">More Translations</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/xml/quran_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
android:title="@string/prefs_night_mode_title"
app:iconSpaceReserved="false"/>

<com.quran.labs.androidquran.ui.preference.SeekBarPreference
<com.quran.labs.androidquran.ui.preference.SeekBarTextBrightnessPreference
android:defaultValue="255"
android:dependency="@string/prefs_night_mode"
android:key="@string/prefs_night_mode_text_brightness"
Expand Down Expand Up @@ -154,7 +154,7 @@
android:title="@string/prefs_ayah_before_translation_title"
app:iconSpaceReserved="false"/>

<com.quran.labs.androidquran.ui.preference.SeekBarPreference
<com.quran.labs.androidquran.ui.preference.SeekBarTextSizePreference
android:defaultValue="15"
android:key="@string/prefs_translation_text_size"
android:max="40"
Expand Down