Android Open Source - DEVIEW2014_AndroidApp_Demo Program Manager






From Project

Back to project page DEVIEW2014_AndroidApp_Demo.

License

The source code is released under:

Apache License

If you think the Android project DEVIEW2014_AndroidApp_Demo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nhn.android.deview.dao.program;
/*www . j a v a 2 s. c  o  m*/
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Vector;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.nhn.android.deview.AppContext;
import com.nhn.android.deview.AppTable;
import com.nhn.android.deview.core.db.CursorReader;
import com.nhn.android.deview.core.db.DbTable;
import com.nhn.android.deview.dao.MySchedule;

public class ProgramManager {
  
  static ProgramManager mInstance = null;
  public static ProgramManager getInstance() {
    if (mInstance == null) {
      mInstance = new ProgramManager();
    }
    return mInstance;
  }
  
  public Vector<ProgramTrack>  mTracks = new Vector<ProgramTrack>();  
  public HashMap<String,ProgramData> mProgramMap = new HashMap<String, ProgramData>();
  
  public void parseTrack(String json) {
    JSONObject root;
    try {
      root = new JSONObject(json);
      JSONObject trackMap = root.getJSONObject("trackMap");
      JSONArray trackArray = trackMap.getJSONArray("DAY 1");
      for (int i = 0; i< trackArray.length(); i++) {
        ProgramTrack trackData = new ProgramTrack((JSONObject)trackArray.get(i));
        mTracks.add(trackData);
      }
            
      trackArray = trackMap.getJSONArray("DAY 2");
      for (int i = 0; i< trackArray.length(); i++) {
        ProgramTrack trackData = new ProgramTrack((JSONObject)trackArray.get(i));
        mTracks.add(trackData);
      }
      /*
      for (ProgramTrack t: mTracks) {
        ProgramListConnector c= new ProgramListConnector();
        c.open(t, null);
      }*/
    } catch (JSONException e) {
      e.printStackTrace();
    }
  
    
  }

  public void setProgramList(ProgramTrack track,Vector<ProgramData> list) {
  {
        Collections.sort(list,new Comparator<ProgramData>() {
          @Override
          public int compare(ProgramData lhs, ProgramData rhs) {
            return lhs.programStrt.compareTo(rhs.programStrt);
          }
        });
        
        track.mTimeTable = list;
        for (ProgramData data:list) {
          mProgramMap.put(data.id, data);
        }
        
        return;
      }
    
  }

  public Vector<ProgramData> getProgramList(String trackName,int seq) {
    for(ProgramTrack t: mTracks) {
      if (t.seq == seq) {
        return t.mTimeTable;
      }
    }
    return null;
  }
  
  public ProgramData getProgram(String id) {
    return mProgramMap.get(id);
  }
  
  public Vector<ProgramData> getMyProgramList() {

    Vector<ProgramData> mMyProgram = new Vector<ProgramData>();
    
    Cursor c = AppContext.getDB().query(AppTable.MYSCHEDULE, null , null, null, null, null, null);
    
    Vector<MySchedule> listData = CursorReader.readAll(c, MySchedule.class);
    
    for (int i = 0; i < listData.size(); i++) {
      MySchedule schedule = listData.get(i);
      ProgramData item = ProgramManager.getInstance().mProgramMap.get(schedule.id);
      
      if (item != null) {
        item.mMySchedule = schedule;
        mMyProgram.add(item);
      }
    }
    
    Collections.sort(mMyProgram,new Comparator<ProgramData>() {
      @Override
      public int compare(ProgramData lhs, ProgramData rhs) {
        return lhs.programStrt.compareTo(rhs.programStrt);
      }
    });
    return mMyProgram;
  }
    
  
  public boolean addMySchedule(ProgramData data) {
     ContentValues values = DbTable.toContentValues(new MySchedule(data), null);
    SQLiteDatabase db = AppContext.getDB();
    long result = db.insert(AppTable.MYSCHEDULE , null, values);
    return result >= 0;
  }
}




Java Source Code List

com.nhn.android.deview.AppContext.java
com.nhn.android.deview.AppTable.java
com.nhn.android.deview.DeViewApplication.java
com.nhn.android.deview.DeviewSchemeActivity.java
com.nhn.android.deview.MainDB.java
com.nhn.android.deview.ThreadWorker.java
com.nhn.android.deview.core.connector.DataConnectorListener.java
com.nhn.android.deview.core.connector.DataDoc.java
com.nhn.android.deview.core.connector.DataField.java
com.nhn.android.deview.core.connector.DataSet.java
com.nhn.android.deview.core.connector.DefaultDataConnector.java
com.nhn.android.deview.core.db.CursorReader.java
com.nhn.android.deview.core.db.DbTable.java
com.nhn.android.deview.core.lifecycle.CycleBaseLayout.java
com.nhn.android.deview.core.lifecycle.CycleControllable.java
com.nhn.android.deview.core.lifecycle.CycleControllerActivity.java
com.nhn.android.deview.core.lifecycle.CycleController.java
com.nhn.android.deview.core.lifecycle.CycleFragment.java
com.nhn.android.deview.core.listview.ListCellViewAdapter.java
com.nhn.android.deview.core.listview.ListCellView.java
com.nhn.android.deview.core.listview.PageViewPagerAdapter.java
com.nhn.android.deview.core.listview.PageView.java
com.nhn.android.deview.core.pager.SimplePagerAdapter.java
com.nhn.android.deview.core.transfer.BundleField.java
com.nhn.android.deview.core.transfer.BundleMapper.java
com.nhn.android.deview.core.transfer.IntentUri.java
com.nhn.android.deview.core.transfer.UriObject.java
com.nhn.android.deview.core.view.DeclareView.java
com.nhn.android.deview.core.view.ViewMapper.java
com.nhn.android.deview.dao.DeviewUri.java
com.nhn.android.deview.dao.MyMemoManager.java
com.nhn.android.deview.dao.MyMemo.java
com.nhn.android.deview.dao.MySchedule.java
com.nhn.android.deview.dao.program.ProgramData.java
com.nhn.android.deview.dao.program.ProgramListConnector.java
com.nhn.android.deview.dao.program.ProgramListDoc.java
com.nhn.android.deview.dao.program.ProgramManager.java
com.nhn.android.deview.dao.program.ProgramTrack.java
com.nhn.android.deview.dao.program.TrackListConnector.java
com.nhn.android.deview.ui.main.MainActivity.java
com.nhn.android.deview.ui.main.ProgramCellView.java
com.nhn.android.deview.ui.main.ProgramPageView.java
com.nhn.android.deview.ui.note.MemoCellView.java
com.nhn.android.deview.ui.note.MemoListActivity.java
com.nhn.android.deview.ui.note.MemoRecorder.java
com.nhn.android.deview.ui.note.MyScheduleActivity.java
com.nhn.android.deview.webviewer.MemoWebToolbar.java
com.nhn.android.deview.webviewer.ProgramWebActivity.java
com.nhn.android.deview.webviewer.WebPageView.java