本文整理汇总了Java中com.example.android.sunshine.app.R类的典型用法代码示例。如果您正苦于以下问题:Java R类的具体用法?Java R怎么用?Java R使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
R类属于com.example.android.sunshine.app包,在下文中一共展示了R类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configurePeriodicSync
import com.example.android.sunshine.app.R; //导入依赖的package包/类
/**
* Helper method to schedule the sync adapter periodic execution
*/
public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) {
Account account = getSyncAccount(context);
String authority = context.getString(R.string.content_authority);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// we can enable inexact timers in our periodic sync
SyncRequest request = new SyncRequest.Builder().
syncPeriodic(syncInterval, flexTime).
setSyncAdapter(account, authority).
setExtras(new Bundle()).build();
ContentResolver.requestSync(request);
} else {
ContentResolver.addPeriodicSync(account,
authority, new Bundle(), syncInterval);
}
}
示例2: onAccountCreated
import com.example.android.sunshine.app.R; //导入依赖的package包/类
private static void onAccountCreated(Account newAccount, Context context) {
/*
* Since we've created an account
*/
SunshineSyncAdapter.configurePeriodicSync(context, SYNC_INTERVAL, SYNC_FLEXTIME);
/*
* Without calling setSyncAutomatically, our periodic sync will not be enabled.
*/
ContentResolver.setSyncAutomatically(newAccount, context.getString(R.string.content_authority), true);
/*
* Finally, let's do a sync to get things started
*/
syncImmediately(context);
}
示例3: getWidgetWidthFromOptions
import com.example.android.sunshine.app.R; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private int getWidgetWidthFromOptions(AppWidgetManager appWidgetManager, int appWidgetId) {
Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
if (options.containsKey(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH)) {
int minWidthDp = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
// The width returned is in dp, but we'll convert it to pixels to match the other widths
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, minWidthDp,
displayMetrics);
}
return getResources().getDimensionPixelSize(R.dimen.widget_today_default_width);
}
示例4: sendNotification
import com.example.android.sunshine.app.R; //导入依赖的package包/类
/**
* Put the message into a notification and post it.
* This is just one simple example of what you might choose to do with a GCM message.
*
* @param message The alert message to be posted.
*/
private void sendNotification(String message) {
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent =
PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
// Notifications using both a large and a small icon (which yours should!) need the large
// icon as a bitmap. So we need to create that here from the resource ID, and pass the
// object along in our notification builder. Generally, you want to use the app icon as the
// small icon, so that users understand what app is triggering this notification.
Bitmap largeIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.art_storm);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.art_clear)
.setLargeIcon(largeIcon)
.setContentTitle("Weather Alert!")
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_HIGH);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
示例5: fromCursorRow
import com.example.android.sunshine.app.R; //导入依赖的package包/类
public static Forecast fromCursorRow(Context context, Cursor cursor) {
Forecast forecast = new Forecast();
// NOTE: The constant lookup of the column index for each field in this query is not optimal
// If this were being done for more than a few rows you would want to cache the lookups.
forecast.mWeatherId = cursor.getInt(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_WEATHER_ID));
forecast.mHigh = cursor.getDouble(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_MAX_TEMP));
forecast.mLow = cursor.getDouble(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_MIN_TEMP));
forecast.mDescription = cursor.getString(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_SHORT_DESC));
String date = cursor.getString(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_DATE));
forecast.mMillisecondsSincEpoch = Long.parseLong(date);
// Generate an ID to uniquely identify the notifications.
forecast.mDaysSinceEpoch = (int)(Long.parseLong(date) / MILLISECONDS_IN_A_DAY);
// Define the text of the forecast.
forecast.mNotificationContentText = String.format(context.getString(
R.string.format_notification),
forecast.mDescription,
Utility.formatTemperature(context, forecast.mHigh),
Utility.formatTemperature(context, forecast.mLow));
forecast.mNotificationTitle = context.getString(R.string.app_name);
return forecast;
}
示例6: syncImmediately
import com.example.android.sunshine.app.R; //导入依赖的package包/类
/**
* Helper method to have the sync adapter sync immediately
* @param context The context used to access the account service
*/
public static void syncImmediately(Context context) {
Bundle bundle = new Bundle();
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
ContentResolver.requestSync(getSyncAccount(context),
context.getString(R.string.content_authority), bundle);
}
示例7: getSyncAccount
import com.example.android.sunshine.app.R; //导入依赖的package包/类
/**
* Helper method to get the fake account to be used with SyncAdapter, or make a new one
* if the fake account doesn't exist yet. If we make a new account, we call the
* onAccountCreated method so we can initialize things.
*
* @param context The context used to access the account service
* @return a fake account.
*/
public static Account getSyncAccount(Context context) {
// Get an instance of the Android account manager
AccountManager accountManager =
(AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
// Create the account type and default account
Account newAccount = new Account(
context.getString(R.string.app_name), context.getString(R.string.sync_account_type));
// If the password doesn't exist, the account doesn't exist
if ( null == accountManager.getPassword(newAccount) ) {
/*
* Add the account and account type, no password or user data
* If successful, return the Account object, otherwise report an error.
*/
if (!accountManager.addAccountExplicitly(newAccount, "", null)) {
return null;
}
/*
* If you don't set android:syncable="true" in
* in your <provider> element in the manifest,
* then call ContentResolver.setIsSyncable(account, AUTHORITY, 1)
* here.
*/
onAccountCreated(newAccount, context);
}
return newAccount;
}
示例8: setLocationStatus
import com.example.android.sunshine.app.R; //导入依赖的package包/类
/**
* Sets the location status into shared preference. This function should not be called from
* the UI thread because it uses commit to write to the shared preferences.
* @param c Context to get the PreferenceManager from.
* @param locationStatus The IntDef value to set
*/
static private void setLocationStatus(Context c, @LocationStatus int locationStatus){
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(c);
SharedPreferences.Editor spe = sp.edit();
spe.putInt(c.getString(R.string.pref_location_status_key), locationStatus);
spe.commit();
}
示例9: onUpdate
import com.example.android.sunshine.app.R; //导入依赖的package包/类
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// Perform this loop procedure for each App Widget that belongs to this provider
for (int appWidgetId : appWidgetIds) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_detail);
// Create an Intent to launch MainActivity
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.widget, pendingIntent);
// Set up the collection
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
setRemoteAdapter(context, views);
} else {
setRemoteAdapterV11(context, views);
}
boolean useDetailActivity = context.getResources()
.getBoolean(R.bool.use_detail_activity);
Intent clickIntentTemplate = useDetailActivity
? new Intent(context, DetailActivity.class)
: new Intent(context, MainActivity.class);
PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context)
.addNextIntentWithParentStack(clickIntentTemplate)
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
views.setPendingIntentTemplate(R.id.widget_list, clickPendingIntentTemplate);
views.setEmptyView(R.id.widget_list, R.id.widget_empty);
// Tell the AppWidgetManager to perform an update on the current app widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
示例10: onReceive
import com.example.android.sunshine.app.R; //导入依赖的package包/类
@Override
public void onReceive(@NonNull Context context, @NonNull Intent intent) {
super.onReceive(context, intent);
if (SunshineSyncAdapter.ACTION_DATA_UPDATED.equals(intent.getAction())) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(
new ComponentName(context, getClass()));
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.widget_list);
}
}
示例11: getWidgetWidth
import com.example.android.sunshine.app.R; //导入依赖的package包/类
private int getWidgetWidth(AppWidgetManager appWidgetManager, int appWidgetId) {
// Prior to Jelly Bean, widgets were always their default size
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
return getResources().getDimensionPixelSize(R.dimen.widget_today_default_width);
}
// For Jelly Bean and higher devices, widgets can be resized - the current size can be
// retrieved from the newly added App Widget Options
return getWidgetWidthFromOptions(appWidgetManager, appWidgetId);
}
示例12: onMessageReceived
import com.example.android.sunshine.app.R; //导入依赖的package包/类
/**
* Called when message is received.
*
* @param from SenderID of the sender.
* @param data Data bundle containing message data as key/value pairs.
* For Set of keys use data.keySet().
*/
@Override
public void onMessageReceived(String from, Bundle data) {
// Time to unparcel the bundle!
if (!data.isEmpty()) {
// TODO: gcm_default sender ID comes from the API console
String senderId = getString(R.string.gcm_defaultSenderId);
if (senderId.length() == 0) {
Toast.makeText(this, "SenderID string needs to be set", Toast.LENGTH_LONG).show();
}
// Not a bad idea to check that the message is coming from your server.
if ((senderId).equals(from)) {
// Process message and then post a notification of the received message.
try {
JSONObject jsonObject = new JSONObject(data.getString(EXTRA_DATA));
String weather = jsonObject.getString(EXTRA_WEATHER);
String location = jsonObject.getString(EXTRA_LOCATION);
String alert =
String.format(getString(R.string.gcm_weather_alert), weather, location);
sendNotification(alert);
} catch (JSONException e) {
// JSON parsing failed, so we just let this message go, since GCM is not one
// of our critical features.
}
}
Log.i(TAG, "Received: " + data.toString());
}
}
示例13: onHandleIntent
import com.example.android.sunshine.app.R; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
try {
// In the (unlikely) event that multiple refresh operations occur simultaneously,
// ensure that they are processed sequentially.
synchronized (TAG) {
// Initially this call goes out to the network to retrieve the token, subsequent calls
// are local.
InstanceID instanceID = InstanceID.getInstance(this);
// TODO: gcm_default sender ID comes from the API console
String senderId = getString(R.string.gcm_defaultSenderId);
if ( senderId.length() != 0 ) {
String token = instanceID.getToken(senderId,
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
sendRegistrationToServer(token);
}
// You should store a boolean that indicates whether the generated token has been
// sent to your server. If the boolean is false, send the token to your server,
// otherwise your server should have already received the token.
sharedPreferences.edit().putBoolean(MainActivity.SENT_TOKEN_TO_SERVER, true).apply();
}
} catch (Exception e) {
Log.d(TAG, "Failed to complete token refresh", e);
// If an exception happens while fetching the new token or updating our registration data
// on a third-party server, this ensures that we'll attempt the update at a later time.
sharedPreferences.edit().putBoolean(MainActivity.SENT_TOKEN_TO_SERVER, false).apply();
}
}