Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.69 KB | None | 0 0
  1. package ather.radio.desistan;
  2.  
  3. import java.io.IOException;
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.app.ActionBar;
  8. import android.app.Fragment;
  9. import android.app.FragmentManager;
  10. import android.content.Context;
  11. import android.content.DialogInterface.OnClickListener;
  12. import android.content.Intent;
  13. import android.media.AudioManager;
  14. import android.media.MediaPlayer;
  15. import android.net.Uri;
  16. import android.os.Build;
  17. import android.os.Bundle;
  18. import android.view.Gravity;
  19. import android.view.LayoutInflater;
  20. import android.view.Menu;
  21. import android.view.MenuItem;
  22. import android.view.View;
  23. import android.view.ViewGroup;
  24. import android.support.v4.widget.DrawerLayout;
  25. import android.widget.ArrayAdapter;
  26. import android.widget.Button;
  27. import android.widget.ImageView;
  28.  
  29. import android.widget.TextView;
  30. import android.widget.Toast;
  31.  
  32.  
  33.      
  34.  
  35.  
  36. public class MainActivity extends Activity
  37.  implements NavigationDrawerFragment.NavigationDrawerCallbacks {
  38.  
  39.    
  40.    
  41.     /**
  42.      * Fragment managing the behaviors, interactions and presentation of the navigation drawer.
  43.      */
  44.     private NavigationDrawerFragment mNavigationDrawerFragment;
  45.  
  46.     /**
  47.      * Used to store the last screen title. For use in {@link #restoreActionBar()}.
  48.      */
  49.     private CharSequence mTitle;
  50.  
  51.     @Override
  52.     protected void onCreate(Bundle savedInstanceState) {
  53.         super.onCreate(savedInstanceState);
  54.         setContentView(R.layout.activity_main);
  55.      
  56.         mNavigationDrawerFragment = (NavigationDrawerFragment)
  57.                 getFragmentManager().findFragmentById(R.id.navigation_drawer);
  58.         mTitle = getTitle();
  59.  
  60.         // Set up the drawer.
  61.         mNavigationDrawerFragment.setUp(
  62.                 R.id.navigation_drawer,
  63.                 (DrawerLayout) findViewById(R.id.drawer_layout));
  64.     }
  65.  
  66.     @Override
  67.     public void onNavigationDrawerItemSelected(int position) {
  68.         // update the main content by replacing fragments
  69.         FragmentManager fragmentManager = getFragmentManager();
  70.         fragmentManager.beginTransaction()
  71.                 .replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
  72.                 .commit();
  73.     }
  74.  
  75.     public void onSectionAttached(int number) {
  76.         switch (number) {
  77.             case 1:
  78.                 mTitle = getString(R.string.title_section1);
  79.                 break;
  80.             case 2:
  81.                 mTitle = getString(R.string.title_section2);
  82.                 Toast.makeText(getApplicationContext(), "Like us on Facebook", Toast.LENGTH_LONG).show();
  83.                 Intent fb = new Intent(Intent.ACTION_VIEW);
  84.                 fb.setData(Uri.parse("https://www.facebook.com/RadioDesistan"));
  85.                 startActivity(fb);
  86.                 break;
  87.             case 3:
  88.                 mTitle = getString(R.string.title_section3);
  89.                 Toast.makeText(getApplicationContext(), "Follow us on Twitter", Toast.LENGTH_LONG).show();
  90.                 Intent twit = new Intent(Intent.ACTION_VIEW);
  91.                 twit.setData(Uri.parse("https://twitter.com/radiodesistan"));
  92.                 startActivity(twit);
  93.  
  94.                 break;
  95.                
  96.             case 4:
  97.                 mTitle = getString(R.string.title_section4);
  98.  Toast.makeText(getApplicationContext(), "Follow us on Instagram", Toast.LENGTH_LONG).show();
  99.                
  100.                 Intent ig = new Intent(Intent.ACTION_VIEW);
  101.                 ig.setData(Uri.parse("http://instagram.com/radiodesistan"));
  102.                 startActivity(ig);
  103.                
  104.                 break;
  105.         }
  106.     }
  107.  
  108.     public void restoreActionBar() {
  109.         ActionBar actionBar = getActionBar();
  110.         actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
  111.         actionBar.setDisplayShowTitleEnabled(true);
  112.         actionBar.setTitle(mTitle);
  113.     }
  114.  
  115.  
  116.     @Override
  117.     public boolean onCreateOptionsMenu(Menu menu) {
  118.         if (!mNavigationDrawerFragment.isDrawerOpen()) {
  119.             // Only show items in the action bar relevant to this screen
  120.             // if the drawer is not showing. Otherwise, let the drawer
  121.             // decide what to show in the action bar.
  122.             getMenuInflater().inflate(R.menu.main, menu);
  123.             restoreActionBar();
  124.             return true;
  125.         }
  126.         return super.onCreateOptionsMenu(menu);
  127.     }
  128.  
  129.     @Override
  130.     public boolean onOptionsItemSelected(MenuItem item) {
  131.         // Handle action bar item clicks here. The action bar will
  132.         // automatically handle clicks on the Home/Up button, so long
  133.         // as you specify a parent activity in AndroidManifest.xml.
  134.         int id = item.getItemId();
  135.         if (id == R.id.action_settings) {
  136.             finish();
  137.             System.exit(0);
  138.             return true;
  139.         }
  140.         if (id == R.id.action_about) {
  141.             Toast.makeText(this, "Radio Desistan is completely non profit non commercial Online Radio Station and a Social Hub for connecting Desi's World Wide which aims to serve the Desi community who understands Urdu/Hindi no matter where they are from\nThey might be from Pakistan, India, Bangladesh or Srilanka living in any part of the world. we wish to unite all desi's to a single platform spreading peace & love.", Toast.LENGTH_SHORT).show();
  142.             return true;
  143.         }
  144.         return super.onOptionsItemSelected(item);
  145.     }
  146.  
  147.     /**
  148.      * A placeholder fragment containing a simple view.
  149.      */
  150.     public static class PlaceholderFragment extends Fragment {
  151.         /**
  152.          * The fragment argument representing the section number for this
  153.          * fragment.
  154.          */
  155.         private static final String ARG_SECTION_NUMBER = "section_number";
  156.  
  157.         /**
  158.          * Returns a new instance of this fragment for the given section
  159.          * number.
  160.          */
  161.         public static PlaceholderFragment newInstance(int sectionNumber) {
  162.             PlaceholderFragment fragment = new PlaceholderFragment();
  163.             Bundle args = new Bundle();
  164.             args.putInt(ARG_SECTION_NUMBER, sectionNumber);
  165.             fragment.setArguments(args);
  166.             return fragment;
  167.         }
  168.  
  169.         public PlaceholderFragment() {
  170.         }
  171.  
  172.         @Override
  173.         public View onCreateView(LayoutInflater inflater, ViewGroup container,
  174.                 Bundle savedInstanceState) {
  175.             View rootView = inflater.inflate(R.layout.fragment_main, container, false);
  176.             return rootView;
  177.         }
  178.  
  179.         @Override
  180.         public void onAttach(Activity activity) {
  181.             super.onAttach(activity);
  182.             ((MainActivity) activity).onSectionAttached(
  183.                     getArguments().getInt(ARG_SECTION_NUMBER));
  184.         }
  185.     }
  186.  
  187.    
  188.    
  189.  
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement