本文整理汇总了Java中android.content.Context类的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Context类属于android.content包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReceive
import android.content.Context; //导入依赖的package包/类
@Override
public void onReceive(final Context context, final Intent intent) {
final String action = intent.getAction();
if (RSCService.BROADCAST_RSC_MEASUREMENT.equals(action)) {
final float speed = intent.getFloatExtra(RSCService.EXTRA_SPEED, 0.0f);
final int cadence = intent.getIntExtra(RSCService.EXTRA_CADENCE, 0);
final float totalDistance = intent.getFloatExtra(RSCService.EXTRA_TOTAL_DISTANCE, RSCManagerCallbacks.NOT_AVAILABLE);
final int activity = intent.getIntExtra(RSCService.EXTRA_ACTIVITY, RSCManagerCallbacks.ACTIVITY_WALKING);
// Update GUI
onMeasurementReceived(speed, cadence, totalDistance, activity);
} else if (RSCService.BROADCAST_STRIDES_UPDATE.equals(action)) {
final int strides = intent.getIntExtra(RSCService.EXTRA_STRIDES, 0);
final float distance = intent.getFloatExtra(RSCService.EXTRA_DISTANCE, 0);
// Update GUI
onStripesUpdate(distance, strides);
}
}
示例2: onReceive
import android.content.Context; //导入依赖的package包/类
@Override
public void onReceive(final Context context, Intent intent) {
if (AppWidgetManager.ACTION_APPWIDGET_HOST_RESTORED.equals(intent.getAction())) {
final int[] oldIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_OLD_IDS);
final int[] newIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
if (oldIds.length == newIds.length) {
final PendingResult asyncResult = goAsync();
new Handler(LauncherModel.getWorkerLooper())
.postAtFrontOfQueue(new Runnable() {
@Override
public void run() {
restoreAppWidgetIds(context, asyncResult, oldIds, newIds);
}
});
}
}
}
示例3: setUp
import android.content.Context; //导入依赖的package包/类
private void setUp(Context context, AttributeSet attrs)
{
TypedArray a =context.obtainStyledAttributes(attrs, R.styleable.CoolImageView);
String direction=a.getString(R.styleable.CoolImageView_direction);
if (direction == null)
{
throw new RuntimeException("You don't set direction properties,If you don't want to do that." +
"You can use ordinary ImageView instead");
}
else if (direction.equals("vertical"))
{
isSetVerticalMove = true;
}
else if (direction.equals("horizontal"));
else
{
throw new RuntimeException("Direction attribute set is not valid,It is only allowed to set to vertical or horizontal");
}
mDrawable = getDrawable();
mHandler = new MoveHandler();
mHandler.sendEmptyMessageDelayed(1, 220L);
}
示例4: setupPay
import android.content.Context; //导入依赖的package包/类
public static void setupPay(Context cxt, Config config) {
Intent i = new Intent(cxt, ZhiActivity.class);
i.putExtra(EXTRA_KEY_PAY_CONFIG, config);
cxt.startActivity(i);
}
示例5: onReceive
import android.content.Context; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
boolean connected = IU_Utils.checkConnection(context);
if(connected) {
if(this.attendingReconnection) {
this.attendingReconnection = false;
onReconnection();
}
} else {
this.attendingReconnection = true;
}
}
示例6: isWifi
import android.content.Context; //导入依赖的package包/类
/**
* isWifi
*
* @param context
* @return boolean
*/
public static boolean isWifi(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
if (activeNetInfo != null
&& activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
return true;
}
return false;
}
示例7: handleServerError
import android.content.Context; //导入依赖的package包/类
/**
* Handles the server error, tries to determine whether to show a stock message or to
* show a message retrieved from the server.
*
* @param err Volley error
* @param context Context
* @return String
*/
private static String handleServerError(Object err, Context context) {
VolleyError error = (VolleyError) err;
NetworkResponse response = error.networkResponse;
if (response != null) {
switch (response.statusCode) {
case 404:
case 422:
case 400:
case 401:
try {
String string = new String(error.networkResponse.data);
JSONObject object = new JSONObject(string);
if (object.has("message")) {
return object.get("message").toString();
}
else if(object.has("error_description")) {
return object.get("error_description").toString();
}
}catch (JSONException e)
{
return "Could not parse response";
}
// invalid request
return error.getMessage();
default:
return ERR_UNKNOWN_STATUS_CODE;
}
}
return ERR_GENERIC;
}
示例8: start
import android.content.Context; //导入依赖的package包/类
public static void start(Context context, String subscriber, String url,
int requestType) {
Intent intent = new Intent(context, TlIntentService.class);
intent.putExtra(Extra.SUBSCRIBER, subscriber);
intent.putExtra(Extra.URL, url);
intent.putExtra(Extra.REQUEST_TYPE, requestType);
context.startService(intent);
}
示例9: getDrawable
import android.content.Context; //导入依赖的package包/类
public static Drawable getDrawable(Context context, int id){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return context.getDrawable(id);
} else {
return context.getResources().getDrawable(id);
}
}
示例10: getSMSMessagesByThreadId
import android.content.Context; //导入依赖的package包/类
@Nullable
private SMSMessageCursorWrapper getSMSMessagesByThreadId(Context context, int threadId,
boolean desc, int limit) {
if (!Permissions.isGranted(context, Permissions.READ_SMS) ||
!Permissions.isGranted(context, Permissions.READ_CONTACTS)) {
return null;
}
String orderClause = (desc ? DATE + " DESC " : DATE + " ASC ");
String limitClause = (limit > 0 ? " LIMIT " + limit : "");
Cursor cursor = contentResolver.query(
URI_CONTENT_SMS,
null,
THREAD_ID + " = ? " +
// we don't support drafts yet
" AND " + ADDRESS + " NOT NULL ",
new String[]{String.valueOf(threadId)},
orderClause + limitClause);
return (validate(cursor) ? new SMSMessageCursorWrapper(cursor) : null);
}
示例11: getIdentityKeyPair
import android.content.Context; //导入依赖的package包/类
public static @NonNull IdentityKeyPair getIdentityKeyPair(@NonNull Context context) {
if (!hasIdentityKey(context)) throw new AssertionError("There isn't one!");
try {
IdentityKey publicKey = getIdentityKey(context);
ECPrivateKey privateKey = Curve.decodePrivatePoint(Base64.decode(retrieve(context, IDENTITY_PRIVATE_KEY_PREF)));
return new IdentityKeyPair(publicKey, privateKey);
} catch (IOException e) {
throw new AssertionError(e);
}
}
示例12: EmptyViewPod
import android.content.Context; //导入依赖的package包/类
public EmptyViewPod(Context context) {
super(context);
}
示例13: formatHighLows
import android.content.Context; //导入依赖的package包/类
/**
* This method will format the temperatures to be displayed in the
* following form: "HIGH° / LOW°"
*
* @param context Android Context to access preferences and resources
* @param high High temperature for a day in user's preferred units
* @param low Low temperature for a day in user's preferred units
*
* @return String in the form: "HIGH° / LOW°"
*/
public static String formatHighLows(Context context, double high, double low) {
long roundedHigh = Math.round(high);
long roundedLow = Math.round(low);
String formattedHigh = formatTemperature(context, roundedHigh);
String formattedLow = formatTemperature(context, roundedLow);
String highLowStr = formattedHigh + " / " + formattedLow;
return highLowStr;
}
示例14: MonthRecyclerView
import android.content.Context; //导入依赖的package包/类
public MonthRecyclerView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
mAdapter = new MonthAdapter(context);
setLayoutManager(new GridLayoutManager(context, 3));
setAdapter(mAdapter);
mAdapter.setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener() {
@Override
public void onItemClick(int position, long itemId) {
if (mListener != null) {
Month month = mAdapter.getItem(position);
mListener.onMonthSelected(month.getYear(), month.getMonth());
}
}
});
}
示例15: FragmentHostCallback
import android.content.Context; //导入依赖的package包/类
FragmentHostCallback(Activity activity, Context context, Handler handler, int windowAnimations) {
this.mFragmentManager = new FragmentManagerImpl();
this.mActivity = activity;
this.mContext = context;
this.mHandler = handler;
this.mWindowAnimations = windowAnimations;
}