<commit_before>/*
 * Copyright (C) 2009-2014 <NAME> <http://markupartist.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.markupartist.sthlmtraveling;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;

import com.crashlytics.android.Crashlytics;
import com.markupartist.sthlmtraveling.provider.planner.JourneyQuery;
import com.markupartist.sthlmtraveling.provider.site.Site;
import com.markupartist.sthlmtraveling.utils.Analytics;

import java.util.ArrayList;
import java.util.Date;


public class UriLauncherActivity extends Activity {
    private static int INDEX_ORIGIN_NAME = 6;
    private static int INDEX_DESTINATION_NAME = 7;
    private static int INDEX_ORIGIN_ID = 8;
    private static int INDEX_ORIGIN_LAT = 8;
    private static int INDEX_ORIGIN_LON = 9;
    private static int INDEX_DESTINATION_ID = 9;
    private static int INDEX_DATE_TIME = 10;
    private static int INDEX_TIME_MODE = 11;
    private static int INDEX_VIA_ID = 14;
    private static int INDEX_TRAFFIC_MODE = 15;
    private static int INDEX_VIA_NAME = 25;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        launchFromIntent(getIntent());
    }

    protected void launchFromIntent(Intent intent) {
        Uri uri = intent.getData();

        String fullUrl = uri.toString();

        try {
            if (fullUrl.contains("Travel")) {
                handlePlanner(fullUrl);
                return;
            } else if (fullUrl.contains("Realtime")) {
                handleDepartures(fullUrl);
                return;
            }
        } catch (Exception e) {
            Crashlytics.logException(e);
        }
        Intent i = new Intent(this, StartActivity.class);
        startActivity(i);
        finish();
    }

    protected void handleDepartures(String url) {
        String[] parts = TextUtils.split(url, "/");
        Site site = parseSite(parts[5], parts[6], null);
        Intent i = new Intent(this, DeparturesActivity.class);
        i.putExtra(DeparturesActivity.EXTRA_SITE, site);

        Analytics.getInstance(this).event("Launch", "SL", "Departure");

        startActivity(i);
        finish();<commit_msg>Fix NPE when launching from a URI<commit_after>/*
 * Copyright (C) 2009-2014 <NAME> <http://markupartist.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.markupartist.sthlmtraveling;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;

import com.crashlytics.android.Crashlytics;
import com.markupartist.sthlmtraveling.provider.planner.JourneyQuery;
import com.markupartist.sthlmtraveling.provider.site.Site;
import com.markupartist.sthlmtraveling.utils.Analytics;

import java.util.ArrayList;
import java.util.Date;


public class UriLauncherActivity extends Activity {
    private static int INDEX_ORIGIN_NAME = 6;
    private static int INDEX_DESTINATION_NAME = 7;
    private static int INDEX_ORIGIN_ID = 8;
    private static int INDEX_ORIGIN_LAT = 8;
    private static int INDEX_ORIGIN_LON = 9;
    private static int INDEX_DESTINATION_ID = 9;
    private static int INDEX_DATE_TIME = 10;
    private static int INDEX_TIME_MODE = 11;
    private static int INDEX_VIA_ID = 14;
    private static int INDEX_TRAFFIC_MODE = 15;
    private static int INDEX_VIA_NAME = 25;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        launchFromIntent(getIntent());
    }

    protected void launchFromIntent(Intent intent) {
        Uri uri = intent.getData();

        String fullUrl = "";
        if (uri != null) {
            fullUrl = uri.toString();
        }

        try {
            if (fullUrl.contains("Travel")) {
                handlePlanner(fullUrl);
                return;
            } else if (fullUrl.contains("Realtime")) {
                handleDepartures(fullUrl);
                return;
            }
        } catch (Exception e) {
            Crashlytics.logException(e);
        }
        Intent i = new Intent(this, StartActivity.class);
        startActivity(i);
        finish();
    }

    protected void handleDepartures(String url) {
        String[] parts = TextUtils.split(url, "/");
        Site site = parseSite(parts[5], parts[6], null);
        Intent i = new Intent(this, DeparturesActivity.class);
        i.putExtra(DeparturesActivity.EXTRA_SITE, site);

        Analytics.getInstance(this).event("Launch", "SL", "Departure");

        startActivity(i);
        finish();
{'fraction_non_alphanumeric': 0.09117903930131005, 'fraction_numerical': 0.010480349344978166, 'mean_word_length': 3.021067415730337, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5531734', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1635, 'n_words': 469}