Example usage for android.view ContextThemeWrapper ContextThemeWrapper

List of usage examples for android.view ContextThemeWrapper ContextThemeWrapper

Introduction

In this page you can find the example usage for android.view ContextThemeWrapper ContextThemeWrapper.

Prototype

public ContextThemeWrapper(Context base, Resources.Theme theme) 

Source Link

Document

Creates a new context wrapper with the specified theme.

Usage

From source file:pl.mrwojtek.sensrec.app.SamplingPeriodDialog.java

@NonNull
@Override//from  w  w  w .j  a  v  a 2 s.  co m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), R.style.DialogTheme);
    LayoutInflater inflater = getActivity().getLayoutInflater().cloneInContext(context);
    View view = inflater.inflate(R.layout.sampling_period_dialog, null);

    initializeSamplingSpinner(view);
    initializeMillisecondsEdit(view);

    if (savedInstanceState == null) {
        setFromPreferences();
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.DialogTheme);
    builder.setTitle(R.string.sampling_period_title);
    builder.setView(view);
    builder.setNegativeButton(R.string.action_cancel, null);
    builder.setPositiveButton(R.string.action_ok, this);
    return MaterialUtils.fixTitle(context, builder.create(), this);
}

From source file:nz.ac.otago.psyanlab.common.designer.assets.AssetDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    inflater.cloneInContext(new ContextThemeWrapper(getActivity(), android.R.style.Theme_Holo_Light));
    return inflater.inflate(R.layout.fragment_designer_asset_detail, container, false);
}

From source file:lewa.support.v7.internal.widget.AbsActionBarView.java

AbsActionBarView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    ///LEWA ADD BEGIN
    this.mContext = context;
    ///LEWA ADD END
    final TypedValue tv = new TypedValue();
    if (context.getTheme().resolveAttribute(R.attr.actionBarPopupTheme, tv, true) && tv.resourceId != 0) {
        mPopupContext = new ContextThemeWrapper(context, tv.resourceId);
    } else {//from  w ww  .j  a va 2s . co  m
        mPopupContext = context;
    }
}

From source file:com.klick.plugins.listviewalert.ListViewAlert.java

public void loadList(final JSONArray thelist, final CallbackContext callbackContext) {
    final CordovaInterface cordova = this.cordova;
    Runnable runnable = new Runnable() {
        public void run() {
            List<String> list = new ArrayList<String>();
            // we start with index 1 because index 0 is the title
            for (int x = 1; x < thelist.length(); x++) {
                try {
                    list.add(thelist.getString(x));
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }/*from  w ww . j av  a  2 s  .  c om*/
            }
            CharSequence[] items = list.toArray(new CharSequence[list.size()]);
            AlertDialog.Builder builder = new AlertDialog.Builder(
                    new ContextThemeWrapper(cordova.getActivity(), android.R.style.Theme_Holo_Dialog));
            try {
                builder.setTitle(thelist.getString(0));
                // builder.setMessage( "This is a hardcoded message to try whether or not this is feasible!");
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } // index 0 contains the title
            builder.setItems(items, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    dialog.dismiss();
                    // we +1 to item because item starts from 0, but from
                    // thelist[0], that was the title...
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, item + 1));
                    //callbackContext.sendPluginResult(pluginResult)
                }
            });
            AlertDialog alert = builder.create();
            alert.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            alert.show();
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:com.example.android.leanback.CardPresenter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    Log.d(TAG, "onCreateViewHolder");
    Context context = parent.getContext();
    if (mCardThemeResId != 0) {
        if (mContextThemeWrapper == null) {
            mContextThemeWrapper = new ContextThemeWrapper(context, mCardThemeResId);
        }//  w  w w  .j  av a2  s .  c  o  m
        context = mContextThemeWrapper;
    }
    ImageCardView v = new ImageCardView(context);
    v.setFocusable(true);
    v.setFocusableInTouchMode(true);
    // Randomly makes image view crop as a square or just stretch to original
    // aspect ratio.
    if (sRand.nextBoolean()) {
        v.setMainImageAdjustViewBounds(false);
        v.setMainImageDimensions(getRowHeight(parent.getContext()), getRowHeight(parent.getContext()));
    } else {
        v.setMainImageAdjustViewBounds(true);
        v.setMainImageDimensions(LayoutParams.WRAP_CONTENT, getRowHeight(parent.getContext()));
    }
    return new ViewHolder(v);
}

From source file:org.ciasaboark.tacere.activity.fragment.EventDetailsFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    setStyle(DialogFragment.STYLE_NORMAL, R.style.Dialog);

    long instanceId = getArguments().getLong("instanceId");
    context = getActivity();//from  w  w w.  j  ava 2 s .  co m
    dataSetManager = new DataSetManager(this, context);
    databaseInterface = DatabaseInterface.getInstance(context);
    prefs = new Prefs(context);
    authenticator = new Authenticator(context);

    try {
        event = databaseInterface.getEvent(instanceId);
    } catch (NoSuchEventInstanceException e) {
        Log.e(TAG, "unable to find event with id " + instanceId);
        return null;
    }

    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(
            new ContextThemeWrapper(getActivity(), R.style.Dialog));
    view = getActivity().getLayoutInflater().inflate(R.layout.dialog_event_longclick, null);
    setupWidgetsForView();
    dialogBuilder.setView(view);

    //the clear button should only be visible if the event has a custom ringer or if the events
    //series has a custom ringer set
    EventManager eventManager = new EventManager(context, event);

    if (eventManager.getRingerSource() == RingerSource.EVENT_SERIES
            || eventManager.getRingerSource() == RingerSource.INSTANCE) {
        dialogBuilder.setNegativeButton(R.string.clear, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                resetEvent();
            }
        });

    }

    dialogBuilder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            //nothing to do here
        }
    });

    dialogBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            saveSettings();
        }
    });

    //the positive button should only be enabled if the selected ringer is not UNDEFINED
    AlertDialog dialog = dialogBuilder.create();
    dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    return dialog;
}

From source file:org.fdroid.fdroid.privileged.views.UninstallDialogActivity.java

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

    final Intent intent = getIntent();
    final String packageName = intent.getStringExtra(Installer.EXTRA_PACKAGE_NAME);

    PackageManager pm = getPackageManager();

    ApplicationInfo appInfo;//from w  w  w  .j a  v a  2  s. c o  m
    try {
        //noinspection WrongConstant (lint is actually wrong here!)
        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
    } catch (PackageManager.NameNotFoundException e) {
        throw new RuntimeException("Failed to get ApplicationInfo for uninstalling");
    }

    final boolean isSystem = (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
    final boolean isUpdate = (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;

    if (isSystem && !isUpdate) {
        // Cannot remove system apps unless we're uninstalling updates
        throw new RuntimeException("Cannot remove system apps unless we're uninstalling updates");
    }

    int messageId;
    if (isUpdate) {
        messageId = R.string.uninstall_update_confirm;
    } else {
        messageId = R.string.uninstall_confirm;
    }

    // hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay
    ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());

    final AlertDialog.Builder builder = new AlertDialog.Builder(theme);
    builder.setTitle(appInfo.loadLabel(pm));
    builder.setIcon(appInfo.loadIcon(pm));
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent data = new Intent();
            data.putExtra(Installer.EXTRA_PACKAGE_NAME, packageName);
            setResult(Activity.RESULT_OK, intent);
            finish();
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
    });
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
    });
    builder.setMessage(messageId);
    builder.create().show();
}

From source file:org.mariotaku.twidere.preference.ThemePreviewPreference.java

@Override
protected View onCreateView(final ViewGroup parent) {
    final Context context = getContext();
    final int themeResource = ThemeUtils.getNoActionBarThemeResource(context);
    final Context theme = new ContextThemeWrapper(context, themeResource);
    final LayoutInflater inflater = LayoutInflater.from(theme);
    try {//from   w ww.  j av a2s  .c om
        final View view = inflater.inflate(R.layout.theme_preview, parent, false);
        setPreviewView(theme, view.findViewById(R.id.theme_preview_content), themeResource);
        return view;
    } catch (InflateException e) {
        if (e.getCause() instanceof InvocationTargetException) {
            e.getCause().getCause().printStackTrace();
        }
        throw e;
    }
}

From source file:com.koushikdutta.desksms.plugin.EditActivity.java

/**
 * {@inheritDoc}//from  w  ww  .j  a v  a 2 s.  c o  m
 */
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /*
     * A hack to prevent a private serializable classloader attack
     */
    BundleManager.scrub(getIntent());
    BundleManager.scrub(getIntent().getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE));

    setContentView(R.layout.main);

    setTitle(BreadCrumber.generateBreadcrumb(getApplicationContext(), getIntent(),
            getString(R.string.plugin_name)));

    final FrameLayout frame = (FrameLayout) findViewById(R.id.frame);
    frame.addView(getLayoutInflater().cloneInContext(new ContextThemeWrapper(this, R.style.Theme_Locale_Light))
            .inflate(R.layout.frame, frame, false));

    bindUIElements();
    /*
     * if savedInstanceState == null, then then this is a new Activity instance and a check for EXTRA_BUNDLE is needed
     */
    if (savedInstanceState == null) {
        final Bundle forwardedBundle = getIntent()
                .getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE);

        if (BundleManager.isBundleValid(forwardedBundle)) {
            if (forwardedBundle.containsKey(BundleManager.BUNDLE_EXTRA_FORWARD_EMAIL)) {
                boolean enabled = forwardedBundle.getBoolean(BundleManager.BUNDLE_EXTRA_FORWARD_EMAIL);
                mChkEmail.setChecked(true);
                mToggleEmail.setChecked(enabled);
            } else {
                mChkEmail.setChecked(false);
                mToggleEmail.setEnabled(false);
            }

            if (forwardedBundle.containsKey(BundleManager.BUNDLE_EXTRA_FORWARD_WEB)) {
                boolean enabled = forwardedBundle.getBoolean(BundleManager.BUNDLE_EXTRA_FORWARD_WEB);
                mChkWeb.setChecked(true);
                mToggleWeb.setChecked(enabled);
            } else {
                mChkWeb.setChecked(false);
                mToggleWeb.setEnabled(false);
            }

            if (forwardedBundle.containsKey(BundleManager.BUNDLE_EXTRA_FORWARD_XMPP)) {
                boolean enabled = forwardedBundle.getBoolean(BundleManager.BUNDLE_EXTRA_FORWARD_XMPP);
                mChkXMPP.setChecked(true);
                mToggleXMPP.setChecked(enabled);
            } else {
                mChkXMPP.setChecked(false);
                mToggleXMPP.setEnabled(false);
            }
        } else {
            setDefaults();
        }
    }
}

From source file:com.koushikdutta.desktopsms.plugin.EditActivity.java

/**
 * {@inheritDoc}//from   ww w .j  a va 2  s .  c  o  m
 */
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /*
     * A hack to prevent a private serializable classloader attack
     */
    BundleManager.scrub(getIntent());
    BundleManager.scrub(getIntent().getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE));

    setContentView(R.layout.plugin);

    setTitle(BreadCrumber.generateBreadcrumb(getApplicationContext(), getIntent(),
            getString(R.string.plugin_name)));

    final FrameLayout frame = (FrameLayout) findViewById(R.id.frame);
    frame.addView(getLayoutInflater().cloneInContext(new ContextThemeWrapper(this, R.style.Theme_Locale_Light))
            .inflate(R.layout.frame, frame, false));

    bindUIElements();
    /*
     * if savedInstanceState == null, then then this is a new Activity instance and a check for EXTRA_BUNDLE is needed
     */
    if (savedInstanceState == null) {
        final Bundle forwardedBundle = getIntent()
                .getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE);

        if (BundleManager.isBundleValid(forwardedBundle)) {
            if (forwardedBundle.containsKey(BundleManager.BUNDLE_EXTRA_FORWARD_EMAIL)) {
                boolean enabled = forwardedBundle.getBoolean(BundleManager.BUNDLE_EXTRA_FORWARD_EMAIL);
                mChkEmail.setChecked(true);
                mToggleEmail.setChecked(enabled);
            } else {
                mChkEmail.setChecked(false);
                mToggleEmail.setEnabled(false);
            }

            if (forwardedBundle.containsKey(BundleManager.BUNDLE_EXTRA_FORWARD_WEB)) {
                boolean enabled = forwardedBundle.getBoolean(BundleManager.BUNDLE_EXTRA_FORWARD_WEB);
                mChkWeb.setChecked(true);
                mToggleWeb.setChecked(enabled);
            } else {
                mChkWeb.setChecked(false);
                mToggleWeb.setEnabled(false);
            }

            if (forwardedBundle.containsKey(BundleManager.BUNDLE_EXTRA_FORWARD_XMPP)) {
                boolean enabled = forwardedBundle.getBoolean(BundleManager.BUNDLE_EXTRA_FORWARD_XMPP);
                mChkXMPP.setChecked(true);
                mToggleXMPP.setChecked(enabled);
            } else {
                mChkXMPP.setChecked(false);
                mToggleXMPP.setEnabled(false);
            }
        } else {
            setDefaults();
        }
    }
}