Example usage for android.os Bundle get

List of usage examples for android.os Bundle get

Introduction

In this page you can find the example usage for android.os Bundle get.

Prototype

@Nullable
public Object get(String key) 

Source Link

Document

Returns the entry with the given key as an object.

Usage

From source file:com.umaps.gpslogger.GpsLoggingService.java

private void HandleIntent(Intent intent) {

    GetPreferences();// w ww .ja v  a  2s  . c  o  m

    ActivityRecognitionResult arr = ActivityRecognitionResult.extractResult(intent);
    if (arr != null) {
        EventBus.getDefault().post(new ServiceEvents.ActivityRecognitionEvent(arr));
        return;
    }

    if (intent != null) {
        Bundle bundle = intent.getExtras();

        if (bundle != null) {
            boolean needToStartGpsManager = false;

            if (bundle.getBoolean(IntentConstants.IMMEDIATE_START)) {
                Log.i(TAG, "Intent received - Start Logging Now");
                EventBus.getDefault().postSticky(new CommandEvents.RequestStartStop(true));
            }

            if (bundle.getBoolean(IntentConstants.IMMEDIATE_STOP)) {
                Log.i(TAG, "Intent received - Stop logging now");
                EventBus.getDefault().postSticky(new CommandEvents.RequestStartStop(false));
            }

            if (bundle.getBoolean(IntentConstants.AUTOSEND_NOW)) {
                Log.i(TAG, "Intent received - Send Email Now");
                EventBus.getDefault().postSticky(new CommandEvents.AutoSend(null));
            }

            if (bundle.getBoolean(IntentConstants.GET_NEXT_POINT)) {
                Log.i(TAG, "Intent received - Get Next Point");
                needToStartGpsManager = true;
            }

            if (bundle.getString(IntentConstants.SET_DESCRIPTION) != null) {
                Log.i(TAG, "Intent received - Set Next Point Description: "
                        + bundle.getString(IntentConstants.SET_DESCRIPTION));
                EventBus.getDefault()
                        .post(new CommandEvents.Annotate(bundle.getString(IntentConstants.SET_DESCRIPTION)));
            }

            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

            if (bundle.get(IntentConstants.PREFER_CELLTOWER) != null) {
                boolean preferCellTower = bundle.getBoolean(IntentConstants.PREFER_CELLTOWER);
                Log.d(TAG, "Intent received - Set Prefer Cell Tower: " + String.valueOf(preferCellTower));

                List<String> listeners = Utilities.GetListeners();
                if (preferCellTower) {
                    listeners.remove(listeners.indexOf("gps"));
                } else {
                    listeners.remove(listeners.indexOf("network"));
                    listeners.remove(listeners.indexOf("passive"));
                }
                Set<String> listenersSet = new HashSet<String>(listeners);
                prefs.edit().putStringSet("listeners", listenersSet).apply();
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.TIME_BEFORE_LOGGING) != null) {
                int timeBeforeLogging = bundle.getInt(IntentConstants.TIME_BEFORE_LOGGING);
                Log.d(TAG, "Intent received - Set Time Before Logging: " + String.valueOf(timeBeforeLogging));
                prefs.edit().putString("time_before_logging", String.valueOf(timeBeforeLogging)).apply();
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.DISTANCE_BEFORE_LOGGING) != null) {
                int distanceBeforeLogging = bundle.getInt(IntentConstants.DISTANCE_BEFORE_LOGGING);
                Log.d(TAG, "Intent received - Set Distance Before Logging: "
                        + String.valueOf(distanceBeforeLogging));
                prefs.edit().putString("distance_before_logging", String.valueOf(distanceBeforeLogging))
                        .apply();
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.GPS_ON_BETWEEN_FIX) != null) {
                boolean keepBetweenFix = bundle.getBoolean(IntentConstants.GPS_ON_BETWEEN_FIX);
                Log.d(TAG, "Intent received - Set Keep Between Fix: " + String.valueOf(keepBetweenFix));
                prefs.edit().putBoolean("keep_fix", keepBetweenFix).apply();
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.RETRY_TIME) != null) {
                int retryTime = bundle.getInt(IntentConstants.RETRY_TIME);
                Log.d(TAG, "Intent received - Set Retry Time: " + String.valueOf(retryTime));
                prefs.edit().putString("retry_time", String.valueOf(retryTime)).apply();
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.ABSOLUTE_TIMEOUT) != null) {
                int absolumeTimeOut = bundle.getInt(IntentConstants.ABSOLUTE_TIMEOUT);
                Log.d(TAG, "Intent received - Set Retry Time: " + String.valueOf(absolumeTimeOut));
                prefs.edit().putString("absolute_timeout", String.valueOf(absolumeTimeOut)).apply();
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.LOG_ONCE) != null) {
                boolean logOnceIntent = bundle.getBoolean(IntentConstants.LOG_ONCE);
                Log.d(TAG, "Intent received - Log Once: " + String.valueOf(logOnceIntent));
                needToStartGpsManager = false;
                //LogOnce();
            }

            try {
                if (bundle.get(Intent.EXTRA_ALARM_COUNT) != "0") {
                    needToStartGpsManager = true;
                }
            } catch (Throwable t) {
                Log.w(TAG, "Received a weird EXTRA_ALARM_COUNT value. Cannot continue.");
                needToStartGpsManager = false;
            }

            if (needToStartGpsManager && Session.isStarted()) {
                StartGpsManager();
            }
        }
    } else {
        // A null intent is passed in if the service has been killed and restarted.
        Log.d(TAG, "Service restarted with null intent. Start logging.");
        StartLogging();
    }
}

From source file:ch.scythe.hsr.TimeTableActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    api = new TimeTableAPI(TimeTableActivity.this);

    setContentView(R.layout.timetable_main);

    fragmentPageAdapter = new MyAdapter(getSupportFragmentManager());
    accountManager = AccountManager.get(getApplicationContext());
    preferences = getPreferences(MODE_PRIVATE);

    dayPager = (ViewPager) findViewById(R.id.day_pager);
    dayPager.setAdapter(fragmentPageAdapter);

    final float density = getResources().getDisplayMetrics().density;

    TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titles);
    titleIndicator.setViewPager(dayPager);

    titleIndicator.setBackgroundColor(getResources().getColor(android.R.color.background_dark)); // 0x330065A3
    titleIndicator.setFooterColor(0xFF0065A3);
    titleIndicator.setFooterLineHeight(4 * density); // 1dp
    titleIndicator.setFooterIndicatorHeight(6 * density); // 3dp
    titleIndicator.setFooterIndicatorStyle(IndicatorStyle.Triangle);
    titleIndicator.setTextColor(getResources().getColor(android.R.color.primary_text_dark));
    titleIndicator.setTextColor(getResources().getColor(android.R.color.secondary_text_dark));

    datebox = (TextView) findViewById(R.id.date_value);
    weekbox = (TextView) findViewById(R.id.week_value);

    Date date = new Date();
    weekbox.setText(DateHelper.formatToWeekNumber(date));

    UiWeek lastInstance = (UiWeek) getLastCustomNonConfigurationInstance();
    if (lastInstance != null) {
        Log.i(LOGGING_TAG, "Creating Activity from lastInstance.");
        // there was a screen orientation change.
        // we can don't have to create the ui...
        week = lastInstance;//  w  w  w .ja v  a  2 s  .  c o  m
        datebox.setText(DateHelper.formatToUserFriendlyFormat(week.getLastUpdate()));
    } else if (savedInstanceState != null && savedInstanceState.containsKey(SAVED_INSTANCE_TIMETABLE_WEEK)) {
        Log.i(LOGGING_TAG, "Creating Activity from savedInstanceState.");
        // the state of the app was saved, so we can just update the ui
        week = (UiWeek) savedInstanceState.get(SAVED_INSTANCE_TIMETABLE_WEEK);
        datebox.setText(DateHelper.formatToUserFriendlyFormat(week.getLastUpdate()));
    } else {
        Log.i(LOGGING_TAG, "Creating Activity from scratch.");
        // no data available, read it!
        reloadCurrentTab();
        startRequest(date, false);
    }

}

From source file:eu.trentorise.smartcampus.trentinofamiglia.fragments.poi.PoisListingFragment.java

private List<POIObject> getPOIs(AbstractLstingFragment.ListingRequest... params) {
    try {/* w  ww .j  a va2 s  . com*/
        Collection<PoiObjectForBean> result = null;
        List<POIObject> returnArray = new ArrayList<POIObject>();
        Bundle bundle = getArguments();
        boolean my = false;
        if (bundle.getBoolean(SearchFragment.ARG_MY))
            my = true;
        String categories = bundle.getString(SearchFragment.ARG_CATEGORY);

        SortedMap<String, Integer> sort = new TreeMap<String, Integer>();
        sort.put("title", 1);

        if (bundle.containsKey(SearchFragment.ARG_CATEGORY)
                && (bundle.getString(SearchFragment.ARG_CATEGORY) != null)) {

            result = DTHelper.searchInGeneral(params[0].position, params[0].size,
                    bundle.getString(SearchFragment.ARG_QUERY),
                    (WhereForSearch) bundle.getParcelable(SearchFragment.ARG_WHERE_SEARCH),
                    (WhenForSearch) bundle.getParcelable(SearchFragment.ARG_WHEN_SEARCH), my,
                    PoiObjectForBean.class, sort, categories);

        } else if (bundle.containsKey(SearchFragment.ARG_MY) && (bundle.getBoolean(SearchFragment.ARG_MY))) {

            result = DTHelper.searchInGeneral(params[0].position, params[0].size,
                    bundle.getString(SearchFragment.ARG_QUERY),
                    (WhereForSearch) bundle.getParcelable(SearchFragment.ARG_WHERE_SEARCH),
                    (WhenForSearch) bundle.getParcelable(SearchFragment.ARG_WHEN_SEARCH), my,
                    PoiObjectForBean.class, sort, categories);

        } else if (bundle.containsKey(SearchFragment.ARG_QUERY)) {

            result = DTHelper.searchInGeneral(params[0].position, params[0].size,
                    bundle.getString(SearchFragment.ARG_QUERY),
                    (WhereForSearch) bundle.getParcelable(SearchFragment.ARG_WHERE_SEARCH),
                    (WhenForSearch) bundle.getParcelable(SearchFragment.ARG_WHEN_SEARCH), my,
                    PoiObjectForBean.class, sort, categories);

        } else if (bundle.containsKey(SearchFragment.ARG_LIST)) {
            return (List<POIObject>) bundle.get(SearchFragment.ARG_LIST);
        } else {
            return Collections.emptyList();
        }

        for (PoiObjectForBean storyBean : result) {
            returnArray.add(storyBean.getObjectForBean());
        }
        return returnArray;

    } catch (Exception e) {
        Log.e(PoisListingFragment.class.getName(), e.getMessage());
        e.printStackTrace();
        return Collections.emptyList();
    }
}

From source file:com.raddapp.radika.raddappv001.GpsLoggingService.java

private void HandleIntent(Intent intent) {
    Log.d("GPSLOGSERV 101", "HandleIntent");
    ActivityRecognitionResult arr = ActivityRecognitionResult.extractResult(intent);
    if (arr != null) {
        EventBus.getDefault().post(new ServiceEvents.ActivityRecognitionEvent(arr));
        return;//from  w w  w .  j  a va 2 s . co m
    }

    if (intent != null) {
        Bundle bundle = intent.getExtras();

        if (bundle != null) {
            boolean needToStartGpsManager = false;

            if (bundle.getBoolean(IntentConstants.IMMEDIATE_START)) {
                //tracer.info("Intent received - Start Logging Now");
                EventBus.getDefault().postSticky(new CommandEvents.RequestStartStop(true));
            }

            if (bundle.getBoolean(IntentConstants.IMMEDIATE_STOP)) {
                //tracer.info("Intent received - Stop logging now");
                EventBus.getDefault().postSticky(new CommandEvents.RequestStartStop(false));
            }

            if (bundle.getBoolean(IntentConstants.AUTOSEND_NOW)) {
                //tracer.info("Intent received - Send Email Now");
                EventBus.getDefault().postSticky(new CommandEvents.AutoSend(null));
            }

            if (bundle.getBoolean(IntentConstants.GET_NEXT_POINT)) {
                //tracer.info("Intent received - Get Next Point");
                needToStartGpsManager = true;
            }

            if (bundle.getString(IntentConstants.SET_DESCRIPTION) != null) {
                //tracer.info("Intent received - Set Next Point Description: " + bundle.getString(IntentConstants.SET_DESCRIPTION));
                EventBus.getDefault()
                        .post(new CommandEvents.Annotate(bundle.getString(IntentConstants.SET_DESCRIPTION)));
            }

            if (bundle.get(IntentConstants.PREFER_CELLTOWER) != null) {
                boolean preferCellTower = bundle.getBoolean(IntentConstants.PREFER_CELLTOWER);
                //tracer.debug("Intent received - Set Prefer Cell Tower: " + String.valueOf(preferCellTower));

                if (preferCellTower) {
                    // AppSettings.setChosenListeners(0);
                } else {
                    //AppSettings.setChosenListeners(1,2);
                }

                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.TIME_BEFORE_LOGGING) != null) {
                int timeBeforeLogging = bundle.getInt(IntentConstants.TIME_BEFORE_LOGGING);
                //tracer.debug("Intent received - Set Time Before Logging: " + String.valueOf(timeBeforeLogging));
                //AppSettings.setMinimumLoggingInterval(timeBeforeLogging);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.DISTANCE_BEFORE_LOGGING) != null) {
                int distanceBeforeLogging = bundle.getInt(IntentConstants.DISTANCE_BEFORE_LOGGING);
                //tracer.debug("Intent received - Set Distance Before Logging: " + String.valueOf(distanceBeforeLogging));
                //AppSettings.setMinimumDistanceInMeters(distanceBeforeLogging);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.GPS_ON_BETWEEN_FIX) != null) {
                boolean keepBetweenFix = bundle.getBoolean(IntentConstants.GPS_ON_BETWEEN_FIX);
                //tracer.debug("Intent received - Set Keep Between Fix: " + String.valueOf(keepBetweenFix));
                //AppSettings.setShouldKeepGPSOnBetweenFixes(keepBetweenFix);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.RETRY_TIME) != null) {
                int retryTime = bundle.getInt(IntentConstants.RETRY_TIME);
                //tracer.debug("Intent received - Set Retry Time: " + String.valueOf(retryTime));
                //AppSettings.setLoggingRetryPeriod(retryTime);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.ABSOLUTE_TIMEOUT) != null) {
                int absoluteTimeout = bundle.getInt(IntentConstants.ABSOLUTE_TIMEOUT);
                // tracer.debug("Intent received - Set Retry Time: " + String.valueOf(absoluteTimeout));
                //AppSettings.setAbsoluteTimeoutForAcquiringPosition(absoluteTimeout);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.LOG_ONCE) != null) {
                boolean logOnceIntent = bundle.getBoolean(IntentConstants.LOG_ONCE);
                //tracer.debug("Intent received - Log Once: " + String.valueOf(logOnceIntent));
                needToStartGpsManager = false;
                LogOnce();
            }

            try {
                if (bundle.get(Intent.EXTRA_ALARM_COUNT) != "0") {
                    needToStartGpsManager = true;
                }
            } catch (Throwable t) {
                //tracer.warn(SessionLogcatAppender.MARKER_INTERNAL, "Received a weird EXTRA_ALARM_COUNT value. Cannot continue.");
                needToStartGpsManager = false;
            }

            if (needToStartGpsManager && Session.isStarted()) { //
                StartGpsManager();
            }
        }
    } else {
        // A null intent is passed in if the service has been killed and restarted.
        //tracer.debug("Service restarted with null intent. Start logging.");
        StartLogging();
    }

    //StartLogging();
}

From source file:com.mjhram.geodata.GpsLoggingService.java

private void HandleIntent(Intent intent) {

    ActivityRecognitionResult arr = ActivityRecognitionResult.extractResult(intent);
    if (arr != null) {
        EventBus.getDefault().post(new ServiceEvents.ActivityRecognitionEvent(arr));
        return;/* w ww .ja va2  s  .  c o  m*/
    }

    if (intent != null) {
        Bundle bundle = intent.getExtras();

        if (bundle != null) {
            boolean needToStartGpsManager = false;

            //availabilityState = bundle.getInt("availabilityState");
            /*if (bundle.getBoolean(IntentConstants.IMMEDIATE_START)) {
            tracer.info("Intent received - Start Logging Now");
            EventBus.getDefault().postSticky(new CommandEvents.RequestStartStop(true));
            }
                    
            if (bundle.getBoolean(IntentConstants.IMMEDIATE_STOP)) {
            tracer.info("Intent received - Stop logging now");
            EventBus.getDefault().postSticky(new CommandEvents.RequestStartStop(false));
            }
                    
            if (bundle.getBoolean(IntentConstants.AUTOSEND_NOW)) {
            tracer.info("Intent received - Send Email Now");
            EventBus.getDefault().postSticky(new CommandEvents.AutoSend(null));
            }*/

            if (bundle.getBoolean(IntentConstants.GET_NEXT_POINT)) {
                tracer.info("Intent received - Get Next Point");
                needToStartGpsManager = true;
            }

            /*if (bundle.getString(IntentConstants.SET_DESCRIPTION) != null) {
            tracer.info("Intent received - Set Next Point Description: " + bundle.getString(IntentConstants.SET_DESCRIPTION));
            EventBus.getDefault().post(new CommandEvents.Annotate(bundle.getString(IntentConstants.SET_DESCRIPTION)));
            }*/

            if (bundle.get(IntentConstants.PREFER_CELLTOWER) != null) {
                boolean preferCellTower = bundle.getBoolean(IntentConstants.PREFER_CELLTOWER);
                tracer.debug("Intent received - Set Prefer Cell Tower: " + String.valueOf(preferCellTower));

                if (preferCellTower) {
                    AppSettings.setChosenListeners(0);
                } else {
                    AppSettings.setChosenListeners(1, 2);
                }

                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.TIME_BEFORE_LOGGING) != null) {
                int timeBeforeLogging = bundle.getInt(IntentConstants.TIME_BEFORE_LOGGING);
                tracer.debug("Intent received - Set Time Before Logging: " + String.valueOf(timeBeforeLogging));
                AppSettings.setMinimumLoggingInterval(timeBeforeLogging);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.DISTANCE_BEFORE_LOGGING) != null) {
                int distanceBeforeLogging = bundle.getInt(IntentConstants.DISTANCE_BEFORE_LOGGING);
                tracer.debug("Intent received - Set Distance Before Logging: "
                        + String.valueOf(distanceBeforeLogging));
                AppSettings.setMinimumDistanceInMeters(distanceBeforeLogging);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.GPS_ON_BETWEEN_FIX) != null) {
                boolean keepBetweenFix = bundle.getBoolean(IntentConstants.GPS_ON_BETWEEN_FIX);
                tracer.debug("Intent received - Set Keep Between Fix: " + String.valueOf(keepBetweenFix));
                AppSettings.setShouldKeepGPSOnBetweenFixes(keepBetweenFix);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.RETRY_TIME) != null) {
                int retryTime = bundle.getInt(IntentConstants.RETRY_TIME);
                tracer.debug("Intent received - Set Retry Time: " + String.valueOf(retryTime));
                AppSettings.setLoggingRetryPeriod(retryTime);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.ABSOLUTE_TIMEOUT) != null) {
                int absoluteTimeout = bundle.getInt(IntentConstants.ABSOLUTE_TIMEOUT);
                tracer.debug("Intent received - Set Retry Time: " + String.valueOf(absoluteTimeout));
                AppSettings.setAbsoluteTimeoutForAcquiringPosition(absoluteTimeout);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.LOG_ONCE) != null) {
                boolean logOnceIntent = bundle.getBoolean(IntentConstants.LOG_ONCE);
                tracer.debug("Intent received - Log Once: " + String.valueOf(logOnceIntent));
                needToStartGpsManager = false;
                LogOnce();
            }

            try {
                if (bundle.get(Intent.EXTRA_ALARM_COUNT) != "0") {
                    needToStartGpsManager = true;
                }
            } catch (Throwable t) {
                tracer.warn(SessionLogcatAppender.MARKER_INTERNAL,
                        "Received a weird EXTRA_ALARM_COUNT value. Cannot continue.");
                needToStartGpsManager = false;
            }

            if (needToStartGpsManager && Session.isStarted()) {
                StartGpsManager();
            }
        }
    } else {
        // A null intent is passed in if the service has been killed and restarted.
        tracer.debug("Service restarted with null intent. Start logging.");
        StartLogging();
    }
}

From source file:eu.trentorise.smartcampus.trentinofamiglia.fragments.info.InfoListingFragment.java

private List<InfoObject> getInfos(AbstractLstingFragment.ListingRequest... params) {
    try {//from   w ww. jav  a 2  s . co m
        Collection<InfoObjectForBean> result = null;
        List<InfoObject> returnArray = new ArrayList<InfoObject>();
        Bundle bundle = getArguments();
        boolean my = false;
        if (bundle.getBoolean(SearchFragment.ARG_MY))
            my = true;
        String categories = bundle.getString(SearchFragment.ARG_CATEGORY);
        String query = bundle.getString(SearchFragment.ARG_QUERY);

        SortedMap<String, Integer> sort = new TreeMap<String, Integer>();
        sort.put("title", 1);

        if (categories != null || my || query != null) {
            // workaround for 'politiche dei distretti'
            // where ordering should be performed based on the districts,
            // which are the elements of custom data
            if (categories != null && CategoryHelper.CAT_INFO_POLITICHE_DEI_DISTRETTI.equals(categories)) {
                result = DTHelper.searchInGeneral(0, -1, query,
                        (WhereForSearch) bundle.getParcelable(SearchFragment.ARG_WHERE_SEARCH),
                        (WhenForSearch) bundle.getParcelable(SearchFragment.ARG_WHEN_SEARCH), my,
                        InfoObjectForBean.class, sort, categories);
                List<InfoObjectForBean> list = new ArrayList<InfoObjectForBean>(result);
                Collections.sort(list, new Comparator<InfoObjectForBean>() {
                    @Override
                    public int compare(InfoObjectForBean lhs, InfoObjectForBean rhs) {
                        return lhs.getObjectForBean().getCustomData().get("district name").toString().compareTo(
                                rhs.getObjectForBean().getCustomData().get("district name").toString());
                    }
                });
                this.lastSize = list.size();
                this.position = list.size();
                result = list;
            } else {
                result = DTHelper.searchInGeneral(params[0].position, params[0].size, query,
                        (WhereForSearch) bundle.getParcelable(SearchFragment.ARG_WHERE_SEARCH),
                        (WhenForSearch) bundle.getParcelable(SearchFragment.ARG_WHEN_SEARCH), my,
                        InfoObjectForBean.class, sort, categories);
            }
        } else if (bundle.containsKey(SearchFragment.ARG_LIST)) {
            return (List<InfoObject>) bundle.get(SearchFragment.ARG_LIST);
        } else {
            return Collections.emptyList();
        }

        for (InfoObjectForBean trackBean : result) {
            returnArray.add(trackBean.getObjectForBean());
        }
        return returnArray;

    } catch (Exception e) {
        Log.e(InfoListingFragment.class.getName(), e.getMessage());
        e.printStackTrace();
        return Collections.emptyList();
    }
}

From source file:com.linute.linute.API.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param data GCM Bundle received./*w  ww.  ja  v  a2s . co m*/
 */
private void sendNotification(Bundle data, String action) {

    Intent intent = buildIntent(data, action);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent,
            PendingIntent.FLAG_ONE_SHOT);

    //Log.d(TAG, data.toString());

    String message = data.getString("message");

    //int type = gettNotificationType(data.getString("action"));
    //String name = data.getString("ownerFullName");
    boolean isAnon = "1".equals(data.getString("privacy"));
    String profileImage = null;
    switch (action) {
    case "messager":
        try {
            JSONObject image = new JSONObject(data.getString("roomProfileImage"));
            profileImage = image.getString("original");
        } catch (JSONException | NullPointerException e) {
        }
        break;
    default:
        profileImage = data.getString("ownerProfileImage");
        profileImage = (isAnon ? Utils.getAnonImageUrl(String.valueOf(profileImage))
                : Utils.getImageUrlOfUser(String.valueOf(profileImage)));
    }

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    ChatRoom chatRoom = (ChatRoom) intent.getParcelableExtra("chatRoom");
    String title = chatRoom != null ? chatRoom.getRoomName() : "Tapt";
    final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_untitled_4_01).setColor(Color.BLACK).setContentTitle(title)
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent).setStyle(new NotificationCompat.BigTextStyle().bigText(message));
    if (profileImage != null) {
        File image = null;
        try {
            image = Glide.with(this).load(profileImage).downloadOnly(256, 256).get();
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
        if (image != null) {
            /*ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
            ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo();
            manager.getMemoryInfo(info);*/

            notificationBuilder.setLargeIcon(getCircleBitmap(image));

        }
    }

    BigInteger notificationId;

    Object ownerId = data.get("room");
    Object eventId = data.get("event");
    if (eventId != null) {
        notificationId = new BigInteger(String.valueOf(eventId), 16);
    } else if (ownerId != null) {
        notificationId = new BigInteger(String.valueOf(ownerId), 16);
    } else {
        notificationId = BigInteger.ZERO;
    }

    final int notifId = notificationId.intValue();
    Notification notifications = notificationBuilder.build();
    NotificationManagerCompat.from(this).notify(notificationId.intValue(), notifications);
}

From source file:com.crearo.gpslogger.GpsLoggingService.java

private void handleIntent(Intent intent) {

    ActivityRecognitionResult arr = ActivityRecognitionResult.extractResult(intent);
    if (arr != null) {
        EventBus.getDefault().post(new ServiceEvents.ActivityRecognitionEvent(arr));
        return;// w  ww.j a v  a 2  s  . com
    }

    if (intent != null) {
        Bundle bundle = intent.getExtras();

        if (bundle != null) {
            boolean needToStartGpsManager = false;

            if (bundle.getBoolean(IntentConstants.IMMEDIATE_START)) {
                LOG.info("Intent received - Start Logging Now");
                EventBus.getDefault().postSticky(new CommandEvents.RequestStartStop(true));
            }

            if (bundle.getBoolean(IntentConstants.IMMEDIATE_STOP)) {
                LOG.info("Intent received - Stop logging now");
                EventBus.getDefault().postSticky(new CommandEvents.RequestStartStop(false));
            }

            if (bundle.getBoolean(IntentConstants.AUTOSEND_NOW)) {
                LOG.info("Intent received - Send Email Now");
                EventBus.getDefault().postSticky(new CommandEvents.AutoSend(null));
            }

            if (bundle.getBoolean(IntentConstants.GET_NEXT_POINT)) {
                LOG.info("Intent received - Get Next Point");
                needToStartGpsManager = true;
            }

            if (bundle.getString(IntentConstants.SET_DESCRIPTION) != null) {
                LOG.info("Intent received - Set Next Point Description: "
                        + bundle.getString(IntentConstants.SET_DESCRIPTION));
                EventBus.getDefault()
                        .post(new CommandEvents.Annotate(bundle.getString(IntentConstants.SET_DESCRIPTION)));
            }

            if (bundle.getString(IntentConstants.SWITCH_PROFILE) != null) {
                LOG.info("Intent received - switch profile: "
                        + bundle.getString(IntentConstants.SWITCH_PROFILE));
                EventBus.getDefault().post(
                        new ProfileEvents.SwitchToProfile(bundle.getString(IntentConstants.SWITCH_PROFILE)));
            }

            if (bundle.get(IntentConstants.PREFER_CELLTOWER) != null) {
                boolean preferCellTower = bundle.getBoolean(IntentConstants.PREFER_CELLTOWER);
                LOG.debug("Intent received - Set Prefer Cell Tower: " + String.valueOf(preferCellTower));

                if (preferCellTower) {
                    preferenceHelper.setChosenListeners(0);
                } else {
                    preferenceHelper.setChosenListeners(1, 2);
                }

                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.TIME_BEFORE_LOGGING) != null) {
                int timeBeforeLogging = bundle.getInt(IntentConstants.TIME_BEFORE_LOGGING);
                LOG.debug("Intent received - Set Time Before Logging: " + String.valueOf(timeBeforeLogging));
                preferenceHelper.setMinimumLoggingInterval(timeBeforeLogging);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.DISTANCE_BEFORE_LOGGING) != null) {
                int distanceBeforeLogging = bundle.getInt(IntentConstants.DISTANCE_BEFORE_LOGGING);
                LOG.debug("Intent received - Set Distance Before Logging: "
                        + String.valueOf(distanceBeforeLogging));
                preferenceHelper.setMinimumDistanceInMeters(distanceBeforeLogging);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.GPS_ON_BETWEEN_FIX) != null) {
                boolean keepBetweenFix = bundle.getBoolean(IntentConstants.GPS_ON_BETWEEN_FIX);
                LOG.debug("Intent received - Set Keep Between Fix: " + String.valueOf(keepBetweenFix));
                preferenceHelper.setShouldKeepGPSOnBetweenFixes(keepBetweenFix);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.RETRY_TIME) != null) {
                int retryTime = bundle.getInt(IntentConstants.RETRY_TIME);
                LOG.debug("Intent received - Set Retry Time: " + String.valueOf(retryTime));
                preferenceHelper.setLoggingRetryPeriod(retryTime);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.ABSOLUTE_TIMEOUT) != null) {
                int absoluteTimeout = bundle.getInt(IntentConstants.ABSOLUTE_TIMEOUT);
                LOG.debug("Intent received - Set Retry Time: " + String.valueOf(absoluteTimeout));
                preferenceHelper.setAbsoluteTimeoutForAcquiringPosition(absoluteTimeout);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.LOG_ONCE) != null) {
                boolean logOnceIntent = bundle.getBoolean(IntentConstants.LOG_ONCE);
                LOG.debug("Intent received - Log Once: " + String.valueOf(logOnceIntent));
                needToStartGpsManager = false;
                logOnce();
            }

            try {
                if (bundle.get(Intent.EXTRA_ALARM_COUNT) != "0") {
                    needToStartGpsManager = true;
                }
            } catch (Throwable t) {
                LOG.warn(SessionLogcatAppender.MARKER_INTERNAL,
                        "Received a weird EXTRA_ALARM_COUNT value. Cannot continue.");
                needToStartGpsManager = false;
            }

            if (needToStartGpsManager && Session.isStarted()) {
                startGpsManager();
            }
        }
    } else {
        // A null intent is passed in if the service has been killed and restarted.
        LOG.debug("Service restarted with null intent. Start logging.");
        startLogging();
    }
}

From source file:com.mendhak.gpslogger.GpsLoggingService.java

private void handleIntent(Intent intent) {

    ActivityRecognitionResult arr = ActivityRecognitionResult.extractResult(intent);
    if (arr != null) {
        EventBus.getDefault().post(new ServiceEvents.ActivityRecognitionEvent(arr));
        return;/*from  ww w.j  a  va 2  s . c  om*/
    }

    if (intent != null) {
        Bundle bundle = intent.getExtras();

        if (bundle != null) {
            boolean needToStartGpsManager = false;

            if (bundle.getBoolean(IntentConstants.IMMEDIATE_START)) {
                LOG.info("Intent received - Start Logging Now");
                EventBus.getDefault().postSticky(new CommandEvents.RequestStartStop(true));
            }

            if (bundle.getBoolean(IntentConstants.IMMEDIATE_STOP)) {
                LOG.info("Intent received - Stop logging now");
                EventBus.getDefault().postSticky(new CommandEvents.RequestStartStop(false));
            }

            if (bundle.getBoolean(IntentConstants.AUTOSEND_NOW)) {
                LOG.info("Intent received - Send Email Now");
                EventBus.getDefault().postSticky(new CommandEvents.AutoSend(null));
            }

            if (bundle.getBoolean(IntentConstants.GET_NEXT_POINT)) {
                LOG.info("Intent received - Get Next Point");
                needToStartGpsManager = true;
            }

            if (bundle.getString(IntentConstants.SET_DESCRIPTION) != null) {
                LOG.info("Intent received - Set Next Point Description: "
                        + bundle.getString(IntentConstants.SET_DESCRIPTION));
                EventBus.getDefault()
                        .post(new CommandEvents.Annotate(bundle.getString(IntentConstants.SET_DESCRIPTION)));
            }

            if (bundle.getString(IntentConstants.SWITCH_PROFILE) != null) {
                LOG.info("Intent received - switch profile: "
                        + bundle.getString(IntentConstants.SWITCH_PROFILE));
                EventBus.getDefault().post(
                        new ProfileEvents.SwitchToProfile(bundle.getString(IntentConstants.SWITCH_PROFILE)));
            }

            if (bundle.get(IntentConstants.PREFER_CELLTOWER) != null) {
                boolean preferCellTower = bundle.getBoolean(IntentConstants.PREFER_CELLTOWER);
                LOG.debug("Intent received - Set Prefer Cell Tower: " + String.valueOf(preferCellTower));

                if (preferCellTower) {
                    preferenceHelper.setChosenListeners(0);
                } else {
                    preferenceHelper.setChosenListeners(1, 2);
                }

                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.TIME_BEFORE_LOGGING) != null) {
                int timeBeforeLogging = bundle.getInt(IntentConstants.TIME_BEFORE_LOGGING);
                LOG.debug("Intent received - Set Time Before Logging: " + String.valueOf(timeBeforeLogging));
                preferenceHelper.setMinimumLoggingInterval(timeBeforeLogging);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.DISTANCE_BEFORE_LOGGING) != null) {
                int distanceBeforeLogging = bundle.getInt(IntentConstants.DISTANCE_BEFORE_LOGGING);
                LOG.debug("Intent received - Set Distance Before Logging: "
                        + String.valueOf(distanceBeforeLogging));
                preferenceHelper.setMinimumDistanceInMeters(distanceBeforeLogging);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.GPS_ON_BETWEEN_FIX) != null) {
                boolean keepBetweenFix = bundle.getBoolean(IntentConstants.GPS_ON_BETWEEN_FIX);
                LOG.debug("Intent received - Set Keep Between Fix: " + String.valueOf(keepBetweenFix));
                preferenceHelper.setShouldKeepGPSOnBetweenFixes(keepBetweenFix);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.RETRY_TIME) != null) {
                int retryTime = bundle.getInt(IntentConstants.RETRY_TIME);
                LOG.debug("Intent received - Set Retry Time: " + String.valueOf(retryTime));
                preferenceHelper.setLoggingRetryPeriod(retryTime);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.ABSOLUTE_TIMEOUT) != null) {
                int absoluteTimeout = bundle.getInt(IntentConstants.ABSOLUTE_TIMEOUT);
                LOG.debug("Intent received - Set Retry Time: " + String.valueOf(absoluteTimeout));
                preferenceHelper.setAbsoluteTimeoutForAcquiringPosition(absoluteTimeout);
                needToStartGpsManager = true;
            }

            if (bundle.get(IntentConstants.LOG_ONCE) != null) {
                boolean logOnceIntent = bundle.getBoolean(IntentConstants.LOG_ONCE);
                LOG.debug("Intent received - Log Once: " + String.valueOf(logOnceIntent));
                needToStartGpsManager = false;
                logOnce();
            }

            try {
                if (bundle.get(Intent.EXTRA_ALARM_COUNT) != "0") {
                    needToStartGpsManager = true;
                }
            } catch (Throwable t) {
                LOG.warn(SessionLogcatAppender.MARKER_INTERNAL,
                        "Received a weird EXTRA_ALARM_COUNT value. Cannot continue.");
                needToStartGpsManager = false;
            }

            if (needToStartGpsManager && Session.isStarted()) {
                startGpsManager();
            }
        }
    } else {
        // A null intent is passed in if the service has been killed and restarted.
        LOG.debug("Service restarted with null intent. Were we logging previously - " + Session.isStarted());
        if (Session.isStarted()) {
            startLogging();
        }

    }
}

From source file:eu.iescities.pilot.rovereto.roveretoexplorer.fragments.event.EventsListingFragment.java

private List<ExplorerObject> getEvents(AbstractLstingFragment.ListingRequest... params) {
    try {/*from  w ww. j  av  a  2s. com*/
        Collection<ExplorerObject> result = null;

        Bundle bundle = getArguments();
        boolean my = false;

        if (bundle == null) {
            return Collections.emptyList();
        }
        if (bundle.getBoolean(SearchFragment.ARG_MY))
            my = true;
        String categories = bundle.getString(SearchFragment.ARG_CATEGORY);
        SortedMap<String, Integer> sort = new TreeMap<String, Integer>();
        sort.put("fromTime", 1);
        whenForSearch = bundle.getParcelable(SearchFragment.ARG_WHEN_SEARCH);
        if (bundle.containsKey(SearchFragment.ARG_CATEGORY)
                && (bundle.getString(SearchFragment.ARG_CATEGORY) != null)) {

            result = DTHelper.searchInGeneral(0, -1, bundle.getString(SearchFragment.ARG_QUERY),
                    (WhereForSearch) bundle.getParcelable(SearchFragment.ARG_WHERE_SEARCH),
                    (WhenForSearch) bundle.getParcelable(SearchFragment.ARG_WHEN_SEARCH), my,
                    ExplorerObject.class, sort, categories);

        } else if (bundle.containsKey(ARG_POI) && (bundle.getString(ARG_POI) != null)) {
            result = DTHelper.getEventsByPOI(0, -1, bundle.getString(ARG_POI));
        } else if (bundle.containsKey(SearchFragment.ARG_MY) && (bundle.getBoolean(SearchFragment.ARG_MY))) {

            result = DTHelper.searchInGeneral(0, -1, bundle.getString(SearchFragment.ARG_QUERY),
                    (WhereForSearch) bundle.getParcelable(SearchFragment.ARG_WHERE_SEARCH),
                    (WhenForSearch) bundle.getParcelable(SearchFragment.ARG_WHEN_SEARCH), my,
                    ExplorerObject.class, sort, categories);

        } else if (bundle.containsKey(SearchFragment.ARG_QUERY)) {

            result = DTHelper.searchInGeneral(0, -1, bundle.getString(SearchFragment.ARG_QUERY),
                    (WhereForSearch) bundle.getParcelable(SearchFragment.ARG_WHERE_SEARCH),
                    (WhenForSearch) bundle.getParcelable(SearchFragment.ARG_WHEN_SEARCH), my,
                    ExplorerObject.class, sort, categories);
        } else if (bundle.containsKey(ARG_QUERY_TODAY)) {
            today = true;
            result = DTHelper.searchTodayEvents(0, -1, bundle.getString(SearchFragment.ARG_QUERY));
        } else if (bundle.containsKey(SearchFragment.ARG_LIST)) {
            result = (Collection<ExplorerObject>) bundle.get(SearchFragment.ARG_LIST);
        } else {
            return Collections.emptyList();
        }

        listEvents.addAll(result);

        List<ExplorerObject> sorted = new ArrayList<ExplorerObject>(listEvents);

        return sorted;
    } catch (Exception e) {
        Log.e(EventsListingFragment.class.getName(), e.getMessage());
        e.printStackTrace();
        listEvents = Collections.emptyList();
        return listEvents;
    }
}