use of android.support.v7.widget.AppCompatButton in project android by owncloud.
the class ShareFileFragment method updatePublicShareSection.
/**
* Updates in the UI the section about public share with the information in the current
* public share bound to mFile, if any
*/
private void updatePublicShareSection() {
if (mPublicShare != null && ShareType.PUBLIC_LINK.equals(mPublicShare.getShareType())) {
/// public share bound -> expand section
SwitchCompat shareViaLinkSwitch = getShareViaLinkSwitch();
if (!shareViaLinkSwitch.isChecked()) {
// set null listener before setChecked() to prevent infinite loop of calls
shareViaLinkSwitch.setOnCheckedChangeListener(null);
shareViaLinkSwitch.setChecked(true);
shareViaLinkSwitch.setOnCheckedChangeListener(mOnShareViaLinkSwitchCheckedChangeListener);
}
getExpirationDateSection().setVisibility(View.VISIBLE);
getPasswordSection().setVisibility(View.VISIBLE);
if (mFile.isFolder() && !mCapabilities.getFilesSharingPublicUpload().isFalse()) {
getEditPermissionSection().setVisibility(View.VISIBLE);
} else {
getEditPermissionSection().setVisibility(View.GONE);
}
// GetLink button
AppCompatButton getLinkButton = getGetLinkButton();
getLinkButton.setVisibility(View.VISIBLE);
getLinkButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//GetLink from the server and show ShareLinkToDialog
((FileActivity) getActivity()).getFileOperationsHelper().getFileWithLink(mFile);
}
});
/// update state of expiration date switch and message depending on expiration date
SwitchCompat expirationDateSwitch = getExpirationDateSwitch();
// set null listener before setChecked() to prevent infinite loop of calls
expirationDateSwitch.setOnCheckedChangeListener(null);
long expirationDate = mPublicShare.getExpirationDate();
if (expirationDate > 0) {
if (!expirationDateSwitch.isChecked()) {
expirationDateSwitch.toggle();
}
String formattedDate = SimpleDateFormat.getDateInstance().format(new Date(expirationDate));
getExpirationDateValue().setText(formattedDate);
} else {
if (expirationDateSwitch.isChecked()) {
expirationDateSwitch.toggle();
}
getExpirationDateValue().setText(R.string.empty);
}
// recover listener
expirationDateSwitch.setOnCheckedChangeListener(mOnExpirationDateInteractionListener);
/// update state of password switch and message depending on password protection
SwitchCompat passwordSwitch = getPasswordSwitch();
// set null listener before setChecked() to prevent infinite loop of calls
passwordSwitch.setOnCheckedChangeListener(null);
if (mPublicShare.isPasswordProtected()) {
if (!passwordSwitch.isChecked()) {
passwordSwitch.toggle();
}
getPasswordValue().setVisibility(View.VISIBLE);
} else {
if (passwordSwitch.isChecked()) {
passwordSwitch.toggle();
}
getPasswordValue().setVisibility(View.INVISIBLE);
}
// recover listener
passwordSwitch.setOnCheckedChangeListener(mOnPasswordInteractionListener);
/// update state of the edit permission switch
SwitchCompat editPermissionSwitch = getEditPermissionSwitch();
// set null listener before setChecked() to prevent infinite loop of calls
editPermissionSwitch.setOnCheckedChangeListener(null);
if (mPublicShare.getPermissions() > OCShare.READ_PERMISSION_FLAG) {
if (!editPermissionSwitch.isChecked()) {
editPermissionSwitch.toggle();
}
} else {
if (editPermissionSwitch.isChecked()) {
editPermissionSwitch.toggle();
}
}
// recover listener
editPermissionSwitch.setOnCheckedChangeListener(mOnEditPermissionInteractionListener);
} else {
/// no public share -> collapse section
SwitchCompat shareViaLinkSwitch = getShareViaLinkSwitch();
if (shareViaLinkSwitch.isChecked()) {
shareViaLinkSwitch.setOnCheckedChangeListener(null);
getShareViaLinkSwitch().setChecked(false);
shareViaLinkSwitch.setOnCheckedChangeListener(mOnShareViaLinkSwitchCheckedChangeListener);
}
getExpirationDateSection().setVisibility(View.GONE);
getPasswordSection().setVisibility(View.GONE);
getEditPermissionSection().setVisibility(View.GONE);
getGetLinkButton().setVisibility(View.GONE);
}
}
use of android.support.v7.widget.AppCompatButton in project Rashr by DsLNeXuS.
the class BackupRestoreFragment method createBackup.
public void createBackup(final boolean RecoveryBackup) {
String prefix;
String CurrentName;
String EXT;
if (RecoveryBackup) {
prefix = "recovery";
EXT = RashrApp.DEVICE.getRecoveryExt();
CurrentName = RashrApp.DEVICE.getRecoveryVersion();
} else {
prefix = "kernel";
EXT = RashrApp.DEVICE.getKernelExt();
CurrentName = RashrApp.DEVICE.getKernelVersion();
}
final AppCompatDialog dialog = new AppCompatDialog(mContext);
dialog.setTitle(R.string.setname);
dialog.setContentView(R.layout.dialog_input);
final AppCompatButton bGoBackup = (AppCompatButton) dialog.findViewById(R.id.bGoBackup);
final AppCompatEditText etFileName = (AppCompatEditText) dialog.findViewById(R.id.etFileName);
final AppCompatCheckBox optName = (AppCompatCheckBox) dialog.findViewById(R.id.cbOptInput);
if (bGoBackup == null || etFileName == null || optName == null)
return;
final String NameHint = prefix + "-from-" + Calendar.getInstance().get(Calendar.DATE) + "-" + Calendar.getInstance().get(Calendar.MONTH) + "-" + Calendar.getInstance().get(Calendar.YEAR) + "-" + Calendar.getInstance().get(Calendar.HOUR) + "-" + Calendar.getInstance().get(Calendar.MINUTE) + EXT;
optName.setText(CurrentName);
optName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
etFileName.setEnabled(!optName.isChecked());
}
});
etFileName.setHint(NameHint);
bGoBackup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String EXT;
File Path;
final int JOB;
if (RecoveryBackup) {
EXT = RashrApp.DEVICE.getRecoveryExt();
Path = Const.PathToRecoveryBackups;
JOB = FlashUtil.JOB_BACKUP_RECOVERY;
} else {
EXT = RashrApp.DEVICE.getKernelExt();
Path = Const.PathToKernelBackups;
JOB = FlashUtil.JOB_BACKUP_KERNEL;
}
CharSequence Name = "";
if (optName.isChecked()) {
Name = optName.getText() + EXT;
} else {
if (etFileName.getText() != null && !etFileName.getText().toString().equals("")) {
Name = etFileName.getText().toString();
}
if (Name.equals("")) {
Name = String.valueOf(etFileName.getHint());
}
if (!Name.toString().endsWith(EXT)) {
Name = Name + EXT;
}
}
final File fBACKUP = new File(Path, Name.toString());
if (fBACKUP.exists()) {
Toast.makeText(mActivity, R.string.backupalready, Toast.LENGTH_SHORT).show();
} else {
final FlashUtil BackupCreator = new FlashUtil(mActivity, fBACKUP, JOB);
BackupCreator.setOnTaskDoneListener(new FlashUtil.OnTaskDoneListener() {
@Override
public void onSuccess() {
mAdapter.reload();
}
@Override
public void onFail(Exception e) {
String msg;
if (e != null) {
msg = e.toString();
} else {
msg = getString(R.string.bak_error);
}
Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show();
}
});
BackupCreator.execute();
}
dialog.dismiss();
}
});
dialog.show();
}
use of android.support.v7.widget.AppCompatButton in project Rashr by DsLNeXuS.
the class SettingsFragment method onCreateView.
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View root = inflater.inflate(R.layout.fragment_settings, container, false);
final AppCompatButton bSetDevName = (AppCompatButton) root.findViewById(R.id.bSetDevName);
final AppCompatCheckBox cbShowAds = (AppCompatCheckBox) root.findViewById(R.id.cbShowAds);
final AppCompatCheckBox cbLog = (AppCompatCheckBox) root.findViewById(R.id.cbLog);
// final AppCompatCheckBox cbDarkUI = (AppCompatCheckBox) root.findViewById(R.id.cbDarkUI);
final AppCompatCheckBox cbCheckUpdates = (AppCompatCheckBox) root.findViewById(R.id.cbCheckUpdates);
final AppCompatCheckBox cbHideUpToDateHint = (AppCompatCheckBox) root.findViewById(R.id.cbShowUpToDateHints);
final AppCompatCheckBox cbSkipSizeCheck = (AppCompatCheckBox) root.findViewById(R.id.cbSkipSizeChecking);
final AppCompatCheckBox cbSkipValidate = (AppCompatCheckBox) root.findViewById(R.id.cbSkipValidateImages);
final AppCompatButton bShowLogs = (AppCompatButton) root.findViewById(R.id.bShowLogs);
final AppCompatButton bReport = (AppCompatButton) root.findViewById(R.id.bReport);
final AppCompatButton bShowChangelog = (AppCompatButton) root.findViewById(R.id.bShowChangelog);
final AppCompatButton bReset = (AppCompatButton) root.findViewById(R.id.bReset);
final AppCompatButton bClearCache = (AppCompatButton) root.findViewById(R.id.bClearCache);
final AppCompatButton bShowLicences = (AppCompatButton) root.findViewById(R.id.bShowLicenses);
// cbDarkUI.setChecked(Common.getBooleanPref(root.getContext(), Const.PREF_NAME,
// Const.PREF_KEY_DARK_UI));
cbShowAds.setChecked(Common.getBooleanPref(root.getContext(), Const.PREF_NAME, Const.PREF_KEY_ADS));
cbLog.setChecked(Common.getBooleanPref(root.getContext(), Const.PREF_NAME, Const.PREF_KEY_LOG));
cbCheckUpdates.setChecked(Common.getBooleanPref(root.getContext(), Const.PREF_NAME, Const.PREF_KEY_CHECK_UPDATES));
cbShowAds.setChecked(Common.getBooleanPref(root.getContext(), Const.PREF_NAME, Const.PREF_KEY_ADS));
cbHideUpToDateHint.setChecked(Common.getBooleanPref(root.getContext(), Const.PREF_NAME, Const.PREF_KEY_HIDE_UPDATE_HINTS));
cbSkipSizeCheck.setChecked(Common.getBooleanPref(root.getContext(), Const.PREF_NAME, Const.PREF_KEY_SKIP_SIZE_CHECK));
cbSkipValidate.setChecked(Common.getBooleanPref(root.getContext(), Const.PREF_NAME, Const.PREF_KEY_SKIP_IMAGE_CHECK));
// cbDarkUI.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
// @Override
// public void onCheckedChanged(CompoundButton view, boolean isChecked) {
// Common.setBooleanPref(view.getContext(), Const.PREF_NAME,
// Const.PREF_KEY_DARK_UI, isChecked);
// RashrActivity.isDark = isChecked;
// }
// });
cbLog.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
Common.setBooleanPref(view.getContext(), Const.PREF_NAME, Const.PREF_KEY_LOG, isChecked);
root.findViewById(R.id.bShowLogs).setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE);
}
});
cbCheckUpdates.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
Common.setBooleanPref(view.getContext(), Const.PREF_NAME, Const.PREF_KEY_CHECK_UPDATES, isChecked);
}
});
cbShowAds.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
Common.setBooleanPref(view.getContext(), Const.PREF_NAME, Const.PREF_KEY_ADS, isChecked);
}
});
cbHideUpToDateHint.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
Common.setBooleanPref(view.getContext(), Const.PREF_NAME, Const.PREF_KEY_HIDE_UPDATE_HINTS, isChecked);
}
});
cbSkipSizeCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Common.setBooleanPref(buttonView.getContext(), Const.PREF_NAME, Const.PREF_KEY_SKIP_SIZE_CHECK, isChecked);
}
});
cbSkipValidate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Common.setBooleanPref(buttonView.getContext(), Const.PREF_NAME, Const.PREF_KEY_SKIP_IMAGE_CHECK, isChecked);
}
});
final RashrActivity activity = (RashrActivity) getActivity();
bReport.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ReportDialog dialog = new ReportDialog(activity, "");
dialog.show();
}
});
bShowLogs.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showLogs();
}
});
bShowLogs.setVisibility(cbLog.isChecked() ? View.VISIBLE : View.INVISIBLE);
bReset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AppCompatActivity activity = (AppCompatActivity) getActivity();
SharedPreferences.Editor editor = activity.getSharedPreferences(Const.PREF_NAME, Context.MODE_PRIVATE).edit();
editor.clear().apply();
editor = activity.getSharedPreferences(Const.PREF_NAME, Context.MODE_PRIVATE).edit();
editor.clear().apply();
RashrActivity.firstSetup(v.getContext());
}
});
bClearCache.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final AlertDialog.Builder ConfirmationDialog = new AlertDialog.Builder(v.getContext());
ConfirmationDialog.setTitle(R.string.warning);
ConfirmationDialog.setMessage(R.string.delete_confirmation);
ConfirmationDialog.setPositiveButton(R.string.positive, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (!Common.deleteFolder(Const.PathToCWM, false) || !Common.deleteFolder(Const.PathToTWRP, false) || !Common.deleteFolder(Const.PathToPhilz, false) || !Common.deleteFolder(Const.PathToStockRecovery, false) || !Common.deleteFolder(Const.PathToStockKernel, false)) {
Toast.makeText(getActivity(), R.string.delete_failed, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), R.string.files_deleted, Toast.LENGTH_SHORT).show();
}
}
});
ConfirmationDialog.setNegativeButton(R.string.negative, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
ConfirmationDialog.show();
}
});
bShowChangelog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SettingsFragment.showChangelog(v.getContext());
}
});
bShowLicences.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new LicensesDialog.Builder(v.getContext()).setNotices(R.raw.licenses_notice).setIncludeOwnLicense(true).build().show();
}
});
bSetDevName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final AppCompatEditText et = new AppCompatEditText(v.getContext());
AlertDialog.Builder inputDialog = new AlertDialog.Builder(v.getContext());
String dev_name = Common.getStringPref(v.getContext(), Const.PREF_NAME, Const.PREF_KEY_DEVICE_NAME);
if (dev_name.equals(""))
dev_name = RashrApp.DEVICE.getName();
et.setText(dev_name);
inputDialog.setTitle(R.string.device_name);
inputDialog.setView(et);
inputDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String name = et.getText().toString();
if (!name.equals("")) {
Common.setStringPref(getContext(), Const.PREF_NAME, Const.PREF_KEY_DEVICE_NAME, et.getText().toString());
Snackbar.make(bSetDevName, R.string.please_restart, Snackbar.LENGTH_SHORT).show();
}
}
});
inputDialog.setNeutralButton(R.string.reset, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Common.setStringPref(getContext(), Const.PREF_NAME, Const.PREF_KEY_DEVICE_NAME, Build.DEVICE.toLowerCase());
}
});
inputDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
inputDialog.show();
}
});
return root;
}
use of android.support.v7.widget.AppCompatButton in project Rashr by DsLNeXuS.
the class FlashFragment method showUnifiedBuildsDialog.
/**
* Check if Device uses a Unified base like some Galaxy S4: htle, htltespr htltexx uses the same
* sources so they can use the unified kernels and recoveries. Let the User choice which one is
* the correct for him. PLEASE BE CAREFUL!
*/
public void showUnifiedBuildsDialog() {
final AppCompatDialog UnifiedBuildsDialog = new AppCompatDialog(mContext);
UnifiedBuildsDialog.setTitle(R.string.make_choice);
final ArrayList<String> DevName = new ArrayList<>();
ArrayList<String> DevNamesCarriers = new ArrayList<>();
UnifiedBuildsDialog.setContentView(R.layout.dialog_unified_build);
ListView UnifiedList = (ListView) UnifiedBuildsDialog.findViewById(R.id.lvUnifiedList);
ArrayAdapter<String> UnifiedAdapter = new ArrayAdapter<>(mContext, android.R.layout.simple_list_item_1, DevNamesCarriers);
if (UnifiedList != null) {
UnifiedList.setAdapter(UnifiedAdapter);
UnifiedList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
UnifiedBuildsDialog.dismiss();
final ProgressDialog reloading = new ProgressDialog(mContext);
reloading.setMessage(mContext.getString(R.string.reloading));
reloading.setCancelable(false);
reloading.show();
new Thread(new Runnable() {
@Override
public void run() {
Common.setBooleanPref(mContext, Const.PREF_NAME, Const.PREF_KEY_SHOW_UNIFIED, false);
RashrApp.DEVICE.setName(DevName.get(position));
RashrApp.DEVICE.loadRecoveryList();
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
reloading.dismiss();
mActivity.switchTo(FlashFragment.newInstance(mActivity));
}
});
}
}).start();
}
});
}
if (RashrApp.DEVICE.getManufacture().equals("samsung")) {
String[] unifiedGalaxyS3 = { "d2lte", "d2att", "d2cri", "d2mtr", "d2spr", "d2tmo", "d2usc", "d2vzw" };
String[] unifiedGalaxyNote3 = { "hlte", "hltespr", "hltetmo", "hltevzw", "htlexx" };
String[] unifiedGalaxyS4 = { "jflte", "jflteatt", "jfltecan", "jfltecri", "jfltecsp", "jfltespr", "jfltetmo", "jflteusc", "jfltevzw", "jfltexx", "jgedlte" };
String[] unifiedGalaxyNote4 = { "trlte", "trltecan", "trltedt", "trltexx", "trltespr", "trltetmo", "trltevzw", "trlteusc" };
if (Common.stringEndsWithArray(RashrApp.DEVICE.getName(), unifiedGalaxyS3)) {
DevName.addAll(Arrays.asList(unifiedGalaxyS3));
} else if (Common.stringEndsWithArray(RashrApp.DEVICE.getName(), unifiedGalaxyS3)) {
DevName.addAll(Arrays.asList(unifiedGalaxyNote3));
} else if (Common.stringEndsWithArray(RashrApp.DEVICE.getName(), unifiedGalaxyS4)) {
DevName.addAll(Arrays.asList(unifiedGalaxyS4));
} else if (Common.stringEndsWithArray(RashrApp.DEVICE.getName(), unifiedGalaxyNote4)) {
DevName.addAll(Arrays.asList(unifiedGalaxyNote4));
}
}
if (RashrApp.DEVICE.getManufacture().equals("motorola")) {
String[] unifiedMsm8960 = { "moto_msm8960" };
if (RashrApp.DEVICE.getBOARD().equals("msm8960")) {
DevName.addAll(Arrays.asList(unifiedMsm8960));
}
}
for (String i : DevName) {
if (i.contains("att")) {
DevNamesCarriers.add(i + " (AT&T Mobility)");
} else if (i.contains("can")) {
DevNamesCarriers.add(i + " (Canada)");
} else if (i.contains("cri")) {
DevNamesCarriers.add(i + " (Cricket Wireless)");
} else if (i.contains("csp")) {
DevNamesCarriers.add(i + " (C Spire Wireless)");
} else if (i.contains("mtr")) {
DevNamesCarriers.add(i + " (MetroPCS)");
} else if (i.contains("spr")) {
DevNamesCarriers.add(i + " (Sprint Corporation)");
} else if (i.contains("tmo")) {
DevNamesCarriers.add(i + " (T-Mobile US)");
} else if (i.contains("usc")) {
DevNamesCarriers.add(i + " (U.S. Cellular)");
} else if (i.contains("vzw")) {
DevNamesCarriers.add(i + " (Verizon Wireless)");
} else if (i.contains("xx")) {
DevNamesCarriers.add(i + " (International)");
} else if (i.contains("ged")) {
DevNamesCarriers.add(i + " (Google Play Edition)");
} else if (i.contains("dt")) {
DevNamesCarriers.add(i + " (India)");
} else {
DevNamesCarriers.add(i + " (Unified)");
}
}
AppCompatButton KeepCurrent = (AppCompatButton) UnifiedBuildsDialog.findViewById(R.id.bKeepCurrent);
if (KeepCurrent != null) {
KeepCurrent.setText(String.format(getString(R.string.keep_current_name), RashrApp.DEVICE.getName()));
KeepCurrent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Common.setBooleanPref(mContext, Const.PREF_NAME, Const.PREF_KEY_SHOW_UNIFIED, false);
UnifiedBuildsDialog.dismiss();
}
});
}
if (DevName.size() > 0) {
UnifiedBuildsDialog.show();
UnifiedBuildsDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
Common.setBooleanPref(mContext, Const.PREF_NAME, Const.PREF_KEY_SHOW_UNIFIED, false);
}
});
}
}
use of android.support.v7.widget.AppCompatButton in project Rashr by DsLNeXuS.
the class RecoverySystemFragment method onCreateView.
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
mActivity = (RashrActivity) getActivity();
final ScrollView root = (ScrollView) inflater.inflate(R.layout.fragment_recovery_system, container, false);
mContext = root.getContext();
final AppCompatTextView tvTitle = (AppCompatTextView) root.findViewById(R.id.tvSysName);
tvTitle.setText(mTitle.toUpperCase());
final AppCompatTextView tvDesc = (AppCompatTextView) root.findViewById(R.id.tvRecSysDesc);
tvDesc.setText(mDesc);
final AppCompatSpinner spVersions = (AppCompatSpinner) root.findViewById(R.id.spVersions);
ArrayList<String> formatedVersions = new ArrayList<>();
for (String versionLinks : mVersions) {
formatedVersions.add(formatName(versionLinks, mTitle));
}
final ArrayAdapter<String> adapter = new ArrayAdapter<>(root.getContext(), android.R.layout.simple_list_item_1, formatedVersions);
spVersions.setAdapter(adapter);
spVersions.setSelection(0);
final AppCompatTextView tvDev = (AppCompatTextView) root.findViewById(R.id.tvDevName);
tvDev.setText(mDev);
final AppCompatImageView imLogo = (AppCompatImageView) root.findViewById(R.id.ivRecLogo);
if (mLogo == 0) {
root.removeView(imLogo);
} else {
imLogo.setImageResource(mLogo);
}
final AppCompatButton bFlash = (AppCompatButton) root.findViewById(R.id.bFlashRecovery);
bFlash.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
flashSupportedRecovery(mTitle, mVersions.get(spVersions.getSelectedItemPosition()));
}
});
final LinearLayout ScreenshotLayout = (LinearLayout) root.findViewById(R.id.ScreenshotLayout);
if (mScreenshotURL == null) {
((ViewGroup) ScreenshotLayout.getParent()).removeView(ScreenshotLayout);
} else {
try {
Downloader jsonDownloader = new Downloader(new URL(mScreenshotURL + "/getScreenshots.php"), new File(mContext.getExternalCacheDir(), "screenhots.json"));
jsonDownloader.setOverrideFile(true);
jsonDownloader.setOnDownloadListener(new Downloader.OnDownloadListener() {
@Override
public void onSuccess(File file) {
try {
JSONArray arr = new JSONArray(Common.fileContent(file));
for (int i = 0; i < arr.length(); i++) {
final String name = arr.get(i).toString();
if (name.equals(".") || name.equals("..") || name.equals("getScreenshots.php"))
continue;
Downloader imageDownloader = new Downloader(new URL(mScreenshotURL + "/" + name), new File(file.getParentFile(), name));
//Do not redownload predownloaded images
imageDownloader.setOverrideFile(false);
imageDownloader.setOnDownloadListener(new Downloader.OnDownloadListener() {
@Override
public void onSuccess(File file) {
AppCompatImageView iv = (AppCompatImageView) inflater.inflate(R.layout.recovery_screenshot, null);
try {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
Bitmap screenshot = BitmapFactory.decodeFile(file.toString());
iv.setImageBitmap(screenshot);
ScreenshotLayout.addView(iv);
} catch (OutOfMemoryError e) {
App.ERRORS.add("Screenshot " + file.toString() + " could not be decoded " + e.toString());
}
}
@Override
public void onFail(Exception e) {
}
});
imageDownloader.download();
}
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
onFail(e);
}
}
@Override
public void onFail(Exception e) {
e.printStackTrace();
}
});
jsonDownloader.download();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
return root;
}
Aggregations