Skip to content

Commit

Permalink
rewrite module indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
SereneGuest committed Nov 10, 2018
1 parent b719561 commit eb40808
Show file tree
Hide file tree
Showing 12 changed files with 417 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ public void remove(String key) {
mList.remove(index);
}
}

public void clear() {
mList.clear();
}
}
55 changes: 32 additions & 23 deletions app/src/main/java/com/smewise/camera2/manager/ModuleManager.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
package com.smewise.camera2.manager;

import android.content.Context;
import android.util.Log;
import android.view.View;

import com.smewise.camera2.R;
import com.smewise.camera2.data.CamListPreference;
import com.smewise.camera2.data.PrefListAdapter;
import com.smewise.camera2.data.PreferenceGroup;
import com.smewise.camera2.module.CameraModule;
import com.smewise.camera2.module.DualCameraModule;
import com.smewise.camera2.module.PhotoModule;
import com.smewise.camera2.module.ProfessionalModule;
import com.smewise.camera2.ui.ModuleIndicator;
import com.smewise.camera2.ui.IndicatorView;
import com.smewise.camera2.utils.XmlInflater;

import java.util.ArrayList;
import java.util.List;

/**
* Created by wenzhe on 9/12/17.
*/

public class ModuleManager implements PrefListAdapter.PrefClickListener {
public class ModuleManager implements IndicatorView.IndicatorListener {
private static int sModuleNum = 1;
private static int mCurrentIndex = 0;
private static int mCurrentIndex = 1;
private CameraModule mCurrentModule;
private ModuleIndicator mIndicator;
private IndicatorView mIndicatorView;
private Class<?>[] mModulesClass;
private Controller mController;

Expand All @@ -37,19 +28,41 @@ public class ModuleManager implements PrefListAdapter.PrefClickListener {
*/
public ModuleManager(Context context, Controller controller) {
mController = controller;
mIndicator = new ModuleIndicator(context);
mIndicatorView = mController.getBaseUI().getIndicatorView();
XmlInflater inflater = new XmlInflater(context);
PreferenceGroup group = inflater.inflate(R.xml.module_preference);
mIndicatorView.setIndicatorListener(this);
boolean loadDualCamera = mController.getCameraSettings(context).isDualCameraEnable();
mModulesClass = mIndicator.getModuleClass(loadDualCamera);
mModulesClass = getModuleClass(group, loadDualCamera);
sModuleNum = mModulesClass.length;
mIndicator.setPrefClickListener(this);
// init default position
mIndicatorView.select(mCurrentIndex);
}

private Class<?>[] getModuleClass(PreferenceGroup group, boolean loadDualCamera) {
if (!loadDualCamera) {
group.remove(DualCameraModule.class.getName());
}
Class<?>[] moduleCls = new Class[group.size()];
for (int i = 0; i < group.size(); i++) {
// use reflection to get module class
try {
moduleCls[i] = Class.forName(group.get(i).getKey());
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
// add indicator item
mIndicatorView.addItem(group.get(i).getTitle());
}
group.clear();
return moduleCls;
}

public boolean needChangeModule(int index) {
if (index < 0 || index >= sModuleNum || mCurrentIndex == index) {
return false;
} else {
mCurrentIndex = index;
mIndicator.updateHighlightIndex(mCurrentIndex);
return true;
}
}
Expand All @@ -67,10 +80,6 @@ public CameraModule getCurrentModule() {
return mCurrentModule;
}

public View getIndicatorView() {
return mIndicator.getIndicatorView();
}

public static int getCurrentIndex() {
return mCurrentIndex;
}
Expand All @@ -84,7 +93,7 @@ public static int getModuleCount() {
}

@Override
public void onClick(View view, int position, CamListPreference preference) {
mController.changeModule(position);
public void onPositionChanged(int index) {
mController.changeModule(index);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
mRootView = LayoutInflater.from(getActivity()).inflate(R.layout.camera_fragment_layout, null);
mBaseUI = new AppBaseUI(mAppContext, mRootView);
mModuleManager = new ModuleManager(mAppContext, mController);
mBaseUI.setIndicatorView(mModuleManager.getIndicatorView());
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public Void run() {

void setNewModule(int index) {
mController.changeModule(index);
getBaseUI().getIndicatorView().select(index);
}

CameraToolKit getToolKit() {
Expand Down
15 changes: 7 additions & 8 deletions app/src/main/java/com/smewise/camera2/ui/AppBaseUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

public class AppBaseUI implements View.OnClickListener {
private CoverView mCoverView;
private LinearLayout mIndicatorContainer;
private RelativeLayout mPreviewRootView;
private ShutterButton mShutter;
private ImageButton mSetting;
Expand All @@ -29,14 +28,14 @@ public class AppBaseUI implements View.OnClickListener {
private FocusView mFocusView;
private LinearLayout mMenuContainer;
private CameraUiEvent mEvent;
private IndicatorView mIndicatorView;

private Point mDisplaySize;
private int mVirtualKeyHeight;
private int mTopBarHeight;

public AppBaseUI(Context context, View rootView) {
mCoverView = rootView.findViewById(R.id.cover_view);
mIndicatorContainer = rootView.findViewById(R.id.module_indicator_container);

mPreviewRootView = rootView.findViewById(R.id.preview_root_view);
mShutter = rootView.findViewById(R.id.btn_shutter);
Expand All @@ -47,6 +46,7 @@ public AppBaseUI(Context context, View rootView) {
mThumbnail = rootView.findViewById(R.id.thumbnail);
mThumbnail.setOnClickListener(this);
mMenuContainer = rootView.findViewById(R.id.menu_container);
mIndicatorView = rootView.findViewById(R.id.indicator_view);

mDisplaySize = CameraUtil.getDisplaySize(context);
mVirtualKeyHeight = CameraUtil.getVirtualKeyHeight(context);
Expand All @@ -60,11 +60,6 @@ public void setCameraUiEvent(CameraUiEvent event) {
mEvent = event;
}

public void setIndicatorView(View view) {
mIndicatorContainer.removeAllViews();
mIndicatorContainer.addView(view);
}

public RelativeLayout getRootView() {
return mPreviewRootView;
}
Expand All @@ -81,6 +76,10 @@ public View getBottomView() {
return mBottomContainer;
}

public IndicatorView getIndicatorView() {
return mIndicatorView;
}

public void setMenuView(View view) {
mMenuContainer.removeAllViews();
mMenuContainer.addView(view);
Expand Down Expand Up @@ -159,7 +158,7 @@ public void setUIClickable(boolean clickable) {
if (mMenuContainer.getChildCount() > 0) {
mMenuContainer.getChildAt(0).setClickable(clickable);
}
mIndicatorContainer.getChildAt(0).setClickable(clickable);
mIndicatorView.setClickable(clickable);
}

@Override
Expand Down
Loading

0 comments on commit eb40808

Please sign in to comment.