<commit_before>/*
 * Copyright (C) 2014 <NAME>  <http://gregmeiste.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.meiste.tempalarm.ui;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Dialog;
import android.app.LoaderManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.CursorLoader;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.Loader;
import android.content.SharedPreferences;
import android.content.SyncStatusObserver;
import android.database.Cursor;
import android.preference.PreferenceManager;
import android.support.v4.widget.SimpleCursorAdapter;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
import com.jjoe64.graphview.CustomLabelFormatter;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.GraphViewSeries;
import com.jjoe64.graphview.LineGraphView;
import com.meiste.greg.gcm.GCMHelper;
import com.meiste.tempalarm.AppConstants;
import com.meiste.tempalarm.R;
import com.meiste.tempalarm.backend.registration.Registration;
import com.meiste.tempalarm.provider.RasPiContract;
import com.meiste.tempalarm.sync.AccountUtils;
import com.meiste.tempalarm.sync.SyncAdapter;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import timber.log.Timber;

public class CurrentTemp extends ActionBarActivity
        implements GCMHelper.OnGcmRegistrationListener, LoaderManager.LoaderCallbacks<Cursor> {

    private static final int GPS_REQUEST = 1337;
    private static final int ACCOUNT_PICKER_REQUEST = 1338;

    /**
     * Projection for querying the content provider.
     */
    private static final String[] PROJECTION = new String[]{
            RasPiContract.RasPiReport._ID,
            RasPiContract.RasPiReport.COLUMN_NAME_TIMESTAMP,
            RasPiContract.RasPiReport.COLUMN_NAME_DEGF,
            RasPiContract.RasPiReport.COLUMN_NAME_LIGHT,
    };

    private static final int COLUMN_TIMESTAMP = 1;
    private static final int COLUMN_DEGF = 2;
    private static final int COLUMN_LIGHT = 3;

    /**
     * List of Cursor columns to read from when preparing an adapter to populate the ListView.
     */
    private static final String[] FROM_COLUMNS = new String[]{
            RasPiContract.RasPiReport.COLUMN_NAME_TIMESTAMP,
            RasPiContract.RasPiReport.COLUMN_NAME_DEGF,
            RasPiContract.RasPiReport.COLUMN_NAME_LIGHT,
    };

    /**
     * List of Views which will be populated by Cursor data.
     */
    private static final int[] TO_FIELDS = new int[]{
            R.id.timestamp,
            R.id.degF,
            R.id.lights,
    };

    private Dialog mDialog;
    private Registration mRegService;
    private Object mSyncObserverHandle;
    private Menu mOptionsMenu;
    private SimpleCursorAdapter mAdapter;
    private int mLightThreshold;
    private LineGraphView mGraph;

    @InjectView(R.id.temp_list)
    protected ListView mListView;

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.current_temp);
        ButterKnife.inject(this);

        mAdapter = new SimpleCursorAdapter(this, R.layout.record, null, FROM_COLUMNS, TO_FIELDS, 0);
        mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
            @Override
            public boolean setViewValue(final View view, final Cursor cursor, final int columnIndex) {
                final TextView textView = (TextView) view;
                switch (columnIndex) {
                    case COLUMN_TIMESTAMP:
                        // Convert timestamp to human-readable date
                        textView.setText(DateUtils.formatDateTime(getApplicationContext(),
                                cursor.getLong(columnIndex), AppConstants.DATE_FORMAT_FLAGS));
                        return true;
                    case COLUMN_DEGF:
                        // Restrict to one decimal place
                        textView.setText(String.format("%.1f", cursor.getFloat(columnIndex)));
                        return true;
                    case COLUMN_LIGHT:
                        if (cursor.getInt(columnIndex) < mLightThreshold) {
                            textView.setText(getText(R.string.lights_on));
                        } else {
                            textView.setText(getText(R.string.lights_off));
                        }
                        return true;
                }
                return false;
            }
        });

        final View header = getLayoutInflater().inflate(R.layout.record_header, mListView, false);
        final FrameLayout frameLayout = ButterKnife.findById(header, R.id.graph_placeholder);
        mGraph = new LineGraphView(this, "");
        mGraph.setDrawBackground(true);
        mGraph.setBackgroundColor(getResources().getColor(R.color.primary_graph));
        mGraph.setCustomLabelFormatter(new CustomLabelFormatter() {
            @Override
            public String formatLabel(final double value, final boolean isValueX) {
                if (isValueX) {
                    return DateUtils.formatDateTime(getApplicationContext(),
                            (long) value, AppConstants.DATE_FORMAT_FLAGS_GRAPH);
                }
                return String.format("%.1f", value);
            }
        });<commit_msg>Specify locale to String.format() to resolve lint warning<commit_after>/*
 * Copyright (C) 2014 <NAME>  <http://gregmeiste.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.meiste.tempalarm.ui;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Dialog;
import android.app.LoaderManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.CursorLoader;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.Loader;
import android.content.SharedPreferences;
import android.content.SyncStatusObserver;
import android.database.Cursor;
import android.preference.PreferenceManager;
import android.support.v4.widget.SimpleCursorAdapter;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
import com.jjoe64.graphview.CustomLabelFormatter;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.GraphViewSeries;
import com.jjoe64.graphview.LineGraphView;
import com.meiste.greg.gcm.GCMHelper;
import com.meiste.tempalarm.AppConstants;
import com.meiste.tempalarm.R;
import com.meiste.tempalarm.backend.registration.Registration;
import com.meiste.tempalarm.provider.RasPiContract;
import com.meiste.tempalarm.sync.AccountUtils;
import com.meiste.tempalarm.sync.SyncAdapter;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import butterknife.ButterKnife;
import butterknife.InjectView;
import timber.log.Timber;

public class CurrentTemp extends ActionBarActivity
        implements GCMHelper.OnGcmRegistrationListener, LoaderManager.LoaderCallbacks<Cursor> {

    private static final int GPS_REQUEST = 1337;
    private static final int ACCOUNT_PICKER_REQUEST = 1338;

    /**
     * Projection for querying the content provider.
     */
    private static final String[] PROJECTION = new String[]{
            RasPiContract.RasPiReport._ID,
            RasPiContract.RasPiReport.COLUMN_NAME_TIMESTAMP,
            RasPiContract.RasPiReport.COLUMN_NAME_DEGF,
            RasPiContract.RasPiReport.COLUMN_NAME_LIGHT,
    };

    private static final int COLUMN_TIMESTAMP = 1;
    private static final int COLUMN_DEGF = 2;
    private static final int COLUMN_LIGHT = 3;

    /**
     * List of Cursor columns to read from when preparing an adapter to populate the ListView.
     */
    private static final String[] FROM_COLUMNS = new String[]{
            RasPiContract.RasPiReport.COLUMN_NAME_TIMESTAMP,
            RasPiContract.RasPiReport.COLUMN_NAME_DEGF,
            RasPiContract.RasPiReport.COLUMN_NAME_LIGHT,
    };

    /**
     * List of Views which will be populated by Cursor data.
     */
    private static final int[] TO_FIELDS = new int[]{
            R.id.timestamp,
            R.id.degF,
            R.id.lights,
    };

    private Dialog mDialog;
    private Registration mRegService;
    private Object mSyncObserverHandle;
    private Menu mOptionsMenu;
    private SimpleCursorAdapter mAdapter;
    private int mLightThreshold;
    private LineGraphView mGraph;

    @InjectView(R.id.temp_list)
    protected ListView mListView;

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.current_temp);
        ButterKnife.inject(this);

        mAdapter = new SimpleCursorAdapter(this, R.layout.record, null, FROM_COLUMNS, TO_FIELDS, 0);
        mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
            @Override
            public boolean setViewValue(final View view, final Cursor cursor, final int columnIndex) {
                final TextView textView = (TextView) view;
                switch (columnIndex) {
                    case COLUMN_TIMESTAMP:
                        // Convert timestamp to human-readable date
                        textView.setText(DateUtils.formatDateTime(getApplicationContext(),
                                cursor.getLong(columnIndex), AppConstants.DATE_FORMAT_FLAGS));
                        return true;
                    case COLUMN_DEGF:
                        // Restrict to one decimal place
                        textView.setText(String.format("%.1f", cursor.getFloat(columnIndex)));
                        return true;
                    case COLUMN_LIGHT:
                        if (cursor.getInt(columnIndex) < mLightThreshold) {
                            textView.setText(getText(R.string.lights_on));
                        } else {
                            textView.setText(getText(R.string.lights_off));
                        }
                        return true;
                }
                return false;
            }
        });

        final View header = getLayoutInflater().inflate(R.layout.record_header, mListView, false);
        final FrameLayout frameLayout = ButterKnife.findById(header, R.id.graph_placeholder);
        mGraph = new LineGraphView(this, "");
        mGraph.setDrawBackground(true);
        mGraph.setBackgroundColor(getResources().getColor(R.color.primary_graph));
        mGraph.setCustomLabelFormatter(new CustomLabelFormatter() {
            @Override
            public String formatLabel(final double value, final boolean isValueX) {
                if (isValueX) {
                    return DateUtils.formatDateTime(getApplicationContext(),
                            (long) value, AppConstants.DATE_FORMAT_FLAGS_GRAPH);
                }
                return String.format(Locale.getDefault(), "%.1f", value);
            }
        });
{'fraction_non_alphanumeric': 0.08163575554879902, 'fraction_numerical': 0.00486470051687443, 'mean_word_length': 2.8258214597266647, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '3831865', 'n_tokens_mistral': 3614, 'n_tokens_neox': 3504, 'n_words': 836}