小编gmm*_*mmo的帖子

diff命令只获取不同行的数量

我可以使用diff命令找出两个文件是否相差k行?

我不想要上下文差异,只是两个文件之间不同的行总数.如果结果只是一个整数,则效果最佳.

谢谢!

linux shell ubuntu

16
推荐指数
2
解决办法
2万
查看次数

Glide断言:java.lang.IllegalArgumentException:您必须在主线程上调用此方法

有没有人用Glide从后台线程中获取图像?我一直得到这个断言:

java.lang.IllegalArgumentException: You must call this method on the main thread
Run Code Online (Sandbox Code Playgroud)

但根据这个线程,它应该工作:

https://github.com/bumptech/glide/issues/310

然而,我不能让它工作,除非我从主线程中调用它.

这是我试图从主线程做的事情:

    Glide.get(mContext);
    loadUserImage(userImageUrl);

    // wait 5 seconds before trying again
    int imageLoadingTimeOut = mContext.getResources().getInteger(R.integer.image_loading_time_out);
    if (imageLoadingTimeOut > 0) {
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                if (!mUserImageLoaded) {
                    loadUserImage(userImageUrl);
                }
            }
        }, imageLoadingTimeOut);
    }
}
Run Code Online (Sandbox Code Playgroud)

和loadUserImage:

private boolean mUserImageLoaded = false;

private void loadUserImage(String userImageUrl) {

    if (userImageUrl != null && !userImageUrl.isEmpty() && !mUserImageLoaded) {
        Glide.with(mContext).using(Cloudinary.getUrlLoader(mContext)).load(userImageUrl).crossFade().listener(new RequestListener<String, GlideDrawable>() {

            @Override
            public boolean onException(Exception …
Run Code Online (Sandbox Code Playgroud)

multithreading android android-glide

14
推荐指数
3
解决办法
2万
查看次数

自定义键盘:处理inputType更改

我遇到了一个我无法弄清楚的问题.我根据这个示例编写了一个简单的自定义IME键盘.

它基本上有两个自定义键盘,一个用于字母,一个用于数字.他们使用不同的布局.

但是,当我EditText为文本添加两个控件时,为数字添加一个控件时,键盘不会刷新到它所属的类型.我的意思是,如果我选择了EditTextinputType="text"第一,QWERTY键盘布局出现.但后来当我选择第二个EditTextinputType="number"QWERTY键盘再次出现.但是,它应该为连接到代码中的数字加载不同的布局.

换句话说,这是测试活动布局:

在此输入图像描述

现在,如果我选择"文本"字段,QWERTY键盘将显示如下:

在此输入图像描述

但是,如果我选择"数字"字段,QWERTY键盘仍会显示错误.

在此输入图像描述

预期的行为将是这个键盘出现.

在此输入图像描述

这是CustomIME的代码,我试图postInvalidate()在视图上使用,预加载所有布局onInitializeInterface()但没有任何效果.它永远不会正确切换到数字的布局

public class CustomIME extends InputMethodService
        implements KeyboardView.OnKeyboardActionListener {

    public static final String CUSTOM_IME = "CUSTOM_IME";
    private KeyboardView mKeyboardView;
    private Keyboard mKeyboardCurrent;
    private KeyboardType mKeyboardTypeCurrent = KeyboardType.QWERTY_LETTERS;
    private boolean mCAPs = false;


    enum KeyboardType {
        QWERTY_LETTERS,
        NUMBERS
    }

    @Override
    public View onCreateInputView() {
        loadCurrentKeyboard();
        mKeyboardView = (KeyboardView) getLayoutInflater().inflate(R.layout.custom_ime_keyboard, null);
        mKeyboardView.setBackgroundResource(R.drawable.btn_gradient);
        mKeyboardView.setOnKeyboardActionListener(this);

        if (mKeyboardCurrent != null) {
            mKeyboardView.setKeyboard(mKeyboardCurrent); …
Run Code Online (Sandbox Code Playgroud)

java android android-layout android-softkeyboard android-edittext

14
推荐指数
1
解决办法
1733
查看次数

为什么在android Listeners上使用WeakReference?

我正在开发一个大型代码库,并在很多地方看到这种类型的代码:

public static class RequestCustomData implements View.OnClickListener {
    WeakReference<MainActivity> mainActivity;

    public RequestCustomData(MainActivity activity) {
        mainActivity = new WeakReference<>(activity);
    }

    @Override
    public void onClick(View view) {
        MainActivity activity = mainActivity.get();
        activity.requestCustomData(true, null);
    }
}
Run Code Online (Sandbox Code Playgroud)

我有点困惑为什么这个用的是这么多地方?我看了一下这个文档,但它没有说明为什么这类代码在我正在使用它的应用程序上如此频繁地使用

https://community.oracle.com/blogs/enicholas/2006/05/04/understanding-weak-references

如果这是一种常见模式,任何人都可以解释我吗?如果是这样,为什么?

android weak-references

13
推荐指数
1
解决办法
8351
查看次数

应用程序关闭后无法使android服务保持活动状态

我正在尝试生成一个始终保持活动的服务,即使用户关闭了应用程序.根据这些线程

关闭应用程序后,保持位置服务活动

应用程序关闭时Android服务停止

Android:当应用程序被杀时,保持服务运行

这可以通过IntentServices或Service.START_STICKY来完成

然而,我尝试了两种类型的服务而没有成功.换句话说,当用户关闭应用程序时,我的服务就会被杀死.有人可以指出这是否可以做到以及如何做?这是我没有成功的尝试:

使用IntentService:

public class MyIntentService extends IntentService {
    private final int mPollingTimeMS = 500;
    private int mInitializationPollingCount = 0;
    private Thread mPollThread;
    public MyIntentService() {
        super("MyIntentService");
    }
    @Override
    protected void onHandleIntent(Intent intent) {
        mPollThread = new Thread() {
            public void run() {
                while (true) {
                    try {
                        Log.e(Constants.Engine.LOGGER_TAG_DEV,
                                "SDK Service Running: " +
                                        mInitializationPollingCount * mPollingTimeMS +
                                        "ms have elapsed");
                        mInitializationPollingCount++;
                        sleep(mPollingTimeMS);

                    } catch (Exception e) {
                        StackTraceElement trace = new Exception().getStackTrace()[0];
                        Logger.e(Constants.Engine.LOGGER_TAG_APP, "[Exception:" + …
Run Code Online (Sandbox Code Playgroud)

android android-service

11
推荐指数
2
解决办法
3万
查看次数

无法更改SwitchCompat小部件的文本大小

我很难改变开关紧凑型拇指的文字大小.

这是我的布局:

<android.support.v7.widget.SwitchCompat
    android:id="@+id/switch_compat2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="20dp"
    android:checked="true"
    android:switchTextAppearance="@style/MyStyle"
    android:text="SwitchCompat (SDK v7+)"
    app:showText="true" />
Run Code Online (Sandbox Code Playgroud)

和风格:

<style name="MyStyle">
    <item name="android:textColor">#229922</item>
    <item name="android:textSize">10sp</item>
</style>
Run Code Online (Sandbox Code Playgroud)

然而,无论我在"MyStyle"上做什么,开关总是如下所示:

在此输入图像描述

理想情况下,我希望它看起来像这样:

在此输入图像描述

任何人都愿意分享他们的drawables我可以尝试匹配上面的图像?

我正在调查这些线程但没有正确匹配.它让它看起来更糟.

如何更改Switch Widget的大小

谢谢!

android android-widget

8
推荐指数
1
解决办法
2030
查看次数

停止记录Android Beacon Library

我试图阻止Android信标库的调试,但它不起作用.

我在我的gradle中有这个:

compile 'org.altbeacon:android-beacon-library:2.3.3'
Run Code Online (Sandbox Code Playgroud)

我试过了:

public BeaconManager(Context ctx, org.altbeacon.beacon.BeaconManager beaconManager) {
    mContext = ctx;
    this.beaconManager = beaconManager;


    // this is saying deprecated
    this.beaconManager.setDebug(false);

    // I also tried this and the same thing
    org.altbeacon.beacon.logging.LogManager.setVerboseLoggingEnabled(false);
Run Code Online (Sandbox Code Playgroud)

但无论如何,我一直在获取这些日志.他们开始调试其他事情.

02-18 16:21:29.784 31809-31818/com.myapp D/ScanRecord: first manudata for manu ID
02-18 16:21:29.784 31809-31818/com.myapp D/BluetoothLeScanner: onScanResult() - ScanResult{mDevice=45:0A:1B:49:64:7F, mScanRecord=ScanRecord [mAdvertiseFlags=6, mServiceUuids=[f41ef1ee-fde5-23be-5f4b-589c71babfdd], mManufacturerSpecificData={76=[2, 21, 97, 104, 113, 9, -112, 95, 68, 54, -111, -8, -26, 2, -11, 20, -55, 109, 0, 3, 17, -71, -89]}, mServiceData={}, mTxPowerLevel=-2147483648, mDeviceName=BC Beacon?], …
Run Code Online (Sandbox Code Playgroud)

android proximity beacon android-api-levels

6
推荐指数
1
解决办法
2387
查看次数

从 OpenSSL AES 在 python 中解密 AES CBC

我需要使用 python 解密在 OpenSSL 上加密的文件,但我不了解 pycrypto 的选项。

这是我在 OpenSSL 中所做的

  1. openssl enc -aes-256-cbc -a -salt -pbkdf2 -iter 100000 -in "clear.txt" -out "crypt.txt" -pass pass:"mypassword"

  2. openssl enc -d -aes-256-cbc -a -pbkdf2 -iter 100000 -in "crypt.txt" -out "out.txt" -pass pass:"mypassword"

我试过了(这显然行不通)

obj2 = AES.new("mypassword", AES.MODE_CBC)
output = obj2.decrypt(text)
Run Code Online (Sandbox Code Playgroud)

我只想在python中做第二步,但是在查看示例时:

https://pypi.org/project/pycrypto/

obj2 = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')
obj2.decrypt(ciphertext)
Run Code Online (Sandbox Code Playgroud)

我不需要IV,我如何指定盐?pbkdf2 哈希?我也在看这个线程

如何在 Python 中解密 OpenSSL AES 加密的文件?

但没有帮助。

有人可以告诉我如何使用 python 做到这一点吗?

谢谢你。

python encryption openssl pycrypto pycryptodome

6
推荐指数
1
解决办法
1391
查看次数

无法自定义EditText的外观选择横向上的句柄/锚点

我很难自定义EditText选择句柄.我正在关注这个帖子:

如何更改EditText的颜色/外观选择句柄/锚点?

看起来很简单.然而,我无法让它在景观方面发挥作用.谁能发现我做错了什么?我几乎在测试活动上粘贴了相同的代码,但锚句柄总是相同的.我尝试使用建议和编程方式的样式.仍然我总是得到相同的默认蓝色锚:(

我在Nougat不确定是否有任何区别.

测试活动:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(R.style.MyCustomTheme);
    setContentView(R.layout.activity_main);
    final EditText editText = (EditText) findViewById(R.id.edit1);
    // tried programatically too and no success
    try {
        final Field fEditor = TextView.class.getDeclaredField("mEditor");
        fEditor.setAccessible(true);
        final Object editor = fEditor.get(editText);
        final Field fSelectHandleLeft = editor.getClass().getDeclaredField("mSelectHandleLeft");
        final Field fSelectHandleRight =
                editor.getClass().getDeclaredField("mSelectHandleRight");
        final Field fSelectHandleCenter =
                editor.getClass().getDeclaredField("mSelectHandleCenter");
        fSelectHandleLeft.setAccessible(true);
        fSelectHandleRight.setAccessible(true);
        fSelectHandleCenter.setAccessible(true);
        fSelectHandleLeft.set(editor, ContextCompat.getDrawable(this, R.drawable.small_rect));
        fSelectHandleRight.set(editor, ContextCompat.getDrawable(this, R.drawable.small_rect));
        fSelectHandleCenter.set(editor, ContextCompat.getDrawable(this, R.drawable.small_rect));
    } catch (final Exception e) {
        Log.d("CUSTOM_ANCHORS", e.toString());
    }
}
Run Code Online (Sandbox Code Playgroud)

布局:

<?xml version="1.0" …
Run Code Online (Sandbox Code Playgroud)

android android-edittext

5
推荐指数
1
解决办法
735
查看次数

android studio 1.4.1错误:(15,0)未找到Gradle DSL方法:'ndk()'

我在线关注本教程

https://youtu.be/kFtxo7rr2HQ

当我试图建立时,我一直在努力:

错误:(15,0)未找到Gradle DSL方法:'ndk()'可能的原因:

  • 项目"NDKTest"可能正在使用不包含该方法的Gradle版本.Gradle设置
  • 构建文件可能缺少Gradle插件.应用Gradle插件
  • 我试过这个帖子:

    未找到Android Studio Gradle DSL方法:'android()' - 错误(17,0)

    但现在已经很老了.

    这是我的build.gradle文件

    apply plugin: 'com.android.application'
    android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    
    defaultConfig {
        applicationId "com.guitarv.www.ndktest"
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    
    ndk {
    
                moduleName = "HelloJNI"
        }
    
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    }
    
    Run Code Online (Sandbox Code Playgroud)

    Android Studio 1.4.1 android-ndk-r10e

    谁知道发生了什么事?

    谢谢!

    android-studio

    3
    推荐指数
    1
    解决办法
    2946
    查看次数