Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.68 KB | None | 0 0
  1. package com.customplay.secondscreen;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import org.json.JSONArray;
  6. import org.json.JSONException;
  7.  
  8. import android.app.Activity;
  9. import android.app.AlertDialog;
  10. import android.app.Fragment;
  11. import android.app.FragmentManager;
  12. import android.content.Context;
  13. import android.content.DialogInterface;
  14. import android.content.Intent;
  15. import android.content.res.TypedArray;
  16. import android.graphics.Typeface;
  17. import android.os.Bundle;
  18. import android.os.Handler;
  19. import android.os.Message;
  20. import android.support.v4.widget.DrawerLayout;
  21. import android.support.v7.app.ActionBarDrawerToggle;
  22. import android.util.DisplayMetrics;
  23. import android.util.Log;
  24. import android.view.LayoutInflater;
  25. import android.view.Menu;
  26. import android.view.MenuInflater;
  27. import android.view.MenuItem;
  28. import android.view.View;
  29. import android.view.ViewGroup;
  30. import android.view.inputmethod.InputMethodManager;
  31. import android.widget.AdapterView;
  32. import android.widget.BaseAdapter;
  33. import android.widget.Button;
  34. import android.widget.EditText;
  35. import android.widget.ImageView;
  36. import android.widget.LinearLayout;
  37. import android.widget.ListView;
  38. import android.widget.RelativeLayout;
  39. import android.widget.TextView;
  40. import android.widget.Toast;
  41.  
  42. import com.squareup.picasso.Picasso;
  43.  
  44. public class Home extends Activity implements TaskCompleted {
  45.  
  46. private String TAG = "CUSTOMPLAY:";
  47.  
  48. // Define the number of box art per row visible when the carousel is first
  49. // shown.
  50.  
  51. private static final float INITIAL_ITEMS_COUNT = 7;
  52.  
  53. // The Movie Database API Key
  54.  
  55. private static String API_KEY = "2842da55488d33ac0b3b9f9f88759e18";
  56.  
  57. // The Movie Database URL
  58.  
  59. private static String URL = "https://api.themoviedb.org/3/";
  60.  
  61. // Carousel container layouts
  62.  
  63. private LinearLayout mCarouselContainer1;
  64. private LinearLayout mCarouselContainer2;
  65. private LinearLayout mCarouselContainer3;
  66. private LinearLayout mCarouselContainer4;
  67. private LinearLayout mCarouselContainer5;
  68.  
  69. private static String title1;
  70. private static String title2;
  71. private static String title3;
  72. private static String title4;
  73. private static String title5;
  74. private static String title6;
  75. private static String title7;
  76. private static String title8;
  77. private static String title9;
  78. private static String title10;
  79. private static String title11;
  80. private static String title12;
  81. private static String title13;
  82. private static String title14;
  83. private static String title15;
  84. private static String title16;
  85. private static String title17;
  86. private static String title18;
  87. private static String title19;
  88. private static String title20;
  89. private static String title21;
  90. private static String title22;
  91. private static String title23;
  92. private static String title24;
  93. // JSON Node names
  94. private static final String TAG_CONTACTS = "contacts";
  95. private static final String TAG_ID = "id";
  96. private static final String TAG_NAME = "title";
  97. private static final String TAG_EMAIL = "year";
  98. private static final String TAG_ADDRESS = "rating";
  99. private static final String TAG_GENDER = "genres";
  100. private static final String TAG_PHONE = "boxart";
  101. private static final String TAG_PHONE_MOBILE = "background";
  102. private static final String TAG_PHONE_HOME = "version";
  103. private static final String TAG_PHONE_OFFICE = "datapack";
  104.  
  105. // Implement Hamburger Menu Items
  106.  
  107.  
  108.  
  109. ListView mDrawerList;
  110. RelativeLayout mDrawerPane;
  111. private ActionBarDrawerToggle mDrawerToggle;
  112. private android.support.v4.widget.DrawerLayout mDrawerLayout;
  113.  
  114. ArrayList<NavItem> mNavItems = new ArrayList<NavItem>();
  115.  
  116. // contacts JSONArray
  117. JSONArray contacts = null;
  118.  
  119. Boolean connected = false;
  120. public static Context mContext;
  121. Globals sharedData = Globals.getInstance();
  122.  
  123. @Override
  124. protected void onCreate(Bundle savedInstanceState) {
  125. super.onCreate(savedInstanceState);
  126. setTitle(R.string.AppTitle);
  127.  
  128. setContentView(R.layout.ss_home);
  129.  
  130. mNavItems.add(new NavItem("Home", "Meetup destination", R.drawable.icon_music_top_center));
  131. mNavItems.add(new NavItem("Preferences", "Change your preferences", R.drawable.icon_vehicles_top_center));
  132. mNavItems.add(new NavItem("About", "Get to know about us", R.drawable.icon_weapons_top_center));
  133.  
  134. // DrawerLayout
  135. mDrawerLayout = (android.support.v4.widget.DrawerLayout) findViewById(R.id.drawerLayout);
  136.  
  137. // Populate the Navigtion Drawer with options
  138. mDrawerPane = (RelativeLayout) findViewById(R.id.drawerPane);
  139. mDrawerList = (ListView) findViewById(R.id.navList);
  140. DrawerListAdapter adapter = new DrawerListAdapter(this, mNavItems);
  141. mDrawerList.setAdapter(adapter);
  142.  
  143. // Drawer Item click listeners
  144. mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  145. @Override
  146. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  147. selectItemFromDrawer(position);
  148. }
  149. });
  150.  
  151. // More info: http://codetheory.in/difference-between-setdisplayhomeasupenabled-sethomebuttonenabled-and-setdisplayshowhomeenabled/
  152. getActionBar().setDisplayHomeAsUpEnabled(true);
  153. String url = "http://xxx.168.1.xxx/index.php";
  154. new MyAsyncTask(this).execute(url);
  155.  
  156. String n = sharedData.getValue();
  157.  
  158. Typeface defaultFont = Typeface.createFromAsset(getAssets(),
  159. "fonts/PN.otf");
  160. Button buttona = (Button) findViewById(R.id.buttona);
  161. buttona.setTypeface(defaultFont);
  162. Button buttonb = (Button) findViewById(R.id.buttonb);
  163. buttonb.setTypeface(defaultFont);
  164. Button buttonc = (Button) findViewById(R.id.buttonc);
  165. buttonc.setTypeface(defaultFont);
  166. Button buttond = (Button) findViewById(R.id.buttond);
  167. buttond.setTypeface(defaultFont);
  168. Button buttone = (Button) findViewById(R.id.buttone);
  169. buttone.setTypeface(defaultFont);
  170. Button buttonf = (Button) findViewById(R.id.buttonf);
  171. buttonf.setTypeface(defaultFont);
  172. Button buttong = (Button) findViewById(R.id.buttong);
  173. buttong.setTypeface(defaultFont);
  174. Button buttonh = (Button) findViewById(R.id.buttonh);
  175. buttonh.setTypeface(defaultFont);
  176. Button buttoni = (Button) findViewById(R.id.buttoni);
  177. buttoni.setTypeface(defaultFont);
  178. Button buttonj = (Button) findViewById(R.id.buttonj);
  179. buttonj.setTypeface(defaultFont);
  180. Button buttonk = (Button) findViewById(R.id.buttonk);
  181. buttonk.setTypeface(defaultFont);
  182. Button buttonl = (Button) findViewById(R.id.buttonl);
  183. buttonl.setTypeface(defaultFont);
  184. Button buttonm = (Button) findViewById(R.id.buttonm);
  185. buttonm.setTypeface(defaultFont);
  186. Button buttonn = (Button) findViewById(R.id.buttonn);
  187. buttonn.setTypeface(defaultFont);
  188. Button buttono = (Button) findViewById(R.id.buttono);
  189. buttono.setTypeface(defaultFont);
  190. Button buttonp = (Button) findViewById(R.id.buttonp);
  191. buttonp.setTypeface(defaultFont);
  192. Button buttonq = (Button) findViewById(R.id.buttonq);
  193. buttonq.setTypeface(defaultFont);
  194. Button buttonr = (Button) findViewById(R.id.buttonr);
  195. buttonr.setTypeface(defaultFont);
  196. Button buttons = (Button) findViewById(R.id.buttons);
  197. buttons.setTypeface(defaultFont);
  198. Button buttont = (Button) findViewById(R.id.buttont);
  199. buttont.setTypeface(defaultFont);
  200. Button buttonu = (Button) findViewById(R.id.buttonu);
  201. buttonu.setTypeface(defaultFont);
  202. Button buttonv = (Button) findViewById(R.id.buttonv);
  203. buttonv.setTypeface(defaultFont);
  204. Button buttonw = (Button) findViewById(R.id.buttonw);
  205. buttonw.setTypeface(defaultFont);
  206. Button buttonx = (Button) findViewById(R.id.buttonx);
  207. buttonx.setTypeface(defaultFont);
  208. Button buttony = (Button) findViewById(R.id.buttony);
  209. buttony.setTypeface(defaultFont);
  210. Button buttonz = (Button) findViewById(R.id.buttonz);
  211. buttonz.setTypeface(defaultFont);
  212. Button button1 = (Button) findViewById(R.id.button1);
  213. button1.setTypeface(defaultFont);
  214. TextView textView1 = (TextView) findViewById(R.id.textView1);
  215. textView1.setTypeface(defaultFont);
  216.  
  217. // Check the users internet connection
  218. // checkConnection();
  219.  
  220. // //Hide The Keyboard
  221. EditText myEditText = (EditText) findViewById(R.id.editText1);
  222. myEditText.setTypeface(defaultFont);
  223. InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
  224. imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
  225.  
  226. // Create Carousel's to contain the movie titles
  227. mCarouselContainer1 = (LinearLayout) findViewById(R.id.carousel1);
  228. mCarouselContainer2 = (LinearLayout) findViewById(R.id.carousel2);
  229. mCarouselContainer3 = (LinearLayout) findViewById(R.id.carousel3);
  230. mCarouselContainer4 = (LinearLayout) findViewById(R.id.carousel4);
  231. mCarouselContainer5 = (LinearLayout) findViewById(R.id.carousel5);
  232. int title1 = 137113;
  233. int title2 = 13804;
  234. int title3 = 82992;
  235. int title4 = 9799;
  236. int title5 = 9615;
  237. int title6 = 51497;
  238. int title7 = 238;
  239. int title8 = 70160;
  240. int title9 = 101299;
  241. int title10 = 1858;
  242. int title11 = 91314;
  243. int title12 = 38356;
  244. int title13 = 100402;
  245. int title14 = 24428;
  246. int title15 = 1271;
  247. int title16 = 62;
  248. int title17 = 12155;
  249. int title18 = 348;
  250. int title19 = 578;
  251. int title20 = 127585;
  252. int title21 = 37724;
  253. int title22 = 137106;
  254. int title23 = 57158;
  255. int title24 = 49026;
  256.  
  257. mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,R.drawable.ic_launcher, R.string.hello_world) {
  258.  
  259. @Override
  260. public void onDrawerOpened(View drawerView) {
  261. super.onDrawerOpened(drawerView);
  262.  
  263. invalidateOptionsMenu();
  264. }
  265.  
  266. @Override
  267. public void onDrawerClosed(View drawerView) {
  268. super.onDrawerClosed(drawerView);
  269. Log.d(TAG, "onDrawerClosed: " + getTitle());
  270.  
  271. invalidateOptionsMenu();
  272. }
  273. };
  274.  
  275. mDrawerLayout.setDrawerListener(mDrawerToggle);
  276.  
  277. }
  278.  
  279.  
  280.  
  281.  
  282. /*
  283. * Called when a particular item from the navigation drawer
  284. * is selected.
  285. * */
  286. private void selectItemFromDrawer(int position) {
  287. Fragment fragment = new PreferencesFragment();
  288.  
  289. FragmentManager fragmentManager = getFragmentManager();
  290. fragmentManager.beginTransaction()
  291. .replace(R.id.mainContent, fragment)
  292. .commit();
  293.  
  294. mDrawerList.setItemChecked(position, true);
  295. setTitle(mNavItems.get(position).mTitle);
  296.  
  297. // Close the drawer
  298. mDrawerLayout.closeDrawer(mDrawerPane);
  299. }
  300.  
  301.  
  302.  
  303.  
  304. // CHECK NETWORK STATUS //CHECK CONNECTION METHOD CALLED IN ONCREATE
  305. public void checkConnection() {
  306.  
  307. connected = WebData.getStatus(mContext);
  308. if (connected) {
  309. Log.i(TAG + "NETWORK CONNECTED - INTERNET DETECTED",
  310. WebData.getType(mContext));
  311.  
  312. } else {
  313. // Add notation to the logs to ensure the error is documented
  314. Log.i(TAG + "NETWORK CONNECTION FAILED - NO INTERNET DETECTED",
  315. WebData.getType(mContext));
  316. // Display dialog box for no connection
  317. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  318. builder.setMessage(
  319. "No Internet Connection Detected. Check your connection and try again.")
  320. .setCancelable(false)
  321. .setPositiveButton("OK",
  322. new DialogInterface.OnClickListener() {
  323. @Override
  324. public void onClick(DialogInterface dialog,
  325. int id) {
  326. dialog.cancel();
  327. }
  328. });
  329. AlertDialog alert = builder.create();
  330. alert.show();
  331.  
  332. }
  333. }
  334.  
  335. @Override
  336. protected void onPostCreate(Bundle savedInstanceState) {
  337. super.onPostCreate(savedInstanceState);
  338. mDrawerToggle.syncState();
  339. // Compute the width of a carousel item based on the screen width and
  340. // number of initial items.
  341. final DisplayMetrics displayMetrics = new DisplayMetrics();
  342. getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
  343. final int imageWidth = (int) (displayMetrics.widthPixels / INITIAL_ITEMS_COUNT);
  344.  
  345. // Get the array of box art
  346. final TypedArray titleResourcesTypedArray = getResources()
  347. .obtainTypedArray(R.array.title_array1);
  348. final TypedArray titleResourcesTypedArray2 = getResources()
  349. .obtainTypedArray(R.array.title_array2);
  350.  
  351. final TypedArray titleResourcesTypedArray3 = getResources()
  352. .obtainTypedArray(R.array.title_array3);
  353. final TypedArray titleResourcesTypedArray4 = getResources()
  354. .obtainTypedArray(R.array.title_array4);
  355. final TypedArray titleResourcesTypedArray5 = getResources()
  356. .obtainTypedArray(R.array.title_array5);
  357. // Populate the carousel with boxart
  358. ImageView imageItem;
  359. ImageView imageItem2;
  360. ImageView imageItem3;
  361. ImageView imageItem4;
  362. ImageView imageItem5;
  363.  
  364. for (int i = 0; i < titleResourcesTypedArray2.length(); ++i) {
  365.  
  366. imageItem2 = new ImageView(this);
  367.  
  368. imageItem2.setBackgroundResource(R.drawable.shadow);
  369.  
  370. imageItem2.setImageResource(titleResourcesTypedArray2
  371. .getResourceId(i, -1));
  372.  
  373. imageItem2.setLayoutParams(new LinearLayout.LayoutParams(
  374. imageWidth, imageWidth));
  375.  
  376. mCarouselContainer2.addView(imageItem2);
  377. }
  378. for (int i = 0; i < titleResourcesTypedArray3.length(); ++i) {
  379.  
  380. imageItem3 = new ImageView(this);
  381.  
  382. imageItem3.setBackgroundResource(R.drawable.shadow);
  383.  
  384. imageItem3.setImageResource(titleResourcesTypedArray3
  385. .getResourceId(i, -1));
  386.  
  387. imageItem3.setLayoutParams(new LinearLayout.LayoutParams(
  388. imageWidth, imageWidth));
  389.  
  390. mCarouselContainer3.addView(imageItem3);
  391. }
  392. for (int i = 0; i < titleResourcesTypedArray4.length(); ++i) {
  393.  
  394. imageItem4 = new ImageView(this);
  395.  
  396. imageItem4.setBackgroundResource(R.drawable.shadow);
  397.  
  398. imageItem4.setImageResource(titleResourcesTypedArray4
  399. .getResourceId(i, -1));
  400.  
  401. imageItem4.setLayoutParams(new LinearLayout.LayoutParams(
  402. imageWidth, imageWidth));
  403.  
  404. mCarouselContainer4.addView(imageItem4);
  405. }
  406. for (int i = 0; i < titleResourcesTypedArray5.length(); ++i) {
  407.  
  408. imageItem5 = new ImageView(this);
  409.  
  410. imageItem5.setBackgroundResource(R.drawable.shadow);
  411.  
  412. imageItem5.setImageResource(titleResourcesTypedArray5
  413. .getResourceId(i, -1));
  414.  
  415. imageItem5.setLayoutParams(new LinearLayout.LayoutParams(
  416. imageWidth, imageWidth));
  417.  
  418. mCarouselContainer5.addView(imageItem5);
  419.  
  420. }
  421.  
  422. }
  423.  
  424. @Override
  425. public boolean onCreateOptionsMenu(Menu menu) {
  426. // Inflate the menu; this adds items to the action bar
  427. MenuInflater inflater = getMenuInflater();
  428. inflater.inflate(R.menu.activity_main_actions, menu);
  429.  
  430. return super.onCreateOptionsMenu(menu);
  431. }
  432.  
  433. @Override
  434. public boolean onOptionsItemSelected(MenuItem item) {
  435. // Handle action bar item clicks here
  436.  
  437. // int id = item.getItemId();
  438. // if (id == R.id.icon_settings_top_right) {
  439. // Intent intent = new Intent(Home.this, SyncOptions.class);
  440. // startActivity(intent);
  441. // return true;
  442. // }
  443. //
  444. // if (id == R.id.icon_music_top_center) {
  445. // Intent intent = new Intent(Home.this, Music.class);
  446. // startActivity(intent);
  447. // return true;
  448. // }
  449. //
  450. // if (id == R.id.icon_who_top_center) {
  451. // Intent intent = new Intent(Home.this, MainActivity.class);
  452. // startActivity(intent);
  453. // return true;
  454. // }
  455. //
  456. // if (id == R.id.icon_weapons_top_center) {
  457. // Intent intent = new Intent(Home.this, Weapons.class);
  458. // startActivity(intent);
  459. // return true;
  460. // }
  461. //
  462. // if (id == R.id.icon_vehicles_top_center) {
  463. // Intent intent = new Intent(Home.this, Vehicles.class);
  464. // startActivity(intent);
  465. // return true;
  466. // }
  467. //
  468. // if (id == R.id.action_settings) {
  469. // Intent intent = new Intent(Home.this, RestFulWebservice.class);
  470. // startActivity(intent);
  471. // return true;
  472. // }
  473. return super.onOptionsItemSelected(item);
  474. }
  475.  
  476. @Override
  477. public void onWindowFocusChanged(boolean hasFocus) {
  478. super.onWindowFocusChanged(hasFocus);
  479. // When the window loses focus (e.g. the action overflow is shown),
  480. // cancel any pending hide action. When the window gains focus,
  481. // hide the system UI.
  482. if (hasFocus) {
  483. delayedHide(300);
  484. } else {
  485. mHideHandler.removeMessages(0);
  486. }
  487. }
  488.  
  489. private void hideSystemUI() {
  490. // getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
  491. // | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
  492. // | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
  493. // | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
  494. // | View.SYSTEM_UI_FLAG_FULLSCREEN
  495. // | View.SYSTEM_UI_FLAG_LOW_PROFILE
  496. // | View.SYSTEM_UI_FLAG_IMMERSIVE);
  497. }
  498.  
  499. private void showSystemUI() {
  500. getWindow().getDecorView().setSystemUiVisibility(
  501. View.SYSTEM_UI_FLAG_LAYOUT_STABLE
  502. | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
  503. | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
  504. }
  505.  
  506. private final Handler mHideHandler = new Handler() {
  507. @Override
  508. public void handleMessage(Message msg) {
  509. hideSystemUI();
  510. }
  511. };
  512.  
  513. private void delayedHide(int delayMillis) {
  514. mHideHandler.removeMessages(0);
  515. mHideHandler.sendEmptyMessageDelayed(0, delayMillis);
  516. }
  517.  
  518. public void onTaskComplete(String content) {
  519. Toast.makeText(this, "The result is " + content, Toast.LENGTH_LONG)
  520. .show();
  521.  
  522. if (content != null) {
  523. try {
  524.  
  525. JSONArray jArrayObject;
  526. try {
  527. jArrayObject = new JSONArray(content);
  528. for (int i = 0; i < jArrayObject.length(); i++) {
  529. Log.d("id==",
  530. jArrayObject.getJSONObject(i).getString("id")
  531. .toString());
  532. Log.d("title==", jArrayObject.getJSONObject(i)
  533. .getString("title").toString());
  534. Log.d("year==", jArrayObject.getJSONObject(i)
  535. .getString("year").toString());
  536. Log.d("rating==", jArrayObject.getJSONObject(i)
  537. .getString("rating").toString());
  538. Log.d("genres==", jArrayObject.getJSONObject(i)
  539. .getString("genres").toString());
  540.  
  541. ImageView imageItem;
  542.  
  543. imageItem = new ImageView(this);
  544.  
  545. // Set the shadow background
  546. imageItem.setTag(R.drawable.shadow);
  547. // Set the ID tag
  548. imageItem.setTag(i);
  549. final DisplayMetrics displayMetrics = new DisplayMetrics();
  550. getWindowManager().getDefaultDisplay().getMetrics(
  551. displayMetrics);
  552. final int imageWidth = (int) (displayMetrics.widthPixels / INITIAL_ITEMS_COUNT);
  553.  
  554. // Set the image view resource
  555.  
  556. // Set the size of the image view to the previously
  557. // computed value
  558. imageItem
  559. .setLayoutParams(new LinearLayout.LayoutParams(
  560. imageWidth, imageWidth));
  561.  
  562. imageItem.setTag(i);
  563.  
  564. // / Add image to the carousel
  565. mCarouselContainer1.addView(imageItem);
  566.  
  567.  
  568. // Pull BoxArt Photo
  569. Picasso.with(this)
  570. .load(jArrayObject.getJSONObject(i)
  571. .getString("boxart").toString())
  572. .into(imageItem);
  573. // TO DO MONDAY - REWORK THIS CODE (AVOIDING MEMORY LEAK ISSUES)
  574. // http://stackoverflow.com/questions/23740307/load-large-images-with-picasso-and-custom-transform-object
  575. // private static final int MAX_WIDTH = 1024;
  576. // private static final int MAX_HEIGHT = 768;
  577. //
  578. // int size = (int) Math.ceil(Math.sqrt(MAX_WIDTH * MAX_HEIGHT));
  579. //
  580. // // Loads given image
  581. // Picasso.with(imageView.getContext())
  582. // .load(imagePath)
  583. // .transform(new BitmapTransform(MAX_WIDTH, MAX_HEIGHT))
  584. // .skipMemoryCache()
  585. // .resize(size, size)
  586. // .centerInside()
  587. // .into(imageView);
  588.  
  589.  
  590.  
  591. Log.d("mapdate==", jArrayObject.getJSONObject(i)
  592. .getString("mapdate").toString());
  593.  
  594. imageItem
  595. .setOnClickListener(new View.OnClickListener() {
  596.  
  597. // create an onClick Listener
  598. @Override
  599. public void onClick(View v) {
  600.  
  601. Intent intent = new Intent(Home.this,
  602. Download.class);
  603. intent.putExtra("coverArt", v.getTag()
  604. .toString());
  605. startActivity(intent);
  606. // v.getTag();
  607.  
  608. }
  609. });
  610.  
  611. }
  612.  
  613. } catch (JSONException e) {
  614. // TODO Auto-generated catch block
  615. e.printStackTrace();
  616. }
  617.  
  618. } finally {
  619. }
  620. }
  621. }
  622.  
  623. private void getBoxart() {
  624. // TODO Auto-generated method stub
  625. new DownloadImageTask((ImageView) findViewById(R.id.imageView1))
  626. .execute("http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png");
  627. }
  628.  
  629. @Override
  630. protected void onDestroy() {
  631. super.onDestroy();
  632. // Perform Bitmap Scaling to Conserve Memory
  633. unbindDrawables(findViewById(R.id.drawerLayout));
  634. System.gc();
  635. }
  636.  
  637. // Perform Bitmap Scaling to Conserve Memory
  638. private void unbindDrawables(View view) {
  639. if (view.getBackground() != null) {
  640. view.getBackground().setCallback(null);
  641. }
  642. if (view instanceof ViewGroup) {
  643. for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
  644. unbindDrawables(((ViewGroup) view).getChildAt(i));
  645. }
  646. ((ViewGroup) view).removeAllViews();
  647. }
  648. }
  649.  
  650.  
  651. // Create Custom Hamburger Menu
  652. class NavItem {
  653. String mTitle;
  654. String mSubtitle;
  655. int mIcon;
  656.  
  657. public NavItem(String title, String subtitle, int icon) {
  658. mTitle = title;
  659. mSubtitle = subtitle;
  660. mIcon = icon;
  661. }
  662. }
  663.  
  664.  
  665.  
  666.  
  667. class DrawerListAdapter extends BaseAdapter {
  668.  
  669. Context mContext;
  670. ArrayList<NavItem> mNavItems;
  671.  
  672. public DrawerListAdapter(Context context, ArrayList<NavItem> navItems) {
  673. mContext = context;
  674. mNavItems = navItems;
  675. }
  676.  
  677. @Override
  678. public int getCount() {
  679. return mNavItems.size();
  680. }
  681.  
  682. @Override
  683. public Object getItem(int position) {
  684. return mNavItems.get(position);
  685. }
  686.  
  687. @Override
  688. public long getItemId(int position) {
  689. return 0;
  690. }
  691.  
  692. @Override
  693. public View getView(int position, View convertView, ViewGroup parent) {
  694. View view;
  695.  
  696. if (convertView == null) {
  697. LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  698. view = inflater.inflate(R.layout.drawer_item, null);
  699. }
  700. else {
  701. view = convertView;
  702. }
  703.  
  704. TextView titleView = (TextView) view.findViewById(R.id.title);
  705. TextView subtitleView = (TextView) view.findViewById(R.id.subTitle);
  706. ImageView iconView = (ImageView) view.findViewById(R.id.icon);
  707.  
  708. titleView.setText( mNavItems.get(position).mTitle );
  709. subtitleView.setText( mNavItems.get(position).mSubtitle );
  710. iconView.setImageResource(mNavItems.get(position).mIcon);
  711.  
  712. return view;
  713. }
  714. }
  715.  
  716.  
  717.  
  718. // Called when invalidateOptionsMenu() is invoked
  719. public boolean onPrepareOptionsMenu(Menu menu) {
  720. // If the nav drawer is open, hide action items related to the content view
  721. boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
  722. menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
  723. return super.onPrepareOptionsMenu(menu);
  724. }
  725.  
  726.  
  727.  
  728.  
  729. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement