Project

General

Profile

Download (3.96 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / MainEntry.java @ 68191e7d

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.objects;
21

    
22
import android.app.Activity;
23
import android.graphics.drawable.Drawable;
24
import android.widget.ImageButton;
25

    
26
import org.distorted.main.RubikActivity;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

    
30
public class MainEntry
31
{
32
  public final static int TYPE_OBJECT  = 0;
33
  public final static int TYPE_CREATOR = 1;
34

    
35
  private final RubikObject mObject;
36
  private final int mType;
37
  private final int mIconID;
38
  private final int mOridnal;
39
  private Drawable mIconDrawable;
40
  private boolean mPrepared;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
  public MainEntry(RubikObject object, int ordinal)
45
    {
46
    mType         = TYPE_OBJECT;
47
    mIconID       = 0;
48
    mOridnal      = ordinal;
49
    mIconDrawable = null;
50
    mObject       = object;
51
    mPrepared     = false;
52
    }
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
  public MainEntry(int type, int iconID)
57
    {
58
    mType         = type;
59
    mIconID       = iconID;
60
    mOridnal      = -1;
61
    mIconDrawable = null;
62
    mObject       = null;
63
    mPrepared     = false;
64
    }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
  private void prepare(Activity act)
69
    {
70
    mIconDrawable = act.getDrawable(mIconID);
71
    mPrepared = true;
72
    }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75
// PUBLIC API
76

    
77
  public void setIconTo(RubikActivity act, ImageButton button)
78
    {
79
    if( mType==TYPE_OBJECT )
80
      {
81
      if( mObject!=null ) mObject.setIconTo(act,button);
82
      else android.util.Log.e("D", "MainListEntry: object null!!");
83
      }
84
    else if( mType==TYPE_CREATOR )
85
      {
86
      if( !mPrepared ) prepare(act);
87
      button.setBackground(mIconDrawable);
88
      }
89
    }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

    
93
  public int getType()
94
    {
95
    return mType;
96
    }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

    
100
  public int getOrdinal()
101
    {
102
    return mOridnal;
103
    }
104
}
(1-1/4)