Skip to content

Commit

Permalink
扫码功能完善
Browse files Browse the repository at this point in the history
  • Loading branch information
maning0303 committed Oct 16, 2020
1 parent 4f02e48 commit f02938e
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 53 deletions.
26 changes: 17 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ dependencies {
implementation librarys.recyclerview
implementation librarys.cardview
implementation librarys.multidex
implementation 'com.android.support.constraint:constraint-layout:2.0.2'

/*-----------------------------------------*/

/*Umeng统计*/
implementation 'com.umeng.sdk:common:1.5.3'
implementation 'com.umeng.sdk:analytics:7.5.3'
/*极光推送*/
implementation files('libs/jcore-android_v1.1.2.jar')
implementation files('libs/jpush-android_v3.0.5.jar')


/*-----------------------------------------*/

/*RecycleView的间隔线*/
implementation 'com.yqritc:recyclerview-flexibledivider:1.2.9'
/*解析Json*/
Expand All @@ -139,27 +153,20 @@ dependencies {
/*点赞收藏按钮*/
implementation 'com.ldoublem.thumbUplib:ThumbUplib:0.5'
/*material风格的dialogs*/
implementation 'com.afollestad.material-dialogs:core:0.9.3.0'
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
/*解析HTML页面*/
implementation 'org.jsoup:jsoup:1.9.2'
/*权限库*/
implementation 'com.yanzhenjie:permission:2.0.0-rc4'
/*ViewPager指示器*/
implementation 'com.ogaclejapan.smarttablayout:library:1.6.1@aar'
/*Umeng统计*/
implementation 'com.umeng.sdk:common:1.5.3'
implementation 'com.umeng.sdk:analytics:7.5.3'
/*极光推送*/
implementation files('libs/jcore-android_v1.1.2.jar')
implementation files('libs/jpush-android_v3.0.5.jar')
/*菜单*/
implementation 'io.github.yavski:fab-speed-dial:1.0.4'
/*高德地图*/
implementation 'com.amap.api:location:5.2.0'
/* 模糊 */
implementation 'jp.wasabeef:blurry:2.1.1'
/*网络监测*/
implementation 'com.android.support.constraint:constraint-layout:2.0.2'
debugImplementation 'com.readystatesoftware.chuck:library:1.1.0'
releaseImplementation 'com.readystatesoftware.chuck:library-no-op:1.1.0'
/* 表格 */
Expand All @@ -183,7 +190,8 @@ dependencies {
/* 图片浏览器所需 */
implementation 'com.github.chrisbanes:PhotoView:2.0.0'

/* ----------自己------------ */
/*-----------------------------------------*/

/*二维码扫描*/
implementation 'com.github.maning0303:MNZXingCode:V2.1.4'
/*翻滚广告条TextView*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.maning.gankmm.R;
Expand All @@ -20,8 +22,10 @@
import com.maning.gankmm.ui.base.BaseActivity;
import com.maning.gankmm.utils.CacheManager;
import com.maning.gankmm.utils.ClipUtils;
import com.maning.gankmm.utils.DialogUtils;
import com.maning.gankmm.utils.MMKVUtils;
import com.maning.gankmm.utils.MySnackbar;
import com.maning.gankmm.utils.PermissionUtils;
import com.maning.gankmm.utils.ThreadPoolUtils;
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;

Expand All @@ -43,8 +47,11 @@ public class ScanResultActivity extends BaseActivity {
RecyclerView recyclerView;
@Bind(R.id.tv_show)
TextView tvShow;
@Bind(R.id.ll_result_show)
LinearLayout ll_result_show;

private String content;
private List<String> scanResult = new ArrayList<>();
private ArrayList<String> scanResult = new ArrayList<>();
private RecycleScanHistoryAdapter recycleScanHistoryAdapter;

public static void open(Context context, String content) {
Expand All @@ -59,23 +66,32 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_scan_result);
ButterKnife.bind(this);
initIntent();
initBackToolBar(toolbar, "扫码结果");
initMyToolbar();
initRecyclerView();
initDatas();
}

private void initMyToolbar() {
if (TextUtils.isEmpty(content)) {
initBackToolBar(toolbar, "扫码记录");
ll_result_show.setVisibility(View.GONE);
} else {
initBackToolBar(toolbar, "扫码内容");
}
}

private void initDatas() {
tvShow.setText(content);

//获取扫码历史
ThreadPoolUtils.execute(new Runnable() {
@Override
public void run() {
scanResult = CacheManager.getScanResult();
scanResult = (ArrayList<String>) CacheManager.getScanResult();
runOnUiThread(new Runnable() {
@Override
public void run() {
recycleScanHistoryAdapter = new RecycleScanHistoryAdapter(mActivity, (ArrayList<String>) scanResult);
recycleScanHistoryAdapter = new RecycleScanHistoryAdapter(mActivity, scanResult);
recyclerView.setAdapter(recycleScanHistoryAdapter);
}
});
Expand All @@ -90,9 +106,28 @@ public boolean onOptionsItemSelected(MenuItem item) {
this.finish();
return true;
case R.id.item_delete:
//TODO:删除提示


DialogUtils.showMyDialog(this,
"提示",
"确定要清除所有记录吗?",
"确定",
"取消",
new DialogUtils.OnDialogClickListener() {
@Override
public void onConfirm() {
CacheManager.cleanScanResult();
//刷新页面
scanResult = new ArrayList<>();
if (recycleScanHistoryAdapter != null) {
recycleScanHistoryAdapter.updateDatas(scanResult);
}
MySnackbar.makeSnackBarGreen(toolbar, "删除成功");
}

@Override
public void onCancel() {

}
});
return true;
}
return super.onOptionsItemSelected(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class RecycleMoreItemAdapter extends RecyclerView.Adapter<RecyclerView.Vi
put("IP地址", R.drawable.gank_icon_tools_ip);
put("世界电话区号", R.drawable.gank_icon_tools_phone_code);
put("扫一扫", R.drawable.gank_icon_tools_scan);
put("扫码记录", R.drawable.gank_icon_tools_scan);
put("扫码记录", R.drawable.gank_icon_tools_scan_history);
put("二维码生成", R.drawable.gank_icon_tools_scancode);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public RecycleScanHistoryAdapter(Context context, ArrayList<String> mDatas) {
layoutInflater = LayoutInflater.from(this.context);
}

public void updateDatas(ArrayList<String> mDatas) {
this.mDatas = mDatas;
notifyDataSetChanged();
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View inflate = layoutInflater.inflate(R.layout.item_scan_history, parent, false);
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/com/maning/gankmm/utils/CacheManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,22 @@ public class CacheManager {
private static final String KEY_SCAN_RESULT = "KEY_SCAN_RESULT";
private static Gson gson = new Gson();

public static void cleanScanResult() {
MMKVUtils.getInstance().putString(KEY_SCAN_RESULT, "");
}

public static void saveScanResult(String content) {
if (TextUtils.isEmpty(content)) {
return;
}
List<String> caches = new ArrayList<>();
String cache = MMKVUtils.getInstance().getString(KEY_SCAN_RESULT, "");
if (TextUtils.isEmpty(cache)) {
caches.add(content);
} else {
caches = gson.fromJson(cache, new TypeToken<List<String>>() {
}.getType());
caches.add(0,content);
caches.add(0, content);
}
MMKVUtils.getInstance().putString(KEY_SCAN_RESULT, gson.toJson(caches));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void open(final Activity activity) {
.setFullScreenScan(true)
//二维码标记点
.isShowResultPoint(true)
.setResultPointConfigs(40, 30, 10, "#70FFFFFF", "#7000A81F")
.setResultPointConfigs(60, 30, 10, "#FFFFFFFF", "#7000A81F")
.builder();
MNScanManager.startScan(activity, scanConfig, new MNScanCallback() {
@Override
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/gank_icon_tools_scan_history.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="128dp"
android:height="128dp"
android:viewportWidth="1024"
android:viewportHeight="1024">
<path
android:pathData="M512,953.82c244.02,0 441.82,-197.8 441.82,-441.82C953.82,267.98 756.02,70.18 512,70.18 267.98,70.18 70.18,267.98 70.18,512c0,244.02 197.8,441.82 441.82,441.82zM512,888.36a376.36,376.36 0,1 1,0 -752.73,376.36 376.36,0 0,1 0,752.73z"
android:fillColor="#1296db"/>
<path
android:pathData="M365.63,677.19a32.73,32.73 0,1 0,47.29 45.25l157.91,-164.86a40.91,40.91 0,0 0,11.33 -28.31V348.36a32.73,32.73 0,1 0,-65.45 -0v171.04l-151.08,157.79z"
android:fillColor="#1296db"/>
</vector>
76 changes: 42 additions & 34 deletions app/src/main/res/layout/activity_scan_result.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,55 @@

<include layout="@layout/toolbar" />

<TextView
android:layout_width="match_parent"
android:layout_height="36dp"
android:background="#E6E6E6"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:text="扫描结果"
android:textColor="#555555"
android:textSize="13sp" />

<RelativeLayout
<LinearLayout
android:id="@+id/ll_result_show"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="16dp">
android:orientation="vertical">

<TextView
android:id="@+id/tv_show"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="36dp"
android:background="#E6E6E6"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:text="扫描结果"
android:textColor="#555555"
android:textSize="13sp" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="16dp"
android:layout_toLeftOf="@+id/btn_copy"
android:textColor="@color/black_text2_color"
android:textSize="18sp"
android:textStyle="bold"
tools:text="大家好才是真的好,广州好迪广州好迪广州好迪广州好迪广州好迪广州好迪广州好迪" />
android:orientation="horizontal"
android:padding="16dp">

<Button
android:id="@+id/btn_copy"
style="?android:attr/borderlessButtonStyle"
android:layout_width="80dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/btn_background"
android:text="复制"
android:textColor="@color/white"
android:textSize="13sp" />
<TextView
android:id="@+id/tv_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="16dp"
android:layout_toLeftOf="@+id/btn_copy"
android:textColor="@color/black_text2_color"
android:textSize="18sp"
android:textStyle="bold"
tools:text="大家好才是真的好,广州好迪广州好迪广州好迪广州好迪广州好迪广州好迪广州好迪" />

<Button
android:id="@+id/btn_copy"
style="?android:attr/borderlessButtonStyle"
android:layout_width="80dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/btn_background"
android:text="复制"
android:textColor="@color/white"
android:textSize="13sp" />

</RelativeLayout>

</RelativeLayout>
</LinearLayout>

<TextView
android:layout_width="match_parent"
Expand Down

0 comments on commit f02938e

Please sign in to comment.