FileDocCategorySizeDatePackage
UsageTracker.javaAPI DocAndroid 5.1 API3620Thu Mar 12 22:22:42 GMT 2015com.android.systemui.qs

UsageTracker

public class UsageTracker extends Object implements com.android.systemui.statusbar.policy.Listenable

Fields Summary
private static final long
MILLIS_PER_DAY
private final android.content.Context
mContext
private final long
mTimeToShowTile
private final String
mPrefKey
private final String
mResetAction
private boolean
mRegistered
private android.content.BroadcastReceiver
mReceiver
Constructors Summary
public UsageTracker(android.content.Context context, Class tile, int timeoutResource)


           
        mContext = context;
        mPrefKey = tile.getSimpleName() + "LastUsed";
        mTimeToShowTile = MILLIS_PER_DAY * mContext.getResources().getInteger(timeoutResource);
        mResetAction = "com.android.systemui.qs." + tile.getSimpleName() + ".usage_reset";
    
Methods Summary
private android.content.SharedPreferencesgetSharedPrefs()

        return mContext.getSharedPreferences(mContext.getPackageName(), 0);
    
public booleanisRecentlyUsed()

        long lastUsed = getSharedPrefs().getLong(mPrefKey, 0);
        return (System.currentTimeMillis() - lastUsed) < mTimeToShowTile;
    
public voidreset()

        getSharedPrefs().edit().remove(mPrefKey).commit();
    
public voidsetListening(boolean listen)

        if (listen && !mRegistered) {
             mContext.registerReceiver(mReceiver, new IntentFilter(mResetAction));
             mRegistered = true;
        } else if (!listen && mRegistered) {
            mContext.unregisterReceiver(mReceiver);
            mRegistered = false;
        }
    
public voidshowResetConfirmation(java.lang.String title, java.lang.Runnable onConfirmed)

        final SystemUIDialog d = new SystemUIDialog(mContext);
        d.setTitle(title);
        d.setMessage(mContext.getString(R.string.quick_settings_reset_confirmation_message));
        d.setNegativeButton(android.R.string.cancel, null);
        d.setPositiveButton(R.string.quick_settings_reset_confirmation_button,
                new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                reset();
                if (onConfirmed != null) {
                    onConfirmed.run();
                }
            }
        });
        d.setCanceledOnTouchOutside(true);
        d.show();
    
public voidtrackUsage()

        getSharedPrefs().edit().putLong(mPrefKey, System.currentTimeMillis()).commit();