Java Code Examples for androidx.appcompat.app.AppCompatActivity#getApplicationContext()
The following examples show how to use
androidx.appcompat.app.AppCompatActivity#getApplicationContext() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GameHelper.java From Asteroid with Apache License 2.0 | 6 votes |
/** * Call this method from your Activity's onStart(). */ public void onStart(AppCompatActivity act) { mActivity = act; mAppContext = act.getApplicationContext(); debugLog("onStart"); assertConfigured("onStart"); if (mConnectOnStart) { if (mGoogleApiClient.isConnected()) { Log.w(TAG, "GameHelper: client was already connected on onStart()"); } else { debugLog("Connecting client."); mConnecting = true; mGoogleApiClient.connect(); } } else { debugLog("Not attempting to connect because mConnectOnStart=false"); debugLog("Instead, reporting a sign-in failure."); mHandler.postDelayed(() -> notifyListener(false), 1000); } }
Example 2
Source File: Location.java From UberClone with MIT License | 5 votes |
public Location(AppCompatActivity activity, final locationListener locationListener) { this.activity=activity; fusedLocationClient=new FusedLocationProviderClient(activity.getApplicationContext()); inicializeLocationRequest(); locationCallback=new LocationCallback(){ @Override public void onLocationResult(LocationResult locationResult) { super.onLocationResult(locationResult); locationListener.locationResponse(locationResult); } }; }
Example 3
Source File: Location.java From UberClone with MIT License | 5 votes |
public Location(AppCompatActivity activity, final locationListener locationListener) { this.activity=activity; fusedLocationClient=new FusedLocationProviderClient(activity.getApplicationContext()); inicializeLocationRequest(); locationCallback=new LocationCallback(){ @Override public void onLocationResult(LocationResult locationResult) { super.onLocationResult(locationResult); locationListener.locationResponse(locationResult); } }; }
Example 4
Source File: RangeDateSelectorTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Before public void setupMonthAdapters() { ApplicationProvider.getApplicationContext().setTheme(R.style.Theme_MaterialComponents_Light); AppCompatActivity activity = Robolectric.buildActivity(AppCompatActivity.class).setup().get(); context = activity.getApplicationContext(); GridView gridView = new GridView(context); rangeDateSelector = new RangeDateSelector(); adapter = new MonthAdapter( Month.create(2016, Calendar.FEBRUARY), rangeDateSelector, new CalendarConstraints.Builder().build()); gridView.setAdapter(adapter); }
Example 5
Source File: SingleDateSelectorTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Before public void setupMonthAdapters() { ApplicationProvider.getApplicationContext().setTheme(R.style.Theme_MaterialComponents_Light); AppCompatActivity activity = Robolectric.buildActivity(AppCompatActivity.class).setup().get(); Context context = activity.getApplicationContext(); GridView gridView = new GridView(context); singleDateSelector = new SingleDateSelector(); adapter = new MonthAdapter( Month.create(2016, Calendar.FEBRUARY), singleDateSelector, new CalendarConstraints.Builder().build()); gridView.setAdapter(adapter); }
Example 6
Source File: CalendarStyleTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Before public void setupCalendarStyleAndTestView() { ApplicationProvider.getApplicationContext() .setTheme(R.style.Test_Theme_MaterialComponents_MaterialCalendar); AppCompatActivity activity = Robolectric.buildActivity(AppCompatActivity.class).setup().get(); context = activity.getApplicationContext(); calendarStyle = new CalendarStyle(context); textView = new TextView(context); }
Example 7
Source File: AppData.java From MaterialScrollBar with Apache License 2.0 | 4 votes |
private static void openMainActivity(AppCompatActivity activity) { Intent main = new Intent(activity.getApplicationContext(), MainActivity.class); activity.startActivity(main); }
Example 8
Source File: RedditPreparedMessage.java From RedReader with GNU General Public License v3.0 | 4 votes |
public RedditPreparedMessage( @NonNull final AppCompatActivity activity, @NonNull final RedditMessage message, final long timestamp) { final Context applicationContext = activity.getApplicationContext(); this.src = message; // TODO custom time // TODO respect RRTheme final int rrCommentHeaderBoldCol; final int rrCommentHeaderAuthorCol; { final TypedArray appearance = activity.obtainStyledAttributes(new int[]{ R.attr.rrCommentHeaderBoldCol, R.attr.rrCommentHeaderAuthorCol, }); rrCommentHeaderBoldCol = appearance.getColor(0, 255); rrCommentHeaderAuthorCol = appearance.getColor(1, 255); appearance.recycle(); } body = HtmlReader.parse(message.getUnescapedBodyHtml(), activity); idAndType = message.name; final BetterSSB sb = new BetterSSB(); if(src.author == null) { sb.append("[" + applicationContext.getString(R.string.general_unknown) + "]", BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, rrCommentHeaderAuthorCol, 0, 1f); } else { sb.append(src.author, BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, rrCommentHeaderAuthorCol, 0, 1f); } sb.append(" ", 0); sb.append(RRTime.formatDurationFrom(applicationContext, src.created_utc * 1000L), BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, rrCommentHeaderBoldCol, 0, 1f); header = sb.get(); }
Example 9
Source File: GameHelper.java From Asteroid with Apache License 2.0 | 3 votes |
/** * Construct a GameHelper object, initially tied to the given Activity. * After constructing this object, call @link{setup} from the onCreate() * method of your Activity. * * @param clientsToUse the API clients to use (a combination of the CLIENT_* flags, * or CLIENT_ALL to mean all clients). */ public GameHelper(AppCompatActivity activity, int clientsToUse) { mActivity = activity; mAppContext = activity.getApplicationContext(); mRequestedClients = clientsToUse; mHandler = new Handler(); }