Example usage for android.content.res Resources getString

List of usage examples for android.content.res Resources getString

Introduction

In this page you can find the example usage for android.content.res Resources getString.

Prototype

@NonNull
public String getString(@StringRes int id) throws NotFoundException 

Source Link

Document

Return the string value associated with a particular resource ID.

Usage

From source file:com.fairphone.fplauncher3.Folder.java

/**
 * Used to inflate the Workspace from XML.
 *
 * @param context The application's context.
 * @param attrs The attribtues set containing the Workspace's customization values.
 */// ww  w  .  j a v  a2s  .  c  o m
public Folder(Context context, AttributeSet attrs) {
    super(context, attrs);

    mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);

    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    setAlwaysDrawnWithCacheEnabled(false);
    mInflater = LayoutInflater.from(context);
    mIconCache = app.getIconCache();

    Resources res = getResources();
    mMaxCountX = (int) grid.numColumns;
    // Allow scrolling folders when DISABLE_ALL_APPS is true.
    if (LauncherAppState.isDisableAllApps()) {
        mMaxCountY = mMaxNumItems = Integer.MAX_VALUE;
    } else {
        mMaxCountY = (int) grid.numRows;
        mMaxNumItems = mMaxCountX * mMaxCountY;
    }

    mInputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

    mExpandDuration = res.getInteger(R.integer.config_folderExpandDuration);
    mMaterialExpandDuration = res.getInteger(R.integer.config_materialFolderExpandDuration);
    mMaterialExpandStagger = res.getInteger(R.integer.config_materialFolderExpandStagger);

    if (sDefaultFolderName == null) {
        sDefaultFolderName = res.getString(R.string.folder_name);
    }
    if (sHintText == null) {
        sHintText = res.getString(R.string.folder_hint_text);
    }
    mLauncher = (Launcher) context;
    // We need this view to be focusable in touch mode so that when text editing of the folder
    // name is complete, we have something to focus on, thus hiding the cursor and giving
    // reliable behvior when clicking the text field (since it will always gain focus on click).
    setFocusableInTouchMode(true);
}

From source file:org.witness.ssc.xfer.utils.PublishingUtils.java

public Thread videoUploadToVideoBin(final Activity activity, final Handler handler,
        final String video_absolutepath, final String title, final String description,
        final String emailAddress, final long sdrecord_id) {

    Log.d(TAG, "doPOSTtoVideoBin starting");

    // Make the progress bar view visible.
    ((SSCXferActivity) activity).startedUploading();
    final Resources res = activity.getResources();

    Thread t = new Thread(new Runnable() {
        public void run() {
            // Do background task.

            boolean failed = false;

            HttpClient client = new DefaultHttpClient();

            if (useProxy) {
                HttpHost proxy = new HttpHost(PROXY_HOST, PROXY_PORT_HTTP);
                client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
            }// ww  w  .j av a2  s .c  om

            client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

            URI url = null;
            try {
                url = new URI(res.getString(R.string.http_videobin_org_add));
            } catch (URISyntaxException e) {
                // Ours is a fixed URL, so not likely to get here.
                e.printStackTrace();
                return;

            }
            HttpPost post = new HttpPost(url);
            CustomMultiPartEntity entity = new CustomMultiPartEntity(HttpMultipartMode.BROWSER_COMPATIBLE,
                    new ProgressListener() {
                        int lastPercent = 0;

                        @Override
                        public void transferred(long num) {

                            percentUploaded = (int) (((float) num) / ((float) totalLength) * 99f);
                            //Log.d(TAG, "percent uploaded: " + percentUploaded + " - " + num + " / " + totalLength);
                            if (lastPercent != percentUploaded) {
                                ((SSCXferActivity) activity).showProgress("uploading...", percentUploaded);
                                lastPercent = percentUploaded;
                            }
                        }

                    });

            File file = new File(video_absolutepath);
            entity.addPart(res.getString(R.string.video_bin_API_videofile), new FileBody(file));

            try {
                entity.addPart(res.getString(R.string.video_bin_API_api),
                        new StringBody("1", "text/plain", Charset.forName("UTF-8")));

                // title
                entity.addPart(res.getString(R.string.video_bin_API_title),
                        new StringBody(title, "text/plain", Charset.forName("UTF-8")));

                // description
                entity.addPart(res.getString(R.string.video_bin_API_description),
                        new StringBody(description, "text/plain", Charset.forName("UTF-8")));

            } catch (IllegalCharsetNameException e) {
                // error
                e.printStackTrace();
                failed = true;

            } catch (UnsupportedCharsetException e) {
                // error
                e.printStackTrace();
                return;
            } catch (UnsupportedEncodingException e) {
                // error
                e.printStackTrace();
                failed = true;
            }

            post.setEntity(entity);

            totalLength = entity.getContentLength();

            // Here we go!
            String response = null;
            try {
                response = EntityUtils.toString(client.execute(post).getEntity(), "UTF-8");
            } catch (ParseException e) {
                // error
                e.printStackTrace();
                failed = true;
            } catch (ClientProtocolException e) {
                // error
                e.printStackTrace();
                failed = true;
            } catch (IOException e) {
                // error
                e.printStackTrace();
                failed = true;
            }

            client.getConnectionManager().shutdown();

            if (failed) {
                // Use the handler to execute a Runnable on the
                // main thread in order to have access to the
                // UI elements.
                handler.postDelayed(new Runnable() {
                    public void run() {
                        // Update UI

                        // Indicate back to calling activity the result!
                        // update uploadInProgress state also.

                        ((SSCXferActivity) activity).finishedUploading(false);

                        ((SSCXferActivity) activity)
                                .createNotification(res.getString(R.string.upload_to_videobin_org_failed_));
                    }
                }, 0);

                return;
            }

            Log.d(TAG, " video bin got back " + response);

            // XXX Convert to preference for auto-email on videobin post
            // XXX ADD EMAIL NOTIF to all other upload methods
            // stuck on YES here, if email is defined.

            if (emailAddress != null && response != null) {

                // EmailSender through IR controlled gmail system.
                SSLEmailSender sender = new SSLEmailSender(
                        activity.getString(R.string.automatic_email_username),
                        activity.getString(R.string.automatic_email_password)); // consider
                // this
                // public
                // knowledge.
                try {
                    sender.sendMail(activity.getString(R.string.vidiom_automatic_email), // subject.getText().toString(),
                            activity.getString(R.string.url_of_hosted_video_is_) + " " + response, // body.getText().toString(),
                            activity.getString(R.string.automatic_email_from), // from.getText().toString(),
                            emailAddress // to.getText().toString()
                    );
                } catch (Exception e) {
                    Log.e(TAG, e.getMessage(), e);
                }
            }

            // Log record of this URL in POSTs table
            dbutils.creatHostDetailRecordwithNewVideoUploaded(sdrecord_id,
                    res.getString(R.string.http_videobin_org_add), response, "");

            // Use the handler to execute a Runnable on the
            // main thread in order to have access to the
            // UI elements.
            handler.postDelayed(new Runnable() {
                public void run() {
                    // Update UI

                    // Indicate back to calling activity the result!
                    // update uploadInProgress state also.

                    ((SSCXferActivity) activity).finishedUploading(true);
                    ((SSCXferActivity) activity)
                            .createNotification(res.getString(R.string.upload_to_videobin_org_succeeded_));

                }
            }, 0);
        }
    });

    t.start();

    return t;

}

From source file:com.customdatepicker.time.TimePickerDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    int viewRes = mVersion == Version.VERSION_1 ? R.layout.mdtp_time_picker_dialog
            : R.layout.mdtp_time_picker_dialog_v2;
    View view = inflater.inflate(viewRes, container, false);
    KeyboardListener keyboardListener = new KeyboardListener();
    view.findViewById(R.id.mdtp_time_picker_dialog).setOnKeyListener(keyboardListener);

    // If an accent color has not been set manually, get it from the context
    if (mAccentColor == -1) {
        mAccentColor = Utils.getAccentColorFromThemeIfAvailable(getActivity());
    }/*from w w  w  .j av  a2 s  .c om*/

    // if theme mode has not been set by java code, check if it is specified in Style.xml
    if (!mThemeDarkChanged) {
        mThemeDark = Utils.isDarkTheme(getActivity(), mThemeDark);
    }

    Resources res = getResources();
    Context context = getActivity();
    mHourPickerDescription = res.getString(R.string.mdtp_hour_picker_description);
    mSelectHours = res.getString(R.string.mdtp_select_hours);
    mMinutePickerDescription = res.getString(R.string.mdtp_minute_picker_description);
    mSelectMinutes = res.getString(R.string.mdtp_select_minutes);
    mSecondPickerDescription = res.getString(R.string.mdtp_second_picker_description);
    mSelectSeconds = res.getString(R.string.mdtp_select_seconds);
    mSelectedColor = ContextCompat.getColor(context, R.color.mdtp_white);
    mUnselectedColor = ContextCompat.getColor(context, R.color.mdtp_accent_color_focused);

    mHourView = (TextView) view.findViewById(R.id.mdtp_hours);
    mHourView.setOnKeyListener(keyboardListener);
    mHourSpaceView = (TextView) view.findViewById(R.id.mdtp_hour_space);
    mMinuteSpaceView = (TextView) view.findViewById(R.id.mdtp_minutes_space);
    mMinuteView = (TextView) view.findViewById(R.id.mdtp_minutes);
    mMinuteView.setOnKeyListener(keyboardListener);
    mSecondSpaceView = (TextView) view.findViewById(R.id.mdtp_seconds_space);
    mSecondView = (TextView) view.findViewById(R.id.mdtp_seconds);
    mSecondView.setOnKeyListener(keyboardListener);
    mAmTextView = (TextView) view.findViewById(R.id.mdtp_am_label);
    mAmTextView.setOnKeyListener(keyboardListener);
    mPmTextView = (TextView) view.findViewById(R.id.mdtp_pm_label);
    mPmTextView.setOnKeyListener(keyboardListener);
    mAmPmLayout = view.findViewById(R.id.mdtp_ampm_layout);
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    mHapticFeedbackController = new HapticFeedbackController(getActivity());

    if (mTimePicker != null) {
        mInitialTime = new Timepoint(mTimePicker.getHours(), mTimePicker.getMinutes(),
                mTimePicker.getSeconds());
    }

    mInitialTime = roundToNearest(mInitialTime);

    mTimePicker = (RadialPickerLayout) view.findViewById(R.id.mdtp_time_picker);
    mTimePicker.setOnValueSelectedListener(this);
    mTimePicker.setOnKeyListener(keyboardListener);
    mTimePicker.initialize(getActivity(), this, mInitialTime, mIs24HourMode);

    int currentItemShowing = HOUR_INDEX;
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) {
        currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
    }
    setCurrentItemShowing(currentItemShowing, false, true, true);
    mTimePicker.invalidate();

    mHourView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(HOUR_INDEX, true, false, true);
            tryVibrate();
        }
    });
    mMinuteView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(MINUTE_INDEX, true, false, true);
            tryVibrate();
        }
    });
    mSecondView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            setCurrentItemShowing(SECOND_INDEX, true, false, true);
            tryVibrate();
        }
    });

    mOkButton = (Button) view.findViewById(R.id.mdtp_ok);
    mOkButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInKbMode && isTypedTimeFullyLegal()) {
                finishKbMode(false);
            } else {
                tryVibrate();
            }
            notifyOnDateListener();
            dismiss();
        }
    });
    mOkButton.setOnKeyListener(keyboardListener);
    mOkButton.setTypeface(TypefaceHelper.get(context, "Roboto-Medium"));
    if (mOkString != null)
        mOkButton.setText(mOkString);
    else
        mOkButton.setText(mOkResid);

    mCancelButton = (Button) view.findViewById(R.id.mdtp_cancel);
    mCancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            tryVibrate();
            if (getDialog() != null)
                getDialog().cancel();
        }
    });
    mCancelButton.setTypeface(TypefaceHelper.get(context, "Roboto-Medium"));
    if (mCancelString != null)
        mCancelButton.setText(mCancelString);
    else
        mCancelButton.setText(mCancelResid);
    mCancelButton.setVisibility(isCancelable() ? View.VISIBLE : View.GONE);

    // Enable or disable the AM/PM view.
    if (mIs24HourMode) {
        mAmPmLayout.setVisibility(View.GONE);
    } else {
        OnClickListener listener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                // Don't do anything if either AM or PM are disabled
                if (isAmDisabled() || isPmDisabled())
                    return;

                tryVibrate();
                int amOrPm = mTimePicker.getIsCurrentlyAmOrPm();
                if (amOrPm == AM) {
                    amOrPm = PM;
                } else if (amOrPm == PM) {
                    amOrPm = AM;
                }
                mTimePicker.setAmOrPm(amOrPm);
            }
        };
        mAmTextView.setVisibility(View.GONE);
        mPmTextView.setVisibility(View.VISIBLE);
        mAmPmLayout.setOnClickListener(listener);
        if (mVersion == Version.VERSION_2) {
            mAmTextView.setText(mAmText);
            mPmTextView.setText(mPmText);
            mAmTextView.setVisibility(View.VISIBLE);
        }
        updateAmPmDisplay(mInitialTime.isAM() ? AM : PM);

    }

    // Disable seconds picker
    if (!mEnableSeconds) {
        mSecondView.setVisibility(View.GONE);
        view.findViewById(R.id.mdtp_separator_seconds).setVisibility(View.GONE);
    }

    // Disable minutes picker
    if (!mEnableMinutes) {
        mMinuteSpaceView.setVisibility(View.GONE);
        view.findViewById(R.id.mdtp_separator).setVisibility(View.GONE);
    }

    // Center stuff depending on what's visible
    boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    // Landscape layout is radically different
    if (isLandscape) {
        if (!mEnableMinutes && !mEnableSeconds) {
            // Just the hour
            // Put the hour above the center
            RelativeLayout.LayoutParams paramsHour = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsHour.addRule(RelativeLayout.ABOVE, R.id.mdtp_center_view);
            paramsHour.addRule(RelativeLayout.CENTER_HORIZONTAL);
            mHourSpaceView.setLayoutParams(paramsHour);
            if (mIs24HourMode) {
                // Hour + Am/Pm indicator
                // Put the am / pm indicator next to the hour
                RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                paramsAmPm.addRule(RelativeLayout.RIGHT_OF, R.id.mdtp_hour_space);
                mAmPmLayout.setLayoutParams(paramsAmPm);
            }
        } else if (!mEnableSeconds && mIs24HourMode) {
            // Hour + Minutes
            // Put the separator above the center
            RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL);
            paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_center_view);
            TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator);
            separatorView.setLayoutParams(paramsSeparator);
        } else if (!mEnableSeconds) {
            // Hour + Minutes + Am/Pm indicator
            // Put separator above the center
            RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL);
            paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_center_view);
            TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator);
            separatorView.setLayoutParams(paramsSeparator);
            // Put the am/pm indicator below the separator
            RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsAmPm.addRule(RelativeLayout.CENTER_IN_PARENT);
            paramsAmPm.addRule(RelativeLayout.BELOW, R.id.mdtp_center_view);
            mAmPmLayout.setLayoutParams(paramsAmPm);
        } else if (mIs24HourMode) {
            // Hour + Minutes + Seconds
            // Put the separator above the center
            RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL);
            paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_seconds_space);
            TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator);
            separatorView.setLayoutParams(paramsSeparator);
            // Center the seconds
            RelativeLayout.LayoutParams paramsSeconds = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsSeconds.addRule(RelativeLayout.CENTER_IN_PARENT);
            mSecondSpaceView.setLayoutParams(paramsSeconds);
        } else {
            // Hour + Minutes + Seconds + Am/Pm Indicator
            // Put the seconds on the center
            RelativeLayout.LayoutParams paramsSeconds = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsSeconds.addRule(RelativeLayout.CENTER_IN_PARENT);
            mSecondSpaceView.setLayoutParams(paramsSeconds);
            // Put the separator above the seconds
            RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL);
            paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_seconds_space);
            TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator);
            separatorView.setLayoutParams(paramsSeparator);
            // Put the Am/Pm indicator below the seconds
            RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsAmPm.addRule(RelativeLayout.CENTER_HORIZONTAL);
            paramsAmPm.addRule(RelativeLayout.BELOW, R.id.mdtp_seconds_space);
            mAmPmLayout.setLayoutParams(paramsAmPm);
        }
    } else if (mIs24HourMode && !mEnableSeconds && mEnableMinutes) {
        // center first separator
        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT);
        TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator);
        separatorView.setLayoutParams(paramsSeparator);
    } else if (!mEnableMinutes && !mEnableSeconds) {
        // center the hour
        RelativeLayout.LayoutParams paramsHour = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsHour.addRule(RelativeLayout.CENTER_IN_PARENT);
        mHourSpaceView.setLayoutParams(paramsHour);

        if (!mIs24HourMode) {
            RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            paramsAmPm.addRule(RelativeLayout.RIGHT_OF, R.id.mdtp_hour_space);
            paramsAmPm.addRule(RelativeLayout.ALIGN_BASELINE, R.id.mdtp_hour_space);
            mAmPmLayout.setLayoutParams(paramsAmPm);
        }
    } else if (mEnableSeconds) {
        // link separator to minutes
        final View separator = view.findViewById(R.id.mdtp_separator);
        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.LEFT_OF, R.id.mdtp_minutes_space);
        paramsSeparator.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
        separator.setLayoutParams(paramsSeparator);

        if (!mIs24HourMode) {
            // center minutes
            RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            paramsMinutes.addRule(RelativeLayout.CENTER_IN_PARENT);
            mMinuteSpaceView.setLayoutParams(paramsMinutes);
        } else {
            // move minutes to right of center
            RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            paramsMinutes.addRule(RelativeLayout.RIGHT_OF, R.id.mdtp_center_view);
            mMinuteSpaceView.setLayoutParams(paramsMinutes);
        }
    }

    mAllowAutoAdvance = true;
    setHour(mInitialTime.getHour(), true);
    setMinute(mInitialTime.getMinute());
    setSecond(mInitialTime.getSecond());

    // Set up for keyboard mode.
    mDoublePlaceholderText = res.getString(R.string.mdtp_time_placeholder);
    mDeletedKeyFormat = res.getString(R.string.mdtp_deleted_key);
    mPlaceholderText = mDoublePlaceholderText.charAt(0);
    mAmKeyCode = mPmKeyCode = -1;
    generateLegalTimesTree();
    if (mInKbMode) {
        mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES);
        tryStartingKbMode(-1);
        mHourView.invalidate();
    } else if (mTypedTimes == null) {
        mTypedTimes = new ArrayList<>();
    }

    // Set the title (if any)
    TextView timePickerHeader = (TextView) view.findViewById(R.id.mdtp_time_picker_header);
    if (!mTitle.isEmpty()) {
        timePickerHeader.setVisibility(TextView.VISIBLE);
        timePickerHeader.setText(mTitle.toUpperCase(Locale.getDefault()));
    }

    // Set the theme at the end so that the initialize()s above don't counteract the theme.
    timePickerHeader.setBackgroundColor(Utils.darkenColor(mAccentColor));
    view.findViewById(R.id.mdtp_time_display_background).setBackgroundColor(mAccentColor);
    view.findViewById(R.id.mdtp_time_display).setBackgroundColor(mAccentColor);

    // Button text can have a different color
    if (mOkColor != -1)
        mOkButton.setTextColor(mOkColor);
    else
        mOkButton.setTextColor(mAccentColor);
    if (mCancelColor != -1)
        mCancelButton.setTextColor(mCancelColor);
    else
        mCancelButton.setTextColor(mAccentColor);

    if (getDialog() == null) {
        view.findViewById(R.id.mdtp_done_background).setVisibility(View.GONE);
    }

    int circleBackground = ContextCompat.getColor(context, R.color.mdtp_circle_background);
    int backgroundColor = ContextCompat.getColor(context, R.color.mdtp_background_color);
    int darkBackgroundColor = ContextCompat.getColor(context, R.color.mdtp_light_gray);
    int lightGray = ContextCompat.getColor(context, R.color.mdtp_light_gray);

    mTimePicker.setBackgroundColor(mThemeDark ? lightGray : circleBackground);
    view.findViewById(R.id.mdtp_time_picker_dialog)
            .setBackgroundColor(mThemeDark ? darkBackgroundColor : backgroundColor);
    return view;
}

From source file:activities.PaintActivity.java

private void invokeApplication(String packageName, Resources resources) {

    int requestCode = 0;
    Log.d("DialogShare", "Seleccionado ... " + packageName);
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.setType("image/*");

    shareIntent.setPackage(packageName);

    //Image/*from  www  .  j a v  a  2s . c om*/
    Bitmap bitmap = painter.getImageBitmap();

    if ((uriTempImage = PaintUtility.saveTempPhoto(this, bitmap)) == null)
        Toast.makeText(this, "Error al crear imagonen ", Toast.LENGTH_SHORT).show();

    shareIntent.putExtra(Intent.EXTRA_STREAM, uriTempImage);

    if (packageName.contains("twitter")) {
        shareIntent.putExtra(Intent.EXTRA_TEXT, resources.getString(string.sharecontent_twitter_text));
        requestCode = RS_CODE_SHARE_TWITTER;

    } else if (packageName.contains("facebook")) {
        // Warning: Facebook IGNORES our text. They say "These fields are intended for users to express themselves. Pre-filling these fields erodes the authenticity of the user voice."
        // One workaround is to use the Facebook SDK to post, but that doesn't allow the user to choose how they want to share. We can also make a custom landing page, and the link
        // will show the <meta content ="..."> text from that page with our link in Facebook.
        shareIntent.putExtra(Intent.EXTRA_TEXT, resources.getString(string.sharecontent_fb_text));
        requestCode = RS_CODE_SHARE_FB;
    } else if (packageName.contains("gm")) {

        shareIntent.putExtra(Intent.EXTRA_TEXT, resources.getString(string.sharecontent_email_text));
        shareIntent.putExtra(Intent.EXTRA_SUBJECT, resources.getString(string.sharecontent_subject));
        shareIntent.setType("message/rfc822");
        requestCode = RS_CODE_SHARE_GMAIL;
    }

    startActivityForResult(shareIntent, requestCode);
}

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

/**
 * Perform the following tasks://  ww w  . jav a  2s. c om
 * Automatic backup
 * loadStudyOptionsFragment() if tablet
 * Automatic sync
 */
private void onFinishedStartup() {
    // create backup in background if needed
    BackupManager.performBackupInBackground(getCol().getPath());

    // Force a full sync if flag was set in upgrade path, asking the user to confirm if necessary
    if (mRecommendFullSync) {
        mRecommendFullSync = false;
        try {
            getCol().modSchema();
        } catch (ConfirmModSchemaException e) {
            // If libanki determines it's necessary to confirm the full sync then show a confirmation dialog
            // We have to show the dialog via the DialogHandler since this method is called via a Loader
            Resources res = getResources();
            Message handlerMessage = Message.obtain();
            handlerMessage.what = DialogHandler.MSG_SHOW_FORCE_FULL_SYNC_DIALOG;
            Bundle handlerMessageData = new Bundle();
            handlerMessageData.putString("message", res.getString(R.string.full_sync_confirmation_upgrade)
                    + "\n\n" + res.getString(R.string.full_sync_confirmation));
            handlerMessage.setData(handlerMessageData);
            getDialogHandler().sendMessage(handlerMessage);
        }
    }
    // Open StudyOptionsFragment if in fragmented mode
    if (mFragmented) {
        loadStudyOptionsFragment(false);
    }
    automaticSync();
}

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

public void renameDeckDialog(final long did) {
    final Resources res = getResources();
    mDialogEditText = new EditText(DeckPicker.this);
    mDialogEditText.setSingleLine();/*  w w w.  j  a  v  a2 s .com*/
    final String currentName = getCol().getDecks().name(did);
    mDialogEditText.setText(currentName);
    new MaterialDialog.Builder(DeckPicker.this).title(res.getString(R.string.rename_deck))
            .customView(mDialogEditText, true).positiveText(res.getString(R.string.rename))
            .negativeText(res.getString(R.string.dialog_cancel)).callback(new MaterialDialog.ButtonCallback() {
                @Override
                public void onPositive(MaterialDialog dialog) {
                    String newName = mDialogEditText.getText().toString().replaceAll("\"", "");
                    Collection col = getCol();
                    if (!TextUtils.isEmpty(newName) && !newName.equals(currentName)) {
                        try {
                            col.getDecks().rename(col.getDecks().get(did), newName);
                        } catch (DeckRenameException e) {
                            // We get a localized string from libanki to explain the error
                            Themes.showThemedToast(DeckPicker.this, e.getLocalizedMessage(res), false);
                        }
                    }
                    dismissAllDialogFragments();
                    mDeckListAdapter.notifyDataSetChanged();
                    updateDeckList();
                    if (mFragmented) {
                        loadStudyOptionsFragment(false);
                    }
                }

                @Override
                public void onNegative(MaterialDialog dialog) {
                    dismissAllDialogFragments();
                }
            }).build().show();
}

From source file:cn.suishen.email.activity.MessageViewFragmentBase.java

protected void updateHeaderView(Message message) {
    mSubjectView.setText(message.mSubject);
    final Address from = Address.unpackFirst(message.mFrom);

    // Set sender address/display name
    // Note we set " " for empty field, so TextView's won't get squashed.
    // Otherwise their height will be 0, which breaks the layout.
    if (from != null) {
        final String fromFriendly = from.toFriendly();
        final String fromAddress = from.getAddress();
        mFromNameView.setText(fromFriendly);
        mFromAddressView.setText(fromFriendly.equals(fromAddress) ? " " : fromAddress);
    } else {//from w  w w .j  a  v a  2s  . co m
        mFromNameView.setText(" ");
        mFromAddressView.setText(" ");
    }
    mDateTimeView.setText(DateUtils.getRelativeTimeSpanString(mContext, message.mTimeStamp).toString());

    // To/Cc/Bcc
    final Resources res = mContext.getResources();
    final SpannableStringBuilder ssb = new SpannableStringBuilder();
    final String friendlyTo = Address.toFriendly(Address.unpack(message.mTo));
    final String friendlyCc = Address.toFriendly(Address.unpack(message.mCc));
    final String friendlyBcc = Address.toFriendly(Address.unpack(message.mBcc));

    if (!TextUtils.isEmpty(friendlyTo)) {
        Utility.appendBold(ssb, res.getString(R.string.message_view_to_label));
        ssb.append(" ");
        ssb.append(friendlyTo);
    }
    if (!TextUtils.isEmpty(friendlyCc)) {
        ssb.append("  ");
        Utility.appendBold(ssb, res.getString(R.string.message_view_cc_label));
        ssb.append(" ");
        ssb.append(friendlyCc);
    }
    if (!TextUtils.isEmpty(friendlyBcc)) {
        ssb.append("  ");
        Utility.appendBold(ssb, res.getString(R.string.message_view_bcc_label));
        ssb.append(" ");
        ssb.append(friendlyBcc);
    }
    mAddressesView.setText(ssb);
}

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

/**
 * Change the note type from oldModel to newModel, handling the case where a full sync will be required
 * @param oldModel/*from  w w w .  j av  a  2s.  c  o  m*/
 * @param newModel
 */
private void changeNoteTypeWithErrorHandling(final JSONObject oldModel, final JSONObject newModel) {
    Resources res = getResources();
    try {
        changeNoteType(oldModel, newModel);
    } catch (ConfirmModSchemaException e) {
        // Libanki has determined we should ask the user to confirm first
        ConfirmationDialog dialog = new ConfirmationDialog() {
            @Override
            public void confirm() {
                // Bypass the check once the user confirms
                getCol().modSchemaNoCheck();
                try {
                    changeNoteType(oldModel, newModel);
                } catch (ConfirmModSchemaException e2) {
                    // This should never be reached as we explicitly called modSchemaNoCheck()
                    throw new RuntimeException(e2);
                }
            }
        };
        dialog.setArgs(res.getString(R.string.full_sync_confirmation));
        showDialogFragment(dialog);
    }
}

From source file:com.aimfire.gallery.GalleryActivity.java

/**
 * share only to certain apps. code based on "http://stackoverflow.com/questions/
 * 9730243/how-to-filter-specific-apps-for-action-send-intent-and-set-a-different-
 * text-for/18980872#18980872"// w  w w. j  a v a2s  .  com
 * 
 * "copy link" inspired by http://cketti.de/2016/06/15/share-url-to-clipboard/
 * 
 * in general, "deep linking" is supported by the apps below. Facebook, Wechat,
 * Telegram are exceptions. click on the link would bring users to the landing
 * page. 
 * 
 * Facebook doesn't take our EXTRA_TEXT so user will have to "copy link" first 
 * then paste the link
 */
private void shareMedia(Intent data) {
    /*
     * we log this as "share complete", but user can still cancel the share at this point,
     * and we wouldn't be able to know
     */
    mFirebaseAnalytics.logEvent(MainConsts.FIREBASE_CUSTOM_EVENT_SHARE_COMPLETE, null);

    Resources resources = getResources();

    /*
     * get the resource id for the shared file
     */
    String id = data.getStringExtra(MainConsts.EXTRA_ID_RESOURCE);

    /*
     * construct link
     */
    String link = "https://" + resources.getString(R.string.app_domain) + "/?id=" + id + "&name="
            + ((mPreviewName != null) ? mPreviewName : mMediaName);

    /*
     * message subject and text
     */
    String emailSubject, emailText, twitterText;

    if (MediaScanner.isPhoto(mMediaPath)) {
        emailSubject = resources.getString(R.string.emailSubjectPhoto);
        emailText = resources.getString(R.string.emailBodyPhotoPrefix) + link;
        twitterText = resources.getString(R.string.emailBodyPhotoPrefix) + link
                + resources.getString(R.string.twitterHashtagPhoto) + resources.getString(R.string.app_hashtag);
    } else if (MediaScanner.is3dMovie(mMediaPath)) {
        emailSubject = resources.getString(R.string.emailSubjectVideo);
        emailText = resources.getString(R.string.emailBodyVideoPrefix) + link;
        twitterText = resources.getString(R.string.emailBodyVideoPrefix) + link
                + resources.getString(R.string.twitterHashtagVideo) + resources.getString(R.string.app_hashtag);
    } else //if(MediaScanner.is2dMovie(mMediaPath))
    {
        emailSubject = resources.getString(R.string.emailSubjectVideo2d);
        emailText = resources.getString(R.string.emailBodyVideoPrefix2d) + link;
        twitterText = resources.getString(R.string.emailBodyVideoPrefix2d) + link
                + resources.getString(R.string.twitterHashtagVideo) + resources.getString(R.string.app_hashtag);
    }

    Intent emailIntent = new Intent();
    emailIntent.setAction(Intent.ACTION_SEND);
    // Native email client doesn't currently support HTML, but it doesn't hurt to try in case they fix it
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);
    //emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_native)));
    emailIntent.setType("message/rfc822");

    PackageManager pm = getPackageManager();
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType("text/plain");

    Intent openInChooser = Intent.createChooser(emailIntent, resources.getString(R.string.share_chooser_text));

    List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
    List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
    for (int i = 0; i < resInfo.size(); i++) {
        // Extract the label, append it, and repackage it in a LabeledIntent
        ResolveInfo ri = resInfo.get(i);
        String packageName = ri.activityInfo.packageName;
        if (packageName.contains("android.email")) {
            emailIntent.setPackage(packageName);
        } else if (packageName.contains("twitter") || packageName.contains("facebook")
                || packageName.contains("whatsapp") || packageName.contains("tencent.mm") || //wechat
                packageName.contains("line") || packageName.contains("skype") || packageName.contains("viber")
                || packageName.contains("kik") || packageName.contains("sgiggle") || //tango
                packageName.contains("kakao") || packageName.contains("telegram")
                || packageName.contains("nimbuzz") || packageName.contains("hike")
                || packageName.contains("imoim") || packageName.contains("bbm")
                || packageName.contains("threema") || packageName.contains("mms")
                || packageName.contains("android.apps.messaging") || //google messenger
                packageName.contains("android.talk") || //google hangouts
                packageName.contains("android.gm")) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("text/plain");
            if (packageName.contains("twitter")) {
                intent.putExtra(Intent.EXTRA_TEXT, twitterText);
            } else if (packageName.contains("facebook")) {
                /*
                 * the warning below is wrong! at least on GS5, Facebook client does take
                 * our text, however it seems it takes only the first hyperlink in the
                 * text.
                 * 
                 * Warning: Facebook IGNORES our text. They say "These fields are intended 
                 * for users to express themselves. Pre-filling these fields erodes the 
                 * authenticity of the user voice."
                 * One workaround is to use the Facebook SDK to post, but that doesn't 
                 * allow the user to choose how they want to share. We can also make a 
                 * custom landing page, and the link will show the <meta content ="..."> 
                 * text from that page with our link in Facebook.
                 */
                intent.putExtra(Intent.EXTRA_TEXT, link);
            } else if (packageName.contains("tencent.mm")) //wechat
            {
                /*
                 * wechat appears to do this similar to Facebook
                 */
                intent.putExtra(Intent.EXTRA_TEXT, link);
            } else if (packageName.contains("android.gm")) {
                // If Gmail shows up twice, try removing this else-if clause and the reference to "android.gm" above
                intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
                intent.putExtra(Intent.EXTRA_TEXT, emailText);
                //intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_gmail)));
                intent.setType("message/rfc822");
            } else if (packageName.contains("android.apps.docs")) {
                /*
                 * google drive - no reason to send link to it
                 */
                continue;
            } else {
                intent.putExtra(Intent.EXTRA_TEXT, emailText);
            }

            intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
        }
    }

    /*
     *  create "Copy Link To Clipboard" Intent
     */
    Intent clipboardIntent = new Intent(this, CopyToClipboardActivity.class);
    clipboardIntent.setData(Uri.parse(link));
    intentList.add(new LabeledIntent(clipboardIntent, getPackageName(),
            getResources().getString(R.string.clipboard_activity_name), R.drawable.ic_copy_link));

    // convert intentList to array
    LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);

    openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
    startActivity(openInChooser);
}

From source file:com.androzic.MapActivity.java

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Resources resources = getResources();
    // application preferences
    if (getString(R.string.pref_folder_data).equals(key)) {
        application.setDataPath(Androzic.PATH_DATA,
                sharedPreferences.getString(key, resources.getString(R.string.def_folder_data)));
    } else if (getString(R.string.pref_folder_icon).equals(key)) {
        application.setDataPath(Androzic.PATH_ICONS,
                sharedPreferences.getString(key, resources.getString(R.string.def_folder_icon)));
    } else if (getString(R.string.pref_orientation).equals(key)) {
        setRequestedOrientation(Integer.parseInt(sharedPreferences.getString(key, "-1")));
    } else if (getString(R.string.pref_grid_mapshow).equals(key)) {
        application.mapGrid = sharedPreferences.getBoolean(key, false);
        application.initGrids();//from w w w  .ja  va 2s.  c om
    } else if (getString(R.string.pref_grid_usershow).equals(key)) {
        application.userGrid = sharedPreferences.getBoolean(key, false);
        application.initGrids();
    } else if (getString(R.string.pref_grid_preference).equals(key)) {
        application.gridPrefer = Integer.parseInt(sharedPreferences.getString(key, "0"));
        application.initGrids();
    } else if (getString(R.string.pref_grid_userscale).equals(key)
            || getString(R.string.pref_grid_userunit).equals(key)
            || getString(R.string.pref_grid_usermpp).equals(key)) {
        application.initGrids();
    } else if (getString(R.string.pref_useonlinemap).equals(key) && sharedPreferences.getBoolean(key, false)) {
        application.setOnlineMap(sharedPreferences.getString(getString(R.string.pref_onlinemap),
                resources.getString(R.string.def_onlinemap)));
    } else if (getString(R.string.pref_onlinemap).equals(key)
            || getString(R.string.pref_onlinemapscale).equals(key)) {
        application.setOnlineMap(sharedPreferences.getString(getString(R.string.pref_onlinemap),
                resources.getString(R.string.def_onlinemap)));
    } else if (getString(R.string.pref_mapadjacent).equals(key)) {
        application.adjacentMaps = sharedPreferences.getBoolean(key,
                resources.getBoolean(R.bool.def_mapadjacent));
    } else if (getString(R.string.pref_mapcropborder).equals(key)) {
        application.cropMapBorder = sharedPreferences.getBoolean(key,
                resources.getBoolean(R.bool.def_mapcropborder));
    } else if (getString(R.string.pref_mapdrawborder).equals(key)) {
        application.drawMapBorder = sharedPreferences.getBoolean(key,
                resources.getBoolean(R.bool.def_mapdrawborder));
    }
    // activity preferences
    else if (getString(R.string.pref_wakelock).equals(key)) {
        keepScreenOn = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_wakelock));
        android.view.Window wnd = getWindow();
        if (wnd != null) {
            if (keepScreenOn)
                wnd.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            else
                wnd.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        }
    } else if (getString(R.string.pref_exit).equals(key)) {
        exitConfirmation = Integer.parseInt(sharedPreferences.getString(key, "0"));
        secondBack = false;
    } else if (getString(R.string.pref_unitprecision).equals(key)) {
        boolean precision = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_unitprecision));
        precisionFormat = precision ? "%.1f" : "%.0f";
    }
    // map preferences
    else if (getString(R.string.pref_cursorcolor).equals(key)) {
        map.setCursorColor(sharedPreferences.getInt(key, resources.getColor(R.color.cursor)));
    } else if (getString(R.string.pref_panelactions).equals(key)) {
        String pa = sharedPreferences.getString(key, resources.getString(R.string.def_panelactions));
        activeActions = Arrays.asList(pa.split(","));
    }
}