SHOW:
|
|
- or go back to the newest paste.
1 | Apologies for not using my actual source - I tried to make the post as generic as possible so it helps other people in the future. | |
2 | ||
3 | ||
4 | I'm attempting to change the value of playlist in this line: | |
5 | ||
6 | new GetYouTubeUserVideosTask(responseHandler, playlist).execute(); | |
7 | ||
8 | ||
9 | It refreshes a listView of youtube videos. | |
10 | ||
11 | ||
12 | I'd like to be able to use my stringArray to change the station. | |
13 | ||
14 | ||
15 | private String[] stringArray = new String[] { "vevo", | |
16 | "TheMozARTGROUP", "TimMcGrawVEVO", "TiestoVEVO", | |
17 | "EminemVEVO" }; | |
18 | ||
19 | ||
20 | ||
21 | Are you sure I'll need to create a new textView? I did (just to try) and it didn't seem to accomplish what I'm looking for. | |
22 | ||
23 | ||
24 | ||
25 | ||
26 | /** | |
27 | * The Activity can retrieve Videos for a specific username from YouTube</br> It | |
28 | * then displays them into a list including the Thumbnail preview and the | |
29 | * title</br> There is a reference to each video on YouTube as well but this | |
30 | * isn't used in this tutorial</br> </br> <b>Note<b/> orientation change isn't | |
31 | * covered in this tutorial, you will want to override onSaveInstanceState() and | |
32 | * onRestoreInstanceState() when you come to this </br> | |
33 | * | |
34 | */ | |
35 | public class Home extends YouTubeBaseActivity implements | |
36 | ||
37 | VideoClickListener { | |
38 | ||
39 | private VideosListView listView; | |
40 | private ActionBarDrawerToggle actionBarDrawerToggle; | |
41 | public static final String API_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; | |
42 | public static final String VIDEO_ID = "o7VVHhK9zf0"; | |
43 | private int mCurrentTabPosition = NO_CURRENT_POSITION; | |
44 | private static final int NO_CURRENT_POSITION = -1; | |
45 | private DrawerLayout drawerLayout; | |
46 | private ListView drawerListView; | |
47 | private String[] drawerListViewItems; | |
48 | ||
49 | ScrollView mainScrollView; | |
50 | Button fav_up_btn1; | |
51 | Button fav_dwn_btn1; | |
52 | String TAG = "DEBUG THIS"; | |
53 | String playlist = "eminemvevo"; | |
54 | Activity activity; | |
55 | int imageArray[]; | |
56 | String[] stringArray; | |
57 | String runPrevious = "No"; | |
58 | private OnPageChangeListener mPageChangeListener; | |
59 | ImagePagerAdapter adapter = new ImagePagerAdapter(); | |
60 | ||
61 | @Override | |
62 | public void onCreate(Bundle savedInstanceState) { | |
63 | super.onCreate(savedInstanceState); | |
64 | setContentView(R.layout.home); | |
65 | final ActionBar actionBar = getActionBar(); | |
66 | final ViewPager mPager = (ViewPager) findViewById(R.id.view_pager); | |
67 | adapter.notifyDataSetChanged(); | |
68 | mPager.setAdapter(adapter); | |
69 | actionBar.setCustomView(R.layout.actionbar_custom_view_home); | |
70 | actionBar.setDisplayShowTitleEnabled(false); | |
71 | actionBar.setDisplayShowCustomEnabled(true); | |
72 | drawerListViewItems = getResources().getStringArray(R.array.items); | |
73 | drawerListView = (ListView) findViewById(R.id.left_drawer); | |
74 | drawerListView.setAdapter(new ArrayAdapter<String>(this, | |
75 | R.layout.drawer_listview_item, drawerListViewItems)); | |
76 | mPager.setOnPageChangeListener(mPageChangeListener); | |
77 | drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); | |
78 | actionBarDrawerToggle = new ActionBarDrawerToggle(this, | |
79 | drawerLayout, | |
80 | R.drawable.ic_drawer, | |
81 | R.string.drawer_open, | |
82 | R.string.drawer_close | |
83 | ); | |
84 | drawerLayout.setDrawerListener(actionBarDrawerToggle); | |
85 | ||
86 | getActionBar().setDisplayHomeAsUpEnabled(true); | |
87 | _initMenu(); | |
88 | drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, | |
89 | GravityCompat.START); | |
90 | ||
91 | listView = (VideosListView) findViewById(R.id.videosListView); | |
92 | listView.setOnVideoClickListener(this); | |
93 | ||
94 | new GetYouTubeUserVideosTask(responseHandler, playlist).execute(); | |
95 | ||
96 | mPager.setOnPageChangeListener(new OnPageChangeListener() { | |
97 | ||
98 | @Override | |
99 | public void onPageSelected(int pos) { | |
100 | String playlist1 = "themozartgroup"; | |
101 | Log.d("PK", "**** onPageSelected"); | |
102 | new GetYouTubeUserVideosTask(responseHandler, playlist1) | |
103 | .execute(); | |
104 | ||
105 | } | |
106 | ||
107 | @Override | |
108 | public void onPageScrolled(int arg0, float arg1, int arg2) { | |
109 | Log.d("PK", "onPageScrolled"); | |
110 | // TODO Auto-generated method stub | |
111 | } | |
112 | ||
113 | @Override | |
114 | public void onPageScrollStateChanged(int pos) { | |
115 | ||
116 | Log.d("PK", "onPageScrollStateChanged"); | |
117 | ||
118 | } | |
119 | }); | |
120 | ||
121 | mPageChangeListener = new ViewPager.SimpleOnPageChangeListener() { | |
122 | ||
123 | @Override | |
124 | public void onPageSelected(int position) { | |
125 | onTabChanged(mPager.getAdapter(), mCurrentTabPosition, position); | |
126 | position = mCurrentTabPosition; | |
127 | int oldPos = mPager.getCurrentItem(); | |
128 | ||
129 | Log.d("PK", "Page selected"); | |
130 | ||
131 | if (position > oldPos) { | |
132 | ||
133 | System.out.print(position); | |
134 | // Moving to the right | |
135 | String playlist = "TheMozARTGROUP"; | |
136 | new GetYouTubeUserVideosTask(responseHandler, playlist) | |
137 | .execute(); | |
138 | ||
139 | } else if (position < oldPos) { | |
140 | // Moving to the Left | |
141 | System.out.print(position); | |
142 | String playlist = "TheMozARTGROUP"; | |
143 | new GetYouTubeUserVideosTask(responseHandler, playlist) | |
144 | .execute(); | |
145 | ||
146 | } | |
147 | mPager.setOnPageChangeListener(mPageChangeListener); | |
148 | } | |
149 | ||
150 | private void onTabChanged(PagerAdapter adapter, | |
151 | int mCurrentTabPosition, int position) { | |
152 | ||
153 | Log.d("PK", "Tab changed"); | |
154 | // TODO Auto-generated method stub | |
155 | ||
156 | } | |
157 | }; | |
158 | } | |
159 | ||
160 | private class MyActivityGetYouTubeUserVideosTask extends | |
161 | GetYouTubeUserVideosTask { | |
162 | public MyActivityGetYouTubeUserVideosTask(Handler replyTo, | |
163 | String username) { | |
164 | super(replyTo, username); | |
165 | // TODO Auto-generated constructor stub | |
166 | } | |
167 | ||
168 | @Override | |
169 | protected void onPostExecute(Void result) { | |
170 | if (result != null) { | |
171 | // TODO update your list data | |
172 | adapter.notifyDataSetChanged(); | |
173 | } | |
174 | ||
175 | } | |
176 | } | |
177 | ||
178 | private void _initMenu() { | |
179 | ||
180 | // drawerListView.setOnItemClickListener(new DrawerItemClickListener()); | |
181 | ||
182 | } | |
183 | ||
184 | Handler responseHandler = new Handler() { | |
185 | @Override | |
186 | public void handleMessage(Message msg) { | |
187 | populateListWithVideos(msg); | |
188 | }; | |
189 | }; | |
190 | ||
191 | private void populateListWithVideos(Message msg) { | |
192 | Library lib = (Library) msg.getData().get( | |
193 | GetYouTubeUserVideosTask.LIBRARY); | |
194 | listView.setVideos(lib.getVideos()); | |
195 | ||
196 | } | |
197 | ||
198 | @Override | |
199 | protected void onStop() { | |
200 | responseHandler = null; | |
201 | super.onStop(); | |
202 | } | |
203 | ||
204 | @Override | |
205 | public void onVideoClicked(Video video) { | |
206 | Intent intent = new Intent(this, Player.class); | |
207 | intent.putExtra("id", video.getId()); | |
208 | intent.putExtra("title", video.getTitle()); | |
209 | intent.putExtra("uploader", video.getUploader()); | |
210 | intent.putExtra("viewCount", video.getviewCount()); | |
211 | startActivity(intent); | |
212 | } | |
213 | ||
214 | @Override | |
215 | public void onConfigurationChanged(Configuration newConfig) { | |
216 | super.onConfigurationChanged(newConfig); | |
217 | actionBarDrawerToggle.onConfigurationChanged(newConfig); | |
218 | } | |
219 | ||
220 | @Override | |
221 | public boolean onCreateOptionsMenu(Menu menu) { | |
222 | MenuInflater inflater = getMenuInflater(); | |
223 | inflater.inflate(R.menu.main, menu); | |
224 | return super.onCreateOptionsMenu(menu); | |
225 | } | |
226 | ||
227 | @Override | |
228 | public boolean onOptionsItemSelected(MenuItem item) { | |
229 | ||
230 | if (actionBarDrawerToggle.onOptionsItemSelected(item)) { | |
231 | return true; | |
232 | } | |
233 | return super.onOptionsItemSelected(item); | |
234 | } | |
235 | ||
236 | private class ImagePagerAdapter extends PagerAdapter implements | |
237 | ViewPager.OnPageChangeListener { | |
238 | public ImagePagerAdapter(Activity act, int[] mImages, | |
239 | String[] stringArra) { | |
240 | imageArray = mImages; | |
241 | activity = act; | |
242 | stringArray = stringArra; | |
243 | } | |
244 | ||
245 | public ImagePagerAdapter() { | |
246 | super(); | |
247 | ||
248 | } | |
249 | ||
250 | private int[] mImages = new int[] { R.drawable.selstation_up_btn, | |
251 | R.drawable.classical_up_btn, R.drawable.country_up_btn, | |
252 | R.drawable.dance_up_btn, R.drawable.hiphop_up_btn, | |
253 | R.drawable.island_up_btn, R.drawable.latin_up_btn, | |
254 | R.drawable.pop_up_btn, R.drawable.samba_up_btn }; | |
255 | ||
256 | private String[] stringArray = new String[] { "vevo", | |
257 | "TheMozARTGROUP", "TimMcGrawVEVO", "TiestoVEVO", | |
258 | "EminemVEVO" }; | |
259 | ||
260 | @Override | |
261 | public int getCount() { | |
262 | return mImages.length; | |
263 | } | |
264 | ||
265 | @Override | |
266 | public boolean isViewFromObject(View view, Object object) { | |
267 | return view == ((ImageView) object); | |
268 | } | |
269 | ||
270 | @Override | |
271 | public Object instantiateItem(ViewGroup container, int position) { | |
272 | Context context = Home.this; | |
273 | ImageView imageView = new ImageView(context); | |
274 | imageView.setScaleType(ScaleType.FIT_XY); | |
275 | imageView.setImageResource(mImages[position]); | |
276 | container.addView(imageView); | |
277 | ||
278 | TextView text = new TextView(container.getContext()); | |
279 | text.setText(stringArray[position]); | |
280 | container.addView(text); | |
281 | ||
282 | ||
283 | return imageView; | |
284 | } | |
285 | ||
286 | public void destroyItem(ViewGroup container, int position, Object object) { | |
287 | ((ViewPager) container).removeView((ImageView) object); | |
288 | } | |
289 | ||
290 | private class DrawerItemClickListener implements | |
291 | ListView.OnItemClickListener { | |
292 | ||
293 | @Override | |
294 | public void onItemClick(AdapterView parent, View view, | |
295 | int position, long id) { | |
296 | ||
297 | Log.d("pk", "onItemClick"); | |
298 | // Highlight the selected item, update the title, and close the | |
299 | // drawer | |
300 | // update selected item and title, then close the drawer | |
301 | drawerListView.setItemChecked(position, true); | |
302 | setTitle("......"); | |
303 | ||
304 | String text = "menu click... should be implemented"; | |
305 | // Toast.makeText(Home.this, text, Toast.LENGTH_LONG).show(); | |
306 | drawerLayout.closeDrawer(drawerListView); | |
307 | ||
308 | } | |
309 | ||
310 | } | |
311 | ||
312 | @Override | |
313 | public void onPageScrollStateChanged(int arg0) { | |
314 | // TODO Auto-generated method stub | |
315 | Log.d("pk", "onPageScrollStateChanged"); | |
316 | } | |
317 | ||
318 | @Override | |
319 | public void onPageScrolled(int arg0, float arg1, int arg2) { | |
320 | // TODO Auto-generated method stub | |
321 | Log.d("pk", "onPageScrolled"); | |
322 | } | |
323 | ||
324 | @Override | |
325 | public void onPageSelected(int arg0) { | |
326 | // TODO Auto-generated method stub | |
327 | Log.d("pk", "onPageSelected"); | |
328 | } | |
329 | } | |
330 | } |