Android Open Source - DashNotifier Unlock Receiver






From Project

Back to project page DashNotifier.

License

The source code is released under:

MIT License

If you think the Android project DashNotifier listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.umang.dashnotifier;
/*from   w  ww.j a  v a  2 s.  co  m*/
import java.util.ArrayList;

import com.umang.dashnotifier.provider.NotifSQLiteHelper;
import com.umang.dashnotifier.provider.NotificationProvider;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;

public class UnlockReceiver extends BroadcastReceiver {

  //exts must be equal to the number of extensions you want DashNotifier to support
  private static final int exts = 11;
  @Override
  public void onReceive(Context context, Intent intent) {
    Log.d("UnlcokReceiver", "Unlocked");
    ArrayList<String> packageNames = clearOnUnlock(context);
    System.out.println(packageNames.toString());
    
    if ( !packageNames.isEmpty() ){
      int count = context.getContentResolver().delete(NotificationProvider.CONTENT_URI,  
          NotifSQLiteHelper.COL_PNAME  + " IN ( " + makePlaceholders(packageNames.size()) + " )", 
          packageNames.toArray(new String[packageNames.size()]));
      System.out.println("Deleted: "+ Integer.toString(count));
    }
    

  }
  
  private ArrayList<String> clearOnUnlock(Context context){
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    
    ArrayList<String> packages = new ArrayList<String>();
    String pName;
    for (int i = 1 ; i<=exts ; i++){
      if (preferences.getBoolean("clear_on_unlock" + Integer.toString(i), false)){
        pName = preferences.getString("extapp" + Integer.toString(i), "dummy.xx.name");
        if (pName != "dummy.xx.name")
          packages.add(pName);
      }
    }
    return packages;
  }
  
  String makePlaceholders(int len) {
      if (len < 1) {
          // It will lead to an invalid query anyway ..
          throw new RuntimeException("No placeholders");
      } else {
          StringBuilder sb = new StringBuilder(len * 2 - 1);
          sb.append("?");
          for (int i = 1; i < len; i++) {
              sb.append(",?");
          }
          return sb.toString();
      }
  }

}




Java Source Code List

com.google.android.apps.dashclock.configuration.AppChooserPreference.java
com.google.android.apps.dashclock.ui.SimplePagedTabsHelper.java
com.umang.dashnotifier.AbstractSettings.java
com.umang.dashnotifier.AppListFragment.java
com.umang.dashnotifier.AppSelectActivity.java
com.umang.dashnotifier.ClickIntentActivity.java
com.umang.dashnotifier.Commons.java
com.umang.dashnotifier.DashNotificationListenerAcc.java
com.umang.dashnotifier.DashNotificationListener.java
com.umang.dashnotifier.DashNotifierExtension10.java
com.umang.dashnotifier.DashNotifierExtension11.java
com.umang.dashnotifier.DashNotifierExtension2.java
com.umang.dashnotifier.DashNotifierExtension3.java
com.umang.dashnotifier.DashNotifierExtension4.java
com.umang.dashnotifier.DashNotifierExtension5.java
com.umang.dashnotifier.DashNotifierExtension6.java
com.umang.dashnotifier.DashNotifierExtension7.java
com.umang.dashnotifier.DashNotifierExtension8.java
com.umang.dashnotifier.DashNotifierExtension9.java
com.umang.dashnotifier.DashNotifierExtension.java
com.umang.dashnotifier.DashNotifierSettingsActivity10.java
com.umang.dashnotifier.DashNotifierSettingsActivity11.java
com.umang.dashnotifier.DashNotifierSettingsActivity2.java
com.umang.dashnotifier.DashNotifierSettingsActivity3.java
com.umang.dashnotifier.DashNotifierSettingsActivity4.java
com.umang.dashnotifier.DashNotifierSettingsActivity5.java
com.umang.dashnotifier.DashNotifierSettingsActivity6.java
com.umang.dashnotifier.DashNotifierSettingsActivity7.java
com.umang.dashnotifier.DashNotifierSettingsActivity8.java
com.umang.dashnotifier.DashNotifierSettingsActivity9.java
com.umang.dashnotifier.DashNotifierSettingsActivity.java
com.umang.dashnotifier.HelpUtils.java
com.umang.dashnotifier.IconPicker.java
com.umang.dashnotifier.PackageAdapter.java
com.umang.dashnotifier.PackageItem.java
com.umang.dashnotifier.PrefsFragment.java
com.umang.dashnotifier.UnlockReceiver.java
com.umang.dashnotifier.provider.NotifSQLiteHelper.java
com.umang.dashnotifier.provider.NotificationProvider.java
com.umang.dashnotifier.provider.NotificationStore.java