1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2022 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9
|
|
10
|
package org.distorted.objects;
|
11
|
|
12
|
import android.app.Activity;
|
13
|
import android.graphics.drawable.Drawable;
|
14
|
import android.widget.ImageButton;
|
15
|
|
16
|
import org.distorted.main.RubikActivity;
|
17
|
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
public class MainEntry
|
21
|
{
|
22
|
public final static int TYPE_OBJECT = 0;
|
23
|
public final static int TYPE_CREATOR = 1;
|
24
|
|
25
|
private final RubikObject mObject;
|
26
|
private final int mType;
|
27
|
private final int mIconID;
|
28
|
private final int mOridnal;
|
29
|
private Drawable mIconDrawable;
|
30
|
private boolean mPrepared;
|
31
|
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
|
34
|
public MainEntry(RubikObject object, int ordinal)
|
35
|
{
|
36
|
mType = TYPE_OBJECT;
|
37
|
mIconID = 0;
|
38
|
mOridnal = ordinal;
|
39
|
mIconDrawable = null;
|
40
|
mObject = object;
|
41
|
mPrepared = false;
|
42
|
}
|
43
|
|
44
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45
|
|
46
|
public MainEntry(int type, int iconID)
|
47
|
{
|
48
|
mType = type;
|
49
|
mIconID = iconID;
|
50
|
mOridnal = -1;
|
51
|
mIconDrawable = null;
|
52
|
mObject = null;
|
53
|
mPrepared = false;
|
54
|
}
|
55
|
|
56
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57
|
|
58
|
private void prepare(Activity act)
|
59
|
{
|
60
|
mIconDrawable = act.getDrawable(mIconID);
|
61
|
mPrepared = true;
|
62
|
}
|
63
|
|
64
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
65
|
// PUBLIC API
|
66
|
|
67
|
public void setIconTo(RubikActivity act, ImageButton button)
|
68
|
{
|
69
|
if( mType==TYPE_OBJECT )
|
70
|
{
|
71
|
if( mObject!=null ) mObject.setIconTo(act,button);
|
72
|
else android.util.Log.e("D", "MainListEntry: object null!!");
|
73
|
}
|
74
|
else if( mType==TYPE_CREATOR )
|
75
|
{
|
76
|
if( !mPrepared ) prepare(act);
|
77
|
button.setBackground(mIconDrawable);
|
78
|
}
|
79
|
}
|
80
|
|
81
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
82
|
|
83
|
public int getType()
|
84
|
{
|
85
|
return mType;
|
86
|
}
|
87
|
|
88
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
89
|
|
90
|
public int getOrdinal()
|
91
|
{
|
92
|
return mOridnal;
|
93
|
}
|
94
|
}
|