List of usage examples for android.support.v4.app AlertDialog.Builder setIcon
public void setIcon(Drawable icon)
From source file:com.appteam.nimbus.activity.homeActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_logout) { personalData.SaveData(false);/*from w ww . j a v a2 s. c o m*/ Intent launch_logout = new Intent(homeActivity.this, Login.class); launch_logout.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); launch_logout.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); launch_logout.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(launch_logout); finish(); return true; } else if (id == R.id.action_leaderboard) { startActivity(new Intent(homeActivity.this, Leaderboard.class)); return true; } else if (id == R.id.action_important_contact) { CharSequence name[] = { "Ankush Sharma\n(Discipline Secretary)", "Rishabh Kumar\n(Discipline Joint Secretary)", "Kumud Jindal\n(Discipline Joint Secretary)", }; final CharSequence number[] = { "9736688292", "8627090570", "9882263949" }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setIcon(android.R.drawable.ic_menu_call); builder.setTitle("Emergency Contact"); builder.setItems(name, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:+91" + number[i])); startActivity(intent); } }); AlertDialog alertDialog = builder.create(); alertDialog.show(); } return super.onOptionsItemSelected(item); }
From source file:appteam.nith.hillffair.activities.HomeActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.logout) { pref.setUserId(null);//from w w w. j a va2s . co m pref.setRollNo(null); pref.setUserName(null); startActivity(new Intent(HomeActivity.this, LoginActivity.class)); finish(); return true; } else if (id == R.id.contacts) { CharSequence name[] = { "Deepak Kumar Jain\n(Hillffair Secretary)\n9882654141\n", "Rishabh Bhandari\n(Clubs Secretary)\n9882852966\n" }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setIcon(android.R.drawable.ic_menu_call); builder.setTitle("Emergency Contact"); builder.setItems(name, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { a = i; call(a); } }); AlertDialog alertDialog = builder.create(); alertDialog.show(); } return super.onOptionsItemSelected(item); }
From source file:com.appteam.nimbus.activity.homeActivity.java
@SuppressWarnings("StatementWithEmptyBody") @Override//from w ww . j av a 2 s.c om public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.navigation_to_profile) { // Handle the camera action Intent i = new Intent(homeActivity.this, Profile.class); startActivity(i); } else if (id == R.id.aboutus_nav) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(String.format("%1$s", getString(R.string.app_name))); builder.setMessage(getResources().getText(R.string.aboutus_text)); builder.setPositiveButton("OK", null); builder.setIcon(R.mipmap.nimbus16); AlertDialog welcomeAlert = builder.create(); welcomeAlert.show(); ((TextView) welcomeAlert.findViewById(android.R.id.message)) .setMovementMethod(LinkMovementMethod.getInstance()); } else if (id == R.id.feedback_nav) { Intent intent = new Intent(Intent.ACTION_SENDTO); String uriText = "mailto:" + Uri.encode("appteam.nith@gmail.com") + "?subject=" + Uri.encode("Reporting A Bug/Feedback") + "&body=" + Uri.encode( "Hello, Appteam \nI want to report a bug/give feedback corresponding to the app Nimbus 2k16.\n.....\n\n-Your name"); Uri uri = Uri.parse(uriText); intent.setData(uri); startActivity(Intent.createChooser(intent, "Send Email")); } else if (id == R.id.opensourcelicenses_nav) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(String.format("%1$s", getString(R.string.open_source_licenses))); builder.setMessage(getResources().getText(R.string.licenses_text)); builder.setPositiveButton("OK", null); //builder.setIcon(R.mipmap.nimbus_icon); AlertDialog welcomeAlert = builder.create(); welcomeAlert.show(); ((TextView) welcomeAlert.findViewById(android.R.id.message)) .setMovementMethod(LinkMovementMethod.getInstance()); } else if (id == R.id.contributors_nav) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(String.format("%1$s", getString(R.string.contributors))); builder.setMessage(getResources().getText(R.string.contributors_text)); builder.setPositiveButton("OK", null); //builder.setIcon(R.mipmap.nimbus_icon); AlertDialog welcomeAlert = builder.create(); welcomeAlert.show(); ((TextView) welcomeAlert.findViewById(android.R.id.message)) .setMovementMethod(LinkMovementMethod.getInstance()); } else if (id == R.id.notifications) { startActivity(new Intent(homeActivity.this, ViewActivity.class)); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
From source file:appteam.nith.hillffair.activities.HomeActivity.java
@SuppressWarnings("StatementWithEmptyBody") @Override/*from w w w. java 2 s .co m*/ public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); switch (id) { case R.id.profile: startActivity(new Intent(HomeActivity.this, ProfileActivity.class)); break; case R.id.settings: startActivity(new Intent(HomeActivity.this, SettingsActivity.class)); finish(); break; case R.id.aboutus: AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(String.format("%1$s", getString(R.string.app_name))); builder.setMessage(getResources().getText(R.string.aboutus_text)); builder.setPositiveButton("OK", null); builder.setIcon(R.drawable.ic_action_about); AlertDialog welcomeAlert = builder.create(); welcomeAlert.show(); break; case R.id.report: Intent intent = new Intent(Intent.ACTION_SENDTO); String uriText = "mailto:" + Uri.encode("appteam.nith@gmail.com") + "?subject=" + Uri.encode("Reporting A Bug/Feedback") + "&body=" + Uri.encode( "Hello, Appteam \nI want to report a bug/give feedback corresponding to the app Hillfair 2k16.\n.....\n\n-Your name"); Uri uri = Uri.parse(uriText); intent.setData(uri); startActivity(Intent.createChooser(intent, "Send Email")); break; case R.id.license: AlertDialog.Builder builder2 = new AlertDialog.Builder(this); builder2.setTitle(String.format("%1$s", getString(R.string.open_source_licenses))); CharSequence str = getResources().getText(R.string.licenses_text); builder2.setMessage(str); builder2.setPositiveButton("OK", null); AlertDialog welcomeAlert2 = builder2.create(); welcomeAlert2.show(); ((TextView) welcomeAlert2.findViewById(android.R.id.message)) .setMovementMethod(LinkMovementMethod.getInstance()); break; case R.id.notification: startActivity(new Intent(HomeActivity.this, NotificationActivity.class)); break; case R.id.logout: pref.setUserId(null); pref.setRollNo(null); pref.setUserName(null); startActivity(new Intent(HomeActivity.this, LoginActivity.class)); finish(); break; } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
From source file:eu.basicairdata.graziano.gpslogger.GPSActivity.java
private void ShutdownApp() { if ((GPSApplication.getInstance().getCurrentTrack().getNumberOfLocations() > 0) || (GPSApplication.getInstance().getCurrentTrack().getNumberOfPlacemarks() > 0) || (GPSApplication.getInstance().getRecording()) || (GPSApplication.getInstance().getPlacemarkRequest())) { AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(this, R.style.StyledDialog)); builder.setMessage(getResources().getString(R.string.message_exit_confirmation)); builder.setIcon(android.R.drawable.ic_menu_info_details); builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { GPSApplication.getInstance().setRecording(false); GPSApplication.getInstance().setPlacemarkRequest(false); EventBus.getDefault().post(EventBusMSG.NEW_TRACK); GPSApplication.getInstance().StopAndUnbindGPSService(); GPSApplication.getInstance().setLocationPermissionChecked(false); dialog.dismiss();//from w w w. j a v a2 s. c o m finish(); } }); builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); AlertDialog dialog = builder.create(); dialog.show(); } else { GPSApplication.getInstance().setRecording(false); GPSApplication.getInstance().setPlacemarkRequest(false); GPSApplication.getInstance().StopAndUnbindGPSService(); GPSApplication.getInstance().setLocationPermissionChecked(false); finish(); } }
From source file:com.duy.pascal.ui.editor.BaseEditorActivity.java
@Override public void doRemoveFile(@NonNull final File file) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(getString(R.string.remove_file_msg) + " " + file.getName()); builder.setTitle(R.string.delete_file); builder.setIcon(R.drawable.ic_delete_forever_white_24dp); builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override//from w w w .j a va2 s. c o m public void onClick(DialogInterface dialog, int which) { int position = mPagerAdapter.getPositionForTag(file.getPath()); boolean success = FileUtils.deleteRecursive(file); if (success) { if (position >= 0) { removePage(position); } Toast.makeText(getApplicationContext(), R.string.deleted, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), R.string.failed, Toast.LENGTH_SHORT).show(); } //reload file FileExplorerView controller = (FileExplorerView) getSupportFragmentManager() .findFragmentByTag("fragment_file_view"); if (controller != null) { controller.refresh(); } else { DLog.d(TAG, "onClick: Fragment file is null"); } } }); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); builder.create().show(); }
From source file:eu.basicairdata.graziano.gpslogger.FragmentTracklist.java
@Override public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.cardmenu_delete: if (!data.isEmpty() && (selectedtrackID >= 0)) { final Track track = GPSApplication.getInstance().GPSDataBase.getTrack(selectedtrackID); if (track != null) { boolean fileexist = FileExists( Environment.getExternalStorageDirectory() + "/GPSLogger/" + track.getName() + ".kml") || FileExists(Environment.getExternalStorageDirectory() + "/GPSLogger/" + track.getName() + ".gpx") || FileExists(Environment.getExternalStorageDirectory() + "/GPSLogger/" + track.getName() + ".txt"); if (fileexist) { AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(getActivity(), R.style.StyledDialog)); builder.setMessage(getResources().getString(R.string.card_message_delete_also_exported)); builder.setIcon(android.R.drawable.ic_menu_info_details); builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String name = track.getName(); String nameID = String.valueOf(track.getId()); EventBus.getDefault() .post(new EventBusMSGNormal(EventBusMSG.DELETE_TRACK, track.getId())); getActivity().runOnUiThread(new Runnable() { @Override public void run() { int i = 0; boolean found = false; synchronized (data) { do { if (data.get(i).getId() == selectedtrackID) { found = true; data.remove(i); adapter.notifyItemRemoved(i); if (data.isEmpty()) TVTracklistEmpty.setVisibility(View.VISIBLE); } i++; } while ((i < data.size()) && !found); }//from w w w. java 2s .c o m } }); // Delete exported files DeleteFile( Environment.getExternalStorageDirectory() + "/GPSLogger/" + name + ".txt"); DeleteFile( Environment.getExternalStorageDirectory() + "/GPSLogger/" + name + ".kml"); DeleteFile( Environment.getExternalStorageDirectory() + "/GPSLogger/" + name + ".gpx"); // Delete track files DeleteFile(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/" + name + ".txt"); DeleteFile(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/" + name + ".kml"); DeleteFile(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/" + name + ".gpx"); DeleteFile(getContext().getFilesDir() + "/Thumbnails/" + nameID + ".png"); dialog.dismiss(); } }); builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String name = track.getName(); String nameID = String.valueOf(track.getId()); EventBus.getDefault() .post(new EventBusMSGNormal(EventBusMSG.DELETE_TRACK, track.getId())); getActivity().runOnUiThread(new Runnable() { @Override public void run() { int i = 0; boolean found = false; synchronized (data) { do { if (data.get(i).getId() == selectedtrackID) { found = true; data.remove(i); adapter.notifyItemRemoved(i); if (data.isEmpty()) TVTracklistEmpty.setVisibility(View.VISIBLE); } i++; } while ((i < data.size()) && !found); } } }); // Delete track files DeleteFile(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/" + name + ".txt"); DeleteFile(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/" + name + ".kml"); DeleteFile(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/" + name + ".gpx"); DeleteFile(getContext().getFilesDir() + "/Thumbnails/" + nameID + ".png"); dialog.dismiss(); } }); builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); AlertDialog dialog = builder.create(); dialog.show(); } else { AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(getActivity(), R.style.StyledDialog)); builder.setMessage(getResources().getString(R.string.card_message_delete_confirmation)); builder.setIcon(android.R.drawable.ic_menu_info_details); builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String name = track.getName(); String nameID = String.valueOf(track.getId()); EventBus.getDefault() .post(new EventBusMSGNormal(EventBusMSG.DELETE_TRACK, track.getId())); getActivity().runOnUiThread(new Runnable() { @Override public void run() { int i = 0; boolean found = false; synchronized (data) { do { if (data.get(i).getId() == selectedtrackID) { found = true; data.remove(i); adapter.notifyItemRemoved(i); if (data.isEmpty()) TVTracklistEmpty.setVisibility(View.VISIBLE); } i++; } while ((i < data.size()) && !found); } } }); // Delete track files DeleteFile(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/" + name + ".txt"); DeleteFile(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/" + name + ".kml"); DeleteFile(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/" + name + ".gpx"); DeleteFile(getContext().getFilesDir() + "/Thumbnails/" + nameID + ".png"); dialog.dismiss(); } }); builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); AlertDialog dialog = builder.create(); dialog.show(); } } else Update(); // Update the Tracklist!! } break; case R.id.cardmenu_export: if (!data.isEmpty() && (selectedtrackID >= 0)) { int i = 0; boolean found = false; synchronized (data) { do { if (data.get(i).getId() == selectedtrackID) { found = true; if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // Store the message to send in case the storage permission will be granted GPSApplication.getInstance().setDoIfGrantStoragePermission( new EventBusMSGNormal(EventBusMSG.EXPORT_TRACK, data.get(i).getId())); // Ask for storage permission CheckStoragePermission(); } else EventBus.getDefault() .post(new EventBusMSGNormal(EventBusMSG.EXPORT_TRACK, data.get(i).getId())); } i++; } while ((i < data.size()) && !found); } } break; case R.id.cardmenu_view: if (!data.isEmpty() && (selectedtrackID >= 0)) { int i = 0; boolean found = false; synchronized (data) { do { if (data.get(i).getId() == selectedtrackID) { found = true; if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // Store the message to send in case the storage permission will be granted GPSApplication.getInstance().setDoIfGrantStoragePermission( new EventBusMSGNormal(EventBusMSG.VIEW_TRACK, data.get(i).getId())); // Ask for storage permission CheckStoragePermission(); } else EventBus.getDefault() .post(new EventBusMSGNormal(EventBusMSG.VIEW_TRACK, data.get(i).getId())); } i++; } while ((i < data.size()) && !found); } } break; case R.id.cardmenu_share: if (!data.isEmpty() && (selectedtrackID >= 0)) { int i = 0; boolean found = false; synchronized (data) { do { if (data.get(i).getId() == selectedtrackID) { found = true; if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // Store the message to send in case the storage permission will be granted GPSApplication.getInstance().setDoIfGrantStoragePermission( new EventBusMSGNormal(EventBusMSG.SHARE_TRACK, data.get(i).getId())); // Ask for storage permission CheckStoragePermission(); } else EventBus.getDefault() .post(new EventBusMSGNormal(EventBusMSG.SHARE_TRACK, data.get(i).getId())); } i++; } while ((i < data.size()) && !found); } } break; default: //TODO: selectedtrackID = -1; return false; } return true; }
From source file:github.popeen.dsub.fragments.SelectDirectoryFragment.java
private void showDonationDialog(int trialDaysLeft, final LoadingTask onValid) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setIcon(android.R.drawable.ic_dialog_info); if (trialDaysLeft == 0) { builder.setTitle(R.string.select_album_donate_dialog_0_trial_days_left); } else {/*from ww w. j a v a 2 s .co m*/ builder.setTitle(context.getResources().getQuantityString( R.plurals.select_album_donate_dialog_n_trial_days_left, trialDaysLeft, trialDaysLeft)); } builder.setMessage(R.string.select_album_donate_dialog_message); builder.setPositiveButton(R.string.select_album_donate_dialog_now, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.DONATION_URL))); } }); builder.setNegativeButton(R.string.select_album_donate_dialog_later, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); if (onValid != null) { onValid.execute(); } } }); builder.create().show(); }
From source file:com.xperia64.rompatcher.MainActivity.java
public void patch(final boolean c, final boolean d, final boolean r, final String ed) { final ProgressDialog myPd_ring = ProgressDialog.show(MainActivity.this, getResources().getString(R.string.wait), getResources().getString(R.string.wait_desc), true); myPd_ring.setCancelable(false);// w ww. j a va 2 s. co m new Thread(new Runnable() { public void run() { if (new File(Globals.patchToApply).exists() && new File(Globals.fileToPatch).exists() && !Globals.fileToPatch.toLowerCase(Locale.US).endsWith(".ecm")) { String msg = getResources().getString(R.string.success); if (!new File(Globals.fileToPatch).canWrite()) { Globals.msg = msg = "Can not write to output file. If you are on KitKat or Lollipop, move the file to your internal storage."; return; } if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".ups")) { int e = upsPatchRom(Globals.fileToPatch, Globals.patchToApply, Globals.fileToPatch + ".new", r ? 1 : 0); if (e != 0) { msg = parseError(e, Globals.TYPE_UPS); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".xdelta") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".xdelta3") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".vcdiff")) { RandomAccessFile f = null; try { f = new RandomAccessFile(Globals.patchToApply, "r"); } catch (FileNotFoundException e1) { e1.printStackTrace(); Globals.msg = msg = getResources().getString(R.string.fnf); return; } StringBuilder s = new StringBuilder(); try { if (f.length() >= 9) { for (int i = 0; i < 8; i++) { s.append((char) f.readByte()); f.seek(i + 1); } } } catch (IOException e1) { e1.printStackTrace(); } try { f.close(); } catch (IOException e1) { e1.printStackTrace(); } // Header of xdelta patch determines version if (s.toString().equals("%XDELTA%") || s.toString().equals("%XDZ000%") || s.toString().equals("%XDZ001%") || s.toString().equals("%XDZ002%") || s.toString().equals("%XDZ003%") || s.toString().equals("%XDZ004%")) { int e = xdelta1PatchRom(Globals.fileToPatch, Globals.patchToApply, Globals.fileToPatch + ".new"); if (e != 0) { msg = parseError(e, Globals.TYPE_XDELTA1); } } else { int e = xdelta3PatchRom(Globals.fileToPatch, Globals.patchToApply, Globals.fileToPatch + ".new"); if (e != 0) { msg = parseError(e, Globals.TYPE_XDELTA3); } } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".bps")) { int e = bpsPatchRom(Globals.fileToPatch, Globals.patchToApply, Globals.fileToPatch + ".new", r ? 1 : 0); if (e != 0) { msg = parseError(e, Globals.TYPE_BPS); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".dps")) { int e = dpsPatchRom(Globals.fileToPatch, Globals.patchToApply, Globals.fileToPatch + ".new"); if (e != 0) { msg = parseError(e, Globals.TYPE_DPS); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".bsdiff")) { int e = bsdiffPatchRom(Globals.fileToPatch, Globals.patchToApply, Globals.fileToPatch + ".new"); if (e != 0) { msg = parseError(e, Globals.TYPE_BSDIFF); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".aps")) { File f = new File(Globals.fileToPatch); File f2 = new File(Globals.fileToPatch + ".bak"); try { Files.copy(f, f2); } catch (IOException e) { e.printStackTrace(); } // Wow. byte[] gbaSig = { 0x41, 0x50, 0x53, 0x31, 0x00 }; byte[] n64Sig = { 0x41, 0x50, 0x53, 0x31, 0x30 }; byte[] realSig = new byte[5]; RandomAccessFile raf = null; System.out.println("APS Patch"); try { raf = new RandomAccessFile(Globals.patchToApply, "r"); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); Globals.msg = msg = getResources().getString(R.string.fnf); return; } try { raf.read(realSig); raf.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (Arrays.equals(realSig, gbaSig)) { System.out.println("GBA APS"); APSGBAPatcher aa = new APSGBAPatcher(); aa.crcTableInit(); int e = 0; try { e = aa.ApplyPatch(Globals.patchToApply, Globals.fileToPatch, r); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); e = -5; } System.out.println("e: " + e); if (e != 0) { msg = parseError(e, Globals.TYPE_APSGBA); } } else if (Arrays.equals(realSig, n64Sig)) { System.out.println("N64 APS"); int e = apsN64PatchRom(Globals.fileToPatch, Globals.patchToApply); if (e != 0) { msg = parseError(e, Globals.TYPE_APSN64); } } else { msg = parseError(-131, -10000); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".ppf")) { File f = new File(Globals.fileToPatch); File f2 = new File(Globals.fileToPatch + ".bak"); try { Files.copy(f, f2); } catch (IOException e) { e.printStackTrace(); } int e = ppfPatchRom(Globals.fileToPatch, Globals.patchToApply, r ? 1 : 0); if (e != 0) { msg = parseError(e, Globals.TYPE_PPF); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".patch")) { int e = xdelta1PatchRom(Globals.fileToPatch, Globals.patchToApply, Globals.fileToPatch + ".new"); if (e != 0) { msg = parseError(e, Globals.TYPE_XDELTA1); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".asm")) { File f = new File(Globals.fileToPatch); File f2 = new File(Globals.fileToPatch + ".bak"); try { Files.copy(f, f2); } catch (IOException e) { e.printStackTrace(); } int e; if (Globals.asar) e = asarPatchRom(Globals.fileToPatch, Globals.patchToApply, r ? 1 : 0); else e = asmPatchRom(Globals.fileToPatch, Globals.patchToApply); if (e != 0) { msg = parseError(e, Globals.TYPE_ASM); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".dldi")) { File f = new File(Globals.fileToPatch); File f2 = new File(Globals.fileToPatch + ".bak"); try { Files.copy(f, f2); } catch (IOException e) { e.printStackTrace(); } int e = dldiPatchRom(Globals.fileToPatch, Globals.patchToApply); if (e != 0) { msg = parseError(e, Globals.TYPE_DLDI); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".xpc")) { int e = xpcPatchRom(Globals.fileToPatch, Globals.patchToApply, Globals.fileToPatch + ".new"); if (e != 0) { msg = parseError(e, Globals.TYPE_XPC); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".nmp")) { String drm = MainActivity.this.getPackageName(); System.out.println("Drm is: " + drm); if (drm.equals("com.xperia64.rompatcher.donation")) { if (c) { File f = new File(Globals.fileToPatch); File f2 = new File(Globals.fileToPatch + ".bak"); try { Files.copy(f, f2); } catch (IOException e) { e.printStackTrace(); } } NitroROMFilesystem fs; try { fs = new NitroROMFilesystem(Globals.fileToPatch); ROM.load(fs); RealPatch.patch(Globals.patchToApply, new Object()); ROM.close(); } catch (Exception e1) { // TODO Auto-generated catch block //e1.printStackTrace(); Globals.msg = msg = String.format(getResources().getString(R.string.nmpDefault), e1.getStackTrace()[0].getFileName(), e1.getStackTrace()[0].getLineNumber()); } if (c && d && !TextUtils.isEmpty(ed)) { File f = new File(Globals.fileToPatch); File f3 = new File(Globals.fileToPatch + ".bak"); File f2 = new File( Globals.fileToPatch.substring(0, Globals.fileToPatch.lastIndexOf('/') + 1) + ed); f.renameTo(f2); f3.renameTo(f); } } else { Globals.msg = msg = getResources().getString(R.string.drmwarning); MainActivity.this.runOnUiThread(new Runnable() { public void run() { AlertDialog.Builder b = new AlertDialog.Builder(MainActivity.this); b.setTitle(getResources().getString(R.string.drmwarning)); b.setIcon( ResourcesCompat.getDrawable(getResources(), R.drawable.icon_pro, null)); b.setMessage(getResources().getString(R.string.drmwarning_desc)); b.setCancelable(false); b.setNegativeButton(getResources().getString(android.R.string.cancel), new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { } }); b.setPositiveButton(getResources().getString(R.string.nagInfo), new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse( "market://details?id=com.xperia64.rompatcher.donation"))); } catch (android.content.ActivityNotFoundException anfe) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse( "http://play.google.com/store/apps/details?id=com.xperia64.rompatcher.donation"))); } } }); b.create().show(); } }); } } else { RandomAccessFile f = null; try { f = new RandomAccessFile(Globals.patchToApply, "r"); } catch (FileNotFoundException e1) { e1.printStackTrace(); Globals.msg = msg = getResources().getString(R.string.fnf); return; } StringBuilder s = new StringBuilder(); try { if (f.length() >= 6) { for (int i = 0; i < 5; i++) { s.append((char) f.readByte()); f.seek(i + 1); } } } catch (IOException e1) { e1.printStackTrace(); } try { f.close(); } catch (IOException e1) { e1.printStackTrace(); } int e; // Two variants of IPS, the normal PATCH type, then this weird one called IPS32 with messily hacked in 32 bit offsets if (s.toString().equals("IPS32")) { e = ips32PatchRom(Globals.fileToPatch, Globals.patchToApply); if (e != 0) { msg = parseError(e, Globals.TYPE_IPS); } } else { e = ipsPatchRom(Globals.fileToPatch, Globals.patchToApply); if (e != 0) { msg = parseError(e, Globals.TYPE_IPS); } } } if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".ups") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".xdelta") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".xdelta3") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".vcdiff") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".patch") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".bps") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".bsdiff") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".dps") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".xpc")) { File oldrom = new File(Globals.fileToPatch); File bkrom = new File(Globals.fileToPatch + ".bak"); oldrom.renameTo(bkrom); File newrom = new File(Globals.fileToPatch + ".new"); newrom.renameTo(oldrom); } if (!c) { File f = new File(Globals.fileToPatch + ".bak"); if (f.exists()) { f.delete(); } } else { if (d) { File one = new File(Globals.fileToPatch + ".bak"); File two = new File(Globals.fileToPatch); File three = new File( Globals.fileToPatch.substring(0, Globals.fileToPatch.lastIndexOf('/') + 1) + ed); two.renameTo(three); File four = new File(Globals.fileToPatch); one.renameTo(four); } } Globals.msg = msg; } else if (Globals.fileToPatch.toLowerCase(Locale.US).endsWith(".ecm")) { int e = 0; String msg = getResources().getString(R.string.success); if (c) { if (d) { e = ecmPatchRom(Globals.fileToPatch, Globals.fileToPatch.substring(0, Globals.fileToPatch.lastIndexOf('/')) + ed, 1); } else { //new File(Globals.fileToPatch).renameTo(new File(Globals.fileToPatch+".bak")); e = ecmPatchRom(Globals.fileToPatch, Globals.fileToPatch.substring(0, Globals.fileToPatch.lastIndexOf('.')), 1); } } else { e = ecmPatchRom(Globals.fileToPatch, "", 0); } if (e != 0) { msg = parseError(e, Globals.TYPE_ECM); } Globals.msg = msg; } else { Globals.msg = getResources().getString(R.string.fnf); } } }).start(); new Thread(new Runnable() { @Override public void run() { try { while (Globals.msg.equals("")) { Thread.sleep(25); } ; myPd_ring.dismiss(); runOnUiThread(new Runnable() { public void run() { Toast t = Toast.makeText(staticThis, Globals.msg, Toast.LENGTH_SHORT); t.show(); Globals.msg = ""; } }); if (Globals.msg.equals(getResources().getString(R.string.success))) // Don't annoy people who did something wrong even further { final SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(MainActivity.this); int x = prefs.getInt("purchaseNag", 5); if (x != -1) { if ((isPackageInstalled("com.xperia64.timidityae", MainActivity.this) || isPackageInstalled("com.xperia64.rompatcher.donation", MainActivity.this))) { prefs.edit().putInt("purchaseNag", -1); } else { if (x >= 5) { prefs.edit().putInt("purchaseNag", 0).commit(); /*runOnUiThread(new Runnable() { public void run() { AlertDialog.Builder b = new AlertDialog.Builder(MainActivity.this); b.setTitle("Like ROM Patcher?"); b.setIcon(getResources().getDrawable(R.drawable.icon_pro)); b.setMessage(getResources().getString(R.string.nagMsg)); b.setCancelable(false); b.setNegativeButton(getResources().getString(android.R.string.cancel), new OnClickListener(){@Override public void onClick(DialogInterface arg0, int arg1) {}}); b.setPositiveButton(getResources().getString(R.string.nagInfo), new OnClickListener(){ @Override public void onClick(DialogInterface arg0, int arg1) { try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.xperia64.rompatcher.donation"))); } catch (android.content.ActivityNotFoundException anfe) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.xperia64.rompatcher.donation"))); } } }); b.create().show(); } }); // end of UIThread*/ } else { prefs.edit().putInt("purchaseNag", x + 1).commit(); } } } } } catch (Exception e) { } } }).start(); }