mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-04-26 22:05:41 +02:00
Move SeekBarPreference layout to xml file.
This commit is contained in:
parent
0144b0b02d
commit
b1f6cae789
DroidFishApp/src/main
@ -68,65 +68,28 @@ public class SeekBarPreference extends Preference
|
|||||||
@Override
|
@Override
|
||||||
protected View onCreateView(ViewGroup parent) {
|
protected View onCreateView(ViewGroup parent) {
|
||||||
super.onCreateView(parent);
|
super.onCreateView(parent);
|
||||||
TextView name = new TextView(getContext());
|
|
||||||
|
LinearLayout layout = (LinearLayout)View.inflate(getContext(), R.layout.seekbar_preference, null);
|
||||||
|
TextView name = layout.findViewById(R.id.seekbar_title);
|
||||||
name.setText(getTitle());
|
name.setText(getTitle());
|
||||||
name.setTextAppearance(getContext(), android.R.style.TextAppearance_Large);
|
|
||||||
name.setGravity(Gravity.LEFT);
|
|
||||||
LinearLayout.LayoutParams lp =
|
|
||||||
new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
|
|
||||||
LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
||||||
lp.gravity = Gravity.LEFT;
|
|
||||||
lp.weight = 1.0f;
|
|
||||||
name.setLayoutParams(lp);
|
|
||||||
|
|
||||||
currValBox = new TextView(getContext());
|
currValBox = layout.findViewById(R.id.seekbar_value);
|
||||||
currValBox.setTextSize(12);
|
|
||||||
currValBox.setTypeface(Typeface.MONOSPACE, Typeface.ITALIC);
|
|
||||||
currValBox.setPadding(2, 5, 0, 0);
|
|
||||||
currValBox.setText(valToString());
|
currValBox.setText(valToString());
|
||||||
lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
|
|
||||||
LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
||||||
lp.gravity = Gravity.CENTER;
|
|
||||||
currValBox.setLayoutParams(lp);
|
|
||||||
|
|
||||||
LinearLayout row1 = new LinearLayout(getContext());
|
final SeekBar bar = layout.findViewById(R.id.seekbar_bar);
|
||||||
row1.setOrientation(LinearLayout.HORIZONTAL);
|
|
||||||
row1.addView(name);
|
|
||||||
row1.addView(currValBox);
|
|
||||||
|
|
||||||
final SeekBar bar = new SeekBar(getContext());
|
|
||||||
bar.setMax(maxValue);
|
bar.setMax(maxValue);
|
||||||
bar.setProgress(currVal);
|
bar.setProgress(currVal);
|
||||||
bar.setOnSeekBarChangeListener(this);
|
bar.setOnSeekBarChangeListener(this);
|
||||||
lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
|
|
||||||
LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
||||||
lp.gravity = Gravity.RIGHT;
|
|
||||||
bar.setLayoutParams(lp);
|
|
||||||
|
|
||||||
|
TextView summary = layout.findViewById(R.id.seekbar_summary);
|
||||||
CharSequence summaryCharSeq = getSummary();
|
CharSequence summaryCharSeq = getSummary();
|
||||||
boolean haveSummary = (summaryCharSeq != null) && (summaryCharSeq.length() > 0);
|
boolean haveSummary = (summaryCharSeq != null) && (summaryCharSeq.length() > 0);
|
||||||
TextView summary = null;
|
|
||||||
if (haveSummary) {
|
if (haveSummary) {
|
||||||
summary = new TextView(getContext());
|
|
||||||
summary.setText(getSummary());
|
summary.setText(getSummary());
|
||||||
// summary.setTextAppearance(getContext(), android.R.style.TextAppearance_Large);
|
} else {
|
||||||
summary.setGravity(Gravity.LEFT);
|
summary.setVisibility(View.GONE);
|
||||||
lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
|
|
||||||
LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
||||||
lp.gravity = Gravity.LEFT;
|
|
||||||
lp.weight = 1.0f;
|
|
||||||
summary.setLayoutParams(lp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LinearLayout layout = new LinearLayout(getContext());
|
|
||||||
layout.setPadding(25, 5, 25, 5);
|
|
||||||
layout.setOrientation(LinearLayout.VERTICAL);
|
|
||||||
layout.addView(row1);
|
|
||||||
layout.addView(bar);
|
|
||||||
if (summary != null)
|
|
||||||
layout.addView(summary);
|
|
||||||
layout.setId(android.R.id.widget_frame);
|
|
||||||
|
|
||||||
currValBox.setOnClickListener(v -> {
|
currValBox.setOnClickListener(v -> {
|
||||||
View content = View.inflate(SeekBarPreference.this.getContext(), R.layout.select_percentage, null);
|
View content = View.inflate(SeekBarPreference.this.getContext(), R.layout.select_percentage, null);
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(SeekBarPreference.this.getContext());
|
final AlertDialog.Builder builder = new AlertDialog.Builder(SeekBarPreference.this.getContext());
|
||||||
|
51
DroidFishApp/src/main/res/layout/seekbar_preference.xml
Normal file
51
DroidFishApp/src/main/res/layout/seekbar_preference.xml
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@android:id/widget_frame"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingLeft="16dp"
|
||||||
|
android:paddingRight="5dp"
|
||||||
|
android:paddingTop="20dp"
|
||||||
|
android:paddingBottom="10dp">
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/seekbar_title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="15dp"
|
||||||
|
android:textColor="@color/White"
|
||||||
|
android:text="">
|
||||||
|
</TextView>
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="right">
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/seekbar_value"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:typeface="monospace"
|
||||||
|
android:textStyle="italic"
|
||||||
|
android:textSize="12dp"
|
||||||
|
android:text="">
|
||||||
|
</TextView>
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
<SeekBar
|
||||||
|
android:id="@+id/seekbar_bar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
</SeekBar>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/seekbar_summary"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:text="">
|
||||||
|
</TextView>
|
||||||
|
</LinearLayout>
|
Loading…
x
Reference in New Issue
Block a user