1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.example.android.rs.miscsamples;
18
19import java.io.Writer;
20import java.util.Vector;
21
22import android.content.res.Resources;
23import android.renderscript.*;
24import android.renderscript.ProgramStore.DepthFunc;
25import android.util.Log;
26
27
28public class RsListRS {
29
30    private final int STATE_LAST_FOCUS = 1;
31
32    private static final String[] DATA_LIST = {
33    "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
34    "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina",
35    "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan",
36    "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium",
37    "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia",
38    "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil",
39    "British Indian Ocean Territory", "British Virgin Islands", "Brunei", "Bulgaria",
40    "Burkina Faso", "Burundi", "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
41    "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
42    "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
43    "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
44    "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
45    "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
46    "Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
47    "Former Yugoslav Republic of Macedonia", "France", "French Guiana", "French Polynesia",
48    "French Southern Territories", "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar",
49    "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau",
50    "Guyana", "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary",
51    "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica",
52    "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos",
53    "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg",
54    "Macau", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands",
55    "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova",
56    "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia",
57    "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand",
58    "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "Northern Marianas",
59    "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru",
60    "Philippines", "Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar",
61    "Reunion", "Romania", "Russia", "Rwanda", "Sqo Tome and Principe", "Saint Helena",
62    "Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon",
63    "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Saudi Arabia", "Senegal",
64    "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands",
65    "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Korea",
66    "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden",
67    "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas",
68    "The Gambia", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey",
69    "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Virgin Islands", "Uganda",
70    "Ukraine", "United Arab Emirates", "United Kingdom",
71    "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan",
72    "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara",
73    "Yemen", "Yugoslavia", "Zambia", "Zimbabwe"
74    };
75
76    public RsListRS() {
77    }
78
79    public void init(RenderScriptGL rs, Resources res) {
80        mRS = rs;
81        mRes = res;
82        initRS();
83    }
84
85    private Resources mRes;
86    private RenderScriptGL mRS;
87    private Font mItalic;
88
89    ScriptField_ListAllocs_s mListAllocs;
90
91    private ScriptC_rslist mScript;
92
93    int mLastX;
94    int mLastY;
95
96    public void onActionDown(int x, int y) {
97        mScript.set_gDY(0.0f);
98
99        mLastX = x;
100        mLastY = y;
101    }
102
103    public void onActionMove(int x, int y) {
104        int dx = mLastX - x;
105        int dy = mLastY - y;
106
107        if (Math.abs(dy) <= 2) {
108            dy = 0;
109        }
110
111        mScript.set_gDY(dy);
112
113        mLastX = x;
114        mLastY = y;
115    }
116
117    private void initRS() {
118
119        mScript = new ScriptC_rslist(mRS, mRes, R.raw.rslist);
120
121        mListAllocs = new ScriptField_ListAllocs_s(mRS, DATA_LIST.length);
122        for (int i = 0; i < DATA_LIST.length; i ++) {
123            ScriptField_ListAllocs_s.Item listElem = new ScriptField_ListAllocs_s.Item();
124            listElem.text = Allocation.createFromString(mRS, DATA_LIST[i], Allocation.USAGE_SCRIPT);
125            mListAllocs.set(listElem, i, false);
126        }
127
128        mListAllocs.copyAll();
129
130        mScript.bind_gList(mListAllocs);
131
132        mItalic = Font.create(mRS, mRes, "serif", Font.Style.BOLD_ITALIC, 8);
133        mScript.set_gItalic(mItalic);
134
135        mRS.bindRootScript(mScript);
136    }
137}
138
139
140
141