com.google.android.apps.dashclock.api.ExtensionData Java Examples

The following examples show how to use com.google.android.apps.dashclock.api.ExtensionData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DashClockService.java    From android with Apache License 2.0 5 votes vote down vote up
@Override
public void handlePrayerContext(PrayerContext prayerContext) {
    Intent intent = new Intent(this, MainActivity.class);

    String[] prayerNames = getResources().getStringArray(R.array.prayer_names);
    Prayer prayer = prayerContext.getNextPrayer();
    int prayerIndex = prayer.getIndex();
    Date prayerTime = prayer.getDate();

    String prayerName = prayerNames[prayerIndex];
    String formattedDate = getFormattedDate(prayerTime);

    String status = String.format("%s\n%s", prayerName, formattedDate);
    String title = String.format("%s โ€” %s", prayerName, formattedDate);
    String body = prayerContext.getLocationName();

    boolean visible = prayer.getDate().getTime() <= System.currentTimeMillis()
            + mNotificationPreferences.getDashClockVisibilityDuration();

    publishUpdate(new ExtensionData()
            .visible(visible)
            .clickIntent(intent)
            .icon(R.drawable.ic_dashclock)
            .status(status)
            .expandedTitle(title)
            .expandedBody(body)
    );
}
 
Example #2
Source File: DashClock.java    From Pedometer with Apache License 2.0 5 votes vote down vote up
@Override
protected void onUpdateData(int reason) {
    ExtensionData data = new ExtensionData();
    Database db = Database.getInstance(this);
    int steps = Math.max(db.getCurrentSteps() + db.getSteps(Util.getToday()), 0);
    data.visible(true).status(Fragment_Overview.formatter.format(steps))
            .icon(R.drawable.ic_dashclock)
            .clickIntent(new Intent(DashClock.this, Activity_Main.class));
    db.close();
    publishUpdate(data);
}
 
Example #3
Source File: DashClock.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onUpdateData(int reason) {
    final String status = getString(R.string.app_name);
    final int cores = CPUFreq.getInstance(this).getCpuCount();

    if (extensionData == null) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        extensionData = new ExtensionData()
                .visible(true)
                .icon(R.drawable.ic_launcher_preview)
                .clickIntent(intent);
    }
    if (!mRunning) {
        new Thread(() -> {
            while (true) {
                try {
                    StringBuilder message = new StringBuilder();
                    if (RootUtils.rootAccess()) {
                        CPUFreq cpuFreq = CPUFreq.getInstance(DashClock.this);
                        GPUFreq gpuFreq = GPUFreq.getInstance();

                        StringBuilder cpu = new StringBuilder();
                        for (int i = 0; i < cores; i++) {
                            int freq = cpuFreq.getCurFreq(i) / 1000;
                            if (i != 0) cpu.append(" | ");
                            cpu.append(freq == 0 ? getString(R.string.offline) : freq);
                        }
                        if (cpu.length() > 0) {
                            message.append(getString(R.string.cpu)).append(": ")
                                    .append(cpu.toString()).append("\n");
                        }
                        message.append(getString(R.string.cpu_governor)).append(": ")
                                .append(cpuFreq.getGovernor(false)).append("\n");

                        if (gpuFreq.hasCurFreq()) {
                            message.append(getString(R.string.gpu)).append(": ")
                                    .append(gpuFreq.getCurFreq() / 1000000)
                                    .append(getString(R.string.mhz));
                        }
                    } else {
                        message.append(getString(R.string.no_root));
                    }

                    publishUpdate(extensionData.status(status).expandedBody(message.toString()));
                    Thread.sleep(5000);
                } catch (Exception e) {
                    e.printStackTrace();
                    break;
                }
            }
        }).start();
    }
    mRunning = true;
}
 
Example #4
Source File: DashClock.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onUpdateData(int reason) {
    final String status = getString(R.string.app_name);
    final int cores = CPUFreq.getInstance(this).getCpuCount();

    if (extensionData == null) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        extensionData = new ExtensionData()
                .visible(true)
                .icon(R.drawable.ic_launcher_preview)
                .clickIntent(intent);
    }
    if (!mRunning) {
        new Thread(() -> {
            while (true) {
                try {
                    StringBuilder message = new StringBuilder();
                    if (RootUtils.rootAccess()) {
                        CPUFreq cpuFreq = CPUFreq.getInstance(DashClock.this);
                        GPUFreq gpuFreq = GPUFreq.getInstance();

                        StringBuilder cpu = new StringBuilder();
                        for (int i = 0; i < cores; i++) {
                            int freq = cpuFreq.getCurFreq(i) / 1000;
                            if (i != 0) cpu.append(" | ");
                            cpu.append(freq == 0 ? getString(R.string.offline) : freq);
                        }
                        if (cpu.length() > 0) {
                            message.append(getString(R.string.cpu)).append(": ")
                                    .append(cpu.toString()).append("\n");
                        }
                        message.append(getString(R.string.cpu_governor)).append(": ")
                                .append(cpuFreq.getGovernor(false)).append("\n");

                        if (gpuFreq.hasCurFreq()) {
                            message.append(getString(R.string.gpu)).append(": ")
                                    .append(gpuFreq.getCurFreq() / 1000000)
                                    .append(getString(R.string.mhz));
                        }
                    } else {
                        message.append(getString(R.string.no_root));
                    }

                    publishUpdate(extensionData.status(status).expandedBody(message.toString()));
                    Thread.sleep(5000);
                } catch (Exception e) {
                    e.printStackTrace();
                    break;
                }
            }
        }).start();
    }
    mRunning = true;
}
 
Example #5
Source File: DashClockService.java    From kernel_adiutor with Apache License 2.0 4 votes vote down vote up
@Override
protected void onUpdateData(int reason) {
    final String status = getString(R.string.app_name);
    final int cores = CPU.getCoreCount();

    if (extensionData == null)
        extensionData = new ExtensionData().visible(true).icon(R.drawable.ic_launcher_preview);
    if (!running) new Thread(new Runnable() {
        @Override
        public void run() {
            while (true) {
                try {
                    StringBuilder message = new StringBuilder();
                    if (RootUtils.rootAccess()) {
                        StringBuilder cpu = new StringBuilder();
                        for (int i = 0; i < cores; i++) {
                            int freq = CPU.getCurFreq(i) / 1000;
                            if (i != 0) cpu.append(" | ");
                            cpu.append(freq == 0 ? getString(R.string.offline) : freq);
                        }
                        if (cpu.length() > 0)
                            message.append(getString(R.string.cpu)).append(": ").append(cpu.toString()).append("\n");
                        message.append(getString(R.string.cpu_governor)).append(": ")
                                .append(CPU.getCurGovernor(true)).append("\n");

                        if (GPU.hasGpuCurFreq())
                            message.append(getString(R.string.gpu)).append(": ")
                                    .append(GPU.getGpuCurFreq() / 1000000).append(getString(R.string.mhz));
                    } else message.append(getString(R.string.no_root));

                    publishUpdate(extensionData.status(status).expandedBody(message.toString()));
                    Thread.sleep(5000);
                } catch (Exception e) {
                    e.printStackTrace();
                    break;
                }
            }
        }
    }).start();
    running = true;
}
 
Example #6
Source File: PhoneProfilesDashClockExtension.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
@Override
protected void onUpdateData(int reason) {
    Profile profile;

    if (dataWrapper == null)
        return;

    //profile = Profile.getMappedProfile(
    //                            dataWrapper.getActivatedProfile(true, false), this);
    profile = dataWrapper.getActivatedProfile(true, false);

    boolean isIconResourceID;
    String iconIdentifier;
    String profileName;
    if (profile != null)
    {
        isIconResourceID = profile.getIsIconResourceID();
        iconIdentifier = profile.getIconIdentifier();
        profileName = DataWrapper.getProfileNameWithManualIndicatorAsString(profile, true, "", false, false, false, dataWrapper);
    }
    else
    {
        isIconResourceID = true;
        iconIdentifier = Profile.PROFILE_ICON_DEFAULT;
        profileName = getResources().getString(R.string.profiles_header_profile_name_no_activated);
    }
    int iconResource;
    if (isIconResourceID)
        //iconResource = getResources().getIdentifier(iconIdentifier, "drawable", getPackageName());
        iconResource = Profile.getIconResource(iconIdentifier);
    else
        //iconResource = getResources().getIdentifier(Profile.PROFILE_ICON_DEFAULT, "drawable", getPackageName());
        iconResource = Profile.getIconResource(Profile.PROFILE_ICON_DEFAULT);

    /////////////////////////////////////////////////////////////

    // intent
    Intent intent = new Intent(this, LauncherActivity.class);
    // clear all opened activities
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(PPApplication.EXTRA_STARTUP_SOURCE, PPApplication.STARTUP_SOURCE_WIDGET);

    String status = "";
    if (ApplicationPreferences.prefEventsBlocked)
        if (ApplicationPreferences.prefForceRunEventRunning)
        {
            /*if (android.os.Build.VERSION.SDK_INT >= 16)
                status = "\u23E9";
            else*/
                status = "[ยป]";
        }
        else
        {
            /*if (android.os.Build.VERSION.SDK_INT >= 16)
                status = "\uD83D\uDC46";
            else */
                status = "[M]";
        }

    // Publish the extension data update.
    publishUpdate(new ExtensionData()
            .visible(true)
            .icon(iconResource)
            .status(status)
            .expandedTitle(profileName)
            .expandedBody(ProfilePreferencesIndicator.getString(profile, 25, this))
            .contentDescription("PhoneProfilesPlus - "+profileName)
            .clickIntent(intent));		
}
 
Example #7
Source File: DashClock.java    From KernelAdiutor with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onUpdateData(int reason) {
    final String status = getString(R.string.app_name);
    final int cores = CPUFreq.getInstance(this).getCpuCount();

    if (extensionData == null) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        extensionData = new ExtensionData()
                .visible(true)
                .icon(R.drawable.ic_launcher_preview)
                .clickIntent(intent);
    }
    if (!mRunning) {
        new Thread(() -> {
            while (true) {
                try {
                    StringBuilder message = new StringBuilder();
                    if (RootUtils.rootAccess()) {
                        CPUFreq cpuFreq = CPUFreq.getInstance(DashClock.this);
                        GPUFreq gpuFreq = GPUFreq.getInstance();

                        StringBuilder cpu = new StringBuilder();
                        for (int i = 0; i < cores; i++) {
                            int freq = cpuFreq.getCurFreq(i) / 1000;
                            if (i != 0) cpu.append(" | ");
                            cpu.append(freq == 0 ? getString(R.string.offline) : freq);
                        }
                        if (cpu.length() > 0) {
                            message.append(getString(R.string.cpu)).append(": ")
                                    .append(cpu.toString()).append("\n");
                        }
                        message.append(getString(R.string.cpu_governor)).append(": ")
                                .append(cpuFreq.getGovernor(false)).append("\n");

                        if (gpuFreq.hasCurFreq()) {
                            message.append(getString(R.string.gpu)).append(": ")
                                    .append(gpuFreq.getCurFreq() / 1000000)
                                    .append(getString(R.string.mhz));
                        }
                    } else {
                        message.append(getString(R.string.no_root));
                    }

                    publishUpdate(extensionData.status(status).expandedBody(message.toString()));
                    Thread.sleep(5000);
                } catch (Exception e) {
                    e.printStackTrace();
                    break;
                }
            }
        }).start();
    }
    mRunning = true;
}
 
Example #8
Source File: TasksExtension.java    From opentasks with Apache License 2.0 4 votes vote down vote up
protected void publishRecentTaskUpdate()
{

    // get next task that is due
    Cursor recentTaskCursor = null;
    Cursor allDayTaskCursor = null;
    Cursor pinnedTaskCursor = null;

    try
    {

        switch (mDisplayMode)
        {
            case DashClockPreferenceActivity.DISPLAY_MODE_DUE:
                recentTaskCursor = loadRecentDueTaskCursor();
                allDayTaskCursor = loadAllDayTasksDueTodayCursor();
                break;

            case DashClockPreferenceActivity.DISPLAY_MODE_START:
                recentTaskCursor = loadRecentStartTaskCursor();
                allDayTaskCursor = loadAllDayTasksStartTodayCursor();
                break;

            case DashClockPreferenceActivity.DISPLAY_MODE_PINNED:
                pinnedTaskCursor = loadPinnedTaskCursor();
                break;

            default:
                recentTaskCursor = loadRecentStartDueTaskCursor();
                allDayTaskCursor = loadAllDayTasksStartDueTodayCursor();
                pinnedTaskCursor = loadPinnedTaskCursor();
                break;
        }

        int recentTaskCount = recentTaskCursor == null ? 0 : recentTaskCursor.getCount();
        int allDayTaskCount = allDayTaskCursor == null ? 0 : allDayTaskCursor.getCount();
        int pinnedTaskCount = pinnedTaskCursor == null ? 0 : pinnedTaskCursor.getCount();
        if ((recentTaskCount + allDayTaskCount + pinnedTaskCount) > 0)
        {
            // select the right cursor
            Cursor c = null;
            if (pinnedTaskCount > 0)
            {
                c = pinnedTaskCursor;
            }
            else if ((recentTaskCount + allDayTaskCount) > 0)
            {
                c = recentTaskCount > 0 ? recentTaskCursor : allDayTaskCursor;
            }

            c.moveToFirst();

            boolean isAllDay = allDayTaskCount > 0;

            String description = c.getString(c.getColumnIndex(Tasks.DESCRIPTION));
            if (description != null)
            {
                description = description.replaceAll("\\[\\s?\\]", "โ€").replaceAll("\\[[xX]\\]", "โœ“");
            }
            String title = getTaskTitleDisplayString(c, isAllDay);

            // intent
            String accountType = c.getString(c.getColumnIndex(Instances.ACCOUNT_TYPE));
            long taskId = c.getLong(c.getColumnIndex(Instances._ID));
            Intent clickIntent = buildClickIntent(taskId, accountType);

            // Publish the extension data update.
            publishUpdate(new ExtensionData().visible(true).icon(R.drawable.ic_dashboard)
                    .status(String.valueOf(allDayTaskCount + recentTaskCount + pinnedTaskCount)).expandedTitle(title).expandedBody(description)
                    .clickIntent(clickIntent));
        }
        else
        {
            // no upcoming task -> empty update
            publishUpdate(null);
        }
    }
    finally
    {
        closeCursor(recentTaskCursor);
        closeCursor(allDayTaskCursor);
        closeCursor(pinnedTaskCursor);
    }

}