Activity_main_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main_menu_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="fyp.hkust.facet.activity.MainMenuActivity"
android:background="@drawable/background_dark_circle">
<ImageButton
android:layout_width="65dp"
android:layout_height="65dp"
android:background="@mipmap/ic_location_on_white_36dp"
android:id="@+id/store_button"
android:layout_below="@+id/photo_camera"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="65dp"
android:layout_height="65dp"
android:background="@mipmap/ic_favorite_white_36dp"
android:id="@+id/fav_button"
android:layout_below="@+id/photo_camera"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:id="@+id/location_text"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/store_text"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/store_button"
android:layout_alignEnd="@+id/store_button"
android:layout_below="@+id/store_button" />
<TextView
android:id="@+id/fav_text"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/favourite_text"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:layout_below="@+id/fav_button"
android:layout_alignLeft="@+id/fav_button"
android:layout_alignStart="@+id/fav_button" />
<TextView
android:id="@+id/account_text"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/my_account_text"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:layout_below="@+id/account_button"
android:layout_alignLeft="@+id/account_button"
android:layout_alignStart="@+id/account_button" />
<TextView
android:id="@+id/photo_camera_text"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/facet_match_text"
android:layout_marginLeft="5dp"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:layout_above="@+id/fav_text"
android:layout_centerHorizontal="true"
android:layout_marginBottom="58dp" />
<ImageButton
android:layout_width="125dp"
android:layout_height="125dp"
android:background="@mipmap/ic_photo_camera_white_36dp"
android:id="@+id/photo_camera"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/>
<ImageButton
android:layout_width="65dp"
android:layout_height="65dp"
android:background="@mipmap/ic_account_circle_white_36dp"
android:id="@+id/account_button"
android:layout_alignTop="@+id/shopping_button"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
/>
<TextView
android:id="@+id/product_text"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/all_products_text"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignBottom="@+id/account_text"
android:layout_below="@+id/account_button"
android:layout_alignRight="@+id/shopping_button"
android:layout_alignEnd="@+id/shopping_button" />
<ImageButton
android:layout_width="65dp"
android:layout_height="65dp"
android:background="@mipmap/ic_shopping_basket_white_36dp"
android:id="@+id/shopping_button"
android:layout_marginBottom="15dp"
android:layout_marginLeft="5dp"
android:layout_above="@+id/photo_camera"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
MainMenuActivity.java
public class MainMenuActivity extends AppCompatActivity {
private static final String TAG = MainMenuActivity.class.getSimpleName();
private static final int CAM_REQUEST = 3;
private static String[] PERMISSIONS_REQ = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA
};
private static final int REQUEST_CODE_PERMISSION = 2;
private View activity_main_menu_layout;
private ImageButton shoppingBtn;
private ImageButton photoCameraBtn;
private ImageButton accountBtn;
private ImageButton storeBtn;
private static final int GALLERY_REQUEST = 1;
private static int OVERLAY_PERMISSION_REQ_CODE = 3;
private ImageButton favBtn;
private int buttonNumber = 0;
private String captureImageFullPath = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
activity_main_menu_layout = (RelativeLayout) findViewById(R.id.activity_main_menu_layout);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window window = getWindow();
// Translucent status bar
window.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
Typeface fontType = FontManager.getTypeface(getApplicationContext(), FontManager.APP_FONT);
FontManager.markAsIconContainer(findViewById(R.id.activity_main_menu_layout), fontType);
photoCameraBtn = (ImageButton) findViewById(R.id.photo_camera);
shoppingBtn = (ImageButton) findViewById(R.id.shopping_button);
accountBtn = (ImageButton) findViewById(R.id.account_button);
storeBtn = (ImageButton) findViewById(R.id.store_button);
favBtn = (ImageButton) findViewById(R.id.fav_button);
photoCameraBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showAlertDialog();
}
});
shoppingBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent Intent = new Intent(MainMenuActivity.this, MainActivity.class);
startActivity(Intent);
}
});
accountBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent accountIntent = new Intent(MainMenuActivity.this, ProfileActivity.class);
startActivity(accountIntent);
}
});
storeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showMakeUpDialog();
}
});
favBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent storeIntent = new Intent(MainMenuActivity.this, ShopListActivity.class);
startActivity(storeIntent);
}
});
// Just use hugo to print log
isExternalStorageWritable();
isExternalStorageReadable();
// For API 23+ you need to request the read/write permissions even if they are already in your manifest.
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= Build.VERSION_CODES.M) {
verifyPermissions(this);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.canDrawOverlays(this.getApplicationContext())) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
}
}
if (!isMyServiceRunning(MyService.class))
startService(new Intent(this, MyService.class));
}
private void showAlertDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Choose the way to get your selfie");
builder.setIcon(R.mipmap.app_icon);
builder.setCancelable(true);
final String[] items = new String[]{"From Gallery", "Take Photo"};
final Integer[] icons = new Integer[]{R.mipmap.app_icon, R.mipmap.app_icon};
ListAdapter adapter = new ArrayAdapterWithIcon(getApplication(), items, icons);
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
switch (item) {
case 0: {
buttonNumber = 1;
Intent intent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, GALLERY_REQUEST);
break;
}
case 1: {
Intent cameraViewIntent = new Intent(MainMenuActivity.this, ShowCameraViewActivity.class);
startActivity(cameraViewIntent);
break;
}
}
}
}).show();
}
private void showMakeUpDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Choose the way to get your selfie");
builder.setIcon(R.mipmap.app_icon);
builder.setCancelable(true);
final String[] items = new String[]{"From Gallery", "Take Photo"};
final Integer[] icons = new Integer[]{R.mipmap.app_icon, R.mipmap.app_icon};
ListAdapter adapter = new ArrayAdapterWithIcon(getApplication(), items, icons);
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
switch (item) {
case 0: {
buttonNumber = 2;
Intent intent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, GALLERY_REQUEST);
break;
}
case 1: {
Intent cameraViewIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = getFile();
cameraViewIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(cameraViewIntent, CAM_REQUEST);
break;
}
}
}
}).show();
}
private boolean isMyServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
private File getFile() {
File folder = new File("sdcard/FaceT");
if (!folder.exists()) {
folder.mkdir();
}
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
captureImageFullPath = folder + "/makeup_" + currentDateTimeString;
File imageFile = new File(captureImageFullPath);
return imageFile;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == OVERLAY_PERMISSION_REQ_CODE) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.canDrawOverlays(this.getApplicationContext())) {
Snackbar snackbar = Snackbar
.make(activity_main_menu_layout, "CameraActivity\", \"SYSTEM_ALERT_WINDOW, permission not granted...", Snackbar.LENGTH_SHORT);
snackbar.show();
} else {
Intent intent = getIntent();
finish();
startActivity(intent);
}
}
}
if (requestCode == GALLERY_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri pickedImage = data.getData();
Log.d(TAG, "selected!!!" + " : " + pickedImage.getPath());
// Let's read picked image path using content resolver
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(pickedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
Log.d(TAG + "Path:", picturePath);
Intent intent = new Intent();
if (buttonNumber == 1)
intent.setClass(MainMenuActivity.this, CaptureActivity.class);
else if (buttonNumber == 2)
intent.setClass(MainMenuActivity.this, ColorizeFaceActivity.class);
intent.putExtra("path", picturePath);
//intent.putExtra("color" , "" + mBlobColorHsv);
startActivity(intent);
} else if (requestCode == CAM_REQUEST) {
Intent intent = new Intent();
intent.setClass(MainMenuActivity.this, ColorizeFaceActivity.class);
intent.putExtra("path", captureImageFullPath);
startActivity(intent);
}
}
/**
* Checks if the app has permission to write to device storage or open camera
* If the app does not has permission then the user will be prompted to grant permissions
*
* @param activity
*/
private static boolean verifyPermissions(Activity activity) {
// Check if we have write permission
int write_permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
int read_persmission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
int camera_permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.CAMERA);
if (write_permission != PackageManager.PERMISSION_GRANTED ||
read_persmission != PackageManager.PERMISSION_GRANTED ||
camera_permission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
ActivityCompat.requestPermissions(
activity,
PERMISSIONS_REQ,
REQUEST_CODE_PERMISSION
);
return false;
} else {
return true;
}
}
/* Checks if external storage is available for read and write */
private boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
/* Checks if external storage is available to at least read */
private boolean isExternalStorageReadable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state) ||
Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
return true;
}
return false;
}
}
Сообщение в logcat:
04-06 16:47:17.794 934-934/? I/art: Позднее включение -Xcheck:jni 04-06 16:47:17.945 934-934/fyp.hkust.facet W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath -- runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime -arg -Xms64m --runtime-arg -Xmx512m --вариант-набора-инструкций=krait --набор-инструкций-функций=по умолчанию --dex-file=/data/app/fyp.hkust.facet-2/split_lib_dependencies_apk. apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]), поскольку статус выхода не равен 0 04-06 16:47:18.685 934-934/fyp.hkust.facet W/art: /data/app/fyp.hkust.facet-2/split_lib_dependencies_apk.apk содержит более 100 файлов dex. Рассмотрите возможность объединения и сокращения числа, чтобы избежать накладных расходов во время выполнения.
04-06 16:47:18.851 934-934/fyp.hkust.facet W/art: Ошибка execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set = arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/fyp.hkust.facet-2/split_lib_slice_0_apk.apk --oat-file=/data/dalvik -cache/arm/data@[email protected]@[email protected]), потому что статус выхода не равен 0
04-06 16:47:18.919 934-934/fyp.hkust.facet W/art: Ошибка execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set = arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/fyp.hkust.facet-2/split_lib_slice
apk.apk --oat-file=/data/dalvik -cache/arm/data@[email protected]@split_lib_slice<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main_menu_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="fyp.hkust.facet.activity.MainMenuActivity" android:background="@drawable/background_dark_circle"> <ImageButton android:layout_width="65dp" android:layout_height="65dp" android:background="@mipmap/ic_location_on_white_36dp" android:id="@+id/store_button" android:layout_below="@+id/photo_camera" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <ImageButton android:layout_width="65dp" android:layout_height="65dp" android:background="@mipmap/ic_favorite_white_36dp" android:id="@+id/fav_button" android:layout_below="@+id/photo_camera" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" /> <TextView android:id="@+id/location_text" android:layout_width="80dp" android:layout_height="wrap_content" android:gravity="center" android:text="@string/store_text" android:textColor="#FFFFFF" android:textStyle="bold" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignRight="@+id/store_button" android:layout_alignEnd="@+id/store_button" android:layout_below="@+id/store_button" /> <TextView android:id="@+id/fav_text" android:layout_width="80dp" android:layout_height="wrap_content" android:gravity="center" android:text="@string/favourite_text" android:textColor="#FFFFFF" android:textStyle="bold" android:layout_below="@+id/fav_button" android:layout_alignLeft="@+id/fav_button" android:layout_alignStart="@+id/fav_button" /> <TextView android:id="@+id/account_text" android:layout_width="150dp" android:layout_height="wrap_content" android:gravity="center" android:text="@string/my_account_text" android:textColor="#FFFFFF" android:textStyle="bold" android:layout_below="@+id/account_button" android:layout_alignLeft="@+id/account_button" android:layout_alignStart="@+id/account_button" /> <TextView android:id="@+id/photo_camera_text" android:layout_width="100dp" android:layout_height="wrap_content" android:gravity="center" android:text="@string/facet_match_text" android:layout_marginLeft="5dp" android:textColor="#FFFFFF" android:textStyle="bold" android:layout_above="@+id/fav_text" android:layout_centerHorizontal="true" android:layout_marginBottom="58dp" /> <ImageButton android:layout_width="125dp" android:layout_height="125dp" android:background="@mipmap/ic_photo_camera_white_36dp" android:id="@+id/photo_camera" android:layout_centerVertical="true" android:layout_centerHorizontal="true" /> <ImageButton android:layout_width="65dp" android:layout_height="65dp" android:background="@mipmap/ic_account_circle_white_36dp" android:id="@+id/account_button" android:layout_alignTop="@+id/shopping_button" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" /> <TextView android:id="@+id/product_text" android:layout_width="80dp" android:layout_height="wrap_content" android:gravity="center" android:text="@string/all_products_text" android:textColor="#FFFFFF" android:textStyle="bold" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignBottom="@+id/account_text" android:layout_below="@+id/account_button" android:layout_alignRight="@+id/shopping_button" android:layout_alignEnd="@+id/shopping_button" /> <ImageButton android:layout_width="65dp" android:layout_height="65dp" android:background="@mipmap/ic_shopping_basket_white_36dp" android:id="@+id/shopping_button" android:layout_marginBottom="15dp" android:layout_marginLeft="5dp" android:layout_above="@+id/photo_camera" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> </RelativeLayout>
[email protected]), потому что статус выхода не равен 0<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main_menu_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="fyp.hkust.facet.activity.MainMenuActivity" android:background="@drawable/background_dark_circle"> <ImageButton android:layout_width="65dp" android:layout_height="65dp" android:background="@mipmap/ic_location_on_white_36dp" android:id="@+id/store_button" android:layout_below="@+id/photo_camera" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <ImageButton android:layout_width="65dp" android:layout_height="65dp" android:background="@mipmap/ic_favorite_white_36dp" android:id="@+id/fav_button" android:layout_below="@+id/photo_camera" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" /> <TextView android:id="@+id/location_text" android:layout_width="80dp" android:layout_height="wrap_content" android:gravity="center" android:text="@string/store_text" android:textColor="#FFFFFF" android:textStyle="bold" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignRight="@+id/store_button" android:layout_alignEnd="@+id/store_button" android:layout_below="@+id/store_button" /> <TextView android:id="@+id/fav_text" android:layout_width="80dp" android:layout_height="wrap_content" android:gravity="center" android:text="@string/favourite_text" android:textColor="#FFFFFF" android:textStyle="bold" android:layout_below="@+id/fav_button" android:layout_alignLeft="@+id/fav_button" android:layout_alignStart="@+id/fav_button" /> <TextView android:id="@+id/account_text" android:layout_width="150dp" android:layout_height="wrap_content" android:gravity="center" android:text="@string/my_account_text" android:textColor="#FFFFFF" android:textStyle="bold" android:layout_below="@+id/account_button" android:layout_alignLeft="@+id/account_button" android:layout_alignStart="@+id/account_button" /> <TextView android:id="@+id/photo_camera_text" android:layout_width="100dp" android:layout_height="wrap_content" android:gravity="center" android:text="@string/facet_match_text" android:layout_marginLeft="5dp" android:textColor="#FFFFFF" android:textStyle="bold" android:layout_above="@+id/fav_text" android:layout_centerHorizontal="true" android:layout_marginBottom="58dp" /> <ImageButton android:layout_width="125dp" android:layout_height="125dp" android:background="@mipmap/ic_photo_camera_white_36dp" android:id="@+id/photo_camera" android:layout_centerVertical="true" android:layout_centerHorizontal="true" /> <ImageButton android:layout_width="65dp" android:layout_height="65dp" android:background="@mipmap/ic_account_circle_white_36dp" android:id="@+id/account_button" android:layout_alignTop="@+id/shopping_button" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" /> <TextView android:id="@+id/product_text" android:layout_width="80dp" android:layout_height="wrap_content" android:gravity="center" android:text="@string/all_products_text" android:textColor="#FFFFFF" android:textStyle="bold" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignBottom="@+id/account_text" android:layout_below="@+id/account_button" android:layout_alignRight="@+id/shopping_button" android:layout_alignEnd="@+id/shopping_button" /> <ImageButton android:layout_width="65dp" android:layout_height="65dp" android:background="@mipmap/ic_shopping_basket_white_36dp" android:id="@+id/shopping_button" android:layout_marginBottom="15dp" android:layout_marginLeft="5dp" android:layout_above="@+id/photo_camera" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> </RelativeLayout>
04-06 16:47:18.995 934-934/fyp.hkust.facet W/art: Ошибка execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set = arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/fyp.hkust.facet-2/split_lib_slice
apk.apk --oat-file=/data/dalvik -cache/arm/data@[email protected]@split_lib_slicepublic class MainMenuActivity extends AppCompatActivity { private static final String TAG = MainMenuActivity.class.getSimpleName(); private static final int CAM_REQUEST = 3; private static String[] PERMISSIONS_REQ = { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA }; private static final int REQUEST_CODE_PERMISSION = 2; private View activity_main_menu_layout; private ImageButton shoppingBtn; private ImageButton photoCameraBtn; private ImageButton accountBtn; private ImageButton storeBtn; private static final int GALLERY_REQUEST = 1; private static int OVERLAY_PERMISSION_REQ_CODE = 3; private ImageButton favBtn; private int buttonNumber = 0; private String captureImageFullPath = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_menu); activity_main_menu_layout = (RelativeLayout) findViewById(R.id.activity_main_menu_layout); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window window = getWindow(); // Translucent status bar window.setFlags( WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } Typeface fontType = FontManager.getTypeface(getApplicationContext(), FontManager.APP_FONT); FontManager.markAsIconContainer(findViewById(R.id.activity_main_menu_layout), fontType); photoCameraBtn = (ImageButton) findViewById(R.id.photo_camera); shoppingBtn = (ImageButton) findViewById(R.id.shopping_button); accountBtn = (ImageButton) findViewById(R.id.account_button); storeBtn = (ImageButton) findViewById(R.id.store_button); favBtn = (ImageButton) findViewById(R.id.fav_button); photoCameraBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showAlertDialog(); } }); shoppingBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent Intent = new Intent(MainMenuActivity.this, MainActivity.class); startActivity(Intent); } }); accountBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent accountIntent = new Intent(MainMenuActivity.this, ProfileActivity.class); startActivity(accountIntent); } }); storeBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showMakeUpDialog(); } }); favBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent storeIntent = new Intent(MainMenuActivity.this, ShopListActivity.class); startActivity(storeIntent); } }); // Just use hugo to print log isExternalStorageWritable(); isExternalStorageReadable(); // For API 23+ you need to request the read/write permissions even if they are already in your manifest. int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= Build.VERSION_CODES.M) { verifyPermissions(this); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!Settings.canDrawOverlays(this.getApplicationContext())) { Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE); } } if (!isMyServiceRunning(MyService.class)) startService(new Intent(this, MyService.class)); } private void showAlertDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Choose the way to get your selfie"); builder.setIcon(R.mipmap.app_icon); builder.setCancelable(true); final String[] items = new String[]{"From Gallery", "Take Photo"}; final Integer[] icons = new Integer[]{R.mipmap.app_icon, R.mipmap.app_icon}; ListAdapter adapter = new ArrayAdapterWithIcon(getApplication(), items, icons); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { switch (item) { case 0: { buttonNumber = 1; Intent intent = new Intent( Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, GALLERY_REQUEST); break; } case 1: { Intent cameraViewIntent = new Intent(MainMenuActivity.this, ShowCameraViewActivity.class); startActivity(cameraViewIntent); break; } } } }).show(); } private void showMakeUpDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Choose the way to get your selfie"); builder.setIcon(R.mipmap.app_icon); builder.setCancelable(true); final String[] items = new String[]{"From Gallery", "Take Photo"}; final Integer[] icons = new Integer[]{R.mipmap.app_icon, R.mipmap.app_icon}; ListAdapter adapter = new ArrayAdapterWithIcon(getApplication(), items, icons); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { switch (item) { case 0: { buttonNumber = 2; Intent intent = new Intent( Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, GALLERY_REQUEST); break; } case 1: { Intent cameraViewIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File file = getFile(); cameraViewIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(cameraViewIntent, CAM_REQUEST); break; } } } }).show(); } private boolean isMyServiceRunning(Class<?> serviceClass) { ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (serviceClass.getName().equals(service.service.getClassName())) { return true; } } return false; } private File getFile() { File folder = new File("sdcard/FaceT"); if (!folder.exists()) { folder.mkdir(); } String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date()); captureImageFullPath = folder + "/makeup_" + currentDateTimeString; File imageFile = new File(captureImageFullPath); return imageFile; } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == OVERLAY_PERMISSION_REQ_CODE) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!Settings.canDrawOverlays(this.getApplicationContext())) { Snackbar snackbar = Snackbar .make(activity_main_menu_layout, "CameraActivity\", \"SYSTEM_ALERT_WINDOW, permission not granted...", Snackbar.LENGTH_SHORT); snackbar.show(); } else { Intent intent = getIntent(); finish(); startActivity(intent); } } } if (requestCode == GALLERY_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) { Uri pickedImage = data.getData(); Log.d(TAG, "selected!!!" + " : " + pickedImage.getPath()); // Let's read picked image path using content resolver String[] filePathColumn = {MediaStore.Images.Media.DATA}; Cursor cursor = getContentResolver().query(pickedImage, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String picturePath = cursor.getString(columnIndex); cursor.close(); Log.d(TAG + "Path:", picturePath); Intent intent = new Intent(); if (buttonNumber == 1) intent.setClass(MainMenuActivity.this, CaptureActivity.class); else if (buttonNumber == 2) intent.setClass(MainMenuActivity.this, ColorizeFaceActivity.class); intent.putExtra("path", picturePath); //intent.putExtra("color" , "" + mBlobColorHsv); startActivity(intent); } else if (requestCode == CAM_REQUEST) { Intent intent = new Intent(); intent.setClass(MainMenuActivity.this, ColorizeFaceActivity.class); intent.putExtra("path", captureImageFullPath); startActivity(intent); } } /** * Checks if the app has permission to write to device storage or open camera * If the app does not has permission then the user will be prompted to grant permissions * * @param activity */ private static boolean verifyPermissions(Activity activity) { // Check if we have write permission int write_permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE); int read_persmission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE); int camera_permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.CAMERA); if (write_permission != PackageManager.PERMISSION_GRANTED || read_persmission != PackageManager.PERMISSION_GRANTED || camera_permission != PackageManager.PERMISSION_GRANTED) { // We don't have permission so prompt the user ActivityCompat.requestPermissions( activity, PERMISSIONS_REQ, REQUEST_CODE_PERMISSION ); return false; } else { return true; } } /* Checks if external storage is available for read and write */ private boolean isExternalStorageWritable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return true; } return false; } /* Checks if external storage is available to at least read */ private boolean isExternalStorageReadable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { return true; } return false; } }
[email protected]), потому что статус выхода не равен 0public class MainMenuActivity extends AppCompatActivity { private static final String TAG = MainMenuActivity.class.getSimpleName(); private static final int CAM_REQUEST = 3; private static String[] PERMISSIONS_REQ = { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA }; private static final int REQUEST_CODE_PERMISSION = 2; private View activity_main_menu_layout; private ImageButton shoppingBtn; private ImageButton photoCameraBtn; private ImageButton accountBtn; private ImageButton storeBtn; private static final int GALLERY_REQUEST = 1; private static int OVERLAY_PERMISSION_REQ_CODE = 3; private ImageButton favBtn; private int buttonNumber = 0; private String captureImageFullPath = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_menu); activity_main_menu_layout = (RelativeLayout) findViewById(R.id.activity_main_menu_layout); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window window = getWindow(); // Translucent status bar window.setFlags( WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } Typeface fontType = FontManager.getTypeface(getApplicationContext(), FontManager.APP_FONT); FontManager.markAsIconContainer(findViewById(R.id.activity_main_menu_layout), fontType); photoCameraBtn = (ImageButton) findViewById(R.id.photo_camera); shoppingBtn = (ImageButton) findViewById(R.id.shopping_button); accountBtn = (ImageButton) findViewById(R.id.account_button); storeBtn = (ImageButton) findViewById(R.id.store_button); favBtn = (ImageButton) findViewById(R.id.fav_button); photoCameraBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showAlertDialog(); } }); shoppingBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent Intent = new Intent(MainMenuActivity.this, MainActivity.class); startActivity(Intent); } }); accountBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent accountIntent = new Intent(MainMenuActivity.this, ProfileActivity.class); startActivity(accountIntent); } }); storeBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showMakeUpDialog(); } }); favBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent storeIntent = new Intent(MainMenuActivity.this, ShopListActivity.class); startActivity(storeIntent); } }); // Just use hugo to print log isExternalStorageWritable(); isExternalStorageReadable(); // For API 23+ you need to request the read/write permissions even if they are already in your manifest. int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= Build.VERSION_CODES.M) { verifyPermissions(this); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!Settings.canDrawOverlays(this.getApplicationContext())) { Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE); } } if (!isMyServiceRunning(MyService.class)) startService(new Intent(this, MyService.class)); } private void showAlertDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Choose the way to get your selfie"); builder.setIcon(R.mipmap.app_icon); builder.setCancelable(true); final String[] items = new String[]{"From Gallery", "Take Photo"}; final Integer[] icons = new Integer[]{R.mipmap.app_icon, R.mipmap.app_icon}; ListAdapter adapter = new ArrayAdapterWithIcon(getApplication(), items, icons); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { switch (item) { case 0: { buttonNumber = 1; Intent intent = new Intent( Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, GALLERY_REQUEST); break; } case 1: { Intent cameraViewIntent = new Intent(MainMenuActivity.this, ShowCameraViewActivity.class); startActivity(cameraViewIntent); break; } } } }).show(); } private void showMakeUpDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Choose the way to get your selfie"); builder.setIcon(R.mipmap.app_icon); builder.setCancelable(true); final String[] items = new String[]{"From Gallery", "Take Photo"}; final Integer[] icons = new Integer[]{R.mipmap.app_icon, R.mipmap.app_icon}; ListAdapter adapter = new ArrayAdapterWithIcon(getApplication(), items, icons); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { switch (item) { case 0: { buttonNumber = 2; Intent intent = new Intent( Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, GALLERY_REQUEST); break; } case 1: { Intent cameraViewIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File file = getFile(); cameraViewIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(cameraViewIntent, CAM_REQUEST); break; } } } }).show(); } private boolean isMyServiceRunning(Class<?> serviceClass) { ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (serviceClass.getName().equals(service.service.getClassName())) { return true; } } return false; } private File getFile() { File folder = new File("sdcard/FaceT"); if (!folder.exists()) { folder.mkdir(); } String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date()); captureImageFullPath = folder + "/makeup_" + currentDateTimeString; File imageFile = new File(captureImageFullPath); return imageFile; } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == OVERLAY_PERMISSION_REQ_CODE) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!Settings.canDrawOverlays(this.getApplicationContext())) { Snackbar snackbar = Snackbar .make(activity_main_menu_layout, "CameraActivity\", \"SYSTEM_ALERT_WINDOW, permission not granted...", Snackbar.LENGTH_SHORT); snackbar.show(); } else { Intent intent = getIntent(); finish(); startActivity(intent); } } } if (requestCode == GALLERY_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) { Uri pickedImage = data.getData(); Log.d(TAG, "selected!!!" + " : " + pickedImage.getPath()); // Let's read picked image path using content resolver String[] filePathColumn = {MediaStore.Images.Media.DATA}; Cursor cursor = getContentResolver().query(pickedImage, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String picturePath = cursor.getString(columnIndex); cursor.close(); Log.d(TAG + "Path:", picturePath); Intent intent = new Intent(); if (buttonNumber == 1) intent.setClass(MainMenuActivity.this, CaptureActivity.class); else if (buttonNumber == 2) intent.setClass(MainMenuActivity.this, ColorizeFaceActivity.class); intent.putExtra("path", picturePath); //intent.putExtra("color" , "" + mBlobColorHsv); startActivity(intent); } else if (requestCode == CAM_REQUEST) { Intent intent = new Intent(); intent.setClass(MainMenuActivity.this, ColorizeFaceActivity.class); intent.putExtra("path", captureImageFullPath); startActivity(intent); } } /** * Checks if the app has permission to write to device storage or open camera * If the app does not has permission then the user will be prompted to grant permissions * * @param activity */ private static boolean verifyPermissions(Activity activity) { // Check if we have write permission int write_permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE); int read_persmission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE); int camera_permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.CAMERA); if (write_permission != PackageManager.PERMISSION_GRANTED || read_persmission != PackageManager.PERMISSION_GRANTED || camera_permission != PackageManager.PERMISSION_GRANTED) { // We don't have permission so prompt the user ActivityCompat.requestPermissions( activity, PERMISSIONS_REQ, REQUEST_CODE_PERMISSION ); return false; } else { return true; } } /* Checks if external storage is available for read and write */ private boolean isExternalStorageWritable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return true; } return false; } /* Checks if external storage is available to at least read */ private boolean isExternalStorageReadable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { return true; } return false; } }
. . .
04-06 16:47:19.590 934-934/fyp.hkust.facet W/art: Ошибка execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set = arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/fyp.hkust.facet-2/split_lib_slice_9_apk.apk --oat-file=/data/dalvik -cache/arm/data@[email protected]@[email protected]), потому что статус выхода не равен 0
Когда я вхожу в это действие, мой телефон должен загрузить так много вещей (в моем логарифме), что я не знаю, что это такое. Я не знаю, что они означают. Кто-нибудь может решить эту проблему? Большое тебе спасибо.