forked from arthurzaczek/launcherforblind
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reduce the need of Context references by using the global app context
- Loading branch information
1 parent
e09889d
commit 5349aa3
Showing
8 changed files
with
80 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
package net.zaczek.launcherforblind; | ||
|
||
import android.app.Application; | ||
import android.content.Context; | ||
|
||
public class MyApplication extends Application { | ||
public void onCreate() { | ||
super.onCreate(); | ||
} | ||
private static Context context; | ||
|
||
public void onCreate(){ | ||
super.onCreate(); | ||
MyApplication.context = getApplicationContext(); | ||
} | ||
|
||
public static Context getAppContext() { | ||
return MyApplication.context; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 9 additions & 7 deletions
16
src/net/zaczek/launcherforblind/listentries/AppListEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
package net.zaczek.launcherforblind.listentries; | ||
|
||
import net.zaczek.launcherforblind.MyApplication; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.pm.ResolveInfo; | ||
|
||
public class AppListEntry extends AbstractListEntry implements Comparable<AppListEntry> { | ||
public class AppListEntry extends AbstractListEntry implements | ||
Comparable<AppListEntry> { | ||
private ResolveInfo mInfo; | ||
private Context mCtx; | ||
|
||
public AppListEntry(String label, Context ctx, ResolveInfo info) { | ||
public AppListEntry(String label, ResolveInfo info) { | ||
super(label); | ||
mCtx = ctx; | ||
mInfo = info; | ||
} | ||
|
||
@Override | ||
public void onSelected() { | ||
final Intent i = mCtx.getPackageManager().getLaunchIntentForPackage( | ||
final Context ctx = MyApplication.getAppContext(); | ||
final Intent i = ctx.getPackageManager().getLaunchIntentForPackage( | ||
mInfo.activityInfo.packageName); | ||
mCtx.startActivity(i); | ||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
ctx.startActivity(i); | ||
} | ||
|
||
@Override | ||
public int compareTo(AppListEntry another) { | ||
public int compareTo(AppListEntry another) { | ||
return getLabel().compareTo(another.getLabel()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 6 additions & 7 deletions
13
src/net/zaczek/launcherforblind/listentries/SMSListEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters