List of usage examples for android.app Activity getResources
@Override
public Resources getResources()
From source file:com.mobicage.rogerthat.util.ui.UIUtils.java
public static boolean showHintWithImage(final Activity activity, final MainService mainService, final SafeRunnable onDismissHandler, final String hintCode, final FontAwesome.Icon hintIcon, final int hintResource, final Object... args) { final ConfigurationProvider configurationProvider = mainService.getConfigurationProvider(); final String configkey = "HINT_REPOSITORY"; final com.mobicage.rogerthat.config.Configuration config = configurationProvider .getConfiguration(configkey); if (config.get(hintCode, false)) return false; LayoutInflater inflater = activity.getLayoutInflater(); final View checkboxLayout = inflater.inflate(R.layout.hint, null); final TextView message = (TextView) checkboxLayout.findViewById(R.id.message); final CheckBox checkBox = (CheckBox) checkboxLayout.findViewById(R.id.checkBox); if (hintIcon != null) { final ImageView icon = (ImageView) checkboxLayout.findViewById(R.id.icon); icon.setImageDrawable(new IconicsDrawable(activity, hintIcon).color(Color.DKGRAY).sizeDp(30)); icon.setVisibility(View.VISIBLE); }/* w w w . j a v a 2 s . c om*/ Resources resources = activity.getResources(); message.setText(resources.getString(hintResource, args)); AlertDialog dialog = new AlertDialog.Builder(activity) .setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (onDismissHandler != null) { onDismissHandler.run(); } } }).setTitle(R.string.activity_hint).setView(checkboxLayout).setPositiveButton( resources.getString(R.string.activity_close_hint), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (checkBox.isChecked()) { config.put(hintCode, true); configurationProvider.updateConfigurationNow(configkey, config); } if (onDismissHandler != null) { onDismissHandler.run(); } } }) .create(); dialog.show(); int buttonId = mainService.getResources().getIdentifier("android:id/button1", null, null); ((Button) dialog.findViewById(buttonId)).setTextColor(LookAndFeelConstants.getPrimaryColor(activity)); return true; }
From source file:io.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 w w .j a v a 2 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, 70, 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:openscience.crowdsource.video.experiments.MainActivity.java
public static void setTaskBarColored(android.app.Activity context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window w = context.getWindow(); w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // todo: resolve default top bar height issue or find enother way to change top bar color // int statusBarHeight = 50; View view = new View(context); // view.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); // view.getLayoutParams().height = statusBarHeight; // ((ViewGroup) w.getDecorView()).addView(view); view.setBackgroundColor(context.getResources().getColor(R.color.colorStatusBar)); }//from www . j ava 2s .c om }
From source file:com.cyanogenmod.filemanager.ui.widgets.ActionBarDrawerToggle.java
/** * Construct a new ActionBarDrawerToggle. * * <p>/*from w w w . jav a 2 s . c o m*/ * 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 ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, int drawerImageRes, int openDrawerContentDescRes, int closeDrawerContentDescRes) { mActivity = activity; // Allow the Activity to provide an impl if (activity instanceof DelegateProvider) { mActivityImpl = ((DelegateProvider) activity).getDrawerToggleDelegate(); } else { mActivityImpl = null; } mDrawerLayout = drawerLayout; mDrawerImageResource = drawerImageRes; mOpenDrawerContentDescRes = openDrawerContentDescRes; mCloseDrawerContentDescRes = closeDrawerContentDescRes; mThemeImage = getThemeUpIndicator(); mDrawerImage = activity.getResources().getDrawable(drawerImageRes); mSlider = new SlideDrawable(mDrawerImage); mSlider.setOffset(TOGGLE_DRAWABLE_OFFSET); }
From source file:com.xandy.calendar.month.SimpleDayPickerFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); mContext = activity;//from w w w .j a v a2 s . c om String tz = Time.getCurrentTimezone(); ViewConfiguration viewConfig = ViewConfiguration.get(activity); mMinimumFlingVelocity = viewConfig.getScaledMinimumFlingVelocity(); // Ensure we're in the correct time zone mSelectedDay.switchTimezone(tz); mSelectedDay.normalize(true); mFirstDayOfMonth.timezone = tz; mFirstDayOfMonth.normalize(true); mFirstVisibleDay.timezone = tz; mFirstVisibleDay.normalize(true); mTempTime.timezone = tz; Resources res = activity.getResources(); mSaturdayColor = res.getColor(R.color.month_saturday); mSundayColor = res.getColor(R.color.month_sunday); mDayNameColor = res.getColor(R.color.month_day_names_color); // Adjust sizes for screen density if (mScale == 0) { mScale = activity.getResources().getDisplayMetrics().density; if (mScale != 1) { WEEK_MIN_VISIBLE_HEIGHT *= mScale; BOTTOM_BUFFER *= mScale; LIST_TOP_OFFSET *= mScale; } } setUpAdapter(); setListAdapter(mAdapter); }
From source file:com.android.calendar.month.SimpleDayPickerFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); mContext = activity;//from w w w . j a v a 2 s. c o m String tz = Time.getCurrentTimezone(); ViewConfiguration viewConfig = ViewConfiguration.get(activity); mMinimumFlingVelocity = viewConfig.getScaledMinimumFlingVelocity(); // Ensure we're in the correct time zone mSelectedDay.switchTimezone(tz); mSelectedDay.normalize(true); mFirstDayOfMonth.timezone = tz; mFirstDayOfMonth.normalize(true); mFirstVisibleDay.timezone = tz; mFirstVisibleDay.normalize(true); mTempTime.timezone = tz; Resources res = activity.getResources(); mSaturdayColor = res.getColor(R.color.month_saturday); mSundayColor = res.getColor(R.color.month_sunday); mFridayColor = res.getColor(R.color.month_friday); mDayNameColor = res.getColor(R.color.month_day_names_color); // Adjust sizes for screen density if (mScale == 0) { mScale = activity.getResources().getDisplayMetrics().density; if (mScale != 1) { WEEK_MIN_VISIBLE_HEIGHT *= mScale; BOTTOM_BUFFER *= mScale; LIST_TOP_OFFSET *= mScale; } } setUpAdapter(); setListAdapter(mAdapter); }
From source file:com.luke.lukef.lukeapp.tools.LukeNetUtils.java
/** * Method for asynchronously fetching an image from the internet and setting it into an imageView. * Allows bigger image download to not pause the app. * @param imageViewToSet ImageView where the image will be set * @param url Url of the image as a String * @param defaultImageId Default image id, in case the online image is unavailable * @param activity Activity that can run setting the imageView on a UiThread *//*from w w w.j a v a 2s. c om*/ public static void imageSetupTask(ImageView imageViewToSet, String url, final int defaultImageId, Activity activity) { class LoadImageTask extends AsyncTask<Void, Void, Void> { private ImageView imageView; private String urlString; private Activity activity; private Bitmap bitmap = null; int defaultId; LoadImageTask(ImageView imageView, String urlString, Activity activity, int defaultId) { this.activity = activity; this.urlString = urlString; this.imageView = imageView; this.defaultId = defaultId; } @Override protected Void doInBackground(Void... params) { if (this.urlString != null) { LukeNetUtils lukeNetUtils = new LukeNetUtils(this.activity); try { this.bitmap = lukeNetUtils.getBitmapFromURL(urlString); } catch (ExecutionException | InterruptedException e) { Log.e("ImageAsyncTask", "doInBackground: ", e); } } else { this.bitmap = null; } return null; } @Override protected void onPostExecute(Void aVoid) { this.activity.runOnUiThread(new Runnable() { @Override public void run() { if (LoadImageTask.this.bitmap == null) { LoadImageTask.this.imageView.setImageDrawable( ResourcesCompat.getDrawable(activity.getResources(), defaultImageId, null)); } else { LoadImageTask.this.imageView.setImageBitmap(LoadImageTask.this.bitmap); } } }); super.onPostExecute(aVoid); } } LoadImageTask bitmapTask = new LoadImageTask(imageViewToSet, url, activity, defaultImageId); bitmapTask.execute(); }
From source file:com.android.launcher3.Utilities.java
public static void answerToRestoreIconPack(final Activity context, String packName) { AlertDialog.Builder alert = new AlertDialog.Builder( new ContextThemeWrapper(context, R.style.AlertDialogCustom)); alert.setTitle(context.getResources().getString(R.string.app_name)); alert.setMessage(context.getResources().getString(R.string.ask_icon) + " " + packName + "?"); alert.setPositiveButton(context.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { applyChange(context); }/*from www. j ava 2 s. c o m*/ }); alert.setNegativeButton(context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Utilities.setAppIconPackageNamePrefEnabled(context.getApplicationContext(), "NULL"); dialog.dismiss(); } }); alert.setIcon(R.mipmap.ic_launcher_home); alert.show(); }
From source file:com.borax12.materialdaterangepicker.date.DatePickerDialog.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); View view = inflater.inflate(R.layout.range_date_picker_dialog, container, false); tabHost = (TabHost) view.findViewById(R.id.tabHost); tabHost.findViewById(R.id.tabHost);/*from w w w .j ava 2 s.c o m*/ tabHost.setup(); final Activity activity = getActivity(); TabHost.TabSpec startDatePage = tabHost.newTabSpec("start"); startDatePage.setContent(R.id.start_date_group); startDatePage.setIndicator((startTitle != null && !startTitle.isEmpty()) ? startTitle : activity.getResources().getString(R.string.mdtrp_from)); TabHost.TabSpec endDatePage = tabHost.newTabSpec("end"); endDatePage.setContent(R.id.end_date_group); endDatePage.setIndicator((endTitle != null && !endTitle.isEmpty()) ? endTitle : activity.getResources().getString(R.string.mdtrp_to)); tabHost.addTab(startDatePage); tabHost.addTab(endDatePage); mDayOfWeekView = (TextView) view.findViewById(R.id.date_picker_header); mMonthAndDayView = (LinearLayout) view.findViewById(R.id.date_picker_month_and_day); mMonthAndDayViewEnd = (LinearLayout) view.findViewById(R.id.date_picker_month_and_day_end); mMonthAndDayView.setOnClickListener(this); mMonthAndDayViewEnd.setOnClickListener(this); mSelectedMonthTextView = (TextView) view.findViewById(R.id.date_picker_month); mSelectedMonthTextViewEnd = (TextView) view.findViewById(R.id.date_picker_month_end); mSelectedDayTextView = (TextView) view.findViewById(R.id.date_picker_day); mSelectedDayTextViewEnd = (TextView) view.findViewById(R.id.date_picker_day_end); mYearView = (TextView) view.findViewById(R.id.date_picker_year); mYearViewEnd = (TextView) view.findViewById(R.id.date_picker_year_end); mYearView.setOnClickListener(this); mYearViewEnd.setOnClickListener(this); int listPosition = -1; int listPositionOffset = 0; int listPositionEnd = -1; int listPositionOffsetEnd = 0; int currentView = MONTH_AND_DAY_VIEW; int currentViewEnd = MONTH_AND_DAY_VIEW; if (savedInstanceState != null) { mWeekStart = savedInstanceState.getInt(KEY_WEEK_START); mWeekStartEnd = savedInstanceState.getInt(KEY_WEEK_START_END); mMinYear = savedInstanceState.getInt(KEY_YEAR_START); mMaxYear = savedInstanceState.getInt(KEY_MAX_YEAR); currentView = savedInstanceState.getInt(KEY_CURRENT_VIEW); currentViewEnd = savedInstanceState.getInt(KEY_CURRENT_VIEW_END); listPosition = savedInstanceState.getInt(KEY_LIST_POSITION); listPositionOffset = savedInstanceState.getInt(KEY_LIST_POSITION_OFFSET); listPositionEnd = savedInstanceState.getInt(KEY_LIST_POSITION_END); listPositionOffsetEnd = savedInstanceState.getInt(KEY_LIST_POSITION_OFFSET_END); mMinDate = (Calendar) savedInstanceState.getSerializable(KEY_MIN_DATE); mMaxDate = (Calendar) savedInstanceState.getSerializable(KEY_MAX_DATE); mMinDateEnd = (Calendar) savedInstanceState.getSerializable(KEY_MIN_DATE_END); mMaxDateEnd = (Calendar) savedInstanceState.getSerializable(KEY_MAX_DATE_END); highlightedDays = (Calendar[]) savedInstanceState.getSerializable(KEY_HIGHLIGHTED_DAYS); selectableDays = (Calendar[]) savedInstanceState.getSerializable(KEY_SELECTABLE_DAYS); highlightedDaysEnd = (Calendar[]) savedInstanceState.getSerializable(KEY_HIGHLIGHTED_DAYS_END); selectableDaysEnd = (Calendar[]) savedInstanceState.getSerializable(KEY_SELECTABLE_DAYS_END); mThemeDark = savedInstanceState.getBoolean(KEY_THEME_DARK); mAccentColor = savedInstanceState.getInt(KEY_ACCENT); mVibrate = savedInstanceState.getBoolean(KEY_VIBRATE); mDismissOnPause = savedInstanceState.getBoolean(KEY_DISMISS); } mDayPickerView = new com.borax12.materialdaterangepicker.date.SimpleDayPickerView(activity, this); mYearPickerView = new com.borax12.materialdaterangepicker.date.YearPickerView(activity, this); mDayPickerViewEnd = new com.borax12.materialdaterangepicker.date.SimpleDayPickerView(activity, this); mYearPickerViewEnd = new com.borax12.materialdaterangepicker.date.YearPickerView(activity, this); Resources res = getResources(); mDayPickerDescription = res.getString(R.string.mdtrp_day_picker_description); mSelectDay = res.getString(R.string.mdtrp_select_day); mYearPickerDescription = res.getString(R.string.mdtrp_year_picker_description); mSelectYear = res.getString(R.string.mdtrp_select_year); int bgColorResource = mThemeDark ? R.color.mdtrp_date_picker_view_animator_dark_theme : R.color.mdtrp_date_picker_view_animator; view.setBackgroundColor(ContextCompat.getColor(activity, bgColorResource)); mAnimator = (com.borax12.materialdaterangepicker.date.AccessibleDateAnimator) view .findViewById(R.id.animator); mAnimatorEnd = (com.borax12.materialdaterangepicker.date.AccessibleDateAnimator) view .findViewById(R.id.animator_end); mAnimator.addView(mDayPickerView); mAnimator.addView(mYearPickerView); mAnimator.setDateMillis(mCalendar.getTimeInMillis()); // TODO: Replace with animation decided upon by the design team. Animation animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(ANIMATION_DURATION); mAnimator.setInAnimation(animation); // TODO: Replace with animation decided upon by the design team. Animation animation2 = new AlphaAnimation(1.0f, 0.0f); animation2.setDuration(ANIMATION_DURATION); mAnimator.setOutAnimation(animation2); mAnimatorEnd.addView(mDayPickerViewEnd); mAnimatorEnd.addView(mYearPickerViewEnd); mAnimatorEnd.setDateMillis(mCalendarEnd.getTimeInMillis()); // TODO: Replace with animation decided upon by the design team. Animation animationEnd = new AlphaAnimation(0.0f, 1.0f); animationEnd.setDuration(ANIMATION_DURATION); mAnimatorEnd.setInAnimation(animation); // TODO: Replace with animation decided upon by the design team. Animation animation2End = new AlphaAnimation(1.0f, 0.0f); animation2End.setDuration(ANIMATION_DURATION); mAnimatorEnd.setOutAnimation(animation2); Button okButton = (Button) view.findViewById(R.id.ok); okButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); if (mCallBack != null) { mCallBack.onDateSet(DatePickerDialog.this, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH), mCalendarEnd.get(Calendar.YEAR), mCalendarEnd.get(Calendar.MONTH), mCalendarEnd.get(Calendar.DAY_OF_MONTH)); } dismiss(); } }); okButton.setTypeface(TypefaceHelper.get(activity, "Roboto-Medium")); Button cancelButton = (Button) view.findViewById(R.id.cancel); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); if (getDialog() != null) getDialog().cancel(); } }); cancelButton.setTypeface(TypefaceHelper.get(activity, "Roboto-Medium")); cancelButton.setVisibility(isCancelable() ? View.VISIBLE : View.GONE); //If an accent color has not been set manually, try and get it from the context if (mAccentColor == -1) { int accentColor = Utils.getAccentColorFromThemeIfAvailable(getActivity()); if (accentColor != -1) { mAccentColor = accentColor; } } if (mAccentColor != -1) { if (mDayOfWeekView != null) mDayOfWeekView.setBackgroundColor(Utils.darkenColor(mAccentColor)); view.findViewById(R.id.day_picker_selected_date_layout).setBackgroundColor(mAccentColor); view.findViewById(R.id.day_picker_selected_date_layout_end).setBackgroundColor(mAccentColor); okButton.setTextColor(mAccentColor); cancelButton.setTextColor(mAccentColor); mYearPickerView.setAccentColor(mAccentColor); mDayPickerView.setAccentColor(mAccentColor); mYearPickerViewEnd.setAccentColor(mAccentColor); mDayPickerViewEnd.setAccentColor(mAccentColor); } updateDisplay(false); setCurrentView(currentView); if (listPosition != -1) { if (currentView == MONTH_AND_DAY_VIEW) { mDayPickerView.postSetSelection(listPosition); } else if (currentView == YEAR_VIEW) { mYearPickerView.postSetSelectionFromTop(listPosition, listPositionOffset); } } if (listPositionEnd != -1) { if (currentViewEnd == MONTH_AND_DAY_VIEW) { mDayPickerViewEnd.postSetSelection(listPositionEnd); } else if (currentViewEnd == YEAR_VIEW) { mYearPickerViewEnd.postSetSelectionFromTop(listPositionEnd, listPositionOffsetEnd); } } mHapticFeedbackController = new HapticFeedbackController(activity); tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { com.borax12.materialdaterangepicker.date.MonthAdapter.CalendarDay calendarDay; if (tabId.equals("start")) { calendarDay = new com.borax12.materialdaterangepicker.date.MonthAdapter.CalendarDay( mCalendar.getTimeInMillis()); mDayPickerView.goTo(calendarDay, true, true, false); } else { calendarDay = new com.borax12.materialdaterangepicker.date.MonthAdapter.CalendarDay( mCalendarEnd.getTimeInMillis()); mDayPickerViewEnd.goTo(calendarDay, true, true, false); } } }); return view; }
From source file:com.vuze.android.remote.AndroidUtils.java
public static void openFileChooser(Activity activity, String mimeType, int requestCode) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType(mimeType);//from w w w.j a v a2 s . c o m intent.addCategory(Intent.CATEGORY_OPENABLE); // special intent for Samsung file manager Intent sIntent = new Intent("com.sec.android.app.myfiles.PICK_DATA"); sIntent.putExtra("CONTENT_TYPE", mimeType); sIntent.addCategory(Intent.CATEGORY_DEFAULT); Intent chooserIntent; if (activity.getPackageManager().resolveActivity(sIntent, 0) != null) { chooserIntent = Intent.createChooser(sIntent, "Open file"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { intent }); } else { chooserIntent = Intent.createChooser(intent, "Open file"); } if (chooserIntent != null) { try { activity.startActivityForResult(chooserIntent, requestCode); return; } catch (android.content.ActivityNotFoundException ex) { } } Toast.makeText(activity.getApplicationContext(), activity.getResources().getString(R.string.no_file_chooser), Toast.LENGTH_SHORT).show(); }