-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e40142
commit 22460a5
Showing
6 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/visualeditor/FontSelectionDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
Copyright (c) 2021 Akshay Jadhav <[email protected]> | ||
This program is free software; you can redistribute it and/or modify it under | ||
the terms of the GNU General Public License as published by the Free Software | ||
Foundation; either version 3 of the License, or (at your option) any later | ||
version. | ||
This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License along with | ||
this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.ichi2.anki.multimediacard.visualeditor; | ||
|
||
import android.content.Context; | ||
import android.os.Build; | ||
import android.view.Gravity; | ||
import android.widget.LinearLayout; | ||
import android.widget.SeekBar; | ||
|
||
import com.afollestad.materialdialogs.MaterialDialog; | ||
import com.ichi2.anki.R; | ||
import com.ichi2.ui.FixedTextView; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
public class FontSelectionDialog { | ||
|
||
private final Context mContext; | ||
private Integer mFontSize; | ||
private FixedTextView mFontSizeText; | ||
public @Nullable | ||
Consumer<Integer> mOnFontSizeChanged; | ||
|
||
|
||
public FontSelectionDialog(@NonNull Context context, @NonNull int fontSize) { | ||
this.mContext = context; | ||
this.mFontSize = fontSize; | ||
} | ||
|
||
|
||
public final SeekBar.OnSeekBarChangeListener seekBarChangeListener = new SeekBar.OnSeekBarChangeListener() { | ||
@Override | ||
public void onProgressChanged(SeekBar seekBar, int value, boolean b) { | ||
mFontSize = value; | ||
mFontSizeText.setText("" + value); | ||
} | ||
|
||
@Override | ||
public void onStartTrackingTouch(SeekBar seekBar) { | ||
// intentionally blank | ||
} | ||
|
||
|
||
@Override | ||
public void onStopTrackingTouch(SeekBar seekBar) { | ||
// intentionally blank | ||
} | ||
}; | ||
|
||
public void showFontSelectionDialog() { | ||
LinearLayout layout = new LinearLayout(mContext); | ||
layout.setOrientation(LinearLayout.VERTICAL); | ||
layout.setPadding(6, 6, 6, 6); | ||
|
||
mFontSizeText = new FixedTextView(mContext); | ||
mFontSizeText.setGravity(Gravity.CENTER_HORIZONTAL); | ||
mFontSizeText.setTextSize(30); | ||
mFontSizeText.setText("" + mFontSize); | ||
|
||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | ||
|
||
layout.addView(mFontSizeText, params); | ||
|
||
SeekBar seekBar = new SeekBar(mContext); | ||
seekBar.setProgress(mFontSize); | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
seekBar.setMin(15); | ||
} | ||
seekBar.setMax(60); | ||
|
||
seekBar.setOnSeekBarChangeListener(seekBarChangeListener); | ||
|
||
layout.addView(seekBar, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, | ||
LinearLayout.LayoutParams.WRAP_CONTENT)); | ||
|
||
new MaterialDialog.Builder(mContext) | ||
.title(R.string.visual_editor_font_size) | ||
.positiveText(R.string.save) | ||
.negativeText(R.string.dialog_cancel) | ||
.customView(layout, true) | ||
.onPositive((dialog, which) -> { | ||
if (mOnFontSizeChanged != null) { | ||
mOnFontSizeChanged.accept(mFontSize); | ||
} | ||
}) | ||
.show(); | ||
} | ||
|
||
public void setOnFontSizeChanged(Consumer<Integer> c) { | ||
this.mOnFontSizeChanged = c; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters