List of usage examples for android.app Activity getResources
@Override
public Resources getResources()
From source file:com.google.plus.wigwamnow.social.FacebookProvider.java
/** * Create a share action for the {@link Wigwam} on the Open Graph. *///from w ww . j a v a 2 s .com @Override public boolean structuredShare(Wigwam wigwam, Activity activity) { Session session = Session.getActiveSession(); if (session == null || !session.isOpened()) { return false; } if (!hasPublishPermissions()) { // Get user's permission to post OG Actions requestPublishPermissions(session, activity); return false; } final Activity hostActivity = activity; String postingString = activity.getResources().getString(R.string.posting); showProgressDialog(postingString, activity); final Wigwam toShare = wigwam; AsyncTask<Void, Void, Response> task = new AsyncTask<Void, Void, Response>() { @Override protected Response doInBackground(Void... params) { ShareAction shareAction = GraphObject.Factory.create(ShareAction.class); WigwamGraphObject wigwamObject = GraphObject.Factory.create(WigwamGraphObject.class); // Set wigwam URL String host = hostActivity.getResources().getString(R.string.external_host); String wigwamUrl = host + "/wigwams/" + toShare.getId().toString(); wigwamObject.setUrl(wigwamUrl); // Add wigwam shareAction.setWigwam(wigwamObject); // Post to OpenGraph Request request = new Request(Session.getActiveSession(), SHARE_ACTION_PATH, null, HttpMethod.POST); request.setGraphObject(shareAction); return request.executeAndWait(); } @Override protected void onPostExecute(Response response) { onPostActionResponse(response, hostActivity); } }; task.execute(); return true; }
From source file:us.phyxsi.gameshelf.ui.FeedAdapter.java
public FeedAdapter(Activity hostActivity, Context context, DataLoadingSubject dataLoading, int columns) { this.host = hostActivity; this.context = context; this.dataLoading = dataLoading; dataLoading.addCallbacks(this); this.columns = columns; layoutInflater = LayoutInflater.from(host); comparator = new BoardgameComparator(); items = new ArrayList<>(); setHasStableIds(true);/* w ww . j a v a 2s . c o m*/ TypedArray placeholderColors = hostActivity.getResources().obtainTypedArray(R.array.loading_placeholders); shotLoadingPlaceholders = new ColorDrawable[placeholderColors.length()]; for (int i = 0; i < placeholderColors.length(); i++) { shotLoadingPlaceholders[i] = new ColorDrawable(placeholderColors.getColor(i, Color.DKGRAY)); } }
From source file:com.google.plus.wigwamnow.social.FacebookProvider.java
/** * Create a rental action for the {@link Wigwam} on the Open Graph. *//*from w w w.j a v a 2 s . c o m*/ @Override public boolean rent(Wigwam wigwam, Activity activity) { // Write an OpenGraph action to Facebook Session session = Session.getActiveSession(); if (session == null || !session.isOpened()) { return false; } if (!hasPublishPermissions()) { // Get user's permission to post OG Actions requestPublishPermissions(session, activity); return false; } String postingString = activity.getResources().getString(R.string.posting); showProgressDialog(postingString, activity); final Wigwam toShare = wigwam; final Activity hostActivity = activity; AsyncTask<Void, Void, Response> task = new AsyncTask<Void, Void, Response>() { @Override protected Response doInBackground(Void... params) { RentAction rentAction = GraphObject.Factory.create(RentAction.class); WigwamGraphObject wigwamObject = GraphObject.Factory.create(WigwamGraphObject.class); // Set wigwam URL String host = hostActivity.getResources().getString(R.string.external_host); String wigwamUrl = host + "/wigwams/" + toShare.getId().toString(); wigwamObject.setUrl(wigwamUrl); // Add wigwam rentAction.setWigwam(wigwamObject); // Post to OpenGraph Request request = new Request(Session.getActiveSession(), RENT_ACTION_PATH, null, HttpMethod.POST); request.setGraphObject(rentAction); return request.executeAndWait(); } @Override protected void onPostExecute(Response response) { onPostActionResponse(response, hostActivity); } }; task.execute(); return true; }
From source file:org.openqa.selendroid.server.model.DefaultSelendroidDriver.java
@Override @SuppressWarnings("deprecation") public byte[] takeScreenshot() { ViewHierarchyAnalyzer viewAnalyzer = ViewHierarchyAnalyzer.getDefaultInstance(); // TODO ddary review later, but with getRecentDecorView() it seems to work better // long drawingTime = 0; // View container = null; // for (View view : viewAnalyzer.getTopLevelViews()) { // if (view != null && view.isShown() && view.hasWindowFocus() // && view.getDrawingTime() > drawingTime) { // container = view; // drawingTime = view.getDrawingTime(); // }//from w ww .jav a2 s .c om // } // final View mainView = container; final View mainView = viewAnalyzer.getRecentDecorView(); if (mainView == null) { throw new SelendroidException("No open windows."); } done = false; long end = System.currentTimeMillis() + serverInstrumentation.getAndroidWait().getTimeoutInMillis(); final byte[][] rawPng = new byte[1][1]; ServerInstrumentation.getInstance().getCurrentActivity().runOnUiThread(new Runnable() { public void run() { synchronized (syncObject) { Display display = serverInstrumentation.getCurrentActivity().getWindowManager() .getDefaultDisplay(); Point size = new Point(); try { display.getSize(size); } catch (NoSuchMethodError ignore) { // Older than api level 13 size.x = display.getWidth(); size.y = display.getHeight(); } // Get root view View view = mainView.getRootView(); // Create the bitmap to use to draw the screenshot final Bitmap bitmap = Bitmap.createBitmap(size.x, size.y, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); // Get current theme to know which background to use final Activity activity = serverInstrumentation.getCurrentActivity(); final Theme theme = activity.getTheme(); final TypedArray ta = theme .obtainStyledAttributes(new int[] { android.R.attr.windowBackground }); final int res = ta.getResourceId(0, 0); final Drawable background = activity.getResources().getDrawable(res); // Draw background background.draw(canvas); // Draw views view.draw(canvas); ByteArrayOutputStream stream = new ByteArrayOutputStream(); if (!bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)) { throw new RuntimeException("Error while compressing screenshot image."); } try { stream.flush(); stream.close(); } catch (IOException e) { throw new RuntimeException("I/O Error while capturing screenshot: " + e.getMessage()); } finally { Closeable closeable = (Closeable) stream; try { if (closeable != null) { closeable.close(); } } catch (IOException ioe) { // ignore } } rawPng[0] = stream.toByteArray(); mainView.destroyDrawingCache(); done = true; syncObject.notify(); } } }); waitForDone(end, serverInstrumentation.getAndroidWait().getTimeoutInMillis(), "Failed to take screenshot."); return rawPng[0]; }
From source file:com.ijiaban.navigationdrawer.SherlockActionBarDrawerToggle.java
/** * Construct a new ActionBarDrawerToggle. * /*from w w w . j a v a2 s.c o m*/ * <p> * The given {@link Activity} will be linked to the specified * {@link DrawerLayout}. The provided drawer indicator drawable will animate * slightly off-screen as the drawer is opened, indicating that in the open * state the drawer will move off-screen when pressed and in the closed * state the drawer will move on-screen when pressed. * </p> * * <p> * String resources must be provided to describe the open/close drawer * actions for accessibility services. * </p> * * @param activity * The Activity hosting the drawer * @param drawerLayout * The DrawerLayout to link to the given Activity's ActionBar * @param drawerImageRes * A Drawable resource to use as the drawer indicator * @param openDrawerContentDescRes * A String resource to describe the "open drawer" action for * accessibility * @param closeDrawerContentDescRes * A String resource to describe the "close drawer" action for * accessibility */ public SherlockActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, int drawerImageRes, int openDrawerContentDescRes, int closeDrawerContentDescRes) { mActivity = activity; mDrawerLayout = drawerLayout; mDrawerImageResource = drawerImageRes; mOpenDrawerContentDescRes = openDrawerContentDescRes; mCloseDrawerContentDescRes = closeDrawerContentDescRes; mThemeImage = IMPL.getThemeUpIndicator(activity); mDrawerImage = activity.getResources().getDrawable(drawerImageRes); mSlider = new SlideDrawable(mDrawerImage); mSlider.setOffsetBy(1.f / 3); }
From source file:com.google.plus.wigwamnow.social.FacebookProvider.java
/** * Share a {@link Wigwam} on the user's timeline using the Feed Dialog. *//* ww w.java 2 s .c o m*/ @Override public boolean share(Wigwam wigwam, Activity activity) { final Activity hostActivity = activity; Session session = Session.getActiveSession(); if (!hasPublishPermissions()) { requestPublishPermissions(session, activity); return false; } final Wigwam toShare = wigwam; Bundle postParams = new Bundle(); postParams.putString("name", wigwam.getName()); postParams.putString("caption", wigwam.getDescription()); String host = activity.getResources().getString(R.string.external_host); postParams.putString("link", host + "/wigwams/" + Integer.toString(wigwam.getId())); postParams.putString("message", "Check out this wigwam!"); postParams.putString("picture", wigwam.getSrc()); WebDialog feedDialog = new WebDialog.FeedDialogBuilder(hostActivity, session, postParams) .setOnCompleteListener(new OnCompleteListener() { @Override public void onComplete(Bundle values, FacebookException error) { if (error == null) { final String postId = values.getString("post_id"); if (postId != null) { Toast.makeText(hostActivity, "Published to timeline", Toast.LENGTH_SHORT).show(); } } } }).build(); feedDialog.show(); return true; }
From source file:com.daiv.android.twitter.manipulations.widgets.ActionBarDrawerToggle.java
/** * Construct a new ActionBarDrawerToggle. * <p/>/* w w w .jav a 2 s. co m*/ * <p>The given {@link Activity} will be linked to the specified {@link DrawerLayout}. * The provided drawer indicator drawable will animate slightly off-screen as the drawer * is opened, indicating that in the open state the drawer will move off-screen when pressed * and in the closed state the drawer will move on-screen when pressed.</p> * <p/> * <p>String resources must be provided to describe the open/close drawer actions for * accessibility services.</p> * * @param activity The Activity hosting the drawer * @param drawerLayout The DrawerLayout to link to the given Activity's ActionBar * @param drawerImageRes A Drawable resource to use as the drawer indicator * @param openDrawerContentDescRes A String resource to describe the "open drawer" action * for accessibility * @param closeDrawerContentDescRes A String resource to describe the "close drawer" action * for accessibility */ public ActionBarDrawerToggle(Activity activity, NotificationDrawerLayout drawerLayout, int drawerImageRes, int openDrawerContentDescRes, int closeDrawerContentDescRes) { mActivity = activity; mDrawerLayout = drawerLayout; mDrawerImageResource = drawerImageRes; mOpenDrawerContentDescRes = openDrawerContentDescRes; mCloseDrawerContentDescRes = closeDrawerContentDescRes; mThemeImage = getThemeUpIndicator(); mDrawerImage = activity.getResources().getDrawable(drawerImageRes); mSlider = new SlideDrawable(mDrawerImage); mSlider.setOffsetBy(1.f / 3); // Allow the Activity to provide an impl if (activity instanceof DelegateProvider) { mActivityImpl = ((DelegateProvider) activity).getDrawerToggleDelegate(); } else { mActivityImpl = null; } }
From source file:com.docd.purefm.adapters.BrowserBaseAdapter.java
protected BrowserBaseAdapter(@NonNull final Activity context) { if (sDrawableLruCache == null) { sDrawableLruCache = new DrawableLruCache<>(); }//from w w w .j av a2 s. c o m if (sMimeTypeIconCache == null) { sMimeTypeIconCache = new DrawableLruCache<>(); } mSettings = Settings.getInstance(context); mPreviewHolder = PreviewHolder.getInstance(context); mTheme = context.getTheme(); mResources = context.getResources(); mHandler = new FileObserverEventHandler(this); mLayoutInflater = context.getLayoutInflater(); }
From source file:org.mozilla.gecko.home.TopSitesPanel.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); mMaxGridEntries = activity.getResources().getInteger(R.integer.number_of_top_sites); }
From source file:com.appdevper.mediaplayer.adater.MediaItemViewHolder.java
static View setupGridView(Activity activity, View convertView, ViewGroup parent, ContentItem item, int state) { if (sColorStateNotPlaying == null || sColorStatePlaying == null) { initializeColorStateLists(activity); }//from w w w . java 2 s. c o m MediaItemViewHolder holder; Integer cachedState = STATE_INVALID; if (convertView == null) { convertView = LayoutInflater.from(activity).inflate(R.layout.media_grid_item, parent, false); holder = new MediaItemViewHolder(); holder.layGrid = (RelativeLayout) convertView.findViewById(R.id.layGrid); holder.mImageBack = (ImageView) convertView.findViewById(R.id.imgBack); holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq); holder.mTitleView = (TextView) convertView.findViewById(R.id.title); holder.mDescriptionView = (TextView) convertView.findViewById(R.id.description); convertView.setTag(holder); } else { holder = (MediaItemViewHolder) convertView.getTag(); cachedState = (Integer) convertView.getTag(R.id.tag_mediaitem_state_cache); } GridView grid = (GridView) parent; int size = grid.getRequestedColumnWidth(); holder.mTitleView.setText(item.toString()); holder.mDescriptionView.setText(item.getSubtitle()); int w = holder.layGrid.getLayoutParams().width; // holder.layGrid.setLayoutParams(new GridView.LayoutParams(w, w)); holder.mImageBack.setLayoutParams(new RelativeLayout.LayoutParams(w, w)); if (item.isContainer()) { holder.mImageBack.setImageResource(item.getDefaultResource()); } else { Utils.downloadBitmap(activity.getResources(), item, holder.mImageBack); } // If the state of convertView is different, we need to adapt the view to the // new state. if (cachedState == null || cachedState != state) { switch (state) { case STATE_PLAYABLE: holder.mImageView.setImageDrawable(activity.getDrawable(R.drawable.ic_play_arrow_black_36dp)); holder.mImageView.setImageTintList(sColorStateNotPlaying); holder.mImageView.setVisibility(View.VISIBLE); break; case STATE_PLAYING: AnimationDrawable animation = (AnimationDrawable) activity .getDrawable(R.drawable.ic_equalizer_white_36dp); holder.mImageView.setImageDrawable(animation); holder.mImageView.setImageTintList(sColorStatePlaying); holder.mImageView.setVisibility(View.VISIBLE); if (animation != null) animation.start(); break; case STATE_PAUSED: holder.mImageView.setImageDrawable(activity.getDrawable(R.drawable.ic_equalizer1_white_36dp)); holder.mImageView.setImageTintList(sColorStateNotPlaying); holder.mImageView.setVisibility(View.VISIBLE); break; default: holder.mImageView.setVisibility(View.GONE); } convertView.setTag(R.id.tag_mediaitem_state_cache, state); } return convertView; }