Advertisement
Guest User

Untitled

a guest
Dec 26th, 2011
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.29 KB | None | 0 0
  1. /*******************************************************************************
  2.  * Copyright (c) 2011 Ethan Hall
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a
  5.  * copy of this software and associated documentation files (the "Software"),
  6.  *  to deal in the Software without restriction, including without limitation
  7.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8.  * and/or sell copies of the Software, and to permit persons to whom the
  9.  * Software is furnished to do so, subject to the following conditions:
  10.  *
  11.  * The above copyright notice and this permission notice shall be included
  12.  * in all copies or substantial portions of the Software.
  13.  *
  14.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20.  * DEALINGS IN THE SOFTWARE.
  21.  ******************************************************************************/
  22.  
  23. package com.kopysoft.chronos.view;
  24.  
  25. import android.content.Context;
  26. import android.os.Parcelable;
  27. import android.support.v4.view.PagerAdapter;
  28. import android.support.v4.view.ViewPager;
  29. import android.util.Log;
  30. import android.view.View;
  31. import android.widget.*;
  32. import com.kopysoft.chronos.adapter.TodayAdapterDropDown;
  33. import com.kopysoft.chronos.adapter.TodayAdapterIndividual;
  34. import com.kopysoft.chronos.adapter.TodayAdapterPair;
  35. import com.kopysoft.chronos.adapter.TodayAdapterSummary;
  36. import com.kopysoft.chronos.content.Chronos;
  37. import com.kopysoft.chronos.enums.Defines;
  38. import com.viewpagerindicator.TitleProvider;
  39.  
  40. public class ClockViewer extends PagerAdapter implements TitleProvider{
  41.  
  42.     private static final String TAG = Defines.TAG + " - ClockViewer";
  43.  
  44.     private static String[] titles = new String[] { "Demo 1", "Demo 2", "Demo 3", "Demo 4" };
  45.     private final Context context;
  46.     private int[] scrollPosition = new int[titles.length];
  47.  
  48.     public ClockViewer(Context context)
  49.     {
  50.         this.context = context;
  51.         for ( int i = 0; i < titles.length; i++ )
  52.         {
  53.             scrollPosition[i] = 0;
  54.         }
  55.     }
  56.  
  57.     public String getTitle( int position )
  58.     {
  59.         return titles[position];
  60.     }
  61.  
  62.     public int getCount()
  63.     {
  64.         return titles.length;
  65.     }
  66.  
  67.     @Override
  68.     public Object instantiateItem( ViewPager pager, int position )
  69.     {
  70.         Log.d(TAG, "Position: " + position);
  71.         LinearLayout layout = new LinearLayout(context);
  72.         layout.setOrientation(LinearLayout.VERTICAL);
  73.  
  74.         if(position == 0){
  75.             //Log.d(TAG, "Position: " + position);
  76.             Chronos chrono = new Chronos(context);
  77.             ListView retView = new ListView( context );
  78.             BaseAdapter adapter;
  79.  
  80.             //header to the row
  81.             RowElement header = new RowElement(context);
  82.             header.left().setText("In time");
  83.             header.center().setText("Task");
  84.             header.right().setText("Out time");
  85.             //retView.addHeaderView(header);
  86.             layout.addView(header, 0);
  87.             layout.addView(retView, 1);
  88.  
  89.             adapter = new TodayAdapterPair(context, chrono.getAllPunches());
  90.             retView.setAdapter( adapter );
  91.             retView.setSelection( scrollPosition[ position ] );
  92.  
  93.             chrono.close();
  94.  
  95.         }  else if(position == 1) {
  96.             Chronos chrono = new Chronos(context);
  97.             ListView retView = new ListView( context );
  98.             BaseAdapter adapter;
  99.  
  100.             RowElement header = new RowElement(context);
  101.             header.left().setText("In time");
  102.             header.center().setText("");
  103.             header.right().setText("Type");
  104.             //retView.addHeaderView(header);
  105.             layout.addView(header, 0);
  106.             layout.addView(retView, 1);
  107.  
  108.             adapter = new TodayAdapterIndividual(context, chrono.getAllPunches());
  109.             retView.setAdapter( adapter );
  110.             retView.setSelection( scrollPosition[ position ] );
  111.  
  112.             chrono.close();
  113.  
  114.         }   else if(position == 2){
  115.             //retView = new ExpandableListView(context);
  116.             Chronos chrono = new Chronos(context);
  117.             ListView retView = new ListView( context );
  118.             BaseAdapter adapter;
  119.  
  120.             RowElement header = new RowElement(context);
  121.             header.left().setText("Time");
  122.             header.center().setText("");
  123.             header.right().setText("Type");
  124.             //retView.addHeaderView(header);
  125.             layout.addView(header, 0);
  126.             layout.addView(retView, 1);
  127.  
  128.             adapter = new TodayAdapterSummary(context, chrono.getAllPunches());
  129.             retView.setAdapter( adapter );
  130.             retView.setSelection( scrollPosition[ position ] );
  131.  
  132.             chrono.close();
  133.         }   else if(position == 3) {
  134.             //retView = new ExpandableListView(context);
  135.             Chronos chrono = new Chronos(context);
  136.             ExpandableListView retView = new ExpandableListView( context );
  137.             BaseExpandableListAdapter adapter;
  138.  
  139.             RowElement header = new RowElement(context);
  140.             header.left().setText("");
  141.             header.center().setText("Time");
  142.             header.right().setText("Task");
  143.             //retView.addHeaderView(header);
  144.             layout.addView(header, 0);
  145.             layout.addView(retView, 1);
  146.  
  147.             adapter = new TodayAdapterDropDown(context, chrono.getAllPunches());
  148.             retView.setAdapter( adapter );
  149.             retView.setSelection( scrollPosition[ position ] );
  150.  
  151.             chrono.close();
  152.         }
  153.  
  154.         ((ViewPager) pager).addView( layout, 0 );
  155.  
  156.         /*
  157.         ListView v = new ListView( context );
  158.         String[] from = new String[] { "str" };
  159.         int[] to = new int[] { android.R.id.text1 };
  160.         List<Map<String, String>> items = new ArrayList<Map<String, String>>();
  161.         for ( int i = 0; i < 20; i++ )
  162.         {
  163.             Map<String, String> map = new HashMap<String, String>();
  164.             map.put( "str", String.format( "Item %d", i + 1 ) );
  165.             items.add( map );
  166.         }
  167.         SimpleAdapter adapter = new SimpleAdapter( context, items,
  168.                 android.R.layout.simple_list_item_1, from, to );
  169.         v.setAdapter( adapter );
  170.         ((ViewPager)pager ).addView( v, 0 );
  171.         v.setSelection( scrollPosition[ position ] );
  172.          */
  173.  
  174.         return layout;
  175.     }
  176.  
  177.     public void destroyItem( ViewPager pager, int position, Object view )
  178.     {
  179.         (pager ).removeView( (View) view );
  180.     }
  181.  
  182.     public boolean isViewFromObject( View view, Object object )
  183.     {
  184.         return view.equals( object );
  185.     }
  186.  
  187.     public void finishUpdate( View view )
  188.     {
  189.     }
  190.  
  191.     public void restoreState( Parcelable p, ClassLoader c )
  192.     {
  193.         if ( p instanceof ScrollState )
  194.         {
  195.             scrollPosition = ( (ScrollState) p ).getScrollPos();
  196.         }
  197.     }
  198.  
  199.     public Parcelable saveState()
  200.     {
  201.         return new ScrollState( scrollPosition );
  202.     }
  203.  
  204.     public void startUpdate( View view )
  205.     {
  206.     }
  207.  
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement