Skip to content

Instantly share code, notes, and snippets.

View j-onathan's full-sized avatar

Jonathan j-onathan

View GitHub Profile
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()));
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());
}
private void replyMessage(Context context, SmsMessage msg) {
SmsManager sms = SmsManager.getDefault();
String message = msg.getMessageBody();
sms.sendTextMessage(msg.getOriginatingAddress(), null, message, null, null);
}
}
protected void startRecording(String file){
if (!isRecording){
saveFile=file;
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(this.recording);
try {
recorder.prepare();
TextView textView = (TextView)row.findViewById(android.R.id.text1);
float scale = activity.getResources().getDisplayMetrics().density;
boolean leftPadding = (parent.getTag().equals("right"));
boolean topPadding = (position == 0);
textView.setPadding((int)(20 * scale) * (leftPadding ? 2 : 1), (int)(20 * scale) * (!leftPadding && topPadding ? 1 : 0), (int)(20 * scale), 0);
textView.setText(item);
textView.setTextColor(Color.BLACK);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
try {
in = pAssetManager.open(pAssetPath);
BitmapFactory.decodeStream(in, null, decodeOptions);
} catch (final IOException e) {
Debug.e("Failed loading Bitmap in AssetBitmapTextureAtlasSource. AssetPath: " + pAssetPath, e);
} finally {
StreamUtils.close(in);
}
public PushMessage(String jsonMessage) throws PreyException{
try {
JSONObject jsonObj = new JSONObject(jsonMessage);
JSONObject data = jsonObj.getJSONObject("data");
this.event = jsonObj.getString("event");
this.type = data.getString("type");
this.body = data.getString("body");
} catch (JSONException e) {
throw new PreyException("Couldn't parse pushed json message");
}
public static Location getLatestLocation(final Context context) {
LocationManager manager = (LocationManager) context
.getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(ACCURACY_FINE);
String provider = manager.getBestProvider(criteria, true);
Location bestLocation;
if (provider != null)
bestLocation = manager.getLastKnownLocation(provider);
else
protected void onListItemClick (ListView listView, View view, int position, long id) {
super.onListItemClick(listView, view, position, id);
Editor editor = prefs.edit();
editor.putInt("index", listView.getFirstVisiblePosition());
editor.putInt("top", listView.getChildAt(0) == null ? 0 : listView.getChildAt(0).getTop());
editor.commit();
Object o = this.getListAdapter().getItem(position);
String testName = o.toString();
public void clearState() {
Editor editor = m_prefs.edit();
editor.remove(PREF_FIRSTRUN);
editor.remove(PREF_DONE_REV);
editor.remove(PREF_TODO_REV);
editor.remove(PREF_NEED_TO_PUSH);
editor.commit();
}