mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-02-23 15:38:29 +01:00
ListPreferences popup issue almost fixed.
This commit is contained in:
@@ -11,6 +11,13 @@
|
||||
android:state_pressed="true"
|
||||
android:state_enabled="true"
|
||||
/>
|
||||
|
||||
<item
|
||||
android:drawable="@drawable/ui_blue_radiobutton_enabled_checked"
|
||||
android:state_selected="true"
|
||||
android:state_enabled="true"
|
||||
/>
|
||||
|
||||
|
||||
<!-- <item
|
||||
android:drawable="@drawable/ui_blue_radiobutton_disabled_unchecked"
|
||||
|
||||
7
AndorsTrail/res/layout/custom_checkedlistitem_layout.xml
Normal file
7
AndorsTrail/res/layout/custom_checkedlistitem_layout.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@android:id/text1"
|
||||
style="@style/checkedListItem"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableRight="@drawable/ui_blue_radiobutton" />
|
||||
@@ -165,6 +165,7 @@
|
||||
<item name="android:textSize">14sp</item>
|
||||
</style>
|
||||
|
||||
|
||||
<!-- <style name="AndorsTrail_Blue_TabWidget" parent="android:style/Widget.TabWidget">
|
||||
<item name="android:textColor">@color/ui_blue_textbutton_textcolor</item>
|
||||
<item name="android:background">@drawable/ui_blue_tabwidget</item>
|
||||
@@ -222,6 +223,11 @@
|
||||
<item name="android:textColor">@color/ui_blue_textbutton_textcolor</item>
|
||||
</style>
|
||||
|
||||
<style name="checkedListItem" parent="android:style/Widget.TextView">
|
||||
<item name="android:textColor">@color/ui_blue_textbutton_textcolor</item>
|
||||
<item name="android:textSize">@dimen/titletext</item>
|
||||
</style>
|
||||
|
||||
<style name="statsBoxStyle" parent="android:Widget.TextView">
|
||||
<item name="android:background">@drawable/ui_blue_richframe</item>
|
||||
<item name="android:drawablePadding">@dimen/boxshape_margin</item>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
android:defaultValue="true"
|
||||
android:summary="@string/preferences_display_fullscreen"
|
||||
android:key="fullscreen" />
|
||||
<ListPreference
|
||||
<com.gpl.rpg.AndorsTrail.view.CustomListPreference
|
||||
android:title="@string/preferences_display_scaling_factor_title"
|
||||
android:summary="@string/preferences_display_scaling_factor"
|
||||
android:key="scaling_factor"
|
||||
@@ -32,14 +32,14 @@
|
||||
android:defaultValue="true"
|
||||
android:summary="@string/preferences_dialog_confirmattack"
|
||||
android:key="confirm_attack" />
|
||||
<ListPreference
|
||||
<com.gpl.rpg.AndorsTrail.view.CustomListPreference
|
||||
android:title="@string/preferences_dialog_monsterloot_title"
|
||||
android:summary="@string/preferences_dialog_monsterloot"
|
||||
android:key="display_lootdialog"
|
||||
android:defaultValue="0"
|
||||
android:entries="@array/preferences_display_loot"
|
||||
android:entryValues="@array/preferences_display_loot_values" />
|
||||
<ListPreference
|
||||
<com.gpl.rpg.AndorsTrail.view.CustomListPreference
|
||||
android:title="@string/preferences_dialog_overwrite_savegame_title"
|
||||
android:summary="@string/preferences_dialog_overwrite_savegame"
|
||||
android:key="display_overwrite_savegame"
|
||||
@@ -49,7 +49,7 @@
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:title="@string/preferences_combat_category">
|
||||
<ListPreference
|
||||
<com.gpl.rpg.AndorsTrail.view.CustomListPreference
|
||||
android:title="@string/preferences_combat_speed_title"
|
||||
android:summary="@string/preferences_combat_speed"
|
||||
android:key="attackspeed"
|
||||
@@ -59,14 +59,14 @@
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:title="@string/preferences_movement_category">
|
||||
<ListPreference
|
||||
<com.gpl.rpg.AndorsTrail.view.CustomListPreference
|
||||
android:title="@string/preferences_movementmethod_title"
|
||||
android:summary="@string/preferences_movementmethod"
|
||||
android:key="movementmethod"
|
||||
android:defaultValue="0"
|
||||
android:entries="@array/preferences_movementmethods"
|
||||
android:entryValues="@array/preferences_movementmethod_values" />
|
||||
<ListPreference
|
||||
<com.gpl.rpg.AndorsTrail.view.CustomListPreference
|
||||
android:title="@string/preferences_movement_dpad_position_title"
|
||||
android:summary="@string/preferences_movement_dpad_position"
|
||||
android:key="dpadposition"
|
||||
@@ -86,7 +86,7 @@
|
||||
android:defaultValue="true"
|
||||
android:summary="@string/preferences_ui_enable_animations"
|
||||
android:key="enableUiAnimations" />
|
||||
<ListPreference
|
||||
<com.gpl.rpg.AndorsTrail.view.CustomListPreference
|
||||
android:title="@string/preferences_quickslots_placement"
|
||||
android:summary="@string/preferences_quickslots_placement_summary"
|
||||
android:key="quickslots_placement"
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.gpl.rpg.AndorsTrail.view;
|
||||
|
||||
import android.app.Dialog;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.R;
|
||||
import com.gpl.rpg.AndorsTrail.view.CustomDialogFactory.CustomDialog;
|
||||
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.preference.ListPreference;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
public class CustomListPreference extends ListPreference {
|
||||
|
||||
//Extensive constructor support
|
||||
public CustomListPreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
public CustomListPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
// Min API 21
|
||||
// public CustomListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
// super(context, attrs, defStyleAttr);
|
||||
// }
|
||||
// public CustomListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
// super(context, attrs, defStyleAttr, defStyleRes);
|
||||
// }
|
||||
|
||||
CustomDialog d = null;
|
||||
int clickedEntryIndex = 0;
|
||||
|
||||
@Override
|
||||
public Dialog getDialog() {
|
||||
if (d == null) createDialog();
|
||||
return d;
|
||||
}
|
||||
|
||||
private void createDialog() {
|
||||
final ListView choicesList = new ListView(getContext());
|
||||
choicesList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
|
||||
ArrayAdapter<CharSequence> choicesAdapter = new ArrayAdapter<CharSequence>(getContext(), R.layout.custom_checkedlistitem_layout, getEntries()) {
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = super.getView(position, convertView, parent);
|
||||
// choicesList.setItemChecked(position, getValueIndex() == position);
|
||||
v.setSelected(getValueIndex() == position);
|
||||
return v;
|
||||
}
|
||||
};
|
||||
choicesList.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, ListView.LayoutParams.WRAP_CONTENT));
|
||||
choicesList.setAdapter(choicesAdapter);
|
||||
choicesList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
if (getValue() != getEntryValues()[position]) {
|
||||
CustomListPreference.this.notifyChanged();
|
||||
clickedEntryIndex = position;
|
||||
CustomListPreference.this.onClick(d, DialogInterface.BUTTON_POSITIVE);
|
||||
} else {
|
||||
CustomListPreference.this.onClick(d, DialogInterface.BUTTON_NEGATIVE);
|
||||
}
|
||||
d.dismiss();
|
||||
}
|
||||
});
|
||||
choicesList.setItemChecked(getValueIndex(), true);
|
||||
|
||||
d = CustomDialogFactory.createDialog(getContext(), getTitle().toString(), null, null, choicesList, false);
|
||||
}
|
||||
|
||||
public int getValueIndex() {
|
||||
int selectedPosition;
|
||||
for (selectedPosition = getEntryValues().length - 1; selectedPosition >= 0; selectedPosition--) {
|
||||
if (getValue().equals(getEntryValues()[selectedPosition].toString())) break;
|
||||
}
|
||||
return selectedPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
CharSequence[] entryValues = getEntryValues();
|
||||
if (positiveResult && clickedEntryIndex >= 0 && entryValues != null) {
|
||||
String value = entryValues[clickedEntryIndex].toString();
|
||||
if (callChangeListener(value)) {
|
||||
setValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showDialog(Bundle state) {
|
||||
getDialog().setOnDismissListener(this);
|
||||
getDialog().show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
d = null;
|
||||
super.onDismiss(dialog);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user