Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / MainEntry.java @ 05f6d7bd

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.os.Bundle;
25
import android.widget.ImageButton;
26

    
27
import org.distorted.dialogs.RubikDialogPlayPopup;
28
import org.distorted.dialogs.RubikDialogScores;
29
import org.distorted.main.RubikActivity;
30

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
public class MainEntry
34
{
35
  public final static int TYPE_OBJECT  = 0;
36
  public final static int TYPE_CREATOR = 1;
37

    
38
  private final RubikObject mObject;
39
  private final int mType;
40
  private final int mIconID;
41
  private Drawable mIconDrawable;
42
  private boolean mPrepared;
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

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

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
  MainEntry(int type, int iconID)
58
    {
59
    mType         = type;
60
    mIconID       = iconID;
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 void onClick(RubikActivity act)
94
    {
95
    if( mType==TYPE_OBJECT )
96
      {
97
      if( mObject!=null )
98
        {
99
        Bundle bundle = new Bundle();
100
        bundle.putInt("ordinal", 0 );
101
        RubikDialogPlayPopup diag = new RubikDialogPlayPopup();
102
        diag.setArguments(bundle);
103
        diag.show(act.getSupportFragmentManager(), null);
104
        }
105
      else android.util.Log.e("D", "MainListEntry: object null!!");
106
      }
107
    else if( mType==TYPE_CREATOR )
108
      {
109
      act.switchToBandagedCreator();
110
      }
111
    }
112
}
(1-1/4)