Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.customplay.secondscreen;
- import java.util.ArrayList;
- import org.json.JSONArray;
- import org.json.JSONException;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.app.Fragment;
- import android.app.FragmentManager;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.res.TypedArray;
- import android.graphics.Typeface;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.Message;
- import android.support.v4.widget.DrawerLayout;
- import android.support.v7.app.ActionBarDrawerToggle;
- import android.util.DisplayMetrics;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.Menu;
- import android.view.MenuInflater;
- import android.view.MenuItem;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.inputmethod.InputMethodManager;
- import android.widget.AdapterView;
- import android.widget.BaseAdapter;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.ListView;
- import android.widget.RelativeLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.squareup.picasso.Picasso;
- public class Home extends Activity implements TaskCompleted {
- private String TAG = "CUSTOMPLAY:";
- // Define the number of box art per row visible when the carousel is first
- // shown.
- private static final float INITIAL_ITEMS_COUNT = 7;
- // The Movie Database API Key
- private static String API_KEY = "2842da55488d33ac0b3b9f9f88759e18";
- // The Movie Database URL
- private static String URL = "https://api.themoviedb.org/3/";
- // Carousel container layouts
- private LinearLayout mCarouselContainer1;
- private LinearLayout mCarouselContainer2;
- private LinearLayout mCarouselContainer3;
- private LinearLayout mCarouselContainer4;
- private LinearLayout mCarouselContainer5;
- private static String title1;
- private static String title2;
- private static String title3;
- private static String title4;
- private static String title5;
- private static String title6;
- private static String title7;
- private static String title8;
- private static String title9;
- private static String title10;
- private static String title11;
- private static String title12;
- private static String title13;
- private static String title14;
- private static String title15;
- private static String title16;
- private static String title17;
- private static String title18;
- private static String title19;
- private static String title20;
- private static String title21;
- private static String title22;
- private static String title23;
- private static String title24;
- // JSON Node names
- private static final String TAG_CONTACTS = "contacts";
- private static final String TAG_ID = "id";
- private static final String TAG_NAME = "title";
- private static final String TAG_EMAIL = "year";
- private static final String TAG_ADDRESS = "rating";
- private static final String TAG_GENDER = "genres";
- private static final String TAG_PHONE = "boxart";
- private static final String TAG_PHONE_MOBILE = "background";
- private static final String TAG_PHONE_HOME = "version";
- private static final String TAG_PHONE_OFFICE = "datapack";
- // Implement Hamburger Menu Items
- ListView mDrawerList;
- RelativeLayout mDrawerPane;
- private ActionBarDrawerToggle mDrawerToggle;
- private android.support.v4.widget.DrawerLayout mDrawerLayout;
- ArrayList<NavItem> mNavItems = new ArrayList<NavItem>();
- // contacts JSONArray
- JSONArray contacts = null;
- Boolean connected = false;
- public static Context mContext;
- Globals sharedData = Globals.getInstance();
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setTitle(R.string.AppTitle);
- setContentView(R.layout.ss_home);
- mNavItems.add(new NavItem("Home", "Meetup destination", R.drawable.icon_music_top_center));
- mNavItems.add(new NavItem("Preferences", "Change your preferences", R.drawable.icon_vehicles_top_center));
- mNavItems.add(new NavItem("About", "Get to know about us", R.drawable.icon_weapons_top_center));
- // DrawerLayout
- mDrawerLayout = (android.support.v4.widget.DrawerLayout) findViewById(R.id.drawerLayout);
- // Populate the Navigtion Drawer with options
- mDrawerPane = (RelativeLayout) findViewById(R.id.drawerPane);
- mDrawerList = (ListView) findViewById(R.id.navList);
- DrawerListAdapter adapter = new DrawerListAdapter(this, mNavItems);
- mDrawerList.setAdapter(adapter);
- // Drawer Item click listeners
- mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- selectItemFromDrawer(position);
- }
- });
- // More info: http://codetheory.in/difference-between-setdisplayhomeasupenabled-sethomebuttonenabled-and-setdisplayshowhomeenabled/
- getActionBar().setDisplayHomeAsUpEnabled(true);
- String url = "http://xxx.168.1.xxx/index.php";
- new MyAsyncTask(this).execute(url);
- String n = sharedData.getValue();
- Typeface defaultFont = Typeface.createFromAsset(getAssets(),
- "fonts/PN.otf");
- Button buttona = (Button) findViewById(R.id.buttona);
- buttona.setTypeface(defaultFont);
- Button buttonb = (Button) findViewById(R.id.buttonb);
- buttonb.setTypeface(defaultFont);
- Button buttonc = (Button) findViewById(R.id.buttonc);
- buttonc.setTypeface(defaultFont);
- Button buttond = (Button) findViewById(R.id.buttond);
- buttond.setTypeface(defaultFont);
- Button buttone = (Button) findViewById(R.id.buttone);
- buttone.setTypeface(defaultFont);
- Button buttonf = (Button) findViewById(R.id.buttonf);
- buttonf.setTypeface(defaultFont);
- Button buttong = (Button) findViewById(R.id.buttong);
- buttong.setTypeface(defaultFont);
- Button buttonh = (Button) findViewById(R.id.buttonh);
- buttonh.setTypeface(defaultFont);
- Button buttoni = (Button) findViewById(R.id.buttoni);
- buttoni.setTypeface(defaultFont);
- Button buttonj = (Button) findViewById(R.id.buttonj);
- buttonj.setTypeface(defaultFont);
- Button buttonk = (Button) findViewById(R.id.buttonk);
- buttonk.setTypeface(defaultFont);
- Button buttonl = (Button) findViewById(R.id.buttonl);
- buttonl.setTypeface(defaultFont);
- Button buttonm = (Button) findViewById(R.id.buttonm);
- buttonm.setTypeface(defaultFont);
- Button buttonn = (Button) findViewById(R.id.buttonn);
- buttonn.setTypeface(defaultFont);
- Button buttono = (Button) findViewById(R.id.buttono);
- buttono.setTypeface(defaultFont);
- Button buttonp = (Button) findViewById(R.id.buttonp);
- buttonp.setTypeface(defaultFont);
- Button buttonq = (Button) findViewById(R.id.buttonq);
- buttonq.setTypeface(defaultFont);
- Button buttonr = (Button) findViewById(R.id.buttonr);
- buttonr.setTypeface(defaultFont);
- Button buttons = (Button) findViewById(R.id.buttons);
- buttons.setTypeface(defaultFont);
- Button buttont = (Button) findViewById(R.id.buttont);
- buttont.setTypeface(defaultFont);
- Button buttonu = (Button) findViewById(R.id.buttonu);
- buttonu.setTypeface(defaultFont);
- Button buttonv = (Button) findViewById(R.id.buttonv);
- buttonv.setTypeface(defaultFont);
- Button buttonw = (Button) findViewById(R.id.buttonw);
- buttonw.setTypeface(defaultFont);
- Button buttonx = (Button) findViewById(R.id.buttonx);
- buttonx.setTypeface(defaultFont);
- Button buttony = (Button) findViewById(R.id.buttony);
- buttony.setTypeface(defaultFont);
- Button buttonz = (Button) findViewById(R.id.buttonz);
- buttonz.setTypeface(defaultFont);
- Button button1 = (Button) findViewById(R.id.button1);
- button1.setTypeface(defaultFont);
- TextView textView1 = (TextView) findViewById(R.id.textView1);
- textView1.setTypeface(defaultFont);
- // Check the users internet connection
- // checkConnection();
- // //Hide The Keyboard
- EditText myEditText = (EditText) findViewById(R.id.editText1);
- myEditText.setTypeface(defaultFont);
- InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
- // Create Carousel's to contain the movie titles
- mCarouselContainer1 = (LinearLayout) findViewById(R.id.carousel1);
- mCarouselContainer2 = (LinearLayout) findViewById(R.id.carousel2);
- mCarouselContainer3 = (LinearLayout) findViewById(R.id.carousel3);
- mCarouselContainer4 = (LinearLayout) findViewById(R.id.carousel4);
- mCarouselContainer5 = (LinearLayout) findViewById(R.id.carousel5);
- int title1 = 137113;
- int title2 = 13804;
- int title3 = 82992;
- int title4 = 9799;
- int title5 = 9615;
- int title6 = 51497;
- int title7 = 238;
- int title8 = 70160;
- int title9 = 101299;
- int title10 = 1858;
- int title11 = 91314;
- int title12 = 38356;
- int title13 = 100402;
- int title14 = 24428;
- int title15 = 1271;
- int title16 = 62;
- int title17 = 12155;
- int title18 = 348;
- int title19 = 578;
- int title20 = 127585;
- int title21 = 37724;
- int title22 = 137106;
- int title23 = 57158;
- int title24 = 49026;
- mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,R.drawable.ic_launcher, R.string.hello_world) {
- @Override
- public void onDrawerOpened(View drawerView) {
- super.onDrawerOpened(drawerView);
- invalidateOptionsMenu();
- }
- @Override
- public void onDrawerClosed(View drawerView) {
- super.onDrawerClosed(drawerView);
- Log.d(TAG, "onDrawerClosed: " + getTitle());
- invalidateOptionsMenu();
- }
- };
- mDrawerLayout.setDrawerListener(mDrawerToggle);
- }
- /*
- * Called when a particular item from the navigation drawer
- * is selected.
- * */
- private void selectItemFromDrawer(int position) {
- Fragment fragment = new PreferencesFragment();
- FragmentManager fragmentManager = getFragmentManager();
- fragmentManager.beginTransaction()
- .replace(R.id.mainContent, fragment)
- .commit();
- mDrawerList.setItemChecked(position, true);
- setTitle(mNavItems.get(position).mTitle);
- // Close the drawer
- mDrawerLayout.closeDrawer(mDrawerPane);
- }
- // CHECK NETWORK STATUS //CHECK CONNECTION METHOD CALLED IN ONCREATE
- public void checkConnection() {
- connected = WebData.getStatus(mContext);
- if (connected) {
- Log.i(TAG + "NETWORK CONNECTED - INTERNET DETECTED",
- WebData.getType(mContext));
- } else {
- // Add notation to the logs to ensure the error is documented
- Log.i(TAG + "NETWORK CONNECTION FAILED - NO INTERNET DETECTED",
- WebData.getType(mContext));
- // Display dialog box for no connection
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setMessage(
- "No Internet Connection Detected. Check your connection and try again.")
- .setCancelable(false)
- .setPositiveButton("OK",
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog,
- int id) {
- dialog.cancel();
- }
- });
- AlertDialog alert = builder.create();
- alert.show();
- }
- }
- @Override
- protected void onPostCreate(Bundle savedInstanceState) {
- super.onPostCreate(savedInstanceState);
- mDrawerToggle.syncState();
- // Compute the width of a carousel item based on the screen width and
- // number of initial items.
- final DisplayMetrics displayMetrics = new DisplayMetrics();
- getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
- final int imageWidth = (int) (displayMetrics.widthPixels / INITIAL_ITEMS_COUNT);
- // Get the array of box art
- final TypedArray titleResourcesTypedArray = getResources()
- .obtainTypedArray(R.array.title_array1);
- final TypedArray titleResourcesTypedArray2 = getResources()
- .obtainTypedArray(R.array.title_array2);
- final TypedArray titleResourcesTypedArray3 = getResources()
- .obtainTypedArray(R.array.title_array3);
- final TypedArray titleResourcesTypedArray4 = getResources()
- .obtainTypedArray(R.array.title_array4);
- final TypedArray titleResourcesTypedArray5 = getResources()
- .obtainTypedArray(R.array.title_array5);
- // Populate the carousel with boxart
- ImageView imageItem;
- ImageView imageItem2;
- ImageView imageItem3;
- ImageView imageItem4;
- ImageView imageItem5;
- for (int i = 0; i < titleResourcesTypedArray2.length(); ++i) {
- imageItem2 = new ImageView(this);
- imageItem2.setBackgroundResource(R.drawable.shadow);
- imageItem2.setImageResource(titleResourcesTypedArray2
- .getResourceId(i, -1));
- imageItem2.setLayoutParams(new LinearLayout.LayoutParams(
- imageWidth, imageWidth));
- mCarouselContainer2.addView(imageItem2);
- }
- for (int i = 0; i < titleResourcesTypedArray3.length(); ++i) {
- imageItem3 = new ImageView(this);
- imageItem3.setBackgroundResource(R.drawable.shadow);
- imageItem3.setImageResource(titleResourcesTypedArray3
- .getResourceId(i, -1));
- imageItem3.setLayoutParams(new LinearLayout.LayoutParams(
- imageWidth, imageWidth));
- mCarouselContainer3.addView(imageItem3);
- }
- for (int i = 0; i < titleResourcesTypedArray4.length(); ++i) {
- imageItem4 = new ImageView(this);
- imageItem4.setBackgroundResource(R.drawable.shadow);
- imageItem4.setImageResource(titleResourcesTypedArray4
- .getResourceId(i, -1));
- imageItem4.setLayoutParams(new LinearLayout.LayoutParams(
- imageWidth, imageWidth));
- mCarouselContainer4.addView(imageItem4);
- }
- for (int i = 0; i < titleResourcesTypedArray5.length(); ++i) {
- imageItem5 = new ImageView(this);
- imageItem5.setBackgroundResource(R.drawable.shadow);
- imageItem5.setImageResource(titleResourcesTypedArray5
- .getResourceId(i, -1));
- imageItem5.setLayoutParams(new LinearLayout.LayoutParams(
- imageWidth, imageWidth));
- mCarouselContainer5.addView(imageItem5);
- }
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.activity_main_actions, menu);
- return super.onCreateOptionsMenu(menu);
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here
- // int id = item.getItemId();
- // if (id == R.id.icon_settings_top_right) {
- // Intent intent = new Intent(Home.this, SyncOptions.class);
- // startActivity(intent);
- // return true;
- // }
- //
- // if (id == R.id.icon_music_top_center) {
- // Intent intent = new Intent(Home.this, Music.class);
- // startActivity(intent);
- // return true;
- // }
- //
- // if (id == R.id.icon_who_top_center) {
- // Intent intent = new Intent(Home.this, MainActivity.class);
- // startActivity(intent);
- // return true;
- // }
- //
- // if (id == R.id.icon_weapons_top_center) {
- // Intent intent = new Intent(Home.this, Weapons.class);
- // startActivity(intent);
- // return true;
- // }
- //
- // if (id == R.id.icon_vehicles_top_center) {
- // Intent intent = new Intent(Home.this, Vehicles.class);
- // startActivity(intent);
- // return true;
- // }
- //
- // if (id == R.id.action_settings) {
- // Intent intent = new Intent(Home.this, RestFulWebservice.class);
- // startActivity(intent);
- // return true;
- // }
- return super.onOptionsItemSelected(item);
- }
- @Override
- public void onWindowFocusChanged(boolean hasFocus) {
- super.onWindowFocusChanged(hasFocus);
- // When the window loses focus (e.g. the action overflow is shown),
- // cancel any pending hide action. When the window gains focus,
- // hide the system UI.
- if (hasFocus) {
- delayedHide(300);
- } else {
- mHideHandler.removeMessages(0);
- }
- }
- private void hideSystemUI() {
- // getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
- // | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
- // | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
- // | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
- // | View.SYSTEM_UI_FLAG_FULLSCREEN
- // | View.SYSTEM_UI_FLAG_LOW_PROFILE
- // | View.SYSTEM_UI_FLAG_IMMERSIVE);
- }
- private void showSystemUI() {
- getWindow().getDecorView().setSystemUiVisibility(
- View.SYSTEM_UI_FLAG_LAYOUT_STABLE
- | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
- | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
- }
- private final Handler mHideHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- hideSystemUI();
- }
- };
- private void delayedHide(int delayMillis) {
- mHideHandler.removeMessages(0);
- mHideHandler.sendEmptyMessageDelayed(0, delayMillis);
- }
- public void onTaskComplete(String content) {
- Toast.makeText(this, "The result is " + content, Toast.LENGTH_LONG)
- .show();
- if (content != null) {
- try {
- JSONArray jArrayObject;
- try {
- jArrayObject = new JSONArray(content);
- for (int i = 0; i < jArrayObject.length(); i++) {
- Log.d("id==",
- jArrayObject.getJSONObject(i).getString("id")
- .toString());
- Log.d("title==", jArrayObject.getJSONObject(i)
- .getString("title").toString());
- Log.d("year==", jArrayObject.getJSONObject(i)
- .getString("year").toString());
- Log.d("rating==", jArrayObject.getJSONObject(i)
- .getString("rating").toString());
- Log.d("genres==", jArrayObject.getJSONObject(i)
- .getString("genres").toString());
- ImageView imageItem;
- imageItem = new ImageView(this);
- // Set the shadow background
- imageItem.setTag(R.drawable.shadow);
- // Set the ID tag
- imageItem.setTag(i);
- final DisplayMetrics displayMetrics = new DisplayMetrics();
- getWindowManager().getDefaultDisplay().getMetrics(
- displayMetrics);
- final int imageWidth = (int) (displayMetrics.widthPixels / INITIAL_ITEMS_COUNT);
- // Set the image view resource
- // Set the size of the image view to the previously
- // computed value
- imageItem
- .setLayoutParams(new LinearLayout.LayoutParams(
- imageWidth, imageWidth));
- imageItem.setTag(i);
- // / Add image to the carousel
- mCarouselContainer1.addView(imageItem);
- // Pull BoxArt Photo
- Picasso.with(this)
- .load(jArrayObject.getJSONObject(i)
- .getString("boxart").toString())
- .into(imageItem);
- // TO DO MONDAY - REWORK THIS CODE (AVOIDING MEMORY LEAK ISSUES)
- // http://stackoverflow.com/questions/23740307/load-large-images-with-picasso-and-custom-transform-object
- // private static final int MAX_WIDTH = 1024;
- // private static final int MAX_HEIGHT = 768;
- //
- // int size = (int) Math.ceil(Math.sqrt(MAX_WIDTH * MAX_HEIGHT));
- //
- // // Loads given image
- // Picasso.with(imageView.getContext())
- // .load(imagePath)
- // .transform(new BitmapTransform(MAX_WIDTH, MAX_HEIGHT))
- // .skipMemoryCache()
- // .resize(size, size)
- // .centerInside()
- // .into(imageView);
- Log.d("mapdate==", jArrayObject.getJSONObject(i)
- .getString("mapdate").toString());
- imageItem
- .setOnClickListener(new View.OnClickListener() {
- // create an onClick Listener
- @Override
- public void onClick(View v) {
- Intent intent = new Intent(Home.this,
- Download.class);
- intent.putExtra("coverArt", v.getTag()
- .toString());
- startActivity(intent);
- // v.getTag();
- }
- });
- }
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } finally {
- }
- }
- }
- private void getBoxart() {
- // TODO Auto-generated method stub
- new DownloadImageTask((ImageView) findViewById(R.id.imageView1))
- .execute("http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png");
- }
- @Override
- protected void onDestroy() {
- super.onDestroy();
- // Perform Bitmap Scaling to Conserve Memory
- unbindDrawables(findViewById(R.id.drawerLayout));
- System.gc();
- }
- // Perform Bitmap Scaling to Conserve Memory
- private void unbindDrawables(View view) {
- if (view.getBackground() != null) {
- view.getBackground().setCallback(null);
- }
- if (view instanceof ViewGroup) {
- for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
- unbindDrawables(((ViewGroup) view).getChildAt(i));
- }
- ((ViewGroup) view).removeAllViews();
- }
- }
- // Create Custom Hamburger Menu
- class NavItem {
- String mTitle;
- String mSubtitle;
- int mIcon;
- public NavItem(String title, String subtitle, int icon) {
- mTitle = title;
- mSubtitle = subtitle;
- mIcon = icon;
- }
- }
- class DrawerListAdapter extends BaseAdapter {
- Context mContext;
- ArrayList<NavItem> mNavItems;
- public DrawerListAdapter(Context context, ArrayList<NavItem> navItems) {
- mContext = context;
- mNavItems = navItems;
- }
- @Override
- public int getCount() {
- return mNavItems.size();
- }
- @Override
- public Object getItem(int position) {
- return mNavItems.get(position);
- }
- @Override
- public long getItemId(int position) {
- return 0;
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- View view;
- if (convertView == null) {
- LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- view = inflater.inflate(R.layout.drawer_item, null);
- }
- else {
- view = convertView;
- }
- TextView titleView = (TextView) view.findViewById(R.id.title);
- TextView subtitleView = (TextView) view.findViewById(R.id.subTitle);
- ImageView iconView = (ImageView) view.findViewById(R.id.icon);
- titleView.setText( mNavItems.get(position).mTitle );
- subtitleView.setText( mNavItems.get(position).mSubtitle );
- iconView.setImageResource(mNavItems.get(position).mIcon);
- return view;
- }
- }
- // Called when invalidateOptionsMenu() is invoked
- public boolean onPrepareOptionsMenu(Menu menu) {
- // If the nav drawer is open, hide action items related to the content view
- boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
- menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
- return super.onPrepareOptionsMenu(menu);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement