Search in sources :

Example 1 with SpinnerWithIconItem

use of nodomain.freeyourgadget.gadgetbridge.adapter.SpinnerWithIconItem in project Gadgetbridge by Freeyourgadget.

the class DiscoveryActivity method onItemLongClick.

@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long id) {
    stopDiscovery();
    final GBDeviceCandidate deviceCandidate = deviceCandidates.get(position);
    if (deviceCandidate == null) {
        LOG.error("Device candidate clicked, but item not found");
        return true;
    }
    if (!deviceCandidate.getDeviceType().isSupported()) {
        LOG.error("Unsupported device candidate");
        LinkedHashMap<String, Pair<Long, Integer>> allDevices;
        allDevices = DebugActivity.getAllSupportedDevices(getApplicationContext());
        final LinearLayout linearLayout = new LinearLayout(DiscoveryActivity.this);
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        final LinearLayout macLayout = new LinearLayout(DiscoveryActivity.this);
        macLayout.setOrientation(LinearLayout.HORIZONTAL);
        macLayout.setPadding(20, 0, 20, 0);
        final Spinner deviceListSpinner = new Spinner(DiscoveryActivity.this);
        ArrayList<SpinnerWithIconItem> deviceListArray = new ArrayList<>();
        for (Map.Entry<String, Pair<Long, Integer>> item : allDevices.entrySet()) {
            deviceListArray.add(new SpinnerWithIconItem(item.getKey(), item.getValue().first, item.getValue().second));
        }
        final SpinnerWithIconAdapter deviceListAdapter = new SpinnerWithIconAdapter(DiscoveryActivity.this, R.layout.spinner_with_image_layout, R.id.spinner_item_text, deviceListArray);
        deviceListSpinner.setAdapter(deviceListAdapter);
        addListenerOnSpinnerDeviceSelection(deviceListSpinner);
        linearLayout.addView(deviceListSpinner);
        linearLayout.addView(macLayout);
        new AlertDialog.Builder(DiscoveryActivity.this).setCancelable(true).setTitle(R.string.add_test_device).setView(linearLayout).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (selectedUnsupportedDeviceKey != DebugActivity.SELECT_DEVICE) {
                    DebugActivity.createTestDevice(DiscoveryActivity.this, selectedUnsupportedDeviceKey, deviceCandidate.getMacAddress());
                    finish();
                }
            }
        }).setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        }).show();
        return true;
    }
    DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(deviceCandidate);
    GBDevice device = DeviceHelper.getInstance().toSupportedDevice(deviceCandidate);
    if (coordinator.getSupportedDeviceSpecificSettings(device) == null) {
        return true;
    }
    Intent startIntent;
    startIntent = new Intent(this, DeviceSettingsActivity.class);
    startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
    startActivity(startIntent);
    return true;
}
Also used : GBDeviceCandidate(nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate) DialogInterface(android.content.DialogInterface) Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) Intent(android.content.Intent) SpinnerWithIconItem(nodomain.freeyourgadget.gadgetbridge.adapter.SpinnerWithIconItem) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) DeviceSettingsActivity(nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsActivity) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) LinearLayout(android.widget.LinearLayout) SpinnerWithIconAdapter(nodomain.freeyourgadget.gadgetbridge.adapter.SpinnerWithIconAdapter) DeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator) Pair(android.util.Pair)

Example 2 with SpinnerWithIconItem

use of nodomain.freeyourgadget.gadgetbridge.adapter.SpinnerWithIconItem in project Gadgetbridge by Freeyourgadget.

the class DebugActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_debug);
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_REPLY);
    filter.addAction(DeviceService.ACTION_REALTIME_SAMPLES);
    LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
    // for ACTION_REPLY
    registerReceiver(mReceiver, filter);
    editContent = findViewById(R.id.editContent);
    final ArrayList<String> spinnerArray = new ArrayList<>();
    for (NotificationType notificationType : NotificationType.values()) {
        spinnerArray.add(notificationType.name());
    }
    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, spinnerArray);
    sendTypeSpinner = findViewById(R.id.sendTypeSpinner);
    sendTypeSpinner.setAdapter(spinnerArrayAdapter);
    Button sendButton = findViewById(R.id.sendButton);
    sendButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            NotificationSpec notificationSpec = new NotificationSpec();
            String testString = editContent.getText().toString();
            notificationSpec.phoneNumber = testString;
            notificationSpec.body = testString;
            notificationSpec.sender = testString;
            notificationSpec.subject = testString;
            notificationSpec.type = NotificationType.values()[sendTypeSpinner.getSelectedItemPosition()];
            notificationSpec.pebbleColor = notificationSpec.type.color;
            GBApplication.deviceService().onNotification(notificationSpec);
        }
    });
    Button incomingCallButton = findViewById(R.id.incomingCallButton);
    incomingCallButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CallSpec callSpec = new CallSpec();
            callSpec.command = CallSpec.CALL_INCOMING;
            callSpec.number = editContent.getText().toString();
            GBApplication.deviceService().onSetCallState(callSpec);
        }
    });
    Button outgoingCallButton = findViewById(R.id.outgoingCallButton);
    outgoingCallButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CallSpec callSpec = new CallSpec();
            callSpec.command = CallSpec.CALL_OUTGOING;
            callSpec.number = editContent.getText().toString();
            GBApplication.deviceService().onSetCallState(callSpec);
        }
    });
    Button startCallButton = findViewById(R.id.startCallButton);
    startCallButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CallSpec callSpec = new CallSpec();
            callSpec.command = CallSpec.CALL_START;
            GBApplication.deviceService().onSetCallState(callSpec);
        }
    });
    Button endCallButton = findViewById(R.id.endCallButton);
    endCallButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CallSpec callSpec = new CallSpec();
            callSpec.command = CallSpec.CALL_END;
            GBApplication.deviceService().onSetCallState(callSpec);
        }
    });
    Button rebootButton = findViewById(R.id.rebootButton);
    rebootButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            GBApplication.deviceService().onReset(GBDeviceProtocol.RESET_FLAGS_REBOOT);
        }
    });
    Button factoryResetButton = findViewById(R.id.factoryResetButton);
    factoryResetButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(DebugActivity.this).setCancelable(true).setTitle(R.string.debugactivity_really_factoryreset_title).setMessage(R.string.debugactivity_really_factoryreset).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    GBApplication.deviceService().onReset(GBDeviceProtocol.RESET_FLAGS_FACTORY_RESET);
                }
            }).setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).show();
        }
    });
    Button heartRateButton = findViewById(R.id.HeartRateButton);
    heartRateButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            GB.toast("Measuring heart rate, please wait...", Toast.LENGTH_LONG, GB.INFO);
            GBApplication.deviceService().onHeartRateTest();
        }
    });
    Button setFetchTimeButton = findViewById(R.id.SetFetchTimeButton);
    setFetchTimeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final Calendar currentDate = Calendar.getInstance();
            Context context = getApplicationContext();
            if (context instanceof GBApplication) {
                GBApplication gbApp = (GBApplication) context;
                final GBDevice device = gbApp.getDeviceManager().getSelectedDevice();
                if (device != null) {
                    new DatePickerDialog(DebugActivity.this, new DatePickerDialog.OnDateSetListener() {

                        @Override
                        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                            Calendar date = Calendar.getInstance();
                            date.set(year, monthOfYear, dayOfMonth);
                            long timestamp = date.getTimeInMillis() - 1000;
                            GB.toast("Setting lastSyncTimeMillis: " + timestamp, Toast.LENGTH_LONG, GB.INFO);
                            SharedPreferences.Editor editor = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).edit();
                            // FIXME: key reconstruction is BAD
                            editor.remove("lastSyncTimeMillis");
                            editor.putLong("lastSyncTimeMillis", timestamp);
                            editor.apply();
                        }
                    }, currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DATE)).show();
                } else {
                    GB.toast("Device not selected/connected", Toast.LENGTH_LONG, GB.INFO);
                }
            }
        }
    });
    Button setMusicInfoButton = findViewById(R.id.setMusicInfoButton);
    setMusicInfoButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MusicSpec musicSpec = new MusicSpec();
            String testString = editContent.getText().toString();
            musicSpec.artist = testString + "(artist)";
            musicSpec.album = testString + "(album)";
            musicSpec.track = testString + "(track)";
            musicSpec.duration = 10;
            musicSpec.trackCount = 5;
            musicSpec.trackNr = 2;
            GBApplication.deviceService().onSetMusicInfo(musicSpec);
            MusicStateSpec stateSpec = new MusicStateSpec();
            stateSpec.position = 0;
            // playing
            stateSpec.state = 0x01;
            stateSpec.playRate = 100;
            stateSpec.repeat = 1;
            stateSpec.shuffle = 1;
            GBApplication.deviceService().onSetMusicState(stateSpec);
        }
    });
    Button setTimeButton = findViewById(R.id.setTimeButton);
    setTimeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            GBApplication.deviceService().onSetTime();
        }
    });
    Button testNotificationButton = findViewById(R.id.testNotificationButton);
    testNotificationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            testNotification();
        }
    });
    Button testPebbleKitNotificationButton = findViewById(R.id.testPebbleKitNotificationButton);
    testPebbleKitNotificationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            testPebbleKitNotification();
        }
    });
    Button fetchDebugLogsButton = findViewById(R.id.fetchDebugLogsButton);
    fetchDebugLogsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_DEBUGLOGS);
        }
    });
    Button testNewFunctionalityButton = findViewById(R.id.testNewFunctionality);
    testNewFunctionalityButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            testNewFunctionality();
        }
    });
    Button shareLogButton = findViewById(R.id.shareLog);
    shareLogButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showWarning();
        }
    });
    Button showWidgetsButton = findViewById(R.id.showWidgetsButton);
    showWidgetsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showAllRegisteredAppWidgets();
        }
    });
    Button unregisterWidgetsButton = findViewById(R.id.deleteWidgets);
    unregisterWidgetsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            unregisterAllRegisteredAppWidgets();
        }
    });
    Button showWidgetsPrefsButton = findViewById(R.id.showWidgetsPrefs);
    showWidgetsPrefsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showAppWidgetsPrefs();
        }
    });
    Button deleteWidgetsPrefsButton = findViewById(R.id.deleteWidgetsPrefs);
    deleteWidgetsPrefsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            deleteWidgetsPrefs();
        }
    });
    Button removeDevicePreferencesButton = findViewById(R.id.removeDevicePreferences);
    removeDevicePreferencesButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Context context = getApplicationContext();
            GBApplication gbApp = (GBApplication) context;
            final GBDevice device = gbApp.getDeviceManager().getSelectedDevice();
            if (device != null) {
                GBApplication.deleteDeviceSpecificSharedPrefs(device.getAddress());
            }
        }
    });
    Button runDebugFunction = findViewById(R.id.runDebugFunction);
    runDebugFunction.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
        // SharedPreferences.Editor editor = GBApplication.getPrefs().getPreferences().edit();
        // editor.remove("notification_list_is_blacklist").apply();
        }
    });
    Button addDeviceButtonDebug = findViewById(R.id.addDeviceButtonDebug);
    addDeviceButtonDebug.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            LinkedHashMap<String, Pair<Long, Integer>> allDevices;
            allDevices = getAllSupportedDevices(getApplicationContext());
            final LinearLayout linearLayout = new LinearLayout(DebugActivity.this);
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            final LinearLayout macLayout = new LinearLayout(DebugActivity.this);
            macLayout.setOrientation(LinearLayout.HORIZONTAL);
            macLayout.setPadding(20, 0, 20, 0);
            final TextView textView = new TextView(DebugActivity.this);
            textView.setText("MAC Address: ");
            final EditText editText = new EditText(DebugActivity.this);
            selectedTestDeviceMAC = randomMac();
            editText.setText(selectedTestDeviceMAC);
            editText.addTextChangedListener(new TextWatcher() {

                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                }

                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                }

                @Override
                public void afterTextChanged(Editable editable) {
                    selectedTestDeviceMAC = editable.toString();
                }
            });
            macLayout.addView(textView);
            macLayout.addView(editText);
            final Spinner deviceListSpinner = new Spinner(DebugActivity.this);
            ArrayList<SpinnerWithIconItem> deviceListArray = new ArrayList<>();
            for (Map.Entry<String, Pair<Long, Integer>> item : allDevices.entrySet()) {
                deviceListArray.add(new SpinnerWithIconItem(item.getKey(), item.getValue().first, item.getValue().second));
            }
            final SpinnerWithIconAdapter deviceListAdapter = new SpinnerWithIconAdapter(DebugActivity.this, R.layout.spinner_with_image_layout, R.id.spinner_item_text, deviceListArray);
            deviceListSpinner.setAdapter(deviceListAdapter);
            addListenerOnSpinnerDeviceSelection(deviceListSpinner);
            linearLayout.addView(deviceListSpinner);
            linearLayout.addView(macLayout);
            new AlertDialog.Builder(DebugActivity.this).setCancelable(true).setTitle(R.string.add_test_device).setView(linearLayout).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    createTestDevice(DebugActivity.this, selectedTestDeviceKey, selectedTestDeviceMAC);
                }
            }).setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).show();
        }
    });
    CheckBox activity_list_debug_extra_time_range = findViewById(R.id.activity_list_debug_extra_time_range);
    activity_list_debug_extra_time_range.setAllCaps(true);
    boolean activity_list_debug_extra_time_range_value = GBApplication.getPrefs().getPreferences().getBoolean("activity_list_debug_extra_time_range", false);
    activity_list_debug_extra_time_range.setChecked(activity_list_debug_extra_time_range_value);
    activity_list_debug_extra_time_range.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            GBApplication.getPrefs().getPreferences().getBoolean("activity_list_debug_extra_time_range", false);
            SharedPreferences.Editor editor = GBApplication.getPrefs().getPreferences().edit();
            editor.putBoolean("activity_list_debug_extra_time_range", b).apply();
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) GBApplication(nodomain.freeyourgadget.gadgetbridge.GBApplication) DialogInterface(android.content.DialogInterface) Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) SpinnerWithIconItem(nodomain.freeyourgadget.gadgetbridge.adapter.SpinnerWithIconItem) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) LinkedHashMap(java.util.LinkedHashMap) MusicStateSpec(nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec) MusicSpec(nodomain.freeyourgadget.gadgetbridge.model.MusicSpec) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) CallSpec(nodomain.freeyourgadget.gadgetbridge.model.CallSpec) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) Context(android.content.Context) EditText(android.widget.EditText) IntentFilter(android.content.IntentFilter) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) CheckBox(android.widget.CheckBox) NotificationType(nodomain.freeyourgadget.gadgetbridge.model.NotificationType) NotificationSpec(nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec) DatePicker(android.widget.DatePicker) ArrayAdapter(android.widget.ArrayAdapter) LinearLayout(android.widget.LinearLayout) SpinnerWithIconAdapter(nodomain.freeyourgadget.gadgetbridge.adapter.SpinnerWithIconAdapter) CompoundButton(android.widget.CompoundButton)

Example 3 with SpinnerWithIconItem

use of nodomain.freeyourgadget.gadgetbridge.adapter.SpinnerWithIconItem in project Gadgetbridge by Freeyourgadget.

the class ActivitySummariesFilter method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle bundle = this.getIntent().getExtras();
    activityKindMap = (HashMap<String, Integer>) bundle.getSerializable("activityKindMap");
    itemsFilter = (List<Long>) bundle.getSerializable("itemsFilter");
    activityFilter = bundle.getInt("activityFilter", 0);
    dateFromFilter = bundle.getLong("dateFromFilter", 0);
    dateToFilter = bundle.getLong("dateToFilter", 0);
    initial_deviceFilter = bundle.getLong("initial_deviceFilter", 0);
    deviceFilter = bundle.getLong("deviceFilter", 0);
    nameContainsFilter = bundle.getString("nameContainsFilter");
    Context appContext = this.getApplicationContext();
    if (appContext instanceof GBApplication) {
        setContentView(R.layout.sport_activity_filter);
    }
    BACKGROUND_COLOR = GBApplication.getBackgroundColor(appContext);
    allDevices = getAllDevices(appContext);
    // device filter spinner
    final Spinner deviceFilterSpinner = findViewById(R.id.select_device);
    ArrayList<SpinnerWithIconItem> filterDevicesArray = new ArrayList<>();
    for (Map.Entry<String, Pair<Long, Integer>> item : allDevices.entrySet()) {
        filterDevicesArray.add(new SpinnerWithIconItem(item.getKey(), item.getValue().first, item.getValue().second));
    }
    final SpinnerWithIconAdapter filterDevicesAdapter = new SpinnerWithIconAdapter(this, R.layout.spinner_with_image_layout, R.id.spinner_item_text, filterDevicesArray);
    deviceFilterSpinner.setAdapter(filterDevicesAdapter);
    deviceFilterSpinner.setSelection(filterDevicesAdapter.getItemPositionForSelection(getDeviceById(deviceFilter)));
    addListenerOnSpinnerDeviceSelection();
    // Kind filter spinner - assign data, set selected item...
    final Spinner filterKindSpinner = findViewById(R.id.select_kind);
    ArrayList<SpinnerWithIconItem> kindArray = new ArrayList<>();
    for (Map.Entry<String, Integer> item : activityKindMap.entrySet()) {
        // do not put here All devices, but we do need them in the array
        if (item.getValue() == 0)
            continue;
        kindArray.add(new SpinnerWithIconItem(item.getKey(), new Long(item.getValue()), ActivityKind.getIconId(item.getValue())));
    }
    // ensure that all items is always first in the list, this is an issue on old android
    SpinnerWithIconItem allActivities = new SpinnerWithIconItem(getString(R.string.activity_summaries_all_activities), new Long(0), ActivityKind.getIconId(0));
    kindArray.add(0, allActivities);
    SpinnerWithIconAdapter adapter = new SpinnerWithIconAdapter(this, R.layout.spinner_with_image_layout, R.id.spinner_item_text, kindArray);
    SpinnerWithIconItem selectedActivity = getKindByValue(activityFilter);
    int selectedPosition = adapter.getItemPositionForSelection(selectedActivity);
    filterKindSpinner.setAdapter(adapter);
    filterKindSpinner.setSelection(selectedPosition);
    addListenerOnSpinnerKindSelection();
    // quick date filter selection
    final Spinner quick_filter_period_select = findViewById(R.id.quick_filter_period_select);
    ArrayList<String> quickDateArray = new ArrayList<>(activityKindMap.keySet());
    ArrayList activity_filter_quick_filter_period_items = new ArrayList(Arrays.asList(getResources().getStringArray(R.array.activity_filter_quick_filter_period_items)));
    ArrayAdapter<String> filterDateAdapter = new ArrayAdapter<String>(this, R.layout.simple_spinner_item_themed, activity_filter_quick_filter_period_items);
    quick_filter_period_select.setAdapter(filterDateAdapter);
    addListenerOnQuickFilterSelection();
    // set current values coming from parent
    update_filter_fields();
    final LinearLayout filterfrom = findViewById(R.id.filterfrom);
    final LinearLayout filterto = findViewById(R.id.filterto);
    final EditText nameContainsFilterdata = findViewById(R.id.textViewNameData);
    final Button reset_filter_button = findViewById(R.id.reset_filter_button);
    final Button apply_filter_button = findViewById(R.id.apply_filter_button);
    nameContainsFilterdata.addTextChangedListener(new TextWatcher() {

        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            nameContainsFilter = s.toString();
            update_filter_fields();
        }
    });
    reset_filter_button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            activityFilter = 0;
            dateFromFilter = 0;
            dateToFilter = 0;
            nameContainsFilter = "";
            filterKindSpinner.setSelection(0);
            itemsFilter = null;
            deviceFilterSpinner.setSelection(filterDevicesAdapter.getItemPositionForSelection(getDeviceById(initial_deviceFilter)));
            quick_filter_period_select.setSelection(0);
            update_filter_fields();
        }
    });
    apply_filter_button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String text = nameContainsFilterdata.getText().toString();
            if (text != null && text.length() > 0) {
                nameContainsFilter = text;
            }
            Intent intent = new Intent();
            Bundle bundle = new Bundle();
            bundle.putInt("activityFilter", activityFilter);
            bundle.putSerializable("itemsFilter", (Serializable) itemsFilter);
            bundle.putLong("dateFromFilter", dateFromFilter);
            bundle.putLong("dateToFilter", dateToFilter);
            bundle.putLong("deviceFilter", deviceFilter);
            bundle.putString("nameContainsFilter", nameContainsFilter);
            intent.putExtras(bundle);
            setResult(1, intent);
            finish();
        }
    });
    filterfrom.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getDate(DATE_FILTER_FROM, dateFromFilter);
            quick_filter_period_select.setSelection(0);
        }
    });
    filterto.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getDate(DATE_FILTER_TO, dateToFilter);
            quick_filter_period_select.setSelection(0);
        }
    });
}
Also used : Serializable(java.io.Serializable) GBApplication(nodomain.freeyourgadget.gadgetbridge.GBApplication) Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) SpinnerWithIconItem(nodomain.freeyourgadget.gadgetbridge.adapter.SpinnerWithIconItem) Button(android.widget.Button) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Pair(android.util.Pair) Context(android.content.Context) EditText(android.widget.EditText) Bundle(android.os.Bundle) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SpinnerWithIconAdapter(nodomain.freeyourgadget.gadgetbridge.adapter.SpinnerWithIconAdapter) ArrayAdapter(android.widget.ArrayAdapter) LinearLayout(android.widget.LinearLayout)

Aggregations

LinearLayout (android.widget.LinearLayout)3 Spinner (android.widget.Spinner)3 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 SpinnerWithIconAdapter (nodomain.freeyourgadget.gadgetbridge.adapter.SpinnerWithIconAdapter)3 SpinnerWithIconItem (nodomain.freeyourgadget.gadgetbridge.adapter.SpinnerWithIconItem)3 Context (android.content.Context)2 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 Pair (android.util.Pair)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ArrayAdapter (android.widget.ArrayAdapter)2 Button (android.widget.Button)2 EditText (android.widget.EditText)2 TextView (android.widget.TextView)2 Map (java.util.Map)2 GBApplication (nodomain.freeyourgadget.gadgetbridge.GBApplication)2