Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. @Override
  2. protected void onCreate(Bundle savedInstanceState) {
  3. super.onCreate(savedInstanceState);
  4. setContentView(R.layout.navigation_main);
  5. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  6.  
  7. //View header=getLayoutInflater().inflate(R.layout.nav_header_main, null);
  8. imageView = (ImageView)findViewById(R.id.imageView1);
  9. image = dataBasehelper.getCompanyLogo();
  10. String newImage = ApiConstants.BaseApi + "/images/" + image;
  11. // Picasso.with(getApplicationContext()).load(newImage).into(imageView);
  12. URL url = null;
  13.  
  14. new LoadBitmap().execute(newImage);
  15.  
  16.  
  17. setSupportActionBar(toolbar);
  18. FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  19. fab.setOnClickListener(new View.OnClickListener() {
  20. @Override
  21. public void onClick(View view) {
  22. Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
  23. .setAction("Action", null).show();
  24. }
  25. });
  26.  
  27. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  28. ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
  29. this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  30. drawer.setDrawerListener(toggle);
  31. toggle.syncState();
  32.  
  33. navigationView = (NavigationView) findViewById(R.id.nav_view);
  34. navigationView.setNavigationItemSelectedListener(this);
  35.  
  36.  
  37.  
  38. }
  39.  
  40. public class LoadBitmap extends AsyncTask<String, String, String> {
  41.  
  42. JSONObject json = null;
  43.  
  44.  
  45. @Override
  46. protected void onPreExecute() {
  47. try{
  48.  
  49.  
  50.  
  51. }catch (Exception exp){}
  52. }
  53.  
  54. @Override
  55. protected String doInBackground(String... params) {
  56. try
  57. {
  58. String image= params[0];
  59. URL url = new URL(image);
  60. HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  61. connection.setDoInput(true);
  62. connection.connect();
  63. InputStream input = connection.getInputStream();
  64. myBitmap = BitmapFactory.decodeStream(input);
  65.  
  66. Drawable d = new BitmapDrawable(myBitmap);
  67. // navigationView.setItemBackground(d);
  68. return "";
  69.  
  70. }
  71. catch (Exception ex)
  72. {
  73. ex.printStackTrace();
  74. return "";
  75. }
  76.  
  77.  
  78. }
  79.  
  80.  
  81. @Override
  82. protected void onPostExecute(String result) {
  83.  
  84.  
  85. }
  86. }
  87.  
  88.  
  89. @Override
  90. public void onBackPressed() {
  91. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  92. if (drawer.isDrawerOpen(GravityCompat.START)) {
  93. drawer.closeDrawer(GravityCompat.START);
  94. } else {
  95. super.onBackPressed();
  96. }
  97. }
  98.  
  99. @Override
  100. public boolean onCreateOptionsMenu(Menu menu) {
  101. // Inflate the menu; this adds items to the action bar if it is present.
  102. getMenuInflater().inflate(R.menu.main, menu);
  103. return true;
  104. }
  105.  
  106. @Override
  107. public boolean onOptionsItemSelected(MenuItem item) {
  108. // Handle action bar item clicks here. The action bar will
  109. // automatically handle clicks on the Home/Up button, so long
  110. // as you specify a parent activity in AndroidManifest.xml.
  111. int id = item.getItemId();
  112.  
  113. //noinspection SimplifiableIfStatement
  114. if (id == R.id.action_settings) {
  115. return true;
  116. }
  117.  
  118. return super.onOptionsItemSelected(item);
  119. }
  120.  
  121. @SuppressWarnings("StatementWithEmptyBody")
  122. @Override
  123. public boolean onNavigationItemSelected(MenuItem item) {
  124. // Handle navigation view item clicks here.
  125. int id = item.getItemId();
  126.  
  127. if (id == R.id.nav_camera) {
  128. // Handle the camera action
  129. } else if (id == R.id.nav_gallery) {
  130.  
  131. } else if (id == R.id.nav_slideshow) {
  132.  
  133. } else if (id == R.id.nav_manage) {
  134.  
  135. } else if (id == R.id.nav_share) {
  136.  
  137. } else if (id == R.id.nav_send) {
  138.  
  139. }
  140.  
  141. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  142. drawer.closeDrawer(GravityCompat.START);
  143. return true;
  144. }
  145.  
  146. public Bitmap GetBitmapfromUrl(String scr) {
  147. try {
  148. URL url = new URL(scr);
  149. HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  150. connection.setDoInput(true);
  151. connection.connect();
  152. InputStream input = connection.getInputStream();
  153. Bitmap bmp = BitmapFactory.decodeStream(input);
  154. return bmp;
  155.  
  156.  
  157. } catch (Exception e) {
  158. // TODO Auto-generated catch block
  159. e.printStackTrace();
  160. return null;
  161.  
  162. }
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement