~registry/dolphin-emu/triforce

« back to all changes in this revision

Viewing changes to Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListItem.java

  • Committer: Sérgio Benjamim
  • Date: 2015-02-13 05:54:40 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20150213055440-ey2rt3sjpy27km78
Dolphin Triforce branch from code.google, commit b957980 (4.0-315).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright 2013 Dolphin Emulator Project
 
3
 * Licensed under GPLv2
 
4
 * Refer to the license.txt file included.
 
5
 */
 
6
 
 
7
package org.dolphinemu.dolphinemu.gamelist;
 
8
 
 
9
import android.content.Context;
 
10
import android.graphics.Bitmap;
 
11
import android.graphics.BitmapFactory;
 
12
import android.util.Log;
 
13
 
 
14
import java.io.File;
 
15
import java.io.IOException;
 
16
import java.io.InputStream;
 
17
 
 
18
import org.dolphinemu.dolphinemu.NativeLibrary;
 
19
 
 
20
/**
 
21
 * Represents an item in the game list.
 
22
 */
 
23
public final class GameListItem implements Comparable<GameListItem>
 
24
{
 
25
        private String name;
 
26
        private final String data;
 
27
        private final String path;
 
28
        private Bitmap image;
 
29
 
 
30
        /**
 
31
         * Constructor.
 
32
         * 
 
33
         * @param ctx  The current {@link Context}
 
34
         * @param name The name of this GameListItem.
 
35
         * @param data The subtitle for this GameListItem
 
36
         * @param path The file path for the game represented by this GameListItem.
 
37
         */
 
38
        public GameListItem(Context ctx, String name, String data, String path)
 
39
        {
 
40
                this.name = name;
 
41
                this.data = data;
 
42
                this.path = path;
 
43
 
 
44
                File file = new File(path);
 
45
                if (!file.isDirectory() && !path.isEmpty())
 
46
                {
 
47
                        int[] Banner = NativeLibrary.GetBanner(path);
 
48
                        if (Banner[0] == 0)
 
49
                        {
 
50
                                try
 
51
                                {
 
52
                                        // Open the no banner icon.
 
53
                                        InputStream noBannerPath = ctx.getAssets().open("NoBanner.png");
 
54
 
 
55
                                        // Decode the bitmap.
 
56
                                        image = BitmapFactory.decodeStream(noBannerPath);
 
57
 
 
58
                                        // Scale the bitmap to match other banners.
 
59
                                        image = Bitmap.createScaledBitmap(image, 96, 32, false);
 
60
                                }
 
61
                                catch (IOException e)
 
62
                                {
 
63
                                        Log.e("GameListItem", e.toString());
 
64
                                }
 
65
                        }
 
66
                        else
 
67
                        {
 
68
                                image = Bitmap.createBitmap(Banner, 96, 32, Bitmap.Config.ARGB_8888);
 
69
                        }
 
70
 
 
71
                        this.name = NativeLibrary.GetTitle(path);
 
72
                }
 
73
        }
 
74
 
 
75
        /**
 
76
         * Gets the name of this GameListItem.
 
77
         * 
 
78
         * @return the name of this GameListItem.
 
79
         */
 
80
        public String getName()
 
81
        {
 
82
                return name;
 
83
        }
 
84
 
 
85
        /**
 
86
         * Gets the subtitle of this GameListItem.
 
87
         * 
 
88
         * @return the subtitle of this GameListItem.
 
89
         */
 
90
        public String getData()
 
91
        {
 
92
                return data;
 
93
        }
 
94
 
 
95
        /**
 
96
         * Gets the file path of the game represented by this GameListItem.
 
97
         * 
 
98
         * @return the file path of the game represented by this GameListItem.
 
99
         */
 
100
        public String getPath()
 
101
        {
 
102
                return path;
 
103
        }
 
104
 
 
105
        /**
 
106
         * Gets the image data for this game as a {@link Bitmap}.
 
107
         * 
 
108
         * @return the image data for this game as a {@link Bitmap}.
 
109
         */
 
110
        public Bitmap getImage()
 
111
        {
 
112
                return image;
 
113
        }
 
114
 
 
115
        @Override
 
116
        public int compareTo(GameListItem o) 
 
117
        {
 
118
                if (name != null)
 
119
                        return name.toLowerCase().compareTo(o.getName().toLowerCase()); 
 
120
                else 
 
121
                        throw new NullPointerException("The name of this GameListItem is null");
 
122
        }
 
123
}
 
124