Java Code Examples for android.app.Activity#getString()

The following examples show how to use android.app.Activity#getString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Dialogs.java    From Aegis with GNU General Public License v3.0 6 votes vote down vote up
public static void showDeleteEntriesDialog(Activity activity, DialogInterface.OnClickListener onDelete, int totalEntries) {
    String title, message;
    if (totalEntries > 1) {
        title = activity.getString(R.string.delete_entries);
        message = String.format(activity.getString(R.string.delete_entries_description), totalEntries);
    } else {
        title = activity.getString(R.string.delete_entry);
        message = activity.getString(R.string.delete_entry_description);
    }

    showSecureDialog(new AlertDialog.Builder(activity)
            .setTitle(title)
            .setMessage(message)
            .setPositiveButton(android.R.string.yes, onDelete)
            .setNegativeButton(android.R.string.no, null)
            .create());
}
 
Example 2
Source File: MnistClassifier.java    From fritz-examples with MIT License 6 votes vote down vote up
public MnistClassifier(Activity activity) {

        /**
         * This MNIST model provided is used to demonstrate custom models with TensorFlow Lite
         * and should not be used in production.
         */
        FritzManagedModel managedModel = new FritzManagedModel(activity.getString(R.string.tflite_model_id));
        FritzModelManager modelManager = new FritzModelManager(managedModel);
        modelManager.loadModel(new ModelReadyListener() {
            @Override
            public void onModelReady(FritzOnDeviceModel onDeviceModel) {
                tflite = new FritzTFLiteInterpreter(onDeviceModel);
                Log.d(TAG, "Interpreter is now ready to use");
            }
        });
        imgData =
                ByteBuffer.allocateDirect(
                        BYTE_SIZE_OF_FLOAT * DIM_BATCH_SIZE * DIM_IMG_SIZE_X * DIM_IMG_SIZE_Y * DIM_PIXEL_SIZE);
        imgData.order(ByteOrder.nativeOrder());
        mnistOutput = new float[DIM_BATCH_SIZE][NUMBER_LENGTH];
        Log.d(TAG, "Created a Tensorflow Lite MNIST Classifier.");
    }
 
Example 3
Source File: MyActionBarActivity.java    From Clip-Stack with MIT License 6 votes vote down vote up
public static void setOverflowButtonColor(final Activity activity, final int imageID) {
    final String overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description);
    final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            final ArrayList<View> outViews = new ArrayList<View>();
            decorView.findViewsWithText(outViews, overflowDescription,
                    View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
            if (outViews.isEmpty()) {
                return;
            }
            TintImageView overflow=(TintImageView) outViews.get(0);
            //overflow.setColorFilter(Color.CYAN);
            overflow.setImageResource(imageID);
            removeOnGlobalLayoutListener(decorView, this);
        }
    });
}
 
Example 4
Source File: CommunicationHandler.java    From secure-quick-reliable-login with MIT License 6 votes vote down vote up
public String getErrorMessage(Activity a, boolean shouldUseCPSServer) {
    StringBuilder sb = new StringBuilder();
    if(!lastResponse.containsKey("tif")) {
        return a.getString(R.string.communication_incorrect_response);
    } else if(shouldUseCPSServer && !isTIFBitSet(CommunicationHandler.TIF_IP_MATCHED)) {
        sb.append(a.getString(R.string.communication_ip_mismatch));
    } else if(
        isTIFBitSet(CommunicationHandler.TIF_BAD_ID_ASSOCIATION) ||
        isTIFBitSet(CommunicationHandler.TIF_CLIENT_FAILURE) ||
        isTIFBitSet(CommunicationHandler.TIF_COMMAND_FAILED)
    ) {
        sb.append(a.getString(R.string.error_message_login_failed));
    } else if(isTIFBitSet(CommunicationHandler.TIF_FUNCTION_NOT_SUPPORTED)) {
        sb.append(a.getString(R.string.communication_function_not_supported));
    } else if(isTIFBitSet(CommunicationHandler.TIF_TRANSIENT_ERROR)) {
        sb.append(a.getString(R.string.error_message_stale_page));
    }
    return sb.toString();
}
 
Example 5
Source File: AccountsSetManager.java    From fingen with Apache License 2.0 6 votes vote down vote up
public void editName(final AccountsSet accountsSet, Activity activity, final IOnEditAction onEditAction) {
    String title = activity.getString(R.string.ent_name);

    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(title);
    final EditText input = (EditText) activity.getLayoutInflater().inflate(R.layout.template_edittext, null);
    input.setText(accountsSet.getAccountsSetRef().getName());
    builder.setView(input);

    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            accountsSet.getAccountsSetRef().setName(input.getText().toString());
            onEditAction.onEdit(accountsSet);
        }
    });

    builder.show();
    input.requestFocus();
}
 
Example 6
Source File: URMUtils.java    From rebootmenu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 打开辅助服务设置或者发送执行广播
 *
 * @param activity 1
 */
public static void accessibilityOn(@NonNull Activity activity) {
    new DebugLog("accessibilityOn", DebugLog.LogLevel.V);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P && SpecialSupport.isAndroidWearOS(activity)) {
        activity.startActivity(new Intent(Settings.ACTION_SETTINGS));
        new TextToast(activity, activity.getString(R.string.android_wear_power_menu_in_sys_settings));
    } else {
        if (!isAccessibilitySettingsOn(activity.getApplicationContext())) {
            new TextToast(activity.getApplicationContext(), activity.getString(R.string.service_disabled));
            Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
            try {
                //匪夷所思,这个都能阉割掉(
                activity.startActivity(intent);
            }
            // SecurityException:BYD(com.byd.vehiclesettings/.system.mvp.view.app.AccessibilityActivity)
            // requires android.permission.GRANT_RUNTIME_PERMISSIONS
            catch (ActivityNotFoundException | SecurityException e) {
                new TextToast(activity, true, activity.getString(R.string.accessibility_settings_not_found), true);
            }
        } else {
            boolean isSucceed = LocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(UnRootAccessibility.POWER_DIALOG_ACTION));
            new DebugLog("sendBroadcast POWER_DIALOG_ACTION : " + isSucceed);
        }
    }
    activity.finish();
}
 
Example 7
Source File: ActionBarHelperCompat.java    From zhangshangwuda with Apache License 2.0 5 votes vote down vote up
public static void setActionBarUpIndicator(Object info, Activity activity, Drawable drawable, int contentDescRes) {
    final SetIndicatorInfo sii = (SetIndicatorInfo) info;
    if (sii.mUpIndicatorView != null) {
        sii.mUpIndicatorView.setImageDrawable(drawable);
        final String contentDescription = contentDescRes == 0 ? null : activity.getString(contentDescRes);
        sii.mUpIndicatorView.setContentDescription(contentDescription);
    }
}
 
Example 8
Source File: SuntimesSettingsActivity.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
private static void initPref_altitude(final Activity context, final CheckBoxPreference altitudePref)
{
    TypedArray a = context.obtainStyledAttributes(new int[]{R.attr.icActionAltitude});
    int drawableID = a.getResourceId(0, R.drawable.baseline_terrain_black_18);
    a.recycle();

    String title = context.getString(R.string.configLabel_general_altitude_enabled) + "  [i]";
    ImageSpan altitudeIcon = SuntimesUtils.createImageSpan(context, drawableID, 32, 32, 0);
    SpannableStringBuilder altitudeSpan = SuntimesUtils.createSpan(context, title, "[i]", altitudeIcon);
    altitudePref.setTitle(altitudeSpan);
}
 
Example 9
Source File: RightsStatus.java    From evercam-android with GNU Affero General Public License v3.0 5 votes vote down vote up
public RightsStatus(Activity activity, String description) {
    this.activity = activity;
    this.description = description;
    String fullRightsDescription = activity.getString(fullRightsStringId);
    String readOnlyDescription = activity.getString(readOnlyStringId);
    String noAccessDescription = activity.getString(noAccessStringId);

    if (description.equals(fullRightsDescription)) {
        rightString = Right.FULL_RIGHTS;
    } else if (description.equals(readOnlyDescription)) {
        rightString = Right.READ_ONLY;
    } else if (description.equals(noAccessDescription)) {
        rightString = null;
    }
}
 
Example 10
Source File: ContextMenuHelper.java    From uPods-android with Apache License 2.0 5 votes vote down vote up
public static void selectRadioStreamQuality(final Activity activity, final FragmentPlayer fragmentPlayer, final RadioItem currentMediaItem) {
    final RadioItem playableMediaItem = (RadioItem) UniversalPlayer.getInstance().getPlayingMediaItem();
    String[] availableStreams = (playableMediaItem).getAvailableStreams();
    for (int i = 0; i < availableStreams.length; i++) {
        availableStreams[i] = availableStreams[i] + activity.getString(R.string.kbps);
    }
    if (availableStreams.length == 0) {
        Toast.makeText(activity, activity.getString(R.string.not_available_for_stream), Toast.LENGTH_SHORT).show();
    } else {
        new MaterialDialog.Builder(activity).title(R.string.select_stream_quality)
                .items(availableStreams)
                .itemsCallbackSingleChoice(playableMediaItem.getSelectedStreamAsNumber(availableStreams),
                        new MaterialDialog.ListCallbackSingleChoice() {
                            @Override
                            public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                                String selectedStream = text.toString().replace(activity.getString(R.string.kbps), "");
                                SettingsManager.getInstace().saveStreamQualitySelection(playableMediaItem, selectedStream);
                                playableMediaItem.selectStreamUrl(selectedStream);
                                currentMediaItem.selectStreamUrl(selectedStream);
                                UniversalPlayer.getInstance().softRestart();
                                fragmentPlayer.initPlayerStateUI();
                                return true;
                            }
                        })
                .positiveText(R.string.select)
                .show();
    }
}
 
Example 11
Source File: AppRate.java    From discreet-app-rate with Apache License 2.0 5 votes vote down vote up
public static AppRate with(Activity activity) {
    if (activity == null) {
        throw new IllegalStateException("Activity cannot be null");
    }

    AppRate instance = new AppRate(activity);
    instance.text = activity.getString(R.string.dra_rate_app);
    instance.settings = activity.getSharedPreferences(PREFS_NAME, 0);
    instance.editor = instance.settings.edit();
    instance.packageName = activity.getPackageName();
    return instance;
}
 
Example 12
Source File: AccountManager.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
public SwitchAccountAsyncTask(Activity activity, int title, @Nullable Account destAccount, @Nullable String deleteDbName, @Nullable String qrAccount) {
    super(activity, null, activity.getString(title));
    this.activityWeakReference = new WeakReference<>(activity);
    this.destAccount = destAccount;
    this.deleteDbName = deleteDbName;
    this.qrAccount = qrAccount;
}
 
Example 13
Source File: PermissionHelper.java    From ToGoZip with GNU General Public License v3.0 5 votes vote down vote up
public static void showNowPermissionMessage(Activity activity) {
    String format = activity.getString(R.string.ERR_NO_WRITE_PERMISSIONS);

    String msg = String.format(
            format,
            "",
            "");

    Toast.makeText(activity, msg, Toast.LENGTH_LONG).show();
}
 
Example 14
Source File: URMUtils.java    From rebootmenu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 用辅助功能锁屏
 *
 * @param activity            1
 * @param componentName       2
 * @param requestCode         3
 * @param devicePolicyManager 4
 * @param needConfig          是否需要 配置管理员
 */

public static void lockScreen(@NonNull Activity activity, ComponentName componentName, int requestCode, DevicePolicyManager devicePolicyManager, boolean needConfig) {
    new DebugLog("lockScreen", DebugLog.LogLevel.V);
    //设备管理器是否启用
    boolean active = devicePolicyManager.isAdminActive(componentName);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
        //自动移除不必要的管理员,避免在卸载时造成困扰
        if (active) devicePolicyManager.removeActiveAdmin(componentName);
        //请求打开辅助服务设置
        if (!isAccessibilitySettingsOn(activity.getApplicationContext())) {
            new TextToast(activity.getApplicationContext(), activity.getString(R.string.service_disabled));
            try {
                activity.startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS));
            } catch (Throwable t) {
                t.printStackTrace();
                UIUtils.visibleHint(activity, R.string.accessibility_settings_not_found);
            }
        } else
            LocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(UnRootAccessibility.LOCK_SCREEN_ACTION));
        activity.finish();
    } else {
        if (!active) {
            //请求启用
            Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
            intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
            intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, activity.getString(R.string.service_explanation));
            try {
                activity.startActivityForResult(intent, requestCode);
            } catch (ActivityNotFoundException e) {
                UIUtils.visibleHint(activity, R.string.hint_add_dev_admin_activity_not_found);
            }
        } else {
            devicePolicyManager.lockNow();
            if (needConfig)
                //如果需要二次确认,禁用设备管理器。(这里的策略和root模式的锁屏无需确认不同)
                if (!ConfigManager.get(ConfigManager.NO_NEED_TO_CONFIRM)) {
                    devicePolicyManager.removeActiveAdmin(componentName);
                }
            activity.finish();
        }
    }
}
 
Example 15
Source File: TopicInfoFragment.java    From tindroid with Apache License 2.0 4 votes vote down vote up
private void showConfirmationDialog(final String arg1, final String arg2,
                                    final String uid,
                                    int title_id, int message_id,
                                    final int what) {
    final Activity activity = getActivity();
    if (activity == null) {
        return;
    }

    final AlertDialog.Builder confirmBuilder = new AlertDialog.Builder(activity);
    confirmBuilder.setNegativeButton(android.R.string.no, null);
    if (title_id != 0) {
        confirmBuilder.setTitle(title_id);
    }
    String message = activity.getString(message_id, arg1, arg2);
    confirmBuilder.setMessage(message);

    confirmBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            PromisedReply<ServerMessage> response = null;
            switch (what) {
                case ACTION_LEAVE:
                    response = mTopic.delete(true);
                    break;
                case ACTION_REPORT:
                    HashMap<String, Object> json =  new HashMap<>();
                    json.put("action", "report");
                    json.put("target", mTopic.getName());
                    Drafty msg = new Drafty().attachJSON(json);
                    Cache.getTinode().publish(Tinode.TOPIC_SYS, msg, Tinode.draftyHeadersFor(msg));
                    response = mTopic.updateMode(null, "-JP");
                    break;
                case ACTION_REMOVE:
                    response = mTopic.eject(uid, false);
                    break;
                case ACTION_BAN_TOPIC:
                    response = mTopic.updateMode(null, "-JP");
                    break;
                case ACTION_BAN_MEMBER:
                    response = mTopic.eject(uid, true);
                    break;
                case ACTION_DELMSG:
                    response = mTopic.delMessages(true);
            }

            if (response != null) {
                response.thenApply(new PromisedReply.SuccessListener<ServerMessage>() {
                    @Override
                    public PromisedReply<ServerMessage> onSuccess(ServerMessage result) {
                        Intent intent = new Intent(activity, ChatsActivity.class);
                        intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                        startActivity(intent);
                        activity.finish();
                        return null;
                    }
                }).thenCatch(mFailureListener);
            }
        }
    });
    confirmBuilder.show();
}
 
Example 16
Source File: TweetUnit.java    From Tweetin with Apache License 2.0 4 votes vote down vote up
public TweetUnit(Activity activity) {
    this.activity = activity;

    this.useScreenName = TwitterUnit.getUseScreenNameFromSharedPreferences(activity);
    this.me = activity.getString(R.string.tweet_info_retweeted_by_me);
}
 
Example 17
Source File: AboutDialog.java    From SuntimesWidget with GNU General Public License v3.0 4 votes vote down vote up
public static String initTranslationCredits(Activity activity)
{
    final String[] localeValues = activity.getResources().getStringArray(R.array.locale_values);
    final String[] localeCredits = activity.getResources().getStringArray(R.array.locale_credits);
    final String[] localeDisplay = activity.getResources().getStringArray(R.array.locale_display);

    final String currentLanguage = AppSettings.getLocale().getLanguage();
    Integer[] index = new Integer[localeDisplay.length];    // sort alphabetical (localized)
    for (int i=0; i < index.length; i++) {
        index[i] = i;
    }
    Arrays.sort(index, new Comparator<Integer>() {
        public int compare(Integer i1, Integer i2) {
            if (localeValues[i1].startsWith(currentLanguage)) {
                return -1;
            } else if (localeValues[i2].startsWith(currentLanguage)) {
                return 1;
            } else return localeDisplay[i1].compareTo(localeDisplay[i2]);
        }
    });

    StringBuilder credits = new StringBuilder();
    for (int i=0; i<index.length; i++)
    {
        int j = index[i];

        String localeCredits_j = (localeCredits.length > j ? localeCredits[j] : "");
        if (!localeCredits[j].isEmpty())
        {
            String localeDisplay_j = (localeDisplay.length > j ? localeDisplay[j] : localeValues[j]);
            String[] authorList = localeCredits_j.split("\\|");

            String authors = "";
            if (authorList.length < 2) {
                authors = authorList[0];

            } else if (authorList.length == 2) {
                authors = activity.getString(R.string.authorListFormat_n, authorList[0], authorList[1]);

            } else {
                for (int k=0; k<authorList.length-1; k++)
                {
                    if (authors.isEmpty())
                        authors = authorList[k];
                    else authors = activity.getString(R.string.authorListFormat_i, authors, authorList[k]);
                }
                authors = activity.getString(R.string.authorListFormat_n, authors, authorList[authorList.length-1]);
            }

            String line = activity.getString(R.string.translationCreditsFormat, localeDisplay_j, authors);
            if (i != index.length-1) {
                if (!line.endsWith("<br/>") && !line.endsWith("<br />"))
                    line = line + "<br/>";
            }
            credits.append(line);
        }
    }
    return activity.getString(R.string.app_legal2, credits.toString());
}
 
Example 18
Source File: EditorProfilesActivity.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
static void showDialogAboutRedText(Profile profile, Event event, boolean forShowInActivator, boolean forRunStopEvent, Activity activity) {
        if (activity == null)
            return;

        String nTitle = "";
        String nText = "";

        if (profile != null) {
            nTitle = activity.getString(R.string.profile_preferences_red_texts_title);
            nText = activity.getString(R.string.profile_preferences_red_texts_text_1) + " " +
                    "\"" + profile._name + "\" " +
                    activity.getString(R.string.preferences_red_texts_text_2);
            if (android.os.Build.VERSION.SDK_INT < 24) {
                nTitle = activity.getString(R.string.ppp_app_name);
                nText = activity.getString(R.string.profile_preferences_red_texts_title) + ": " +
                        activity.getString(R.string.profile_preferences_red_texts_text_1) + " " +
                        "\"" + profile._name + "\" " +
                        activity.getString(R.string.preferences_red_texts_text_2);
            }
            if (forShowInActivator)
                nText = nText + " " + activity.getString(R.string.profile_preferences_red_texts_text_3);
            else
                nText = nText + " " + activity.getString(R.string.profile_preferences_red_texts_text_2);
        }

        if (event != null) {
            nTitle = activity.getString(R.string.event_preferences_red_texts_title);
            nText = activity.getString(R.string.event_preferences_red_texts_text_1) + " " +
                    "\"" + event._name + "\" " +
                    activity.getString(R.string.preferences_red_texts_text_2);
            if (android.os.Build.VERSION.SDK_INT < 24) {
                nTitle = activity.getString(R.string.ppp_app_name);
                nText = activity.getString(R.string.event_preferences_red_texts_title) + ": " +
                        activity.getString(R.string.event_preferences_red_texts_text_1) + " " +
                        "\"" + event._name + "\" " +
                        activity.getString(R.string.preferences_red_texts_text_2);
            }
            if (forRunStopEvent)
                nText = nText + " " + activity.getString(R.string.event_preferences_red_texts_text_2);
            else
                nText = nText + " " + activity.getString(R.string.profile_preferences_red_texts_text_2);
        }

        if ((profile != null) || (event != null)) {
            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity);
            dialogBuilder.setTitle(nTitle);
            dialogBuilder.setMessage(nText);
            dialogBuilder.setPositiveButton(android.R.string.ok, null);
            AlertDialog dialog = dialogBuilder.create();

//            dialog.setOnShowListener(new DialogInterface.OnShowListener() {
//                @Override
//                public void onShow(DialogInterface dialog) {
//                    Button positive = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_POSITIVE);
//                    if (positive != null) positive.setAllCaps(false);
//                    Button negative = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
//                    if (negative != null) negative.setAllCaps(false);
//                }
//            });

            if (!activity.isFinishing())
                dialog.show();
        }
    }
 
Example 19
Source File: TimeZoneDialogTest.java    From SuntimesWidget with GNU General Public License v3.0 4 votes vote down vote up
public static void showTimezoneDialog(Activity activity, boolean verify)
{
    String actionTimezoneText = activity.getString(R.string.configAction_setTimeZone);
    openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getTargetContext());
    onView(withText(actionTimezoneText)).perform(click());
}
 
Example 20
Source File: HistoryPage.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
protected void initialize(Activity activity, final NativePageHost host) {
    mHistoryManager = new HistoryManager(
            activity, false, ((SnackbarManageable) activity).getSnackbarManager());
    mTitle = activity.getString(R.string.menu_history);
}