This repository has been archived by the owner on May 7, 2024. It is now read-only.
forked from PurpleGuitar/MWM-for-Android
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optionally send all notifications to watch, with blacklist.
- Loading branch information
1 parent
695e826
commit f592ec2
Showing
11 changed files
with
321 additions
and
27 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
> | ||
<LinearLayout android:id="@+id/app_blacklist_layout" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent"> | ||
<ListView android:id="@android:id/list" | ||
android:layout_height="fill_parent" | ||
android:layout_width="fill_parent"> | ||
</ListView> | ||
</LinearLayout> | ||
</LinearLayout> |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="fill_parent" android:layout_height="wrap_content"> | ||
<ImageView android:id="@+id/app_blacklist_list_item_icon" | ||
android:layout_width="48dp" android:layout_height="48dp" | ||
android:layout_marginRight="6dip" android:src="@drawable/icon" /> | ||
<TextView android:layout_width="wrap_content" android:layout_weight="1" | ||
android:layout_height="wrap_content" android:id="@+id/app_blacklist_list_item_name" | ||
android:textSize="30px" android:text="Hello There"></TextView> | ||
<CheckBox android:id="@+id/app_blacklist_list_item_check" | ||
android:layout_width="wrap_content" android:layout_height="wrap_content" | ||
android:layout_marginLeft="4px" android:layout_marginRight="10px"></CheckBox> | ||
</LinearLayout> |
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 |
---|---|---|
@@ -0,0 +1,173 @@ | ||
package org.metawatch.manager; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import android.app.Activity; | ||
import android.app.ProgressDialog; | ||
import android.content.SharedPreferences; | ||
import android.content.pm.PackageInfo; | ||
import android.content.pm.PackageManager; | ||
import android.graphics.drawable.Drawable; | ||
import android.os.AsyncTask; | ||
import android.os.Bundle; | ||
import android.preference.PreferenceManager; | ||
import android.util.Log; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.CheckBox; | ||
import android.widget.CompoundButton; | ||
import android.widget.CompoundButton.OnCheckedChangeListener; | ||
import android.widget.ImageView; | ||
import android.widget.ListView; | ||
import android.widget.TextView; | ||
|
||
public class AppBlacklist extends Activity { | ||
|
||
public static final String DEFAULT_BLACKLIST = "com.android.mms,com.google.android.gm,com.fsck.k9,com.android.alarmclock,com.htc.android.worldclock,com.android.deskclock,com.sonyericsson.alarm"; | ||
private List<AppInfo> appInfos; | ||
|
||
private class AppLoader extends AsyncTask<Void, Void, List<AppInfo>> { | ||
private ProgressDialog pdWait; | ||
|
||
@Override | ||
protected void onPreExecute() { | ||
pdWait = new ProgressDialog(AppBlacklist.this); | ||
pdWait.setTitle("Loading apps, please wait..."); | ||
pdWait.show(); | ||
} | ||
|
||
@Override | ||
protected List<AppInfo> doInBackground(Void... params) { | ||
SharedPreferences sharedPreferences = PreferenceManager | ||
.getDefaultSharedPreferences(AppBlacklist.this); | ||
String blacklist = sharedPreferences.getString("appBlacklist", | ||
DEFAULT_BLACKLIST); | ||
PackageManager pm = getPackageManager(); | ||
List<PackageInfo> packages = pm.getInstalledPackages(0); | ||
List<AppInfo> appInfos = new ArrayList<AppInfo>(); | ||
for (PackageInfo pi : packages) { | ||
/* Ignore system (non-versioned) packages */ | ||
if (pi.versionName == null) { | ||
continue; | ||
} | ||
/* Ignore Android System */ | ||
if (pi.packageName.equals("android")) { | ||
continue; | ||
} | ||
AppInfo appInfo = new AppInfo(); | ||
appInfo.packageInfo = pi; | ||
appInfo.name = appInfo.packageInfo.applicationInfo | ||
.loadLabel(pm).toString(); | ||
appInfo.icon = appInfo.packageInfo.applicationInfo.loadIcon(pm); | ||
appInfo.isBlacklisted = blacklist.contains(pi.packageName); | ||
appInfos.add(appInfo); | ||
} | ||
Collections.sort(appInfos); | ||
|
||
// for (AppInfo appInfo : appInfos) { | ||
// Log.d(MetaWatch.TAG, "appName='" + appInfo.name | ||
// + "' packageName='" + appInfo.packageInfo.packageName + | ||
// "' selected=" | ||
// + appInfo.selected); | ||
// } | ||
|
||
return appInfos; | ||
} | ||
|
||
@Override | ||
protected void onPostExecute(List<AppInfo> appInfos) { | ||
|
||
ListView listView = (ListView) findViewById(android.R.id.list); | ||
// listView.setAdapter(new ArrayAdapter<String>(this, | ||
// android.R.layout.simple_list_item_1, menuList)); | ||
listView.setAdapter(new BlacklistAdapter(AppBlacklist.this, | ||
appInfos)); | ||
AppBlacklist.this.appInfos = appInfos; | ||
pdWait.dismiss(); | ||
|
||
} | ||
|
||
} | ||
|
||
public class AppInfo implements Comparable<AppInfo> { | ||
String name; | ||
Drawable icon; | ||
PackageInfo packageInfo; | ||
boolean isBlacklisted; | ||
|
||
public int compareTo(AppInfo another) { | ||
return this.name.compareTo(another.name); | ||
} | ||
} | ||
|
||
class BlacklistAdapter extends ArrayAdapter<AppInfo> { | ||
private final Activity context; | ||
private final List<AppInfo> apps; | ||
|
||
public BlacklistAdapter(Activity context, List<AppInfo> apps) { | ||
super(context, R.layout.app_blacklist_list_item, apps); | ||
this.context = context; | ||
this.apps = apps; | ||
} | ||
|
||
@Override | ||
public View getView(int position, View convertView, ViewGroup parent) { | ||
View view = null; | ||
LayoutInflater inflater = context.getLayoutInflater(); | ||
view = inflater.inflate(R.layout.app_blacklist_list_item, null); | ||
ImageView icon = (ImageView) view | ||
.findViewById(R.id.app_blacklist_list_item_icon); | ||
TextView appName = (TextView) view | ||
.findViewById(R.id.app_blacklist_list_item_name); | ||
CheckBox checkbox = (CheckBox) view | ||
.findViewById(R.id.app_blacklist_list_item_check); | ||
final AppInfo appInfo = apps.get(position); | ||
icon.setImageDrawable(appInfo.icon); | ||
appName.setText(appInfo.name); | ||
checkbox.setChecked(appInfo.isBlacklisted); | ||
checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() { | ||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | ||
appInfo.isBlacklisted = isChecked; | ||
} | ||
}); | ||
return view; | ||
} | ||
|
||
} | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
setContentView(R.layout.app_blacklist); | ||
|
||
AppLoader appLoader = new AppLoader(); | ||
appLoader.execute((Void[]) null); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
StringBuilder sb = new StringBuilder(); | ||
for (AppInfo appInfo : appInfos) { | ||
if (appInfo.isBlacklisted) { | ||
if (sb.length() > 0) { | ||
sb.append(","); | ||
} | ||
sb.append(appInfo.packageInfo.packageName); | ||
} | ||
} | ||
SharedPreferences sharedPreferences = PreferenceManager | ||
.getDefaultSharedPreferences(this); | ||
SharedPreferences.Editor editor = sharedPreferences.edit(); | ||
String blacklist = sb.toString(); | ||
editor.putString("appBlacklist", blacklist); | ||
editor.commit(); | ||
Log.d(MetaWatch.TAG, "App blacklist: " + blacklist); | ||
} | ||
|
||
} |
Oops, something went wrong.