Search in sources :

Example 1 with ExtensionData

use of com.google.android.apps.dashclock.api.ExtensionData in project Talon-for-Twitter by klinker24.

the class TalonDashClockExtension method getUpdateData.

public ExtensionData getUpdateData() {
    SharedPreferences sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
    int currentAccount = sharedPrefs.getInt("current_account", 1);
    int[] unreads;
    try {
        unreads = NotificationUtils.getUnreads(this);
    } catch (Exception e) {
        unreads = new int[] { 0, 0, 0 };
    }
    int homeTweets = unreads[0];
    int mentionsTweets = unreads[1];
    int dmTweets = unreads[2];
    if (sharedPrefs.getBoolean("dashclock_show_pos", false)) {
        homeTweets = HomeDataSource.getInstance(this).getPosition(currentAccount);
        if (homeTweets > AppSettings.getInstance(this).timelineSize) {
            homeTweets = HomeDataSource.getInstance(this).getPosition(currentAccount, sharedPrefs.getLong("current_position_" + currentAccount, 0l));
        }
        unreads[0] = homeTweets;
    }
    if (!sharedPrefs.getBoolean("dashclock_timeline", true)) {
        homeTweets = 0;
        unreads[0] = 0;
    }
    if (!sharedPrefs.getBoolean("dashclock_mentions", true)) {
        mentionsTweets = 0;
        unreads[1] = 0;
    }
    if (!sharedPrefs.getBoolean("dashclock_dms", true)) {
        dmTweets = 0;
        unreads[2] = 0;
    }
    if (homeTweets > 0 || mentionsTweets > 0 || dmTweets > 0) {
        Intent intent = new Intent(this, MainActivity.class);
        Bundle b = new Bundle();
        b.putBoolean("dashclock", true);
        intent.putExtras(b);
        String smallStatus = (homeTweets == 0 ? "" : homeTweets + " | ") + (mentionsTweets == 0 ? "" : mentionsTweets + " | ") + (dmTweets == 0 ? "" : dmTweets + " | ");
        smallStatus = smallStatus.substring(0, smallStatus.length() - 3);
        return new ExtensionData().visible(true).icon(R.drawable.ic_stat_icon).status(smallStatus).expandedTitle(NotificationUtils.getTitle(unreads, this, currentAccount)[0]).expandedBody(TweetLinkUtils.removeColorHtml(NotificationUtils.getLongTextNoHtml(unreads, this, currentAccount), AppSettings.getInstance(this))).clickIntent(intent);
    } else {
        return new ExtensionData().visible(false);
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) Intent(android.content.Intent) ExtensionData(com.google.android.apps.dashclock.api.ExtensionData)

Example 2 with ExtensionData

use of com.google.android.apps.dashclock.api.ExtensionData in project JamsMusicPlayer by psaravan.

the class DashClockExtensionService method updateExtensionData.

private void updateExtensionData() {
    ExtensionData data = new ExtensionData();
    //Publish the extension data update.
    if (mApp.isServiceRunning()) {
        //Show the extension with updated data.
        try {
            status = "Playing";
            expandedTitle = mApp.getService().getCurrentSong().getTitle();
            expandedBody = mApp.getService().getCurrentSong().getAlbum() + " - " + mApp.getService().getCurrentSong().getArtist();
            Intent notificationIntent = new Intent(this, NowPlayingActivity.class);
            notificationIntent.putExtra("CALLED_FROM_FOOTER", true);
            notificationIntent.putExtra("CALLED_FROM_NOTIF", true);
            //Publish the extension data update.
            publishUpdate(data.visible(true).icon(R.drawable.dashclock_icon).status(status).expandedTitle(expandedTitle).expandedBody(expandedBody).clickIntent(notificationIntent));
        } catch (Exception e) {
            e.printStackTrace();
            //Hide the extension.
            publishUpdate(data.visible(false));
        }
    } else {
        //Hide the extension.
        publishUpdate(data.visible(false));
    }
}
Also used : Intent(android.content.Intent) ExtensionData(com.google.android.apps.dashclock.api.ExtensionData)

Example 3 with ExtensionData

use of com.google.android.apps.dashclock.api.ExtensionData in project SeriesGuide by UweTrottmann.

the class UpcomingEpisodeExtension method onUpdateData.

@Override
protected void onUpdateData(int arg0) {
    final Cursor upcomingEpisodes = DBUtils.getUpcomingEpisodes(getApplicationContext(), false, true);
    final long customCurrentTime = TimeTools.getCurrentTime(getApplicationContext());
    int hourThreshold = DashClockSettings.getUpcomingTreshold(getApplicationContext());
    long latestTimeToInclude = customCurrentTime + hourThreshold * DateUtils.HOUR_IN_MILLIS;
    // Ensure there are episodes to show
    if (upcomingEpisodes != null) {
        if (upcomingEpisodes.moveToFirst()) {
            // Ensure those episodes are within the user set time frame
            long releaseTime = upcomingEpisodes.getLong(CalendarAdapter.Query.RELEASE_TIME_MS);
            if (releaseTime <= latestTimeToInclude) {
                // build our DashClock panel
                // title and episode of first show, like 'Title 1x01'
                String expandedTitle = TextTools.getShowWithEpisodeNumber(getApplicationContext(), upcomingEpisodes.getString(CalendarAdapter.Query.SHOW_TITLE), upcomingEpisodes.getInt(CalendarAdapter.Query.SEASON), upcomingEpisodes.getInt(CalendarAdapter.Query.NUMBER));
                // get the actual release time
                Date actualRelease = TimeTools.applyUserOffset(this, releaseTime);
                String absoluteTime = TimeTools.formatToLocalTime(this, actualRelease);
                String releaseDay = TimeTools.formatToLocalDay(actualRelease);
                // time and network, e.g. 'Mon 10:00, Network'
                StringBuilder expandedBody = new StringBuilder();
                if (!DateUtils.isToday(actualRelease.getTime())) {
                    expandedBody.append(releaseDay).append(" ");
                }
                expandedBody.append(absoluteTime);
                String network = upcomingEpisodes.getString(CalendarAdapter.Query.SHOW_NETWORK);
                if (!TextUtils.isEmpty(network)) {
                    expandedBody.append(" — ").append(network);
                }
                // more than one episode at this time? Append e.g. '3 more'
                int additionalEpisodes = 0;
                while (upcomingEpisodes.moveToNext() && releaseTime == upcomingEpisodes.getLong(CalendarAdapter.Query.RELEASE_TIME_MS)) {
                    additionalEpisodes++;
                }
                if (additionalEpisodes > 0) {
                    expandedBody.append("\n");
                    expandedBody.append(getString(R.string.more, additionalEpisodes));
                }
                publishUpdate(new ExtensionData().visible(true).icon(R.drawable.ic_notification).status(releaseDay + "\n" + absoluteTime).expandedTitle(expandedTitle).expandedBody(expandedBody.toString()).clickIntent(new Intent(getApplicationContext(), ShowsActivity.class).putExtra(ShowsActivity.InitBundle.SELECTED_TAB, ShowsActivity.InitBundle.INDEX_TAB_UPCOMING)));
                upcomingEpisodes.close();
                return;
            }
        }
        upcomingEpisodes.close();
    }
    // nothing to show
    publishUpdate(null);
}
Also used : ShowsActivity(com.battlelancer.seriesguide.ui.ShowsActivity) Intent(android.content.Intent) Cursor(android.database.Cursor) Date(java.util.Date) ExtensionData(com.google.android.apps.dashclock.api.ExtensionData)

Aggregations

Intent (android.content.Intent)3 ExtensionData (com.google.android.apps.dashclock.api.ExtensionData)3 SharedPreferences (android.content.SharedPreferences)1 Cursor (android.database.Cursor)1 Bundle (android.os.Bundle)1 ShowsActivity (com.battlelancer.seriesguide.ui.ShowsActivity)1 Date (java.util.Date)1