use of com.moro.mtweaks.views.recyclerview.DescriptionView in project MTweaks-KernelAdiutorMOD by morogoku.
the class OnBootFragment method load.
private void load(List<RecyclerViewItem> items) {
List<RecyclerViewItem> applyOnBoot = new ArrayList<>();
TitleView applyOnBootTitle = new TitleView();
applyOnBootTitle.setText(getString(R.string.apply_on_boot));
List<Settings.SettingsItem> settings = mSettings.getAllSettings();
HashMap<String, Boolean> applyOnBootEnabled = new HashMap<>();
List<ApplyOnBootItem> applyOnBootItems = new ArrayList<>();
for (int i = 0; i < settings.size(); i++) {
if (!applyOnBootEnabled.containsKey(settings.get(i).getCategory())) {
applyOnBootEnabled.put(settings.get(i).getCategory(), Prefs.getBoolean(settings.get(i).getCategory(), false, getActivity()));
}
if (applyOnBootEnabled.get(settings.get(i).getCategory())) {
applyOnBootItems.add(new ApplyOnBootItem(settings.get(i).getSetting(), settings.get(i).getCategory(), i));
}
}
for (int i = 0; i < applyOnBootItems.size(); i++) {
final ApplyOnBootItem applyOnBootItem = applyOnBootItems.get(i);
DescriptionView applyOnBootView = new DescriptionView();
applyOnBootView.setSummary((i + 1) + ". " + applyOnBootItem.mCategory.replace("_onboot", "") + ": " + applyOnBootItem.mCommand);
applyOnBootView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {
@Override
public void onClick(RecyclerViewItem item) {
mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.delete_question, applyOnBootItem.mCommand), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
mSettings.delete(applyOnBootItem.mPosition);
mSettings.commit();
reload();
}
}, new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
mDeleteDialog = null;
}
}, getActivity());
mDeleteDialog.show();
}
});
applyOnBoot.add(applyOnBootView);
}
if (applyOnBoot.size() > 0) {
items.add(applyOnBootTitle);
items.addAll(applyOnBoot);
}
List<RecyclerViewItem> customControls = new ArrayList<>();
TitleView customControlTitle = new TitleView();
customControlTitle.setText(getString(R.string.custom_controls));
for (final Controls.ControlItem controlItem : mControls.getAllControls()) {
if (controlItem.isOnBootEnabled() && controlItem.getArguments() != null) {
DescriptionView controlView = new DescriptionView();
controlView.setTitle(controlItem.getTitle());
controlView.setSummary(getString(R.string.arguments, controlItem.getArguments()));
controlView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {
@Override
public void onClick(RecyclerViewItem item) {
mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.disable_question, controlItem.getTitle()), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
controlItem.enableOnBoot(false);
mControls.commit();
reload();
}
}, new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
mDeleteDialog = null;
}
}, getActivity());
mDeleteDialog.show();
}
});
customControls.add(controlView);
}
}
if (customControls.size() > 0) {
items.add(customControlTitle);
items.addAll(customControls);
}
List<RecyclerViewItem> profiles = new ArrayList<>();
TitleView profileTitle = new TitleView();
profileTitle.setText(getString(R.string.profile));
for (final Profiles.ProfileItem profileItem : mProfiles.getAllProfiles()) {
if (profileItem.isOnBootEnabled()) {
DescriptionView profileView = new DescriptionView();
profileView.setSummary(profileItem.getName());
profileView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {
@Override
public void onClick(RecyclerViewItem item) {
mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.disable_question, profileItem.getName()), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
profileItem.enableOnBoot(false);
mProfiles.commit();
reload();
}
}, new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
mDeleteDialog = null;
}
}, getActivity());
mDeleteDialog.show();
}
});
profiles.add(profileView);
}
}
if (profiles.size() > 0) {
items.add(profileTitle);
items.addAll(profiles);
}
if (Prefs.getBoolean("initd_onboot", false, getActivity())) {
TitleView initdTitle = new TitleView();
initdTitle.setText(getString(R.string.initd));
items.add(initdTitle);
DescriptionView emulateInitd = new DescriptionView();
emulateInitd.setSummary(getString(R.string.emulate_initd));
emulateInitd.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {
@Override
public void onClick(RecyclerViewItem item) {
mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.disable_question, getString(R.string.emulate_initd)), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Prefs.saveBoolean("initd_onboot", false, getActivity());
reload();
}
}, new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
mDeleteDialog = null;
}
}, getActivity());
mDeleteDialog.show();
}
});
items.add(emulateInitd);
}
}
use of com.moro.mtweaks.views.recyclerview.DescriptionView in project MTweaks-KernelAdiutorMOD by morogoku.
the class KSMFragment method infoInit.
private void infoInit(List<RecyclerViewItem> items) {
mInfos.clear();
for (int i = 0; i < KSM.getInfosSize(); i++) {
if (KSM.hasInfo(i)) {
DescriptionView info = new DescriptionView();
info.setTitle(KSM.getInfoText(i, getActivity()));
items.add(info);
mInfos.add(info);
}
}
}
use of com.moro.mtweaks.views.recyclerview.DescriptionView in project MTweaks-KernelAdiutorMOD by morogoku.
the class BackupFragment method itemInit.
private void itemInit(List<RecyclerViewItem> items, final Backup.PARTITION partition) {
File file = new File(Backup.getPath(partition));
if (file.exists()) {
for (final File image : file.listFiles()) {
if (image.isFile()) {
DescriptionView descriptionView = new DescriptionView();
descriptionView.setTitle(image.getName().replace(".img", ""));
descriptionView.setSummary((image.length() / 1024L / 1024L) + getString(R.string.mb));
descriptionView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {
@Override
public void onClick(RecyclerViewItem item) {
mItemOptionsDialog = new Dialog(getActivity()).setItems(getResources().getStringArray(R.array.backup_item_options), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
switch(i) {
case 0:
restore(partition, image, false);
break;
case 1:
delete(image);
break;
}
}
}).setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
mItemOptionsDialog = null;
}
});
mItemOptionsDialog.show();
}
});
items.add(descriptionView);
}
}
}
}
use of com.moro.mtweaks.views.recyclerview.DescriptionView in project MTweaks-KernelAdiutorMOD by morogoku.
the class ProfileFragment method load.
private void load(List<RecyclerViewItem> items) {
mProfiles = new Profiles(getActivity());
List<Profiles.ProfileItem> profileItems = mProfiles.getAllProfiles();
if (mTaskerMode && profileItems.size() == 0) {
Snackbar.make(getRootView(), R.string.no_profiles, Snackbar.LENGTH_LONG).show();
return;
}
for (int i = 0; i < profileItems.size(); i++) {
final int position = i;
final CardView cardView = new CardView(getActivity());
cardView.setOnMenuListener(new CardView.OnMenuListener() {
@Override
public void onMenuReady(final CardView cardView, PopupMenu popupMenu) {
Menu menu = popupMenu.getMenu();
menu.add(Menu.NONE, 0, Menu.NONE, getString(R.string.append));
menu.add(Menu.NONE, 1, Menu.NONE, getString(R.string.edit));
menu.add(Menu.NONE, 2, Menu.NONE, getString(R.string.details));
final MenuItem onBoot = menu.add(Menu.NONE, 3, Menu.NONE, getString(R.string.on_boot)).setCheckable(true);
onBoot.setChecked(mProfiles.getAllProfiles().get(position).isOnBootEnabled());
menu.add(Menu.NONE, 4, Menu.NONE, getString(R.string.export));
menu.add(Menu.NONE, 5, Menu.NONE, getString(R.string.delete));
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
List<Profiles.ProfileItem> items = mProfiles.getAllProfiles();
switch(item.getItemId()) {
case 0:
if (Utils.DONATED) {
Intent intent = new Intent(getActivity(), ProfileActivity.class);
intent.putExtra(ProfileActivity.POSITION_INTENT, position);
startActivityForResult(intent, 2);
} else {
mDonateDialog = ViewUtils.dialogDonate(getActivity());
mDonateDialog.show();
}
break;
case 1:
if (Utils.DONATED) {
Intent intent = new Intent(getActivity(), ProfileEditActivity.class);
intent.putExtra(ProfileEditActivity.POSITION_INTENT, position);
startActivityForResult(intent, 3);
} else {
mDonateDialog = ViewUtils.dialogDonate(getActivity());
mDonateDialog.show();
}
break;
case 2:
if (items.get(position).getName() != null) {
List<Profiles.ProfileItem.CommandItem> commands = items.get(position).getCommands();
if (commands.size() > 0) {
setForegroundText(items.get(position).getName().toUpperCase());
mDetailsFragment.setText(commands);
showForeground();
} else {
Utils.toast(R.string.profile_empty, getActivity());
}
}
break;
case 3:
onBoot.setChecked(!onBoot.isChecked());
items.get(position).enableOnBoot(onBoot.isChecked());
mProfiles.commit();
break;
case 4:
mExportProfile = items.get(position);
requestPermission(0, Manifest.permission.WRITE_EXTERNAL_STORAGE);
break;
case 5:
mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.sure_question), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
mProfiles.delete(position);
mProfiles.commit();
reload();
}
}, new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
mDeleteDialog = null;
}
}, getActivity());
mDeleteDialog.show();
break;
}
return false;
}
});
}
});
final DescriptionView descriptionView = new DescriptionView();
descriptionView.setSummary(profileItems.get(i).getName());
descriptionView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {
@Override
public void onClick(RecyclerViewItem item) {
if (mTaskerMode) {
mSelectDialog = ViewUtils.dialogBuilder(getString(R.string.select_question, descriptionView.getSummary()), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
((ProfileTaskerActivity) getActivity()).finish(descriptionView.getSummary().toString(), mProfiles.getAllProfiles().get(position).getCommands());
}
}, new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
mSelectDialog = null;
}
}, getActivity());
mSelectDialog.show();
} else {
mApplyDialog = ViewUtils.dialogBuilder(getString(R.string.apply_question, descriptionView.getSummary()), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
for (Profiles.ProfileItem.CommandItem command : mProfiles.getAllProfiles().get(position).getCommands()) {
CPUFreq.ApplyCpu applyCpu;
if (command.getCommand().startsWith("#") && ((applyCpu = new CPUFreq.ApplyCpu(command.getCommand().substring(1))).toString() != null)) {
for (String applyCpuCommand : ApplyOnBoot.getApplyCpu(applyCpu, RootUtils.getSU())) {
Control.runSetting(applyCpuCommand, null, null, null);
}
} else {
Control.runSetting(command.getCommand(), null, null, null);
}
}
}
}, new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
mApplyDialog = null;
}
}, getActivity());
try {
mApplyDialog.show();
} catch (NullPointerException ignored) {
}
}
}
});
if (mTaskerMode) {
items.add(descriptionView);
} else {
cardView.addItem(descriptionView);
items.add(cardView);
}
}
if (!mTaskerMode) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getActivity());
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(getActivity(), Widget.class));
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.profile_list);
Tile.publishProfileTile(profileItems, getActivity());
}
}
use of com.moro.mtweaks.views.recyclerview.DescriptionView in project MTweaks-KernelAdiutorMOD by morogoku.
the class RecoveryFragment method addAction.
private void addAction(Recovery.RECOVERY_COMMAND recovery_command, String path) {
String summary = null;
switch(recovery_command) {
case WIPE_DATA:
summary = getString(R.string.wipe_data);
break;
case WIPE_CACHE:
summary = getString(R.string.wipe_cache);
break;
case FLASH_ZIP:
summary = new File(path).getName();
break;
}
final Recovery recovery = new Recovery(recovery_command, path == null ? null : new File(path));
mCommands.add(recovery);
CardView cardView = new CardView(getActivity());
cardView.setOnMenuListener(new CardView.OnMenuListener() {
@Override
public void onMenuReady(final CardView cardView, PopupMenu popupMenu) {
popupMenu.getMenu().add(Menu.NONE, 0, Menu.NONE, getString(R.string.delete));
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == 0) {
mCommands.remove(recovery);
removeItem(cardView);
}
return false;
}
});
}
});
DescriptionView descriptionView = new DescriptionView();
if (path != null) {
descriptionView.setTitle(getString(R.string.flash_zip));
}
descriptionView.setSummary(summary);
cardView.addItem(descriptionView);
addItem(cardView);
}
Aggregations