@Override public RemoteViews getViewAt(int position) { RemoteViews row = new RemoteViews(context.getPackageName(), R.layout.widget_list_item); cursor.moveToPosition(position); Log.d(TAG, "view at " + position); row.setTextViewText( R.id.score_textview, Utilies.getScores( cursor.getInt(scoresAdapter.COL_HOME_GOALS), cursor.getInt(scoresAdapter.COL_AWAY_GOALS))); row.setTextViewText(R.id.home_name, cursor.getString(scoresAdapter.COL_HOME)); row.setTextViewText(R.id.away_name, cursor.getString(scoresAdapter.COL_AWAY)); row.setTextViewText(R.id.data_textview, cursor.getString(scoresAdapter.COL_MATCHTIME)); Intent fillInIntent = new Intent(); row.setOnClickFillInIntent(R.id.list_item, fillInIntent); row.setImageViewResource( R.id.home_crest, Utilies.getTeamCrestByTeamName(cursor.getString(scoresAdapter.COL_HOME))); row.setImageViewResource( R.id.away_crest, Utilies.getTeamCrestByTeamName(cursor.getString(scoresAdapter.COL_AWAY))); return row; }
@Override public void bindView(View view, final Context context, Cursor cursor) { final ViewHolder mHolder = (ViewHolder) view.getTag(); mHolder.home_name.setText(cursor.getString(COL_HOME)); mHolder.away_name.setText(cursor.getString(COL_AWAY)); mHolder.date.setText(cursor.getString(COL_MATCHTIME)); mHolder.score.setText( Utilies.getScores(cursor.getInt(COL_HOME_GOALS), cursor.getInt(COL_AWAY_GOALS))); mHolder.match_id = cursor.getDouble(COL_ID); mHolder.home_crest.setImageResource(Utilies.getTeamCrestByTeamName(cursor.getString(COL_HOME))); mHolder.home_crest.getLayoutParams().width = 150; mHolder.home_crest.getLayoutParams().height = 150; mHolder.away_crest.setImageResource(Utilies.getTeamCrestByTeamName(cursor.getString(COL_AWAY))); mHolder.away_crest.getLayoutParams().height = 150; mHolder.away_crest.getLayoutParams().width = 150; // Log.v(FetchScoreTask.LOG_TAG,mHolder.home_name.getText() + " Vs. " + // mHolder.away_name.getText() +" id " + String.valueOf(mHolder.match_id)); // Log.v(FetchScoreTask.LOG_TAG,String.valueOf(detail_match_id)); LayoutInflater vi = (LayoutInflater) context.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = vi.inflate(R.layout.detail_fragment, null); ViewGroup container = (ViewGroup) view.findViewById(R.id.details_fragment_container); if (mHolder.match_id == detail_match_id) { // Log.v(FetchScoreTask.LOG_TAG,"will insert extraView"); container.addView( v, 0, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); TextView match_day = (TextView) v.findViewById(R.id.matchday_textview); match_day.setText( Utilies.getMatchDay(cursor.getInt(COL_MATCHDAY), cursor.getInt(COL_LEAGUE))); TextView league = (TextView) v.findViewById(R.id.league_textview); league.setText(Utilies.getLeague(cursor.getInt(COL_LEAGUE))); Button share_button = (Button) v.findViewById(R.id.share_button); share_button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // add Share Action context.startActivity( createShareForecastIntent( mHolder.home_name.getText() + " " + mHolder.score.getText() + " " + mHolder.away_name.getText() + " ")); } }); } else { container.removeAllViews(); } }
@Override protected void onHandleIntent(Intent intent) { Intent service_start = new Intent(getApplicationContext(), myFetchService.class); getApplicationContext().startService(service_start); Cursor scores = getApplicationContext() .getContentResolver() .query(DatabaseContract.scores_table.buildScores(), null, null, null, null); scores.moveToFirst(); String lastestHome = scores.getString(scoresAdapter.COL_HOME); String lastestAway = scores.getString(scoresAdapter.COL_AWAY); Integer lastestScoreHome = scores.getInt(scoresAdapter.COL_HOME_GOALS); Integer lastestScoreAway = scores.getInt(scoresAdapter.COL_AWAY_GOALS); String lastestMatchTime = scores.getString(scoresAdapter.COL_MATCHTIME); // Retrieve all of the Today widget ids: these are the widgets we need to update AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(this, ScoreWidgetProvider.class)); for (int appWidgetId : appWidgetIds) { int layoutId = R.layout.widget_score_small; RemoteViews views = new RemoteViews(getPackageName(), layoutId); // views.widget_home_name.setText(cursor.getString(COL_HOME)); views.setTextViewText(R.id.widget_home_name, lastestHome); views.setTextViewText(R.id.widget_away_name, lastestAway); views.setTextViewText(R.id.widget_date_textview, lastestMatchTime); views.setTextViewText( R.id.widget_score_textview, Utilies.getScores(lastestScoreHome, lastestScoreAway)); views.setImageViewResource( R.id.widget_home_crest, Utilies.getTeamCrestByTeamName(lastestHome)); views.setImageViewResource( R.id.widget_away_crest, Utilies.getTeamCrestByTeamName(lastestAway)); // Add the data to the RemoteViews // Content Descriptions for RemoteViews were only added in ICS MR1 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { views.setContentDescription( R.id.widget_score_textview, "Score " + Utilies.getScores(lastestScoreHome, lastestScoreAway)); views.setContentDescription(R.id.widget_date_textview, "Time " + lastestMatchTime); } // Create an Intent to launch MainActivity Intent launchIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, launchIntent, 0); views.setOnClickPendingIntent(R.id.widget, pendingIntent); // Tell the AppWidgetManager to perform an update on the current app widget appWidgetManager.updateAppWidget(appWidgetId, views); } }
@Override public void onCreate() { cursor = context .getContentResolver() .query( DatabaseContract.scores_table.buildScoreWithDate(), null, null, new String[] {Utilies.getFormatedDate(new Date(System.currentTimeMillis()))}, null); observer = new ContentObserver(new Handler(Looper.getMainLooper())) { public void onChange(boolean selfChange, Uri uri) { onChange(selfChange); } public void onChange(boolean selfChange) { Log.d(TAG, "WidgetService.observer.onChange()"); AppWidgetManager.getInstance(WidgetService.this) .notifyAppWidgetViewDataChanged(appWidgetId, R.id.scores_list); } }; cursor.registerContentObserver(observer); // }
// Returns the page title for the top indicator @Override public CharSequence getPageTitle(int position) { return Utilies.getDayName( System.currentTimeMillis() + ((position - 2) * 86400000), getActivity().getString(R.string.today), getActivity().getString(R.string.tomorrow), getActivity().getString(R.string.yesterday)); }
private void updateWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { int layoutId = getLayoutId(context, appWidgetManager, appWidgetId); Intent intent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); RemoteViews views = new RemoteViews(context.getPackageName(), layoutId); views.setOnClickPendingIntent(R.id.widget_background, pendingIntent); views.setTextViewText(R.id.home_name, mLatestHome); views.setTextViewText(R.id.away_name, mLatestAway); views.setTextViewText(R.id.score_textview, mLatestScore); views.setTextViewText(R.id.data_textview, mLatestTime); views.setImageViewResource( R.id.home_crest, Utilies.getTeamCrestByTeamName(context.getResources(), mLatestHome)); views.setImageViewResource( R.id.away_crest, Utilies.getTeamCrestByTeamName(context.getResources(), mLatestAway)); appWidgetManager.updateAppWidget(appWidgetId, views); }
private void saveCursor(String title, Cursor cursor) { Match m = new Match(); m.setTitle(title); data.add(m); while (cursor.moveToNext()) { m = new Match(); m.setHome(cursor.getString(scoresAdapter.COL_HOME)); m.setHomeCrest(Utilies.getTeamCrestByTeamName(cursor.getString(scoresAdapter.COL_HOME))); m.setAway(cursor.getString(scoresAdapter.COL_AWAY)); m.setAwayCrest(Utilies.getTeamCrestByTeamName(cursor.getString(scoresAdapter.COL_AWAY))); m.setScore( Utilies.getScores( cursor.getInt(scoresAdapter.COL_HOME_GOALS), cursor.getInt(scoresAdapter.COL_AWAY_GOALS))); m.setMacthTime(cursor.getString(scoresAdapter.COL_MATCHTIME)); data.add(m); } }
@Override public RemoteViews getViewAt(int position) { RemoteViews mView = new RemoteViews(mContext.getPackageName(), R.layout.scores_list_item); if (cursor != null) { if (cursor.moveToPosition(position)) { String dir = cursor.getString(cursor.getColumnIndex("date")); mView.setTextViewText(R.id.home_name, "" + cursor.getString(COL_HOME)); mView.setTextViewText(R.id.away_name, "" + cursor.getString(COL_AWAY)); mView.setTextViewText(R.id.data_textview, "" + cursor.getString(COL_DATE)); mView.setTextViewText( R.id.score_textview, "" + Utilies.getScores(cursor.getInt(COL_HOME_GOALS), cursor.getInt(COL_AWAY_GOALS))); mView.setImageViewResource( R.id.home_crest, Utilies.getTeamCrestByTeamName(cursor.getString(COL_HOME))); mView.setImageViewResource( R.id.away_crest, Utilies.getTeamCrestByTeamName(cursor.getString(COL_AWAY))); } } final Intent fillInIntent = new Intent(); fillInIntent.setAction(WidgetProvider.ACTION_OPEN_ACTIVITY); final Bundle bundle = new Bundle(); bundle.putString(WidgetProvider.EXTRA_HOME_NAME, cursor.getString(COL_HOME)); bundle.putString(WidgetProvider.EXTRA_AWAY_NAME, cursor.getString(COL_AWAY)); bundle.putString( WidgetProvider.EXTRA_SCORE, Utilies.getScores(cursor.getInt(COL_HOME_GOALS), cursor.getInt(COL_AWAY_GOALS))); bundle.putString(WidgetProvider.EXTRA_DATE, cursor.getString(COL_DATE)); bundle.putInt(WidgetProvider.EXTRA_MATCH_DAY, cursor.getInt(COL_MATCH_DAY)); bundle.putInt(WidgetProvider.EXTRA_LEAGUE, cursor.getInt(COL_LEAGUE)); fillInIntent.putExtras(bundle); mView.setOnClickFillInIntent(R.id.widget_id, fillInIntent); return mView; }
private void getLatest(Context context) { Cursor c = context .getContentResolver() .query( DatabaseContract.BASE_CONTENT_URI, null, null, null, DatabaseContract.ScoresTable.DATE_COL + " DESC, " + DatabaseContract.ScoresTable.TIME_COL + " DESC"); if (c == null) { return; } if (!c.moveToFirst()) { c.close(); return; } do { String date = c.getString(c.getColumnIndex(DatabaseContract.ScoresTable.DATE_COL)); String time = c.getString(c.getColumnIndex(DatabaseContract.ScoresTable.TIME_COL)); String home = c.getString(c.getColumnIndex(DatabaseContract.ScoresTable.HOME_COL)); String away = c.getString(c.getColumnIndex(DatabaseContract.ScoresTable.AWAY_COL)); int homeGoals = c.getInt(c.getColumnIndex(DatabaseContract.ScoresTable.HOME_GOALS_COL)); int awayGoals = c.getInt(c.getColumnIndex(DatabaseContract.ScoresTable.AWAY_GOALS_COL)); // Log.v(TAG, "DateTime: " + date + " " + time + " " + "Goals: " + homeGoals + // "-" + awayGoals); if (homeGoals != -1 && awayGoals != -1) { mLatestHome = home; mLatestAway = away; mLatestScore = Utilies.getScores(context.getResources(), homeGoals, awayGoals); mLatestTime = time; break; } } while (c.moveToNext()); c.close(); // Log.v(TAG, "Latest: " + mLatestHome + " " + mLatestScore + " " + mLatestAway); }
@Override public void bindView(View view, final Context context, Cursor cursor) { final ViewHolder mHolder = (ViewHolder) view.getTag(); mHolder.home_name.setText(cursor.getString(COL_HOME)); mHolder.away_name.setText(cursor.getString(COL_AWAY)); mHolder.date.setText(cursor.getString(COL_MATCHTIME)); mHolder.score.setText( Utilies.getScores(cursor.getInt(COL_HOME_GOALS), cursor.getInt(COL_AWAY_GOALS))); mHolder.match_id = cursor.getDouble(COL_ID); // String s = cursor.getString(COL_HOME_CREST); // if (s != null && !"".equals(s)) { // mHolder.home_crest.setLayerType(View.LAYER_TYPE_SOFTWARE, null); // mHolder.home_crest.setImageDrawable(Utilies.transformSVGImageToDrawable(s)); // //mHolder.home_crest.setImageBitmap(Utilies.transformSVGImageToBitmap(s)); // } // // s = cursor.getString(COL_AWAY_CREST); // if (s != null && !"".equals(s)) // mHolder.away_crest.setImageBitmap(Utilies.transformSVGImageToBitmap(s)); downloadImageToView(cursor.getString(COL_HOME_CREST), mHolder.home_crest, context); downloadImageToView(cursor.getString(COL_AWAY_CREST), mHolder.away_crest, context); // Log.v(FetchScoreTask.LOG_TAG,mHolder.home_name.getText() + " Vs. " + // mHolder.away_name.getText() +" id " + String.valueOf(mHolder.match_id)); // Log.v(FetchScoreTask.LOG_TAG,String.valueOf(detail_match_id)); LayoutInflater vi = (LayoutInflater) context.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = vi.inflate(R.layout.detail_fragment, null); ViewGroup container = (ViewGroup) view.findViewById(R.id.details_fragment_container); if (mHolder.match_id == detail_match_id) { // Log.v(FetchScoreTask.LOG_TAG,"will insert extraView"); container.addView( v, 0, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); TextView match_day = (TextView) v.findViewById(R.id.matchday_textview); match_day.setText("Matchday : " + cursor.getInt(COL_MATCHDAY)); TextView league = (TextView) v.findViewById(R.id.league_textview); league.setText(cursor.getString(COL_LEAGUE)); Button share_button = (Button) v.findViewById(R.id.share_button); share_button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // add Share Action context.startActivity( createShareForecastIntent( mHolder.home_name.getText() + " " + mHolder.score.getText() + " " + mHolder.away_name.getText() + " ")); } }); } else { container.removeAllViews(); } }