Revision 054fbee1
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/dialogs/RubikDialogPatternListAdapter.java | ||
|---|---|---|
| 26 | 26 |
import android.widget.BaseExpandableListAdapter; |
| 27 | 27 |
import android.widget.TextView; |
| 28 | 28 |
|
| 29 |
import org.distorted.main.RubikActivity; |
|
| 29 | 30 |
import org.distorted.patterns.RubikPattern; |
| 30 | 31 |
import org.distorted.main.R; |
| 31 | 32 |
|
| ... | ... | |
| 34 | 35 |
class RubikDialogPatternListAdapter extends BaseExpandableListAdapter |
| 35 | 36 |
{
|
| 36 | 37 |
private Context mContext; |
| 37 |
private int mTab; |
|
| 38 |
private int mTab, mWidth;
|
|
| 38 | 39 |
|
| 39 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 40 | 41 |
|
| 41 |
public RubikDialogPatternListAdapter(Context context, int tab) |
|
| 42 |
public RubikDialogPatternListAdapter(Context context, int tab, int width)
|
|
| 42 | 43 |
{
|
| 43 | 44 |
mContext = context; |
| 44 | 45 |
mTab = tab; |
| 46 |
mWidth = width; |
|
| 45 | 47 |
} |
| 46 | 48 |
|
| 47 | 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 74 | 76 |
view = infalInflater.inflate(R.layout.dialog_pattern_child_item, null); |
| 75 | 77 |
} |
| 76 | 78 |
|
| 77 |
TextView sequence = view.findViewById(R.id.sequence);
|
|
| 78 |
sequence.setText(mContext.getString(R.string.sq_placeholder,childPosition+1)); |
|
| 79 |
TextView childItem = view.findViewById(R.id.childItem);
|
|
| 79 |
int size = (int)(mWidth* RubikActivity.PATTERN_CHILD_TEXT);
|
|
| 80 |
|
|
| 81 |
TextView childItem = view.findViewById(R.id.child); |
|
| 80 | 82 |
childItem.setText(childName); |
| 83 |
childItem.setTextSize(size); |
|
| 81 | 84 |
|
| 82 | 85 |
return view; |
| 83 | 86 |
} |
| ... | ... | |
| 130 | 133 |
view = inf.inflate(R.layout.dialog_pattern_group_item, null); |
| 131 | 134 |
} |
| 132 | 135 |
|
| 136 |
int size = (int)(mWidth* RubikActivity.PATTERN_GROUP_TEXT); |
|
| 137 |
|
|
| 133 | 138 |
TextView heading = view.findViewById(R.id.heading); |
| 134 | 139 |
heading.setText(groupName); |
| 140 |
heading.setTextSize(size); |
|
| 141 |
|
|
| 142 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
| 143 |
int numPatterns = pattern.getNumPatterns(mTab,groupPosition); |
|
| 144 |
TextView counter = view.findViewById(R.id.counter); |
|
| 145 |
counter.setText(String.format("%d", numPatterns));
|
|
| 146 |
counter.setTextSize(size); |
|
| 135 | 147 |
|
| 136 | 148 |
return view; |
| 137 | 149 |
} |
| src/main/java/org/distorted/dialogs/RubikDialogPatternPagerAdapter.java | ||
|---|---|---|
| 60 | 60 |
for(int i=0; i<mNumTabs; i++) |
| 61 | 61 |
{
|
| 62 | 62 |
int cat = mViews[i].getCurrentCategory(); |
| 63 |
int pos = mViews[i].getCurrentScrollPos(); |
|
| 64 |
pattern.rememberState(i,cat,pos); |
|
| 63 |
int pos = mViews[i].getCurrentVisiblePos(); |
|
| 64 |
int exp = mViews[i].getExpanded(); |
|
| 65 |
pattern.rememberState(i,cat,pos,exp); |
|
| 65 | 66 |
} |
| 66 | 67 |
} |
| 67 | 68 |
|
| src/main/java/org/distorted/dialogs/RubikDialogPatternView.java | ||
|---|---|---|
| 68 | 68 |
|
| 69 | 69 |
mTab = position; |
| 70 | 70 |
mDialog = dialog; |
| 71 |
mExpandedGroup = -1; |
|
| 71 |
|
|
| 72 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
| 73 |
mExpandedGroup = pattern.recallExpanded(position); |
|
| 72 | 74 |
|
| 73 | 75 |
View tab = inflate( act, R.layout.dialog_pattern_tab, null); |
| 74 | 76 |
|
| 75 | 77 |
mListView = tab.findViewById(R.id.patternListView); |
| 76 |
mListAdapter = new RubikDialogPatternListAdapter(act,mTab); |
|
| 78 |
mListAdapter = new RubikDialogPatternListAdapter(act,mTab, ract.getScreenHeightInPixels());
|
|
| 77 | 79 |
mListView.setAdapter(mListAdapter); |
| 78 | 80 |
|
| 81 |
if( mExpandedGroup>=0 ) |
|
| 82 |
{
|
|
| 83 |
mListView.expandGroup(mExpandedGroup); |
|
| 84 |
} |
|
| 85 |
|
|
| 86 |
int visible = pattern.recallVisiblePos(mTab); |
|
| 87 |
mListView.setSelectionFromTop(visible,0); |
|
| 88 |
|
|
| 79 | 89 |
mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() |
| 80 | 90 |
{
|
| 81 | 91 |
@Override |
| ... | ... | |
| 126 | 136 |
|
| 127 | 137 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 128 | 138 |
|
| 129 |
int getCurrentScrollPos()
|
|
| 139 |
int getCurrentVisiblePos()
|
|
| 130 | 140 |
{
|
| 131 |
return 0;//mScroll.getScrollY();
|
|
| 141 |
return mListView.getFirstVisiblePosition();
|
|
| 132 | 142 |
} |
| 133 | 143 |
|
| 134 | 144 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 135 | 145 |
|
| 136 |
@Override |
|
| 137 |
protected void onLayout(boolean changed, int left, int top, int right, int bottom) |
|
| 146 |
int getExpanded() |
|
| 138 | 147 |
{
|
| 139 |
super.onLayout(changed,left,top,right,bottom); |
|
| 140 |
/* |
|
| 141 |
if( !changed ) |
|
| 142 |
{
|
|
| 143 |
final RubikPattern pattern = RubikPattern.getInstance(); |
|
| 144 |
mScroll.setScrollY( pattern.recallScrollPos(mTab) ); |
|
| 145 |
} |
|
| 146 |
*/ |
|
| 148 |
return mExpandedGroup; |
|
| 147 | 149 |
} |
| 148 | 150 |
} |
| src/main/java/org/distorted/main/RubikActivity.java | ||
|---|---|---|
| 43 | 43 |
|
| 44 | 44 |
public class RubikActivity extends AppCompatActivity |
| 45 | 45 |
{
|
| 46 |
public static final float PADDING = 0.01f; |
|
| 47 |
public static final float MARGIN = 0.004f; |
|
| 48 |
public static final float LARGE_MARGIN = 0.025f; |
|
| 49 |
public static final float BUTTON_TEXT_SIZE = 0.05f; |
|
| 50 |
public static final float TITLE_TEXT_SIZE = 0.06f; |
|
| 51 |
public static final float BITMAP_TEXT_SIZE = 0.09f; |
|
| 52 |
public static final float MENU_ITEM_SIZE = 0.12f; |
|
| 46 |
public static final float PADDING = 0.01f; |
|
| 47 |
public static final float MARGIN = 0.004f; |
|
| 48 |
public static final float LARGE_MARGIN = 0.025f; |
|
| 49 |
public static final float BUTTON_TEXT_SIZE = 0.05f; |
|
| 50 |
public static final float TITLE_TEXT_SIZE = 0.06f; |
|
| 51 |
public static final float BITMAP_TEXT_SIZE = 0.09f; |
|
| 52 |
public static final float MENU_ITEM_SIZE = 0.12f; |
|
| 53 |
public static final float PATTERN_GROUP_TEXT = 0.012f; |
|
| 54 |
public static final float PATTERN_CHILD_TEXT = 0.008f; |
|
| 53 | 55 |
|
| 54 | 56 |
public static final float MENU_BIG_TEXT_SIZE = 0.05f; |
| 55 | 57 |
public static final float MENU_MEDIUM_TEXT_SIZE= 0.04f; |
| src/main/java/org/distorted/patterns/RubikPattern.java | ||
|---|---|---|
| 32 | 32 |
{
|
| 33 | 33 |
private static final int DURATION_MILLIS = 750; |
| 34 | 34 |
|
| 35 |
private int[] numCategories = new int[NUM_OBJECTS]; |
|
| 36 |
private int[] currentCategory = new int[NUM_OBJECTS]; |
|
| 37 |
private int[] currentScrollPos= new int[NUM_OBJECTS]; |
|
| 35 |
private int[] numCategories = new int[NUM_OBJECTS]; |
|
| 36 |
private int[] currentCategory = new int[NUM_OBJECTS]; |
|
| 37 |
private int[] currentVisiblePos= new int[NUM_OBJECTS]; |
|
| 38 |
private int[] currentExpanded = new int[NUM_OBJECTS]; |
|
| 38 | 39 |
|
| 39 | 40 |
private List<List<Category>> mCategories; |
| 40 | 41 |
private static RubikPattern mThis; |
| ... | ... | |
| 361 | 362 |
|
| 362 | 363 |
mCategories.add(list); |
| 363 | 364 |
numCategories[i]=patStrings.length; |
| 365 |
|
|
| 366 |
currentExpanded[i] = -1; |
|
| 364 | 367 |
} |
| 365 | 368 |
} |
| 366 | 369 |
|
| ... | ... | |
| 418 | 421 |
|
| 419 | 422 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 420 | 423 |
|
| 421 |
public void rememberState(int tab, int cat, int scrollPos) |
|
| 424 |
public void rememberState(int tab, int cat, int scrollPos, int expanded)
|
|
| 422 | 425 |
{
|
| 423 | 426 |
if( tab>=0 && tab<NUM_OBJECTS ) |
| 424 | 427 |
{
|
| 425 |
currentCategory[tab] = cat; |
|
| 426 |
currentScrollPos[tab]= scrollPos; |
|
| 428 |
currentCategory[tab] = cat; |
|
| 429 |
currentVisiblePos[tab]= scrollPos; |
|
| 430 |
currentExpanded[tab] = expanded; |
|
| 427 | 431 |
} |
| 428 | 432 |
} |
| 429 | 433 |
|
| ... | ... | |
| 436 | 440 |
|
| 437 | 441 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 438 | 442 |
|
| 439 |
public int recallScrollPos(int tab) |
|
| 443 |
public int recallVisiblePos(int tab) |
|
| 444 |
{
|
|
| 445 |
return tab>=0 && tab<NUM_OBJECTS ? currentVisiblePos[tab] : 0; |
|
| 446 |
} |
|
| 447 |
|
|
| 448 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 449 |
|
|
| 450 |
public int recallExpanded(int tab) |
|
| 440 | 451 |
{
|
| 441 |
return tab>=0 && tab<NUM_OBJECTS ? currentScrollPos[tab] : 0;
|
|
| 452 |
return tab>=0 && tab<NUM_OBJECTS ? currentExpanded[tab] : -1;
|
|
| 442 | 453 |
} |
| 443 | 454 |
|
| 444 | 455 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/res/layout/dialog_pattern_child_item.xml | ||
|---|---|---|
| 1 | 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
| 3 |
android:layout_width="match_parent"
|
|
| 2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
| 3 |
android:layout_width="fill_parent"
|
|
| 4 | 4 |
android:layout_height="match_parent" |
| 5 |
android:orientation="vertical"> |
|
| 5 |
android:orientation="vertical" >
|
|
| 6 | 6 |
|
| 7 | 7 |
<TextView |
| 8 |
android:id="@+id/sequence"
|
|
| 8 |
android:id="@+id/child"
|
|
| 9 | 9 |
android:layout_width="wrap_content" |
| 10 | 10 |
android:layout_height="wrap_content" |
| 11 |
android:layout_alignParentLeft="true" |
|
| 12 |
android:layout_alignParentTop="true" |
|
| 13 |
android:paddingLeft="35sp" |
|
| 14 |
/> |
|
| 11 |
android:layout_marginTop="5sp" |
|
| 12 |
android:layout_marginBottom="5sp" |
|
| 13 |
android:paddingLeft="35sp"/> |
|
| 15 | 14 |
|
| 16 |
<TextView |
|
| 17 |
android:id="@+id/childItem" |
|
| 18 |
android:layout_width="wrap_content" |
|
| 19 |
android:layout_height="wrap_content" |
|
| 20 |
android:layout_alignParentTop="true" |
|
| 21 |
android:layout_toRightOf="@id/sequence" |
|
| 22 |
/> |
|
| 23 |
|
|
| 24 |
</RelativeLayout> |
|
| 15 |
</LinearLayout> |
|
| src/main/res/layout/dialog_pattern_group_item.xml | ||
|---|---|---|
| 1 | 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
| 2 |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
| 3 | 3 |
android:layout_width="fill_parent" |
| 4 | 4 |
android:layout_height="match_parent" |
| 5 |
android:orientation="vertical" >
|
|
| 5 |
android:orientation="horizontal">
|
|
| 6 | 6 |
|
| 7 | 7 |
<TextView |
| 8 | 8 |
android:id="@+id/heading" |
| 9 | 9 |
android:layout_width="wrap_content" |
| 10 | 10 |
android:layout_height="wrap_content" |
| 11 |
android:layout_alignParentLeft="true" |
|
| 12 |
android:layout_alignParentTop="true" |
|
| 13 |
android:gravity="left" |
|
| 11 | 14 |
android:paddingLeft="35sp" |
| 12 |
android:textStyle="bold" /> |
|
| 15 |
android:textStyle="bold" |
|
| 16 |
/> |
|
| 13 | 17 |
|
| 14 |
</LinearLayout> |
|
| 18 |
<TextView |
|
| 19 |
android:id="@+id/counter" |
|
| 20 |
android:layout_width="wrap_content" |
|
| 21 |
android:layout_height="wrap_content" |
|
| 22 |
android:layout_alignParentRight="true" |
|
| 23 |
android:gravity="right" |
|
| 24 |
android:layout_toRightOf="@id/heading" |
|
| 25 |
android:paddingRight="10sp" |
|
| 26 |
android:textStyle="bold" |
|
| 27 |
/> |
|
| 28 |
|
|
| 29 |
</RelativeLayout> |
|
| src/main/res/layout/dialog_pattern_tab.xml | ||
|---|---|---|
| 2 | 2 |
<ExpandableListView xmlns:android="http://schemas.android.com/apk/res/android" |
| 3 | 3 |
android:id="@+id/patternListView" |
| 4 | 4 |
android:background="@color/grey" |
| 5 |
android:paddingLeft="10dp"
|
|
| 6 |
android:paddingRight="10dp"
|
|
| 5 |
android:paddingLeft="0dp" |
|
| 6 |
android:paddingRight="0dp" |
|
| 7 | 7 |
android:paddingTop="10dp" |
| 8 | 8 |
android:paddingBottom="10dp" |
| 9 | 9 |
android:layout_width="fill_parent" |
Also available in: Unified diff
Reinvent the Pattern Dialog (Part 2)