Android Open Source - qingzhou Test






From Project

Back to project page qingzhou.

License

The source code is released under:

GNU General Public License

If you think the Android project qingzhou 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

/* 
 *  Copyright 2012 Loong H/*w  ww.j a v a  2 s . c  om*/
 * 
 *  Qingzhou is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Qingzhou is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.loongsoft.qingzhou;

import java.util.Random;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.net.Uri;
import android.util.Log;

import com.loongsoft.qingzhou.QingzhouProviderMetaData.ThingTableMetaData;

public class Test {
  public static final long A_DAY_LONG_IN_MILL = 86400000;
  private static int totalDays = 1095;
  private static int thingsMinNum = 1;
  private static int thingsMaxNum = 10;
  private static int thingMinLen = 2;
  private static int thingMaxLen = 20;
  private static int thingMinQuantity = 0;
  private static int thingMaxQuantity = 1000;
  
  private static String[] preThingsDes = {
    "????","????","???","??","??","??","???","??","??","??",
    "????","??","???","??","??","?????","?????","?????","?????","????",
    "??","??","???","??","????","???QQ","????","????","???","??",
    "????","????","??","????","??","???","???","??","????","????",
  };
  
  public static void generateFakeData(Context context, int daysNum) {
    Random ran = new Random();
    RandomHan rh = new RandomHan();
    
    Long cur = System.currentTimeMillis();
    Long des = cur - A_DAY_LONG_IN_MILL * daysNum;
    Log.i("cur,des", cur+","+des);
    
    ContentResolver resolver = context.getContentResolver();
    ContentValues values = new ContentValues();
    
    //First,delete all data in original database
    int count = resolver.delete(ThingTableMetaData.CONTENT_URI,null,null);
    Log.i("Deleted", count+"");
    
    for (long i =cur; i >= des; i-=A_DAY_LONG_IN_MILL) {
      int thingsNum = ran.nextInt(thingsMaxNum-thingsMinNum) + thingsMinNum;
      for (int n = 0; n < thingsNum; n++) {
        int thingIndex = ran.nextInt(preThingsDes.length);
        int quantity = ran.nextInt(thingMaxQuantity);
        long created_date = i + n;
        
        String descString = preThingsDes[thingIndex];
        String quanString = quantity == 0? "": Integer.toString(quantity);

        values.put(ThingTableMetaData.DESCRIPTION, descString);
        values.put(ThingTableMetaData.QUANTITY, quanString);
        values.put(ThingTableMetaData.CREATED_DATE, created_date);
        values.put(ThingTableMetaData.MODIFIED_DATE, created_date);
        
        Uri insertedUri = resolver.insert(ThingTableMetaData.CONTENT_URI, values);
      }
    }
  }
  
  static class RandomHan {
      private Random ran = new Random();
      private final static int delta = 0x4eff - 0x4e00 + 1;
      
      public char getRandomHan() {
          return (char)(0x4e00 + ran.nextInt(delta)); 
      }
      
      public String getRandomHans(int len) {
        StringBuilder hans = new StringBuilder();
        
        for (int i=0; i<len; i++) {
          hans.append(getRandomHan());
        }
        
        return hans.toString();
      }
  }
}




Java Source Code List

com.loongsoft.qingzhou.ADayActivity.java
com.loongsoft.qingzhou.ADayAdapter.java
com.loongsoft.qingzhou.DaysActivity.java
com.loongsoft.qingzhou.DaysAdapter.java
com.loongsoft.qingzhou.FrequentActivity.java
com.loongsoft.qingzhou.FrequentAdapter.java
com.loongsoft.qingzhou.FrequentThing.java
com.loongsoft.qingzhou.MetaData.java
com.loongsoft.qingzhou.QingzhouPreference.java
com.loongsoft.qingzhou.QingzhouProviderMetaData.java
com.loongsoft.qingzhou.QingzhouProvider.java
com.loongsoft.qingzhou.ReminderReciever.java
com.loongsoft.qingzhou.ResetPasswordPreference.java
com.loongsoft.qingzhou.SplashActivity.java
com.loongsoft.qingzhou.Test.java
com.loongsoft.qingzhou.ThingManager.java
com.loongsoft.qingzhou.Thing.java
com.loongsoft.qingzhou.TimePreference.java
com.loongsoft.qingzhou.Utils.java
com.loongsoft.qingzhou.WelcomeActivity.java