Files
app_Settings/src/com/android/settings/localepicker/LocaleRecyclerView.java
Tsung-Mao Fang 2b78aa0988 Fix unable to change language
In some cases, recycler view receives the cancel touch event,
it causes recycler view doesn't update the new locale list.

Currently, we also treat cancel event as a signal to update the locale.
According to the document, we can treat cancel event as a up
event, but not perform any action that you normally would.

It's ok in our case since we check if updated list is same as
last one in adapater.

Test: Drag and drop locale item, and make sure the language system
is updated.
Fix: 184051013
Fix: 184903189
Fix: 185000363

Change-Id: I06610080f34c5ed3562c74e1cdd955571cae55c0
2021-04-23 22:35:55 +08:00

49 lines
1.5 KiB
Java

/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.localepicker;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import androidx.recyclerview.widget.RecyclerView;
class LocaleRecyclerView extends RecyclerView {
public LocaleRecyclerView(Context context) {
super(context);
}
public LocaleRecyclerView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public LocaleRecyclerView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onTouchEvent(MotionEvent e) {
if (e.getAction() == MotionEvent.ACTION_UP || e.getAction() == MotionEvent.ACTION_CANCEL) {
LocaleDragAndDropAdapter adapter = (LocaleDragAndDropAdapter) this.getAdapter();
if (adapter != null) {
adapter.doTheUpdate();
}
}
return super.onTouchEvent(e);
}
}