Skip to content

Commit

Permalink
Set launcher dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyAdshead committed Feb 21, 2017
1 parent a1eff9b commit 48c802d
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions app/src/main/java/com/baronkiko/launcherhijack/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,24 @@ public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
// get the list adapter
AppInfoAdapter appInfoAdapter = (AppInfoAdapter) parent.getAdapter();
// get selected item on the list
ApplicationInfo appInfo = (ApplicationInfo) appInfoAdapter.getItem(pos);

// We need an Editor object to make preference changes.
// All objects are from android.context.Context
SharedPreferences settings = getSharedPreferences("LauncherHijack", MODE_WORLD_READABLE);
SharedPreferences.Editor editor = settings.edit();
editor.putString("ChosenLauncher", appInfo.packageName);
editor.commit(); // Commit the edits!

final ApplicationInfo appInfo = (ApplicationInfo) appInfoAdapter.getItem(pos);

// Notify User
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("Launcher Set");
alertDialog.setMessage("Your launcher has been set to " + appInfo.loadLabel(getPackageManager()) + " (" + appInfo.packageName + ")");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
alertDialog.setTitle("Set Launcher");
alertDialog.setMessage("Set your launcher to " + appInfo.loadLabel(getPackageManager()) + " (" + appInfo.packageName + ")");
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// We need an Editor object to make preference changes.
// All objects are from android.context.Context
SharedPreferences settings = getSharedPreferences("LauncherHijack", MODE_WORLD_READABLE);
SharedPreferences.Editor editor = settings.edit();
editor.putString("ChosenLauncher", appInfo.packageName);
editor.commit(); // Commit the edits!
}
});
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
Expand Down

0 comments on commit 48c802d

Please sign in to comment.