Java Code Examples for android.content.Context

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project 2Degrees-Toolbox, under directory /ActionBarSherlock/src/com/actionbarsherlock/internal/.

Source file: ActionBarSherlockNative.java

  35 
vote

@Override protected Context getThemedContext(){
  Context context=mActivity;
  TypedValue outValue=new TypedValue();
  mActivity.getTheme().resolveAttribute(android.R.attr.actionBarWidgetTheme,outValue,true);
  if (outValue.resourceId != 0) {
    context=new ContextThemeWrapper(context,outValue.resourceId);
  }
  return context;
}
 

Example 2

From project 2Degrees-Toolbox, under directory /ActionBarSherlock/src/com/actionbarsherlock/internal/view/menu/.

Source file: MenuItemImpl.java

  33 
vote

public MenuItem setActionView(int resId){
  final Context context=mMenu.getContext();
  final LayoutInflater inflater=LayoutInflater.from(context);
  setActionView(inflater.inflate(resId,new LinearLayout(context),false));
  return this;
}
 

Example 3

From project agit, under directory /agit-integration-tests/src/main/java/com/madgag/agit/.

Source file: AndroidTestEnvironment.java

  33 
vote

public InputStream streamFor(String fileName){
  try {
    Context context=instrumentation.getContext();
    Log.i("ATE",asList(context.getAssets().list("")).toString());
    return context.getAssets().open(fileName);
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
}
 

Example 4

From project 4308Cirrus, under directory /Extras/actionbarsherlock/src/com/actionbarsherlock/internal/.

Source file: ActionBarSherlockNative.java

  32 
vote

@Override protected Context getThemedContext(){
  Context context=mActivity;
  TypedValue outValue=new TypedValue();
  mActivity.getTheme().resolveAttribute(android.R.attr.actionBarWidgetTheme,outValue,true);
  if (outValue.resourceId != 0) {
    context=new ContextThemeWrapper(context,outValue.resourceId);
  }
  return context;
}
 

Example 5

From project 4308Cirrus, under directory /Extras/actionbarsherlock/src/com/actionbarsherlock/internal/view/menu/.

Source file: MenuItemImpl.java

  32 
vote

public MenuItem setActionView(int resId){
  final Context context=mMenu.getContext();
  final LayoutInflater inflater=LayoutInflater.from(context);
  setActionView(inflater.inflate(resId,new LinearLayout(context),false));
  return this;
}
 

Example 6

From project ActionBarCompat, under directory /ActionBarCompat/src/sk/m217/actionbarcompat/.

Source file: SimpleMenuItem.java

  32 
vote

public MenuItem setActionView(int resId){
  final Context context=mMenu.getContext();
  final LayoutInflater inflater=LayoutInflater.from(context);
  setActionView(inflater.inflate(resId,null));
  return this;
}
 

Example 7

From project ActionBarSherlock, under directory /library/src/com/actionbarsherlock/internal/.

Source file: ActionBarSherlockNative.java

  32 
vote

@Override protected Context getThemedContext(){
  Context context=mActivity;
  TypedValue outValue=new TypedValue();
  mActivity.getTheme().resolveAttribute(android.R.attr.actionBarWidgetTheme,outValue,true);
  if (outValue.resourceId != 0) {
    context=new ContextThemeWrapper(context,outValue.resourceId);
  }
  return context;
}
 

Example 8

From project ActionBarSherlock, under directory /library/src/com/actionbarsherlock/internal/view/menu/.

Source file: MenuItemImpl.java

  32 
vote

public MenuItem setActionView(int resId){
  final Context context=mMenu.getContext();
  final LayoutInflater inflater=LayoutInflater.from(context);
  setActionView(inflater.inflate(resId,new LinearLayout(context),false));
  return this;
}
 

Example 9

From project agit, under directory /agit-integration-tests/src/main/java/com/madgag/agit/.

Source file: RepoNotificationsTest.java

  32 
vote

@SmallTest public void testShouldHaveDifferentOngoingNotificationIds() throws Exception {
  File gitdir1=new File(helper.newFolder(),DOT_GIT), gitdir2=new File(helper.newFolder(),DOT_GIT);
  Context c=getInstrumentation().getContext();
  RepoNotifications roc1a=new RepoNotifications(c,gitdir1,null);
  RepoNotifications roc1b=new RepoNotifications(c,gitdir1,null);
  RepoNotifications roc2=new RepoNotifications(c,gitdir2,null);
  assertTrue(roc1a.getOngoingNotificationId() == roc1b.getOngoingNotificationId());
  assertFalse(roc1a.getOngoingNotificationId() == roc2.getOngoingNotificationId());
}
 

Example 10

From project adg-android, under directory /src/com/analysedesgeeks/android/os_service/.

Source file: MediaButtonIntentReceiver.java

  31 
vote

@Override public void handleMessage(final Message msg){
switch (msg.what) {
case MSG_LONGPRESS_TIMEOUT:
    if (!mLaunched) {
      final Context context=(Context)msg.obj;
      final Intent i=new Intent();
      i.putExtra("autoshuffle","true");
      i.setClass(context,PodcastPlaybackService.class);
      i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
      context.startActivity(i);
      mLaunched=true;
    }
  break;
}
}
 

Example 11

From project Absolute-Android-RSS, under directory /src/com/AA/Activities/.

Source file: AASettings.java

  30 
vote

/** 
 * Sets up our adapter
 * @param context - Context that we will be working with
 */
public ColorAdapter(Context context){
  super(context,R.layout.settings_main,R.id.tv_colorType);
  this.add("Unread Article Background");
  this.add("Read Article Background");
  this.add("Unread Article Text Color");
  this.add("Read Article Text Color");
}
 

Example 12

From project AChartEngine, under directory /achartengine/src/org/achartengine/.

Source file: GraphicalView.java

  30 
vote

/** 
 * Creates a new graphical view.
 * @param context the context
 * @param chart the chart to be drawn
 */
public void setup(Context context){
  AbstractChart chart=buildChart();
  mChart=chart;
  mHandler=new Handler();
  if (mChart instanceof XYChart) {
    mRenderer=((XYChart)mChart).getRenderer();
  }
 else {
    mRenderer=((RoundChart)mChart).getRenderer();
  }
  if (mRenderer.isZoomButtonsVisible()) {
    zoomInImage=BitmapFactory.decodeStream(GraphicalView.class.getResourceAsStream("image/zoom_in.png"));
    zoomOutImage=BitmapFactory.decodeStream(GraphicalView.class.getResourceAsStream("image/zoom_out.png"));
    fitZoomImage=BitmapFactory.decodeStream(GraphicalView.class.getResourceAsStream("image/zoom-1.png"));
  }
  if (mRenderer instanceof XYMultipleSeriesRenderer && ((XYMultipleSeriesRenderer)mRenderer).getMarginsColor() == XYMultipleSeriesRenderer.NO_COLOR) {
    ((XYMultipleSeriesRenderer)mRenderer).setMarginsColor(mPaint.getColor());
  }
  if (mRenderer.isZoomEnabled() && mRenderer.isZoomButtonsVisible() || mRenderer.isExternalZoomEnabled()) {
    mZoomIn=new Zoom(mChart,true,mRenderer.getZoomRate());
    mZoomOut=new Zoom(mChart,false,mRenderer.getZoomRate());
    mFitZoom=new FitZoom(mChart);
  }
  int version=7;
  try {
    version=Integer.valueOf(Build.VERSION.SDK);
  }
 catch (  Exception e) {
  }
  if (version < 7) {
    mTouchHandler=new TouchHandlerOld(this,mChart);
  }
 else {
    mTouchHandler=new TouchHandler(this,mChart);
  }
}
 

Example 13

From project abalone-android, under directory /src/com/bytopia/abalone/.

Source file: GameActivity.java

  29 
vote

@Override protected void onPause(){
  Log.d("state","paused");
  try {
    FileOutputStream fos=openFileOutput(FILE_NAME,Context.MODE_PRIVATE);
    ObjectOutputStream oos=new ObjectOutputStream(fos);
    oos.writeObject(game.getBoard());
    oos.writeByte(game.getSide());
    oos.writeByte(game.getVsType());
    if (cpuType != null) {
      oos.writeObject(cpuType);
    }
    oos.writeByte((byte)game.getBoard().getMarblesCaptured(Side.BLACK));
    oos.writeByte((byte)game.getBoard().getMarblesCaptured(Side.WHITE));
    oos.close();
  }
 catch (  FileNotFoundException e) {
    Log.d("state","FileNotFound");
  }
catch (  IOException e) {
    Log.d("state","IO Exception");
  }
  super.onPause();
}
 

Example 14

From project Absolute-Android-RSS, under directory /src/com/AA/Activities/.

Source file: AAMain.java

  29 
vote

/** 
 * Called when the activity is created and put into memory. This is where all GUI elements should be set up and any other member variables that is used throughout the class
 */
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  articles=new ArrayList<Article>();
  settings=this.getSharedPreferences("settings",0);
  AlarmReceiver.stopAlarm(this);
  adapter=new ArticleAdapter(this);
  this.setListAdapter(adapter);
  ib_refresh=(ImageButton)findViewById(R.id.ib_refresh);
  TextView tv=(TextView)findViewById(R.id.AATitle);
  Typeface face=Typeface.createFromAsset(getAssets(),"fonts/WREXHAM_.TTF");
  tv.setTypeface(face);
  finishReceiver=new BroadcastReceiver(){
    @Override public void onReceive(    Context context,    Intent intent){
      articles.clear();
      Bundle articleBundle=intent.getBundleExtra("articles");
      ArrayList<String> titles=articleBundle.getStringArrayList("titles");
      for (      String title : titles)       articles.add((Article)articleBundle.getSerializable(title));
      progressDialog.cancel();
      refresh();
    }
  }
;
  this.registerReceiver(finishReceiver,new IntentFilter("RSSFinish"));
  ib_refresh.setOnClickListener(new OnClickListener(){
    /** 
 * Handles when the user clicks the refresh button
 * @param v - view that was clicked
 */
    @Override public void onClick(    View v){
      runService();
    }
  }
);
  runService();
}
 

Example 15

From project AChartEngine, under directory /src/org/achartengine/.

Source file: GraphicalView.java

  29 
vote

private void setup(Context context){
  mChart=buildChart();
  mHandler=new Handler();
  if (mChart instanceof XYChart) {
    mRenderer=((XYChart)mChart).getRenderer();
  }
 else {
    mRenderer=((RoundChart)mChart).getRenderer();
  }
  if (mRenderer.isZoomButtonsVisible()) {
    zoomInImage=BitmapFactory.decodeStream(GraphicalView.class.getResourceAsStream("image/zoom_in.png"));
    zoomOutImage=BitmapFactory.decodeStream(GraphicalView.class.getResourceAsStream("image/zoom_out.png"));
    fitZoomImage=BitmapFactory.decodeStream(GraphicalView.class.getResourceAsStream("image/zoom-1.png"));
  }
  if (mRenderer.isZoomEnabled() && mRenderer.isZoomButtonsVisible() || mRenderer.isExternalZoomEnabled()) {
    mZoomIn=new Zoom(mChart,true,mRenderer.getZoomRate());
    mZoomOut=new Zoom(mChart,false,mRenderer.getZoomRate());
    mFitZoom=new FitZoom(mChart);
  }
  int version=7;
  try {
    version=Integer.valueOf(Build.VERSION.SDK);
  }
 catch (  Exception e) {
  }
  if (version < 7) {
    mTouchHandler=new TouchHandlerOld(this,mChart);
  }
 else {
    mTouchHandler=new TouchHandler(this,mChart);
  }
}
 

Example 16

From project actionbar, under directory /actionbar-library/src/main/java/com/github/erd/actionbar/widget/.

Source file: Actionbar.java

  29 
vote

/** 
 * Class constructor.
 * @param context Current context.
 * @param attrs XML attributes.
 * @param style Style definition.
 */
public Actionbar(Context context,AttributeSet attrs,int style){
  super(context,attrs);
  final TypedArray a=context.obtainStyledAttributes(attrs,R.styleable.Actionbar,style,0);
  data=a.getString(R.styleable.Actionbar_title);
  draw=a.getDrawable(R.styleable.Actionbar_logo);
  back=a.getDrawable(R.styleable.Actionbar_background);
  type=a.getInt(R.styleable.Actionbar_type,TYPE_STANDARD);
  back=a.getDrawable(R.styleable.Actionbar_background);
  a.recycle();
  setId(R.id.action_bar);
  View.inflate(context,R.layout.actionbar,this);
}
 

Example 17

From project actionbar, under directory /actionbar-library/src/main/java/com/github/erd/actionbar/widget/.

Source file: ActionbarButton.java

  29 
vote

/** 
 * Class constructor.
 * @param context Current context.
 * @param attrs XML attributes.
 * @param style Default style.
 */
public ActionbarButton(Context context,AttributeSet attrs,int style){
  super(context,attrs,style);
  final TypedArray a=context.obtainStyledAttributes(attrs,R.styleable.ActionbarButton,style,0);
  int micon=a.getInt(R.styleable.ActionbarButton_icon,ICON_HOME);
  if (micon > 0) {
    setButtonIcon(micon);
  }
  a.recycle();
}
 

Example 18

From project ActionBarCompat, under directory /ActionBarCompat/src/sk/m217/actionbarcompat/.

Source file: ActionBarHelperHoneycomb.java

  29 
vote

@Override public void setRefreshActionItemState(boolean refreshing){
  if (mOptionsMenu == null) {
    return;
  }
  final MenuItem refreshItem=mOptionsMenu.findItem(R.id.menu_refresh);
  if (refreshItem != null) {
    if (refreshing) {
      if (mRefreshIndeterminateProgressView == null) {
        LayoutInflater inflater=(LayoutInflater)getActionBarThemedContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mRefreshIndeterminateProgressView=inflater.inflate(R.layout.actionbar_indeterminate_progress,null);
      }
      refreshItem.setActionView(mRefreshIndeterminateProgressView);
    }
 else {
      refreshItem.setActionView(null);
    }
  }
}
 

Example 19

From project adg-android, under directory /src/com/analysedesgeeks/android/.

Source file: ActivityController.java

  29 
vote

public static void onContactEmailClicked(final Context context){
  final Intent emailIntent=new Intent(android.content.Intent.ACTION_SEND);
  final Resources res=context.getResources();
  emailIntent.setType("plain/text");
  emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{Const.ADG_CONTACT_EMAIL});
  emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,res.getString(R.string.contactEmailSubject));
  context.startActivity(Intent.createChooser(emailIntent,res.getString(R.string.sendEmail)));
}
 

Example 20

From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/activity/adapter/.

Source file: SessionAdapter.java

  29 
vote

private void fillTitle(View view,Context context,Session session){
  TextView sessionTitle=(TextView)view.findViewById(R.id.session_title);
  if (session.getTitle() != null && session.getTitle().length() > 0) {
    sessionTitle.setText(session.getTitle());
  }
 else {
    String unnamed=context.getString(R.string.unnamed_session);
    sessionTitle.setText(Html.fromHtml(unnamed));
  }
}
 

Example 21

From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/activity/extsens/.

Source file: IOIOInteractor.java

  29 
vote

void startPreviouslyConnectedIOIO(SettingsHelper settings,Context context){
  List<ExternalSensorDescriptor> descriptors=settings.knownSensors();
  for (  ExternalSensorDescriptor descriptor : descriptors) {
    startIfNecessary(descriptor,context);
  }
}