<commit_before>package com.jtmcn.archwiki.viewer;

import android.app.Activity;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.widget.*;

public class WikiActivity extends Activity implements OnClickListener {

    private WikiView wikiViewer;
    LinearLayout titleBar;
    TextView tvTitle;
    String titleString;
    ProgressBar progressBar;
    Button searchButton;
    Button overflowButton;
    Menu optionMenu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();

        setContentView(R.layout.wiki_layout);

        initializeUI();
        setWebSettings();

        // reset historyStacks
        wikiViewer.resetApplication();

        handleIntent(intent);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        setIntent(intent);
        handleIntent(intent);
    }

    private void handleIntent(Intent intent) {
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                optionMenu.findItem(R.id.menu_search).collapseActionView();
            }
            String query = intent.getStringExtra(SearchManager.QUERY);
            String searchUrl = "https://wiki.archlinux.org/index.php?&search="
                    + query;
            wikiViewer.passSearch(searchUrl);
        }
        else if (Intent.ACTION_VIEW.equals(intent.getAction())){
            final String url = intent.getDataString();
            wikiViewer.wikiClient.shouldOverrideUrlLoading(wikiViewer, url);
        }
    }

    public void initializeUI() {
        // associate xml variables
        wikiViewer = (WikiView) findViewById(R.id.wvMain);
        progressBar = (ProgressBar) findViewById(R.id.ProgressBar);

        WikiChromeClient wikiChrome;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            wikiChrome = new WikiChromeClient(progressBar, null, getActionBar());
        } else {
            searchButton = (Button) findViewById(R.id.search);
            searchButton.setOnClickListener(this);

            overflowButton = (Button) findViewById(R.id.overflow);
            overflowButton.setOnClickListener(this);

            tvTitle = (TextView) findViewById(R.id.title);
            wikiChrome = new WikiChromeClient(progressBar, tvTitle, null);
        }

        wikiViewer.setWebChromeClient(wikiChrome);
    }

    public void setWebSettings() {
        WebSettings webSettings = wikiViewer.getSettings();

        SharedPreferences prefs = PreferenceManager
                .getDefaultSharedPreferences(getApplicationContext());

        // due to a known bug, the size cannot be stored in an integer array
        String fontSizePref = prefs.getString("listPref", "2");
        int fontSize = Integer.valueOf(fontSizePref);

        // deprecated method must be used for consistency with variable
        // resolutions and dpi

        switch (fontSize) {
            case 0:
                webSettings.setTextSize(WebSettings.TextSize.SMALLEST);
                break;
            case 1:
                webSettings.setTextSize(WebSettings.TextSize.SMALLER);
                break;
            case 2:
                webSettings.setTextSize(WebSettings.TextSize.NORMAL);
                break;
            case 3:
                webSettings.setTextSize(WebSettings.TextSize.LARGER);
                break;
            case 4:
                webSettings.setTextSize(WebSettings.TextSize.LARGEST);
                break;
        }
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.search:
                onSearchRequested();
                break;
            case R.id.overflow:
                openOptionsMenu();
                break;
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.options, menu);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
            SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
            searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        }
        optionMenu = menu;
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_settings:
                Intent p = new Intent("com.jtmcn.archwiki.viewer.WIKIPREFS");
                startActivityForResult(p, 0);
                break;
            case R.id.menu_share:
                Intent sendIntent = new Intent();
                sendIntent.setAction(Intent.ACTION_SEND);
                sendIntent.putExtra(Intent.EXTRA_TEXT, ArchWikiApplication.getInstance().getCurrentUrl());
                sendIntent.putExtra(Intent.EXTRA_TITLE, ArchWikiApplication.getInstance().getCurrentTitle());
                sendIntent.setType("text/plain");
                startActivity(sendIntent);
                break;<commit_msg>added handling share from home page, which isnt shareable<commit_after>package com.jtmcn.archwiki.viewer;

import android.app.Activity;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.widget.*;

public class WikiActivity extends Activity implements OnClickListener {

    private WikiView wikiViewer;
    LinearLayout titleBar;
    TextView tvTitle;
    String titleString;
    ProgressBar progressBar;
    Button searchButton;
    Button overflowButton;
    Menu optionMenu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();

        setContentView(R.layout.wiki_layout);

        initializeUI();
        setWebSettings();

        // reset historyStacks
        wikiViewer.resetApplication();

        handleIntent(intent);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        setIntent(intent);
        handleIntent(intent);
    }

    private void handleIntent(Intent intent) {
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                optionMenu.findItem(R.id.menu_search).collapseActionView();
            }
            String query = intent.getStringExtra(SearchManager.QUERY);
            String searchUrl = "https://wiki.archlinux.org/index.php?&search="
                    + query;
            wikiViewer.passSearch(searchUrl);
        } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            final String url = intent.getDataString();
            wikiViewer.wikiClient.shouldOverrideUrlLoading(wikiViewer, url);
        }
    }

    public void initializeUI() {
        // associate xml variables
        wikiViewer = (WikiView) findViewById(R.id.wvMain);
        progressBar = (ProgressBar) findViewById(R.id.ProgressBar);

        WikiChromeClient wikiChrome;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            wikiChrome = new WikiChromeClient(progressBar, null, getActionBar());
        } else {
            searchButton = (Button) findViewById(R.id.search);
            searchButton.setOnClickListener(this);

            overflowButton = (Button) findViewById(R.id.overflow);
            overflowButton.setOnClickListener(this);

            tvTitle = (TextView) findViewById(R.id.title);
            wikiChrome = new WikiChromeClient(progressBar, tvTitle, null);
        }

        wikiViewer.setWebChromeClient(wikiChrome);
    }

    public void setWebSettings() {
        WebSettings webSettings = wikiViewer.getSettings();

        SharedPreferences prefs = PreferenceManager
                .getDefaultSharedPreferences(getApplicationContext());

        // due to a known bug, the size cannot be stored in an integer array
        String fontSizePref = prefs.getString("listPref", "2");
        int fontSize = Integer.valueOf(fontSizePref);

        // deprecated method must be used for consistency with variable
        // resolutions and dpi

        switch (fontSize) {
            case 0:
                webSettings.setTextSize(WebSettings.TextSize.SMALLEST);
                break;
            case 1:
                webSettings.setTextSize(WebSettings.TextSize.SMALLER);
                break;
            case 2:
                webSettings.setTextSize(WebSettings.TextSize.NORMAL);
                break;
            case 3:
                webSettings.setTextSize(WebSettings.TextSize.LARGER);
                break;
            case 4:
                webSettings.setTextSize(WebSettings.TextSize.LARGEST);
                break;
        }
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.search:
                onSearchRequested();
                break;
            case R.id.overflow:
                openOptionsMenu();
                break;
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.options, menu);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
            SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
            searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        }
        optionMenu = menu;
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_settings:
                Intent p = new Intent("com.jtmcn.archwiki.viewer.WIKIPREFS");
                startActivityForResult(p, 0);
                break;
            case R.id.menu_share:
                if (ArchWikiApplication.getInstance().getCurrentUrl() != null
                        && !ArchWikiApplication.getInstance().getCurrentUrl().equals("")) {
                    Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.putExtra(Intent.EXTRA_TEXT, ArchWikiApplication.getInstance().getCurrentUrl());
                    sendIntent.putExtra(Intent.EXTRA_TITLE, ArchWikiApplication.getInstance().getCurrentTitle());
                    sendIntent.setType("text/plain");
                    startActivity(sendIntent);
                }
                else {
                    Toast.makeText(this, "Sorry, can't share this page!", Toast.LENGTH_SHORT).show();
                }
                break;
{'fraction_non_alphanumeric': 0.09165808444902163, 'fraction_numerical': 0.001201510470305527, 'mean_word_length': 2.289949181253529, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4661944', 'n_tokens_mistral': 3133, 'n_tokens_neox': 2952, 'n_words': 583}