Example usage for android.util TypedValue TypedValue

List of usage examples for android.util TypedValue TypedValue

Introduction

In this page you can find the example usage for android.util TypedValue TypedValue.

Prototype

TypedValue

Source Link

Usage

From source file:android.support.v17.leanback.app.GuidedStepFragment.java

private void resolveTheme() {
    // Look up the guidedStepTheme in the currently specified theme.  If it exists,
    // replace the theme with its value.
    Activity activity = getActivity();// w  w  w  .  ja v a 2  s . com
    if (mTheme == -1 && !isGuidedStepTheme(activity)) {
        // Look up the guidedStepTheme in the activity's currently specified theme.  If it
        // exists, replace the theme with its value.
        int resId = R.attr.guidedStepTheme;
        TypedValue typedValue = new TypedValue();
        boolean found = activity.getTheme().resolveAttribute(resId, typedValue, true);
        if (DEBUG)
            Log.v(TAG, "Found guided step theme reference? " + found);
        if (found) {
            ContextThemeWrapper themeWrapper = new ContextThemeWrapper(activity, typedValue.resourceId);
            if (isGuidedStepTheme(themeWrapper)) {
                mTheme = typedValue.resourceId;
                mThemeWrapper = themeWrapper;
            } else {
                found = false;
                mThemeWrapper = null;
            }
        }
        if (!found) {
            Log.e(TAG, "GuidedStepFragment does not have an appropriate theme set.");
        }
    } else if (mTheme != -1) {
        mThemeWrapper = new ContextThemeWrapper(activity, mTheme);
    }
}

From source file:android.support.v17.leanback.app.GuidedStepSupportFragment.java

private void resolveTheme() {
    // Look up the guidedStepTheme in the currently specified theme.  If it exists,
    // replace the theme with its value.
    FragmentActivity activity = getActivity();
    if (mTheme == -1 && !isGuidedStepTheme(activity)) {
        // Look up the guidedStepTheme in the activity's currently specified theme.  If it
        // exists, replace the theme with its value.
        int resId = R.attr.guidedStepTheme;
        TypedValue typedValue = new TypedValue();
        boolean found = activity.getTheme().resolveAttribute(resId, typedValue, true);
        if (DEBUG)
            Log.v(TAG, "Found guided step theme reference? " + found);
        if (found) {
            ContextThemeWrapper themeWrapper = new ContextThemeWrapper(activity, typedValue.resourceId);
            if (isGuidedStepTheme(themeWrapper)) {
                mTheme = typedValue.resourceId;
                mThemeWrapper = themeWrapper;
            } else {
                found = false;//from   ww  w.j a  v a 2 s. c o  m
                mThemeWrapper = null;
            }
        }
        if (!found) {
            Log.e(TAG, "GuidedStepSupportFragment does not have an appropriate theme set.");
        }
    } else if (mTheme != -1) {
        mThemeWrapper = new ContextThemeWrapper(activity, mTheme);
    }
}

From source file:com.google.samples.apps.iosched.ui.BaseActivity.java

/**
 * Returns true if the theme sets the {@code R.attr.isFloatingWindow} flag to true.
 *//*from w w w  . j  av  a  2 s . co m*/
protected boolean shouldBeFloatingWindow() {
    Resources.Theme theme = getTheme();
    TypedValue floatingWindowFlag = new TypedValue();

    // Check isFloatingWindow flag is defined in theme.
    if (theme == null || !theme.resolveAttribute(R.attr.isFloatingWindow, floatingWindowFlag, true)) {
        return false;
    }

    return (floatingWindowFlag.data != 0);
}

From source file:com.ichi2.anki.AbstractFlashcardViewer.java

protected void initTimer() {
    final TypedValue typedValue = new TypedValue();
    mShowTimer = mCurrentCard.showTimer();
    if (mShowTimer && mCardTimer.getVisibility() == View.INVISIBLE) {
        mCardTimer.setVisibility(View.VISIBLE);
    } else if (!mShowTimer && mCardTimer.getVisibility() != View.INVISIBLE) {
        mCardTimer.setVisibility(View.INVISIBLE);
    }/*from   w w  w. j  a  v  a  2  s . com*/
    // Set normal timer color
    getTheme().resolveAttribute(android.R.attr.textColor, typedValue, true);
    mCardTimer.setTextColor(typedValue.data);

    mCardTimer.setBase(SystemClock.elapsedRealtime());
    mCardTimer.start();

    // Stop and highlight the timer if it reaches the time limit.
    getTheme().resolveAttribute(R.attr.maxTimerColor, typedValue, true);
    final int limit = mCurrentCard.timeLimit();
    mCardTimer.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
        @Override
        public void onChronometerTick(Chronometer chronometer) {
            long elapsed = SystemClock.elapsedRealtime() - chronometer.getBase();
            if (elapsed >= limit) {
                chronometer.setTextColor(typedValue.data);
                chronometer.stop();
            }
        }
    });
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

private Notification getEnforcingNotification(int allowed, int blocked, int hosts) {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_security_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_started)).setContentIntent(pi).setColor(tv.data)
            .setOngoing(true).setAutoCancel(false);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET)
                .setPriority(Notification.PRIORITY_MIN);
    }/*from www  .j a  v  a  2  s .co  m*/

    if (allowed > 0 || blocked > 0 || hosts > 0) {
        NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
        notification.bigText(getString(R.string.msg_started));
        if (Util.isPlayStoreInstall(this))
            notification.setSummaryText(getString(R.string.msg_packages, allowed, blocked));
        else
            notification.setSummaryText(getString(R.string.msg_hosts, allowed, blocked, hosts));
        return notification.build();
    } else
        return builder.build();
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

private Notification getWaitingNotification() {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_security_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_waiting)).setContentIntent(pi).setColor(tv.data)
            .setOngoing(true).setAutoCancel(false);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET)
                .setPriority(Notification.PRIORITY_MIN);
    }//  w w  w  .jav a 2s . com

    return builder.build();
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

private void showDisabledNotification() {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_revoked)).setContentIntent(pi).setColor(tv.data)
            .setOngoing(false).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
    }/*from w w w .j  av a  2 s  .c  o  m*/

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_revoked));

    NotificationManagerCompat.from(this).notify(NOTIFY_DISABLED, notification.build());
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

private void showAutoStartNotification() {
    Intent main = new Intent(this, ActivityMain.class);
    main.putExtra(ActivityMain.EXTRA_APPROVE, true);
    PendingIntent pi = PendingIntent.getActivity(this, NOTIFY_AUTOSTART, main,
            PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_autostart)).setContentIntent(pi).setColor(tv.data)
            .setOngoing(false).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
    }/*w w  w . j a  v  a  2s  . co  m*/

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_autostart));

    NotificationManagerCompat.from(this).notify(NOTIFY_AUTOSTART, notification.build());
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

private void showExitNotification(String reason) {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_error)).setContentIntent(pi).setColor(tv.data)
            .setOngoing(false).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
    }//ww  w  . j  av  a 2s .  co  m

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_error));
    notification.setSummaryText(reason);

    NotificationManagerCompat.from(this).notify(NOTIFY_EXIT, notification.build());
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

private void showErrorNotification(int error, String message) {
    Intent main = new Intent(this, ActivityMain.class);
    main.putExtra(ActivityMain.EXTRA_LOGCAT, true);
    PendingIntent pi = PendingIntent.getActivity(this, NOTIFY_ERROR, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(message).setContentIntent(pi).setNumber(error).setColor(tv.data).setOngoing(false)
            .setAutoCancel(true);/*from  ww w.j  a  va 2s . c o  m*/

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
    }

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(message);

    NotificationManagerCompat.from(this).notify(error + 100, notification.build());
}