// ##date:2013/11/28 ##author:hongxing.whx
  // backup restore functionality support
  private void handleRestore() {
    if (BackupManager.getRestoreFlag(this)) {
      // set in restore flag, so that other part can use it to judge if homeshell
      // is in restore mode
      Log.d(TAG, "Set homeshell inRestore flag");
      BackupManager.getInstance().setIsInRestore(true);
      //            BackupManager.setRestoreFlag(this, false);

      /*YUNOS BEGIN*/
      // ##date:2013/12/20 ##author:hao.liuhaolh ##BugID: 75596
      // restore app isn't in folder if restore failed and reload.
      Cursor c = null;
      File restoreDBfile =
          new File(getApplicationContext().getFilesDir() + "/backup/" + RESTORE_DB_FILE);
      if (restoreDBfile.exists() == true) {
        Log.d(TAG, "handleRestore read data from restore db");
        SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(restoreDBfile, null);
        c = db.query("favorites", null, null, null, null, null, null);
        // convertDBToBackupSet will close cursor, so we don't need to close it
        mBackupRecordMap = BackupUitil.convertDBToBackupSet(c);
        db.close();
      } else {
        Log.d(TAG, "handleRestore read data from homeshell db");
        final ContentResolver contentResolver = getApplicationContext().getContentResolver();
        c = contentResolver.query(Favorites.CONTENT_URI, null, null, null, null);
        // convertDBToBackupSet will close cursor, so we don't need to close it
        mBackupRecordMap = BackupUitil.convertDBToBackupSet(c);
      }
      /*YUNOS END*/

      for (Entry<String, BackupRecord> r : LauncherApplication.mBackupRecordMap.entrySet()) {
        Log.d(TAG, r.getValue().getField(Favorites._ID));
        String intentStr = r.getValue().getField(Favorites.INTENT);
        if (TextUtils.isEmpty(intentStr)) {
          continue;
        }
        try {
          Intent intent = Intent.parseUri(intentStr, 0);
          final ComponentName name = intent.getComponent();
          if (name == null) {
            Log.e(TAG, "ComponentName == Null");
            Log.i(TAG, "intent = " + intent.toString());
            continue;
          }
          Log.d(
              TAG,
              "onCreate() mBackupRecordMap getPackageName()="
                  + intent.getComponent().getPackageName());
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
Example #2
0
  @Override
  public synchronized SQLiteDatabase getWritableDatabase() {
    // TODO Auto-generated method stub
    File dbp = new File(dbPath);
    File dbf = new File(DB_NAME);
    if (!dbp.exists()) {
      dbp.mkdir();
    }

    boolean isFileCreateSuccess = false;
    if (!dbf.exists()) {
      try {
        isFileCreateSuccess = dbf.createNewFile();
        if (isFileCreateSuccess) {
          SQLiteDatabase.openOrCreateDatabase(dbf, null).execSQL(CREATE_TBL);
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    } else {
      isFileCreateSuccess = true;
    }
    if (isFileCreateSuccess) {
      return SQLiteDatabase.openOrCreateDatabase(dbf, null);
    } else {
      return null;
    }
  }
Example #3
0
 /**
  * 在SD卡的指定目录上创建文件
  *
  * @param sdcardPath
  * @param dbfilename
  * @return
  */
 private SQLiteDatabase createDbFileOnSDCard(String sdcardPath, String dbfilename) {
   File dbf = new File(sdcardPath, dbfilename);
   if (!dbf.exists()) {
     try {
       if (dbf.createNewFile()) {
         return SQLiteDatabase.openOrCreateDatabase(dbf, null);
       }
     } catch (IOException ioex) {
       throw new RuntimeException("数据库文件创建失败", ioex);
     }
   } else {
     return SQLiteDatabase.openOrCreateDatabase(dbf, null);
   }
   return null;
 }
Example #4
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.city_list);

    mCityLit = (ListView) findViewById(R.id.city_list);
    // mCityLit.setmHeaderViewVisible(true);
    //        mCityLit.setPinnedHeaderView(this, R.layout.title,
    //                R.id.contactitem_catalog);
    letterListView = (MyLetterListView) findViewById(R.id.cityLetterListView);
    DBManager dbManager = new DBManager(this);
    dbManager.openDateBase();
    dbManager.closeDatabase();
    database =
        SQLiteDatabase.openOrCreateDatabase(DBManager.DB_PATH + "/" + DBManager.DB_NAME, null);
    Log.e("x", "存储路径=" + DBManager.DB_PATH + "/" + DBManager.DB_NAME);
    mCityNames = getCityNames();
    database.close();
    letterListView.setOnTouchingLetterChangedListener(new LetterListViewListener());
    alphaIndexer = new HashMap<String, Integer>();
    handler = new Handler();
    overlayThread = new OverlayThread();
    initOverlay();

    mCityLit.addHeaderView(getHeadView());

    setAdapter(mCityNames);
    mCityLit.setOnItemClickListener(new CityListOnItemClick());
  }
Example #5
0
  public int getContactsCount() {

    database = SQLiteDatabase.openOrCreateDatabase(outFileName, null);
    String sql = "select * from " + TABLE_LEARNEDCOMMANDS + " where " + KEY_ROBOTID + "=" + robotID;
    Cursor cursor = database.rawQuery(sql, null);
    return cursor.getCount();
  }
Example #6
0
  private FinalDb(DaoConfig config) {
    if (config == null) throw new DbException("daoConfig is null");
    if (config.getContext() == null) throw new DbException("android context is null");
    if (config.type == 1) {
      File file = new File(config.getContext().getFilesDir(), config.getDbName());
      if (!file.exists()) {
        // 拷贝数据库
        try {
          InputStream is = config.getContext().getAssets().open(config.getDbName());
          Utils.copyFile(is, file);

        } catch (Exception e) {
          e.printStackTrace();
        }
      }
      this.db = SQLiteDatabase.openOrCreateDatabase(file, null);
    } else if (config.getTargetDirectory() != null
        && config.getTargetDirectory().trim().length() > 0
        && config.type != 1) {
      this.db = createDbFileOnSDCard(config.getTargetDirectory(), config.getDbName());
    } else {
      this.db =
          new SqliteDbHelper(
                  config.getContext().getApplicationContext(),
                  config.getDbName(),
                  config.getDbVersion(),
                  config.getDbUpdateListener())
              .getWritableDatabase();
    }
    this.config = config;
  }
  public boolean openOrCreateDatabase(Context context, File dbFile) {

    try {

      if (dbFile.exists()) {
        Log.i("SQLiteHelper", "Opening database at " + dbFile);
        mDb =
            SQLiteDatabase.openDatabase(
                dbFile.getAbsolutePath(), null, SQLiteDatabase.OPEN_READWRITE);
        return true;

        // Test if DB works properly
        // get(MapTile.TABLE_TILE_NAME, "tilekey");
        // ---

        // if (DATABASE_VERSION > db.getVersion())
        // upgrade();
      } else {
        Log.i("SQLiteHelper", "Creating database at " + dbFile);
        mDb = SQLiteDatabase.openOrCreateDatabase(dbFile, null);
        Log.i("SQLiteHelper", "Opened database at " + dbFile);
        upgradeFromFile(mDb, R.raw.sql_osm_maptile);
        return true;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return false;
  }
Example #8
0
 /**
  * 通过名字或者拼音搜索
  *
  * @param keyword
  * @return
  */
 public List<City> searchCity(final String keyword) {
   SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(DB_PATH + DB_NAME, null);
   Cursor cursor =
       db.rawQuery(
           "select * from "
               + TABLE_NAME
               + " where name like \"%"
               + keyword
               + "%\" or pinyin like \"%"
               + keyword
               + "%\"",
           null);
   List<City> result = new ArrayList<>();
   City city;
   while (cursor.moveToNext()) {
     String name = cursor.getString(cursor.getColumnIndex(NAME));
     String pinyin = cursor.getString(cursor.getColumnIndex(PINYIN));
     city = new City(name, pinyin);
     result.add(city);
   }
   cursor.close();
   db.close();
   Collections.sort(result, new CityComparator());
   return result;
 }
Example #9
0
  /* init methods */
  private void initialized() {
    // 初始化db
    if (null == dbHelper) dbHelper = new DBHelper(this, D.DB_VERSION);

    try {
      rdb = dbHelper.getWritableDatabase();
      wdb = dbHelper.getReadableDatabase();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    String path2 = getApplicationContext().getFilesDir().getPath();
    path2 = path2.substring(0, path2.lastIndexOf("/")) + "/databases/";
    putProviceTo();
    putimagrfromassats();
    File file = new File(path2, D.DB_NAME_PROVINCE);
    pcdDB = SQLiteDatabase.openOrCreateDatabase(file, null);

    // 初始化百度定位
    mLocationClient = getmLocationClient();
    BDLocationListener locationListener =
        new BDLocationListener() {
          @Override
          public void onReceiveLocation(BDLocation location) {
            ZhongTuanApp.getInstance().setLocation(location);
            mLocationClient.stop();
          }
        };
    mLocationClient.registerLocationListener(locationListener);
    mLocationClient.start();
  }
Example #10
0
 // 判断数据库是否存在
 public SQLiteDatabase getSQLiteDatabase(String dbName) {
   File db = this.getDatabasePath(dbName);
   if (!db.exists()) {
     return null;
   } else {
     return SQLiteDatabase.openOrCreateDatabase(db, null);
   }
 }
Example #11
0
 public void open(Context context) throws IOException {
   if (databaseFile.exists()) {
     if (Debug.D) Log.i("SQLiteHelper", "Opening database at " + databaseFile);
     db = SQLiteDatabase.openOrCreateDatabase(databaseFile, null);
     int dbVersion = db.getVersion();
     if (DATABASE_VERSION > dbVersion) upgrade(DATABASE_VERSION, dbVersion, context);
   } else {
     if (Debug.D) {
       Log.i("SQLiteHelper", "Creating database at " + databaseFile);
       Log.i("SQLiteHelper", "db folder exists: " + databaseFile.getParentFile().exists());
       Log.i(
           "SQLiteHelper", "db folder is writable: " + databaseFile.getParentFile().canWrite());
     }
     db = SQLiteDatabase.openOrCreateDatabase(databaseFile, null);
     create(context);
   }
 }
 @TargetApi(11)
 public final SQLiteDatabase openOrCreateDatabase(
     String paramString,
     int paramInt,
     SQLiteDatabase.CursorFactory paramCursorFactory,
     DatabaseErrorHandler paramDatabaseErrorHandler) {
   return SQLiteDatabase.openOrCreateDatabase(
       getDatabasePath(paramString).getPath(), paramCursorFactory, paramDatabaseErrorHandler);
 }
Example #13
0
 /**
  * 打开数据库
  *
  * @param dbName 数据库名称
  * @param clz 对应的实体类的class
  * @return
  */
 public static DBManager open(String dbName, Class<?> clz) {
   DBManager dbm = new DBManager();
   {
     SQLiteDatabase db =
         SQLiteDatabase.openOrCreateDatabase(new File(dbDir, dbName + ".db"), null);
     db.execSQL(SqlGetter.getCreateTable(clz));
     dbm.db = db;
   }
   return dbm;
 }
Example #14
0
 public static SQLiteDatabase createOrOpenDatabase() {
   SQLiteDatabase sld = null;
   try {
     sld =
         SQLiteDatabase.openOrCreateDatabase(
             exActivity.getactivity().getFilesDir().toString() + "/daydel", null);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return sld;
 }
Example #15
0
 public boolean ifExistCustomerRemoter() {
   database = SQLiteDatabase.openOrCreateDatabase(outFileName, null);
   String sql =
       "select count(*) from " + TABLE_LEARNEDCOMMANDS + " where " + KEY_ROBOTID + "=" + robotID;
   Cursor cursor = database.rawQuery(sql, null);
   if (cursor.moveToFirst()) {
     if (cursor.getInt(0) > 0) return true;
     else return false;
   }
   return false;
 }
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   mDatabaseFile = new File("/sqlite_stmt_journals", "database_test.db");
   if (mDatabaseFile.exists()) {
     mDatabaseFile.delete();
   }
   mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null);
   assertNotNull(mDatabase);
   mDatabase.setVersion(CURRENT_DATABASE_VERSION);
 }
Example #17
0
 public Cursor getGroups() {
   database = SQLiteDatabase.openOrCreateDatabase(outFileName, null);
   String sql =
       "select distinct buttonGroup from "
           + TABLE_LEARNEDCOMMANDS
           + " where "
           + KEY_ROBOTID
           + "="
           + robotID;
   Cursor cursor = database.rawQuery(sql, null);
   return cursor;
 }
 private void setupDatabase() {
   File dbDir = getContext().getDir("tests", Context.MODE_PRIVATE);
   mDatabaseFile = new File(dbDir, "database_test.db");
   if (mDatabaseFile.exists()) {
     mDatabaseFile.delete();
   }
   mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null);
   assertNotNull(mDatabaseFile);
   createTable(TABLE_NAME_1, TABLE1_COLUMNS);
   createTable(TABLE_NAME_2, TABLE2_COLUMNS);
   initializeTables();
 }
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    File dbDir = getContext().getDir("tests", Context.MODE_PRIVATE);
    mDatabaseFile = new File(dbDir, "database_test.db");

    if (mDatabaseFile.exists()) {
      mDatabaseFile.delete();
    }
    mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null);
    assertNotNull(mDatabase);
    mDatabase.setVersion(CURRENT_DATABASE_VERSION);
  }
Example #20
0
 @Override
 public SQLiteDatabase openOrCreateDatabase(
     final String name, final int mode, final SQLiteDatabase.CursorFactory factory) {
   final SQLiteDatabase result =
       SQLiteDatabase.openOrCreateDatabase(this.getDatabasePath(name), null);
   // SQLiteDatabase result = super.openOrCreateDatabase(name, mode,
   // factory);
   if (Log.isLoggable(DatabaseContext.DEBUG_CONTEXT, Log.WARN)) {
     Log.w(
         DatabaseContext.DEBUG_CONTEXT,
         "openOrCreateDatabase(" + name + ",,) = " + result.getPath());
   }
   return result;
 }
Example #21
0
  public DialogDAO(Context context) {

    try {
      db = SQLiteDatabase.openOrCreateDatabase(IOUtils.getDatabaseFolder2(), null);
      db.execSQL(
          "create table  if  not  exists  "
              + TABLENAME
              + "(id integer primary key autoincrement,dialogid varchar(50),uid varchar(20),nickname varchar(20),icon varchar(100),msg varchar(200),msgnums integer, logintime  datetime)");
      // Log.e("创建表", "OK");
    } catch (Exception e) {
      // TODO: handle exception
      // Log.e("创建表异常", e.toString());
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.io_sqlitedatabase);
    /*
     * 在tool下有sqlite3.exe工具 .database查看数据库 .tables查看数据库中的表
     * .help查看sqlite3支持的命令
     */

    db = SQLiteDatabase.openOrCreateDatabase(new File(getExternalCacheDir(), "zsx.db3"), null);
    Button insert = (Button) findViewById(R.id.global_btn1);
    mEditText = (EditText) findViewById(R.id.global_edittext1);
    mListView = (ListView) findViewById(R.id.global_listview);
    insert.setOnClickListener(this);
  }
Example #23
0
  private SQLiteDatabase createDatabase(DaoConfig config) {
    SQLiteDatabase result = null;

    String dbDir = config.getDbDir();
    if (!TextUtils.isEmpty(dbDir)) {
      File dir = new File(dbDir);
      if (dir.exists() || dir.mkdirs()) {
        File dbFile = new File(dbDir, config.getDbName());
        result = SQLiteDatabase.openOrCreateDatabase(dbFile, null);
      }
    } else {
      result = config.getContext().openOrCreateDatabase(config.getDbName(), 0, null);
    }
    return result;
  }
Example #24
0
 public int getMaxAddress() {
   database = SQLiteDatabase.openOrCreateDatabase(outFileName, null);
   String sql =
       "select max("
           + KEY_ADDRESS
           + ") from "
           + TABLE_LEARNEDCOMMANDS
           + " where "
           + KEY_ROBOTID
           + "="
           + robotID;
   Cursor cursor = database.rawQuery(sql, null);
   if (cursor.moveToFirst()) {
     return cursor.getInt(0);
   } else return -1;
 }
Example #25
0
 public Cursor selectMaxAddress() {
   database = SQLiteDatabase.openOrCreateDatabase(outFileName, null);
   String sql =
       "select max("
           + KEY_ADDRESS
           + ")+1 from "
           + TABLE_LEARNEDCOMMANDS
           + " where "
           + KEY_ADDRESS
           + "+1 between 1 and 63 and "
           + KEY_ROBOTID
           + "="
           + robotID;
   Cursor cursor = database.rawQuery(sql, null);
   return cursor;
 }
Example #26
0
 public int getMinUnusedAddress() {
   database = SQLiteDatabase.openOrCreateDatabase(outFileName, null);
   String sql =
       "select address-1 as lad  from LearnedCommands where lad between 1 and 63  and where "
           + KEY_ROBOTID
           + "="
           + robotID
           + "and lad not in (select address  from LearnedCommands where "
           + KEY_ROBOTID
           + "="
           + robotID
           + ") order by lad asc limit 1";
   Cursor cursor = database.rawQuery(sql, null);
   if (cursor.moveToFirst()) return cursor.getInt(0);
   else return -1;
 }
  protected void onCreate(Bundle saveInstanceState) {
    super.onCreate(saveInstanceState);
    setContentView(R.layout.login);
    // 建立或打开数据库
    db =
        SQLiteDatabase.openOrCreateDatabase(
            LoginActivity.this.getFilesDir().toString() + "/test.dbs", null);
    etuser = (EditText) findViewById(R.id.editText);
    etpwd = (EditText) findViewById(R.id.editText2);
    cb = (CheckBox) findViewById(R.id.checkBox);
    edname = (EditText) findViewById(R.id.editText);
    edpassword = (EditText) findViewById(R.id.editText2);
    btregister = (Button) findViewById(R.id.button2);
    btlogin = (Button) findViewById(R.id.button);

    // 添加图片的点击响应时间
    btn1 = (Button) findViewById(R.id.button3);
    btn1.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent getAlbum = new Intent(Intent.ACTION_GET_CONTENT);

            getAlbum.setType(IMAGE_TYPE);

            startActivityForResult(getAlbum, IMAGE_CODE);
          }
        });
    // 设置事件监控
    btregister.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent();
            intent.setClass(LoginActivity.this, RegisterActivity.class);
            startActivity(intent);
          }
        });
    btlogin.setOnClickListener(new LoginListener());

    // 从SharePerferences中读取用户的账号和密码
    checkIfRemember();
  }
Example #28
0
  public void createTables() {
    SQLiteDatabase db = null;
    String sql = "";

    try {
      db = SQLiteDatabase.openOrCreateDatabase(DATABASE_PATH + DATABASE_NAME, null, null);

      sql =
          "CREATE TABLE IF NOT EXISTS localsave(scheduleId int NOT NULL,"
              + " crn int NOT NULL,"
              + " number varchar (100) NOT NULL,"
              + " title varchar (500) NOT NULL,"
              + " units int NOT NULL,"
              + " activity varchar (60) NOT NULL,"
              + " days varchar (20) NOT NULL,"
              + " time varchar (20) NOT NULL,"
              + " room varchar (20) NOT NULL,"
              + " length varchar (20),"
              + " instructor varchar (40),"
              + " maxEnrl int,"
              + " seatsAvailable int,"
              + " activeEnrl int,"
              + " sem_id int  NOT NULL);";

      db.execSQL(sql);
      Log.d("DATABASE", "Executing Query: " + sql);

      sql =
          "CREATE TABLE IF NOT EXISTS "
              + NOTIFICATION_TABLE
              + "("
              + "crn int NOT NULL,"
              + "number varchar (100) NOT NULL);";

      db.execSQL(sql);

      Log.d("DATABASE", "Executing Query: " + sql);

      db.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #29
0
  private void init() {
    // TODO Auto-generated method stub
    mContext = this;
    db = SQLiteDatabase.openOrCreateDatabase(Globe.dbFile.getPath(), null);
    mhead_title = (TextView) findViewById(R.id.mhead_title);
    mhead_title.setText("其他设置");
    soundSb = (SwitchButton) findViewById(R.id.other_detail_soundsb);
    soundSb.setChecked(PLAYSOUND);
    soundSb.setOnCheckedChangeListener(new sbCheckChanged());

    tv_demic = (TextView) findViewById(R.id.tvsize_item_size);
    tv_note_demic = (TextView) findViewById(R.id.tvsize_item_note);
    add_demic = (ImageButton) findViewById(R.id.tvsize_item_add);
    sub_demic = (ImageButton) findViewById(R.id.tvsize_item_sub);
    tv_note_demic.setText("保留小数位");
    tv_demic.setText("" + Globe.demic);
    add_demic.setOnClickListener(new click());
    sub_demic.setOnClickListener(new click());
  }
  /**
   * Open a database.
   *
   * @param dbname The name of the database-NOT including its extension.
   * @param password The database password or null.
   */
  private void openDatabase(String dbname, String password) {
    if (this.getDatabase(dbname) != null) this.closeDatabase(dbname);

    String completeDBName = dbname + ".db";

    File dbfile = this.cordova.getActivity().getDatabasePath(dbname + ".db");

    if (!dbfile.exists()) copyPrepopulatedDatabase(completeDBName, dbfile);

    if (!dbfile.exists()) {
      dbfile.getParentFile().mkdirs();
    }

    Log.v("info", "Open sqlite db: " + dbfile.getAbsolutePath());

    SQLiteDatabase mydb = SQLiteDatabase.openOrCreateDatabase(dbfile, null);

    dbmap.put(dbname, mydb);
  }