Search in sources :

Example 1 with SwipeEvents

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

Aggregations

SuppressLint (android.annotation.SuppressLint)1 AlertDialog (android.app.AlertDialog)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 View (android.view.View)1 Animation (android.view.animation.Animation)1 ArrayAdapter (android.widget.ArrayAdapter)1 EditText (android.widget.EditText)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GBApplication (nodomain.freeyourgadget.gadgetbridge.GBApplication)1 BaseActivitySummary (nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary)1 ActivitySummaryItems (nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryItems)1 SwipeEvents (nodomain.freeyourgadget.gadgetbridge.util.SwipeEvents)1