Skip to content

Instantly share code, notes, and snippets.

View j-onathan's full-sized avatar

Jonathan j-onathan

View GitHub Profile
public void shouldStoreLastSentTextMessageParameters() {
smsManager.sendTextMessage(testDestinationAddress, testScAddress, testText, null, null);
ShadowSmsManager.TextSmsParams lastParams = shadowSmsManager.getLastSentTextMessageParams();
Assert.assertEquals(testDestinationAddress, lastParams.getDestinationAddress());
Assert.assertEquals(testScAddress, lastParams.getScAddress());
Assert.assertEquals(testText, lastParams.getText());
}
public static Intent createYoutubeIntent(MovieBean movie) {
Builder youtubeUri = new Builder();
youtubeUri.scheme("http");
youtubeUri.authority("m.youtube.com");
youtubeUri.path("results");
youtubeUri.appendQueryParameter("q", new StringBuilder("\"").append(movie.getMovieName()).append("\" trailer").toString());
StringBuilder youtubeUriStr = new StringBuilder("http://m.youtube.com/results?q=");
youtubeUriStr.append(new StringBuilder("\"").append(Uri.encode(movie.getMovieName())).append("\"+trailer").toString());
Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(youtubeUriStr.toString()));
private void ifGPSregisterOneShotNetworkUpdate() {
String bestEnabledProvider = locationManager.getBestProvider(criteria, true);
if (bestEnabledProvider != null && LocationManager.GPS_PROVIDER.equals(bestEnabledProvider)) {
locationManager.removeUpdates(oneShotNetworkLocationListener);
if (isNetworkProviderEnabled()) {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, oneShotNetworkLocationListener);
}
}
}
public static boolean haveNetworkConnection(Context context) {
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
if(activeNetwork == null) return false;
return activeNetwork.isConnected();
}
AnimatorSet set = new AnimatorSet();
set.playSequentially(moveAnim, skewAnim, wobbleAnim);
if (finishDownAnim != null) {
set.play(finishDownAnim).before(moveAnim);
}
toneGen1 = new ToneGenerator(AudioManager.STREAM_MUSIC, 100);
toneGen2 = new ToneGenerator(AudioManager.STREAM_MUSIC, 50);
if (toneGen1.startTone(ToneGenerator.TONE_DTMF_1)) {
Thread.sleep(100);
if (toneGen2.startTone(ToneGenerator.TONE_DTMF_2)) {
Thread.sleep(500);
toneGen1.stopTone();
Thread.sleep(100);
toneGen2.stopTone();
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(WHITE);
Bitmap clipped = Bitmap.createBitmap(width, height, ARGB_8888);
Canvas canvas = new Canvas(clipped);
canvas.drawRoundRect(new RectF(0, 0, width, height), radius, radius, paint);
paint.setXfermode(new PorterDuffXfermode(DST_IN));
public static AlertDialog newMessageDialog(final Context context, String dialogTitle,
String screenMessage, int iconResourceId) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setCancelable(false);
builder.setPositiveButton("Okay", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
int uriType = sURIMatcher.match(uri);
switch (uriType) {
case SIMPLEENTITY_DIR:
queryBuilder.setTables(TABLENAME);
break;
case SIMPLEENTITY_ID:
HandlerThread thr = new HandlerThread("SystemUI StorageNotification");
thr.start();
mAsyncEventHandler = new Handler(thr.getLooper());