use of rocks.tbog.tblauncher.db.WidgetRecord in project TBLauncher by TBog.
the class WidgetManager method loadFromDB.
private void loadFromDB(Context context) {
ArrayList<WidgetRecord> widgets = DBHelper.getWidgets(context);
mWidgets.clear();
mPlaceholders.clear();
// we expect no placeholders
mWidgets.ensureCapacity(widgets.size());
for (WidgetRecord record : widgets) {
if (record instanceof PlaceholderWidgetRecord) {
mPlaceholders.add((PlaceholderWidgetRecord) record);
} else {
mWidgets.put(record.appWidgetId, record);
}
}
}
use of rocks.tbog.tblauncher.db.WidgetRecord in project TBLauncher by TBog.
the class WidgetManager method getConfigPopup.
/**
* Popup with options for the widget in the view
*
* @param view of the widget
* @return the popup menu
*/
protected ListPopup getConfigPopup(WidgetView view) {
final int appWidgetId = view.getAppWidgetId();
Context ctx = mLayout.getContext();
LinearAdapter adapter = new LinearAdapter();
WidgetRecord widget = mWidgets.get(appWidgetId);
if (widget != null) {
addConfigPopupItems(mLayout, adapter, view, widget);
} else {
adapter.add(new LinearAdapter.ItemString("ERROR: Not found"));
}
ListPopup menu = ListPopup.create(ctx, adapter);
menu.setOnItemClickListener((a, v, position) -> handleConfigPopupItemClick(a, view, position));
return menu;
}
use of rocks.tbog.tblauncher.db.WidgetRecord in project TBLauncher by TBog.
the class WidgetManager method getWidgetListPopup.
/**
* A popup with all active widgets to choose one
*
* @return the menu
*/
public ListPopup getWidgetListPopup(@StringRes int title) {
Context ctx = mLayout.getContext();
LinearAdapter adapter = new LinearAdapterPlus();
adapter.add(new LinearAdapter.ItemTitle(ctx, title));
for (WidgetRecord rec : mWidgets.values()) {
adapter.add(WidgetPopupItem.create(ctx, mAppWidgetManager, rec.appWidgetId));
}
for (PlaceholderWidgetRecord placeholder : mPlaceholders) {
adapter.add(PlaceholderPopupItem.create(ctx, placeholder));
}
return ListPopup.create(ctx, adapter);
}
use of rocks.tbog.tblauncher.db.WidgetRecord in project TBLauncher by TBog.
the class WidgetManager method restoreFromBackup.
/**
* called when importing from backup / XML
*
* @param append if true widget information will not be changed / imported / restored
* @param record placeholder information
*/
public void restoreFromBackup(boolean append, PlaceholderWidgetRecord record) /*, String name, ComponentName provider, byte[] preview, WidgetRecord record*/
{
int appWidgetId = record.appWidgetId;
boolean bFound = false;
{
WidgetRecord widgetRecord = mWidgets.get(appWidgetId);
AppWidgetProviderInfo info = widgetRecord != null ? getWidgetProviderInfo(widgetRecord.appWidgetId) : null;
// check if appWidgetId can be restored
if (info != null) {
bFound = record.provider.equals(info.provider);
}
}
// check if we can find a provider match
if (!bFound) {
for (WidgetRecord rec : mWidgets.values()) {
// if we already restored this widget, skip
if (mLayout.getWidget(rec.appWidgetId) != null)
continue;
AppWidgetProviderInfo info = getWidgetProviderInfo(rec.appWidgetId);
if (info == null)
continue;
if (record.provider.equals(info.provider)) {
appWidgetId = rec.appWidgetId;
bFound = true;
break;
}
}
}
if (bFound) {
record.appWidgetId = appWidgetId;
if (!append) {
// widget found, apply the properties
mWidgets.put(appWidgetId, record);
}
mLayout.removeWidget(appWidgetId);
restoreWidget(record);
} else {
// widget not found, add a placeholder
record.appWidgetId = INVALID_WIDGET_ID;
mPlaceholders.add(record);
addPlaceholderToLayout(record);
}
}
use of rocks.tbog.tblauncher.db.WidgetRecord in project TBLauncher by TBog.
the class WidgetManager method onAfterRestoreFromBackup.
public void onAfterRestoreFromBackup(boolean clearExtra) {
if (clearExtra) {
// remove all widgets not found in mLayout
int[] appWidgetIds = new int[mWidgets.size()];
// Arrays.fill(appWidgetIds, INVALID_WIDGET_ID);
// copy widget ids we may need to remove
{
int idx = 0;
for (WidgetRecord rec : mWidgets.values()) appWidgetIds[idx++] = rec.appWidgetId;
}
for (int appWidgetId : appWidgetIds) {
AppWidgetHostView widgetHostView = mLayout.getWidget(appWidgetId);
if (widgetHostView != null)
removeWidget(widgetHostView);
}
} else {
// restore widgets from mWidgets that are not in mLayout yet
for (WidgetRecord rec : mWidgets.values()) {
if (mLayout.getWidget(rec.appWidgetId) == null)
restoreWidget(rec);
}
}
Context ctx = mLayout.getContext();
for (WidgetRecord rec : mWidgets.values()) {
DBHelper.setWidgetProperties(ctx, rec);
}
// remove all placeholders
DBHelper.removeWidget(ctx, INVALID_WIDGET_ID);
// add back all placeholders
for (PlaceholderWidgetRecord placeholder : mPlaceholders) {
DBHelper.addWidget(ctx, placeholder);
}
}
Aggregations