Tag Archives: Android

Android’s viewpager slides to determine whether the current stop page is the last page

Step 1: write several global variables to record:

   /**
     * Record if the sliding page is the last page
     */
    private boolean isHomeLastPage = false;
    private boolean isHomeDragPage = false;

The second step is to get the last element by implementing the listening onpageselected() in VP

@Override
	     public void onPageSelected(int position) {
	            super.onPageSelected(position);
	
	            Log.e("videoPositionposition", position + "");
	            //get the last page/position equals the last element
	            isHomeLastPage = position == datas.size() - 1;
	      }

The third step is to implement the listening onpagescrollstatechanged() in VP to determine whether the current sliding state is in,

   @Override
            public void onPageScrollStateChanged(int state) {
                // 0: do nothing 1: start sliding 2: end sliding Scrolling listener
                isHomeDragPage = state == ViewPager2.SCROLL_STATE_DRAGGING;
                //judge that the last one will not be loaded
            }

The fourth step is to implement onpagescrolled() 1.
1. Judge whether it is the last element
2. Whether it is in sliding state,
3. The offset of posionoffsetpixels is 0.
the work is done, and the judgment of VP sliding to the last page has been done

 @Override
 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

       //Determine the last element and slide state, and the offset is 0
       Log.e("vp2CCC", "vp2CCC" + isHomeLastPage + " " + isHomeDragPage + " " + positionOffsetPixels);
       if (isHomeLastPage && isHomeDragPage && positionOffsetPixels == 0) { //the current page is the last page and is dragging and the pixel offset is 0
           Toast.makeText(getActivity(), "The current page is the last page", Toast.LENGTH_SHORT).show();
       } else {
       }
   }

Could not install Gradle distribution

Could not install Gradle distribution

New computer, new Android studio 4.2, new first project error:

Could not install Gradle distribution from 'https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip'

Solution:
(1) click the link in the error message:
1 https://services.gradle.org/distributions/gradle-6.7.1-bin.zip
Download the compressed package to the specified path and unzip it
(2) click file – & gt; Settings-> Build, Execution,Deployment-> Build Tools-> Gradle, in the gradle projects area, change use gradle from to your own download path, retry:

(3) Successful solution:

On the solution of fileprovider conflict

Fileprovider conflict resolution

Because the Maven service of Weibo sharing SDK is abnormal, the Maven automatic integration fails, so the AAR file of Weibo 10.10.0 is downloaded for local integration. Error report after adding project android:resource= “@xml/file_ XXX “reuse does not work 1. Upgrade compilesdkversion = 29
2. Add tools:replace= “ android:resource ”Go to the following figure

   <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileProvider"
            android:exported="false"
            android:grantUriPermissions="true"
            tools:replace="android:authorities">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_xxx"
                tools:replace="android:resource" />
        </provider>

solve

It is invalid to submit the content directly after pasting it on the mobile terminal of Vue HTML5 editor

Modify the source code vue-html5-editor.js
Directory:

open this file, search for contenteditable, add id = “container”

and then search for Keyup
comment code

 // content.addEventListener('keyup', function () {
 //     this$1.$emit('change', content.innerHTML);
 //     this$1.saveCurrentRange();
 // }, false);

Add code

const handleListenChange = (mutationsList, observer) => {
 this$1.$emit('change', content.innerHTML);
 this$1.saveCurrentRange();
}
const mutationObserver = new MutationObserver(handleListenChange)
const element = document.querySelector('#container')
const options = {
 attributes: true,
 childList: true,
 subtree: true,
 characterData: true
}

It’s like this on the whole

I’ve looked at others and modified it myself. This question is more detailed than that of the blogger. Link to attach. If you have any other questions, take a look
CSDN of Dashen

java.lang.IllegalArgumentException: Receiver not registered:

Problem: the radio receiver is not registered;

Recurrence: register the broadcast in oncreate() and de register in onstop(). In this activity, the device enters the screen saver state and executes onstop(). At this time, the broadcast has been de registered. Click the screen to return to the interface and no longer execute oncreate(). If you enter the screen saver interface again, an exception will be generated.

Solution: if receiver registration and de registration are placed in onresume and onpause, these two processes will definitely appear in pairs, which can avoid this exception.

Android notex Q9: pop up settings can be touched

If it is set to true, it will still be dropped by miss when clicking outside. Why?

/**
 * <p>Controls whether the pop-up will be informed of touch events outside
 * of its window.  This only makes sense for pop-ups that are touchable
 * but not focusable, which means touches outside of the window will
 * be delivered to the window behind.  The default is false.</p>
 *
 * <p>If the popup is showing, calling this method will take effect only
 * the next time the popup is shown or through a manual call to one of
 * the {@link #update()} methods.</p>
 *
 * @param touchable true if the popup should receive outside
 * touch events, false otherwise
 *
 * @see #isOutsideTouchable()
 * @see #isShowing()
 * @see #update()
 */
public void setOutsideTouchable(boolean touchable) {
mOutsideTouchable = touchable;
}

According to the interpretation of the official API, when focusable = false, setting setoutsidetouchable is meaningful. If focusable = true is set, it is meaningless, because focusable = true will take away the focus event. If outside can’t get the focus, then the touch of outside is useless.

So how to set focusable = true and keep external clicks from being ignored?

var isForceDismiss = false
override fun dismiss() {
if (isForceDismiss) {
super.dismiss()
isForceDismiss = true
    }
}

Rewrite the Miss method of popupwindow and make a logical judgment

Project with path ‘XXXX’ could not be found

 
My main problem is to delete a library module and submit the code to the server through GIT. When my colleagues pull the code I upload through git, the project still exists in the library and report the dependency error E rror:Project with path ‘XXXX’ could not be found

reason:

When the project is compiled, options corresponding to the related library will appear in gradle.xml automatically generated by. Idea, as shown in the figure

terms of settlement:

Delete the option node of the corresponding library, close the project and re open the compilation.

A more crude way is to delete the. Idea file directly, close the project, and reopen the compilation.

How to remove the title bar (using the request window feature)( Window.FEATURE_ NO_ Title); why it fails)

The method to remove the title bar (use requestWindowFeature(window.feature_no_title); Why does it fail?
Use RequestWindowFeature (window.feature_no_title) to hide the cause of the failure of the title bar, possibly because the activity inherits from AppCompatActivity. The use method is described in detail below:
A, if you create the activity inherited activity:
the first one: introduction to often use a method:

requestWindowFeature(Window.FEATURE_NO_TITLE);

//remove the title bar of note that this sentence must be written in the book of the setContentView () method, in front of or complains
the second: in the AndroidManifest. Defined in the XML file

<application android:theme="@android:style/Theme.NoTitleBar">

Wrote, then the application will remove the title bar, if just want to get rid of a certain Activity of the title bar, you can add this property to the Activity inside the tag
the third: this is not commonly used in general application, is in the res/values below to create a new style. The XML file
code is as follows:
duplicate code

<?xml version="1.0" encoding="UTF-8" ?>
<resources>
    <style name="notitle">
        <item name="android:windowNoTitle">
            true
        </item>
    </style>
</resources>

Copying code
in this way, we can customize a style, is equivalent to a topic, and then in the AndroidManifest. Defined in the XML file, also can achieve the effect of removing the title bar
code is as follows:

<application 
    android:icon="@drawable/icon" 
    android:label="@string/app_name" 
    android:theme="@style/notitle">

AppCompatActivity>

getSupportActionBar().hide();
//Remove the title bar Note that this sentence must be written after the setContentView() method

Second: You can do the following in AndroidManifest.xml, so there is no title bar

<application
   android:theme="@style/Theme.AppCompat.NoActionBar">

Failed to dlsym make_device: undefined symbol: make_device

Failed to dlsym make_ device: undefined symbol: make_ device

Recently, I encountered some bugs when doing development. I have been troubled for a long time. Although I am a good cook, I think I can accumulate it. When I encounter the same type of problems in the future, I have a way to solve the problems. The problem is as follows: Android recovery system can do some basic test demo below. But this latest demo is developed by C + + and C language. Some functions need to rely on dynamic libraries, such as librecovery_ UI. So, but there is a special library called librecovery_ ui.recovery.so。 At that time, using the find command, we could find the generation location of the library. However, when using grep to find the generation location of the dynamic library, we couldn’t find it. We only found the calling location. For a time, we doubted whether we had made a mistake. Finally, we searched under the general system root directory. Finally, we kept printing a lot of messy code under the out subdirectory, thinking it was a program crash, It’s time for ^ C to end the process. But in the end, no matter how many, just let it collapse. Finally, we found the location of the Library under the out directory. It turned out that it was an automatically generated MK file, in which many concise generation dependent library scripts were used. Finally, we found the location of the so.

Then I met the problem on the topic, that is, how can the so library compiled according to the correct android.mk script file not find the defined library when using dlopen call?I wonder if there is a problem with the function, and then I wrote a new function to test the call, and found it still can’t work, Failed to dlsym FN: undefined symbol: test is also displayed. Then I searched the Internet and found that most people said that they needed to add extern “C” to the function. Finally, according to what I said on the Internet, I found that it was still not possible. Finally, I asked my colleagues and got the answer to the question, which is to use the nm command of Linux to find the dynamic library or the static library that contains the functions that can be called. Finally, I found that the dynamic library that I passed to the board did not have the make that I wanted to call_ Then use the find command to find two. So libraries with the same name. Finally, find the function body to be called in another library. Finally, transfer another. So library to the board. Finally, it is successful.

Remember an android app startup error Error running: Default Activity not found

The errors are shown in the figure below:

Reason 1:
This is because it is possible that When we delete the activity during the operation, Android Studio automatically removes our activity tag information from the Androidmanifest.XML, but when we create the activity again, it does not automatically fill in our activity information, so we need to fill it out manually.
Reason 1 Solution:
Fill in the Activity tag information in the Androidmanifest.xml:

<application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

Reason 2:
Because of the requirement, projects do not need the Activity class. This is because When you create a project, AndroidStudio defaults to Lunche, which requires activity, so it will report an error.
Reason 2 solutions:
Step 1: Go to the Settings page

Step 2: Set it to Nothing in launch.

[error record] Android application release package error handling (turn off syntax check log processing release configuration)

1. Turn off grammar checking


 

When Android applications are packaged, there will be a series of syntax checks, such as the placement of a layout file, which is cumbersome;

In build. Gradle under the module, configure as follows: check the syntax and ignore some minor syntax errors;

android {
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
}

 

 

 

 

2. Log processing

According to the compilation type buildconfig.debug in the current compilation configuration, select whether to print the log;

public final class BuildConfig {
  public static final boolean DEBUG = Boolean.parseBoolean("true");
  public static final String APPLICATION_ID = "cn.zkhw.midi";
  public static final String BUILD_TYPE = "debug";
  public static final int VERSION_CODE = 1;
  public static final String VERSION_NAME = "0.1";
}

If the current version is release, the value of buildconfig.debug is false;

 

Example of development log tool class log:

public class L {

    public static void i(String TAG, String msg) {
        if (BuildConfig.DEBUG)
            Log.i(TAG, msg);
    }
}

 

3. Release compiler optimization configuration

In general, the release release version needs the following configuration;

android {
    buildTypes {
        debug {
        }

        release {
            zipAlignEnabled true     
            shrinkResources true    
            minifyEnabled true      
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}