您的位置:首页 > 其它

launcher 桌面启动器的DB文件数据处理操作

2013-01-28 13:56 260 查看
launcher-----启动器中的launcher.db文件的数据处理方法:

主要是查询,更新数据:

/**
* 类描述:缩略图帮助类
*  @author hexiaoming
*  @version
*/
public class PreviewHelper {

/********WorkspaceScreen的最大值*******/
public static final int MaxWorkspaceScreen = 40;

private  Context context = null;

public static final String Preview_Helper = "Preview_Helper";

public static final String  AUTHORITY = "com.konka.launcher2.settings";

public static final Uri CONTENT_URI =
Uri.parse("content://" + AUTHORITY + "/" + "favorites" + "?" + "notify" + "=true");
//Uri.parse("content://" + AUTHORITY  + "favorites");

private static String[] projection = new String[] {"container","screen"};
private static String[] projection_delete = new String[] {"_id","container","screen"};

public static final int CONTAINER_DESKTOP = -100;

/**
* 方法描述:PreviewHelper的构造方法
* @param
* @return
* @see PreviewHelper
*/
public PreviewHelper(Context context) {
this.context = context;
}

/**
* 方法描述:getArrayListForScreenIsNull方法,获取表示当前界面是否没有APP和Weight的ArrayList
* @param
* @return  ArrayList<Boolean>
* @see PreviewHelper
*/
public Boolean[] getScreenIsNull()
{
int length = LauncherPreviewActivity.bitmaps.size();
Boolean[] screenIsNull = new Boolean[length] ;

for(int i=0;i<screenIsNull.length;i++)
{
screenIsNull[i] = true;
}

final ContentResolver cr = context.getContentResolver();
Cursor c = cr.query(
CONTENT_URI,
projection,
null,
null,
null);

final int containerIndex = c.getColumnIndexOrThrow(projection[0]);
final int screenIndex = c.getColumnIndexOrThrow(projection[1]);

int container;
int screen;

try {
while (c.moveToNext()) {
container = c.getInt(containerIndex);
screen = c.getInt(screenIndex);
if(container == CONTAINER_DESKTOP)
{
screenIsNull[screen] = false;
}

}
} catch (Exception e) {

} finally {
c.close();
}

return screenIsNull;
}

/**
* 方法描述:ProcessDBForDeletePreviewScreen方法,处理删除缩略图片item_delete时的launcher.db数据
* @param   int item_delete
* @return  void
* @see PreviewHelper
*/
public void ProcessDBForDeletePreviewScreen(int item_delete)
{
final ContentResolver cr = context.getContentResolver();
Cursor c = cr.query(
CONTENT_URI,
projection_delete,
null,
null,
null);

final int favoriteIdIndex = c.getColumnIndexOrThrow(projection_delete[0]);
final int containerIndex = c.getColumnIndexOrThrow(projection_delete[1]);
final int screenIndex = c.getColumnIndexOrThrow(projection_delete[2]);

int favoritedId;
int container;
int screen;

ContentValues values = new ContentValues();

try {
while (c.moveToNext()) {

favoritedId = c.getInt(favoriteIdIndex);
container = c.getInt(containerIndex);
screen = c.getInt(screenIndex);

if(container == CONTAINER_DESKTOP)
{
if(screen > item_delete)
{
values.clear();
values.put("SCREEN", screen - 1);

String updateWhere = "_id" + "=" + favoritedId;

//                		String updateWhere = "(" + "SCREEN" + " == 'screen' " + ")" + "AND"
//                							+ "(" + "container" + "== 'container'"  + ")" ;

//                		BluetoothShare.STATUS + " >= '200' AND " +  "(" + BluetoothShare.VISIBILITY + " IS NULL OR "
//                        + BluetoothShare.VISIBILITY + " == '" + BluetoothShare.VISIBILITY_VISIBLE + "'" + ")";

cr.update(
CONTENT_URI,
values,
updateWhere,
null);}
}

}
} catch (Exception e) {

} finally {
c.close();
}

}

/**
* 方法描述:ProcessDBForExchangePreviewScreen方法,处理拖动缩略图片时的launcher.db数据
* @param   int start_item,int end_item
* @return  void
* @see PreviewHelper
*/
public void ProcessDBForExchangePreviewScreen(int start_item,int end_item)
{
final ContentResolver cr = context.getContentResolver();
Cursor c = cr.query(
CONTENT_URI,
projection_delete,
null,
null,
null);

final int favoriteIdIndex = c.getColumnIndexOrThrow(projection_delete[0]);
final int containerIndex = c.getColumnIndexOrThrow(projection_delete[1]);
final int screenIndex = c.getColumnIndexOrThrow(projection_delete[2]);

int favoritedId;
int container;
int screen;

ContentValues values = new ContentValues();

if(start_item < end_item)
{
try {
while (c.moveToNext()) {

favoritedId = c.getInt(favoriteIdIndex);
container = c.getInt(containerIndex);
screen = c.getInt(screenIndex);

if(container == CONTAINER_DESKTOP)
{
if(screen == start_item)
{
values.clear();
values.put("SCREEN", end_item);

String updateWhere = "_id" + "=" + favoritedId;
cr.update(
CONTENT_URI,
values,
updateWhere,
null);
}

if(screen > start_item && screen <= end_item)
{
values.clear();
values.put("SCREEN", screen - 1);

String updateWhere = "_id" + "=" + favoritedId;
cr.update(
CONTENT_URI,
values,
updateWhere,
null);
}

}

}
} catch (Exception e) {

} finally {
c.close();
}

}

if(start_item > end_item)
{
try {
while (c.moveToNext()) {

favoritedId = c.getInt(favoriteIdIndex);
container = c.getInt(containerIndex);
screen = c.getInt(screenIndex);

if(container == CONTAINER_DESKTOP)
{
if(screen == start_item)
{
values.clear();
values.put("SCREEN", end_item);

String updateWhere = "_id" + "=" + favoritedId;
cr.update(
CONTENT_URI,
values,
updateWhere,
null);
}

if(screen >= end_item && screen < start_item)
{
values.clear();
values.put("SCREEN", screen + 1);

String updateWhere = "_id" + "=" + favoritedId;
cr.update(
CONTENT_URI,
values,
updateWhere,
null);
}

}

}
} catch (Exception e) {

} finally {
c.close();
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐