Search in sources :

Example 11 with Resources

use of android.content.res.Resources in project nmid-headline by miao1007.

the class NavigationItemsAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    if (v == null) {
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = inflater.inflate(R.layout.item_navigation, null);
    }
    NavItem item = mDataset.get(position);
    if (item != null) {
        ImageView mIcon = (ImageView) v.findViewById(R.id.navigation_item_icon);
        TextView mTitle = (TextView) v.findViewById(R.id.navigation_item_title);
        mIcon.setImageResource(item.getIcon());
        mTitle.setText(item.getTitle());
        Resources res = getContext().getResources();
        int transparentColor = res.getColor(android.R.color.transparent);
        int selectedBackgroundColor = res.getColor(R.color.separator_light);
        int selectedItemColor = res.getColor(R.color.primarg_bg);
        int unselectedItemColor = res.getColor(R.color.text_gray);
        v.setBackgroundColor(position == selectedItem ? selectedBackgroundColor : transparentColor);
        mTitle.setTextColor(position == selectedItem ? selectedItemColor : unselectedItemColor);
        mIcon.setColorFilter(position == selectedItem ? selectedItemColor : unselectedItemColor, PorterDuff.Mode.SRC_ATOP);
    }
    return v;
}
Also used : LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Resources(android.content.res.Resources) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View)

Example 12 with Resources

use of android.content.res.Resources in project AndroidTraining by mixi-inc.

the class SuggestionsAdapter method getTheDrawable.

public Drawable getTheDrawable(Uri uri) throws FileNotFoundException {
    String authority = uri.getAuthority();
    Resources r;
    if (TextUtils.isEmpty(authority)) {
        throw new FileNotFoundException("No authority: " + uri);
    } else {
        try {
            r = mContext.getPackageManager().getResourcesForApplication(authority);
        } catch (NameNotFoundException ex) {
            throw new FileNotFoundException("No package found for authority: " + uri);
        }
    }
    List<String> path = uri.getPathSegments();
    if (path == null) {
        throw new FileNotFoundException("No path: " + uri);
    }
    int len = path.size();
    int id;
    if (len == 1) {
        try {
            id = Integer.parseInt(path.get(0));
        } catch (NumberFormatException e) {
            throw new FileNotFoundException("Single path segment is not a resource ID: " + uri);
        }
    } else if (len == 2) {
        id = r.getIdentifier(path.get(1), path.get(0), authority);
    } else {
        throw new FileNotFoundException("More than two path segments: " + uri);
    }
    if (id == 0) {
        throw new FileNotFoundException("No resource found for: " + uri);
    }
    return r.getDrawable(id);
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) FileNotFoundException(java.io.FileNotFoundException) SpannableString(android.text.SpannableString) Resources(android.content.res.Resources)

Example 13 with Resources

use of android.content.res.Resources in project LollipopShowcase by mikepenz.

the class AppInfo method getEnglishRessources.

public Resources getEnglishRessources(Resources standardResources) {
    AssetManager assets = standardResources.getAssets();
    DisplayMetrics metrics = standardResources.getDisplayMetrics();
    Configuration config = new Configuration(standardResources.getConfiguration());
    config.locale = Locale.US;
    return new Resources(assets, metrics, config);
}
Also used : AssetManager(android.content.res.AssetManager) Configuration(android.content.res.Configuration) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics)

Example 14 with Resources

use of android.content.res.Resources in project AndroidTraining by mixi-inc.

the class MenuBuilder method setHeaderInternal.

private void setHeaderInternal(final int titleRes, final CharSequence title, final int iconRes, final Drawable icon, final View view) {
    final Resources r = getResources();
    if (view != null) {
        mHeaderView = view;
        // If using a custom view, then the title and icon aren't used
        mHeaderTitle = null;
        mHeaderIcon = null;
    } else {
        if (titleRes > 0) {
            mHeaderTitle = r.getText(titleRes);
        } else if (title != null) {
            mHeaderTitle = title;
        }
        if (iconRes > 0) {
            mHeaderIcon = r.getDrawable(iconRes);
        } else if (icon != null) {
            mHeaderIcon = icon;
        }
        // If using the title or icon, then a custom view isn't used
        mHeaderView = null;
    }
    // Notify of change
    onItemsChanged(false);
}
Also used : Resources(android.content.res.Resources)

Example 15 with Resources

use of android.content.res.Resources in project AndroidTraining by mixi-inc.

the class SearchView method createVoiceAppSearchIntent.

/**
     * Create and return an Intent that can launch the voice search activity, perform a specific
     * voice transcription, and forward the results to the searchable activity.
     *
     * @param baseIntent The voice app search intent to start from
     * @return A completely-configured intent ready to send to the voice search activity
     */
private Intent createVoiceAppSearchIntent(Intent baseIntent, SearchableInfo searchable) {
    ComponentName searchActivity = searchable.getSearchActivity();
    // create the necessary intent to set up a search-and-forward operation
    // in the voice search system.   We have to keep the bundle separate,
    // because it becomes immutable once it enters the PendingIntent
    Intent queryIntent = new Intent(Intent.ACTION_SEARCH);
    queryIntent.setComponent(searchActivity);
    PendingIntent pending = PendingIntent.getActivity(getContext(), 0, queryIntent, PendingIntent.FLAG_ONE_SHOT);
    // Now set up the bundle that will be inserted into the pending intent
    // when it's time to do the search.  We always build it here (even if empty)
    // because the voice search activity will always need to insert "QUERY" into
    // it anyway.
    Bundle queryExtras = new Bundle();
    // Now build the intent to launch the voice search.  Add all necessary
    // extras to launch the voice recognizer, and then all the necessary extras
    // to forward the results to the searchable activity
    Intent voiceIntent = new Intent(baseIntent);
    // Add all of the configuration options supplied by the searchable's metadata
    String languageModel = RecognizerIntent.LANGUAGE_MODEL_FREE_FORM;
    String prompt = null;
    String language = null;
    int maxResults = 1;
    Resources resources = getResources();
    if (searchable.getVoiceLanguageModeId() != 0) {
        languageModel = resources.getString(searchable.getVoiceLanguageModeId());
    }
    if (searchable.getVoicePromptTextId() != 0) {
        prompt = resources.getString(searchable.getVoicePromptTextId());
    }
    if (searchable.getVoiceLanguageId() != 0) {
        language = resources.getString(searchable.getVoiceLanguageId());
    }
    if (searchable.getVoiceMaxResults() != 0) {
        maxResults = searchable.getVoiceMaxResults();
    }
    voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, languageModel);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxResults);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, searchActivity == null ? null : searchActivity.flattenToShortString());
    // Add the values that configure forwarding the results
    voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, pending);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT_BUNDLE, queryExtras);
    return voiceIntent;
}
Also used : Bundle(android.os.Bundle) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent) PendingIntent(android.app.PendingIntent) SuggestionsAdapter.getColumnString(com.actionbarsherlock.widget.SuggestionsAdapter.getColumnString) Resources(android.content.res.Resources)

Aggregations

Resources (android.content.res.Resources)3195 Context (android.content.Context)292 Intent (android.content.Intent)280 View (android.view.View)236 TextView (android.widget.TextView)214 IOException (java.io.IOException)209 PackageManager (android.content.pm.PackageManager)206 Drawable (android.graphics.drawable.Drawable)197 Paint (android.graphics.Paint)178 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)176 Bitmap (android.graphics.Bitmap)174 DisplayMetrics (android.util.DisplayMetrics)165 Configuration (android.content.res.Configuration)151 Point (android.graphics.Point)151 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)137 ArrayList (java.util.ArrayList)134 XmlResourceParser (android.content.res.XmlResourceParser)132 TypedArray (android.content.res.TypedArray)129 Test (org.junit.Test)126 PendingIntent (android.app.PendingIntent)122