当前位置: 首页>>代码示例>>Java>>正文


Java Context类代码示例

本文整理汇总了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);
	}
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:19,代码来源:RSCActivity.java

示例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);
                        }
                    });
        }
    }
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:18,代码来源:AppWidgetsRestoredReceiver.java

示例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);

  }
 
开发者ID:stytooldex,项目名称:stynico,代码行数:24,代码来源:CookView.java

示例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);
}
 
开发者ID:NicoLiutong,项目名称:miaosou,代码行数:6,代码来源:MiniPayUtils.java

示例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;
    }
}
 
开发者ID:customerly,项目名称:Customerly-Android-SDK,代码行数:13,代码来源:IAct_AInput.java

示例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;
}
 
开发者ID:ZhouKanZ,项目名称:SweepRobot,代码行数:17,代码来源:NetworkUtil.java

示例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;
}
 
开发者ID:jamesddube,项目名称:LaravelNewsApp,代码行数:43,代码来源:VolleyErrorHelper.java

示例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);
}
 
开发者ID:TigranSarkisian,项目名称:Boilerplate,代码行数:9,代码来源:TlIntentService.java

示例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);
    }

}
 
开发者ID:jbmlaird,项目名称:DiscogsBrowser,代码行数:9,代码来源:UtilsJava.java

示例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);
}
 
开发者ID:kaliturin,项目名称:BlackList,代码行数:22,代码来源:ContactsAccessHelper.java

示例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);
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:13,代码来源:IdentityKeyUtil.java

示例12: EmptyViewPod

import android.content.Context; //导入依赖的package包/类
public EmptyViewPod(Context context) {
    super(context);
}
 
开发者ID:agpyaephyo,项目名称:PADC-SFC-News,代码行数:4,代码来源:EmptyViewPod.java

示例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;
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:21,代码来源:SunshineWeatherUtils.java

示例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());
            }
        }
    });
}
 
开发者ID:yhyonghao,项目名称:CalendarView_master,代码行数:16,代码来源:MonthRecyclerView.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:8,代码来源:FragmentHostCallback.java


注:本文中的android.content.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。