Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CMake support #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Built application files
*.apk
*.ap_
.idea

# Files for the Dalvik VM
*.dex
Expand Down
33 changes: 16 additions & 17 deletions Project-AndroidStudio/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
apply plugin: 'com.android.model.application'
apply plugin: 'com.android.application'

model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.3"
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.3"

defaultConfig.with {
applicationId = "com.seu.magiccamera"
minSdkVersion.apiLevel = 18
targetSdkVersion.apiLevel = 23
versionCode = 1
versionName = "1.0"
}
defaultConfig {
applicationId "com.seu.magiccamera"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
}

android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.txt'))
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.txt'))
}
}

Expand All @@ -28,4 +26,5 @@ dependencies {
compile project(':magicfilter')
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile "com.jakewharton.timber:timber:4.1.2"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.seu.magiccamera.activity;

import android.Manifest;
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
Expand All @@ -11,11 +10,10 @@
import android.graphics.Point;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.PermissionChecker;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
Expand All @@ -32,10 +30,12 @@
import java.util.Date;
import java.util.Locale;

import timber.log.Timber;

/**
* Created by why8222 on 2016/3/17.
*/
public class CameraActivity extends Activity{
public class CameraActivity extends Activity {
private LinearLayout mFilterLayout;
private RecyclerView mFilterListView;
private FilterAdapter mAdapter;
Expand Down Expand Up @@ -95,22 +95,30 @@ public class CameraActivity extends Activity{
MagicFilterType.XPROII
};

static boolean timberPlanted = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (!timberPlanted) {
Timber.plant(new Timber.DebugTree());
timberPlanted = true;
}

setContentView(R.layout.activity_camera);
MagicEngine.Builder builder = new MagicEngine.Builder();
magicEngine = builder
.build((MagicCameraView)findViewById(R.id.glsurfaceview_camera));
.build((MagicCameraView) findViewById(R.id.glsurfaceview_camera));
initView();
}

private void initView(){
mFilterLayout = (LinearLayout)findViewById(R.id.layout_filter);
private void initView() {
mFilterLayout = (LinearLayout) findViewById(R.id.layout_filter);
mFilterListView = (RecyclerView) findViewById(R.id.filter_listView);

btn_shutter = (ImageView)findViewById(R.id.btn_camera_shutter);
btn_mode = (ImageView)findViewById(R.id.btn_camera_mode);
btn_shutter = (ImageView) findViewById(R.id.btn_camera_shutter);
btn_mode = (ImageView) findViewById(R.id.btn_camera_mode);

findViewById(R.id.btn_camera_filter).setOnClickListener(btn_listener);
findViewById(R.id.btn_camera_closefilter).setOnClickListener(btn_listener);
Expand All @@ -127,19 +135,19 @@ private void initView(){
mFilterListView.setAdapter(mAdapter);
mAdapter.setOnFilterChangeListener(onFilterChangeListener);

animator = ObjectAnimator.ofFloat(btn_shutter,"rotation",0,360);
animator = ObjectAnimator.ofFloat(btn_shutter, "rotation", 0, 360);
animator.setDuration(500);
animator.setRepeatCount(ValueAnimator.INFINITE);
Point screenSize = new Point();
getWindowManager().getDefaultDisplay().getSize(screenSize);
MagicCameraView cameraView = (MagicCameraView)findViewById(R.id.glsurfaceview_camera);
MagicCameraView cameraView = (MagicCameraView) findViewById(R.id.glsurfaceview_camera);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) cameraView.getLayoutParams();
params.width = screenSize.x;
params.height = screenSize.x * 4 / 3;
cameraView.setLayoutParams(params);
}

private FilterAdapter.onFilterChangeListener onFilterChangeListener = new FilterAdapter.onFilterChangeListener(){
private FilterAdapter.onFilterChangeListener onFilterChangeListener = new FilterAdapter.onFilterChangeListener() {

@Override
public void onFilterChanged(MagicFilterType filterType) {
Expand All @@ -151,7 +159,7 @@ public void onFilterChanged(MagicFilterType filterType) {
public void onRequestPermissionsResult(int requestCode, String[] permissions,
int[] grantResults) {
if (grantResults.length != 1 || grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if(mode == MODE_PIC)
if (mode == MODE_PIC)
takePhoto();
else
takeVideo();
Expand All @@ -160,41 +168,57 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions,
}
}

private void zoomOut() {
ViewGroup.LayoutParams layoutParams = MagicParams.magicBaseView.getLayoutParams();
layoutParams.width /= 2;
layoutParams.height /= 2;
MagicParams.magicBaseView.setLayoutParams(layoutParams);
}

private void zoomIn() {
ViewGroup.LayoutParams layoutParams = MagicParams.magicBaseView.getLayoutParams();
layoutParams.width *= 2;
layoutParams.height *= 2;
MagicParams.magicBaseView.setLayoutParams(layoutParams);
}

private View.OnClickListener btn_listener = new View.OnClickListener() {

@Override
public void onClick(View v) {
switch (v.getId()){
switch (v.getId()) {
case R.id.btn_camera_mode:
switchMode();
break;
case R.id.btn_camera_shutter:
if (PermissionChecker.checkSelfPermission(CameraActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_DENIED) {
ActivityCompat.requestPermissions(CameraActivity.this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
v.getId());
} else {
if(mode == MODE_PIC)
takePhoto();
else
takeVideo();
}
// if (PermissionChecker.checkSelfPermission(CameraActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
// == PackageManager.PERMISSION_DENIED) {
// ActivityCompat.requestPermissions(CameraActivity.this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
// v.getId());
// } else {
// if(mode == MODE_PIC)
// takePhoto();
// else
// takeVideo();
// }
zoomOut();
break;
case R.id.btn_camera_filter:
showFilters();
// showFilters();
zoomIn();
break;
case R.id.btn_camera_switch:
magicEngine.switchCamera();
break;
case R.id.btn_camera_beauty:
new AlertDialog.Builder(CameraActivity.this)
.setSingleChoiceItems(new String[] { "关闭", "1", "2", "3", "4", "5"}, MagicParams.beautyLevel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
magicEngine.setBeautyLevel(which);
dialog.dismiss();
}
})
.setSingleChoiceItems(new String[]{"关闭", "1", "2", "3", "4", "5"}, MagicParams.beautyLevel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
magicEngine.setBeautyLevel(which);
dialog.dismiss();
}
})
.setNegativeButton("取消", null)
.show();
break;
Expand All @@ -205,32 +229,32 @@ public void onClick(DialogInterface dialog, int which) {
}
};

private void switchMode(){
if(mode == MODE_PIC){
private void switchMode() {
if (mode == MODE_PIC) {
mode = MODE_VIDEO;
btn_mode.setImageResource(R.drawable.icon_camera);
}else{
} else {
mode = MODE_PIC;
btn_mode.setImageResource(R.drawable.icon_video);
}
}

private void takePhoto(){
magicEngine.savePicture(getOutputMediaFile(),null);
private void takePhoto() {
magicEngine.savePicture(getOutputMediaFile(), null);
}

private void takeVideo(){
if(isRecording) {
private void takeVideo() {
if (isRecording) {
animator.end();
magicEngine.stopRecord();
}else {
} else {
animator.start();
magicEngine.startRecord();
}
isRecording = !isRecording;
}

private void showFilters(){
private void showFilters() {
ObjectAnimator animator = ObjectAnimator.ofFloat(mFilterLayout, "translationY", mFilterLayout.getHeight(), 0);
animator.setDuration(200);
animator.addListener(new Animator.AnimatorListener() {
Expand Down Expand Up @@ -259,8 +283,8 @@ public void onAnimationCancel(Animator animation) {
animator.start();
}

private void hideFilters(){
ObjectAnimator animator = ObjectAnimator.ofFloat(mFilterLayout, "translationY", 0 , mFilterLayout.getHeight());
private void hideFilters() {
ObjectAnimator animator = ObjectAnimator.ofFloat(mFilterLayout, "translationY", 0, mFilterLayout.getHeight());
animator.setDuration(200);
animator.addListener(new Animator.AnimatorListener() {

Expand Down
56 changes: 32 additions & 24 deletions Project-AndroidStudio/app/src/main/res/layout/activity_camera.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,84 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.seu.magiccamera.activity.CameraActivity" >
tools:context="com.seu.magiccamera.activity.CameraActivity">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.seu.magicfilter.widget.MagicCameraView
android:id="@+id/glsurfaceview_camera"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="5dp"
android:layout_alignParentRight="true"
android:layout_gravity="center_horizontal"
android:background="@android:color/transparent"
android:orientation="horizontal"
android:background="@android:color/transparent">
android:padding="5dp">

<ImageView
android:id="@+id/btn_camera_mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_camera_mode"
android:src="@drawable/icon_video"/>
android:src="@drawable/icon_video" />

<ImageView
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:id="@+id/btn_camera_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/selector_rewardcamera"/>
android:layout_marginLeft="10dp"
android:src="@drawable/selector_rewardcamera" />
</LinearLayout>
</RelativeLayout>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="match_parent"
android:layout_gravity="bottom"
android:layout_height="120.0dip"
android:paddingTop="5dip"
android:paddingBottom="5dip"
android:layout_alignParentBottom="true"
android:background="@android:color/white">
android:layout_gravity="bottom"
android:background="@android:color/white"
android:paddingBottom="5dip"
android:paddingTop="5dip">

<ImageView
android:id="@+id/btn_camera_beauty"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:src="@drawable/btn_camera_beauty"
android:scaleType="center">
</ImageView>
android:scaleType="center"
android:src="@drawable/btn_camera_beauty"></ImageView>

<ImageView
android:id="@+id/btn_camera_shutter"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:id="@+id/btn_camera_shutter"
android:src="@drawable/btn_camera_shutter">
</ImageView>
android:src="@drawable/btn_camera_shutter"></ImageView>

<ImageView
android:id="@+id/btn_camera_filter"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:scaleType="center"
android:id="@+id/btn_camera_filter"
android:src="@drawable/btn_camera_filter">
</ImageView>
android:src="@drawable/btn_camera_filter"></ImageView>
</LinearLayout>

<include
android:id="@+id/layout_filter"
layout="@layout/filter_layout"
android:visibility="invisible"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
android:layout_gravity="bottom"
android:visibility="invisible" />
</FrameLayout>
</LinearLayout>
Loading