Project

General

Profile

« Previous | Next » 

Revision ab66b70e

Added by Leszek Koltunski almost 2 years ago

IAP, part 3: non-free objects appear in the popup with a lock icon.

View differences:

src/main/java/org/distorted/helpers/PopupCreator.java
10 10
package org.distorted.helpers;
11 11

  
12 12
import android.app.Activity;
13
import android.content.Context;
14
import android.view.LayoutInflater;
15
import android.view.View;
13 16
import android.widget.GridLayout;
14 17
import android.widget.ImageButton;
15 18

  
19
import org.distorted.main.R;
16 20
import org.distorted.objects.RubikObject;
17 21
import org.distorted.objects.RubikObjectList;
18 22

  
......
40 44
      colSpecs[col] = GridLayout.spec(col);
41 45
      }
42 46

  
47
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
48

  
43 49
    for(int object=0; object<numObjects; object++)
44 50
      {
45
      final RubikObject rObject = RubikObjectList.getObject(object);
51
      View v = createView(act,layoutInflater,object);
46 52
      int row = object/colCount;
47
      ImageButton button = new ImageButton(act);
48
      if( rObject!=null ) rObject.setIconTo(act,button);
49 53

  
50 54
      GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[row],colSpecs[nextInRow[row]]);
51 55
      params.bottomMargin = margin;
......
58 62

  
59 63
      nextInRow[row]++;
60 64

  
61
      grid.addView(button, params);
65
      grid.addView(v,params);
66
      }
67
    }
68

  
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

  
71
  private static View createView(Activity act, LayoutInflater inflater, int ordinal)
72
    {
73
    final RubikObject obj = RubikObjectList.getObject(ordinal);
74

  
75
    if( obj!=null )
76
      {
77
      if( obj.isFree() )
78
        {
79
        ImageButton button = new ImageButton(act);
80
        obj.setIconTo(act,button);
81
        return button;
82
        }
83
      else
84
        {
85
        final View layout = inflater.inflate(R.layout.non_free_object, null);
86
        ImageButton button= layout.findViewById(R.id.non_free_button);
87
        obj.setIconTo(act,button);
88
        return layout;
89
        }
62 90
      }
91

  
92
    return null;
63 93
    }
64 94
  }
src/main/res/layout/non_free_object.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
        android:id="@+id/non_free_layout"
4
        android:layout_width="match_parent"
5
        android:layout_height="wrap_content" >
6

  
7
        <ImageButton
8
            android:id="@+id/non_free_button"
9
            android:layout_width="match_parent"
10
            android:layout_height="wrap_content"
11
            android:gravity="center"/>
12

  
13
        <ImageView
14
            android:id="@+id/non_free_lock"
15
            android:layout_width="wrap_content"
16
            android:layout_height="wrap_content"
17
            android:layout_gravity="bottom|end"
18
            android:adjustViewBounds="true"
19
            android:paddingTop="-10dp"
20
            android:scaleType="fitStart"
21
            android:src="@drawable/ui_big_locked"/>
22

  
23
    </FrameLayout>

Also available in: Unified diff