Android Open Source - Thrift-box Utils






From Project

Back to project page Thrift-box.

License

The source code is released under:

GNU General Public License

If you think the Android project Thrift-box listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ru.sash0k.thriftbox;
//from ww  w. j  a v  a2  s .c  om
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import java.util.Calendar;

/**
 * ???????????????? ??????
 */
public class Utils {
    public static final String TAG = "THRIFTBOX";
    public static final boolean DEBUG = false;

    public static final char ROUBLE = '\u20BD';
    public static final String ROUBLE_FONT = "fonts/rouble2.ttf";
    public static void log(String msg) {
        if (DEBUG) Log.w(TAG, msg);
    }

    /**
     * ???????? ????????? ???????? ?????.
     * ?????????? ????????? ???????? ? ???????? ??? -1 ??? ???????????? ?????
     */
    public static int parseCurrency(String value) {
        if (value.matches("\\d+(\\.\\d{1,2})?")) {
            final int dot = value.indexOf(".");
            if (dot == -1) return Integer.parseInt(value) * 100; // ??????? ?????? ???
            else {
                int rub = Integer.parseInt(value.substring(0, dot)); // ?????? ??????
                // ?????? ??????
                value = value.substring(dot + 1);
                if (value.length() == 1) value += "0";
                int cop = Integer.parseInt(value);
                return rub * 100 + cop;
            }
        } else return -1;
    }
    // ============================================================================

    /**
     * ??????????? ?????? ? ???????? ????
     */
    public static String formatValue(long value) {
        return value / 100 + "." + String.format("%02d", value % 100);
    }
    // ============================================================================

    /**
     * ????????? ????????? ????? ?????? ??????, ??????, ????????
     */
    public static long[] getTimestamps() {
        final int MILLIS = 1000;
        long[] result = new long[3];
        Calendar c = Calendar.getInstance();
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        result[0] = c.getTimeInMillis() / MILLIS;
        c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
        result[1] = c.getTimeInMillis() / MILLIS;

        Calendar mc = Calendar.getInstance();
        mc.set(Calendar.DAY_OF_MONTH, 1);
        mc.set(Calendar.HOUR_OF_DAY, 0);
        mc.set(Calendar.MINUTE, 0);
        mc.set(Calendar.SECOND, 0);
        result[2] = mc.getTimeInMillis() / MILLIS;
        return result;
    }
    // ============================================================================

    /**
     * ???????? ???????
     */
    public static void updateWidgets(Context context) {
        Intent intent = new Intent(context, Widget.class);
        intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
        int[] ids = AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, Widget.class));
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
        context.sendBroadcast(intent);
    }
    // ============================================================================
}




Java Source Code List

android.support.v4.preference.PreferenceFragment.java
android.support.v4.preference.PreferenceManagerCompat.java
android.widget_fixed.CursorFilter.java
android.widget_fixed.CursorTreeAdapter.java
com.github.mikephil.charting.charts.Chart.java
com.github.mikephil.charting.charts.PieChart.java
com.github.mikephil.charting.charts.PieRadarChartBase.java
com.github.mikephil.charting.data.ChartData.java
com.github.mikephil.charting.data.DataSet.java
com.github.mikephil.charting.data.Entry.java
com.github.mikephil.charting.data.PieDataSet.java
com.github.mikephil.charting.data.PieData.java
com.github.mikephil.charting.data.filter.Approximator.java
com.github.mikephil.charting.exception.DrawingDataSetNotCreatedException.java
com.github.mikephil.charting.interfaces.ChartInterface.java
com.github.mikephil.charting.interfaces.OnChartGestureListener.java
com.github.mikephil.charting.interfaces.OnChartValueSelectedListener.java
com.github.mikephil.charting.interfaces.OnDrawLineChartTouchListener.java
com.github.mikephil.charting.interfaces.OnDrawListener.java
com.github.mikephil.charting.listener.PieRadarChartTouchListener.java
com.github.mikephil.charting.matrix.Vector3.java
com.github.mikephil.charting.renderer.Transformer.java
com.github.mikephil.charting.utils.ColorFormatter.java
com.github.mikephil.charting.utils.ColorTemplate.java
com.github.mikephil.charting.utils.Highlight.java
com.github.mikephil.charting.utils.LabelBase.java
com.github.mikephil.charting.utils.LargeValueFormatter.java
com.github.mikephil.charting.utils.Legend.java
com.github.mikephil.charting.utils.LimitLine.java
com.github.mikephil.charting.utils.MarkerView.java
com.github.mikephil.charting.utils.PointD.java
com.github.mikephil.charting.utils.SelInfo.java
com.github.mikephil.charting.utils.Utils.java
com.github.mikephil.charting.utils.ValueFormatter.java
com.github.mikephil.charting.utils.XLabels.java
com.github.mikephil.charting.utils.YLabels.java
net.margaritov.preference.colorpicker.AlphaPatternDrawable.java
net.margaritov.preference.colorpicker.ColorPickerDialog.java
net.margaritov.preference.colorpicker.ColorPickerPanelView.java
net.margaritov.preference.colorpicker.ColorPickerPreference.java
net.margaritov.preference.colorpicker.ColorPickerView.java
ru.sash0k.thriftbox.AdapterExpenses.java
ru.sash0k.thriftbox.MainActivity.java
ru.sash0k.thriftbox.TypefaceSpan2.java
ru.sash0k.thriftbox.Utils.java
ru.sash0k.thriftbox.Widget.java
ru.sash0k.thriftbox.categories.Categories.java
ru.sash0k.thriftbox.categories.InterceptingHorizontalScrollView.java
ru.sash0k.thriftbox.database.DBProvider.java
ru.sash0k.thriftbox.database.DB.java
ru.sash0k.thriftbox.fragments.CommentDialog.java
ru.sash0k.thriftbox.fragments.DeleteConfirmDialog.java
ru.sash0k.thriftbox.fragments.ExpandableListFragment.java
ru.sash0k.thriftbox.fragments.ExpensesFragment.java
ru.sash0k.thriftbox.fragments.InputFragment.java
ru.sash0k.thriftbox.fragments.PieChartFragment.java
ru.sash0k.thriftbox.fragments.SettingsFragment.java