List of usage examples for android.content Intent FLAG_ACTIVITY_BROUGHT_TO_FRONT
int FLAG_ACTIVITY_BROUGHT_TO_FRONT
To view the source code for android.content Intent FLAG_ACTIVITY_BROUGHT_TO_FRONT.
Click Source Link
From source file:ufms.br.com.ufmsapp.activity.GraficosActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: Intent parentIntent = NavUtils.getParentActivityIntent(this); parentIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(parentIntent);//from ww w. j a v a 2s .co m supportFinishAfterTransition(); break; } return super.onOptionsItemSelected(item); }
From source file:cm.aptoide.pt.DownloadQueueService.java
private void setFinishedNotification(int apkidHash, String localPath) { String apkid = notifications.get(apkidHash).get("apkid"); int size = Integer.parseInt(notifications.get(apkidHash).get("intSize")); String version = notifications.get(apkidHash).get("version"); RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification); contentView.setImageViewResource(R.id.download_notification_icon, R.drawable.ic_notification); contentView.setTextViewText(R.id.download_notification_name, getString(R.string.finished_download_message) + " " + apkid + " v." + version); contentView.setProgressBar(R.id.download_notification_progress_bar, size * KBYTES_TO_BYTES, size * KBYTES_TO_BYTES, false); Intent onClick = new Intent("pt.caixamagica.aptoide.INSTALL_APK", Uri.parse("apk:" + apkid)); onClick.setClassName("cm.aptoide.pt", "cm.aptoide.pt.RemoteInTab"); onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); onClick.putExtra("localPath", localPath); onClick.putExtra("apkid", apkid); onClick.putExtra("apkidHash", apkidHash); onClick.putExtra("isUpdate", Boolean.parseBoolean(notifications.get(apkid.hashCode()).get("isUpdate"))); /*Changed by Rafael Campos*/ onClick.putExtra("version", notifications.get(apkid.hashCode()).get("version")); Log.d("Aptoide-DownloadQueuService", "finished notification apkidHash: " + apkidHash + " localPath: " + localPath); // The PendingIntent to launch our activity if the user selects this notification PendingIntent onClickAction = PendingIntent.getActivity(context, 0, onClick, 0); Notification notification = new Notification(R.drawable.ic_notification, getString(R.string.finished_download_alrt) + " " + apkid, System.currentTimeMillis()); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.contentView = contentView; // Set the info for the notification panel. notification.contentIntent = onClickAction; // notification.setLatestEventInfo(this, getText(R.string.app_name), getText(R.string.add_repo_text), contentIntent); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Send the notification. // We use the position because it is a unique number. We use it later to cancel. notificationManager.notify(apkidHash, notification); // Log.d("Aptoide-DownloadQueueService", "Notification Set"); }
From source file:at.flack.receiver.SmsReceiver.java
@Override public void onReceive(Context context, Intent intent) { sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); notify = sharedPrefs.getBoolean("notifications", true); vibrate = sharedPrefs.getBoolean("vibration", true); headsup = sharedPrefs.getBoolean("headsup", true); led_color = sharedPrefs.getInt("notification_light", -16776961); boolean all = sharedPrefs.getBoolean("all_sms", true); if (notify == false) return;// w ww . j a v a 2 s.com Bundle bundle = intent.getExtras(); SmsMessage[] msgs = null; String str = ""; if (bundle != null) { Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int i = 0; i < msgs.length; i++) { msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); str += msgs[i].getMessageBody().toString(); str += "\n"; } NotificationCompat.Builder mBuilder; if (main != null) { main.addNewMessage(str); return; } boolean use_profile_picture = false; Bitmap profile_picture = null; String origin_name = null; try { origin_name = getContactName(context, msgs[0].getDisplayOriginatingAddress()); if (origin_name == null) origin_name = msgs[0].getDisplayOriginatingAddress(); } catch (Exception e) { } if (origin_name == null) origin_name = "Unknown"; try { profile_picture = RoundedImageView.getCroppedBitmap(Bitmap.createScaledBitmap( fetchThumbnail(context, msgs[0].getDisplayOriginatingAddress()), 200, 200, false), 300); use_profile_picture = true; } catch (Exception e) { use_profile_picture = false; } Resources res = context.getResources(); int positionOfBase64End = str.lastIndexOf("="); if (positionOfBase64End > 0 && Base64.isBase64(str.substring(0, positionOfBase64End))) { mBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.raven_notification_icon) .setContentTitle(origin_name).setColor(0xFFB71C1C) .setContentText(res.getString(R.string.sms_receiver_new_encrypted)).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else if (str.toString().charAt(0) == '%' && (str.toString().length() == 10 || str.toString().length() == 9)) { int lastIndex = str.toString().lastIndexOf("="); if (lastIndex > 0 && Base64.isBase64(str.toString().substring(1, lastIndex))) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFB71C1C) .setContentText(res.getString(R.string.sms_receiver_handshake_received)) .setSmallIcon(R.drawable.raven_notification_icon).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } else if (str.toString().charAt(0) == '%' && str.toString().length() >= 120 && str.toString().length() < 125) { // DH Handshake int lastIndex = str.toString().lastIndexOf("="); if (lastIndex > 0 && Base64.isBase64(str.toString().substring(1, lastIndex))) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFB71C1C) .setContentText(res.getString(R.string.sms_receiver_handshake_received)) .setSmallIcon(R.drawable.raven_notification_icon).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } else { // unencrypted messages if (all) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFB71C1C).setContentText(str).setAutoCancel(true) .setStyle(new NotificationCompat.BigTextStyle().bigText(str)) .setSmallIcon(R.drawable.raven_notification_icon); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(alarmSound); mBuilder.setLights(led_color, 750, 4000); if (vibrate) { mBuilder.setVibrate(new long[] { 0, 100, 200, 300 }); } Intent resultIntent = new Intent(context, MainActivity.class); resultIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); resultIntent.putExtra("CONTACT_NUMBER", msgs[0].getOriginatingAddress()); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); if (Build.VERSION.SDK_INT >= 16 && headsup) mBuilder.setPriority(Notification.PRIORITY_HIGH); if (Build.VERSION.SDK_INT >= 21) mBuilder.setCategory(Notification.CATEGORY_MESSAGE); final NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED") && !MainActivity.isOnTop) mNotificationManager.notify(7, mBuilder.build()); // Save SMS if default app if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && Telephony.Sms.getDefaultSmsPackage(context).equals(context.getPackageName())) { ContentValues values = new ContentValues(); values.put("address", msgs[0].getDisplayOriginatingAddress()); values.put("body", str.replace("\n", "").replace("\r", "")); if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) context.getContentResolver().insert(Telephony.Sms.Inbox.CONTENT_URI, values); } } }
From source file:org.scratch.microwebserver.MicrowebserverService.java
private void createNotification(final String msg) { Context ctx = this.getApplicationContext(); Intent intent = new Intent(ctx, MicrowebserverActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); //Intent nIntent=new Intent(getBaseContext(),MicrowebserverActivity.class); //nIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); //notificationIntent=PendingIntent.getActivity(this,0,nIntent,PendingIntent.FLAG_UPDATE_CURRENT); notificationIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); notificationBuilder.setTicker("service started").setSmallIcon(R.drawable.ic_launcher).setOngoing(true) .setContentTitle("MicroWebServer").setContentText(msg).setContentIntent(notificationIntent); mNotificationManager.notify(APPICON_ID, notificationBuilder.getNotification()); }
From source file:apps.junkuvo.alertapptowalksafely.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Fabric.with(this, new Crashlytics()); ActionBar actionbar = getSupportActionBar(); if (actionbar != null) { actionbar.show();/*from ww w .j ava 2 s .co m*/ } // ????APK???????BG???onCreate??Activity?? // Intent?????????????? if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { finish(); return; } if (!isRunningJunit) { setContentView(R.layout.activity_main); FirebaseRemoteConfigUtil.initialize(); LikeView likeView = (LikeView) findViewById(R.id.like_view); likeView.setObjectIdAndType(String.format(getString(R.string.app_googlePlay_url), getPackageName()), LikeView.ObjectType.PAGE); // Create the interstitial. mInterstitialAd = new InterstitialAd(this); mInterstitialAd.setAdUnitId(getString(R.string.ad_mob_id)); // Create ad request. final AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // All emulators .addTestDevice("1BEC3806A9717F2A87F4D1FC2039D5F2") // An device ID ASUS .addTestDevice("64D37FCE47B679A7F4639D180EC4C547").build(); // Begin loading your interstitial. mInterstitialAd.loadAd(adRequest); mInterstitialAd.setAdListener(new AdListener() { @Override public void onAdLeftApplication() { super.onAdLeftApplication(); enableNewFunction = true; supportInvalidateOptionsMenu(); } @Override public void onAdClosed() { super.onAdClosed(); // ????????????? if (!enableNewFunction) { // Begin loading your interstitial. mInterstitialAd.loadAd(adRequest); } else { LayoutInflater inflater = LayoutInflater.from(MainActivity.this); final View layout = inflater.inflate(R.layout.new_function_dialog, (ViewGroup) findViewById(R.id.layout_root_new)); new MaterialStyledDialog(MainActivity.this).setTitle("?").setDescription( "????????\n???????????") .setCustomView(layout).setIcon(R.drawable.ic_fiber_new_white_48dp) .setHeaderDrawable(R.drawable.pattern_bg_blue) .setPositive(getString(R.string.ok), null).show(); RealmUtil.insertHistoryItemAsync(realm, createHistoryItemData(), new RealmUtil.realmTransactionCallbackListener() { @Override public void OnSuccess() { } @Override public void OnError() { } }); } } }); // FIXME : ?????? AdView mAdView = (AdView) findViewById(R.id.adView); // mAdView.loadAd(adRequest); DefaultLayoutPromptView promptView = (DefaultLayoutPromptView) findViewById(R.id.prompt_view); final BasePromptViewConfig basePromptViewConfig = new BasePromptViewConfig.Builder() .setUserOpinionQuestionTitle(getString(R.string.prompt_title)) .setUserOpinionQuestionPositiveButtonLabel(getString(R.string.prompt_btn_yes)) .setUserOpinionQuestionNegativeButtonLabel(getString(R.string.prompt_btn_no)) .setPositiveFeedbackQuestionTitle(getString(R.string.prompt_title_feedback)) .setPositiveFeedbackQuestionPositiveButtonLabel(getString(R.string.prompt_btn_sure)) .setPositiveFeedbackQuestionNegativeButtonLabel(getString(R.string.prompt_btn_notnow)) .setCriticalFeedbackQuestionTitle(getString(R.string.prompt_title_feedback_2)) .setCriticalFeedbackQuestionNegativeButtonLabel(getString(R.string.prompt_btn_notnow)) .setCriticalFeedbackQuestionPositiveButtonLabel(getString(R.string.prompt_btn_sure)) .setThanksTitle(getString(R.string.prompt_thanks)).build(); promptView.applyBaseConfig(basePromptViewConfig); Amplify.getSharedInstance().promptIfReady(promptView); mAnimationBlink = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink); int buttonColor = ContextCompat.getColor(this, R.color.colorPrimary); int buttonPressedColor = ContextCompat.getColor(this, R.color.colorPrimaryDark); mbtnStart = (ActionButton) findViewById(R.id.fabStart); mbtnStart.setButtonColor(buttonColor); mbtnStart.setButtonColorPressed(buttonPressedColor); // ? new MaterialIntroView.Builder(this).enableDotAnimation(false).enableIcon(true) .setFocusGravity(FocusGravity.CENTER).setFocusType(Focus.MINIMUM).setDelayMillis(500) .enableFadeAnimation(true).performClick(true).setInfoText(getString(R.string.intro_description)) .setTarget(mbtnStart).setUsageId(TUTORIAL_ID) //THIS SHOULD BE UNIQUE ID .dismissOnTouch(true).show(); mbtnStart.setOnClickListener(this); Intent mAlertServiceIntent = new Intent(MainActivity.this, AlertService.class); // ?????????????(???????) // ???????? if (!Utility.isTabletNotPhone(this)) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } mTwitter = TwitterUtility.getTwitterInstance(this); mCallbackURL = getString(R.string.twitter_callback_url); mPlusOneButton = (PlusOneButton) findViewById(R.id.plus_one_button); // Refresh the state of the +1 button each time the activity receives focus. mPlusOneButton.initialize( String.format(getString(R.string.app_googlePlay_url_plusOne), getPackageName()), PLUS_ONE_REQUEST_CODE); RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.rtlMain); relativeLayout.setOnClickListener(this); findViewById(R.id.llStepCount).setVisibility(mShouldShowPedometer ? View.VISIBLE : View.INVISIBLE); // // Service?????Activity?Destroy????Activity?????? // // UI?Service????????Service??????????Bind???????? // // Application???? // if (((AlertApplication) getApplication()).IsRunningService()) { // btnIsStarted = false; // setStartButtonFunction(findViewById(R.id.fabStart)); // } // // startService(mAlertServiceIntent); bindService(mAlertServiceIntent, mConnection, Context.BIND_AUTO_CREATE); } mIsToastOn = SharedPreferencesUtil.getBoolean(this, SETTING_SHAREDPREF_NAME, "message", true); mIsVibrationOn = SharedPreferencesUtil.getBoolean(this, SETTING_SHAREDPREF_NAME, "vibrate", true); mToastPosition = SharedPreferencesUtil.getInt(this, SETTING_SHAREDPREF_NAME, "toastPosition", Gravity.CENTER); mAlertStartAngle = SharedPreferencesUtil.getInt(this, SETTING_SHAREDPREF_NAME, "progress", ALERT_ANGLE_INITIAL_VALUE) + ALERT_ANGLE_INITIAL_OFFSET; mShouldShowPedometer = SharedPreferencesUtil.getBoolean(this, SETTING_SHAREDPREF_NAME, "pedometer", true); // ?????(update??) or ??? enableNewFunction = RealmUtil.hasHistoryItem(realm) || SharedPreferencesUtil.getBoolean(this, AD_STATUS_SHAREDPREF_NAME, "AD_STATUS_SHAREDPREF_NAME", false); }
From source file:cm.aptoide.pt.services.ServiceDownloadManager.java
private synchronized void setNotification() { managerNotification = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = new NotificationCompat.Builder(this); Intent onClick = new Intent(); onClick.setClassName(Constants.APTOIDE_PACKAGE_NAME, Constants.APTOIDE_PACKAGE_NAME + ".DownloadManager"); onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); onClick.setAction(Constants.APTOIDE_PACKAGE_NAME + ".FROM_NOTIFICATION"); // The PendingIntent to launch our activity if the user selects this notification PendingIntent onClickAction = PendingIntent.getActivity(this, 0, onClick, 0); mBuilder.setOngoing(true);/*from w w w. j a v a 2s. co m*/ mBuilder.setContentTitle(getString(R.string.aptoide_downloading, ApplicationAptoide.MARKETNAME)) .setContentText(getString(R.string.x_app, ongoingDownloads.size())) .setSmallIcon(android.R.drawable.stat_sys_download); mBuilder.setContentIntent(onClickAction); mBuilder.setProgress((int) globaDownloadStatus.getProgressTarget(), (int) globaDownloadStatus.getProgress(), (globaDownloadStatus.getProgress() == 0 ? true : false)); // Displays the progress bar for the first time managerNotification.notify(globaDownloadStatus.hashCode(), mBuilder.build()); // String notificationTitle = getString(R.string.aptoide_downloading, ApplicationAptoide.MARKETNAME); // int notificationIcon = android.R.drawable.stat_sys_download; // RemoteViews contentView = new RemoteViews(Constants.APTOIDE_PACKAGE_NAME, R.layout.row_notification_progress_bar); // // contentView.setImageViewResource(R.id.download_notification_icon, notificationIcon); // contentView.setTextViewText(R.id.download_notification_name, notificationTitle); // contentView.setProgressBar(R.id.download_notification_progress_bar, (int)globaDownloadStatus.getProgressTarget(), (int)globaDownloadStatus.getProgress(), (globaDownloadStatus.getProgress() == 0?true:false)); // if(ongoingDownloads.size()>1){ // contentView.setTextViewText(R.id.download_notification_number, getString(R.string.x_apps, ongoingDownloads.size())); // }else{ // contentView.setTextViewText(R.id.download_notification_number, getString(R.string.x_app, ongoingDownloads.size())); // } // // Intent onClick = new Intent(); // onClick.setClassName(Constants.APTOIDE_PACKAGE_NAME, Constants.APTOIDE_PACKAGE_NAME+".DownloadManager"); // onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); // onClick.setAction(Constants.APTOIDE_PACKAGE_NAME+".FROM_NOTIFICATION"); // // // The PendingIntent to launch our activity if the user selects this notification // PendingIntent onClickAction = PendingIntent.getActivity(this, 0, onClick, 0); // // Notification notification = new Notification(notificationIcon, notificationTitle, System.currentTimeMillis()); // notification.flags |= Notification.FLAG_NO_CLEAR|Notification.FLAG_ONGOING_EVENT; // notification.contentView = contentView; // // // // Set the info for the notification panel. // notification.contentIntent = onClickAction; //// notification.setLatestEventInfo(this, getText(R.string.aptoide), getText(R.string.add_repo_text), contentIntent); // // // managerNotification = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); // // Send the notification. // // We use the position because it is a unique number. We use it later to cancel. // managerNotification.notify(globaDownloadStatus.hashCode(), notification); // //// Log.d("Aptoide-ApplicationServiceManager", "Notification Set"); }
From source file:org.cowboycoders.cyclisimo.UserListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM); setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); setContentView(R.layout.generic_list_select); mHandler = new Handler(); this.providerUtils = MyTracksProviderUtils.Factory.getCyclimso(this); sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); listView = (ListView) findViewById(R.id.generic_list); this.setTitle( this.getString(R.string.my_tracks_app_name) + " : " + this.getString(R.string.user_list_title)); TextView userEmptyListText = (TextView) findViewById(R.id.generic_list_empty_view); userEmptyListText.setText(R.string.user_list_empty_message); this.cancelButton = (Button) this.findViewById(R.id.generic_list_left_button); cancelButton.setText(getString(R.string.cancel)); initCancelButton();/* ww w . j a v a 2s. c o m*/ Button addUserButton = (Button) this.findViewById(R.id.generic_list_right_button); addUserButton.setText(getString(R.string.user_create)); addUserButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = IntentUtils.newIntent(UserListActivity.this, UserEditActivity.class) .putExtra(UserEditActivity.EXTRA_NEW_USER, true); intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); // intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } }); listView.setEmptyView(userEmptyListText); resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.user_list_item, null, 0) { @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { View view = super.newView(context, cursor, parent); return view; } @Override public void bindView(View view, Context context, Cursor cursor) { final User user = providerUtils.createUser(cursor, false); TextView userName = (TextView) view.findViewById(R.id.list_item_name); userName.setText(user.getName()); userName.setEnabled(!isRecording()); userName.setVisibility(View.VISIBLE); view.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT; if (isRecording) { onUnableToPerformOperation(); } else { // new Thread() { // public void run() { // PreferencesUtils.setLong(UserListActivity.this, R.string.settings_select_user_current_selection_key, user.getId()); // } // // }.start(); // // Intent intent = IntentUtils.newIntent(UserListActivity.this, // TrackListActivity.class); // intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); // intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // startActivity(intent); // String unformated = getString(R.string.user_list_new_user_selected); // Toast.makeText(UserListActivity.this, String.format(unformated, user.getName()), Toast.LENGTH_SHORT).show(); // UserListActivity.this.finish(); getSyncSettingsTask().execute(user.getId()); } } }); registerForContextMenu(view); } }; listView.setAdapter(resourceCursorAdapter); ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView, contextualActionModeCallback, R.menu.user_list_context_menu); getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { return new CursorLoader(UserListActivity.this, UserInfoColumns.CONTENT_URI, PROJECTION, null, null, "LOWER(" + UserInfoColumns.NAME + ")"); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { resourceCursorAdapter.swapCursor(cursor); } @Override public void onLoaderReset(Loader<Cursor> loader) { resourceCursorAdapter.swapCursor(null); } }); updateCancelButton(); this.contextMenu = (ContextMenu) findViewById(R.menu.user_list_context_menu); }
From source file:org.cowboycoders.cyclisimo.BikeListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM); setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); setContentView(R.layout.generic_list_select); mHandler = new Handler(); this.providerUtils = MyTracksProviderUtils.Factory.getCyclimso(this); sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); listView = (ListView) findViewById(R.id.generic_list); this.setTitle( this.getString(R.string.my_tracks_app_name) + " : " + this.getString(R.string.bike_list_title)); TextView userEmptyListText = (TextView) findViewById(R.id.generic_list_empty_view); userEmptyListText.setText(R.string.bike_list_empty_message); this.cancelButton = (Button) this.findViewById(R.id.generic_list_left_button); cancelButton.setText(getString(R.string.cancel)); initCancelButton();/*from w w w . j a va 2 s .c o m*/ Button addUserButton = (Button) this.findViewById(R.id.generic_list_right_button); addUserButton.setText(getString(R.string.bike_create)); addUserButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //TODO: make bike edit Intent intent = IntentUtils.newIntent(BikeListActivity.this, BikeEditActivity.class) .putExtra(BikeEditActivity.EXTRA_NEW_BIKE, true); intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); // intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } }); listView.setEmptyView(userEmptyListText); resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.user_list_item, null, 0) { @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { View view = super.newView(context, cursor, parent); return view; } @Override public void bindView(View view, Context context, Cursor cursor) { final Bike bike = providerUtils.createBike(cursor, false); TextView userName = (TextView) view.findViewById(R.id.list_item_name); userName.setText(bike.getName()); userName.setEnabled(!isRecording()); userName.setVisibility(View.VISIBLE); view.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT; if (isRecording) { onUnableToPerformOperation(); } else { new Thread() { public void run() { // update user first as we count on this being updated on shared change updateUser(BikeListActivity.this, bike.getId()); PreferencesUtils.setLong(BikeListActivity.this, R.string.settings_select_bike_current_selection_key, bike.getId()); } }.start(); String unformated = getString(R.string.bike_list_new_user_selected); Toast.makeText(BikeListActivity.this, String.format(unformated, bike.getName()), Toast.LENGTH_SHORT).show(); BikeListActivity.this.doFinish(); } } }); registerForContextMenu(view); } }; listView.setAdapter(resourceCursorAdapter); ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView, contextualActionModeCallback, R.menu.user_list_context_menu); getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { long ownerId = PreferencesUtils.getLong(BikeListActivity.this, R.string.settings_select_user_current_selection_key); String selection = BikeInfoColumns.OWNER + "=? OR " + BikeInfoColumns.SHARED + "=?"; // one true, 0 false String[] args = new String[] { Long.toString(ownerId), Integer.toString(1) }; return new CursorLoader(BikeListActivity.this, BikeInfoColumns.CONTENT_URI, PROJECTION, selection, args, "LOWER(" + BikeInfoColumns.NAME + ")"); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { resourceCursorAdapter.swapCursor(cursor); } @Override public void onLoaderReset(Loader<Cursor> loader) { resourceCursorAdapter.swapCursor(null); } }); updateUI(); this.contextMenu = (ContextMenu) findViewById(R.menu.user_list_context_menu); }
From source file:com.android.tv.settings.accessories.AddAccessoryActivity.java
@Override public void onNewIntent(Intent intent) { if (ACTION_CONNECT_INPUT.equals(intent.getAction()) && (intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) == 0) { // We were the front most app and we got a new intent. // If screen saver is going, stop it. try {// w w w .j av a 2 s . c o m if (mDreamManager != null && mDreamManager.isDreaming()) { mDreamManager.awaken(); } } catch (RemoteException e) { // Do nothing. } KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_PAIRING) { if (event.getAction() == KeyEvent.ACTION_UP) { onHwKeyEvent(false); } else if (event.getAction() == KeyEvent.ACTION_DOWN) { onHwKeyEvent(true); } } } else { setIntent(intent); } }
From source file:org.cowboycoders.cyclisimo.TrackListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM); setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); setContentView(R.layout.track_list); sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback); trackController = new TrackController(this, trackRecordingServiceConnection, true, recordListener, stopListener);/*from ww w. j av a 2 s . c o m*/ listView = (ListView) findViewById(R.id.track_list); listView.setEmptyView(findViewById(R.id.track_list_empty_view)); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = IntentUtils.newIntent(TrackListActivity.this, TrackDetailActivity.class) .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, id); intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } }); resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) { @Override public void bindView(View view, Context context, Cursor cursor) { int idIndex = cursor.getColumnIndex(TracksColumns._ID); int iconIndex = cursor.getColumnIndex(TracksColumns.ICON); int nameIndex = cursor.getColumnIndex(TracksColumns.NAME); int categoryIndex = cursor.getColumnIndex(TracksColumns.CATEGORY); int totalTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALTIME); int totalDistanceIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALDISTANCE); int startTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.STARTTIME); int descriptionIndex = cursor.getColumnIndex(TracksColumns.DESCRIPTION); boolean isRecording = cursor.getLong(idIndex) == recordingTrackId; int iconId = TrackIconUtils.getIconDrawable(cursor.getString(iconIndex)); String name = cursor.getString(nameIndex); String totalTime = StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex)); String totalDistance = StringUtils.formatDistance(TrackListActivity.this, cursor.getDouble(totalDistanceIndex), metricUnits); long startTime = cursor.getLong(startTimeIndex); String startTimeDisplay = StringUtils.formatDateTime(context, startTime).equals(name) ? null : StringUtils.formatRelativeDateTime(context, startTime); ListItemUtils.setListItem(TrackListActivity.this, view, isRecording, recordingTrackPaused, iconId, R.string.icon_track, name, cursor.getString(categoryIndex), totalTime, totalDistance, startTimeDisplay, cursor.getString(descriptionIndex)); } }; listView.setAdapter(resourceCursorAdapter); ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView, contextualActionModeCallback); getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { updateCurrentUserId(); long userId = currentUserId.get(); String selection = TracksColumns.OWNER + "=?"; String[] args = new String[] { Long.toString(userId) }; return new CursorLoader(TrackListActivity.this, TracksColumns.CONTENT_URI, PROJECTION, selection, args, TracksColumns._ID + " DESC"); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { resourceCursorAdapter.swapCursor(cursor); } @Override public void onLoaderReset(Loader<Cursor> loader) { resourceCursorAdapter.swapCursor(null); } }); trackDataHub = TrackDataHub.newInstance(this); if (savedInstanceState != null) { startGps = savedInstanceState.getBoolean(START_GPS_KEY); } showStartupDialogs(); }