android.support.v4.util.ArraySet Java Examples

The following examples show how to use android.support.v4.util.ArraySet. 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: Database.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public Set<File> getListFile() {
    ArraySet<File> files = new android.support.v4.util.ArraySet<>();
    try {
        SQLiteDatabase sqLiteDatabase = this.getReadableDatabase();
        String query = "SELECT * FROM " + TABLE_FILE_TAB;
        Cursor cursor = sqLiteDatabase.rawQuery(query, null);
        if (cursor.moveToFirst()) {
            do {
                String result = cursor.getString(cursor.getColumnIndex(KEY_FILE_PATH));
                File file = new File(result);
                if (file.isFile())
                    files.add(file);
                else
                    removeFile(result);
            } while (cursor.moveToNext());
        }
        cursor.close();
    } catch (Exception ignored) {

    }
    return files;
}
 
Example #2
Source File: NotificationsService.java    From ForPDA with GNU General Public License v3.0 6 votes vote down vote up
private List<NotificationEvent> getSavedEvents(NotificationEvent.Source source) {
    String prefKey = "";
    if (NotificationEvent.fromQms(source)) {
        prefKey = Preferences.Notifications.Data.QMS_EVENTS;
    } else if (NotificationEvent.fromTheme(source)) {
        prefKey = Preferences.Notifications.Data.FAVORITES_EVENTS;
    }

    Set<String> savedEvents = App.get().getPreferences().getStringSet(prefKey, new ArraySet<>());
    StringBuilder responseBuilder = new StringBuilder();
    for (String saved : savedEvents) {
        responseBuilder.append(saved).append('\n');
    }
    String response = responseBuilder.toString();

    if (NotificationEvent.fromQms(source)) {
        return Api.UniversalEvents().getQmsEvents(response);
    } else if (NotificationEvent.fromTheme(source)) {
        return Api.UniversalEvents().getFavoritesEvents(response);
    }
    return new ArrayList<>();
}
 
Example #3
Source File: GeoReportHelper.java    From mobile-messaging-sdk-android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns list of inactive campaign ids based on reporting result
 *
 * @param result response from the server
 * @return set of inactive campaign ids
 */
public static Set<String> getAndUpdateInactiveCampaigns(Context context, GeoReportingResult result) {
    Set<String> inactiveCampaigns = new ArraySet<>();
    if (result == null || result.hasError()) {
        inactiveCampaigns.addAll(GeofencingHelper.getSuspendedCampaignIds(context));
        inactiveCampaigns.addAll(GeofencingHelper.getFinishedCampaignIds(context));
        return inactiveCampaigns;
    }

    GeofencingHelper.addCampaignStatus(context, result.getFinishedCampaignIds(), result.getSuspendedCampaignIds());
    if (result.getFinishedCampaignIds() != null) {
        inactiveCampaigns.addAll(result.getFinishedCampaignIds());
    }
    if (result.getSuspendedCampaignIds() != null) {
        inactiveCampaigns.addAll(result.getSuspendedCampaignIds());
    }
    return inactiveCampaigns;
}
 
Example #4
Source File: TaskSortUtil.java    From android-performance with MIT License 5 votes vote down vote up
/**
 * 任务的有向无环图的拓扑排序
 *
 * @return
 */
public static synchronized List<Task> getSortResult(List<Task> originTasks,
                                                    List<Class<? extends Task>> clsLaunchTasks) {
    long makeTime = System.currentTimeMillis();

    Set<Integer> dependSet = new ArraySet<>();
    Graph graph = new Graph(originTasks.size());
    for (int i = 0; i < originTasks.size(); i++) {
        Task task = originTasks.get(i);
        if (task.isSend() || task.dependsOn() == null || task.dependsOn().size() == 0) {
            continue;
        }
        for (Class cls : task.dependsOn()) {
            int indexOfDepend = getIndexOfTask(originTasks, clsLaunchTasks, cls);
            if (indexOfDepend < 0) {
                throw new IllegalStateException(task.getClass().getSimpleName() +
                        " depends on " + cls.getSimpleName() + " can not be found in task list ");
            }
            dependSet.add(indexOfDepend);
            graph.addEdge(indexOfDepend, i);
        }
    }
    List<Integer> indexList = graph.topologicalSort();
    List<Task> newTasksAll = getResultTasks(originTasks, dependSet, indexList);

    DispatcherLog.i("task analyse cost makeTime " + (System.currentTimeMillis() - makeTime));
    printAllTaskName(newTasksAll);
    return newTasksAll;
}
 
Example #5
Source File: NotificationChannelManagerHelper.java    From notification-channel-compat with Apache License 2.0 5 votes vote down vote up
public NotificationChannelManagerHelper(Context context, NotificationManager manager) {
    _manager = manager;
    _prefs = context.getSharedPreferences(SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
    _channelIds = _prefs.getStringSet(PREF_KEY_CHANNELS_IDS, null);
    _groupIds = _prefs.getStringSet(PREF_KEY_GROUPS_IDS, null);
    if (_channelIds == null)
        _channelIds = new ArraySet<>();
    if (_groupIds == null)
        _groupIds = new ArraySet<>();
}
 
Example #6
Source File: PluginManager.java    From Phantom with Apache License 2.0 5 votes vote down vote up
private void initHostCompileDependencies() {
    final AssetManager assetManager = mContext.getAssets();
    InputStream inputStream = null;
    try {
        inputStream = assetManager.open(COMPILE_DEPENDENCIES_FILE, AssetManager.ACCESS_BUFFER);
        final List<String> lines = IoUtils.readLines(inputStream, IoUtils.DEFAULT_CHARSET);

        ArrayMap<String, String> librariesMap = new ArrayMap<>();  // lib -> version
        for (String line : lines) {
            final String[] parts = line.split(":");
            if (parts.length == 3) {
                final String lib = parts[0] + ":" + parts[1];   // groupId:artifactId
                final String newVersion = parts[2];
                final String oldVersion = librariesMap.get(lib);
                if (oldVersion != null && new Version(newVersion).lessThan(new Version(oldVersion))) {
                    // skip lower version
                    continue;
                }

                librariesMap.put(lib, newVersion);
            }
        }
        mHostCompileDependencyMap = librariesMap;

        ArraySet<String> librariesSet = new ArraySet<>();
        for (Map.Entry entry : librariesMap.entrySet()) {
            librariesSet.add(entry.getKey() + ":" + entry.getValue());
        }
        mHostCompileDependencySet = librariesSet;

    } catch (IOException e) {
        VLog.w(e, "error initHostCompileDependencies");
        mHostCompileDependencyMap = Collections.emptyMap();
        mHostCompileDependencySet = Collections.emptySet();
    } finally {
        IoUtils.closeQuietly(inputStream);
    }
}
 
Example #7
Source File: NotificationsService.java    From ForPDA with GNU General Public License v3.0 5 votes vote down vote up
private void saveEvents(List<NotificationEvent> loadedEvents, NotificationEvent.Source source) {
    String prefKey = "";
    if (NotificationEvent.fromQms(source)) {
        prefKey = Preferences.Notifications.Data.QMS_EVENTS;
    } else if (NotificationEvent.fromTheme(source)) {
        prefKey = Preferences.Notifications.Data.FAVORITES_EVENTS;
    }

    Set<String> savedEvents = new ArraySet<>();
    for (NotificationEvent event : loadedEvents) {
        savedEvents.add(event.getSourceEventText());
    }
    App.get().getPreferences().edit().putStringSet(prefKey, savedEvents).apply();
}
 
Example #8
Source File: GeoTransitionHelper.java    From mobile-messaging-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * Resolves transition information from geofencing intent
 *
 * @param intent geofencing intent
 * @return transition information
 * @throws RuntimeException if information cannot be resolved
 */
static GeoTransition resolveTransitionFromIntent(Intent intent) throws RuntimeException {
    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
    if (geofencingEvent == null) {
        throw new RuntimeException("Geofencing event is null, cannot process");
    }

    if (geofencingEvent.hasError()) {
        if (geofencingEvent.getErrorCode() == GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE) {
            throw new GeofenceNotAvailableException();
        }
        throw new RuntimeException("ERROR: " + GeofenceStatusCodes.getStatusCodeString(geofencingEvent.getErrorCode()));
    }

    GeoEventType event = supportedTransitionEvents.get(geofencingEvent.getGeofenceTransition());
    if (event == null) {
        throw new RuntimeException("Transition is not supported: " + geofencingEvent.getGeofenceTransition());
    }

    Set<String> triggeringRequestIds = new ArraySet<>();
    for (Geofence geofence : geofencingEvent.getTriggeringGeofences()) {
        triggeringRequestIds.add(geofence.getRequestId());
    }

    Location location = geofencingEvent.getTriggeringLocation();
    return new GeoTransition(event, triggeringRequestIds, new GeoLatLng(location.getLatitude(), location.getLongitude()));
}
 
Example #9
Source File: GeofencingHelper.java    From mobile-messaging-sdk-android with Apache License 2.0 5 votes vote down vote up
public static void addCampaignStatus(final Context context, final Set<String> finishedCampaignIds, final Set<String> suspendedCampaignIds) {
    PreferenceHelper.runTransaction(new PreferenceHelper.Transaction<Void>() {
        @Override
        public Void run() {
            PreferenceHelper.saveStringSet(context, MobileMessagingGeoProperty.FINISHED_CAMPAIGN_IDS.getKey(),
                    finishedCampaignIds != null ? finishedCampaignIds : new ArraySet<String>());
            PreferenceHelper.saveStringSet(context, MobileMessagingGeoProperty.SUSPENDED_CAMPAIGN_IDS.getKey(),
                    suspendedCampaignIds != null ? suspendedCampaignIds : new ArraySet<String>());
            return null;
        }
    });
}
 
Example #10
Source File: GeoReportHelper.java    From mobile-messaging-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * Generates set of geofencing reports
 *
 * @param context          context
 * @param signalingMessage original signaling message
 * @param areas            list of areas that triggered this geofencing event
 * @param event            transition type
 * @return set of geofencing reports to send to server
 */
private static Set<GeoReport> createReports(Context context, Message signalingMessage, List<Area> areas, @NonNull GeoEventType event, @NonNull GeoLatLng triggeringLocation) {
    Set<GeoReport> reports = new ArraySet<>();
    for (Area area : areas) {
        GeoReport report = createReport(signalingMessage, area, event, triggeringLocation);
        reports.add(report);
        MobileMessagingCore.getInstance(context).addGeneratedMessageIds(report.getMessageId());
    }
    return reports;
}
 
Example #11
Source File: EmailConfigGenTool.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
public static String genConfig(Context context) {
    SharedPreferences currentMusicPrefs = context.getSharedPreferences("current_music", Context.MODE_PRIVATE);
    return String.format(Locale.US, "Package version: %s %d\r\n" +
                    "Device model: %s %s\r\n" +
                    "API version: %s\r\n" +
                    "Locale: %s\r\n" +
                    "Premium: %s\r\n" +
                    (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ? "Notification Listener: %s %s %s \r\n" : "%s%s%s\r\n") +
                    (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT ? "Players used: %s\r\n" : "%s\r\n") +
                    (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? "Storage permission granted: %s\r\n" : "%s\r\n") +
                    "Latest Track: %s - %s\r\n" +
                    "Latest Result: %s\r\n" +
                    "\r\n\r\n%s\r\n\r\n" +
                    "---------------------\r\n\r\nInsert your message here:\r\n",
            BuildConfig.VERSION_NAME,
            BuildConfig.VERSION_CODE,
            Build.MANUFACTURER,
            Build.MODEL,
            Build.VERSION.SDK_INT,
            Locale.getDefault().getDisplayLanguage(),
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ?
                    NotificationListenerService.isListeningAuthorized(context) ? "Authorized" : "Not Authorized" : "",
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ?
                    NotificationListenerService.isNotificationListenerServiceEnabled(context) ? "Enabled" : "Disabled" : "",
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ?
                    NotificationListenerService.isAppScrobbling(context) ? "Running" : "Not Running" : "",
            Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT ?
                    Arrays.toString(context.getSharedPreferences("NotificationListenerService", Context.MODE_PRIVATE)
                            .getStringSet("players_used", new ArraySet<>()).toArray()) : "",
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? ContextCompat.checkSelfPermission(context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) : "",
            currentMusicPrefs.getString("artist", null),
            currentMusicPrefs.getString("track", null),
            DownloadThread.getStoredResult(context),
            PreferenceManager.getDefaultSharedPreferences(context).getAll()
    );
}
 
Example #12
Source File: DialogNewClass.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
private void createNewClass() {
    String className = mEditName.getText().toString();
    if (className.isEmpty()) {
        mEditName.setError(getString(R.string.enter_name));
        return;
    }
    if (!className.matches(PatternFactory.IDENTIFIER.pattern())) {
        mEditName.setError(getString(R.string.invalid_name));
        return;
    }
    String currentPackage = mPackage.getText().toString();
    if (currentPackage.trim().isEmpty()) {
        mPackage.setError(getString(R.string.enter_package));
        return;
    }
    if (!currentPackage.matches(PatternFactory.PACKAGE_NAME.pattern())) {
        mPackage.setError(getString(R.string.invalid_name));
        return;
    }

    Set<javax.lang.model.element.Modifier> modifiers = new ArraySet<>();
    if ((mVisibility.getCheckedRadioButtonId() == R.id.rad_public)) {
        modifiers.add(javax.lang.model.element.Modifier.PUBLIC);
    }

    int checkedRadioButtonId = mModifiers.getCheckedRadioButtonId();
    if (checkedRadioButtonId == R.id.rad_abstract) {
        modifiers.add(javax.lang.model.element.Modifier.ABSTRACT);
    } else if (checkedRadioButtonId == R.id.rad_final) {
        modifiers.add(javax.lang.model.element.Modifier.FINAL);
    }
    String kind = mKind.getSelectedItem().toString();
    try {
        StringWriter out = new StringWriter();
        JavaWriter writer = new JavaWriter(out);
        writer.emitPackage(currentPackage)
                .beginType(className, kind, modifiers)
                .emitEmptyLine();
        if (mCreateMainFunc.isChecked()) {
            //public static void main
            modifiers.clear();
            modifiers.add(Modifier.PUBLIC);
            modifiers.add(Modifier.STATIC);
            writer.beginMethod("void", "main", modifiers, "String[]", "args")
                    .emitEmptyLine()
                    .endMethod()
                    .emitEmptyLine();
        }
        writer.endType();
        writer.close();

        String content = out.toString();
        File clazz = project.createClass(currentPackage, className, content);
        if (listener != null) {
            listener.onFileCreated(clazz);
            Toast.makeText(getContext(), "success!", Toast.LENGTH_SHORT).show();
            this.dismiss();
        }
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
    }

}
 
Example #13
Source File: GeofencingHelper.java    From mobile-messaging-sdk-android with Apache License 2.0 4 votes vote down vote up
public static Set<String> getFinishedCampaignIds(Context context) {
    return PreferenceHelper.findStringSet(context, MobileMessagingGeoProperty.FINISHED_CAMPAIGN_IDS.getKey(), new ArraySet<String>());
}
 
Example #14
Source File: GeofencingHelper.java    From mobile-messaging-sdk-android with Apache License 2.0 4 votes vote down vote up
public static Set<String> getSuspendedCampaignIds(Context context) {
    return PreferenceHelper.findStringSet(context, MobileMessagingGeoProperty.SUSPENDED_CAMPAIGN_IDS.getKey(), new ArraySet<String>());
}
 
Example #15
Source File: GeoReporterTest.java    From mobile-messaging-sdk-android with Apache License 2.0 4 votes vote down vote up
@Test
public void test_withNonActiveCampaigns() throws InterruptedException {

    // Given
    Area area1 = createArea("areaId1");
    Area area2 = createArea("areaId2");
    Area area3 = createArea("areaId3");
    createMessage(context, "signalingMessageId1", "campaignId1", true, area1, area2);
    createMessage(context, "signalingMessageId2", "campaignId3", true, area3);
    createReport(context, "signalingMessageId1", "campaignId1", "messageId1", true, area1);
    createReport(context, "signalingMessageId1", "campaignId1", "messageId2", true, area2);
    createReport(context, "signalingMessageId2", "campaignId3", "messageId3", true, area3);
    given(mobileApiGeo.report(any(EventReportBody.class))).willReturn(new EventReportResponse() {{
        setFinishedCampaignIds(newSet("campaignId1"));
        setSuspendedCampaignIds(newSet("campaignId2"));
    }});

    // When
    geoReporter.synchronize();

    // Then
    // Examine what is reported back via broadcast intent
    Mockito.verify(geoBroadcaster, Mockito.after(1000).atLeastOnce()).geoReported(geoReportCaptor.capture());

    List<GeoReport> broadcastedReports = geoReportCaptor.getValue();
    assertEquals(broadcastedReports.size(), 1);

    GeoReport geoReport = broadcastedReports.get(0);
    assertEquals(GeoEventType.entry, geoReport.getEvent());
    assertEquals("campaignId3", geoReport.getCampaignId());
    assertEquals("messageId3", geoReport.getMessageId());
    assertEquals("areaId3", geoReport.getArea().getId());

    final Set<String> finishedCampaignIds = PreferenceHelper.findStringSet(context, MobileMessagingGeoProperty.FINISHED_CAMPAIGN_IDS.getKey(), new ArraySet<String>(0));
    final Set<String> suspendedCampaignIds = PreferenceHelper.findStringSet(context, MobileMessagingGeoProperty.SUSPENDED_CAMPAIGN_IDS.getKey(), new ArraySet<String>(0));

    assertEquals(finishedCampaignIds.size(), 1);
    assertEquals(finishedCampaignIds.iterator().next(), "campaignId1");

    assertEquals(suspendedCampaignIds.size(), 1);
    assertEquals(suspendedCampaignIds.iterator().next(), "campaignId2");
}
 
Example #16
Source File: MediaControllerCallback.java    From QuickLyric with GNU General Public License v3.0 4 votes vote down vote up
public static Set<String> getUsedPlayersList(Context context) {
    return context.getSharedPreferences("NotificationListenerService", Context.MODE_PRIVATE)
                .getStringSet("players_used", new ArraySet<>());
}