Android Open Source - timestatistic Counters Cursor Adapter






From Project

Back to project page timestatistic.

License

The source code is released under:

GNU General Public License

If you think the Android project timestatistic 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 maximsblog.blogspot.com.timestatistic;
//w ww.  ja  va2s.c om
import java.util.Date;

import android.content.Context;
import android.content.res.ColorStateList;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.v4.widget.SimpleCursorAdapter;
import android.text.InputFilter.LengthFilter;
import android.view.View;
import android.widget.GridView;
import android.widget.TextView;

public class CountersCursorAdapter extends SimpleCursorAdapter {

  private long mStartdate;
  private long mEnddate;
  
  public CountersCursorAdapter(Context context, int layout, Cursor c,
      String[] from, int[] to, int flags, long startdate, long enddate) {
    super(context, layout, c, from, to, flags);
    mStartdate = startdate;
    mEnddate = enddate;
  }

  @Override
  public void bindView(View view, Context context, Cursor cursor) {
    super.bindView(view, context, cursor);
    boolean isRunning = cursor.getInt(6) == 1;
    int intColor = cursor.getInt(7);
    view.findViewById(R.id.linearLayout).setBackgroundColor(intColor);
    TextView t = (TextView) view.findViewById(R.id.current);
    intColor = ~0xFFFFFF | (0xFFFFFF & ~intColor);
    t.setTextColor(intColor);
    if (isRunning) {
        long start = cursor.getLong(3);
        if(start < mStartdate)
          start = mStartdate;
        long now = new Date().getTime();
        long lenght;
        if(now > mEnddate && mEnddate != -1){
          lenght = cursor.getLong(2);
        } else {
          lenght = now - start +  cursor.getLong(2);
        }
        setTime(t, lenght);
        view.findViewById(R.id.selectorLayout).setVisibility(View.VISIBLE);
        
    } else {
      long lenght = cursor.getLong(2);
      long start = cursor.getLong(3);
      setTime(t, lenght);
      view.findViewById(R.id.selectorLayout).setVisibility(View.GONE);
    }
    t = (TextView) view.findViewById(R.id.name);
    t.setTextColor(intColor);
  }
  
  public void setTime(TextView t, long time)
  {
    int day;
    int hours;
    int minutes;
    int seconds;
    day = (int) (time / (24 * 60 * 60 * 1000));
    hours = (int) (time / (60 * 60 * 1000)) - day * 24;
    minutes = (int) (time / (60 * 1000)) - day * 24 * 60 - 60* hours;
    seconds = (int) (time / 1000) - day * 24 * 60 * 60 - 60 * 60
        * hours - 60 * minutes;
    String s = new String();
    if(day>0)
    {
      s = String.format("%s\n%02d:%02d:%02d",getTimeString("day", day), hours, minutes, seconds);
    } else
      s = String.format("%02d:%02d:%02d", hours, minutes, seconds);
    t.setText(s);
  }
  
  private String getTimeString(String res, int l) {
    StringBuilder s = new StringBuilder();
    s.append(l);
    s.append(' ');
    if (l == 1 || (l % 10 == 1 && l != 11)) {
      s.append(mContext.getString(mContext.getResources().getIdentifier(
          res + "1", "string", mContext.getPackageName())));
    } else if ((l % 10 == 2 || l % 10 == 3 || l % 10 == 4) && l != 12
        && l != 13 && l != 14) {
      s.append(mContext.getString(mContext.getResources().getIdentifier(
          res + "234", "string", mContext.getPackageName())));
    } else
      s.append(mContext.getString(mContext.getResources().getIdentifier(
          res + "s", "string", mContext.getPackageName())));
    return s.toString();
  }


  public void setDate(long startdate, long enddate) {
    mStartdate = startdate;
    mEnddate = enddate;
  }
  

}




Java Source Code List

maximsblog.blogspot.com.timestatistic.AboutActivity.java
maximsblog.blogspot.com.timestatistic.AboutFragment.java
maximsblog.blogspot.com.timestatistic.AlarmManagerBroadcastReceiver.java
maximsblog.blogspot.com.timestatistic.AreYouSureResetAllDialogFragment.java
maximsblog.blogspot.com.timestatistic.AreYouSureResetAllDialog.java
maximsblog.blogspot.com.timestatistic.BootUpReceiver.java
maximsblog.blogspot.com.timestatistic.CalendarSetupDialogFragment.java
maximsblog.blogspot.com.timestatistic.ColorPickerDialogFragment.java
maximsblog.blogspot.com.timestatistic.ColorPickerDialog.java
maximsblog.blogspot.com.timestatistic.CounterEditorDialogFragment.java
maximsblog.blogspot.com.timestatistic.CountersCursorAdapter.java
maximsblog.blogspot.com.timestatistic.CountersFragment.java
maximsblog.blogspot.com.timestatistic.CountersPeriodSetupDialogFragment.java
maximsblog.blogspot.com.timestatistic.CustomDateTimePicker.java
maximsblog.blogspot.com.timestatistic.DiagramFragment.java
maximsblog.blogspot.com.timestatistic.DiaryCursorAdapter.java
maximsblog.blogspot.com.timestatistic.DiaryEditorDialogFragment.java
maximsblog.blogspot.com.timestatistic.DiaryFragment.java
maximsblog.blogspot.com.timestatistic.ExportImportBackupActivity.java
maximsblog.blogspot.com.timestatistic.ExportToCSVActivity.java
maximsblog.blogspot.com.timestatistic.ExportToCSVService.java
maximsblog.blogspot.com.timestatistic.ExportToGoogleCalendarActivity.java
maximsblog.blogspot.com.timestatistic.ExportToGoogleCalendarService.java
maximsblog.blogspot.com.timestatistic.FileDialog.java
maximsblog.blogspot.com.timestatistic.FilterDateOption.java
maximsblog.blogspot.com.timestatistic.FilterDateSetDialogFragment.java
maximsblog.blogspot.com.timestatistic.FilterDialogFragment.java
maximsblog.blogspot.com.timestatistic.GdriveUpload.java
maximsblog.blogspot.com.timestatistic.HelpActivity.java
maximsblog.blogspot.com.timestatistic.HistoryFragment.java
maximsblog.blogspot.com.timestatistic.ICustomDateTimeListener.java
maximsblog.blogspot.com.timestatistic.IRecordDialog.java
maximsblog.blogspot.com.timestatistic.IdateChange.java
maximsblog.blogspot.com.timestatistic.Item.java
maximsblog.blogspot.com.timestatistic.MainActivity.java
maximsblog.blogspot.com.timestatistic.OpenHelper.java
maximsblog.blogspot.com.timestatistic.PeriodAnalyseActivity.java
maximsblog.blogspot.com.timestatistic.PeriodAnalyseFragment.java
maximsblog.blogspot.com.timestatistic.PeriodData.java
maximsblog.blogspot.com.timestatistic.PeriodSetupDialogFragment.java
maximsblog.blogspot.com.timestatistic.RecordsDbHelper.java
maximsblog.blogspot.com.timestatistic.SelectionMode.java
maximsblog.blogspot.com.timestatistic.SettingsActivity.java
maximsblog.blogspot.com.timestatistic.SplitRecordDialogFragment.java
maximsblog.blogspot.com.timestatistic.TimeRecordsFragment.java
maximsblog.blogspot.com.timestatistic.TimesCursorAdapter.java
maximsblog.blogspot.com.timestatistic.TopicActivity.java
maximsblog.blogspot.com.timestatistic.UnionRecordDialogFragment.java
maximsblog.blogspot.com.timestatistic.XYMultipleSeriesDatasetLoader.java
maximsblog.blogspot.com.timestatistic.app.java