Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / MainEntry.java @ c5fca790

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 Drawable mIconDrawable;
39
  private boolean mPrepared;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

    
43
  MainEntry(RubikObject object)
44
    {
45
    mType         = TYPE_OBJECT;
46
    mIconID       = 0;
47
    mIconDrawable = null;
48
    mObject       = object;
49
    mPrepared     = false;
50
    }
51

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

    
54
  MainEntry(int type, int iconID)
55
    {
56
    mType         = type;
57
    mIconID       = iconID;
58
    mIconDrawable = null;
59
    mObject       = null;
60
    mPrepared     = false;
61
    }
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

    
65
  private void prepare(Activity act)
66
    {
67
    mIconDrawable = act.getDrawable(mIconID);
68
    mPrepared = true;
69
    }
70

    
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72
// PUBLIC API
73

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

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
  public void onClick(RubikActivity act)
91
    {
92
    if( mType==TYPE_OBJECT )
93
      {
94
      if( mObject!=null )
95
        {
96
        android.util.Log.e("D", "clicked on "+ mObject.getLowerName());
97
        }
98
      else android.util.Log.e("D", "MainListEntry: object null!!");
99
      }
100
    else if( mType==TYPE_CREATOR )
101
      {
102
      act.switchToBandagedCreator();
103
      }
104
    }
105
}
(1-1/4)