Search in sources :

Example 6 with GBApplication

use of nodomain.freeyourgadget.gadgetbridge.GBApplication 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)

Example 7 with GBApplication

use of nodomain.freeyourgadget.gadgetbridge.GBApplication in project Gadgetbridge by Freeyourgadget.

the class ActivitySummariesFilter method getAllDevices.

public LinkedHashMap getAllDevices(Context appContext) {
    DaoSession daoSession;
    GBApplication gbApp = (GBApplication) appContext;
    LinkedHashMap<String, Pair<Long, Integer>> newMap = new LinkedHashMap<>(1);
    List<? extends GBDevice> devices = gbApp.getDeviceManager().getDevices();
    newMap.put(getString(R.string.activity_summaries_all_devices), new Pair(ALL_DEVICES, R.drawable.ic_device_default_disabled));
    try (DBHandler handler = GBApplication.acquireDB()) {
        daoSession = handler.getDaoSession();
        for (GBDevice device : devices) {
            DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
            Device dbDevice = DBHelper.findDevice(device, daoSession);
            int icon = device.isInitialized() ? device.getType().getIcon() : device.getType().getDisabledIcon();
            if (dbDevice != null && coordinator != null && coordinator.supportsActivityTracks() && !newMap.containsKey(device.getAliasOrName())) {
                newMap.put(device.getAliasOrName(), new Pair(dbDevice.getId(), icon));
            }
        }
    } catch (Exception e) {
        LOG.debug("Error getting list of all devices: " + e);
    }
    return newMap;
}
Also used : GBApplication(nodomain.freeyourgadget.gadgetbridge.GBApplication) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) LinkedHashMap(java.util.LinkedHashMap) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) DeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator) DaoSession(nodomain.freeyourgadget.gadgetbridge.entities.DaoSession) Pair(android.util.Pair)

Example 8 with GBApplication

use of nodomain.freeyourgadget.gadgetbridge.GBApplication in project Gadgetbridge by Freeyourgadget.

the class ActivitySummaryDetail method onCreate.

@SuppressLint("ClickableViewAccessibility")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Context appContext = this.getApplicationContext();
    if (appContext instanceof GBApplication) {
        setContentView(R.layout.activity_summary_details);
    }
    Intent intent = getIntent();
    Bundle bundle = intent.getExtras();
    gbDevice = bundle.getParcelable(GBDevice.EXTRA_DEVICE);
    final int position = bundle.getInt("position", 0);
    final int activityFilter = bundle.getInt("activityFilter", 0);
    final long dateFromFilter = bundle.getLong("dateFromFilter", 0);
    final long dateToFilter = bundle.getLong("dateToFilter", 0);
    final long deviceFilter = bundle.getLong("deviceFilter", 0);
    final String nameContainsFilter = bundle.getString("nameContainsFilter");
    final List itemsFilter = (List<Long>) bundle.getSerializable("itemsFilter");
    final ActivitySummaryItems items = new ActivitySummaryItems(this, gbDevice, activityFilter, dateFromFilter, dateToFilter, nameContainsFilter, deviceFilter, itemsFilter);
    final ScrollView layout = findViewById(R.id.activity_summary_detail_scroll_layout);
    // final LinearLayout layout = findViewById(R.id.activity_summary_detail_relative_layout);
    alternateColor = getAlternateColor(this);
    final Animation animFadeRight;
    final Animation animFadeLeft;
    final Animation animBounceLeft;
    final Animation animBounceRight;
    animFadeRight = AnimationUtils.loadAnimation(this, R.anim.flyright);
    animFadeLeft = AnimationUtils.loadAnimation(this, R.anim.flyleft);
    animBounceLeft = AnimationUtils.loadAnimation(this, R.anim.bounceleft);
    animBounceRight = AnimationUtils.loadAnimation(this, R.anim.bounceright);
    final ActivitySummariesChartFragment activitySummariesChartFragment = new ActivitySummariesChartFragment();
    final ActivitySummariesGpsFragment activitySummariesGpsFragment = new ActivitySummariesGpsFragment();
    getSupportFragmentManager().beginTransaction().replace(R.id.chartsFragmentHolder, activitySummariesChartFragment).replace(R.id.gpsFragmentHolder, activitySummariesGpsFragment).commit();
    layout.setOnTouchListener(new SwipeEvents(this) {

        @Override
        public void onSwipeRight() {
            BaseActivitySummary newItem = items.getNextItem();
            if (newItem != null) {
                currentItem = newItem;
                makeSummaryHeader(newItem);
                makeSummaryContent(newItem);
                activitySummariesChartFragment.setDateAndGetData(getGBDevice(currentItem.getDevice()), currentItem.getStartTime().getTime() / 1000, currentItem.getEndTime().getTime() / 1000);
                if (get_gpx_file() != null) {
                    showCanvas();
                    activitySummariesGpsFragment.set_data(get_gpx_file());
                } else {
                    hideCanvas();
                }
                layout.startAnimation(animFadeRight);
                show_hide_gpx_menu();
            } else {
                layout.startAnimation(animBounceRight);
            }
        }

        @Override
        public void onSwipeLeft() {
            BaseActivitySummary newItem = items.getPrevItem();
            if (newItem != null) {
                currentItem = newItem;
                makeSummaryHeader(newItem);
                makeSummaryContent(newItem);
                activitySummariesChartFragment.setDateAndGetData(getGBDevice(currentItem.getDevice()), currentItem.getStartTime().getTime() / 1000, currentItem.getEndTime().getTime() / 1000);
                if (get_gpx_file() != null) {
                    showCanvas();
                    activitySummariesGpsFragment.set_data(get_gpx_file());
                } else {
                    hideCanvas();
                }
                layout.startAnimation(animFadeLeft);
                show_hide_gpx_menu();
            } else {
                layout.startAnimation(animBounceLeft);
            }
        }
    });
    currentItem = items.getItem(position);
    if (currentItem != null) {
        makeSummaryHeader(currentItem);
        makeSummaryContent(currentItem);
        activitySummariesChartFragment.setDateAndGetData(getGBDevice(currentItem.getDevice()), currentItem.getStartTime().getTime() / 1000, currentItem.getEndTime().getTime() / 1000);
        if (get_gpx_file() != null) {
            showCanvas();
            activitySummariesGpsFragment.set_data(get_gpx_file());
        } else {
            hideCanvas();
        }
    }
    // allows long-press.switch of data being in raw form or recalculated
    ImageView activity_icon = findViewById(R.id.item_image);
    activity_icon.setOnLongClickListener(new View.OnLongClickListener() {

        public boolean onLongClick(View v) {
            show_raw_data = !show_raw_data;
            if (currentItem != null) {
                makeSummaryHeader(currentItem);
                makeSummaryContent(currentItem);
            }
            return false;
        }
    });
    ImageView activity_summary_detail_edit_name_image = findViewById(R.id.activity_summary_detail_edit_name);
    activity_summary_detail_edit_name_image.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final EditText input = new EditText(ActivitySummaryDetail.this);
            input.setInputType(InputType.TYPE_CLASS_TEXT);
            String name = currentItem.getName();
            input.setText((name != null) ? name : "");
            FrameLayout container = new FrameLayout(ActivitySummaryDetail.this);
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.leftMargin = getResources().getDimensionPixelSize(R.dimen.dialog_margin);
            params.rightMargin = getResources().getDimensionPixelSize(R.dimen.dialog_margin);
            input.setLayoutParams(params);
            container.addView(input);
            new AlertDialog.Builder(ActivitySummaryDetail.this).setView(container).setCancelable(true).setTitle(ActivitySummaryDetail.this.getString(R.string.activity_summary_edit_name_title)).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String name = input.getText().toString();
                    if (name.length() < 1)
                        name = null;
                    currentItem.setName(name);
                    currentItem.update();
                    makeSummaryHeader(currentItem);
                    makeSummaryContent(currentItem);
                }
            }).setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                // do nothing
                }
            }).show();
        }
    });
    ImageView activity_summary_detail_edit_gps = findViewById(R.id.activity_summary_detail_edit_gps);
    activity_summary_detail_edit_gps.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            export_path = get_path();
            filesGpxList = get_gpx_file_list();
            AlertDialog.Builder builder = new AlertDialog.Builder(ActivitySummaryDetail.this);
            builder.setTitle(R.string.activity_summary_detail_select_gpx_track);
            ArrayAdapter<String> directory_listing = new ArrayAdapter<String>(ActivitySummaryDetail.this, android.R.layout.simple_list_item_1, filesGpxList);
            builder.setSingleChoiceItems(directory_listing, 0, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    selectedGpxIndex = which;
                    selectedGpxFile = export_path + "/" + filesGpxList.get(selectedGpxIndex);
                    String message = String.format("%s %s?", getString(R.string.set), filesGpxList.get(selectedGpxIndex));
                    if (selectedGpxIndex == 0) {
                        selectedGpxFile = null;
                        message = String.format("%s?", getString(R.string.activity_summary_detail_clear_gpx_track));
                    }
                    new AlertDialog.Builder(ActivitySummaryDetail.this).setCancelable(true).setIcon(R.drawable.ic_warning).setTitle(R.string.activity_summary_detail_editing_gpx_track).setMessage(message).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            currentItem.setGpxTrack(selectedGpxFile);
                            currentItem.update();
                            if (get_gpx_file() != null) {
                                showCanvas();
                                activitySummariesGpsFragment.set_data(get_gpx_file());
                            } else {
                                hideCanvas();
                            }
                        }
                    }).setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    }).show();
                    dialog.dismiss();
                }
            });
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) GBApplication(nodomain.freeyourgadget.gadgetbridge.GBApplication) DialogInterface(android.content.DialogInterface) BaseActivitySummary(nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary) List(java.util.List) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) Context(android.content.Context) EditText(android.widget.EditText) Bundle(android.os.Bundle) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) SuppressLint(android.annotation.SuppressLint) SwipeEvents(nodomain.freeyourgadget.gadgetbridge.util.SwipeEvents) ScrollView(android.widget.ScrollView) ActivitySummaryItems(nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryItems) FrameLayout(android.widget.FrameLayout) Animation(android.view.animation.Animation) ArrayAdapter(android.widget.ArrayAdapter) SuppressLint(android.annotation.SuppressLint)

Example 9 with GBApplication

use of nodomain.freeyourgadget.gadgetbridge.GBApplication in project Gadgetbridge by Freeyourgadget.

the class ActivitySummaryDetail method getGBDevice.

private GBDevice getGBDevice(Device findDevice) {
    DaoSession daoSession;
    GBApplication gbApp = (GBApplication) getApplicationContext();
    List<? extends GBDevice> devices = gbApp.getDeviceManager().getDevices();
    try (DBHandler handler = GBApplication.acquireDB()) {
        daoSession = handler.getDaoSession();
        for (GBDevice device : devices) {
            Device dbDevice = DBHelper.findDevice(device, daoSession);
            if (dbDevice.equals(findDevice))
                return device;
        }
    } catch (Exception e) {
        LOG.debug("Error getting device: " + e);
    }
    return null;
}
Also used : DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) GBApplication(nodomain.freeyourgadget.gadgetbridge.GBApplication) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) JSONException(org.json.JSONException) ActivityNotFoundException(android.content.ActivityNotFoundException) IOException(java.io.IOException) DaoSession(nodomain.freeyourgadget.gadgetbridge.entities.DaoSession) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)

Example 10 with GBApplication

use of nodomain.freeyourgadget.gadgetbridge.GBApplication in project Gadgetbridge by Freeyourgadget.

the class DailyTotals method getDailyTotalsForAllDevices.

public long[] getDailyTotalsForAllDevices(Calendar day) {
    Context context = GBApplication.getContext();
    // get today's steps for all devices in GB
    long all_steps = 0;
    long all_sleep = 0;
    if (context instanceof GBApplication) {
        GBApplication gbApp = (GBApplication) context;
        List<? extends GBDevice> devices = gbApp.getDeviceManager().getDevices();
        for (GBDevice device : devices) {
            DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
            if (!coordinator.supportsActivityDataFetching() && !coordinator.supportsActivityTracking()) {
                continue;
            }
            long[] all_daily = getDailyTotalsForDevice(device, day);
            all_steps += all_daily[0];
            all_sleep += all_daily[1];
        }
    }
    // LOG.debug("gbwidget  daily totals, all sleep:" + all_sleep);
    return new long[] { all_steps, all_sleep };
}
Also used : Context(android.content.Context) GBApplication(nodomain.freeyourgadget.gadgetbridge.GBApplication) DeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)

Aggregations

GBApplication (nodomain.freeyourgadget.gadgetbridge.GBApplication)13 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)9 Context (android.content.Context)7 DeviceCoordinator (nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator)6 Bundle (android.os.Bundle)5 ArrayList (java.util.ArrayList)5 LinkedHashMap (java.util.LinkedHashMap)5 Intent (android.content.Intent)4 Pair (android.util.Pair)4 View (android.view.View)4 TextView (android.widget.TextView)4 ArrayAdapter (android.widget.ArrayAdapter)3 EditText (android.widget.EditText)3 LinearLayout (android.widget.LinearLayout)3 DBHandler (nodomain.freeyourgadget.gadgetbridge.database.DBHandler)3 DaoSession (nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)3 Device (nodomain.freeyourgadget.gadgetbridge.entities.Device)3 AlertDialog (android.app.AlertDialog)2 DatePickerDialog (android.app.DatePickerDialog)2 DialogInterface (android.content.DialogInterface)2