Java Code Examples for android.widget.RemoteViews#setOnClickFillInIntent()

The following examples show how to use android.widget.RemoteViews#setOnClickFillInIntent() . 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: WidgetListFactory.java    From WanAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public RemoteViews getViewAt(int i) {
    RemoteViews remoteViews = new RemoteViews(
            context.getPackageName(), R.layout.item_list_app_widget);
    Realm realm=Realm.getInstance(new RealmConfiguration.Builder()
            .deleteRealmIfMigrationNeeded()
            .name(RealmHelper.DATABASE_NAME)
            .build());
    List<ReadLaterArticleData> list = realm.copyFromRealm(
            realm.where(ReadLaterArticleData.class)
                    .equalTo("userId", userId)
                    .sort("timestamp", Sort.DESCENDING)
                    .findAll());
    ReadLaterArticleData data = list.get(i);
    remoteViews.setTextViewText(R.id.text_view_author,data.getAuthor());
    remoteViews.setTextViewText(R.id.text_view_title, StringUtil.replaceInvalidChar(data.getTitle()));
    Intent intent = new Intent();
    intent.putExtra(DetailActivity.ID, data.getId());
    intent.putExtra(DetailActivity.TITLE, data.getTitle());
    intent.putExtra(DetailActivity.URL, data.getLink());
    intent.putExtra(DetailActivity.FROM_FAVORITE_FRAGMENT, false);
    intent.putExtra(DetailActivity.FROM_BANNER, false);
    remoteViews.setOnClickFillInIntent(R.id.item_main, intent);
    return remoteViews;
}
 
Example 2
Source File: ListProvider.java    From DebugPurge with MIT License 6 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {
    final RemoteViews remoteView = new RemoteViews(
            mContext.getPackageName(), R.layout.widget_app_item);
    PackageInfo pkgInfo = mPackageInfoList.get(position);
    remoteView.setTextViewText(R.id.appItemNameText, mContext.getPackageManager().getApplicationLabel(pkgInfo.applicationInfo));
    remoteView.setTextViewText(R.id.appItemPackageText, pkgInfo.packageName);

    Bundle extras = new Bundle();
    extras.putInt(WidgetProvider.EXTRA_ITEM, position);
    extras.putString(WidgetProvider.PACKAGE_ITEM, pkgInfo.packageName);
    Intent fillInIntent = new Intent();
    fillInIntent.putExtras(extras);
    remoteView.setOnClickFillInIntent(R.id.appItemButton, fillInIntent);
    return remoteView;
}
 
Example 3
Source File: MyRemoteViewsFactory.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
public RemoteViews getViewAt(int index) {
  // Create a view to display at the required index.
  RemoteViews rv = new RemoteViews(context.getPackageName(),
    R.layout.widget_collection_item_layout);

  // Populate the view from the underlying data.
  rv.setTextViewText(R.id.widget_title_text,
    myWidgetText.get(index));
  rv.setTextViewText(R.id.widget_text, "View Number: " +
                                         String.valueOf(index));

  // Listing 19-21: Filling in a Pending Intent template for each item displayed in your Collection View Widget
  // Create the item-specific fill-in Intent that will populate
  // the Pending Intent template created in the App Widget Provider.
  Intent fillInIntent = new Intent();
  fillInIntent.putExtra(Intent.EXTRA_TEXT, myWidgetText.get(index));
  rv.setOnClickFillInIntent(R.id.widget_title_text, fillInIntent);

  return rv;
}
 
Example 4
Source File: WidgetService.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {
    RemoteViews remoteViews = new RemoteViews(mContext.getPackageName(),
            mLightTheme ? R.layout.item_widget_light : R.layout.item_widget);
    Item item = getItem(position);
    if (item == null) {
        return remoteViews;
    }
    if (!isItemAvailable(item)) {
        Item remoteItem = mItemManager.getItem(item.getId(), ItemManager.MODE_NETWORK);
        if (remoteItem != null) {
            item.populate(remoteItem);
        } else {
            return remoteViews;
        }
    }
    remoteViews.setTextViewText(R.id.title, item.getDisplayedTitle());
    remoteViews.setTextViewText(R.id.score, new SpannableStringBuilder()
            .append(getSpan(item.getScore(), SCORE, mHotThreshold * AppUtils.HOT_FACTOR))
            .append(SUBTITLE_SEPARATOR)
            .append(getSpan(item.getKidCount(), COMMENT, mHotThreshold)));
    remoteViews.setOnClickFillInIntent(R.id.item_view, new Intent().setData(
            AppUtils.createItemUri(item.getId())));
    return remoteViews;
}
 
Example 5
Source File: StackWidgetService.java    From GitJourney with Apache License 2.0 6 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {
    Log.v(TAG, "getViewAt: position = " + position);

    // Construct a remote views item based on the app widget item XML file,
    // and set the text based on the position.
    RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_list_item);
    Intent fillInIntent = new Intent();
    fillInIntent.putExtra(EXTRA_LIST_VIEW_ROW_NUMBER, position);
    rv.setOnClickFillInIntent(R.id.main_list_item, fillInIntent);

    rv.setTextViewText(R.id.w_author_name, widgetDatas.get(position).getAuthorName());
    rv.setTextViewText(R.id.w_title, widgetDatas.get(position).getTitle());
    Picasso pic = Picasso.with(context);
    try {
        Bitmap map = pic.load(widgetDatas.get(position).getAvatar()).get();
        rv.setImageViewBitmap(R.id.w_github_user_image, map);
    } catch (IOException e) {
        Log.e(TAG, "", e);
    }
    return rv;
}
 
Example 6
Source File: Widget.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 5 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {
    RemoteViews row = new RemoteViews(mContext.getPackageName(), R.layout.widget_profile_item);

    row.setTextViewText(R.id.text, mItems.get(position).getName());

    Intent i = new Intent();
    Bundle extras = new Bundle();

    extras.putInt(ITEM_ARG, position);
    i.putExtras(extras);
    row.setOnClickFillInIntent(R.id.text, i);

    return (row);
}
 
Example 7
Source File: WidgetViewsFactory.java    From Birdays with Apache License 2.0 5 votes vote down vote up
@Override
public RemoteViews getViewAt(int i) {
    RemoteViews view = new RemoteViews(context.getPackageName(),
            R.layout.description_widget_list_view);

    String name = widgetList.get(i).getName();
    long date = widgetList.get(i).getDate();
    boolean yearUnknown = widgetList.get(i).isYearUnknown();

    // Age column
    if (!yearUnknown) {
        String displayedAge = PreferenceManager.getDefaultSharedPreferences(context)
                .getString(Constants.DISPLAYED_AGE_KEY, "0");
        int age = (displayedAge.equals("0") ? Utils.getCurrentAge(date) : Utils.getFutureAge(date));
        view.setTextViewText(R.id.textview_widget_age, String.valueOf(age));
    } else {
        view.setTextViewText(R.id.textview_widget_age, "");
    }

    // Name column
    view.setTextViewText(R.id.textview_widget_name, name);

    // Date column
    String today = context.getString(R.string.today);
    if (Utils.daysLeft(context, date).equals(today)) {
        view.setTextViewText(R.id.textview_widget_date, today);
        setTextColor(view, ContextCompat.getColor(context, R.color.red_alert));
    } else {
        view.setTextViewText(R.id.textview_widget_date, Utils.getDateWithoutYear(date));
        setTextColor(view, ContextCompat.getColor(context, android.R.color.white));
    }

    // OnClick handling
    Intent clickIntent = new Intent();
    clickIntent.putExtra(Constants.TIME_STAMP, widgetList.get(i).getTimeStamp());
    view.setOnClickFillInIntent(R.id.relativelayout_widget, clickIntent);

    return view;
}
 
Example 8
Source File: Widget.java    From KernelAdiutor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {
    RemoteViews row = new RemoteViews(mContext.getPackageName(), R.layout.widget_profile_item);

    row.setTextViewText(R.id.text, mItems.get(position).getName());

    Intent i = new Intent();
    Bundle extras = new Bundle();

    extras.putInt(ITEM_ARG, position);
    i.putExtras(extras);
    row.setOnClickFillInIntent(R.id.text, i);

    return (row);
}
 
Example 9
Source File: ListProvider.java    From Expense-Tracker-App with MIT License 5 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {
    final RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.layout_expense_widget_item);
    Expense expense = expenseList.get(position);
    remoteView.setTextViewText(R.id.tv_category, String.valueOf(expense.getCategory().getName()));
    remoteView.setTextViewText(R.id.tv_description, expense.getDescription());
    remoteView.setTextViewText(R.id.tv_total, Util.getFormattedCurrency(expense.getTotal()));
    remoteView.setViewVisibility(R.id.tv_description, (expense.getDescription() != null && !expense.getDescription().isEmpty()) ? View.VISIBLE : View.GONE);
    remoteView.setTextColor(R.id.tv_total, expense.getType() == IExpensesType.MODE_EXPENSES ? context.getResources().getColor(R.color.colorAccentRed) : context.getResources().getColor(R.color.colorAccentGreen));
    Intent expenseIntent = new Intent();
    expenseIntent.putExtra(ExpenseDetailFragment.EXPENSE_ID_KEY, expense.getId());
    remoteView.setOnClickFillInIntent(R.id.widget_item, expenseIntent);
    return remoteView;
}
 
Example 10
Source File: RssfeedWidgetService.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {

	RssItem feed = InMemoryDataStorage.get().getItem(position);
	RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.widget_item);
	views.setTextViewText(R.id.item, feed.getTitle());
	
	Intent fillInIntent = new Intent();
	Bundle extras = new Bundle();
	extras.putString(RssfeedWidgetProvider.EXT_LINK, feed.getLink());
	fillInIntent.putExtras(extras);
	views.setOnClickFillInIntent(R.id.item, fillInIntent);
	
	return views;
}
 
Example 11
Source File: ListWidgetRemoteViewsFactory.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {
    RemoteViews row = new RemoteViews(app.getPackageName(), R.layout.list_widget_row);

    Note note = notes.get(position);

    row.setTextViewText(R.id.list_widget_row_summary, note.getSummary());

    Intent i = new Intent();
    i.putExtra(Utils.NOTE_UID, note.getIdentification().getUid());
    i.putExtra(Utils.INTENT_ACCOUNT_EMAIL,accountEmail);
    i.putExtra(Utils.INTENT_ACCOUNT_ROOT_FOLDER,rootFolder);

    //if the widget is not updated after a sync, the UID of the notebook is not OK, the notebook UID mus always be read when needed
    //String correctNotebookUID= notesRepository.getUIDofNotebook(accountEmail,rootFolder,note.getIdentification().getUid());

    //i.putExtra(Utils.NOTEBOOK_UID, correctNotebookUID);

    row.setOnClickFillInIntent(R.id.list_widget_row_summary, i);

    Color noteColor = note.getColor();

    //Buggy, if one requests it, I will active it again
    // if(noteColor != null) {
    //    int color = android.graphics.Color.parseColor(noteColor.getHexcode());
    //    row.setInt(R.id.list_widget_row_summary, "setBackgroundColor", color);
    //}

    return row;
}
 
Example 12
Source File: QueueWidgetService.java    From Rey-MusicPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {
    RemoteViews remoteViews = new RemoteViews(mContext.getPackageName(), R.layout.queue_widget_listview_layout);
    if (position <= getCount()) {

        String songTitle = songs.get(position)._title;

        ImageSize imageSize = new ImageSize(75, 75);

        long songDurationInMillis = 0;
        try {
            songDurationInMillis = songs.get(position)._duration;
        } catch (Exception e) {
        }

        remoteViews.setTextViewText(R.id.listViewSubText, songTitle);
        remoteViews.setTextViewText(R.id.listViewRightSubText, MusicUtils.convertMillisToMinsSecs(songDurationInMillis));


        Bitmap bitmap = ImageLoader.getInstance().loadImageSync(String.valueOf(MusicUtils.getAlbumArtUri(mApp.getService().getSongList().get(position)._albumId)), imageSize);
        if (bitmap != null) {
            remoteViews.setImageViewBitmap(R.id.listViewLeftIcon, bitmap);
        } else {
            remoteViews.setImageViewResource(R.id.listViewLeftIcon, R.mipmap.ic_launcher);
        }

    }


  /* This intent latches itself onto the pendingIntentTemplate from
 * LargeWidgetProvider.java and adds the extra "INDEX" argument to it. */
    Intent fillInIntent = new Intent();
    fillInIntent.putExtra("INDEX", position);
    remoteViews.setOnClickFillInIntent(R.id.listViewParent, fillInIntent);

    return remoteViews;
}
 
Example 13
Source File: AppWidgetService.java    From Clip-Stack with MIT License 5 votes vote down vote up
public RemoteViews getViewAt(int position) {
    ClipObject clip = clipObjects.get(position);
    RemoteViews remoteViews = new RemoteViews(mContext.getPackageName(), R.layout.app_widget_card);

    remoteViews.setTextViewText(R.id.widget_card_date, MyUtil.getFormatDate(mContext, clip.getDate()));
    remoteViews.setTextViewText(R.id.widget_card_time, MyUtil.getFormatTime(mContext, clip.getDate()));
    remoteViews.setTextViewText(R.id.widget_card_text, MyUtil.stringLengthCut(clip.getText()));
    remoteViews.setImageViewResource(
            R.id.widget_card_star,
            clip.isStarred() ?
                    R.drawable.ic_action_star_yellow
                    :
                    R.drawable.ic_action_star_outline_grey600
            );
    Intent fillInEditorIntent = new Intent();
    final Bundle editorExtras = new Bundle();
    editorExtras.putInt(ClipObjectActionBridge.ACTION_CODE, ClipObjectActionBridge.ACTION_EDIT);
    editorExtras.putBoolean(ClipObjectActionBridge.STATUE_IS_STARRED, clip.isStarred());
    editorExtras.putString(Intent.EXTRA_TEXT, clip.getText());
    fillInEditorIntent.putExtras(editorExtras);
    remoteViews.setOnClickFillInIntent(
            R.id.widget_card_click_edit,
            fillInEditorIntent
    );
    Intent fillInStarIntent = new Intent();
    final Bundle starExtras = new Bundle();
    starExtras.putInt(ClipObjectActionBridge.ACTION_CODE, ClipObjectActionBridge.ACTION_STAR);
    starExtras.putBoolean(ClipObjectActionBridge.STATUE_IS_STARRED, clip.isStarred());
    starExtras.putString(Intent.EXTRA_TEXT, clip.getText());
    fillInStarIntent.putExtras(starExtras);
    remoteViews.setOnClickFillInIntent(
            R.id.widget_card_click_star,
            fillInStarIntent
    );
    return remoteViews;
}
 
Example 14
Source File: ListRemoteViewsFactory.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {
    RemoteViews row = new RemoteViews(app.getPackageName(), R.layout.widget_item_assignment);

    Assignment assignment = assignmentList.get(position);

    row.setTextViewText(R.id.tv_title, assignment.getName());

    row.setImageViewResource(R.id.iv_priority, assignment.getPriority().iconRes);

    row.setImageViewResource(R.id.iv_completed, assignment.getProgress() == Constants.MAX_ASSIGNMENT_PROGRESS ?
            R.drawable.ic_check_box_black_24dp :
            R.drawable.ic_check_box_outline_blank_black_24dp);

    row.setTextViewText(R.id.tv_time_info,
            PalmApp.getStringCompact(R.string.text_last_modified_time) + ":"
                    + TimeUtils.getLongDateTime(app.getApplicationContext(), assignment.getLastModifiedTime()));
    row.setInt(R.id.root, "setBackgroundColor", app.getResources().getColor(R.color.white_translucent));
    row.setViewVisibility(R.id.iv_files, assignment.getAttachments() != 0 ? View.VISIBLE : View.GONE);
    row.setViewVisibility(R.id.iv_alarm, assignment.getAlarms() != 0 ? View.VISIBLE : View.GONE);

    Bundle extras = new Bundle();
    extras.putParcelable(Constants.EXTRA_MODEL, assignment);
    Intent fillInIntent = new Intent();
    fillInIntent.putExtras(extras);
    row.setOnClickFillInIntent(R.id.root, fillInIntent);

    return row;
}
 
Example 15
Source File: FilesWidgetFactory.java    From writeily-pro with MIT License 5 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {
    File file = widgetFilesList[position];
    Intent fillInIntent = new Intent().putExtra(Constants.NOTE_KEY,file);
    RemoteViews rowView = new RemoteViews(context.getPackageName(), R.layout.widget_file_item);
    rowView.setTextViewText(R.id.widget_note_title, Constants.MD_EXTENSION.matcher(file.getName()).replaceAll(""));
    rowView.setOnClickFillInIntent(R.id.widget_note_title, fillInIntent);
    return rowView;
}
 
Example 16
Source File: ListViewWidgetService.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
public RemoteViews getViewAt(int position) {
    // position will always range from 0 to getCount() - 1.
    // Construct a RemoteViews item based on the app widget item XML file, and set the
    // text based on the position.
    int view = R.layout.submission_widget_light;
    switch (SubredditWidgetProvider.getViewType(id, mContext)) {
        case 1:
        case 0:
            if (SubredditWidgetProvider.getThemeFromId(id, mContext) == 2) {
                view = R.layout.submission_widget_light;
            } else {
                view = R.layout.submission_widget;
            }

            break;
        case 2:
            if (SubredditWidgetProvider.getThemeFromId(id, mContext) == 2) {
                view = R.layout.submission_widget_compact_light;
            } else {
                view = R.layout.submission_widget_compact;
            }
            break;
    }
    final RemoteViews rv = new RemoteViews(mContext.getPackageName(), view);
    try {

        // feed row
        Submission data = records.get(position);

        rv.setTextViewText(R.id.title, Html.fromHtml(data.getTitle()));
        rv.setTextViewText(R.id.score, data.getScore() + "");
        rv.setTextViewText(R.id.comments, data.getCommentCount() + "");
        rv.setTextViewText(R.id.information,
                data.getAuthor() + " " + TimeUtils.getTimeAgo(data.getCreated().getTime(),
                        mContext));
        rv.setTextViewText(R.id.subreddit, data.getSubredditName());
        rv.setTextColor(R.id.subreddit, Palette.getColor(data.getSubredditName()));
        if (SubredditWidgetProvider.getViewType(id, mContext) == 1) {
            Thumbnails s = data.getThumbnails();
            rv.setViewVisibility(R.id.thumbimage2, View.GONE);
            if (s != null && s.getVariations() != null && s.getSource() != null) {
                rv.setImageViewBitmap(R.id.bigpic,
                        ((Reddit) mContext.getApplicationContext()).getImageLoader()
                                .loadImageSync(
                                        Html.fromHtml(data.getThumbnails().getSource().getUrl())
                                                .toString()));
                rv.setViewVisibility(R.id.bigpic, View.VISIBLE);
            } else {
                rv.setViewVisibility(R.id.bigpic, View.GONE);
            }
        } else {
            if (SubredditWidgetProvider.getViewType(id, mContext) != 2) {
                rv.setViewVisibility(R.id.bigpic, View.GONE);
            }
            if (data.getThumbnailType() == Submission.ThumbnailType.URL) {
                rv.setImageViewBitmap(R.id.thumbimage2,
                        ((Reddit) mContext.getApplicationContext()).getImageLoader()
                                .loadImageSync(data.getThumbnail()));
                rv.setViewVisibility(R.id.thumbimage2, View.VISIBLE);
            } else {
                rv.setViewVisibility(R.id.thumbimage2, View.GONE);
            }
        }
        switch (SubredditWidgetProvider.getViewType(id, mContext)) {
            case 1:
            case 0:
                if (SubredditWidgetProvider.getThemeFromId(id, mContext) == 2) {
                } else {
                    rv.setTextColor(R.id.title, Color.WHITE);
                    rv.setTextColor(R.id.score, Color.WHITE);
                    rv.setTextColor(R.id.comments, Color.WHITE);
                    rv.setTextColor(R.id.information, Color.WHITE);
                }

                break;
            case 2:
                if (SubredditWidgetProvider.getThemeFromId(id, mContext) == 2) {
                } else {
                    rv.setTextColor(R.id.title, Color.WHITE);
                    rv.setTextColor(R.id.score, Color.WHITE);
                    rv.setTextColor(R.id.comments, Color.WHITE);
                    rv.setTextColor(R.id.information, Color.WHITE);
                }
                break;
        }

        Bundle infos = new Bundle();
        infos.putString(OpenContent.EXTRA_URL, data.getPermalink());
        infos.putBoolean("popup", true);
        final Intent activityIntent = new Intent();
        activityIntent.putExtras(infos);
        activityIntent.setAction(data.getTitle());
        rv.setOnClickFillInIntent(R.id.card, activityIntent);
    } catch (Exception e) {

    }
    return rv;
}
 
Example 17
Source File: ShotWidgetService.java    From droidddle with Apache License 2.0 4 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {
    RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.shot_widget_item);
    if (position >= mWidgetItems.size()) {
        return rv;
    }
    Shot shot = mWidgetItems.get(position);
    // Construct a remote views item based on the app widget item XML file,
    // and set the text based on the position.

    // Set the click intent so that we can handle it and show a toast message
    final Intent fillInIntent = new Intent();
    final Bundle extras = new Bundle();
    extras.putLong(ShotAppWidgetProvider.EXTRA_SHOT_ID, shot.id);
    fillInIntent.putExtras(extras);
    rv.setOnClickFillInIntent(R.id.shot_item_layout, fillInIntent);

    rv.setTextViewText(R.id.shot_title, shot.title);
    //           rv.setTextViewText(R.id.shot_views, UiUtils.getCountValue(shot.viewsCount)+"");

    if (shot.createdAt != null) {
        CharSequence date = DateUtils.getRelativeTimeSpanString(shot.createdAt.getTime(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE | DateUtils.FORMAT_NUMERIC_DATE);
        rv.setTextViewText(R.id.shot_date, date);
    } else {
        rv.setTextViewText(R.id.shot_date, null);
    }
    if (TextUtils.isEmpty(shot.description)) {
        rv.setTextViewText(R.id.shot_description, null);
        rv.setViewVisibility(R.id.shot_description, View.INVISIBLE);
    } else {
        rv.setViewVisibility(R.id.shot_description, View.VISIBLE);
        Spanned spannable = GoURLSpan.hackURLSpan(Html.fromHtml(shot.description));
        rv.setTextViewText(R.id.shot_description, spannable);
    }
    //            AppWidgetTarget target = new AppWidgetTarget(mContext, rv, R.id.shot_image, mAppWidgetId);
    Bitmap bitmap = downloadImage(mContext, shot.images.normal);
    rv.setImageViewBitmap(R.id.shot_image, bitmap);
    //           Glide.with(mContext).load(shot.images.normal).asBitmap().into(target);
    // Return the remote views object.

    return rv;
}
 
Example 18
Source File: CalenderWidgetAdapter.java    From MuslimMateAndroid with GNU General Public License v3.0 4 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {
    RemoteViews row = new RemoteViews(context.getPackageName(),
            R.layout.calender_cell);

    CalendarCell cell = daysList.get(position);

    Intent islamicIntent = new Intent();
    Bundle islamicIntentExtras = new Bundle();
    islamicIntentExtras.putString("islamic_day",
            NumbersLocal.convertNumberType(context, cell.day + ""));
    islamicIntent.putExtras(islamicIntentExtras);

    Intent gregorianIntent = new Intent();
    Bundle gregorianIntentExtras = new Bundle();
    gregorianIntentExtras.putString("gregorian_day",
            NumbersLocal.convertNumberType(context, cell.dayOther + ""));
    gregorianIntent.putExtras(gregorianIntentExtras);

    //not empty date
    if (cell.day != -1) {

        //set dates in calender
        row.setViewVisibility(R.id.textView31, View.VISIBLE);
        row.setViewVisibility(R.id.textView30, View.VISIBLE);
        row.setTextViewText(R.id.textView31, NumbersLocal.convertToNumberTypeSystem(context, cell.dayOther + ""));
        row.setTextViewText(R.id.textView30, NumbersLocal.convertToNumberTypeSystem(context, cell.day + ""));

        //get current day
        HGDate hgDate = new HGDate();
        hgDate.toHigri();

        //check if that is the current day or not
        if (cell.day == hgDate.getDay()) {
            row.setTextColor(R.id.textView31, Color.WHITE);
            row.setTextColor(R.id.textView30, Color.WHITE);
            row.setInt(R.id.textView31, "setBackgroundColor", Color.argb(255, 73, 138, 127));
            row.setInt(R.id.textView30, "setBackgroundColor", Color.argb(255, 73, 138, 127));
        } else {
            row.setTextColor(R.id.textView31, Color.GRAY);
            row.setTextColor(R.id.textView30, Color.BLACK);
            row.setInt(R.id.textView31, "setBackgroundColor", Color.WHITE);
            row.setInt(R.id.textView30, "setBackgroundColor", Color.WHITE);
        }


        //check if the day one of the islamic events
        for (Event event : eventList) {
            String[] date = event.hejriDate.split("-");
            if (cell.day == Integer.parseInt(date[0]) && cell.hijriMonth == Integer.parseInt(date[1])) {
                row.setInt(R.id.textView31, "setBackgroundColor", Color.YELLOW);
                row.setInt(R.id.textView30, "setBackgroundColor", Color.YELLOW);
            }
        }


    } else {
        //hide empty cellls
        row.setViewVisibility(R.id.textView31, View.GONE);
        row.setViewVisibility(R.id.textView30, View.GONE);
    }

    row.setOnClickFillInIntent(R.id.textView31, gregorianIntent);
    row.setOnClickFillInIntent(R.id.textView30, islamicIntent);

    return (row);
}
 
Example 19
Source File: StackWidgetService.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
public RemoteViews getViewAt(int position) {
    final RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.submission_widget);

    if (position <= getCount()) {

        final Submission submission = submissions.get(position);

        String url = "";
        ContentType.Type type = ContentType.getContentType(submission);
        if (type == ContentType.Type.IMAGE) {
            url = submission.getUrl();
        } else if (submission.getDataNode().has("preview") && submission.getDataNode().get("preview").get("images").get(0).get("source").has("height") && submission.getDataNode().get("preview").get("images").get(0).get("source").get("height").asInt() > 200) {

            url = submission.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText();

        } else if (submission.getThumbnail() != null && (submission.getThumbnailType() == Submission.ThumbnailType.URL || submission.getThumbnailType() == Submission.ThumbnailType.NSFW)) {
            url = submission.getThumbnail();
        }
        try {

            //todo rv.setImageViewBitmap(R.id.thumbnail, Glide.with(mContext).load(url).asBitmap().);
            rv.setTextViewText(R.id.title, Html.fromHtml(submission.getTitle()));


        } catch (Exception e) {
            Log.v(LogUtil.getTag(), e.toString());
        }


        rv.setTextViewText(R.id.title, Html.fromHtml(submission.getTitle()));

        rv.setTextViewText(R.id.subreddit, submission.getSubredditName());
        rv.setTextViewText(R.id.info, submission.getAuthor() + " " + TimeUtils.getTimeAgo(submission.getCreated().getTime(), mContext));

        Bundle extras = new Bundle();
        extras.putString("url", submission.getUrl());
        Intent fillInIntent = new Intent();
        fillInIntent.putExtras(extras);
        rv.setOnClickFillInIntent(R.id.card, fillInIntent);
    }

    return rv;
}
 
Example 20
Source File: StackWidgetService.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public RemoteViews getViewAt(int position) {
	// position will always range from 0 to getCount() - 1.

	// We construct a remote views item based on our widget item xml file,
	// and set the
	// text based on the position.
	RemoteViews rv = new RemoteViews(mContext.getPackageName(),
			R.layout.widget_item);
	if (position % 2 == 0) {
		rv.setImageViewResource(R.id.widget_item, R.drawable.fire);
	} else {
		rv.setImageViewResource(R.id.widget_item, R.drawable.ente);
	}
	// rv.setTextViewText(R.id.widget_item,
	// mWidgetItems.get(position).text);

	// Next, we set a fill-intent which will be used to fill-in the pending
	// intent template
	// which is set on the collection view in StackWidgetProvider.
	Bundle extras = new Bundle();
	extras.putInt(StackWidgetProvider.EXTRA_ITEM, position);
	Intent fillInIntent = new Intent();
	fillInIntent.putExtras(extras);
	rv.setOnClickFillInIntent(R.id.widget_item, fillInIntent);

	// You can do heaving lifting in here, synchronously. For example, if
	// you need to
	// process an image, fetch something from the network, etc., it is ok to
	// do it here,
	// synchronously. A loading view will show up in lieu of the actual
	// contents in the
	// interim.
	try {
		System.out.println("Loading view " + position);
		Thread.sleep(500);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}

	// Return the remote views object.
	return rv;
}