mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2024-11-23 11:31:33 +01:00
Move SeekBarPreference layout to xml file.
This commit is contained in:
parent
0144b0b02d
commit
b1f6cae789
|
@ -68,65 +68,28 @@ public class SeekBarPreference extends Preference
|
|||
@Override
|
||||
protected View onCreateView(ViewGroup 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.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.setTextSize(12);
|
||||
currValBox.setTypeface(Typeface.MONOSPACE, Typeface.ITALIC);
|
||||
currValBox.setPadding(2, 5, 0, 0);
|
||||
currValBox = layout.findViewById(R.id.seekbar_value);
|
||||
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());
|
||||
row1.setOrientation(LinearLayout.HORIZONTAL);
|
||||
row1.addView(name);
|
||||
row1.addView(currValBox);
|
||||
|
||||
final SeekBar bar = new SeekBar(getContext());
|
||||
final SeekBar bar = layout.findViewById(R.id.seekbar_bar);
|
||||
bar.setMax(maxValue);
|
||||
bar.setProgress(currVal);
|
||||
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();
|
||||
boolean haveSummary = (summaryCharSeq != null) && (summaryCharSeq.length() > 0);
|
||||
TextView summary = null;
|
||||
if (haveSummary) {
|
||||
summary = new TextView(getContext());
|
||||
summary.setText(getSummary());
|
||||
// summary.setTextAppearance(getContext(), android.R.style.TextAppearance_Large);
|
||||
summary.setGravity(Gravity.LEFT);
|
||||
lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
lp.gravity = Gravity.LEFT;
|
||||
lp.weight = 1.0f;
|
||||
summary.setLayoutParams(lp);
|
||||
} else {
|
||||
summary.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
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 -> {
|
||||
View content = View.inflate(SeekBarPreference.this.getContext(), R.layout.select_percentage, null);
|
||||
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>
|
|
@ -9,4 +9,4 @@
|
|||
<item name="colorPrimary">#000000</item>
|
||||
<item name="colorPrimaryDark">#000000</item>
|
||||
</style>
|
||||
</resources>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue
Block a user